rosy white rosy white -4 years ago 184
Javascript Question

vis.js change node color also affect edge color

I used this function to change the node color from it's id however i found that the edge that start with that node also change color

example

If i changed node 2 to red

edge 8,7,6 that is connect from: 2, to: 1,4,5 also changed to red

function draw() {
nodes.add([
{id: 1, label: 'Node 1'},
{id: 2, label: 'Node 2'},
{id: 3, label: 'Node 3'},
{id: 4, label: 'Node 4'},
{id: 5, label: 'Node 5'}
]);
edges.add([
{id:9, from: 3, to: 1},
{id:8, from: 2, to: 1},
{id:7, from: 2, to: 4},
{id:6, from: 2, to: 5}
]);


Here is my code

network.on( 'click', function(params) {
idnode = params.nodes;
idedge = params.edges;
});


function red() {
idnode2 = idnode;
nodes.update({id: idnode2, color: "red"});
}

Answer Source

My understanding is that this is exactly how vis.js works: the edge color by default is the color of the (border of) the origin node (you could of course change it, just like you did with the node). For details on this, see the documentation for the option: 'color.inherit' in http://visjs.org/docs/network/edges.html# If this helps you, please mark it as an answer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download