From 8fb94fe2c4a969eddd26b6d834dce19f83ffc126 Mon Sep 17 00:00:00 2001 From: Alex de Mulder Date: Mon, 15 Sep 2014 16:02:40 +0200 Subject: [PATCH] fixed drag events, tweaked allowed to move implementation --- dist/vis.js | 40 +++++++++++++++++++++++++++++++--------- lib/network/Network.js | 7 +++---- lib/network/Node.js | 33 ++++++++++++++++++++++++++++----- 3 files changed, 62 insertions(+), 18 deletions(-) diff --git a/dist/vis.js b/dist/vis.js index c8e29478..c18773fd 100644 --- a/dist/vis.js +++ b/dist/vis.js @@ -21782,7 +21782,9 @@ return /******/ (function(modules) { // webpackBootstrap if (!node.isSelected()) { this._selectObject(node,false); } + this.emit("dragStart",{nodeIds:this.getSelection().nodes}); + // create an array with the selected nodes and their original location and status for (var objectId in this.selectionObj.nodes) { if (this.selectionObj.nodes.hasOwnProperty(objectId)) { @@ -21882,7 +21884,6 @@ return /******/ (function(modules) { // webpackBootstrap * @private */ Network.prototype._onDragEnd = function () { - this.emit("dragEnd",{nodeIds:this.getSelection().nodes}); this.drag.dragging = false; var selection = this.drag.selection; if (selection && selection.length) { @@ -21897,7 +21898,7 @@ return /******/ (function(modules) { // webpackBootstrap else { this._redraw(); } - + this.emit("dragEnd",{nodeIds:this.getSelection().nodes}); }; /** @@ -23005,7 +23006,6 @@ return /******/ (function(modules) { // webpackBootstrap var renderTime = Date.now(); this._redraw(); this.renderTime = Date.now() - renderTime; - }; if (typeof window !== 'undefined') { @@ -23041,7 +23041,6 @@ return /******/ (function(modules) { // webpackBootstrap } else { this._redraw(); - if (this.stabilizationIterations > 0) { // trigger the "stabilized" event. // The event is triggered on the next tick, to prevent the case that @@ -24630,6 +24629,8 @@ return /******/ (function(modules) { // webpackBootstrap this.id = undefined; this.x = null; this.y = null; + this.allowedToMoveX = false; + this.allowedToMoveY = false; this.xFixed = false; this.yFixed = false; this.horizontalAlignLeft = true; // these are for the navigation controls @@ -24770,13 +24771,22 @@ return /******/ (function(modules) { // webpackBootstrap } } - if (properties.allowedToMoveX == true) {this.xFixed = false;} - else {this.xFixed = this.xFixed || (properties.x !== undefined && !properties.allowedToMoveX);} - if (properties.allowedToMoveY == true) {this.yFixed = false;} - else {this.yFixed = this.yFixed || (properties.y !== undefined && !properties.allowedToMoveY);} - + if (properties.allowedToMoveX !== undefined) { + this.xFixed = !properties.allowedToMoveX; + this.allowedToMoveX = properties.allowedToMoveX; + } + else if (properties.x !== undefined && this.allowedToMoveX == false) { + this.xFixed = true; + } + if (properties.allowedToMoveY !== undefined) { + this.yFixed = !properties.allowedToMoveY; + this.allowedToMoveY = properties.allowedToMoveY; + } + else if (properties.y !== undefined && this.allowedToMoveY == false) { + this.yFixed = true; + } this.radiusFixed = this.radiusFixed || (properties.radius !== undefined); @@ -24786,6 +24796,7 @@ return /******/ (function(modules) { // webpackBootstrap } + // choose draw method depending on the shape switch (this.options.shape) { case 'database': this.draw = this._drawDatabase; this.resize = this._resizeDatabase; break; @@ -24804,6 +24815,7 @@ return /******/ (function(modules) { // webpackBootstrap } // reset the size of the node, this can be changed this._reset(); + }; /** @@ -24927,6 +24939,10 @@ return /******/ (function(modules) { // webpackBootstrap this.vx += ax * interval; // velocity this.x += this.vx * interval; // position } + else { + this.fx = 0; + this.vx = 0; + } if (!this.yFixed) { var dy = this.damping * this.vy; // damping force @@ -24934,6 +24950,10 @@ return /******/ (function(modules) { // webpackBootstrap this.vy += ay * interval; // velocity this.y += this.vy * interval; // position } + else { + this.fy = 0; + this.vy = 0; + } }; @@ -24953,6 +24973,7 @@ return /******/ (function(modules) { // webpackBootstrap } else { this.fx = 0; + this.vx = 0; } if (!this.yFixed) { @@ -24964,6 +24985,7 @@ return /******/ (function(modules) { // webpackBootstrap } else { this.fy = 0; + this.vy = 0; } }; diff --git a/lib/network/Network.js b/lib/network/Network.js index 7b1e9bc9..93347053 100644 --- a/lib/network/Network.js +++ b/lib/network/Network.js @@ -852,7 +852,9 @@ Network.prototype._handleDragStart = function() { if (!node.isSelected()) { this._selectObject(node,false); } + this.emit("dragStart",{nodeIds:this.getSelection().nodes}); + // create an array with the selected nodes and their original location and status for (var objectId in this.selectionObj.nodes) { if (this.selectionObj.nodes.hasOwnProperty(objectId)) { @@ -952,7 +954,6 @@ Network.prototype._handleOnDrag = function(event) { * @private */ Network.prototype._onDragEnd = function () { - this.emit("dragEnd",{nodeIds:this.getSelection().nodes}); this.drag.dragging = false; var selection = this.drag.selection; if (selection && selection.length) { @@ -967,7 +968,7 @@ Network.prototype._onDragEnd = function () { else { this._redraw(); } - + this.emit("dragEnd",{nodeIds:this.getSelection().nodes}); }; /** @@ -2075,7 +2076,6 @@ Network.prototype._animationStep = function() { var renderTime = Date.now(); this._redraw(); this.renderTime = Date.now() - renderTime; - }; if (typeof window !== 'undefined') { @@ -2111,7 +2111,6 @@ Network.prototype.start = function() { } else { this._redraw(); - if (this.stabilizationIterations > 0) { // trigger the "stabilized" event. // The event is triggered on the next tick, to prevent the case that diff --git a/lib/network/Node.js b/lib/network/Node.js index 2c5bb61a..685d33b3 100644 --- a/lib/network/Node.js +++ b/lib/network/Node.js @@ -42,6 +42,8 @@ function Node(properties, imagelist, grouplist, networkConstants) { this.id = undefined; this.x = null; this.y = null; + this.allowedToMoveX = false; + this.allowedToMoveY = false; this.xFixed = false; this.yFixed = false; this.horizontalAlignLeft = true; // these are for the navigation controls @@ -182,13 +184,22 @@ Node.prototype.setProperties = function(properties, constants) { } } - if (properties.allowedToMoveX == true) {this.xFixed = false;} - else {this.xFixed = this.xFixed || (properties.x !== undefined && !properties.allowedToMoveX);} - if (properties.allowedToMoveY == true) {this.yFixed = false;} - else {this.yFixed = this.yFixed || (properties.y !== undefined && !properties.allowedToMoveY);} - + if (properties.allowedToMoveX !== undefined) { + this.xFixed = !properties.allowedToMoveX; + this.allowedToMoveX = properties.allowedToMoveX; + } + else if (properties.x !== undefined && this.allowedToMoveX == false) { + this.xFixed = true; + } + if (properties.allowedToMoveY !== undefined) { + this.yFixed = !properties.allowedToMoveY; + this.allowedToMoveY = properties.allowedToMoveY; + } + else if (properties.y !== undefined && this.allowedToMoveY == false) { + this.yFixed = true; + } this.radiusFixed = this.radiusFixed || (properties.radius !== undefined); @@ -198,6 +209,7 @@ Node.prototype.setProperties = function(properties, constants) { } + // choose draw method depending on the shape switch (this.options.shape) { case 'database': this.draw = this._drawDatabase; this.resize = this._resizeDatabase; break; @@ -216,6 +228,7 @@ Node.prototype.setProperties = function(properties, constants) { } // reset the size of the node, this can be changed this._reset(); + }; /** @@ -339,6 +352,10 @@ Node.prototype.discreteStep = function(interval) { this.vx += ax * interval; // velocity this.x += this.vx * interval; // position } + else { + this.fx = 0; + this.vx = 0; + } if (!this.yFixed) { var dy = this.damping * this.vy; // damping force @@ -346,6 +363,10 @@ Node.prototype.discreteStep = function(interval) { this.vy += ay * interval; // velocity this.y += this.vy * interval; // position } + else { + this.fy = 0; + this.vy = 0; + } }; @@ -365,6 +386,7 @@ Node.prototype.discreteStepLimited = function(interval, maxVelocity) { } else { this.fx = 0; + this.vx = 0; } if (!this.yFixed) { @@ -376,6 +398,7 @@ Node.prototype.discreteStepLimited = function(interval, maxVelocity) { } else { this.fy = 0; + this.vy = 0; } };