Browse Source

extended selection API, deprecated setSelection as per #174

css_transitions
Alex de Mulder 10 years ago
parent
commit
424df3caaa
2 changed files with 88 additions and 8 deletions
  1. +26
    -6
      docs/graph.html
  2. +62
    -2
      src/graph/graphMixins/SelectionMixin.js

+ 26
- 6
docs/graph.html View File

@ -2149,16 +2149,36 @@ var options: {
</td> </td>
</tr> </tr>
<tr>
<td>selectNodes(selection, [highlightEdges])</td>
<td>none</td>
<td>Select nodes.
<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>graph.selectNodes([3, 5]);</code> will select
nodes with id 3 and 5. The highlisghEdges boolean can be used to automatically select the edges connected to the node.
</td>
</tr>
<tr>
<td>selectEdges(selection)</td>
<td>none</td>
<td>Select Edges.
<code>selection</code> is an array with ids of edges to be selected.
The array <code>selection</code> can contain zero or multiple ids.
Example usage: <code>graph.selectEdges([3, 5]);</code> will select
edges with id 3 and 5.
</td>
</tr>
<tr> <tr>
<td>setSelection(selection)</td> <td>setSelection(selection)</td>
<td>none</td> <td>none</td>
<td>Select nodes.
<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>graph.setSelection([3, 5]);</code> will select
nodes with id 3 and 5.
<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>graph.setSelection([3, 5]);</code> will select
nodes with id 3 and 5.
</td> </td>
</tr>
</tr>
<tr> <tr>
<td>setSize(width, height)</td> <td>setSize(width, height)</td>

+ 62
- 2
src/graph/graphMixins/SelectionMixin.js View File

@ -402,10 +402,13 @@ var SelectionMixin = {
* @param {Boolean} [doNotTrigger] | ignore trigger * @param {Boolean} [doNotTrigger] | ignore trigger
* @private * @private
*/ */
_selectObject : function(object, append, doNotTrigger) {
_selectObject : function(object, append, doNotTrigger, highlightEdges) {
if (doNotTrigger === undefined) { if (doNotTrigger === undefined) {
doNotTrigger = false; doNotTrigger = false;
} }
if (highlightEdges === undefined) {
highlightEdges = true;
}
if (this._selectionIsEmpty() == false && append == false && this.forceAppendSelection == false) { if (this._selectionIsEmpty() == false && append == false && this.forceAppendSelection == false) {
this._unselectAll(true); this._unselectAll(true);
@ -414,7 +417,7 @@ var SelectionMixin = {
if (object.selected == false) { if (object.selected == false) {
object.select(); object.select();
this._addToSelection(object); this._addToSelection(object);
if (object instanceof Node && this.blockConnectingEdgeSelection == false) {
if (object instanceof Node && this.blockConnectingEdgeSelection == false && highlightEdges == true) {
this._selectConnectedEdges(object); this._selectConnectedEdges(object);
} }
} }
@ -619,10 +622,67 @@ var SelectionMixin = {
} }
this._selectObject(node,true,true); this._selectObject(node,true,true);
} }
console.log("setSelection is deprecated. Please use selectNodes instead.")
this.redraw(); this.redraw();
}, },
/**
* select zero or more nodes with the option to highlight edges
* @param {Number[] | String[]} selection An array with the ids of the
* selected nodes.
* @param {boolean} [highlightEdges]
*/
selectNodes : function(selection, highlightEdges) {
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,highlightEdges);
}
this.redraw();
},
/**
* select zero or more edges
* @param {Number[] | String[]} selection An array with the ids of the
* selected nodes.
*/
selectEdges : 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 edge = this.edges[id];
if (!edge) {
throw new RangeError('Edge with id "' + id + '" not found');
}
this._selectObject(edge,true,true,highlightEdges);
}
this.redraw();
},
/** /**
* Validate the selection: remove ids of nodes which no longer exist * Validate the selection: remove ids of nodes which no longer exist
* @private * @private

Loading…
Cancel
Save