@urban-toolkit/autk-grammar 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,385 @@
1
- export * from './main';
2
- export * from './types';
1
+ import { AutkMap } from '@urban-toolkit/autk-map';
2
+ import { AutkPlot } from '@urban-toolkit/autk-plot';
3
+ import { FeatureCollection } from 'geojson';
4
+
5
+ export declare type AggregateFunction = 'sum' | 'avg' | 'count' | 'min' | 'max' | 'weighted' | 'collect';
6
+
7
+ export declare class AutkGrammar {
8
+ private dataAdapter?;
9
+ private mapAdapter?;
10
+ private plotAdapter?;
11
+ private computeAdapter?;
12
+ private grammarEngine?;
13
+ private _computeCache;
14
+ private _data;
15
+ private _mapRegistry;
16
+ private _plotRegistry;
17
+ private _fwdCleanups;
18
+ private _plotMapLinks;
19
+ readonly interactions: GrammarEventEmitter;
20
+ constructor(targets?: Targets);
21
+ /**
22
+ * The coordinate reference system used internally by the autk workspace.
23
+ *
24
+ * Input data is expected in EPSG:4326 (WGS84) by default and is transformed
25
+ * to this CRS on load. Consumers that prepare data for injection (e.g. by
26
+ * serialising a GeoDataFrame) can read this value and reproject accordingly
27
+ * instead of hard-coding a CRS string.
28
+ */
29
+ get workspaceCrs(): string;
30
+ get data(): Record<string, Promise<FeatureCollection>>;
31
+ run(spec: UrbanSpec): Promise<void>;
32
+ /**
33
+ * Highlights features on the map layer identified by `layerId`.
34
+ * If that layer is linked to a plot via `mapRef`, the plot selection is updated too.
35
+ */
36
+ highlightOnMap(layerId: string, featureIds: number[]): void;
37
+ /**
38
+ * Clears highlighted features on the map layer identified by `layerId`.
39
+ * If that layer is linked to a plot via `mapRef`, the plot selection is cleared too.
40
+ */
41
+ clearHighlightOnMap(layerId: string): void;
42
+ /**
43
+ * Clears the selection on the plot identified by `plotId` (its dataRef).
44
+ * If that plot is linked to a map via `mapRef`, the map highlight is cleared too.
45
+ */
46
+ clearHighlightOnPlot(plotId: string): void;
47
+ /**
48
+ * Applies a selection to the plot identified by `plotId` (its dataRef).
49
+ * If that plot is linked to a map via `mapRef`, the map highlight is updated too.
50
+ */
51
+ setPlotSelection(plotId: string, featureIds: number[]): void;
52
+ private _rewireInteractions;
53
+ }
54
+
55
+ export declare type AutkGrammarSpec = UrbanSpec;
56
+
57
+ export declare interface BoundingBox {
58
+ minLon: number;
59
+ minLat: number;
60
+ maxLon: number;
61
+ maxLat: number;
62
+ }
63
+
64
+ export declare enum ColorMapInterpolator {
65
+ CAT_ACCENT = "schemeAccent",
66
+ CAT_DARK2 = "schemeDark2",
67
+ CAT_CATEGORY10 = "schemeCategory10",
68
+ CAT_OBSERVABLE10 = "schemeObservable10",
69
+ CAT_PAIRED = "schemePaired",
70
+ CAT_PASTEL1 = "schemePastel1",
71
+ CAT_PASTEL2 = "schemePastel2",
72
+ CAT_SET1 = "schemeSet1",
73
+ CAT_SET2 = "schemeSet2",
74
+ CAT_SET3 = "schemeSet3",
75
+ CAT_TABLEAU10 = "schemeTableau10",
76
+ SEQ_REDS = "interpolateReds",
77
+ SEQ_BLUES = "interpolateBlues",
78
+ SEQ_GREENS = "interpolateGreens",
79
+ SEQ_GREYS = "interpolateGreys",
80
+ SEQ_ORANGES = "interpolateOranges",
81
+ SEQ_PURPLES = "interpolatePurples",
82
+ SEQ_TURBO = "interpolateTurbo",
83
+ SEQ_VIRIDIS = "interpolateViridis",
84
+ SEQ_INFERNO = "interpolateInferno",
85
+ SEQ_MAGMA = "interpolateMagma",
86
+ SEQ_PLASMA = "interpolatePlasma",
87
+ SEQ_CIVIDIS = "interpolateCividis",
88
+ SEQ_WARM = "interpolateWarm",
89
+ SEQ_COOL = "interpolateCool",
90
+ SEQ_BU_GN = "interpolateBuGn",
91
+ SEQ_BU_PU = "interpolateBuPu",
92
+ SEQ_GN_BU = "interpolateGnBu",
93
+ SEQ_OR_RD = "interpolateOrRd",
94
+ SEQ_PU_BU = "interpolatePuBu",
95
+ SEQ_PU_RD = "interpolatePuRd",
96
+ SEQ_RD_PU = "interpolateRdPu",
97
+ SEQ_YL_GN = "interpolateYlGn",
98
+ SEQ_YL_OR_BR = "interpolateYlOrBr",
99
+ SEQ_YL_OR_RD = "interpolateYlOrRd",
100
+ DIV_BR_BG = "interpolateBrBG",
101
+ DIV_PR_GN = "interpolatePRGn",
102
+ DIV_PI_YG = "interpolatePiYG",
103
+ DIV_PU_OR = "interpolatePuOr",
104
+ DIV_RED_BLUE = "interpolateRdBu",
105
+ DIV_RED_GREY = "interpolateRdGy",
106
+ DIV_RED_YELLOW_BLUE = "interpolateRdYlBu",
107
+ DIV_RED_YELLOW_GREEN = "interpolateRdYlGn",
108
+ DIV_SPECTRAL = "interpolateSpectral"
109
+ }
110
+
111
+ export declare interface ComputeAdapter {
112
+ resolveCompute(context: unknown, spec: ComputeSpec): Promise<unknown>;
113
+ }
114
+
115
+ export declare type ComputeCache = Map<string, FeatureCollection>;
116
+
117
+ export declare type ComputeSpec = {
118
+ dataRef: string;
119
+ attributes: Record<string, string>;
120
+ attributeArrays?: Record<string, number>;
121
+ attributeMatrices?: Record<string, {
122
+ rows: number | 'auto';
123
+ cols: number;
124
+ }>;
125
+ uniforms?: Record<string, number>;
126
+ uniformArrays?: Record<string, number[]>;
127
+ uniformMatrices?: Record<string, {
128
+ data: number[][];
129
+ cols: number;
130
+ }>;
131
+ outputColumnName?: string;
132
+ outputColumns?: string[];
133
+ wglsFunction: string;
134
+ };
135
+
136
+ export declare function createEngine(options: EngineOptions): IEngine;
137
+
138
+ export declare type CsvDataSourceSpec = TableSourceSpec & {
139
+ csvFileUrl?: string;
140
+ csvObject?: unknown[][];
141
+ delimiter?: string;
142
+ geometryColumns?: {
143
+ latColumnName: string;
144
+ longColumnName: string;
145
+ coordinateFormat?: string;
146
+ };
147
+ };
148
+
149
+ export declare type CustomDataSourceSpec = TableSourceSpec & {
150
+ geojsonFileUrl?: string;
151
+ /**
152
+ * GeoJSON FeatureCollection to load directly.
153
+ *
154
+ * Per RFC 7946, GeoJSON coordinates MUST be in WGS84 (EPSG:4326) longitude/latitude.
155
+ * This is the default assumption when `coordinateFormat` is omitted.
156
+ *
157
+ * If your FeatureCollection is in a different CRS (e.g. a projected system such as
158
+ * EPSG:3395), you MUST set `coordinateFormat` explicitly to match the actual CRS
159
+ * of the input data. Omitting `coordinateFormat` when the data is not in EPSG:4326
160
+ * will cause the spatial transform to produce invalid geometry.
161
+ */
162
+ geojsonObject?: FeatureCollection;
163
+ /**
164
+ * Source coordinate reference system of the input data, expressed as an EPSG string
165
+ * (e.g. `'EPSG:4326'`, `'EPSG:3395'`).
166
+ *
167
+ * Defaults to `'EPSG:4326'` (WGS84) when omitted, which is the correct value for
168
+ * standards-compliant GeoJSON. Only set this when the source data deviates from
169
+ * RFC 7946.
170
+ */
171
+ coordinateFormat?: string;
172
+ boundingBox?: BoundingBox;
173
+ };
174
+
175
+ export declare interface DataAdapter {
176
+ resolveSource(context: unknown, spec: DataSourceSpec): Promise<unknown>;
177
+ }
178
+
179
+ export declare type DataSourceSpec = OsmDataSourceSpec | CsvDataSourceSpec | JsonDataSourceSpec | CustomDataSourceSpec | HeatmapSourceSpec | JoinSourceSpec;
180
+
181
+ export declare type DataSourceType = 'osm' | 'csv' | 'json' | 'geojson' | 'heatmap' | 'join';
182
+
183
+ export declare type EngineOptions = {
184
+ spec: UrbanSpec;
185
+ adapters: {
186
+ db: DataAdapter;
187
+ map: MapAdapter;
188
+ plot: PlotAdapter;
189
+ compute: ComputeAdapter;
190
+ };
191
+ };
192
+
193
+ export declare type GeoJsonCache = Map<string, FeatureCollection>;
194
+
195
+ export declare class GrammarEventEmitter {
196
+ private _listeners;
197
+ on<K extends keyof GrammarEventRecord>(event: K, listener: (payload: GrammarEventRecord[K]) => void): () => void;
198
+ /* Excluded from this release type: emit */
199
+ }
200
+
201
+ export declare type GrammarEventRecord = {
202
+ 'map:picking': GrammarPickingEvent;
203
+ 'plot:selection': GrammarPlotSelectionEvent;
204
+ };
205
+
206
+ export declare interface GrammarPickingEvent {
207
+ layerId: string;
208
+ selection: number[];
209
+ }
210
+
211
+ export declare interface GrammarPlotSelectionEvent {
212
+ plotId: string;
213
+ event: 'click' | 'brush' | 'brushX' | 'brushY';
214
+ selection: number[];
215
+ }
216
+
217
+ export declare type HeatmapSourceSpec = TableSourceSpec & {
218
+ tableJoinName: string;
219
+ near: {
220
+ distance: number;
221
+ };
222
+ groupBy?: Array<{
223
+ column: string;
224
+ aggregateFn?: AggregateFunction;
225
+ }>;
226
+ grid: {
227
+ rows: number;
228
+ columns: number;
229
+ };
230
+ };
231
+
232
+ export declare interface IEngine {
233
+ run(): Promise<void>;
234
+ updatedSpec(spec: UrbanSpec): Promise<void>;
235
+ destroy(): void;
236
+ readonly context: unknown;
237
+ }
238
+
239
+ export declare type JoinSourceSpec = Omit<TableSourceSpec, 'outputTableName'> & {
240
+ tableRootName: string;
241
+ tableJoinName: string;
242
+ near?: {
243
+ distance: number;
244
+ useCentroid?: boolean;
245
+ };
246
+ groupBy?: Array<{
247
+ column: string;
248
+ aggregateFn?: AggregateFunction;
249
+ normalize?: boolean;
250
+ }>;
251
+ };
252
+
253
+ export declare type JsonDataSourceSpec = TableSourceSpec & {
254
+ jsonFileUrl?: string;
255
+ jsonObject?: unknown[];
256
+ geometryColumns?: {
257
+ latColumnName: string;
258
+ longColumnName: string;
259
+ coordinateFormat?: string;
260
+ };
261
+ };
262
+
263
+ export declare type LayerType = 'surface' | 'water' | 'parks' | 'roads' | 'buildings' | 'points' | 'polygons' | 'polylines' | 'raster';
264
+
265
+ /**
266
+ * Interface for map styles.
267
+ * @property {Promise<unknown>} resolveMap - Resolves map specification.
268
+ * @param {unkown} context Grand grammar context for sharing data between adapters.
269
+ * @param {MapSpec} spec The type of the layer.
270
+ */
271
+ export declare interface MapAdapter {
272
+ resolveMap(context: unknown, spec: MapSpec, index?: number): Promise<unknown>;
273
+ }
274
+
275
+ export declare type MapRegistry = Map<string, AutkMap>;
276
+
277
+ /**
278
+ * Type for map.
279
+ * @property {string} style Map style.
280
+ * @property {...} layerRef Reference to layer in data specification.
281
+ * @property {number} opacity Opacity of the layer.
282
+ * @property {boolean} [isColorMap] Indicates if the layer is a color map.
283
+ * @property {ColorMapInterpolator} colorMapInterpolator Interpolator for color mapping.
284
+ * @property {number[]} [pickedComps] Components that are picked, if any.
285
+ * @property {boolean} [isSkip] Indicates if the layer should be skipped in rendering.
286
+ * @property {boolean} [isPick] Indicates if the layer is for picking
287
+ * @property {string} getFnv Field path to extract thematic values from. Supports dot notation for nested properties (e.g. "tags.highway" resolves to feature.properties.tags.highway).
288
+ * @property {'categorical' | 'quantitative'} getFnvType How to interpret the extracted value. 'categorical' coerces to string (for discrete color palettes); 'quantitative' coerces to number (for continuous/diverging scales). When omitted the raw value is used as-is.
289
+ * @property {string[]} colorMapDomain Explicit set of allowed category values. Values not in this list are collapsed to 'other'. Only meaningful when getFnvType is 'categorical'.
290
+ */
291
+ export declare type MapSpec = {
292
+ style?: string;
293
+ layerRefs: {
294
+ dataRef: string;
295
+ opacity?: number;
296
+ isColorMap?: boolean;
297
+ colorMapInterpolator?: ColorMapInterpolator;
298
+ colorMapLabels?: string[];
299
+ pickedComps?: number[];
300
+ normalization?: {
301
+ mode: NormalizationMode;
302
+ lowerPercentile?: number;
303
+ upperPercentile?: number;
304
+ };
305
+ isSkip?: boolean;
306
+ isPick?: boolean;
307
+ getFnv?: string;
308
+ getFnvType?: 'categorical' | 'quantitative';
309
+ colorMapDomain?: string[];
310
+ catchAllCategory?: string;
311
+ defaultFnv?: string | number;
312
+ }[];
313
+ };
314
+
315
+ export declare enum NormalizationMode {
316
+ MIN_MAX = "minMax",
317
+ PERCENTILE = "percentile"
318
+ }
319
+
320
+ export declare type OsmDataSourceSpec = TableSourceSpec & {
321
+ pbfFileUrl?: string;
322
+ autoLoadLayers?: {
323
+ dropOsmTable: boolean;
324
+ layers: Array<LayerType>;
325
+ };
326
+ queryArea: {
327
+ geocodeArea: string;
328
+ areas: string[];
329
+ };
330
+ };
331
+
332
+ export declare interface PlotAdapter {
333
+ resolvePlot(context: unknown, spec: PlotSpec): Promise<unknown>;
334
+ }
335
+
336
+ export declare type PlotEvent = 'click' | 'brush' | 'brushY' | 'brushX';
337
+
338
+ export declare type PlotMapLinks = Map<string, string>;
339
+
340
+ export declare type PlotMark = 'scatter' | 'bar' | 'line' | 'linechart' | 'parallel-coordinates' | 'table' | 'heatmatrix';
341
+
342
+ export declare type PlotRegistry = Map<string, AutkPlot>;
343
+
344
+ export declare type PlotSpec = {
345
+ dataRef: string;
346
+ mark: PlotMark;
347
+ axis: string[];
348
+ color?: string;
349
+ title?: string;
350
+ events?: PlotEvent[];
351
+ width?: number;
352
+ height?: number;
353
+ margins?: {
354
+ left: number;
355
+ right: number;
356
+ top: number;
357
+ bottom: number;
358
+ };
359
+ transform?: {
360
+ preset: string;
361
+ options?: Record<string, unknown>;
362
+ };
363
+ mapRef?: string;
364
+ };
365
+
366
+ export declare type TableSourceSpec = {
367
+ type: DataSourceType;
368
+ outputTableName: string;
369
+ };
370
+
371
+ export declare type Targets = {
372
+ compute?: string;
373
+ db?: string;
374
+ map?: string[] | string;
375
+ plot?: string;
376
+ };
377
+
378
+ export declare type UrbanSpec = {
379
+ data?: DataSourceSpec[];
380
+ compute?: ComputeSpec[];
381
+ map?: MapSpec[] | MapSpec;
382
+ plot?: PlotSpec[] | PlotSpec;
383
+ };
384
+
385
+ export { }
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@urban-toolkit/autk-grammar",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Autark adapter for the urban grammar",
5
5
  "license": "MIT",
6
6
  "author": "Gustavo Moreira",
7
+ "homepage": "https://autarkjs.org/grammar/",
7
8
  "repository": {
8
9
  "type": "git",
9
- "url": "https://github.com/urban-toolkit/the-urban-grammar"
10
+ "url": "https://github.com/urban-toolkit/autk-grammar"
10
11
  },
11
12
  "type": "module",
12
13
  "files": [
@@ -35,7 +36,7 @@
35
36
  "devDependencies": {
36
37
  "@typescript-eslint/eslint-plugin": "^8.46.2",
37
38
  "@typescript-eslint/parser": "^8.46.2",
38
- "@types/geojson": "^7946.0.16",
39
+ "@urban-toolkit/the-urban-grammar": "*",
39
40
  "@webgpu/types": "^0.1.66",
40
41
  "eslint": "^9.38.0",
41
42
  "eslint-config-prettier": "^10.1.8",
@@ -50,13 +51,11 @@
50
51
  "vite-plugin-glsl": "^1.5.4"
51
52
  },
52
53
  "dependencies": {
53
- "@urban-toolkit/autk-compute": "2.1.2",
54
- "@urban-toolkit/autk-core": "2.1.2",
55
- "@urban-toolkit/autk-db": "2.1.2",
56
- "@urban-toolkit/autk-map": "2.1.2",
57
- "@urban-toolkit/autk-plot": "2.1.2"
58
- },
59
- "peerDependencies": {
60
- "@urban-toolkit/the-urban-grammar": "^0.1.0"
54
+ "@types/geojson": "^7946.0.16",
55
+ "@urban-toolkit/autk-compute": "^3.0.0",
56
+ "@urban-toolkit/autk-core": "^3.0.0",
57
+ "@urban-toolkit/autk-db": "^3.0.0",
58
+ "@urban-toolkit/autk-map": "^3.0.0",
59
+ "@urban-toolkit/autk-plot": "^3.0.0"
61
60
  }
62
61
  }
@@ -1,3 +0,0 @@
1
- import { ComputeAdapter } from '@urban-toolkit/the-urban-grammar';
2
- import { ComputeCache } from '../types';
3
- export declare function createComputeAdapter(cache?: ComputeCache): ComputeAdapter;
@@ -1,3 +0,0 @@
1
- import { DataAdapter } from '@urban-toolkit/the-urban-grammar';
2
- import { Targets, GeoJsonCache } from '../types';
3
- export declare function createDataAdapter(targets?: Targets, cache?: GeoJsonCache): DataAdapter;
@@ -1,3 +0,0 @@
1
- import { MapAdapter } from '@urban-toolkit/the-urban-grammar';
2
- import { Targets, MapRegistry, ComputeCache } from '../types';
3
- export declare function createMapAdapter(targets?: Targets, registry?: MapRegistry, computeCache?: ComputeCache): MapAdapter;
@@ -1,3 +0,0 @@
1
- import { PlotAdapter } from '@urban-toolkit/the-urban-grammar';
2
- import { Targets, MapRegistry, PlotRegistry, PlotMapLinks, GeoJsonCache } from '../types';
3
- export declare function createPlotAdapter(targets?: Targets, registry?: MapRegistry, plotRegistry?: PlotRegistry, plotMapLinks?: PlotMapLinks, cache?: GeoJsonCache): PlotAdapter;
@@ -1 +0,0 @@
1
- export {};
package/dist/main.d.ts DELETED
@@ -1,50 +0,0 @@
1
- import { UrbanSpec } from '@urban-toolkit/the-urban-grammar';
2
- import { FeatureCollection } from 'geojson';
3
- import { Targets, GrammarEventEmitter } from './types';
4
- export declare class AutkGrammar {
5
- private dataAdapter?;
6
- private mapAdapter?;
7
- private plotAdapter?;
8
- private computeAdapter?;
9
- private grammarEngine?;
10
- private _computeCache;
11
- private _data;
12
- private _mapRegistry;
13
- private _plotRegistry;
14
- private _fwdCleanups;
15
- private _plotMapLinks;
16
- readonly interactions: GrammarEventEmitter;
17
- constructor(targets?: Targets);
18
- /**
19
- * The coordinate reference system used internally by the autk workspace.
20
- *
21
- * Input data is expected in EPSG:4326 (WGS84) by default and is transformed
22
- * to this CRS on load. Consumers that prepare data for injection (e.g. by
23
- * serialising a GeoDataFrame) can read this value and reproject accordingly
24
- * instead of hard-coding a CRS string.
25
- */
26
- get workspaceCrs(): string;
27
- get data(): Record<string, Promise<FeatureCollection>>;
28
- run(spec: UrbanSpec): Promise<void>;
29
- /**
30
- * Highlights features on the map layer identified by `layerId`.
31
- * If that layer is linked to a plot via `mapRef`, the plot selection is updated too.
32
- */
33
- highlightOnMap(layerId: string, featureIds: number[]): void;
34
- /**
35
- * Clears highlighted features on the map layer identified by `layerId`.
36
- * If that layer is linked to a plot via `mapRef`, the plot selection is cleared too.
37
- */
38
- clearHighlightOnMap(layerId: string): void;
39
- /**
40
- * Clears the selection on the plot identified by `plotId` (its dataRef).
41
- * If that plot is linked to a map via `mapRef`, the map highlight is cleared too.
42
- */
43
- clearHighlightOnPlot(plotId: string): void;
44
- /**
45
- * Applies a selection to the plot identified by `plotId` (its dataRef).
46
- * If that plot is linked to a map via `mapRef`, the map highlight is updated too.
47
- */
48
- setPlotSelection(plotId: string, featureIds: number[]): void;
49
- private _rewireInteractions;
50
- }
package/dist/types.d.ts DELETED
@@ -1,36 +0,0 @@
1
- import { UrbanSpec } from '@urban-toolkit/the-urban-grammar';
2
- import { AutkMap } from '@urban-toolkit/autk-map';
3
- import { AutkPlot } from '@urban-toolkit/autk-plot';
4
- import { FeatureCollection } from 'geojson';
5
- export type Targets = {
6
- compute?: string;
7
- db?: string;
8
- map?: string[] | string;
9
- plot?: string;
10
- };
11
- export type MapRegistry = Map<string, AutkMap>;
12
- export type PlotRegistry = Map<string, AutkPlot>;
13
- export type PlotMapLinks = Map<string, string>;
14
- export type GeoJsonCache = Map<string, FeatureCollection>;
15
- export type ComputeCache = Map<string, FeatureCollection>;
16
- export type AutkGrammarSpec = UrbanSpec;
17
- export interface GrammarPickingEvent {
18
- layerId: string;
19
- selection: number[];
20
- }
21
- export interface GrammarPlotSelectionEvent {
22
- plotId: string;
23
- event: 'click' | 'brush' | 'brushX' | 'brushY';
24
- selection: number[];
25
- }
26
- export type GrammarEventRecord = {
27
- 'map:picking': GrammarPickingEvent;
28
- 'plot:selection': GrammarPlotSelectionEvent;
29
- };
30
- export declare class GrammarEventEmitter {
31
- private _listeners;
32
- on<K extends keyof GrammarEventRecord>(event: K, listener: (payload: GrammarEventRecord[K]) => void): () => void;
33
- /** @internal */
34
- emit<K extends keyof GrammarEventRecord>(event: K, payload: GrammarEventRecord[K]): void;
35
- }
36
- export { ColorMapInterpolator, NormalizationMode } from '@urban-toolkit/the-urban-grammar';