kurkle / chartjs-chart-sankey

Chart.js module for creating sankey diagrams
MIT License
152 stars 29 forks source link

Overlap when output branch greater than input branch #146

Closed jesnault closed 1 month ago

jesnault commented 1 month ago

Currently in the case the position of the y value in the processTo only take into account the input branch value, which create overlap when the branch output value is higher.

In the following example the branch d and f are overlap

Actual Expected
actual expected

Configuration:

data: [
  {from: 'a', to: 'b', flow: 8},
  {from: 'b', to: 'c', flow: 9},
  {from: 'b', to: 'd', flow: 1},
  {from: 'a', to: 'e', flow: 7},
  {from: 'e', to: 'f', flow: 10},
  {from: 'e', to: 'g', flow: 5},
],

In the actual screenshot the e node y coordinate is 8 because only the input branch (a->b) of upper node b is take into account to calculate the position of e. In the expected screenshot the e node y coordinate is 10 because both input and output branches of upper nodenb are take into account

Proposal:

const size = Math.max(n.in, n.out);
 y = Math.max(n.y + size, y);

PR: https://github.com/kurkle/chartjs-chart-sankey/pull/148