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

Is it possible to do loops? #24

Open
Eric-oktagon opened this issue Apr 21, 2021 · 2 comments
Open

Is it possible to do loops? #24

Eric-oktagon opened this issue Apr 21, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@Eric-oktagon
Copy link

I am trying to do loops, like
{ from:"A", to:"B", flow:20 },
{ from:"B", to:"B", flow:10 }

but I'm not getting it, am I doing something wrong or still not supported loops?

@kurkle kurkle added the enhancement New feature or request label May 10, 2021
@kurkle
Copy link
Owner

kurkle commented May 10, 2021

Direct loops are not currently possible

@simevo
Copy link

simevo commented Sep 29, 2021

When I try this, the CPU fan starts to spin, after a while I get Maximum call stack size exceeded in the console and the chart is not drawn

I have patched the nodeCountfunction like this:

const nodeCount = (list, prop) => {
  return list.reduce((acc, cur) => {
    if (cur.node[prop] === list) {
      return acc + cur.node[prop].length;
    } else {
      return acc + cur.node[prop].length + nodeCount(cur.node[prop], prop);
    }
  }, 0);
}

and now the loop is not shown but a vertical length of the node "bar" is reserved for it:
image

here is the test file I am using in the build dir:

<!DOCTYPE html>
<html lang="">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>Sankey</title>
    <style>
      .chart {
        max-width: 800px;
        max-height: 600px;
      }
    </style>
  </head>
  <body>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script src="dist/chartjs-chart-sankey.js"></script>

    <div class="chart">
      <canvas id="chart"></canvas>
    </div>
    <script>
      var ctx = document.getElementById("chart").getContext("2d");

      var colors = {
        A: 'red',
        B: 'blue'
      }

      function getColor(name) {
        return colors[name] || "green";
      }

      var chart = new Chart(ctx, {
        type: "sankey",
        data: {
          datasets: [
            {
              data: [
              { from:"A", to:"B", flow:20 },
              { from:"B", to:"B", flow:10 }
              ],
              colorFrom: (c) => getColor(c.dataset.data[c.dataIndex].from),
              colorTo: (c) => getColor(c.dataset.data[c.dataIndex].to),
              borderWidth: 2,
              borderColor: 'black'
            }
          ]
        }
      });
      </script>
  </body>
</html>

can you give me a hint how to make it draw the loop ? I'd send a PR if you wish, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants