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

Expand Child Node when invoking filterChart #439

Open
thedt opened this issue Oct 5, 2024 · 0 comments
Open

Expand Child Node when invoking filterChart #439

thedt opened this issue Oct 5, 2024 · 0 comments

Comments

@thedt
Copy link

thedt commented Oct 5, 2024

Hello,

I hope you are doing well and good job on this project it is really good!
So I am trying to enable the search function shown in the link below to expand the direct child nodes (descendants) of the searched name.

Link to the search example:
https://stackblitz.com/edit/js-wdexqc?file=index.html

In #429 I see we can call the stratify()(data) function with descendants. The issue I'm facing is its expanding all the nodes and not just the ones that made it past the IF statement. Would you have an idea of what I might be missing?
Again thank you so much for your time!

The modified filterChart function:

`function filterChart(e) {
// Get input value
const value = e.srcElement.value;

  // Clear previous higlighting
  chart.clearHighlighting();

  // Get chart nodes
  const data = chart.data();
  // Mark all previously expanded nodes for collapse

  data.forEach((d) => (d._expanded = false));
  // Loop over data and check if input value matches any name
  const hierarchical = d3.stratify()(data);
  data.forEach((d) => {
    if (value != '' && d.name.toLowerCase().includes(value.toLowerCase())) {
      // If matches, mark node as highlighted
      d._highlighted = true;

      hierarchical.each((d) => {
          console.log(d);
          const descendants = d.descendants();
          descendants.forEach((d) => (d.data._expanded = true));
      });
    }
  });
  // Update data and rerender graph
  chart.data(data).render().fit();
  console.log('filtering chart', e.srcElement.value);
}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant