|
|
@ -6,14 +6,14 @@ 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 autoHeight from '../autoHeight'; |
|
|
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 */ |
|
|
@autoHeight() |
|
|
|
|
|
class Pie extends Component { |
|
|
class Pie extends Component { |
|
|
state = { |
|
|
state = { |
|
|
|
|
|
width: 0, |
|
|
|
|
|
height: 0, |
|
|
legendData: [], |
|
|
legendData: [], |
|
|
legendBlock: false, |
|
|
legendBlock: false, |
|
|
}; |
|
|
}; |
|
|
@ -26,6 +26,7 @@ class Pie extends Component { |
|
|
}, |
|
|
}, |
|
|
{ passive: true } |
|
|
{ passive: true } |
|
|
); |
|
|
); |
|
|
|
|
|
this.resizeObserver(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
componentDidUpdate(preProps) { |
|
|
componentDidUpdate(preProps) { |
|
|
@ -93,6 +94,24 @@ 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) { |
|
|
|
|
|
return { |
|
|
|
|
|
width: width - (hasLegend ? 240 : 0), |
|
|
|
|
|
height, |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
if (this.root) { |
|
|
|
|
|
ro.observe(this.root); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// for window resize auto responsive legend
|
|
|
// for window resize auto responsive legend
|
|
|
@Bind() |
|
|
@Bind() |
|
|
@Debounce(300) |
|
|
@Debounce(300) |
|
|
@ -125,7 +144,6 @@ class Pie extends Component { |
|
|
className, |
|
|
className, |
|
|
style, |
|
|
style, |
|
|
height, |
|
|
height, |
|
|
forceFit = true, |
|
|
|
|
|
percent, |
|
|
percent, |
|
|
color, |
|
|
color, |
|
|
inner = 0.75, |
|
|
inner = 0.75, |
|
|
@ -134,7 +152,7 @@ class Pie extends Component { |
|
|
lineWidth = 1, |
|
|
lineWidth = 1, |
|
|
} = this.props; |
|
|
} = this.props; |
|
|
|
|
|
|
|
|
const { legendData, legendBlock } = this.state; |
|
|
const { legendData, height: StateHeight, width, legendBlock } = this.state; |
|
|
const pieClassName = classNames(styles.pie, className, { |
|
|
const pieClassName = classNames(styles.pie, className, { |
|
|
[styles.hasLegend]: !!hasLegend, |
|
|
[styles.hasLegend]: !!hasLegend, |
|
|
[styles.legendBlock]: legendBlock, |
|
|
[styles.legendBlock]: legendBlock, |
|
|
@ -211,9 +229,9 @@ class Pie extends Component { |
|
|
<div className={styles.chart}> |
|
|
<div className={styles.chart}> |
|
|
<Chart |
|
|
<Chart |
|
|
scale={scale} |
|
|
scale={scale} |
|
|
height={height} |
|
|
height={height || StateHeight} |
|
|
forceFit={forceFit} |
|
|
|
|
|
data={dv} |
|
|
data={dv} |
|
|
|
|
|
width={width} |
|
|
padding={padding} |
|
|
padding={padding} |
|
|
animate={animate} |
|
|
animate={animate} |
|
|
onGetG2Instance={this.getG2Instance} |
|
|
onGetG2Instance={this.getG2Instance} |
|
|
@ -241,7 +259,6 @@ class Pie extends Component { |
|
|
)} |
|
|
)} |
|
|
</div> |
|
|
</div> |
|
|
</ReactFitText> |
|
|
</ReactFitText> |
|
|
|
|
|
|
|
|
{hasLegend && ( |
|
|
{hasLegend && ( |
|
|
<ul className={styles.legend}> |
|
|
<ul className={styles.legend}> |
|
|
{legendData.map((item, i) => ( |
|
|
{legendData.map((item, i) => ( |
|
|
|