Skip to content

Commit

Permalink
feat: plot 更新判断属性是否有变化
Browse files Browse the repository at this point in the history
  • Loading branch information
Leannechn committed Nov 15, 2021
1 parent 222dc86 commit 2709315
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 199 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bizcharts",
"version": "4.1.14",
"version": "4.1.15-beta.1",
"description": "bizcharts",
"keywords": [
"bizcharts",
Expand Down
2 changes: 1 addition & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ registerEngine('svg', SVGEngine);

// @ts-ignore
export * from '@antv/g2/lib/core';
export const VERSION = '4.1.14';
export const VERSION = '4.1.15-beta.1';



Expand Down
32 changes: 15 additions & 17 deletions src/createPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
polyfillTitleEvent,
polyfillDescriptionEvent,
} from './plots/core/polyfill';
import { debounce, isArray, isFunction, isNil } from '@antv/util';
import { debounce, isArray, isFunction, isNil, isEqual } from '@antv/util';
import warn from 'warning';

// 国际化处理
Expand Down Expand Up @@ -133,33 +133,31 @@ class BasePlot extends React.Component<any> {
}

protected checkInstanceReady() {
// 缓存配置
const currentConfig = pickWithout(this.props, [
...REACT_PIVATE_PROPS,
'container',
'PlotClass',
'onGetG2Instance',
'data',
]);
if (!this.g2Instance) {
this.initInstance();
this.g2Instance.render();
} else if (this.shouldReCreate()) {
// 只有数据更新就不重绘,其他全部直接重新创建实例。
// forceupdate
this.g2Instance.destroy();
this.initInstance();
this.g2Instance.render();
} else if (this.diffConfig()) {
const options = pickWithout(this.props, [
'container',
'PlotClass',
'onGetG2Instance',
'children',
]);
this.g2Instance.update(options);
// 对比options是否更新
if (!isEqual(currentConfig, this.preConfig)) {
this.g2Instance.update(currentConfig);
}
} else if (this.diffData()) {
this.g2Instance.changeData(this.props.data);
}
// 缓存配置
const currentConfig = pickWithout(this.props, [
...REACT_PIVATE_PROPS,
'container',
'PlotClass',
'onGetG2Instance',
'data',
]);

this.preConfig = cloneDeep(currentConfig);
this.g2Instance.data = this.props.data;
}
Expand Down
Loading

0 comments on commit 2709315

Please sign in to comment.