@urban-toolkit/autk-grammar 0.1.0 → 0.1.1
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/autk-grammar.js +166 -117
- package/dist/autk-grammar.js.map +1 -1
- package/dist/autk-grammar.umd.cjs +1 -1
- package/dist/autk-grammar.umd.cjs.map +1 -1
- package/dist/main.d.ts +13 -0
- package/package.json +61 -61
package/dist/autk-grammar.js
CHANGED
|
@@ -1,66 +1,83 @@
|
|
|
1
|
-
import { NormalizationMode as
|
|
2
|
-
import { ColorMapInterpolator as K, NormalizationMode as
|
|
3
|
-
import { AutkDb as C } from "@urban-toolkit/autk-db";
|
|
4
|
-
import { AutkMap as P, MapStyle as N, ColorMapDomainStrategy as g, MapEvent as
|
|
5
|
-
import { AutkPlot as
|
|
6
|
-
import { AutkComputeEngine as
|
|
7
|
-
function
|
|
8
|
-
function r(
|
|
1
|
+
import { NormalizationMode as R, createEngine as v } from "@urban-toolkit/the-urban-grammar";
|
|
2
|
+
import { ColorMapInterpolator as K, NormalizationMode as X } from "@urban-toolkit/the-urban-grammar";
|
|
3
|
+
import { AutkDb as L, DEFAULT_WORKSPACE_COORDINATE_FORMAT as C } from "@urban-toolkit/autk-db";
|
|
4
|
+
import { AutkMap as P, MapStyle as N, ColorMapDomainStrategy as g, MapEvent as T } from "@urban-toolkit/autk-map";
|
|
5
|
+
import { AutkPlot as x } from "@urban-toolkit/autk-plot";
|
|
6
|
+
import { AutkComputeEngine as F } from "@urban-toolkit/autk-compute";
|
|
7
|
+
function S(n, i) {
|
|
8
|
+
function r(s, e) {
|
|
9
9
|
if (!e || !e.db)
|
|
10
10
|
return;
|
|
11
11
|
const t = document.getElementById(e.db);
|
|
12
12
|
if (t) {
|
|
13
|
-
const
|
|
13
|
+
const c = s.tables;
|
|
14
14
|
t.innerHTML += "<ul>";
|
|
15
|
-
for (const
|
|
16
|
-
t.innerHTML += `<li>${
|
|
17
|
-
t.innerHTML += "</ul>", t.innerHTML += `<p>Number of tables: ${
|
|
15
|
+
for (const u of c)
|
|
16
|
+
t.innerHTML += `<li>${u.name}: (${u.source}, ${u.type}) </li>`;
|
|
17
|
+
t.innerHTML += "</ul>", t.innerHTML += `<p>Number of tables: ${c.length}</p>`;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
return {
|
|
21
|
-
async resolveSource(
|
|
22
|
-
let t =
|
|
23
|
-
t || (t = new
|
|
24
|
-
let { type:
|
|
25
|
-
switch (
|
|
21
|
+
async resolveSource(s, e) {
|
|
22
|
+
let t = s;
|
|
23
|
+
t || (t = new L(), await t.init());
|
|
24
|
+
let { type: c, ...u } = e;
|
|
25
|
+
switch (c) {
|
|
26
26
|
case "osm":
|
|
27
|
-
return await t.loadOsm(
|
|
27
|
+
return await t.loadOsm(u), r(t, n), t;
|
|
28
28
|
case "csv":
|
|
29
|
-
return await t.loadCsv(
|
|
29
|
+
return await t.loadCsv(u), r(t, n), t;
|
|
30
30
|
case "json":
|
|
31
|
-
return await t.loadJson(
|
|
31
|
+
return await t.loadJson(u), r(t, n), t;
|
|
32
32
|
case "geojson": {
|
|
33
|
-
const a =
|
|
34
|
-
let
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
const a = u;
|
|
34
|
+
let l;
|
|
35
|
+
a.geojsonFileUrl ? l = await (await fetch(a.geojsonFileUrl)).json() : l = a.geojsonObject, i && l && i.set(a.outputTableName, l);
|
|
36
|
+
const p = l ? (() => {
|
|
37
|
+
const o = { ...a, geojsonObject: l };
|
|
38
|
+
return delete o.geojsonFileUrl, o;
|
|
39
|
+
})() : a;
|
|
40
|
+
try {
|
|
41
|
+
await t.loadGeojson(p);
|
|
42
|
+
} catch (o) {
|
|
43
|
+
const m = p.coordinateFormat ? `coordinateFormat is set to "${p.coordinateFormat}"` : "no coordinateFormat was specified — defaulting to EPSG:4326 (WGS84 per RFC 7946)";
|
|
44
|
+
throw new Error(
|
|
45
|
+
`Failed to load GeoJSON layer "${p.outputTableName}": ${o instanceof Error ? o.message : String(o)}. ${m}. Verify that coordinateFormat matches the actual CRS of the input data.`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const o = await t.getBoundingBoxFromLayer(p.outputTableName), m = 25e6;
|
|
50
|
+
if (!isFinite(o.minLon) || !isFinite(o.minLat) || !isFinite(o.maxLon) || !isFinite(o.maxLat) || Math.abs(o.minLon) > m || Math.abs(o.maxLon) > m || Math.abs(o.minLat) > m || Math.abs(o.maxLat) > m)
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Geometry bounding box after transform is invalid for layer "${p.outputTableName}" (bbox: [${o.minLon}, ${o.minLat}, ${o.maxLon}, ${o.maxLat}]). Verify that coordinateFormat matches the actual CRS of the input data. The workspace uses ${C}; input is expected in EPSG:4326 by default.`
|
|
53
|
+
);
|
|
54
|
+
} catch (o) {
|
|
55
|
+
if (o instanceof Error && o.message.includes("bounding box after transform")) throw o;
|
|
56
|
+
}
|
|
57
|
+
return r(t, n), t;
|
|
41
58
|
}
|
|
42
59
|
case "heatmap": {
|
|
43
|
-
const a =
|
|
60
|
+
const a = u;
|
|
44
61
|
return await t.buildHeatmap({
|
|
45
62
|
tableJoinName: a.tableJoinName,
|
|
46
63
|
near: { distance: a.near.distance },
|
|
47
64
|
outputTableName: a.outputTableName,
|
|
48
65
|
grid: a.grid,
|
|
49
66
|
...a.groupBy && { groupBy: a.groupBy }
|
|
50
|
-
}), r(t,
|
|
67
|
+
}), r(t, n), t;
|
|
51
68
|
}
|
|
52
69
|
case "join": {
|
|
53
|
-
const a =
|
|
70
|
+
const a = u;
|
|
54
71
|
if (await t.spatialQuery({
|
|
55
72
|
tableRootName: a.tableRootName,
|
|
56
73
|
tableJoinName: a.tableJoinName,
|
|
57
74
|
...a.near && { near: a.near },
|
|
58
75
|
...a.groupBy && { groupBy: a.groupBy }
|
|
59
|
-
}),
|
|
60
|
-
const
|
|
61
|
-
|
|
76
|
+
}), i) {
|
|
77
|
+
const l = await t.getLayer(a.tableRootName);
|
|
78
|
+
i.set(a.tableRootName, l);
|
|
62
79
|
}
|
|
63
|
-
return r(t,
|
|
80
|
+
return r(t, n), t;
|
|
64
81
|
}
|
|
65
82
|
default:
|
|
66
83
|
return;
|
|
@@ -68,81 +85,81 @@ function k(o, n) {
|
|
|
68
85
|
}
|
|
69
86
|
};
|
|
70
87
|
}
|
|
71
|
-
function
|
|
72
|
-
return
|
|
88
|
+
function I(n, i) {
|
|
89
|
+
return i && i.length > 0 ? { type: g.USER, params: i } : n?.mode === R.PERCENTILE ? n.lowerPercentile !== void 0 || n.upperPercentile !== void 0 ? {
|
|
73
90
|
type: g.PERCENTILE,
|
|
74
|
-
params: [
|
|
91
|
+
params: [n.lowerPercentile ?? 0, n.upperPercentile ?? 100]
|
|
75
92
|
} : { type: g.PERCENTILE } : { type: g.MIN_MAX };
|
|
76
93
|
}
|
|
77
|
-
function
|
|
78
|
-
return
|
|
94
|
+
function j(n, i) {
|
|
95
|
+
return i.split(".").reduce((r, s) => {
|
|
79
96
|
if (!(r == null || typeof r != "object"))
|
|
80
|
-
return r[
|
|
81
|
-
},
|
|
97
|
+
return r[s];
|
|
98
|
+
}, n);
|
|
82
99
|
}
|
|
83
|
-
function
|
|
84
|
-
const
|
|
100
|
+
function $(n, i, r) {
|
|
101
|
+
const s = i.split("."), e = { ...n };
|
|
85
102
|
let t = e;
|
|
86
|
-
for (let
|
|
87
|
-
t[
|
|
88
|
-
return t[
|
|
103
|
+
for (let c = 0; c < s.length - 1; c++)
|
|
104
|
+
t[s[c]] = { ...t[s[c]] ?? {} }, t = t[s[c]];
|
|
105
|
+
return t[s[s.length - 1]] = r, e;
|
|
89
106
|
}
|
|
90
|
-
function
|
|
91
|
-
async function
|
|
92
|
-
let
|
|
107
|
+
function k(n, i, r) {
|
|
108
|
+
async function s(e, t, c) {
|
|
109
|
+
let u = {};
|
|
93
110
|
for (const a of t.tables)
|
|
94
|
-
a.type !== void 0 && (
|
|
95
|
-
for (const a of
|
|
96
|
-
const
|
|
97
|
-
...
|
|
98
|
-
features: (
|
|
111
|
+
a.type !== void 0 && (u[a.name] = a.type);
|
|
112
|
+
for (const a of c.layerRefs) {
|
|
113
|
+
const l = a.dataRef, p = u[l], o = a.getFnv, m = r?.get(l) ?? await t.getLayer(l), f = {
|
|
114
|
+
...m,
|
|
115
|
+
features: (m.features ?? []).filter((d) => d.geometry != null)
|
|
99
116
|
};
|
|
100
|
-
|
|
101
|
-
const { catchAllCategory: y, colorMapDomain:
|
|
102
|
-
let
|
|
103
|
-
if (
|
|
104
|
-
const d = new Set(
|
|
105
|
-
|
|
106
|
-
...
|
|
107
|
-
features:
|
|
108
|
-
const
|
|
109
|
-
return
|
|
117
|
+
p === "raster" ? e.loadCollection(l, { collection: f, type: "raster", property: o ?? "" }) : e.loadCollection(l, { collection: f, type: p }), a.opacity != null && e.updateRenderInfo(l, { opacity: a.opacity }), a.isColorMap && e.updateRenderInfo(l, { isColorMap: !0 }), a.isPick && e.updateRenderInfo(l, { isPick: !0 }), a.isSkip && e.updateRenderInfo(l, { isSkip: !0 });
|
|
118
|
+
const { catchAllCategory: y, colorMapDomain: h } = a;
|
|
119
|
+
let E = f, A = h;
|
|
120
|
+
if (o && y && h?.length) {
|
|
121
|
+
const d = new Set(h);
|
|
122
|
+
E = {
|
|
123
|
+
...f,
|
|
124
|
+
features: f.features.map((b) => {
|
|
125
|
+
const M = b.properties, w = j(M, o);
|
|
126
|
+
return w == null || !d.has(String(w)) ? { ...b, properties: $(M, o, y) } : b;
|
|
110
127
|
})
|
|
111
|
-
},
|
|
128
|
+
}, A = d.has(y) ? h : [...h, y];
|
|
112
129
|
}
|
|
113
130
|
if (a.colorMapInterpolator) {
|
|
114
131
|
const d = {
|
|
115
132
|
// urban-grammar ColorMapInterpolator values are string-compatible
|
|
116
133
|
// with autk-core ColorMapInterpolator at runtime
|
|
117
134
|
interpolator: a.colorMapInterpolator,
|
|
118
|
-
domainSpec:
|
|
135
|
+
domainSpec: I(a.normalization, A)
|
|
119
136
|
};
|
|
120
|
-
e.updateRenderInfo(
|
|
137
|
+
e.updateRenderInfo(l, { colormap: { config: d }, isColorMap: !0 });
|
|
121
138
|
}
|
|
122
|
-
if (
|
|
123
|
-
const d =
|
|
124
|
-
e.updateThematic(
|
|
139
|
+
if (o && p !== "raster") {
|
|
140
|
+
const d = o.startsWith("properties.") ? o : `properties.${o}`;
|
|
141
|
+
e.updateThematic(l, { collection: E, property: d });
|
|
125
142
|
}
|
|
126
143
|
}
|
|
127
144
|
}
|
|
128
145
|
return {
|
|
129
|
-
async resolveMap(e, t,
|
|
130
|
-
if (
|
|
131
|
-
let
|
|
132
|
-
if (Array.isArray(
|
|
133
|
-
throw new Error("Could not find rendering target for map: " +
|
|
134
|
-
if (!(
|
|
135
|
-
throw new Error("Target for map is not a canvas: " +
|
|
136
|
-
const a = new P(
|
|
137
|
-
if (t.style && N.setPredefinedStyle(t.style), await a.init(), await
|
|
138
|
-
for (const
|
|
139
|
-
|
|
146
|
+
async resolveMap(e, t, c = 0) {
|
|
147
|
+
if (n && n.map && e) {
|
|
148
|
+
let u;
|
|
149
|
+
if (Array.isArray(n.map) ? u = document.getElementById(n.map[c]) : u = document.getElementById(n.map), !u)
|
|
150
|
+
throw new Error("Could not find rendering target for map: " + n.map);
|
|
151
|
+
if (!(u instanceof HTMLCanvasElement))
|
|
152
|
+
throw new Error("Target for map is not a canvas: " + n.map);
|
|
153
|
+
const a = new P(u);
|
|
154
|
+
if (t.style && N.setPredefinedStyle(t.style), await a.init(), await s(a, e, t), i)
|
|
155
|
+
for (const l of t.layerRefs)
|
|
156
|
+
i.set(l.dataRef, a);
|
|
140
157
|
a.draw();
|
|
141
158
|
}
|
|
142
159
|
}
|
|
143
160
|
};
|
|
144
161
|
}
|
|
145
|
-
function
|
|
162
|
+
function B(n) {
|
|
146
163
|
return {
|
|
147
164
|
scatter: "scatterplot",
|
|
148
165
|
bar: "barchart",
|
|
@@ -151,19 +168,19 @@ function x(o) {
|
|
|
151
168
|
"parallel-coordinates": "parallel-coordinates",
|
|
152
169
|
table: "table",
|
|
153
170
|
heatmatrix: "heatmatrix"
|
|
154
|
-
}[
|
|
171
|
+
}[n];
|
|
155
172
|
}
|
|
156
|
-
function
|
|
173
|
+
function _(n, i, r) {
|
|
157
174
|
return {
|
|
158
|
-
async resolvePlot(
|
|
159
|
-
if (!
|
|
160
|
-
const t = document.getElementById(
|
|
161
|
-
if (!t) throw new Error(`Could not find plot target: ${
|
|
162
|
-
const
|
|
163
|
-
if (!
|
|
164
|
-
const
|
|
165
|
-
type:
|
|
166
|
-
collection:
|
|
175
|
+
async resolvePlot(s, e) {
|
|
176
|
+
if (!n || !n.plot) return;
|
|
177
|
+
const t = document.getElementById(n.plot);
|
|
178
|
+
if (!t) throw new Error(`Could not find plot target: ${n.plot}`);
|
|
179
|
+
const c = s;
|
|
180
|
+
if (!c) throw new Error("No data context available for plot.");
|
|
181
|
+
const u = r?.get(e.dataRef) ?? await c.getLayer(e.dataRef), a = e.events ?? [], l = new x(t, {
|
|
182
|
+
type: B(e.mark),
|
|
183
|
+
collection: u,
|
|
167
184
|
attributes: { axis: e.axis, ...e.color && { color: e.color } },
|
|
168
185
|
labels: { axis: e.axis, title: e.title },
|
|
169
186
|
events: a,
|
|
@@ -172,27 +189,27 @@ function F(o, n, r) {
|
|
|
172
189
|
...e.margins && { margins: e.margins },
|
|
173
190
|
...e.transform && { transform: e.transform }
|
|
174
191
|
});
|
|
175
|
-
if (e.mapRef &&
|
|
176
|
-
const
|
|
177
|
-
if (
|
|
178
|
-
|
|
179
|
-
|
|
192
|
+
if (e.mapRef && i) {
|
|
193
|
+
const p = i.get(e.mapRef);
|
|
194
|
+
if (p) {
|
|
195
|
+
p.updateRenderInfo(e.mapRef, { isPick: !0 }), p.events.on(T.PICKING, ({ selection: o }) => {
|
|
196
|
+
l.setSelection(o);
|
|
180
197
|
});
|
|
181
|
-
for (const
|
|
182
|
-
|
|
183
|
-
|
|
198
|
+
for (const o of a)
|
|
199
|
+
l.events.on(o, ({ selection: m }) => {
|
|
200
|
+
p.setHighlightedIds(e.mapRef, m);
|
|
184
201
|
});
|
|
185
202
|
}
|
|
186
203
|
}
|
|
187
204
|
}
|
|
188
205
|
};
|
|
189
206
|
}
|
|
190
|
-
function
|
|
207
|
+
function D(n) {
|
|
191
208
|
return {
|
|
192
|
-
async resolveCompute(
|
|
193
|
-
if (
|
|
194
|
-
const
|
|
195
|
-
collection:
|
|
209
|
+
async resolveCompute(i, r) {
|
|
210
|
+
if (i) {
|
|
211
|
+
const s = await i.getLayer(r.dataRef), t = await new F().gpgpuPipeline({
|
|
212
|
+
collection: s,
|
|
196
213
|
variableMapping: r.attributes,
|
|
197
214
|
wgslBody: r.wglsFunction,
|
|
198
215
|
...r.outputColumnName && { resultField: r.outputColumnName },
|
|
@@ -203,22 +220,38 @@ function H(o) {
|
|
|
203
220
|
...r.uniformArrays && { uniformArrays: r.uniformArrays },
|
|
204
221
|
...r.uniformMatrices && { uniformMatrices: r.uniformMatrices }
|
|
205
222
|
});
|
|
206
|
-
return
|
|
223
|
+
return n && n.set(r.dataRef, t), i;
|
|
207
224
|
}
|
|
208
225
|
}
|
|
209
226
|
};
|
|
210
227
|
}
|
|
211
|
-
class
|
|
228
|
+
class W {
|
|
212
229
|
dataAdapter;
|
|
213
230
|
mapAdapter;
|
|
214
231
|
plotAdapter;
|
|
215
232
|
computeAdapter;
|
|
216
233
|
grammarEngine;
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
234
|
+
_computeCache = /* @__PURE__ */ new Map();
|
|
235
|
+
_data = {};
|
|
236
|
+
constructor(i) {
|
|
237
|
+
const r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
|
|
238
|
+
this.dataAdapter = S(i, s), this.mapAdapter = k(i, r, this._computeCache), this.plotAdapter = _(i, r, s), this.computeAdapter = D(this._computeCache);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The coordinate reference system used internally by the autk workspace.
|
|
242
|
+
*
|
|
243
|
+
* Input data is expected in EPSG:4326 (WGS84) by default and is transformed
|
|
244
|
+
* to this CRS on load. Consumers that prepare data for injection (e.g. by
|
|
245
|
+
* serialising a GeoDataFrame) can read this value and reproject accordingly
|
|
246
|
+
* instead of hard-coding a CRS string.
|
|
247
|
+
*/
|
|
248
|
+
get workspaceCrs() {
|
|
249
|
+
return C;
|
|
250
|
+
}
|
|
251
|
+
get data() {
|
|
252
|
+
return this._data;
|
|
220
253
|
}
|
|
221
|
-
async run(
|
|
254
|
+
async run(i) {
|
|
222
255
|
if (!this.dataAdapter)
|
|
223
256
|
throw new Error("Database adapter not initialized. Please call the constructor first.");
|
|
224
257
|
if (!this.mapAdapter)
|
|
@@ -227,8 +260,8 @@ class O {
|
|
|
227
260
|
throw new Error("Plot adapter not initialized. Please call the constructor first.");
|
|
228
261
|
if (!this.computeAdapter)
|
|
229
262
|
throw new Error("Compute adapter not initialized. Please call the constructor first.");
|
|
230
|
-
this.grammarEngine =
|
|
231
|
-
spec:
|
|
263
|
+
this.grammarEngine = v({
|
|
264
|
+
spec: i,
|
|
232
265
|
adapters: {
|
|
233
266
|
db: this.dataAdapter,
|
|
234
267
|
map: this.mapAdapter,
|
|
@@ -236,11 +269,27 @@ class O {
|
|
|
236
269
|
compute: this.computeAdapter
|
|
237
270
|
}
|
|
238
271
|
}), await this.grammarEngine.run();
|
|
272
|
+
const r = this.grammarEngine.context;
|
|
273
|
+
if (!r) {
|
|
274
|
+
console.warn("Grammar engine produced no data context."), this._data = {};
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const s = {};
|
|
278
|
+
for (const e of r.getLayerTables())
|
|
279
|
+
Object.defineProperty(s, e.name, {
|
|
280
|
+
get: () => {
|
|
281
|
+
const t = this._computeCache.get(e.name);
|
|
282
|
+
return t ? Promise.resolve(t) : r.getLayer(e.name);
|
|
283
|
+
},
|
|
284
|
+
enumerable: !0,
|
|
285
|
+
configurable: !0
|
|
286
|
+
});
|
|
287
|
+
this._data = s;
|
|
239
288
|
}
|
|
240
289
|
}
|
|
241
290
|
export {
|
|
242
|
-
|
|
291
|
+
W as AutkGrammar,
|
|
243
292
|
K as ColorMapInterpolator,
|
|
244
|
-
|
|
293
|
+
X as NormalizationMode
|
|
245
294
|
};
|
|
246
295
|
//# sourceMappingURL=autk-grammar.js.map
|
package/dist/autk-grammar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autk-grammar.js","sources":["../src/adapters/data.ts","../src/adapters/map.ts","../src/adapters/plot.ts","../src/adapters/compute.ts","../src/main.ts"],"sourcesContent":["import { CsvDataSourceSpec, CustomDataSourceSpec, DataAdapter, DataSourceSpec, HeatmapSourceSpec, JoinSourceSpec, JsonDataSourceSpec, OsmDataSourceSpec } from '@urban-toolkit/the-urban-grammar';\r\nimport { AutkDb } from '@urban-toolkit/autk-db';\r\nimport type { FeatureCollection } from 'geojson';\r\nimport { Targets, GeoJsonCache } from '../types';\r\n\r\nexport function createDataAdapter(targets?: Targets, cache?: GeoJsonCache): DataAdapter {\r\n\r\n function print(db: AutkDb, targets?: Targets): void {\r\n if(!targets || !targets.db)\r\n return\r\n\r\n const div = document.getElementById(targets.db);\r\n if (div) {\r\n const tables = db.tables;\r\n\r\n div.innerHTML += `<ul>`;\r\n for (const table of tables) {\r\n div.innerHTML += `<li>${table.name}: (${table.source}, ${table.type}) </li>`;\r\n }\r\n div.innerHTML += `</ul>`;\r\n\r\n div.innerHTML += `<p>Number of tables: ${tables.length}</p>`;\r\n }\r\n }\r\n\r\n return {\r\n async resolveSource(context: AutkDb | undefined, spec: DataSourceSpec): Promise<AutkDb | undefined> {\r\n\r\n let db = context;\r\n\r\n if(!db){\r\n db = new AutkDb();\r\n await db.init();\r\n }\r\n\r\n let {type, ...rest_spec} = spec;\r\n\r\n switch (type) {\r\n case 'osm':\r\n await db.loadOsm(rest_spec as OsmDataSourceSpec);\r\n print(db, targets);\r\n return db;\r\n case 'csv':\r\n await db.loadCsv(rest_spec as CsvDataSourceSpec);\r\n print(db, targets);\r\n return db;\r\n case 'json':\r\n await db.loadJson(rest_spec as JsonDataSourceSpec);\r\n print(db, targets);\r\n return db;\r\n case 'geojson': {\r\n const geojsonSpec = rest_spec as CustomDataSourceSpec;\r\n let geojsonData: FeatureCollection | undefined;\r\n\r\n if (geojsonSpec.geojsonFileUrl) {\r\n const response = await fetch(geojsonSpec.geojsonFileUrl);\r\n geojsonData = await response.json() as FeatureCollection;\r\n } else {\r\n geojsonData = geojsonSpec.geojsonObject;\r\n }\r\n\r\n if (cache && geojsonData) cache.set(geojsonSpec.outputTableName, geojsonData);\r\n\r\n // Pass the fetched object directly so autk-db doesn't need to re-fetch\r\n if (geojsonData) {\r\n const { geojsonFileUrl: _url, ...specWithoutUrl } = geojsonSpec;\r\n await db.loadGeojson({ ...specWithoutUrl, geojsonObject: geojsonData });\r\n } else {\r\n await db.loadGeojson(geojsonSpec);\r\n }\r\n print(db, targets);\r\n return db;\r\n }\r\n case 'heatmap': {\r\n const hm = rest_spec as HeatmapSourceSpec;\r\n await db.buildHeatmap({\r\n tableJoinName: hm.tableJoinName,\r\n near: { distance: hm.near.distance },\r\n outputTableName: hm.outputTableName,\r\n grid: hm.grid,\r\n ...(hm.groupBy && { groupBy: hm.groupBy as any }),\r\n });\r\n print(db, targets);\r\n return db;\r\n }\r\n case 'join': {\r\n const jn = rest_spec as JoinSourceSpec;\r\n await db.spatialQuery({\r\n tableRootName: jn.tableRootName,\r\n tableJoinName: jn.tableJoinName,\r\n ...(jn.near && { near: jn.near }),\r\n ...(jn.groupBy && { groupBy: jn.groupBy }),\r\n });\r\n if (cache) {\r\n const updated = await db.getLayer(jn.tableRootName);\r\n cache.set(jn.tableRootName, updated);\r\n }\r\n print(db, targets);\r\n return db;\r\n }\r\n default:\r\n return\r\n }\r\n }\r\n }\r\n}\r\n","import { MapAdapter, MapSpec, NormalizationMode } from '@urban-toolkit/the-urban-grammar';\r\nimport { Targets, MapRegistry, ComputeCache } from '../types';\r\nimport { AutkMap, MapStyle } from '@urban-toolkit/autk-map';\r\nimport { ColorMapDomainStrategy } from '@urban-toolkit/autk-map';\r\nimport type { ColorMapConfig, ColorMapDomainSpec, LayerType } from '@urban-toolkit/autk-map';\r\nimport { AutkDb } from '@urban-toolkit/autk-db';\r\n\r\nfunction buildDomainSpec(\r\n normalization: MapSpec['layerRefs'][number]['normalization'],\r\n colorMapDomain?: string[],\r\n): ColorMapDomainSpec {\r\n if (colorMapDomain && colorMapDomain.length > 0)\r\n return { type: ColorMapDomainStrategy.USER, params: colorMapDomain };\r\n if (normalization?.mode === NormalizationMode.PERCENTILE) {\r\n const hasExplicitBounds =\r\n normalization.lowerPercentile !== undefined || normalization.upperPercentile !== undefined;\r\n if (hasExplicitBounds)\r\n return {\r\n type: ColorMapDomainStrategy.PERCENTILE,\r\n params: [normalization.lowerPercentile ?? 0, normalization.upperPercentile ?? 100],\r\n };\r\n return { type: ColorMapDomainStrategy.PERCENTILE };\r\n }\r\n return { type: ColorMapDomainStrategy.MIN_MAX };\r\n}\r\n\r\nfunction valueAtPath(obj: unknown, path: string): unknown {\r\n return path.split('.').reduce<unknown>((acc, key) => {\r\n if (acc == null || typeof acc !== 'object') return undefined;\r\n return (acc as Record<string, unknown>)[key];\r\n }, obj);\r\n}\r\n\r\nfunction setValueAtPath(obj: Record<string, unknown>, path: string, value: unknown): Record<string, unknown> {\r\n const keys = path.split('.');\r\n const result = { ...obj };\r\n let current = result as Record<string, unknown>;\r\n for (let i = 0; i < keys.length - 1; i++) {\r\n current[keys[i]] = { ...(current[keys[i]] as Record<string, unknown> ?? {}) };\r\n current = current[keys[i]] as Record<string, unknown>;\r\n }\r\n current[keys[keys.length - 1]] = value;\r\n return result;\r\n}\r\n\r\nexport function createMapAdapter(targets?: Targets, registry?: MapRegistry, computeCache?: ComputeCache): MapAdapter {\r\n\r\n async function loadLayers(map: AutkMap, context: AutkDb, spec: MapSpec): Promise<void> {\r\n let tableToTypeMap: {[tableName: string]: string} = {};\r\n for(const table of context.tables) {\r\n if(table.type !== undefined) tableToTypeMap[table.name] = table.type;\r\n }\r\n\r\n for(const layerRef of spec.layerRefs){\r\n const name = layerRef.dataRef;\r\n const type = tableToTypeMap[name] as LayerType;\r\n const getFnv = layerRef.getFnv;\r\n\r\n const rawData = computeCache?.get(name) ?? await context.getLayer(name);\r\n const data = {\r\n ...rawData,\r\n features: (rawData.features ?? []).filter((f: any) => f.geometry != null),\r\n };\r\n\r\n if(type === 'raster') {\r\n map.loadCollection(name, { collection: data, type: 'raster', property: getFnv ?? '' });\r\n } else {\r\n map.loadCollection(name, { collection: data, type });\r\n }\r\n\r\n if(layerRef.opacity != null)\r\n map.updateRenderInfo(name, { opacity: layerRef.opacity });\r\n\r\n if(layerRef.isColorMap)\r\n map.updateRenderInfo(name, { isColorMap: true });\r\n\r\n if(layerRef.isPick)\r\n map.updateRenderInfo(name, { isPick: true });\r\n\r\n if(layerRef.isSkip)\r\n map.updateRenderInfo(name, { isSkip: true });\r\n\r\n // When catchAllCategory is set, remap features whose property value is not\r\n // in colorMapDomain to the catch-all label, and extend the domain to include it.\r\n const { catchAllCategory, colorMapDomain } = layerRef;\r\n let thematicData = data;\r\n let effectiveDomain = colorMapDomain;\r\n\r\n if(getFnv && catchAllCategory && colorMapDomain?.length) {\r\n const allowed = new Set(colorMapDomain);\r\n thematicData = {\r\n ...data,\r\n features: data.features.map((f: any) => {\r\n const props = f.properties as Record<string, unknown>;\r\n const val = valueAtPath(props, getFnv);\r\n if(val === undefined || val === null || !allowed.has(String(val))) {\r\n return { ...f, properties: setValueAtPath(props, getFnv, catchAllCategory) };\r\n }\r\n return f;\r\n }),\r\n };\r\n effectiveDomain = allowed.has(catchAllCategory)\r\n ? colorMapDomain\r\n : [...colorMapDomain, catchAllCategory];\r\n }\r\n\r\n if(layerRef.colorMapInterpolator) {\r\n const colormapConfig: ColorMapConfig = {\r\n // urban-grammar ColorMapInterpolator values are string-compatible\r\n // with autk-core ColorMapInterpolator at runtime\r\n interpolator: layerRef.colorMapInterpolator as unknown as ColorMapConfig['interpolator'],\r\n domainSpec: buildDomainSpec(layerRef.normalization, effectiveDomain),\r\n };\r\n map.updateRenderInfo(name, { colormap: { config: colormapConfig }, isColorMap: true });\r\n }\r\n\r\n if(getFnv && type !== 'raster') {\r\n const property = getFnv.startsWith('properties.') ? getFnv : `properties.${getFnv}`;\r\n map.updateThematic(name, { collection: thematicData, property });\r\n }\r\n }\r\n }\r\n\r\n return {\r\n async resolveMap(context: AutkDb | undefined, spec: MapSpec, index: number = 0): Promise<void> {\r\n if(targets && targets.map && context){\r\n\r\n let canvas;\r\n\r\n if(Array.isArray(targets.map)){\r\n canvas = document.getElementById(targets.map[index]);\r\n }else{\r\n canvas = document.getElementById(targets.map);\r\n }\r\n\r\n if(!canvas)\r\n throw new Error(\"Could not find rendering target for map: \"+targets.map);\r\n\r\n if(!(canvas instanceof HTMLCanvasElement))\r\n throw new Error(\"Target for map is not a canvas: \"+targets.map);\r\n\r\n const map = new AutkMap(canvas);\r\n\r\n if(spec.style)\r\n MapStyle.setPredefinedStyle(spec.style)\r\n\r\n await map.init();\r\n await loadLayers(map, context, spec);\r\n\r\n if(registry)\r\n for(const layerRef of spec.layerRefs)\r\n registry.set(layerRef.dataRef, map);\r\n\r\n map.draw();\r\n }\r\n }\r\n }\r\n}\r\n","import { PlotAdapter, PlotSpec, PlotMark } from '@urban-toolkit/the-urban-grammar';\r\nimport { Targets, MapRegistry, GeoJsonCache } from '../types';\r\nimport { AutkDb } from '@urban-toolkit/autk-db';\r\nimport { AutkPlot, PlotEvent as AutkPlotEvent } from '@urban-toolkit/autk-plot';\r\nimport type { PlotEventData, PlotType, PlotTransformConfig } from '@urban-toolkit/autk-plot';\r\nimport { AutkMap, MapEvent } from '@urban-toolkit/autk-map';\r\nimport type { MapEventData } from '@urban-toolkit/autk-map';\r\nimport { FeatureCollection } from 'geojson';\r\n\r\nfunction grammarMarkToPlotType(mark: PlotMark): PlotType {\r\n const mapping: Record<PlotMark, PlotType> = {\r\n 'scatter': 'scatterplot',\r\n 'bar': 'barchart',\r\n 'line': 'linechart',\r\n 'linechart': 'linechart',\r\n 'parallel-coordinates': 'parallel-coordinates',\r\n 'table': 'table',\r\n 'heatmatrix': 'heatmatrix',\r\n };\r\n return mapping[mark];\r\n}\r\n\r\nexport function createPlotAdapter(targets?: Targets, registry?: MapRegistry, cache?: GeoJsonCache): PlotAdapter {\r\n\r\n return {\r\n async resolvePlot(context: unknown, spec: PlotSpec): Promise<void> {\r\n if(!targets || !targets.plot) return;\r\n\r\n const div = document.getElementById(targets.plot);\r\n if(!div) throw new Error(`Could not find plot target: ${targets.plot}`);\r\n\r\n const db = context as AutkDb | undefined;\r\n if(!db) throw new Error('No data context available for plot.');\r\n\r\n const geojson: FeatureCollection = cache?.get(spec.dataRef) ?? await db.getLayer(spec.dataRef);\r\n\r\n const events = (spec.events ?? []) as unknown as AutkPlotEvent[];\r\n\r\n const plot = new AutkPlot(div, {\r\n type: grammarMarkToPlotType(spec.mark),\r\n collection: geojson,\r\n attributes: { axis: spec.axis, ...(spec.color && { color: spec.color }) },\r\n labels: { axis: spec.axis, title: spec.title },\r\n events,\r\n ...(spec.width && { width: spec.width }),\r\n ...(spec.height && { height: spec.height }),\r\n ...(spec.margins && { margins: spec.margins }),\r\n ...(spec.transform && { transform: spec.transform as PlotTransformConfig }),\r\n });\r\n\r\n // Wire map ↔ plot events if a mapRef is specified\r\n if(spec.mapRef && registry) {\r\n const map: AutkMap | undefined = registry.get(spec.mapRef);\r\n\r\n if(map) {\r\n map.updateRenderInfo(spec.mapRef, { isPick: true });\r\n\r\n map.events.on(MapEvent.PICKING, ({ selection }: MapEventData) => {\r\n plot.setSelection(selection);\r\n });\r\n\r\n for(const event of events) {\r\n plot.events.on(event, ({ selection }: PlotEventData) => {\r\n map.setHighlightedIds(spec.mapRef!, selection);\r\n });\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\n","import { ComputeAdapter, ComputeSpec } from '@urban-toolkit/the-urban-grammar';\r\nimport { AutkDb } from '@urban-toolkit/autk-db';\r\nimport { AutkComputeEngine } from '@urban-toolkit/autk-compute';\r\nimport { FeatureCollection } from 'geojson';\r\nimport { ComputeCache } from '../types';\r\n\r\nexport function createComputeAdapter(cache?: ComputeCache): ComputeAdapter {\r\n\r\n return {\r\n async resolveCompute(context: AutkDb | undefined, spec: ComputeSpec): Promise<AutkDb | undefined> {\r\n if(context){\r\n const geojson: FeatureCollection = await context.getLayer(spec.dataRef);\r\n const engine = new AutkComputeEngine();\r\n\r\n const result = await engine.gpgpuPipeline({\r\n collection: geojson,\r\n variableMapping: spec.attributes,\r\n wgslBody: spec.wglsFunction,\r\n ...(spec.outputColumnName && { resultField: spec.outputColumnName }),\r\n ...(spec.outputColumns && { outputColumns: spec.outputColumns }),\r\n ...(spec.attributeArrays && { attributeArrays: spec.attributeArrays }),\r\n ...(spec.attributeMatrices && { attributeMatrices: spec.attributeMatrices }),\r\n ...(spec.uniforms && { uniforms: spec.uniforms }),\r\n ...(spec.uniformArrays && { uniformArrays: spec.uniformArrays }),\r\n ...(spec.uniformMatrices && { uniformMatrices: spec.uniformMatrices }),\r\n });\r\n\r\n if (cache) cache.set(spec.dataRef, result);\r\n\r\n return context;\r\n }\r\n }\r\n }\r\n}\r\n","import { DataAdapter, MapAdapter, PlotAdapter, ComputeAdapter, IEngine, UrbanSpec, createEngine } from \"@urban-toolkit/the-urban-grammar\";\r\nimport { createDataAdapter } from \"./adapters/data\";\r\nimport { createMapAdapter } from \"./adapters/map\";\r\nimport { createPlotAdapter } from \"./adapters/plot\";\r\nimport { createComputeAdapter } from \"./adapters/compute\";\r\nimport { Targets, MapRegistry, GeoJsonCache, ComputeCache } from \"./types\";\r\n\r\nexport class AutkGrammar {\r\n private dataAdapter?: DataAdapter;\r\n private mapAdapter?: MapAdapter;\r\n private plotAdapter?: PlotAdapter;\r\n private computeAdapter?: ComputeAdapter;\r\n private grammarEngine?: IEngine;\r\n\r\n constructor(targets?: Targets) {\r\n const registry: MapRegistry = new Map();\r\n const cache: GeoJsonCache = new Map();\r\n const computeCache: ComputeCache = new Map();\r\n this.dataAdapter = createDataAdapter(targets, cache);\r\n this.mapAdapter = createMapAdapter(targets, registry, computeCache);\r\n this.plotAdapter = createPlotAdapter(targets, registry, cache);\r\n this.computeAdapter = createComputeAdapter(computeCache);\r\n }\r\n\r\n async run(spec: UrbanSpec) {\r\n if(!this.dataAdapter)\r\n throw new Error('Database adapter not initialized. Please call the constructor first.');\r\n\r\n if(!this.mapAdapter)\r\n throw new Error('Map engine not initialized. Please call the constructor first.');\r\n\r\n if(!this.plotAdapter)\r\n throw new Error('Plot adapter not initialized. Please call the constructor first.');\r\n\r\n if(!this.computeAdapter)\r\n throw new Error('Compute adapter not initialized. Please call the constructor first.');\r\n\r\n this.grammarEngine = createEngine({\r\n spec,\r\n adapters: {\r\n db: this.dataAdapter,\r\n map: this.mapAdapter,\r\n plot: this.plotAdapter,\r\n compute: this.computeAdapter\r\n }\r\n });\r\n\r\n await this.grammarEngine.run();\r\n }\r\n}"],"names":["createDataAdapter","targets","cache","print","db","div","tables","table","context","spec","AutkDb","type","rest_spec","geojsonSpec","geojsonData","_url","specWithoutUrl","hm","jn","updated","buildDomainSpec","normalization","colorMapDomain","ColorMapDomainStrategy","NormalizationMode","valueAtPath","obj","path","acc","key","setValueAtPath","value","keys","result","current","i","createMapAdapter","registry","computeCache","loadLayers","map","tableToTypeMap","layerRef","name","getFnv","rawData","data","f","catchAllCategory","thematicData","effectiveDomain","allowed","props","val","colormapConfig","property","index","canvas","AutkMap","MapStyle","grammarMarkToPlotType","mark","createPlotAdapter","geojson","events","plot","AutkPlot","MapEvent","selection","event","createComputeAdapter","AutkComputeEngine","AutkGrammar","createEngine"],"mappings":";;;;;;AAKO,SAASA,EAAkBC,GAAmBC,GAAmC;AAEpF,WAASC,EAAMC,GAAYH,GAA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AAAA,EAEA,MAAM,IAAI7B,GAAiB;AACvB,QAAG,CAAC,KAAK;AACL,YAAM,IAAI,MAAM,sEAAsE;AAE1F,QAAG,CAAC,KAAK;AACL,YAAM,IAAI,MAAM,gEAAgE;AAEpF,QAAG,CAAC,KAAK;AACL,YAAM,IAAI,MAAM,kEAAkE;AAEtF,QAAG,CAAC,KAAK;AACL,YAAM,IAAI,MAAM,qEAAqE;AAEzF,SAAK,gBAAgBgE,EAAa;AAAA,MAC9B,MAAAhE;AAAA,MACA,UAAU;AAAA,QACN,IAAI,KAAK;AAAA,QACT,KAAK,KAAK;AAAA,QACV,MAAM,KAAK;AAAA,QACX,SAAS,KAAK;AAAA,MAAA;AAAA,IAClB,CACH,GAED,MAAM,KAAK,cAAc,IAAA;AAAA,EAC7B;AACJ;"}
|
|
1
|
+
{"version":3,"file":"autk-grammar.js","sources":["../src/adapters/data.ts","../src/adapters/map.ts","../src/adapters/plot.ts","../src/adapters/compute.ts","../src/main.ts"],"sourcesContent":["import { CsvDataSourceSpec, CustomDataSourceSpec, DataAdapter, DataSourceSpec, HeatmapSourceSpec, JoinSourceSpec, JsonDataSourceSpec, OsmDataSourceSpec } from '@urban-toolkit/the-urban-grammar';\nimport { AutkDb, DEFAULT_WORKSPACE_COORDINATE_FORMAT } from '@urban-toolkit/autk-db';\nimport type { FeatureCollection } from 'geojson';\nimport { Targets, GeoJsonCache } from '../types';\n\nexport function createDataAdapter(targets?: Targets, cache?: GeoJsonCache): DataAdapter {\n\n function print(db: AutkDb, targets?: Targets): void {\n if(!targets || !targets.db)\n return\n\n const div = document.getElementById(targets.db);\n if (div) {\n const tables = db.tables;\n\n div.innerHTML += `<ul>`;\n for (const table of tables) {\n div.innerHTML += `<li>${table.name}: (${table.source}, ${table.type}) </li>`;\n }\n div.innerHTML += `</ul>`;\n\n div.innerHTML += `<p>Number of tables: ${tables.length}</p>`;\n }\n }\n\n return {\n async resolveSource(context: AutkDb | undefined, spec: DataSourceSpec): Promise<AutkDb | undefined> {\n\n let db = context;\n\n if(!db){\n db = new AutkDb();\n await db.init();\n }\n\n let {type, ...rest_spec} = spec;\n\n switch (type) {\n case 'osm':\n await db.loadOsm(rest_spec as OsmDataSourceSpec);\n print(db, targets);\n return db;\n case 'csv':\n await db.loadCsv(rest_spec as CsvDataSourceSpec);\n print(db, targets);\n return db;\n case 'json':\n await db.loadJson(rest_spec as JsonDataSourceSpec);\n print(db, targets);\n return db;\n case 'geojson': {\n const geojsonSpec = rest_spec as CustomDataSourceSpec;\n let geojsonData: FeatureCollection | undefined;\n\n if (geojsonSpec.geojsonFileUrl) {\n const response = await fetch(geojsonSpec.geojsonFileUrl);\n geojsonData = await response.json() as FeatureCollection;\n } else {\n geojsonData = geojsonSpec.geojsonObject;\n }\n\n if (cache && geojsonData) cache.set(geojsonSpec.outputTableName, geojsonData);\n\n // Pass the fetched object directly so autk-db doesn't need to re-fetch\n const loadSpec = geojsonData\n ? (() => { const s = { ...geojsonSpec, geojsonObject: geojsonData }; delete s.geojsonFileUrl; return s; })()\n : geojsonSpec;\n\n try {\n await db.loadGeojson(loadSpec);\n } catch (err) {\n const crsHint = loadSpec.coordinateFormat\n ? `coordinateFormat is set to \"${loadSpec.coordinateFormat}\"`\n : `no coordinateFormat was specified — defaulting to EPSG:4326 (WGS84 per RFC 7946)`;\n throw new Error(\n `Failed to load GeoJSON layer \"${loadSpec.outputTableName}\": ${err instanceof Error ? err.message : String(err)}. ` +\n `${crsHint}. Verify that coordinateFormat matches the actual CRS of the input data.`\n );\n }\n\n // Validate that the loaded geometry is within the workspace CRS extent.\n // A bounding box outside the valid world extent indicates a CRS mismatch.\n try {\n const bbox = await db.getBoundingBoxFromLayer(loadSpec.outputTableName);\n const WORLD_EXTENT = 25_000_000; // generous bound for DEFAULT_WORKSPACE_COORDINATE_FORMAT (EPSG:3395)\n if (\n !isFinite(bbox.minLon) || !isFinite(bbox.minLat) ||\n !isFinite(bbox.maxLon) || !isFinite(bbox.maxLat) ||\n Math.abs(bbox.minLon) > WORLD_EXTENT || Math.abs(bbox.maxLon) > WORLD_EXTENT ||\n Math.abs(bbox.minLat) > WORLD_EXTENT || Math.abs(bbox.maxLat) > WORLD_EXTENT\n ) {\n throw new Error(\n `Geometry bounding box after transform is invalid for layer \"${loadSpec.outputTableName}\" ` +\n `(bbox: [${bbox.minLon}, ${bbox.minLat}, ${bbox.maxLon}, ${bbox.maxLat}]). ` +\n `Verify that coordinateFormat matches the actual CRS of the input data. ` +\n `The workspace uses ${DEFAULT_WORKSPACE_COORDINATE_FORMAT}; input is expected in EPSG:4326 by default.`\n );\n }\n } catch (bboxErr) {\n if (bboxErr instanceof Error && bboxErr.message.includes('bounding box after transform')) throw bboxErr;\n // getBoundingBoxFromLayer failed (empty table, unsupported layer type, etc.) — skip validation\n }\n print(db, targets);\n return db;\n }\n case 'heatmap': {\n const hm = rest_spec as HeatmapSourceSpec;\n await db.buildHeatmap({\n tableJoinName: hm.tableJoinName,\n near: { distance: hm.near.distance },\n outputTableName: hm.outputTableName,\n grid: hm.grid,\n ...(hm.groupBy && { groupBy: hm.groupBy as any }),\n });\n print(db, targets);\n return db;\n }\n case 'join': {\n const jn = rest_spec as JoinSourceSpec;\n await db.spatialQuery({\n tableRootName: jn.tableRootName,\n tableJoinName: jn.tableJoinName,\n ...(jn.near && { near: jn.near }),\n ...(jn.groupBy && { groupBy: jn.groupBy }),\n });\n if (cache) {\n const updated = await db.getLayer(jn.tableRootName);\n cache.set(jn.tableRootName, updated);\n }\n print(db, targets);\n return db;\n }\n default:\n return\n }\n }\n }\n}\n","import { MapAdapter, MapSpec, NormalizationMode } from '@urban-toolkit/the-urban-grammar';\nimport { Targets, MapRegistry, ComputeCache } from '../types';\nimport { AutkMap, MapStyle } from '@urban-toolkit/autk-map';\nimport { ColorMapDomainStrategy } from '@urban-toolkit/autk-map';\nimport type { ColorMapConfig, ColorMapDomainSpec, LayerType } from '@urban-toolkit/autk-map';\nimport { AutkDb } from '@urban-toolkit/autk-db';\n\nfunction buildDomainSpec(\n normalization: MapSpec['layerRefs'][number]['normalization'],\n colorMapDomain?: string[],\n): ColorMapDomainSpec {\n if (colorMapDomain && colorMapDomain.length > 0)\n return { type: ColorMapDomainStrategy.USER, params: colorMapDomain };\n if (normalization?.mode === NormalizationMode.PERCENTILE) {\n const hasExplicitBounds =\n normalization.lowerPercentile !== undefined || normalization.upperPercentile !== undefined;\n if (hasExplicitBounds)\n return {\n type: ColorMapDomainStrategy.PERCENTILE,\n params: [normalization.lowerPercentile ?? 0, normalization.upperPercentile ?? 100],\n };\n return { type: ColorMapDomainStrategy.PERCENTILE };\n }\n return { type: ColorMapDomainStrategy.MIN_MAX };\n}\n\nfunction valueAtPath(obj: unknown, path: string): unknown {\n return path.split('.').reduce<unknown>((acc, key) => {\n if (acc == null || typeof acc !== 'object') return undefined;\n return (acc as Record<string, unknown>)[key];\n }, obj);\n}\n\nfunction setValueAtPath(obj: Record<string, unknown>, path: string, value: unknown): Record<string, unknown> {\n const keys = path.split('.');\n const result = { ...obj };\n let current = result as Record<string, unknown>;\n for (let i = 0; i < keys.length - 1; i++) {\n current[keys[i]] = { ...(current[keys[i]] as Record<string, unknown> ?? {}) };\n current = current[keys[i]] as Record<string, unknown>;\n }\n current[keys[keys.length - 1]] = value;\n return result;\n}\n\nexport function createMapAdapter(targets?: Targets, registry?: MapRegistry, computeCache?: ComputeCache): MapAdapter {\n\n async function loadLayers(map: AutkMap, context: AutkDb, spec: MapSpec): Promise<void> {\n let tableToTypeMap: {[tableName: string]: string} = {};\n for(const table of context.tables) {\n if(table.type !== undefined) tableToTypeMap[table.name] = table.type;\n }\n\n for(const layerRef of spec.layerRefs){\n const name = layerRef.dataRef;\n const type = tableToTypeMap[name] as LayerType;\n const getFnv = layerRef.getFnv;\n\n const rawData = computeCache?.get(name) ?? await context.getLayer(name);\n const data = {\n ...rawData,\n features: (rawData.features ?? []).filter((f: any) => f.geometry != null),\n };\n\n if(type === 'raster') {\n map.loadCollection(name, { collection: data, type: 'raster', property: getFnv ?? '' });\n } else {\n map.loadCollection(name, { collection: data, type });\n }\n\n if(layerRef.opacity != null)\n map.updateRenderInfo(name, { opacity: layerRef.opacity });\n\n if(layerRef.isColorMap)\n map.updateRenderInfo(name, { isColorMap: true });\n\n if(layerRef.isPick)\n map.updateRenderInfo(name, { isPick: true });\n\n if(layerRef.isSkip)\n map.updateRenderInfo(name, { isSkip: true });\n\n // When catchAllCategory is set, remap features whose property value is not\n // in colorMapDomain to the catch-all label, and extend the domain to include it.\n const { catchAllCategory, colorMapDomain } = layerRef;\n let thematicData = data;\n let effectiveDomain = colorMapDomain;\n\n if(getFnv && catchAllCategory && colorMapDomain?.length) {\n const allowed = new Set(colorMapDomain);\n thematicData = {\n ...data,\n features: data.features.map((f: any) => {\n const props = f.properties as Record<string, unknown>;\n const val = valueAtPath(props, getFnv);\n if(val === undefined || val === null || !allowed.has(String(val))) {\n return { ...f, properties: setValueAtPath(props, getFnv, catchAllCategory) };\n }\n return f;\n }),\n };\n effectiveDomain = allowed.has(catchAllCategory)\n ? colorMapDomain\n : [...colorMapDomain, catchAllCategory];\n }\n\n if(layerRef.colorMapInterpolator) {\n const colormapConfig: ColorMapConfig = {\n // urban-grammar ColorMapInterpolator values are string-compatible\n // with autk-core ColorMapInterpolator at runtime\n interpolator: layerRef.colorMapInterpolator as unknown as ColorMapConfig['interpolator'],\n domainSpec: buildDomainSpec(layerRef.normalization, effectiveDomain),\n };\n map.updateRenderInfo(name, { colormap: { config: colormapConfig }, isColorMap: true });\n }\n\n if(getFnv && type !== 'raster') {\n const property = getFnv.startsWith('properties.') ? getFnv : `properties.${getFnv}`;\n map.updateThematic(name, { collection: thematicData, property });\n }\n }\n }\n\n return {\n async resolveMap(context: AutkDb | undefined, spec: MapSpec, index: number = 0): Promise<void> {\n if(targets && targets.map && context){\n\n let canvas;\n\n if(Array.isArray(targets.map)){\n canvas = document.getElementById(targets.map[index]);\n }else{\n canvas = document.getElementById(targets.map);\n }\n\n if(!canvas)\n throw new Error(\"Could not find rendering target for map: \"+targets.map);\n\n if(!(canvas instanceof HTMLCanvasElement))\n throw new Error(\"Target for map is not a canvas: \"+targets.map);\n\n const map = new AutkMap(canvas);\n\n if(spec.style)\n MapStyle.setPredefinedStyle(spec.style)\n\n await map.init();\n await loadLayers(map, context, spec);\n\n if(registry)\n for(const layerRef of spec.layerRefs)\n registry.set(layerRef.dataRef, map);\n\n map.draw();\n }\n }\n }\n}\n","import { PlotAdapter, PlotSpec, PlotMark } from '@urban-toolkit/the-urban-grammar';\nimport { Targets, MapRegistry, GeoJsonCache } from '../types';\nimport { AutkDb } from '@urban-toolkit/autk-db';\nimport { AutkPlot, PlotEvent as AutkPlotEvent } from '@urban-toolkit/autk-plot';\nimport type { PlotEventData, PlotType, PlotTransformConfig } from '@urban-toolkit/autk-plot';\nimport { AutkMap, MapEvent } from '@urban-toolkit/autk-map';\nimport type { MapEventData } from '@urban-toolkit/autk-map';\nimport { FeatureCollection } from 'geojson';\n\nfunction grammarMarkToPlotType(mark: PlotMark): PlotType {\n const mapping: Record<PlotMark, PlotType> = {\n 'scatter': 'scatterplot',\n 'bar': 'barchart',\n 'line': 'linechart',\n 'linechart': 'linechart',\n 'parallel-coordinates': 'parallel-coordinates',\n 'table': 'table',\n 'heatmatrix': 'heatmatrix',\n };\n return mapping[mark];\n}\n\nexport function createPlotAdapter(targets?: Targets, registry?: MapRegistry, cache?: GeoJsonCache): PlotAdapter {\n\n return {\n async resolvePlot(context: unknown, spec: PlotSpec): Promise<void> {\n if(!targets || !targets.plot) return;\n\n const div = document.getElementById(targets.plot);\n if(!div) throw new Error(`Could not find plot target: ${targets.plot}`);\n\n const db = context as AutkDb | undefined;\n if(!db) throw new Error('No data context available for plot.');\n\n const geojson: FeatureCollection = cache?.get(spec.dataRef) ?? await db.getLayer(spec.dataRef);\n\n const events = (spec.events ?? []) as unknown as AutkPlotEvent[];\n\n const plot = new AutkPlot(div, {\n type: grammarMarkToPlotType(spec.mark),\n collection: geojson,\n attributes: { axis: spec.axis, ...(spec.color && { color: spec.color }) },\n labels: { axis: spec.axis, title: spec.title },\n events,\n ...(spec.width && { width: spec.width }),\n ...(spec.height && { height: spec.height }),\n ...(spec.margins && { margins: spec.margins }),\n ...(spec.transform && { transform: spec.transform as PlotTransformConfig }),\n });\n\n // Wire map ↔ plot events if a mapRef is specified\n if(spec.mapRef && registry) {\n const map: AutkMap | undefined = registry.get(spec.mapRef);\n\n if(map) {\n map.updateRenderInfo(spec.mapRef, { isPick: true });\n\n map.events.on(MapEvent.PICKING, ({ selection }: MapEventData) => {\n plot.setSelection(selection);\n });\n\n for(const event of events) {\n plot.events.on(event, ({ selection }: PlotEventData) => {\n map.setHighlightedIds(spec.mapRef!, selection);\n });\n }\n }\n }\n }\n }\n}\n","import { ComputeAdapter, ComputeSpec } from '@urban-toolkit/the-urban-grammar';\nimport { AutkDb } from '@urban-toolkit/autk-db';\nimport { AutkComputeEngine } from '@urban-toolkit/autk-compute';\nimport { FeatureCollection } from 'geojson';\nimport { ComputeCache } from '../types';\n\nexport function createComputeAdapter(cache?: ComputeCache): ComputeAdapter {\n\n return {\n async resolveCompute(context: AutkDb | undefined, spec: ComputeSpec): Promise<AutkDb | undefined> {\n if(context){\n const geojson: FeatureCollection = await context.getLayer(spec.dataRef);\n const engine = new AutkComputeEngine();\n\n const result = await engine.gpgpuPipeline({\n collection: geojson,\n variableMapping: spec.attributes,\n wgslBody: spec.wglsFunction,\n ...(spec.outputColumnName && { resultField: spec.outputColumnName }),\n ...(spec.outputColumns && { outputColumns: spec.outputColumns }),\n ...(spec.attributeArrays && { attributeArrays: spec.attributeArrays }),\n ...(spec.attributeMatrices && { attributeMatrices: spec.attributeMatrices }),\n ...(spec.uniforms && { uniforms: spec.uniforms }),\n ...(spec.uniformArrays && { uniformArrays: spec.uniformArrays }),\n ...(spec.uniformMatrices && { uniformMatrices: spec.uniformMatrices }),\n });\n\n if (cache) cache.set(spec.dataRef, result);\n\n return context;\n }\n }\n }\n}\n","import { DataAdapter, MapAdapter, PlotAdapter, ComputeAdapter, IEngine, UrbanSpec, createEngine } from \"@urban-toolkit/the-urban-grammar\";\nimport { AutkDb, DEFAULT_WORKSPACE_COORDINATE_FORMAT } from \"@urban-toolkit/autk-db\";\nimport { FeatureCollection } from \"geojson\";\nimport { createDataAdapter } from \"./adapters/data\";\nimport { createMapAdapter } from \"./adapters/map\";\nimport { createPlotAdapter } from \"./adapters/plot\";\nimport { createComputeAdapter } from \"./adapters/compute\";\nimport { Targets, MapRegistry, GeoJsonCache, ComputeCache } from \"./types\";\n\nexport class AutkGrammar {\n private dataAdapter?: DataAdapter;\n private mapAdapter?: MapAdapter;\n private plotAdapter?: PlotAdapter;\n private computeAdapter?: ComputeAdapter;\n private grammarEngine?: IEngine;\n private _computeCache: ComputeCache = new Map();\n private _data: Record<string, Promise<FeatureCollection>> = {};\n\n constructor(targets?: Targets) {\n const registry: MapRegistry = new Map();\n const cache: GeoJsonCache = new Map();\n this.dataAdapter = createDataAdapter(targets, cache);\n this.mapAdapter = createMapAdapter(targets, registry, this._computeCache);\n this.plotAdapter = createPlotAdapter(targets, registry, cache);\n this.computeAdapter = createComputeAdapter(this._computeCache);\n }\n\n /**\n * The coordinate reference system used internally by the autk workspace.\n *\n * Input data is expected in EPSG:4326 (WGS84) by default and is transformed\n * to this CRS on load. Consumers that prepare data for injection (e.g. by\n * serialising a GeoDataFrame) can read this value and reproject accordingly\n * instead of hard-coding a CRS string.\n */\n get workspaceCrs(): string {\n return DEFAULT_WORKSPACE_COORDINATE_FORMAT;\n }\n\n get data(): Record<string, Promise<FeatureCollection>> {\n return this._data;\n }\n\n async run(spec: UrbanSpec) {\n if(!this.dataAdapter)\n throw new Error('Database adapter not initialized. Please call the constructor first.');\n\n if(!this.mapAdapter)\n throw new Error('Map engine not initialized. Please call the constructor first.');\n\n if(!this.plotAdapter)\n throw new Error('Plot adapter not initialized. Please call the constructor first.');\n\n if(!this.computeAdapter)\n throw new Error('Compute adapter not initialized. Please call the constructor first.');\n\n this.grammarEngine = createEngine({\n spec,\n adapters: {\n db: this.dataAdapter,\n map: this.mapAdapter,\n plot: this.plotAdapter,\n compute: this.computeAdapter\n }\n });\n\n await this.grammarEngine.run();\n\n const db = this.grammarEngine.context as AutkDb | undefined;\n if (!db) {\n console.warn('Grammar engine produced no data context.');\n this._data = {};\n return;\n }\n\n const dataObj: Record<string, Promise<FeatureCollection>> = {};\n for (const table of db.getLayerTables()) {\n Object.defineProperty(dataObj, table.name, {\n get: () => {\n const computed = this._computeCache.get(table.name);\n return computed ? Promise.resolve(computed) : db.getLayer(table.name);\n },\n enumerable: true,\n configurable: true,\n });\n }\n this._data = dataObj;\n }\n}"],"names":["createDataAdapter","targets","cache","print","db","div","tables","table","context","spec","AutkDb","type","rest_spec","geojsonSpec","geojsonData","loadSpec","s","err","crsHint","bbox","WORLD_EXTENT","DEFAULT_WORKSPACE_COORDINATE_FORMAT","bboxErr","hm","jn","updated","buildDomainSpec","normalization","colorMapDomain","ColorMapDomainStrategy","NormalizationMode","valueAtPath","obj","path","acc","key","setValueAtPath","value","keys","result","current","i","createMapAdapter","registry","computeCache","loadLayers","map","tableToTypeMap","layerRef","name","getFnv","rawData","data","f","catchAllCategory","thematicData","effectiveDomain","allowed","props","val","colormapConfig","property","index","canvas","AutkMap","MapStyle","grammarMarkToPlotType","mark","createPlotAdapter","geojson","events","plot","AutkPlot","MapEvent","selection","event","createComputeAdapter","AutkComputeEngine","AutkGrammar","createEngine","dataObj","computed"],"mappings":";;;;;;AAKO,SAASA,EAAkBC,GAAmBC,GAAmC;AAEpF,WAASC,EAAMC,GAAYH,GAAyB;AAChD,QAAG,CAACA,KAAW,CAACA,EAAQ;AACpB;AAEJ,UAAMI,IAAM,SAAS,eAAeJ,EAAQ,EAAE;AAC9C,QAAII,GAAK;AACL,YAAMC,IAASF,EAAG;AAElB,MAAAC,EAAI,aAAa;AACjB,iBAAWE,KAASD;AAChB,QAAAD,EAAI,aAAa,OAAOE,EAAM,IAAI,MAAMA,EAAM,M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QACX,SAAS,KAAK;AAAA,MAAA;AAAA,IAClB,CACH,GAED,MAAM,KAAK,cAAc,IAAA;AAEzB,UAAML,IAAK,KAAK,cAAc;AAC9B,QAAI,CAACA,GAAI;AACL,cAAQ,KAAK,0CAA0C,GACvD,KAAK,QAAQ,CAAA;AACb;AAAA,IACJ;AAEA,UAAM4E,IAAsD,CAAA;AAC5D,eAAWzE,KAASH,EAAG;AACnB,aAAO,eAAe4E,GAASzE,EAAM,MAAM;AAAA,QACvC,KAAK,MAAM;AACP,gBAAM0E,IAAW,KAAK,cAAc,IAAI1E,EAAM,IAAI;AAClD,iBAAO0E,IAAW,QAAQ,QAAQA,CAAQ,IAAI7E,EAAG,SAASG,EAAM,IAAI;AAAA,QACxE;AAAA,QACA,YAAY;AAAA,QACZ,cAAc;AAAA,MAAA,CACjB;AAEL,SAAK,QAAQyE;AAAA,EACjB;AACJ;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(p,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("@urban-toolkit/the-urban-grammar"),require("@urban-toolkit/autk-db"),require("@urban-toolkit/autk-map"),require("@urban-toolkit/autk-plot"),require("@urban-toolkit/autk-compute")):typeof define=="function"&&define.amd?define(["exports","@urban-toolkit/the-urban-grammar","@urban-toolkit/autk-db","@urban-toolkit/autk-map","@urban-toolkit/autk-plot","@urban-toolkit/autk-compute"],f):(p=typeof globalThis<"u"?globalThis:p||self,f(p["autk-grammar"]={},p.theUrbanGrammar,p.autkDb,p.autkMap,p.autkPlot,p.autkCompute))})(this,(function(p,f,E,b,T,v){"use strict";function k(n,i){function o(u,e){if(!e||!e.db)return;const t=document.getElementById(e.db);if(t){const c=u.tables;t.innerHTML+="<ul>";for(const s of c)t.innerHTML+=`<li>${s.name}: (${s.source}, ${s.type}) </li>`;t.innerHTML+="</ul>",t.innerHTML+=`<p>Number of tables: ${c.length}</p>`}}return{async resolveSource(u,e){let t=u;t||(t=new E.AutkDb,await t.init());let{type:c,...s}=e;switch(c){case"osm":return await t.loadOsm(s),o(t,n),t;case"csv":return await t.loadCsv(s),o(t,n),t;case"json":return await t.loadJson(s),o(t,n),t;case"geojson":{const a=s;let l;a.geojsonFileUrl?l=await(await fetch(a.geojsonFileUrl)).json():l=a.geojsonObject,i&&l&&i.set(a.outputTableName,l);const d=l?(()=>{const r={...a,geojsonObject:l};return delete r.geojsonFileUrl,r})():a;try{await t.loadGeojson(d)}catch(r){const m=d.coordinateFormat?`coordinateFormat is set to "${d.coordinateFormat}"`:"no coordinateFormat was specified — defaulting to EPSG:4326 (WGS84 per RFC 7946)";throw new Error(`Failed to load GeoJSON layer "${d.outputTableName}": ${r instanceof Error?r.message:String(r)}. ${m}. Verify that coordinateFormat matches the actual CRS of the input data.`)}try{const r=await t.getBoundingBoxFromLayer(d.outputTableName),m=25e6;if(!isFinite(r.minLon)||!isFinite(r.minLat)||!isFinite(r.maxLon)||!isFinite(r.maxLat)||Math.abs(r.minLon)>m||Math.abs(r.maxLon)>m||Math.abs(r.minLat)>m||Math.abs(r.maxLat)>m)throw new Error(`Geometry bounding box after transform is invalid for layer "${d.outputTableName}" (bbox: [${r.minLon}, ${r.minLat}, ${r.maxLon}, ${r.maxLat}]). Verify that coordinateFormat matches the actual CRS of the input data. The workspace uses ${E.DEFAULT_WORKSPACE_COORDINATE_FORMAT}; input is expected in EPSG:4326 by default.`)}catch(r){if(r instanceof Error&&r.message.includes("bounding box after transform"))throw r}return o(t,n),t}case"heatmap":{const a=s;return await t.buildHeatmap({tableJoinName:a.tableJoinName,near:{distance:a.near.distance},outputTableName:a.outputTableName,grid:a.grid,...a.groupBy&&{groupBy:a.groupBy}}),o(t,n),t}case"join":{const a=s;if(await t.spatialQuery({tableRootName:a.tableRootName,tableJoinName:a.tableJoinName,...a.near&&{near:a.near},...a.groupBy&&{groupBy:a.groupBy}}),i){const l=await t.getLayer(a.tableRootName);i.set(a.tableRootName,l)}return o(t,n),t}default:return}}}}function L(n,i){return i&&i.length>0?{type:b.ColorMapDomainStrategy.USER,params:i}:n?.mode===f.NormalizationMode.PERCENTILE?n.lowerPercentile!==void 0||n.upperPercentile!==void 0?{type:b.ColorMapDomainStrategy.PERCENTILE,params:[n.lowerPercentile??0,n.upperPercentile??100]}:{type:b.ColorMapDomainStrategy.PERCENTILE}:{type:b.ColorMapDomainStrategy.MIN_MAX}}function N(n,i){return i.split(".").reduce((o,u)=>{if(!(o==null||typeof o!="object"))return o[u]},n)}function S(n,i,o){const u=i.split("."),e={...n};let t=e;for(let c=0;c<u.length-1;c++)t[u[c]]={...t[u[c]]??{}},t=t[u[c]];return t[u[u.length-1]]=o,e}function j(n,i,o){async function u(e,t,c){let s={};for(const a of t.tables)a.type!==void 0&&(s[a.name]=a.type);for(const a of c.layerRefs){const l=a.dataRef,d=s[l],r=a.getFnv,m=o?.get(l)??await t.getLayer(l),y={...m,features:(m.features??[]).filter(h=>h.geometry!=null)};d==="raster"?e.loadCollection(l,{collection:y,type:"raster",property:r??""}):e.loadCollection(l,{collection:y,type:d}),a.opacity!=null&&e.updateRenderInfo(l,{opacity:a.opacity}),a.isColorMap&&e.updateRenderInfo(l,{isColorMap:!0}),a.isPick&&e.updateRenderInfo(l,{isPick:!0}),a.isSkip&&e.updateRenderInfo(l,{isSkip:!0});const{catchAllCategory:w,colorMapDomain:g}=a;let M=y,R=g;if(r&&w&&g?.length){const h=new Set(g);M={...y,features:y.features.map(A=>{const P=A.properties,C=N(P,r);return C==null||!h.has(String(C))?{...A,properties:S(P,r,w)}:A})},R=h.has(w)?g:[...g,w]}if(a.colorMapInterpolator){const h={interpolator:a.colorMapInterpolator,domainSpec:L(a.normalization,R)};e.updateRenderInfo(l,{colormap:{config:h},isColorMap:!0})}if(r&&d!=="raster"){const h=r.startsWith("properties.")?r:`properties.${r}`;e.updateThematic(l,{collection:M,property:h})}}}return{async resolveMap(e,t,c=0){if(n&&n.map&&e){let s;if(Array.isArray(n.map)?s=document.getElementById(n.map[c]):s=document.getElementById(n.map),!s)throw new Error("Could not find rendering target for map: "+n.map);if(!(s instanceof HTMLCanvasElement))throw new Error("Target for map is not a canvas: "+n.map);const a=new b.AutkMap(s);if(t.style&&b.MapStyle.setPredefinedStyle(t.style),await a.init(),await u(a,e,t),i)for(const l of t.layerRefs)i.set(l.dataRef,a);a.draw()}}}}function F(n){return{scatter:"scatterplot",bar:"barchart",line:"linechart",linechart:"linechart","parallel-coordinates":"parallel-coordinates",table:"table",heatmatrix:"heatmatrix"}[n]}function I(n,i,o){return{async resolvePlot(u,e){if(!n||!n.plot)return;const t=document.getElementById(n.plot);if(!t)throw new Error(`Could not find plot target: ${n.plot}`);const c=u;if(!c)throw new Error("No data context available for plot.");const s=o?.get(e.dataRef)??await c.getLayer(e.dataRef),a=e.events??[],l=new T.AutkPlot(t,{type:F(e.mark),collection:s,attributes:{axis:e.axis,...e.color&&{color:e.color}},labels:{axis:e.axis,title:e.title},events:a,...e.width&&{width:e.width},...e.height&&{height:e.height},...e.margins&&{margins:e.margins},...e.transform&&{transform:e.transform}});if(e.mapRef&&i){const d=i.get(e.mapRef);if(d){d.updateRenderInfo(e.mapRef,{isPick:!0}),d.events.on(b.MapEvent.PICKING,({selection:r})=>{l.setSelection(r)});for(const r of a)l.events.on(r,({selection:m})=>{d.setHighlightedIds(e.mapRef,m)})}}}}}function x(n){return{async resolveCompute(i,o){if(i){const u=await i.getLayer(o.dataRef),t=await new v.AutkComputeEngine().gpgpuPipeline({collection:u,variableMapping:o.attributes,wgslBody:o.wglsFunction,...o.outputColumnName&&{resultField:o.outputColumnName},...o.outputColumns&&{outputColumns:o.outputColumns},...o.attributeArrays&&{attributeArrays:o.attributeArrays},...o.attributeMatrices&&{attributeMatrices:o.attributeMatrices},...o.uniforms&&{uniforms:o.uniforms},...o.uniformArrays&&{uniformArrays:o.uniformArrays},...o.uniformMatrices&&{uniformMatrices:o.uniformMatrices}});return n&&n.set(o.dataRef,t),i}}}}class O{dataAdapter;mapAdapter;plotAdapter;computeAdapter;grammarEngine;_computeCache=new Map;_data={};constructor(i){const o=new Map,u=new Map;this.dataAdapter=k(i,u),this.mapAdapter=j(i,o,this._computeCache),this.plotAdapter=I(i,o,u),this.computeAdapter=x(this._computeCache)}get workspaceCrs(){return E.DEFAULT_WORKSPACE_COORDINATE_FORMAT}get data(){return this._data}async run(i){if(!this.dataAdapter)throw new Error("Database adapter not initialized. Please call the constructor first.");if(!this.mapAdapter)throw new Error("Map engine not initialized. Please call the constructor first.");if(!this.plotAdapter)throw new Error("Plot adapter not initialized. Please call the constructor first.");if(!this.computeAdapter)throw new Error("Compute adapter not initialized. Please call the constructor first.");this.grammarEngine=f.createEngine({spec:i,adapters:{db:this.dataAdapter,map:this.mapAdapter,plot:this.plotAdapter,compute:this.computeAdapter}}),await this.grammarEngine.run();const o=this.grammarEngine.context;if(!o){console.warn("Grammar engine produced no data context."),this._data={};return}const u={};for(const e of o.getLayerTables())Object.defineProperty(u,e.name,{get:()=>{const t=this._computeCache.get(e.name);return t?Promise.resolve(t):o.getLayer(e.name)},enumerable:!0,configurable:!0});this._data=u}}Object.defineProperty(p,"ColorMapInterpolator",{enumerable:!0,get:()=>f.ColorMapInterpolator}),Object.defineProperty(p,"NormalizationMode",{enumerable:!0,get:()=>f.NormalizationMode}),p.AutkGrammar=O,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
|
|
2
2
|
//# sourceMappingURL=autk-grammar.umd.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autk-grammar.umd.cjs","sources":["../src/adapters/data.ts","../src/adapters/map.ts","../src/adapters/plot.ts","../src/adapters/compute.ts","../src/main.ts"],"sourcesContent":["import { CsvDataSourceSpec, CustomDataSourceSpec, DataAdapter, DataSourceSpec, HeatmapSourceSpec, JoinSourceSpec, JsonDataSourceSpec, OsmDataSourceSpec } from '@urban-toolkit/the-urban-grammar';\r\nimport { AutkDb } from '@urban-toolkit/autk-db';\r\nimport type { FeatureCollection } from 'geojson';\r\nimport { Targets, GeoJsonCache } from '../types';\r\n\r\nexport function createDataAdapter(targets?: Targets, cache?: GeoJsonCache): DataAdapter {\r\n\r\n function print(db: AutkDb, targets?: Targets): void {\r\n if(!targets || !targets.db)\r\n return\r\n\r\n const div = document.getElementById(targets.db);\r\n if (div) {\r\n const tables = db.tables;\r\n\r\n div.innerHTML += `<ul>`;\r\n for (const table of tables) {\r\n div.innerHTML += `<li>${table.name}: (${table.source}, ${table.type}) </li>`;\r\n }\r\n div.innerHTML += `</ul>`;\r\n\r\n div.innerHTML += `<p>Number of tables: ${tables.length}</p>`;\r\n }\r\n }\r\n\r\n return {\r\n async resolveSource(context: AutkDb | undefined, spec: DataSourceSpec): Promise<AutkDb | undefined> {\r\n\r\n let db = context;\r\n\r\n if(!db){\r\n db = new AutkDb();\r\n await db.init();\r\n }\r\n\r\n let {type, ...rest_spec} = spec;\r\n\r\n switch (type) {\r\n case 'osm':\r\n await db.loadOsm(rest_spec as OsmDataSourceSpec);\r\n print(db, targets);\r\n return db;\r\n case 'csv':\r\n await db.loadCsv(rest_spec as CsvDataSourceSpec);\r\n print(db, targets);\r\n return db;\r\n case 'json':\r\n await db.loadJson(rest_spec as JsonDataSourceSpec);\r\n print(db, targets);\r\n return db;\r\n case 'geojson': {\r\n const geojsonSpec = rest_spec as CustomDataSourceSpec;\r\n let geojsonData: FeatureCollection | undefined;\r\n\r\n if (geojsonSpec.geojsonFileUrl) {\r\n const response = await fetch(geojsonSpec.geojsonFileUrl);\r\n geojsonData = await response.json() as FeatureCollection;\r\n } else {\r\n geojsonData = geojsonSpec.geojsonObject;\r\n }\r\n\r\n if (cache && geojsonData) cache.set(geojsonSpec.outputTableName, geojsonData);\r\n\r\n // Pass the fetched object directly so autk-db doesn't need to re-fetch\r\n if (geojsonData) {\r\n const { geojsonFileUrl: _url, ...specWithoutUrl } = geojsonSpec;\r\n await db.loadGeojson({ ...specWithoutUrl, geojsonObject: geojsonData });\r\n } else {\r\n await db.loadGeojson(geojsonSpec);\r\n }\r\n print(db, targets);\r\n return db;\r\n }\r\n case 'heatmap': {\r\n const hm = rest_spec as HeatmapSourceSpec;\r\n await db.buildHeatmap({\r\n tableJoinName: hm.tableJoinName,\r\n near: { distance: hm.near.distance },\r\n outputTableName: hm.outputTableName,\r\n grid: hm.grid,\r\n ...(hm.groupBy && { groupBy: hm.groupBy as any }),\r\n });\r\n print(db, targets);\r\n return db;\r\n }\r\n case 'join': {\r\n const jn = rest_spec as JoinSourceSpec;\r\n await db.spatialQuery({\r\n tableRootName: jn.tableRootName,\r\n tableJoinName: jn.tableJoinName,\r\n ...(jn.near && { near: jn.near }),\r\n ...(jn.groupBy && { groupBy: jn.groupBy }),\r\n });\r\n if (cache) {\r\n const updated = await db.getLayer(jn.tableRootName);\r\n cache.set(jn.tableRootName, updated);\r\n }\r\n print(db, targets);\r\n return db;\r\n }\r\n default:\r\n return\r\n }\r\n }\r\n }\r\n}\r\n","import { MapAdapter, MapSpec, NormalizationMode } from '@urban-toolkit/the-urban-grammar';\r\nimport { Targets, MapRegistry, ComputeCache } from '../types';\r\nimport { AutkMap, MapStyle } from '@urban-toolkit/autk-map';\r\nimport { ColorMapDomainStrategy } from '@urban-toolkit/autk-map';\r\nimport type { ColorMapConfig, ColorMapDomainSpec, LayerType } from '@urban-toolkit/autk-map';\r\nimport { AutkDb } from '@urban-toolkit/autk-db';\r\n\r\nfunction buildDomainSpec(\r\n normalization: MapSpec['layerRefs'][number]['normalization'],\r\n colorMapDomain?: string[],\r\n): ColorMapDomainSpec {\r\n if (colorMapDomain && colorMapDomain.length > 0)\r\n return { type: ColorMapDomainStrategy.USER, params: colorMapDomain };\r\n if (normalization?.mode === NormalizationMode.PERCENTILE) {\r\n const hasExplicitBounds =\r\n normalization.lowerPercentile !== undefined || normalization.upperPercentile !== undefined;\r\n if (hasExplicitBounds)\r\n return {\r\n type: ColorMapDomainStrategy.PERCENTILE,\r\n params: [normalization.lowerPercentile ?? 0, normalization.upperPercentile ?? 100],\r\n };\r\n return { type: ColorMapDomainStrategy.PERCENTILE };\r\n }\r\n return { type: ColorMapDomainStrategy.MIN_MAX };\r\n}\r\n\r\nfunction valueAtPath(obj: unknown, path: string): unknown {\r\n return path.split('.').reduce<unknown>((acc, key) => {\r\n if (acc == null || typeof acc !== 'object') return undefined;\r\n return (acc as Record<string, unknown>)[key];\r\n }, obj);\r\n}\r\n\r\nfunction setValueAtPath(obj: Record<string, unknown>, path: string, value: unknown): Record<string, unknown> {\r\n const keys = path.split('.');\r\n const result = { ...obj };\r\n let current = result as Record<string, unknown>;\r\n for (let i = 0; i < keys.length - 1; i++) {\r\n current[keys[i]] = { ...(current[keys[i]] as Record<string, unknown> ?? {}) };\r\n current = current[keys[i]] as Record<string, unknown>;\r\n }\r\n current[keys[keys.length - 1]] = value;\r\n return result;\r\n}\r\n\r\nexport function createMapAdapter(targets?: Targets, registry?: MapRegistry, computeCache?: ComputeCache): MapAdapter {\r\n\r\n async function loadLayers(map: AutkMap, context: AutkDb, spec: MapSpec): Promise<void> {\r\n let tableToTypeMap: {[tableName: string]: string} = {};\r\n for(const table of context.tables) {\r\n if(table.type !== undefined) tableToTypeMap[table.name] = table.type;\r\n }\r\n\r\n for(const layerRef of spec.layerRefs){\r\n const name = layerRef.dataRef;\r\n const type = tableToTypeMap[name] as LayerType;\r\n const getFnv = layerRef.getFnv;\r\n\r\n const rawData = computeCache?.get(name) ?? await context.getLayer(name);\r\n const data = {\r\n ...rawData,\r\n features: (rawData.features ?? []).filter((f: any) => f.geometry != null),\r\n };\r\n\r\n if(type === 'raster') {\r\n map.loadCollection(name, { collection: data, type: 'raster', property: getFnv ?? '' });\r\n } else {\r\n map.loadCollection(name, { collection: data, type });\r\n }\r\n\r\n if(layerRef.opacity != null)\r\n map.updateRenderInfo(name, { opacity: layerRef.opacity });\r\n\r\n if(layerRef.isColorMap)\r\n map.updateRenderInfo(name, { isColorMap: true });\r\n\r\n if(layerRef.isPick)\r\n map.updateRenderInfo(name, { isPick: true });\r\n\r\n if(layerRef.isSkip)\r\n map.updateRenderInfo(name, { isSkip: true });\r\n\r\n // When catchAllCategory is set, remap features whose property value is not\r\n // in colorMapDomain to the catch-all label, and extend the domain to include it.\r\n const { catchAllCategory, colorMapDomain } = layerRef;\r\n let thematicData = data;\r\n let effectiveDomain = colorMapDomain;\r\n\r\n if(getFnv && catchAllCategory && colorMapDomain?.length) {\r\n const allowed = new Set(colorMapDomain);\r\n thematicData = {\r\n ...data,\r\n features: data.features.map((f: any) => {\r\n const props = f.properties as Record<string, unknown>;\r\n const val = valueAtPath(props, getFnv);\r\n if(val === undefined || val === null || !allowed.has(String(val))) {\r\n return { ...f, properties: setValueAtPath(props, getFnv, catchAllCategory) };\r\n }\r\n return f;\r\n }),\r\n };\r\n effectiveDomain = allowed.has(catchAllCategory)\r\n ? colorMapDomain\r\n : [...colorMapDomain, catchAllCategory];\r\n }\r\n\r\n if(layerRef.colorMapInterpolator) {\r\n const colormapConfig: ColorMapConfig = {\r\n // urban-grammar ColorMapInterpolator values are string-compatible\r\n // with autk-core ColorMapInterpolator at runtime\r\n interpolator: layerRef.colorMapInterpolator as unknown as ColorMapConfig['interpolator'],\r\n domainSpec: buildDomainSpec(layerRef.normalization, effectiveDomain),\r\n };\r\n map.updateRenderInfo(name, { colormap: { config: colormapConfig }, isColorMap: true });\r\n }\r\n\r\n if(getFnv && type !== 'raster') {\r\n const property = getFnv.startsWith('properties.') ? getFnv : `properties.${getFnv}`;\r\n map.updateThematic(name, { collection: thematicData, property });\r\n }\r\n }\r\n }\r\n\r\n return {\r\n async resolveMap(context: AutkDb | undefined, spec: MapSpec, index: number = 0): Promise<void> {\r\n if(targets && targets.map && context){\r\n\r\n let canvas;\r\n\r\n if(Array.isArray(targets.map)){\r\n canvas = document.getElementById(targets.map[index]);\r\n }else{\r\n canvas = document.getElementById(targets.map);\r\n }\r\n\r\n if(!canvas)\r\n throw new Error(\"Could not find rendering target for map: \"+targets.map);\r\n\r\n if(!(canvas instanceof HTMLCanvasElement))\r\n throw new Error(\"Target for map is not a canvas: \"+targets.map);\r\n\r\n const map = new AutkMap(canvas);\r\n\r\n if(spec.style)\r\n MapStyle.setPredefinedStyle(spec.style)\r\n\r\n await map.init();\r\n await loadLayers(map, context, spec);\r\n\r\n if(registry)\r\n for(const layerRef of spec.layerRefs)\r\n registry.set(layerRef.dataRef, map);\r\n\r\n map.draw();\r\n }\r\n }\r\n }\r\n}\r\n","import { PlotAdapter, PlotSpec, PlotMark } from '@urban-toolkit/the-urban-grammar';\r\nimport { Targets, MapRegistry, GeoJsonCache } from '../types';\r\nimport { AutkDb } from '@urban-toolkit/autk-db';\r\nimport { AutkPlot, PlotEvent as AutkPlotEvent } from '@urban-toolkit/autk-plot';\r\nimport type { PlotEventData, PlotType, PlotTransformConfig } from '@urban-toolkit/autk-plot';\r\nimport { AutkMap, MapEvent } from '@urban-toolkit/autk-map';\r\nimport type { MapEventData } from '@urban-toolkit/autk-map';\r\nimport { FeatureCollection } from 'geojson';\r\n\r\nfunction grammarMarkToPlotType(mark: PlotMark): PlotType {\r\n const mapping: Record<PlotMark, PlotType> = {\r\n 'scatter': 'scatterplot',\r\n 'bar': 'barchart',\r\n 'line': 'linechart',\r\n 'linechart': 'linechart',\r\n 'parallel-coordinates': 'parallel-coordinates',\r\n 'table': 'table',\r\n 'heatmatrix': 'heatmatrix',\r\n };\r\n return mapping[mark];\r\n}\r\n\r\nexport function createPlotAdapter(targets?: Targets, registry?: MapRegistry, cache?: GeoJsonCache): PlotAdapter {\r\n\r\n return {\r\n async resolvePlot(context: unknown, spec: PlotSpec): Promise<void> {\r\n if(!targets || !targets.plot) return;\r\n\r\n const div = document.getElementById(targets.plot);\r\n if(!div) throw new Error(`Could not find plot target: ${targets.plot}`);\r\n\r\n const db = context as AutkDb | undefined;\r\n if(!db) throw new Error('No data context available for plot.');\r\n\r\n const geojson: FeatureCollection = cache?.get(spec.dataRef) ?? await db.getLayer(spec.dataRef);\r\n\r\n const events = (spec.events ?? []) as unknown as AutkPlotEvent[];\r\n\r\n const plot = new AutkPlot(div, {\r\n type: grammarMarkToPlotType(spec.mark),\r\n collection: geojson,\r\n attributes: { axis: spec.axis, ...(spec.color && { color: spec.color }) },\r\n labels: { axis: spec.axis, title: spec.title },\r\n events,\r\n ...(spec.width && { width: spec.width }),\r\n ...(spec.height && { height: spec.height }),\r\n ...(spec.margins && { margins: spec.margins }),\r\n ...(spec.transform && { transform: spec.transform as PlotTransformConfig }),\r\n });\r\n\r\n // Wire map ↔ plot events if a mapRef is specified\r\n if(spec.mapRef && registry) {\r\n const map: AutkMap | undefined = registry.get(spec.mapRef);\r\n\r\n if(map) {\r\n map.updateRenderInfo(spec.mapRef, { isPick: true });\r\n\r\n map.events.on(MapEvent.PICKING, ({ selection }: MapEventData) => {\r\n plot.setSelection(selection);\r\n });\r\n\r\n for(const event of events) {\r\n plot.events.on(event, ({ selection }: PlotEventData) => {\r\n map.setHighlightedIds(spec.mapRef!, selection);\r\n });\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\n","import { ComputeAdapter, ComputeSpec } from '@urban-toolkit/the-urban-grammar';\r\nimport { AutkDb } from '@urban-toolkit/autk-db';\r\nimport { AutkComputeEngine } from '@urban-toolkit/autk-compute';\r\nimport { FeatureCollection } from 'geojson';\r\nimport { ComputeCache } from '../types';\r\n\r\nexport function createComputeAdapter(cache?: ComputeCache): ComputeAdapter {\r\n\r\n return {\r\n async resolveCompute(context: AutkDb | undefined, spec: ComputeSpec): Promise<AutkDb | undefined> {\r\n if(context){\r\n const geojson: FeatureCollection = await context.getLayer(spec.dataRef);\r\n const engine = new AutkComputeEngine();\r\n\r\n const result = await engine.gpgpuPipeline({\r\n collection: geojson,\r\n variableMapping: spec.attributes,\r\n wgslBody: spec.wglsFunction,\r\n ...(spec.outputColumnName && { resultField: spec.outputColumnName }),\r\n ...(spec.outputColumns && { outputColumns: spec.outputColumns }),\r\n ...(spec.attributeArrays && { attributeArrays: spec.attributeArrays }),\r\n ...(spec.attributeMatrices && { attributeMatrices: spec.attributeMatrices }),\r\n ...(spec.uniforms && { uniforms: spec.uniforms }),\r\n ...(spec.uniformArrays && { uniformArrays: spec.uniformArrays }),\r\n ...(spec.uniformMatrices && { uniformMatrices: spec.uniformMatrices }),\r\n });\r\n\r\n if (cache) cache.set(spec.dataRef, result);\r\n\r\n return context;\r\n }\r\n }\r\n }\r\n}\r\n","import { DataAdapter, MapAdapter, PlotAdapter, ComputeAdapter, IEngine, UrbanSpec, createEngine } from \"@urban-toolkit/the-urban-grammar\";\r\nimport { createDataAdapter } from \"./adapters/data\";\r\nimport { createMapAdapter } from \"./adapters/map\";\r\nimport { createPlotAdapter } from \"./adapters/plot\";\r\nimport { createComputeAdapter } from \"./adapters/compute\";\r\nimport { Targets, MapRegistry, GeoJsonCache, ComputeCache } from \"./types\";\r\n\r\nexport class AutkGrammar {\r\n private dataAdapter?: DataAdapter;\r\n private mapAdapter?: MapAdapter;\r\n private plotAdapter?: PlotAdapter;\r\n private computeAdapter?: ComputeAdapter;\r\n private grammarEngine?: IEngine;\r\n\r\n constructor(targets?: Targets) {\r\n const registry: MapRegistry = new Map();\r\n const cache: GeoJsonCache = new Map();\r\n const computeCache: ComputeCache = new Map();\r\n this.dataAdapter = createDataAdapter(targets, cache);\r\n this.mapAdapter = createMapAdapter(targets, registry, computeCache);\r\n this.plotAdapter = createPlotAdapter(targets, registry, cache);\r\n this.computeAdapter = createComputeAdapter(computeCache);\r\n }\r\n\r\n async run(spec: UrbanSpec) {\r\n if(!this.dataAdapter)\r\n throw new Error('Database adapter not initialized. Please call the constructor first.');\r\n\r\n if(!this.mapAdapter)\r\n throw new Error('Map engine not initialized. Please call the constructor first.');\r\n\r\n if(!this.plotAdapter)\r\n throw new Error('Plot adapter not initialized. Please call the constructor first.');\r\n\r\n if(!this.computeAdapter)\r\n throw new Error('Compute adapter not initialized. Please call the constructor first.');\r\n\r\n this.grammarEngine = createEngine({\r\n spec,\r\n adapters: {\r\n db: this.dataAdapter,\r\n map: this.mapAdapter,\r\n plot: this.plotAdapter,\r\n compute: this.computeAdapter\r\n }\r\n });\r\n\r\n await this.grammarEngine.run();\r\n }\r\n}"],"names":["createDataAdapter","targets","cache","print","db","div","tables","table","context","spec","AutkDb","type","rest_spec","geojsonSpec","geojsonData","_url","specWithoutUrl","hm","jn","updated","buildDomainSpec","normalization","colorMapDomain","ColorMapDomainStrategy","NormalizationMode","valueAtPath","obj","path","acc","key","setValueAtPath","value","keys","result","current","i","createMapAdapter","registry","computeCache","loadLayers","map","tableToTypeMap","layerRef","name","getFnv","rawData","data","f","catchAllCategory","thematicData","effectiveDomain","allowed","props","val","colormapConfig","property","index","canvas","AutkMap","MapStyle","grammarMarkToPlotType","mark","createPlotAdapter","geojson","events","plot","AutkPlot","MapEvent","selection","event","createComputeAdapter","AutkComputeEngine","AutkGrammar","createEngine"],"mappings":"2nBAKO,SAASA,EAAkBC,EAAmBC,EAAmC,CAEpF,SAASC,EAAMC,EAAYH,EAAyB,CAChD,GAAG,CAACA,GAAW,CAACA,EAAQ,GACpB,OAEJ,MAAMI,EAAM,SAAS,eAAeJ,EAAQ,EAAE,EAC9C,GAAII,EAAK,CACL,MAAMC,EAASF,EAAG,OAElBC,EAAI,WAAa,OACjB,UAAWE,KAASD,EAChBD,EAAI,WAAa,OAAOE,EAAM,IAAI,MAAMA,EAAM,MAAM,KAAKA,EAAM,IAAI,UAEvEF,EAAI,WAAa,QAEjBA,EAAI,WAAa,wBAAwBC,EAAO,MAAM,MAC1D,CACJ,CAEA,MAAO,CACH,MAAM,cAAcE,EAA6BC,EAAmD,CAEhG,IAAIL,EAAKI,EAELJ,IACAA,EAAK,IAAIM,EAAAA,OACT,MAAMN,EAAG,KAAA,GAGb,GAAI,CAAC,KAAAO,EAAM,GAAGC,CAAA,EAAaH,EAE3B,OAAQE,EAAA,CACJ,IAAK,MACD,aAAMP,EAAG,QAAQQ,CAA8B,EAC/CT,EAAMC,EAAIH,CAAO,EACVG,EACX,IAAK,MACD,aAAMA,EAAG,QAAQQ,CAA8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,MAAM,gEAAgE,EAEpF,GAAG,CAAC,KAAK,YACL,MAAM,IAAI,MAAM,kEAAkE,EAEtF,GAAG,CAAC,KAAK,eACL,MAAM,IAAI,MAAM,qEAAqE,EAEzF,KAAK,cAAgBgE,eAAa,CAC9B,KAAAhE,EACA,SAAU,CACN,GAAI,KAAK,YACT,IAAK,KAAK,WACV,KAAM,KAAK,YACX,QAAS,KAAK,cAAA,CAClB,CACH,EAED,MAAM,KAAK,cAAc,IAAA,CAC7B,CACJ"}
|
|
1
|
+
{"version":3,"file":"autk-grammar.umd.cjs","sources":["../src/adapters/data.ts","../src/adapters/map.ts","../src/adapters/plot.ts","../src/adapters/compute.ts","../src/main.ts"],"sourcesContent":["import { CsvDataSourceSpec, CustomDataSourceSpec, DataAdapter, DataSourceSpec, HeatmapSourceSpec, JoinSourceSpec, JsonDataSourceSpec, OsmDataSourceSpec } from '@urban-toolkit/the-urban-grammar';\nimport { AutkDb, DEFAULT_WORKSPACE_COORDINATE_FORMAT } from '@urban-toolkit/autk-db';\nimport type { FeatureCollection } from 'geojson';\nimport { Targets, GeoJsonCache } from '../types';\n\nexport function createDataAdapter(targets?: Targets, cache?: GeoJsonCache): DataAdapter {\n\n function print(db: AutkDb, targets?: Targets): void {\n if(!targets || !targets.db)\n return\n\n const div = document.getElementById(targets.db);\n if (div) {\n const tables = db.tables;\n\n div.innerHTML += `<ul>`;\n for (const table of tables) {\n div.innerHTML += `<li>${table.name}: (${table.source}, ${table.type}) </li>`;\n }\n div.innerHTML += `</ul>`;\n\n div.innerHTML += `<p>Number of tables: ${tables.length}</p>`;\n }\n }\n\n return {\n async resolveSource(context: AutkDb | undefined, spec: DataSourceSpec): Promise<AutkDb | undefined> {\n\n let db = context;\n\n if(!db){\n db = new AutkDb();\n await db.init();\n }\n\n let {type, ...rest_spec} = spec;\n\n switch (type) {\n case 'osm':\n await db.loadOsm(rest_spec as OsmDataSourceSpec);\n print(db, targets);\n return db;\n case 'csv':\n await db.loadCsv(rest_spec as CsvDataSourceSpec);\n print(db, targets);\n return db;\n case 'json':\n await db.loadJson(rest_spec as JsonDataSourceSpec);\n print(db, targets);\n return db;\n case 'geojson': {\n const geojsonSpec = rest_spec as CustomDataSourceSpec;\n let geojsonData: FeatureCollection | undefined;\n\n if (geojsonSpec.geojsonFileUrl) {\n const response = await fetch(geojsonSpec.geojsonFileUrl);\n geojsonData = await response.json() as FeatureCollection;\n } else {\n geojsonData = geojsonSpec.geojsonObject;\n }\n\n if (cache && geojsonData) cache.set(geojsonSpec.outputTableName, geojsonData);\n\n // Pass the fetched object directly so autk-db doesn't need to re-fetch\n const loadSpec = geojsonData\n ? (() => { const s = { ...geojsonSpec, geojsonObject: geojsonData }; delete s.geojsonFileUrl; return s; })()\n : geojsonSpec;\n\n try {\n await db.loadGeojson(loadSpec);\n } catch (err) {\n const crsHint = loadSpec.coordinateFormat\n ? `coordinateFormat is set to \"${loadSpec.coordinateFormat}\"`\n : `no coordinateFormat was specified — defaulting to EPSG:4326 (WGS84 per RFC 7946)`;\n throw new Error(\n `Failed to load GeoJSON layer \"${loadSpec.outputTableName}\": ${err instanceof Error ? err.message : String(err)}. ` +\n `${crsHint}. Verify that coordinateFormat matches the actual CRS of the input data.`\n );\n }\n\n // Validate that the loaded geometry is within the workspace CRS extent.\n // A bounding box outside the valid world extent indicates a CRS mismatch.\n try {\n const bbox = await db.getBoundingBoxFromLayer(loadSpec.outputTableName);\n const WORLD_EXTENT = 25_000_000; // generous bound for DEFAULT_WORKSPACE_COORDINATE_FORMAT (EPSG:3395)\n if (\n !isFinite(bbox.minLon) || !isFinite(bbox.minLat) ||\n !isFinite(bbox.maxLon) || !isFinite(bbox.maxLat) ||\n Math.abs(bbox.minLon) > WORLD_EXTENT || Math.abs(bbox.maxLon) > WORLD_EXTENT ||\n Math.abs(bbox.minLat) > WORLD_EXTENT || Math.abs(bbox.maxLat) > WORLD_EXTENT\n ) {\n throw new Error(\n `Geometry bounding box after transform is invalid for layer \"${loadSpec.outputTableName}\" ` +\n `(bbox: [${bbox.minLon}, ${bbox.minLat}, ${bbox.maxLon}, ${bbox.maxLat}]). ` +\n `Verify that coordinateFormat matches the actual CRS of the input data. ` +\n `The workspace uses ${DEFAULT_WORKSPACE_COORDINATE_FORMAT}; input is expected in EPSG:4326 by default.`\n );\n }\n } catch (bboxErr) {\n if (bboxErr instanceof Error && bboxErr.message.includes('bounding box after transform')) throw bboxErr;\n // getBoundingBoxFromLayer failed (empty table, unsupported layer type, etc.) — skip validation\n }\n print(db, targets);\n return db;\n }\n case 'heatmap': {\n const hm = rest_spec as HeatmapSourceSpec;\n await db.buildHeatmap({\n tableJoinName: hm.tableJoinName,\n near: { distance: hm.near.distance },\n outputTableName: hm.outputTableName,\n grid: hm.grid,\n ...(hm.groupBy && { groupBy: hm.groupBy as any }),\n });\n print(db, targets);\n return db;\n }\n case 'join': {\n const jn = rest_spec as JoinSourceSpec;\n await db.spatialQuery({\n tableRootName: jn.tableRootName,\n tableJoinName: jn.tableJoinName,\n ...(jn.near && { near: jn.near }),\n ...(jn.groupBy && { groupBy: jn.groupBy }),\n });\n if (cache) {\n const updated = await db.getLayer(jn.tableRootName);\n cache.set(jn.tableRootName, updated);\n }\n print(db, targets);\n return db;\n }\n default:\n return\n }\n }\n }\n}\n","import { MapAdapter, MapSpec, NormalizationMode } from '@urban-toolkit/the-urban-grammar';\nimport { Targets, MapRegistry, ComputeCache } from '../types';\nimport { AutkMap, MapStyle } from '@urban-toolkit/autk-map';\nimport { ColorMapDomainStrategy } from '@urban-toolkit/autk-map';\nimport type { ColorMapConfig, ColorMapDomainSpec, LayerType } from '@urban-toolkit/autk-map';\nimport { AutkDb } from '@urban-toolkit/autk-db';\n\nfunction buildDomainSpec(\n normalization: MapSpec['layerRefs'][number]['normalization'],\n colorMapDomain?: string[],\n): ColorMapDomainSpec {\n if (colorMapDomain && colorMapDomain.length > 0)\n return { type: ColorMapDomainStrategy.USER, params: colorMapDomain };\n if (normalization?.mode === NormalizationMode.PERCENTILE) {\n const hasExplicitBounds =\n normalization.lowerPercentile !== undefined || normalization.upperPercentile !== undefined;\n if (hasExplicitBounds)\n return {\n type: ColorMapDomainStrategy.PERCENTILE,\n params: [normalization.lowerPercentile ?? 0, normalization.upperPercentile ?? 100],\n };\n return { type: ColorMapDomainStrategy.PERCENTILE };\n }\n return { type: ColorMapDomainStrategy.MIN_MAX };\n}\n\nfunction valueAtPath(obj: unknown, path: string): unknown {\n return path.split('.').reduce<unknown>((acc, key) => {\n if (acc == null || typeof acc !== 'object') return undefined;\n return (acc as Record<string, unknown>)[key];\n }, obj);\n}\n\nfunction setValueAtPath(obj: Record<string, unknown>, path: string, value: unknown): Record<string, unknown> {\n const keys = path.split('.');\n const result = { ...obj };\n let current = result as Record<string, unknown>;\n for (let i = 0; i < keys.length - 1; i++) {\n current[keys[i]] = { ...(current[keys[i]] as Record<string, unknown> ?? {}) };\n current = current[keys[i]] as Record<string, unknown>;\n }\n current[keys[keys.length - 1]] = value;\n return result;\n}\n\nexport function createMapAdapter(targets?: Targets, registry?: MapRegistry, computeCache?: ComputeCache): MapAdapter {\n\n async function loadLayers(map: AutkMap, context: AutkDb, spec: MapSpec): Promise<void> {\n let tableToTypeMap: {[tableName: string]: string} = {};\n for(const table of context.tables) {\n if(table.type !== undefined) tableToTypeMap[table.name] = table.type;\n }\n\n for(const layerRef of spec.layerRefs){\n const name = layerRef.dataRef;\n const type = tableToTypeMap[name] as LayerType;\n const getFnv = layerRef.getFnv;\n\n const rawData = computeCache?.get(name) ?? await context.getLayer(name);\n const data = {\n ...rawData,\n features: (rawData.features ?? []).filter((f: any) => f.geometry != null),\n };\n\n if(type === 'raster') {\n map.loadCollection(name, { collection: data, type: 'raster', property: getFnv ?? '' });\n } else {\n map.loadCollection(name, { collection: data, type });\n }\n\n if(layerRef.opacity != null)\n map.updateRenderInfo(name, { opacity: layerRef.opacity });\n\n if(layerRef.isColorMap)\n map.updateRenderInfo(name, { isColorMap: true });\n\n if(layerRef.isPick)\n map.updateRenderInfo(name, { isPick: true });\n\n if(layerRef.isSkip)\n map.updateRenderInfo(name, { isSkip: true });\n\n // When catchAllCategory is set, remap features whose property value is not\n // in colorMapDomain to the catch-all label, and extend the domain to include it.\n const { catchAllCategory, colorMapDomain } = layerRef;\n let thematicData = data;\n let effectiveDomain = colorMapDomain;\n\n if(getFnv && catchAllCategory && colorMapDomain?.length) {\n const allowed = new Set(colorMapDomain);\n thematicData = {\n ...data,\n features: data.features.map((f: any) => {\n const props = f.properties as Record<string, unknown>;\n const val = valueAtPath(props, getFnv);\n if(val === undefined || val === null || !allowed.has(String(val))) {\n return { ...f, properties: setValueAtPath(props, getFnv, catchAllCategory) };\n }\n return f;\n }),\n };\n effectiveDomain = allowed.has(catchAllCategory)\n ? colorMapDomain\n : [...colorMapDomain, catchAllCategory];\n }\n\n if(layerRef.colorMapInterpolator) {\n const colormapConfig: ColorMapConfig = {\n // urban-grammar ColorMapInterpolator values are string-compatible\n // with autk-core ColorMapInterpolator at runtime\n interpolator: layerRef.colorMapInterpolator as unknown as ColorMapConfig['interpolator'],\n domainSpec: buildDomainSpec(layerRef.normalization, effectiveDomain),\n };\n map.updateRenderInfo(name, { colormap: { config: colormapConfig }, isColorMap: true });\n }\n\n if(getFnv && type !== 'raster') {\n const property = getFnv.startsWith('properties.') ? getFnv : `properties.${getFnv}`;\n map.updateThematic(name, { collection: thematicData, property });\n }\n }\n }\n\n return {\n async resolveMap(context: AutkDb | undefined, spec: MapSpec, index: number = 0): Promise<void> {\n if(targets && targets.map && context){\n\n let canvas;\n\n if(Array.isArray(targets.map)){\n canvas = document.getElementById(targets.map[index]);\n }else{\n canvas = document.getElementById(targets.map);\n }\n\n if(!canvas)\n throw new Error(\"Could not find rendering target for map: \"+targets.map);\n\n if(!(canvas instanceof HTMLCanvasElement))\n throw new Error(\"Target for map is not a canvas: \"+targets.map);\n\n const map = new AutkMap(canvas);\n\n if(spec.style)\n MapStyle.setPredefinedStyle(spec.style)\n\n await map.init();\n await loadLayers(map, context, spec);\n\n if(registry)\n for(const layerRef of spec.layerRefs)\n registry.set(layerRef.dataRef, map);\n\n map.draw();\n }\n }\n }\n}\n","import { PlotAdapter, PlotSpec, PlotMark } from '@urban-toolkit/the-urban-grammar';\nimport { Targets, MapRegistry, GeoJsonCache } from '../types';\nimport { AutkDb } from '@urban-toolkit/autk-db';\nimport { AutkPlot, PlotEvent as AutkPlotEvent } from '@urban-toolkit/autk-plot';\nimport type { PlotEventData, PlotType, PlotTransformConfig } from '@urban-toolkit/autk-plot';\nimport { AutkMap, MapEvent } from '@urban-toolkit/autk-map';\nimport type { MapEventData } from '@urban-toolkit/autk-map';\nimport { FeatureCollection } from 'geojson';\n\nfunction grammarMarkToPlotType(mark: PlotMark): PlotType {\n const mapping: Record<PlotMark, PlotType> = {\n 'scatter': 'scatterplot',\n 'bar': 'barchart',\n 'line': 'linechart',\n 'linechart': 'linechart',\n 'parallel-coordinates': 'parallel-coordinates',\n 'table': 'table',\n 'heatmatrix': 'heatmatrix',\n };\n return mapping[mark];\n}\n\nexport function createPlotAdapter(targets?: Targets, registry?: MapRegistry, cache?: GeoJsonCache): PlotAdapter {\n\n return {\n async resolvePlot(context: unknown, spec: PlotSpec): Promise<void> {\n if(!targets || !targets.plot) return;\n\n const div = document.getElementById(targets.plot);\n if(!div) throw new Error(`Could not find plot target: ${targets.plot}`);\n\n const db = context as AutkDb | undefined;\n if(!db) throw new Error('No data context available for plot.');\n\n const geojson: FeatureCollection = cache?.get(spec.dataRef) ?? await db.getLayer(spec.dataRef);\n\n const events = (spec.events ?? []) as unknown as AutkPlotEvent[];\n\n const plot = new AutkPlot(div, {\n type: grammarMarkToPlotType(spec.mark),\n collection: geojson,\n attributes: { axis: spec.axis, ...(spec.color && { color: spec.color }) },\n labels: { axis: spec.axis, title: spec.title },\n events,\n ...(spec.width && { width: spec.width }),\n ...(spec.height && { height: spec.height }),\n ...(spec.margins && { margins: spec.margins }),\n ...(spec.transform && { transform: spec.transform as PlotTransformConfig }),\n });\n\n // Wire map ↔ plot events if a mapRef is specified\n if(spec.mapRef && registry) {\n const map: AutkMap | undefined = registry.get(spec.mapRef);\n\n if(map) {\n map.updateRenderInfo(spec.mapRef, { isPick: true });\n\n map.events.on(MapEvent.PICKING, ({ selection }: MapEventData) => {\n plot.setSelection(selection);\n });\n\n for(const event of events) {\n plot.events.on(event, ({ selection }: PlotEventData) => {\n map.setHighlightedIds(spec.mapRef!, selection);\n });\n }\n }\n }\n }\n }\n}\n","import { ComputeAdapter, ComputeSpec } from '@urban-toolkit/the-urban-grammar';\nimport { AutkDb } from '@urban-toolkit/autk-db';\nimport { AutkComputeEngine } from '@urban-toolkit/autk-compute';\nimport { FeatureCollection } from 'geojson';\nimport { ComputeCache } from '../types';\n\nexport function createComputeAdapter(cache?: ComputeCache): ComputeAdapter {\n\n return {\n async resolveCompute(context: AutkDb | undefined, spec: ComputeSpec): Promise<AutkDb | undefined> {\n if(context){\n const geojson: FeatureCollection = await context.getLayer(spec.dataRef);\n const engine = new AutkComputeEngine();\n\n const result = await engine.gpgpuPipeline({\n collection: geojson,\n variableMapping: spec.attributes,\n wgslBody: spec.wglsFunction,\n ...(spec.outputColumnName && { resultField: spec.outputColumnName }),\n ...(spec.outputColumns && { outputColumns: spec.outputColumns }),\n ...(spec.attributeArrays && { attributeArrays: spec.attributeArrays }),\n ...(spec.attributeMatrices && { attributeMatrices: spec.attributeMatrices }),\n ...(spec.uniforms && { uniforms: spec.uniforms }),\n ...(spec.uniformArrays && { uniformArrays: spec.uniformArrays }),\n ...(spec.uniformMatrices && { uniformMatrices: spec.uniformMatrices }),\n });\n\n if (cache) cache.set(spec.dataRef, result);\n\n return context;\n }\n }\n }\n}\n","import { DataAdapter, MapAdapter, PlotAdapter, ComputeAdapter, IEngine, UrbanSpec, createEngine } from \"@urban-toolkit/the-urban-grammar\";\nimport { AutkDb, DEFAULT_WORKSPACE_COORDINATE_FORMAT } from \"@urban-toolkit/autk-db\";\nimport { FeatureCollection } from \"geojson\";\nimport { createDataAdapter } from \"./adapters/data\";\nimport { createMapAdapter } from \"./adapters/map\";\nimport { createPlotAdapter } from \"./adapters/plot\";\nimport { createComputeAdapter } from \"./adapters/compute\";\nimport { Targets, MapRegistry, GeoJsonCache, ComputeCache } from \"./types\";\n\nexport class AutkGrammar {\n private dataAdapter?: DataAdapter;\n private mapAdapter?: MapAdapter;\n private plotAdapter?: PlotAdapter;\n private computeAdapter?: ComputeAdapter;\n private grammarEngine?: IEngine;\n private _computeCache: ComputeCache = new Map();\n private _data: Record<string, Promise<FeatureCollection>> = {};\n\n constructor(targets?: Targets) {\n const registry: MapRegistry = new Map();\n const cache: GeoJsonCache = new Map();\n this.dataAdapter = createDataAdapter(targets, cache);\n this.mapAdapter = createMapAdapter(targets, registry, this._computeCache);\n this.plotAdapter = createPlotAdapter(targets, registry, cache);\n this.computeAdapter = createComputeAdapter(this._computeCache);\n }\n\n /**\n * The coordinate reference system used internally by the autk workspace.\n *\n * Input data is expected in EPSG:4326 (WGS84) by default and is transformed\n * to this CRS on load. Consumers that prepare data for injection (e.g. by\n * serialising a GeoDataFrame) can read this value and reproject accordingly\n * instead of hard-coding a CRS string.\n */\n get workspaceCrs(): string {\n return DEFAULT_WORKSPACE_COORDINATE_FORMAT;\n }\n\n get data(): Record<string, Promise<FeatureCollection>> {\n return this._data;\n }\n\n async run(spec: UrbanSpec) {\n if(!this.dataAdapter)\n throw new Error('Database adapter not initialized. Please call the constructor first.');\n\n if(!this.mapAdapter)\n throw new Error('Map engine not initialized. Please call the constructor first.');\n\n if(!this.plotAdapter)\n throw new Error('Plot adapter not initialized. Please call the constructor first.');\n\n if(!this.computeAdapter)\n throw new Error('Compute adapter not initialized. Please call the constructor first.');\n\n this.grammarEngine = createEngine({\n spec,\n adapters: {\n db: this.dataAdapter,\n map: this.mapAdapter,\n plot: this.plotAdapter,\n compute: this.computeAdapter\n }\n });\n\n await this.grammarEngine.run();\n\n const db = this.grammarEngine.context as AutkDb | undefined;\n if (!db) {\n console.warn('Grammar engine produced no data context.');\n this._data = {};\n return;\n }\n\n const dataObj: Record<string, Promise<FeatureCollection>> = {};\n for (const table of db.getLayerTables()) {\n Object.defineProperty(dataObj, table.name, {\n get: () => {\n const computed = this._computeCache.get(table.name);\n return computed ? Promise.resolve(computed) : db.getLayer(table.name);\n },\n enumerable: true,\n configurable: true,\n });\n }\n this._data = dataObj;\n }\n}"],"names":["createDataAdapter","targets","cache","print","db","div","tables","table","context","spec","AutkDb","type","rest_spec","geojsonSpec","geojsonData","loadSpec","s","err","crsHint","bbox","WORLD_EXTENT","DEFAULT_WORKSPACE_COORDINATE_FORMAT","bboxErr","hm","jn","updated","buildDomainSpec","normalization","colorMapDomain","ColorMapDomainStrategy","NormalizationMode","valueAtPath","obj","path","acc","key","setValueAtPath","value","keys","result","current","i","createMapAdapter","registry","computeCache","loadLayers","map","tableToTypeMap","layerRef","name","getFnv","rawData","data","f","catchAllCategory","thematicData","effectiveDomain","allowed","props","val","colormapConfig","property","index","canvas","AutkMap","MapStyle","grammarMarkToPlotType","mark","createPlotAdapter","geojson","events","plot","AutkPlot","MapEvent","selection","event","createComputeAdapter","AutkComputeEngine","AutkGrammar","createEngine","dataObj","computed"],"mappings":"2nBAKO,SAASA,EAAkBC,EAAmBC,EAAmC,CAEpF,SAASC,EAAMC,EAAYH,EAAyB,CAChD,GAAG,CAACA,GAAW,CAACA,EAAQ,GACpB,OAEJ,MAAMI,EAAM,SAAS,eAAeJ,EAAQ,EAAE,EAC9C,GAAII,EAAK,CACL,MAAMC,EAASF,EAAG,OAElBC,EAAI,WAAa,OACjB,UAAWE,KAASD,EAChBD,EAAI,WAAa,OAAOE,EAAM,IAAI,MAAMA,EAAM,MAAM,KAAKA,EAAM,IAAI,UAEvEF,EAAI,WAAa,QAEjBA,EAAI,WAAa,wBAAwBC,EAAO,MAAM,MAC1D,CACJ,CAEA,MAAO,CACH,MAAM,cAAcE,EAA6BC,EAAmD,CAEhG,IAAIL,EAAKI,EAELJ,IACAA,EAAK,IAAIM,EAA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,kEAAkE,EAEtF,GAAG,CAAC,KAAK,eACL,MAAM,IAAI,MAAM,qEAAqE,EAEzF,KAAK,cAAgBsE,eAAa,CAC9B,KAAAtE,EACA,SAAU,CACN,GAAI,KAAK,YACT,IAAK,KAAK,WACV,KAAM,KAAK,YACX,QAAS,KAAK,cAAA,CAClB,CACH,EAED,MAAM,KAAK,cAAc,IAAA,EAEzB,MAAML,EAAK,KAAK,cAAc,QAC9B,GAAI,CAACA,EAAI,CACL,QAAQ,KAAK,0CAA0C,EACvD,KAAK,MAAQ,CAAA,EACb,MACJ,CAEA,MAAM4E,EAAsD,CAAA,EAC5D,UAAWzE,KAASH,EAAG,iBACnB,OAAO,eAAe4E,EAASzE,EAAM,KAAM,CACvC,IAAK,IAAM,CACP,MAAM0E,EAAW,KAAK,cAAc,IAAI1E,EAAM,IAAI,EAClD,OAAO0E,EAAW,QAAQ,QAAQA,CAAQ,EAAI7E,EAAG,SAASG,EAAM,IAAI,CACxE,EACA,WAAY,GACZ,aAAc,EAAA,CACjB,EAEL,KAAK,MAAQyE,CACjB,CACJ"}
|
package/dist/main.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UrbanSpec } from '@urban-toolkit/the-urban-grammar';
|
|
2
|
+
import { FeatureCollection } from 'geojson';
|
|
2
3
|
import { Targets } from './types';
|
|
3
4
|
export declare class AutkGrammar {
|
|
4
5
|
private dataAdapter?;
|
|
@@ -6,6 +7,18 @@ export declare class AutkGrammar {
|
|
|
6
7
|
private plotAdapter?;
|
|
7
8
|
private computeAdapter?;
|
|
8
9
|
private grammarEngine?;
|
|
10
|
+
private _computeCache;
|
|
11
|
+
private _data;
|
|
9
12
|
constructor(targets?: Targets);
|
|
13
|
+
/**
|
|
14
|
+
* The coordinate reference system used internally by the autk workspace.
|
|
15
|
+
*
|
|
16
|
+
* Input data is expected in EPSG:4326 (WGS84) by default and is transformed
|
|
17
|
+
* to this CRS on load. Consumers that prepare data for injection (e.g. by
|
|
18
|
+
* serialising a GeoDataFrame) can read this value and reproject accordingly
|
|
19
|
+
* instead of hard-coding a CRS string.
|
|
20
|
+
*/
|
|
21
|
+
get workspaceCrs(): string;
|
|
22
|
+
get data(): Record<string, Promise<FeatureCollection>>;
|
|
10
23
|
run(spec: UrbanSpec): Promise<void>;
|
|
11
24
|
}
|
package/package.json
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@urban-toolkit/autk-grammar",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Autark adapter for the urban grammar",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"author": "Gustavo Moreira",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "https://github.com/urban-toolkit/the-urban-grammar"
|
|
10
|
-
},
|
|
11
|
-
"type": "module",
|
|
12
|
-
"files": [
|
|
13
|
-
"dist"
|
|
14
|
-
],
|
|
15
|
-
"main": "./dist/autk-grammar.umd.cjs",
|
|
16
|
-
"module": "./dist/autk-grammar.js",
|
|
17
|
-
"types": "./dist/index.d.ts",
|
|
18
|
-
"exports": {
|
|
19
|
-
".": {
|
|
20
|
-
"types": "./dist/index.d.ts",
|
|
21
|
-
"import": "./dist/autk-grammar.js",
|
|
22
|
-
"require": "./dist/autk-grammar.umd.cjs"
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"scripts": {
|
|
26
|
-
"doc": "typedoc --options typedoc.json --watch",
|
|
27
|
-
"dev": "vite",
|
|
28
|
-
"dev-build": "vite build --watch",
|
|
29
|
-
"build": "tsc && vite build",
|
|
30
|
-
"preview": "vite preview",
|
|
31
|
-
"lint": "eslint src",
|
|
32
|
-
"typecheck": "tsc --noEmit",
|
|
33
|
-
"format": "prettier --write ."
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
|
37
|
-
"@typescript-eslint/parser": "^8.46.2",
|
|
38
|
-
"@types/geojson": "^7946.0.16",
|
|
39
|
-
"@webgpu/types": "^0.1.66",
|
|
40
|
-
"eslint": "^9.38.0",
|
|
41
|
-
"eslint-config-prettier": "^10.1.8",
|
|
42
|
-
"globals": "^16.4.0",
|
|
43
|
-
"prettier": "^3.6.2",
|
|
44
|
-
"ts-loader": "^9.5.4",
|
|
45
|
-
"typedoc": "^0.28.14",
|
|
46
|
-
"typedoc-theme-oxide": "^0.2.0",
|
|
47
|
-
"typescript": "^5.9.3",
|
|
48
|
-
"vite": "^7.1.12",
|
|
49
|
-
"vite-plugin-dts": "^4.5.4",
|
|
50
|
-
"vite-plugin-glsl": "^1.5.4"
|
|
51
|
-
},
|
|
52
|
-
"dependencies": {
|
|
53
|
-
"@urban-toolkit/autk-db": "^2.1.2",
|
|
54
|
-
"@urban-toolkit/autk-map": "^2.1.2",
|
|
55
|
-
"@urban-toolkit/autk-plot": "^2.1.2",
|
|
56
|
-
"@urban-toolkit/autk-compute": "^2.1.2"
|
|
57
|
-
},
|
|
58
|
-
"peerDependencies": {
|
|
59
|
-
"@urban-toolkit/the-urban-grammar": "^0.1.0"
|
|
60
|
-
}
|
|
61
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@urban-toolkit/autk-grammar",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Autark adapter for the urban grammar",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Gustavo Moreira",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/urban-toolkit/the-urban-grammar"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"main": "./dist/autk-grammar.umd.cjs",
|
|
16
|
+
"module": "./dist/autk-grammar.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/autk-grammar.js",
|
|
22
|
+
"require": "./dist/autk-grammar.umd.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"doc": "typedoc --options typedoc.json --watch",
|
|
27
|
+
"dev": "vite",
|
|
28
|
+
"dev-build": "vite build --watch",
|
|
29
|
+
"build": "tsc && vite build",
|
|
30
|
+
"preview": "vite preview",
|
|
31
|
+
"lint": "eslint src",
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"format": "prettier --write ."
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
|
37
|
+
"@typescript-eslint/parser": "^8.46.2",
|
|
38
|
+
"@types/geojson": "^7946.0.16",
|
|
39
|
+
"@webgpu/types": "^0.1.66",
|
|
40
|
+
"eslint": "^9.38.0",
|
|
41
|
+
"eslint-config-prettier": "^10.1.8",
|
|
42
|
+
"globals": "^16.4.0",
|
|
43
|
+
"prettier": "^3.6.2",
|
|
44
|
+
"ts-loader": "^9.5.4",
|
|
45
|
+
"typedoc": "^0.28.14",
|
|
46
|
+
"typedoc-theme-oxide": "^0.2.0",
|
|
47
|
+
"typescript": "^5.9.3",
|
|
48
|
+
"vite": "^7.1.12",
|
|
49
|
+
"vite-plugin-dts": "^4.5.4",
|
|
50
|
+
"vite-plugin-glsl": "^1.5.4"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@urban-toolkit/autk-db": "^2.1.2",
|
|
54
|
+
"@urban-toolkit/autk-map": "^2.1.2",
|
|
55
|
+
"@urban-toolkit/autk-plot": "^2.1.2",
|
|
56
|
+
"@urban-toolkit/autk-compute": "^2.1.2"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@urban-toolkit/the-urban-grammar": "^0.1.0"
|
|
60
|
+
}
|
|
61
|
+
}
|