Browse Source

added method setselection used by both selectNodes and selectEdges methods

fixDataView
Maxime Douailin 9 years ago
parent
commit
ee0300c38a
1 changed files with 45 additions and 31 deletions
  1. +45
    -31
      lib/network/modules/SelectionHandler.js

+ 45
- 31
lib/network/modules/SelectionHandler.js View File

@ -300,7 +300,7 @@ class SelectionHandler {
this.selectionObj.edges[edgeId].unselect(); this.selectionObj.edges[edgeId].unselect();
} }
} }
this.selectionObj = {nodes:{},edges:{}}; this.selectionObj = {nodes:{},edges:{}};
} }
@ -601,6 +601,44 @@ class SelectionHandler {
return idArray; 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 edges properties';
// first unselect any selected node
if (options.unselectAll || options.unselectAll === undefined) {
this.unselectAll();
}
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);
}
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 * select zero or more nodes with the option to highlight edges
@ -610,23 +648,11 @@ class SelectionHandler {
*/ */
selectNodes(selection, highlightEdges = true) { selectNodes(selection, highlightEdges = true) {
let i, id; let i, id;
if (!selection || (selection.length === undefined)) if (!selection || (selection.length === undefined))
throw 'Selection must be an array with ids'; 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, edges: []}, {highlightEdges: highlightEdges});
} }
@ -637,23 +663,11 @@ class SelectionHandler {
*/ */
selectEdges(selection) { selectEdges(selection) {
let i, id; let i, id;
if (!selection || (selection.length === undefined)) if (!selection || (selection.length === undefined))
throw 'Selection must be an array with ids'; 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({nodes: [], edges: selection});
} }
/** /**

Loading…
Cancel
Save