uccser/cs-field-guide

View on GitHub
csfieldguide/static/interactives/tree-diagram/js/tree-diagram.js

Summary

Maintainability
A
0 mins
Test Coverage
/**
 * A script for displaying tree diagrams.
 */

var urlParameters = require('../../../js/third-party/url-parameters.js');

/**
 * The configuration of diagrams.
 * @type {number}
 */
let configs = {
    "basic-parse-tree": require('./configs/basic-parse-tree.json'),
    "mathematical-expression": require('./configs/mathematical-expression.json'),
}


$(document).ready(function () {
    var configName = urlParameters.getUrlParameter('config');
    var config = configs[configName];
    if (config) {
        diagram = new Treant(config);
    } else {
        var element = document.getElementById("tree-diagram");
        element.textContent = "ERROR: Invalid config name";
        element.classList.add("error");
    }
});