From 602814cc71ae7f5f0356543f0f0d69799ad40e07 Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 17 May 2019 17:14:43 +0800 Subject: [PATCH] :chart: Remove unused resize fns in Pie --- src/components/Charts/Pie/index.js | 111 +++++++++-------------------- 1 file changed, 33 insertions(+), 78 deletions(-) diff --git a/src/components/Charts/Pie/index.js b/src/components/Charts/Pie/index.js index c6370ea3..ae3201f2 100644 --- a/src/components/Charts/Pie/index.js +++ b/src/components/Charts/Pie/index.js @@ -6,7 +6,6 @@ import classNames from 'classnames'; import ReactFitText from 'react-fittext'; import Debounce from 'lodash-decorators/debounce'; import Bind from 'lodash-decorators/bind'; -import ResizeObserver from 'resize-observer-polyfill'; import styles from './index.less'; /* eslint react/no-danger:0 */ @@ -17,17 +16,6 @@ class Pie extends Component { legendBlock: false, }; - componentDidMount() { - window.addEventListener( - 'resize', - () => { - this.requestRef = requestAnimationFrame(() => this.resize()); - }, - { passive: true } - ); - this.resizeObserver(); - } - componentDidUpdate(preProps) { const { data } = this.props; if (data !== preProps.data) { @@ -37,20 +25,10 @@ class Pie extends Component { } } - componentWillUnmount() { - window.cancelAnimationFrame(this.requestRef); - window.removeEventListener('resize', this.resize); - this.resize.cancel(); - if (this.chartDom) { - this.resizeObserverInstance.unobserve(this.chartDom); - } - } - getG2Instance = chart => { this.chart = chart; requestAnimationFrame(() => { this.getLegendData(); - this.resize(); }); }; @@ -96,23 +74,6 @@ class Pie extends Component { }); }; - resizeObserver() { - this.resizeObserverInstance = new ResizeObserver(entries => { - const { height } = entries[0].contentRect; - this.setState(preState => { - if (preState.height !== height) { - return { - height, - }; - } - return null; - }); - }); - if (this.chartDom) { - this.resizeObserverInstance.observe(this.chartDom); - } - } - // for window resize auto responsive legend @Bind() @Debounce(300) @@ -226,45 +187,39 @@ class Pie extends Component { return (
-
{ - this.chartDom = ref; - }} - > - -
- - {!!tooltip && } - - - - - {(subTitle || total) && ( -
- {subTitle &&

{subTitle}

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

{subTitle}

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