admin管理员组文章数量:1387295
Does cytoscape.js support collapsing/expanding pound node ?
Eg. before collapsing
node1 (-)
--node1.1
--node1.2
------node1.2.1
After collapsing
node1 (+)
A (+) or (-) sign to expand/collapse would be great.
Looking for options to Group a set of nodes using Compound node and collapse/expand via user-interaction. If cytoscape.js doesn't support this by-default, any alternatives/workarounds to reach the goal ?
Does cytoscape.js support collapsing/expanding pound node ?
Eg. before collapsing
node1 (-)
--node1.1
--node1.2
------node1.2.1
After collapsing
node1 (+)
A (+) or (-) sign to expand/collapse would be great.
Looking for options to Group a set of nodes using Compound node and collapse/expand via user-interaction. If cytoscape.js doesn't support this by-default, any alternatives/workarounds to reach the goal ?
Share Improve this question edited Nov 20, 2022 at 1:42 Daniel Widdis 9,16013 gold badges48 silver badges68 bronze badges asked May 27, 2015 at 18:38 NellaiXpressNellaiXpress 631 silver badge3 bronze badges2 Answers
Reset to default 4It's relatively straightforward using the API.
Collapse: node1.descendants().addClass('collapsed-child')
Expand: node1.descendants().removeClass('collapsed-child')
... where .collapsed-child { opacity: 0; }
You may also want to change the positions of the descendants so the parent node is smaller. Alternatively, you could use display: none
for .collapsed-child
if you don't care about seeing edges of collapsed children.
For others in search of a solution to the issue of removing a node and it's children in Cytoscape.js, I tried and failed with the (admittedly dated) solution in the accepted answer: .descendants()
.
While awaiting a response on GitHub,
https://github./cytoscape/cytoscape.js/issues/2877
I devised the following solution. Briefly, I :
- use
.successors()
rather than.dependents()
(suggested above) - save the data in a variable; then, restore those data
- obviates the need for
.addClass()
var myNode = cy.elements('node[name="Technology"]');
// cy.collection() : return a new, empty collection
// https://js.cytoscape/#cy.collection
var myCollection = cy.collection();
setTimeout(function(){
console.log('Deleting "Technology" node + descendants ...')
// Save data for later recall:
// https://js.cytoscape/#cy.remove
myCollection = myCollection.union(myNode.successors().targets().remove());
myNode.successors().targets().remove();
// nested setTimeout():
setTimeout(function(){
console.log('Restoring "Technology" node + descendants ...')
myCollection.restore();
console.log('Done!')
}, 2000);
}, 2000);
本文标签: javascriptcollapsingexpanding compound node in cytoscapeStack Overflow
版权声明:本文标题:javascript - collapsingexpanding compound node in cytoscape - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744568632a2613205.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论