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

fix: zoom domain excluding first point on data update #1114

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion src/components/visx/TimeSeriesChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
padding?: Margin;
defaultZoomDomain?: number;
minZoomDomain: number;
domainBasePadding?: [number, number];
numGridLines?: number;
withGridRows?: boolean;
withGridColumns?: boolean;
Expand Down Expand Up @@ -123,6 +124,7 @@
padding,
defaultZoomDomain,
minZoomDomain = 0,
domainBasePadding = [0, 0],
numGridLines,
withGridRows = true,
withGridColumns = false,
Expand Down Expand Up @@ -209,9 +211,13 @@

const zoom = zoomDomain / minZoomDomain;

const domain = [
const domainBase = [
clamp(xAccessor(latestDatum) - zoomDomain, xAccessor(earliestDatum), xAccessor(latestDatum)),
xAccessor(latestDatum),
] as [number, number];
const domain = [
domainBase[0] - (domainBase[1] - domainBase[0]) * domainBasePadding[0],
domainBase[1] + (domainBase[1] - domainBase[0]) * domainBasePadding[1],
] as const;

const visibleData = data.filter(
Expand All @@ -226,7 +232,7 @@
] as const);

return { zoom, domain, range, visibleData };
}, [data, zoomDomain, minZoomDomain]);

Check warning on line 235 in src/components/visx/TimeSeriesChart.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useMemo has missing dependencies: 'domainBasePadding', 'earliestDatum', 'latestDatum', 'xAccessor', and 'yAccessor'. Either include them or remove the dependency array

Check warning on line 235 in src/components/visx/TimeSeriesChart.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useMemo has missing dependencies: 'domainBasePadding', 'earliestDatum', 'latestDatum', 'xAccessor', and 'yAccessor'. Either include them or remove the dependency array

Check warning on line 235 in src/components/visx/TimeSeriesChart.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useMemo has missing dependencies: 'domainBasePadding', 'earliestDatum', 'latestDatum', 'xAccessor', and 'yAccessor'. Either include them or remove the dependency array

const { domain, range, visibleData, zoom } = calculatedValues;

Expand All @@ -234,7 +240,7 @@
if (visibleData) {
onVisibleDataChange?.(visibleData);
}
}, [visibleData]);

Check warning on line 243 in src/components/visx/TimeSeriesChart.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'onVisibleDataChange'. Either include it or remove the dependency array. If 'onVisibleDataChange' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 243 in src/components/visx/TimeSeriesChart.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'onVisibleDataChange'. Either include it or remove the dependency array. If 'onVisibleDataChange' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 243 in src/components/visx/TimeSeriesChart.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'onVisibleDataChange'. Either include it or remove the dependency array. If 'onVisibleDataChange' changes too often, find the parent component that defines it and wrap that definition in useCallback

// Events
const onWheel = ({ deltaY }: React.WheelEvent) => {
Expand Down
1 change: 1 addition & 0 deletions src/pages/vaults/VaultPnlChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export const VaultPnlChart = ({ className }: VaultPnlChartProps) => {
onTooltipContext={onTooltipContext}
onZoom={handleZoom}
defaultZoomDomain={zoomDomain}
domainBasePadding={[0.01, 0]}
minZoomDomain={timeUnits.day * 2.5}
slotEmpty={undefined}
numGridLines={0}
Expand Down
Loading