Skip to content

Commit b23f0b4

Browse files
committed
add more vis-state schema
Signed-off-by: Shan He <[email protected]>
1 parent 824c9bf commit b23f0b4

File tree

7 files changed

+65
-13
lines changed

7 files changed

+65
-13
lines changed

src/schemas/src/interaction-config.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/schemas/src/vis-state.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,33 @@
22

33
import {z} from 'zod';
44

5-
import {AnimationConfigSchema} from './animation';
6-
import {EffectSchema} from './effect';
7-
import {FilterSchema} from './filter';
5+
import {AnimationConfigSchema} from './vis-state/animation';
6+
import {EffectSchema} from './vis-state/effect';
7+
import {FilterSchema} from './vis-state/filter';
88
import {LayerSchema} from './layers';
9-
import {InteractionConfigSchema} from './interaction-config';
9+
import {InteractionConfigSchema} from './vis-state/interaction-config';
10+
import {EditorSchema} from './vis-state/editor';
1011

1112
export const VisStateSchema = z.object({
1213
effects: z.array(EffectSchema).optional().describe('Effects to apply to the map layers'),
1314
filters: z.array(FilterSchema).optional().describe('Filters to apply to the data'),
1415
layers: z.array(LayerSchema).default([]).describe('Layers to display in the map'),
15-
interactionConfig: z.unknown(),
16-
layerBlending: z.unknown(),
17-
overlayBlending: z.unknown().optional(),
16+
interactionConfig: InteractionConfigSchema.optional().describe(
17+
'Interaction configuration for the map, setting tooltips, geocoder, etc.'
18+
),
19+
layerBlending: z
20+
.enum(['additive', 'normal', 'subtractive'])
21+
.default('normal')
22+
.optional()
23+
.describe('How layers are blended together on top of the map'),
24+
overlayBlending: z
25+
.enum(['normal', 'screen', 'darken'])
26+
.default('normal')
27+
.optional()
28+
.describe('How map overlayers are blended with the map'),
1829
splitMaps: z.unknown(),
1930
animationConfig: AnimationConfigSchema.optional().describe('Configuration for animating the map'),
20-
editor: z.unknown().optional(),
31+
editor: EditorSchema.optional(),
2132
datasets: z.unknown(),
2233
layerOrder: z.unknown()
2334
});

src/schemas/src/animation.ts renamed to src/schemas/src/vis-state/animation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import {z} from 'zod';
55

6-
import {TimeRangeFilterSchema} from './filter';
6+
import {TimeRangeFilterSchema} from '../filter';
77

88
export const AnimationTimeFormat = z.enum(['L', 'L LT', 'L LTS']);
99
export type AnimationTimeFormat = z.infer<typeof AnimationTimeFormat>;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright contributors to the kepler.gl project
3+
4+
import {z} from 'zod';
5+
6+
const GeoJsonFeaturesSchema = z.array(
7+
z.object({
8+
type: z.literal('Feature'),
9+
properties: z.object({}).optional(),
10+
geometry: z.object({
11+
type: z.string(),
12+
coordinates: z.array(z.any())
13+
})
14+
})
15+
);
16+
17+
export const EditorSchema = z.object({
18+
features: GeoJsonFeaturesSchema.optional(),
19+
visible: z.boolean().optional()
20+
});

src/schemas/src/effect.ts renamed to src/schemas/src/vis-state/effect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import {z} from 'zod';
55

6-
import {RGBColorSchema} from './color';
6+
import {RGBColorSchema} from '../color';
77

88
export const EffectTypeSchema = z.enum([
99
'brightnessContrast',

src/schemas/src/filter.ts renamed to src/schemas/src/vis-state/filter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
AggregationKeySchema,
99
TIME_INTERVAL_DESC,
1010
TimeIntervalSchema
11-
} from './common';
11+
} from '../common';
1212

1313
export const FilterTypesSchema = z.enum(['range', 'select', 'multiSelect', 'timeRange', 'polygon']);
1414
export type FilterTypesSchema = z.infer<typeof FilterTypesSchema>;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright contributors to the kepler.gl project
3+
4+
import {z} from 'zod';
5+
6+
export const InteractionConfigSchema = z.object({
7+
tooltip: z.object({
8+
fieldsToShow: z.record(z.string(), z.array(z.string())).optional(),
9+
compareMode: z.boolean().default(false),
10+
compareType: z.enum(['absolute', 'percent']).default('absolute'),
11+
enabled: z.boolean().default(true)
12+
}),
13+
brush: z.object({
14+
size: z.number().min(0).max(5).default(0.5),
15+
enabled: z.boolean().default(false)
16+
}),
17+
geocoder: z.object({
18+
enabled: z.boolean().default(false)
19+
}),
20+
coordinate: z.object({
21+
enabled: z.boolean().default(false)
22+
})
23+
});

0 commit comments

Comments
 (0)