From 855313c3076fae304e70a2e51898d9f289ff0ccf Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Wed, 12 Aug 2020 11:35:58 -0700 Subject: [PATCH] new(xy-chart): add hook to context for full scale modification, not just domain --- .../src/sandboxes/vx-chart-poc/Example.tsx | 37 +++++++++-------- .../components/providers/ChartProvider.tsx | 41 +++++++++---------- .../src/components/series/Stack.tsx | 32 ++++++++++++--- .../vx-chart-poc/src/types/context.ts | 14 ++++--- 4 files changed, 75 insertions(+), 49 deletions(-) diff --git a/packages/vx-demo/src/sandboxes/vx-chart-poc/Example.tsx b/packages/vx-demo/src/sandboxes/vx-chart-poc/Example.tsx index 7b282cf13..bf8f2a260 100644 --- a/packages/vx-demo/src/sandboxes/vx-chart-poc/Example.tsx +++ b/packages/vx-demo/src/sandboxes/vx-chart-poc/Example.tsx @@ -20,13 +20,7 @@ import Stack from './src/components/series/Stack'; type DataKeys = 'austin' | 'sf' | 'ny'; -const data = cityTemperature.slice(100, 100 + 12).map(({ date, ...d }) => ({ - ...d, - // current format is like `20200105` which you can't form a valid date from - // @TODO PR soon! - date: `${date.slice(0, 4)}-${date.slice(4, 6)}-${date.slice(6, 8)}`, - key: date, -})) as CityTemperature[]; +const data = cityTemperature.slice(100, 100 + 16); // @TODO wip updating data, not currently used // const halfData = data.slice(0, Math.floor(data.length / 2)); @@ -129,7 +123,17 @@ export default function Example() { const [renderTooltipInPortal, setRenderTooltipInPortal] = useState(true); const [visibleSeries, setVisibleSeries] = useState< ('line' | 'bar' | 'groupedbar' | 'stackedbar')[] - >(['stackedbar']); + >(['bar']); + const canSnapTooltipToDataX = + (visibleSeries.includes('groupedbar') && renderHorizontally) || + (visibleSeries.includes('stackedbar') && !renderHorizontally) || + visibleSeries.includes('bar'); + + const canSnapTooltipToDataY = + (visibleSeries.includes('groupedbar') && !renderHorizontally) || + (visibleSeries.includes('stackedbar') && renderHorizontally) || + visibleSeries.includes('bar'); + const dateScaleConfig: ScaleConfig = useMemo(() => ({ type: 'band', padding: 0.2 }), []); const temperatureScaleConfig: ScaleConfig = useMemo( () => ({ @@ -262,8 +266,8 @@ export default function Example() { /> @@ -279,7 +283,6 @@ export default function Example() {