admin管理员组文章数量:1405636
I am using vis.js and one of my tasks is to implement the following behavior: when I select a node, the node and its neighbors must be highlighted. In the same time, all the other nodes must have a 'grayed-out' effect. Looking at the vis.js showcase I saw this: / and it is exactly what I want to acquire.
The question is...how do I achieve this effect easily? Do I really need to iterate between all the nodes in the graph and change their color properties?
Thanks!
I am using vis.js and one of my tasks is to implement the following behavior: when I select a node, the node and its neighbors must be highlighted. In the same time, all the other nodes must have a 'grayed-out' effect. Looking at the vis.js showcase I saw this: https://kenedict./networks/startups/ and it is exactly what I want to acquire.
The question is...how do I achieve this effect easily? Do I really need to iterate between all the nodes in the graph and change their color properties?
Thanks!
Share Improve this question asked Apr 10, 2018 at 13:31 Adrian PopAdrian Pop 1,9675 gold badges29 silver badges42 bronze badges 1- tl;dr: as far as I know, yes. I have the same feature in my network and I do the same thing. One thing you can do to maybe optmize this is, instead of greying out each node, you can set the color property for all nodes in the options as grey and then you "only" colorize the neighbours... But still, not an easy to do... – João Menighin Commented Apr 10, 2018 at 20:12
1 Answer
Reset to default 6The answer is a half of what you might expect:
yes, there is a quick way to find the neighbours: see the
getConnectedNodes
method:network.getConnectedNodes(nodeId)
will return an array of ids of the connected nodes;after you got those ids, you do have to iterate the nodes and add colors. You can add/remove groups instead, but you will still need to iterate all the nodes since you need to change non-selected-or-neighbours nodes' colors too. The thing is, this is a very custom set of nodes, and nothing is changed about them on select by default.
本文标签: javascriptVisjs Highlight selected node and grey out the othersStack Overflow
版权声明:本文标题:javascript - Vis.js: Highlight selected node and grey out the others - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744296483a2599367.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论