|
|
@ -62,6 +62,25 @@ class Edge { |
|
|
|
} |
|
|
|
this.colorDirty = true; |
|
|
|
|
|
|
|
Edge.parseOptions(this.options, options); |
|
|
|
|
|
|
|
if (options.id !== undefined) {this.id = options.id;} |
|
|
|
if (options.from !== undefined) {this.fromId = options.from;} |
|
|
|
if (options.to !== undefined) {this.toId = options.to;} |
|
|
|
if (options.title !== undefined) {this.title = options.title;} |
|
|
|
if (options.value !== undefined) {this.value = options.value;} |
|
|
|
|
|
|
|
// A node is connected when it has a from and to node that both exist in the network.body.nodes.
|
|
|
|
this.connect(); |
|
|
|
|
|
|
|
// update label Module
|
|
|
|
this.updateLabelModule(); |
|
|
|
|
|
|
|
let dataChanged = this.updateEdgeType(); |
|
|
|
return dataChanged; |
|
|
|
} |
|
|
|
|
|
|
|
static parseOptions(parentOptions, newOptions) { |
|
|
|
var fields = [ |
|
|
|
'id', |
|
|
|
'font', |
|
|
@ -82,71 +101,59 @@ class Edge { |
|
|
|
'widthMax', |
|
|
|
'widthSelectionMultiplier' |
|
|
|
]; |
|
|
|
util.selectiveDeepExtend(fields, this.options, options); |
|
|
|
|
|
|
|
util.mergeOptions(this.options, options, 'smooth'); |
|
|
|
util.mergeOptions(this.options, options, 'dashes'); |
|
|
|
|
|
|
|
if (options.id !== undefined) {this.id = options.id;} |
|
|
|
if (options.from !== undefined) {this.fromId = options.from;} |
|
|
|
if (options.to !== undefined) {this.toId = options.to;} |
|
|
|
if (options.title !== undefined) {this.title = options.title;} |
|
|
|
if (options.value !== undefined) {this.value = options.value;} |
|
|
|
// only deep extend the items in the field array. These do not have shorthand.
|
|
|
|
util.selectiveDeepExtend(fields, parentOptions, newOptions); |
|
|
|
|
|
|
|
util.mergeOptions(parentOptions, newOptions, 'smooth'); |
|
|
|
util.mergeOptions(parentOptions, newOptions, 'dashes'); |
|
|
|
|
|
|
|
// set the scaling options
|
|
|
|
if (options.scaling !== undefined) { |
|
|
|
if (options.scaling.min !== undefined) {this.options.scaling.min = options.scaling.min;} |
|
|
|
if (options.scaling.max !== undefined) {this.options.scaling.max = options.scaling.max;} |
|
|
|
util.mergeOptions(this.options.scaling, options.scaling, 'label'); |
|
|
|
// set the scaling newOptions
|
|
|
|
if (newOptions.scaling !== undefined) { |
|
|
|
if (newOptions.scaling.min !== undefined) {parentOptions.scaling.min = newOptions.scaling.min;} |
|
|
|
if (newOptions.scaling.max !== undefined) {parentOptions.scaling.max = newOptions.scaling.max;} |
|
|
|
util.mergeOptions(parentOptions.scaling, newOptions.scaling, 'label'); |
|
|
|
} |
|
|
|
|
|
|
|
// hanlde multiple input cases for arrows
|
|
|
|
if (options.arrows !== undefined) { |
|
|
|
if (typeof options.arrows === 'string') { |
|
|
|
let arrows = options.arrows.toLowerCase(); |
|
|
|
if (arrows.indexOf("to") != -1) {this.options.arrows.to.enabled = true;} |
|
|
|
if (arrows.indexOf("middle") != -1) {this.options.arrows.middle.enabled = true;} |
|
|
|
if (arrows.indexOf("from") != -1) {this.options.arrows.from.enabled = true;} |
|
|
|
if (newOptions.arrows !== undefined) { |
|
|
|
if (typeof newOptions.arrows === 'string') { |
|
|
|
let arrows = newOptions.arrows.toLowerCase(); |
|
|
|
if (arrows.indexOf("to") != -1) {parentOptions.arrows.to.enabled = true;} |
|
|
|
if (arrows.indexOf("middle") != -1) {parentOptions.arrows.middle.enabled = true;} |
|
|
|
if (arrows.indexOf("from") != -1) {parentOptions.arrows.from.enabled = true;} |
|
|
|
} |
|
|
|
else if (typeof options.arrows === 'object') { |
|
|
|
util.mergeOptions(this.options.arrows, options.arrows, 'to'); |
|
|
|
util.mergeOptions(this.options.arrows, options.arrows, 'middle'); |
|
|
|
util.mergeOptions(this.options.arrows, options.arrows, 'from'); |
|
|
|
else if (typeof newOptions.arrows === 'object') { |
|
|
|
util.mergeOptions(parentOptions.arrows, newOptions.arrows, 'to'); |
|
|
|
util.mergeOptions(parentOptions.arrows, newOptions.arrows, 'middle'); |
|
|
|
util.mergeOptions(parentOptions.arrows, newOptions.arrows, 'from'); |
|
|
|
} |
|
|
|
else { |
|
|
|
throw new Error("The arrow options can only be an object or a string. Refer to the documentation. You used:" + JSON.stringify(options.arrows)); |
|
|
|
throw new Error("The arrow newOptions can only be an object or a string. Refer to the documentation. You used:" + JSON.stringify(newOptions.arrows)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// hanlde multiple input cases for color
|
|
|
|
if (options.color !== undefined) { |
|
|
|
if (util.isString(options.color)) { |
|
|
|
util.assignAllKeys(this.options.color, options.color); |
|
|
|
this.options.color.inherit.enabled = false; |
|
|
|
if (newOptions.color !== undefined) { |
|
|
|
if (util.isString(newOptions.color)) { |
|
|
|
parentOptions.color.color = newOptions.color; |
|
|
|
parentOptions.color.highlight = newOptions.color; |
|
|
|
parentOptions.color.hover = newOptions.color; |
|
|
|
parentOptions.color.inherit.enabled = false; |
|
|
|
} |
|
|
|
else { |
|
|
|
let colorsDefined = false; |
|
|
|
if (options.color.color !== undefined) {this.options.color.color = options.color.color; colorsDefined = true;} |
|
|
|
if (options.color.highlight !== undefined) {this.options.color.highlight = options.color.highlight; colorsDefined = true;} |
|
|
|
if (options.color.hover !== undefined) {this.options.color.hover = options.color.hover; colorsDefined = true;} |
|
|
|
if (options.color.opacity !== undefined) {this.options.color.opacity = options.color.opacity;} |
|
|
|
if (newOptions.color.color !== undefined) {parentOptions.color.color = newOptions.color.color; colorsDefined = true;} |
|
|
|
if (newOptions.color.highlight !== undefined) {parentOptions.color.highlight = newOptions.color.highlight; colorsDefined = true;} |
|
|
|
if (newOptions.color.hover !== undefined) {parentOptions.color.hover = newOptions.color.hover; colorsDefined = true;} |
|
|
|
if (newOptions.color.opacity !== undefined) {parentOptions.color.opacity = newOptions.color.opacity;} |
|
|
|
|
|
|
|
if (options.color.inherit === undefined && colorsDefined === true) { |
|
|
|
this.options.color.inherit.enabled = false; |
|
|
|
if (newOptions.color.inherit === undefined && colorsDefined === true) { |
|
|
|
parentOptions.color.inherit.enabled = false; |
|
|
|
} |
|
|
|
} |
|
|
|
util.mergeOptions(this.options.color, options.color, 'inherit'); |
|
|
|
util.mergeOptions(parentOptions.color, newOptions.color, 'inherit'); |
|
|
|
} |
|
|
|
|
|
|
|
// A node is connected when it has a from and to node that both exist in the network.body.nodes.
|
|
|
|
this.connect(); |
|
|
|
|
|
|
|
// update label Module
|
|
|
|
this.updateLabelModule(); |
|
|
|
|
|
|
|
let dataChanged = this.updateEdgeType(); |
|
|
|
return dataChanged; |
|
|
|
} |
|
|
|
|
|
|
|
updateLabelModule() { |
|
|
|