Skip to content

Commit

Permalink
fix: analytic type transform bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ObservedObserver committed Sep 29, 2023
1 parent 3ae153d commit d5a5b30
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion packages/graphic-walker/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
39 changes: 39 additions & 0 deletions packages/graphic-walker/src/models/field.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
3 changes: 2 additions & 1 deletion packages/graphic-walker/src/store/visualSpecStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d5a5b30

Please sign in to comment.