Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(xychart): add AreaStack tests #1036

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
new(xychart/useScales): avoid NaN domain when no values are present
  • Loading branch information
williaster committed Jan 26, 2021
commit d5722d7978b8491bcfebf93e5d7627b502b11515
10 changes: 8 additions & 2 deletions packages/visx-xychart/src/hooks/useScales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export default function useScales<
[],
);

// d3Extent scale returns NaN domain for empty arrays
if (xValues.length === 0) return undefined;

const xDomain = isDiscreteScale(xScaleConfig) ? xValues : d3Extent(xValues);

let xScale = (scaleCanBeZeroed(xScaleConfig)
Expand All @@ -54,7 +57,7 @@ export default function useScales<
...xScaleConfig,
})) as XScale;

// apply any scale updates from the registy
// apply any scale updates from the registry
registryEntries.forEach(entry => {
if (entry?.xScale) xScale = entry.xScale(xScale);
});
Expand All @@ -74,6 +77,9 @@ export default function useScales<
[],
);

// d3Extent scale returns NaN domain for empty arrays
if (yValues.length === 0) return undefined;

const yDomain = isDiscreteScale(yScaleConfig) ? yValues : d3Extent(yValues);

let yScale = (scaleCanBeZeroed(yScaleConfig)
Expand All @@ -89,7 +95,7 @@ export default function useScales<
...yScaleConfig,
})) as YScale;

// apply any scale updates from the registy
// apply any scale updates from the registry
registryEntries.forEach(entry => {
if (entry?.yScale) yScale = entry.yScale(yScale);
});
Expand Down