diff --git a/__tests__/plots/static/index.ts b/__tests__/plots/static/index.ts index 7f3fce3719..cfd9d2620a 100644 --- a/__tests__/plots/static/index.ts +++ b/__tests__/plots/static/index.ts @@ -301,6 +301,7 @@ export { liquidDiamond } from './liquid-diamond'; export { liquidContent } from './liquid-content'; export { liquidTriangle } from './liquid-triangle'; export { liquidCustomShape } from './liquid-custom-shape'; +export { liquidNumber } from './liquid-number'; export { alphabetIntervalAxisOptions } from './alphabet-interval-axis-options'; export { profitIntervalAxisTransform } from './profit-interval-axis-transform'; export { intervalPointBullet } from './interval-point-bullet'; diff --git a/__tests__/plots/static/liquid-number.ts b/__tests__/plots/static/liquid-number.ts new file mode 100644 index 0000000000..9509ac981b --- /dev/null +++ b/__tests__/plots/static/liquid-number.ts @@ -0,0 +1,11 @@ +import { G2Spec } from '../../../src'; + +export function liquidNumber(): G2Spec { + return { + type: 'view', + data: 0.3, + children: [{ type: 'liquid' }], + }; +} + +liquidNumber.skip = true; diff --git a/site/docs/spec/mark/liquid.zh.md b/site/docs/spec/mark/liquid.zh.md index 5b84174de3..ed1e016226 100644 --- a/site/docs/spec/mark/liquid.zh.md +++ b/site/docs/spec/mark/liquid.zh.md @@ -20,7 +20,7 @@ const chart = new Chart({ chart .liquid() - .data({value:.3}) + .data(0.3) .style({ outlineBorder: 4, outlineDistance: 8, diff --git a/site/examples/general/Liquid/demo/liquid-background.ts b/site/examples/general/Liquid/demo/liquid-background.ts index 13c239fada..1e7d628e76 100644 --- a/site/examples/general/Liquid/demo/liquid-background.ts +++ b/site/examples/general/Liquid/demo/liquid-background.ts @@ -5,7 +5,7 @@ const chart = new Chart({ autoFit: true, }); -chart.liquid().data({ value: 0.3 }).style({ +chart.liquid().data(0.3).style({ backgroundFill: 'pink', }); diff --git a/site/examples/general/Liquid/demo/liquid-content.ts b/site/examples/general/Liquid/demo/liquid-content.ts index 74ffa9f5bf..e7f9051395 100644 --- a/site/examples/general/Liquid/demo/liquid-content.ts +++ b/site/examples/general/Liquid/demo/liquid-content.ts @@ -5,7 +5,7 @@ const chart = new Chart({ autoFit: true, }); -chart.liquid().data({ value: 0.581 }).style({ +chart.liquid().data(0.581).style({ contentFill: '#000', contentText: 'center text', contentStroke: '#fff', diff --git a/site/examples/general/Liquid/demo/liquid-custom-shape.ts b/site/examples/general/Liquid/demo/liquid-custom-shape.ts index df74ca9c17..4b45d05900 100644 --- a/site/examples/general/Liquid/demo/liquid-custom-shape.ts +++ b/site/examples/general/Liquid/demo/liquid-custom-shape.ts @@ -7,7 +7,7 @@ const chart = new Chart({ chart .liquid() - .data({ value: 0.3 }) + .data(0.3) .style({ shape: (x, y, r) => { const path = []; diff --git a/site/examples/general/Liquid/demo/liquid-default.ts b/site/examples/general/Liquid/demo/liquid-default.ts index 3c946e1380..1fb475480d 100644 --- a/site/examples/general/Liquid/demo/liquid-default.ts +++ b/site/examples/general/Liquid/demo/liquid-default.ts @@ -5,7 +5,7 @@ const chart = new Chart({ autoFit: true, }); -chart.liquid().data({ value: 0.3 }).style({ +chart.liquid().data(0.3).style({ outlineBorder: 4, outlineDistance: 8, waveLength: 128, diff --git a/site/examples/general/Liquid/demo/liquid-pin.ts b/site/examples/general/Liquid/demo/liquid-pin.ts index 06b6b22559..b9b3e4b9cb 100644 --- a/site/examples/general/Liquid/demo/liquid-pin.ts +++ b/site/examples/general/Liquid/demo/liquid-pin.ts @@ -5,7 +5,7 @@ const chart = new Chart({ autoFit: true, }); -chart.liquid().data({ value: 0.581 }).style({ +chart.liquid().data(0.581).style({ shape: 'pin', // Build-in shapes: rect, circle, pin, diamond, triangle. contentFill: '#fff', outlineBorder: 4, diff --git a/src/composition/utils.ts b/src/composition/utils.ts index f3edf48f10..83aaae7a71 100644 --- a/src/composition/utils.ts +++ b/src/composition/utils.ts @@ -16,12 +16,20 @@ export function useOverrideAdaptor(adaptor: Adapter): Adapter { return (options?, ...rest) => deepMix({}, options, adaptor(options, ...rest)); } +export function isObject(d) { + if (d instanceof Date) return false; + return typeof d === 'object'; +} + export function mergeData( dataDescriptor: any[] | { value: any; [key: string]: any }, dataValue: any[], ) { if (!dataDescriptor) return dataValue; if (Array.isArray(dataDescriptor)) return dataDescriptor; - const { value = dataValue, ...rest } = dataDescriptor; - return { ...rest, value }; + if (isObject(dataDescriptor)) { + const { value = dataValue, ...rest } = dataDescriptor; + return { ...rest, value }; + } + return dataDescriptor; }