Skip to content

Commit

Permalink
fix: liquid data is not in object form antvis #6145 (#6379)
Browse files Browse the repository at this point in the history
* 同步代码

* docs: migrate 4.0 Simple Rose diagram (#5900)

* docs: add bar range demo #6276

* docs: add bar-range screenshot

* fix: the liquid demo value of docs is NaN #6145

* fix: liquid data is not in object form #6145

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

* test: liquid number #6145

* fix: liquid data is not in object form #6145

* fix: liquid data is not in object form #6145

---------

Co-authored-by: zhenglingpeng <2472931959@qq.com>
  • Loading branch information
the-lemonboy and zhenglingpeng authored Jul 23, 2024
1 parent 633b291 commit 1aabab7
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 8 deletions.
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;
}

0 comments on commit 1aabab7

Please sign in to comment.