diff --git a/__tests__/plots/static/gauge-default.ts b/__tests__/plots/static/gauge-default.ts index 15fd6bfba2..c0616c6cfc 100644 --- a/__tests__/plots/static/gauge-default.ts +++ b/__tests__/plots/static/gauge-default.ts @@ -2,7 +2,8 @@ import { G2Spec } from '../../../src'; export function gaugeDefault(): G2Spec { return { - type: 'gauge', + type: 'view', + legend: false, data: { value: { target: 120, @@ -10,5 +11,6 @@ export function gaugeDefault(): G2Spec { name: 'score', }, }, + children: [{ type: 'gauge' }], }; } diff --git a/src/runtime/plot.ts b/src/runtime/plot.ts index eda2538967..f3f0f21997 100644 --- a/src/runtime/plot.ts +++ b/src/runtime/plot.ts @@ -500,8 +500,16 @@ async function transformMarks( const { composite = true } = props; if (!composite) flattenMarks.push(mark); else { + // Unwrap data from { value: data } to data, + // then the composite mark can process the normalized data. + const { data } = mark; + const newMark = { + ...mark, + data: data ? (Array.isArray(data) ? data : data.value) : data, + }; + // Convert composite mark to marks. - const marks = await useMark(mark, context); + const marks = await useMark(newMark, context); const M = Array.isArray(marks) ? marks : [marks]; discovered.unshift(...M.map((d, i) => ({ ...d, key: `${key}-${i}` }))); } diff --git a/src/runtime/transform.ts b/src/runtime/transform.ts index f7b94394e1..9b16e1a2e5 100644 --- a/src/runtime/transform.ts +++ b/src/runtime/transform.ts @@ -42,9 +42,20 @@ export async function applyDataTransform( const transform = [connector, ...T]; const transformFunctions = transform.map(useData); const transformedData = await composeAsync(transformFunctions)(data); + + // Maintain the consistency of shape between input and output data. + // If the shape of raw data is like { value: any } + // and the returned transformedData is Object, + // returns the wrapped data: { value: transformedData }, + // otherwise returns the processed tabular data. + const newData = + data && !Array.isArray(data) && !Array.isArray(transformedData) + ? { value: transformedData } + : transformedData; + return [ Array.isArray(transformedData) ? indexOf(transformedData) : [], - { ...mark, data: transformedData }, + { ...mark, data: newData }, ]; }