Skip to content

Commit

Permalink
fix(theme): 修复主题切换后,Geometry 样式未更新的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ authored and hustcc committed Apr 3, 2020
1 parent cf9b2f4 commit 7e75a54
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/chart/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,7 @@ export class View extends Base {
coordinate: this.getCoordinate(), // 使用 coordinate 引用,可以保持 coordinate 的同步更新
scaleDefs: get(this.options, 'scales', {}),
data: this.filteredData,
theme: deepMix({}, this.themeObject, geometry.theme), // 支持 geometry 层级的主题设置
theme: this.themeObject,
isDataChanged: this.isDataChanged,
};
if (isUpdate) {
Expand Down
8 changes: 6 additions & 2 deletions src/geometry/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Adjust, getAdjust as getAdjustClass } from '@antv/adjust';
import { Attribute, getAttribute as getAttributeClass } from '@antv/attr';
import {
clone,
deepMix,
each,
flatten,
get,
Expand Down Expand Up @@ -197,6 +198,8 @@ export default class Geometry extends Base {
/** 存储每个 shape 的默认 size,用于 Interval、Schema 几何标记 */
protected defaultSize: number;

// 用户通过 geometry 构造函数设置的主题
private userTheme: LooseObject;
private adjusts: Record<string, Adjust> = {};
private lastAttributeOption;
private idFields: string[] = [];
Expand Down Expand Up @@ -229,7 +232,7 @@ export default class Geometry extends Base {
this.data = data;
this.sortable = sortable;
this.visible = visible;
this.theme = theme;
this.userTheme = theme;
this.scales = scales;
this.scaleDefs = scaleDefs;
}
Expand Down Expand Up @@ -914,6 +917,7 @@ export default class Geometry extends Base {
this.geometryLabel.destroy();
this.geometryLabel = null;
}
this.theme = undefined;
super.destroy();
}

Expand Down Expand Up @@ -1812,7 +1816,7 @@ export default class Geometry extends Base {
});
}
if (theme) {
this.theme = theme;
this.theme = this.userTheme ? deepMix({}, theme, this.userTheme) : theme; // 支持 geometry 层级的主题设置
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/geometry/util/is-model-change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ import { ShapeInfo } from '../../interface';
* @returns
*/
export function isModelChange(currentModel: ShapeInfo, preModel: ShapeInfo) {
return some(['color', 'shape', 'size', 'x', 'y', 'isInCircle', 'data', 'style', 'points', 'mappingData'], (key: string) => {
return some([
'color',
'shape',
'size',
'x',
'y',
'isInCircle',
'data',
'style',
'defaultStyle',
'points',
'mappingData',
], (key: string) => {
return !isEqual(currentModel[key], preModel[key]);
});
}
4 changes: 3 additions & 1 deletion tests/bugs/2258-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ describe('2258', () => {
expect(chart.getTheme().colors10).toEqual(['#F6BD16', '#E86452']);

chart.theme('dark');
// todo 测试点图需要更新
chart.render(true);

expect(chart.geometries[0].elements[0].shape.attr('fill')).toBe('#000');
});
});

0 comments on commit 7e75a54

Please sign in to comment.