|
@@ -6,7 +6,6 @@ import classNames from 'classnames';
|
|
|
import ReactFitText from 'react-fittext';
|
|
import ReactFitText from 'react-fittext';
|
|
|
import Debounce from 'lodash-decorators/debounce';
|
|
import Debounce from 'lodash-decorators/debounce';
|
|
|
import Bind from 'lodash-decorators/bind';
|
|
import Bind from 'lodash-decorators/bind';
|
|
|
-import ResizeObserver from 'resize-observer-polyfill';
|
|
|
|
|
import styles from './index.less';
|
|
import styles from './index.less';
|
|
|
|
|
|
|
|
/* eslint react/no-danger:0 */
|
|
/* eslint react/no-danger:0 */
|
|
@@ -17,17 +16,6 @@ class Pie extends Component {
|
|
|
legendBlock: false,
|
|
legendBlock: false,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- componentDidMount() {
|
|
|
|
|
- window.addEventListener(
|
|
|
|
|
- 'resize',
|
|
|
|
|
- () => {
|
|
|
|
|
- this.requestRef = requestAnimationFrame(() => this.resize());
|
|
|
|
|
- },
|
|
|
|
|
- { passive: true }
|
|
|
|
|
- );
|
|
|
|
|
- this.resizeObserver();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
componentDidUpdate(preProps) {
|
|
componentDidUpdate(preProps) {
|
|
|
const { data } = this.props;
|
|
const { data } = this.props;
|
|
|
if (data !== preProps.data) {
|
|
if (data !== preProps.data) {
|
|
@@ -37,17 +25,10 @@ class Pie extends Component {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- componentWillUnmount() {
|
|
|
|
|
- window.cancelAnimationFrame(this.requestRef);
|
|
|
|
|
- window.removeEventListener('resize', this.resize);
|
|
|
|
|
- this.resize.cancel();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
getG2Instance = chart => {
|
|
getG2Instance = chart => {
|
|
|
this.chart = chart;
|
|
this.chart = chart;
|
|
|
requestAnimationFrame(() => {
|
|
requestAnimationFrame(() => {
|
|
|
this.getLegendData();
|
|
this.getLegendData();
|
|
|
- this.resize();
|
|
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -93,23 +74,6 @@ class Pie extends Component {
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- resizeObserver() {
|
|
|
|
|
- const ro = new ResizeObserver(entries => {
|
|
|
|
|
- const { height } = entries[0].contentRect;
|
|
|
|
|
- this.setState(preState => {
|
|
|
|
|
- if (preState.height !== height) {
|
|
|
|
|
- return {
|
|
|
|
|
- height,
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
- return null;
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
- if (this.chartDom) {
|
|
|
|
|
- ro.observe(this.chartDom);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// for window resize auto responsive legend
|
|
// for window resize auto responsive legend
|
|
|
@Bind()
|
|
@Bind()
|
|
|
@Debounce(300)
|
|
@Debounce(300)
|
|
@@ -223,45 +187,39 @@ class Pie extends Component {
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div ref={this.handleRoot} className={pieClassName} style={style}>
|
|
<div ref={this.handleRoot} className={pieClassName} style={style}>
|
|
|
- <div
|
|
|
|
|
- ref={ref => {
|
|
|
|
|
- this.chartDom = ref;
|
|
|
|
|
- }}
|
|
|
|
|
- >
|
|
|
|
|
- <ReactFitText maxFontSize={25}>
|
|
|
|
|
- <div className={styles.chart}>
|
|
|
|
|
- <Chart
|
|
|
|
|
- scale={scale}
|
|
|
|
|
- height={height || stateHeight}
|
|
|
|
|
- data={dv}
|
|
|
|
|
- padding={padding}
|
|
|
|
|
- animate={animate}
|
|
|
|
|
- onGetG2Instance={this.getG2Instance}
|
|
|
|
|
- >
|
|
|
|
|
- {!!tooltip && <Tooltip showTitle={false} />}
|
|
|
|
|
- <Coord type="theta" innerRadius={inner} />
|
|
|
|
|
- <Geom
|
|
|
|
|
- style={{ lineWidth, stroke: '#fff' }}
|
|
|
|
|
- tooltip={tooltip && tooltipFormat}
|
|
|
|
|
- type="intervalStack"
|
|
|
|
|
- position="percent"
|
|
|
|
|
- color={['x', percent || percent === 0 ? formatColor : defaultColors]}
|
|
|
|
|
- selected={selected}
|
|
|
|
|
- />
|
|
|
|
|
- </Chart>
|
|
|
|
|
-
|
|
|
|
|
- {(subTitle || total) && (
|
|
|
|
|
- <div className={styles.total}>
|
|
|
|
|
- {subTitle && <h4 className="pie-sub-title">{subTitle}</h4>}
|
|
|
|
|
- {/* eslint-disable-next-line */}
|
|
|
|
|
- {total && (
|
|
|
|
|
- <div className="pie-stat">{typeof total === 'function' ? total() : total}</div>
|
|
|
|
|
- )}
|
|
|
|
|
- </div>
|
|
|
|
|
- )}
|
|
|
|
|
- </div>
|
|
|
|
|
- </ReactFitText>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <ReactFitText maxFontSize={25}>
|
|
|
|
|
+ <div className={styles.chart}>
|
|
|
|
|
+ <Chart
|
|
|
|
|
+ scale={scale}
|
|
|
|
|
+ height={height || stateHeight}
|
|
|
|
|
+ data={dv}
|
|
|
|
|
+ padding={padding}
|
|
|
|
|
+ animate={animate}
|
|
|
|
|
+ onGetG2Instance={this.getG2Instance}
|
|
|
|
|
+ >
|
|
|
|
|
+ {!!tooltip && <Tooltip showTitle={false} />}
|
|
|
|
|
+ <Coord type="theta" innerRadius={inner} />
|
|
|
|
|
+ <Geom
|
|
|
|
|
+ style={{ lineWidth, stroke: '#fff' }}
|
|
|
|
|
+ tooltip={tooltip && tooltipFormat}
|
|
|
|
|
+ type="intervalStack"
|
|
|
|
|
+ position="percent"
|
|
|
|
|
+ color={['x', percent || percent === 0 ? formatColor : defaultColors]}
|
|
|
|
|
+ selected={selected}
|
|
|
|
|
+ />
|
|
|
|
|
+ </Chart>
|
|
|
|
|
+
|
|
|
|
|
+ {(subTitle || total) && (
|
|
|
|
|
+ <div className={styles.total}>
|
|
|
|
|
+ {subTitle && <h4 className="pie-sub-title">{subTitle}</h4>}
|
|
|
|
|
+ {/* eslint-disable-next-line */}
|
|
|
|
|
+ {total && (
|
|
|
|
|
+ <div className="pie-stat">{typeof total === 'function' ? total() : total}</div>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </ReactFitText>
|
|
|
{hasLegend && (
|
|
{hasLegend && (
|
|
|
<ul className={styles.legend}>
|
|
<ul className={styles.legend}>
|
|
|
{legendData.map((item, i) => (
|
|
{legendData.map((item, i) => (
|