Commit c8ea5979 authored by ι™ˆεΈ…'s avatar ι™ˆεΈ…

remove auto width

parent a2cca354
...@@ -12,7 +12,6 @@ import styles from './index.less'; ...@@ -12,7 +12,6 @@ import styles from './index.less';
/* eslint react/no-danger:0 */ /* eslint react/no-danger:0 */
class Pie extends Component { class Pie extends Component {
state = { state = {
width: 0,
height: 0, height: 0,
legendData: [], legendData: [],
legendBlock: false, legendBlock: false,
...@@ -96,19 +95,18 @@ class Pie extends Component { ...@@ -96,19 +95,18 @@ class Pie extends Component {
resizeObserver() { resizeObserver() {
const ro = new ResizeObserver(entries => { const ro = new ResizeObserver(entries => {
const { width, height } = entries[0].contentRect; const { height } = entries[0].contentRect;
this.setState((preState, { hasLegend }) => { this.setState(preState => {
if (preState.width !== width || preState.height !== height) { if (preState.height !== height) {
return { return {
width: width - (hasLegend ? 240 : 0),
height, height,
}; };
} }
return null; return null;
}); });
}); });
if (this.root) { if (this.chartDom) {
ro.observe(this.root); ro.observe(this.chartDom);
} }
} }
...@@ -152,7 +150,7 @@ class Pie extends Component { ...@@ -152,7 +150,7 @@ class Pie extends Component {
lineWidth = 1, lineWidth = 1,
} = this.props; } = this.props;
const { legendData, height: StateHeight, width, legendBlock } = this.state; const { legendData, height: stateHeight, 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,
...@@ -225,40 +223,45 @@ class Pie extends Component { ...@@ -225,40 +223,45 @@ class Pie extends Component {
return ( return (
<div ref={this.handleRoot} className={pieClassName} style={style}> <div ref={this.handleRoot} className={pieClassName} style={style}>
<ReactFitText maxFontSize={25}> <div
<div className={styles.chart}> ref={ref => {
<Chart this.chartDom = ref;
scale={scale} }}
height={height || StateHeight} >
data={dv} <ReactFitText maxFontSize={25}>
width={width} <div className={styles.chart}>
padding={padding} <Chart
animate={animate} scale={scale}
onGetG2Instance={this.getG2Instance} height={height || stateHeight}
> data={dv}
{!!tooltip && <Tooltip showTitle={false} />} padding={padding}
<Coord type="theta" innerRadius={inner} /> animate={animate}
<Geom onGetG2Instance={this.getG2Instance}
style={{ lineWidth, stroke: '#fff' }} >
tooltip={tooltip && tooltipFormat} {!!tooltip && <Tooltip showTitle={false} />}
type="intervalStack" <Coord type="theta" innerRadius={inner} />
position="percent" <Geom
color={['x', percent || percent === 0 ? formatColor : defaultColors]} style={{ lineWidth, stroke: '#fff' }}
selected={selected} tooltip={tooltip && tooltipFormat}
/> type="intervalStack"
</Chart> position="percent"
color={['x', percent || percent === 0 ? formatColor : defaultColors]}
selected={selected}
/>
</Chart>
{(subTitle || total) && ( {(subTitle || total) && (
<div className={styles.total}> <div className={styles.total}>
{subTitle && <h4 className="pie-sub-title">{subTitle}</h4>} {subTitle && <h4 className="pie-sub-title">{subTitle}</h4>}
{/* eslint-disable-next-line */} {/* eslint-disable-next-line */}
{total && ( {total && (
<div className="pie-stat">{typeof total === 'function' ? total() : total}</div> <div className="pie-stat">{typeof total === 'function' ? total() : total}</div>
)} )}
</div> </div>
)} )}
</div> </div>
</ReactFitText> </ReactFitText>
</div>
{hasLegend && ( {hasLegend && (
<ul className={styles.legend}> <ul className={styles.legend}>
{legendData.map((item, i) => ( {legendData.map((item, i) => (
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment