ECharts.js 1019 Bytes
Newer Older
1
import React, { memo, useMemo } from 'react';
崔佳豪's avatar
崔佳豪 committed
2 3 4 5 6 7
import { ConfigProvider } from 'antd';
import classNames from 'classnames';
import ReactEcharts from 'echarts-for-react';
import { omit } from 'lodash';
import buildOption from './utils';

8 9 10 11
const ECharts = memo(
  React.forwardRef((props, ref) => {
    const { getPrefixCls } = React.useContext(ConfigProvider.ConfigContext);
    const prefixCls = getPrefixCls('basic-chart');
崔佳豪's avatar
崔佳豪 committed
12

13 14 15 16
    const chartProps = omit(props, ['className', 'option']);
    const option = useMemo(() => {
      return buildOption(props.option);
    }, [props.option]);
崔佳豪's avatar
崔佳豪 committed
17

18
    // const chartProps = pick(props, ['option', 'notMerge', 'lazyUpdate', 'style', 'className', 'theme', 'onChartReady', 'loadingOption', 'showLoading', 'onEvents', 'opts']);
崔佳豪's avatar
崔佳豪 committed
19

20 21 22 23 24
    return (
      <ReactEcharts
        ref={ref}
        className={classNames(prefixCls, props.className)}
        option={option}
程恺文's avatar
程恺文 committed
25
        style={{ width: '100%', height: '100%' }}
26 27 28 29 30
        {...chartProps}
      />
    );
  }),
);
崔佳豪's avatar
崔佳豪 committed
31 32

export default ECharts;