blowfish/node_modules/non-layered-tidy-tree-layout/test/tree-node.js

24 lines
508 B
JavaScript
Raw Normal View History

2023-01-29 16:30:24 -06:00
export default class TreeNode {
constructor(width, height) {
this.width = width
this.height = height
this.x = 0
this.y = 0
this.children = []
}
addChild(child) {
child.y = this.y + this.height
this.children.push(child)
}
randExpand(tree) {
tree.y += this.height
const i = Math.floor(Math.random() * (this.children.length + 1))
if (i === this.children.length) {
this.children.push(tree)
} else {
this.children[i].randExpand(tree)
}
}
}