From 7c22bd3c3b88ca463d10af74c9821dbd5dd7d4af Mon Sep 17 00:00:00 2001 From: jos Date: Tue, 16 Jun 2015 14:44:05 +0200 Subject: [PATCH] Configurator is now lazy loaded in Timeline, Graph2d, and Network (see #964) --- lib/network/Network.js | 15 +++++++++------ lib/timeline/Core.js | 17 ++++++++++++++++- lib/timeline/Graph2d.js | 12 +++++++++--- lib/timeline/Timeline.js | 12 +++++++++--- 4 files changed, 43 insertions(+), 13 deletions(-) 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