Skip to content

An open source alternative to Tableau. Embeddable visual analytic

fix: analytic type transform bug (#175)

Observed Observer1d065fd31a8f
diff --git a/.github/workflows/auto-build.yml b/.github/workflows/auto-build.yml
index 3ffd8fc1..42368ded 100644
--- a/.github/workflows/auto-build.yml
+++ b/.github/workflows/auto-build.yml
@@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- node-version: [16.x]
+ node-version: [16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
diff --git a/packages/graphic-walker/package.json b/packages/graphic-walker/package.json
index 839f05e6..843feef8 100644
--- a/packages/graphic-walker/package.json
+++ b/packages/graphic-walker/package.json
@@ -1,6 +1,6 @@
{
"name": "@kanaries/graphic-walker",
- "version": "0.4.15",
+ "version": "0.4.16",
"scripts": {
"dev:front_end": "vite --host",
"dev": "npm run dev:front_end",
diff --git a/packages/graphic-walker/src/models/field.ts b/packages/graphic-walker/src/models/field.ts
new file mode 100644
index 00000000..cd0a4df7
--- /dev/null
+++ b/packages/graphic-walker/src/models/field.ts
@@ -0,0 +1,39 @@
+import { IField } from "../interfaces";
+
+// TODO: make property with couping effect as readonly, and implements a setFunction to edit those prop with those effects.
+export class Field<T extends IField> {
+ protected _field: T;
+ constructor (f: T) {
+ this._field = f;
+ }
+ public asDimension (): T {
+ this._field.analyticType = 'dimension';
+ return this._field
+ }
+ public asMeasure (): T {
+ this._field.analyticType = 'measure';
+ this._field.aggName = 'sum';
+ this._field.semanticType = 'quantitative'
+ return this._field
+ }
+ public asGeo(role: T['geoRole']): T {
+ this._field.geoRole = role;
+ if (role === 'longitude') {
+ this._field.semanticType = 'quantitative';
+ this._field.analyticType = 'dimension';
+ }
+ if (role === 'latitude') {
+ this._field.semanticType = 'quantitative';
+ this._field.analyticType = 'measure'
+ }
+ return this._field
+ }
+ public switchAnalyticType (analyticType: T['analyticType'] | string): T {
+ if (analyticType === 'dimension') {
+ return this.asDimension();
+ } else if (analyticType === 'measure') {
+ return this.asMeasure();
+ }
+ return this._field
+ }
+}
\ No newline at end of file
diff --git a/packages/graphic-walker/src/store/visualSpecStore.ts b/packages/graphic-walker/src/store/visualSpecStore.ts
index 129147e3..70bc7d6f 100644
--- a/packages/graphic-walker/src/store/visualSpecStore.ts
+++ b/packages/graphic-walker/src/store/visualSpecStore.ts
@@ -38,6 +38,7 @@ import { createCountField } from '../utils';
import { COUNT_FIELD_ID } from '../constants';
import { nanoid } from 'nanoid';
import { toWorkflow } from '../utils/workflow';
+import { Field } from '../models/field';
function getChannelSizeLimit(channel: string): number {
if (typeof GLOBAL_CONFIG.CHANNEL_LIMIT[channel] === 'undefined') return Infinity;
@@ -481,7 +482,7 @@ export class VizSpecStore {
if (GLOBAL_CONFIG.META_FIELD_KEYS.includes(destinationKey)) {
if (!GLOBAL_CONFIG.META_FIELD_KEYS.includes(sourceKey)) return;
encodings[sourceKey].splice(sourceIndex, 1);
- movingField.analyticType = destinationKey === 'dimensions' ? 'dimension' : 'measure';
+ movingField = new Field(movingField).switchAnalyticType(destinationKey === 'dimensions' ? 'dimension' : 'measure')
}
const limitSize = getChannelSizeLimit(destinationKey);
const fixedDestinationIndex = Math.min(destinationIndex, limitSize - 1);