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

Commit

Permalink
Merge pull request #1497 from metasfresh/dev-1427
Browse files Browse the repository at this point in the history
Fix drawing bars for negative values #1427
  • Loading branch information
metas-mk committed Jan 13, 2018
2 parents 531ade5 + c77bbab commit cbdd40a
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const drawData = (
if (yChanged || reRender) {
return dimensions.height;
} else {
return ranges.y(d.valuePrev);
return getY(d.valuePrev, ranges);
}
})
.attr("height", d => {
Expand All @@ -116,7 +116,17 @@ export const drawData = (
})
.transition()
.duration(1000)
.attr("y", d => ranges.y(d.value))
.attr("y", d => {
return getY(d.value, ranges);
})
.attr("height", d => Math.abs(ranges.y(d.value) - ranges.y(0)))
.attr("fill", d => ranges.z(d.key));
};

function getY(value, ranges) {
if (value < 0) {
return ranges.y(0);
} else {
return ranges.y(value);
}
}

0 comments on commit cbdd40a

Please sign in to comment.