Skip to content

Commit b30d9f1

Browse files
committed
fix: fix vchart spec when leafSpec is simple type
1 parent e441972 commit b30d9f1

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

packages/vmind/__tests__/unit/vchartSpec/bar.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,22 @@ describe('mergeAppendSpec of barchart', () => {
295295
}
296296
]);
297297
});
298+
299+
it('should contain all spec when spec has more than one path', () => {
300+
const append = {
301+
leafSpec: {
302+
mark: {
303+
maxLineCount: 20
304+
},
305+
dimension: {
306+
maxLineCount: 20
307+
}
308+
},
309+
parentKeyPath: 'tooltip',
310+
aliasKeyPath: 'tooltip'
311+
};
312+
313+
const { newSpec } = mergeAppendSpec(merge({}, spec), append);
314+
expect(newSpec.tooltip).toEqual(append.leafSpec);
315+
});
298316
});

packages/vmind/src/atom/VChartSpec/index.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { BaseOptions } from '../type';
33
import { BaseAtom } from '../base';
44
import type { VChartSpecCtx } from '../../types';
55
import { mergeAppendSpec } from './utils';
6+
import { isNil } from '@visactor/vutils';
67

78
export class VChartSpec extends BaseAtom<VChartSpecCtx, BaseOptions> {
89
name = AtomName.VCHART_SPEC;
@@ -29,15 +30,13 @@ export class VChartSpec extends BaseAtom<VChartSpecCtx, BaseOptions> {
2930
return this.context;
3031
}
3132

32-
if (!appendSpec || !appendSpec.leafSpec) {
33-
return this.context;
34-
}
33+
if (appendSpec && 'leafSpec' in appendSpec) {
34+
const { newSpec, code } = mergeAppendSpec(this.context.spec, appendSpec);
3535

36-
const { newSpec, code } = mergeAppendSpec(this.context.spec, appendSpec);
37-
38-
this.context.appendCode = code;
39-
this.context.prevSpec = this.context.spec;
40-
this.context.spec = newSpec;
36+
this.context.appendCode = code;
37+
this.context.prevSpec = this.context.spec;
38+
this.context.spec = newSpec;
39+
}
4140

4241
return this.context;
4342
}

0 commit comments

Comments
 (0)