Spaces:
Running
Running
Automatically resize charts. #52
Browse files
lynxkite-app/web/src/workspace/nodes/NodeWithVisualization.tsx
CHANGED
@@ -10,20 +10,28 @@ const NodeWithVisualization = (props: any) => {
|
|
10 |
if (!opts || !chartsRef.current) return;
|
11 |
chartsInstanceRef.current = echarts.init(chartsRef.current, null, {
|
12 |
renderer: "canvas",
|
13 |
-
width:
|
14 |
-
height:
|
15 |
});
|
16 |
chartsInstanceRef.current.setOption(opts);
|
17 |
-
const
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
return () => {
|
20 |
-
|
21 |
chartsInstanceRef.current?.dispose();
|
22 |
};
|
23 |
}, [props.data?.display?.value]);
|
|
|
|
|
24 |
return (
|
25 |
-
<NodeWithParams collapsed {...props}>
|
26 |
-
<div
|
27 |
</NodeWithParams>
|
28 |
);
|
29 |
};
|
|
|
10 |
if (!opts || !chartsRef.current) return;
|
11 |
chartsInstanceRef.current = echarts.init(chartsRef.current, null, {
|
12 |
renderer: "canvas",
|
13 |
+
width: "auto",
|
14 |
+
height: "auto",
|
15 |
});
|
16 |
chartsInstanceRef.current.setOption(opts);
|
17 |
+
const resizeObserver = new ResizeObserver(() => {
|
18 |
+
const e = chartsRef.current!;
|
19 |
+
e.style.padding = "1px";
|
20 |
+
chartsInstanceRef.current?.resize();
|
21 |
+
e.style.padding = "0";
|
22 |
+
});
|
23 |
+
const observed = chartsRef.current;
|
24 |
+
resizeObserver.observe(observed);
|
25 |
return () => {
|
26 |
+
resizeObserver.unobserve(observed);
|
27 |
chartsInstanceRef.current?.dispose();
|
28 |
};
|
29 |
}, [props.data?.display?.value]);
|
30 |
+
const nodeStyle = { display: "flex", flexDirection: "column" };
|
31 |
+
const vizStyle = { flex: 1 };
|
32 |
return (
|
33 |
+
<NodeWithParams nodeStyle={nodeStyle} collapsed {...props}>
|
34 |
+
<div style={vizStyle} ref={chartsRef} />
|
35 |
</NodeWithParams>
|
36 |
);
|
37 |
};
|