【问题标题】:How to Zoom in a selected node in cytoscape如何放大 cytoscape 中的选定节点
【发布时间】:2018-09-10 10:36:16
【问题描述】:

我是 javascript 和 cytoscape 的新手。 我想生成一个图表,(仍然是硬编码的)

  1. 现在我需要缩放一个点击的节点..
  2. 此外,当单击节点时,显示另一个图形

感谢您的帮助

谢谢

【问题讨论】:

标签: javascript graph cytoscape.js flowchart


【解决方案1】:

您可以像这样将节点上的点击事件绑定到 cytoscape:

cy.bind('click ', 'node', function (evt) {
    var pos = cy.nodes("[id = " + evt.target.data().id + "]").position();
    cy.zoom({                       // Zoom to the specified position
      level: yourLevel,             // 0 <= yourLevel, maybe try out 1,2,3,4... and see what fits
      position: pos
    });
});

要显示另一个图表,只需执行相同的绑定函数并将元素添加到空图表:

cy.bind('click', 'node', function (evt) {
    cy.remove(cy.elements());                 // remove elements and reset graph
    cy.reset();                               // graph is empty now
    cy.add(yourElements);                     // add new elements
    cy.elements().layout(yourLayout).run();   // give them a layout
});

最后,您可能想要 cy.unbind() 您拥有的绑定并再次绑定它们,以确保您不会多次调用这些绑定。

亲切的问候!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-13
    相关资源
    最近更新 更多