Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Fix drawing bars for negative values #1427
Browse files Browse the repository at this point in the history
  • Loading branch information
wiadev committed Jan 10, 2018
1 parent 9f42605 commit 5920044
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/components/charts/BarChartComponent/axes.js
Expand Up @@ -26,9 +26,9 @@ export const populateY0Axis = (svg, rangeY, width, data, fields) => {
svg
.select("g.y0-axis")
.append("line")
.attr("y1", rangeY(-3))
.attr("y1", rangeY(0))
.attr("x1", 0)
.attr("y2", rangeY(-3))
.attr("y2", rangeY(0))
.attr("x2", width)
.attr("stroke-width", 1)
.attr("opacity", 0.5)
Expand Down
14 changes: 12 additions & 2 deletions src/components/charts/BarChartComponent/data.js
Expand Up @@ -104,7 +104,11 @@ export const drawData = (
if (yChanged || reRender) {
return dimensions.height;
} else {
return ranges.y(d.valuePrev);
if (d.valuePrev < 0) {
return ranges.y(0);
} else {
return ranges.y(d.valuePrev);
}
}
})
.attr("height", d => {
Expand All @@ -116,7 +120,13 @@ export const drawData = (
})
.transition()
.duration(1000)
.attr("y", d => ranges.y(d.value))
.attr("y", d => {
if (d.value < 0) {
return ranges.y(0);
} else {
return ranges.y(d.value);
}
})
.attr("height", d => Math.abs(ranges.y(d.value) - ranges.y(0)))
.attr("fill", d => ranges.z(d.key));
};

0 comments on commit 5920044

Please sign in to comment.