vis-network icon indicating copy to clipboard operation
vis-network copied to clipboard

Edge color updating bug.

Open baloian opened this issue 7 years ago • 30 comments

Hi Everyone,

I am trying to update edges' color by providing an array of edges (every single edge has different color), but it updated all edges' color. But if I update just one edge it works correct, other edges remain the same, if number of updated data is more than one it updates all colors, basically sets the last element's color.

Is this bug or I am not doing it in a right way?

Here is how I update edge data dataSetsObject.update(edges);

baloian avatar Oct 11 '19 15:10 baloian

I'm just supposed to just know what's the content of edges by looking into my crystal ball or what?

Thomaash avatar Oct 11 '19 15:10 Thomaash

Sorry, I missed to provide it. An edges is an array of JSON objects and format of every single object is this (real example) Screenshot from 2019-10-11 11-50-42

baloian avatar Oct 11 '19 15:10 baloian

@Thomaash so the color object's color field is different for every single edge, but as a result I see the latest object's color for all edges instead of different colors. Any recommendations ?

baloian avatar Oct 11 '19 15:10 baloian

Hmmm, it doesn't happen to me. Could you tweak the following MWE https://jsfiddle.net/thomaash/ov0nfkw9/ to show your issue, please?

Thomaash avatar Oct 11 '19 16:10 Thomaash

Thanks @Thomaash!. Interesting, I do the same but in a big project. I am assigning color object dynamically do you think that it can cause the problem? may be it creates one value and multiple links.

baloian avatar Oct 11 '19 19:10 baloian

I don't see how this could happen. But you can simply try JSON.parse(JSON.stringify(edges)) and see if it makes the issues disappear.

Thomaash avatar Oct 11 '19 19:10 Thomaash

I tried but it didn't help. This is really strange because I do update for nodes using the same methods.

baloian avatar Oct 11 '19 19:10 baloian

Hmm, could you post console.log(edges._data) output (fully unpack at least one edge)?

Thomaash avatar Oct 11 '19 19:10 Thomaash

See the result of the console.log(edges._data) for one item. Just wanted you to know that colors are different after update operation only here not in UI. Also, I can give you access to repo if you wish so you can see how I designed it.

Screenshot from 2019-10-11 17-21-09

baloian avatar Oct 11 '19 21:10 baloian

Oh, the color values are getters. This could mess things up. Where do these getters get their values?

Thomaash avatar Oct 11 '19 21:10 Thomaash

Oops, I do not modify edge object after this dataSets.edges = new vis.DataSet(edges); operation. Any recommendations how can I debug it and figure it out?

baloian avatar Oct 11 '19 21:10 baloian

I would put a break point (or console.log) into the getters to see what's actually going on there.

Thomaash avatar Oct 11 '19 21:10 Thomaash

Feel free to see (link) the results in console mode where I print edges._object after update operation. Let me know you thoughts please.

baloian avatar Oct 11 '19 21:10 baloian

Do you have the whole data set observed by Vue?

Thomaash avatar Oct 11 '19 21:10 Thomaash

I don't think so. Do you want me to change the code and you will see whole data set object?

baloian avatar Oct 11 '19 21:10 baloian

Actually looking through your source code (VisGraph.vue:65-68) you have it observed. I would try to define it without observing to see if it changes anything.

Thomaash avatar Oct 11 '19 21:10 Thomaash

@Thomaash , I am not sure that I got you properly, but I need a value in Vue to keep it kind of global right? as DataSet and update not in the same scope.

baloian avatar Oct 11 '19 21:10 baloian

Check https://github.com/rpkilby/vue-nonreactive out. Then you should be able to put data: Vue.nonreactive({ nodes: [], edges: [] }) into VisGraph.vue:65-68. This should prevent the data sets from being observed and maybe (really not sure here) resolve the issues.

Thomaash avatar Oct 11 '19 21:10 Thomaash

Okay, thanks a lot I appreciate it. Let me check it out and will keep you updated. I just wanted you to notice one thing that in the same they everything works for Nodes, and I cannot explain it, on the other side when I do this edges.update(edge[0]) it works prefect. Problem occures when I am trying to update more than one edges.

baloian avatar Oct 11 '19 22:10 baloian

BTW, when I use the old version of vis.js (version to 4.9.0) it works without any problem.

baloian avatar Oct 11 '19 22:10 baloian