An open source alternative to Tableau. Embeddable visual analytic
TypeScript bidatadata-analysisdata-miningdata-visualizationedak6skanarieslow-codepivot-tablereacttableautableau-alternativetypescriptvegavega-litevisualization
fix: aggergation computed field with fold (#292)
islxyqwe71b055d09233
diff --git a/packages/graphic-walker/src/interfaces.ts b/packages/graphic-walker/src/interfaces.tsindex bd9f7f02..d45d3861 100644--- a/packages/graphic-walker/src/interfaces.ts+++ b/packages/graphic-walker/src/interfaces.ts@@ -188,7 +188,7 @@ export interface IField {*/name: string;/**- * aggregator's name+ * aggregator's name, "expr" represents for aggergated computed field.*/aggName?: string;semanticType: ISemanticType;diff --git a/packages/graphic-walker/src/lib/op/fold.ts b/packages/graphic-walker/src/lib/op/fold.tsindex bf36596a..4128bbde 100644--- a/packages/graphic-walker/src/lib/op/fold.ts+++ b/packages/graphic-walker/src/lib/op/fold.ts@@ -18,6 +18,16 @@ export function fold(data: IRow[], query: IFoldQuery): IRow[] {return ans;}+export function replaceAggForFold<T extends { aggName?: string }>(x: T, newAggName?: string) {+ if (x.aggName === 'expr') {+ return x;+ }+ return {+ ...x,+ aggName: newAggName,+ };+}+export function fold2(data: IRow,defaultAggregated: boolean,@@ -36,9 +46,10 @@ export function fold2(.filter(Boolean).map((x) => {if (defaultAggregated) {+ const fieldWithReplacedAgg = replaceAggForFold(x, meaVal.aggName);return {- name: getMeaAggName(x.name, meaVal.aggName),- fid: getMeaAggKey(x.fid, meaVal.aggName),+ name: getMeaAggName(fieldWithReplacedAgg.name, fieldWithReplacedAgg.aggName),+ fid: getMeaAggKey(fieldWithReplacedAgg.name, fieldWithReplacedAgg.aggName),};}return { name: x.name, fid: x.fid };diff --git a/packages/graphic-walker/src/utils/workflow.ts b/packages/graphic-walker/src/utils/workflow.tsindex 8d1e1c10..1817205d 100644--- a/packages/graphic-walker/src/utils/workflow.ts+++ b/packages/graphic-walker/src/utils/workflow.ts@@ -19,6 +19,7 @@ import { getFilterMeaAggKey, getMeaAggKey, getSort } from '.';import { MEA_KEY_ID, MEA_VAL_ID } from '../constants';import { decodeVisSpec } from '../models/visSpecHistory';import { replaceFid, walkFid } from '../lib/sql';+import { replaceAggForFold } from '../lib/op/fold';const walkExpression = (expression: IExpression, each: (field: string) => void): void => {for (const param of expression.params) {@@ -82,8 +83,8 @@ export const toWorkflow = (const aggName = viewMeasuresRaw.find((x) => x.fid === MEA_VAL_ID)!.aggName;const newFields = folds.map((k) => allFields.find((x) => x.fid === k)!)- .map((x) => ({ ...x, aggName }))- .filter(Boolean);+ .filter(Boolean)+ .map((x) => replaceAggForFold(x, aggName));viewDimensions.push(...newFields.filter((x) => x?.analyticType === 'dimension'));viewMeasures.push(...newFields.filter((x) => x?.analyticType === 'measure'));}@@ -242,7 +243,7 @@ export const toWorkflow = (query: [{op: 'raw',- fields: [...new Set([...viewDimensions, ...viewMeasures])].map((f) => f.fid),+ fields: [...new Set([...viewDimensions, ...viewMeasures])].filter(f => f.aggName !== 'expr').map((f) => f.fid),},],};