简体   繁体   English

如何在Cytoscape.js中自动选择DAG节点祖先

[英]How to autoselect DAG node ancestors in Cytoscape.js

When selecting (ie clicking on) a node in a DAG rendered with Cytoscape.js, I would like all "ancestor" nodes to be selected automatically. 在用Cytoscape.js渲染的DAG中选择(即单击)一个节点时,我希望所有“祖先”节点都被自动选择。

I have adapted this algorithm to set a property, "visited", to 1 for all nodes that are ancestors (or perhaps more accurately, predecessors - see Directed graph page on Wikipedia) of the selected node. 我已对该算法进行了修改,以将所有作为选定节点的祖先节点(或更准确地说,是前任节点-参见Wikipedia上的定向图页面)的属性“ visited”设置为1。

However, subsequently calling node.select() on all nodes with node.data('visited') == 1 does not cause the style defined with the :selected selector to apply to those nodes unless you hold down shift. 但是,随后在所有具有node.data('visited') == 1节点上调用node.select()不会导致通过:selected选择器定义的样式应用于这些节点,除非您按住shift键。 Even then, only the ancestors are highlighted, the clicked on node is not styled. 即使这样,也仅突出显示祖先,未设置单击节点的样式。

http://jsbin.com/piguxuna/1/edit?js,console,output http://jsbin.com/piguxuna/1/edit?js,控制台,输出

Side note: the example shows how to do a GraphViz dot/Sugiyama layout in Cytoscape.js using dagre. 旁注:该示例显示了如何使用dagre在Cytoscape.js中进行GraphViz点/ Sugiyama布局。

(1) If you use old browsers, you'll probably run into bugs. (1)如果使用旧的浏览器,则可能会遇到错误。 Only modern, autoupdated browsers are supported. 仅支持现代的,自动更新的浏览器。 If you can't update your browser on your phone, update your OS to the latest version. 如果您无法在手机上更新浏览器,请将操作系统更新到最新版本。

(2) Your approach for selection is problematic. (2)您的选择方法有问题。 On tap, you should build a collection of the desired elements (see cy.add() and cy.collection() ). 点击时,您应该构建所需元素的集合(请参见cy.add()cy.collection() )。 Then, you can do toSelectEles.select() and cy.elements().not( toSelectEles ).unselect() . 然后,您可以执行toSelectEles.select() and cy.elements().not( toSelectEles ).unselect()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM