Browse Source

Configurator is now lazy loaded in Timeline, Graph2d, and Network (see #964)

flowchartTest
jos 9 years ago
parent
commit
7c22bd3c3b
4 changed files with 43 additions and 13 deletions
  1. +9
    -6
      lib/network/Network.js
  2. +16
    -1
      lib/timeline/Core.js
  3. +9
    -3
      lib/timeline/Graph2d.js
  4. +9
    -3
      lib/timeline/Timeline.js

+ 9
- 6
lib/network/Network.js View File

@ -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);

+ 16
- 1
lib/timeline/Core.js View File

@ -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;

+ 9
- 3
lib/timeline/Graph2d.js View File

@ -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;

+ 9
- 3
lib/timeline/Timeline.js View File

@ -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

Loading…
Cancel
Save