Skip to content

Commit

Permalink
Merge pull request #1045 from visualize-admin/fix/column-chart-negati…
Browse files Browse the repository at this point in the history
…ve-y-origin

fix: Column chart negative values Y origin
  • Loading branch information
bprusinowski authored May 31, 2023
2 parents bea31bb + bda1cf8 commit 25d186e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ You can also check the [release page](https://github.com/visualize-admin/visuali

## Unreleased

Nothing yet.
- Fixes
- Bars with negative values are now correctly attached to 0 again.

## [3.19.18] - 2023-05-16

Expand Down
3 changes: 2 additions & 1 deletion app/charts/column/columns-simple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ export const Columns = () => {
const xScaled = xScale(x) as number;
const y = getY(d) ?? NaN;
const yScaled = yScale(y);
const yRender = yScale(Math.max(y, 0));
const height = Math.abs(yScaled - y0);
const color = getColor(y);

return {
key: x,
x: xScaled,
y: yScaled,
y: yRender,
width: bandwidth,
height,
color,
Expand Down
5 changes: 2 additions & 3 deletions app/charts/column/columns-stacked.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,20 @@ export const ColumnsStacked = () => {
x: xScale(x) as number,
y: yScale(segment[1]),
width: bandwidth,
height: y0 - yScale(segment[1] - segment[0]),
height: yScale(segment[0]) - yScale(segment[1]),
color,
};
}),
};
});
}, [bandwidth, colors, getX, series, xScale, y0, yScale]);
}, [bandwidth, colors, getX, series, xScale, yScale]);

React.useEffect(() => {
if (ref.current) {
select(ref.current)
.selectAll<SVGGElement, StackedRenderDatum>("g")
.data(renderData, (d) => d.key)
.join("g")
.attr("data-n", (d) => d.key)
.selectAll<SVGRectElement, RenderDatum>("rect")
.data(
(d) => d.data,
Expand Down

1 comment on commit 25d186e

@vercel
Copy link

@vercel vercel bot commented on 25d186e May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

visualization-tool – ./

visualization-tool-git-main-ixt1.vercel.app
visualization-tool-alpha.vercel.app
visualization-tool-ixt1.vercel.app

Please sign in to comment.