antvis/G6

单独使用布局报这个错 Cannot read properties of undefined (reading 'rank') #5033

katerinaaaaaa posted onGitHub

问题描述

单独使用布局报这个错 Cannot read properties of undefined (reading 'rank')

重现链接

https://codesandbox.io/s/new

重现步骤

1.

import { DagreLayout } from '@antv/layout'
const data = {
  nodes: [
    {
      name: '应用服务器',
      id: '8c811eec-e60b-4609-a9f6-ed5d36d58ab9',
      comboId: 'sasasa'
    },
    {
      name: '防火墙',
      id: '170a711d-0c1c-4778-98a7-04c6b095110e',
      comboId: 'sasasa'
    },
    {
      name: '路由器',
      id: '38069dbb-b526-4c87-b182-7093b91dfc3f'
    },
    {
      name: '应用服务器',
      id: '016af125-ab6e-499b-9456-b06590bbd81a'
    },
    {
      name: '防火墙',
      id: 'e055704a-3c3c-4f5b-afdd-fdaf7739b868'
    }
  ],
  combos: [
    {
      id: 'sasasa'
    }
  ],
  edges: [
    {
      source: '170a711d-0c1c-4778-98a7-04c6b095110e',
      target: 'e055704a-3c3c-4f5b-afdd-fdaf7739b868'
    },
    {
      source: '8c811eec-e60b-4609-a9f6-ed5d36d58ab9',
      target: '016af125-ab6e-499b-9456-b06590bbd81a'
    },
    {
      source: '016af125-ab6e-499b-9456-b06590bbd81a',
      target: '38069dbb-b526-4c87-b182-7093b91dfc3f'
    },
    {
      source: 'sasasa',
      target: '38069dbb-b526-4c87-b182-7093b91dfc3f'
    }
  ]
}
const darge = new DagreLayout({
  type: 'dagre',
  ranker: 'network-simplex', // 节点分层算法,可选:'tight-tree' 'longest-path' 'network-simplex'
  rankdir: 'TB', // 图的延展方向,可选: 'TB' | 'BT' | 'LR' | 'RL'
  ranksep: 100, // 图的各个层次之间的间距
  nodesep: 100, // 同层各个节点之间的间距
  sortByCombo: true,
  nodeSize: 30
})
const res = darge.layout(data)
console.log('res', res)

2.浏览器报错 Cannot read properties of undefined (reading 'rank') TKU( GZMCLYACU_ NR%%10

预期行为

期望正常运行,输出布局位置信息

平台

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

屏幕截图或视频(可选)

https://github.com/antvis/G6/assets/87105438/debbc4f6-fa8f-49ec-a8a4-861db8f3b0e4 TKU( GZMCLYACU_ NR%%10

补充说明(可选)

No response


hi @katerinaaaaaa, welcome!

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

当使用 G6 配置的 layout 时,数据在给到 dagre 算法时经过处理。如果单独使用,需要将 combo 相关的边放到 comboEdges 数组中:

const res = darge.layout({ nodes: data.nodes, combos: data.combos, edges: data.edges.filter(edge => !data.combos.find(edge.source) && !data.combos.find(edge.target)), comboEdges: data.edges.filter(edge => data.combos.find(edge.source) || data.combos.find(edge.target)), })

posted by Yanyan-Wang over 1 year ago

当使用 G6 配置的 layout 时,数据在给到 dagre 算法时经过处理。如果单独使用,需要将 combo 相关的边放到 comboEdges 数组中:

const res = darge.layout({ nodes: data.nodes, combos: data.combos, edges: data.edges.filter(edge => !data.combos.find(edge.source) && !data.combos.find(edge.target)), comboEdges: data.edges.filter(edge => data.combos.find(edge.source) || data.combos.find(edge.target)), })

你好,在最新版中是必须用GraphLib的数据结构吧; 另外,我发现涉及combo的一些处理,G6中在给到layout之前也进行了一些处理,总之就是很难 直接单独使用layout;能不能给一个涉及的combo的稍微复杂的一些的 单独使用layout的示例,比如antv-dagre或comboCombined;

posted by liseri 10 months 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