chore: add prettier with config and format all files
This commit is contained in:
@@ -2,9 +2,9 @@ import { useCallback, useEffect, useRef } from 'react';
|
||||
import uPlot from 'uplot';
|
||||
|
||||
export type BuildFn = (
|
||||
el: HTMLDivElement,
|
||||
w: number,
|
||||
h: number,
|
||||
el: HTMLDivElement,
|
||||
w: number,
|
||||
h: number,
|
||||
legendRef: React.RefObject<HTMLDivElement>,
|
||||
) => uPlot | null;
|
||||
|
||||
@@ -25,17 +25,21 @@ function idxToPixel(plot: uPlot, idx: number): number {
|
||||
export function usePlot(
|
||||
build: BuildFn,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
deps: any[],
|
||||
): { containerRef: React.RefObject<HTMLDivElement | null>; legendRef: React.RefObject<HTMLDivElement> } {
|
||||
deps: any[],
|
||||
): {
|
||||
containerRef: React.RefObject<HTMLDivElement | null>;
|
||||
legendRef: React.RefObject<HTMLDivElement>;
|
||||
} {
|
||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||
const legendRef = useRef<HTMLDivElement>(null!);
|
||||
const plotRef = useRef<uPlot | null>(null);
|
||||
const lastIdxRef = useRef<number>(0);
|
||||
const legendRef = useRef<HTMLDivElement>(null!);
|
||||
const plotRef = useRef<uPlot | null>(null);
|
||||
const lastIdxRef = useRef<number>(0);
|
||||
|
||||
const rebuild = useCallback(() => {
|
||||
const el = containerRef.current;
|
||||
if (!el) return;
|
||||
const w = el.clientWidth, h = el.clientHeight;
|
||||
const w = el.clientWidth,
|
||||
h = el.clientHeight;
|
||||
if (w < 10 || h < 10) return;
|
||||
|
||||
plotRef.current?.destroy();
|
||||
@@ -60,12 +64,15 @@ export function usePlot(
|
||||
});
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, deps);
|
||||
|
||||
useEffect(() => {
|
||||
rebuild();
|
||||
return () => { plotRef.current?.destroy(); plotRef.current = null; };
|
||||
return () => {
|
||||
plotRef.current?.destroy();
|
||||
plotRef.current = null;
|
||||
};
|
||||
}, [rebuild]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -77,4 +84,4 @@ export function usePlot(
|
||||
}, [rebuild]);
|
||||
|
||||
return { containerRef, legendRef };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user