antvis/G6

[Feat]: I need help with layout calculation. #6941

RackweLLizm posted onGitHub

Describe the feature / 功能描述

I am using Antv G6 v4.8.21. I am using "force2" layout in Graph.

In my example scenario, the graph is created and there are 50 nodes and 50 edges in it. Their x and y values ​​are known (calculated by the layout during the first creation)

Later, I add 30 nodes and 20 edges to the graph with addItem and what I want is not to recalculate the nodes whose x and y values ​​are determined before, their locations remain fixed. But I want calculations to be made for the nodes and edges added later.

Which way would be the best when doing this?

1-) Doing it with pipes (I don't know exactly which order to follow)

2-)layout: { type: 'force2', nodeStrength: (node) => (node.x !== undefined && node.y !== undefined ? 0 : 30), // Moving fixed nodes

}, Doing it with nodeStrength

3-) Doing it with a setting like preset:"preset".

4-) or another method?

Are you willing to contribute? / 是否愿意参与贡献?

✅ Yes / 是


A simple method to fix existing node positions while enabling dynamic layout for new nodes:

{
  layout: {
    type: 'force2',
    onLayoutEnd: (nodes) => {
      nodes.forEach(node => {
        node.fx = node.x;
        node.fy = node.y;
     })
  }
}
posted by yvonneyx 28 days ago

@yvonneyx

Really great solution. You are great. Thank you

posted by RackweLLizm 28 days ago

Fund this Issue

$0.00
Funded

Pull requests