Browse Source

Merge pull request #1421 from zefrog/feat-network-setselection

setSelection feature
fixDataView
Jos de Jong 9 years ago
parent
commit
608446e3f1
2 changed files with 68 additions and 33 deletions
  1. +22
    -0
      docs/network/index.html
  2. +46
    -33
      lib/network/modules/SelectionHandler.js

+ 22
- 0
docs/network/index.html View File

@ -940,6 +940,28 @@ function releaseFunction (clusterPosition, containedNodesPositions) {
before selecting its own objects. <i>Does not fire events</i>.
</td>
</tr>
<tr class="collapsible toggle" onclick="toggleTable('methodTable','setSelection', this);">
<td colspan="2"><span parent="setSelection" class="right-caret" id="method_setSelection"></span> setSelection(
<code>Object selection</code>,
<code>[Object options]</code>)</td>
</tr>
<tr class="hidden" parent="setSelection">
<td class="midMethods">Returns: none</td>
<td>Sets the selection, wich must be an object like this:
<pre class="code">
{
nodes: [Array of nodeIds],
edges: [Array of edgeIds]
}</pre>
You can also pass only <code>nodes</code> or <code>edges</code> in <code>selection</code> object.
Available options are:
<pre class="code">
{
unselectAll: Boolean,
highlightEdges: Boolean
}</pre>
</td>
</tr>
<tr class="collapsible toggle" onclick="toggleTable('methodTable','unselectAll', this);">
<td colspan="2"><span parent="unselectAll" class="right-caret" id="method_unselectAll"></span> unselectAll()</td>
</tr>

+ 46
- 33
lib/network/modules/SelectionHandler.js View File

@ -300,7 +300,7 @@ class SelectionHandler {
this.selectionObj.edges[edgeId].unselect();
}
}
this.selectionObj = {nodes:{},edges:{}};
}
@ -601,6 +601,47 @@ class SelectionHandler {
return idArray;
}
/**
* Updates the current selection
* @param {{nodes: Array.<String>, edges: Array.<String>}} Selection
* @param {Object} options Options
*/
setSelection(selection, options = {}) {
let i, id;
if (!selection || (!selection.nodes && !selection.edges))
throw 'Selection must be an object with nodes and/or edges properties';
// first unselect any selected node, if option is true or undefined
if (options.unselectAll || options.unselectAll === undefined) {
this.unselectAll();
}
if (selection.nodes) {
for (i = 0; i < selection.nodes.length; i++) {
id = selection.nodes[i];
let node = this.body.nodes[id];
if (!node) {
throw new RangeError('Node with id "' + id + '" not found');
}
// don't select edges with it
this.selectObject(node, options.highlightEdges);
}
}
if (selection.edges) {
for (i = 0; i < selection.edges.length; i++) {
id = selection.edges[i];
let edge = this.body.edges[id];
if (!edge) {
throw new RangeError('Edge with id "' + id + '" not found');
}
this.selectObject(edge);
}
}
this.body.emitter.emit('_requestRedraw');
}
/**
* select zero or more nodes with the option to highlight edges
@ -609,24 +650,10 @@ class SelectionHandler {
* @param {boolean} [highlightEdges]
*/
selectNodes(selection, highlightEdges = true) {
let i, id;
if (!selection || (selection.length === undefined))
throw 'Selection must be an array with ids';
// first unselect any selected node
this.unselectAll();
for (i = 0; i < selection.length; i++) {
id = selection[i];
let node = this.body.nodes[id];
if (!node) {
throw new RangeError('Node with id "' + id + '" not found');
}
this.selectObject(node,highlightEdges);
}
this.body.emitter.emit('_requestRedraw');
this.setSelection({nodes: selection}, {highlightEdges: highlightEdges});
}
@ -636,24 +663,10 @@ class SelectionHandler {
* selected nodes.
*/
selectEdges(selection) {
let i, id;
if (!selection || (selection.length === undefined))
throw 'Selection must be an array with ids';
// first unselect any selected objects
this.unselectAll();
for (i = 0; i < selection.length; i++) {
id = selection[i];
let edge = this.body.edges[id];
if (!edge) {
throw new RangeError('Edge with id "' + id + '" not found');
}
this.selectObject(edge);
}
this.body.emitter.emit('_requestRedraw');
this.setSelection({edges: selection});
}
/**

Loading…
Cancel
Save