Browse Source

A fix in dragging nodes in the graph around

css_transitions
josdejong 11 years ago
parent
commit
6ff96bb8a9
4 changed files with 62 additions and 81 deletions
  1. +2
    -1
      HISTORY.md
  2. +30
    -40
      src/graph/Graph.js
  3. +29
    -39
      vis.js
  4. +1
    -1
      vis.min.js

+ 2
- 1
HISTORY.md View File

@ -2,8 +2,9 @@ vis.js history
http://visjs.org http://visjs.org
## (not yet released), version 0.1.1
## (not yet released), version 0.2.0
- Implemented full touch support for Graph.
- Fixed initial empty range in the Timeline in case of a single item. - Fixed initial empty range in the Timeline in case of a single item.
- Fixed field `className` not working for items. - Fixed field `className` not working for items.

+ 30
- 40
src/graph/Graph.js View File

@ -366,52 +366,42 @@ Graph.prototype._onTouch = function (event) {
Graph.prototype._onDragStart = function () { Graph.prototype._onDragStart = function () {
var drag = this.drag; var drag = this.drag;
drag.selection = [];
drag.translation = this._getTranslation(); drag.translation = this._getTranslation();
// note: drag.pointer is set in _onTouch to get the initial touch location
drag.nodeId = this._getNodeAt(drag.pointer); drag.nodeId = this._getNodeAt(drag.pointer);
// note: drag.pointer is set in _onTouch to get the initial touch location
// select the clicked node if not yet selected
var node = this.nodes[drag.nodeId]; var node = this.nodes[drag.nodeId];
if (node && !node.isSelected()) {
this._selectNodes([drag.nodeId]);
}
// creat an array with the selected nodes and their original location and status
var me = this;
drag.selection = [];
this.selection.forEach(function (id) {
var node = me.nodes[id];
if (node) {
var s = {
id: id,
node: node,
// store original x, y, xFixed and yFixed, make the node temporarily Fixed
x: node.x,
y: node.y,
xFixed: node.xFixed,
yFixed: node.yFixed
};
node.xFixed = true;
node.yFixed = true;
drag.selection.push(s);
if (node) {
// select the clicked node if not yet selected
if (!node.isSelected()) {
this._selectNodes([drag.nodeId]);
} }
});
/* TODO: cleanup
if (drag.node) {
this._selectNodes([drag.nodeId]);
// create an array with the selected nodes and their original location and status
var me = this;
this.selection.forEach(function (id) {
var node = me.nodes[id];
if (node) {
var s = {
id: id,
node: node,
// store original x, y, xFixed and yFixed, make the node temporarily Fixed
x: node.x,
y: node.y,
xFixed: node.xFixed,
yFixed: node.yFixed
};
node.xFixed = true;
node.yFixed = true;
drag.selection.push(s);
}
});
// store original xFixed and yFixed, make the node temporarily Fixed
drag.xFixed = drag.node.xFixed;
drag.yFixed = drag.node.yFixed;
drag.node.xFixed = true;
drag.node.yFixed = true;
} }
*/
}; };
/** /**
@ -438,11 +428,11 @@ Graph.prototype._onDrag = function (event) {
var node = s.node; var node = s.node;
if (!s.xFixed) { if (!s.xFixed) {
node.x = me._xToCanvas(me._canvasToX(s.x) + deltaX);
node.x = me._canvasToX(me._xToCanvas(s.x) + deltaX);
} }
if (!s.yFixed) { if (!s.yFixed) {
node.y = me._yToCanvas(me._canvasToX(s.y) + deltaY);
node.y = me._canvasToY(me._yToCanvas(s.y) + deltaY);
} }
}); });

+ 29
- 39
vis.js View File

@ -13219,52 +13219,42 @@ Graph.prototype._onTouch = function (event) {
Graph.prototype._onDragStart = function () { Graph.prototype._onDragStart = function () {
var drag = this.drag; var drag = this.drag;
drag.selection = [];
drag.translation = this._getTranslation(); drag.translation = this._getTranslation();
// note: drag.pointer is set in _onTouch to get the initial touch location
drag.nodeId = this._getNodeAt(drag.pointer); drag.nodeId = this._getNodeAt(drag.pointer);
// note: drag.pointer is set in _onTouch to get the initial touch location
// select the clicked node if not yet selected
var node = this.nodes[drag.nodeId]; var node = this.nodes[drag.nodeId];
if (node && !node.isSelected()) {
this._selectNodes([drag.nodeId]);
}
// creat an array with the selected nodes and their original location and status
var me = this;
drag.selection = [];
this.selection.forEach(function (id) {
var node = me.nodes[id];
if (node) {
var s = {
id: id,
node: node,
// store original x, y, xFixed and yFixed, make the node temporarily Fixed
x: node.x,
y: node.y,
xFixed: node.xFixed,
yFixed: node.yFixed
};
if (node) {
// select the clicked node if not yet selected
if (!node.isSelected()) {
this._selectNodes([drag.nodeId]);
}
node.xFixed = true;
node.yFixed = true;
// create an array with the selected nodes and their original location and status
var me = this;
this.selection.forEach(function (id) {
var node = me.nodes[id];
if (node) {
var s = {
id: id,
node: node,
// store original x, y, xFixed and yFixed, make the node temporarily Fixed
x: node.x,
y: node.y,
xFixed: node.xFixed,
yFixed: node.yFixed
};
drag.selection.push(s);
}
});
node.xFixed = true;
node.yFixed = true;
/* TODO: cleanup
if (drag.node) {
this._selectNodes([drag.nodeId]);
drag.selection.push(s);
}
});
// store original xFixed and yFixed, make the node temporarily Fixed
drag.xFixed = drag.node.xFixed;
drag.yFixed = drag.node.yFixed;
drag.node.xFixed = true;
drag.node.yFixed = true;
} }
*/
}; };
/** /**
@ -13291,11 +13281,11 @@ Graph.prototype._onDrag = function (event) {
var node = s.node; var node = s.node;
if (!s.xFixed) { if (!s.xFixed) {
node.x = me._xToCanvas(me._canvasToX(s.x) + deltaX);
node.x = me._canvasToX(me._xToCanvas(s.x) + deltaX);
} }
if (!s.yFixed) { if (!s.yFixed) {
node.y = me._yToCanvas(me._canvasToX(s.y) + deltaY);
node.y = me._canvasToY(me._yToCanvas(s.y) + deltaY);
} }
}); });

+ 1
- 1
vis.min.js
File diff suppressed because it is too large
View File


Loading…
Cancel
Save