poprawki i zmiany ux

This commit is contained in:
Mateusz Gruszczyński
2026-03-26 09:30:39 +01:00
parent fd0f645251
commit 138059945e
28 changed files with 1000 additions and 225 deletions

View File

@@ -9,23 +9,41 @@ interface EChartProps {
export function EChart({ option, className = "h-80 w-full" }: EChartProps) {
const ref = useRef<HTMLDivElement | null>(null);
const chartRef = useRef<echarts.EChartsType | null>(null);
useEffect(() => {
if (!ref.current) {
if (!ref.current || chartRef.current) {
return;
}
const chart = echarts.init(ref.current);
chart.setOption(option);
chartRef.current = echarts.init(ref.current);
const observer = new ResizeObserver(() => chart.resize());
return () => {
chartRef.current?.dispose();
chartRef.current = null;
};
}, []);
useEffect(() => {
if (!chartRef.current) {
return;
}
chartRef.current.setOption(option, { notMerge: false, lazyUpdate: true });
}, [option]);
useEffect(() => {
if (!ref.current || !chartRef.current) {
return;
}
const observer = new ResizeObserver(() => chartRef.current?.resize());
observer.observe(ref.current);
return () => {
observer.disconnect();
chart.dispose();
};
}, [option]);
}, []);
return <div ref={ref} className={className} />;
}