Skip to content

Commit

Permalink
fix: slow throttle interval making chart feel laggy (#921)
Browse files Browse the repository at this point in the history
* fix: slow throttle interval making chart feel laggy

* feat: make throttle ms a prop
  • Loading branch information
mattrussell36 authored Nov 8, 2023
1 parent afa76d2 commit d635460
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/feature/candlestick-chart/candlestick-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export type CandlestickChartProps = {
interval: Interval;
options?: Options;
theme?: ThemeVariant;
drawThrottleMs?: number;
onOptionsChanged?: (options: Options) => void;
onPaneChanged?: (size: number[]) => void;
onViewportChanged?: (viewport: Viewport) => void;
Expand All @@ -93,6 +94,7 @@ export const CandlestickChart = forwardRef(
},
initialViewport,
theme = "dark",
drawThrottleMs = 16.67,
onOptionsChanged = noop,
onPaneChanged = noop,
onViewportChanged = noop,
Expand Down Expand Up @@ -370,6 +372,7 @@ export const CandlestickChart = forwardRef(
colors={colors}
studySize={studySize}
studySizes={studySizes}
drawThrottleMs={drawThrottleMs}
onViewportChanged={handleViewportChanged}
onGetDataRange={handleGetDataRange}
onClosePane={handleClosePane}
Expand Down
11 changes: 6 additions & 5 deletions src/ui/components/plot-container/plot-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import "./plot-container.css";
import "../../../lib/d3fc-element";

import { Core } from "@ui/core";
import { THROTTLE_INTERVAL } from "@util/constants";
import { asyncSnapshot, calculatePreferredSize } from "@util/misc";
import {
Bounds,
Expand Down Expand Up @@ -45,6 +44,7 @@ export type PlotContainerProps = {
colors: Colors;
studySize: number | string;
studySizes: Array<number | string>;
drawThrottleMs: number;
onBoundsChanged?: (bounds: Bounds) => void;
onViewportChanged?: (viewport: Viewport) => void;
onRightClick?: (event: any) => void;
Expand Down Expand Up @@ -72,6 +72,7 @@ export const PlotContainer = forwardRef<
colors,
studySize,
studySizes,
drawThrottleMs,
onViewportChanged = () => {},
onBoundsChanged = () => {},
onRightClick = () => {},
Expand Down Expand Up @@ -117,7 +118,7 @@ export const PlotContainer = forwardRef<
}, []);

const throttleRequestRedraw = useMemo(
() => throttle(requestRedraw, THROTTLE_INTERVAL),
() => throttle(requestRedraw, drawThrottleMs),
[requestRedraw],

Check warning on line 122 in src/ui/components/plot-container/plot-container.tsx

View workflow job for this annotation

GitHub Actions / build

React Hook useMemo has a missing dependency: 'drawThrottleMs'. Either include it or remove the dependency array
);

Expand All @@ -130,17 +131,17 @@ export const PlotContainer = forwardRef<
);

const handleThrottledBoundsChanged = useMemo(
() => throttle(handleBoundsChanged, THROTTLE_INTERVAL),
() => throttle(handleBoundsChanged, drawThrottleMs),
[handleBoundsChanged],

Check warning on line 135 in src/ui/components/plot-container/plot-container.tsx

View workflow job for this annotation

GitHub Actions / build

React Hook useMemo has a missing dependency: 'drawThrottleMs'. Either include it or remove the dependency array
);

const handleDataIndexChanged = useMemo(
() => throttle(setDataIndex, THROTTLE_INTERVAL),
() => throttle(setDataIndex, drawThrottleMs),
[],

Check warning on line 140 in src/ui/components/plot-container/plot-container.tsx

View workflow job for this annotation

GitHub Actions / build

React Hook useMemo has a missing dependency: 'drawThrottleMs'. Either include it or remove the dependency array
);

const handleViewportChanged = useMemo(
() => throttle(onViewportChanged, THROTTLE_INTERVAL),
() => throttle(onViewportChanged, drawThrottleMs),
[onViewportChanged],

Check warning on line 145 in src/ui/components/plot-container/plot-container.tsx

View workflow job for this annotation

GitHub Actions / build

React Hook useMemo has a missing dependency: 'drawThrottleMs'. Either include it or remove the dependency array
);

Expand Down
1 change: 0 additions & 1 deletion src/util/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const AXIS_HEIGHT = FONT_SIZE + 5;
export const AXIS_WIDTH = FONT_SIZE + 60;

export const Y_AXIS_WIDTH = 92;
export const THROTTLE_INTERVAL = 150;
export const INITIAL_NUM_CANDLES_TO_DISPLAY = 100;
export const INITIAL_NUM_CANDLES_TO_FETCH = 10000;
export const DEFAULT_INTERVAL_WIDTH = 10;
Expand Down

0 comments on commit d635460

Please sign in to comment.