Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复 axis rerender 不更新布局和 labelOffset 报错 #1293

Merged
merged 2 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段逻辑如果去掉的话, 如果多次update 会导致Chart里的layout越来越小

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

具体可以跑下 packages/f2/test/components/interaction/pan.test.tsx 这个用例复现出来

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改好了,这个是update 时 坐标轴没有重置导致的

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