From addc471d3c9fefb5d2815d487fce09a6cefff820 Mon Sep 17 00:00:00 2001 From: xile611 Date: Tue, 24 Dec 2024 11:37:01 +0800 Subject: [PATCH 1/6] perf: base-chart should not create spec transformer --- .../vchart/__tests__/unit/chart/bar.test.ts | 2 +- .../__tests__/unit/chart/histogram.test.ts | 2 +- .../vchart/__tests__/unit/chart/line.test.ts | 4 +- .../unit/chart/linearProgress.test.ts | 2 +- .../__tests__/unit/chart/rangeColumn.test.ts | 2 +- .../__tests__/unit/chart/treemap.test.ts | 2 +- .../__tests__/unit/chart/word-cloud.test.ts | 2 +- .../vchart/__tests__/unit/data/fields.test.ts | 4 +- .../vchart/__tests__/unit/morph/morph.test.ts | 6 +-- .../__tests__/unit/scale/global-scale.test.ts | 4 +- .../src/chart/base/base-chart-transformer.ts | 49 +++++++++---------- packages/vchart/src/chart/base/base-chart.ts | 18 +++---- packages/vchart/src/chart/interface/chart.ts | 4 +- packages/vchart/src/core/vchart.ts | 42 ++++++++-------- 14 files changed, 67 insertions(+), 76 deletions(-) diff --git a/packages/vchart/__tests__/unit/chart/bar.test.ts b/packages/vchart/__tests__/unit/chart/bar.test.ts index 9f59f83cb8..b90c76e915 100644 --- a/packages/vchart/__tests__/unit/chart/bar.test.ts +++ b/packages/vchart/__tests__/unit/chart/bar.test.ts @@ -117,7 +117,7 @@ describe('Bar chart test', () => { getSpecInfo: () => info } as any ); - chart.created(); + chart.created(transformer); chart.init(); // spec diff --git a/packages/vchart/__tests__/unit/chart/histogram.test.ts b/packages/vchart/__tests__/unit/chart/histogram.test.ts index 13dcdaff29..70a48cb7c8 100644 --- a/packages/vchart/__tests__/unit/chart/histogram.test.ts +++ b/packages/vchart/__tests__/unit/chart/histogram.test.ts @@ -75,7 +75,7 @@ describe('histogram chart test', () => { getSpecInfo: () => info } as any ); - chart.created(); + chart.created(transformer); chart.init(); // spec diff --git a/packages/vchart/__tests__/unit/chart/line.test.ts b/packages/vchart/__tests__/unit/chart/line.test.ts index b98650eeb0..1dcde0d18a 100644 --- a/packages/vchart/__tests__/unit/chart/line.test.ts +++ b/packages/vchart/__tests__/unit/chart/line.test.ts @@ -60,7 +60,7 @@ describe('line chart test', () => { getSpecInfo: () => info } as any ); - chart.created(); + chart.created(transformer); chart.init(); // spec @@ -125,7 +125,7 @@ describe('line chart test', () => { getTheme: () => ThemeManager.getCurrentTheme(true), getSpecInfo: () => info } as any); - chart.created(); + chart.created(transformer); chart.init(); // spec diff --git a/packages/vchart/__tests__/unit/chart/linearProgress.test.ts b/packages/vchart/__tests__/unit/chart/linearProgress.test.ts index c207753aa3..38fce1eb37 100644 --- a/packages/vchart/__tests__/unit/chart/linearProgress.test.ts +++ b/packages/vchart/__tests__/unit/chart/linearProgress.test.ts @@ -64,7 +64,7 @@ describe('linearProgress chart test', () => { getSpecInfo: () => info } as any ); - chart.created(); + chart.created(transformer); chart.init(); // spec diff --git a/packages/vchart/__tests__/unit/chart/rangeColumn.test.ts b/packages/vchart/__tests__/unit/chart/rangeColumn.test.ts index 303d756adf..82a59d1751 100644 --- a/packages/vchart/__tests__/unit/chart/rangeColumn.test.ts +++ b/packages/vchart/__tests__/unit/chart/rangeColumn.test.ts @@ -77,7 +77,7 @@ describe('rangeColumn chart test', () => { getSpecInfo: () => info } as any ); - chart.created(); + chart.created(transformer); chart.init(); // spec diff --git a/packages/vchart/__tests__/unit/chart/treemap.test.ts b/packages/vchart/__tests__/unit/chart/treemap.test.ts index fab11d74b9..4de64e7871 100644 --- a/packages/vchart/__tests__/unit/chart/treemap.test.ts +++ b/packages/vchart/__tests__/unit/chart/treemap.test.ts @@ -80,7 +80,7 @@ describe('treemap chart test', () => { getSpecInfo: () => info } as any ); - chart.created(); + chart.created(transformer); chart.init(); const series: TreemapSeries = chart.getAllSeries()[0] as TreemapSeries; diff --git a/packages/vchart/__tests__/unit/chart/word-cloud.test.ts b/packages/vchart/__tests__/unit/chart/word-cloud.test.ts index 29b2277b70..37cef8aabe 100644 --- a/packages/vchart/__tests__/unit/chart/word-cloud.test.ts +++ b/packages/vchart/__tests__/unit/chart/word-cloud.test.ts @@ -84,7 +84,7 @@ describe('wordCloud chart test', () => { getTheme: () => ThemeManager.getCurrentTheme(true), getSpecInfo: () => info } as any); - chart.created(); + chart.created(transformer); chart.init(); // spec diff --git a/packages/vchart/__tests__/unit/data/fields.test.ts b/packages/vchart/__tests__/unit/data/fields.test.ts index c8ffa9357b..ad3261ce5f 100644 --- a/packages/vchart/__tests__/unit/data/fields.test.ts +++ b/packages/vchart/__tests__/unit/data/fields.test.ts @@ -78,7 +78,7 @@ describe('data fields test', () => { getTheme: () => ThemeManager.getCurrentTheme(true), getSpecInfo: () => info } as any); - chart.created(); + chart.created(transformer); chart.init(); const lastData = chart.getAllSeries()[0].getRawData()?.latestData; @@ -159,7 +159,7 @@ describe('data fields test', () => { getTheme: () => ThemeManager.getCurrentTheme(true), getSpecInfo: () => info } as any); - chart.created(); + chart.created(transformer); chart.init(); const lastData = chart.getAllSeries()[0].getRawData()?.latestData; diff --git a/packages/vchart/__tests__/unit/morph/morph.test.ts b/packages/vchart/__tests__/unit/morph/morph.test.ts index efc37b497a..289d78482f 100644 --- a/packages/vchart/__tests__/unit/morph/morph.test.ts +++ b/packages/vchart/__tests__/unit/morph/morph.test.ts @@ -139,7 +139,7 @@ describe('Bar chart test', () => { getSpecInfo: () => info } as any ); - scatterChart.created(); + scatterChart.created(transformer); scatterChart.init(); const barTransformer = new BarChart.transformerConstructor({ @@ -171,7 +171,7 @@ describe('Bar chart test', () => { getSpecInfo: () => barInfo } as any ); - barChart.created(); + barChart.created(barTransformer); barChart.init(); const barSeries = barChart.getAllSeries()[0]; @@ -216,7 +216,7 @@ describe('Bar chart test', () => { getSpecInfo: () => info } as any ); - scatterChart.created(); + scatterChart.created(transformer); scatterChart.init(); const ASeries = scatterChart.getAllSeries()[0]; diff --git a/packages/vchart/__tests__/unit/scale/global-scale.test.ts b/packages/vchart/__tests__/unit/scale/global-scale.test.ts index 4e1735a32d..aeeeb669ef 100644 --- a/packages/vchart/__tests__/unit/scale/global-scale.test.ts +++ b/packages/vchart/__tests__/unit/scale/global-scale.test.ts @@ -314,7 +314,7 @@ describe('global-scale test', () => { getTheme: () => ThemeManager.getCurrentTheme(true) } as any ); - chart.created(); + chart.created(transformer); chart.init(); // spec @@ -464,7 +464,7 @@ describe('global-scale test', () => { getTheme: () => ThemeManager.getCurrentTheme(true) } as any ); - chart.created(); + chart.created(transformer); chart.init(); // spec diff --git a/packages/vchart/src/chart/base/base-chart-transformer.ts b/packages/vchart/src/chart/base/base-chart-transformer.ts index 8c87dbb942..ecf15e0409 100644 --- a/packages/vchart/src/chart/base/base-chart-transformer.ts +++ b/packages/vchart/src/chart/base/base-chart-transformer.ts @@ -57,13 +57,8 @@ export class BaseChartSpecTransformer implements IChartSpe } } - /** - * 转换 model spec。包含以下步骤: - * - model 层级的主题合并 - * - model 层级的在初始化阶段的 spec 修改,如添加 label spec - */ - transformModelSpec(chartSpec: T): IChartSpecInfo { - const transform = (constructor: IModelConstructor, specInfo: IModelSpecInfo, chartSpecInfo?: IChartSpecInfo) => { + generateTransform(chartSpec: T, isRuntime?: boolean) { + return (constructor: IModelConstructor, specInfo: IModelSpecInfo, chartSpecInfo?: IChartSpecInfo) => { const { spec, specPath, specInfoPath, type } = specInfo; const transformer = new constructor.transformerConstructor({ ...this._option, @@ -71,13 +66,26 @@ export class BaseChartSpecTransformer implements IChartSpe }); // 调用 model 自己的 transformer 进行转换 const transformResult = transformer.transformSpec(spec, chartSpec, chartSpecInfo); - setProperty(chartSpec, specPath, transformResult.spec); - setProperty(chartSpecInfo, specInfoPath ?? specPath, { + const chartSpecInfoValue = { ...specInfo, ...transformResult - }); + }; + if (isRuntime) { + chartSpecInfoValue.theme = transformer.getTheme(spec, chartSpec); + } else { + setProperty(chartSpec, specPath, transformResult.spec); + } + setProperty(chartSpecInfo, specInfoPath ?? specPath, chartSpecInfoValue); }; - return this.createSpecInfo(chartSpec, transform); + } + + /** + * 转换 model spec。包含以下步骤: + * - model 层级的主题合并 + * - model 层级的在初始化阶段的 spec 修改,如添加 label spec + */ + transformModelSpec(chartSpec: T): IChartSpecInfo { + return this.createSpecInfo(chartSpec, this.generateTransform(chartSpec, false)); } /** 遍历图表 spec 中包含的所有的 model,进行 spec 转换并生成图表 spec info */ @@ -93,20 +101,7 @@ export class BaseChartSpecTransformer implements IChartSpe ) => void ): IChartSpecInfo { if (!transform) { - transform = (constructor: IModelConstructor, specInfo: IModelSpecInfo, chartSpecInfo?: IChartSpecInfo) => { - const { spec, specPath, specInfoPath, type } = specInfo; - const transformer = new constructor.transformerConstructor({ - ...this._option, - type - }); - const transformResult = transformer.transformSpec(spec, chartSpec, chartSpecInfo); - - setProperty(chartSpecInfo, specInfoPath ?? specPath, { - ...specInfo, - ...transformResult, - theme: transformer.getTheme(spec, chartSpec) - }); - }; + transform = this.generateTransform(chartSpec, true); } const currentChartSpecInfo: IChartSpecInfo = {}; @@ -271,7 +266,7 @@ export class BaseChartSpecTransformer implements IChartSpe polarAxis = cmp; } else if (cmp.type === ComponentTypeEnum.geoCoordinate) { geoCoordinate = cmp; - } else if (alwaysCheck || chartSpec[cmp.specKey ?? cmp.type]) { + } else if (alwaysCheck || (chartSpec as any)[cmp.specKey ?? cmp.type]) { if (cmp.type === ComponentTypeEnum.tooltip) { tooltip = cmp; } else { @@ -340,7 +335,7 @@ export class BaseChartSpecTransformer implements IChartSpe } Object.keys(defaultSeriesSpec).forEach(k => { if (!(k in s)) { - s[k] = defaultSeriesSpec[k]; + (s as any)[k] = defaultSeriesSpec[k]; } }); }); diff --git a/packages/vchart/src/chart/base/base-chart.ts b/packages/vchart/src/chart/base/base-chart.ts index bd7c1a77e4..a75679138d 100644 --- a/packages/vchart/src/chart/base/base-chart.ts +++ b/packages/vchart/src/chart/base/base-chart.ts @@ -52,7 +52,7 @@ import { BaseMark } from '../../mark/base/base-mark'; import { DEFAULT_CHART_WIDTH, DEFAULT_CHART_HEIGHT } from '../../constant/base'; // eslint-disable-next-line no-duplicate-imports import type { IParserOptions } from '@visactor/vdataset'; -import type { IBoundsLike } from '@visactor/vutils'; +import type { IBoundsLike, Maybe } from '@visactor/vutils'; // eslint-disable-next-line no-duplicate-imports import { isFunction, isEmpty, isNil, isString, isEqual, pickWithout } from '@visactor/vutils'; import { getDataScheme } from '../../theme/color-scheme/util'; @@ -77,8 +77,6 @@ export class BaseChart extends CompilableBase implements I readonly id: number = createID(); - protected _transformer: IChartSpecTransformer; - //FIXME: 转换后的 spec 需要声明 ITransformedChartSpec protected _spec: T; getSpec() { @@ -203,12 +201,7 @@ export class BaseChart extends CompilableBase implements I this._spec = spec; } - created() { - this._transformer = new this.transformerConstructor({ - ...this._option, - type: this.type, - seriesType: this.seriesType - }); + created(transformer: Maybe) { // data this._chartData.parseData(this._spec.data); // scale @@ -219,11 +212,12 @@ export class BaseChart extends CompilableBase implements I this._createLayout(); // 基于spec 创建元素。 // region - this._transformer.forEachRegionInSpec(this._spec, this._createRegion.bind(this)); + debugger; + transformer.forEachRegionInSpec(this._spec, this._createRegion.bind(this)); // series - this._transformer.forEachSeriesInSpec(this._spec, this._createSeries.bind(this)); + transformer.forEachSeriesInSpec(this._spec, this._createSeries.bind(this)); // components - this._transformer.forEachComponentInSpec(this._spec, this._createComponent.bind(this), this._option.getSpecInfo()); + transformer.forEachComponentInSpec(this._spec, this._createComponent.bind(this), this._option.getSpecInfo()); } init() { diff --git a/packages/vchart/src/chart/interface/chart.ts b/packages/vchart/src/chart/interface/chart.ts index 88213ef32f..718fed8b45 100644 --- a/packages/vchart/src/chart/interface/chart.ts +++ b/packages/vchart/src/chart/interface/chart.ts @@ -16,7 +16,7 @@ import type { IChartSpecTransformerOption, ILayoutParams } from './common'; -import type { IBoundsLike, IPadding } from '@visactor/vutils'; +import type { IBoundsLike, IPadding, Maybe } from '@visactor/vutils'; import type { ICompilable } from '../../compile/interface'; import type { IRegionQuerier, @@ -87,7 +87,7 @@ export interface IChart extends ICompilable { // update scale domain which in GlobalScale updateGlobalScaleDomain: () => void; //生命周期 - created: () => void; + created: (transformer: Maybe) => void; init: () => void; onLayoutStart: (ctx: IChartLayoutOption) => void; onLayoutEnd: (ctx: IChartLayoutOption) => void; diff --git a/packages/vchart/src/core/vchart.ts b/packages/vchart/src/core/vchart.ts index 161e034fda..0c1df16f67 100644 --- a/packages/vchart/src/core/vchart.ts +++ b/packages/vchart/src/core/vchart.ts @@ -524,7 +524,7 @@ export class VChart implements IVChart { } this._chart = chart; this._chart.setCanvasRect(this._currentSize.width, this._currentSize.height); - this._chart.created(); + this._chart.created(this._chartSpecTransformer); this._chart.init(); this._event.emit(ChartEvent.initialized, { chart, @@ -547,13 +547,15 @@ export class VChart implements IVChart { if (!this._compiler) { return; } - this._compiler.getVGrammarView().addEventListener(VGRAMMAR_HOOK_EVENT.ALL_ANIMATION_END, () => { + const view = this._compiler.getVGrammarView(); + + view.addEventListener(VGRAMMAR_HOOK_EVENT.ALL_ANIMATION_END, () => { this._event.emit(ChartEvent.animationFinished, { chart: this._chart, vchart: this }); }); - this._compiler.getVGrammarView().addEventListener(VGRAMMAR_HOOK_EVENT.AFTER_VRENDER_NEXT_RENDER, () => { + view.addEventListener(VGRAMMAR_HOOK_EVENT.AFTER_VRENDER_NEXT_RENDER, () => { this._event.emit(ChartEvent.renderFinished, { chart: this._chart, vchart: this @@ -668,17 +670,24 @@ export class VChart implements IVChart { if (updateResult.reMake) { this._releaseData(); this._initDataSet(); - // 释放图表等等 - this._chartSpecTransformer = null; this._chart?.release(); this._chart = null as unknown as IChart; - // 卸载了chart之后再设置主题 避免多余的reInit - if (updateResult.changeTheme) { - this._setCurrentTheme(); - this._setFontFamilyTheme(this._currentTheme?.fontFamily as string); - } else if (updateResult.changeBackground) { - this._compiler?.setBackground(this._getBackground()); - } + } + + if (updateResult.reTransformSpec) { + // 释放图表等等 + this._chartSpecTransformer = null; + } + + // 卸载了chart之后再设置主题 避免多余的reInit + if (updateResult.changeTheme) { + this._setCurrentTheme(); + this._setFontFamilyTheme(this._currentTheme?.fontFamily as string); + } else if (updateResult.changeBackground) { + this._compiler?.setBackground(this._getBackground()); + } + + if (updateResult.reMake) { // 如果不需要动画,那么释放item,避免元素残留 this._compiler?.releaseGrammar(this._option?.animation === false || this._spec?.animation === false); // chart 内部事件 模块自己必须删除 @@ -690,13 +699,6 @@ export class VChart implements IVChart { this._doResize(); } } else { - // 不remake的情况下,可以在这里更新主题 - if (updateResult.changeTheme) { - this._setCurrentTheme(); - this._setFontFamilyTheme(this._currentTheme?.fontFamily as string); - } else if (updateResult.changeBackground) { - this._compiler?.setBackground(this._getBackground()); - } if (updateResult.reCompile) { // recompile // 清除之前的所有 compile 内容 @@ -1324,7 +1326,7 @@ export class VChart implements IVChart { }); this._event?.on(eType as any, query as any, handler as any); } - off(eType: string, handler?: EventCallback): void { + off(eType: EventType, handler?: EventCallback): void { if (!this._userEvents || this._userEvents.length === 0) { return; } From a8aca46acbb0fdb0806cc5f64cc77af94e7edefa Mon Sep 17 00:00:00 2001 From: xile611 Date: Tue, 24 Dec 2024 16:06:00 +0800 Subject: [PATCH 2/6] perf: reduce duplicated code in core/vchart.ts --- packages/vchart/src/chart/base/base-chart.ts | 9 ++-- packages/vchart/src/core/vchart.ts | 48 ++++---------------- 2 files changed, 14 insertions(+), 43 deletions(-) diff --git a/packages/vchart/src/chart/base/base-chart.ts b/packages/vchart/src/chart/base/base-chart.ts index a75679138d..5be79e7106 100644 --- a/packages/vchart/src/chart/base/base-chart.ts +++ b/packages/vchart/src/chart/base/base-chart.ts @@ -128,9 +128,11 @@ export class BaseChart extends CompilableBase implements I } setLayoutTag(tag: boolean, morphConfig?: IMorphConfig, renderNextTick: boolean = true): boolean { this._layoutTag = tag; - if (this.getCompiler()?.getVGrammarView()) { - this.getCompiler().getVGrammarView().updateLayoutTag(); - tag && renderNextTick && this.getCompiler().renderNextTick(morphConfig); + const compiler = this.getCompiler(); + + if (compiler?.getVGrammarView()) { + compiler.getVGrammarView().updateLayoutTag(); + tag && renderNextTick && compiler.renderNextTick(morphConfig); } return this._layoutTag; } @@ -212,7 +214,6 @@ export class BaseChart extends CompilableBase implements I this._createLayout(); // 基于spec 创建元素。 // region - debugger; transformer.forEachRegionInSpec(this._spec, this._createRegion.bind(this)); // series transformer.forEachSeriesInSpec(this._spec, this._createSeries.bind(this)); diff --git a/packages/vchart/src/core/vchart.ts b/packages/vchart/src/core/vchart.ts index 0c1df16f67..fdcb29a7de 100644 --- a/packages/vchart/src/core/vchart.ts +++ b/packages/vchart/src/core/vchart.ts @@ -1110,9 +1110,9 @@ export class VChart implements IVChart { const reSize = this._shouldChartResize(lastSpec); result.reSize = reSize; - this._compiler?.getVGrammarView()?.updateLayoutTag(); if (this._spec.type !== lastSpec.type) { + this._compiler?.getVGrammarView()?.updateLayoutTag(); result.reMake = true; result.reTransformSpec = true; result.change = true; @@ -1146,25 +1146,7 @@ export class VChart implements IVChart { forceMerge: boolean = false, morphConfig?: IMorphConfig ) { - if (!spec || !this._spec) { - return this as unknown as IVChart; - } - if (isString(spec)) { - spec = JSON.parse(spec); - } - - if (!isFunction(filter)) { - // find spec and update - mergeSpecWithFilter(this._spec, filter, spec, forceMerge); - } - - if (this._chart) { - const model = this._chart.getModelInFilter(filter); - if (model) { - return this._updateModelSpec(model, spec, false, forceMerge, morphConfig); - } - } - return this as unknown as IVChart; + return this.updateModelSpecSync(filter, spec, forceMerge, morphConfig); } /** @@ -1553,16 +1535,7 @@ export class VChart implements IVChart { * @returns */ async setCurrentTheme(name: string) { - if (!ThemeManager.themeExist(name)) { - return this as unknown as IVChart; - } - const result = this._setCurrentTheme(name); - this._setFontFamilyTheme(this._currentTheme?.fontFamily as string); - await this.updateCustomConfigAndRerender(result, false, { - transformSpec: false, - actionSource: 'setCurrentTheme' - }); - return this as unknown as IVChart; + return this.setCurrentThemeSync(name); } /** @@ -2126,14 +2099,7 @@ export class VChart implements IVChart { * @since 1.11.10 */ geoZoomByIndex(regionIndex: number = 0, zoom: number, center?: { x: number; y: number }) { - const region = this._chart?.getRegionsInQuerier({ regionIndex })[0]; - const geoCoordinates = this._chart?.getComponentsByType( - ComponentTypeEnum.geoCoordinate - ) as unknown as IGeoCoordinate[]; - const coord = geoCoordinates?.find(coord => coord.getRegions()?.includes(region)); - if (coord) { - coord.dispatchZoom(zoom, center); - } + this._geoZoomByQuery({ regionIndex }, zoom, center); } /** @@ -2144,7 +2110,11 @@ export class VChart implements IVChart { * @since 1.11.10 */ geoZoomById(regionId: string | number, zoom: number, center?: { x: number; y: number }) { - const region = this._chart?.getRegionsInQuerier({ regionId })[0]; + this._geoZoomByQuery({ regionId }, zoom, center); + } + + _geoZoomByQuery(query: MaybeArray, zoom: number, center?: { x: number; y: number }) { + const region = this._chart?.getRegionsInQuerier(query)[0]; const geoCoordinates = this._chart?.getComponentsByType( ComponentTypeEnum.geoCoordinate ) as unknown as IGeoCoordinate[]; From a90c16a4d0cbd551273905b43cc9446c56c4969f Mon Sep 17 00:00:00 2001 From: xile611 Date: Tue, 24 Dec 2024 17:36:54 +0800 Subject: [PATCH 3/6] perf: optimize `_getDefaultSeriesSpec` of specTransformer --- .../vchart/src/chart/area/area-transformer.ts | 27 ++++--- .../src/chart/bar/3d/bar-3d-transformer.ts | 14 ++-- .../vchart/src/chart/bar/bar-transformer.ts | 25 +++---- .../src/chart/base/base-chart-transformer.ts | 19 ++++- .../chart/box-plot/box-plot-transformer.ts | 25 +++---- .../chart/cartesian/cartesian-transformer.ts | 36 ++++----- .../circle-packing-transformer.ts | 25 ++----- .../correlation/correlation-transformer.ts | 40 ++++------ .../src/chart/funnel/funnel-transformer.ts | 47 +++++------- .../src/chart/gauge/gauge-transformer.ts | 18 ++--- .../src/chart/heatmap/heatmap-transformer.ts | 7 +- .../base/histogram-base-transformer.ts | 8 +- .../vchart/src/chart/line/line-transformer.ts | 26 +++---- .../src/chart/liquid/liquid-transformer.ts | 26 +++---- .../vchart/src/chart/map/map-transformer.ts | 33 +++------ .../src/chart/mosaic/mosaic-transformer.ts | 23 +++--- .../chart/pictogram/pictogram-transformer.ts | 27 +++---- .../src/chart/pie/base/pie-transformer.ts | 38 ++++------ .../src/chart/polar/polar-transformer.ts | 31 +++----- .../progress-like-transformer.ts | 17 +---- .../polar/rose-like/rose-like-transformer.ts | 11 ++- .../circular/circular-progress-transformer.ts | 16 ++-- .../linear/linear-progress-transformer.ts | 14 +--- .../src/chart/radar/radar-transformer.ts | 36 +++++---- .../range-area/range-area-transformer.ts | 4 +- .../3d/range-column-3d-transformer.ts | 7 +- .../range-column/range-column-transformer.ts | 22 +++--- .../vchart/src/chart/rose/rose-transformer.ts | 18 ++--- .../src/chart/sankey/sankey-transformer.ts | 74 ++++++++----------- .../src/chart/scatter/scatter-transformer.ts | 9 +-- .../chart/sunburst/sunburst-transformer.ts | 47 +++++------- .../src/chart/treemap/treemap-transformer.ts | 48 +++++------- .../vchart/src/chart/venn/venn-transformer.ts | 23 ++---- .../chart/waterfall/waterfall-transformer.ts | 14 ++-- .../3d/word-cloud-3d-transformer.ts | 50 ++++++------- .../word-cloud/word-cloud-transformer.ts | 49 ++++++------ 36 files changed, 392 insertions(+), 562 deletions(-) diff --git a/packages/vchart/src/chart/area/area-transformer.ts b/packages/vchart/src/chart/area/area-transformer.ts index be2be59f73..68e045f9ed 100644 --- a/packages/vchart/src/chart/area/area-transformer.ts +++ b/packages/vchart/src/chart/area/area-transformer.ts @@ -6,20 +6,19 @@ export class AreaChartSpecTransformer< T extends IAreaChartSpec = IAreaChartSpec > extends CartesianChartSpecTransformer { protected _getDefaultSeriesSpec(spec: T): any { - return { - ...super._getDefaultSeriesSpec(spec), - point: spec.point, - line: spec.line, - area: spec.area, - seriesMark: spec.seriesMark, - activePoint: spec.activePoint, - sampling: spec.sampling, - samplingFactor: spec.samplingFactor, - pointDis: spec.pointDis, - pointDisMul: spec.pointDisMul, - markOverlap: spec.markOverlap, - areaLabel: spec.areaLabel - }; + return super._getDefaultSeriesSpec(spec, [ + 'point', + 'line', + 'area', + 'seriesMark', + 'activePoint', + 'sampling', + 'samplingFactor', + 'pointDis', + 'pointDisMul', + 'markOverlap', + 'areaLabel' + ]); } transformSpec(spec: T): void { diff --git a/packages/vchart/src/chart/bar/3d/bar-3d-transformer.ts b/packages/vchart/src/chart/bar/3d/bar-3d-transformer.ts index 95de566107..bf5a2d7fe8 100644 --- a/packages/vchart/src/chart/bar/3d/bar-3d-transformer.ts +++ b/packages/vchart/src/chart/bar/3d/bar-3d-transformer.ts @@ -6,12 +6,12 @@ export class Bar3dChartSpecTransformer > { protected _getDefaultSeriesSpec(spec: AdaptiveSpec): any { - return { - ...super._getDefaultSeriesSpec(spec), - barWidth: spec.barWidth, - barMaxWidth: spec.barMaxWidth, - barMinWidth: spec.barMinWidth, - barGapInGroup: spec.barGapInGroup - }; + const seriesSpec = super._getDefaultSeriesSpec(spec); + seriesSpec.barWidth = spec.barWidth; + seriesSpec.barMaxWidth = spec.barMaxWidth; + seriesSpec.barMinWidth = spec.barMinWidth; + seriesSpec.barGapInGroup = spec.barGapInGroup; + + return seriesSpec; } } diff --git a/packages/vchart/src/chart/bar/bar-transformer.ts b/packages/vchart/src/chart/bar/bar-transformer.ts index b51068db47..4cdb65a9f9 100644 --- a/packages/vchart/src/chart/bar/bar-transformer.ts +++ b/packages/vchart/src/chart/bar/bar-transformer.ts @@ -1,4 +1,4 @@ -import { isArray, isNumber, isObject } from '@visactor/vutils'; +import { isObject } from '@visactor/vutils'; import type { IBarSeriesSpec } from '../../series'; import { CartesianChartSpecTransformer } from '../cartesian'; import { setDefaultCrosshairForCartesianChart } from '../util'; @@ -7,18 +7,17 @@ import type { ICartesianBandAxisSpec } from '../../component'; export class BarChartSpecTransformer extends CartesianChartSpecTransformer { protected _getDefaultSeriesSpec(spec: T): any { - return { - ...super._getDefaultSeriesSpec(spec), - barWidth: spec.barWidth, - barMaxWidth: spec.barMaxWidth, - barMinWidth: spec.barMinWidth, - barGapInGroup: spec.barGapInGroup, - barMinHeight: spec.barMinHeight, - sampling: spec.sampling, - samplingFactor: spec.samplingFactor, - barBackground: spec.barBackground, - stackCornerRadius: spec.stackCornerRadius - } as IBarSeriesSpec; + return super._getDefaultSeriesSpec(spec, [ + 'barWidth', + 'barMaxWidth', + 'barMinWidth', + 'barGapInGroup', + 'barMinHeight', + 'sampling', + 'samplingFactor', + 'barBackground', + 'stackCornerRadius' + ]) as IBarSeriesSpec; } transformSpec(spec: T): void { diff --git a/packages/vchart/src/chart/base/base-chart-transformer.ts b/packages/vchart/src/chart/base/base-chart-transformer.ts index ecf15e0409..59aec151c7 100644 --- a/packages/vchart/src/chart/base/base-chart-transformer.ts +++ b/packages/vchart/src/chart/base/base-chart-transformer.ts @@ -160,7 +160,7 @@ export class BaseChartSpecTransformer implements IChartSpe return true; } - protected _getDefaultSeriesSpec(chartSpec: any) { + protected _getDefaultSeriesSpec(chartSpec: any, pickKeys?: string[], pickKeys2?: string[]) { const series: any = { dataKey: chartSpec.dataKey, @@ -197,6 +197,23 @@ export class BaseChartSpecTransformer implements IChartSpe interactions: chartSpec.interactions }; + + const seriesType = this.seriesType; + if (seriesType) { + series.type = seriesType; + series[seriesType] = (chartSpec as any)[seriesType]; + } + + if (pickKeys && pickKeys.length) { + pickKeys.forEach(k => { + series[k] = chartSpec[k]; + }); + } + if (pickKeys2 && pickKeys2.length) { + pickKeys2.forEach(k => { + series[k] = chartSpec[k]; + }); + } return series; } diff --git a/packages/vchart/src/chart/box-plot/box-plot-transformer.ts b/packages/vchart/src/chart/box-plot/box-plot-transformer.ts index a780384e68..57ff3163a1 100644 --- a/packages/vchart/src/chart/box-plot/box-plot-transformer.ts +++ b/packages/vchart/src/chart/box-plot/box-plot-transformer.ts @@ -8,19 +8,18 @@ export class BoxPlotChartSpecTransformer< > extends CartesianChartSpecTransformer { protected _getDefaultSeriesSpec(spec: T): any { const dataFields = [spec.maxField, spec.medianField, spec.q1Field, spec.q3Field, spec.minField, spec.outliersField]; - const seriesSpec = { - ...super._getDefaultSeriesSpec(spec), - boxPlot: spec.boxPlot, - direction: spec.direction ?? Direction.vertical, - minField: spec.minField, - maxField: spec.maxField, - q1Field: spec.q1Field, - medianField: spec.medianField, - q3Field: spec.q3Field, - outliersField: spec.outliersField, - outliersStyle: spec.outliersStyle - }; - seriesSpec[seriesSpec.direction === Direction.horizontal ? 'xField' : 'yField'] = dataFields; + const seriesSpec = super._getDefaultSeriesSpec(spec, [ + 'boxPlot', + 'minField', + 'maxField', + 'q1Field', + 'medianField', + 'q3Field', + 'outliersField', + 'outliersStyle' + ]); + (seriesSpec.direction = spec.direction ?? Direction.vertical), + (seriesSpec[seriesSpec.direction === Direction.horizontal ? 'xField' : 'yField'] = dataFields); return seriesSpec; } diff --git a/packages/vchart/src/chart/cartesian/cartesian-transformer.ts b/packages/vchart/src/chart/cartesian/cartesian-transformer.ts index 232ef92ed4..5064fefd33 100644 --- a/packages/vchart/src/chart/cartesian/cartesian-transformer.ts +++ b/packages/vchart/src/chart/cartesian/cartesian-transformer.ts @@ -15,26 +15,22 @@ export class CartesianChartSpecTransformer extend return this.seriesType ? type === this.seriesType : true; } - protected _getDefaultSeriesSpec(spec: any): any { - const series: any = { - ...super._getDefaultSeriesSpec(spec), - xField: spec.xField, - yField: spec.yField, - zField: spec.zField, - seriesField: spec.seriesField, - seriesStyle: spec.seriesStyle, - direction: spec.direction, - stack: spec.stack, // 是否堆叠 - percent: spec.percent, // 是否百分比堆叠 - stackOffsetSilhouette: spec.stackOffsetSilhouette, // 是否围绕中心轴偏移轮廓, - totalLabel: spec.totalLabel, - sortDataByAxis: spec.sortDataByAxis - }; - const seriesType = this.seriesType; - if (seriesType) { - series.type = seriesType; - series[seriesType] = spec[seriesType]; - } + protected _getDefaultSeriesSpec(spec: any, pickKeys?: string[]): any { + const series: any = super._getDefaultSeriesSpec( + spec, + [ + 'xField', + 'yField', + 'zField', + 'direction', + 'stack', // 是否堆叠 + 'percent', // 是否百分比堆叠 + 'stackOffsetSilhouette', // 是否围绕中心轴偏移轮廓, + 'totalLabel', + 'sortDataByAxis' + ], + pickKeys + ); return series; } diff --git a/packages/vchart/src/chart/circle-packing/circle-packing-transformer.ts b/packages/vchart/src/chart/circle-packing/circle-packing-transformer.ts index 0e5f7333c1..7e985af71b 100644 --- a/packages/vchart/src/chart/circle-packing/circle-packing-transformer.ts +++ b/packages/vchart/src/chart/circle-packing/circle-packing-transformer.ts @@ -1,5 +1,4 @@ import type { ICirclePackingSeriesSpec } from '../../series/circle-packing/interface'; -import { SeriesTypeEnum } from '../../series/interface'; import { BaseChartSpecTransformer } from '../base'; import type { ICirclePackingChartSpec } from './interface'; @@ -7,22 +6,14 @@ export class CirclePackingChartSpecTransformer< T extends ICirclePackingChartSpec = ICirclePackingChartSpec > extends BaseChartSpecTransformer { protected _getDefaultSeriesSpec(spec: ICirclePackingChartSpec) { - const series: ICirclePackingSeriesSpec = { - ...super._getDefaultSeriesSpec(spec), - categoryField: spec.categoryField, - valueField: spec.valueField, - seriesField: spec.seriesField, - - layoutPadding: spec.layoutPadding, - label: spec.label, - circlePacking: spec.circlePacking, - - drill: spec.drill, - drillField: spec.drillField - }; - const seriesType = SeriesTypeEnum.circlePacking; - series.type = seriesType; - series[seriesType] = spec[seriesType]; + const series: ICirclePackingSeriesSpec = super._getDefaultSeriesSpec(spec, [ + 'categoryField', + 'valueField', + 'layoutPadding', + 'circlePacking', + 'drill', + 'drillField' + ]); return series; } diff --git a/packages/vchart/src/chart/correlation/correlation-transformer.ts b/packages/vchart/src/chart/correlation/correlation-transformer.ts index a24c821080..fd736c9cea 100644 --- a/packages/vchart/src/chart/correlation/correlation-transformer.ts +++ b/packages/vchart/src/chart/correlation/correlation-transformer.ts @@ -8,30 +8,22 @@ export class CorrelationChartSpecTransformer< T extends ICorrelationChartSpec = ICorrelationChartSpec > extends BaseChartSpecTransformer { protected _getDefaultSeriesSpec(spec: T): any { - const series: ICorrelationSeriesSpec = { - ...super._getDefaultSeriesSpec(spec), - categoryField: spec.categoryField, - valueField: spec.valueField, - seriesField: spec.seriesField, - sizeField: spec.sizeField, - sizeRange: spec.sizeRange, - - centerX: spec.centerX, - centerY: spec.centerY, - innerRadius: spec.innerRadius, - outerRadius: spec.outerRadius, - startAngle: spec.startAngle, - endAngle: spec.endAngle, - - ripplePoint: spec.ripplePoint, - centerPoint: spec.centerPoint, - centerLabel: spec.centerLabel, - nodePoint: spec.nodePoint, - label: spec.label - }; - const seriesType = SeriesTypeEnum.correlation; - series.type = seriesType; - series[seriesType] = spec[seriesType]; + const series: ICorrelationSeriesSpec = super._getDefaultSeriesSpec(spec, [ + 'categoryField', + 'valueField', + 'sizeField', + 'sizeRange', + 'centerX', + 'centerY', + 'innerRadius', + 'outerRadius', + 'startAngle', + 'endAngle', + 'ripplePoint', + 'centerPoint', + 'centerLabel', + 'nodePoint' + ]); return series; } diff --git a/packages/vchart/src/chart/funnel/funnel-transformer.ts b/packages/vchart/src/chart/funnel/funnel-transformer.ts index 778c5fc810..448a7fe491 100644 --- a/packages/vchart/src/chart/funnel/funnel-transformer.ts +++ b/packages/vchart/src/chart/funnel/funnel-transformer.ts @@ -9,35 +9,24 @@ export class FunnelChartSpecTransformer extends Base } protected _getDefaultSeriesSpec(spec: T): IFunnelSeriesSpec { - const series: any = { - ...super._getDefaultSeriesSpec(spec), - - categoryField: spec.categoryField, - valueField: spec.valueField, - seriesField: spec.seriesField, - - funnelAlign: spec.funnelAlign, - funnelOrient: spec.funnelOrient, - heightRatio: spec.heightRatio, - - shape: spec.shape, - funnel: spec.funnel, - transform: spec.transform, - outerLabel: spec.outerLabel, - transformLabel: spec.transformLabel, - - isTransform: spec.isTransform, - maxSize: spec.maxSize, - minSize: spec.minSize, - gap: spec.gap, - isCone: spec.isCone, - range: spec.range - }; - const seriesType = this.seriesType; - if (seriesType) { - series.type = seriesType; - series[seriesType] = spec[seriesType]; - } + const series: any = super._getDefaultSeriesSpec(spec, [ + 'categoryField', + 'valueField', + 'funnelAlign', + 'funnelOrient', + 'heightRatio', + 'shape', + 'funnel', + 'transform', + 'outerLabel', + 'transformLabel', + 'isTransform', + 'maxSize', + 'minSize', + 'gap', + 'isCone', + 'range' + ]); return series; } diff --git a/packages/vchart/src/chart/gauge/gauge-transformer.ts b/packages/vchart/src/chart/gauge/gauge-transformer.ts index 1ac5232adf..339ee88d6c 100644 --- a/packages/vchart/src/chart/gauge/gauge-transformer.ts +++ b/packages/vchart/src/chart/gauge/gauge-transformer.ts @@ -12,21 +12,17 @@ export class GaugeChartSpecTransformer< > extends ProgressLikeChartSpecTransformer> { protected _getDefaultSeriesSpec(spec: T): any { const series = super._getDefaultSeriesSpec(spec); - return { - ...series, - radiusField: spec.radiusField, - pin: spec.pin, - pinBackground: spec.pinBackground, - pointer: spec.pointer - }; + series.radiusField = spec.radiusField; + series.pin = spec.pin; + series.pinBackground = spec.pinBackground; + series.pointer = spec.pointer; + return series; } protected _getDefaultCircularProgressSeriesSpec(spec: T): any { - const series: any = { - ...super._getDefaultSeriesSpec(spec), - type: SeriesTypeEnum.circularProgress - }; + const series: any = super._getDefaultSeriesSpec(spec); + series.type = SeriesTypeEnum.circularProgress; return series; } diff --git a/packages/vchart/src/chart/heatmap/heatmap-transformer.ts b/packages/vchart/src/chart/heatmap/heatmap-transformer.ts index 08dfb2a5b3..9ac54fe140 100644 --- a/packages/vchart/src/chart/heatmap/heatmap-transformer.ts +++ b/packages/vchart/src/chart/heatmap/heatmap-transformer.ts @@ -5,11 +5,6 @@ export class HeatmapChartSpecTransformer< T extends IHeatmapChartSpec = IHeatmapChartSpec > extends CartesianChartSpecTransformer { protected _getDefaultSeriesSpec(spec: T): any { - const series = super._getDefaultSeriesSpec(spec); - return { - ...series, - valueField: spec.valueField, - cell: spec.cell - }; + return super._getDefaultSeriesSpec(spec, ['valueField', 'cell']); } } diff --git a/packages/vchart/src/chart/histogram/base/histogram-base-transformer.ts b/packages/vchart/src/chart/histogram/base/histogram-base-transformer.ts index ee58543877..4539a430c9 100644 --- a/packages/vchart/src/chart/histogram/base/histogram-base-transformer.ts +++ b/packages/vchart/src/chart/histogram/base/histogram-base-transformer.ts @@ -9,12 +9,6 @@ export class BaseHistogramChartSpecTransformer ex } protected _getDefaultSeriesSpec(spec: T): any { - return { - ...super._getDefaultSeriesSpec(spec), - x2Field: spec?.x2Field, - y2Field: spec?.y2Field, - barMinHeight: spec?.barMinHeight, - barBackground: spec?.barBackground - }; + return super._getDefaultSeriesSpec(spec, ['x2Field', 'y2Field', 'barMinHeight', 'barBackground']); } } diff --git a/packages/vchart/src/chart/line/line-transformer.ts b/packages/vchart/src/chart/line/line-transformer.ts index d6cd2d4d48..849ca1c48c 100644 --- a/packages/vchart/src/chart/line/line-transformer.ts +++ b/packages/vchart/src/chart/line/line-transformer.ts @@ -4,19 +4,19 @@ import type { ILineChartSpec } from './interface'; export class LineChartSpecTransformer extends CartesianChartSpecTransformer { protected _getDefaultSeriesSpec(spec: T): any { - return { - ...super._getDefaultSeriesSpec(spec), - point: spec.point, - line: spec.line, - seriesMark: spec.seriesMark ?? 'line', - activePoint: spec.activePoint, - sampling: spec.sampling, - samplingFactor: spec.samplingFactor, - pointDis: spec.pointDis, - pointDisMul: spec.pointDisMul, - markOverlap: spec.markOverlap, - lineLabel: spec.lineLabel - }; + const seriesSpec = super._getDefaultSeriesSpec(spec, [ + 'point', + 'line', + 'activePoint', + 'sampling', + 'samplingFactor', + 'pointDis', + 'pointDisMul', + 'markOverlap', + 'lineLabel' + ]); + seriesSpec.seriesMark = spec.seriesMark ?? 'line'; + return seriesSpec; } transformSpec(spec: T): void { super.transformSpec(spec); diff --git a/packages/vchart/src/chart/liquid/liquid-transformer.ts b/packages/vchart/src/chart/liquid/liquid-transformer.ts index af76ca5de2..3e893ca745 100644 --- a/packages/vchart/src/chart/liquid/liquid-transformer.ts +++ b/packages/vchart/src/chart/liquid/liquid-transformer.ts @@ -6,22 +6,16 @@ export class LiquidChartSpecTransformer< T extends ILiquidChartSpec = ILiquidChartSpec > extends BaseChartSpecTransformer { protected _getDefaultSeriesSpec(spec: T): any { - const series: any = { - ...super._getDefaultSeriesSpec(spec), - valueField: spec.valueField, - maskShape: spec.maskShape, - reverse: spec.reverse, - outlineMargin: spec.outlineMargin, - outlinePadding: spec.outlinePadding, - indicatorSmartInvert: spec.indicatorSmartInvert, - liquidBackground: spec.liquidBackground, - liquidOutline: spec.liquidOutline - }; - const seriesType = SeriesTypeEnum.liquid; - if (seriesType) { - series.type = seriesType; - series[seriesType] = spec[seriesType]; - } + const series: any = super._getDefaultSeriesSpec(spec, [ + 'valueField', + 'maskShape', + 'reverse', + 'outlineMargin', + 'outlinePadding', + 'indicatorSmartInvert', + 'liquidBackground', + 'liquidOutline' + ]); return series; } diff --git a/packages/vchart/src/chart/map/map-transformer.ts b/packages/vchart/src/chart/map/map-transformer.ts index 98a5fbb6fc..2882eb644f 100644 --- a/packages/vchart/src/chart/map/map-transformer.ts +++ b/packages/vchart/src/chart/map/map-transformer.ts @@ -11,27 +11,18 @@ export class MapChartSpecTransformer ex } protected _getDefaultSeriesSpec(spec: IMapChartSpec): IMapSeriesSpec { - const series: any = { - ...super._getDefaultSeriesSpec(spec), - - type: spec.type, - - nameField: spec.nameField, - valueField: spec.valueField, - seriesField: spec.seriesField, - - map: spec.map, - - nameProperty: spec.nameProperty, - centroidProperty: spec.centroidProperty, - nameMap: spec.nameMap, - area: spec.area, - - defaultFillColor: spec.defaultFillColor, - showDefaultName: spec.showDefaultName - }; - - return series; + return super._getDefaultSeriesSpec(spec, [ + 'type', + 'nameField', + 'valueField', + 'map', + 'nameProperty', + 'centroidProperty', + 'nameMap', + 'area', + 'defaultFillColor', + 'showDefaultName' + ]); } transformSpec(spec: T): void { diff --git a/packages/vchart/src/chart/mosaic/mosaic-transformer.ts b/packages/vchart/src/chart/mosaic/mosaic-transformer.ts index c942f54a7c..649f17dcff 100644 --- a/packages/vchart/src/chart/mosaic/mosaic-transformer.ts +++ b/packages/vchart/src/chart/mosaic/mosaic-transformer.ts @@ -7,19 +7,16 @@ export class MosaicChartSpecTransformer< T extends IMosaicChartSpec = IMosaicChartSpec > extends CartesianChartSpecTransformer { protected _getDefaultSeriesSpec(spec: T): any { - const series: any = { - ...super._getDefaultSeriesSpec(spec), - barWidth: (spec as IMosaicChartSpec).barWidth, - barMaxWidth: (spec as IMosaicChartSpec).barMaxWidth, - barMinWidth: (spec as IMosaicChartSpec).barMinWidth, - barGapInGroup: (spec as IMosaicChartSpec).barGapInGroup, - barBackground: (spec as IMosaicChartSpec).barBackground, - barMinHeight: (spec as IMosaicChartSpec).barMinHeight, - stackCornerRadius: (spec as IMosaicChartSpec).stackCornerRadius - }; - series.bar = spec.bar; - - return series; + return super._getDefaultSeriesSpec(spec, [ + 'barWidth', + 'barMaxWidth', + 'barMinWidth', + 'barGapInGroup', + 'barBackground', + 'barMinHeight', + 'stackCornerRadius', + 'bar' + ]); } transformSpec(spec: T): void { diff --git a/packages/vchart/src/chart/pictogram/pictogram-transformer.ts b/packages/vchart/src/chart/pictogram/pictogram-transformer.ts index df555dd651..23ae299515 100644 --- a/packages/vchart/src/chart/pictogram/pictogram-transformer.ts +++ b/packages/vchart/src/chart/pictogram/pictogram-transformer.ts @@ -1,6 +1,6 @@ // eslint-disable-next-line no-duplicate-imports import { SeriesTypeEnum } from '../../series'; -import { IPictogramSeriesSpec } from '../../series/pictogram/interface'; +import type { IPictogramSeriesSpec } from '../../series/pictogram/interface'; import type { RegionSpec, ISeriesSpec } from '../../typings'; import { BaseChartSpecTransformer } from '../base'; import type { IPictogramChartSpec } from './interface'; @@ -13,23 +13,14 @@ export class PictogramChartSpecTransformer< } protected _getDefaultSeriesSpec(spec: IPictogramChartSpec): IPictogramSeriesSpec { - const series: any = { - ...super._getDefaultSeriesSpec(spec), - - type: spec.type, - - nameField: spec.nameField, - valueField: spec.valueField, - seriesField: spec.seriesField, - - svg: spec.svg, - - pictogram: spec.pictogram, - - defaultFillColor: spec.defaultFillColor - }; - - return series; + return super._getDefaultSeriesSpec(spec, [ + 'type', + 'nameField', + 'valueField', + 'svg', + 'pictogram', + 'defaultFillColor' + ]); } transformSpec(spec: T): void { diff --git a/packages/vchart/src/chart/pie/base/pie-transformer.ts b/packages/vchart/src/chart/pie/base/pie-transformer.ts index 7c13ae356e..bcb33788a9 100644 --- a/packages/vchart/src/chart/pie/base/pie-transformer.ts +++ b/packages/vchart/src/chart/pie/base/pie-transformer.ts @@ -10,27 +10,21 @@ export class BasePieChartSpecTransformer extends PolarC } protected _getDefaultSeriesSpec(spec: any): any { - return { - ...super._getDefaultSeriesSpec(spec), - - // 兼容旧版写法 - categoryField: spec.categoryField || spec.seriesField, - valueField: spec.valueField || spec.angleField, - - center: spec.center, - centerOffset: spec.centerOffset, - - cornerRadius: spec.cornerRadius, - - padAngle: spec.padAngle, - minAngle: spec.minAngle, - - emptyPlaceholder: spec.emptyPlaceholder, - emptyCircle: spec.emptyPlaceholder?.emptyCircle, - - showAllZero: spec.showAllZero, - supportNegative: spec.supportNegative, - layoutRadius: spec.layoutRadius - }; + const seriesSpec = super._getDefaultSeriesSpec(spec, [ + 'center', + 'centerOffset', + 'cornerRadius', + 'padAngle', + 'minAngle', + 'emptyPlaceholder', + 'showAllZero', + 'supportNegative', + 'layoutRadius' + ]); + // 兼容旧版写法 + seriesSpec.categoryField = spec.categoryField || spec.seriesField; + seriesSpec.valueField = spec.valueField || spec.angleField; + seriesSpec.emptyCircle = spec.emptyPlaceholder?.emptyCircle; + return seriesSpec; } } diff --git a/packages/vchart/src/chart/polar/polar-transformer.ts b/packages/vchart/src/chart/polar/polar-transformer.ts index 34e52d27a8..dabfc08515 100644 --- a/packages/vchart/src/chart/polar/polar-transformer.ts +++ b/packages/vchart/src/chart/polar/polar-transformer.ts @@ -21,27 +21,16 @@ export class PolarChartSpecTransformer extends BaseCh return indicatorSpec; } - protected _getDefaultSeriesSpec(spec: any): any { - const series: any = { - ...super._getDefaultSeriesSpec(spec), - - /** - * 旧的radius写法, 仅做兼容 - * @deprecated use outerRadius instead - */ - radius: spec.radius, - outerRadius: spec.outerRadius, - innerRadius: spec.innerRadius, - - startAngle: spec.startAngle, - endAngle: spec.endAngle, - sortDataByAxis: spec.sortDataByAxis - }; - const seriesType = this.seriesType; - if (seriesType) { - series.type = seriesType; - series[seriesType] = spec[seriesType]; - } + protected _getDefaultSeriesSpec(spec: any, pickKeys?: string[]): any { + /** + * 旧的radius写法, 仅做兼容 + * @deprecated use outerRadius instead + */ + const series: any = super._getDefaultSeriesSpec( + spec, + ['radius', 'outerRadius', 'innerRadius', 'startAngle', 'endAngle', 'sortDataByAxis'], + pickKeys + ); return series; } diff --git a/packages/vchart/src/chart/polar/progress-like/progress-like-transformer.ts b/packages/vchart/src/chart/polar/progress-like/progress-like-transformer.ts index e6ebfc3893..a23a555834 100644 --- a/packages/vchart/src/chart/polar/progress-like/progress-like-transformer.ts +++ b/packages/vchart/src/chart/polar/progress-like/progress-like-transformer.ts @@ -11,22 +11,11 @@ export class ProgressLikeChartSpecTransformer extends } protected _getDefaultSeriesSpec(spec: any): any { - const series: any = { - ...super._getDefaultSeriesSpec(spec), + const series: any = super._getDefaultSeriesSpec(spec, ['startAngle', 'endAngle', 'centerX', 'centerY']); - seriesField: spec.seriesField, - categoryField: spec.categoryField || spec.radiusField, - valueField: spec.valueField || spec.angleField, + series.categoryField = spec.categoryField || spec.radiusField; + series.valueField = spec.valueField || spec.angleField; - startAngle: spec.startAngle, - endAngle: spec.endAngle, - - radius: spec.radius, - innerRadius: spec.innerRadius, - - centerX: spec.centerX, - centerY: spec.centerY - }; return series; } diff --git a/packages/vchart/src/chart/polar/rose-like/rose-like-transformer.ts b/packages/vchart/src/chart/polar/rose-like/rose-like-transformer.ts index 35313b4aa6..b812461bc4 100644 --- a/packages/vchart/src/chart/polar/rose-like/rose-like-transformer.ts +++ b/packages/vchart/src/chart/polar/rose-like/rose-like-transformer.ts @@ -8,13 +8,12 @@ export class RoseLikeChartSpecTransformer extends Pol } protected _getDefaultSeriesSpec(spec: any): any { - const series: any = { - ...super._getDefaultSeriesSpec(spec), + const series: any = super._getDefaultSeriesSpec(spec); + + // 兼容旧版写法 + series.categoryField = spec.categoryField || spec.angleField; + series.valueField = spec.valueField || spec.radiusField; - // 兼容旧版写法 - categoryField: spec.categoryField || spec.angleField, - valueField: spec.valueField || spec.radiusField - }; return series; } diff --git a/packages/vchart/src/chart/progress/circular/circular-progress-transformer.ts b/packages/vchart/src/chart/progress/circular/circular-progress-transformer.ts index d0834ab642..b164a0a711 100644 --- a/packages/vchart/src/chart/progress/circular/circular-progress-transformer.ts +++ b/packages/vchart/src/chart/progress/circular/circular-progress-transformer.ts @@ -7,17 +7,13 @@ export class CircularProgressChartSpecTransformer< > extends ProgressLikeChartSpecTransformer> { protected _getDefaultSeriesSpec(spec: T): any { const series = super._getDefaultSeriesSpec(spec); - return { - ...series, - cornerRadius: spec.cornerRadius ?? 0, - roundCap: spec.roundCap ?? false, - - progress: spec.progress, - track: spec.track, - - tickMask: spec.tickMask - }; + series.progress = spec.progress; + series.track = spec.track; + series.tickMask = spec.tickMask; + series.cornerRadius = spec.cornerRadius ?? 0; + series.roundCap = spec.roundCap ?? false; + return series; } transformSpec(spec: AdaptiveSpec): void { diff --git a/packages/vchart/src/chart/progress/linear/linear-progress-transformer.ts b/packages/vchart/src/chart/progress/linear/linear-progress-transformer.ts index e6338cf6c7..5dbe0a5069 100644 --- a/packages/vchart/src/chart/progress/linear/linear-progress-transformer.ts +++ b/packages/vchart/src/chart/progress/linear/linear-progress-transformer.ts @@ -12,17 +12,11 @@ export class LinearProgressChartSpecTransformer< } protected _getDefaultSeriesSpec(spec: T): ILinearProgressChartSpec { - const series = super._getDefaultSeriesSpec(spec); - return { - ...series, - direction: spec.direction ?? 'horizontal', + const series = super._getDefaultSeriesSpec(spec, ['bandWidth', 'progress', 'track']); + series.direction = spec.direction ?? 'horizontal'; - cornerRadius: spec.cornerRadius ?? 0, - bandWidth: spec.bandWidth, - - progress: spec.progress, - track: spec.track - }; + series.cornerRadius = spec.cornerRadius ?? 0; + return series; } transformSpec(spec: T): void { diff --git a/packages/vchart/src/chart/radar/radar-transformer.ts b/packages/vchart/src/chart/radar/radar-transformer.ts index 734e955730..42d331025b 100644 --- a/packages/vchart/src/chart/radar/radar-transformer.ts +++ b/packages/vchart/src/chart/radar/radar-transformer.ts @@ -7,25 +7,23 @@ export class RadarChartSpecTransformer< T extends IRoseChartSpec = IRoseChartSpec > extends RoseLikeChartSpecTransformer { protected _getDefaultSeriesSpec(spec: any): any { - return { - ...super._getDefaultSeriesSpec(spec), - seriesField: spec.seriesField, - line: spec.line, - point: spec.point, - stack: spec.stack, - percent: spec.percent, - area: mergeSpec( - { - visible: false - }, - spec.area - ), - seriesMark: spec.seriesMark ?? 'area', - activePoint: spec.activePoint, - pointDis: spec.pointDis, - pointDisMul: spec.pointDisMul, - markOverlap: spec.markOverlap - }; + const series = super._getDefaultSeriesSpec(spec); + series.line = spec.line; + series.point = spec.point; + series.stack = spec.stack; + series.percent = spec.percent; + series.area = mergeSpec( + { + visible: false + }, + spec.area + ); + series.seriesMark = spec.seriesMark ?? 'area'; + series.activePoint = spec.activePoint; + series.pointDis = spec.pointDis; + series.pointDisMul = spec.pointDisMul; + series.markOverlap = spec.markOverlap; + return series; } transformSpec(spec: T) { diff --git a/packages/vchart/src/chart/range-area/range-area-transformer.ts b/packages/vchart/src/chart/range-area/range-area-transformer.ts index 3c81752413..fd47b8a5b1 100644 --- a/packages/vchart/src/chart/range-area/range-area-transformer.ts +++ b/packages/vchart/src/chart/range-area/range-area-transformer.ts @@ -7,9 +7,7 @@ export class RangeAreaChartSpecTransformer< T extends IRangeAreaChartSpec = IRangeAreaChartSpec > extends CartesianChartSpecTransformer { protected _getDefaultSeriesSpec(spec: T): any { - const series: any = { - ...super._getDefaultSeriesSpec(spec) - }; + const series: any = super._getDefaultSeriesSpec(spec); series.area = spec.area; if (spec.direction === Direction.horizontal) { series.xField = spec.xField ?? [spec.minField, spec.maxField]; diff --git a/packages/vchart/src/chart/range-column/3d/range-column-3d-transformer.ts b/packages/vchart/src/chart/range-column/3d/range-column-3d-transformer.ts index 4ca53cfac9..828df8c57e 100644 --- a/packages/vchart/src/chart/range-column/3d/range-column-3d-transformer.ts +++ b/packages/vchart/src/chart/range-column/3d/range-column-3d-transformer.ts @@ -6,11 +6,8 @@ export class RangeColumn3dChartSpecTransformer< T extends IRangeColumn3dChartSpec = IRangeColumn3dChartSpec > extends CartesianChartSpecTransformer { protected _getDefaultSeriesSpec(spec: any): any { - const series: any = { - ...super._getDefaultSeriesSpec(spec), - barGapInGroup: (spec as IRangeColumn3dChartSpec).barGapInGroup - }; - series.bar3d = spec.bar3d; + const series: any = super._getDefaultSeriesSpec(spec, ['bar3d', 'barGapInGroup']); + if (spec.direction === Direction.horizontal) { series.xField = spec.xField ?? [spec.minField, spec.maxField]; } else { diff --git a/packages/vchart/src/chart/range-column/range-column-transformer.ts b/packages/vchart/src/chart/range-column/range-column-transformer.ts index da52279225..80df713316 100644 --- a/packages/vchart/src/chart/range-column/range-column-transformer.ts +++ b/packages/vchart/src/chart/range-column/range-column-transformer.ts @@ -7,17 +7,17 @@ export class RangeColumnChartSpecTransformer< T extends IRangeColumnChartSpec = IRangeColumnChartSpec > extends CartesianChartSpecTransformer { protected _getDefaultSeriesSpec(spec: T): any { - const series: any = { - ...super._getDefaultSeriesSpec(spec), - barWidth: (spec as IRangeColumnChartSpec).barWidth, - barMaxWidth: (spec as IRangeColumnChartSpec).barMaxWidth, - barMinWidth: (spec as IRangeColumnChartSpec).barMinWidth, - barGapInGroup: (spec as IRangeColumnChartSpec).barGapInGroup, - barBackground: (spec as IRangeColumnChartSpec).barBackground, - barMinHeight: (spec as IRangeColumnChartSpec).barMinHeight, - stackCornerRadius: (spec as IRangeColumnChartSpec).stackCornerRadius - }; - series.bar = spec.bar; + const series: any = super._getDefaultSeriesSpec(spec, [ + 'barWidth', + 'barMaxWidth', + 'barMinWidth', + 'barGapInGroup', + 'barBackground', + 'barMinHeight', + 'stackCornerRadius', + 'bar' + ]); + if (spec.direction === Direction.horizontal) { series.xField = spec.xField ?? [spec.minField, spec.maxField]; } else { diff --git a/packages/vchart/src/chart/rose/rose-transformer.ts b/packages/vchart/src/chart/rose/rose-transformer.ts index 82d625c8f8..06e7b87888 100644 --- a/packages/vchart/src/chart/rose/rose-transformer.ts +++ b/packages/vchart/src/chart/rose/rose-transformer.ts @@ -9,16 +9,14 @@ export class RoseChartSpecTransformer< T extends IRoseChartSpec = IRoseChartSpec > extends RoseLikeChartSpecTransformer { protected _getDefaultSeriesSpec(spec: T): any { - return { - ...super._getDefaultSeriesSpec(spec), - radius: spec.radius ?? POLAR_DEFAULT_RADIUS, - outerRadius: spec.outerRadius ?? POLAR_DEFAULT_RADIUS, - innerRadius: spec.innerRadius ?? 0, - seriesField: spec.seriesField, - stack: spec.stack, - percent: spec.percent - // startAngle: degreeToRadian(spec.startAngle || 0), - }; + const series = super._getDefaultSeriesSpec(spec); + series.radius = spec.radius ?? POLAR_DEFAULT_RADIUS; + series.outerRadius = spec.outerRadius ?? POLAR_DEFAULT_RADIUS; + series.innerRadius = spec.innerRadius ?? 0; + + series.stack = spec.stack; + series.percent = spec.percent; + return series; } transformSpec(spec: T) { diff --git a/packages/vchart/src/chart/sankey/sankey-transformer.ts b/packages/vchart/src/chart/sankey/sankey-transformer.ts index e12638e734..fa77d2375b 100644 --- a/packages/vchart/src/chart/sankey/sankey-transformer.ts +++ b/packages/vchart/src/chart/sankey/sankey-transformer.ts @@ -6,48 +6,38 @@ export class SankeyChartSpecTransformer< T extends ISankeyChartSpec = ISankeyChartSpec > extends BaseChartSpecTransformer { protected _getDefaultSeriesSpec(spec: T): any { - const series: any = { - ...super._getDefaultSeriesSpec(spec), - categoryField: spec.categoryField, - valueField: spec.valueField, - sourceField: spec.sourceField, - targetField: spec.targetField, - - direction: spec.direction, - nodeAlign: spec.nodeAlign, - crossNodeAlign: spec.crossNodeAlign, - nodeGap: spec.nodeGap, - nodeWidth: spec.nodeWidth, - linkWidth: spec.linkWidth, - minStepWidth: spec.minStepWidth, - minNodeHeight: spec.minNodeHeight, - maxNodeHeight: spec.maxNodeHeight, - minLinkHeight: spec.minLinkHeight, - maxLinkHeight: spec.maxLinkHeight, - dropIsolatedNode: spec.dropIsolatedNode, - nodeHeight: spec.nodeHeight, - linkHeight: spec.linkHeight, - equalNodeHeight: spec.equalNodeHeight, - linkOverlap: spec.linkOverlap, - iterations: spec.iterations, - nodeKey: spec.nodeKey, - linkSortBy: spec.linkSortBy, - nodeSortBy: spec.nodeSortBy, - setNodeLayer: spec.setNodeLayer, - - node: spec.node, - link: spec.link, - label: spec.label, - - emphasis: spec.emphasis, - inverse: spec.inverse, - overflow: spec.overflow - }; - const seriesType = this.seriesType; - if (seriesType) { - series.type = seriesType; - series[seriesType] = spec[seriesType]; - } + const series = super._getDefaultSeriesSpec(spec, [ + 'categoryField', + 'valueField', + 'sourceField', + 'targetField', + 'direction', + 'nodeAlign', + 'crossNodeAlign', + 'nodeGap', + 'nodeWidth', + 'linkWidth', + 'minStepWidth', + 'minNodeHeight', + 'maxNodeHeight', + 'minLinkHeight', + 'maxLinkHeight', + 'dropIsolatedNode', + 'nodeHeight', + 'linkHeight', + 'equalNodeHeight', + 'linkOverlap', + 'iterations', + 'nodeKey', + 'linkSortBy', + 'nodeSortBy', + 'setNodeLayer', + 'node', + 'link', + 'emphasis', + 'inverse', + 'overflow' + ]); return series; } diff --git a/packages/vchart/src/chart/scatter/scatter-transformer.ts b/packages/vchart/src/chart/scatter/scatter-transformer.ts index ffc052ac7a..38a24e3eb9 100644 --- a/packages/vchart/src/chart/scatter/scatter-transformer.ts +++ b/packages/vchart/src/chart/scatter/scatter-transformer.ts @@ -5,13 +5,6 @@ export class ScatterChartSpecTransformer< T extends IScatterChartSpec = IScatterChartSpec > extends CartesianChartSpecTransformer { protected _getDefaultSeriesSpec(spec: IScatterChartSpec): any { - return { - ...super._getDefaultSeriesSpec(spec), - point: spec.point, - size: spec.size, - sizeField: spec.sizeField, - shape: spec.shape, - shapeField: spec.shapeField - }; + return super._getDefaultSeriesSpec(spec, ['point', 'size', 'shape', 'shapeField', 'sizeField']); } } diff --git a/packages/vchart/src/chart/sunburst/sunburst-transformer.ts b/packages/vchart/src/chart/sunburst/sunburst-transformer.ts index 4aa763fe2b..32037d9059 100644 --- a/packages/vchart/src/chart/sunburst/sunburst-transformer.ts +++ b/packages/vchart/src/chart/sunburst/sunburst-transformer.ts @@ -15,34 +15,25 @@ export class SunburstChartSpecTransformer< // 结束角度默认使用用户的配置, 若用户没配置, 默认补成整圆. const endAngle = isValid(spec.endAngle) ? spec.endAngle : startAngle + radianToDegree(Math.PI * 2); - const series: ISunburstSeriesSpec = { - ...super._getDefaultSeriesSpec(spec), - categoryField: spec.categoryField, - valueField: spec.valueField, - seriesField: spec.seriesField, - - centerX: spec.centerX, - centerY: spec.centerY, - offsetX: spec.offsetX, - offsetY: spec.offsetY, - - startAngle: startAngle, - endAngle: endAngle, - - innerRadius: spec.innerRadius, - outerRadius: spec.outerRadius, - gap: spec.gap, - labelLayout: spec.labelLayout, - label: spec.label, - labelAutoVisible: spec.labelAutoVisible, - - drill: spec.drill, - drillField: spec.drillField - }; - - const seriesType = SeriesTypeEnum.sunburst; - series.type = seriesType; - series[seriesType] = spec[seriesType]; + const series: ISunburstSeriesSpec = super._getDefaultSeriesSpec(spec, [ + 'categoryField', + 'valueField', + 'centerX', + 'centerY', + 'offsetX', + 'offsetY', + 'innerRadius', + 'outerRadius', + 'gap', + 'labelLayout', + 'label', + 'labelAutoVisible', + 'drill', + 'drillField' + ]); + + series.startAngle = startAngle; + series.endAngle = endAngle; return series; } diff --git a/packages/vchart/src/chart/treemap/treemap-transformer.ts b/packages/vchart/src/chart/treemap/treemap-transformer.ts index 1e14313a72..4de1ee666b 100644 --- a/packages/vchart/src/chart/treemap/treemap-transformer.ts +++ b/packages/vchart/src/chart/treemap/treemap-transformer.ts @@ -6,36 +6,24 @@ export class TreemapChartSpecTransformer< T extends ITreemapChartSpec = ITreemapChartSpec > extends BaseChartSpecTransformer> { protected _getDefaultSeriesSpec(spec: T): any { - const series: any = { - ...super._getDefaultSeriesSpec(spec), - categoryField: spec.categoryField, - valueField: spec.valueField, - - seriesField: spec.seriesField, - - aspectRatio: spec.aspectRatio, - splitType: spec.splitType, - maxDepth: spec.maxDepth, - gapWidth: spec.gapWidth, - nodePadding: spec.nodePadding, - minVisibleArea: spec.minVisibleArea, - minChildrenVisibleArea: spec.minChildrenVisibleArea, - minChildrenVisibleSize: spec.minChildrenVisibleSize, - - roam: spec.roam, - drill: spec.drill, - drillField: spec.drillField, - - leaf: spec.leaf, - nonLeaf: spec.nonLeaf, - nonLeafLabel: spec.nonLeafLabel - }; - const seriesType = this.seriesType; - if (seriesType) { - series.type = seriesType; - series[seriesType] = spec[seriesType]; - } - + const series: any = super._getDefaultSeriesSpec(spec, [ + 'categoryField', + 'valueField', + 'aspectRatio', + 'splitType', + 'maxDepth', + 'gapWidth', + 'nodePadding', + 'minVisibleArea', + 'minChildrenVisibleArea', + 'minChildrenVisibleSize', + 'roam', + 'drill', + 'drillField', + 'leaf', + 'nonLeaf', + 'nonLeafLabel' + ]); return series; } diff --git a/packages/vchart/src/chart/venn/venn-transformer.ts b/packages/vchart/src/chart/venn/venn-transformer.ts index df30ff380c..e5224777a5 100644 --- a/packages/vchart/src/chart/venn/venn-transformer.ts +++ b/packages/vchart/src/chart/venn/venn-transformer.ts @@ -6,22 +6,13 @@ export class VennChartSpecTransformer AdaptiveSpec > { protected _getDefaultSeriesSpec(spec: T): any { - const series: any = { - ...super._getDefaultSeriesSpec(spec), - categoryField: spec.categoryField, - valueField: spec.valueField, - - seriesField: spec.seriesField, - - circle: spec.circle, - overlap: spec.overlap, - overlapLabel: spec.overlapLabel - }; - const seriesType = this.seriesType; - if (seriesType) { - series.type = seriesType; - series[seriesType] = spec[seriesType]; - } + const series: any = super._getDefaultSeriesSpec(spec, [ + 'categoryField', + 'valueField', + 'circle', + 'overlap', + 'overlapLabel' + ]); return series; } diff --git a/packages/vchart/src/chart/waterfall/waterfall-transformer.ts b/packages/vchart/src/chart/waterfall/waterfall-transformer.ts index f6fd13f21e..96dfcdf376 100644 --- a/packages/vchart/src/chart/waterfall/waterfall-transformer.ts +++ b/packages/vchart/src/chart/waterfall/waterfall-transformer.ts @@ -21,12 +21,12 @@ export class WaterfallChartSpecTransformer< } protected _getDefaultSeriesSpec(spec: AdaptiveSpec): any { - return { - ...super._getDefaultSeriesSpec(spec), - bar: spec.bar, - stackLabel: spec.stackLabel, - leaderLine: spec.leaderLine, - total: spec.total - }; + const series = super._getDefaultSeriesSpec(spec); + series.bar = spec.bar; + series.stackLabel = spec.stackLabel; + series.leaderLine = spec.leaderLine; + series.total = spec.total; + + return series; } } diff --git a/packages/vchart/src/chart/word-cloud/3d/word-cloud-3d-transformer.ts b/packages/vchart/src/chart/word-cloud/3d/word-cloud-3d-transformer.ts index a29d765bd5..1a392bad14 100644 --- a/packages/vchart/src/chart/word-cloud/3d/word-cloud-3d-transformer.ts +++ b/packages/vchart/src/chart/word-cloud/3d/word-cloud-3d-transformer.ts @@ -6,35 +6,27 @@ export class WordCloud3dChartSpecTransformer< T extends IWordCloud3dChartSpec = IWordCloud3dChartSpec > extends BaseWordCloudChartSpecTransformer> { protected _getDefaultSeriesSpec(spec: IWordCloud3dChartSpec): any { - const series: any = { - ...super._getDefaultSeriesSpec(spec), - nameField: spec.nameField, - valueField: spec.valueField, - seriesField: spec.seriesField, - fontFamilyField: spec.fontFamilyField, - fontWeightField: spec.fontWeightField, - fontStyleField: spec.fontStyleField, - colorHexField: spec.colorHexField, - colorMode: spec.colorMode, - colorList: spec.colorList, - rotateAngles: spec.rotateAngles, - fontWeightRange: spec.fontWeightRange, - fontSizeRange: spec.fontSizeRange, - depth_3d: spec.depth_3d, - maskShape: spec.maskShape, - keepAspect: spec.keepAspect, - random: spec.random, - wordCloudConfig: spec.wordCloudConfig, - wordCloudShapeConfig: spec.wordCloudShapeConfig, - word: spec.word, - fillingWord: spec.fillingWord - }; - const seriesType = this.seriesType; - if (seriesType) { - series.type = seriesType; - series[seriesType] = spec[seriesType]; - } - + const series: any = super._getDefaultSeriesSpec(spec, [ + 'nameField', + 'valueField', + 'fontFamilyField', + 'fontWeightField', + 'fontStyleField', + 'colorHexField', + 'colorMode', + 'colorList', + 'rotateAngles', + 'fontWeightRange', + 'fontSizeRange', + 'depth_3d', + 'maskShape', + 'keepAspect', + 'random', + 'wordCloudConfig', + 'wordCloudShapeConfig', + 'word', + 'fillingWord' + ]); return series; } } diff --git a/packages/vchart/src/chart/word-cloud/word-cloud-transformer.ts b/packages/vchart/src/chart/word-cloud/word-cloud-transformer.ts index c10f42b59d..dc2f39f3d6 100644 --- a/packages/vchart/src/chart/word-cloud/word-cloud-transformer.ts +++ b/packages/vchart/src/chart/word-cloud/word-cloud-transformer.ts @@ -5,34 +5,27 @@ export class WordCloudChartSpecTransformer< T extends IWordCloudChartSpec = IWordCloudChartSpec > extends BaseWordCloudChartSpecTransformer { protected _getDefaultSeriesSpec(spec: IWordCloudChartSpec): any { - const series: any = { - ...super._getDefaultSeriesSpec(spec), - nameField: spec.nameField, - valueField: spec.valueField, - seriesField: spec.seriesField, - fontFamilyField: spec.fontFamilyField, - fontWeightField: spec.fontWeightField, - fontStyleField: spec.fontStyleField, - colorHexField: spec.colorHexField, - colorMode: spec.colorMode, - colorList: spec.colorList, - rotateAngles: spec.rotateAngles, - fontWeightRange: spec.fontWeightRange, - fontSizeRange: spec.fontSizeRange, - maskShape: spec.maskShape, - keepAspect: spec.keepAspect, - random: spec.random, - wordCloudConfig: spec.wordCloudConfig, - wordCloudShapeConfig: spec.wordCloudShapeConfig, - word: spec.word, - fillingWord: spec.fillingWord, - wordMask: spec.wordMask - }; - const seriesType = this.seriesType; - if (seriesType) { - series.type = seriesType; - series[seriesType] = spec[seriesType]; - } + const series: any = super._getDefaultSeriesSpec(spec, [ + 'nameField', + 'valueField', + 'fontFamilyField', + 'fontWeightField', + 'fontStyleField', + 'colorHexField', + 'colorMode', + 'colorList', + 'rotateAngles', + 'fontWeightRange', + 'fontSizeRange', + 'maskShape', + 'keepAspect', + 'random', + 'wordCloudConfig', + 'wordCloudShapeConfig', + 'word', + 'fillingWord', + 'wordMask' + ]); return series; } From 76f242beb5334bc2db45d9252c0142a5027061ec Mon Sep 17 00:00:00 2001 From: xile611 Date: Wed, 25 Dec 2024 11:24:47 +0800 Subject: [PATCH 4/6] perf: remove duplicated code --- .../chart/cartesian/cartesian-transformer.ts | 18 +----------------- .../src/chart/funnel/funnel-transformer.ts | 17 +---------------- .../vchart/src/chart/map/map-transformer.ts | 16 +--------------- .../chart/pictogram/pictogram-transformer.ts | 16 +--------------- 4 files changed, 4 insertions(+), 63 deletions(-) diff --git a/packages/vchart/src/chart/cartesian/cartesian-transformer.ts b/packages/vchart/src/chart/cartesian/cartesian-transformer.ts index 5064fefd33..89f4d3526a 100644 --- a/packages/vchart/src/chart/cartesian/cartesian-transformer.ts +++ b/packages/vchart/src/chart/cartesian/cartesian-transformer.ts @@ -37,23 +37,7 @@ export class CartesianChartSpecTransformer extend transformSpec(spec: T): void { super.transformSpec(spec); - - const defaultSeriesSpec = this._getDefaultSeriesSpec(spec); - - if (!spec.series || spec.series.length === 0) { - spec.series = [defaultSeriesSpec]; - } else { - spec.series.forEach((s: ISeriesSpec) => { - if (!this._isValidSeries(s.type)) { - return; - } - Object.keys(defaultSeriesSpec).forEach(k => { - if (!(k in s)) { - s[k] = defaultSeriesSpec[k]; - } - }); - }); - } + super.transformSeriesSpec(spec); this._transformAxisSpec(spec); } diff --git a/packages/vchart/src/chart/funnel/funnel-transformer.ts b/packages/vchart/src/chart/funnel/funnel-transformer.ts index 448a7fe491..1bec6eeee1 100644 --- a/packages/vchart/src/chart/funnel/funnel-transformer.ts +++ b/packages/vchart/src/chart/funnel/funnel-transformer.ts @@ -32,21 +32,6 @@ export class FunnelChartSpecTransformer extends Base } transformSpec(spec: T): void { super.transformSpec(spec); - - const defaultSeriesSpec = this._getDefaultSeriesSpec(spec); - if (!spec.series || spec.series.length === 0) { - spec.series = [defaultSeriesSpec]; - } else { - spec.series.forEach((s: ISeriesSpec) => { - if (!this._isValidSeries(s.type)) { - return; - } - Object.keys(defaultSeriesSpec).forEach(k => { - if (!(k in s)) { - s[k] = defaultSeriesSpec[k]; - } - }); - }); - } + super.transformSeriesSpec(spec); } } diff --git a/packages/vchart/src/chart/map/map-transformer.ts b/packages/vchart/src/chart/map/map-transformer.ts index 2882eb644f..3c3a24410c 100644 --- a/packages/vchart/src/chart/map/map-transformer.ts +++ b/packages/vchart/src/chart/map/map-transformer.ts @@ -32,20 +32,6 @@ export class MapChartSpecTransformer ex r.coordinate = 'geo'; }); - const defaultSeriesSpec = this._getDefaultSeriesSpec(spec); - if (!spec.series || spec.series.length === 0) { - spec.series = [defaultSeriesSpec]; - } else { - spec.series.forEach((s: ISeriesSpec) => { - if (!this._isValidSeries(s.type)) { - return; - } - Object.keys(defaultSeriesSpec).forEach(k => { - if (!(k in s)) { - s[k] = defaultSeriesSpec[k]; - } - }); - }); - } + super.transformSeriesSpec(spec); } } diff --git a/packages/vchart/src/chart/pictogram/pictogram-transformer.ts b/packages/vchart/src/chart/pictogram/pictogram-transformer.ts index 23ae299515..60cf8678c5 100644 --- a/packages/vchart/src/chart/pictogram/pictogram-transformer.ts +++ b/packages/vchart/src/chart/pictogram/pictogram-transformer.ts @@ -30,20 +30,6 @@ export class PictogramChartSpecTransformer< r.coordinate = 'geo'; }); - const defaultSeriesSpec = this._getDefaultSeriesSpec(spec); - if (!spec.series || spec.series.length === 0) { - spec.series = [defaultSeriesSpec]; - } else { - spec.series.forEach((s: ISeriesSpec) => { - if (!this._isValidSeries(s.type)) { - return; - } - Object.keys(defaultSeriesSpec).forEach(k => { - if (!(k in s)) { - s[k] = defaultSeriesSpec[k]; - } - }); - }); - } + super.transformSeriesSpec(spec); } } From 379d57740119b2376782714a255e19be3cc65380 Mon Sep 17 00:00:00 2001 From: xile611 Date: Wed, 25 Dec 2024 17:31:45 +0800 Subject: [PATCH 5/6] perf: remove duplicated code in spec transformer of word-cloud --- .../3d/word-cloud-3d-transformer.ts | 24 ++------------ .../base/word-cloud-base-transformer.ts | 26 +++++++++++++++ packages/vchart/src/chart/word-cloud/index.ts | 1 - .../word-cloud/word-cloud-transformer.ts | 32 ------------------- .../vchart/src/chart/word-cloud/word-cloud.ts | 8 ++--- 5 files changed, 33 insertions(+), 58 deletions(-) delete mode 100644 packages/vchart/src/chart/word-cloud/word-cloud-transformer.ts diff --git a/packages/vchart/src/chart/word-cloud/3d/word-cloud-3d-transformer.ts b/packages/vchart/src/chart/word-cloud/3d/word-cloud-3d-transformer.ts index 1a392bad14..674e5c517b 100644 --- a/packages/vchart/src/chart/word-cloud/3d/word-cloud-3d-transformer.ts +++ b/packages/vchart/src/chart/word-cloud/3d/word-cloud-3d-transformer.ts @@ -6,27 +6,9 @@ export class WordCloud3dChartSpecTransformer< T extends IWordCloud3dChartSpec = IWordCloud3dChartSpec > extends BaseWordCloudChartSpecTransformer> { protected _getDefaultSeriesSpec(spec: IWordCloud3dChartSpec): any { - const series: any = super._getDefaultSeriesSpec(spec, [ - 'nameField', - 'valueField', - 'fontFamilyField', - 'fontWeightField', - 'fontStyleField', - 'colorHexField', - 'colorMode', - 'colorList', - 'rotateAngles', - 'fontWeightRange', - 'fontSizeRange', - 'depth_3d', - 'maskShape', - 'keepAspect', - 'random', - 'wordCloudConfig', - 'wordCloudShapeConfig', - 'word', - 'fillingWord' - ]); + const series: any = super._getDefaultSeriesSpec(spec as any); + series.depth_3d = spec.depth_3d; + return series; } } diff --git a/packages/vchart/src/chart/word-cloud/base/word-cloud-base-transformer.ts b/packages/vchart/src/chart/word-cloud/base/word-cloud-base-transformer.ts index 874a688cca..d82b05ede8 100644 --- a/packages/vchart/src/chart/word-cloud/base/word-cloud-base-transformer.ts +++ b/packages/vchart/src/chart/word-cloud/base/word-cloud-base-transformer.ts @@ -6,4 +6,30 @@ export class BaseWordCloudChartSpecTransformer ex super.transformSpec(spec); this.transformSeriesSpec(spec); } + + protected _getDefaultSeriesSpec(spec: T): any { + const series: any = super._getDefaultSeriesSpec(spec, [ + 'nameField', + 'valueField', + 'fontFamilyField', + 'fontWeightField', + 'fontStyleField', + 'colorHexField', + 'colorMode', + 'colorList', + 'rotateAngles', + 'fontWeightRange', + 'fontSizeRange', + 'maskShape', + 'keepAspect', + 'random', + 'wordCloudConfig', + 'wordCloudShapeConfig', + 'word', + 'fillingWord', + 'wordMask' + ]); + + return series; + } } diff --git a/packages/vchart/src/chart/word-cloud/index.ts b/packages/vchart/src/chart/word-cloud/index.ts index cf1e8d06d8..250bcece96 100644 --- a/packages/vchart/src/chart/word-cloud/index.ts +++ b/packages/vchart/src/chart/word-cloud/index.ts @@ -1,4 +1,3 @@ export * from './word-cloud'; export * from './3d'; export * from './interface'; -export * from './word-cloud-transformer'; diff --git a/packages/vchart/src/chart/word-cloud/word-cloud-transformer.ts b/packages/vchart/src/chart/word-cloud/word-cloud-transformer.ts deleted file mode 100644 index dc2f39f3d6..0000000000 --- a/packages/vchart/src/chart/word-cloud/word-cloud-transformer.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { BaseWordCloudChartSpecTransformer } from './base'; -import type { IWordCloudChartSpec } from './interface'; - -export class WordCloudChartSpecTransformer< - T extends IWordCloudChartSpec = IWordCloudChartSpec -> extends BaseWordCloudChartSpecTransformer { - protected _getDefaultSeriesSpec(spec: IWordCloudChartSpec): any { - const series: any = super._getDefaultSeriesSpec(spec, [ - 'nameField', - 'valueField', - 'fontFamilyField', - 'fontWeightField', - 'fontStyleField', - 'colorHexField', - 'colorMode', - 'colorList', - 'rotateAngles', - 'fontWeightRange', - 'fontSizeRange', - 'maskShape', - 'keepAspect', - 'random', - 'wordCloudConfig', - 'wordCloudShapeConfig', - 'word', - 'fillingWord', - 'wordMask' - ]); - - return series; - } -} diff --git a/packages/vchart/src/chart/word-cloud/word-cloud.ts b/packages/vchart/src/chart/word-cloud/word-cloud.ts index c2940c2bbf..07b630f699 100644 --- a/packages/vchart/src/chart/word-cloud/word-cloud.ts +++ b/packages/vchart/src/chart/word-cloud/word-cloud.ts @@ -1,17 +1,17 @@ import { SeriesTypeEnum } from '../../series/interface/type'; import { ChartTypeEnum } from '../interface/type'; // eslint-disable-next-line no-duplicate-imports -import type { IWordCloudChartSpec } from './interface'; +import { IWordCloudChartSpec } from './interface'; import { BaseWordCloudChart } from './base/base'; import { registerWordCloudSeries, registerWordCloudShapeSeries } from '../../series/word-cloud/word-cloud'; import { Factory } from '../../core/factory'; -import { WordCloudChartSpecTransformer } from './word-cloud-transformer'; +import { BaseWordCloudChartSpecTransformer } from './base/word-cloud-base-transformer'; export class WordCloudChart extends BaseWordCloudChart { static readonly type: string = ChartTypeEnum.wordCloud; static readonly seriesType: string = SeriesTypeEnum.wordCloud; - static readonly transformerConstructor = WordCloudChartSpecTransformer; - readonly transformerConstructor = WordCloudChartSpecTransformer; + static readonly transformerConstructor = BaseWordCloudChartSpecTransformer; + readonly transformerConstructor = BaseWordCloudChartSpecTransformer; readonly type: string = ChartTypeEnum.wordCloud; readonly seriesType: string = SeriesTypeEnum.wordCloud; } From a5f430833bcd4404a26d590ffaa14dc1dd59c4e2 Mon Sep 17 00:00:00 2001 From: xile611 Date: Wed, 25 Dec 2024 18:36:40 +0800 Subject: [PATCH 6/6] fix: fix box-plot-transformer --- packages/vchart/src/chart/box-plot/box-plot-transformer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vchart/src/chart/box-plot/box-plot-transformer.ts b/packages/vchart/src/chart/box-plot/box-plot-transformer.ts index 57ff3163a1..1e70e5a5bf 100644 --- a/packages/vchart/src/chart/box-plot/box-plot-transformer.ts +++ b/packages/vchart/src/chart/box-plot/box-plot-transformer.ts @@ -18,8 +18,8 @@ export class BoxPlotChartSpecTransformer< 'outliersField', 'outliersStyle' ]); - (seriesSpec.direction = spec.direction ?? Direction.vertical), - (seriesSpec[seriesSpec.direction === Direction.horizontal ? 'xField' : 'yField'] = dataFields); + seriesSpec.direction = spec.direction ?? Direction.vertical; + seriesSpec[seriesSpec.direction === Direction.horizontal ? 'xField' : 'yField'] = dataFields; return seriesSpec; }