Files
cs5890_data_visualization/hw2/js/Node.js
2019-09-16 20:36:30 -06:00

48 lines
862 B
JavaScript

/** Class representing a Node in a tree. */
class Node {
/**
* Creates a Node and intializes the following fields to null/empty:
* parentNode, children, parentName,level,position
* @param {string} nodeName - The name of the node.
* @param {string} parentName - The name of the parent node.
*/
constructor(nodeName,parentName) {
//String of Node Name
this.name = nodeName;
//String of Parent Name
this.parentName = parentName;
/**
* Reference to parent Node Object.
*/
this.parentNode = null;
/**
* Array of Children.
*/
this.children=[];
/**
* Level of the node.
*/
this.level=null;
/**
* Position of the node.
* Initialize to -1
*/
this.position=-1;
}
/**
* Add child to current Node.
* @param {Node} The child Node.
*/
addChild(childNode) {
this.children.push(childNode);
}
}