cytoscape js Hiding and restoring nodes with edges afterwards

天大地大妈咪最大 提交于 2019-12-12 02:48:09

问题


There is a cool sample at Hide nodes with animation by maxfranz.

I am having trouble reverting the state though.

Even if i keep the nodes + edges and then run restore on them. The nodes / edges do not reappear. Add doesnt work. Restore doesnt work. I must be missing something.

On clicking the node i hide (collapse) the linked nodes and I keep the removedElements in an array, and then store in a sratch with node specific namespace. When the node is clicked again, i want to restore (expand) the state on graph.

So i would expect something like this to work:

var tapped = e.cyTarget;
if (cy.scratch(tapped.id() + "_removed")) {
    var removedElements = cy.scratch(tapped.id() + "_removed");

    for (var i = removedElements.length - 1; i >= 0; i--) {
        removedElements[i].restore();
    }
}

Note that the order of restoring the edges and nodes to be correct, first adding nodes then edges for them in the reverse order of removal.


回答1:


If you've restored hidden elements, they'll be hidden when you restore them. Make sure their style is set appropriately.



来源:https://stackoverflow.com/questions/33508140/cytoscape-js-hiding-and-restoring-nodes-with-edges-afterwards

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!