c3js / c3js/c3

Stacked area chart with regions: lines don't stack

Open
#2,195 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
9.3k
Forks
1.4k
Avg merge
6d 16h
Merged PRs (30d)
1

Description

* **C3 version**: v0.4.18
* **D3 version**: v3.5
* **Browser**: Chrome 61
* **OS**: Windows 10

Here is a fiddle https://jsfiddle.net/uon10tm5/ it's also reproducible in the editor on c3js.org
Essentially the region lines are being drawn without regard to stacking in area charts.

It looks like the cause of this is in c3_chart_internal_fn.generateDrawLine
`if (config.data_regions[d.id]) {
path = $$.lineWithRegions(values, x, y, config.data_regions[d.id]);
} else {
if ($$.isStepType(d)) { values = $$.convertValuesToStep(values); }
path = line.interpolate($$.getInterpolate(d))(values);
}`

Where earlier on:
`line = config.axis_rotated ? line.x(yValue).y(xValue) : line.x(xValue).y(yValue);`
was passed yValue which was defined as:
`yValue = function (d, i) {
return config.data_groups.length > 0 ? getPoints(d, i)[0][1] : yScaleGetter.call($$, d.id)(d.value);
};`
getPoints is the function which gets the offset of the line positions in stacked area charts.

Since $$.lineWithRegions gets passed a y function:
`y = yScaleGetter.call($$, d.id)`
instead of the yValue function above, it never gets to call getPoints if there are stacked elements

Just noticed there is a previous issue with this problem also unresolved #1749

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.