({
options,
sx,
onChartInitialized,
})
| 55 | }; |
| 56 | |
| 57 | export const EChart: FunctionComponent<GraphProps> = ({ |
| 58 | options, |
| 59 | sx, |
| 60 | onChartInitialized, |
| 61 | }) => { |
| 62 | const wrapperRef = useRef<HTMLDivElement>(null); |
| 63 | |
| 64 | const [chart, setChart] = useState<Chart>(); |
| 65 | |
| 66 | useEffect(() => { |
| 67 | if (wrapperRef.current) { |
| 68 | setChart(echarts.init(wrapperRef.current)); |
| 69 | } |
| 70 | }, [wrapperRef]); |
| 71 | |
| 72 | useEffect(() => { |
| 73 | if (chart) { |
| 74 | onChartInitialized?.(chart); |
| 75 | } |
| 76 | }, [chart, onChartInitialized]); |
| 77 | |
| 78 | useEffect(() => { |
| 79 | if (chart) { |
| 80 | chart.setOption(options, false); |
| 81 | } |
| 82 | }, [chart, options]); |
| 83 | |
| 84 | useEffect(() => { |
| 85 | if (chart && wrapperRef.current) { |
| 86 | const resizeObserver = new ResizeObserver(() => { |
| 87 | chart.resize(); |
| 88 | }); |
| 89 | |
| 90 | resizeObserver.observe(wrapperRef.current); |
| 91 | |
| 92 | return () => { |
| 93 | resizeObserver.disconnect(); |
| 94 | }; |
| 95 | } |
| 96 | }, [chart]); |
| 97 | |
| 98 | return ( |
| 99 | <Box |
| 100 | sx={[ |
| 101 | { width: "100%", height: "100%" }, |
| 102 | ...(Array.isArray(sx) ? sx : [sx]), |
| 103 | ]} |
| 104 | ref={wrapperRef} |
| 105 | /> |
| 106 | ); |
| 107 | }; |
nothing calls this directly
no test coverage detected