|
|
@ -3,8 +3,8 @@ var util = require('../../../../util'); |
|
|
|
/** |
|
|
|
* @class Node |
|
|
|
* A node. A node can be connected to other nodes via one or multiple edges. |
|
|
|
* @param {object} properties An object containing properties for the node. All |
|
|
|
* properties are optional, except for the id. |
|
|
|
* @param {object} properties An object containing options for the node. All |
|
|
|
* options are optional, except for the id. |
|
|
|
* {number} id Id of the node. Required |
|
|
|
* {string} label Text label for the node |
|
|
|
* {number} x Horizontal position of the node |
|
|
@ -20,7 +20,7 @@ var util = require('../../../../util'); |
|
|
|
* @param {Network.Images} imagelist A list with images. Only needed |
|
|
|
* when the node has an image |
|
|
|
* @param {Network.Groups} grouplist A list with groups. Needed for |
|
|
|
* retrieving group properties |
|
|
|
* retrieving group options |
|
|
|
* @param {Object} constants An object with default values for |
|
|
|
* example for the color |
|
|
|
* |
|
|
@ -33,7 +33,7 @@ function Node(properties, imagelist, grouplist, globalOptions) { |
|
|
|
|
|
|
|
this.edges = []; // all edges connected to this node
|
|
|
|
|
|
|
|
// set defaults for the properties
|
|
|
|
// set defaults for the options
|
|
|
|
this.id = undefined; |
|
|
|
this.allowedToMoveX = false; |
|
|
|
this.allowedToMoveY = false; |
|
|
@ -43,6 +43,7 @@ function Node(properties, imagelist, grouplist, globalOptions) { |
|
|
|
this.verticalAlignTop = true; // these are for the navigation controls
|
|
|
|
this.baseRadiusValue = this.options.radius; |
|
|
|
this.radiusFixed = false; |
|
|
|
|
|
|
|
this.level = -1; |
|
|
|
this.preassignedLevel = false; |
|
|
|
this.hierarchyEnumerated = false; |
|
|
@ -52,7 +53,7 @@ function Node(properties, imagelist, grouplist, globalOptions) { |
|
|
|
this.imagelist = imagelist; |
|
|
|
this.grouplist = grouplist; |
|
|
|
|
|
|
|
// physics properties
|
|
|
|
// physics options
|
|
|
|
this.x = null; |
|
|
|
this.y = null; |
|
|
|
this.predefinedPosition = false; // used to check if initial zoomExtent should just take the range or approximate
|
|
|
@ -60,7 +61,7 @@ function Node(properties, imagelist, grouplist, globalOptions) { |
|
|
|
this.fixedData = {x:null,y:null}; |
|
|
|
|
|
|
|
// TODO: global options should not be needed here.
|
|
|
|
this.setProperties(properties, globalOptions); |
|
|
|
this.setOptions(properties, globalOptions); |
|
|
|
|
|
|
|
// variables to tell the node about the network.
|
|
|
|
this.networkScaleInv = 1; |
|
|
@ -94,11 +95,11 @@ Node.prototype.detachEdge = function(edge) { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Set or overwrite properties for the node |
|
|
|
* @param {Object} properties an object with properties |
|
|
|
* @param {Object} constants and object with default, global properties |
|
|
|
* Set or overwrite options for the node |
|
|
|
* @param {Object} properties an object with options |
|
|
|
* @param {Object} constants and object with default, global options |
|
|
|
*/ |
|
|
|
Node.prototype.setProperties = function(properties, constants) { |
|
|
|
Node.prototype.setOptions = function(properties, constants) { |
|
|
|
if (!properties) { |
|
|
|
return; |
|
|
|
} |
|
|
@ -111,7 +112,7 @@ Node.prototype.setProperties = function(properties, constants) { |
|
|
|
]; |
|
|
|
util.selectiveDeepExtend(fields, this.options, properties); |
|
|
|
|
|
|
|
// basic properties
|
|
|
|
// basic options
|
|
|
|
if (properties.id !== undefined) {this.id = properties.id;} |
|
|
|
if (properties.label !== undefined) {this.label = properties.label; this.originalLabel = properties.label;} |
|
|
|
if (properties.title !== undefined) {this.title = properties.title;} |
|
|
@ -120,7 +121,7 @@ Node.prototype.setProperties = function(properties, constants) { |
|
|
|
if (properties.value !== undefined) {this.value = properties.value;} |
|
|
|
if (properties.level !== undefined) {this.level = properties.level; this.preassignedLevel = true;} |
|
|
|
|
|
|
|
// navigation controls properties
|
|
|
|
// navigation controls options
|
|
|
|
if (properties.horizontalAlignLeft !== undefined) {this.horizontalAlignLeft = properties.horizontalAlignLeft;} |
|
|
|
if (properties.verticalAlignTop !== undefined) {this.verticalAlignTop = properties.verticalAlignTop;} |
|
|
|
if (properties.triggerFunction !== undefined) {this.triggerFunction = properties.triggerFunction;} |
|
|
@ -129,14 +130,14 @@ Node.prototype.setProperties = function(properties, constants) { |
|
|
|
throw "Node must have an id"; |
|
|
|
} |
|
|
|
|
|
|
|
// copy group properties
|
|
|
|
// copy group options
|
|
|
|
if (typeof properties.group === 'number' || (typeof properties.group === 'string' && properties.group != '')) { |
|
|
|
var groupObj = this.grouplist.get(properties.group); |
|
|
|
util.deepExtend(this.options, groupObj); |
|
|
|
// the color object needs to be completely defined. Since groups can partially overwrite the colors, we parse it again, just in case.
|
|
|
|
this.options.color = util.parseColor(this.options.color); |
|
|
|
} |
|
|
|
// individual shape properties
|
|
|
|
// individual shape options
|
|
|
|
if (properties.radius !== undefined) {this.baseRadiusValue = this.options.radius;} |
|
|
|
if (properties.color !== undefined) {this.options.color = util.parseColor(properties.color);} |
|
|
|
|
|
|
|