Skip to content

Commit

Permalink
Fix scale options in xychart (#987)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored Jan 4, 2021
1 parent 848bec3 commit 7f678d9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/visx-xychart/src/hooks/useScales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default function useScales<
const memoizedXScale = useMemo(() => {
const registryEntries = registryKeys.map(key => dataRegistry.get(key));

let xScale = createScale(xScaleConfig) as XScale;
type XScaleInput = ScaleInput<XScale>;

const xValues = registryEntries.reduce<XScaleInput[]>(
Expand All @@ -42,8 +41,11 @@ export default function useScales<

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

xScale.range(xScaleConfig.range || [xMin, xMax]);
xScale.domain(xScaleConfig.domain || xDomain);
let xScale = createScale({
range: [xMin, xMax],
domain: xDomain as [number, number],
...xScaleConfig,
}) as XScale;

// apply any scale updates from the registy
registryEntries.forEach(entry => {
Expand All @@ -57,7 +59,6 @@ export default function useScales<
const memoizedYScale = useMemo(() => {
const registryEntries = registryKeys.map(key => dataRegistry.get(key));

let yScale = createScale(yScaleConfig) as YScale;
type YScaleInput = ScaleInput<YScale>;

const yValues = registryEntries.reduce<YScaleInput[]>(
Expand All @@ -68,8 +69,11 @@ export default function useScales<

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

yScale.range(yScaleConfig.range || [yMin, yMax]);
yScale.domain(yScaleConfig.domain || yDomain);
let yScale = createScale({
range: [yMin, yMax],
domain: yDomain as [number, number],
...yScaleConfig,
}) as YScale;

// apply any scale updates from the registy
registryEntries.forEach(entry => {
Expand Down

0 comments on commit 7f678d9

Please sign in to comment.