Skip to content

Commit

Permalink
fix: 修复 rerender 坐标轴不更新
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue committed Nov 29, 2021
1 parent fddc32b commit 36d6a03
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
25 changes: 6 additions & 19 deletions packages/f2/src/components/axis/withAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type BBox = {
export default (View) => {
return class Axis extends Component<AxisProps> {
style: Style = {};
maxBBox: BBox;

constructor(props: AxisProps) {
super(props);
Expand Down Expand Up @@ -67,7 +66,7 @@ export default (View) => {
}
// 获取ticks最大的宽高
getMaxBBox(ticks, style: Style): BBox {
const { context, maxBBox } = this;
const { context } = this;
const { measureText } = context;
const { labelOffset } = style;

Expand All @@ -80,20 +79,10 @@ export default (View) => {
height = Math.max(height, bbox.height);
});

let bbox = {
const bbox = {
width: width + labelOffset,
height: height + labelOffset,
};

// 增量更新,以最大的宽高作为限制
if (maxBBox) {
bbox = {
height: Math.max(0, maxBBox.height - bbox.height),
width: Math.max(0, maxBBox.width - bbox.width),
};
}

this.maxBBox = bbox;
return bbox;
}

Expand Down Expand Up @@ -132,14 +121,12 @@ export default (View) => {
if (style[key] === null) {
return;
}
const styleValue = isFunction(style[key]) ? undefined : style[key]
const styleValue = isFunction(style[key]) ? undefined : style[key];

if (isString(value) || isNumber(value)) {
this.style[key] = px2hd(styleValue) || value;
} else {
this.style[key] = px2hd(
deepMix(clone(value), styleValue)
);
this.style[key] = px2hd(deepMix(clone(value), styleValue));
}
});

Expand Down Expand Up @@ -182,8 +169,8 @@ export default (View) => {

// 主要是计算coord的布局
updateCoord() {
const { props, context } = this;
const { visible, style, chart, coord } = props;
const { props } = this;
const { visible, chart, coord } = props;
if (visible === false) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions packages/f2/test/components/axis/axis.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ describe('Axis 轴', () => {
}
return cfg;
},
labelOffset: '8px',
}}
/>
<Line x="index" y="value" color="#2FC25B" />
Expand Down

0 comments on commit 36d6a03

Please sign in to comment.