简体   繁体   English

如何将节点传递给 cytoscape-cola.js 中的 gapInequalities?

[英]How do you pass nodes to gapInequalities in cytoscape-cola.js?

The cytoscape.js-cola documentation for the gapInequalities element of a layout dictionary says: layout字典的gapInequalities元素的cytoscape.js-cola 文档说:

  gapInequalities: undefined, // list of inequality constraints for the gap between the nodes,
                              // e.g. [{"axis":"y", "left":node1, "right":node2, "gap":25}]

How do you set up the objects that specify the nodes in the values of left and right ?您如何设置在leftright值中指定节点的对象?

maxkfranz helpfully pointed out here that these objects need to be collection objects . maxkfranz 在这里有用地指出这些对象需要是集合对象 These contain references to specified nodes ("elements") and are created by querying the cytoscape.js "core object".这些包含对指定节点(“元素”)的引用,并通过查询 cytoscape.js “核心对象”来创建。 What's not clear to me is, given that the layout object needs to refer to the node elements, and the elements should not be added to the graph before the layout tells how to render them, how do you properly set up those collection objects?我不清楚的是,鉴于layout object 需要引用节点元素,并且在layout告诉如何渲染它们之前不应将元素添加到图中,您如何正确设置这些集合对象?

For example, to specify that node b should be placed above node a , what goes in place of ???a???例如,要指定节点b应该放在节点a之上,用什么来代替???a??? and ???b??????b??? in the code below?在下面的代码中?

cy = cytoscape({
  elements: [
      { data: { id: 'a' } },
      { data: { id: 'b' } },
      . . .
  ],
  layout: {
    name: 'cola',
    gapInequalities: [
        { axis: 'y', left: ???'a'???, right: ???'b'???, gap: 25 }
        . . .
    ],
    . . .
  }
  . . .
]);

In this case, the answer can't be cy.$id('a') and cy.$id('b') because the cy object hasn't been created yet.在这种情况下,答案不能是cy.$id('a')cy.$id('b')因为尚未创建cy object。 You could get around that by creating the cy object without elements and then calling cy.add() to put them in. But then what goes in the layout object that's passed to cytoscape() ?您可以通过创建没有元素的cy object 然后调用cy.add()将它们放入其中来解决这个问题。但是传递给cytoscape()layout object 会发生什么?

I'm new to both cytoscape.js and cola.js , so I'm most likely just missing some very elementary idea here.我对cytoscape.jscola.js都是新手,所以我很可能只是在这里遗漏了一些非常基本的想法。 A simple example showing what function calls set up the objects and the sequence in which to call them would probably do it.一个简单的示例显示 function 调用设置对象和调用它们的顺序可能会做到这一点。 In my application, nodes and edges are added to the graph gradually, and the animation needs to show them being added, so not having all the elements set up at the start makes more sense, anyway.在我的应用程序中,节点和边逐渐添加到图表中,并且 animation 需要显示它们正在添加,因此无论如何不要在开始时设置所有元素更有意义。

Since your nodes and edges are added gradually, you can create cy object without elements and layout object.由于您的节点和边是逐渐添加的,您可以创建没有元素和布局 object 的 cy object。 Then when new nodes come, you can add them to the graph and apply layout.然后当新节点出现时,您可以将它们添加到图表并应用布局。

After initialization of the cy object, every time new nodes come, apply the following: cy object 初始化后,每次新节点到来时,应用以下内容:

cy.add(...);
cy.layout({
  name: 'cola',
  gapInequalities: [{ axis: 'y', left: cy.$id("a"), right: cy.$id("b"), gap: 25 }],
  ...
}).run();

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

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