chartist
chartist copied to clipboard
Bug in summing up stacked bars with undefined items in series
When there are undefined items in the series, the summing of stacked bars goes wrong.
I tracked it to this line:
https://github.com/gionkunz/chartist-js/blob/e7e78201bffe9609915e5e53cfafa29a5d6c49f9/src/scripts/charts/bar.js#L152
Instead of
return {
x: prev.x + (curr && curr.x) || 0,
y: prev.y + (curr && curr.y) || 0
};
It should be
return {
x: prev.x + ((curr && curr.x) || 0),
y: prev.y + ((curr && curr.y) || 0)
};
Otherwise whenever curr is undefined, the reduce resets to 0.
Found the same issue here.
BTW, your solution @JanMisker works pretty fine! thanks for submitting a PR 😉
Looks like it's been fixed in v1.0.0:
https://github.com/chartist-js/chartist/blob/b431f76f95480841c2f04f4eb1b6c8055a1ce5f5/src/charts/BarChart/BarChart.ts#L34-L40