File size: 1,059 Bytes
d1d859f
 
d7ccb5f
d1d859f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import React, { useEffect } from 'react';
import NodeWithParams from './NodeWithParams';
const echarts = await import('echarts');

const NodeWithVisualization = (props: any) => {
  const chartsRef = React.useRef<HTMLDivElement>(null);
  const chartsInstanceRef = React.useRef<echarts.ECharts>();
  useEffect(() => {
    const opts = props.data?.display?.value;
    if (!opts || !chartsRef.current) return;
    console.log(chartsRef.current);
    chartsInstanceRef.current = echarts.init(chartsRef.current, null, { renderer: 'canvas', width: 250, height: 250 });
    chartsInstanceRef.current.setOption(opts);
    const onResize = () => chartsInstanceRef.current?.resize();
    window.addEventListener('resize', onResize);
    return () => {
      window.removeEventListener('resize', onResize);
      chartsInstanceRef.current?.dispose();
    };
  }, [props.data?.display?.value]);
  return (
    <NodeWithParams {...props}>
      <div className="box" draggable={false} ref={chartsRef} />;
    </NodeWithParams>
  );
};

export default NodeWithVisualization;