diff --git a/packages/vmind/__tests__/unit/vchartSpec/bar.test.ts b/packages/vmind/__tests__/unit/vchartSpec/bar.test.ts index 656a16d..c9eb1ee 100644 --- a/packages/vmind/__tests__/unit/vchartSpec/bar.test.ts +++ b/packages/vmind/__tests__/unit/vchartSpec/bar.test.ts @@ -295,4 +295,22 @@ describe('mergeAppendSpec of barchart', () => { } ]); }); + + it('should contain all spec when spec has more than one path', () => { + const append = { + leafSpec: { + mark: { + maxLineCount: 20 + }, + dimension: { + maxLineCount: 20 + } + }, + parentKeyPath: 'tooltip', + aliasKeyPath: 'tooltip' + }; + + const { newSpec } = mergeAppendSpec(merge({}, spec), append); + expect(newSpec.tooltip).toEqual(append.leafSpec); + }); }); diff --git a/packages/vmind/src/atom/VChartSpec/index.ts b/packages/vmind/src/atom/VChartSpec/index.ts index 453a859..96e2678 100644 --- a/packages/vmind/src/atom/VChartSpec/index.ts +++ b/packages/vmind/src/atom/VChartSpec/index.ts @@ -3,6 +3,7 @@ import type { BaseOptions } from '../type'; import { BaseAtom } from '../base'; import type { VChartSpecCtx } from '../../types'; import { mergeAppendSpec } from './utils'; +import { isNil } from '@visactor/vutils'; export class VChartSpec extends BaseAtom { name = AtomName.VCHART_SPEC; @@ -29,15 +30,13 @@ export class VChartSpec extends BaseAtom { return this.context; } - if (!appendSpec || !appendSpec.leafSpec) { - return this.context; - } + if (appendSpec && 'leafSpec' in appendSpec) { + const { newSpec, code } = mergeAppendSpec(this.context.spec, appendSpec); - const { newSpec, code } = mergeAppendSpec(this.context.spec, appendSpec); - - this.context.appendCode = code; - this.context.prevSpec = this.context.spec; - this.context.spec = newSpec; + this.context.appendCode = code; + this.context.prevSpec = this.context.spec; + this.context.spec = newSpec; + } return this.context; }