Skip to content

Commit

Permalink
feat: add new dataset (#197)
Browse files Browse the repository at this point in the history
* feat: add new dataset

* feat: force semantic for geo field
  • Loading branch information
ObservedObserver authored Oct 21, 2023
1 parent b64a3cd commit 73385d8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 18 deletions.
24 changes: 15 additions & 9 deletions packages/graphic-walker/src/dataSource/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
export const DemoDataAssets = true ? {
CARS: "https://chspace.oss-cn-hongkong.aliyuncs.com/api/ds-cars-service.json",
STUDENTS: "https://chspace.oss-cn-hongkong.aliyuncs.com/api/ds-students-service.json",
BTC_GOLD: "https://chspace.oss-cn-hongkong.aliyuncs.com/api/ds_btc_gold_service.json",
BIKE_SHARING: 'https://chspace.oss-cn-hongkong.aliyuncs.com/api/ds-bikesharing-service.json',
CAR_SALES: 'https://chspace.oss-cn-hongkong.aliyuncs.com/api/ds-carsales-service.json',
COLLAGE: 'https://chspace.oss-cn-hongkong.aliyuncs.com/api/ds-collage-service.json',
TITANIC: 'https://chspace.oss-cn-hongkong.aliyuncs.com/api/ds-titanic-service.json',
KELPER: 'https://chspace.oss-cn-hongkong.aliyuncs.com/api/ds-kelper-service.json',
export const DemoDataAssets = process.env.NODE_ENV === 'production' ? {
CARS: "https://pub-2422ed4100b443659f588f2382cfc7b1.r2.dev/datasets/ds-cars-service.json",
STUDENTS: "https://pub-2422ed4100b443659f588f2382cfc7b1.r2.dev/datasets/ds-students-service.json",
BTC_GOLD: "https://pub-2422ed4100b443659f588f2382cfc7b1.r2.dev/datasets/ds-btcgold-service.json",
BIKE_SHARING: 'https://pub-2422ed4100b443659f588f2382cfc7b1.r2.dev/datasets/ds-bikesharing-service.json',
CAR_SALES: 'https://pub-2422ed4100b443659f588f2382cfc7b1.r2.dev/datasets/ds-carsales-service.json',
COLLAGE: 'https://pub-2422ed4100b443659f588f2382cfc7b1.r2.dev/datasets/ds-collage-service.json',
TITANIC: 'https://pub-2422ed4100b443659f588f2382cfc7b1.r2.dev/datasets/ds-titanic-service.json',
KELPER: 'https://pub-2422ed4100b443659f588f2382cfc7b1.r2.dev/datasets/ds-kelper-service.json',
EARTHQUAKE: 'https://pub-2422ed4100b443659f588f2382cfc7b1.r2.dev/datasets/ds-earthquake-service.json'
} : {
// CARS: "https://chspace.oss-cn-hongkong.aliyuncs.com/api/ds-cars-service.json",
CARS: "/datasets/ds-cars-service.json",
Expand All @@ -18,6 +19,7 @@ export const DemoDataAssets = true ? {
COLLAGE: '/datasets/ds-collage-service.json',
TITANIC: '/datasets/ds-titanic-service.json',
KELPER: '/datasets/ds-kelper-service.json',
EARTHQUAKE: '/datasets/ds-earthquake-service.json'
} as const;

interface IPublicData {
Expand All @@ -39,6 +41,10 @@ export const PUBLIC_DATA_LIST: IPublicData[] = [
key: "BIKE_SHARING",
title: "Bike Sharing"
},
{
key: "EARTHQUAKE",
title: "Earthquakes"
},
{
key: "CAR_SALES",
title: "Car Sales"
Expand Down
36 changes: 27 additions & 9 deletions packages/graphic-walker/src/lib/gog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// File name: gog represents the Grammar of Graphics (theory by Wilkinson)
import { DraggableFieldState } from "../interfaces";
import { DraggableFieldState, IAnalyticType, ISemanticType } from "../interfaces";

type SpitialEncodings = Pick<DraggableFieldState, 'columns' | 'rows'> | Pick<DraggableFieldState, 'latitude' | 'longitude'>
type DraggableFieldValues = DraggableFieldState[Exclude<keyof DraggableFieldState, 'filters'>];
Expand Down Expand Up @@ -29,12 +29,22 @@ const LR = {
}, [] as DraggableFieldValues);
}
},
forceDimension(fields: DraggableFieldValues): DraggableFieldValues {
return fields.map(f => ({
...f,
analyticType: 'dimension'
}))
}
forceAnalyticType (analyticType: IAnalyticType) {
return function (fields: DraggableFieldValues): DraggableFieldValues {
return fields.map(f => ({
...f,
analyticType
}))
}
},
forceSemanticType (semanticType: ISemanticType) {
return function (fields: DraggableFieldValues): DraggableFieldValues {
return fields.map(f => ({
...f,
semanticType
}))
}
},
}
type Operator<T> = (value: T) => T;
function applyOperations<T>(initialValue: T, operators: Operator<T>[]): T {
Expand All @@ -61,8 +71,16 @@ export function algebraLint <T extends SpitialEncodings | DraggableFieldValues>(
} else if ('latitude' in encodings && 'longitude' in encodings && (encodings.latitude.length > 0 || encodings.longitude.length > 0)) {
return {
...encodings,
latitude: applyOperations(encodings.latitude, [LR.forceDimension, LR.crossLimit(1)]),
longitude: applyOperations(encodings.longitude, [LR.forceDimension, LR.crossLimit(1)])
latitude: applyOperations(encodings.latitude, [
LR.forceAnalyticType('dimension'),
LR.forceSemanticType('quantitative'),
LR.crossLimit(1)
]),
longitude: applyOperations(encodings.longitude, [
LR.forceAnalyticType('dimension'),
LR.forceSemanticType('quantitative'),
LR.crossLimit(1)
])
};
}
return encodings;
Expand Down

1 comment on commit 73385d8

@vercel
Copy link

@vercel vercel bot commented on 73385d8 Oct 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.