llshb
llshb

Reputation: 11

Select specified nodes and edges in vis.js

I created a small network with less than 100 nodes and I wish to select some specified nodes and edges like:

desiredNodes=[nodeId1,nodeId2...], desiredEdges=[edgeId1,edgeId2...].

The default network.selectEdges() and network.selectNodes() both have unselectAll built in and I could not figure out how to disable unselectAll.

I have tried

mySelection = {nodes: desiredNodes, 
highlightEdges: false, 
edges: desiredEdges};
network.setSelection(mySelection);

But in this case, all edges connected to desiredNodes are selected and the result is exactly like network.selectNodes(desiredNodes,true).

Is there a way to solve it?

Upvotes: 1

Views: 1652

Answers (1)

Suzanne
Suzanne

Reputation: 691

According to the documentation, setSelection takes an optional second argument where you can supply configuration options like highlightEdges.

mySelection = {
    nodes: desiredNodes, 
    edges: desiredEdges
};

myOptions = {
    highlightEdges: false
};

network.setSelection(mySelection, myOptions);

The other available configuration option happens to be unselectAll, so you could try disabling that in the options object too.

Upvotes: 1

Related Questions