Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
},
lineTop: 0
};
this.defaultOptions = {
orientation: {
axis: 'bottom'
}, // axis orientation: 'top' or 'bottom'
showMinorLabels: true,
showMajorLabels: true,
maxMinorChars: 7,
format: TimeStep.FORMAT,
moment: moment,
timeAxis: null
};
this.options = util.extend({}, this.defaultOptions);
this.body = body;
// create the HTML DOM
this._create();
this.setOptions(options);
}
timeAxis2.setOptions = function (options) {
var _options = options ? util.extend({}, options) : {};
_options.orientation = 'top'; // override the orientation option, always top
TimeAxis.prototype.setOptions.call(timeAxis2, _options);
};
this.components.push(timeAxis2);
export function Network(container, data, options) {
if (!(this instanceof Network)) {
throw new SyntaxError('Constructor must be called with the new operator');
}
// set constant values
this.options = {};
this.defaultOptions = {
locale: 'en',
locales: locales,
clickToUse: false
};
util.extend(this.options, this.defaultOptions);
/**
* Containers for nodes and edges.
*
* 'edges' and 'nodes' contain the full definitions of all the network elements.
* 'nodeIndices' and 'edgeIndices' contain the id's of the active elements.
*
* The distinction is important, because a defined node need not be active, i.e.
* visible on the canvas. This happens in particular when clusters are defined, in
* that case there will be nodes and edges not displayed.
* The bottom line is that all code with actions related to visibility, *must* use
* 'nodeIndices' and 'edgeIndices', not 'nodes' and 'edges' directly.
*/
this.body = {
container: container,
constructor(body) {
this.body = body;
this.clusteredNodes = {}; // key: node id, value: { clusterId: , node: }
this.clusteredEdges = {}; // key: edge id, value: restore information for given edge
this.options = {};
this.defaultOptions = {};
util.extend(this.options, this.defaultOptions);
this.body.emitter.on('_resetData', () => {this.clusteredNodes = {}; this.clusteredEdges = {};})
}
setOptions(options) {
if (options !== undefined) {
// extend all but the values in fields
let fields = ['hideEdgesOnDrag', 'hideEdgesOnZoom', 'hideNodesOnDrag','keyboard','multiselect','selectable','selectConnectedEdges'];
util.selectiveNotDeepExtend(fields, this.options, options);
// merge the keyboard options in.
util.mergeOptions(this.options, options, 'keyboard');
if (options.tooltip) {
util.extend(this.options.tooltip, options.tooltip);
if (options.tooltip.color) {
this.options.tooltip.color = util.parseColor(options.tooltip.color);
}
}
}
this.navigationHandler.setOptions(this.options);
}
_hide(storePrevious = true) {
// store the previous color for next time;
if (storePrevious === true) {
this.previousColor = util.extend({}, this.color);
}
if (this.applied === true) {
this.updateCallback(this.initialColor);
}
this.frame.style.display = 'none';
// call the closing callback, restoring the onclick method.
// this is in a setTimeout because it will trigger the show again before the click is done.
setTimeout(() => {
if (this.closeCallback !== undefined) {
this.closeCallback();
this.closeCallback = undefined;
}
},0);
_setColor(rgba, setInitial = true) {
// store the initial color
if (setInitial === true) {
this.initialColor = util.extend({}, rgba);
}
this.color = rgba;
let hsv = util.RGBToHSV(rgba.r, rgba.g, rgba.b);
let angleConvert = 2 * Math.PI;
let radius = this.r * hsv.s;
let x = this.centerCoordinates.x + radius * Math.sin(angleConvert * hsv.h);
let y = this.centerCoordinates.y + radius * Math.cos(angleConvert * hsv.h);
this.colorPickerSelector.style.left = x - 0.5 * this.colorPickerSelector.clientWidth + 'px';
this.colorPickerSelector.style.top = y - 0.5 * this.colorPickerSelector.clientHeight + 'px';
this._updatePicker(rgba);
}
_controlNodeTouch(event) {
this.selectionHandler.unselectAll();
this.lastTouch = this.body.functions.getPointer(event.center);
this.lastTouch.translation = util.extend({},this.body.view.translation); // copy the object
}
onDragStart(event) {
//in case the touch event was triggered on an external div, do the initial touch now.
if (this.drag.pointer === undefined) {
this.onTouch(event);
}
// note: drag.pointer is set in onTouch to get the initial touch location
let node = this.selectionHandler.getNodeAt(this.drag.pointer);
this.drag.dragging = true;
this.drag.selection = [];
this.drag.translation = util.extend({},this.body.view.translation); // copy the object
this.drag.nodeId = undefined;
if (node !== undefined && this.options.dragNodes === true) {
this.drag.nodeId = node.id;
// select the clicked node if not yet selected
if (node.isSelected() === false) {
this.selectionHandler.unselectAll();
this.selectionHandler.selectObject(node);
}
// after select to contain the node
this.selectionHandler._generateClickEvent('dragStart', event, this.drag.pointer);
let selection = this.selectionHandler.selectionObj.nodes;
// create an array with the selected nodes and their original location and status
for (let nodeId in selection) {
initiallyActive: false,
addNode: true,
addEdge: true,
editNode: undefined,
editEdge: true,
deleteNode: true,
deleteEdge: true,
controlNodeStyle:{
shape:'dot',
size:6,
color: {background: '#ff0000', border: '#3c3c3c', highlight: {background: '#07f968', border: '#3c3c3c'}},
borderWidth: 2,
borderWidthSelected: 2
}
};
util.extend(this.options, this.defaultOptions);
this.body.emitter.on('destroy', () => {this._clean();});
this.body.emitter.on('_dataChanged',this._restore.bind(this));
this.body.emitter.on('_resetData', this._restore.bind(this));
}