|
|
@@ -19,8 +19,6 @@ export default class Pie extends Component {
|
|
|
};
|
|
|
|
|
|
componentDidMount() {
|
|
|
- this.getLegendData();
|
|
|
- this.resize();
|
|
|
window.addEventListener('resize', this.resize);
|
|
|
}
|
|
|
|
|
|
@@ -46,12 +44,17 @@ export default class Pie extends Component {
|
|
|
|
|
|
getG2Instance = chart => {
|
|
|
this.chart = chart;
|
|
|
+ requestAnimationFrame(() => {
|
|
|
+ this.getLegendData();
|
|
|
+ this.resize();
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
// for custom lengend view
|
|
|
getLegendData = () => {
|
|
|
if (!this.chart) return;
|
|
|
const geom = this.chart.getAllGeoms()[0]; // 获取所有的图形
|
|
|
+ if (!geom) return;
|
|
|
const items = geom.get('dataArray') || []; // 获取图形对应的
|
|
|
|
|
|
const legendData = items.map(item => {
|
|
|
@@ -71,22 +74,24 @@ export default class Pie extends Component {
|
|
|
@Bind()
|
|
|
@Debounce(300)
|
|
|
resize() {
|
|
|
- const { hasLegend } = this.props;
|
|
|
- if (!hasLegend || !this.root) {
|
|
|
- window.removeEventListener('resize', this.resize);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (this.root.parentNode.clientWidth <= 380) {
|
|
|
- if (!this.state.legendBlock) {
|
|
|
+ requestAnimationFrame(() => {
|
|
|
+ const { hasLegend } = this.props;
|
|
|
+ if (!hasLegend || !this.root) {
|
|
|
+ window.removeEventListener('resize', this.resize);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this.root.parentNode.clientWidth <= 380) {
|
|
|
+ if (!this.state.legendBlock) {
|
|
|
+ this.setState({
|
|
|
+ legendBlock: true,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else if (this.state.legendBlock) {
|
|
|
this.setState({
|
|
|
- legendBlock: true,
|
|
|
+ legendBlock: false,
|
|
|
});
|
|
|
}
|
|
|
- } else if (this.state.legendBlock) {
|
|
|
- this.setState({
|
|
|
- legendBlock: false,
|
|
|
- });
|
|
|
- }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
handleRoot = n => {
|