diff --git a/lib/network/Network.js b/lib/network/Network.js index 4342c397..001d5f01 100644 --- a/lib/network/Network.js +++ b/lib/network/Network.js @@ -122,9 +122,6 @@ function Network(container, data, options) { // create the DOM elements this.canvas._create(); - // setup configuration system - this.configurator = new Configurator(this, this.body.container, configureOptions, this.canvas.pixelRatio); - // apply options this.setOptions(options); @@ -177,15 +174,21 @@ Network.prototype.setOptions = function (options) { //this.view.setOptions(options.view); //this.clustering.setOptions(options.clustering); - this.configurator.setOptions(options.configure); + if ('configure' in options) { + if (!this.configurator) { + this.configurator = new Configurator(this, this.body.container, configureOptions, this.canvas.pixelRatio); + } + + this.configurator.setOptions(options.configure); + } // if the configuration system is enabled, copy all options and put them into the config system - if (this.configurator.options.enabled === true) { + if (this.configurator && this.configurator.options.enabled === true) { let networkOptions = {nodes:{},edges:{},layout:{},interaction:{},manipulation:{},physics:{},global:{}}; util.deepExtend(networkOptions.nodes, this.nodesHandler.options); util.deepExtend(networkOptions.edges, this.edgesHandler.options); util.deepExtend(networkOptions.layout, this.layoutEngine.options); - // load the selectionHandler and rendere default options in to the interaction group + // load the selectionHandler and render default options in to the interaction group util.deepExtend(networkOptions.interaction, this.selectionHandler.options); util.deepExtend(networkOptions.interaction, this.renderer.options); diff --git a/lib/timeline/Core.js b/lib/timeline/Core.js index ada857fd..4000dd96 100644 --- a/lib/timeline/Core.js +++ b/lib/timeline/Core.js @@ -30,6 +30,8 @@ Emitter(Core.prototype); Core.prototype._create = function (container) { this.dom = {}; + this.dom.container = container; + this.dom.root = document.createElement('div'); this.dom.background = document.createElement('div'); this.dom.backgroundVertical = document.createElement('div'); @@ -282,7 +284,11 @@ Core.prototype.setOptions = function (options) { this.components.forEach(component => component.setOptions(options)); // enable/disable configure - if (this.configurator) { + if ('configure' in options) { + if (!this.configurator) { + this.configurator = this._createConfigurator(); + } + this.configurator.setOptions(options.configure); // collect the settings of all components, and pass them to the configuration system @@ -962,4 +968,13 @@ Core.prototype._getScrollTop = function () { return this.props.scrollTop; }; +/** + * Load a configurator + * @return {Object} + * @private + */ +Core.prototype._createConfigurator = function () { + throw new Error('Cannot invoke abstract method _createConfigurator'); +}; + module.exports = Core; diff --git a/lib/timeline/Graph2d.js b/lib/timeline/Graph2d.js index 4cea8d8f..2526193b 100644 --- a/lib/timeline/Graph2d.js +++ b/lib/timeline/Graph2d.js @@ -105,9 +105,6 @@ function Graph2d (container, items, groups, options) { me.emit('contextmenu', me.getEventProperties(event)) }; - // setup configuration system - this.configurator = new Configurator(this, container, configureOptions); - // apply options if (options) { this.setOptions(options); @@ -316,5 +313,14 @@ Graph2d.prototype.getEventProperties = function (event) { } }; +/** + * Load a configurator + * @return {Object} + * @private + */ +Graph2d.prototype._createConfigurator = function () { + return new Configurator(this, this.dom.container, configureOptions); +}; + module.exports = Graph2d; diff --git a/lib/timeline/Timeline.js b/lib/timeline/Timeline.js index 9952c97f..ad06adb4 100644 --- a/lib/timeline/Timeline.js +++ b/lib/timeline/Timeline.js @@ -117,9 +117,6 @@ function Timeline (container, items, groups, options) { me.emit('contextmenu', me.getEventProperties(event)) }; - // setup configuration system - this.configurator = new Configurator(this, container, configureOptions); - // apply options if (options) { this.setOptions(options); @@ -142,6 +139,15 @@ function Timeline (container, items, groups, options) { // Extend the functionality from Core Timeline.prototype = new Core(); +/** + * Load a configurator + * @return {Object} + * @private + */ +Timeline.prototype._createConfigurator = function () { + return new Configurator(this, this.dom.container, configureOptions); +}; + /** * Force a redraw. The size of all items will be recalculated. * Can be useful to manually redraw when option autoResize=false and the window