From 77ce22e8d8ac4cbb37c19879659df729e67422b1 Mon Sep 17 00:00:00 2001 From: JessamineQ Date: Mon, 22 Apr 2024 02:01:10 -0400 Subject: [PATCH] fix: for issue when there are multiple aggregates for same data field and aggregation operation --- src/compile/data/aggregate.ts | 3 ++- test/compile/compile.test.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/compile/data/aggregate.ts b/src/compile/data/aggregate.ts index a8a9cefba1..87b73ecabd 100644 --- a/src/compile/data/aggregate.ts +++ b/src/compile/data/aggregate.ts @@ -164,7 +164,8 @@ export class AggregateNode extends DataFlowNode { meas['*']['count'] = new Set([as ? as : vgField(s, {forAs: true})]); } else { meas[field] ??= {}; - meas[field][op] = new Set([as ? as : vgField(s, {forAs: true})]); + meas[field][op] ??= new Set(); + meas[field][op].add(as ? as : vgField(s, {forAs: true})); } } } diff --git a/test/compile/compile.test.ts b/test/compile/compile.test.ts index e4667bdc07..3991e35bc9 100644 --- a/test/compile/compile.test.ts +++ b/test/compile/compile.test.ts @@ -1,3 +1,4 @@ +import {AggregateTransform} from 'vega'; import {compile} from '../../src/compile/compile'; import * as log from '../../src/log'; @@ -573,3 +574,21 @@ describe('compile/compile', () => { expect(spec.autosize['resize']).toBeTruthy(); }); }); + +it('should generate right tooltip', () => { + const {spec} = compile({ + data: {url: 'data/population.json'}, + mark: 'errorband', + encoding: { + x: {field: 'age', type: 'ordinal'}, + y: {field: 'people', type: 'quantitative'}, + tooltip: {field: 'people', aggregate: 'mean'} + } + }); + + expect((spec.data[0].transform[0] as AggregateTransform).as as string[]).toEqual([ + 'mean_people', + 'center_people', + 'extent_people' + ]); +});