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