diff --git a/dist/vis.js b/dist/vis.js
index 4305a823..7e7a2d99 100644
--- a/dist/vis.js
+++ b/dist/vis.js
@@ -117,7 +117,7 @@ return /******/ (function(modules) { // webpackBootstrap
items: {
Item: __webpack_require__(4),
BackgroundItem: __webpack_require__(41),
- BoxItem: __webpack_require__(2),
+ BoxItem: __webpack_require__(3),
PointItem: __webpack_require__(40),
RangeItem: __webpack_require__(37)
},
@@ -137,7 +137,7 @@ return /******/ (function(modules) { // webpackBootstrap
};
// Network
- exports.Network = __webpack_require__(60);
+ exports.Network = __webpack_require__(2);
exports.network = {
Images: __webpack_require__(112),
dotparser: __webpack_require__(110),
@@ -177,771 +177,974 @@ return /******/ (function(modules) { // webpackBootstrap
/* 2 */
/***/ function(module, exports, __webpack_require__) {
+ // Load custom shapes into CanvasRenderingContext2D
'use strict';
- var Item = __webpack_require__(4);
- var util = __webpack_require__(9);
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
- /**
- * @constructor BoxItem
- * @extends Item
- * @param {Object} data Object containing parameters start
- * content, className.
- * @param {{toScreen: function, toTime: function}} conversion
- * Conversion functions from time to screen and vice versa
- * @param {Object} [options] Configuration options
- * // TODO: describe available options
- */
- function BoxItem(data, conversion, options) {
- this.props = {
- dot: {
- width: 0,
- height: 0
- },
- line: {
- width: 0,
- height: 0
- }
- };
+ var _modulesGroups = __webpack_require__(60);
- // validate data
- if (data) {
- if (data.start == undefined) {
- throw new Error('Property "start" missing in item ' + data);
- }
- }
+ var _modulesGroups2 = _interopRequireDefault(_modulesGroups);
- Item.call(this, data, conversion, options);
- }
+ var _modulesNodesHandler = __webpack_require__(61);
- BoxItem.prototype = new Item(null, null, null);
+ var _modulesNodesHandler2 = _interopRequireDefault(_modulesNodesHandler);
- /**
- * Check whether this item is visible inside given range
- * @returns {{start: Number, end: Number}} range with a timestamp for start and end
- * @returns {boolean} True if visible
- */
- BoxItem.prototype.isVisible = function (range) {
- // determine visibility
- // TODO: account for the real width of the item. Right now we just add 1/4 to the window
- var interval = (range.end - range.start) / 4;
- return this.data.start > range.start - interval && this.data.start < range.end + interval;
- };
+ var _modulesEdgesHandler = __webpack_require__(81);
- /**
- * Repaint the item
- */
- BoxItem.prototype.redraw = function () {
- var dom = this.dom;
- if (!dom) {
- // create DOM
- this.dom = {};
- dom = this.dom;
+ var _modulesEdgesHandler2 = _interopRequireDefault(_modulesEdgesHandler);
- // create main box
- dom.box = document.createElement('DIV');
+ var _modulesPhysicsEngine = __webpack_require__(88);
- // contents box (inside the background box). used for making margins
- dom.content = document.createElement('DIV');
- dom.content.className = 'vis-item-content';
- dom.box.appendChild(dom.content);
+ var _modulesPhysicsEngine2 = _interopRequireDefault(_modulesPhysicsEngine);
- // line to axis
- dom.line = document.createElement('DIV');
- dom.line.className = 'vis-line';
+ var _modulesClustering = __webpack_require__(97);
- // dot on axis
- dom.dot = document.createElement('DIV');
- dom.dot.className = 'vis-dot';
+ var _modulesClustering2 = _interopRequireDefault(_modulesClustering);
- // attach this item as attribute
- dom.box['timeline-item'] = this;
+ var _modulesCanvasRenderer = __webpack_require__(99);
- this.dirty = true;
- }
+ var _modulesCanvasRenderer2 = _interopRequireDefault(_modulesCanvasRenderer);
- // append DOM to parent DOM
- if (!this.parent) {
- throw new Error('Cannot redraw item: no parent attached');
- }
- if (!dom.box.parentNode) {
- var foreground = this.parent.dom.foreground;
- if (!foreground) throw new Error('Cannot redraw item: parent has no foreground container element');
- foreground.appendChild(dom.box);
- }
- if (!dom.line.parentNode) {
- var background = this.parent.dom.background;
- if (!background) throw new Error('Cannot redraw item: parent has no background container element');
- background.appendChild(dom.line);
- }
- if (!dom.dot.parentNode) {
- var axis = this.parent.dom.axis;
- if (!background) throw new Error('Cannot redraw item: parent has no axis container element');
- axis.appendChild(dom.dot);
- }
- this.displayed = true;
+ var _modulesCanvas = __webpack_require__(100);
- // Update DOM when item is marked dirty. An item is marked dirty when:
- // - the item is not yet rendered
- // - the item's data is changed
- // - the item is selected/deselected
- if (this.dirty) {
- this._updateContents(this.dom.content);
- this._updateTitle(this.dom.box);
- this._updateDataAttributes(this.dom.box);
- this._updateStyle(this.dom.box);
+ var _modulesCanvas2 = _interopRequireDefault(_modulesCanvas);
- // update class
- var className = (this.data.className ? ' ' + this.data.className : '') + (this.selected ? ' vis-selected' : '');
- dom.box.className = 'vis-item vis-box' + className;
- dom.line.className = 'vis-item vis-line' + className;
- dom.dot.className = 'vis-item vis-dot' + className;
+ var _modulesView = __webpack_require__(101);
- // recalculate size
- this.props.dot.height = dom.dot.offsetHeight;
- this.props.dot.width = dom.dot.offsetWidth;
- this.props.line.width = dom.line.offsetWidth;
- this.width = dom.box.offsetWidth;
- this.height = dom.box.offsetHeight;
+ var _modulesView2 = _interopRequireDefault(_modulesView);
- this.dirty = false;
- }
+ var _modulesInteractionHandler = __webpack_require__(102);
- this._repaintDeleteButton(dom.box);
- };
+ var _modulesInteractionHandler2 = _interopRequireDefault(_modulesInteractionHandler);
- /**
- * Show the item in the DOM (when not already displayed). The items DOM will
- * be created when needed.
- */
- BoxItem.prototype.show = function () {
- if (!this.displayed) {
- this.redraw();
- }
- };
+ var _modulesSelectionHandler = __webpack_require__(105);
- /**
- * Hide the item from the DOM (when visible)
- */
- BoxItem.prototype.hide = function () {
- if (this.displayed) {
- var dom = this.dom;
+ var _modulesSelectionHandler2 = _interopRequireDefault(_modulesSelectionHandler);
- if (dom.box.parentNode) dom.box.parentNode.removeChild(dom.box);
- if (dom.line.parentNode) dom.line.parentNode.removeChild(dom.line);
- if (dom.dot.parentNode) dom.dot.parentNode.removeChild(dom.dot);
+ var _modulesLayoutEngine = __webpack_require__(106);
- this.displayed = false;
- }
- };
+ var _modulesLayoutEngine2 = _interopRequireDefault(_modulesLayoutEngine);
- /**
- * Reposition the item horizontally
- * @Override
- */
- BoxItem.prototype.repositionX = function () {
- var start = this.conversion.toScreen(this.data.start);
- var align = this.options.align;
- var left;
+ var _modulesManipulationSystem = __webpack_require__(107);
- // calculate left position of the box
- if (align == 'right') {
- this.left = start - this.width;
- } else if (align == 'left') {
- this.left = start;
- } else {
- // default or 'center'
- this.left = start - this.width / 2;
- }
+ var _modulesManipulationSystem2 = _interopRequireDefault(_modulesManipulationSystem);
- // reposition box
- this.dom.box.style.left = this.left + 'px';
+ var _sharedConfigurator = __webpack_require__(46);
- // reposition line
- this.dom.line.style.left = start - this.props.line.width / 2 + 'px';
+ var _sharedConfigurator2 = _interopRequireDefault(_sharedConfigurator);
- // reposition dot
- this.dom.dot.style.left = start - this.props.dot.width / 2 + 'px';
- };
+ var _sharedValidator = __webpack_require__(48);
+
+ var _sharedValidator2 = _interopRequireDefault(_sharedValidator);
+
+ var _optionsJs = __webpack_require__(108);
+
+ __webpack_require__(109);
+
+ var Emitter = __webpack_require__(20);
+ var Hammer = __webpack_require__(5);
+ var util = __webpack_require__(9);
+ var DataSet = __webpack_require__(15);
+ var DataView = __webpack_require__(17);
+ var dotparser = __webpack_require__(110);
+ var gephiParser = __webpack_require__(111);
+ var Images = __webpack_require__(112);
+ var Activator = __webpack_require__(43);
+ var locales = __webpack_require__(113);
/**
- * Reposition the item vertically
- * @Override
+ * @constructor Network
+ * Create a network visualization, displaying nodes and edges.
+ *
+ * @param {Element} container The DOM element in which the Network will
+ * be created. Normally a div element.
+ * @param {Object} data An object containing parameters
+ * {Array} nodes
+ * {Array} edges
+ * @param {Object} options Options
*/
- BoxItem.prototype.repositionY = function () {
- var orientation = this.options.orientation.item;
- var box = this.dom.box;
- var line = this.dom.line;
- var dot = this.dom.dot;
+ function Network(container, data, options) {
+ var _this = this;
- if (orientation == 'top') {
- box.style.top = (this.top || 0) + 'px';
+ if (!(this instanceof Network)) {
+ throw new SyntaxError('Constructor must be called with the new operator');
+ }
- line.style.top = '0';
- line.style.height = this.parent.top + this.top + 1 + 'px';
- line.style.bottom = '';
- } else {
- // orientation 'bottom'
- var itemSetHeight = this.parent.itemSet.props.height; // TODO: this is nasty
- var lineHeight = itemSetHeight - this.parent.top - this.parent.height + this.top;
+ // set constant values
+ this.options = {};
+ this.defaultOptions = {
+ locale: 'en',
+ locales: locales,
+ clickToUse: false
+ };
+ util.extend(this.options, this.defaultOptions);
- box.style.top = (this.parent.height - this.top - this.height || 0) + 'px';
- line.style.top = itemSetHeight - lineHeight + 'px';
- line.style.bottom = '0';
- }
+ // containers for nodes and edges
+ this.body = {
+ nodes: {},
+ nodeIndices: [],
+ edges: {},
+ edgeIndices: [],
+ data: {
+ nodes: null, // A DataSet or DataView
+ edges: null // A DataSet or DataView
+ },
+ functions: {
+ createNode: function createNode() {},
+ createEdge: function createEdge() {},
+ getPointer: function getPointer() {}
+ },
+ emitter: {
+ on: this.on.bind(this),
+ off: this.off.bind(this),
+ emit: this.emit.bind(this),
+ once: this.once.bind(this)
+ },
+ eventListeners: {
+ onTap: function onTap() {},
+ onTouch: function onTouch() {},
+ onDoubleTap: function onDoubleTap() {},
+ onHold: function onHold() {},
+ onDragStart: function onDragStart() {},
+ onDrag: function onDrag() {},
+ onDragEnd: function onDragEnd() {},
+ onMouseWheel: function onMouseWheel() {},
+ onPinch: function onPinch() {},
+ onMouseMove: function onMouseMove() {},
+ onRelease: function onRelease() {},
+ onContext: function onContext() {}
+ },
+ container: container,
+ view: {
+ scale: 1,
+ translation: { x: 0, y: 0 }
+ }
+ };
- dot.style.top = -this.props.dot.height / 2 + 'px';
- };
+ // bind the event listeners
+ this.bindEventListeners();
- module.exports = BoxItem;
+ // setting up all modules
+ this.images = new Images(function () {
+ return _this.body.emitter.emit('_requestRedraw');
+ }); // object with images
+ this.groups = new _modulesGroups2['default'](); // object with groups
+ this.canvas = new _modulesCanvas2['default'](this.body); // DOM handler
+ this.selectionHandler = new _modulesSelectionHandler2['default'](this.body, this.canvas); // Selection handler
+ this.interactionHandler = new _modulesInteractionHandler2['default'](this.body, this.canvas, this.selectionHandler); // Interaction handler handles all the hammer bindings (that are bound by canvas), key
+ this.view = new _modulesView2['default'](this.body, this.canvas); // camera handler, does animations and zooms
+ this.renderer = new _modulesCanvasRenderer2['default'](this.body, this.canvas); // renderer, starts renderloop, has events that modules can hook into
+ this.physics = new _modulesPhysicsEngine2['default'](this.body); // physics engine, does all the simulations
+ this.layoutEngine = new _modulesLayoutEngine2['default'](this.body); // layout engine for inital layout and hierarchical layout
+ this.clustering = new _modulesClustering2['default'](this.body); // clustering api
+ this.manipulation = new _modulesManipulationSystem2['default'](this.body, this.canvas, this.selectionHandler); // data manipulation system
-/***/ },
-/* 3 */
-/***/ function(module, exports, __webpack_require__) {
+ this.nodesHandler = new _modulesNodesHandler2['default'](this.body, this.images, this.groups, this.layoutEngine); // Handle adding, deleting and updating of nodes as well as global options
+ this.edgesHandler = new _modulesEdgesHandler2['default'](this.body, this.images, this.groups); // Handle adding, deleting and updating of edges as well as global options
- "use strict";
+ // create the DOM elements
+ this.canvas._create();
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
+ // setup configuration system
+ this.configurator = new _sharedConfigurator2['default'](this, this.body.container, _optionsJs.configureOptions, this.canvas.pixelRatio);
- var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+ // apply options
+ this.setOptions(options);
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+ // load data (the disable start variable will be the same as the enabled clustering)
+ this.setData(data);
+ }
- var util = __webpack_require__(9);
+ // Extend Network with an Emitter mixin
+ Emitter(Network.prototype);
- var View = (function () {
- function View(body, canvas) {
- var _this = this;
+ /**
+ * Set options
+ * @param {Object} options
+ */
+ Network.prototype.setOptions = function (options) {
+ var _this2 = this;
- _classCallCheck(this, View);
+ if (options !== undefined) {
- this.body = body;
- this.canvas = canvas;
+ var errorFound = _sharedValidator2['default'].validate(options, _optionsJs.allOptions);
+ if (errorFound === true) {
+ console.log('%cErrors have been found in the supplied options object.', _sharedValidator.printStyle);
+ }
- this.animationSpeed = 1 / this.renderRefreshRate;
- this.animationEasingFunction = "easeInOutQuint";
- this.easingTime = 0;
- this.sourceScale = 0;
- this.targetScale = 0;
- this.sourceTranslation = 0;
- this.targetTranslation = 0;
- this.lockedOnNodeId = undefined;
- this.lockedOnNodeOffset = undefined;
- this.touchTime = 0;
+ // copy the global fields over
+ var fields = ['locale', 'locales', 'clickToUse'];
+ util.selectiveDeepExtend(fields, this.options, options);
- this.viewFunction = undefined;
+ // the hierarchical system can adapt the edges and the physics to it's own options because not all combinations work with the hierarichical system.
+ options = this.layoutEngine.setOptions(options.layout, options);
- this.body.emitter.on("fit", this.fit.bind(this));
- this.body.emitter.on("animationFinished", function () {
- _this.body.emitter.emit("_stopRendering");
- });
- this.body.emitter.on("unlockNode", this.releaseNode.bind(this));
- }
+ this.canvas.setOptions(options); // options for canvas are in globals
- _createClass(View, [{
- key: "setOptions",
- value: function setOptions() {
- var options = arguments[0] === undefined ? {} : arguments[0];
+ // pass the options to the modules
+ this.groups.setOptions(options.groups);
+ this.nodesHandler.setOptions(options.nodes);
+ this.edgesHandler.setOptions(options.edges);
+ this.physics.setOptions(options.physics);
+ this.manipulation.setOptions(options.manipulation, options, this.options); // manipulation uses the locales in the globals
- this.options = options;
+ this.interactionHandler.setOptions(options.interaction);
+ this.renderer.setOptions(options.interaction); // options for rendering are in interaction
+ this.selectionHandler.setOptions(options.interaction); // options for selection are in interaction
+
+ // reload the settings of the nodes to apply changes in groups that are not referenced by pointer.
+ if (options.groups !== undefined) {
+ this.body.emitter.emit('refreshNodes');
}
- }, {
- key: "_getRange",
+ // these two do not have options at the moment, here for completeness
+ //this.view.setOptions(options.view);
+ //this.clustering.setOptions(options.clustering);
- /**
- * Find the center position of the network
- * @private
- */
- value: function _getRange() {
- var specificNodes = arguments[0] === undefined ? [] : arguments[0];
+ this.configurator.setOptions(options.configure);
- var minY = 1000000000,
- maxY = -1000000000,
- minX = 1000000000,
- maxX = -1000000000,
- node;
- if (specificNodes.length > 0) {
- for (var i = 0; i < specificNodes.length; i++) {
- node = this.body.nodes[specificNodes[i]];
- if (minX > node.shape.boundingBox.left) {
- minX = node.shape.boundingBox.left;
- }
- if (maxX < node.shape.boundingBox.right) {
- maxX = node.shape.boundingBox.right;
- }
- if (minY > node.shape.boundingBox.top) {
- minY = node.shape.boundingBox.top;
- } // top is negative, bottom is positive
- if (maxY < node.shape.boundingBox.bottom) {
- maxY = node.shape.boundingBox.bottom;
- } // top is negative, bottom is positive
+ // if the configuration system is enabled, copy all options and put them into the config system
+ if (this.configurator.options.enabled === true) {
+ var 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
+ util.deepExtend(networkOptions.interaction, this.selectionHandler.options);
+ util.deepExtend(networkOptions.interaction, this.renderer.options);
+
+ util.deepExtend(networkOptions.interaction, this.interactionHandler.options);
+ util.deepExtend(networkOptions.manipulation, this.manipulation.options);
+ util.deepExtend(networkOptions.physics, this.physics.options);
+
+ // load globals into the global object
+ util.deepExtend(networkOptions.global, this.canvas.options);
+ util.deepExtend(networkOptions.global, this.options);
+
+ this.configurator.setModuleOptions(networkOptions);
+ }
+
+ // handle network global options
+ if (options.clickToUse !== undefined) {
+ if (options.clickToUse === true) {
+ if (this.activator === undefined) {
+ this.activator = new Activator(this.canvas.frame);
+ this.activator.on('change', function () {
+ _this2.body.emitter.emit('activate');
+ });
}
} else {
- for (var nodeId in this.body.nodes) {
- if (this.body.nodes.hasOwnProperty(nodeId)) {
- node = this.body.nodes[nodeId];
- if (minX > node.shape.boundingBox.left) {
- minX = node.shape.boundingBox.left;
- }
- if (maxX < node.shape.boundingBox.right) {
- maxX = node.shape.boundingBox.right;
- }
- if (minY > node.shape.boundingBox.top) {
- minY = node.shape.boundingBox.top;
- } // top is negative, bottom is positive
- if (maxY < node.shape.boundingBox.bottom) {
- maxY = node.shape.boundingBox.bottom;
- } // top is negative, bottom is positive
- }
+ if (this.activator !== undefined) {
+ this.activator.destroy();
+ delete this.activator;
}
+ this.body.emitter.emit('activate');
}
+ } else {
+ this.body.emitter.emit('activate');
+ }
- if (minX === 1000000000 && maxX === -1000000000 && minY === 1000000000 && maxY === -1000000000) {
- minY = 0, maxY = 0, minX = 0, maxX = 0;
+ this.canvas.setSize();
+
+ // start the physics simulation. Can be safely called multiple times.
+ this.body.emitter.emit('startSimulation');
+ }
+ };
+
+ /**
+ * Update the this.body.nodeIndices with the most recent node index list
+ * @private
+ */
+ Network.prototype._updateVisibleIndices = function () {
+ var nodes = this.body.nodes;
+ var edges = this.body.edges;
+ this.body.nodeIndices = [];
+ this.body.edgeIndices = [];
+
+ for (var nodeId in nodes) {
+ if (nodes.hasOwnProperty(nodeId)) {
+ if (nodes[nodeId].options.hidden === false) {
+ this.body.nodeIndices.push(nodeId);
}
- return { minX: minX, maxX: maxX, minY: minY, maxY: maxY };
}
- }, {
- key: "_findCenter",
+ }
- /**
- * @param {object} range = {minX: minX, maxX: maxX, minY: minY, maxY: maxY};
- * @returns {{x: number, y: number}}
- * @private
- */
- value: function _findCenter(range) {
- return { x: 0.5 * (range.maxX + range.minX),
- y: 0.5 * (range.maxY + range.minY) };
+ for (var edgeId in edges) {
+ if (edges.hasOwnProperty(edgeId)) {
+ if (edges[edgeId].options.hidden === false) {
+ this.body.edgeIndices.push(edgeId);
+ }
}
- }, {
- key: "fit",
-
- /**
- * This function zooms out to fit all data on screen based on amount of nodes
- * @param {Object} Options
- * @param {Boolean} [initialZoom] | zoom based on fitted formula or range, true = fitted, default = false;
- */
- value: function fit() {
- var options = arguments[0] === undefined ? { nodes: [] } : arguments[0];
- var initialZoom = arguments[1] === undefined ? false : arguments[1];
+ }
+ };
- var range;
- var zoomLevel;
-
- if (initialZoom === true) {
- // check if more than half of the nodes have a predefined position. If so, we use the range, not the approximation.
- var positionDefined = 0;
- for (var nodeId in this.body.nodes) {
- if (this.body.nodes.hasOwnProperty(nodeId)) {
- var node = this.body.nodes[nodeId];
- if (node.predefinedPosition === true) {
- positionDefined += 1;
- }
- }
- }
- if (positionDefined > 0.5 * this.body.nodeIndices.length) {
- this.fit(options, false);
- return;
- }
-
- range = this._getRange(options.nodes);
-
- var numberOfNodes = this.body.nodeIndices.length;
- zoomLevel = 12.662 / (numberOfNodes + 7.4147) + 0.0964822; // this is obtained from fitting a dataset from 5 points with scale levels that looked good.
-
- // correct for larger canvasses.
- var factor = Math.min(this.canvas.frame.canvas.clientWidth / 600, this.canvas.frame.canvas.clientHeight / 600);
- zoomLevel *= factor;
- } else {
- this.body.emitter.emit("_resizeNodes");
- range = this._getRange(options.nodes);
- var xDistance = Math.abs(range.maxX - range.minX) * 1.1;
- var yDistance = Math.abs(range.maxY - range.minY) * 1.1;
-
- var xZoomLevel = this.canvas.frame.canvas.clientWidth / xDistance;
- var yZoomLevel = this.canvas.frame.canvas.clientHeight / yDistance;
-
- zoomLevel = xZoomLevel <= yZoomLevel ? xZoomLevel : yZoomLevel;
- }
-
- if (zoomLevel > 1) {
- zoomLevel = 1;
- } else if (zoomLevel === 0) {
- zoomLevel = 1;
- }
-
- var center = this._findCenter(range);
- var animationOptions = { position: center, scale: zoomLevel, animation: options.animation };
- this.moveTo(animationOptions);
- }
- }, {
- key: "focus",
-
- // animation
-
- /**
- * Center a node in view.
- *
- * @param {Number} nodeId
- * @param {Number} [options]
- */
- value: function focus(nodeId) {
- var options = arguments[1] === undefined ? {} : arguments[1];
-
- if (this.body.nodes[nodeId] !== undefined) {
- var nodePosition = { x: this.body.nodes[nodeId].x, y: this.body.nodes[nodeId].y };
- options.position = nodePosition;
- options.lockedOnNode = nodeId;
-
- this.moveTo(options);
- } else {
- console.log("Node: " + nodeId + " cannot be found.");
- }
- }
- }, {
- key: "moveTo",
-
- /**
- *
- * @param {Object} options | options.offset = {x:Number, y:Number} // offset from the center in DOM pixels
- * | options.scale = Number // scale to move to
- * | options.position = {x:Number, y:Number} // position to move to
- * | options.animation = {duration:Number, easingFunction:String} || Boolean // position to move to
- */
- value: function moveTo(options) {
- if (options === undefined) {
- options = {};
- return;
- }
- if (options.offset === undefined) {
- options.offset = { x: 0, y: 0 };
- }
- if (options.offset.x === undefined) {
- options.offset.x = 0;
- }
- if (options.offset.y === undefined) {
- options.offset.y = 0;
- }
- if (options.scale === undefined) {
- options.scale = this.body.view.scale;
- }
- if (options.position === undefined) {
- options.position = this.getViewPosition();
- }
- if (options.animation === undefined) {
- options.animation = { duration: 0 };
- }
- if (options.animation === false) {
- options.animation = { duration: 0 };
- }
- if (options.animation === true) {
- options.animation = {};
- }
- if (options.animation.duration === undefined) {
- options.animation.duration = 1000;
- } // default duration
- if (options.animation.easingFunction === undefined) {
- options.animation.easingFunction = "easeInOutQuad";
- } // default easing function
-
- this.animateView(options);
- }
- }, {
- key: "animateView",
-
- /**
- *
- * @param {Object} options | options.offset = {x:Number, y:Number} // offset from the center in DOM pixels
- * | options.time = Number // animation time in milliseconds
- * | options.scale = Number // scale to animate to
- * | options.position = {x:Number, y:Number} // position to animate to
- * | options.easingFunction = String // linear, easeInQuad, easeOutQuad, easeInOutQuad,
- * // easeInCubic, easeOutCubic, easeInOutCubic,
- * // easeInQuart, easeOutQuart, easeInOutQuart,
- * // easeInQuint, easeOutQuint, easeInOutQuint
- */
- value: function animateView(options) {
- if (options === undefined) {
- return;
- }
- this.animationEasingFunction = options.animation.easingFunction;
- // release if something focussed on the node
- this.releaseNode();
- if (options.locked === true) {
- this.lockedOnNodeId = options.lockedOnNode;
- this.lockedOnNodeOffset = options.offset;
- }
-
- // forcefully complete the old animation if it was still running
- if (this.easingTime != 0) {
- this._transitionRedraw(true); // by setting easingtime to 1, we finish the animation.
- }
-
- this.sourceScale = this.body.view.scale;
- this.sourceTranslation = this.body.view.translation;
- this.targetScale = options.scale;
-
- // set the scale so the viewCenter is based on the correct zoom level. This is overridden in the transitionRedraw
- // but at least then we'll have the target transition
- this.body.view.scale = this.targetScale;
- var viewCenter = this.canvas.DOMtoCanvas({ x: 0.5 * this.canvas.frame.canvas.clientWidth, y: 0.5 * this.canvas.frame.canvas.clientHeight });
- console.log("viewCenter", viewCenter, this.body.view.translation, options.position);
- var distanceFromCenter = { // offset from view, distance view has to change by these x and y to center the node
- x: viewCenter.x - options.position.x,
- y: viewCenter.y - options.position.y
- };
- this.targetTranslation = {
- x: this.sourceTranslation.x + distanceFromCenter.x * this.targetScale + options.offset.x,
- y: this.sourceTranslation.y + distanceFromCenter.y * this.targetScale + options.offset.y
- };
-
- // if the time is set to 0, don't do an animation
- if (options.animation.duration === 0) {
- if (this.lockedOnNodeId != undefined) {
- this.viewFunction = this._lockedRedraw.bind(this);
- this.body.emitter.on("initRedraw", this.viewFunction);
- } else {
- this.body.view.scale = this.targetScale;
- this.body.view.translation = this.targetTranslation;
- this.body.emitter.emit("_requestRedraw");
- }
- } else {
- this.animationSpeed = 1 / (60 * options.animation.duration * 0.001) || 1 / 60; // 60 for 60 seconds, 0.001 for milli's
- this.animationEasingFunction = options.animation.easingFunction;
-
- this.viewFunction = this._transitionRedraw.bind(this);
- this.body.emitter.on("initRedraw", this.viewFunction);
- this.body.emitter.emit("_startRendering");
- }
- }
- }, {
- key: "_lockedRedraw",
-
- /**
- * used to animate smoothly by hijacking the redraw function.
- * @private
- */
- value: function _lockedRedraw() {
- var nodePosition = { x: this.body.nodes[this.lockedOnNodeId].x, y: this.body.nodes[this.lockedOnNodeId].y };
- var viewCenter = this.DOMtoCanvas({ x: 0.5 * this.frame.canvas.clientWidth, y: 0.5 * this.frame.canvas.clientHeight });
- var distanceFromCenter = { // offset from view, distance view has to change by these x and y to center the node
- x: viewCenter.x - nodePosition.x,
- y: viewCenter.y - nodePosition.y
- };
- var sourceTranslation = this.body.view.translation;
- var targetTranslation = {
- x: sourceTranslation.x + distanceFromCenter.x * this.body.view.scale + this.lockedOnNodeOffset.x,
- y: sourceTranslation.y + distanceFromCenter.y * this.body.view.scale + this.lockedOnNodeOffset.y
- };
-
- this.body.view.translation = targetTranslation;
- }
- }, {
- key: "releaseNode",
- value: function releaseNode() {
- if (this.lockedOnNodeId !== undefined && this.viewFunction !== undefined) {
- this.body.emitter.off("initRedraw", this.viewFunction);
- this.lockedOnNodeId = undefined;
- this.lockedOnNodeOffset = undefined;
- }
- }
- }, {
- key: "_transitionRedraw",
-
- /**
- *
- * @param easingTime
- * @private
- */
- value: function _transitionRedraw() {
- var finished = arguments[0] === undefined ? false : arguments[0];
+ /**
+ * Bind all events
+ */
+ Network.prototype.bindEventListeners = function () {
+ var _this3 = this;
- this.easingTime += this.animationSpeed;
- this.easingTime = finished === true ? 1 : this.easingTime;
+ // this event will trigger a rebuilding of the cache everything. Used when nodes or edges have been added or removed.
+ this.body.emitter.on('_dataChanged', function () {
+ // update shortcut lists
+ _this3._updateVisibleIndices();
+ _this3.physics.updatePhysicsData();
- var progress = util.easingFunctions[this.animationEasingFunction](this.easingTime);
+ // call the dataUpdated event because the only difference between the two is the updating of the indices
+ _this3.body.emitter.emit('_dataUpdated');
+ });
- this.body.view.scale = this.sourceScale + (this.targetScale - this.sourceScale) * progress;
- this.body.view.translation = {
- x: this.sourceTranslation.x + (this.targetTranslation.x - this.sourceTranslation.x) * progress,
- y: this.sourceTranslation.y + (this.targetTranslation.y - this.sourceTranslation.y) * progress
- };
+ // this is called when options of EXISTING nodes or edges have changed.
+ this.body.emitter.on('_dataUpdated', function () {
+ // update values
+ _this3._updateValueRange(_this3.body.nodes);
+ _this3._updateValueRange(_this3.body.edges);
+ // start simulation (can be called safely, even if already running)
+ _this3.body.emitter.emit('startSimulation');
+ });
+ };
- // cleanup
- if (this.easingTime >= 1) {
- this.body.emitter.off("initRedraw", this.viewFunction);
- this.easingTime = 0;
- if (this.lockedOnNodeId != undefined) {
- this.viewFunction = this._lockedRedraw.bind(this);
- this.body.emitter.on("initRedraw", this.viewFunction);
- }
- this.body.emitter.emit("animationFinished");
- }
- }
- }, {
- key: "getScale",
- value: function getScale() {
- return this.body.view.scale;
- }
- }, {
- key: "getViewPosition",
- value: function getViewPosition() {
- return this.canvas.DOMtoCanvas({ x: 0.5 * this.canvas.frame.canvas.clientWidth, y: 0.5 * this.canvas.frame.canvas.clientHeight });
- }
- }]);
+ /**
+ * Set nodes and edges, and optionally options as well.
+ *
+ * @param {Object} data Object containing parameters:
+ * {Array | DataSet | DataView} [nodes] Array with nodes
+ * {Array | DataSet | DataView} [edges] Array with edges
+ * {String} [dot] String containing data in DOT format
+ * {String} [gephi] String containing data in gephi JSON format
+ * {Options} [options] Object with options
+ */
+ Network.prototype.setData = function (data) {
+ // reset the physics engine.
+ this.body.emitter.emit('resetPhysics');
+ this.body.emitter.emit('_resetData');
- return View;
- })();
+ // unselect all to ensure no selections from old data are carried over.
+ this.selectionHandler.unselectAll();
- exports["default"] = View;
- module.exports = exports["default"];
+ if (data && data.dot && (data.nodes || data.edges)) {
+ throw new SyntaxError('Data must contain either parameter "dot" or ' + ' parameter pair "nodes" and "edges", but not both.');
+ }
-/***/ },
-/* 4 */
-/***/ function(module, exports, __webpack_require__) {
+ // set options
+ this.setOptions(data && data.options);
+ // set all data
+ if (data && data.dot) {
+ console.log('The dot property has been depricated. Please use the static convertDot method to convert DOT into vis.network format and use the normal data format with nodes and edges. This converter is used like this: var data = vis.network.convertDot(dotString);');
+ // parse DOT file
+ var dotData = dotparser.DOTToGraph(data.dot);
+ this.setData(dotData);
+ return;
+ } else if (data && data.gephi) {
+ // parse DOT file
+ console.log('The gephi property has been depricated. Please use the static convertGephi method to convert gephi into vis.network format and use the normal data format with nodes and edges. This converter is used like this: var data = vis.network.convertGephi(gephiJson);');
+ var gephiData = gephiParser.parseGephi(data.gephi);
+ this.setData(gephiData);
+ return;
+ } else {
+ this.nodesHandler.setData(data && data.nodes, true);
+ this.edgesHandler.setData(data && data.edges, true);
+ }
- 'use strict';
+ // emit change in data
+ this.body.emitter.emit('_dataChanged');
- var Hammer = __webpack_require__(5);
- var util = __webpack_require__(9);
+ // find a stable position or start animating to a stable position
+ this.body.emitter.emit('initPhysics');
+ };
/**
- * @constructor Item
- * @param {Object} data Object containing (optional) parameters type,
- * start, end, content, group, className.
- * @param {{toScreen: function, toTime: function}} conversion
- * Conversion functions from time to screen and vice versa
- * @param {Object} options Configuration options
- * // TODO: describe available options
+ * Cleans up all bindings of the network, removing it fully from the memory IF the variable is set to null after calling this function.
+ * var network = new vis.Network(..);
+ * network.destroy();
+ * network = null;
*/
- function Item(data, conversion, options) {
- this.id = null;
- this.parent = null;
- this.data = data;
- this.dom = null;
- this.conversion = conversion || {};
- this.options = options || {};
+ Network.prototype.destroy = function () {
+ this.body.emitter.emit('destroy');
+ // clear events
+ this.body.emitter.off();
+ this.off();
- this.selected = false;
- this.displayed = false;
- this.dirty = true;
+ // delete modules
+ delete this.groups;
+ delete this.canvas;
+ delete this.selectionHandler;
+ delete this.interactionHandler;
+ delete this.view;
+ delete this.renderer;
+ delete this.physics;
+ delete this.layoutEngine;
+ delete this.clustering;
+ delete this.manipulation;
+ delete this.nodesHandler;
+ delete this.edgesHandler;
+ delete this.configurator;
+ delete this.images;
- this.top = null;
- this.left = null;
- this.width = null;
- this.height = null;
- }
+ // delete emitter bindings
+ delete this.body.emitter.emit;
+ delete this.body.emitter.on;
+ delete this.body.emitter.off;
+ delete this.body.emitter.once;
+ delete this.body.emitter;
- Item.prototype.stack = true;
+ for (var nodeId in this.body.nodes) {
+ delete this.body.nodes[nodeId];
+ }
+ for (var edgeId in this.body.edges) {
+ delete this.body.edges[edgeId];
+ }
- /**
- * Select current item
- */
- Item.prototype.select = function () {
- this.selected = true;
- this.dirty = true;
- if (this.displayed) this.redraw();
+ // remove the container and everything inside it recursively
+ util.recursiveDOMDelete(this.body.container);
};
/**
- * Unselect current item
+ * Update the values of all object in the given array according to the current
+ * value range of the objects in the array.
+ * @param {Object} obj An object containing a set of Edges or Nodes
+ * The objects must have a method getValue() and
+ * setValueRange(min, max).
+ * @private
*/
- Item.prototype.unselect = function () {
- this.selected = false;
- this.dirty = true;
- if (this.displayed) this.redraw();
- };
+ Network.prototype._updateValueRange = function (obj) {
+ var id;
- /**
- * Set data for the item. Existing data will be updated. The id should not
- * be changed. When the item is displayed, it will be redrawn immediately.
- * @param {Object} data
- */
- Item.prototype.setData = function (data) {
- var groupChanged = data.group != undefined && this.data.group != data.group;
- if (groupChanged) {
- this.parent.itemSet._moveToGroup(this, data.group);
+ // determine the range of the objects
+ var valueMin = undefined;
+ var valueMax = undefined;
+ var valueTotal = 0;
+ for (id in obj) {
+ if (obj.hasOwnProperty(id)) {
+ var value = obj[id].getValue();
+ if (value !== undefined) {
+ valueMin = valueMin === undefined ? value : Math.min(value, valueMin);
+ valueMax = valueMax === undefined ? value : Math.max(value, valueMax);
+ valueTotal += value;
+ }
+ }
}
- this.data = data;
- this.dirty = true;
- if (this.displayed) this.redraw();
- };
-
- /**
- * Set a parent for the item
- * @param {ItemSet | Group} parent
- */
- Item.prototype.setParent = function (parent) {
- if (this.displayed) {
- this.hide();
- this.parent = parent;
- if (this.parent) {
- this.show();
+ // adjust the range of all objects
+ if (valueMin !== undefined && valueMax !== undefined) {
+ for (id in obj) {
+ if (obj.hasOwnProperty(id)) {
+ obj[id].setValueRange(valueMin, valueMax, valueTotal);
+ }
}
- } else {
- this.parent = parent;
}
};
/**
- * Check whether this item is visible inside given range
- * @returns {{start: Number, end: Number}} range with a timestamp for start and end
- * @returns {boolean} True if visible
+ * Returns true when the Network is active.
+ * @returns {boolean}
*/
- Item.prototype.isVisible = function (range) {
- // Should be implemented by Item implementations
- return false;
+ Network.prototype.isActive = function () {
+ return !this.activator || this.activator.active;
};
- /**
- * Show the Item in the DOM (when not already visible)
- * @return {Boolean} changed
- */
- Item.prototype.show = function () {
- return false;
+ Network.prototype.setSize = function () {
+ return this.canvas.setSize.apply(this.canvas, arguments);
};
-
- /**
- * Hide the Item from the DOM (when visible)
- * @return {Boolean} changed
- */
- Item.prototype.hide = function () {
- return false;
+ Network.prototype.canvasToDOM = function () {
+ return this.canvas.canvasToDOM.apply(this.canvas, arguments);
};
-
- /**
- * Repaint the item
- */
- Item.prototype.redraw = function () {};
-
- /**
- * Reposition the Item horizontally
- */
- Item.prototype.repositionX = function () {};
-
- /**
- * Reposition the Item vertically
- */
- Item.prototype.repositionY = function () {};
-
- /**
- * Repaint a delete button on the top right of the item when the item is selected
- * @param {HTMLElement} anchor
- * @protected
- */
- Item.prototype._repaintDeleteButton = function (anchor) {
- if (this.selected && this.options.editable.remove && !this.dom.deleteButton) {
- // create and show button
- var me = this;
-
- var deleteButton = document.createElement('div');
- deleteButton.className = 'vis-delete';
- deleteButton.title = 'Delete this item';
-
- // TODO: be able to destroy the delete button
+ Network.prototype.DOMtoCanvas = function () {
+ return this.canvas.setSize.DOMtoCanvas(this.canvas, arguments);
+ };
+ Network.prototype.findNode = function () {
+ return this.clustering.findNode.apply(this.clustering, arguments);
+ };
+ Network.prototype.isCluster = function () {
+ return this.clustering.isCluster.apply(this.clustering, arguments);
+ };
+ Network.prototype.openCluster = function () {
+ return this.clustering.openCluster.apply(this.clustering, arguments);
+ };
+ Network.prototype.cluster = function () {
+ return this.clustering.cluster.apply(this.clustering, arguments);
+ };
+ Network.prototype.getNodesInCluster = function () {
+ return this.clustering.getNodesInCluster.apply(this.clustering, arguments);
+ };
+ Network.prototype.clusterByConnection = function () {
+ return this.clustering.clusterByConnection.apply(this.clustering, arguments);
+ };
+ Network.prototype.clusterByHubsize = function () {
+ return this.clustering.clusterByHubsize.apply(this.clustering, arguments);
+ };
+ Network.prototype.clusterOutliers = function () {
+ return this.clustering.clusterOutliers.apply(this.clustering, arguments);
+ };
+ Network.prototype.getSeed = function () {
+ return this.layoutEngine.getSeed.apply(this.layoutEngine, arguments);
+ };
+ Network.prototype.enableEditMode = function () {
+ return this.manipulation.enableEditMode.apply(this.manipulation, arguments);
+ };
+ Network.prototype.disableEditMode = function () {
+ return this.manipulation.disableEditMode.apply(this.manipulation, arguments);
+ };
+ Network.prototype.addNodeMode = function () {
+ return this.manipulation.addNodeMode.apply(this.manipulation, arguments);
+ };
+ Network.prototype.editNode = function () {
+ return this.manipulation.editNode.apply(this.manipulation, arguments);
+ };
+ Network.prototype.editNodeMode = function () {
+ console.log('Depricated: Please use editNode instead of editNodeMode.');return this.manipulation.editNode.apply(this.manipulation, arguments);
+ };
+ Network.prototype.addEdgeMode = function () {
+ return this.manipulation.addEdgeMode.apply(this.manipulation, arguments);
+ };
+ Network.prototype.editEdgeMode = function () {
+ return this.manipulation.editEdgeMode.apply(this.manipulation, arguments);
+ };
+ Network.prototype.deleteSelected = function () {
+ return this.manipulation.deleteSelected.apply(this.manipulation, arguments);
+ };
+ Network.prototype.getPositions = function () {
+ return this.nodesHandler.getPositions.apply(this.nodesHandler, arguments);
+ };
+ Network.prototype.storePositions = function () {
+ return this.nodesHandler.storePositions.apply(this.nodesHandler, arguments);
+ };
+ Network.prototype.getBoundingBox = function () {
+ return this.nodesHandler.getBoundingBox.apply(this.nodesHandler, arguments);
+ };
+ Network.prototype.getConnectedNodes = function (objectId) {
+ if (this.body.nodes[objectId] !== undefined) {
+ return this.nodesHandler.getConnectedNodes.apply(this.nodesHandler, arguments);
+ } else {
+ return this.edgesHandler.getConnectedNodes.apply(this.edgesHandler, arguments);
+ }
+ };
+ Network.prototype.getConnectedEdges = function () {
+ return this.nodesHandler.getConnectedEdges.apply(this.nodesHandler, arguments);
+ };
+ Network.prototype.startSimulation = function () {
+ return this.physics.startSimulation.apply(this.physics, arguments);
+ };
+ Network.prototype.stopSimulation = function () {
+ return this.physics.stopSimulation.apply(this.physics, arguments);
+ };
+ Network.prototype.stabilize = function () {
+ return this.physics.stabilize.apply(this.physics, arguments);
+ };
+ Network.prototype.getSelection = function () {
+ return this.selectionHandler.getSelection.apply(this.selectionHandler, arguments);
+ };
+ Network.prototype.getSelectedNodes = function () {
+ return this.selectionHandler.getSelectedNodes.apply(this.selectionHandler, arguments);
+ };
+ Network.prototype.getSelectedEdges = function () {
+ return this.selectionHandler.getSelectedEdges.apply(this.selectionHandler, arguments);
+ };
+ Network.prototype.getNodeAt = function () {
+ return this.selectionHandler.getNodeAt.apply(this.selectionHandler, arguments);
+ };
+ Network.prototype.getEdgeAt = function () {
+ return this.selectionHandler.getEdgeAt.apply(this.selectionHandler, arguments);
+ };
+ Network.prototype.selectNodes = function () {
+ return this.selectionHandler.selectNodes.apply(this.selectionHandler, arguments);
+ };
+ Network.prototype.selectEdges = function () {
+ return this.selectionHandler.selectEdges.apply(this.selectionHandler, arguments);
+ };
+ Network.prototype.unselectAll = function () {
+ return this.selectionHandler.unselectAll.apply(this.selectionHandler, arguments);
+ };
+ Network.prototype.redraw = function () {
+ return this.renderer.redraw.apply(this.renderer, arguments);
+ };
+ Network.prototype.getScale = function () {
+ return this.view.getScale.apply(this.view, arguments);
+ };
+ Network.prototype.getViewPosition = function () {
+ return this.view.getViewPosition.apply(this.view, arguments);
+ };
+ Network.prototype.fit = function () {
+ return this.view.fit.apply(this.view, arguments);
+ };
+ Network.prototype.moveTo = function () {
+ return this.view.moveTo.apply(this.view, arguments);
+ };
+ Network.prototype.focus = function () {
+ return this.view.focus.apply(this.view, arguments);
+ };
+ Network.prototype.releaseNode = function () {
+ return this.view.releaseNode.apply(this.view, arguments);
+ };
+
+ module.exports = Network;
+
+/***/ },
+/* 3 */
+/***/ function(module, exports, __webpack_require__) {
+
+ 'use strict';
+
+ var Item = __webpack_require__(4);
+ var util = __webpack_require__(9);
+
+ /**
+ * @constructor BoxItem
+ * @extends Item
+ * @param {Object} data Object containing parameters start
+ * content, className.
+ * @param {{toScreen: function, toTime: function}} conversion
+ * Conversion functions from time to screen and vice versa
+ * @param {Object} [options] Configuration options
+ * // TODO: describe available options
+ */
+ function BoxItem(data, conversion, options) {
+ this.props = {
+ dot: {
+ width: 0,
+ height: 0
+ },
+ line: {
+ width: 0,
+ height: 0
+ }
+ };
+
+ // validate data
+ if (data) {
+ if (data.start == undefined) {
+ throw new Error('Property "start" missing in item ' + data);
+ }
+ }
+
+ Item.call(this, data, conversion, options);
+ }
+
+ BoxItem.prototype = new Item(null, null, null);
+
+ /**
+ * Check whether this item is visible inside given range
+ * @returns {{start: Number, end: Number}} range with a timestamp for start and end
+ * @returns {boolean} True if visible
+ */
+ BoxItem.prototype.isVisible = function (range) {
+ // determine visibility
+ // TODO: account for the real width of the item. Right now we just add 1/4 to the window
+ var interval = (range.end - range.start) / 4;
+ return this.data.start > range.start - interval && this.data.start < range.end + interval;
+ };
+
+ /**
+ * Repaint the item
+ */
+ BoxItem.prototype.redraw = function () {
+ var dom = this.dom;
+ if (!dom) {
+ // create DOM
+ this.dom = {};
+ dom = this.dom;
+
+ // create main box
+ dom.box = document.createElement('DIV');
+
+ // contents box (inside the background box). used for making margins
+ dom.content = document.createElement('DIV');
+ dom.content.className = 'vis-item-content';
+ dom.box.appendChild(dom.content);
+
+ // line to axis
+ dom.line = document.createElement('DIV');
+ dom.line.className = 'vis-line';
+
+ // dot on axis
+ dom.dot = document.createElement('DIV');
+ dom.dot.className = 'vis-dot';
+
+ // attach this item as attribute
+ dom.box['timeline-item'] = this;
+
+ this.dirty = true;
+ }
+
+ // append DOM to parent DOM
+ if (!this.parent) {
+ throw new Error('Cannot redraw item: no parent attached');
+ }
+ if (!dom.box.parentNode) {
+ var foreground = this.parent.dom.foreground;
+ if (!foreground) throw new Error('Cannot redraw item: parent has no foreground container element');
+ foreground.appendChild(dom.box);
+ }
+ if (!dom.line.parentNode) {
+ var background = this.parent.dom.background;
+ if (!background) throw new Error('Cannot redraw item: parent has no background container element');
+ background.appendChild(dom.line);
+ }
+ if (!dom.dot.parentNode) {
+ var axis = this.parent.dom.axis;
+ if (!background) throw new Error('Cannot redraw item: parent has no axis container element');
+ axis.appendChild(dom.dot);
+ }
+ this.displayed = true;
+
+ // Update DOM when item is marked dirty. An item is marked dirty when:
+ // - the item is not yet rendered
+ // - the item's data is changed
+ // - the item is selected/deselected
+ if (this.dirty) {
+ this._updateContents(this.dom.content);
+ this._updateTitle(this.dom.box);
+ this._updateDataAttributes(this.dom.box);
+ this._updateStyle(this.dom.box);
+
+ // update class
+ var className = (this.data.className ? ' ' + this.data.className : '') + (this.selected ? ' vis-selected' : '');
+ dom.box.className = 'vis-item vis-box' + className;
+ dom.line.className = 'vis-item vis-line' + className;
+ dom.dot.className = 'vis-item vis-dot' + className;
+
+ // recalculate size
+ this.props.dot.height = dom.dot.offsetHeight;
+ this.props.dot.width = dom.dot.offsetWidth;
+ this.props.line.width = dom.line.offsetWidth;
+ this.width = dom.box.offsetWidth;
+ this.height = dom.box.offsetHeight;
+
+ this.dirty = false;
+ }
+
+ this._repaintDeleteButton(dom.box);
+ };
+
+ /**
+ * Show the item in the DOM (when not already displayed). The items DOM will
+ * be created when needed.
+ */
+ BoxItem.prototype.show = function () {
+ if (!this.displayed) {
+ this.redraw();
+ }
+ };
+
+ /**
+ * Hide the item from the DOM (when visible)
+ */
+ BoxItem.prototype.hide = function () {
+ if (this.displayed) {
+ var dom = this.dom;
+
+ if (dom.box.parentNode) dom.box.parentNode.removeChild(dom.box);
+ if (dom.line.parentNode) dom.line.parentNode.removeChild(dom.line);
+ if (dom.dot.parentNode) dom.dot.parentNode.removeChild(dom.dot);
+
+ this.displayed = false;
+ }
+ };
+
+ /**
+ * Reposition the item horizontally
+ * @Override
+ */
+ BoxItem.prototype.repositionX = function () {
+ var start = this.conversion.toScreen(this.data.start);
+ var align = this.options.align;
+ var left;
+
+ // calculate left position of the box
+ if (align == 'right') {
+ this.left = start - this.width;
+ } else if (align == 'left') {
+ this.left = start;
+ } else {
+ // default or 'center'
+ this.left = start - this.width / 2;
+ }
+
+ // reposition box
+ this.dom.box.style.left = this.left + 'px';
+
+ // reposition line
+ this.dom.line.style.left = start - this.props.line.width / 2 + 'px';
+
+ // reposition dot
+ this.dom.dot.style.left = start - this.props.dot.width / 2 + 'px';
+ };
+
+ /**
+ * Reposition the item vertically
+ * @Override
+ */
+ BoxItem.prototype.repositionY = function () {
+ var orientation = this.options.orientation.item;
+ var box = this.dom.box;
+ var line = this.dom.line;
+ var dot = this.dom.dot;
+
+ if (orientation == 'top') {
+ box.style.top = (this.top || 0) + 'px';
+
+ line.style.top = '0';
+ line.style.height = this.parent.top + this.top + 1 + 'px';
+ line.style.bottom = '';
+ } else {
+ // orientation 'bottom'
+ var itemSetHeight = this.parent.itemSet.props.height; // TODO: this is nasty
+ var lineHeight = itemSetHeight - this.parent.top - this.parent.height + this.top;
+
+ box.style.top = (this.parent.height - this.top - this.height || 0) + 'px';
+ line.style.top = itemSetHeight - lineHeight + 'px';
+ line.style.bottom = '0';
+ }
+
+ dot.style.top = -this.props.dot.height / 2 + 'px';
+ };
+
+ module.exports = BoxItem;
+
+/***/ },
+/* 4 */
+/***/ function(module, exports, __webpack_require__) {
+
+ 'use strict';
+
+ var Hammer = __webpack_require__(5);
+ var util = __webpack_require__(9);
+
+ /**
+ * @constructor Item
+ * @param {Object} data Object containing (optional) parameters type,
+ * start, end, content, group, className.
+ * @param {{toScreen: function, toTime: function}} conversion
+ * Conversion functions from time to screen and vice versa
+ * @param {Object} options Configuration options
+ * // TODO: describe available options
+ */
+ function Item(data, conversion, options) {
+ this.id = null;
+ this.parent = null;
+ this.data = data;
+ this.dom = null;
+ this.conversion = conversion || {};
+ this.options = options || {};
+
+ this.selected = false;
+ this.displayed = false;
+ this.dirty = true;
+
+ this.top = null;
+ this.left = null;
+ this.width = null;
+ this.height = null;
+ }
+
+ Item.prototype.stack = true;
+
+ /**
+ * Select current item
+ */
+ Item.prototype.select = function () {
+ this.selected = true;
+ this.dirty = true;
+ if (this.displayed) this.redraw();
+ };
+
+ /**
+ * Unselect current item
+ */
+ Item.prototype.unselect = function () {
+ this.selected = false;
+ this.dirty = true;
+ if (this.displayed) this.redraw();
+ };
+
+ /**
+ * Set data for the item. Existing data will be updated. The id should not
+ * be changed. When the item is displayed, it will be redrawn immediately.
+ * @param {Object} data
+ */
+ Item.prototype.setData = function (data) {
+ var groupChanged = data.group != undefined && this.data.group != data.group;
+ if (groupChanged) {
+ this.parent.itemSet._moveToGroup(this, data.group);
+ }
+
+ this.data = data;
+ this.dirty = true;
+ if (this.displayed) this.redraw();
+ };
+
+ /**
+ * Set a parent for the item
+ * @param {ItemSet | Group} parent
+ */
+ Item.prototype.setParent = function (parent) {
+ if (this.displayed) {
+ this.hide();
+ this.parent = parent;
+ if (this.parent) {
+ this.show();
+ }
+ } else {
+ this.parent = parent;
+ }
+ };
+
+ /**
+ * Check whether this item is visible inside given range
+ * @returns {{start: Number, end: Number}} range with a timestamp for start and end
+ * @returns {boolean} True if visible
+ */
+ Item.prototype.isVisible = function (range) {
+ // Should be implemented by Item implementations
+ return false;
+ };
+
+ /**
+ * Show the Item in the DOM (when not already visible)
+ * @return {Boolean} changed
+ */
+ Item.prototype.show = function () {
+ return false;
+ };
+
+ /**
+ * Hide the Item from the DOM (when visible)
+ * @return {Boolean} changed
+ */
+ Item.prototype.hide = function () {
+ return false;
+ };
+
+ /**
+ * Repaint the item
+ */
+ Item.prototype.redraw = function () {};
+
+ /**
+ * Reposition the Item horizontally
+ */
+ Item.prototype.repositionX = function () {};
+
+ /**
+ * Reposition the Item vertically
+ */
+ Item.prototype.repositionY = function () {};
+
+ /**
+ * Repaint a delete button on the top right of the item when the item is selected
+ * @param {HTMLElement} anchor
+ * @protected
+ */
+ Item.prototype._repaintDeleteButton = function (anchor) {
+ if (this.selected && this.options.editable.remove && !this.dom.deleteButton) {
+ // create and show button
+ var me = this;
+
+ var deleteButton = document.createElement('div');
+ deleteButton.className = 'vis-delete';
+ deleteButton.title = 'Delete this item';
+
+ // TODO: be able to destroy the delete button
new Hammer(deleteButton).on('tap', function (event) {
me.parent.removeFromDataSet(me);
event.stopPropagation();
@@ -16372,7 +16575,7 @@ return /******/ (function(modules) { // webpackBootstrap
var Component = __webpack_require__(28);
var Group = __webpack_require__(35);
var BackgroundGroup = __webpack_require__(39);
- var BoxItem = __webpack_require__(2);
+ var BoxItem = __webpack_require__(3);
var PointItem = __webpack_require__(40);
var RangeItem = __webpack_require__(37);
var BackgroundItem = __webpack_require__(41);
@@ -20965,10 +21168,10 @@ return /******/ (function(modules) { // webpackBootstrap
this.eventParams = {}; // stores state parameters while dragging the bar
+ this.setOptions(options);
+
// create the DOM
this._create();
-
- this.setOptions(options);
}
CustomTime.prototype = new Component();
@@ -20994,7 +21197,7 @@ return /******/ (function(modules) { // webpackBootstrap
CustomTime.prototype._create = function () {
var bar = document.createElement('div');
bar['custom-time'] = this;
- bar.className = 'vis-custom-time';
+ bar.className = 'vis-custom-time ' + (this.options.id || '');
bar.style.position = 'absolute';
bar.style.top = '0px';
bar.style.height = '100%';
@@ -21527,7 +21730,9 @@ return /******/ (function(modules) { // webpackBootstrap
range.step = step;
if (value !== undefined) {
- if (value * 0.1 < min) {
+ if (value < 0 && value * 2 < min) {
+ range.min = value * 2;
+ } else if (value * 0.1 < min) {
range.min = value / 10;
}
if (value * 2 > max && max !== 1) {
@@ -22854,4112 +23059,3513 @@ return /******/ (function(modules) { // webpackBootstrap
start: { date: date, number: number, string: string, moment: moment },
template: { fn: fn },
timeAxis: {
- scale: { string: string, undef: undef },
- step: { number: number, undef: undef },
- __type__: { object: object }
- },
- type: { string: string },
- width: { string: string, number: number },
- zoomable: { boolean: boolean },
- zoomMax: { number: number },
- zoomMin: { number: number },
-
- __type__: { object: object }
- };
-
- var configureOptions = {
- global: {
- align: ['center', 'left', 'right'],
- autoResize: true,
- clickToUse: false,
- // dataAttributes: ['all'], // FIXME: can be 'all' or string[]
- editable: {
- add: false,
- remove: false,
- updateGroup: false,
- updateTime: false
- },
- end: '',
- format: {
- minorLabels: {
- millisecond: 'SSS',
- second: 's',
- minute: 'HH:mm',
- hour: 'HH:mm',
- weekday: 'ddd D',
- day: 'D',
- month: 'MMM',
- year: 'YYYY'
- },
- majorLabels: {
- millisecond: 'HH:mm:ss',
- second: 'D MMMM HH:mm',
- minute: 'ddd D MMMM',
- hour: 'ddd D MMMM',
- weekday: 'MMMM YYYY',
- day: 'MMMM YYYY',
- month: 'YYYY',
- year: ''
- }
- },
-
- //groupOrder: {string, fn},
- height: '',
- //hiddenDates: {object, array},
- locale: '',
- margin: {
- axis: [20, 0, 100, 1],
- item: {
- horizontal: [10, 0, 100, 1],
- vertical: [10, 0, 100, 1]
- }
- },
- max: '',
- maxHeight: '',
- min: '',
- minHeight: '',
- moveable: false,
- multiselect: false,
- //onAdd: {fn},
- //onUpdate: {fn},
- //onMove: {fn},
- //onMoving: {fn},
- //onRename: {fn},
- //order: {fn},
- orientation: {
- axis: ['both', 'bottom', 'top'],
- item: ['bottom', 'top']
- },
- selectable: true,
- showCurrentTime: false,
- showMajorLabels: true,
- showMinorLabels: true,
- stack: true,
- //snap: {fn, nada},
- start: '',
- //template: {fn},
- //timeAxis: {
- // scale: ['millisecond', 'second', 'minute', 'hour', 'weekday', 'day', 'month', 'year'],
- // step: [1, 1, 10, 1]
- //},
- type: ['box', 'point', 'range', 'background'],
- width: '100%',
- zoomable: true,
- zoomMax: [315360000000000, 10, 315360000000000, 1],
- zoomMin: [10, 10, 315360000000000, 1]
- }
- };
-
- exports.allOptions = allOptions;
- exports.configureOptions = configureOptions;
-
-/***/ },
-/* 50 */
-/***/ function(module, exports, __webpack_require__) {
-
- 'use strict';
-
- var Emitter = __webpack_require__(20);
- var Hammer = __webpack_require__(5);
- var util = __webpack_require__(9);
- var DataSet = __webpack_require__(15);
- var DataView = __webpack_require__(17);
- var Range = __webpack_require__(30);
- var Core = __webpack_require__(33);
- var TimeAxis = __webpack_require__(42);
- var CurrentTime = __webpack_require__(27);
- var CustomTime = __webpack_require__(45);
- var LineGraph = __webpack_require__(51);
-
- var Configurator = __webpack_require__(46);
- var Validator = __webpack_require__(48)['default'];
- var printStyle = __webpack_require__(48).printStyle;
- var allOptions = __webpack_require__(59).allOptions;
- var configureOptions = __webpack_require__(59).configureOptions;
-
- /**
- * Create a timeline visualization
- * @param {HTMLElement} container
- * @param {vis.DataSet | Array} [items]
- * @param {Object} [options] See Graph2d.setOptions for the available options.
- * @constructor
- * @extends Core
- */
- function Graph2d(container, items, groups, options) {
- // if the third element is options, the forth is groups (optionally);
- if (!(Array.isArray(groups) || groups instanceof DataSet) && groups instanceof Object) {
- var forthArgument = options;
- options = groups;
- groups = forthArgument;
- }
-
- var me = this;
- this.defaultOptions = {
- start: null,
- end: null,
-
- autoResize: true,
-
- orientation: {
- axis: 'bottom', // axis orientation: 'bottom', 'top', or 'both'
- item: 'bottom' // not relevant for Graph2d
- },
-
- width: null,
- height: null,
- maxHeight: null,
- minHeight: null
- };
- this.options = util.deepExtend({}, this.defaultOptions);
-
- // Create the DOM, props, and emitter
- this._create(container);
-
- // all components listed here will be repainted automatically
- this.components = [];
-
- this.body = {
- dom: this.dom,
- domProps: this.props,
- emitter: {
- on: this.on.bind(this),
- off: this.off.bind(this),
- emit: this.emit.bind(this)
- },
- hiddenDates: [],
- util: {
- toScreen: me._toScreen.bind(me),
- toGlobalScreen: me._toGlobalScreen.bind(me), // this refers to the root.width
- toTime: me._toTime.bind(me),
- toGlobalTime: me._toGlobalTime.bind(me)
- }
- };
-
- // range
- this.range = new Range(this.body);
- this.components.push(this.range);
- this.body.range = this.range;
-
- // time axis
- this.timeAxis = new TimeAxis(this.body);
- this.components.push(this.timeAxis);
- //this.body.util.snap = this.timeAxis.snap.bind(this.timeAxis);
-
- // current time bar
- this.currentTime = new CurrentTime(this.body);
- this.components.push(this.currentTime);
-
- // item set
- this.linegraph = new LineGraph(this.body);
- this.components.push(this.linegraph);
-
- this.itemsData = null; // DataSet
- this.groupsData = null; // DataSet
-
- this.on('tap', function (event) {
- me.emit('click', me.getEventProperties(event));
- });
- this.on('doubletap', function (event) {
- me.emit('doubleClick', me.getEventProperties(event));
- });
- this.dom.root.oncontextmenu = function (event) {
- me.emit('contextmenu', me.getEventProperties(event));
- };
-
- // setup configuration system
- this.configurator = new Configurator(this, container, configureOptions);
-
- // apply options
- if (options) {
- this.setOptions(options);
- }
-
- // IMPORTANT: THIS HAPPENS BEFORE SET ITEMS!
- if (groups) {
- this.setGroups(groups);
- }
-
- // create itemset
- if (items) {
- this.setItems(items);
- } else {
- this._redraw();
- }
- }
-
- // Extend the functionality from Core
- Graph2d.prototype = new Core();
-
- Graph2d.prototype.setOptions = function (options) {
- // validate options
- var errorFound = Validator.validate(options, allOptions);
- if (errorFound === true) {
- console.log('%cErrors have been found in the supplied options object.', printStyle);
- }
-
- Core.prototype.setOptions.call(this, options);
- };
-
- /**
- * Set items
- * @param {vis.DataSet | Array | null} items
- */
- Graph2d.prototype.setItems = function (items) {
- var initialLoad = this.itemsData == null;
-
- // convert to type DataSet when needed
- var newDataSet;
- if (!items) {
- newDataSet = null;
- } else if (items instanceof DataSet || items instanceof DataView) {
- newDataSet = items;
- } else {
- // turn an array into a dataset
- newDataSet = new DataSet(items, {
- type: {
- start: 'Date',
- end: 'Date'
- }
- });
- }
-
- // set items
- this.itemsData = newDataSet;
- this.linegraph && this.linegraph.setItems(newDataSet);
-
- if (initialLoad) {
- if (this.options.start != undefined || this.options.end != undefined) {
- var start = this.options.start != undefined ? this.options.start : null;
- var end = this.options.end != undefined ? this.options.end : null;
-
- this.setWindow(start, end, { animation: false });
- } else {
- this.fit({ animation: false });
- }
- }
- };
-
- /**
- * Set groups
- * @param {vis.DataSet | Array} groups
- */
- Graph2d.prototype.setGroups = function (groups) {
- // convert to type DataSet when needed
- var newDataSet;
- if (!groups) {
- newDataSet = null;
- } else if (groups instanceof DataSet || groups instanceof DataView) {
- newDataSet = groups;
- } else {
- // turn an array into a dataset
- newDataSet = new DataSet(groups);
- }
-
- this.groupsData = newDataSet;
- this.linegraph.setGroups(newDataSet);
- };
-
- /**
- * Returns an object containing an SVG element with the icon of the group (size determined by iconWidth and iconHeight), the label of the group (content) and the yAxisOrientation of the group (left or right).
- * @param groupId
- * @param width
- * @param height
- */
- Graph2d.prototype.getLegend = function (groupId, width, height) {
- if (width === undefined) {
- width = 15;
- }
- if (height === undefined) {
- height = 15;
- }
- if (this.linegraph.groups[groupId] !== undefined) {
- return this.linegraph.groups[groupId].getLegend(width, height);
- } else {
- return 'cannot find group:' + groupId;
- }
- };
-
- /**
- * This checks if the visible option of the supplied group (by ID) is true or false.
- * @param groupId
- * @returns {*}
- */
- Graph2d.prototype.isGroupVisible = function (groupId) {
- if (this.linegraph.groups[groupId] !== undefined) {
- return this.linegraph.groups[groupId].visible && (this.linegraph.options.groups.visibility[groupId] === undefined || this.linegraph.options.groups.visibility[groupId] == true);
- } else {
- return false;
- }
- };
-
- /**
- * Get the data range of the item set.
- * @returns {{min: Date, max: Date}} range A range with a start and end Date.
- * When no minimum is found, min==null
- * When no maximum is found, max==null
- */
- Graph2d.prototype.getItemRange = function () {
- var min = null;
- var max = null;
-
- // calculate min from start filed
- for (var groupId in this.linegraph.groups) {
- if (this.linegraph.groups.hasOwnProperty(groupId)) {
- if (this.linegraph.groups[groupId].visible == true) {
- for (var i = 0; i < this.linegraph.groups[groupId].itemsData.length; i++) {
- var item = this.linegraph.groups[groupId].itemsData[i];
- var value = util.convert(item.x, 'Date').valueOf();
- min = min == null ? value : min > value ? value : min;
- max = max == null ? value : max < value ? value : max;
- }
- }
- }
- }
-
- return {
- min: min != null ? new Date(min) : null,
- max: max != null ? new Date(max) : null
- };
- };
-
- /**
- * Generate Timeline related information from an event
- * @param {Event} event
- * @return {Object} An object with related information, like on which area
- * The event happened, whether clicked on an item, etc.
- */
- Graph2d.prototype.getEventProperties = function (event) {
- var clientX = event.center ? event.center.x : event.clientX;
- var clientY = event.center ? event.center.y : event.clientY;
- var x = clientX - util.getAbsoluteLeft(this.dom.centerContainer);
- var y = clientY - util.getAbsoluteTop(this.dom.centerContainer);
- var time = this._toTime(x);
-
- var customTime = CustomTime.customTimeFromTarget(event);
-
- var element = util.getTarget(event);
- var what = null;
- if (util.hasParent(element, this.timeAxis.dom.foreground)) {
- what = 'axis';
- } else if (this.timeAxis2 && util.hasParent(element, this.timeAxis2.dom.foreground)) {
- what = 'axis';
- } else if (util.hasParent(element, this.linegraph.yAxisLeft.dom.frame)) {
- what = 'data-axis';
- } else if (util.hasParent(element, this.linegraph.yAxisRight.dom.frame)) {
- what = 'data-axis';
- } else if (util.hasParent(element, this.linegraph.legendLeft.dom.frame)) {
- what = 'legend';
- } else if (util.hasParent(element, this.linegraph.legendRight.dom.frame)) {
- what = 'legend';
- } else if (customTime != null) {
- what = 'custom-time';
- } else if (util.hasParent(element, this.currentTime.bar)) {
- what = 'current-time';
- } else if (util.hasParent(element, this.dom.center)) {
- what = 'background';
- }
-
- var value = [];
- var yAxisLeft = this.linegraph.yAxisLeft;
- var yAxisRight = this.linegraph.yAxisRight;
- if (!yAxisLeft.hidden) {
- value.push(yAxisLeft.screenToValue(y));
- }
- if (!yAxisRight.hidden) {
- value.push(yAxisRight.screenToValue(y));
- }
-
- return {
- event: event,
- what: what,
- pageX: event.srcEvent ? event.srcEvent.pageX : event.pageX,
- pageY: event.srcEvent ? event.srcEvent.pageY : event.pageY,
- x: x,
- y: y,
- time: time,
- value: value
- };
- };
-
- module.exports = Graph2d;
-
-/***/ },
-/* 51 */
-/***/ function(module, exports, __webpack_require__) {
-
- 'use strict';
-
- var util = __webpack_require__(9);
- var DOMutil = __webpack_require__(14);
- var DataSet = __webpack_require__(15);
- var DataView = __webpack_require__(17);
- var Component = __webpack_require__(28);
- var DataAxis = __webpack_require__(52);
- var GraphGroup = __webpack_require__(54);
- var Legend = __webpack_require__(58);
- var BarFunctions = __webpack_require__(57);
- var LineFunctions = __webpack_require__(55);
-
- var UNGROUPED = '__ungrouped__'; // reserved group id for ungrouped items
-
- /**
- * This is the constructor of the LineGraph. It requires a Timeline body and options.
- *
- * @param body
- * @param options
- * @constructor
- */
- function LineGraph(body, options) {
- this.id = util.randomUUID();
- this.body = body;
-
- this.defaultOptions = {
- yAxisOrientation: 'left',
- defaultGroup: 'default',
- sort: true,
- sampling: true,
- stack: false,
- graphHeight: '400px',
- shaded: {
- enabled: false,
- orientation: 'bottom' // top, bottom
- },
- style: 'line', // line, bar
- barChart: {
- width: 50,
- sideBySide: false,
- align: 'center' // left, center, right
- },
- interpolation: {
- enabled: true,
- parametrization: 'centripetal', // uniform (alpha = 0.0), chordal (alpha = 1.0), centripetal (alpha = 0.5)
- alpha: 0.5
- },
- drawPoints: {
- enabled: true,
- size: 6,
- style: 'square' // square, circle
- },
- dataAxis: {
- showMinorLabels: true,
- showMajorLabels: true,
- icons: false,
- width: '40px',
- visible: true,
- alignZeros: true,
- left: {
- range: { min: undefined, max: undefined },
- format: function format(value) {
- return value;
- },
- title: { text: undefined, style: undefined }
- },
- right: {
- range: { min: undefined, max: undefined },
- format: function format(value) {
- return value;
- },
- title: { text: undefined, style: undefined }
- }
- },
- legend: {
- enabled: false,
- icons: true,
- left: {
- visible: true,
- position: 'top-left' // top/bottom - left,right
- },
- right: {
- visible: true,
- position: 'top-right' // top/bottom - left,right
- }
- },
- groups: {
- visibility: {}
- }
- };
-
- // options is shared by this ItemSet and all its items
- this.options = util.extend({}, this.defaultOptions);
- this.dom = {};
- this.props = {};
- this.hammer = null;
- this.groups = {};
- this.abortedGraphUpdate = false;
- this.updateSVGheight = false;
- this.updateSVGheightOnResize = false;
-
- var me = this;
- this.itemsData = null; // DataSet
- this.groupsData = null; // DataSet
-
- // listeners for the DataSet of the items
- this.itemListeners = {
- 'add': function add(event, params, senderId) {
- me._onAdd(params.items);
- },
- 'update': function update(event, params, senderId) {
- me._onUpdate(params.items);
- },
- 'remove': function remove(event, params, senderId) {
- me._onRemove(params.items);
- }
- };
-
- // listeners for the DataSet of the groups
- this.groupListeners = {
- 'add': function add(event, params, senderId) {
- me._onAddGroups(params.items);
- },
- 'update': function update(event, params, senderId) {
- me._onUpdateGroups(params.items);
- },
- 'remove': function remove(event, params, senderId) {
- me._onRemoveGroups(params.items);
- }
- };
-
- this.items = {}; // object with an Item for every data item
- this.selection = []; // list with the ids of all selected nodes
- this.lastStart = this.body.range.start;
- this.touchParams = {}; // stores properties while dragging
-
- this.svgElements = {};
- this.setOptions(options);
- this.groupsUsingDefaultStyles = [0];
- this.COUNTER = 0;
- this.body.emitter.on('rangechanged', function () {
- me.lastStart = me.body.range.start;
- me.svg.style.left = util.option.asSize(-me.props.width);
- me.redraw.call(me, true);
- });
-
- // create the HTML DOM
- this._create();
- this.framework = { svg: this.svg, svgElements: this.svgElements, options: this.options, groups: this.groups };
- this.body.emitter.emit('change');
- }
-
- LineGraph.prototype = new Component();
-
- /**
- * Create the HTML DOM for the ItemSet
- */
- LineGraph.prototype._create = function () {
- var frame = document.createElement('div');
- frame.className = 'vis-line-graph';
- this.dom.frame = frame;
-
- // create svg element for graph drawing.
- this.svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
- this.svg.style.position = 'relative';
- this.svg.style.height = ('' + this.options.graphHeight).replace('px', '') + 'px';
- this.svg.style.display = 'block';
- frame.appendChild(this.svg);
-
- // data axis
- this.options.dataAxis.orientation = 'left';
- this.yAxisLeft = new DataAxis(this.body, this.options.dataAxis, this.svg, this.options.groups);
-
- this.options.dataAxis.orientation = 'right';
- this.yAxisRight = new DataAxis(this.body, this.options.dataAxis, this.svg, this.options.groups);
- delete this.options.dataAxis.orientation;
-
- // legends
- this.legendLeft = new Legend(this.body, this.options.legend, 'left', this.options.groups);
- this.legendRight = new Legend(this.body, this.options.legend, 'right', this.options.groups);
-
- this.show();
- };
-
- /**
- * set the options of the LineGraph. the mergeOptions is used for subObjects that have an enabled element.
- * @param {object} options
- */
- LineGraph.prototype.setOptions = function (options) {
- if (options) {
- var fields = ['sampling', 'defaultGroup', 'stack', 'height', 'graphHeight', 'yAxisOrientation', 'style', 'barChart', 'dataAxis', 'sort', 'groups'];
- if (options.graphHeight === undefined && options.height !== undefined && this.body.domProps.centerContainer.height !== undefined) {
- this.updateSVGheight = true;
- this.updateSVGheightOnResize = true;
- } else if (this.body.domProps.centerContainer.height !== undefined && options.graphHeight !== undefined) {
- if (parseInt((options.graphHeight + '').replace('px', '')) < this.body.domProps.centerContainer.height) {
- this.updateSVGheight = true;
- }
- }
- util.selectiveDeepExtend(fields, this.options, options);
- util.mergeOptions(this.options, options, 'interpolation');
- util.mergeOptions(this.options, options, 'drawPoints');
- util.mergeOptions(this.options, options, 'shaded');
- util.mergeOptions(this.options, options, 'legend');
-
- if (options.interpolation) {
- if (typeof options.interpolation == 'object') {
- if (options.interpolation.parametrization) {
- if (options.interpolation.parametrization == 'uniform') {
- this.options.interpolation.alpha = 0;
- } else if (options.interpolation.parametrization == 'chordal') {
- this.options.interpolation.alpha = 1;
- } else {
- this.options.interpolation.parametrization = 'centripetal';
- this.options.interpolation.alpha = 0.5;
- }
- }
- }
- }
-
- if (this.yAxisLeft) {
- if (options.dataAxis !== undefined) {
- this.yAxisLeft.setOptions(this.options.dataAxis);
- this.yAxisRight.setOptions(this.options.dataAxis);
- }
- }
-
- if (this.legendLeft) {
- if (options.legend !== undefined) {
- this.legendLeft.setOptions(this.options.legend);
- this.legendRight.setOptions(this.options.legend);
- }
- }
-
- if (this.groups.hasOwnProperty(UNGROUPED)) {
- this.groups[UNGROUPED].setOptions(options);
- }
- }
-
- // this is used to redraw the graph if the visibility of the groups is changed.
- if (this.dom.frame) {
- this.redraw(true);
- }
- };
-
- /**
- * Hide the component from the DOM
- */
- LineGraph.prototype.hide = function () {
- // remove the frame containing the items
- if (this.dom.frame.parentNode) {
- this.dom.frame.parentNode.removeChild(this.dom.frame);
- }
- };
-
- /**
- * Show the component in the DOM (when not already visible).
- * @return {Boolean} changed
- */
- LineGraph.prototype.show = function () {
- // show frame containing the items
- if (!this.dom.frame.parentNode) {
- this.body.dom.center.appendChild(this.dom.frame);
- }
- };
-
- /**
- * Set items
- * @param {vis.DataSet | null} items
- */
- LineGraph.prototype.setItems = function (items) {
- var me = this,
- ids,
- oldItemsData = this.itemsData;
-
- // replace the dataset
- if (!items) {
- this.itemsData = null;
- } else if (items instanceof DataSet || items instanceof DataView) {
- this.itemsData = items;
- } else {
- throw new TypeError('Data must be an instance of DataSet or DataView');
- }
-
- if (oldItemsData) {
- // unsubscribe from old dataset
- util.forEach(this.itemListeners, function (callback, event) {
- oldItemsData.off(event, callback);
- });
-
- // remove all drawn items
- ids = oldItemsData.getIds();
- this._onRemove(ids);
- }
-
- if (this.itemsData) {
- // subscribe to new dataset
- var id = this.id;
- util.forEach(this.itemListeners, function (callback, event) {
- me.itemsData.on(event, callback, id);
- });
-
- // add all new items
- ids = this.itemsData.getIds();
- this._onAdd(ids);
- }
- this._updateUngrouped();
- //this._updateGraph();
- this.redraw(true);
- };
-
- /**
- * Set groups
- * @param {vis.DataSet} groups
- */
- LineGraph.prototype.setGroups = function (groups) {
- var me = this;
- var ids;
-
- // unsubscribe from current dataset
- if (this.groupsData) {
- util.forEach(this.groupListeners, function (callback, event) {
- me.groupsData.off(event, callback);
- });
-
- // remove all drawn groups
- ids = this.groupsData.getIds();
- this.groupsData = null;
- this._onRemoveGroups(ids); // note: this will cause a redraw
- }
-
- // replace the dataset
- if (!groups) {
- this.groupsData = null;
- } else if (groups instanceof DataSet || groups instanceof DataView) {
- this.groupsData = groups;
- } else {
- throw new TypeError('Data must be an instance of DataSet or DataView');
- }
-
- if (this.groupsData) {
- // subscribe to new dataset
- var id = this.id;
- util.forEach(this.groupListeners, function (callback, event) {
- me.groupsData.on(event, callback, id);
- });
-
- // draw all ms
- ids = this.groupsData.getIds();
- this._onAddGroups(ids);
- }
- this._onUpdate();
- };
-
- /**
- * Update the data
- * @param [ids]
- * @private
- */
- LineGraph.prototype._onUpdate = function (ids) {
- this._updateUngrouped();
- this._updateAllGroupData();
- //this._updateGraph();
- this.redraw(true);
- };
- LineGraph.prototype._onAdd = function (ids) {
- this._onUpdate(ids);
- };
- LineGraph.prototype._onRemove = function (ids) {
- this._onUpdate(ids);
- };
- LineGraph.prototype._onUpdateGroups = function (groupIds) {
- for (var i = 0; i < groupIds.length; i++) {
- var group = this.groupsData.get(groupIds[i]);
- this._updateGroup(group, groupIds[i]);
- }
-
- //this._updateGraph();
- this.redraw(true);
- };
- LineGraph.prototype._onAddGroups = function (groupIds) {
- this._onUpdateGroups(groupIds);
- };
-
- /**
- * this cleans the group out off the legends and the dataaxis, updates the ungrouped and updates the graph
- * @param {Array} groupIds
- * @private
- */
- LineGraph.prototype._onRemoveGroups = function (groupIds) {
- for (var i = 0; i < groupIds.length; i++) {
- if (this.groups.hasOwnProperty(groupIds[i])) {
- if (this.groups[groupIds[i]].options.yAxisOrientation == 'right') {
- this.yAxisRight.removeGroup(groupIds[i]);
- this.legendRight.removeGroup(groupIds[i]);
- this.legendRight.redraw();
- } else {
- this.yAxisLeft.removeGroup(groupIds[i]);
- this.legendLeft.removeGroup(groupIds[i]);
- this.legendLeft.redraw();
- }
- delete this.groups[groupIds[i]];
- }
- }
- this._updateUngrouped();
- //this._updateGraph();
- this.redraw(true);
- };
-
- /**
- * update a group object with the group dataset entree
- *
- * @param group
- * @param groupId
- * @private
- */
- LineGraph.prototype._updateGroup = function (group, groupId) {
- if (!this.groups.hasOwnProperty(groupId)) {
- this.groups[groupId] = new GraphGroup(group, groupId, this.options, this.groupsUsingDefaultStyles);
- if (this.groups[groupId].options.yAxisOrientation == 'right') {
- this.yAxisRight.addGroup(groupId, this.groups[groupId]);
- this.legendRight.addGroup(groupId, this.groups[groupId]);
- } else {
- this.yAxisLeft.addGroup(groupId, this.groups[groupId]);
- this.legendLeft.addGroup(groupId, this.groups[groupId]);
- }
- } else {
- this.groups[groupId].update(group);
- if (this.groups[groupId].options.yAxisOrientation == 'right') {
- this.yAxisRight.updateGroup(groupId, this.groups[groupId]);
- this.legendRight.updateGroup(groupId, this.groups[groupId]);
- } else {
- this.yAxisLeft.updateGroup(groupId, this.groups[groupId]);
- this.legendLeft.updateGroup(groupId, this.groups[groupId]);
- }
- }
- this.legendLeft.redraw();
- this.legendRight.redraw();
+ scale: { string: string, undef: undef },
+ step: { number: number, undef: undef },
+ __type__: { object: object }
+ },
+ type: { string: string },
+ width: { string: string, number: number },
+ zoomable: { boolean: boolean },
+ zoomMax: { number: number },
+ zoomMin: { number: number },
+
+ __type__: { object: object }
};
- /**
- * this updates all groups, it is used when there is an update the the itemset.
- *
- * @private
- */
- LineGraph.prototype._updateAllGroupData = function () {
- if (this.itemsData != null) {
- var groupsContent = {};
- var groupId;
- for (groupId in this.groups) {
- if (this.groups.hasOwnProperty(groupId)) {
- groupsContent[groupId] = [];
- }
- }
- for (var itemId in this.itemsData._data) {
- if (this.itemsData._data.hasOwnProperty(itemId)) {
- var item = this.itemsData._data[itemId];
- if (groupsContent[item.group] === undefined) {
- throw new Error('Cannot find referenced group. Possible reason: items added before groups? Groups need to be added before items, as items refer to groups.');
- }
- item.x = util.convert(item.x, 'Date');
- groupsContent[item.group].push(item);
+ var configureOptions = {
+ global: {
+ align: ['center', 'left', 'right'],
+ autoResize: true,
+ clickToUse: false,
+ // dataAttributes: ['all'], // FIXME: can be 'all' or string[]
+ editable: {
+ add: false,
+ remove: false,
+ updateGroup: false,
+ updateTime: false
+ },
+ end: '',
+ format: {
+ minorLabels: {
+ millisecond: 'SSS',
+ second: 's',
+ minute: 'HH:mm',
+ hour: 'HH:mm',
+ weekday: 'ddd D',
+ day: 'D',
+ month: 'MMM',
+ year: 'YYYY'
+ },
+ majorLabels: {
+ millisecond: 'HH:mm:ss',
+ second: 'D MMMM HH:mm',
+ minute: 'ddd D MMMM',
+ hour: 'ddd D MMMM',
+ weekday: 'MMMM YYYY',
+ day: 'MMMM YYYY',
+ month: 'YYYY',
+ year: ''
}
- }
- for (groupId in this.groups) {
- if (this.groups.hasOwnProperty(groupId)) {
- this.groups[groupId].setItems(groupsContent[groupId]);
+ },
+
+ //groupOrder: {string, fn},
+ height: '',
+ //hiddenDates: {object, array},
+ locale: '',
+ margin: {
+ axis: [20, 0, 100, 1],
+ item: {
+ horizontal: [10, 0, 100, 1],
+ vertical: [10, 0, 100, 1]
}
- }
+ },
+ max: '',
+ maxHeight: '',
+ min: '',
+ minHeight: '',
+ moveable: false,
+ multiselect: false,
+ //onAdd: {fn},
+ //onUpdate: {fn},
+ //onMove: {fn},
+ //onMoving: {fn},
+ //onRename: {fn},
+ //order: {fn},
+ orientation: {
+ axis: ['both', 'bottom', 'top'],
+ item: ['bottom', 'top']
+ },
+ selectable: true,
+ showCurrentTime: false,
+ showMajorLabels: true,
+ showMinorLabels: true,
+ stack: true,
+ //snap: {fn, nada},
+ start: '',
+ //template: {fn},
+ //timeAxis: {
+ // scale: ['millisecond', 'second', 'minute', 'hour', 'weekday', 'day', 'month', 'year'],
+ // step: [1, 1, 10, 1]
+ //},
+ type: ['box', 'point', 'range', 'background'],
+ width: '100%',
+ zoomable: true,
+ zoomMax: [315360000000000, 10, 315360000000000, 1],
+ zoomMin: [10, 10, 315360000000000, 1]
}
};
- /**
- * Create or delete the group holding all ungrouped items. This group is used when
- * there are no groups specified. This anonymous group is called 'graph'.
- * @protected
- */
- LineGraph.prototype._updateUngrouped = function () {
- if (this.itemsData && this.itemsData != null) {
- var ungroupedCounter = 0;
- for (var itemId in this.itemsData._data) {
- if (this.itemsData._data.hasOwnProperty(itemId)) {
- var item = this.itemsData._data[itemId];
- if (item != undefined) {
- if (item.hasOwnProperty('group')) {
- if (item.group === undefined) {
- item.group = UNGROUPED;
- }
- } else {
- item.group = UNGROUPED;
- }
- ungroupedCounter = item.group == UNGROUPED ? ungroupedCounter + 1 : ungroupedCounter;
- }
- }
- }
+ exports.allOptions = allOptions;
+ exports.configureOptions = configureOptions;
- if (ungroupedCounter == 0) {
- delete this.groups[UNGROUPED];
- this.legendLeft.removeGroup(UNGROUPED);
- this.legendRight.removeGroup(UNGROUPED);
- this.yAxisLeft.removeGroup(UNGROUPED);
- this.yAxisRight.removeGroup(UNGROUPED);
- } else {
- var group = { id: UNGROUPED, content: this.options.defaultGroup };
- this._updateGroup(group, UNGROUPED);
- }
- } else {
- delete this.groups[UNGROUPED];
- this.legendLeft.removeGroup(UNGROUPED);
- this.legendRight.removeGroup(UNGROUPED);
- this.yAxisLeft.removeGroup(UNGROUPED);
- this.yAxisRight.removeGroup(UNGROUPED);
- }
+/***/ },
+/* 50 */
+/***/ function(module, exports, __webpack_require__) {
- this.legendLeft.redraw();
- this.legendRight.redraw();
- };
+ 'use strict';
- /**
- * Redraw the component, mandatory function
- * @return {boolean} Returns true if the component is resized
- */
- LineGraph.prototype.redraw = function (forceGraphUpdate) {
- var resized = false;
+ var Emitter = __webpack_require__(20);
+ var Hammer = __webpack_require__(5);
+ var util = __webpack_require__(9);
+ var DataSet = __webpack_require__(15);
+ var DataView = __webpack_require__(17);
+ var Range = __webpack_require__(30);
+ var Core = __webpack_require__(33);
+ var TimeAxis = __webpack_require__(42);
+ var CurrentTime = __webpack_require__(27);
+ var CustomTime = __webpack_require__(45);
+ var LineGraph = __webpack_require__(51);
- // calculate actual size and position
- this.props.width = this.dom.frame.offsetWidth;
- this.props.height = this.body.domProps.centerContainer.height - this.body.domProps.border.top - this.body.domProps.border.bottom;
+ var Configurator = __webpack_require__(46);
+ var Validator = __webpack_require__(48)['default'];
+ var printStyle = __webpack_require__(48).printStyle;
+ var allOptions = __webpack_require__(59).allOptions;
+ var configureOptions = __webpack_require__(59).configureOptions;
- // update the graph if there is no lastWidth or with, used for the initial draw
- if (this.lastWidth === undefined && this.props.width) {
- forceGraphUpdate = true;
+ /**
+ * Create a timeline visualization
+ * @param {HTMLElement} container
+ * @param {vis.DataSet | Array} [items]
+ * @param {Object} [options] See Graph2d.setOptions for the available options.
+ * @constructor
+ * @extends Core
+ */
+ function Graph2d(container, items, groups, options) {
+ // if the third element is options, the forth is groups (optionally);
+ if (!(Array.isArray(groups) || groups instanceof DataSet) && groups instanceof Object) {
+ var forthArgument = options;
+ options = groups;
+ groups = forthArgument;
}
- // check if this component is resized
- resized = this._isResized() || resized;
-
- // check whether zoomed (in that case we need to re-stack everything)
- var visibleInterval = this.body.range.end - this.body.range.start;
- var zoomed = visibleInterval != this.lastVisibleInterval;
- this.lastVisibleInterval = visibleInterval;
-
- // the svg element is three times as big as the width, this allows for fully dragging left and right
- // without reloading the graph. the controls for this are bound to events in the constructor
- if (resized == true) {
- this.svg.style.width = util.option.asSize(3 * this.props.width);
- this.svg.style.left = util.option.asSize(-this.props.width);
+ var me = this;
+ this.defaultOptions = {
+ start: null,
+ end: null,
- // if the height of the graph is set as proportional, change the height of the svg
- if ((this.options.height + '').indexOf('%') != -1 || this.updateSVGheightOnResize == true) {
- this.updateSVGheight = true;
- }
- }
+ autoResize: true,
- // update the height of the graph on each redraw of the graph.
- if (this.updateSVGheight == true) {
- if (this.options.graphHeight != this.props.height + 'px') {
- this.options.graphHeight = this.props.height + 'px';
- this.svg.style.height = this.props.height + 'px';
- }
- this.updateSVGheight = false;
- } else {
- this.svg.style.height = ('' + this.options.graphHeight).replace('px', '') + 'px';
- }
+ orientation: {
+ axis: 'bottom', // axis orientation: 'bottom', 'top', or 'both'
+ item: 'bottom' // not relevant for Graph2d
+ },
- // zoomed is here to ensure that animations are shown correctly.
- if (resized == true || zoomed == true || this.abortedGraphUpdate == true || forceGraphUpdate == true) {
- resized = this._updateGraph() || resized;
- } else {
- // move the whole svg while dragging
- if (this.lastStart != 0) {
- var offset = this.body.range.start - this.lastStart;
- var range = this.body.range.end - this.body.range.start;
- if (this.props.width != 0) {
- var rangePerPixelInv = this.props.width / range;
- var xOffset = offset * rangePerPixelInv;
- this.svg.style.left = -this.props.width - xOffset + 'px';
- }
- }
- }
+ width: null,
+ height: null,
+ maxHeight: null,
+ minHeight: null
+ };
+ this.options = util.deepExtend({}, this.defaultOptions);
- this.legendLeft.redraw();
- this.legendRight.redraw();
- return resized;
- };
+ // Create the DOM, props, and emitter
+ this._create(container);
- /**
- * Update and redraw the graph.
- *
- */
- LineGraph.prototype._updateGraph = function () {
- // reset the svg elements
- DOMutil.prepareElements(this.svgElements);
- if (this.props.width != 0 && this.itemsData != null) {
- var group, i;
- var preprocessedGroupData = {};
- var processedGroupData = {};
- var groupRanges = {};
- var changeCalled = false;
+ // all components listed here will be repainted automatically
+ this.components = [];
- // getting group Ids
- var groupIds = [];
- for (var groupId in this.groups) {
- if (this.groups.hasOwnProperty(groupId)) {
- group = this.groups[groupId];
- if (group.visible == true && (this.options.groups.visibility[groupId] === undefined || this.options.groups.visibility[groupId] == true)) {
- groupIds.push(groupId);
- }
- }
+ this.body = {
+ dom: this.dom,
+ domProps: this.props,
+ emitter: {
+ on: this.on.bind(this),
+ off: this.off.bind(this),
+ emit: this.emit.bind(this)
+ },
+ hiddenDates: [],
+ util: {
+ toScreen: me._toScreen.bind(me),
+ toGlobalScreen: me._toGlobalScreen.bind(me), // this refers to the root.width
+ toTime: me._toTime.bind(me),
+ toGlobalTime: me._toGlobalTime.bind(me)
}
- if (groupIds.length > 0) {
- // this is the range of the SVG canvas
- var minDate = this.body.util.toGlobalTime(-this.body.domProps.root.width);
- var maxDate = this.body.util.toGlobalTime(2 * this.body.domProps.root.width);
- var groupsData = {};
- // fill groups data, this only loads the data we require based on the timewindow
- this._getRelevantData(groupIds, groupsData, minDate, maxDate);
+ };
- // apply sampling, if disabled, it will pass through this function.
- this._applySampling(groupIds, groupsData);
+ // range
+ this.range = new Range(this.body);
+ this.components.push(this.range);
+ this.body.range = this.range;
- // we transform the X coordinates to detect collisions
- for (i = 0; i < groupIds.length; i++) {
- preprocessedGroupData[groupIds[i]] = this._convertXcoordinates(groupsData[groupIds[i]]);
- }
+ // time axis
+ this.timeAxis = new TimeAxis(this.body);
+ this.components.push(this.timeAxis);
+ //this.body.util.snap = this.timeAxis.snap.bind(this.timeAxis);
- // now all needed data has been collected we start the processing.
- this._getYRanges(groupIds, preprocessedGroupData, groupRanges);
+ // current time bar
+ this.currentTime = new CurrentTime(this.body);
+ this.components.push(this.currentTime);
- // update the Y axis first, we use this data to draw at the correct Y points
- // changeCalled is required to clean the SVG on a change emit.
- changeCalled = this._updateYAxis(groupIds, groupRanges);
- var MAX_CYCLES = 5;
- if (changeCalled == true && this.COUNTER < MAX_CYCLES) {
- DOMutil.cleanupElements(this.svgElements);
- this.abortedGraphUpdate = true;
- this.COUNTER++;
- this.body.emitter.emit('change');
- return true;
- } else {
- if (this.COUNTER > MAX_CYCLES) {
- console.log('WARNING: there may be an infinite loop in the _updateGraph emitter cycle.');
- }
- this.COUNTER = 0;
- this.abortedGraphUpdate = false;
+ // item set
+ this.linegraph = new LineGraph(this.body);
+ this.components.push(this.linegraph);
- // With the yAxis scaled correctly, use this to get the Y values of the points.
- for (i = 0; i < groupIds.length; i++) {
- group = this.groups[groupIds[i]];
- processedGroupData[groupIds[i]] = this._convertYcoordinates(groupsData[groupIds[i]], group);
- }
+ this.itemsData = null; // DataSet
+ this.groupsData = null; // DataSet
- // draw the groups
- for (i = 0; i < groupIds.length; i++) {
- group = this.groups[groupIds[i]];
- if (group.options.style != 'bar') {
- // bar needs to be drawn enmasse
- group.draw(processedGroupData[groupIds[i]], group, this.framework);
- }
- }
- BarFunctions.draw(groupIds, processedGroupData, this.framework);
- }
- }
- }
+ this.on('tap', function (event) {
+ me.emit('click', me.getEventProperties(event));
+ });
+ this.on('doubletap', function (event) {
+ me.emit('doubleClick', me.getEventProperties(event));
+ });
+ this.dom.root.oncontextmenu = function (event) {
+ me.emit('contextmenu', me.getEventProperties(event));
+ };
- // cleanup unused svg elements
- DOMutil.cleanupElements(this.svgElements);
- return false;
- };
+ // setup configuration system
+ this.configurator = new Configurator(this, container, configureOptions);
- /**
- * first select and preprocess the data from the datasets.
- * the groups have their preselection of data, we now loop over this data to see
- * what data we need to draw. Sorted data is much faster.
- * more optimization is possible by doing the sampling before and using the binary search
- * to find the end date to determine the increment.
- *
- * @param {array} groupIds
- * @param {object} groupsData
- * @param {date} minDate
- * @param {date} maxDate
- * @private
- */
- LineGraph.prototype._getRelevantData = function (groupIds, groupsData, minDate, maxDate) {
- var group, i, j, item;
- if (groupIds.length > 0) {
- for (i = 0; i < groupIds.length; i++) {
- group = this.groups[groupIds[i]];
- groupsData[groupIds[i]] = [];
- var dataContainer = groupsData[groupIds[i]];
- // optimization for sorted data
- if (group.options.sort == true) {
- var guess = Math.max(0, util.binarySearchValue(group.itemsData, minDate, 'x', 'before'));
- for (j = guess; j < group.itemsData.length; j++) {
- item = group.itemsData[j];
- if (item !== undefined) {
- if (item.x > maxDate) {
- dataContainer.push(item);
- break;
- } else {
- dataContainer.push(item);
- }
- }
- }
- } else {
- for (j = 0; j < group.itemsData.length; j++) {
- item = group.itemsData[j];
- if (item !== undefined) {
- if (item.x > minDate && item.x < maxDate) {
- dataContainer.push(item);
- }
- }
- }
- }
- }
+ // apply options
+ if (options) {
+ this.setOptions(options);
}
- };
-
- /**
- *
- * @param groupIds
- * @param groupsData
- * @private
- */
- LineGraph.prototype._applySampling = function (groupIds, groupsData) {
- var group;
- if (groupIds.length > 0) {
- for (var i = 0; i < groupIds.length; i++) {
- group = this.groups[groupIds[i]];
- if (group.options.sampling == true) {
- var dataContainer = groupsData[groupIds[i]];
- if (dataContainer.length > 0) {
- var increment = 1;
- var amountOfPoints = dataContainer.length;
- // the global screen is used because changing the width of the yAxis may affect the increment, resulting in an endless loop
- // of width changing of the yAxis.
- var xDistance = this.body.util.toGlobalScreen(dataContainer[dataContainer.length - 1].x) - this.body.util.toGlobalScreen(dataContainer[0].x);
- var pointsPerPixel = amountOfPoints / xDistance;
- increment = Math.min(Math.ceil(0.2 * amountOfPoints), Math.max(1, Math.round(pointsPerPixel)));
+ // IMPORTANT: THIS HAPPENS BEFORE SET ITEMS!
+ if (groups) {
+ this.setGroups(groups);
+ }
- var sampledData = [];
- for (var j = 0; j < amountOfPoints; j += increment) {
- sampledData.push(dataContainer[j]);
- }
- groupsData[groupIds[i]] = sampledData;
- }
- }
- }
+ // create itemset
+ if (items) {
+ this.setItems(items);
+ } else {
+ this._redraw();
}
- };
+ }
- /**
- *
- *
- * @param {array} groupIds
- * @param {object} groupsData
- * @param {object} groupRanges | this is being filled here
- * @private
- */
- LineGraph.prototype._getYRanges = function (groupIds, groupsData, groupRanges) {
- var groupData, group, i;
- var combinedDataLeft = [];
- var combinedDataRight = [];
- var options;
- if (groupIds.length > 0) {
- for (i = 0; i < groupIds.length; i++) {
- groupData = groupsData[groupIds[i]];
- options = this.groups[groupIds[i]].options;
- if (groupData.length > 0) {
- group = this.groups[groupIds[i]];
- // if bar graphs are stacked, their range need to be handled differently and accumulated over all groups.
- if (options.stack === true) {
- if (options.yAxisOrientation == 'left') {
- combinedDataLeft = combinedDataLeft.concat(group.getData(groupData));
- } else {
- combinedDataRight = combinedDataRight.concat(group.getData(groupData));
- }
- } else {
- groupRanges[groupIds[i]] = group.getYRange(groupData, groupIds[i]);
- }
- }
- }
+ // Extend the functionality from Core
+ Graph2d.prototype = new Core();
- // if bar graphs are stacked, their range need to be handled differently and accumulated over all groups.
- BarFunctions.getStackedYRange(combinedDataLeft, groupRanges, groupIds, '__barStackLeft', 'left');
- BarFunctions.getStackedYRange(combinedDataRight, groupRanges, groupIds, '__barStackRight', 'right');
- // if line graphs are stacked, their range need to be handled differently and accumulated over all groups.
- LineFunctions.getStackedYRange(combinedDataLeft, groupRanges, groupIds, '__lineStackLeft', 'left');
- LineFunctions.getStackedYRange(combinedDataRight, groupRanges, groupIds, '__lineStackRight', 'right');
+ Graph2d.prototype.setOptions = function (options) {
+ // validate options
+ var errorFound = Validator.validate(options, allOptions);
+ if (errorFound === true) {
+ console.log('%cErrors have been found in the supplied options object.', printStyle);
}
+
+ Core.prototype.setOptions.call(this, options);
};
/**
- * this sets the Y ranges for the Y axis. It also determines which of the axis should be shown or hidden.
- * @param {Array} groupIds
- * @param {Object} groupRanges
- * @private
+ * Set items
+ * @param {vis.DataSet | Array | null} items
*/
- LineGraph.prototype._updateYAxis = function (groupIds, groupRanges) {
- var resized = false;
- var yAxisLeftUsed = false;
- var yAxisRightUsed = false;
- var minLeft = 1000000000,
- minRight = 1000000000,
- maxLeft = -1000000000,
- maxRight = -1000000000,
- minVal,
- maxVal;
- // if groups are present
- if (groupIds.length > 0) {
- // this is here to make sure that if there are no items in the axis but there are groups, that there is no infinite draw/redraw loop.
- for (var i = 0; i < groupIds.length; i++) {
- var group = this.groups[groupIds[i]];
- if (group && group.options.yAxisOrientation != 'right') {
- yAxisLeftUsed = true;
- minLeft = 0;
- maxLeft = 0;
- } else if (group && group.options.yAxisOrientation) {
- yAxisRightUsed = true;
- minRight = 0;
- maxRight = 0;
+ Graph2d.prototype.setItems = function (items) {
+ var initialLoad = this.itemsData == null;
+
+ // convert to type DataSet when needed
+ var newDataSet;
+ if (!items) {
+ newDataSet = null;
+ } else if (items instanceof DataSet || items instanceof DataView) {
+ newDataSet = items;
+ } else {
+ // turn an array into a dataset
+ newDataSet = new DataSet(items, {
+ type: {
+ start: 'Date',
+ end: 'Date'
}
- }
+ });
+ }
- // if there are items:
- for (var i = 0; i < groupIds.length; i++) {
- if (groupRanges.hasOwnProperty(groupIds[i])) {
- if (groupRanges[groupIds[i]].ignore !== true) {
- minVal = groupRanges[groupIds[i]].min;
- maxVal = groupRanges[groupIds[i]].max;
+ // set items
+ this.itemsData = newDataSet;
+ this.linegraph && this.linegraph.setItems(newDataSet);
- if (groupRanges[groupIds[i]].yAxisOrientation != 'right') {
- yAxisLeftUsed = true;
- minLeft = minLeft > minVal ? minVal : minLeft;
- maxLeft = maxLeft < maxVal ? maxVal : maxLeft;
- } else {
- yAxisRightUsed = true;
- minRight = minRight > minVal ? minVal : minRight;
- maxRight = maxRight < maxVal ? maxVal : maxRight;
- }
- }
- }
- }
+ if (initialLoad) {
+ if (this.options.start != undefined || this.options.end != undefined) {
+ var start = this.options.start != undefined ? this.options.start : null;
+ var end = this.options.end != undefined ? this.options.end : null;
- if (yAxisLeftUsed == true) {
- this.yAxisLeft.setRange(minLeft, maxLeft);
- }
- if (yAxisRightUsed == true) {
- this.yAxisRight.setRange(minRight, maxRight);
+ this.setWindow(start, end, { animation: false });
+ } else {
+ this.fit({ animation: false });
}
}
- resized = this._toggleAxisVisiblity(yAxisLeftUsed, this.yAxisLeft) || resized;
- resized = this._toggleAxisVisiblity(yAxisRightUsed, this.yAxisRight) || resized;
+ };
- if (yAxisRightUsed == true && yAxisLeftUsed == true) {
- this.yAxisLeft.drawIcons = true;
- this.yAxisRight.drawIcons = true;
+ /**
+ * Set groups
+ * @param {vis.DataSet | Array} groups
+ */
+ Graph2d.prototype.setGroups = function (groups) {
+ // convert to type DataSet when needed
+ var newDataSet;
+ if (!groups) {
+ newDataSet = null;
+ } else if (groups instanceof DataSet || groups instanceof DataView) {
+ newDataSet = groups;
} else {
- this.yAxisLeft.drawIcons = false;
- this.yAxisRight.drawIcons = false;
+ // turn an array into a dataset
+ newDataSet = new DataSet(groups);
}
- this.yAxisRight.master = !yAxisLeftUsed;
- if (this.yAxisRight.master == false) {
- if (yAxisRightUsed == true) {
- this.yAxisLeft.lineOffset = this.yAxisRight.width;
- } else {
- this.yAxisLeft.lineOffset = 0;
- }
- resized = this.yAxisLeft.redraw() || resized;
- this.yAxisRight.stepPixels = this.yAxisLeft.stepPixels;
- this.yAxisRight.zeroCrossing = this.yAxisLeft.zeroCrossing;
- this.yAxisRight.amountOfSteps = this.yAxisLeft.amountOfSteps;
- resized = this.yAxisRight.redraw() || resized;
- } else {
- resized = this.yAxisRight.redraw() || resized;
- }
+ this.groupsData = newDataSet;
+ this.linegraph.setGroups(newDataSet);
+ };
- // clean the accumulated lists
- var tempGroups = ['__barStackLeft', '__barStackRight', '__lineStackLeft', '__lineStackRight'];
- for (var i = 0; i < tempGroups.length; i++) {
- if (groupIds.indexOf(tempGroups[i]) != -1) {
- groupIds.splice(groupIds.indexOf(tempGroups[i]), 1);
- }
+ /**
+ * Returns an object containing an SVG element with the icon of the group (size determined by iconWidth and iconHeight), the label of the group (content) and the yAxisOrientation of the group (left or right).
+ * @param groupId
+ * @param width
+ * @param height
+ */
+ Graph2d.prototype.getLegend = function (groupId, width, height) {
+ if (width === undefined) {
+ width = 15;
+ }
+ if (height === undefined) {
+ height = 15;
+ }
+ if (this.linegraph.groups[groupId] !== undefined) {
+ return this.linegraph.groups[groupId].getLegend(width, height);
+ } else {
+ return 'cannot find group:' + groupId;
}
-
- return resized;
};
/**
- * This shows or hides the Y axis if needed. If there is a change, the changed event is emitted by the updateYAxis function
- *
- * @param {boolean} axisUsed
- * @returns {boolean}
- * @private
- * @param axis
+ * This checks if the visible option of the supplied group (by ID) is true or false.
+ * @param groupId
+ * @returns {*}
*/
- LineGraph.prototype._toggleAxisVisiblity = function (axisUsed, axis) {
- var changed = false;
- if (axisUsed == false) {
- if (axis.dom.frame.parentNode && axis.hidden == false) {
- axis.hide();
- changed = true;
- }
+ Graph2d.prototype.isGroupVisible = function (groupId) {
+ if (this.linegraph.groups[groupId] !== undefined) {
+ return this.linegraph.groups[groupId].visible && (this.linegraph.options.groups.visibility[groupId] === undefined || this.linegraph.options.groups.visibility[groupId] == true);
} else {
- if (!axis.dom.frame.parentNode && axis.hidden == true) {
- axis.show();
- changed = true;
- }
+ return false;
}
- return changed;
};
/**
- * This uses the DataAxis object to generate the correct X coordinate on the SVG window. It uses the
- * util function toScreen to get the x coordinate from the timestamp. It also pre-filters the data and get the minMax ranges for
- * the yAxis.
- *
- * @param datapoints
- * @returns {Array}
- * @private
+ * Get the data range of the item set.
+ * @returns {{min: Date, max: Date}} range A range with a start and end Date.
+ * When no minimum is found, min==null
+ * When no maximum is found, max==null
*/
- LineGraph.prototype._convertXcoordinates = function (datapoints) {
- var extractedData = [];
- var xValue, yValue;
- var toScreen = this.body.util.toScreen;
+ Graph2d.prototype.getItemRange = function () {
+ var min = null;
+ var max = null;
- for (var i = 0; i < datapoints.length; i++) {
- xValue = toScreen(datapoints[i].x) + this.props.width;
- yValue = datapoints[i].y;
- extractedData.push({ x: xValue, y: yValue });
+ // calculate min from start filed
+ for (var groupId in this.linegraph.groups) {
+ if (this.linegraph.groups.hasOwnProperty(groupId)) {
+ if (this.linegraph.groups[groupId].visible == true) {
+ for (var i = 0; i < this.linegraph.groups[groupId].itemsData.length; i++) {
+ var item = this.linegraph.groups[groupId].itemsData[i];
+ var value = util.convert(item.x, 'Date').valueOf();
+ min = min == null ? value : min > value ? value : min;
+ max = max == null ? value : max < value ? value : max;
+ }
+ }
+ }
}
- return extractedData;
+ return {
+ min: min != null ? new Date(min) : null,
+ max: max != null ? new Date(max) : null
+ };
};
/**
- * This uses the DataAxis object to generate the correct X coordinate on the SVG window. It uses the
- * util function toScreen to get the x coordinate from the timestamp. It also pre-filters the data and get the minMax ranges for
- * the yAxis.
- *
- * @param datapoints
- * @param group
- * @returns {Array}
- * @private
+ * Generate Timeline related information from an event
+ * @param {Event} event
+ * @return {Object} An object with related information, like on which area
+ * The event happened, whether clicked on an item, etc.
*/
- LineGraph.prototype._convertYcoordinates = function (datapoints, group) {
- var extractedData = [];
- var xValue, yValue;
- var toScreen = this.body.util.toScreen;
- var axis = this.yAxisLeft;
- var svgHeight = Number(this.svg.style.height.replace('px', ''));
- if (group.options.yAxisOrientation == 'right') {
- axis = this.yAxisRight;
- }
+ Graph2d.prototype.getEventProperties = function (event) {
+ var clientX = event.center ? event.center.x : event.clientX;
+ var clientY = event.center ? event.center.y : event.clientY;
+ var x = clientX - util.getAbsoluteLeft(this.dom.centerContainer);
+ var y = clientY - util.getAbsoluteTop(this.dom.centerContainer);
+ var time = this._toTime(x);
- for (var i = 0; i < datapoints.length; i++) {
- var labelValue = datapoints[i].label ? datapoints[i].label : null;
- xValue = toScreen(datapoints[i].x) + this.props.width;
- yValue = Math.round(axis.convertValue(datapoints[i].y));
- extractedData.push({ x: xValue, y: yValue, label: labelValue });
+ var customTime = CustomTime.customTimeFromTarget(event);
+
+ var element = util.getTarget(event);
+ var what = null;
+ if (util.hasParent(element, this.timeAxis.dom.foreground)) {
+ what = 'axis';
+ } else if (this.timeAxis2 && util.hasParent(element, this.timeAxis2.dom.foreground)) {
+ what = 'axis';
+ } else if (util.hasParent(element, this.linegraph.yAxisLeft.dom.frame)) {
+ what = 'data-axis';
+ } else if (util.hasParent(element, this.linegraph.yAxisRight.dom.frame)) {
+ what = 'data-axis';
+ } else if (util.hasParent(element, this.linegraph.legendLeft.dom.frame)) {
+ what = 'legend';
+ } else if (util.hasParent(element, this.linegraph.legendRight.dom.frame)) {
+ what = 'legend';
+ } else if (customTime != null) {
+ what = 'custom-time';
+ } else if (util.hasParent(element, this.currentTime.bar)) {
+ what = 'current-time';
+ } else if (util.hasParent(element, this.dom.center)) {
+ what = 'background';
}
- group.setZeroPosition(Math.min(svgHeight, axis.convertValue(0)));
+ var value = [];
+ var yAxisLeft = this.linegraph.yAxisLeft;
+ var yAxisRight = this.linegraph.yAxisRight;
+ if (!yAxisLeft.hidden) {
+ value.push(yAxisLeft.screenToValue(y));
+ }
+ if (!yAxisRight.hidden) {
+ value.push(yAxisRight.screenToValue(y));
+ }
- return extractedData;
+ return {
+ event: event,
+ what: what,
+ pageX: event.srcEvent ? event.srcEvent.pageX : event.pageX,
+ pageY: event.srcEvent ? event.srcEvent.pageY : event.pageY,
+ x: x,
+ y: y,
+ time: time,
+ value: value
+ };
};
- module.exports = LineGraph;
+ module.exports = Graph2d;
/***/ },
-/* 52 */
+/* 51 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var util = __webpack_require__(9);
var DOMutil = __webpack_require__(14);
+ var DataSet = __webpack_require__(15);
+ var DataView = __webpack_require__(17);
var Component = __webpack_require__(28);
- var DataStep = __webpack_require__(53);
+ var DataAxis = __webpack_require__(52);
+ var GraphGroup = __webpack_require__(54);
+ var Legend = __webpack_require__(58);
+ var BarFunctions = __webpack_require__(57);
+ var LineFunctions = __webpack_require__(55);
+
+ var UNGROUPED = '__ungrouped__'; // reserved group id for ungrouped items
/**
- * A horizontal time axis
- * @param {Object} [options] See DataAxis.setOptions for the available
- * options.
- * @constructor DataAxis
- * @extends Component
+ * This is the constructor of the LineGraph. It requires a Timeline body and options.
+ *
* @param body
+ * @param options
+ * @constructor
*/
- function DataAxis(body, options, svg, linegraphOptions) {
+ function LineGraph(body, options) {
this.id = util.randomUUID();
this.body = body;
this.defaultOptions = {
- orientation: 'left', // supported: 'left', 'right'
- showMinorLabels: true,
- showMajorLabels: true,
- icons: true,
- majorLinesOffset: 7,
- minorLinesOffset: 4,
- labelOffsetX: 10,
- labelOffsetY: 2,
- iconWidth: 20,
- width: '40px',
- visible: true,
- alignZeros: true,
- left: {
- range: { min: undefined, max: undefined },
- format: function format(value) {
- return value;
+ yAxisOrientation: 'left',
+ defaultGroup: 'default',
+ sort: true,
+ sampling: true,
+ stack: false,
+ graphHeight: '400px',
+ shaded: {
+ enabled: false,
+ orientation: 'bottom' // top, bottom
+ },
+ style: 'line', // line, bar
+ barChart: {
+ width: 50,
+ sideBySide: false,
+ align: 'center' // left, center, right
+ },
+ interpolation: {
+ enabled: true,
+ parametrization: 'centripetal', // uniform (alpha = 0.0), chordal (alpha = 1.0), centripetal (alpha = 0.5)
+ alpha: 0.5
+ },
+ drawPoints: {
+ enabled: true,
+ size: 6,
+ style: 'square' // square, circle
+ },
+ dataAxis: {
+ showMinorLabels: true,
+ showMajorLabels: true,
+ icons: false,
+ width: '40px',
+ visible: true,
+ alignZeros: true,
+ left: {
+ range: { min: undefined, max: undefined },
+ format: function format(value) {
+ return value;
+ },
+ title: { text: undefined, style: undefined }
},
- title: { text: undefined, style: undefined }
+ right: {
+ range: { min: undefined, max: undefined },
+ format: function format(value) {
+ return value;
+ },
+ title: { text: undefined, style: undefined }
+ }
},
- right: {
- range: { min: undefined, max: undefined },
- format: function format(value) {
- return value;
+ legend: {
+ enabled: false,
+ icons: true,
+ left: {
+ visible: true,
+ position: 'top-left' // top/bottom - left,right
},
- title: { text: undefined, style: undefined }
+ right: {
+ visible: true,
+ position: 'top-right' // top/bottom - left,right
+ }
+ },
+ groups: {
+ visibility: {}
}
};
- this.linegraphOptions = linegraphOptions;
- this.linegraphSVG = svg;
- this.props = {};
- this.DOMelements = { // dynamic elements
- lines: {},
- labels: {},
- title: {}
- };
-
+ // options is shared by this ItemSet and all its items
+ this.options = util.extend({}, this.defaultOptions);
this.dom = {};
+ this.props = {};
+ this.hammer = null;
+ this.groups = {};
+ this.abortedGraphUpdate = false;
+ this.updateSVGheight = false;
+ this.updateSVGheightOnResize = false;
- this.range = { start: 0, end: 0 };
+ var me = this;
+ this.itemsData = null; // DataSet
+ this.groupsData = null; // DataSet
- this.options = util.extend({}, this.defaultOptions);
- this.conversionFactor = 1;
+ // listeners for the DataSet of the items
+ this.itemListeners = {
+ 'add': function add(event, params, senderId) {
+ me._onAdd(params.items);
+ },
+ 'update': function update(event, params, senderId) {
+ me._onUpdate(params.items);
+ },
+ 'remove': function remove(event, params, senderId) {
+ me._onRemove(params.items);
+ }
+ };
- this.setOptions(options);
- this.width = Number(('' + this.options.width).replace('px', ''));
- this.minWidth = this.width;
- this.height = this.linegraphSVG.offsetHeight;
- this.hidden = false;
+ // listeners for the DataSet of the groups
+ this.groupListeners = {
+ 'add': function add(event, params, senderId) {
+ me._onAddGroups(params.items);
+ },
+ 'update': function update(event, params, senderId) {
+ me._onUpdateGroups(params.items);
+ },
+ 'remove': function remove(event, params, senderId) {
+ me._onRemoveGroups(params.items);
+ }
+ };
- this.stepPixels = 25;
- this.zeroCrossing = -1;
- this.amountOfSteps = -1;
+ this.items = {}; // object with an Item for every data item
+ this.selection = []; // list with the ids of all selected nodes
+ this.lastStart = this.body.range.start;
+ this.touchParams = {}; // stores properties while dragging
- this.lineOffset = 0;
- this.master = true;
this.svgElements = {};
- this.iconsRemoved = false;
-
- this.groups = {};
- this.amountOfGroups = 0;
+ this.setOptions(options);
+ this.groupsUsingDefaultStyles = [0];
+ this.COUNTER = 0;
+ this.body.emitter.on('rangechanged', function () {
+ me.lastStart = me.body.range.start;
+ me.svg.style.left = util.option.asSize(-me.props.width);
+ me.redraw.call(me, true);
+ });
// create the HTML DOM
this._create();
+ this.framework = { svg: this.svg, svgElements: this.svgElements, options: this.options, groups: this.groups };
+ this.body.emitter.emit('change');
+ }
- var me = this;
- this.body.emitter.on('verticalDrag', function () {
- me.dom.lineContainer.style.top = me.body.domProps.scrollTop + 'px';
- });
- }
-
- DataAxis.prototype = new Component();
-
- DataAxis.prototype.addGroup = function (label, graphOptions) {
- if (!this.groups.hasOwnProperty(label)) {
- this.groups[label] = graphOptions;
- }
- this.amountOfGroups += 1;
- };
-
- DataAxis.prototype.updateGroup = function (label, graphOptions) {
- this.groups[label] = graphOptions;
- };
-
- DataAxis.prototype.removeGroup = function (label) {
- if (this.groups.hasOwnProperty(label)) {
- delete this.groups[label];
- this.amountOfGroups -= 1;
- }
- };
-
- DataAxis.prototype.setOptions = function (options) {
- if (options) {
- var redraw = false;
- if (this.options.orientation != options.orientation && options.orientation !== undefined) {
- redraw = true;
- }
- var fields = ['orientation', 'showMinorLabels', 'showMajorLabels', 'icons', 'majorLinesOffset', 'minorLinesOffset', 'labelOffsetX', 'labelOffsetY', 'iconWidth', 'width', 'visible', 'left', 'right', 'alignZeros'];
- util.selectiveExtend(fields, this.options, options);
-
- this.minWidth = Number(('' + this.options.width).replace('px', ''));
-
- if (redraw === true && this.dom.frame) {
- this.hide();
- this.show();
- }
- }
- };
+ LineGraph.prototype = new Component();
/**
- * Create the HTML DOM for the DataAxis
+ * Create the HTML DOM for the ItemSet
*/
- DataAxis.prototype._create = function () {
- this.dom.frame = document.createElement('div');
- this.dom.frame.style.width = this.options.width;
- this.dom.frame.style.height = this.height;
-
- this.dom.lineContainer = document.createElement('div');
- this.dom.lineContainer.style.width = '100%';
- this.dom.lineContainer.style.height = this.height;
- this.dom.lineContainer.style.position = 'relative';
+ LineGraph.prototype._create = function () {
+ var frame = document.createElement('div');
+ frame.className = 'vis-line-graph';
+ this.dom.frame = frame;
// create svg element for graph drawing.
this.svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
- this.svg.style.position = 'absolute';
- this.svg.style.top = '0px';
- this.svg.style.height = '100%';
- this.svg.style.width = '100%';
+ this.svg.style.position = 'relative';
+ this.svg.style.height = ('' + this.options.graphHeight).replace('px', '') + 'px';
this.svg.style.display = 'block';
- this.dom.frame.appendChild(this.svg);
- };
+ frame.appendChild(this.svg);
- DataAxis.prototype._redrawGroupIcons = function () {
- DOMutil.prepareElements(this.svgElements);
+ // data axis
+ this.options.dataAxis.orientation = 'left';
+ this.yAxisLeft = new DataAxis(this.body, this.options.dataAxis, this.svg, this.options.groups);
- var x;
- var iconWidth = this.options.iconWidth;
- var iconHeight = 15;
- var iconOffset = 4;
- var y = iconOffset + 0.5 * iconHeight;
+ this.options.dataAxis.orientation = 'right';
+ this.yAxisRight = new DataAxis(this.body, this.options.dataAxis, this.svg, this.options.groups);
+ delete this.options.dataAxis.orientation;
- if (this.options.orientation === 'left') {
- x = iconOffset;
- } else {
- x = this.width - iconWidth - iconOffset;
- }
+ // legends
+ this.legendLeft = new Legend(this.body, this.options.legend, 'left', this.options.groups);
+ this.legendRight = new Legend(this.body, this.options.legend, 'right', this.options.groups);
- var groupArray = Object.keys(this.groups);
- groupArray.sort(function (a, b) {
- return a < b ? -1 : 1;
- });
+ this.show();
+ };
- for (var i = 0; i < groupArray.length; i++) {
- var groupId = groupArray[i];
- if (this.groups[groupId].visible === true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] === true)) {
- this.groups[groupId].drawIcon(x, y, this.svgElements, this.svg, iconWidth, iconHeight);
- y += iconHeight + iconOffset;
+ /**
+ * set the options of the LineGraph. the mergeOptions is used for subObjects that have an enabled element.
+ * @param {object} options
+ */
+ LineGraph.prototype.setOptions = function (options) {
+ if (options) {
+ var fields = ['sampling', 'defaultGroup', 'stack', 'height', 'graphHeight', 'yAxisOrientation', 'style', 'barChart', 'dataAxis', 'sort', 'groups'];
+ if (options.graphHeight === undefined && options.height !== undefined && this.body.domProps.centerContainer.height !== undefined) {
+ this.updateSVGheight = true;
+ this.updateSVGheightOnResize = true;
+ } else if (this.body.domProps.centerContainer.height !== undefined && options.graphHeight !== undefined) {
+ if (parseInt((options.graphHeight + '').replace('px', '')) < this.body.domProps.centerContainer.height) {
+ this.updateSVGheight = true;
+ }
}
- }
+ util.selectiveDeepExtend(fields, this.options, options);
+ util.mergeOptions(this.options, options, 'interpolation');
+ util.mergeOptions(this.options, options, 'drawPoints');
+ util.mergeOptions(this.options, options, 'shaded');
+ util.mergeOptions(this.options, options, 'legend');
- DOMutil.cleanupElements(this.svgElements);
- this.iconsRemoved = false;
- };
+ if (options.interpolation) {
+ if (typeof options.interpolation == 'object') {
+ if (options.interpolation.parametrization) {
+ if (options.interpolation.parametrization == 'uniform') {
+ this.options.interpolation.alpha = 0;
+ } else if (options.interpolation.parametrization == 'chordal') {
+ this.options.interpolation.alpha = 1;
+ } else {
+ this.options.interpolation.parametrization = 'centripetal';
+ this.options.interpolation.alpha = 0.5;
+ }
+ }
+ }
+ }
- DataAxis.prototype._cleanupIcons = function () {
- if (this.iconsRemoved === false) {
- DOMutil.prepareElements(this.svgElements);
- DOMutil.cleanupElements(this.svgElements);
- this.iconsRemoved = true;
- }
- };
+ if (this.yAxisLeft) {
+ if (options.dataAxis !== undefined) {
+ this.yAxisLeft.setOptions(this.options.dataAxis);
+ this.yAxisRight.setOptions(this.options.dataAxis);
+ }
+ }
- /**
- * Create the HTML DOM for the DataAxis
- */
- DataAxis.prototype.show = function () {
- this.hidden = false;
- if (!this.dom.frame.parentNode) {
- if (this.options.orientation === 'left') {
- this.body.dom.left.appendChild(this.dom.frame);
- } else {
- this.body.dom.right.appendChild(this.dom.frame);
+ if (this.legendLeft) {
+ if (options.legend !== undefined) {
+ this.legendLeft.setOptions(this.options.legend);
+ this.legendRight.setOptions(this.options.legend);
+ }
+ }
+
+ if (this.groups.hasOwnProperty(UNGROUPED)) {
+ this.groups[UNGROUPED].setOptions(options);
}
}
- if (!this.dom.lineContainer.parentNode) {
- this.body.dom.backgroundHorizontal.appendChild(this.dom.lineContainer);
+ // this is used to redraw the graph if the visibility of the groups is changed.
+ if (this.dom.frame) {
+ this.redraw(true);
}
};
/**
- * Create the HTML DOM for the DataAxis
+ * Hide the component from the DOM
*/
- DataAxis.prototype.hide = function () {
- this.hidden = true;
+ LineGraph.prototype.hide = function () {
+ // remove the frame containing the items
if (this.dom.frame.parentNode) {
this.dom.frame.parentNode.removeChild(this.dom.frame);
}
-
- if (this.dom.lineContainer.parentNode) {
- this.dom.lineContainer.parentNode.removeChild(this.dom.lineContainer);
- }
};
/**
- * Set a range (start and end)
- * @param end
- * @param start
- * @param end
+ * Show the component in the DOM (when not already visible).
+ * @return {Boolean} changed
*/
- DataAxis.prototype.setRange = function (start, end) {
- if (this.master === false && this.options.alignZeros === true && this.zeroCrossing != -1) {
- if (start > 0) {
- start = 0;
- }
+ LineGraph.prototype.show = function () {
+ // show frame containing the items
+ if (!this.dom.frame.parentNode) {
+ this.body.dom.center.appendChild(this.dom.frame);
}
- this.range.start = start;
- this.range.end = end;
};
/**
- * Repaint the component
- * @return {boolean} Returns true if the component is resized
+ * Set items
+ * @param {vis.DataSet | null} items
*/
- DataAxis.prototype.redraw = function () {
- var resized = false;
- var activeGroups = 0;
-
- // Make sure the line container adheres to the vertical scrolling.
- this.dom.lineContainer.style.top = this.body.domProps.scrollTop + 'px';
+ LineGraph.prototype.setItems = function (items) {
+ var me = this,
+ ids,
+ oldItemsData = this.itemsData;
- for (var groupId in this.groups) {
- if (this.groups.hasOwnProperty(groupId)) {
- if (this.groups[groupId].visible === true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] === true)) {
- activeGroups++;
- }
- }
- }
- if (this.amountOfGroups === 0 || activeGroups === 0) {
- this.hide();
+ // replace the dataset
+ if (!items) {
+ this.itemsData = null;
+ } else if (items instanceof DataSet || items instanceof DataView) {
+ this.itemsData = items;
} else {
- this.show();
- this.height = Number(this.linegraphSVG.style.height.replace('px', ''));
-
- // svg offsetheight did not work in firefox and explorer...
- this.dom.lineContainer.style.height = this.height + 'px';
- this.width = this.options.visible === true ? Number(('' + this.options.width).replace('px', '')) : 0;
-
- var props = this.props;
- var frame = this.dom.frame;
-
- // update classname
- frame.className = 'vis-data-axis';
-
- // calculate character width and height
- this._calculateCharSize();
-
- var orientation = this.options.orientation;
- var showMinorLabels = this.options.showMinorLabels;
- var showMajorLabels = this.options.showMajorLabels;
-
- // determine the width and height of the elements for the axis
- props.minorLabelHeight = showMinorLabels ? props.minorCharHeight : 0;
- props.majorLabelHeight = showMajorLabels ? props.majorCharHeight : 0;
-
- props.minorLineWidth = this.body.dom.backgroundHorizontal.offsetWidth - this.lineOffset - this.width + 2 * this.options.minorLinesOffset;
- props.minorLineHeight = 1;
- props.majorLineWidth = this.body.dom.backgroundHorizontal.offsetWidth - this.lineOffset - this.width + 2 * this.options.majorLinesOffset;
- props.majorLineHeight = 1;
+ throw new TypeError('Data must be an instance of DataSet or DataView');
+ }
- // take frame offline while updating (is almost twice as fast)
- if (orientation === 'left') {
- frame.style.top = '0';
- frame.style.left = '0';
- frame.style.bottom = '';
- frame.style.width = this.width + 'px';
- frame.style.height = this.height + 'px';
- this.props.width = this.body.domProps.left.width;
- this.props.height = this.body.domProps.left.height;
- } else {
- // right
- frame.style.top = '';
- frame.style.bottom = '0';
- frame.style.left = '0';
- frame.style.width = this.width + 'px';
- frame.style.height = this.height + 'px';
- this.props.width = this.body.domProps.right.width;
- this.props.height = this.body.domProps.right.height;
- }
+ if (oldItemsData) {
+ // unsubscribe from old dataset
+ util.forEach(this.itemListeners, function (callback, event) {
+ oldItemsData.off(event, callback);
+ });
- resized = this._redrawLabels();
- resized = this._isResized() || resized;
+ // remove all drawn items
+ ids = oldItemsData.getIds();
+ this._onRemove(ids);
+ }
- if (this.options.icons === true) {
- this._redrawGroupIcons();
- } else {
- this._cleanupIcons();
- }
+ if (this.itemsData) {
+ // subscribe to new dataset
+ var id = this.id;
+ util.forEach(this.itemListeners, function (callback, event) {
+ me.itemsData.on(event, callback, id);
+ });
- this._redrawTitle(orientation);
+ // add all new items
+ ids = this.itemsData.getIds();
+ this._onAdd(ids);
}
- return resized;
+ this._updateUngrouped();
+ //this._updateGraph();
+ this.redraw(true);
};
/**
- * Repaint major and minor text labels and vertical grid lines
- * @private
+ * Set groups
+ * @param {vis.DataSet} groups
*/
- DataAxis.prototype._redrawLabels = function () {
- var resized = false;
- DOMutil.prepareElements(this.DOMelements.lines);
- DOMutil.prepareElements(this.DOMelements.labels);
- var orientation = this.options['orientation'];
-
- // get the range for the slaved axis
- var step;
- if (this.master === false) {
- var stepSize, rangeStart, rangeEnd, minimumStep;
- if (this.zeroCrossing !== -1 && this.options.alignZeros === true) {
- if (this.range.end > 0) {
- stepSize = this.range.end / this.zeroCrossing; // size of one step
- rangeStart = this.range.end - this.amountOfSteps * stepSize;
- rangeEnd = this.range.end;
- } else {
- // all of the range (including start) has to be done before the zero crossing.
- stepSize = -1 * this.range.start / (this.amountOfSteps - this.zeroCrossing); // absolute size of a step
- rangeStart = this.range.start;
- rangeEnd = this.range.start + stepSize * this.amountOfSteps;
- }
- } else {
- rangeStart = this.range.start;
- rangeEnd = this.range.end;
- }
- minimumStep = this.stepPixels;
- } else {
- // calculate range and step (step such that we have space for 7 characters per label)
- minimumStep = this.props.majorCharHeight;
- rangeStart = this.range.start;
- rangeEnd = this.range.end;
- }
-
- this.step = step = new DataStep(rangeStart, rangeEnd, minimumStep, this.dom.frame.offsetHeight, this.options[this.options.orientation].range, this.options[this.options.orientation].format, this.master === false && this.options.alignZeros // does the step have to align zeros? only if not master and the options is on
- );
-
- // the slave axis needs to use the same horizontal lines as the master axis.
- if (this.master === true) {
- this.stepPixels = this.dom.frame.offsetHeight / step.marginRange * step.step;
- this.amountOfSteps = Math.ceil(this.dom.frame.offsetHeight / this.stepPixels);
- } else {
- // align with zero
- if (this.options.alignZeros === true && this.zeroCrossing !== -1) {
- // distance is the amount of steps away from the zero crossing we are.
- var distance = (step.current - this.zeroCrossing * step.step) / step.step;
- this.step.shift(distance);
- }
- }
-
- // value at the bottom of the SVG
- this.valueAtBottom = step.marginEnd;
-
- this.maxLabelSize = 0;
- var y = 0; // init value
- var stepIndex = 0; // init value
- var isMajor = false; // init value
- while (stepIndex < this.amountOfSteps) {
- y = Math.round(stepIndex * this.stepPixels);
- isMajor = step.isMajor();
-
- if (stepIndex > 0 && stepIndex !== this.amountOfSteps) {
- if (this.options['showMinorLabels'] && isMajor === false || this.master === false && this.options['showMinorLabels'] === true) {
- this._redrawLabel(y - 2, step.getCurrent(), orientation, 'vis-y-axis vis-minor', this.props.minorCharHeight);
- }
-
- if (isMajor && this.options['showMajorLabels'] && this.master === true || this.options['showMinorLabels'] === false && this.master === false && isMajor === true) {
- if (y >= 0) {
- this._redrawLabel(y - 2, step.getCurrent(), orientation, 'vis-y-axis vis-major', this.props.majorCharHeight);
- }
- this._redrawLine(y, orientation, 'vis-grid vis-horizontal vis-major', this.options.majorLinesOffset, this.props.majorLineWidth);
- } else {
- this._redrawLine(y, orientation, 'vis-grid vis-horizontal vis-minor', this.options.minorLinesOffset, this.props.minorLineWidth);
- }
- }
+ LineGraph.prototype.setGroups = function (groups) {
+ var me = this;
+ var ids;
- // get zero crossing
- if (this.master === true && step.current === 0) {
- this.zeroCrossing = stepIndex;
- }
+ // unsubscribe from current dataset
+ if (this.groupsData) {
+ util.forEach(this.groupListeners, function (callback, event) {
+ me.groupsData.off(event, callback);
+ });
- step.next();
- stepIndex += 1;
+ // remove all drawn groups
+ ids = this.groupsData.getIds();
+ this.groupsData = null;
+ this._onRemoveGroups(ids); // note: this will cause a redraw
}
- // get zero crossing if it's the last step
- if (this.master === true && step.current === 0) {
- this.zeroCrossing = stepIndex;
+ // replace the dataset
+ if (!groups) {
+ this.groupsData = null;
+ } else if (groups instanceof DataSet || groups instanceof DataView) {
+ this.groupsData = groups;
+ } else {
+ throw new TypeError('Data must be an instance of DataSet or DataView');
}
- this.conversionFactor = this.stepPixels / step.step;
-
- // Note that title is rotated, so we're using the height, not width!
- var titleWidth = 0;
- if (this.options[orientation].title !== undefined && this.options[orientation].title.text !== undefined) {
- titleWidth = this.props.titleCharHeight;
- }
- var offset = this.options.icons === true ? Math.max(this.options.iconWidth, titleWidth) + this.options.labelOffsetX + 15 : titleWidth + this.options.labelOffsetX + 15;
+ if (this.groupsData) {
+ // subscribe to new dataset
+ var id = this.id;
+ util.forEach(this.groupListeners, function (callback, event) {
+ me.groupsData.on(event, callback, id);
+ });
- // this will resize the yAxis to accommodate the labels.
- if (this.maxLabelSize > this.width - offset && this.options.visible === true) {
- this.width = this.maxLabelSize + offset;
- this.options.width = this.width + 'px';
- DOMutil.cleanupElements(this.DOMelements.lines);
- DOMutil.cleanupElements(this.DOMelements.labels);
- this.redraw();
- resized = true;
- }
- // this will resize the yAxis if it is too big for the labels.
- else if (this.maxLabelSize < this.width - offset && this.options.visible === true && this.width > this.minWidth) {
- this.width = Math.max(this.minWidth, this.maxLabelSize + offset);
- this.options.width = this.width + 'px';
- DOMutil.cleanupElements(this.DOMelements.lines);
- DOMutil.cleanupElements(this.DOMelements.labels);
- this.redraw();
- resized = true;
- } else {
- DOMutil.cleanupElements(this.DOMelements.lines);
- DOMutil.cleanupElements(this.DOMelements.labels);
- resized = false;
+ // draw all ms
+ ids = this.groupsData.getIds();
+ this._onAddGroups(ids);
}
-
- return resized;
+ this._onUpdate();
};
- DataAxis.prototype.convertValue = function (value) {
- var invertedValue = this.valueAtBottom - value;
- var convertedValue = invertedValue * this.conversionFactor;
- return convertedValue;
+ /**
+ * Update the data
+ * @param [ids]
+ * @private
+ */
+ LineGraph.prototype._onUpdate = function (ids) {
+ this._updateUngrouped();
+ this._updateAllGroupData();
+ //this._updateGraph();
+ this.redraw(true);
+ };
+ LineGraph.prototype._onAdd = function (ids) {
+ this._onUpdate(ids);
+ };
+ LineGraph.prototype._onRemove = function (ids) {
+ this._onUpdate(ids);
};
+ LineGraph.prototype._onUpdateGroups = function (groupIds) {
+ for (var i = 0; i < groupIds.length; i++) {
+ var group = this.groupsData.get(groupIds[i]);
+ this._updateGroup(group, groupIds[i]);
+ }
- DataAxis.prototype.screenToValue = function (x) {
- return this.valueAtBottom - x / this.conversionFactor;
+ //this._updateGraph();
+ this.redraw(true);
+ };
+ LineGraph.prototype._onAddGroups = function (groupIds) {
+ this._onUpdateGroups(groupIds);
};
/**
- * Create a label for the axis at position x
+ * this cleans the group out off the legends and the dataaxis, updates the ungrouped and updates the graph
+ * @param {Array} groupIds
* @private
- * @param y
- * @param text
- * @param orientation
- * @param className
- * @param characterHeight
*/
- DataAxis.prototype._redrawLabel = function (y, text, orientation, className, characterHeight) {
- // reuse redundant label
- var label = DOMutil.getDOMElement('div', this.DOMelements.labels, this.dom.frame); //this.dom.redundant.labels.shift();
- label.className = className;
- label.innerHTML = text;
- if (orientation === 'left') {
- label.style.left = '-' + this.options.labelOffsetX + 'px';
- label.style.textAlign = 'right';
- } else {
- label.style.right = '-' + this.options.labelOffsetX + 'px';
- label.style.textAlign = 'left';
+ LineGraph.prototype._onRemoveGroups = function (groupIds) {
+ for (var i = 0; i < groupIds.length; i++) {
+ if (this.groups.hasOwnProperty(groupIds[i])) {
+ if (this.groups[groupIds[i]].options.yAxisOrientation == 'right') {
+ this.yAxisRight.removeGroup(groupIds[i]);
+ this.legendRight.removeGroup(groupIds[i]);
+ this.legendRight.redraw();
+ } else {
+ this.yAxisLeft.removeGroup(groupIds[i]);
+ this.legendLeft.removeGroup(groupIds[i]);
+ this.legendLeft.redraw();
+ }
+ delete this.groups[groupIds[i]];
+ }
}
+ this._updateUngrouped();
+ //this._updateGraph();
+ this.redraw(true);
+ };
- label.style.top = y - 0.5 * characterHeight + this.options.labelOffsetY + 'px';
-
- text += '';
-
- var largestWidth = Math.max(this.props.majorCharWidth, this.props.minorCharWidth);
- if (this.maxLabelSize < text.length * largestWidth) {
- this.maxLabelSize = text.length * largestWidth;
+ /**
+ * update a group object with the group dataset entree
+ *
+ * @param group
+ * @param groupId
+ * @private
+ */
+ LineGraph.prototype._updateGroup = function (group, groupId) {
+ if (!this.groups.hasOwnProperty(groupId)) {
+ this.groups[groupId] = new GraphGroup(group, groupId, this.options, this.groupsUsingDefaultStyles);
+ if (this.groups[groupId].options.yAxisOrientation == 'right') {
+ this.yAxisRight.addGroup(groupId, this.groups[groupId]);
+ this.legendRight.addGroup(groupId, this.groups[groupId]);
+ } else {
+ this.yAxisLeft.addGroup(groupId, this.groups[groupId]);
+ this.legendLeft.addGroup(groupId, this.groups[groupId]);
+ }
+ } else {
+ this.groups[groupId].update(group);
+ if (this.groups[groupId].options.yAxisOrientation == 'right') {
+ this.yAxisRight.updateGroup(groupId, this.groups[groupId]);
+ this.legendRight.updateGroup(groupId, this.groups[groupId]);
+ } else {
+ this.yAxisLeft.updateGroup(groupId, this.groups[groupId]);
+ this.legendLeft.updateGroup(groupId, this.groups[groupId]);
+ }
}
+ this.legendLeft.redraw();
+ this.legendRight.redraw();
};
/**
- * Create a minor line for the axis at position y
- * @param y
- * @param orientation
- * @param className
- * @param offset
- * @param width
+ * this updates all groups, it is used when there is an update the the itemset.
+ *
+ * @private
*/
- DataAxis.prototype._redrawLine = function (y, orientation, className, offset, width) {
- if (this.master === true) {
- var line = DOMutil.getDOMElement('div', this.DOMelements.lines, this.dom.lineContainer); //this.dom.redundant.lines.shift();
- line.className = className;
- line.innerHTML = '';
-
- if (orientation === 'left') {
- line.style.left = this.width - offset + 'px';
- } else {
- line.style.right = this.width - offset + 'px';
+ LineGraph.prototype._updateAllGroupData = function () {
+ if (this.itemsData != null) {
+ var groupsContent = {};
+ var groupId;
+ for (groupId in this.groups) {
+ if (this.groups.hasOwnProperty(groupId)) {
+ groupsContent[groupId] = [];
+ }
+ }
+ for (var itemId in this.itemsData._data) {
+ if (this.itemsData._data.hasOwnProperty(itemId)) {
+ var item = this.itemsData._data[itemId];
+ if (groupsContent[item.group] === undefined) {
+ throw new Error('Cannot find referenced group. Possible reason: items added before groups? Groups need to be added before items, as items refer to groups.');
+ }
+ item.x = util.convert(item.x, 'Date');
+ groupsContent[item.group].push(item);
+ }
+ }
+ for (groupId in this.groups) {
+ if (this.groups.hasOwnProperty(groupId)) {
+ this.groups[groupId].setItems(groupsContent[groupId]);
+ }
}
-
- line.style.width = width + 'px';
- line.style.top = y + 'px';
}
};
/**
- * Create a title for the axis
- * @private
- * @param orientation
+ * Create or delete the group holding all ungrouped items. This group is used when
+ * there are no groups specified. This anonymous group is called 'graph'.
+ * @protected
*/
- DataAxis.prototype._redrawTitle = function (orientation) {
- DOMutil.prepareElements(this.DOMelements.title);
-
- // Check if the title is defined for this axes
- if (this.options[orientation].title !== undefined && this.options[orientation].title.text !== undefined) {
- var title = DOMutil.getDOMElement('div', this.DOMelements.title, this.dom.frame);
- title.className = 'vis-y-axis vis-title vis-' + orientation;
- title.innerHTML = this.options[orientation].title.text;
-
- // Add style - if provided
- if (this.options[orientation].title.style !== undefined) {
- util.addCssText(title, this.options[orientation].title.style);
+ LineGraph.prototype._updateUngrouped = function () {
+ if (this.itemsData && this.itemsData != null) {
+ var ungroupedCounter = 0;
+ for (var itemId in this.itemsData._data) {
+ if (this.itemsData._data.hasOwnProperty(itemId)) {
+ var item = this.itemsData._data[itemId];
+ if (item != undefined) {
+ if (item.hasOwnProperty('group')) {
+ if (item.group === undefined) {
+ item.group = UNGROUPED;
+ }
+ } else {
+ item.group = UNGROUPED;
+ }
+ ungroupedCounter = item.group == UNGROUPED ? ungroupedCounter + 1 : ungroupedCounter;
+ }
+ }
}
- if (orientation === 'left') {
- title.style.left = this.props.titleCharHeight + 'px';
+ if (ungroupedCounter == 0) {
+ delete this.groups[UNGROUPED];
+ this.legendLeft.removeGroup(UNGROUPED);
+ this.legendRight.removeGroup(UNGROUPED);
+ this.yAxisLeft.removeGroup(UNGROUPED);
+ this.yAxisRight.removeGroup(UNGROUPED);
} else {
- title.style.right = this.props.titleCharHeight + 'px';
+ var group = { id: UNGROUPED, content: this.options.defaultGroup };
+ this._updateGroup(group, UNGROUPED);
}
-
- title.style.width = this.height + 'px';
+ } else {
+ delete this.groups[UNGROUPED];
+ this.legendLeft.removeGroup(UNGROUPED);
+ this.legendRight.removeGroup(UNGROUPED);
+ this.yAxisLeft.removeGroup(UNGROUPED);
+ this.yAxisRight.removeGroup(UNGROUPED);
}
- // we need to clean up in case we did not use all elements.
- DOMutil.cleanupElements(this.DOMelements.title);
+ this.legendLeft.redraw();
+ this.legendRight.redraw();
};
/**
- * Determine the size of text on the axis (both major and minor axis).
- * The size is calculated only once and then cached in this.props.
- * @private
+ * Redraw the component, mandatory function
+ * @return {boolean} Returns true if the component is resized
*/
- DataAxis.prototype._calculateCharSize = function () {
- // determine the char width and height on the minor axis
- if (!('minorCharHeight' in this.props)) {
- var textMinor = document.createTextNode('0');
- var measureCharMinor = document.createElement('div');
- measureCharMinor.className = 'vis-y-axis vis-minor vis-measure';
- measureCharMinor.appendChild(textMinor);
- this.dom.frame.appendChild(measureCharMinor);
+ LineGraph.prototype.redraw = function (forceGraphUpdate) {
+ var resized = false;
- this.props.minorCharHeight = measureCharMinor.clientHeight;
- this.props.minorCharWidth = measureCharMinor.clientWidth;
+ // calculate actual size and position
+ this.props.width = this.dom.frame.offsetWidth;
+ this.props.height = this.body.domProps.centerContainer.height - this.body.domProps.border.top - this.body.domProps.border.bottom;
- this.dom.frame.removeChild(measureCharMinor);
+ // update the graph if there is no lastWidth or with, used for the initial draw
+ if (this.lastWidth === undefined && this.props.width) {
+ forceGraphUpdate = true;
}
- if (!('majorCharHeight' in this.props)) {
- var textMajor = document.createTextNode('0');
- var measureCharMajor = document.createElement('div');
- measureCharMajor.className = 'vis-y-axis vis-major vis-measure';
- measureCharMajor.appendChild(textMajor);
- this.dom.frame.appendChild(measureCharMajor);
-
- this.props.majorCharHeight = measureCharMajor.clientHeight;
- this.props.majorCharWidth = measureCharMajor.clientWidth;
+ // check if this component is resized
+ resized = this._isResized() || resized;
- this.dom.frame.removeChild(measureCharMajor);
- }
+ // check whether zoomed (in that case we need to re-stack everything)
+ var visibleInterval = this.body.range.end - this.body.range.start;
+ var zoomed = visibleInterval != this.lastVisibleInterval;
+ this.lastVisibleInterval = visibleInterval;
- if (!('titleCharHeight' in this.props)) {
- var textTitle = document.createTextNode('0');
- var measureCharTitle = document.createElement('div');
- measureCharTitle.className = 'vis-y-axis vis-title vis-measure';
- measureCharTitle.appendChild(textTitle);
- this.dom.frame.appendChild(measureCharTitle);
+ // the svg element is three times as big as the width, this allows for fully dragging left and right
+ // without reloading the graph. the controls for this are bound to events in the constructor
+ if (resized == true) {
+ this.svg.style.width = util.option.asSize(3 * this.props.width);
+ this.svg.style.left = util.option.asSize(-this.props.width);
- this.props.titleCharHeight = measureCharTitle.clientHeight;
- this.props.titleCharWidth = measureCharTitle.clientWidth;
+ // if the height of the graph is set as proportional, change the height of the svg
+ if ((this.options.height + '').indexOf('%') != -1 || this.updateSVGheightOnResize == true) {
+ this.updateSVGheight = true;
+ }
+ }
- this.dom.frame.removeChild(measureCharTitle);
+ // update the height of the graph on each redraw of the graph.
+ if (this.updateSVGheight == true) {
+ if (this.options.graphHeight != this.props.height + 'px') {
+ this.options.graphHeight = this.props.height + 'px';
+ this.svg.style.height = this.props.height + 'px';
+ }
+ this.updateSVGheight = false;
+ } else {
+ this.svg.style.height = ('' + this.options.graphHeight).replace('px', '') + 'px';
}
- };
- module.exports = DataAxis;
+ // zoomed is here to ensure that animations are shown correctly.
+ if (resized == true || zoomed == true || this.abortedGraphUpdate == true || forceGraphUpdate == true) {
+ resized = this._updateGraph() || resized;
+ } else {
+ // move the whole svg while dragging
+ if (this.lastStart != 0) {
+ var offset = this.body.range.start - this.lastStart;
+ var range = this.body.range.end - this.body.range.start;
+ if (this.props.width != 0) {
+ var rangePerPixelInv = this.props.width / range;
+ var xOffset = offset * rangePerPixelInv;
+ this.svg.style.left = -this.props.width - xOffset + 'px';
+ }
+ }
+ }
-/***/ },
-/* 53 */
-/***/ function(module, exports, __webpack_require__) {
+ this.legendLeft.redraw();
+ this.legendRight.redraw();
+ return resized;
+ };
/**
- * @constructor DataStep
- * The class DataStep is an iterator for data for the lineGraph. You provide a start data point and an
- * end data point. The class itself determines the best scale (step size) based on the
- * provided start Date, end Date, and minimumStep.
- *
- * If minimumStep is provided, the step size is chosen as close as possible
- * to the minimumStep but larger than minimumStep. If minimumStep is not
- * provided, the scale is set to 1 DAY.
- * The minimumStep should correspond with the onscreen size of about 6 characters
- *
- * Alternatively, you can set a scale by hand.
- * After creation, you can initialize the class by executing first(). Then you
- * can iterate from the start date to the end date via next(). You can check if
- * the end date is reached with the function hasNext(). After each step, you can
- * retrieve the current date via getCurrent().
- * The DataStep has scales ranging from milliseconds, seconds, minutes, hours,
- * days, to years.
- *
- * Version: 1.2
+ * Update and redraw the graph.
*
- * @param {Date} [start] The start date, for example new Date(2010, 9, 21)
- * or new Date(2010, 9, 21, 23, 45, 00)
- * @param {Date} [end] The end date
- * @param {Number} [minimumStep] Optional. Minimum step size in milliseconds
*/
- 'use strict';
+ LineGraph.prototype._updateGraph = function () {
+ // reset the svg elements
+ DOMutil.prepareElements(this.svgElements);
+ if (this.props.width != 0 && this.itemsData != null) {
+ var group, i;
+ var preprocessedGroupData = {};
+ var processedGroupData = {};
+ var groupRanges = {};
+ var changeCalled = false;
- function DataStep(start, end, minimumStep, containerHeight, customRange, formattingFunction, alignZeros) {
- // variables
- this.current = 0;
+ // getting group Ids
+ var groupIds = [];
+ for (var groupId in this.groups) {
+ if (this.groups.hasOwnProperty(groupId)) {
+ group = this.groups[groupId];
+ if (group.visible == true && (this.options.groups.visibility[groupId] === undefined || this.options.groups.visibility[groupId] == true)) {
+ groupIds.push(groupId);
+ }
+ }
+ }
+ if (groupIds.length > 0) {
+ // this is the range of the SVG canvas
+ var minDate = this.body.util.toGlobalTime(-this.body.domProps.root.width);
+ var maxDate = this.body.util.toGlobalTime(2 * this.body.domProps.root.width);
+ var groupsData = {};
+ // fill groups data, this only loads the data we require based on the timewindow
+ this._getRelevantData(groupIds, groupsData, minDate, maxDate);
- this.autoScale = true;
- this.stepIndex = 0;
- this.step = 1;
- this.scale = 1;
- this.formattingFunction = formattingFunction;
+ // apply sampling, if disabled, it will pass through this function.
+ this._applySampling(groupIds, groupsData);
- this.marginStart;
- this.marginEnd;
- this.deadSpace = 0;
+ // we transform the X coordinates to detect collisions
+ for (i = 0; i < groupIds.length; i++) {
+ preprocessedGroupData[groupIds[i]] = this._convertXcoordinates(groupsData[groupIds[i]]);
+ }
- this.majorSteps = [1, 2, 5, 10];
- this.minorSteps = [0.25, 0.5, 1, 2];
+ // now all needed data has been collected we start the processing.
+ this._getYRanges(groupIds, preprocessedGroupData, groupRanges);
- this.alignZeros = alignZeros;
+ // update the Y axis first, we use this data to draw at the correct Y points
+ // changeCalled is required to clean the SVG on a change emit.
+ changeCalled = this._updateYAxis(groupIds, groupRanges);
+ var MAX_CYCLES = 5;
+ if (changeCalled == true && this.COUNTER < MAX_CYCLES) {
+ DOMutil.cleanupElements(this.svgElements);
+ this.abortedGraphUpdate = true;
+ this.COUNTER++;
+ this.body.emitter.emit('change');
+ return true;
+ } else {
+ if (this.COUNTER > MAX_CYCLES) {
+ console.log('WARNING: there may be an infinite loop in the _updateGraph emitter cycle.');
+ }
+ this.COUNTER = 0;
+ this.abortedGraphUpdate = false;
- this.setRange(start, end, minimumStep, containerHeight, customRange);
- }
+ // With the yAxis scaled correctly, use this to get the Y values of the points.
+ for (i = 0; i < groupIds.length; i++) {
+ group = this.groups[groupIds[i]];
+ processedGroupData[groupIds[i]] = this._convertYcoordinates(groupsData[groupIds[i]], group);
+ }
+
+ // draw the groups
+ for (i = 0; i < groupIds.length; i++) {
+ group = this.groups[groupIds[i]];
+ if (group.options.style != 'bar') {
+ // bar needs to be drawn enmasse
+ group.draw(processedGroupData[groupIds[i]], group, this.framework);
+ }
+ }
+ BarFunctions.draw(groupIds, processedGroupData, this.framework);
+ }
+ }
+ }
+
+ // cleanup unused svg elements
+ DOMutil.cleanupElements(this.svgElements);
+ return false;
+ };
/**
- * Set a new range
- * If minimumStep is provided, the step size is chosen as close as possible
- * to the minimumStep but larger than minimumStep. If minimumStep is not
- * provided, the scale is set to 1 DAY.
- * The minimumStep should correspond with the onscreen size of about 6 characters
- * @param {Number} [start] The start date and time.
- * @param {Number} [end] The end date and time.
- * @param {Number} [minimumStep] Optional. Minimum step size in milliseconds
+ * first select and preprocess the data from the datasets.
+ * the groups have their preselection of data, we now loop over this data to see
+ * what data we need to draw. Sorted data is much faster.
+ * more optimization is possible by doing the sampling before and using the binary search
+ * to find the end date to determine the increment.
+ *
+ * @param {array} groupIds
+ * @param {object} groupsData
+ * @param {date} minDate
+ * @param {date} maxDate
+ * @private
*/
- DataStep.prototype.setRange = function (start, end, minimumStep, containerHeight, customRange) {
- this._start = customRange.min === undefined ? start : customRange.min;
- this._end = customRange.max === undefined ? end : customRange.max;
- if (this._start === this._end) {
- this._start = customRange.min === undefined ? this._start - 0.75 : this._start;
- this._end = customRange.max === undefined ? this._end + 1 : this._end;;
+ LineGraph.prototype._getRelevantData = function (groupIds, groupsData, minDate, maxDate) {
+ var group, i, j, item;
+ if (groupIds.length > 0) {
+ for (i = 0; i < groupIds.length; i++) {
+ group = this.groups[groupIds[i]];
+ groupsData[groupIds[i]] = [];
+ var dataContainer = groupsData[groupIds[i]];
+ // optimization for sorted data
+ if (group.options.sort == true) {
+ var guess = Math.max(0, util.binarySearchValue(group.itemsData, minDate, 'x', 'before'));
+ for (j = guess; j < group.itemsData.length; j++) {
+ item = group.itemsData[j];
+ if (item !== undefined) {
+ if (item.x > maxDate) {
+ dataContainer.push(item);
+ break;
+ } else {
+ dataContainer.push(item);
+ }
+ }
+ }
+ } else {
+ for (j = 0; j < group.itemsData.length; j++) {
+ item = group.itemsData[j];
+ if (item !== undefined) {
+ if (item.x > minDate && item.x < maxDate) {
+ dataContainer.push(item);
+ }
+ }
+ }
+ }
+ }
}
+ };
- if (this.autoScale === true) {
- this.setMinimumStep(minimumStep, containerHeight);
- }
+ /**
+ *
+ * @param groupIds
+ * @param groupsData
+ * @private
+ */
+ LineGraph.prototype._applySampling = function (groupIds, groupsData) {
+ var group;
+ if (groupIds.length > 0) {
+ for (var i = 0; i < groupIds.length; i++) {
+ group = this.groups[groupIds[i]];
+ if (group.options.sampling == true) {
+ var dataContainer = groupsData[groupIds[i]];
+ if (dataContainer.length > 0) {
+ var increment = 1;
+ var amountOfPoints = dataContainer.length;
- this.setFirst(customRange);
+ // the global screen is used because changing the width of the yAxis may affect the increment, resulting in an endless loop
+ // of width changing of the yAxis.
+ var xDistance = this.body.util.toGlobalScreen(dataContainer[dataContainer.length - 1].x) - this.body.util.toGlobalScreen(dataContainer[0].x);
+ var pointsPerPixel = amountOfPoints / xDistance;
+ increment = Math.min(Math.ceil(0.2 * amountOfPoints), Math.max(1, Math.round(pointsPerPixel)));
+
+ var sampledData = [];
+ for (var j = 0; j < amountOfPoints; j += increment) {
+ sampledData.push(dataContainer[j]);
+ }
+ groupsData[groupIds[i]] = sampledData;
+ }
+ }
+ }
+ }
};
/**
- * Automatically determine the scale that bests fits the provided minimum step
- * @param {Number} [minimumStep] The minimum step size in pixels
+ *
+ *
+ * @param {array} groupIds
+ * @param {object} groupsData
+ * @param {object} groupRanges | this is being filled here
+ * @private
*/
- DataStep.prototype.setMinimumStep = function (minimumStep, containerHeight) {
- // round to floor
- var range = this._end - this._start;
- var safeRange = range * 1.2;
- var minimumStepValue = minimumStep * (safeRange / containerHeight);
- var orderOfMagnitude = Math.round(Math.log(safeRange) / Math.LN10);
-
- var minorStepIdx = -1;
- var magnitudefactor = Math.pow(10, orderOfMagnitude);
+ LineGraph.prototype._getYRanges = function (groupIds, groupsData, groupRanges) {
+ var groupData, group, i;
+ var combinedDataLeft = [];
+ var combinedDataRight = [];
+ var options;
+ if (groupIds.length > 0) {
+ for (i = 0; i < groupIds.length; i++) {
+ groupData = groupsData[groupIds[i]];
+ options = this.groups[groupIds[i]].options;
+ if (groupData.length > 0) {
+ group = this.groups[groupIds[i]];
+ // if bar graphs are stacked, their range need to be handled differently and accumulated over all groups.
+ if (options.stack === true) {
+ if (options.yAxisOrientation == 'left') {
+ combinedDataLeft = combinedDataLeft.concat(group.getData(groupData));
+ } else {
+ combinedDataRight = combinedDataRight.concat(group.getData(groupData));
+ }
+ } else {
+ groupRanges[groupIds[i]] = group.getYRange(groupData, groupIds[i]);
+ }
+ }
+ }
- var start = 0;
- if (orderOfMagnitude < 0) {
- start = orderOfMagnitude;
+ // if bar graphs are stacked, their range need to be handled differently and accumulated over all groups.
+ BarFunctions.getStackedYRange(combinedDataLeft, groupRanges, groupIds, '__barStackLeft', 'left');
+ BarFunctions.getStackedYRange(combinedDataRight, groupRanges, groupIds, '__barStackRight', 'right');
+ // if line graphs are stacked, their range need to be handled differently and accumulated over all groups.
+ LineFunctions.getStackedYRange(combinedDataLeft, groupRanges, groupIds, '__lineStackLeft', 'left');
+ LineFunctions.getStackedYRange(combinedDataRight, groupRanges, groupIds, '__lineStackRight', 'right');
}
+ };
- var solutionFound = false;
- for (var i = start; Math.abs(i) <= Math.abs(orderOfMagnitude); i++) {
- magnitudefactor = Math.pow(10, i);
- for (var j = 0; j < this.minorSteps.length; j++) {
- var stepSize = magnitudefactor * this.minorSteps[j];
- if (stepSize >= minimumStepValue) {
- solutionFound = true;
- minorStepIdx = j;
- break;
+ /**
+ * this sets the Y ranges for the Y axis. It also determines which of the axis should be shown or hidden.
+ * @param {Array} groupIds
+ * @param {Object} groupRanges
+ * @private
+ */
+ LineGraph.prototype._updateYAxis = function (groupIds, groupRanges) {
+ var resized = false;
+ var yAxisLeftUsed = false;
+ var yAxisRightUsed = false;
+ var minLeft = 1000000000,
+ minRight = 1000000000,
+ maxLeft = -1000000000,
+ maxRight = -1000000000,
+ minVal,
+ maxVal;
+ // if groups are present
+ if (groupIds.length > 0) {
+ // this is here to make sure that if there are no items in the axis but there are groups, that there is no infinite draw/redraw loop.
+ for (var i = 0; i < groupIds.length; i++) {
+ var group = this.groups[groupIds[i]];
+ if (group && group.options.yAxisOrientation != 'right') {
+ yAxisLeftUsed = true;
+ minLeft = 0;
+ maxLeft = 0;
+ } else if (group && group.options.yAxisOrientation) {
+ yAxisRightUsed = true;
+ minRight = 0;
+ maxRight = 0;
+ }
+ }
+
+ // if there are items:
+ for (var i = 0; i < groupIds.length; i++) {
+ if (groupRanges.hasOwnProperty(groupIds[i])) {
+ if (groupRanges[groupIds[i]].ignore !== true) {
+ minVal = groupRanges[groupIds[i]].min;
+ maxVal = groupRanges[groupIds[i]].max;
+
+ if (groupRanges[groupIds[i]].yAxisOrientation != 'right') {
+ yAxisLeftUsed = true;
+ minLeft = minLeft > minVal ? minVal : minLeft;
+ maxLeft = maxLeft < maxVal ? maxVal : maxLeft;
+ } else {
+ yAxisRightUsed = true;
+ minRight = minRight > minVal ? minVal : minRight;
+ maxRight = maxRight < maxVal ? maxVal : maxRight;
+ }
+ }
}
}
- if (solutionFound === true) {
- break;
+
+ if (yAxisLeftUsed == true) {
+ this.yAxisLeft.setRange(minLeft, maxLeft);
+ }
+ if (yAxisRightUsed == true) {
+ this.yAxisRight.setRange(minRight, maxRight);
}
}
- this.stepIndex = minorStepIdx;
- this.scale = magnitudefactor;
- this.step = magnitudefactor * this.minorSteps[minorStepIdx];
- };
+ resized = this._toggleAxisVisiblity(yAxisLeftUsed, this.yAxisLeft) || resized;
+ resized = this._toggleAxisVisiblity(yAxisRightUsed, this.yAxisRight) || resized;
- /**
- * Round the current date to the first minor date value
- * This must be executed once when the current date is set to start Date
- */
- DataStep.prototype.setFirst = function (customRange) {
- if (customRange === undefined) {
- customRange = {};
+ if (yAxisRightUsed == true && yAxisLeftUsed == true) {
+ this.yAxisLeft.drawIcons = true;
+ this.yAxisRight.drawIcons = true;
+ } else {
+ this.yAxisLeft.drawIcons = false;
+ this.yAxisRight.drawIcons = false;
}
+ this.yAxisRight.master = !yAxisLeftUsed;
+ if (this.yAxisRight.master == false) {
+ if (yAxisRightUsed == true) {
+ this.yAxisLeft.lineOffset = this.yAxisRight.width;
+ } else {
+ this.yAxisLeft.lineOffset = 0;
+ }
- var niceStart = customRange.min === undefined ? this._start - this.scale * 2 * this.minorSteps[this.stepIndex] : customRange.min;
- var niceEnd = customRange.max === undefined ? this._end + this.scale * this.minorSteps[this.stepIndex] : customRange.max;
-
- this.marginEnd = customRange.max === undefined ? this.roundToMinor(niceEnd) : customRange.max;
- this.marginStart = customRange.min === undefined ? this.roundToMinor(niceStart) : customRange.min;
-
- // if we need to align the zero's we need to make sure that there is a zero to use.
- if (this.alignZeros === true && (this.marginEnd - this.marginStart) % this.step != 0) {
- this.marginEnd += this.marginEnd % this.step;
+ resized = this.yAxisLeft.redraw() || resized;
+ this.yAxisRight.stepPixels = this.yAxisLeft.stepPixels;
+ this.yAxisRight.zeroCrossing = this.yAxisLeft.zeroCrossing;
+ this.yAxisRight.amountOfSteps = this.yAxisLeft.amountOfSteps;
+ resized = this.yAxisRight.redraw() || resized;
+ } else {
+ resized = this.yAxisRight.redraw() || resized;
}
- this.deadSpace = this.roundToMinor(niceEnd) - niceEnd + this.roundToMinor(niceStart) - niceStart;
- this.marginRange = this.marginEnd - this.marginStart;
-
- this.current = this.marginEnd;
- };
-
- DataStep.prototype.roundToMinor = function (value) {
- var rounded = value - value % (this.scale * this.minorSteps[this.stepIndex]);
- if (value % (this.scale * this.minorSteps[this.stepIndex]) > 0.5 * (this.scale * this.minorSteps[this.stepIndex])) {
- return rounded + this.scale * this.minorSteps[this.stepIndex];
- } else {
- return rounded;
+ // clean the accumulated lists
+ var tempGroups = ['__barStackLeft', '__barStackRight', '__lineStackLeft', '__lineStackRight'];
+ for (var i = 0; i < tempGroups.length; i++) {
+ if (groupIds.indexOf(tempGroups[i]) != -1) {
+ groupIds.splice(groupIds.indexOf(tempGroups[i]), 1);
+ }
}
+
+ return resized;
};
/**
- * Check if the there is a next step
- * @return {boolean} true if the current date has not passed the end date
+ * This shows or hides the Y axis if needed. If there is a change, the changed event is emitted by the updateYAxis function
+ *
+ * @param {boolean} axisUsed
+ * @returns {boolean}
+ * @private
+ * @param axis
*/
- DataStep.prototype.hasNext = function () {
- return this.current >= this.marginStart;
+ LineGraph.prototype._toggleAxisVisiblity = function (axisUsed, axis) {
+ var changed = false;
+ if (axisUsed == false) {
+ if (axis.dom.frame.parentNode && axis.hidden == false) {
+ axis.hide();
+ changed = true;
+ }
+ } else {
+ if (!axis.dom.frame.parentNode && axis.hidden == true) {
+ axis.show();
+ changed = true;
+ }
+ }
+ return changed;
};
/**
- * Do the next step
+ * This uses the DataAxis object to generate the correct X coordinate on the SVG window. It uses the
+ * util function toScreen to get the x coordinate from the timestamp. It also pre-filters the data and get the minMax ranges for
+ * the yAxis.
+ *
+ * @param datapoints
+ * @returns {Array}
+ * @private
*/
- DataStep.prototype.next = function () {
- var prev = this.current;
- this.current -= this.step;
+ LineGraph.prototype._convertXcoordinates = function (datapoints) {
+ var extractedData = [];
+ var xValue, yValue;
+ var toScreen = this.body.util.toScreen;
- // safety mechanism: if current time is still unchanged, move to the end
- if (this.current === prev) {
- this.current = this._end;
+ for (var i = 0; i < datapoints.length; i++) {
+ xValue = toScreen(datapoints[i].x) + this.props.width;
+ yValue = datapoints[i].y;
+ extractedData.push({ x: xValue, y: yValue });
}
- };
- /**
- * Do the next step
- */
- DataStep.prototype.previous = function () {
- this.current += this.step;
- this.marginEnd += this.step;
- this.marginRange = this.marginEnd - this.marginStart;
+ return extractedData;
};
/**
- * Get the current datetime
- * @return {String} current The current date
+ * This uses the DataAxis object to generate the correct X coordinate on the SVG window. It uses the
+ * util function toScreen to get the x coordinate from the timestamp. It also pre-filters the data and get the minMax ranges for
+ * the yAxis.
+ *
+ * @param datapoints
+ * @param group
+ * @returns {Array}
+ * @private
*/
- DataStep.prototype.getCurrent = function () {
- // prevent round-off errors when close to zero
- var current = Math.abs(this.current) < this.step / 2 ? 0 : this.current;
- var returnValue = current.toPrecision(5);
- if (typeof this.formattingFunction === 'function') {
- returnValue = this.formattingFunction(current);
+ LineGraph.prototype._convertYcoordinates = function (datapoints, group) {
+ var extractedData = [];
+ var xValue, yValue;
+ var toScreen = this.body.util.toScreen;
+ var axis = this.yAxisLeft;
+ var svgHeight = Number(this.svg.style.height.replace('px', ''));
+ if (group.options.yAxisOrientation == 'right') {
+ axis = this.yAxisRight;
}
- if (typeof returnValue === 'number') {
- return '' + returnValue;
- } else if (typeof returnValue === 'string') {
- return returnValue;
- } else {
- return current.toPrecision(5);
+ for (var i = 0; i < datapoints.length; i++) {
+ var labelValue = datapoints[i].label ? datapoints[i].label : null;
+ xValue = toScreen(datapoints[i].x) + this.props.width;
+ yValue = Math.round(axis.convertValue(datapoints[i].y));
+ extractedData.push({ x: xValue, y: yValue, label: labelValue });
}
- };
- /**
- * Check if the current value is a major value (for example when the step
- * is DAY, a major value is each first day of the MONTH)
- * @return {boolean} true if current date is major, else false.
- */
- DataStep.prototype.isMajor = function () {
- return this.current % (this.scale * this.majorSteps[this.stepIndex]) === 0;
- };
+ group.setZeroPosition(Math.min(svgHeight, axis.convertValue(0)));
- DataStep.prototype.shift = function (steps) {
- if (steps < 0) {
- for (var i = 0; i < -steps; i++) {
- this.previous();
- }
- } else if (steps > 0) {
- for (var i = 0; i < steps; i++) {
- this.next();
- }
- }
+ return extractedData;
};
- module.exports = DataStep;
+ module.exports = LineGraph;
/***/ },
-/* 54 */
+/* 52 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var util = __webpack_require__(9);
var DOMutil = __webpack_require__(14);
- var Line = __webpack_require__(55);
- var Bar = __webpack_require__(57);
- var Points = __webpack_require__(56);
+ var Component = __webpack_require__(28);
+ var DataStep = __webpack_require__(53);
/**
- * /**
- * @param {object} group | the object of the group from the dataset
- * @param {string} groupId | ID of the group
- * @param {object} options | the default options
- * @param {array} groupsUsingDefaultStyles | this array has one entree.
- * It is passed as an array so it is passed by reference.
- * It enumerates through the default styles
- * @constructor
+ * A horizontal time axis
+ * @param {Object} [options] See DataAxis.setOptions for the available
+ * options.
+ * @constructor DataAxis
+ * @extends Component
+ * @param body
*/
- function GraphGroup(group, groupId, options, groupsUsingDefaultStyles) {
- this.id = groupId;
- var fields = ['sampling', 'style', 'sort', 'yAxisOrientation', 'barChart', 'drawPoints', 'shaded', 'interpolation'];
- this.options = util.selectiveBridgeObject(fields, options);
- this.usingDefaultStyle = group.className === undefined;
- this.groupsUsingDefaultStyles = groupsUsingDefaultStyles;
- this.zeroPosition = 0;
- this.update(group);
- if (this.usingDefaultStyle == true) {
- this.groupsUsingDefaultStyles[0] += 1;
- }
- this.itemsData = [];
- this.visible = group.visible === undefined ? true : group.visible;
- }
+ function DataAxis(body, options, svg, linegraphOptions) {
+ this.id = util.randomUUID();
+ this.body = body;
- /**
- * this loads a reference to all items in this group into this group.
- * @param {array} items
- */
- GraphGroup.prototype.setItems = function (items) {
- if (items != null) {
- this.itemsData = items;
- if (this.options.sort == true) {
- this.itemsData.sort(function (a, b) {
- return a.x - b.x;
- });
+ this.defaultOptions = {
+ orientation: 'left', // supported: 'left', 'right'
+ showMinorLabels: true,
+ showMajorLabels: true,
+ icons: true,
+ majorLinesOffset: 7,
+ minorLinesOffset: 4,
+ labelOffsetX: 10,
+ labelOffsetY: 2,
+ iconWidth: 20,
+ width: '40px',
+ visible: true,
+ alignZeros: true,
+ left: {
+ range: { min: undefined, max: undefined },
+ format: function format(value) {
+ return value;
+ },
+ title: { text: undefined, style: undefined }
+ },
+ right: {
+ range: { min: undefined, max: undefined },
+ format: function format(value) {
+ return value;
+ },
+ title: { text: undefined, style: undefined }
}
- } else {
- this.itemsData = [];
+ };
+
+ this.linegraphOptions = linegraphOptions;
+ this.linegraphSVG = svg;
+ this.props = {};
+ this.DOMelements = { // dynamic elements
+ lines: {},
+ labels: {},
+ title: {}
+ };
+
+ this.dom = {};
+
+ this.range = { start: 0, end: 0 };
+
+ this.options = util.extend({}, this.defaultOptions);
+ this.conversionFactor = 1;
+
+ this.setOptions(options);
+ this.width = Number(('' + this.options.width).replace('px', ''));
+ this.minWidth = this.width;
+ this.height = this.linegraphSVG.offsetHeight;
+ this.hidden = false;
+
+ this.stepPixels = 25;
+ this.zeroCrossing = -1;
+ this.amountOfSteps = -1;
+
+ this.lineOffset = 0;
+ this.master = true;
+ this.svgElements = {};
+ this.iconsRemoved = false;
+
+ this.groups = {};
+ this.amountOfGroups = 0;
+
+ // create the HTML DOM
+ this._create();
+
+ var me = this;
+ this.body.emitter.on('verticalDrag', function () {
+ me.dom.lineContainer.style.top = me.body.domProps.scrollTop + 'px';
+ });
+ }
+
+ DataAxis.prototype = new Component();
+
+ DataAxis.prototype.addGroup = function (label, graphOptions) {
+ if (!this.groups.hasOwnProperty(label)) {
+ this.groups[label] = graphOptions;
}
+ this.amountOfGroups += 1;
};
- /**
- * this is used for plotting barcharts, this way, we only have to calculate it once.
- * @param pos
- */
- GraphGroup.prototype.setZeroPosition = function (pos) {
- this.zeroPosition = pos;
+ DataAxis.prototype.updateGroup = function (label, graphOptions) {
+ this.groups[label] = graphOptions;
};
- /**
- * set the options of the graph group over the default options.
- * @param options
- */
- GraphGroup.prototype.setOptions = function (options) {
- if (options !== undefined) {
- var fields = ['sampling', 'style', 'sort', 'yAxisOrientation', 'barChart'];
- util.selectiveDeepExtend(fields, this.options, options);
-
- util.mergeOptions(this.options, options, 'interpolation');
- util.mergeOptions(this.options, options, 'drawPoints');
- util.mergeOptions(this.options, options, 'shaded');
+ DataAxis.prototype.removeGroup = function (label) {
+ if (this.groups.hasOwnProperty(label)) {
+ delete this.groups[label];
+ this.amountOfGroups -= 1;
+ }
+ };
- if (options.interpolation) {
- if (typeof options.interpolation == 'object') {
- if (options.interpolation.parametrization) {
- if (options.interpolation.parametrization == 'uniform') {
- this.options.interpolation.alpha = 0;
- } else if (options.interpolation.parametrization == 'chordal') {
- this.options.interpolation.alpha = 1;
- } else {
- this.options.interpolation.parametrization = 'centripetal';
- this.options.interpolation.alpha = 0.5;
- }
- }
- }
+ DataAxis.prototype.setOptions = function (options) {
+ if (options) {
+ var redraw = false;
+ if (this.options.orientation != options.orientation && options.orientation !== undefined) {
+ redraw = true;
}
- }
+ var fields = ['orientation', 'showMinorLabels', 'showMajorLabels', 'icons', 'majorLinesOffset', 'minorLinesOffset', 'labelOffsetX', 'labelOffsetY', 'iconWidth', 'width', 'visible', 'left', 'right', 'alignZeros'];
+ util.selectiveExtend(fields, this.options, options);
- if (this.options.style == 'line') {
- this.type = new Line(this.id, this.options);
- } else if (this.options.style == 'bar') {
- this.type = new Bar(this.id, this.options);
- } else if (this.options.style == 'points') {
- this.type = new Points(this.id, this.options);
+ this.minWidth = Number(('' + this.options.width).replace('px', ''));
+
+ if (redraw === true && this.dom.frame) {
+ this.hide();
+ this.show();
+ }
}
};
/**
- * this updates the current group class with the latest group dataset entree, used in _updateGroup in linegraph
- * @param group
+ * Create the HTML DOM for the DataAxis
*/
- GraphGroup.prototype.update = function (group) {
- this.group = group;
- this.content = group.content || 'graph';
- this.className = group.className || this.className || 'vis-graph-group' + this.groupsUsingDefaultStyles[0] % 10;
- this.visible = group.visible === undefined ? true : group.visible;
- this.style = group.style;
- this.setOptions(group.options);
+ DataAxis.prototype._create = function () {
+ this.dom.frame = document.createElement('div');
+ this.dom.frame.style.width = this.options.width;
+ this.dom.frame.style.height = this.height;
+
+ this.dom.lineContainer = document.createElement('div');
+ this.dom.lineContainer.style.width = '100%';
+ this.dom.lineContainer.style.height = this.height;
+ this.dom.lineContainer.style.position = 'relative';
+
+ // create svg element for graph drawing.
+ this.svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
+ this.svg.style.position = 'absolute';
+ this.svg.style.top = '0px';
+ this.svg.style.height = '100%';
+ this.svg.style.width = '100%';
+ this.svg.style.display = 'block';
+ this.dom.frame.appendChild(this.svg);
};
- /**
- * draw the icon for the legend.
- *
- * @param x
- * @param y
- * @param JSONcontainer
- * @param SVGcontainer
- * @param iconWidth
- * @param iconHeight
- */
- GraphGroup.prototype.drawIcon = function (x, y, JSONcontainer, SVGcontainer, iconWidth, iconHeight) {
- var fillHeight = iconHeight * 0.5;
- var path, fillPath;
+ DataAxis.prototype._redrawGroupIcons = function () {
+ DOMutil.prepareElements(this.svgElements);
- var outline = DOMutil.getSVGElement('rect', JSONcontainer, SVGcontainer);
- outline.setAttributeNS(null, 'x', x);
- outline.setAttributeNS(null, 'y', y - fillHeight);
- outline.setAttributeNS(null, 'width', iconWidth);
- outline.setAttributeNS(null, 'height', 2 * fillHeight);
- outline.setAttributeNS(null, 'class', 'vis-outline');
+ var x;
+ var iconWidth = this.options.iconWidth;
+ var iconHeight = 15;
+ var iconOffset = 4;
+ var y = iconOffset + 0.5 * iconHeight;
- if (this.options.style == 'line') {
- path = DOMutil.getSVGElement('path', JSONcontainer, SVGcontainer);
- path.setAttributeNS(null, 'class', this.className);
- if (this.style !== undefined) {
- path.setAttributeNS(null, 'style', this.style);
- }
+ if (this.options.orientation === 'left') {
+ x = iconOffset;
+ } else {
+ x = this.width - iconWidth - iconOffset;
+ }
- path.setAttributeNS(null, 'd', 'M' + x + ',' + y + ' L' + (x + iconWidth) + ',' + y + '');
- if (this.options.shaded.enabled == true) {
- fillPath = DOMutil.getSVGElement('path', JSONcontainer, SVGcontainer);
- if (this.options.shaded.orientation == 'top') {
- fillPath.setAttributeNS(null, 'd', 'M' + x + ', ' + (y - fillHeight) + 'L' + x + ',' + y + ' L' + (x + iconWidth) + ',' + y + ' L' + (x + iconWidth) + ',' + (y - fillHeight));
- } else {
- fillPath.setAttributeNS(null, 'd', 'M' + x + ',' + y + ' ' + 'L' + x + ',' + (y + fillHeight) + ' ' + 'L' + (x + iconWidth) + ',' + (y + fillHeight) + 'L' + (x + iconWidth) + ',' + y);
- }
- fillPath.setAttributeNS(null, 'class', this.className + ' vis-icon-fill');
+ var groupArray = Object.keys(this.groups);
+ groupArray.sort(function (a, b) {
+ return a < b ? -1 : 1;
+ });
+
+ for (var i = 0; i < groupArray.length; i++) {
+ var groupId = groupArray[i];
+ if (this.groups[groupId].visible === true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] === true)) {
+ this.groups[groupId].drawIcon(x, y, this.svgElements, this.svg, iconWidth, iconHeight);
+ y += iconHeight + iconOffset;
}
+ }
- if (this.options.drawPoints.enabled == true) {
- DOMutil.drawPoint(x + 0.5 * iconWidth, y, this, JSONcontainer, SVGcontainer);
+ DOMutil.cleanupElements(this.svgElements);
+ this.iconsRemoved = false;
+ };
+
+ DataAxis.prototype._cleanupIcons = function () {
+ if (this.iconsRemoved === false) {
+ DOMutil.prepareElements(this.svgElements);
+ DOMutil.cleanupElements(this.svgElements);
+ this.iconsRemoved = true;
+ }
+ };
+
+ /**
+ * Create the HTML DOM for the DataAxis
+ */
+ DataAxis.prototype.show = function () {
+ this.hidden = false;
+ if (!this.dom.frame.parentNode) {
+ if (this.options.orientation === 'left') {
+ this.body.dom.left.appendChild(this.dom.frame);
+ } else {
+ this.body.dom.right.appendChild(this.dom.frame);
}
- } else {
- var barWidth = Math.round(0.3 * iconWidth);
- var bar1Height = Math.round(0.4 * iconHeight);
- var bar2Height = Math.round(0.75 * iconHeight);
+ }
- var offset = Math.round((iconWidth - 2 * barWidth) / 3);
+ if (!this.dom.lineContainer.parentNode) {
+ this.body.dom.backgroundHorizontal.appendChild(this.dom.lineContainer);
+ }
+ };
- DOMutil.drawBar(x + 0.5 * barWidth + offset, y + fillHeight - bar1Height - 1, barWidth, bar1Height, this.className + ' vis-bar', JSONcontainer, SVGcontainer, this.style);
- DOMutil.drawBar(x + 1.5 * barWidth + offset + 2, y + fillHeight - bar2Height - 1, barWidth, bar2Height, this.className + ' vis-bar', JSONcontainer, SVGcontainer, this.style);
+ /**
+ * Create the HTML DOM for the DataAxis
+ */
+ DataAxis.prototype.hide = function () {
+ this.hidden = true;
+ if (this.dom.frame.parentNode) {
+ this.dom.frame.parentNode.removeChild(this.dom.frame);
+ }
+
+ if (this.dom.lineContainer.parentNode) {
+ this.dom.lineContainer.parentNode.removeChild(this.dom.lineContainer);
}
};
/**
- * return the legend entree for this group.
- *
- * @param iconWidth
- * @param iconHeight
- * @returns {{icon: HTMLElement, label: (group.content|*|string), orientation: (.options.yAxisOrientation|*)}}
+ * Set a range (start and end)
+ * @param end
+ * @param start
+ * @param end
*/
- GraphGroup.prototype.getLegend = function (iconWidth, iconHeight) {
- var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
- this.drawIcon(0, 0.5 * iconHeight, [], svg, iconWidth, iconHeight);
- return { icon: svg, label: this.content, orientation: this.options.yAxisOrientation };
+ DataAxis.prototype.setRange = function (start, end) {
+ if (this.master === false && this.options.alignZeros === true && this.zeroCrossing != -1) {
+ if (start > 0) {
+ start = 0;
+ }
+ }
+ this.range.start = start;
+ this.range.end = end;
};
- GraphGroup.prototype.getYRange = function (groupData) {
- return this.type.getYRange(groupData);
- };
+ /**
+ * Repaint the component
+ * @return {boolean} Returns true if the component is resized
+ */
+ DataAxis.prototype.redraw = function () {
+ var resized = false;
+ var activeGroups = 0;
- GraphGroup.prototype.getData = function (groupData) {
- return this.type.getData(groupData);
- };
+ // Make sure the line container adheres to the vertical scrolling.
+ this.dom.lineContainer.style.top = this.body.domProps.scrollTop + 'px';
- GraphGroup.prototype.draw = function (dataset, group, framework) {
- this.type.draw(dataset, group, framework);
- };
+ for (var groupId in this.groups) {
+ if (this.groups.hasOwnProperty(groupId)) {
+ if (this.groups[groupId].visible === true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] === true)) {
+ activeGroups++;
+ }
+ }
+ }
+ if (this.amountOfGroups === 0 || activeGroups === 0) {
+ this.hide();
+ } else {
+ this.show();
+ this.height = Number(this.linegraphSVG.style.height.replace('px', ''));
- module.exports = GraphGroup;
+ // svg offsetheight did not work in firefox and explorer...
+ this.dom.lineContainer.style.height = this.height + 'px';
+ this.width = this.options.visible === true ? Number(('' + this.options.width).replace('px', '')) : 0;
-/***/ },
-/* 55 */
-/***/ function(module, exports, __webpack_require__) {
+ var props = this.props;
+ var frame = this.dom.frame;
- 'use strict';
+ // update classname
+ frame.className = 'vis-data-axis';
- var DOMutil = __webpack_require__(14);
- var Points = __webpack_require__(56);
+ // calculate character width and height
+ this._calculateCharSize();
- function Line(groupId, options) {
- this.groupId = groupId;
- this.options = options;
- }
+ var orientation = this.options.orientation;
+ var showMinorLabels = this.options.showMinorLabels;
+ var showMajorLabels = this.options.showMajorLabels;
- Line.prototype.getData = function (groupData) {
- var combinedData = [];
- for (var j = 0; j < groupData.length; j++) {
- combinedData.push({
- x: groupData[j].x,
- y: groupData[j].y,
- groupId: this.groupId
- });
- }
- return combinedData;
- };
+ // determine the width and height of the elements for the axis
+ props.minorLabelHeight = showMinorLabels ? props.minorCharHeight : 0;
+ props.majorLabelHeight = showMajorLabels ? props.majorCharHeight : 0;
- Line.prototype.getYRange = function (groupData) {
- var yMin = groupData[0].y;
- var yMax = groupData[0].y;
- for (var j = 0; j < groupData.length; j++) {
- yMin = yMin > groupData[j].y ? groupData[j].y : yMin;
- yMax = yMax < groupData[j].y ? groupData[j].y : yMax;
- }
- return { min: yMin, max: yMax, yAxisOrientation: this.options.yAxisOrientation };
- };
+ props.minorLineWidth = this.body.dom.backgroundHorizontal.offsetWidth - this.lineOffset - this.width + 2 * this.options.minorLinesOffset;
+ props.minorLineHeight = 1;
+ props.majorLineWidth = this.body.dom.backgroundHorizontal.offsetWidth - this.lineOffset - this.width + 2 * this.options.majorLinesOffset;
+ props.majorLineHeight = 1;
- Line.getStackedYRange = function (combinedData, groupRanges, groupIds, groupLabel, orientation) {
- if (combinedData.length > 0) {
- // sort by time and by group
- combinedData.sort(function (a, b) {
- if (a.x === b.x) {
- return a.groupId < b.groupId ? -1 : 1;
- } else {
- return a.x - b.x;
- }
- });
- var intersections = {};
+ // take frame offline while updating (is almost twice as fast)
+ if (orientation === 'left') {
+ frame.style.top = '0';
+ frame.style.left = '0';
+ frame.style.bottom = '';
+ frame.style.width = this.width + 'px';
+ frame.style.height = this.height + 'px';
+ this.props.width = this.body.domProps.left.width;
+ this.props.height = this.body.domProps.left.height;
+ } else {
+ // right
+ frame.style.top = '';
+ frame.style.bottom = '0';
+ frame.style.left = '0';
+ frame.style.width = this.width + 'px';
+ frame.style.height = this.height + 'px';
+ this.props.width = this.body.domProps.right.width;
+ this.props.height = this.body.domProps.right.height;
+ }
- Line._getDataIntersections(intersections, combinedData);
- groupRanges[groupLabel] = Line._getStackedYRange(intersections, combinedData);
- groupRanges[groupLabel].yAxisOrientation = orientation;
- groupIds.push(groupLabel);
- }
- };
+ resized = this._redrawLabels();
+ resized = this._isResized() || resized;
- Line._getStackedYRange = function (intersections, combinedData) {
- var key;
- var yMin = combinedData[0].y;
- var yMax = combinedData[0].y;
- for (var i = 0; i < combinedData.length; i++) {
- key = combinedData[i].x;
- if (intersections[key] === undefined) {
- yMin = yMin > combinedData[i].y ? combinedData[i].y : yMin;
- yMax = yMax < combinedData[i].y ? combinedData[i].y : yMax;
+ if (this.options.icons === true) {
+ this._redrawGroupIcons();
} else {
- if (combinedData[i].y < 0) {
- intersections[key].accumulatedNegative += combinedData[i].y;
- } else {
- intersections[key].accumulatedPositive += combinedData[i].y;
- }
- }
- }
- for (var xpos in intersections) {
- if (intersections.hasOwnProperty(xpos)) {
- yMin = yMin > intersections[xpos].accumulatedNegative ? intersections[xpos].accumulatedNegative : yMin;
- yMin = yMin > intersections[xpos].accumulatedPositive ? intersections[xpos].accumulatedPositive : yMin;
- yMax = yMax < intersections[xpos].accumulatedNegative ? intersections[xpos].accumulatedNegative : yMax;
- yMax = yMax < intersections[xpos].accumulatedPositive ? intersections[xpos].accumulatedPositive : yMax;
+ this._cleanupIcons();
}
- }
- return { min: yMin, max: yMax };
+ this._redrawTitle(orientation);
+ }
+ return resized;
};
/**
- * Fill the intersections object with counters of how many datapoints share the same x coordinates
- * @param intersections
- * @param combinedData
+ * Repaint major and minor text labels and vertical grid lines
* @private
*/
- Line._getDataIntersections = function (intersections, combinedData) {
- // get intersections
- var coreDistance;
- for (var i = 0; i < combinedData.length; i++) {
- if (i + 1 < combinedData.length) {
- coreDistance = Math.abs(combinedData[i + 1].x - combinedData[i].x);
- }
- if (i > 0) {
- coreDistance = Math.min(coreDistance, Math.abs(combinedData[i - 1].x - combinedData[i].x));
- }
- if (coreDistance === 0) {
- if (intersections[combinedData[i].x] === undefined) {
- intersections[combinedData[i].x] = { amount: 0, resolved: 0, accumulatedPositive: 0, accumulatedNegative: 0 };
+ DataAxis.prototype._redrawLabels = function () {
+ var resized = false;
+ DOMutil.prepareElements(this.DOMelements.lines);
+ DOMutil.prepareElements(this.DOMelements.labels);
+ var orientation = this.options['orientation'];
+
+ // get the range for the slaved axis
+ var step;
+ if (this.master === false) {
+ var stepSize, rangeStart, rangeEnd, minimumStep;
+ if (this.zeroCrossing !== -1 && this.options.alignZeros === true) {
+ if (this.range.end > 0) {
+ stepSize = this.range.end / this.zeroCrossing; // size of one step
+ rangeStart = this.range.end - this.amountOfSteps * stepSize;
+ rangeEnd = this.range.end;
+ } else {
+ // all of the range (including start) has to be done before the zero crossing.
+ stepSize = -1 * this.range.start / (this.amountOfSteps - this.zeroCrossing); // absolute size of a step
+ rangeStart = this.range.start;
+ rangeEnd = this.range.start + stepSize * this.amountOfSteps;
}
- intersections[combinedData[i].x].amount += 1;
+ } else {
+ rangeStart = this.range.start;
+ rangeEnd = this.range.end;
}
+ minimumStep = this.stepPixels;
+ } else {
+ // calculate range and step (step such that we have space for 7 characters per label)
+ minimumStep = this.props.majorCharHeight;
+ rangeStart = this.range.start;
+ rangeEnd = this.range.end;
}
- };
- /**
- * draw a line graph
- *
- * @param dataset
- * @param group
- */
- Line.prototype.draw = function (dataset, group, framework) {
- if (dataset != null) {
- if (dataset.length > 0) {
- var path, d;
- var svgHeight = Number(framework.svg.style.height.replace('px', ''));
- path = DOMutil.getSVGElement('path', framework.svgElements, framework.svg);
- path.setAttributeNS(null, 'class', group.className);
- if (group.style !== undefined) {
- path.setAttributeNS(null, 'style', group.style);
- }
+ this.step = step = new DataStep(rangeStart, rangeEnd, minimumStep, this.dom.frame.offsetHeight, this.options[this.options.orientation].range, this.options[this.options.orientation].format, this.master === false && this.options.alignZeros // does the step have to align zeros? only if not master and the options is on
+ );
- // construct path from dataset
- if (group.options.interpolation.enabled == true) {
- d = Line._catmullRom(dataset, group);
- } else {
- d = Line._linear(dataset);
+ // the slave axis needs to use the same horizontal lines as the master axis.
+ if (this.master === true) {
+ this.stepPixels = this.dom.frame.offsetHeight / step.marginRange * step.step;
+ this.amountOfSteps = Math.ceil(this.dom.frame.offsetHeight / this.stepPixels);
+ } else {
+ // align with zero
+ if (this.options.alignZeros === true && this.zeroCrossing !== -1) {
+ // distance is the amount of steps away from the zero crossing we are.
+ var distance = (step.current - this.zeroCrossing * step.step) / step.step;
+ this.step.shift(distance);
+ }
+ }
+
+ // value at the bottom of the SVG
+ this.valueAtBottom = step.marginEnd;
+
+ this.maxLabelSize = 0;
+ var y = 0; // init value
+ var stepIndex = 0; // init value
+ var isMajor = false; // init value
+ while (stepIndex < this.amountOfSteps) {
+ y = Math.round(stepIndex * this.stepPixels);
+ isMajor = step.isMajor();
+
+ if (stepIndex > 0 && stepIndex !== this.amountOfSteps) {
+ if (this.options['showMinorLabels'] && isMajor === false || this.master === false && this.options['showMinorLabels'] === true) {
+ this._redrawLabel(y - 2, step.getCurrent(), orientation, 'vis-y-axis vis-minor', this.props.minorCharHeight);
}
- // append with points for fill and finalize the path
- if (group.options.shaded.enabled == true) {
- var fillPath = DOMutil.getSVGElement('path', framework.svgElements, framework.svg);
- var dFill;
- if (group.options.shaded.orientation == 'top') {
- dFill = 'M' + dataset[0].x + ',' + 0 + ' ' + d + 'L' + dataset[dataset.length - 1].x + ',' + 0;
- } else {
- dFill = 'M' + dataset[0].x + ',' + svgHeight + ' ' + d + 'L' + dataset[dataset.length - 1].x + ',' + svgHeight;
- }
- fillPath.setAttributeNS(null, 'class', group.className + ' vis-fill');
- if (group.options.shaded.style !== undefined) {
- fillPath.setAttributeNS(null, 'style', group.options.shaded.style);
+ if (isMajor && this.options['showMajorLabels'] && this.master === true || this.options['showMinorLabels'] === false && this.master === false && isMajor === true) {
+ if (y >= 0) {
+ this._redrawLabel(y - 2, step.getCurrent(), orientation, 'vis-y-axis vis-major', this.props.majorCharHeight);
}
- fillPath.setAttributeNS(null, 'd', dFill);
+ this._redrawLine(y, orientation, 'vis-grid vis-horizontal vis-major', this.options.majorLinesOffset, this.props.majorLineWidth);
+ } else {
+ this._redrawLine(y, orientation, 'vis-grid vis-horizontal vis-minor', this.options.minorLinesOffset, this.props.minorLineWidth);
}
- // copy properties to path for drawing.
- path.setAttributeNS(null, 'd', 'M' + d);
+ }
- // draw points
- if (group.options.drawPoints.enabled == true) {
- Points.draw(dataset, group, framework);
- }
+ // get zero crossing
+ if (this.master === true && step.current === 0) {
+ this.zeroCrossing = stepIndex;
}
- }
- };
- /**
- * This uses an uniform parametrization of the interpolation algorithm:
- * 'On the Parameterization of Catmull-Rom Curves' by Cem Yuksel et al.
- * @param data
- * @returns {string}
- * @private
- */
- Line._catmullRomUniform = function (data) {
- // catmull rom
- var p0, p1, p2, p3, bp1, bp2;
- var d = Math.round(data[0].x) + ',' + Math.round(data[0].y) + ' ';
- var normalization = 1 / 6;
- var length = data.length;
- for (var i = 0; i < length - 1; i++) {
+ step.next();
+ stepIndex += 1;
+ }
- p0 = i == 0 ? data[0] : data[i - 1];
- p1 = data[i];
- p2 = data[i + 1];
- p3 = i + 2 < length ? data[i + 2] : p2;
+ // get zero crossing if it's the last step
+ if (this.master === true && step.current === 0) {
+ this.zeroCrossing = stepIndex;
+ }
- // Catmull-Rom to Cubic Bezier conversion matrix
- // 0 1 0 0
- // -1/6 1 1/6 0
- // 0 1/6 1 -1/6
- // 0 0 1 0
+ this.conversionFactor = this.stepPixels / step.step;
- // bp0 = { x: p1.x, y: p1.y };
- bp1 = { x: (-p0.x + 6 * p1.x + p2.x) * normalization, y: (-p0.y + 6 * p1.y + p2.y) * normalization };
- bp2 = { x: (p1.x + 6 * p2.x - p3.x) * normalization, y: (p1.y + 6 * p2.y - p3.y) * normalization };
- // bp0 = { x: p2.x, y: p2.y };
+ // Note that title is rotated, so we're using the height, not width!
+ var titleWidth = 0;
+ if (this.options[orientation].title !== undefined && this.options[orientation].title.text !== undefined) {
+ titleWidth = this.props.titleCharHeight;
+ }
+ var offset = this.options.icons === true ? Math.max(this.options.iconWidth, titleWidth) + this.options.labelOffsetX + 15 : titleWidth + this.options.labelOffsetX + 15;
- d += 'C' + bp1.x + ',' + bp1.y + ' ' + bp2.x + ',' + bp2.y + ' ' + p2.x + ',' + p2.y + ' ';
+ // this will resize the yAxis to accommodate the labels.
+ if (this.maxLabelSize > this.width - offset && this.options.visible === true) {
+ this.width = this.maxLabelSize + offset;
+ this.options.width = this.width + 'px';
+ DOMutil.cleanupElements(this.DOMelements.lines);
+ DOMutil.cleanupElements(this.DOMelements.labels);
+ this.redraw();
+ resized = true;
+ }
+ // this will resize the yAxis if it is too big for the labels.
+ else if (this.maxLabelSize < this.width - offset && this.options.visible === true && this.width > this.minWidth) {
+ this.width = Math.max(this.minWidth, this.maxLabelSize + offset);
+ this.options.width = this.width + 'px';
+ DOMutil.cleanupElements(this.DOMelements.lines);
+ DOMutil.cleanupElements(this.DOMelements.labels);
+ this.redraw();
+ resized = true;
+ } else {
+ DOMutil.cleanupElements(this.DOMelements.lines);
+ DOMutil.cleanupElements(this.DOMelements.labels);
+ resized = false;
}
- return d;
+ return resized;
+ };
+
+ DataAxis.prototype.convertValue = function (value) {
+ var invertedValue = this.valueAtBottom - value;
+ var convertedValue = invertedValue * this.conversionFactor;
+ return convertedValue;
+ };
+
+ DataAxis.prototype.screenToValue = function (x) {
+ return this.valueAtBottom - x / this.conversionFactor;
};
/**
- * This uses either the chordal or centripetal parameterization of the catmull-rom algorithm.
- * By default, the centripetal parameterization is used because this gives the nicest results.
- * These parameterizations are relatively heavy because the distance between 4 points have to be calculated.
- *
- * One optimization can be used to reuse distances since this is a sliding window approach.
- * @param data
- * @param group
- * @returns {string}
+ * Create a label for the axis at position x
* @private
+ * @param y
+ * @param text
+ * @param orientation
+ * @param className
+ * @param characterHeight
*/
- Line._catmullRom = function (data, group) {
- var alpha = group.options.interpolation.alpha;
- if (alpha == 0 || alpha === undefined) {
- return this._catmullRomUniform(data);
+ DataAxis.prototype._redrawLabel = function (y, text, orientation, className, characterHeight) {
+ // reuse redundant label
+ var label = DOMutil.getDOMElement('div', this.DOMelements.labels, this.dom.frame); //this.dom.redundant.labels.shift();
+ label.className = className;
+ label.innerHTML = text;
+ if (orientation === 'left') {
+ label.style.left = '-' + this.options.labelOffsetX + 'px';
+ label.style.textAlign = 'right';
} else {
- var p0, p1, p2, p3, bp1, bp2, d1, d2, d3, A, B, N, M;
- var d3powA, d2powA, d3pow2A, d2pow2A, d1pow2A, d1powA;
- var d = Math.round(data[0].x) + ',' + Math.round(data[0].y) + ' ';
- var length = data.length;
- for (var i = 0; i < length - 1; i++) {
-
- p0 = i == 0 ? data[0] : data[i - 1];
- p1 = data[i];
- p2 = data[i + 1];
- p3 = i + 2 < length ? data[i + 2] : p2;
-
- d1 = Math.sqrt(Math.pow(p0.x - p1.x, 2) + Math.pow(p0.y - p1.y, 2));
- d2 = Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
- d3 = Math.sqrt(Math.pow(p2.x - p3.x, 2) + Math.pow(p2.y - p3.y, 2));
-
- // Catmull-Rom to Cubic Bezier conversion matrix
-
- // A = 2d1^2a + 3d1^a * d2^a + d3^2a
- // B = 2d3^2a + 3d3^a * d2^a + d2^2a
-
- // [ 0 1 0 0 ]
- // [ -d2^2a /N A/N d1^2a /N 0 ]
- // [ 0 d3^2a /M B/M -d2^2a /M ]
- // [ 0 0 1 0 ]
-
- d3powA = Math.pow(d3, alpha);
- d3pow2A = Math.pow(d3, 2 * alpha);
- d2powA = Math.pow(d2, alpha);
- d2pow2A = Math.pow(d2, 2 * alpha);
- d1powA = Math.pow(d1, alpha);
- d1pow2A = Math.pow(d1, 2 * alpha);
-
- A = 2 * d1pow2A + 3 * d1powA * d2powA + d2pow2A;
- B = 2 * d3pow2A + 3 * d3powA * d2powA + d2pow2A;
- N = 3 * d1powA * (d1powA + d2powA);
- if (N > 0) {
- N = 1 / N;
- }
- M = 3 * d3powA * (d3powA + d2powA);
- if (M > 0) {
- M = 1 / M;
- }
-
- bp1 = { x: (-d2pow2A * p0.x + A * p1.x + d1pow2A * p2.x) * N,
- y: (-d2pow2A * p0.y + A * p1.y + d1pow2A * p2.y) * N };
+ label.style.right = '-' + this.options.labelOffsetX + 'px';
+ label.style.textAlign = 'left';
+ }
- bp2 = { x: (d3pow2A * p1.x + B * p2.x - d2pow2A * p3.x) * M,
- y: (d3pow2A * p1.y + B * p2.y - d2pow2A * p3.y) * M };
+ label.style.top = y - 0.5 * characterHeight + this.options.labelOffsetY + 'px';
- if (bp1.x == 0 && bp1.y == 0) {
- bp1 = p1;
- }
- if (bp2.x == 0 && bp2.y == 0) {
- bp2 = p2;
- }
- d += 'C' + bp1.x + ',' + bp1.y + ' ' + bp2.x + ',' + bp2.y + ' ' + p2.x + ',' + p2.y + ' ';
- }
+ text += '';
- return d;
+ var largestWidth = Math.max(this.props.majorCharWidth, this.props.minorCharWidth);
+ if (this.maxLabelSize < text.length * largestWidth) {
+ this.maxLabelSize = text.length * largestWidth;
}
};
/**
- * this generates the SVG path for a linear drawing between datapoints.
- * @param data
- * @returns {string}
- * @private
+ * Create a minor line for the axis at position y
+ * @param y
+ * @param orientation
+ * @param className
+ * @param offset
+ * @param width
*/
- Line._linear = function (data) {
- // linear
- var d = '';
- for (var i = 0; i < data.length; i++) {
- if (i == 0) {
- d += data[i].x + ',' + data[i].y;
+ DataAxis.prototype._redrawLine = function (y, orientation, className, offset, width) {
+ if (this.master === true) {
+ var line = DOMutil.getDOMElement('div', this.DOMelements.lines, this.dom.lineContainer); //this.dom.redundant.lines.shift();
+ line.className = className;
+ line.innerHTML = '';
+
+ if (orientation === 'left') {
+ line.style.left = this.width - offset + 'px';
} else {
- d += ' ' + data[i].x + ',' + data[i].y;
+ line.style.right = this.width - offset + 'px';
}
+
+ line.style.width = width + 'px';
+ line.style.top = y + 'px';
}
- return d;
};
- module.exports = Line;
-
-/***/ },
-/* 56 */
-/***/ function(module, exports, __webpack_require__) {
+ /**
+ * Create a title for the axis
+ * @private
+ * @param orientation
+ */
+ DataAxis.prototype._redrawTitle = function (orientation) {
+ DOMutil.prepareElements(this.DOMelements.title);
- 'use strict';
+ // Check if the title is defined for this axes
+ if (this.options[orientation].title !== undefined && this.options[orientation].title.text !== undefined) {
+ var title = DOMutil.getDOMElement('div', this.DOMelements.title, this.dom.frame);
+ title.className = 'vis-y-axis vis-title vis-' + orientation;
+ title.innerHTML = this.options[orientation].title.text;
- var DOMutil = __webpack_require__(14);
+ // Add style - if provided
+ if (this.options[orientation].title.style !== undefined) {
+ util.addCssText(title, this.options[orientation].title.style);
+ }
- function Points(groupId, options) {
- this.groupId = groupId;
- this.options = options;
- }
+ if (orientation === 'left') {
+ title.style.left = this.props.titleCharHeight + 'px';
+ } else {
+ title.style.right = this.props.titleCharHeight + 'px';
+ }
- Points.prototype.getYRange = function (groupData) {
- var yMin = groupData[0].y;
- var yMax = groupData[0].y;
- for (var j = 0; j < groupData.length; j++) {
- yMin = yMin > groupData[j].y ? groupData[j].y : yMin;
- yMax = yMax < groupData[j].y ? groupData[j].y : yMax;
+ title.style.width = this.height + 'px';
}
- return { min: yMin, max: yMax, yAxisOrientation: this.options.yAxisOrientation };
- };
- Points.prototype.draw = function (dataset, group, framework, offset) {
- Points.draw(dataset, group, framework, offset);
+ // we need to clean up in case we did not use all elements.
+ DOMutil.cleanupElements(this.DOMelements.title);
};
/**
- * draw the data points
- *
- * @param {Array} dataset
- * @param {Object} JSONcontainer
- * @param {Object} svg | SVG DOM element
- * @param {GraphGroup} group
- * @param {Number} [offset]
+ * Determine the size of text on the axis (both major and minor axis).
+ * The size is calculated only once and then cached in this.props.
+ * @private
*/
- Points.draw = function (dataset, group, framework, offset) {
- if (offset === undefined) {
- offset = 0;
- }
- for (var i = 0; i < dataset.length; i++) {
- DOMutil.drawPoint(dataset[i].x + offset, dataset[i].y, group, framework.svgElements, framework.svg, dataset[i].label);
+ DataAxis.prototype._calculateCharSize = function () {
+ // determine the char width and height on the minor axis
+ if (!('minorCharHeight' in this.props)) {
+ var textMinor = document.createTextNode('0');
+ var measureCharMinor = document.createElement('div');
+ measureCharMinor.className = 'vis-y-axis vis-minor vis-measure';
+ measureCharMinor.appendChild(textMinor);
+ this.dom.frame.appendChild(measureCharMinor);
+
+ this.props.minorCharHeight = measureCharMinor.clientHeight;
+ this.props.minorCharWidth = measureCharMinor.clientWidth;
+
+ this.dom.frame.removeChild(measureCharMinor);
}
- };
- module.exports = Points;
+ if (!('majorCharHeight' in this.props)) {
+ var textMajor = document.createTextNode('0');
+ var measureCharMajor = document.createElement('div');
+ measureCharMajor.className = 'vis-y-axis vis-major vis-measure';
+ measureCharMajor.appendChild(textMajor);
+ this.dom.frame.appendChild(measureCharMajor);
-/***/ },
-/* 57 */
-/***/ function(module, exports, __webpack_require__) {
+ this.props.majorCharHeight = measureCharMajor.clientHeight;
+ this.props.majorCharWidth = measureCharMajor.clientWidth;
- 'use strict';
+ this.dom.frame.removeChild(measureCharMajor);
+ }
- var DOMutil = __webpack_require__(14);
- var Points = __webpack_require__(56);
+ if (!('titleCharHeight' in this.props)) {
+ var textTitle = document.createTextNode('0');
+ var measureCharTitle = document.createElement('div');
+ measureCharTitle.className = 'vis-y-axis vis-title vis-measure';
+ measureCharTitle.appendChild(textTitle);
+ this.dom.frame.appendChild(measureCharTitle);
- function Bargraph(groupId, options) {
- this.groupId = groupId;
- this.options = options;
- }
+ this.props.titleCharHeight = measureCharTitle.clientHeight;
+ this.props.titleCharWidth = measureCharTitle.clientWidth;
- Bargraph.prototype.getYRange = function (groupData) {
- var yMin = groupData[0].y;
- var yMax = groupData[0].y;
- for (var j = 0; j < groupData.length; j++) {
- yMin = yMin > groupData[j].y ? groupData[j].y : yMin;
- yMax = yMax < groupData[j].y ? groupData[j].y : yMax;
+ this.dom.frame.removeChild(measureCharTitle);
}
- return { min: yMin, max: yMax, yAxisOrientation: this.options.yAxisOrientation };
};
- Bargraph.prototype.getData = function (groupData) {
- var combinedData = [];
- for (var j = 0; j < groupData.length; j++) {
- combinedData.push({
- x: groupData[j].x,
- y: groupData[j].y,
- groupId: this.groupId
- });
- }
- return combinedData;
- };
+ module.exports = DataAxis;
+
+/***/ },
+/* 53 */
+/***/ function(module, exports, __webpack_require__) {
/**
- * draw a bar graph
+ * @constructor DataStep
+ * The class DataStep is an iterator for data for the lineGraph. You provide a start data point and an
+ * end data point. The class itself determines the best scale (step size) based on the
+ * provided start Date, end Date, and minimumStep.
*
- * @param groupIds
- * @param processedGroupData
+ * If minimumStep is provided, the step size is chosen as close as possible
+ * to the minimumStep but larger than minimumStep. If minimumStep is not
+ * provided, the scale is set to 1 DAY.
+ * The minimumStep should correspond with the onscreen size of about 6 characters
+ *
+ * Alternatively, you can set a scale by hand.
+ * After creation, you can initialize the class by executing first(). Then you
+ * can iterate from the start date to the end date via next(). You can check if
+ * the end date is reached with the function hasNext(). After each step, you can
+ * retrieve the current date via getCurrent().
+ * The DataStep has scales ranging from milliseconds, seconds, minutes, hours,
+ * days, to years.
+ *
+ * Version: 1.2
+ *
+ * @param {Date} [start] The start date, for example new Date(2010, 9, 21)
+ * or new Date(2010, 9, 21, 23, 45, 00)
+ * @param {Date} [end] The end date
+ * @param {Number} [minimumStep] Optional. Minimum step size in milliseconds
*/
- Bargraph.draw = function (groupIds, processedGroupData, framework) {
- var combinedData = [];
- var intersections = {};
- var coreDistance;
- var key, drawData;
- var group;
- var i, j;
- var barPoints = 0;
-
- // combine all barchart data
- for (i = 0; i < groupIds.length; i++) {
- group = framework.groups[groupIds[i]];
- if (group.options.style === 'bar') {
- if (group.visible === true && (framework.options.groups.visibility[groupIds[i]] === undefined || framework.options.groups.visibility[groupIds[i]] === true)) {
- for (j = 0; j < processedGroupData[groupIds[i]].length; j++) {
- combinedData.push({
- x: processedGroupData[groupIds[i]][j].x,
- y: processedGroupData[groupIds[i]][j].y,
- groupId: groupIds[i],
- label: processedGroupData[groupIds[i]][j].label
- });
- barPoints += 1;
- }
- }
- }
- }
+ 'use strict';
- if (barPoints === 0) {
- return;
- }
+ function DataStep(start, end, minimumStep, containerHeight, customRange, formattingFunction, alignZeros) {
+ // variables
+ this.current = 0;
- // sort by time and by group
- combinedData.sort(function (a, b) {
- if (a.x === b.x) {
- return a.groupId < b.groupId ? -1 : 1;
- } else {
- return a.x - b.x;
- }
- });
+ this.autoScale = true;
+ this.stepIndex = 0;
+ this.step = 1;
+ this.scale = 1;
+ this.formattingFunction = formattingFunction;
- // get intersections
- Bargraph._getDataIntersections(intersections, combinedData);
+ this.marginStart;
+ this.marginEnd;
+ this.deadSpace = 0;
- // plot barchart
- for (i = 0; i < combinedData.length; i++) {
- group = framework.groups[combinedData[i].groupId];
- var minWidth = 0.1 * group.options.barChart.width;
+ this.majorSteps = [1, 2, 5, 10];
+ this.minorSteps = [0.25, 0.5, 1, 2];
- key = combinedData[i].x;
- var heightOffset = 0;
- if (intersections[key] === undefined) {
- if (i + 1 < combinedData.length) {
- coreDistance = Math.abs(combinedData[i + 1].x - key);
- }
- if (i > 0) {
- coreDistance = Math.min(coreDistance, Math.abs(combinedData[i - 1].x - key));
- }
- drawData = Bargraph._getSafeDrawData(coreDistance, group, minWidth);
- } else {
- var nextKey = i + (intersections[key].amount - intersections[key].resolved);
- var prevKey = i - (intersections[key].resolved + 1);
- if (nextKey < combinedData.length) {
- coreDistance = Math.abs(combinedData[nextKey].x - key);
- }
- if (prevKey > 0) {
- coreDistance = Math.min(coreDistance, Math.abs(combinedData[prevKey].x - key));
- }
- drawData = Bargraph._getSafeDrawData(coreDistance, group, minWidth);
- intersections[key].resolved += 1;
+ this.alignZeros = alignZeros;
- if (group.options.stack === true) {
- if (combinedData[i].y < group.zeroPosition) {
- heightOffset = intersections[key].accumulatedNegative;
- intersections[key].accumulatedNegative += group.zeroPosition - combinedData[i].y;
- } else {
- heightOffset = intersections[key].accumulatedPositive;
- intersections[key].accumulatedPositive += group.zeroPosition - combinedData[i].y;
- }
- } else if (group.options.barChart.sideBySide === true) {
- drawData.width = drawData.width / intersections[key].amount;
- drawData.offset += intersections[key].resolved * drawData.width - 0.5 * drawData.width * (intersections[key].amount + 1);
- if (group.options.barChart.align === 'left') {
- drawData.offset -= 0.5 * drawData.width;
- } else if (group.options.barChart.align === 'right') {
- drawData.offset += 0.5 * drawData.width;
- }
- }
- }
- DOMutil.drawBar(combinedData[i].x + drawData.offset, combinedData[i].y - heightOffset, drawData.width, group.zeroPosition - combinedData[i].y, group.className + ' vis-bar', framework.svgElements, framework.svg, group.style);
- // draw points
- if (group.options.drawPoints.enabled === true) {
- Points.draw([combinedData[i]], group, framework, drawData.offset);
- //DOMutil.drawPoint(combinedData[i].x + drawData.offset, combinedData[i].y, group, framework.svgElements, framework.svg);
- }
- }
- };
+ this.setRange(start, end, minimumStep, containerHeight, customRange);
+ }
/**
- * Fill the intersections object with counters of how many datapoints share the same x coordinates
- * @param intersections
- * @param combinedData
- * @private
+ * Set a new range
+ * If minimumStep is provided, the step size is chosen as close as possible
+ * to the minimumStep but larger than minimumStep. If minimumStep is not
+ * provided, the scale is set to 1 DAY.
+ * The minimumStep should correspond with the onscreen size of about 6 characters
+ * @param {Number} [start] The start date and time.
+ * @param {Number} [end] The end date and time.
+ * @param {Number} [minimumStep] Optional. Minimum step size in milliseconds
*/
- Bargraph._getDataIntersections = function (intersections, combinedData) {
- // get intersections
- var coreDistance;
- for (var i = 0; i < combinedData.length; i++) {
- if (i + 1 < combinedData.length) {
- coreDistance = Math.abs(combinedData[i + 1].x - combinedData[i].x);
- }
- if (i > 0) {
- coreDistance = Math.min(coreDistance, Math.abs(combinedData[i - 1].x - combinedData[i].x));
- }
- if (coreDistance === 0) {
- if (intersections[combinedData[i].x] === undefined) {
- intersections[combinedData[i].x] = { amount: 0, resolved: 0, accumulatedPositive: 0, accumulatedNegative: 0 };
- }
- intersections[combinedData[i].x].amount += 1;
- }
+ DataStep.prototype.setRange = function (start, end, minimumStep, containerHeight, customRange) {
+ this._start = customRange.min === undefined ? start : customRange.min;
+ this._end = customRange.max === undefined ? end : customRange.max;
+ if (this._start === this._end) {
+ this._start = customRange.min === undefined ? this._start - 0.75 : this._start;
+ this._end = customRange.max === undefined ? this._end + 1 : this._end;;
}
- };
-
- /**
- * Get the width and offset for bargraphs based on the coredistance between datapoints
- *
- * @param coreDistance
- * @param group
- * @param minWidth
- * @returns {{width: Number, offset: Number}}
- * @private
- */
- Bargraph._getSafeDrawData = function (coreDistance, group, minWidth) {
- var width, offset;
- if (coreDistance < group.options.barChart.width && coreDistance > 0) {
- width = coreDistance < minWidth ? minWidth : coreDistance;
- offset = 0; // recalculate offset with the new width;
- if (group.options.barChart.align === 'left') {
- offset -= 0.5 * coreDistance;
- } else if (group.options.barChart.align === 'right') {
- offset += 0.5 * coreDistance;
- }
- } else {
- // default settings
- width = group.options.barChart.width;
- offset = 0;
- if (group.options.barChart.align === 'left') {
- offset -= 0.5 * group.options.barChart.width;
- } else if (group.options.barChart.align === 'right') {
- offset += 0.5 * group.options.barChart.width;
- }
+ if (this.autoScale === true) {
+ this.setMinimumStep(minimumStep, containerHeight);
}
- return { width: width, offset: offset };
+ this.setFirst(customRange);
};
- Bargraph.getStackedYRange = function (combinedData, groupRanges, groupIds, groupLabel, orientation) {
- if (combinedData.length > 0) {
- // sort by time and by group
- combinedData.sort(function (a, b) {
- if (a.x === b.x) {
- return a.groupId < b.groupId ? -1 : 1;
- } else {
- return a.x - b.x;
- }
- });
- var intersections = {};
+ /**
+ * Automatically determine the scale that bests fits the provided minimum step
+ * @param {Number} [minimumStep] The minimum step size in pixels
+ */
+ DataStep.prototype.setMinimumStep = function (minimumStep, containerHeight) {
+ // round to floor
+ var range = this._end - this._start;
+ var safeRange = range * 1.2;
+ var minimumStepValue = minimumStep * (safeRange / containerHeight);
+ var orderOfMagnitude = Math.round(Math.log(safeRange) / Math.LN10);
- Bargraph._getDataIntersections(intersections, combinedData);
- groupRanges[groupLabel] = Bargraph._getStackedYRange(intersections, combinedData);
- groupRanges[groupLabel].yAxisOrientation = orientation;
- groupIds.push(groupLabel);
+ var minorStepIdx = -1;
+ var magnitudefactor = Math.pow(10, orderOfMagnitude);
+
+ var start = 0;
+ if (orderOfMagnitude < 0) {
+ start = orderOfMagnitude;
}
- };
- Bargraph._getStackedYRange = function (intersections, combinedData) {
- var key;
- var yMin = combinedData[0].y;
- var yMax = combinedData[0].y;
- for (var i = 0; i < combinedData.length; i++) {
- key = combinedData[i].x;
- if (intersections[key] === undefined) {
- yMin = yMin > combinedData[i].y ? combinedData[i].y : yMin;
- yMax = yMax < combinedData[i].y ? combinedData[i].y : yMax;
- } else {
- if (combinedData[i].y < 0) {
- intersections[key].accumulatedNegative += combinedData[i].y;
- } else {
- intersections[key].accumulatedPositive += combinedData[i].y;
+ var solutionFound = false;
+ for (var i = start; Math.abs(i) <= Math.abs(orderOfMagnitude); i++) {
+ magnitudefactor = Math.pow(10, i);
+ for (var j = 0; j < this.minorSteps.length; j++) {
+ var stepSize = magnitudefactor * this.minorSteps[j];
+ if (stepSize >= minimumStepValue) {
+ solutionFound = true;
+ minorStepIdx = j;
+ break;
}
}
- }
- for (var xpos in intersections) {
- if (intersections.hasOwnProperty(xpos)) {
- yMin = yMin > intersections[xpos].accumulatedNegative ? intersections[xpos].accumulatedNegative : yMin;
- yMin = yMin > intersections[xpos].accumulatedPositive ? intersections[xpos].accumulatedPositive : yMin;
- yMax = yMax < intersections[xpos].accumulatedNegative ? intersections[xpos].accumulatedNegative : yMax;
- yMax = yMax < intersections[xpos].accumulatedPositive ? intersections[xpos].accumulatedPositive : yMax;
+ if (solutionFound === true) {
+ break;
}
}
-
- return { min: yMin, max: yMax };
+ this.stepIndex = minorStepIdx;
+ this.scale = magnitudefactor;
+ this.step = magnitudefactor * this.minorSteps[minorStepIdx];
};
- module.exports = Bargraph;
-
-/***/ },
-/* 58 */
-/***/ function(module, exports, __webpack_require__) {
-
- 'use strict';
-
- var util = __webpack_require__(9);
- var DOMutil = __webpack_require__(14);
- var Component = __webpack_require__(28);
-
/**
- * Legend for Graph2d
+ * Round the current date to the first minor date value
+ * This must be executed once when the current date is set to start Date
*/
- function Legend(body, options, side, linegraphOptions) {
- this.body = body;
- this.defaultOptions = {
- enabled: true,
- icons: true,
- iconSize: 20,
- iconSpacing: 6,
- left: {
- visible: true,
- position: 'top-left' // top/bottom - left,center,right
- },
- right: {
- visible: true,
- position: 'top-left' // top/bottom - left,center,right
- }
- };
- this.side = side;
- this.options = util.extend({}, this.defaultOptions);
- this.linegraphOptions = linegraphOptions;
+ DataStep.prototype.setFirst = function (customRange) {
+ if (customRange === undefined) {
+ customRange = {};
+ }
- this.svgElements = {};
- this.dom = {};
- this.groups = {};
- this.amountOfGroups = 0;
- this._create();
+ var niceStart = customRange.min === undefined ? this._start - this.scale * 2 * this.minorSteps[this.stepIndex] : customRange.min;
+ var niceEnd = customRange.max === undefined ? this._end + this.scale * this.minorSteps[this.stepIndex] : customRange.max;
- this.setOptions(options);
- }
+ this.marginEnd = customRange.max === undefined ? this.roundToMinor(niceEnd) : customRange.max;
+ this.marginStart = customRange.min === undefined ? this.roundToMinor(niceStart) : customRange.min;
- Legend.prototype = new Component();
+ // if we need to align the zero's we need to make sure that there is a zero to use.
+ if (this.alignZeros === true && (this.marginEnd - this.marginStart) % this.step != 0) {
+ this.marginEnd += this.marginEnd % this.step;
+ }
- Legend.prototype.clear = function () {
- this.groups = {};
- this.amountOfGroups = 0;
- };
+ this.deadSpace = this.roundToMinor(niceEnd) - niceEnd + this.roundToMinor(niceStart) - niceStart;
+ this.marginRange = this.marginEnd - this.marginStart;
- Legend.prototype.addGroup = function (label, graphOptions) {
+ this.current = this.marginEnd;
+ };
- if (!this.groups.hasOwnProperty(label)) {
- this.groups[label] = graphOptions;
+ DataStep.prototype.roundToMinor = function (value) {
+ var rounded = value - value % (this.scale * this.minorSteps[this.stepIndex]);
+ if (value % (this.scale * this.minorSteps[this.stepIndex]) > 0.5 * (this.scale * this.minorSteps[this.stepIndex])) {
+ return rounded + this.scale * this.minorSteps[this.stepIndex];
+ } else {
+ return rounded;
}
- this.amountOfGroups += 1;
};
- Legend.prototype.updateGroup = function (label, graphOptions) {
- this.groups[label] = graphOptions;
+ /**
+ * Check if the there is a next step
+ * @return {boolean} true if the current date has not passed the end date
+ */
+ DataStep.prototype.hasNext = function () {
+ return this.current >= this.marginStart;
};
- Legend.prototype.removeGroup = function (label) {
- if (this.groups.hasOwnProperty(label)) {
- delete this.groups[label];
- this.amountOfGroups -= 1;
+ /**
+ * Do the next step
+ */
+ DataStep.prototype.next = function () {
+ var prev = this.current;
+ this.current -= this.step;
+
+ // safety mechanism: if current time is still unchanged, move to the end
+ if (this.current === prev) {
+ this.current = this._end;
}
};
- Legend.prototype._create = function () {
- this.dom.frame = document.createElement('div');
- this.dom.frame.className = 'vis-legend';
- this.dom.frame.style.position = 'absolute';
- this.dom.frame.style.top = '10px';
- this.dom.frame.style.display = 'block';
-
- this.dom.textArea = document.createElement('div');
- this.dom.textArea.className = 'vis-legend-text';
- this.dom.textArea.style.position = 'relative';
- this.dom.textArea.style.top = '0px';
-
- this.svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
- this.svg.style.position = 'absolute';
- this.svg.style.top = 0 + 'px';
- this.svg.style.width = this.options.iconSize + 5 + 'px';
- this.svg.style.height = '100%';
-
- this.dom.frame.appendChild(this.svg);
- this.dom.frame.appendChild(this.dom.textArea);
+ /**
+ * Do the next step
+ */
+ DataStep.prototype.previous = function () {
+ this.current += this.step;
+ this.marginEnd += this.step;
+ this.marginRange = this.marginEnd - this.marginStart;
};
- /**
- * Hide the component from the DOM
- */
- Legend.prototype.hide = function () {
- // remove the frame containing the items
- if (this.dom.frame.parentNode) {
- this.dom.frame.parentNode.removeChild(this.dom.frame);
+ /**
+ * Get the current datetime
+ * @return {String} current The current date
+ */
+ DataStep.prototype.getCurrent = function () {
+ // prevent round-off errors when close to zero
+ var current = Math.abs(this.current) < this.step / 2 ? 0 : this.current;
+ var returnValue = current.toPrecision(5);
+ if (typeof this.formattingFunction === 'function') {
+ returnValue = this.formattingFunction(current);
+ }
+
+ if (typeof returnValue === 'number') {
+ return '' + returnValue;
+ } else if (typeof returnValue === 'string') {
+ return returnValue;
+ } else {
+ return current.toPrecision(5);
}
};
/**
- * Show the component in the DOM (when not already visible).
- * @return {Boolean} changed
+ * Check if the current value is a major value (for example when the step
+ * is DAY, a major value is each first day of the MONTH)
+ * @return {boolean} true if current date is major, else false.
*/
- Legend.prototype.show = function () {
- // show frame containing the items
- if (!this.dom.frame.parentNode) {
- this.body.dom.center.appendChild(this.dom.frame);
- }
+ DataStep.prototype.isMajor = function () {
+ return this.current % (this.scale * this.majorSteps[this.stepIndex]) === 0;
};
- Legend.prototype.setOptions = function (options) {
- var fields = ['enabled', 'orientation', 'icons', 'left', 'right'];
- util.selectiveDeepExtend(fields, this.options, options);
+ DataStep.prototype.shift = function (steps) {
+ if (steps < 0) {
+ for (var i = 0; i < -steps; i++) {
+ this.previous();
+ }
+ } else if (steps > 0) {
+ for (var i = 0; i < steps; i++) {
+ this.next();
+ }
+ }
};
- Legend.prototype.redraw = function () {
- var activeGroups = 0;
- var groupArray = Object.keys(this.groups);
- groupArray.sort(function (a, b) {
- return a < b ? -1 : 1;
- });
+ module.exports = DataStep;
- for (var i = 0; i < groupArray.length; i++) {
- var groupId = groupArray[i];
- if (this.groups[groupId].visible == true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] == true)) {
- activeGroups++;
- }
- }
+/***/ },
+/* 54 */
+/***/ function(module, exports, __webpack_require__) {
- if (this.options[this.side].visible == false || this.amountOfGroups == 0 || this.options.enabled == false || activeGroups == 0) {
- this.hide();
- } else {
- this.show();
- if (this.options[this.side].position == 'top-left' || this.options[this.side].position == 'bottom-left') {
- this.dom.frame.style.left = '4px';
- this.dom.frame.style.textAlign = 'left';
- this.dom.textArea.style.textAlign = 'left';
- this.dom.textArea.style.left = this.options.iconSize + 15 + 'px';
- this.dom.textArea.style.right = '';
- this.svg.style.left = 0 + 'px';
- this.svg.style.right = '';
- } else {
- this.dom.frame.style.right = '4px';
- this.dom.frame.style.textAlign = 'right';
- this.dom.textArea.style.textAlign = 'right';
- this.dom.textArea.style.right = this.options.iconSize + 15 + 'px';
- this.dom.textArea.style.left = '';
- this.svg.style.right = 0 + 'px';
- this.svg.style.left = '';
- }
+ 'use strict';
- if (this.options[this.side].position == 'top-left' || this.options[this.side].position == 'top-right') {
- this.dom.frame.style.top = 4 - Number(this.body.dom.center.style.top.replace('px', '')) + 'px';
- this.dom.frame.style.bottom = '';
- } else {
- var scrollableHeight = this.body.domProps.center.height - this.body.domProps.centerContainer.height;
- this.dom.frame.style.bottom = 4 + scrollableHeight + Number(this.body.dom.center.style.top.replace('px', '')) + 'px';
- this.dom.frame.style.top = '';
- }
+ var util = __webpack_require__(9);
+ var DOMutil = __webpack_require__(14);
+ var Line = __webpack_require__(55);
+ var Bar = __webpack_require__(57);
+ var Points = __webpack_require__(56);
- if (this.options.icons == false) {
- this.dom.frame.style.width = this.dom.textArea.offsetWidth + 10 + 'px';
- this.dom.textArea.style.right = '';
- this.dom.textArea.style.left = '';
- this.svg.style.width = '0px';
- } else {
- this.dom.frame.style.width = this.options.iconSize + 15 + this.dom.textArea.offsetWidth + 10 + 'px';
- this.drawLegendIcons();
- }
+ /**
+ * /**
+ * @param {object} group | the object of the group from the dataset
+ * @param {string} groupId | ID of the group
+ * @param {object} options | the default options
+ * @param {array} groupsUsingDefaultStyles | this array has one entree.
+ * It is passed as an array so it is passed by reference.
+ * It enumerates through the default styles
+ * @constructor
+ */
+ function GraphGroup(group, groupId, options, groupsUsingDefaultStyles) {
+ this.id = groupId;
+ var fields = ['sampling', 'style', 'sort', 'yAxisOrientation', 'barChart', 'drawPoints', 'shaded', 'interpolation'];
+ this.options = util.selectiveBridgeObject(fields, options);
+ this.usingDefaultStyle = group.className === undefined;
+ this.groupsUsingDefaultStyles = groupsUsingDefaultStyles;
+ this.zeroPosition = 0;
+ this.update(group);
+ if (this.usingDefaultStyle == true) {
+ this.groupsUsingDefaultStyles[0] += 1;
+ }
+ this.itemsData = [];
+ this.visible = group.visible === undefined ? true : group.visible;
+ }
- var content = '';
- for (var i = 0; i < groupArray.length; i++) {
- var groupId = groupArray[i];
- if (this.groups[groupId].visible == true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] == true)) {
- content += this.groups[groupId].content + '
';
- }
+ /**
+ * this loads a reference to all items in this group into this group.
+ * @param {array} items
+ */
+ GraphGroup.prototype.setItems = function (items) {
+ if (items != null) {
+ this.itemsData = items;
+ if (this.options.sort == true) {
+ this.itemsData.sort(function (a, b) {
+ return a.x - b.x;
+ });
}
- this.dom.textArea.innerHTML = content;
- this.dom.textArea.style.lineHeight = 0.75 * this.options.iconSize + this.options.iconSpacing + 'px';
+ } else {
+ this.itemsData = [];
}
};
- Legend.prototype.drawLegendIcons = function () {
- if (this.dom.frame.parentNode) {
- var groupArray = Object.keys(this.groups);
- groupArray.sort(function (a, b) {
- return a < b ? -1 : 1;
- });
+ /**
+ * this is used for plotting barcharts, this way, we only have to calculate it once.
+ * @param pos
+ */
+ GraphGroup.prototype.setZeroPosition = function (pos) {
+ this.zeroPosition = pos;
+ };
- DOMutil.prepareElements(this.svgElements);
- var padding = window.getComputedStyle(this.dom.frame).paddingTop;
- var iconOffset = Number(padding.replace('px', ''));
- var x = iconOffset;
- var iconWidth = this.options.iconSize;
- var iconHeight = 0.75 * this.options.iconSize;
- var y = iconOffset + 0.5 * iconHeight + 3;
+ /**
+ * set the options of the graph group over the default options.
+ * @param options
+ */
+ GraphGroup.prototype.setOptions = function (options) {
+ if (options !== undefined) {
+ var fields = ['sampling', 'style', 'sort', 'yAxisOrientation', 'barChart'];
+ util.selectiveDeepExtend(fields, this.options, options);
- this.svg.style.width = iconWidth + 5 + iconOffset + 'px';
+ util.mergeOptions(this.options, options, 'interpolation');
+ util.mergeOptions(this.options, options, 'drawPoints');
+ util.mergeOptions(this.options, options, 'shaded');
- for (var i = 0; i < groupArray.length; i++) {
- var groupId = groupArray[i];
- if (this.groups[groupId].visible == true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] == true)) {
- this.groups[groupId].drawIcon(x, y, this.svgElements, this.svg, iconWidth, iconHeight);
- y += iconHeight + this.options.iconSpacing;
+ if (options.interpolation) {
+ if (typeof options.interpolation == 'object') {
+ if (options.interpolation.parametrization) {
+ if (options.interpolation.parametrization == 'uniform') {
+ this.options.interpolation.alpha = 0;
+ } else if (options.interpolation.parametrization == 'chordal') {
+ this.options.interpolation.alpha = 1;
+ } else {
+ this.options.interpolation.parametrization = 'centripetal';
+ this.options.interpolation.alpha = 0.5;
+ }
+ }
}
}
+ }
- DOMutil.cleanupElements(this.svgElements);
+ if (this.options.style == 'line') {
+ this.type = new Line(this.id, this.options);
+ } else if (this.options.style == 'bar') {
+ this.type = new Bar(this.id, this.options);
+ } else if (this.options.style == 'points') {
+ this.type = new Points(this.id, this.options);
}
};
- module.exports = Legend;
-
-/***/ },
-/* 59 */
-/***/ function(module, exports, __webpack_require__) {
+ /**
+ * this updates the current group class with the latest group dataset entree, used in _updateGroup in linegraph
+ * @param group
+ */
+ GraphGroup.prototype.update = function (group) {
+ this.group = group;
+ this.content = group.content || 'graph';
+ this.className = group.className || this.className || 'vis-graph-group' + this.groupsUsingDefaultStyles[0] % 10;
+ this.visible = group.visible === undefined ? true : group.visible;
+ this.style = group.style;
+ this.setOptions(group.options);
+ };
/**
- * This object contains all possible options. It will check if the types are correct, if required if the option is one
- * of the allowed values.
+ * draw the icon for the legend.
*
- * __any__ means that the name of the property does not matter.
- * __type__ is a required field for all objects and contains the allowed types of all objects
+ * @param x
+ * @param y
+ * @param JSONcontainer
+ * @param SVGcontainer
+ * @param iconWidth
+ * @param iconHeight
*/
- 'use strict';
+ GraphGroup.prototype.drawIcon = function (x, y, JSONcontainer, SVGcontainer, iconWidth, iconHeight) {
+ var fillHeight = iconHeight * 0.5;
+ var path, fillPath;
- Object.defineProperty(exports, '__esModule', {
- value: true
- });
- var string = 'string';
- var boolean = 'boolean';
- var number = 'number';
- var array = 'array';
- var date = 'date';
- var object = 'object'; // should only be in a __type__ property
- var dom = 'dom';
- var moment = 'moment';
- var fn = 'function';
- var nada = 'null';
- var undef = 'undefined';
- var any = 'any';
+ var outline = DOMutil.getSVGElement('rect', JSONcontainer, SVGcontainer);
+ outline.setAttributeNS(null, 'x', x);
+ outline.setAttributeNS(null, 'y', y - fillHeight);
+ outline.setAttributeNS(null, 'width', iconWidth);
+ outline.setAttributeNS(null, 'height', 2 * fillHeight);
+ outline.setAttributeNS(null, 'class', 'vis-outline');
- var allOptions = {
- configure: {
- enabled: { boolean: boolean },
- filter: { boolean: boolean, fn: fn },
- container: { dom: dom },
- __type__: { object: object, boolean: boolean, fn: fn }
- },
+ if (this.options.style == 'line') {
+ path = DOMutil.getSVGElement('path', JSONcontainer, SVGcontainer);
+ path.setAttributeNS(null, 'class', this.className);
+ if (this.style !== undefined) {
+ path.setAttributeNS(null, 'style', this.style);
+ }
- //globals :
- yAxisOrientation: { string: ['left', 'right'] },
- defaultGroup: { string: string },
- sort: { boolean: boolean },
- sampling: { boolean: boolean },
- stack: { boolean: boolean },
- graphHeight: { string: string, number: number },
- shaded: {
- enabled: { boolean: boolean },
- orientation: { string: ['bottom', 'top'] }, // top, bottom
- __type__: { boolean: boolean, object: object }
- },
- style: { string: ['line', 'bar', 'points'] }, // line, bar
- barChart: {
- width: { number: number },
- sideBySide: { boolean: boolean },
- align: { string: ['left', 'center', 'right'] },
- __type__: { object: object }
- },
- interpolation: {
- enabled: { boolean: boolean },
- parametrization: { string: ['centripetal', 'chordal', 'uniform'] }, // uniform (alpha = 0.0), chordal (alpha = 1.0), centripetal (alpha = 0.5)
- alpha: { number: number },
- __type__: { object: object, boolean: boolean }
- },
- drawPoints: {
- enabled: { boolean: boolean },
- size: { number: number },
- style: { string: ['square', 'circle'] }, // square, circle
- __type__: { object: object, boolean: boolean }
- },
- dataAxis: {
- showMinorLabels: { boolean: boolean },
- showMajorLabels: { boolean: boolean },
- icons: { boolean: boolean },
- width: { string: string, number: number },
- visible: { boolean: boolean },
- alignZeros: { boolean: boolean },
- left: {
- range: { min: { number: number }, max: { number: number }, __type__: { object: object } },
- format: { fn: fn },
- title: { text: { string: string, number: number }, style: { string: string }, __type__: { object: object } },
- __type__: { object: object }
- },
- right: {
- range: { min: { number: number }, max: { number: number }, __type__: { object: object } },
- format: { fn: fn },
- title: { text: { string: string, number: number }, style: { string: string }, __type__: { object: object } },
- __type__: { object: object }
- },
- __type__: { object: object }
- },
- legend: {
- enabled: { boolean: boolean },
- icons: { boolean: boolean },
- left: {
- visible: { boolean: boolean },
- position: { string: ['top-right', 'bottom-right', 'top-left', 'bottom-left'] },
- __type__: { object: object }
- },
- right: {
- visible: { boolean: boolean },
- position: { string: ['top-right', 'bottom-right', 'top-left', 'bottom-left'] },
- __type__: { object: object }
- },
- __type__: { object: object, boolean: boolean }
- },
- groups: {
- visibility: { any: any },
- __type__: { object: object }
- },
+ path.setAttributeNS(null, 'd', 'M' + x + ',' + y + ' L' + (x + iconWidth) + ',' + y + '');
+ if (this.options.shaded.enabled == true) {
+ fillPath = DOMutil.getSVGElement('path', JSONcontainer, SVGcontainer);
+ if (this.options.shaded.orientation == 'top') {
+ fillPath.setAttributeNS(null, 'd', 'M' + x + ', ' + (y - fillHeight) + 'L' + x + ',' + y + ' L' + (x + iconWidth) + ',' + y + ' L' + (x + iconWidth) + ',' + (y - fillHeight));
+ } else {
+ fillPath.setAttributeNS(null, 'd', 'M' + x + ',' + y + ' ' + 'L' + x + ',' + (y + fillHeight) + ' ' + 'L' + (x + iconWidth) + ',' + (y + fillHeight) + 'L' + (x + iconWidth) + ',' + y);
+ }
+ fillPath.setAttributeNS(null, 'class', this.className + ' vis-icon-fill');
+ }
- autoResize: { boolean: boolean },
- clickToUse: { boolean: boolean },
- end: { number: number, date: date, string: string, moment: moment },
- format: {
- minorLabels: {
- millisecond: { string: string, undef: undef },
- second: { string: string, undef: undef },
- minute: { string: string, undef: undef },
- hour: { string: string, undef: undef },
- weekday: { string: string, undef: undef },
- day: { string: string, undef: undef },
- month: { string: string, undef: undef },
- year: { string: string, undef: undef },
- __type__: { object: object }
- },
- majorLabels: {
- millisecond: { string: string, undef: undef },
- second: { string: string, undef: undef },
- minute: { string: string, undef: undef },
- hour: { string: string, undef: undef },
- weekday: { string: string, undef: undef },
- day: { string: string, undef: undef },
- month: { string: string, undef: undef },
- year: { string: string, undef: undef },
- __type__: { object: object }
- },
- __type__: { object: object }
- },
- height: { string: string, number: number },
- hiddenDates: { object: object, array: array },
- locale: { string: string },
- locales: {
- __any__: { object: object },
- __type__: { object: object }
- },
- max: { date: date, number: number, string: string, moment: moment },
- maxHeight: { number: number, string: string },
- min: { date: date, number: number, string: string, moment: moment },
- minHeight: { number: number, string: string },
- moveable: { boolean: boolean },
- multiselect: { boolean: boolean },
- orientation: { string: string },
- showCurrentTime: { boolean: boolean },
- showMajorLabels: { boolean: boolean },
- showMinorLabels: { boolean: boolean },
- start: { date: date, number: number, string: string, moment: moment },
- timeAxis: {
- scale: { string: string, undef: undef },
- step: { number: number, undef: undef },
- __type__: { object: object }
- },
- width: { string: string, number: number },
- zoomable: { boolean: boolean },
- zoomMax: { number: number },
- zoomMin: { number: number },
- __type__: { object: object }
+ if (this.options.drawPoints.enabled == true) {
+ DOMutil.drawPoint(x + 0.5 * iconWidth, y, this, JSONcontainer, SVGcontainer);
+ }
+ } else {
+ var barWidth = Math.round(0.3 * iconWidth);
+ var bar1Height = Math.round(0.4 * iconHeight);
+ var bar2Height = Math.round(0.75 * iconHeight);
+
+ var offset = Math.round((iconWidth - 2 * barWidth) / 3);
+
+ DOMutil.drawBar(x + 0.5 * barWidth + offset, y + fillHeight - bar1Height - 1, barWidth, bar1Height, this.className + ' vis-bar', JSONcontainer, SVGcontainer, this.style);
+ DOMutil.drawBar(x + 1.5 * barWidth + offset + 2, y + fillHeight - bar2Height - 1, barWidth, bar2Height, this.className + ' vis-bar', JSONcontainer, SVGcontainer, this.style);
+ }
};
- var configureOptions = {
- global: {
- yAxisOrientation: ['left', 'right'],
- sort: true,
- sampling: true,
- stack: false,
- shaded: {
- enabled: false,
- orientation: ['top', 'bottom'] // top, bottom
- },
- style: ['line', 'bar', 'points'], // line, bar
- barChart: {
- width: [50, 5, 100, 5],
- sideBySide: false,
- align: ['left', 'center', 'right'] // left, center, right
- },
- interpolation: {
- enabled: true,
- parametrization: ['centripetal', 'chordal', 'uniform'] // uniform (alpha = 0.0), chordal (alpha = 1.0), centripetal (alpha = 0.5)
- },
- drawPoints: {
- enabled: true,
- size: [6, 2, 30, 1],
- style: ['square', 'circle'] // square, circle
- },
- dataAxis: {
- showMinorLabels: true,
- showMajorLabels: true,
- icons: false,
- width: [40, 0, 200, 1],
- visible: true,
- alignZeros: true,
- left: {
- //range: {min:undefined,max:undefined},
- //format: function (value) {return value;},
- title: { text: '', style: '' }
- },
- right: {
- //range: {min:undefined,max:undefined},
- //format: function (value) {return value;},
- title: { text: '', style: '' }
- }
- },
- legend: {
- enabled: false,
- icons: true,
- left: {
- visible: true,
- position: ['top-right', 'bottom-right', 'top-left', 'bottom-left'] // top/bottom - left,right
- },
- right: {
- visible: true,
- position: ['top-right', 'bottom-right', 'top-left', 'bottom-left'] // top/bottom - left,right
- }
- },
+ /**
+ * return the legend entree for this group.
+ *
+ * @param iconWidth
+ * @param iconHeight
+ * @returns {{icon: HTMLElement, label: (group.content|*|string), orientation: (.options.yAxisOrientation|*)}}
+ */
+ GraphGroup.prototype.getLegend = function (iconWidth, iconHeight) {
+ var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
+ this.drawIcon(0, 0.5 * iconHeight, [], svg, iconWidth, iconHeight);
+ return { icon: svg, label: this.content, orientation: this.options.yAxisOrientation };
+ };
- autoResize: true,
- clickToUse: false,
- end: '',
- format: {
- minorLabels: {
- millisecond: 'SSS',
- second: 's',
- minute: 'HH:mm',
- hour: 'HH:mm',
- weekday: 'ddd D',
- day: 'D',
- month: 'MMM',
- year: 'YYYY'
- },
- majorLabels: {
- millisecond: 'HH:mm:ss',
- second: 'D MMMM HH:mm',
- minute: 'ddd D MMMM',
- hour: 'ddd D MMMM',
- weekday: 'MMMM YYYY',
- day: 'MMMM YYYY',
- month: 'YYYY',
- year: ''
- }
- },
+ GraphGroup.prototype.getYRange = function (groupData) {
+ return this.type.getYRange(groupData);
+ };
- height: '',
- locale: '',
- max: '',
- maxHeight: '',
- min: '',
- minHeight: '',
- moveable: true,
- orientation: ['both', 'bottom', 'top'],
- showCurrentTime: false,
- showMajorLabels: true,
- showMinorLabels: true,
- start: '',
- width: '100%',
- zoomable: true,
- zoomMax: [315360000000000, 10, 315360000000000, 1],
- zoomMin: [10, 10, 315360000000000, 1]
- }
+ GraphGroup.prototype.getData = function (groupData) {
+ return this.type.getData(groupData);
};
- exports.allOptions = allOptions;
- exports.configureOptions = configureOptions;
+ GraphGroup.prototype.draw = function (dataset, group, framework) {
+ this.type.draw(dataset, group, framework);
+ };
+
+ module.exports = GraphGroup;
/***/ },
-/* 60 */
+/* 55 */
/***/ function(module, exports, __webpack_require__) {
- // Load custom shapes into CanvasRenderingContext2D
'use strict';
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
-
- var _modulesGroups = __webpack_require__(61);
+ var DOMutil = __webpack_require__(14);
+ var Points = __webpack_require__(56);
- var _modulesGroups2 = _interopRequireDefault(_modulesGroups);
+ function Line(groupId, options) {
+ this.groupId = groupId;
+ this.options = options;
+ }
- var _modulesNodesHandler = __webpack_require__(62);
+ Line.prototype.getData = function (groupData) {
+ var combinedData = [];
+ for (var j = 0; j < groupData.length; j++) {
+ combinedData.push({
+ x: groupData[j].x,
+ y: groupData[j].y,
+ groupId: this.groupId
+ });
+ }
+ return combinedData;
+ };
- var _modulesNodesHandler2 = _interopRequireDefault(_modulesNodesHandler);
+ Line.prototype.getYRange = function (groupData) {
+ var yMin = groupData[0].y;
+ var yMax = groupData[0].y;
+ for (var j = 0; j < groupData.length; j++) {
+ yMin = yMin > groupData[j].y ? groupData[j].y : yMin;
+ yMax = yMax < groupData[j].y ? groupData[j].y : yMax;
+ }
+ return { min: yMin, max: yMax, yAxisOrientation: this.options.yAxisOrientation };
+ };
- var _modulesEdgesHandler = __webpack_require__(82);
+ Line.getStackedYRange = function (combinedData, groupRanges, groupIds, groupLabel, orientation) {
+ if (combinedData.length > 0) {
+ // sort by time and by group
+ combinedData.sort(function (a, b) {
+ if (a.x === b.x) {
+ return a.groupId < b.groupId ? -1 : 1;
+ } else {
+ return a.x - b.x;
+ }
+ });
+ var intersections = {};
- var _modulesEdgesHandler2 = _interopRequireDefault(_modulesEdgesHandler);
+ Line._getDataIntersections(intersections, combinedData);
+ groupRanges[groupLabel] = Line._getStackedYRange(intersections, combinedData);
+ groupRanges[groupLabel].yAxisOrientation = orientation;
+ groupIds.push(groupLabel);
+ }
+ };
- var _modulesPhysicsEngine = __webpack_require__(89);
+ Line._getStackedYRange = function (intersections, combinedData) {
+ var key;
+ var yMin = combinedData[0].y;
+ var yMax = combinedData[0].y;
+ for (var i = 0; i < combinedData.length; i++) {
+ key = combinedData[i].x;
+ if (intersections[key] === undefined) {
+ yMin = yMin > combinedData[i].y ? combinedData[i].y : yMin;
+ yMax = yMax < combinedData[i].y ? combinedData[i].y : yMax;
+ } else {
+ if (combinedData[i].y < 0) {
+ intersections[key].accumulatedNegative += combinedData[i].y;
+ } else {
+ intersections[key].accumulatedPositive += combinedData[i].y;
+ }
+ }
+ }
+ for (var xpos in intersections) {
+ if (intersections.hasOwnProperty(xpos)) {
+ yMin = yMin > intersections[xpos].accumulatedNegative ? intersections[xpos].accumulatedNegative : yMin;
+ yMin = yMin > intersections[xpos].accumulatedPositive ? intersections[xpos].accumulatedPositive : yMin;
+ yMax = yMax < intersections[xpos].accumulatedNegative ? intersections[xpos].accumulatedNegative : yMax;
+ yMax = yMax < intersections[xpos].accumulatedPositive ? intersections[xpos].accumulatedPositive : yMax;
+ }
+ }
- var _modulesPhysicsEngine2 = _interopRequireDefault(_modulesPhysicsEngine);
+ return { min: yMin, max: yMax };
+ };
- var _modulesClustering = __webpack_require__(98);
+ /**
+ * Fill the intersections object with counters of how many datapoints share the same x coordinates
+ * @param intersections
+ * @param combinedData
+ * @private
+ */
+ Line._getDataIntersections = function (intersections, combinedData) {
+ // get intersections
+ var coreDistance;
+ for (var i = 0; i < combinedData.length; i++) {
+ if (i + 1 < combinedData.length) {
+ coreDistance = Math.abs(combinedData[i + 1].x - combinedData[i].x);
+ }
+ if (i > 0) {
+ coreDistance = Math.min(coreDistance, Math.abs(combinedData[i - 1].x - combinedData[i].x));
+ }
+ if (coreDistance === 0) {
+ if (intersections[combinedData[i].x] === undefined) {
+ intersections[combinedData[i].x] = { amount: 0, resolved: 0, accumulatedPositive: 0, accumulatedNegative: 0 };
+ }
+ intersections[combinedData[i].x].amount += 1;
+ }
+ }
+ };
- var _modulesClustering2 = _interopRequireDefault(_modulesClustering);
+ /**
+ * draw a line graph
+ *
+ * @param dataset
+ * @param group
+ */
+ Line.prototype.draw = function (dataset, group, framework) {
+ if (dataset != null) {
+ if (dataset.length > 0) {
+ var path, d;
+ var svgHeight = Number(framework.svg.style.height.replace('px', ''));
+ path = DOMutil.getSVGElement('path', framework.svgElements, framework.svg);
+ path.setAttributeNS(null, 'class', group.className);
+ if (group.style !== undefined) {
+ path.setAttributeNS(null, 'style', group.style);
+ }
- var _modulesCanvasRenderer = __webpack_require__(100);
+ // construct path from dataset
+ if (group.options.interpolation.enabled == true) {
+ d = Line._catmullRom(dataset, group);
+ } else {
+ d = Line._linear(dataset);
+ }
- var _modulesCanvasRenderer2 = _interopRequireDefault(_modulesCanvasRenderer);
+ // append with points for fill and finalize the path
+ if (group.options.shaded.enabled == true) {
+ var fillPath = DOMutil.getSVGElement('path', framework.svgElements, framework.svg);
+ var dFill;
+ if (group.options.shaded.orientation == 'top') {
+ dFill = 'M' + dataset[0].x + ',' + 0 + ' ' + d + 'L' + dataset[dataset.length - 1].x + ',' + 0;
+ } else {
+ dFill = 'M' + dataset[0].x + ',' + svgHeight + ' ' + d + 'L' + dataset[dataset.length - 1].x + ',' + svgHeight;
+ }
+ fillPath.setAttributeNS(null, 'class', group.className + ' vis-fill');
+ if (group.options.shaded.style !== undefined) {
+ fillPath.setAttributeNS(null, 'style', group.options.shaded.style);
+ }
+ fillPath.setAttributeNS(null, 'd', dFill);
+ }
+ // copy properties to path for drawing.
+ path.setAttributeNS(null, 'd', 'M' + d);
- var _modulesCanvas = __webpack_require__(101);
+ // draw points
+ if (group.options.drawPoints.enabled == true) {
+ Points.draw(dataset, group, framework);
+ }
+ }
+ }
+ };
- var _modulesCanvas2 = _interopRequireDefault(_modulesCanvas);
+ /**
+ * This uses an uniform parametrization of the interpolation algorithm:
+ * 'On the Parameterization of Catmull-Rom Curves' by Cem Yuksel et al.
+ * @param data
+ * @returns {string}
+ * @private
+ */
+ Line._catmullRomUniform = function (data) {
+ // catmull rom
+ var p0, p1, p2, p3, bp1, bp2;
+ var d = Math.round(data[0].x) + ',' + Math.round(data[0].y) + ' ';
+ var normalization = 1 / 6;
+ var length = data.length;
+ for (var i = 0; i < length - 1; i++) {
- var _modulesView = __webpack_require__(3);
+ p0 = i == 0 ? data[0] : data[i - 1];
+ p1 = data[i];
+ p2 = data[i + 1];
+ p3 = i + 2 < length ? data[i + 2] : p2;
- var _modulesView2 = _interopRequireDefault(_modulesView);
+ // Catmull-Rom to Cubic Bezier conversion matrix
+ // 0 1 0 0
+ // -1/6 1 1/6 0
+ // 0 1/6 1 -1/6
+ // 0 0 1 0
- var _modulesInteractionHandler = __webpack_require__(102);
+ // bp0 = { x: p1.x, y: p1.y };
+ bp1 = { x: (-p0.x + 6 * p1.x + p2.x) * normalization, y: (-p0.y + 6 * p1.y + p2.y) * normalization };
+ bp2 = { x: (p1.x + 6 * p2.x - p3.x) * normalization, y: (p1.y + 6 * p2.y - p3.y) * normalization };
+ // bp0 = { x: p2.x, y: p2.y };
- var _modulesInteractionHandler2 = _interopRequireDefault(_modulesInteractionHandler);
+ d += 'C' + bp1.x + ',' + bp1.y + ' ' + bp2.x + ',' + bp2.y + ' ' + p2.x + ',' + p2.y + ' ';
+ }
- var _modulesSelectionHandler = __webpack_require__(105);
+ return d;
+ };
- var _modulesSelectionHandler2 = _interopRequireDefault(_modulesSelectionHandler);
+ /**
+ * This uses either the chordal or centripetal parameterization of the catmull-rom algorithm.
+ * By default, the centripetal parameterization is used because this gives the nicest results.
+ * These parameterizations are relatively heavy because the distance between 4 points have to be calculated.
+ *
+ * One optimization can be used to reuse distances since this is a sliding window approach.
+ * @param data
+ * @param group
+ * @returns {string}
+ * @private
+ */
+ Line._catmullRom = function (data, group) {
+ var alpha = group.options.interpolation.alpha;
+ if (alpha == 0 || alpha === undefined) {
+ return this._catmullRomUniform(data);
+ } else {
+ var p0, p1, p2, p3, bp1, bp2, d1, d2, d3, A, B, N, M;
+ var d3powA, d2powA, d3pow2A, d2pow2A, d1pow2A, d1powA;
+ var d = Math.round(data[0].x) + ',' + Math.round(data[0].y) + ' ';
+ var length = data.length;
+ for (var i = 0; i < length - 1; i++) {
- var _modulesLayoutEngine = __webpack_require__(106);
+ p0 = i == 0 ? data[0] : data[i - 1];
+ p1 = data[i];
+ p2 = data[i + 1];
+ p3 = i + 2 < length ? data[i + 2] : p2;
- var _modulesLayoutEngine2 = _interopRequireDefault(_modulesLayoutEngine);
+ d1 = Math.sqrt(Math.pow(p0.x - p1.x, 2) + Math.pow(p0.y - p1.y, 2));
+ d2 = Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
+ d3 = Math.sqrt(Math.pow(p2.x - p3.x, 2) + Math.pow(p2.y - p3.y, 2));
- var _modulesManipulationSystem = __webpack_require__(107);
+ // Catmull-Rom to Cubic Bezier conversion matrix
- var _modulesManipulationSystem2 = _interopRequireDefault(_modulesManipulationSystem);
+ // A = 2d1^2a + 3d1^a * d2^a + d3^2a
+ // B = 2d3^2a + 3d3^a * d2^a + d2^2a
- var _sharedConfigurator = __webpack_require__(46);
+ // [ 0 1 0 0 ]
+ // [ -d2^2a /N A/N d1^2a /N 0 ]
+ // [ 0 d3^2a /M B/M -d2^2a /M ]
+ // [ 0 0 1 0 ]
- var _sharedConfigurator2 = _interopRequireDefault(_sharedConfigurator);
+ d3powA = Math.pow(d3, alpha);
+ d3pow2A = Math.pow(d3, 2 * alpha);
+ d2powA = Math.pow(d2, alpha);
+ d2pow2A = Math.pow(d2, 2 * alpha);
+ d1powA = Math.pow(d1, alpha);
+ d1pow2A = Math.pow(d1, 2 * alpha);
- var _sharedValidator = __webpack_require__(48);
+ A = 2 * d1pow2A + 3 * d1powA * d2powA + d2pow2A;
+ B = 2 * d3pow2A + 3 * d3powA * d2powA + d2pow2A;
+ N = 3 * d1powA * (d1powA + d2powA);
+ if (N > 0) {
+ N = 1 / N;
+ }
+ M = 3 * d3powA * (d3powA + d2powA);
+ if (M > 0) {
+ M = 1 / M;
+ }
- var _sharedValidator2 = _interopRequireDefault(_sharedValidator);
+ bp1 = { x: (-d2pow2A * p0.x + A * p1.x + d1pow2A * p2.x) * N,
+ y: (-d2pow2A * p0.y + A * p1.y + d1pow2A * p2.y) * N };
- var _optionsJs = __webpack_require__(108);
+ bp2 = { x: (d3pow2A * p1.x + B * p2.x - d2pow2A * p3.x) * M,
+ y: (d3pow2A * p1.y + B * p2.y - d2pow2A * p3.y) * M };
- __webpack_require__(109);
+ if (bp1.x == 0 && bp1.y == 0) {
+ bp1 = p1;
+ }
+ if (bp2.x == 0 && bp2.y == 0) {
+ bp2 = p2;
+ }
+ d += 'C' + bp1.x + ',' + bp1.y + ' ' + bp2.x + ',' + bp2.y + ' ' + p2.x + ',' + p2.y + ' ';
+ }
- var Emitter = __webpack_require__(20);
- var Hammer = __webpack_require__(5);
- var util = __webpack_require__(9);
- var DataSet = __webpack_require__(15);
- var DataView = __webpack_require__(17);
- var dotparser = __webpack_require__(110);
- var gephiParser = __webpack_require__(111);
- var Images = __webpack_require__(112);
- var Activator = __webpack_require__(43);
- var locales = __webpack_require__(113);
+ return d;
+ }
+ };
/**
- * @constructor Network
- * Create a network visualization, displaying nodes and edges.
- *
- * @param {Element} container The DOM element in which the Network will
- * be created. Normally a div element.
- * @param {Object} data An object containing parameters
- * {Array} nodes
- * {Array} edges
- * @param {Object} options Options
+ * this generates the SVG path for a linear drawing between datapoints.
+ * @param data
+ * @returns {string}
+ * @private
*/
- function Network(container, data, options) {
- var _this = this;
-
- 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
- this.body = {
- nodes: {},
- nodeIndices: [],
- edges: {},
- edgeIndices: [],
- data: {
- nodes: null, // A DataSet or DataView
- edges: null // A DataSet or DataView
- },
- functions: {
- createNode: function createNode() {},
- createEdge: function createEdge() {},
- getPointer: function getPointer() {}
- },
- emitter: {
- on: this.on.bind(this),
- off: this.off.bind(this),
- emit: this.emit.bind(this),
- once: this.once.bind(this)
- },
- eventListeners: {
- onTap: function onTap() {},
- onTouch: function onTouch() {},
- onDoubleTap: function onDoubleTap() {},
- onHold: function onHold() {},
- onDragStart: function onDragStart() {},
- onDrag: function onDrag() {},
- onDragEnd: function onDragEnd() {},
- onMouseWheel: function onMouseWheel() {},
- onPinch: function onPinch() {},
- onMouseMove: function onMouseMove() {},
- onRelease: function onRelease() {},
- onContext: function onContext() {}
- },
- container: container,
- view: {
- scale: 1,
- translation: { x: 0, y: 0 }
+ Line._linear = function (data) {
+ // linear
+ var d = '';
+ for (var i = 0; i < data.length; i++) {
+ if (i == 0) {
+ d += data[i].x + ',' + data[i].y;
+ } else {
+ d += ' ' + data[i].x + ',' + data[i].y;
}
- };
-
- // bind the event listeners
- this.bindEventListeners();
-
- // setting up all modules
- this.images = new Images(function () {
- return _this.body.emitter.emit('_requestRedraw');
- }); // object with images
- this.groups = new _modulesGroups2['default'](); // object with groups
- this.canvas = new _modulesCanvas2['default'](this.body); // DOM handler
- this.selectionHandler = new _modulesSelectionHandler2['default'](this.body, this.canvas); // Selection handler
- this.interactionHandler = new _modulesInteractionHandler2['default'](this.body, this.canvas, this.selectionHandler); // Interaction handler handles all the hammer bindings (that are bound by canvas), key
- this.view = new _modulesView2['default'](this.body, this.canvas); // camera handler, does animations and zooms
- this.renderer = new _modulesCanvasRenderer2['default'](this.body, this.canvas); // renderer, starts renderloop, has events that modules can hook into
- this.physics = new _modulesPhysicsEngine2['default'](this.body); // physics engine, does all the simulations
- this.layoutEngine = new _modulesLayoutEngine2['default'](this.body); // layout engine for inital layout and hierarchical layout
- this.clustering = new _modulesClustering2['default'](this.body); // clustering api
- this.manipulation = new _modulesManipulationSystem2['default'](this.body, this.canvas, this.selectionHandler); // data manipulation system
+ }
+ return d;
+ };
- this.nodesHandler = new _modulesNodesHandler2['default'](this.body, this.images, this.groups, this.layoutEngine); // Handle adding, deleting and updating of nodes as well as global options
- this.edgesHandler = new _modulesEdgesHandler2['default'](this.body, this.images, this.groups); // Handle adding, deleting and updating of edges as well as global options
+ module.exports = Line;
- // create the DOM elements
- this.canvas._create();
+/***/ },
+/* 56 */
+/***/ function(module, exports, __webpack_require__) {
- // setup configuration system
- this.configurator = new _sharedConfigurator2['default'](this, this.body.container, _optionsJs.configureOptions, this.canvas.pixelRatio);
+ 'use strict';
- // apply options
- this.setOptions(options);
+ var DOMutil = __webpack_require__(14);
- // load data (the disable start variable will be the same as the enabled clustering)
- this.setData(data);
+ function Points(groupId, options) {
+ this.groupId = groupId;
+ this.options = options;
}
- // Extend Network with an Emitter mixin
- Emitter(Network.prototype);
+ Points.prototype.getYRange = function (groupData) {
+ var yMin = groupData[0].y;
+ var yMax = groupData[0].y;
+ for (var j = 0; j < groupData.length; j++) {
+ yMin = yMin > groupData[j].y ? groupData[j].y : yMin;
+ yMax = yMax < groupData[j].y ? groupData[j].y : yMax;
+ }
+ return { min: yMin, max: yMax, yAxisOrientation: this.options.yAxisOrientation };
+ };
+
+ Points.prototype.draw = function (dataset, group, framework, offset) {
+ Points.draw(dataset, group, framework, offset);
+ };
/**
- * Set options
- * @param {Object} options
+ * draw the data points
+ *
+ * @param {Array} dataset
+ * @param {Object} JSONcontainer
+ * @param {Object} svg | SVG DOM element
+ * @param {GraphGroup} group
+ * @param {Number} [offset]
*/
- Network.prototype.setOptions = function (options) {
- if (options !== undefined) {
+ Points.draw = function (dataset, group, framework, offset) {
+ if (offset === undefined) {
+ offset = 0;
+ }
+ for (var i = 0; i < dataset.length; i++) {
+ DOMutil.drawPoint(dataset[i].x + offset, dataset[i].y, group, framework.svgElements, framework.svg, dataset[i].label);
+ }
+ };
- var errorFound = _sharedValidator2['default'].validate(options, _optionsJs.allOptions);
- if (errorFound === true) {
- console.log('%cErrors have been found in the supplied options object.', _sharedValidator.printStyle);
- }
+ module.exports = Points;
- // copy the global fields over
- var fields = ['locale', 'locales', 'clickToUse'];
- util.selectiveDeepExtend(fields, this.options, options);
+/***/ },
+/* 57 */
+/***/ function(module, exports, __webpack_require__) {
- // the hierarchical system can adapt the edges and the physics to it's own options because not all combinations work with the hierarichical system.
- options = this.layoutEngine.setOptions(options.layout, options);
+ 'use strict';
- this.canvas.setOptions(options); // options for canvas are in globals
+ var DOMutil = __webpack_require__(14);
+ var Points = __webpack_require__(56);
- // pass the options to the modules
- this.groups.setOptions(options.groups);
- this.nodesHandler.setOptions(options.nodes);
- this.edgesHandler.setOptions(options.edges);
- this.physics.setOptions(options.physics);
- this.manipulation.setOptions(options.manipulation, options, this.options); // manipulation uses the locales in the globals
+ function Bargraph(groupId, options) {
+ this.groupId = groupId;
+ this.options = options;
+ }
- this.interactionHandler.setOptions(options.interaction);
- this.renderer.setOptions(options.interaction); // options for rendering are in interaction
- this.selectionHandler.setOptions(options.interaction); // options for selection are in interaction
+ Bargraph.prototype.getYRange = function (groupData) {
+ var yMin = groupData[0].y;
+ var yMax = groupData[0].y;
+ for (var j = 0; j < groupData.length; j++) {
+ yMin = yMin > groupData[j].y ? groupData[j].y : yMin;
+ yMax = yMax < groupData[j].y ? groupData[j].y : yMax;
+ }
+ return { min: yMin, max: yMax, yAxisOrientation: this.options.yAxisOrientation };
+ };
+
+ Bargraph.prototype.getData = function (groupData) {
+ var combinedData = [];
+ for (var j = 0; j < groupData.length; j++) {
+ combinedData.push({
+ x: groupData[j].x,
+ y: groupData[j].y,
+ groupId: this.groupId
+ });
+ }
+ return combinedData;
+ };
+
+ /**
+ * draw a bar graph
+ *
+ * @param groupIds
+ * @param processedGroupData
+ */
+ Bargraph.draw = function (groupIds, processedGroupData, framework) {
+ var combinedData = [];
+ var intersections = {};
+ var coreDistance;
+ var key, drawData;
+ var group;
+ var i, j;
+ var barPoints = 0;
- // reload the settings of the nodes to apply changes in groups that are not referenced by pointer.
- if (options.groups !== undefined) {
- this.body.emitter.emit('refreshNodes');
+ // combine all barchart data
+ for (i = 0; i < groupIds.length; i++) {
+ group = framework.groups[groupIds[i]];
+ if (group.options.style === 'bar') {
+ if (group.visible === true && (framework.options.groups.visibility[groupIds[i]] === undefined || framework.options.groups.visibility[groupIds[i]] === true)) {
+ for (j = 0; j < processedGroupData[groupIds[i]].length; j++) {
+ combinedData.push({
+ x: processedGroupData[groupIds[i]][j].x,
+ y: processedGroupData[groupIds[i]][j].y,
+ groupId: groupIds[i],
+ label: processedGroupData[groupIds[i]][j].label
+ });
+ barPoints += 1;
+ }
+ }
}
- // these two do not have options at the moment, here for completeness
- //this.view.setOptions(options.view);
- //this.clustering.setOptions(options.clustering);
+ }
- this.configurator.setOptions(options.configure);
+ if (barPoints === 0) {
+ return;
+ }
- // if the configuration system is enabled, copy all options and put them into the config system
- if (this.configurator.options.enabled === true) {
- var 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
- util.deepExtend(networkOptions.interaction, this.selectionHandler.options);
- util.deepExtend(networkOptions.interaction, this.renderer.options);
+ // sort by time and by group
+ combinedData.sort(function (a, b) {
+ if (a.x === b.x) {
+ return a.groupId < b.groupId ? -1 : 1;
+ } else {
+ return a.x - b.x;
+ }
+ });
- util.deepExtend(networkOptions.interaction, this.interactionHandler.options);
- util.deepExtend(networkOptions.manipulation, this.manipulation.options);
- util.deepExtend(networkOptions.physics, this.physics.options);
+ // get intersections
+ Bargraph._getDataIntersections(intersections, combinedData);
- // load globals into the global object
- util.deepExtend(networkOptions.global, this.canvas.options);
- util.deepExtend(networkOptions.global, this.options);
+ // plot barchart
+ for (i = 0; i < combinedData.length; i++) {
+ group = framework.groups[combinedData[i].groupId];
+ var minWidth = 0.1 * group.options.barChart.width;
- this.configurator.setModuleOptions(networkOptions);
- }
+ key = combinedData[i].x;
+ var heightOffset = 0;
+ if (intersections[key] === undefined) {
+ if (i + 1 < combinedData.length) {
+ coreDistance = Math.abs(combinedData[i + 1].x - key);
+ }
+ if (i > 0) {
+ coreDistance = Math.min(coreDistance, Math.abs(combinedData[i - 1].x - key));
+ }
+ drawData = Bargraph._getSafeDrawData(coreDistance, group, minWidth);
+ } else {
+ var nextKey = i + (intersections[key].amount - intersections[key].resolved);
+ var prevKey = i - (intersections[key].resolved + 1);
+ if (nextKey < combinedData.length) {
+ coreDistance = Math.abs(combinedData[nextKey].x - key);
+ }
+ if (prevKey > 0) {
+ coreDistance = Math.min(coreDistance, Math.abs(combinedData[prevKey].x - key));
+ }
+ drawData = Bargraph._getSafeDrawData(coreDistance, group, minWidth);
+ intersections[key].resolved += 1;
- // handle network global options
- if (options.clickToUse !== undefined) {
- if (options.clickToUse === true) {
- if (this.activator === undefined) {
- this.activator = new Activator(this.frame);
- this.activator.on('change', this._createKeyBinds.bind(this));
+ if (group.options.stack === true) {
+ if (combinedData[i].y < group.zeroPosition) {
+ heightOffset = intersections[key].accumulatedNegative;
+ intersections[key].accumulatedNegative += group.zeroPosition - combinedData[i].y;
+ } else {
+ heightOffset = intersections[key].accumulatedPositive;
+ intersections[key].accumulatedPositive += group.zeroPosition - combinedData[i].y;
}
- } else {
- if (this.activator !== undefined) {
- this.activator.destroy();
- delete this.activator;
+ } else if (group.options.barChart.sideBySide === true) {
+ drawData.width = drawData.width / intersections[key].amount;
+ drawData.offset += intersections[key].resolved * drawData.width - 0.5 * drawData.width * (intersections[key].amount + 1);
+ if (group.options.barChart.align === 'left') {
+ drawData.offset -= 0.5 * drawData.width;
+ } else if (group.options.barChart.align === 'right') {
+ drawData.offset += 0.5 * drawData.width;
}
- this.body.emitter.emit('activate');
}
- } else {
- this.body.emitter.emit('activate');
}
+ DOMutil.drawBar(combinedData[i].x + drawData.offset, combinedData[i].y - heightOffset, drawData.width, group.zeroPosition - combinedData[i].y, group.className + ' vis-bar', framework.svgElements, framework.svg, group.style);
+ // draw points
+ if (group.options.drawPoints.enabled === true) {
+ Points.draw([combinedData[i]], group, framework, drawData.offset);
+ //DOMutil.drawPoint(combinedData[i].x + drawData.offset, combinedData[i].y, group, framework.svgElements, framework.svg);
+ }
+ }
+ };
- this.canvas.setSize();
-
- // start the physics simulation. Can be safely called multiple times.
- this.body.emitter.emit('startSimulation');
+ /**
+ * Fill the intersections object with counters of how many datapoints share the same x coordinates
+ * @param intersections
+ * @param combinedData
+ * @private
+ */
+ Bargraph._getDataIntersections = function (intersections, combinedData) {
+ // get intersections
+ var coreDistance;
+ for (var i = 0; i < combinedData.length; i++) {
+ if (i + 1 < combinedData.length) {
+ coreDistance = Math.abs(combinedData[i + 1].x - combinedData[i].x);
+ }
+ if (i > 0) {
+ coreDistance = Math.min(coreDistance, Math.abs(combinedData[i - 1].x - combinedData[i].x));
+ }
+ if (coreDistance === 0) {
+ if (intersections[combinedData[i].x] === undefined) {
+ intersections[combinedData[i].x] = { amount: 0, resolved: 0, accumulatedPositive: 0, accumulatedNegative: 0 };
+ }
+ intersections[combinedData[i].x].amount += 1;
+ }
}
};
/**
- * Update the this.body.nodeIndices with the most recent node index list
+ * Get the width and offset for bargraphs based on the coredistance between datapoints
+ *
+ * @param coreDistance
+ * @param group
+ * @param minWidth
+ * @returns {{width: Number, offset: Number}}
* @private
*/
- Network.prototype._updateVisibleIndices = function () {
- var nodes = this.body.nodes;
- var edges = this.body.edges;
- this.body.nodeIndices = [];
- this.body.edgeIndices = [];
+ Bargraph._getSafeDrawData = function (coreDistance, group, minWidth) {
+ var width, offset;
+ if (coreDistance < group.options.barChart.width && coreDistance > 0) {
+ width = coreDistance < minWidth ? minWidth : coreDistance;
- for (var nodeId in nodes) {
- if (nodes.hasOwnProperty(nodeId)) {
- if (nodes[nodeId].options.hidden === false) {
- this.body.nodeIndices.push(nodeId);
- }
+ offset = 0; // recalculate offset with the new width;
+ if (group.options.barChart.align === 'left') {
+ offset -= 0.5 * coreDistance;
+ } else if (group.options.barChart.align === 'right') {
+ offset += 0.5 * coreDistance;
+ }
+ } else {
+ // default settings
+ width = group.options.barChart.width;
+ offset = 0;
+ if (group.options.barChart.align === 'left') {
+ offset -= 0.5 * group.options.barChart.width;
+ } else if (group.options.barChart.align === 'right') {
+ offset += 0.5 * group.options.barChart.width;
}
}
- for (var edgeId in edges) {
- if (edges.hasOwnProperty(edgeId)) {
- if (edges[edgeId].options.hidden === false) {
- this.body.edgeIndices.push(edgeId);
+ return { width: width, offset: offset };
+ };
+
+ Bargraph.getStackedYRange = function (combinedData, groupRanges, groupIds, groupLabel, orientation) {
+ if (combinedData.length > 0) {
+ // sort by time and by group
+ combinedData.sort(function (a, b) {
+ if (a.x === b.x) {
+ return a.groupId < b.groupId ? -1 : 1;
+ } else {
+ return a.x - b.x;
+ }
+ });
+ var intersections = {};
+
+ Bargraph._getDataIntersections(intersections, combinedData);
+ groupRanges[groupLabel] = Bargraph._getStackedYRange(intersections, combinedData);
+ groupRanges[groupLabel].yAxisOrientation = orientation;
+ groupIds.push(groupLabel);
+ }
+ };
+
+ Bargraph._getStackedYRange = function (intersections, combinedData) {
+ var key;
+ var yMin = combinedData[0].y;
+ var yMax = combinedData[0].y;
+ for (var i = 0; i < combinedData.length; i++) {
+ key = combinedData[i].x;
+ if (intersections[key] === undefined) {
+ yMin = yMin > combinedData[i].y ? combinedData[i].y : yMin;
+ yMax = yMax < combinedData[i].y ? combinedData[i].y : yMax;
+ } else {
+ if (combinedData[i].y < 0) {
+ intersections[key].accumulatedNegative += combinedData[i].y;
+ } else {
+ intersections[key].accumulatedPositive += combinedData[i].y;
}
}
}
+ for (var xpos in intersections) {
+ if (intersections.hasOwnProperty(xpos)) {
+ yMin = yMin > intersections[xpos].accumulatedNegative ? intersections[xpos].accumulatedNegative : yMin;
+ yMin = yMin > intersections[xpos].accumulatedPositive ? intersections[xpos].accumulatedPositive : yMin;
+ yMax = yMax < intersections[xpos].accumulatedNegative ? intersections[xpos].accumulatedNegative : yMax;
+ yMax = yMax < intersections[xpos].accumulatedPositive ? intersections[xpos].accumulatedPositive : yMax;
+ }
+ }
+
+ return { min: yMin, max: yMax };
};
- /**
- * Bind all events
- */
- Network.prototype.bindEventListeners = function () {
- var _this2 = this;
+ module.exports = Bargraph;
- // this event will trigger a rebuilding of the cache everything. Used when nodes or edges have been added or removed.
- this.body.emitter.on('_dataChanged', function () {
- // update shortcut lists
- _this2._updateVisibleIndices();
- _this2.physics.updatePhysicsData();
+/***/ },
+/* 58 */
+/***/ function(module, exports, __webpack_require__) {
- // call the dataUpdated event because the only difference between the two is the updating of the indices
- _this2.body.emitter.emit('_dataUpdated');
- });
+ 'use strict';
- // this is called when options of EXISTING nodes or edges have changed.
- this.body.emitter.on('_dataUpdated', function () {
- // update values
- _this2._updateValueRange(_this2.body.nodes);
- _this2._updateValueRange(_this2.body.edges);
- // start simulation (can be called safely, even if already running)
- _this2.body.emitter.emit('startSimulation');
- });
- };
+ var util = __webpack_require__(9);
+ var DOMutil = __webpack_require__(14);
+ var Component = __webpack_require__(28);
/**
- * Set nodes and edges, and optionally options as well.
- *
- * @param {Object} data Object containing parameters:
- * {Array | DataSet | DataView} [nodes] Array with nodes
- * {Array | DataSet | DataView} [edges] Array with edges
- * {String} [dot] String containing data in DOT format
- * {String} [gephi] String containing data in gephi JSON format
- * {Options} [options] Object with options
+ * Legend for Graph2d
*/
- Network.prototype.setData = function (data) {
- // reset the physics engine.
- this.body.emitter.emit('resetPhysics');
- this.body.emitter.emit('_resetData');
+ function Legend(body, options, side, linegraphOptions) {
+ this.body = body;
+ this.defaultOptions = {
+ enabled: true,
+ icons: true,
+ iconSize: 20,
+ iconSpacing: 6,
+ left: {
+ visible: true,
+ position: 'top-left' // top/bottom - left,center,right
+ },
+ right: {
+ visible: true,
+ position: 'top-left' // top/bottom - left,center,right
+ }
+ };
+ this.side = side;
+ this.options = util.extend({}, this.defaultOptions);
+ this.linegraphOptions = linegraphOptions;
- // unselect all to ensure no selections from old data are carried over.
- this.selectionHandler.unselectAll();
+ this.svgElements = {};
+ this.dom = {};
+ this.groups = {};
+ this.amountOfGroups = 0;
+ this._create();
- if (data && data.dot && (data.nodes || data.edges)) {
- throw new SyntaxError('Data must contain either parameter "dot" or ' + ' parameter pair "nodes" and "edges", but not both.');
+ this.setOptions(options);
+ }
+
+ Legend.prototype = new Component();
+
+ Legend.prototype.clear = function () {
+ this.groups = {};
+ this.amountOfGroups = 0;
+ };
+
+ Legend.prototype.addGroup = function (label, graphOptions) {
+
+ if (!this.groups.hasOwnProperty(label)) {
+ this.groups[label] = graphOptions;
}
+ this.amountOfGroups += 1;
+ };
- // set options
- this.setOptions(data && data.options);
- // set all data
- if (data && data.dot) {
- console.log('The dot property has been depricated. Please use the static convertDot method to convert DOT into vis.network format and use the normal data format with nodes and edges. This converter is used like this: var data = vis.network.convertDot(dotString);');
- // parse DOT file
- var dotData = dotparser.DOTToGraph(data.dot);
- this.setData(dotData);
- return;
- } else if (data && data.gephi) {
- // parse DOT file
- console.log('The gephi property has been depricated. Please use the static convertGephi method to convert gephi into vis.network format and use the normal data format with nodes and edges. This converter is used like this: var data = vis.network.convertGephi(gephiJson);');
- var gephiData = gephiParser.parseGephi(data.gephi);
- this.setData(gephiData);
- return;
- } else {
- this.nodesHandler.setData(data && data.nodes, true);
- this.edgesHandler.setData(data && data.edges, true);
+ Legend.prototype.updateGroup = function (label, graphOptions) {
+ this.groups[label] = graphOptions;
+ };
+
+ Legend.prototype.removeGroup = function (label) {
+ if (this.groups.hasOwnProperty(label)) {
+ delete this.groups[label];
+ this.amountOfGroups -= 1;
}
+ };
- // emit change in data
- this.body.emitter.emit('_dataChanged');
+ Legend.prototype._create = function () {
+ this.dom.frame = document.createElement('div');
+ this.dom.frame.className = 'vis-legend';
+ this.dom.frame.style.position = 'absolute';
+ this.dom.frame.style.top = '10px';
+ this.dom.frame.style.display = 'block';
- // find a stable position or start animating to a stable position
- this.body.emitter.emit('initPhysics');
+ this.dom.textArea = document.createElement('div');
+ this.dom.textArea.className = 'vis-legend-text';
+ this.dom.textArea.style.position = 'relative';
+ this.dom.textArea.style.top = '0px';
+
+ this.svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
+ this.svg.style.position = 'absolute';
+ this.svg.style.top = 0 + 'px';
+ this.svg.style.width = this.options.iconSize + 5 + 'px';
+ this.svg.style.height = '100%';
+
+ this.dom.frame.appendChild(this.svg);
+ this.dom.frame.appendChild(this.dom.textArea);
};
/**
- * Cleans up all bindings of the network, removing it fully from the memory IF the variable is set to null after calling this function.
- * var network = new vis.Network(..);
- * network.destroy();
- * network = null;
+ * Hide the component from the DOM
*/
- Network.prototype.destroy = function () {
- this.body.emitter.emit('destroy');
- // clear events
- this.body.emitter.off();
- this.off();
+ Legend.prototype.hide = function () {
+ // remove the frame containing the items
+ if (this.dom.frame.parentNode) {
+ this.dom.frame.parentNode.removeChild(this.dom.frame);
+ }
+ };
- // delete modules
- delete this.groups;
- delete this.canvas;
- delete this.selectionHandler;
- delete this.interactionHandler;
- delete this.view;
- delete this.renderer;
- delete this.physics;
- delete this.layoutEngine;
- delete this.clustering;
- delete this.manipulation;
- delete this.nodesHandler;
- delete this.edgesHandler;
- delete this.configurator;
- delete this.images;
+ /**
+ * Show the component in the DOM (when not already visible).
+ * @return {Boolean} changed
+ */
+ Legend.prototype.show = function () {
+ // show frame containing the items
+ if (!this.dom.frame.parentNode) {
+ this.body.dom.center.appendChild(this.dom.frame);
+ }
+ };
- // delete emitter bindings
- delete this.body.emitter.emit;
- delete this.body.emitter.on;
- delete this.body.emitter.off;
- delete this.body.emitter.once;
- delete this.body.emitter;
+ Legend.prototype.setOptions = function (options) {
+ var fields = ['enabled', 'orientation', 'icons', 'left', 'right'];
+ util.selectiveDeepExtend(fields, this.options, options);
+ };
- for (var nodeId in this.body.nodes) {
- delete this.body.nodes[nodeId];
- }
- for (var edgeId in this.body.edges) {
- delete this.body.edges[edgeId];
+ Legend.prototype.redraw = function () {
+ var activeGroups = 0;
+ var groupArray = Object.keys(this.groups);
+ groupArray.sort(function (a, b) {
+ return a < b ? -1 : 1;
+ });
+
+ for (var i = 0; i < groupArray.length; i++) {
+ var groupId = groupArray[i];
+ if (this.groups[groupId].visible == true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] == true)) {
+ activeGroups++;
+ }
}
- // remove the container and everything inside it recursively
- util.recursiveDOMDelete(this.body.container);
- };
+ if (this.options[this.side].visible == false || this.amountOfGroups == 0 || this.options.enabled == false || activeGroups == 0) {
+ this.hide();
+ } else {
+ this.show();
+ if (this.options[this.side].position == 'top-left' || this.options[this.side].position == 'bottom-left') {
+ this.dom.frame.style.left = '4px';
+ this.dom.frame.style.textAlign = 'left';
+ this.dom.textArea.style.textAlign = 'left';
+ this.dom.textArea.style.left = this.options.iconSize + 15 + 'px';
+ this.dom.textArea.style.right = '';
+ this.svg.style.left = 0 + 'px';
+ this.svg.style.right = '';
+ } else {
+ this.dom.frame.style.right = '4px';
+ this.dom.frame.style.textAlign = 'right';
+ this.dom.textArea.style.textAlign = 'right';
+ this.dom.textArea.style.right = this.options.iconSize + 15 + 'px';
+ this.dom.textArea.style.left = '';
+ this.svg.style.right = 0 + 'px';
+ this.svg.style.left = '';
+ }
- /**
- * Update the values of all object in the given array according to the current
- * value range of the objects in the array.
- * @param {Object} obj An object containing a set of Edges or Nodes
- * The objects must have a method getValue() and
- * setValueRange(min, max).
- * @private
- */
- Network.prototype._updateValueRange = function (obj) {
- var id;
+ if (this.options[this.side].position == 'top-left' || this.options[this.side].position == 'top-right') {
+ this.dom.frame.style.top = 4 - Number(this.body.dom.center.style.top.replace('px', '')) + 'px';
+ this.dom.frame.style.bottom = '';
+ } else {
+ var scrollableHeight = this.body.domProps.center.height - this.body.domProps.centerContainer.height;
+ this.dom.frame.style.bottom = 4 + scrollableHeight + Number(this.body.dom.center.style.top.replace('px', '')) + 'px';
+ this.dom.frame.style.top = '';
+ }
- // determine the range of the objects
- var valueMin = undefined;
- var valueMax = undefined;
- var valueTotal = 0;
- for (id in obj) {
- if (obj.hasOwnProperty(id)) {
- var value = obj[id].getValue();
- if (value !== undefined) {
- valueMin = valueMin === undefined ? value : Math.min(value, valueMin);
- valueMax = valueMax === undefined ? value : Math.max(value, valueMax);
- valueTotal += value;
+ if (this.options.icons == false) {
+ this.dom.frame.style.width = this.dom.textArea.offsetWidth + 10 + 'px';
+ this.dom.textArea.style.right = '';
+ this.dom.textArea.style.left = '';
+ this.svg.style.width = '0px';
+ } else {
+ this.dom.frame.style.width = this.options.iconSize + 15 + this.dom.textArea.offsetWidth + 10 + 'px';
+ this.drawLegendIcons();
+ }
+
+ var content = '';
+ for (var i = 0; i < groupArray.length; i++) {
+ var groupId = groupArray[i];
+ if (this.groups[groupId].visible == true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] == true)) {
+ content += this.groups[groupId].content + '
';
}
}
+ this.dom.textArea.innerHTML = content;
+ this.dom.textArea.style.lineHeight = 0.75 * this.options.iconSize + this.options.iconSpacing + 'px';
}
+ };
+
+ Legend.prototype.drawLegendIcons = function () {
+ if (this.dom.frame.parentNode) {
+ var groupArray = Object.keys(this.groups);
+ groupArray.sort(function (a, b) {
+ return a < b ? -1 : 1;
+ });
+
+ DOMutil.prepareElements(this.svgElements);
+ var padding = window.getComputedStyle(this.dom.frame).paddingTop;
+ var iconOffset = Number(padding.replace('px', ''));
+ var x = iconOffset;
+ var iconWidth = this.options.iconSize;
+ var iconHeight = 0.75 * this.options.iconSize;
+ var y = iconOffset + 0.5 * iconHeight + 3;
- // adjust the range of all objects
- if (valueMin !== undefined && valueMax !== undefined) {
- for (id in obj) {
- if (obj.hasOwnProperty(id)) {
- obj[id].setValueRange(valueMin, valueMax, valueTotal);
+ this.svg.style.width = iconWidth + 5 + iconOffset + 'px';
+
+ for (var i = 0; i < groupArray.length; i++) {
+ var groupId = groupArray[i];
+ if (this.groups[groupId].visible == true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] == true)) {
+ this.groups[groupId].drawIcon(x, y, this.svgElements, this.svg, iconWidth, iconHeight);
+ y += iconHeight + this.options.iconSpacing;
}
}
+
+ DOMutil.cleanupElements(this.svgElements);
}
};
+ module.exports = Legend;
+
+/***/ },
+/* 59 */
+/***/ function(module, exports, __webpack_require__) {
+
/**
- * Returns true when the Network is active.
- * @returns {boolean}
+ * This object contains all possible options. It will check if the types are correct, if required if the option is one
+ * of the allowed values.
+ *
+ * __any__ means that the name of the property does not matter.
+ * __type__ is a required field for all objects and contains the allowed types of all objects
*/
- Network.prototype.isActive = function () {
- return !this.activator || this.activator.active;
- };
+ 'use strict';
- Network.prototype.setSize = function () {
- return this.canvas.setSize.apply(this.canvas, arguments);
- };
- Network.prototype.canvasToDOM = function () {
- return this.canvas.canvasToDOM.apply(this.canvas, arguments);
- };
- Network.prototype.DOMtoCanvas = function () {
- return this.canvas.setSize.DOMtoCanvas(this.canvas, arguments);
- };
- Network.prototype.findNode = function () {
- return this.clustering.findNode.apply(this.clustering, arguments);
- };
- Network.prototype.isCluster = function () {
- return this.clustering.isCluster.apply(this.clustering, arguments);
- };
- Network.prototype.openCluster = function () {
- return this.clustering.openCluster.apply(this.clustering, arguments);
- };
- Network.prototype.cluster = function () {
- return this.clustering.cluster.apply(this.clustering, arguments);
- };
- Network.prototype.clusterByConnection = function () {
- return this.clustering.clusterByConnection.apply(this.clustering, arguments);
- };
- Network.prototype.clusterByHubsize = function () {
- return this.clustering.clusterByHubsize.apply(this.clustering, arguments);
- };
- Network.prototype.clusterOutliers = function () {
- return this.clustering.clusterOutliers.apply(this.clustering, arguments);
- };
- Network.prototype.getSeed = function () {
- return this.layoutEngine.getSeed.apply(this.layoutEngine, arguments);
- };
- Network.prototype.enableEditMode = function () {
- return this.manipulation.enableEditMode.apply(this.manipulation, arguments);
- };
- Network.prototype.disableEditMode = function () {
- return this.manipulation.disableEditMode.apply(this.manipulation, arguments);
- };
- Network.prototype.addNodeMode = function () {
- return this.manipulation.addNodeMode.apply(this.manipulation, arguments);
- };
- Network.prototype.editNode = function () {
- return this.manipulation.editNode.apply(this.manipulation, arguments);
- };
- Network.prototype.editNodeMode = function () {
- console.log('please use editNode instead of editNodeMode');return this.manipulation.editNode.apply(this.manipulation, arguments);
- };
- Network.prototype.addEdgeMode = function () {
- return this.manipulation.addEdgeMode.apply(this.manipulation, arguments);
- };
- Network.prototype.editEdgeMode = function () {
- return this.manipulation.editEdgeMode.apply(this.manipulation, arguments);
- };
- Network.prototype.deleteSelected = function () {
- return this.manipulation.deleteSelected.apply(this.manipulation, arguments);
- };
- Network.prototype.getPositions = function () {
- return this.nodesHandler.getPositions.apply(this.nodesHandler, arguments);
- };
- Network.prototype.storePositions = function () {
- return this.nodesHandler.storePositions.apply(this.nodesHandler, arguments);
- };
- Network.prototype.getBoundingBox = function () {
- return this.nodesHandler.getBoundingBox.apply(this.nodesHandler, arguments);
+ Object.defineProperty(exports, '__esModule', {
+ value: true
+ });
+ var string = 'string';
+ var boolean = 'boolean';
+ var number = 'number';
+ var array = 'array';
+ var date = 'date';
+ var object = 'object'; // should only be in a __type__ property
+ var dom = 'dom';
+ var moment = 'moment';
+ var fn = 'function';
+ var nada = 'null';
+ var undef = 'undefined';
+ var any = 'any';
+
+ var allOptions = {
+ configure: {
+ enabled: { boolean: boolean },
+ filter: { boolean: boolean, fn: fn },
+ container: { dom: dom },
+ __type__: { object: object, boolean: boolean, fn: fn }
+ },
+
+ //globals :
+ yAxisOrientation: { string: ['left', 'right'] },
+ defaultGroup: { string: string },
+ sort: { boolean: boolean },
+ sampling: { boolean: boolean },
+ stack: { boolean: boolean },
+ graphHeight: { string: string, number: number },
+ shaded: {
+ enabled: { boolean: boolean },
+ orientation: { string: ['bottom', 'top'] }, // top, bottom
+ __type__: { boolean: boolean, object: object }
+ },
+ style: { string: ['line', 'bar', 'points'] }, // line, bar
+ barChart: {
+ width: { number: number },
+ sideBySide: { boolean: boolean },
+ align: { string: ['left', 'center', 'right'] },
+ __type__: { object: object }
+ },
+ interpolation: {
+ enabled: { boolean: boolean },
+ parametrization: { string: ['centripetal', 'chordal', 'uniform'] }, // uniform (alpha = 0.0), chordal (alpha = 1.0), centripetal (alpha = 0.5)
+ alpha: { number: number },
+ __type__: { object: object, boolean: boolean }
+ },
+ drawPoints: {
+ enabled: { boolean: boolean },
+ size: { number: number },
+ style: { string: ['square', 'circle'] }, // square, circle
+ __type__: { object: object, boolean: boolean }
+ },
+ dataAxis: {
+ showMinorLabels: { boolean: boolean },
+ showMajorLabels: { boolean: boolean },
+ icons: { boolean: boolean },
+ width: { string: string, number: number },
+ visible: { boolean: boolean },
+ alignZeros: { boolean: boolean },
+ left: {
+ range: { min: { number: number }, max: { number: number }, __type__: { object: object } },
+ format: { fn: fn },
+ title: { text: { string: string, number: number }, style: { string: string }, __type__: { object: object } },
+ __type__: { object: object }
+ },
+ right: {
+ range: { min: { number: number }, max: { number: number }, __type__: { object: object } },
+ format: { fn: fn },
+ title: { text: { string: string, number: number }, style: { string: string }, __type__: { object: object } },
+ __type__: { object: object }
+ },
+ __type__: { object: object }
+ },
+ legend: {
+ enabled: { boolean: boolean },
+ icons: { boolean: boolean },
+ left: {
+ visible: { boolean: boolean },
+ position: { string: ['top-right', 'bottom-right', 'top-left', 'bottom-left'] },
+ __type__: { object: object }
+ },
+ right: {
+ visible: { boolean: boolean },
+ position: { string: ['top-right', 'bottom-right', 'top-left', 'bottom-left'] },
+ __type__: { object: object }
+ },
+ __type__: { object: object, boolean: boolean }
+ },
+ groups: {
+ visibility: { any: any },
+ __type__: { object: object }
+ },
+
+ autoResize: { boolean: boolean },
+ clickToUse: { boolean: boolean },
+ end: { number: number, date: date, string: string, moment: moment },
+ format: {
+ minorLabels: {
+ millisecond: { string: string, undef: undef },
+ second: { string: string, undef: undef },
+ minute: { string: string, undef: undef },
+ hour: { string: string, undef: undef },
+ weekday: { string: string, undef: undef },
+ day: { string: string, undef: undef },
+ month: { string: string, undef: undef },
+ year: { string: string, undef: undef },
+ __type__: { object: object }
+ },
+ majorLabels: {
+ millisecond: { string: string, undef: undef },
+ second: { string: string, undef: undef },
+ minute: { string: string, undef: undef },
+ hour: { string: string, undef: undef },
+ weekday: { string: string, undef: undef },
+ day: { string: string, undef: undef },
+ month: { string: string, undef: undef },
+ year: { string: string, undef: undef },
+ __type__: { object: object }
+ },
+ __type__: { object: object }
+ },
+ height: { string: string, number: number },
+ hiddenDates: { object: object, array: array },
+ locale: { string: string },
+ locales: {
+ __any__: { object: object },
+ __type__: { object: object }
+ },
+ max: { date: date, number: number, string: string, moment: moment },
+ maxHeight: { number: number, string: string },
+ min: { date: date, number: number, string: string, moment: moment },
+ minHeight: { number: number, string: string },
+ moveable: { boolean: boolean },
+ multiselect: { boolean: boolean },
+ orientation: { string: string },
+ showCurrentTime: { boolean: boolean },
+ showMajorLabels: { boolean: boolean },
+ showMinorLabels: { boolean: boolean },
+ start: { date: date, number: number, string: string, moment: moment },
+ timeAxis: {
+ scale: { string: string, undef: undef },
+ step: { number: number, undef: undef },
+ __type__: { object: object }
+ },
+ width: { string: string, number: number },
+ zoomable: { boolean: boolean },
+ zoomMax: { number: number },
+ zoomMin: { number: number },
+ __type__: { object: object }
};
- Network.prototype.getConnectedNodes = function (objectId) {
- if (this.body.nodes[objectId] !== undefined) {
- return this.nodesHandler.getConnectedNodes.apply(this.nodesHandler, arguments);
- } else {
- return this.edgesHandler.getConnectedNodes.apply(this.edgesHandler, arguments);
+
+ var configureOptions = {
+ global: {
+ yAxisOrientation: ['left', 'right'],
+ sort: true,
+ sampling: true,
+ stack: false,
+ shaded: {
+ enabled: false,
+ orientation: ['top', 'bottom'] // top, bottom
+ },
+ style: ['line', 'bar', 'points'], // line, bar
+ barChart: {
+ width: [50, 5, 100, 5],
+ sideBySide: false,
+ align: ['left', 'center', 'right'] // left, center, right
+ },
+ interpolation: {
+ enabled: true,
+ parametrization: ['centripetal', 'chordal', 'uniform'] // uniform (alpha = 0.0), chordal (alpha = 1.0), centripetal (alpha = 0.5)
+ },
+ drawPoints: {
+ enabled: true,
+ size: [6, 2, 30, 1],
+ style: ['square', 'circle'] // square, circle
+ },
+ dataAxis: {
+ showMinorLabels: true,
+ showMajorLabels: true,
+ icons: false,
+ width: [40, 0, 200, 1],
+ visible: true,
+ alignZeros: true,
+ left: {
+ //range: {min:undefined,max:undefined},
+ //format: function (value) {return value;},
+ title: { text: '', style: '' }
+ },
+ right: {
+ //range: {min:undefined,max:undefined},
+ //format: function (value) {return value;},
+ title: { text: '', style: '' }
+ }
+ },
+ legend: {
+ enabled: false,
+ icons: true,
+ left: {
+ visible: true,
+ position: ['top-right', 'bottom-right', 'top-left', 'bottom-left'] // top/bottom - left,right
+ },
+ right: {
+ visible: true,
+ position: ['top-right', 'bottom-right', 'top-left', 'bottom-left'] // top/bottom - left,right
+ }
+ },
+
+ autoResize: true,
+ clickToUse: false,
+ end: '',
+ format: {
+ minorLabels: {
+ millisecond: 'SSS',
+ second: 's',
+ minute: 'HH:mm',
+ hour: 'HH:mm',
+ weekday: 'ddd D',
+ day: 'D',
+ month: 'MMM',
+ year: 'YYYY'
+ },
+ majorLabels: {
+ millisecond: 'HH:mm:ss',
+ second: 'D MMMM HH:mm',
+ minute: 'ddd D MMMM',
+ hour: 'ddd D MMMM',
+ weekday: 'MMMM YYYY',
+ day: 'MMMM YYYY',
+ month: 'YYYY',
+ year: ''
+ }
+ },
+
+ height: '',
+ locale: '',
+ max: '',
+ maxHeight: '',
+ min: '',
+ minHeight: '',
+ moveable: true,
+ orientation: ['both', 'bottom', 'top'],
+ showCurrentTime: false,
+ showMajorLabels: true,
+ showMinorLabels: true,
+ start: '',
+ width: '100%',
+ zoomable: true,
+ zoomMax: [315360000000000, 10, 315360000000000, 1],
+ zoomMin: [10, 10, 315360000000000, 1]
}
};
- Network.prototype.getEdges = function () {
- return this.nodesHandler.getEdges.apply(this.nodesHandler, arguments);
- };
- Network.prototype.startSimulation = function () {
- return this.physics.startSimulation.apply(this.physics, arguments);
- };
- Network.prototype.stopSimulation = function () {
- return this.physics.stopSimulation.apply(this.physics, arguments);
- };
- Network.prototype.stabilize = function () {
- return this.physics.stabilize.apply(this.physics, arguments);
- };
- Network.prototype.getSelection = function () {
- return this.selectionHandler.getSelection.apply(this.selectionHandler, arguments);
- };
- Network.prototype.getSelectedNodes = function () {
- return this.selectionHandler.getSelectedNodes.apply(this.selectionHandler, arguments);
- };
- Network.prototype.getSelectedEdges = function () {
- return this.selectionHandler.getSelectedEdges.apply(this.selectionHandler, arguments);
- };
- Network.prototype.getNodeAt = function () {
- return this.selectionHandler.getNodeAt.apply(this.selectionHandler, arguments);
- };
- Network.prototype.getEdgeAt = function () {
- return this.selectionHandler.getEdgeAt.apply(this.selectionHandler, arguments);
- };
- Network.prototype.selectNodes = function () {
- return this.selectionHandler.selectNodes.apply(this.selectionHandler, arguments);
- };
- Network.prototype.selectEdges = function () {
- return this.selectionHandler.selectEdges.apply(this.selectionHandler, arguments);
- };
- Network.prototype.unselectAll = function () {
- return this.selectionHandler.unselectAll.apply(this.selectionHandler, arguments);
- };
- Network.prototype.redraw = function () {
- return this.renderer.redraw.apply(this.renderer, arguments);
- };
- Network.prototype.getScale = function () {
- return this.view.getScale.apply(this.view, arguments);
- };
- Network.prototype.getViewPosition = function () {
- return this.view.getViewPosition.apply(this.view, arguments);
- };
- Network.prototype.fit = function () {
- return this.view.fit.apply(this.view, arguments);
- };
- Network.prototype.moveTo = function () {
- return this.view.moveTo.apply(this.view, arguments);
- };
- Network.prototype.focus = function () {
- return this.view.focus.apply(this.view, arguments);
- };
- Network.prototype.releaseNode = function () {
- return this.view.releaseNode.apply(this.view, arguments);
- };
- module.exports = Network;
+ exports.allOptions = allOptions;
+ exports.configureOptions = configureOptions;
/***/ },
-/* 61 */
+/* 60 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
@@ -27101,7 +26707,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports["default"];
/***/ },
-/* 62 */
+/* 61 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -27116,11 +26722,11 @@ return /******/ (function(modules) { // webpackBootstrap
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
- var _componentsNode = __webpack_require__(63);
+ var _componentsNode = __webpack_require__(62);
var _componentsNode2 = _interopRequireDefault(_componentsNode);
- var _componentsSharedLabel = __webpack_require__(64);
+ var _componentsSharedLabel = __webpack_require__(63);
var _componentsSharedLabel2 = _interopRequireDefault(_componentsSharedLabel);
@@ -27550,22 +27156,25 @@ return /******/ (function(modules) { // webpackBootstrap
return nodeList;
}
}, {
- key: 'getEdges',
+ key: 'getConnectedEdges',
/**
* Get the ids of the edges connected to this node.
* @param nodeId
* @returns {*}
*/
- value: function getEdges(nodeId) {
+ value: function getConnectedEdges(nodeId) {
var edgeList = [];
if (this.body.nodes[nodeId] !== undefined) {
var node = this.body.nodes[nodeId];
for (var i = 0; i < node.edges.length; i++) {
edgeList.push(node.edges[i].id);
}
+ } else {
+ console.log('NodeId provided for getConnectedEdges does not exist. Provided: ', nodeId);
}
- return nodeList;
+ console.log(edgeList);
+ return edgeList;
}
}]);
@@ -27576,7 +27185,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 63 */
+/* 62 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -27591,63 +27200,63 @@ return /******/ (function(modules) { // webpackBootstrap
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
- var _sharedLabel = __webpack_require__(64);
+ var _sharedLabel = __webpack_require__(63);
var _sharedLabel2 = _interopRequireDefault(_sharedLabel);
- var _nodesShapesBox = __webpack_require__(65);
+ var _nodesShapesBox = __webpack_require__(64);
var _nodesShapesBox2 = _interopRequireDefault(_nodesShapesBox);
- var _nodesShapesCircle = __webpack_require__(67);
+ var _nodesShapesCircle = __webpack_require__(66);
var _nodesShapesCircle2 = _interopRequireDefault(_nodesShapesCircle);
- var _nodesShapesCircularImage = __webpack_require__(69);
+ var _nodesShapesCircularImage = __webpack_require__(68);
var _nodesShapesCircularImage2 = _interopRequireDefault(_nodesShapesCircularImage);
- var _nodesShapesDatabase = __webpack_require__(70);
+ var _nodesShapesDatabase = __webpack_require__(69);
var _nodesShapesDatabase2 = _interopRequireDefault(_nodesShapesDatabase);
- var _nodesShapesDiamond = __webpack_require__(71);
+ var _nodesShapesDiamond = __webpack_require__(70);
var _nodesShapesDiamond2 = _interopRequireDefault(_nodesShapesDiamond);
- var _nodesShapesDot = __webpack_require__(73);
+ var _nodesShapesDot = __webpack_require__(72);
var _nodesShapesDot2 = _interopRequireDefault(_nodesShapesDot);
- var _nodesShapesEllipse = __webpack_require__(74);
+ var _nodesShapesEllipse = __webpack_require__(73);
var _nodesShapesEllipse2 = _interopRequireDefault(_nodesShapesEllipse);
- var _nodesShapesIcon = __webpack_require__(75);
+ var _nodesShapesIcon = __webpack_require__(74);
var _nodesShapesIcon2 = _interopRequireDefault(_nodesShapesIcon);
- var _nodesShapesImage = __webpack_require__(76);
+ var _nodesShapesImage = __webpack_require__(75);
var _nodesShapesImage2 = _interopRequireDefault(_nodesShapesImage);
- var _nodesShapesSquare = __webpack_require__(77);
+ var _nodesShapesSquare = __webpack_require__(76);
var _nodesShapesSquare2 = _interopRequireDefault(_nodesShapesSquare);
- var _nodesShapesStar = __webpack_require__(78);
+ var _nodesShapesStar = __webpack_require__(77);
var _nodesShapesStar2 = _interopRequireDefault(_nodesShapesStar);
- var _nodesShapesText = __webpack_require__(79);
+ var _nodesShapesText = __webpack_require__(78);
var _nodesShapesText2 = _interopRequireDefault(_nodesShapesText);
- var _nodesShapesTriangle = __webpack_require__(80);
+ var _nodesShapesTriangle = __webpack_require__(79);
var _nodesShapesTriangle2 = _interopRequireDefault(_nodesShapesTriangle);
- var _nodesShapesTriangleDown = __webpack_require__(81);
+ var _nodesShapesTriangleDown = __webpack_require__(80);
var _nodesShapesTriangleDown2 = _interopRequireDefault(_nodesShapesTriangleDown);
@@ -28091,7 +27700,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 64 */
+/* 63 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -28406,7 +28015,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 65 */
+/* 64 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -28425,7 +28034,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilNodeBase = __webpack_require__(66);
+ var _utilNodeBase = __webpack_require__(65);
var _utilNodeBase2 = _interopRequireDefault(_utilNodeBase);
@@ -28511,7 +28120,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 66 */
+/* 65 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -28579,7 +28188,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 67 */
+/* 66 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -28598,7 +28207,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilCircleImageBase = __webpack_require__(68);
+ var _utilCircleImageBase = __webpack_require__(67);
var _utilCircleImageBase2 = _interopRequireDefault(_utilCircleImageBase);
@@ -28669,7 +28278,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 68 */
+/* 67 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -28688,7 +28297,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilNodeBase = __webpack_require__(66);
+ var _utilNodeBase = __webpack_require__(65);
var _utilNodeBase2 = _interopRequireDefault(_utilNodeBase);
@@ -28819,7 +28428,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 69 */
+/* 68 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -28838,7 +28447,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilCircleImageBase = __webpack_require__(68);
+ var _utilCircleImageBase = __webpack_require__(67);
var _utilCircleImageBase2 = _interopRequireDefault(_utilCircleImageBase);
@@ -28924,7 +28533,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 70 */
+/* 69 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -28943,7 +28552,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilNodeBase = __webpack_require__(66);
+ var _utilNodeBase = __webpack_require__(65);
var _utilNodeBase2 = _interopRequireDefault(_utilNodeBase);
@@ -29029,7 +28638,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 71 */
+/* 70 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -29048,7 +28657,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilShapeBase = __webpack_require__(72);
+ var _utilShapeBase = __webpack_require__(71);
var _utilShapeBase2 = _interopRequireDefault(_utilShapeBase);
@@ -29085,7 +28694,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 72 */
+/* 71 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -29104,7 +28713,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilNodeBase = __webpack_require__(66);
+ var _utilNodeBase = __webpack_require__(65);
var _utilNodeBase2 = _interopRequireDefault(_utilNodeBase);
@@ -29184,7 +28793,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 73 */
+/* 72 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -29203,7 +28812,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilShapeBase = __webpack_require__(72);
+ var _utilShapeBase = __webpack_require__(71);
var _utilShapeBase2 = _interopRequireDefault(_utilShapeBase);
@@ -29240,7 +28849,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 74 */
+/* 73 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -29259,7 +28868,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilNodeBase = __webpack_require__(66);
+ var _utilNodeBase = __webpack_require__(65);
var _utilNodeBase2 = _interopRequireDefault(_utilNodeBase);
@@ -29347,7 +28956,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 75 */
+/* 74 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -29366,7 +28975,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilNodeBase = __webpack_require__(66);
+ var _utilNodeBase = __webpack_require__(65);
var _utilNodeBase2 = _interopRequireDefault(_utilNodeBase);
@@ -29463,7 +29072,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 76 */
+/* 75 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -29482,7 +29091,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilCircleImageBase = __webpack_require__(68);
+ var _utilCircleImageBase = __webpack_require__(67);
var _utilCircleImageBase2 = _interopRequireDefault(_utilCircleImageBase);
@@ -29550,7 +29159,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 77 */
+/* 76 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -29569,7 +29178,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilShapeBase = __webpack_require__(72);
+ var _utilShapeBase = __webpack_require__(71);
var _utilShapeBase2 = _interopRequireDefault(_utilShapeBase);
@@ -29607,7 +29216,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 78 */
+/* 77 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -29626,7 +29235,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilShapeBase = __webpack_require__(72);
+ var _utilShapeBase = __webpack_require__(71);
var _utilShapeBase2 = _interopRequireDefault(_utilShapeBase);
@@ -29663,7 +29272,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 79 */
+/* 78 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -29682,7 +29291,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilNodeBase = __webpack_require__(66);
+ var _utilNodeBase = __webpack_require__(65);
var _utilNodeBase2 = _interopRequireDefault(_utilNodeBase);
@@ -29748,7 +29357,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 80 */
+/* 79 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -29767,7 +29376,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilShapeBase = __webpack_require__(72);
+ var _utilShapeBase = __webpack_require__(71);
var _utilShapeBase2 = _interopRequireDefault(_utilShapeBase);
@@ -29804,7 +29413,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 81 */
+/* 80 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -29823,7 +29432,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilShapeBase = __webpack_require__(72);
+ var _utilShapeBase = __webpack_require__(71);
var _utilShapeBase2 = _interopRequireDefault(_utilShapeBase);
@@ -29860,7 +29469,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 82 */
+/* 81 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -29875,11 +29484,11 @@ return /******/ (function(modules) { // webpackBootstrap
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
- var _componentsEdge = __webpack_require__(83);
+ var _componentsEdge = __webpack_require__(82);
var _componentsEdge2 = _interopRequireDefault(_componentsEdge);
- var _componentsSharedLabel = __webpack_require__(64);
+ var _componentsSharedLabel = __webpack_require__(63);
var _componentsSharedLabel2 = _interopRequireDefault(_componentsSharedLabel);
@@ -29990,6 +29599,9 @@ return /******/ (function(modules) { // webpackBootstrap
// this allows external modules to force all dynamic curves to turn static.
this.body.emitter.on('_forceDisableDynamicCurves', function (type) {
+ if (type === 'dynamic') {
+ type = 'continuous';
+ }
var emitChange = false;
for (var edgeId in _this2.body.edges) {
if (_this2.body.edges.hasOwnProperty(edgeId)) {
@@ -30001,11 +29613,11 @@ return /******/ (function(modules) { // webpackBootstrap
if (edgeData !== undefined) {
var edgeOptions = edgeData.smooth;
if (edgeOptions !== undefined) {
- if (edgeOptions.enabled === true && edgeOptions.dynamic === true) {
+ if (edgeOptions.enabled === true && edgeOptions.type === 'dynamic') {
if (type === undefined) {
edge.setOptions({ smooth: false });
} else {
- edge.setOptions({ smooth: { dynamic: false, type: type } });
+ edge.setOptions({ smooth: { type: type } });
}
emitChange = true;
}
@@ -30294,7 +29906,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 83 */
+/* 82 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -30309,19 +29921,19 @@ return /******/ (function(modules) { // webpackBootstrap
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
- var _sharedLabel = __webpack_require__(64);
+ var _sharedLabel = __webpack_require__(63);
var _sharedLabel2 = _interopRequireDefault(_sharedLabel);
- var _edgesBezierEdgeDynamic = __webpack_require__(84);
+ var _edgesBezierEdgeDynamic = __webpack_require__(83);
var _edgesBezierEdgeDynamic2 = _interopRequireDefault(_edgesBezierEdgeDynamic);
- var _edgesBezierEdgeStatic = __webpack_require__(87);
+ var _edgesBezierEdgeStatic = __webpack_require__(86);
var _edgesBezierEdgeStatic2 = _interopRequireDefault(_edgesBezierEdgeStatic);
- var _edgesStraightEdge = __webpack_require__(88);
+ var _edgesStraightEdge = __webpack_require__(87);
var _edgesStraightEdge2 = _interopRequireDefault(_edgesStraightEdge);
@@ -30851,7 +30463,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 84 */
+/* 83 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -30870,7 +30482,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilBezierEdgeBase = __webpack_require__(85);
+ var _utilBezierEdgeBase = __webpack_require__(84);
var _utilBezierEdgeBase2 = _interopRequireDefault(_utilBezierEdgeBase);
@@ -31015,7 +30627,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 85 */
+/* 84 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -31034,7 +30646,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _EdgeBase2 = __webpack_require__(86);
+ var _EdgeBase2 = __webpack_require__(85);
var _EdgeBase3 = _interopRequireDefault(_EdgeBase2);
@@ -31162,7 +30774,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 86 */
+/* 85 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -31756,7 +31368,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 87 */
+/* 86 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -31775,7 +31387,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilBezierEdgeBase = __webpack_require__(85);
+ var _utilBezierEdgeBase = __webpack_require__(84);
var _utilBezierEdgeBase2 = _interopRequireDefault(_utilBezierEdgeBase);
@@ -32015,7 +31627,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 88 */
+/* 87 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -32034,7 +31646,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _utilEdgeBase = __webpack_require__(86);
+ var _utilEdgeBase = __webpack_require__(85);
var _utilEdgeBase2 = _interopRequireDefault(_utilEdgeBase);
@@ -32120,7 +31732,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 89 */
+/* 88 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -32135,35 +31747,35 @@ return /******/ (function(modules) { // webpackBootstrap
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
- var _componentsPhysicsBarnesHutSolver = __webpack_require__(90);
+ var _componentsPhysicsBarnesHutSolver = __webpack_require__(89);
var _componentsPhysicsBarnesHutSolver2 = _interopRequireDefault(_componentsPhysicsBarnesHutSolver);
- var _componentsPhysicsRepulsionSolver = __webpack_require__(91);
+ var _componentsPhysicsRepulsionSolver = __webpack_require__(90);
var _componentsPhysicsRepulsionSolver2 = _interopRequireDefault(_componentsPhysicsRepulsionSolver);
- var _componentsPhysicsHierarchicalRepulsionSolver = __webpack_require__(92);
+ var _componentsPhysicsHierarchicalRepulsionSolver = __webpack_require__(91);
var _componentsPhysicsHierarchicalRepulsionSolver2 = _interopRequireDefault(_componentsPhysicsHierarchicalRepulsionSolver);
- var _componentsPhysicsSpringSolver = __webpack_require__(93);
+ var _componentsPhysicsSpringSolver = __webpack_require__(92);
var _componentsPhysicsSpringSolver2 = _interopRequireDefault(_componentsPhysicsSpringSolver);
- var _componentsPhysicsHierarchicalSpringSolver = __webpack_require__(94);
+ var _componentsPhysicsHierarchicalSpringSolver = __webpack_require__(93);
var _componentsPhysicsHierarchicalSpringSolver2 = _interopRequireDefault(_componentsPhysicsHierarchicalSpringSolver);
- var _componentsPhysicsCentralGravitySolver = __webpack_require__(95);
+ var _componentsPhysicsCentralGravitySolver = __webpack_require__(94);
var _componentsPhysicsCentralGravitySolver2 = _interopRequireDefault(_componentsPhysicsCentralGravitySolver);
- var _componentsPhysicsFA2BasedRepulsionSolver = __webpack_require__(96);
+ var _componentsPhysicsFA2BasedRepulsionSolver = __webpack_require__(95);
var _componentsPhysicsFA2BasedRepulsionSolver2 = _interopRequireDefault(_componentsPhysicsFA2BasedRepulsionSolver);
- var _componentsPhysicsFA2BasedCentralGravitySolver = __webpack_require__(97);
+ var _componentsPhysicsFA2BasedCentralGravitySolver = __webpack_require__(96);
var _componentsPhysicsFA2BasedCentralGravitySolver2 = _interopRequireDefault(_componentsPhysicsFA2BasedCentralGravitySolver);
@@ -32743,7 +32355,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 90 */
+/* 89 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
@@ -33235,7 +32847,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports["default"];
/***/ },
-/* 91 */
+/* 90 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
@@ -33330,7 +32942,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports["default"];
/***/ },
-/* 92 */
+/* 91 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
@@ -33421,7 +33033,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports["default"];
/***/ },
-/* 93 */
+/* 92 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
@@ -33531,7 +33143,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports["default"];
/***/ },
-/* 94 */
+/* 93 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
@@ -33652,7 +33264,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports["default"];
/***/ },
-/* 95 */
+/* 94 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
@@ -33721,7 +33333,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports["default"];
/***/ },
-/* 96 */
+/* 95 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
@@ -33740,7 +33352,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _BarnesHutSolver2 = __webpack_require__(90);
+ var _BarnesHutSolver2 = __webpack_require__(89);
var _BarnesHutSolver3 = _interopRequireDefault(_BarnesHutSolver2);
@@ -33795,7 +33407,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports["default"];
/***/ },
-/* 97 */
+/* 96 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
@@ -33814,7 +33426,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _CentralGravitySolver2 = __webpack_require__(95);
+ var _CentralGravitySolver2 = __webpack_require__(94);
var _CentralGravitySolver3 = _interopRequireDefault(_CentralGravitySolver2);
@@ -33851,7 +33463,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports["default"];
/***/ },
-/* 98 */
+/* 97 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -33866,7 +33478,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
- var _componentsNodesCluster = __webpack_require__(99);
+ var _componentsNodesCluster = __webpack_require__(98);
var _componentsNodesCluster2 = _interopRequireDefault(_componentsNodesCluster);
@@ -34420,7 +34032,6 @@ return /******/ (function(modules) { // webpackBootstrap
edge.disconnect();
delete this.body.edges[edgeId];
} else {
-
// one of the nodes connected to this edge is in a cluster. We give the edge to that cluster so it will be released when that cluster is opened.
if (this.clusteredNodes[edge.fromId] !== undefined || this.clusteredNodes[edge.toId] !== undefined) {
var fromId = undefined,
@@ -34430,16 +34041,16 @@ return /******/ (function(modules) { // webpackBootstrap
var _clusterNode = this.body.nodes[clusterId];
_clusterNode.containedEdges[edgeId] = edge;
- // if both from and to nodes are visible, we create a new temporary edge
- if (edge.from.options.hidden !== true && edge.to.options.hidden !== true) {
- if (this.clusteredNodes[edge.fromId] !== undefined) {
- fromId = clusterId;
- toId = edge.toId;
- } else {
- fromId = edge.fromId;
- toId = clusterId;
- }
+ if (this.clusteredNodes[edge.fromId] !== undefined) {
+ fromId = clusterId;
+ toId = edge.toId;
+ } else {
+ fromId = edge.fromId;
+ toId = clusterId;
+ }
+ // if both from and to nodes are visible, we create a new temporary edge
+ if (this.body.nodes[fromId].options.hidden !== true && this.body.nodes[toId].options.hidden !== true) {
var clonedOptions = this._cloneOptions(edge, 'edge');
var id = 'clusterEdge:' + util.randomUUID();
util.deepExtend(clonedOptions, _clusterNode.clusterEdgeProperties);
@@ -34474,30 +34085,19 @@ return /******/ (function(modules) { // webpackBootstrap
}
}
}, {
- key: '_connectEdge',
-
- /**
- * Connect an edge that was previously contained from cluster A to cluster B if the node that it was originally connected to
- * is currently residing in cluster B
- * @param edge
- * @param nodeId
- * @param from
- * @private
- */
- value: function _connectEdge(edge, nodeId, from) {
- var clusterStack = this.findNode(nodeId);
- if (from === true) {
- edge.from = clusterStack[clusterStack.length - 1];
- edge.fromId = clusterStack[clusterStack.length - 1].id;
- clusterStack.pop();
- edge.fromArray = clusterStack;
- } else {
- edge.to = clusterStack[clusterStack.length - 1];
- edge.toId = clusterStack[clusterStack.length - 1].id;
- clusterStack.pop();
- edge.toArray = clusterStack;
+ key: 'getNodesInCluster',
+ value: function getNodesInCluster(clusterId) {
+ var nodesArray = [];
+ if (this.isCluster(clusterId) === true) {
+ var containedNodes = this.body.nodes[clusterId].containedNodes;
+ for (var nodeId in containedNodes) {
+ if (containedNodes.hasOwnProperty(nodeId)) {
+ nodesArray.push(nodeId);
+ }
+ }
}
- edge.connect();
+
+ return nodesArray;
}
}, {
key: 'findNode',
@@ -34588,7 +34188,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 99 */
+/* 98 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -34605,7 +34205,7 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
- var _Node2 = __webpack_require__(63);
+ var _Node2 = __webpack_require__(62);
var _Node3 = _interopRequireDefault(_Node2);
@@ -34633,7 +34233,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 100 */
+/* 99 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -35013,7 +34613,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = exports['default'];
/***/ },
-/* 101 */
+/* 100 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -35380,6 +34980,409 @@ return /******/ (function(modules) { // webpackBootstrap
exports['default'] = Canvas;
module.exports = exports['default'];
+/***/ },
+/* 101 */
+/***/ function(module, exports, __webpack_require__) {
+
+ "use strict";
+
+ Object.defineProperty(exports, "__esModule", {
+ value: true
+ });
+
+ var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+
+ var util = __webpack_require__(9);
+
+ var View = (function () {
+ function View(body, canvas) {
+ var _this = this;
+
+ _classCallCheck(this, View);
+
+ this.body = body;
+ this.canvas = canvas;
+
+ this.animationSpeed = 1 / this.renderRefreshRate;
+ this.animationEasingFunction = "easeInOutQuint";
+ this.easingTime = 0;
+ this.sourceScale = 0;
+ this.targetScale = 0;
+ this.sourceTranslation = 0;
+ this.targetTranslation = 0;
+ this.lockedOnNodeId = undefined;
+ this.lockedOnNodeOffset = undefined;
+ this.touchTime = 0;
+
+ this.viewFunction = undefined;
+
+ this.body.emitter.on("fit", this.fit.bind(this));
+ this.body.emitter.on("animationFinished", function () {
+ _this.body.emitter.emit("_stopRendering");
+ });
+ this.body.emitter.on("unlockNode", this.releaseNode.bind(this));
+ }
+
+ _createClass(View, [{
+ key: "setOptions",
+ value: function setOptions() {
+ var options = arguments[0] === undefined ? {} : arguments[0];
+
+ this.options = options;
+ }
+ }, {
+ key: "_getRange",
+
+ /**
+ * Find the center position of the network
+ * @private
+ */
+ value: function _getRange() {
+ var specificNodes = arguments[0] === undefined ? [] : arguments[0];
+
+ var minY = 1000000000,
+ maxY = -1000000000,
+ minX = 1000000000,
+ maxX = -1000000000,
+ node;
+ if (specificNodes.length > 0) {
+ for (var i = 0; i < specificNodes.length; i++) {
+ node = this.body.nodes[specificNodes[i]];
+ if (minX > node.shape.boundingBox.left) {
+ minX = node.shape.boundingBox.left;
+ }
+ if (maxX < node.shape.boundingBox.right) {
+ maxX = node.shape.boundingBox.right;
+ }
+ if (minY > node.shape.boundingBox.top) {
+ minY = node.shape.boundingBox.top;
+ } // top is negative, bottom is positive
+ if (maxY < node.shape.boundingBox.bottom) {
+ maxY = node.shape.boundingBox.bottom;
+ } // top is negative, bottom is positive
+ }
+ } else {
+ for (var nodeId in this.body.nodes) {
+ if (this.body.nodes.hasOwnProperty(nodeId)) {
+ node = this.body.nodes[nodeId];
+ if (minX > node.shape.boundingBox.left) {
+ minX = node.shape.boundingBox.left;
+ }
+ if (maxX < node.shape.boundingBox.right) {
+ maxX = node.shape.boundingBox.right;
+ }
+ if (minY > node.shape.boundingBox.top) {
+ minY = node.shape.boundingBox.top;
+ } // top is negative, bottom is positive
+ if (maxY < node.shape.boundingBox.bottom) {
+ maxY = node.shape.boundingBox.bottom;
+ } // top is negative, bottom is positive
+ }
+ }
+ }
+
+ if (minX === 1000000000 && maxX === -1000000000 && minY === 1000000000 && maxY === -1000000000) {
+ minY = 0, maxY = 0, minX = 0, maxX = 0;
+ }
+ return { minX: minX, maxX: maxX, minY: minY, maxY: maxY };
+ }
+ }, {
+ key: "_findCenter",
+
+ /**
+ * @param {object} range = {minX: minX, maxX: maxX, minY: minY, maxY: maxY};
+ * @returns {{x: number, y: number}}
+ * @private
+ */
+ value: function _findCenter(range) {
+ return { x: 0.5 * (range.maxX + range.minX),
+ y: 0.5 * (range.maxY + range.minY) };
+ }
+ }, {
+ key: "fit",
+
+ /**
+ * This function zooms out to fit all data on screen based on amount of nodes
+ * @param {Object} Options
+ * @param {Boolean} [initialZoom] | zoom based on fitted formula or range, true = fitted, default = false;
+ */
+ value: function fit() {
+ var options = arguments[0] === undefined ? { nodes: [] } : arguments[0];
+ var initialZoom = arguments[1] === undefined ? false : arguments[1];
+
+ var range;
+ var zoomLevel;
+
+ if (initialZoom === true) {
+ // check if more than half of the nodes have a predefined position. If so, we use the range, not the approximation.
+ var positionDefined = 0;
+ for (var nodeId in this.body.nodes) {
+ if (this.body.nodes.hasOwnProperty(nodeId)) {
+ var node = this.body.nodes[nodeId];
+ if (node.predefinedPosition === true) {
+ positionDefined += 1;
+ }
+ }
+ }
+ if (positionDefined > 0.5 * this.body.nodeIndices.length) {
+ this.fit(options, false);
+ return;
+ }
+
+ range = this._getRange(options.nodes);
+
+ var numberOfNodes = this.body.nodeIndices.length;
+ zoomLevel = 12.662 / (numberOfNodes + 7.4147) + 0.0964822; // this is obtained from fitting a dataset from 5 points with scale levels that looked good.
+
+ // correct for larger canvasses.
+ var factor = Math.min(this.canvas.frame.canvas.clientWidth / 600, this.canvas.frame.canvas.clientHeight / 600);
+ zoomLevel *= factor;
+ } else {
+ this.body.emitter.emit("_resizeNodes");
+ range = this._getRange(options.nodes);
+ var xDistance = Math.abs(range.maxX - range.minX) * 1.1;
+ var yDistance = Math.abs(range.maxY - range.minY) * 1.1;
+
+ var xZoomLevel = this.canvas.frame.canvas.clientWidth / xDistance;
+ var yZoomLevel = this.canvas.frame.canvas.clientHeight / yDistance;
+
+ zoomLevel = xZoomLevel <= yZoomLevel ? xZoomLevel : yZoomLevel;
+ }
+
+ if (zoomLevel > 1) {
+ zoomLevel = 1;
+ } else if (zoomLevel === 0) {
+ zoomLevel = 1;
+ }
+
+ var center = this._findCenter(range);
+ var animationOptions = { position: center, scale: zoomLevel, animation: options.animation };
+ this.moveTo(animationOptions);
+ }
+ }, {
+ key: "focus",
+
+ // animation
+
+ /**
+ * Center a node in view.
+ *
+ * @param {Number} nodeId
+ * @param {Number} [options]
+ */
+ value: function focus(nodeId) {
+ var options = arguments[1] === undefined ? {} : arguments[1];
+
+ if (this.body.nodes[nodeId] !== undefined) {
+ var nodePosition = { x: this.body.nodes[nodeId].x, y: this.body.nodes[nodeId].y };
+ options.position = nodePosition;
+ options.lockedOnNode = nodeId;
+
+ this.moveTo(options);
+ } else {
+ console.log("Node: " + nodeId + " cannot be found.");
+ }
+ }
+ }, {
+ key: "moveTo",
+
+ /**
+ *
+ * @param {Object} options | options.offset = {x:Number, y:Number} // offset from the center in DOM pixels
+ * | options.scale = Number // scale to move to
+ * | options.position = {x:Number, y:Number} // position to move to
+ * | options.animation = {duration:Number, easingFunction:String} || Boolean // position to move to
+ */
+ value: function moveTo(options) {
+ if (options === undefined) {
+ options = {};
+ return;
+ }
+ if (options.offset === undefined) {
+ options.offset = { x: 0, y: 0 };
+ }
+ if (options.offset.x === undefined) {
+ options.offset.x = 0;
+ }
+ if (options.offset.y === undefined) {
+ options.offset.y = 0;
+ }
+ if (options.scale === undefined) {
+ options.scale = this.body.view.scale;
+ }
+ if (options.position === undefined) {
+ options.position = this.getViewPosition();
+ }
+ if (options.animation === undefined) {
+ options.animation = { duration: 0 };
+ }
+ if (options.animation === false) {
+ options.animation = { duration: 0 };
+ }
+ if (options.animation === true) {
+ options.animation = {};
+ }
+ if (options.animation.duration === undefined) {
+ options.animation.duration = 1000;
+ } // default duration
+ if (options.animation.easingFunction === undefined) {
+ options.animation.easingFunction = "easeInOutQuad";
+ } // default easing function
+
+ this.animateView(options);
+ }
+ }, {
+ key: "animateView",
+
+ /**
+ *
+ * @param {Object} options | options.offset = {x:Number, y:Number} // offset from the center in DOM pixels
+ * | options.time = Number // animation time in milliseconds
+ * | options.scale = Number // scale to animate to
+ * | options.position = {x:Number, y:Number} // position to animate to
+ * | options.easingFunction = String // linear, easeInQuad, easeOutQuad, easeInOutQuad,
+ * // easeInCubic, easeOutCubic, easeInOutCubic,
+ * // easeInQuart, easeOutQuart, easeInOutQuart,
+ * // easeInQuint, easeOutQuint, easeInOutQuint
+ */
+ value: function animateView(options) {
+ if (options === undefined) {
+ return;
+ }
+ this.animationEasingFunction = options.animation.easingFunction;
+ // release if something focussed on the node
+ this.releaseNode();
+ if (options.locked === true) {
+ this.lockedOnNodeId = options.lockedOnNode;
+ this.lockedOnNodeOffset = options.offset;
+ }
+
+ // forcefully complete the old animation if it was still running
+ if (this.easingTime != 0) {
+ this._transitionRedraw(true); // by setting easingtime to 1, we finish the animation.
+ }
+
+ this.sourceScale = this.body.view.scale;
+ this.sourceTranslation = this.body.view.translation;
+ this.targetScale = options.scale;
+
+ // set the scale so the viewCenter is based on the correct zoom level. This is overridden in the transitionRedraw
+ // but at least then we'll have the target transition
+ this.body.view.scale = this.targetScale;
+ var viewCenter = this.canvas.DOMtoCanvas({ x: 0.5 * this.canvas.frame.canvas.clientWidth, y: 0.5 * this.canvas.frame.canvas.clientHeight });
+
+ var distanceFromCenter = { // offset from view, distance view has to change by these x and y to center the node
+ x: viewCenter.x - options.position.x,
+ y: viewCenter.y - options.position.y
+ };
+ this.targetTranslation = {
+ x: this.sourceTranslation.x + distanceFromCenter.x * this.targetScale + options.offset.x,
+ y: this.sourceTranslation.y + distanceFromCenter.y * this.targetScale + options.offset.y
+ };
+
+ // if the time is set to 0, don't do an animation
+ if (options.animation.duration === 0) {
+ if (this.lockedOnNodeId != undefined) {
+ this.viewFunction = this._lockedRedraw.bind(this);
+ this.body.emitter.on("initRedraw", this.viewFunction);
+ } else {
+ this.body.view.scale = this.targetScale;
+ this.body.view.translation = this.targetTranslation;
+ this.body.emitter.emit("_requestRedraw");
+ }
+ } else {
+ this.animationSpeed = 1 / (60 * options.animation.duration * 0.001) || 1 / 60; // 60 for 60 seconds, 0.001 for milli's
+ this.animationEasingFunction = options.animation.easingFunction;
+
+ this.viewFunction = this._transitionRedraw.bind(this);
+ this.body.emitter.on("initRedraw", this.viewFunction);
+ this.body.emitter.emit("_startRendering");
+ }
+ }
+ }, {
+ key: "_lockedRedraw",
+
+ /**
+ * used to animate smoothly by hijacking the redraw function.
+ * @private
+ */
+ value: function _lockedRedraw() {
+ var nodePosition = { x: this.body.nodes[this.lockedOnNodeId].x, y: this.body.nodes[this.lockedOnNodeId].y };
+ var viewCenter = this.DOMtoCanvas({ x: 0.5 * this.frame.canvas.clientWidth, y: 0.5 * this.frame.canvas.clientHeight });
+ var distanceFromCenter = { // offset from view, distance view has to change by these x and y to center the node
+ x: viewCenter.x - nodePosition.x,
+ y: viewCenter.y - nodePosition.y
+ };
+ var sourceTranslation = this.body.view.translation;
+ var targetTranslation = {
+ x: sourceTranslation.x + distanceFromCenter.x * this.body.view.scale + this.lockedOnNodeOffset.x,
+ y: sourceTranslation.y + distanceFromCenter.y * this.body.view.scale + this.lockedOnNodeOffset.y
+ };
+
+ this.body.view.translation = targetTranslation;
+ }
+ }, {
+ key: "releaseNode",
+ value: function releaseNode() {
+ if (this.lockedOnNodeId !== undefined && this.viewFunction !== undefined) {
+ this.body.emitter.off("initRedraw", this.viewFunction);
+ this.lockedOnNodeId = undefined;
+ this.lockedOnNodeOffset = undefined;
+ }
+ }
+ }, {
+ key: "_transitionRedraw",
+
+ /**
+ *
+ * @param easingTime
+ * @private
+ */
+ value: function _transitionRedraw() {
+ var finished = arguments[0] === undefined ? false : arguments[0];
+
+ this.easingTime += this.animationSpeed;
+ this.easingTime = finished === true ? 1 : this.easingTime;
+
+ var progress = util.easingFunctions[this.animationEasingFunction](this.easingTime);
+
+ this.body.view.scale = this.sourceScale + (this.targetScale - this.sourceScale) * progress;
+ this.body.view.translation = {
+ x: this.sourceTranslation.x + (this.targetTranslation.x - this.sourceTranslation.x) * progress,
+ y: this.sourceTranslation.y + (this.targetTranslation.y - this.sourceTranslation.y) * progress
+ };
+
+ // cleanup
+ if (this.easingTime >= 1) {
+ this.body.emitter.off("initRedraw", this.viewFunction);
+ this.easingTime = 0;
+ if (this.lockedOnNodeId != undefined) {
+ this.viewFunction = this._lockedRedraw.bind(this);
+ this.body.emitter.on("initRedraw", this.viewFunction);
+ }
+ this.body.emitter.emit("animationFinished");
+ }
+ }
+ }, {
+ key: "getScale",
+ value: function getScale() {
+ return this.body.view.scale;
+ }
+ }, {
+ key: "getViewPosition",
+ value: function getViewPosition() {
+ return this.canvas.DOMtoCanvas({ x: 0.5 * this.canvas.frame.canvas.clientWidth, y: 0.5 * this.canvas.frame.canvas.clientHeight });
+ }
+ }]);
+
+ return View;
+ })();
+
+ exports["default"] = View;
+ module.exports = exports["default"];
+
/***/ },
/* 102 */
/***/ function(module, exports, __webpack_require__) {
@@ -36170,8 +36173,6 @@ return /******/ (function(modules) { // webpackBootstrap
this.navigationHammers = [];
}
- this._navigationReleaseOverload = function () {};
-
// clean up previous navigation items
if (this.navigationDOM && this.navigationDOM['wrapper'] && this.navigationDOM['wrapper'].parentNode) {
this.navigationDOM['wrapper'].parentNode.removeChild(this.navigationDOM['wrapper']);
@@ -36310,7 +36311,6 @@ return /******/ (function(modules) { // webpackBootstrap
}
if (this.options.keyboard.enabled === true) {
-
if (this.options.keyboard.bindToWindow === true) {
this.keycharm = keycharm({ container: window, preventDefault: true });
} else {
@@ -36496,8 +36496,8 @@ return /******/ (function(modules) { // webpackBootstrap
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- var Node = __webpack_require__(63);
- var Edge = __webpack_require__(83);
+ var Node = __webpack_require__(62);
+ var Edge = __webpack_require__(82);
var util = __webpack_require__(9);
var SelectionHandler = (function () {
@@ -37320,18 +37320,31 @@ return /******/ (function(modules) { // webpackBootstrap
// disable smooth curves if nothing is defined. If smooth curves have been turned on, turn them into static smooth curves.
if (allOptions.edges === undefined) {
- this.optionsBackup.edges = { smooth: true, dynamic: true };
+ this.optionsBackup.edges = { smooth: { enabled: true, type: 'dynamic' } };
allOptions.edges = { smooth: false };
} else if (allOptions.edges.smooth === undefined) {
- this.optionsBackup.edges = { smooth: true, dynamic: true };
+ this.optionsBackup.edges = { smooth: { enabled: true, type: 'dynamic' } };
allOptions.edges.smooth = false;
} else {
if (typeof allOptions.edges.smooth === 'boolean') {
- this.optionsBackup.edges = { smooth: allOptions.edges.smooth, dynamic: true };
- allOptions.edges.smooth = { enabled: allOptions.edges.smooth, dynamic: false, type: type };
+ this.optionsBackup.edges = { smooth: allOptions.edges.smooth };
+ allOptions.edges.smooth = { enabled: allOptions.edges.smooth, type: type };
} else {
- this.optionsBackup.edges = { smooth: allOptions.edges.smooth.enabled === undefined ? true : allOptions.edges.smooth.enabled, dynamic: true };
- allOptions.edges.smooth = { enabled: allOptions.edges.smooth.enabled === undefined ? true : allOptions.edges.smooth.enabled, dynamic: false, type: type };
+ // allow custom types except for dynamic
+ if (allOptions.edges.smooth.type !== undefined && allOptions.edges.smooth.type !== 'dynamic') {
+ type = allOptions.edges.smooth.type;
+ }
+
+ this.optionsBackup.edges = {
+ smooth: allOptions.edges.smooth.enabled === undefined ? true : allOptions.edges.smooth.enabled,
+ type: allOptions.edges.smooth.type === undefined ? 'dynamic' : allOptions.edges.smooth.type,
+ roundness: allOptions.edges.smooth.roundness === undefined ? 0.5 : allOptions.edges.smooth.roundness
+ };
+ allOptions.edges.smooth = {
+ enabled: allOptions.edges.smooth.enabled === undefined ? true : allOptions.edges.smooth.enabled,
+ type: type,
+ roundness: allOptions.edges.smooth.roundness === undefined ? 0.5 : allOptions.edges.smooth.roundness
+ };
}
}
@@ -37547,14 +37560,14 @@ return /******/ (function(modules) { // webpackBootstrap
if (this.body.nodes.hasOwnProperty(nodeId)) {
node = this.body.nodes[nodeId];
if (node.edges.length === hubSize) {
- this._setLevel(0, node);
+ this._setLevelByHubsize(0, node);
}
}
}
}
}
}, {
- key: '_setLevel',
+ key: '_setLevelByHubsize',
/**
* this function is called recursively to enumerate the barnches of the largest hubs and give each node a level.
@@ -37564,7 +37577,7 @@ return /******/ (function(modules) { // webpackBootstrap
* @param parentId
* @private
*/
- value: function _setLevel(level, node) {
+ value: function _setLevelByHubsize(level, node) {
if (this.hierarchicalLevels[node.id] !== undefined) return;
var childNode = undefined;
@@ -37575,7 +37588,7 @@ return /******/ (function(modules) { // webpackBootstrap
} else {
childNode = node.edges[i].to;
}
- this._setLevel(level + 1, childNode);
+ this._setLevelByHubsize(level + 1, childNode);
}
}
}, {
@@ -38715,7 +38728,6 @@ return /******/ (function(modules) { // webpackBootstrap
physics: false,
smooth: {
enabled: true,
- dynamic: false,
type: 'continuous',
roundness: 0.5
}
diff --git a/lib/network/modules/View.js b/lib/network/modules/View.js
index a7d9ea6a..19937400 100644
--- a/lib/network/modules/View.js
+++ b/lib/network/modules/View.js
@@ -231,7 +231,7 @@ class View {
// but at least then we'll have the target transition
this.body.view.scale = this.targetScale;
var viewCenter = this.canvas.DOMtoCanvas({x: 0.5 * this.canvas.frame.canvas.clientWidth, y: 0.5 * this.canvas.frame.canvas.clientHeight});
- console.log('viewCenter', viewCenter,this.body.view.translation, options.position)
+
var distanceFromCenter = { // offset from view, distance view has to change by these x and y to center the node
x: viewCenter.x - options.position.x,
y: viewCenter.y - options.position.y