Browse Source

fixed drag events, tweaked allowed to move implementation

v3_develop
Alex de Mulder 10 years ago
parent
commit
8fb94fe2c4
3 changed files with 62 additions and 18 deletions
  1. +31
    -9
      dist/vis.js
  2. +3
    -4
      lib/network/Network.js
  3. +28
    -5
      lib/network/Node.js

+ 31
- 9
dist/vis.js View File

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

+ 3
- 4
lib/network/Network.js View File

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

+ 28
- 5
lib/network/Node.js View File

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

Loading…
Cancel
Save