|
@ -403,7 +403,7 @@ exports._unselectConnectedEdges = function(node) { |
|
|
* @param {Boolean} [doNotTrigger] | ignore trigger |
|
|
* @param {Boolean} [doNotTrigger] | ignore trigger |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
exports._selectObject = function(object, append, doNotTrigger, highlightEdges) { |
|
|
|
|
|
|
|
|
exports._selectObject = function(object, append, doNotTrigger, highlightEdges, overrideSelectable) { |
|
|
if (doNotTrigger === undefined) { |
|
|
if (doNotTrigger === undefined) { |
|
|
doNotTrigger = false; |
|
|
doNotTrigger = false; |
|
|
} |
|
|
} |
|
@ -415,13 +415,19 @@ exports._selectObject = function(object, append, doNotTrigger, highlightEdges) { |
|
|
this._unselectAll(true); |
|
|
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(); |
|
|
object.select(); |
|
|
this._addToSelection(object); |
|
|
this._addToSelection(object); |
|
|
if (object instanceof Node && this.blockConnectingEdgeSelection == false && highlightEdges == true) { |
|
|
if (object instanceof Node && this.blockConnectingEdgeSelection == false && highlightEdges == true) { |
|
|
this._selectConnectedEdges(object); |
|
|
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 { |
|
|
else { |
|
|
object.unselect(); |
|
|
object.unselect(); |
|
|
this._removeFromSelection(object); |
|
|
this._removeFromSelection(object); |
|
@ -487,23 +493,21 @@ exports._handleTouch = function(pointer) { |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
exports._handleTap = function(pointer) { |
|
|
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 { |
|
|
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() { |
|
|
exports.getSelectedNodes = function() { |
|
|
var idArray = []; |
|
|
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 |
|
|
return idArray |
|
@ -595,9 +601,11 @@ exports.getSelectedNodes = function() { |
|
|
*/ |
|
|
*/ |
|
|
exports.getSelectedEdges = function() { |
|
|
exports.getSelectedEdges = function() { |
|
|
var idArray = []; |
|
|
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; |
|
|
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 |
|
|
* @param {Number[] | String[]} selection An array with the ids of the |
|
|
* selected nodes. |
|
|
* 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.") |
|
|
console.log("setSelection is deprecated. Please use selectNodes instead.") |
|
|
|
|
|
|
|
|
this.redraw(); |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -656,7 +644,7 @@ exports.selectNodes = function(selection, highlightEdges) { |
|
|
if (!node) { |
|
|
if (!node) { |
|
|
throw new RangeError('Node with id "' + id + '" not found'); |
|
|
throw new RangeError('Node with id "' + id + '" not found'); |
|
|
} |
|
|
} |
|
|
this._selectObject(node,true,true,highlightEdges); |
|
|
|
|
|
|
|
|
this._selectObject(node,true,true,highlightEdges,true); |
|
|
} |
|
|
} |
|
|
this.redraw(); |
|
|
this.redraw(); |
|
|
}; |
|
|
}; |
|
@ -683,7 +671,7 @@ exports.selectEdges = function(selection) { |
|
|
if (!edge) { |
|
|
if (!edge) { |
|
|
throw new RangeError('Edge with id "' + id + '" not found'); |
|
|
throw new RangeError('Edge with id "' + id + '" not found'); |
|
|
} |
|
|
} |
|
|
this._selectObject(edge,true,true,highlightEdges); |
|
|
|
|
|
|
|
|
this._selectObject(edge,true,true,false,true); |
|
|
} |
|
|
} |
|
|
this.redraw(); |
|
|
this.redraw(); |
|
|
}; |
|
|
}; |
|
|