antvis/G6

自定义布局的问题 #5232

zhangyang-igloo posted onGitHub

问题描述

需求:第1层级横向排列,从第2层级开始纵向排列 实现方式:整体紧凑树布局,从第2层级开始使用缩进树布局的自定义布局 问题:缩进树布局的节点起始位置不对 image

重现链接

暂无

重现步骤

-

预期行为

image

平台

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

屏幕截图或视频(可选)

No response

补充说明(可选)

代码参考了https://github.com/antvis/G6/issues/5062 中的 https://codesandbox.io/s/ecstatic-phoebe-95kxjg 附上layout部分代码 ` layout: ((d: any) => { const compactBoxConfig = { type: 'compactBox', direction: 'TB', getId: function getId(d: any) { return d.id; }, getHeight: function getHeight() { return 84; }, getWidth: function getWidth() { return 233; }, getVGap: function getVGap() { return 20; }, getHGap: function getHGap() { return 20; }, }; const layoutData = Hierarchy[compactBoxConfig.type]( d, compactBoxConfig, );

    const indentConfig = {
      type: 'indented',
      isHorizontal: true,
      direction: 'LR',
      indent: 140,
      getHeight: function getHeight() {
        return 84;
      },
      getWidth: function getWidth() {
        return 233;
      },
    };

    const loop = (tree: any) => {
      if (tree.depth >= 2 && tree.children?.length > 0) {
        const subLayoutData = Hierarchy[indentConfig.type](
          tree,
          indentConfig,
        );
        const childrenBeginX = subLayoutData.children[0].x;
        const displacementX = subLayoutData.x - childrenBeginX;
        G6.Util.traverseTree(subLayoutData, (node: any) => {
          if (node.id === subLayoutData.id) return;
          node.x += displacementX;
        });
      } else {
        if (tree.children?.length > 0) {
          tree.children.forEach((item: any) => {
            loop(item);
          });
        }
      }
    };

    loop(layoutData);

    return layoutData;
  }) as any,`

hi @zhangyang-igloo, welcome!

posted by github-actions[bot] over 1 year ago

Hi @zhangyang-igloo, Please star this repo if you find it useful! Thanks :star:! 你好 @zhangyang-igloo。如果该仓库对你有用,可以 star 一下,感谢你的 :star:!

posted by github-actions[bot] over 1 year ago

提供重现链接

posted by KTBOY over 1 year ago

This issue has been closed because it has been outdate for a long time. Please open a new issue if you still need help.

这个 issue 已经被关闭,因为 它已经过期很久了。 如果你仍然需要帮助,请创建一个新的 issue。

posted by github-actions[bot] 10 months ago

Fund this Issue

$0.00
Funded

Pull requests