seeksdream / relation-graph

relation-graph is a relationship graph display component that supports Vue2, Vue3, React. Allowing you to fully customize the graphical elements using HTML/CSS and Vue or React components through slots. 支持Vue和React的 关联关系图谱组件,可以展示如组织机构图谱、股权架构图谱、集团关系图谱等知识图谱,可提供多种图谱布局,包括树状布局、中心布局、力学布局自动布局等。
https://relation-graph.com
MIT License
1.9k stars 491 forks source link

初始化加载关系重叠 #364

Closed lichengze520 closed 1 month ago

lichengze520 commented 2 months ago

数据准备: const __graph_json_data = { rootId: "a", nodes: [ { id: 'a', text: 'IP'}, { id: 'b', text: 'IP'}, { id: 'c', text: 'IP'}, { id: 'e', text: 'IP'} ], lines: [ { from: 'a', to: 'b', text: '关系1',}, { from: 'b', to: 'c', text: '关系2' }, { from: 'c', to: 'e', text: '关系3' }, { from: 'e', to: 'a', text: '关系4' } ] }: 异常结果:image 期望结果:image 期望初始化加载结果关系显示不重合

disappointao commented 2 months ago

我也遇到了,中心布局是有这个问题,你把布局切换成力学布局就好了

lichengze520 commented 2 months ago

force布局也有这个问题,上面的数据,也有问题;

disappointao commented 2 months ago

image force 布局 用的你的数据,效果能接受

lichengze520 commented 2 months ago

谢谢,用force可以,不会重叠了 但是下面这种数据又会有新问题

  1. 数据 jsonData = { rootId: 'aip', nodes: [ { id: 'aip', text: 'IP' }, { id: 'a1', text: '攻击' }, { id: 'vip1', text: 'IP' }, { id: 'a2', text: '攻击' }, { id: 'vip2', text: 'IP' }, { id: 'a3', text: '攻击' }, { id: 'vip3', text: 'IP' } ], lines: [ { from: 'aip', to: 'a1', text: '关系1' }, { from: 'a1', to: 'vip1', text: '关系2' }, { from: 'vip1', to: 'a2', text: '关系3' }, { from: 'a2', to: 'vip2', text: '关系4' }, { from: 'vip2', to: 'a3', text: '关系5' }, { from: 'a3', to: 'vip3', text: '关系6' } ] } 2.结果截图 异常结果,未居中,并展示不全 image 希望结果,能居中展示 image 备注:目前使用2.2.4版本
seeksdream commented 1 month ago

谢谢,用force可以,不会重叠了 但是下面这种数据又会有新问题

  1. 数据 jsonData = { rootId: 'aip', nodes: [ { id: 'aip', text: 'IP' }, { id: 'a1', text: '攻击' }, { id: 'vip1', text: 'IP' }, { id: 'a2', text: '攻击' }, { id: 'vip2', text: 'IP' }, { id: 'a3', text: '攻击' }, { id: 'vip3', text: 'IP' } ], lines: [ { from: 'aip', to: 'a1', text: '关系1' }, { from: 'a1', to: 'vip1', text: '关系2' }, { from: 'vip1', to: 'a2', text: '关系3' }, { from: 'a2', to: 'vip2', text: '关系4' }, { from: 'vip2', to: 'a3', text: '关系5' }, { from: 'a3', to: 'vip3', text: '关系6' } ] } 2.结果截图 异常结果,未居中,并展示不全 image 希望结果,能居中展示 image 备注:目前使用2.2.4版本

力学布局是基于中心布局的基础上开始力导,像你图中的数据,很容易继续保持一条直线的同时达到力学平衡;

你可以更新到2.2.5,然后在力学布局中使用这个新的属性,可以解决你的问题: fastStart:true(使用这个属性后,布局器会现将所有节点随机分配位置,然后开始力导)

image

你试试