Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When Force-directed has root with no children and non-zero topDepth, addChildData to root dataItem doesn't draw links #1826

Open
sonh1230 opened this issue Jan 14, 2025 · 2 comments
Labels
bug Something isn't working in next release Implemented. Available soon.

Comments

@sonh1230
Copy link

Question
In the initial situation where there are no children in the root and topDepth is greater than 0, if you add children to the root through addChildData, the link is not drawn.

Below is part of the code in my useLayoutEffect.

useLayoutEffect(() => {
  [some code...]
  const series = container.contents.children.push(
    am5hierarchy.ForceDirected.new(root, {
      maskContent: false,
      topDepth: 1,
      downDepth: Infinity,
      idField: 'id',
      categoryField: 'name',
      childDataField: 'children',
      maxRadius: am5.percent(5),
      minRadius: am5.percent(5),
      nodePadding: 20,
      fillField: 'color',
    })
  );
  series.data.setAll([
    {
      id: 'root',
      name: 'Root',
      children: [],
    },
  ]);
  [some code...]
}, []);

And this is simple button to add nodes by addChildData methods.

<button
  onClick={() => {
    const series = seriesRef.current;
    if (series) {
      const rootDataItem = series.getDataItemById('root');
      if (rootDataItem) {
        series.addChildData(rootDataItem, [
          {
            id: 'test',
            name: 'test',
            children: [
              { id: 'a', name: 'a' },
              { id: 'b', name: 'b' },
              { id: 'c', name: 'c' },
            ],
          },
        ]);
      }
    }
  }}
>
  TEST
</button>

Environment (if applicable)
NEXT 14 / REACT 18

Additional context

2025-01-14.5.14.51.mov
@martynasma
Copy link
Collaborator

Would you be able to post your whole chart and data on CodePen/jsFiddle so that we can test?

@sonh1230
Copy link
Author

sonh1230 commented Jan 15, 2025

At CodePen, the root circle is drawn first no matter what the topDepth is...
Anyway here is my CodePen.
https://codepen.io/nyakvzry-the-encoder/pen/ByBxbwp
If you set topDepth to 0 and press the button, the link is drawn. But if you set topDepth to 1 and press the button, you can see that the link is not drawn.

@zeroin zeroin added bug Something isn't working in next release Implemented. Available soon. and removed question labels Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in next release Implemented. Available soon.
Projects
None yet
Development

No branches or pull requests

3 participants