MCPcopy Create free account
hub / github.com/hashintel/hash / EChart

Function EChart

libs/@hashintel/design-system/src/e-chart.tsx:57–107  ·  view source on GitHub ↗
({
  options,
  sx,
  onChartInitialized,
})

Source from the content-addressed store, hash-verified

55};
56
57export 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};

Callers

nothing calls this directly

Calls 4

resizeMethod · 0.80
observeMethod · 0.80
disconnectMethod · 0.80
initMethod · 0.45

Tested by

no test coverage detected