Skip to content

An open source alternative to Tableau. Embeddable visual analytic

fix: pivot table var number limit (#345)

Elwynn Chen2b80169e3696
diff --git a/packages/graphic-walker/src/lib/gog.ts b/packages/graphic-walker/src/lib/gog.ts
index 90e6d82d..2d69c595 100644
--- a/packages/graphic-walker/src/lib/gog.ts
+++ b/packages/graphic-walker/src/lib/gog.ts
@@ -57,13 +57,14 @@ function applyOperations<T>(initialValue: T, operators: Operator<T>[]): T {
* @param encodings
* @returns
*/
-export function algebraLint<T extends Partial<DraggableFieldState>>(encodings: T): Partial<T> {
+export function algebraLint<T extends Partial<DraggableFieldState>>(geom: string, encodings: T): Partial<T> {
+
const result: Partial<T> = {};
if (encodings.rows && encodings.rows.length > 0) {
- result.rows = applyOperations(encodings.rows, [LR.measureAfterDimension, LR.crossLimit(2)]);
+ result.rows = applyOperations(encodings.rows, [LR.measureAfterDimension, LR.crossLimit(geom === 'table' ? Infinity : 2)]);
}
if (encodings.columns && encodings.columns.length > 0) {
- result.columns = applyOperations(encodings.columns, [LR.measureAfterDimension, LR.crossLimit(2)]);
+ result.columns = applyOperations(encodings.columns, [LR.measureAfterDimension, LR.crossLimit(geom === 'table' ? Infinity : 2)]);
}
if (encodings.latitude && encodings.latitude.length > 0) {
result.latitude = applyOperations(encodings.latitude, [LR.forceAnalyticType('dimension'), LR.forceSemanticType('quantitative'), LR.crossLimit(1)]);
diff --git a/packages/graphic-walker/src/models/visSpecHistory.ts b/packages/graphic-walker/src/models/visSpecHistory.ts
index f754b253..630ef0e0 100644
--- a/packages/graphic-walker/src/models/visSpecHistory.ts
+++ b/packages/graphic-walker/src/models/visSpecHistory.ts
@@ -21,7 +21,7 @@ import {
IDefaultConfig,
} from '../interfaces';
import type { FeatureCollection } from 'geojson';
-import { createCountField, createVirtualFields, isNotEmpty } from '../utils';
+import { arrayEqual, createCountField, createVirtualFields, isNotEmpty } from '../utils';
import { emptyEncodings, emptyVisualConfig, emptyVisualLayout, visSpecDecoder, forwardVisualConfigs } from '../utils/save';
import { AssertSameKey, KVTuple, insert, mutPath, remove, replace, uniqueId } from './utils';
import { WithHistory, atWith, create, freeze, performWith, redoWith, undoWith } from './withHistory';
@@ -504,8 +504,12 @@ type reducerMiddleware<T> = (item: T, original: T) => T;
const diffLinter: reducerMiddleware<IChart> = (item, original) => {
const diffs = diffChangedEncodings(original, item);
- if (Object.keys(diffs).length === 0) return item;
- return mutPath(item, 'encodings', (x) => ({ ...x, ...algebraLint(diffs), ...lintExtraFields(diffs) }));
+ const geom = item.config.geoms[0];
+ if (Object.keys(diffs).length === 0 && arrayEqual(item.config.geoms, original.config.geoms)) return item;
+ if (!arrayEqual(item.config.geoms, original.config.geoms)) {
+ return mutPath(item, 'encodings', (x) => ({ ...x, ...algebraLint(geom, x), ...lintExtraFields(x) }));
+ }
+ return mutPath(item, 'encodings', (x) => ({ ...x, ...algebraLint(geom, diffs), ...lintExtraFields(diffs) }));
};
const reducerMiddleWares: reducerMiddleware<IChart>[] = [diffLinter];
diff --git a/packages/graphic-walker/src/utils/index.ts b/packages/graphic-walker/src/utils/index.ts
index 1c39df97..a08335c0 100644
--- a/packages/graphic-walker/src/utils/index.ts
+++ b/packages/graphic-walker/src/utils/index.ts
@@ -415,3 +415,15 @@ export function _unstable_encodeRuleValue(value: any) {
}
return value;
}
+
+export function arrayEqual (list1: any[], list2: any[]): boolean {
+ if (list1.length !== list2.length) {
+ return false;
+ }
+ for (let i = 0; i < list1.length; i++) {
+ if (list1[i] !== list2[i]) {
+ return false;
+ }
+ }
+ return true;
+}
diff --git a/packages/graphic-walker/src/vis/spec/mark.ts b/packages/graphic-walker/src/vis/spec/mark.ts
index f62b6d90..0fcd25b1 100644
--- a/packages/graphic-walker/src/vis/spec/mark.ts
+++ b/packages/graphic-walker/src/vis/spec/mark.ts
@@ -2,19 +2,19 @@ import { ISemanticType } from "../../interfaces";
/**
*
- * @param semanticTypeList semanticTypeList.length <= 2,调用时,手动将columns 和 rows的最后一个元素组合传进来
+ * @param subViewFieldsSemanticTypes subViewFieldsSemanticTypes.length <= 2, subView means the single view visualization in facet system, we only need to consider the semantic types of the fields in the subView
* @returns geom(mark) type
*/
-export function autoMark(semanticTypeList: ISemanticType[]): string {
- if (semanticTypeList.length < 2) {
- if (semanticTypeList[0] === "temporal" || semanticTypeList[0] === 'quantitative') return "tick";
+export function autoMark(subViewFieldsSemanticTypes: ISemanticType[]): string {
+ if (subViewFieldsSemanticTypes.length < 2) {
+ if (subViewFieldsSemanticTypes[0] === "temporal" || subViewFieldsSemanticTypes[0] === 'quantitative') return "tick";
return "bar";
}
const couter: Map<ISemanticType, number> = new Map();
(["nominal", "ordinal", "quantitative", "temporal"] as ISemanticType[]).forEach((s) => {
couter.set(s, 0);
});
- for (let st of semanticTypeList) {
+ for (let st of subViewFieldsSemanticTypes) {
couter.set(st, couter.get(st)! + 1);
}
if (couter.get("nominal") === 1 || couter.get("ordinal") === 1) {