Browse Source

fully depricated setSelection. Improved selectable to respect dragging.

v3_develop
Alex de Mulder 10 years ago
parent
commit
97b2ca51a3
4 changed files with 4460 additions and 4494 deletions
  1. +4426
    -4438
      dist/vis.js
  2. +0
    -10
      docs/network.html
  3. +1
    -1
      lib/network/Network.js
  4. +33
    -45
      lib/network/mixins/SelectionMixin.js

+ 4426
- 4438
dist/vis.js
File diff suppressed because it is too large
View File


+ 0
- 10
docs/network.html View File

@ -2268,16 +2268,6 @@ var options: {
edges with id 3 and 5.
</td>
</tr>
<tr>
<td>setSelection(selection)</td>
<td>none</td>
<td>Select nodes [deprecated].
<code>selection</code> is an array with ids of nodes to be selected.
The array <code>selection</code> can contain zero or multiple ids.
Example usage: <code>network.setSelection([3, 5]);</code> will select
nodes with id 3 and 5.
</td>
</tr>
<tr>
<td>setSize(width, height)</td>

+ 1
- 1
lib/network/Network.js View File

@ -847,7 +847,7 @@ Network.prototype._handleDragStart = function() {
drag.translation = this._getTranslation();
drag.nodeId = null;
if (node != null) {
if (node != null && this.constants.dragNodes == true) {
drag.nodeId = node.id;
// select the clicked node if not yet selected
if (!node.isSelected()) {

+ 33
- 45
lib/network/mixins/SelectionMixin.js View File

@ -403,7 +403,7 @@ exports._unselectConnectedEdges = function(node) {
* @param {Boolean} [doNotTrigger] | ignore trigger
* @private
*/
exports._selectObject = function(object, append, doNotTrigger, highlightEdges) {
exports._selectObject = function(object, append, doNotTrigger, highlightEdges, overrideSelectable) {
if (doNotTrigger === undefined) {
doNotTrigger = false;
}
@ -415,13 +415,19 @@ exports._selectObject = function(object, append, doNotTrigger, highlightEdges) {
this._unselectAll(true);
}
if (object.selected == false) {
// selectable allows the object to be selected. Override can be used if needed to bypass this.
if (object.selected == false && (this.constants.selectable == true || overrideSelectable)) {
object.select();
this._addToSelection(object);
if (object instanceof Node && this.blockConnectingEdgeSelection == false && highlightEdges == true) {
this._selectConnectedEdges(object);
}
}
// do not select the object if selectable is false, only add it to selection to allow drag to work
else if (object.selected == false) {
this._addToSelection(object);
doNotTrigger = true;
}
else {
object.unselect();
this._removeFromSelection(object);
@ -487,23 +493,21 @@ exports._handleTouch = function(pointer) {
* @private
*/
exports._handleTap = function(pointer) {
if (this.constants.selectable == true) {
var node = this._getNodeAt(pointer);
if (node != null) {
this._selectObject(node, false);
var node = this._getNodeAt(pointer);
if (node != null) {
this._selectObject(node, false);
}
else {
var edge = this._getEdgeAt(pointer);
if (edge != null) {
this._selectObject(edge, false);
}
else {
var edge = this._getEdgeAt(pointer);
if (edge != null) {
this._selectObject(edge, false);
}
else {
this._unselectAll();
}
this._unselectAll();
}
this.emit("click", this.getSelection());
this._redraw();
}
this.emit("click", this.getSelection());
this._redraw();
};
@ -579,9 +583,11 @@ exports.getSelection = function() {
*/
exports.getSelectedNodes = function() {
var idArray = [];
for(var nodeId in this.selectionObj.nodes) {
if(this.selectionObj.nodes.hasOwnProperty(nodeId)) {
idArray.push(nodeId);
if (this.constants.selectable == true) {
for (var nodeId in this.selectionObj.nodes) {
if (this.selectionObj.nodes.hasOwnProperty(nodeId)) {
idArray.push(nodeId);
}
}
}
return idArray
@ -595,9 +601,11 @@ exports.getSelectedNodes = function() {
*/
exports.getSelectedEdges = function() {
var idArray = [];
for(var edgeId in this.selectionObj.edges) {
if(this.selectionObj.edges.hasOwnProperty(edgeId)) {
idArray.push(edgeId);
if (this.constants.selectable == true) {
for (var edgeId in this.selectionObj.edges) {
if (this.selectionObj.edges.hasOwnProperty(edgeId)) {
idArray.push(edgeId);
}
}
}
return idArray;
@ -605,32 +613,12 @@ exports.getSelectedEdges = function() {
/**
* select zero or more nodes
* select zero or more nodes DEPRICATED
* @param {Number[] | String[]} selection An array with the ids of the
* selected nodes.
*/
exports.setSelection = function(selection) {
var i, iMax, id;
if (!selection || (selection.length == undefined))
throw 'Selection must be an array with ids';
// first unselect any selected node
this._unselectAll(true);
for (i = 0, iMax = selection.length; i < iMax; i++) {
id = selection[i];
var node = this.nodes[id];
if (!node) {
throw new RangeError('Node with id "' + id + '" not found');
}
this._selectObject(node,true,true);
}
exports.setSelection = function() {
console.log("setSelection is deprecated. Please use selectNodes instead.")
this.redraw();
};
@ -656,7 +644,7 @@ exports.selectNodes = function(selection, highlightEdges) {
if (!node) {
throw new RangeError('Node with id "' + id + '" not found');
}
this._selectObject(node,true,true,highlightEdges);
this._selectObject(node,true,true,highlightEdges,true);
}
this.redraw();
};
@ -683,7 +671,7 @@ exports.selectEdges = function(selection) {
if (!edge) {
throw new RangeError('Edge with id "' + id + '" not found');
}
this._selectObject(edge,true,true,highlightEdges);
this._selectObject(edge,true,true,false,true);
}
this.redraw();
};

Loading…
Cancel
Save