diff --git a/src/chart/view.ts b/src/chart/view.ts index 4117d783af..ce3dcb32ac 100644 --- a/src/chart/view.ts +++ b/src/chart/view.ts @@ -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) { diff --git a/src/geometry/base.ts b/src/geometry/base.ts index 724eaaf840..fda3400721 100644 --- a/src/geometry/base.ts +++ b/src/geometry/base.ts @@ -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, @@ -197,6 +198,8 @@ export default class Geometry extends Base { /** 存储每个 shape 的默认 size,用于 Interval、Schema 几何标记 */ protected defaultSize: number; + // 用户通过 geometry 构造函数设置的主题 + private userTheme: LooseObject; private adjusts: Record = {}; private lastAttributeOption; private idFields: string[] = []; @@ -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; } @@ -914,6 +917,7 @@ export default class Geometry extends Base { this.geometryLabel.destroy(); this.geometryLabel = null; } + this.theme = undefined; super.destroy(); } @@ -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 层级的主题设置 } } diff --git a/src/geometry/util/is-model-change.ts b/src/geometry/util/is-model-change.ts index 0d529f7bfe..ca8ec56409 100644 --- a/src/geometry/util/is-model-change.ts +++ b/src/geometry/util/is-model-change.ts @@ -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]); }); } diff --git a/tests/bugs/2258-spec.ts b/tests/bugs/2258-spec.ts index 4ed4f51218..22051af09d 100644 --- a/tests/bugs/2258-spec.ts +++ b/tests/bugs/2258-spec.ts @@ -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'); }); });