Skip to content

Commit

Permalink
Skip rendering bar if no y value provided
Browse files Browse the repository at this point in the history
  • Loading branch information
owattenmaker committed Sep 29, 2023
1 parent 683bc28 commit 0987dba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/src/cartesian/hooks/useBarPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export const useBarPath = (
const path = Skia.Path.Make();

points.forEach(({ x, y }) => {
// Skip drawing bar if no y value provided (see also transformInputData)
if (isNaN(y)) return;

if (!roundedCorners) {
path.addRect(
Skia.XYWHRect(x - barWidth / 2, y, barWidth, chartBounds.bottom - y),
Expand Down
9 changes: 6 additions & 3 deletions lib/src/cartesian/utils/transformInputData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,14 @@ export const transformInputData = <
});

yKeys.forEach((yKey) => {
y[yKey].i = data.map((datum) => asNumber(datum[yKey]));
y[yKey].o = data.map((datum) => yScale(asNumber(datum[yKey])));
// Filter out non-numerical values (i.e. if the bar shouldn't exist)
const filtered = data.filter((datum) => typeof datum[yKey] === "number");

y[yKey].i = filtered.map((datum) => asNumber(datum[yKey]));
y[yKey].o = filtered.map((datum) => yScale(asNumber(datum[yKey])));
});

// Measure our top-most y-label if we have grid options so we can
// Measure our top-most y-label if we have grid options, so we can
// compensate for it in our x-scale.
const topYLabel =
axisOptions?.formatYLabel?.(yScale.domain().at(0) as RawData[YK]) ||
Expand Down

0 comments on commit 0987dba

Please sign in to comment.