Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: liquid data is not in object form antvis #6145 #6379

Merged
merged 13 commits into from
Jul 23, 2024
1 change: 1 addition & 0 deletions __tests__/plots/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
11 changes: 11 additions & 0 deletions __tests__/plots/static/liquid-number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { G2Spec } from '../../../src';

export function liquidNumber(): G2Spec {
return {
type: 'view',
data: 0.3,
children: [{ type: 'liquid' }],
};
}

liquidNumber.skip = true;
2 changes: 1 addition & 1 deletion site/docs/spec/mark/liquid.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const chart = new Chart({

chart
.liquid()
.data({value:.3})
.data(0.3)
.style({
outlineBorder: 4,
outlineDistance: 8,
Expand Down
2 changes: 1 addition & 1 deletion site/examples/general/Liquid/demo/liquid-background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});

Expand Down
2 changes: 1 addition & 1 deletion site/examples/general/Liquid/demo/liquid-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion site/examples/general/Liquid/demo/liquid-custom-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const chart = new Chart({

chart
.liquid()
.data({ value: 0.3 })
.data(0.3)
.style({
shape: (x, y, r) => {
const path = [];
Expand Down
2 changes: 1 addition & 1 deletion site/examples/general/Liquid/demo/liquid-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion site/examples/general/Liquid/demo/liquid-pin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 10 additions & 2 deletions src/composition/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@ export function useOverrideAdaptor<T>(adaptor: Adapter<T>): Adapter<T> {
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;
}
Loading