diff --git a/src/components/Charts/Pie/index.js b/src/components/Charts/Pie/index.js index acd34231..5f80d747 100644 --- a/src/components/Charts/Pie/index.js +++ b/src/components/Charts/Pie/index.js @@ -12,7 +12,6 @@ import styles from './index.less'; /* eslint react/no-danger:0 */ class Pie extends Component { state = { - width: 0, height: 0, legendData: [], legendBlock: false, @@ -96,19 +95,18 @@ class Pie extends Component { resizeObserver() { const ro = new ResizeObserver(entries => { - const { width, height } = entries[0].contentRect; - this.setState((preState, { hasLegend }) => { - if (preState.width !== width || preState.height !== height) { + const { height } = entries[0].contentRect; + this.setState(preState => { + if (preState.height !== height) { return { - width: width - (hasLegend ? 240 : 0), height, }; } return null; }); }); - if (this.root) { - ro.observe(this.root); + if (this.chartDom) { + ro.observe(this.chartDom); } } @@ -152,7 +150,7 @@ class Pie extends Component { lineWidth = 1, } = this.props; - const { legendData, height: StateHeight, width, legendBlock } = this.state; + const { legendData, height: stateHeight, legendBlock } = this.state; const pieClassName = classNames(styles.pie, className, { [styles.hasLegend]: !!hasLegend, [styles.legendBlock]: legendBlock, @@ -225,40 +223,45 @@ class Pie extends Component { return (
- -
- - {!!tooltip && } - - - +
{ + this.chartDom = ref; + }} + > + +
+ + {!!tooltip && } + + + - {(subTitle || total) && ( -
- {subTitle &&

{subTitle}

} - {/* eslint-disable-next-line */} - {total && ( -
{typeof total === 'function' ? total() : total}
- )} -
- )} -
-
+ {(subTitle || total) && ( +
+ {subTitle &&

{subTitle}

} + {/* eslint-disable-next-line */} + {total && ( +
{typeof total === 'function' ? total() : total}
+ )} +
+ )} +
+ +
{hasLegend && (