简体   繁体   English

有没有办法在具有固定节点的 d3 中创建静态有向图?

[英]Is there a way to create static directed graph in d3 with fixed nodes?

So I need to create a static directed graph that depicts the process of creating something.所以我需要创建一个静态有向图来描述创建某些东西的过程。 Its children can point to the same stage but doesn't have to.它的孩子可以指向同一个阶段,但不是必须的。 What's important is that in the end, all the children branches point to the same final stage.重要的是,最终所有子分支都指向同一个最终阶段。

Its final look if it comes to the structure should be something similar to the photo below如果涉及到结构,它的最终外观应该类似于下面的照片

https://imgur.com/a/BXr44GO https://imgur.com/a/BXr44GO

So until now, I have experimented with the force layout graphs from d3.所以到目前为止,我已经尝试了 d3 中的力布局图。 I have searched for examples and similar questions here, but none of them referred to my specific problem.我在这里搜索了示例和类似问题,但没有一个提到我的具体问题。 However, I'm not an expert in d3, so maybe I was doing something wrong, or I missed something, that's why I'm coming here because nothing else comes to my mind.然而,我不是 d3 的专家,所以也许我做错了什么,或者我错过了什么,这就是我来这里的原因,因为我没有想到其他任何东西。

Some of the examples: https://bl.ocks.org/mbostock/3750558https://bl.ocks.org/heybignick/3faf257bbbbc7743bb72310d03b86ee8一些例子: https : //bl.ocks.org/mbostock/3750558https://bl.ocks.org/heybignick/3faf257bbbbc7743bb72310d03b86ee8

My main issue with the d3 force layout graphs is that I have no clue how to make them static and spam each time in the same position without floating around like they are on the examples.我对 d3 力布局图的主要问题是,我不知道如何使它们每次都在同一位置保持静态和垃圾邮件,而不会像示例中那样四处飘动。

So my question would be, is it possible to make the graph as provided in the image above with d3 force layouts, or should I just work on creating my custom layout that would present graph in the manner that I need.所以我的问题是,是否可以使用 d3 力布局制作上图中提供的图形,或者我应该只创建我的自定义布局,以我需要的方式呈现图形。

If it's possible, I would kindly ask for a piece of advice on how should I proceed with this kind of graph.如果可能的话,我想请教一下我应该如何处理这种图表。

I think that what you are looking for is d3-sankey , you can find more examples here我认为您正在寻找的是d3-sankey ,您可以在此处找到更多示例

If you use force simulation.如果使用力模拟。 you will have to calculate the position of each node and 'fix' them like here and also work in a static force simulation, which is basically the same, but you control how many times the force is 'run', like here , take a look at the following lines:您将必须计算每个节点的位置并像这里一样“修复”它们并且还可以在静态力模拟中工作,这基本上是相同的,但是您可以控制力“运行”的次数, 就像这里一样,采用查看以下几行:

// Run the layout a fixed number of times. // The ideal number of times scales with graph complexity. // Of course, don't run too long—you'll hang the page! force.start(); for (var i = n * n; i > 0; --i) force.tick(); force.stop();

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

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