|
|
@ -609,32 +609,35 @@ class SelectionHandler { |
|
|
|
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 (!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]; |
|
|
|
|
|
|
|
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'); |
|
|
|
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); |
|
|
|
} |
|
|
|
// don't select edges with it
|
|
|
|
this.selectObject(node, options.highlightEdges); |
|
|
|
} |
|
|
|
|
|
|
|
for (i = 0; i < selection.edges.length; i++) { |
|
|
|
id = selection.edges[i]; |
|
|
|
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'); |
|
|
|
let edge = this.body.edges[id]; |
|
|
|
if (!edge) { |
|
|
|
throw new RangeError('Edge with id "' + id + '" not found'); |
|
|
|
} |
|
|
|
this.selectObject(edge); |
|
|
|
} |
|
|
|
this.selectObject(edge); |
|
|
|
} |
|
|
|
this.body.emitter.emit('_requestRedraw'); |
|
|
|
} |
|
|
@ -647,12 +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'; |
|
|
|
|
|
|
|
this.setSelection({nodes: selection, edges: []}, {highlightEdges: highlightEdges}); |
|
|
|
this.setSelection({nodes: selection}, {highlightEdges: highlightEdges}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -662,12 +663,10 @@ class SelectionHandler { |
|
|
|
* selected nodes. |
|
|
|
*/ |
|
|
|
selectEdges(selection) { |
|
|
|
let i, id; |
|
|
|
|
|
|
|
if (!selection || (selection.length === undefined)) |
|
|
|
throw 'Selection must be an array with ids'; |
|
|
|
|
|
|
|
this.setSelection({nodes: [], edges: selection}); |
|
|
|
this.setSelection({edges: selection}); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|