Nuke nodes
by hoolymama
HTML
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
</body>
CSS
canvas { background-color : #eee;
}
JavaScript
// A NODE IN A GRAPH
class Node {
constructor(name, value) {
this.name = name;
this.value = value;
this.children = [];
}
add(child) {
this.children.push(child);
}
}
// Create some nodes
const n1 = new Node("n1", 12);
const n2 = new Node("n2", 2.8);
const n3 = new Node("n3", 10);
const n4 = new Node("n4", 5.5);
const n5 = new Node("n5", 7);
// Make connections
n1.add(n2);
n1.add(n3);
n3.add(n4);
n3.add(n5);
/* console.log(n1) */
const showTree = (node, depth = 0) => console.log("The tree of names with depth indents")
showTree(n1)