antvis/G6

想绘制一个双向的dagre流程图 #4978

zhubin1992 posted onGitHub

问题描述

dagre只能绘制单向的流程图,如rankdir: 'TB'。 现在想使用流水线子图布局添加另一个方向的流程图,rankdir: 'BT',并且两棵‘树’的起始节点相同。

实际与预期不符:

image

重现链接

https://codesandbox.io/s/wizardly-jepsen-5gqn92?file=/src/App.js

重现步骤

layout: {
        pipes: [
          {
            type: "dagre",
            rankdir: "TB",
            nodesFilter: (node) => node.id <= 5,
            nodesepFunc: (d) => {
              if (d.id === "3") {
                return 500;
              }
              return 50;
            },
            ranksep: 70,
            controlPoints: true
          },
          {
            type: "dagre",
            rankdir: "BT",
            nodesFilter: (node) => node.id > 5 || node.id === 1,
            nodesepFunc: (d) => {
              if (d.id === "3") {
                return 500;
              }
              return 50;
            },
            ranksep: 70,
            controlPoints: true
          }
        ]
      },

预期行为

预期图:

image

平台

  • 操作系统: [macOS, Windows, Linux, React Native ...]
  • 网页浏览器: [Google Chrome, Safari, Firefox]
  • G6 版本: [4.5.1 ... ]

屏幕截图或视频(可选)

No response

补充说明(可选)

No response


https://codesandbox.io/s/2-dagres-dh3z5m

  1. 给不同子 dagre 布局设置 begin
  2. 节点 id 是 string,想要对比 > 5 、=== 1 什么的,要么用 Number(node.id) 强转,要么用更合理的方式判断
posted by Yanyan-Wang over 1 year ago

https://codesandbox.io/s/2-dagres-dh3z5m

  1. 给不同子 dagre 布局设置 begin
  2. 节点 id 是 string,想要对比 > 5 、=== 1 什么的,要么用 Number(node.id) 强转,要么用更合理的方式判断

非常感谢!确实可以实现预期效果,看了文档这个begin是4.5.1开始支持,之前一直用3.x没注意。 另外我想再问下,这个begin是“布局的左上角对齐位置”,看你的示例,是[0,100]和[200.-350],这几个值似乎只能通过已知数据的层级,然后计算得出,是这样么?

posted by zhubin1992 over 1 year ago

确实这样需要预估布局的范围才好自动指定 begin,你也可以使用自定义布局,去分步骤调用 dagre,然后计算上一个 dagre 出来节点的范围,再决定下一个 dagre 的 begin。自定义布局 demo:https://g6.antv.antgroup.com/zh/examples/net/layoutMechanism/#customBigraph

可在 registerLayout 里面 new dagre 进行局部的布局,引用布局和 new 的方法可以参考:https://g6.antv.antgroup.com/zh/examples/net/layoutMechanism/#subgraphLayout

posted by Yanyan-Wang over 1 year ago

嗯嗯我会进行尝试,再次感谢你的详细解答

posted by zhubin1992 over 1 year ago

Fund this Issue

$0.00
Funded

Pull requests