@urban-toolkit/autk-grammar 0.2.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/build/autk-grammar-schema.json +2084 -0
- package/dist/autk-grammar.js +395 -217
- package/dist/autk-grammar.js.map +1 -1
- package/dist/autk-grammar.umd.cjs +2 -1
- package/dist/autk-grammar.umd.cjs.map +1 -1
- package/dist/index.d.ts +410 -80
- package/package.json +13 -9
package/dist/autk-grammar.js
CHANGED
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
import { AutkDb as
|
|
2
|
-
import { AutkMap as
|
|
3
|
-
import { AutkPlot as
|
|
4
|
-
import { ColorMapDomainStrategy as
|
|
5
|
-
import { AutkComputeEngine as
|
|
6
|
-
function
|
|
7
|
-
const { spec:
|
|
8
|
-
let
|
|
1
|
+
import { AutkDb as Q, DEFAULT_WORKSPACE_COORDINATE_FORMAT as F } from "@urban-toolkit/autk-db";
|
|
2
|
+
import { AutkMap as $, MapEvent as P } from "@urban-toolkit/autk-map";
|
|
3
|
+
import { AutkPlot as Y, PlotEvent as A } from "@urban-toolkit/autk-plot";
|
|
4
|
+
import { ColorMapDomainStrategy as w } from "@urban-toolkit/autk-core";
|
|
5
|
+
import { AutkComputeEngine as H } from "@urban-toolkit/autk-compute";
|
|
6
|
+
function V(t) {
|
|
7
|
+
const { spec: e, adapters: r } = t;
|
|
8
|
+
let a;
|
|
9
9
|
async function s() {
|
|
10
|
-
let
|
|
11
|
-
if (
|
|
12
|
-
for (const
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
for (const
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
if (Array.isArray(
|
|
19
|
-
for (let
|
|
20
|
-
let u =
|
|
21
|
-
await
|
|
10
|
+
let l;
|
|
11
|
+
if (e.data)
|
|
12
|
+
for (const n of e.data)
|
|
13
|
+
l = await r.db.resolveSource(l, n);
|
|
14
|
+
if (e.compute)
|
|
15
|
+
for (const n of e.compute)
|
|
16
|
+
l = await r.compute.resolveCompute(l, n);
|
|
17
|
+
if (e.map)
|
|
18
|
+
if (Array.isArray(e.map))
|
|
19
|
+
for (let n = 0; n < e.map.length; n++) {
|
|
20
|
+
let u = e.map[n];
|
|
21
|
+
await r.map.resolveMap(l, u, n);
|
|
22
22
|
}
|
|
23
23
|
else
|
|
24
|
-
await
|
|
25
|
-
if (
|
|
26
|
-
if (Array.isArray(
|
|
27
|
-
for (const
|
|
28
|
-
await
|
|
24
|
+
await r.map.resolveMap(l, e.map);
|
|
25
|
+
if (e.plot)
|
|
26
|
+
if (Array.isArray(e.plot))
|
|
27
|
+
for (const n of e.plot)
|
|
28
|
+
await r.plot.resolvePlot(l, n);
|
|
29
29
|
else
|
|
30
|
-
await
|
|
31
|
-
|
|
30
|
+
await r.plot.resolvePlot(l, e.plot);
|
|
31
|
+
a = l;
|
|
32
32
|
}
|
|
33
|
-
function o(
|
|
34
|
-
return console.log("Spec to update",
|
|
35
|
-
|
|
33
|
+
function o(l) {
|
|
34
|
+
return console.log("Spec to update", l), new Promise((n) => {
|
|
35
|
+
n();
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
function i() {
|
|
39
39
|
console.log("Function not implemented yet");
|
|
40
40
|
}
|
|
41
41
|
return { run: s, updatedSpec: o, destroy: i, get context() {
|
|
42
|
-
return
|
|
42
|
+
return a;
|
|
43
43
|
} };
|
|
44
44
|
}
|
|
45
|
-
var
|
|
46
|
-
function
|
|
47
|
-
const { autoLoadLayers:
|
|
48
|
-
return { ...
|
|
45
|
+
var k = /* @__PURE__ */ ((t) => (t.CAT_ACCENT = "schemeAccent", t.CAT_DARK2 = "schemeDark2", t.CAT_CATEGORY10 = "schemeCategory10", t.CAT_OBSERVABLE10 = "schemeObservable10", t.CAT_PAIRED = "schemePaired", t.CAT_PASTEL1 = "schemePastel1", t.CAT_PASTEL2 = "schemePastel2", t.CAT_SET1 = "schemeSet1", t.CAT_SET2 = "schemeSet2", t.CAT_SET3 = "schemeSet3", t.CAT_TABLEAU10 = "schemeTableau10", t.SEQ_REDS = "interpolateReds", t.SEQ_BLUES = "interpolateBlues", t.SEQ_GREENS = "interpolateGreens", t.SEQ_GREYS = "interpolateGreys", t.SEQ_ORANGES = "interpolateOranges", t.SEQ_PURPLES = "interpolatePurples", t.SEQ_TURBO = "interpolateTurbo", t.SEQ_VIRIDIS = "interpolateViridis", t.SEQ_INFERNO = "interpolateInferno", t.SEQ_MAGMA = "interpolateMagma", t.SEQ_PLASMA = "interpolatePlasma", t.SEQ_CIVIDIS = "interpolateCividis", t.SEQ_WARM = "interpolateWarm", t.SEQ_COOL = "interpolateCool", t.SEQ_CUBEHELIX_DEFAULT = "interpolateCubehelixDefault", t.SEQ_BU_GN = "interpolateBuGn", t.SEQ_BU_PU = "interpolateBuPu", t.SEQ_GN_BU = "interpolateGnBu", t.SEQ_OR_RD = "interpolateOrRd", t.SEQ_PU_BU_GN = "interpolatePuBuGn", t.SEQ_PU_BU = "interpolatePuBu", t.SEQ_PU_RD = "interpolatePuRd", t.SEQ_RD_PU = "interpolateRdPu", t.SEQ_YL_GN_BU = "interpolateYlGnBu", t.SEQ_YL_GN = "interpolateYlGn", t.SEQ_YL_OR_BR = "interpolateYlOrBr", t.SEQ_YL_OR_RD = "interpolateYlOrRd", t.DIV_BR_BG = "interpolateBrBG", t.DIV_PR_GN = "interpolatePRGn", t.DIV_PI_YG = "interpolatePiYG", t.DIV_PU_OR = "interpolatePuOr", t.DIV_RED_BLUE = "interpolateRdBu", t.DIV_RED_GREY = "interpolateRdGy", t.DIV_RED_YELLOW_BLUE = "interpolateRdYlBu", t.DIV_RED_YELLOW_GREEN = "interpolateRdYlGn", t.DIV_SPECTRAL = "interpolateSpectral", t))(k || {}), O = /* @__PURE__ */ ((t) => (t.MIN_MAX = "minMax", t.PERCENTILE = "percentile", t))(O || {});
|
|
46
|
+
function W(t) {
|
|
47
|
+
const { autoLoadLayers: e, ...r } = t;
|
|
48
|
+
return { ...r, autoLoadLayers: { layers: e?.layers ?? [] } };
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
function
|
|
50
|
+
function J(t, e) {
|
|
51
|
+
function r(a, s) {
|
|
52
52
|
if (!s || !s.db)
|
|
53
53
|
return;
|
|
54
54
|
const o = document.getElementById(s.db);
|
|
55
55
|
if (o) {
|
|
56
|
-
const i =
|
|
56
|
+
const i = a.getTablesMetadata();
|
|
57
57
|
o.innerHTML += "<ul>";
|
|
58
|
-
for (const
|
|
59
|
-
o.innerHTML += `<li>${
|
|
58
|
+
for (const l of i)
|
|
59
|
+
o.innerHTML += `<li>${l.name}: (${l.source}, ${l.type}) </li>`;
|
|
60
60
|
o.innerHTML += "</ul>", o.innerHTML += `<p>Number of tables: ${i.length}</p>`;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
return {
|
|
64
|
-
async resolveSource(
|
|
65
|
-
let o =
|
|
66
|
-
o || (o = new
|
|
67
|
-
let { type: i, ...
|
|
64
|
+
async resolveSource(a, s) {
|
|
65
|
+
let o = a;
|
|
66
|
+
o || (o = new Q(), await o.init());
|
|
67
|
+
let { type: i, ...l } = s;
|
|
68
68
|
switch (i) {
|
|
69
69
|
case "osm":
|
|
70
|
-
return await o.loadOsm(
|
|
70
|
+
return await o.loadOsm(W(l)), r(o, t), o;
|
|
71
71
|
case "csv":
|
|
72
|
-
return await o.loadCsv(
|
|
72
|
+
return await o.loadCsv(l), r(o, t), o;
|
|
73
73
|
case "json":
|
|
74
|
-
return await o.loadJson(
|
|
74
|
+
return await o.loadJson(l), r(o, t), o;
|
|
75
75
|
case "geojson": {
|
|
76
|
-
const
|
|
76
|
+
const n = l;
|
|
77
77
|
let u;
|
|
78
|
-
|
|
78
|
+
n.geojsonFileUrl ? u = await (await fetch(n.geojsonFileUrl)).json() : u = n.geojsonObject, e && u && e.set(n.outputTableName, u);
|
|
79
79
|
const c = u ? (() => {
|
|
80
|
-
const
|
|
81
|
-
return delete
|
|
82
|
-
})() :
|
|
80
|
+
const f = { ...n, geojsonObject: u };
|
|
81
|
+
return delete f.geojsonFileUrl, f;
|
|
82
|
+
})() : n;
|
|
83
83
|
try {
|
|
84
84
|
await o.loadGeojson(c);
|
|
85
|
-
} catch (
|
|
86
|
-
const
|
|
85
|
+
} catch (f) {
|
|
86
|
+
const p = c.coordinateFormat ? `coordinateFormat is set to "${c.coordinateFormat}"` : "no coordinateFormat was specified — defaulting to EPSG:4326 (WGS84 per RFC 7946)";
|
|
87
87
|
throw new Error(
|
|
88
|
-
`Failed to load GeoJSON layer "${c.outputTableName}": ${
|
|
88
|
+
`Failed to load GeoJSON layer "${c.outputTableName}": ${f instanceof Error ? f.message : String(f)}. ${p}. Verify that coordinateFormat matches the actual CRS of the input data.`
|
|
89
89
|
);
|
|
90
90
|
}
|
|
91
91
|
try {
|
|
92
|
-
const
|
|
93
|
-
if (!isFinite(
|
|
92
|
+
const f = await o.getBoundingBoxFromLayer(c.outputTableName), p = 25e6;
|
|
93
|
+
if (!isFinite(f.minLon) || !isFinite(f.minLat) || !isFinite(f.maxLon) || !isFinite(f.maxLat) || Math.abs(f.minLon) > p || Math.abs(f.maxLon) > p || Math.abs(f.minLat) > p || Math.abs(f.maxLat) > p)
|
|
94
94
|
throw new Error(
|
|
95
|
-
`Geometry bounding box after transform is invalid for layer "${c.outputTableName}" (bbox: [${
|
|
95
|
+
`Geometry bounding box after transform is invalid for layer "${c.outputTableName}" (bbox: [${f.minLon}, ${f.minLat}, ${f.maxLon}, ${f.maxLat}]). Verify that coordinateFormat matches the actual CRS of the input data. The workspace uses ${F}; input is expected in EPSG:4326 by default.`
|
|
96
96
|
);
|
|
97
|
-
} catch (
|
|
98
|
-
if (
|
|
97
|
+
} catch (f) {
|
|
98
|
+
if (f instanceof Error && f.message.includes("bounding box after transform")) throw f;
|
|
99
99
|
}
|
|
100
|
-
return
|
|
100
|
+
return r(o, t), o;
|
|
101
101
|
}
|
|
102
102
|
case "heatmap": {
|
|
103
|
-
const
|
|
103
|
+
const n = l;
|
|
104
104
|
return await o.buildHeatmap({
|
|
105
|
-
tableJoinName:
|
|
106
|
-
near: { distance:
|
|
107
|
-
outputTableName:
|
|
108
|
-
grid:
|
|
109
|
-
...
|
|
110
|
-
}),
|
|
105
|
+
tableJoinName: n.tableJoinName,
|
|
106
|
+
near: { distance: n.near.distance },
|
|
107
|
+
outputTableName: n.outputTableName,
|
|
108
|
+
grid: n.grid,
|
|
109
|
+
...n.groupBy && { groupBy: n.groupBy }
|
|
110
|
+
}), r(o, t), o;
|
|
111
111
|
}
|
|
112
112
|
case "join": {
|
|
113
|
-
const
|
|
113
|
+
const n = l;
|
|
114
114
|
if (await o.spatialQuery({
|
|
115
|
-
tableRootName:
|
|
116
|
-
tableJoinName:
|
|
117
|
-
...
|
|
118
|
-
...
|
|
119
|
-
}),
|
|
120
|
-
const u = await o.getLayer(
|
|
121
|
-
|
|
115
|
+
tableRootName: n.tableRootName,
|
|
116
|
+
tableJoinName: n.tableJoinName,
|
|
117
|
+
...n.near && { near: n.near },
|
|
118
|
+
...n.groupBy && { groupBy: n.groupBy }
|
|
119
|
+
}), e) {
|
|
120
|
+
const u = await o.getLayer(n.tableRootName);
|
|
121
|
+
e.set(n.tableRootName, u);
|
|
122
122
|
}
|
|
123
|
-
return
|
|
123
|
+
return r(o, t), o;
|
|
124
124
|
}
|
|
125
125
|
default:
|
|
126
126
|
return;
|
|
@@ -128,85 +128,85 @@ function D(t, a) {
|
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
|
-
function
|
|
132
|
-
return
|
|
133
|
-
type:
|
|
131
|
+
function K(t, e) {
|
|
132
|
+
return e && e.length > 0 ? { type: w.USER, params: e } : t?.mode === O.PERCENTILE ? t.lowerPercentile !== void 0 || t.upperPercentile !== void 0 ? {
|
|
133
|
+
type: w.PERCENTILE,
|
|
134
134
|
params: [t.lowerPercentile ?? 0, t.upperPercentile ?? 100]
|
|
135
|
-
} : { type:
|
|
135
|
+
} : { type: w.PERCENTILE } : { type: w.MIN_MAX };
|
|
136
136
|
}
|
|
137
|
-
function
|
|
138
|
-
return
|
|
139
|
-
if (!(
|
|
140
|
-
return
|
|
137
|
+
function X(t, e) {
|
|
138
|
+
return e.split(".").reduce((r, a) => {
|
|
139
|
+
if (!(r == null || typeof r != "object"))
|
|
140
|
+
return r[a];
|
|
141
141
|
}, t);
|
|
142
142
|
}
|
|
143
|
-
function
|
|
144
|
-
const
|
|
143
|
+
function q(t, e, r) {
|
|
144
|
+
const a = e.split("."), s = { ...t };
|
|
145
145
|
let o = s;
|
|
146
|
-
for (let i = 0; i <
|
|
147
|
-
o[
|
|
148
|
-
return o[
|
|
149
|
-
}
|
|
150
|
-
function
|
|
151
|
-
const
|
|
152
|
-
return
|
|
153
|
-
}
|
|
154
|
-
function
|
|
155
|
-
async function
|
|
156
|
-
let
|
|
157
|
-
for (const
|
|
158
|
-
|
|
159
|
-
for (const
|
|
160
|
-
const u =
|
|
161
|
-
...
|
|
162
|
-
features: (
|
|
146
|
+
for (let i = 0; i < a.length - 1; i++)
|
|
147
|
+
o[a[i]] = { ...o[a[i]] ?? {} }, o = o[a[i]];
|
|
148
|
+
return o[a[a.length - 1]] = r, s;
|
|
149
|
+
}
|
|
150
|
+
function z(t, e) {
|
|
151
|
+
const a = t.features?.[0]?.properties?.bands ?? [];
|
|
152
|
+
return a.find((o) => o.id === e || o.label === e?.replace(/\./g, "_"))?.id ?? a[0]?.id ?? e ?? "";
|
|
153
|
+
}
|
|
154
|
+
function Z(t, e, r) {
|
|
155
|
+
async function a(s, o, i) {
|
|
156
|
+
let l = {};
|
|
157
|
+
for (const n of o.getTablesMetadata())
|
|
158
|
+
n.type !== void 0 && (l[n.name] = n.type);
|
|
159
|
+
for (const n of i.layerRefs) {
|
|
160
|
+
const u = n.dataRef, c = l[u], f = n.getFnv, p = r?.get(u) ?? await o.getLayer(u), m = c === "raster" ? p : {
|
|
161
|
+
...p,
|
|
162
|
+
features: (p.features ?? []).filter((h) => h.geometry != null)
|
|
163
163
|
};
|
|
164
|
-
c === "raster" ? s.loadCollection(u, { collection:
|
|
165
|
-
const { catchAllCategory:
|
|
166
|
-
let
|
|
167
|
-
if (
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
...
|
|
171
|
-
features:
|
|
172
|
-
const
|
|
173
|
-
return
|
|
164
|
+
c === "raster" ? s.loadCollection(u, { collection: m, type: "raster", property: z(m, f) }) : s.loadCollection(u, { collection: m, type: c }), n.opacity != null && s.updateRenderInfo(u, { opacity: n.opacity }), (n.isColorMap ?? (f != null && c !== "raster")) && s.updateRenderInfo(u, { isColorMap: !0 }), n.isPick && s.updateRenderInfo(u, { isPick: !0 }), n.isSkip && s.updateRenderInfo(u, { isSkip: !0 });
|
|
165
|
+
const { catchAllCategory: d, colorMapDomain: y } = n;
|
|
166
|
+
let E = m, R = y;
|
|
167
|
+
if (f && d && y?.length) {
|
|
168
|
+
const h = new Set(y);
|
|
169
|
+
E = {
|
|
170
|
+
...m,
|
|
171
|
+
features: m.features.map((C) => {
|
|
172
|
+
const L = C.properties, M = X(L, f);
|
|
173
|
+
return M == null || !h.has(String(M)) ? { ...C, properties: q(L, f, d) } : C;
|
|
174
174
|
})
|
|
175
|
-
},
|
|
175
|
+
}, R = h.has(d) ? y : [...y, d];
|
|
176
176
|
}
|
|
177
|
-
if (
|
|
178
|
-
const
|
|
177
|
+
if (n.colorMapInterpolator) {
|
|
178
|
+
const h = {
|
|
179
179
|
// urban-grammar ColorMapInterpolator values are string-compatible
|
|
180
180
|
// with autk-core ColorMapInterpolator at runtime
|
|
181
|
-
interpolator:
|
|
182
|
-
domainSpec:
|
|
181
|
+
interpolator: n.colorMapInterpolator,
|
|
182
|
+
domainSpec: K(n.normalization, R)
|
|
183
183
|
};
|
|
184
|
-
s.updateRenderInfo(u, { colormap: { config:
|
|
184
|
+
s.updateRenderInfo(u, { colormap: { config: h }, isColorMap: !0 });
|
|
185
185
|
}
|
|
186
|
-
if (
|
|
187
|
-
const
|
|
188
|
-
s.updateThematic(u, { collection:
|
|
186
|
+
if (f && c !== "raster") {
|
|
187
|
+
const h = f.startsWith("properties.") ? f : `properties.${f}`;
|
|
188
|
+
s.updateThematic(u, { collection: E, property: h });
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
return {
|
|
193
193
|
async resolveMap(s, o, i = 0) {
|
|
194
194
|
if (t && t.map && s) {
|
|
195
|
-
let
|
|
196
|
-
if (Array.isArray(t.map) ?
|
|
195
|
+
let l;
|
|
196
|
+
if (Array.isArray(t.map) ? l = document.getElementById(t.map[i]) : l = document.getElementById(t.map), !l)
|
|
197
197
|
throw new Error("Could not find rendering target for map: " + t.map);
|
|
198
|
-
if (!(
|
|
198
|
+
if (!(l instanceof HTMLCanvasElement))
|
|
199
199
|
throw new Error("Target for map is not a canvas: " + t.map);
|
|
200
|
-
const
|
|
201
|
-
if (o.style &&
|
|
200
|
+
const n = new $(l);
|
|
201
|
+
if (o.style && n.style.setPredefinedStyle(o.style), await n.init(), await a(n, s, o), e)
|
|
202
202
|
for (const u of o.layerRefs)
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
e.set(u.dataRef, n);
|
|
204
|
+
n.draw();
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
};
|
|
208
208
|
}
|
|
209
|
-
function
|
|
209
|
+
function tt(t) {
|
|
210
210
|
return {
|
|
211
211
|
scatter: "scatterplot",
|
|
212
212
|
bar: "barchart",
|
|
@@ -217,16 +217,16 @@ function F(t) {
|
|
|
217
217
|
heatmatrix: "heatmatrix"
|
|
218
218
|
}[t];
|
|
219
219
|
}
|
|
220
|
-
function
|
|
220
|
+
function et(t, e, r, a, s) {
|
|
221
221
|
return {
|
|
222
222
|
async resolvePlot(o, i) {
|
|
223
223
|
if (!t || !t.plot) return;
|
|
224
|
-
const
|
|
225
|
-
if (!
|
|
226
|
-
const
|
|
227
|
-
if (!
|
|
228
|
-
const u = s?.get(i.dataRef) ?? await
|
|
229
|
-
type:
|
|
224
|
+
const l = document.getElementById(t.plot);
|
|
225
|
+
if (!l) throw new Error(`Could not find plot target: ${t.plot}`);
|
|
226
|
+
const n = o;
|
|
227
|
+
if (!n) throw new Error("No data context available for plot.");
|
|
228
|
+
const u = s?.get(i.dataRef) ?? await n.getLayer(i.dataRef), c = i.events ?? [], f = new Y(l, {
|
|
229
|
+
type: tt(i.mark),
|
|
230
230
|
collection: u,
|
|
231
231
|
attributes: { axis: i.axis, ...i.color && { color: i.color } },
|
|
232
232
|
labels: { axis: i.axis, title: i.title },
|
|
@@ -236,55 +236,222 @@ function j(t, a, e, n, s) {
|
|
|
236
236
|
...i.margins && { margins: i.margins },
|
|
237
237
|
...i.transform && { transform: i.transform }
|
|
238
238
|
});
|
|
239
|
-
if (
|
|
240
|
-
const
|
|
241
|
-
if (
|
|
242
|
-
|
|
243
|
-
|
|
239
|
+
if (r?.set(i.dataRef, f), i.mapRef && a?.set(i.dataRef, i.mapRef), i.mapRef && e) {
|
|
240
|
+
const p = e.get(i.mapRef);
|
|
241
|
+
if (p) {
|
|
242
|
+
p.updateRenderInfo(i.mapRef, { isPick: !0 }), p.events.on(P.PICKING, ({ selection: m }) => {
|
|
243
|
+
f.setSelection(m);
|
|
244
244
|
});
|
|
245
|
-
for (const
|
|
246
|
-
|
|
247
|
-
|
|
245
|
+
for (const m of c)
|
|
246
|
+
f.events.on(m, ({ selection: g }) => {
|
|
247
|
+
p.setHighlightedIds(i.mapRef, g);
|
|
248
248
|
});
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
};
|
|
253
253
|
}
|
|
254
|
-
|
|
254
|
+
const G = 134217728, rt = 4, ot = 32;
|
|
255
|
+
function at(t) {
|
|
256
|
+
return Array.isArray(t) ? t.join(`
|
|
257
|
+
`) : t;
|
|
258
|
+
}
|
|
259
|
+
function _(t) {
|
|
260
|
+
return !!t && typeof t == "object" && !Array.isArray(t) && typeof t.fromFeature == "object" && t.fromFeature !== null;
|
|
261
|
+
}
|
|
262
|
+
function b(t, e) {
|
|
263
|
+
return t instanceof Map ? t.get(e) : t[e];
|
|
264
|
+
}
|
|
265
|
+
function S(t, e) {
|
|
266
|
+
return e.split(".").reduce((r, a) => {
|
|
267
|
+
if (!(r == null || typeof r != "object"))
|
|
268
|
+
return r[a];
|
|
269
|
+
}, t);
|
|
270
|
+
}
|
|
271
|
+
function D(t) {
|
|
272
|
+
const e = [];
|
|
273
|
+
for (const r of [t.uniforms, t.uniformMatrices])
|
|
274
|
+
for (const a of Object.values(r ?? {}))
|
|
275
|
+
_(a) && e.push(a);
|
|
276
|
+
return e;
|
|
277
|
+
}
|
|
278
|
+
function nt(t) {
|
|
279
|
+
return [.../* @__PURE__ */ new Set([t.dataRef, ...D(t).map((e) => e.fromFeature.layer)])];
|
|
280
|
+
}
|
|
281
|
+
function j(t) {
|
|
282
|
+
for (const e of D(t)) {
|
|
283
|
+
const { iterate: r, layer: a } = e.fromFeature;
|
|
284
|
+
if (r === "all" || r === "batched") return { mode: r, layer: a };
|
|
285
|
+
}
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
function x(t, e, r) {
|
|
289
|
+
const a = t.fromFeature, s = r !== void 0 && a.iterate === "all" ? r : a.index ?? 0, o = b(e, a.layer)?.features?.[s];
|
|
290
|
+
return o ? S(o, a.path) : void 0;
|
|
291
|
+
}
|
|
292
|
+
function v(t, e, r) {
|
|
293
|
+
if (!t) return;
|
|
294
|
+
const a = {};
|
|
295
|
+
for (const [s, o] of Object.entries(t)) {
|
|
296
|
+
if (!_(o)) {
|
|
297
|
+
a[s] = o;
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
const i = Number(x(o, e, r) ?? NaN);
|
|
301
|
+
Number.isFinite(i) ? a[s] = i : typeof o.default == "number" && (a[s] = o.default);
|
|
302
|
+
}
|
|
303
|
+
return a;
|
|
304
|
+
}
|
|
305
|
+
function N(t, e, r) {
|
|
306
|
+
if (!t) return;
|
|
307
|
+
const a = {};
|
|
308
|
+
for (const [s, o] of Object.entries(t)) {
|
|
309
|
+
if (!_(o)) {
|
|
310
|
+
a[s] = o;
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
const i = x(o, e, r), l = Array.isArray(i) ? i : Array.isArray(o.default) ? o.default : void 0;
|
|
314
|
+
if (!l) continue;
|
|
315
|
+
const n = o.cols ?? (Array.isArray(l[0]) ? l[0].length : 0);
|
|
316
|
+
n > 0 ? a[s] = { data: l, cols: n } : console.warn(`[autk-grammar] uniform matrix "${s}" has no column count; entry dropped`);
|
|
317
|
+
}
|
|
318
|
+
return a;
|
|
319
|
+
}
|
|
320
|
+
function it(t) {
|
|
321
|
+
return t != null && !(typeof t == "number" && !Number.isFinite(t));
|
|
322
|
+
}
|
|
323
|
+
function I(t) {
|
|
324
|
+
return _(t) && t.fromFeature.iterate === "batched";
|
|
325
|
+
}
|
|
326
|
+
function U(t, e) {
|
|
327
|
+
return Object.values(e ?? {}).some(I) ? ot : Object.values(t ?? {}).some(I) ? rt : 0;
|
|
328
|
+
}
|
|
329
|
+
function st(t, e, r = G) {
|
|
330
|
+
const a = U(t, e);
|
|
331
|
+
return a > 0 ? Math.floor(r / a) : Number.POSITIVE_INFINITY;
|
|
332
|
+
}
|
|
333
|
+
function lt(t, e, r, a = G) {
|
|
334
|
+
const s = {}, o = {}, i = [];
|
|
335
|
+
for (const n of [t, e])
|
|
336
|
+
for (const u of Object.values(n ?? {}))
|
|
337
|
+
_(u) && u.fromFeature.iterate === "batched" && u.fromFeature.required && i.push(u.fromFeature.path);
|
|
338
|
+
if (i.length > 0) {
|
|
339
|
+
const n = r.length;
|
|
340
|
+
r = r.filter((u) => i.every((c) => it(S(u, c)))), r.length < n && console.info(`[autk-grammar] batched compute dropped ${n - r.length} feature(s) missing ${i.join(", ")}`);
|
|
341
|
+
}
|
|
342
|
+
const l = st(t, e, a);
|
|
343
|
+
r.length > l && (console.warn(
|
|
344
|
+
`[autk-grammar] batched compute capped at ${l} features (got ${r.length}): its largest packed array takes ${U(t, e)} B per feature, and a storage buffer binding holds ${a} B`
|
|
345
|
+
), r = r.slice(0, l));
|
|
346
|
+
for (const [n, u] of Object.entries(t ?? {}))
|
|
347
|
+
if (_(u) && u.fromFeature.iterate === "batched") {
|
|
348
|
+
const c = typeof u.default == "number" ? u.default : void 0;
|
|
349
|
+
o[n] = r.map((f) => {
|
|
350
|
+
const p = Number(S(f, u.fromFeature.path) ?? c);
|
|
351
|
+
return Number.isFinite(p) ? p : 0;
|
|
352
|
+
});
|
|
353
|
+
} else typeof u == "number" && (s[n] = u);
|
|
354
|
+
for (const [n, u] of Object.entries(e ?? {})) {
|
|
355
|
+
if (!_(u) || u.fromFeature.iterate !== "batched") continue;
|
|
356
|
+
const c = [];
|
|
357
|
+
for (const f of r) {
|
|
358
|
+
const p = S(f, u.fromFeature.path);
|
|
359
|
+
let m = 1 / 0, g = 1 / 0, d = -1 / 0, y = -1 / 0;
|
|
360
|
+
if (Array.isArray(p))
|
|
361
|
+
for (const E of p) {
|
|
362
|
+
if (!Array.isArray(E) || E.length < 2) continue;
|
|
363
|
+
const R = Number(E[0]), h = Number(E[1]);
|
|
364
|
+
!Number.isFinite(R) || !Number.isFinite(h) || (m = Math.min(m, R), g = Math.min(g, h), d = Math.max(d, R), y = Math.max(y, h));
|
|
365
|
+
}
|
|
366
|
+
Number.isFinite(m) || (m = 0, g = 0, d = 0, y = 0), c.push(m, g, d, g, d, y, m, y);
|
|
367
|
+
}
|
|
368
|
+
o[n] = c;
|
|
369
|
+
}
|
|
370
|
+
return s.num_features = r.length, { uniforms: s, uniformArrays: o };
|
|
371
|
+
}
|
|
372
|
+
function B(t, e, r) {
|
|
373
|
+
const a = b(e, t.dataRef);
|
|
374
|
+
if (!a) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
|
|
375
|
+
const s = {
|
|
376
|
+
collection: a,
|
|
377
|
+
variableMapping: t.attributes,
|
|
378
|
+
wgslBody: at(t.wglsFunction)
|
|
379
|
+
};
|
|
380
|
+
t.attributeArrays && (s.attributeArrays = t.attributeArrays), t.attributeMatrices && (s.attributeMatrices = t.attributeMatrices), t.uniformArrays && (s.uniformArrays = t.uniformArrays), t.outputColumnName && (s.resultField = t.outputColumnName), t.outputColumns && (s.outputColumns = t.outputColumns);
|
|
381
|
+
const o = j(t);
|
|
382
|
+
if (o?.mode === "batched") {
|
|
383
|
+
const u = b(e, o.layer)?.features ?? [], c = lt(t.uniforms, t.uniformMatrices, u), f = v(T(t.uniforms), e) ?? {}, p = N(T(t.uniformMatrices), e);
|
|
384
|
+
return s.uniforms = { ...f, ...c.uniforms }, s.uniformArrays = { ...s.uniformArrays ?? {}, ...c.uniformArrays }, p && Object.keys(p).length > 0 && (s.uniformMatrices = p), s;
|
|
385
|
+
}
|
|
386
|
+
const i = o?.mode === "all" ? r : void 0, l = v(t.uniforms, e, i), n = N(t.uniformMatrices, e, i);
|
|
387
|
+
return l && (s.uniforms = l), n && (s.uniformMatrices = n), s;
|
|
388
|
+
}
|
|
389
|
+
function T(t) {
|
|
390
|
+
if (t)
|
|
391
|
+
return Object.fromEntries(Object.entries(t).filter(([, e]) => !(_(e) && e.fromFeature.iterate === "batched")));
|
|
392
|
+
}
|
|
393
|
+
function ut(t) {
|
|
394
|
+
return t.outputColumns ?? (t.outputColumnName ? [t.outputColumnName] : []);
|
|
395
|
+
}
|
|
396
|
+
async function ft(t, e, r) {
|
|
397
|
+
const a = j(t);
|
|
398
|
+
if (a?.mode !== "all") return r(B(t, e));
|
|
399
|
+
const s = b(e, t.dataRef);
|
|
400
|
+
if (!s) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
|
|
401
|
+
const o = ut(t), i = structuredClone(s);
|
|
402
|
+
for (const n of i.features) {
|
|
403
|
+
const u = n.properties ??= {}, c = u.compute ??= {};
|
|
404
|
+
for (const f of o) c[f] = 0;
|
|
405
|
+
}
|
|
406
|
+
const l = b(e, a.layer)?.features?.length ?? 0;
|
|
407
|
+
for (let n = 0; n < l; n++) {
|
|
408
|
+
const u = await r({ ...B(t, e, n), collection: i });
|
|
409
|
+
i.features.forEach((c, f) => {
|
|
410
|
+
const p = c.properties?.compute, m = u.features[f]?.properties?.compute;
|
|
411
|
+
if (!(!p || !m))
|
|
412
|
+
for (const g of o) {
|
|
413
|
+
const d = Number(m[g]);
|
|
414
|
+
Number.isFinite(d) && (p[g] += d);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
return i;
|
|
419
|
+
}
|
|
420
|
+
function ct(t) {
|
|
255
421
|
return {
|
|
256
|
-
async resolveCompute(
|
|
257
|
-
if (
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
|
|
422
|
+
async resolveCompute(e, r) {
|
|
423
|
+
if (e) {
|
|
424
|
+
const a = {};
|
|
425
|
+
for (const i of nt(r)) {
|
|
426
|
+
const l = t?.get(i);
|
|
427
|
+
if (l) a[i] = l;
|
|
428
|
+
else if (i === r.dataRef) a[i] = await e.getLayer(i);
|
|
429
|
+
else
|
|
430
|
+
try {
|
|
431
|
+
a[i] = await e.getLayer(i);
|
|
432
|
+
} catch {
|
|
433
|
+
a[i] = void 0;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
const s = new H(), o = await ft(r, a, (i) => s.gpgpuPipeline(i));
|
|
437
|
+
return t && t.set(r.dataRef, o), e;
|
|
271
438
|
}
|
|
272
439
|
}
|
|
273
440
|
};
|
|
274
441
|
}
|
|
275
|
-
class
|
|
442
|
+
class pt {
|
|
276
443
|
_listeners = /* @__PURE__ */ new Map();
|
|
277
|
-
on(
|
|
278
|
-
this._listeners.has(
|
|
279
|
-
const
|
|
280
|
-
return
|
|
444
|
+
on(e, r) {
|
|
445
|
+
this._listeners.has(e) || this._listeners.set(e, /* @__PURE__ */ new Set());
|
|
446
|
+
const a = this._listeners.get(e);
|
|
447
|
+
return a.add(r), () => a.delete(r);
|
|
281
448
|
}
|
|
282
449
|
/** @internal */
|
|
283
|
-
emit(
|
|
284
|
-
this._listeners.get(
|
|
450
|
+
emit(e, r) {
|
|
451
|
+
this._listeners.get(e)?.forEach((a) => a(r));
|
|
285
452
|
}
|
|
286
453
|
}
|
|
287
|
-
class
|
|
454
|
+
class _t {
|
|
288
455
|
dataAdapter;
|
|
289
456
|
mapAdapter;
|
|
290
457
|
plotAdapter;
|
|
@@ -296,10 +463,10 @@ class X {
|
|
|
296
463
|
_plotRegistry = /* @__PURE__ */ new Map();
|
|
297
464
|
_fwdCleanups = [];
|
|
298
465
|
_plotMapLinks = /* @__PURE__ */ new Map();
|
|
299
|
-
interactions = new
|
|
300
|
-
constructor(
|
|
301
|
-
const
|
|
302
|
-
this.dataAdapter =
|
|
466
|
+
interactions = new pt();
|
|
467
|
+
constructor(e) {
|
|
468
|
+
const r = /* @__PURE__ */ new Map();
|
|
469
|
+
this.dataAdapter = J(e, r), this.mapAdapter = Z(e, this._mapRegistry, this._computeCache), this.plotAdapter = et(e, this._mapRegistry, this._plotRegistry, this._plotMapLinks, r), this.computeAdapter = ct(this._computeCache);
|
|
303
470
|
}
|
|
304
471
|
/**
|
|
305
472
|
* The coordinate reference system used internally by the autk workspace.
|
|
@@ -310,12 +477,12 @@ class X {
|
|
|
310
477
|
* instead of hard-coding a CRS string.
|
|
311
478
|
*/
|
|
312
479
|
get workspaceCrs() {
|
|
313
|
-
return
|
|
480
|
+
return F;
|
|
314
481
|
}
|
|
315
482
|
get data() {
|
|
316
483
|
return this._data;
|
|
317
484
|
}
|
|
318
|
-
async run(
|
|
485
|
+
async run(e) {
|
|
319
486
|
if (!this.dataAdapter)
|
|
320
487
|
throw new Error("Database adapter not initialized. Please call the constructor first.");
|
|
321
488
|
if (!this.mapAdapter)
|
|
@@ -324,8 +491,8 @@ class X {
|
|
|
324
491
|
throw new Error("Plot adapter not initialized. Please call the constructor first.");
|
|
325
492
|
if (!this.computeAdapter)
|
|
326
493
|
throw new Error("Compute adapter not initialized. Please call the constructor first.");
|
|
327
|
-
this._mapRegistry.clear(), this._plotRegistry.clear(), this._plotMapLinks.clear(), this.grammarEngine =
|
|
328
|
-
spec:
|
|
494
|
+
this._mapRegistry.clear(), this._plotRegistry.clear(), this._plotMapLinks.clear(), this._computeCache.clear(), this.grammarEngine = V({
|
|
495
|
+
spec: e,
|
|
329
496
|
adapters: {
|
|
330
497
|
db: this.dataAdapter,
|
|
331
498
|
map: this.mapAdapter,
|
|
@@ -333,89 +500,100 @@ class X {
|
|
|
333
500
|
compute: this.computeAdapter
|
|
334
501
|
}
|
|
335
502
|
}), await this.grammarEngine.run(), this._rewireInteractions();
|
|
336
|
-
const
|
|
337
|
-
if (!
|
|
503
|
+
const r = this.grammarEngine.context;
|
|
504
|
+
if (!r) {
|
|
338
505
|
console.warn("Grammar engine produced no data context."), this._data = {};
|
|
339
506
|
return;
|
|
340
507
|
}
|
|
341
|
-
const
|
|
342
|
-
for (const s of
|
|
343
|
-
Object.defineProperty(
|
|
508
|
+
const a = {};
|
|
509
|
+
for (const s of r.getLayersMetadata())
|
|
510
|
+
Object.defineProperty(a, s.name, {
|
|
344
511
|
get: () => {
|
|
345
512
|
const o = this._computeCache.get(s.name);
|
|
346
|
-
return o ? Promise.resolve(o) :
|
|
513
|
+
return o ? Promise.resolve(o) : r.getLayer(s.name);
|
|
347
514
|
},
|
|
348
515
|
enumerable: !0,
|
|
349
516
|
configurable: !0
|
|
350
517
|
});
|
|
351
|
-
this._data =
|
|
518
|
+
this._data = a;
|
|
352
519
|
}
|
|
353
520
|
/**
|
|
354
521
|
* Highlights features on the map layer identified by `layerId`.
|
|
355
522
|
* If that layer is linked to a plot via `mapRef`, the plot selection is updated too.
|
|
356
523
|
*/
|
|
357
|
-
highlightOnMap(
|
|
358
|
-
this._mapRegistry.get(
|
|
359
|
-
for (const [
|
|
360
|
-
s ===
|
|
524
|
+
highlightOnMap(e, r) {
|
|
525
|
+
this._mapRegistry.get(e)?.setHighlightedIds(e, r);
|
|
526
|
+
for (const [a, s] of this._plotMapLinks)
|
|
527
|
+
s === e && this._plotRegistry.get(a)?.setSelection(r);
|
|
361
528
|
}
|
|
362
529
|
/**
|
|
363
530
|
* Clears highlighted features on the map layer identified by `layerId`.
|
|
364
531
|
* If that layer is linked to a plot via `mapRef`, the plot selection is cleared too.
|
|
365
532
|
*/
|
|
366
|
-
clearHighlightOnMap(
|
|
367
|
-
this._mapRegistry.get(
|
|
368
|
-
for (const [
|
|
369
|
-
|
|
533
|
+
clearHighlightOnMap(e) {
|
|
534
|
+
this._mapRegistry.get(e)?.clearHighlightedIds(e);
|
|
535
|
+
for (const [r, a] of this._plotMapLinks)
|
|
536
|
+
a === e && this._plotRegistry.get(r)?.setSelection([]);
|
|
370
537
|
}
|
|
371
538
|
/**
|
|
372
539
|
* Clears the selection on the plot identified by `plotId` (its dataRef).
|
|
373
540
|
* If that plot is linked to a map via `mapRef`, the map highlight is cleared too.
|
|
374
541
|
*/
|
|
375
|
-
clearHighlightOnPlot(
|
|
376
|
-
this._plotRegistry.get(
|
|
377
|
-
const
|
|
378
|
-
|
|
542
|
+
clearHighlightOnPlot(e) {
|
|
543
|
+
this._plotRegistry.get(e)?.setSelection([]);
|
|
544
|
+
const r = this._plotMapLinks.get(e);
|
|
545
|
+
r && this._mapRegistry.get(r)?.clearHighlightedIds(r);
|
|
379
546
|
}
|
|
380
547
|
/**
|
|
381
548
|
* Applies a selection to the plot identified by `plotId` (its dataRef).
|
|
382
549
|
* If that plot is linked to a map via `mapRef`, the map highlight is updated too.
|
|
383
550
|
*/
|
|
384
|
-
setPlotSelection(
|
|
385
|
-
this._plotRegistry.get(
|
|
386
|
-
const
|
|
387
|
-
|
|
551
|
+
setPlotSelection(e, r) {
|
|
552
|
+
this._plotRegistry.get(e)?.setSelection(r);
|
|
553
|
+
const a = this._plotMapLinks.get(e);
|
|
554
|
+
a && this._mapRegistry.get(a)?.setHighlightedIds(a, r);
|
|
388
555
|
}
|
|
389
556
|
_rewireInteractions() {
|
|
390
|
-
for (const
|
|
557
|
+
for (const r of this._fwdCleanups) r();
|
|
391
558
|
this._fwdCleanups = [];
|
|
392
|
-
const
|
|
393
|
-
for (const [
|
|
394
|
-
if (
|
|
395
|
-
|
|
559
|
+
const e = /* @__PURE__ */ new Set();
|
|
560
|
+
for (const [r, a] of this._mapRegistry) {
|
|
561
|
+
if (e.has(a)) continue;
|
|
562
|
+
e.add(a);
|
|
396
563
|
const s = ({ selection: o }) => {
|
|
397
|
-
this.interactions.emit("map:picking", { layerId:
|
|
564
|
+
this.interactions.emit("map:picking", { layerId: r, selection: o });
|
|
398
565
|
};
|
|
399
|
-
|
|
566
|
+
a.events.on(P.PICKING, s), this._fwdCleanups.push(() => a.events.off(P.PICKING, s));
|
|
400
567
|
}
|
|
401
|
-
for (const [
|
|
402
|
-
for (const s of [
|
|
568
|
+
for (const [r, a] of this._plotRegistry)
|
|
569
|
+
for (const s of [A.CLICK, A.BRUSH, A.BRUSH_X, A.BRUSH_Y]) {
|
|
403
570
|
const o = ({ selection: i }) => {
|
|
404
571
|
this.interactions.emit("plot:selection", {
|
|
405
|
-
plotId:
|
|
572
|
+
plotId: r,
|
|
406
573
|
event: s,
|
|
407
574
|
selection: i
|
|
408
575
|
});
|
|
409
576
|
};
|
|
410
|
-
|
|
577
|
+
a.events.on(s, o), this._fwdCleanups.push(() => a.events.off(s, o));
|
|
411
578
|
}
|
|
412
579
|
}
|
|
413
580
|
}
|
|
414
581
|
export {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
582
|
+
_t as AutkGrammar,
|
|
583
|
+
k as ColorMapInterpolator,
|
|
584
|
+
pt as GrammarEventEmitter,
|
|
585
|
+
O as NormalizationMode,
|
|
586
|
+
G as STORAGE_BUFFER_BINDING_SIZE,
|
|
587
|
+
lt as buildBatchedUniforms,
|
|
588
|
+
nt as computeLayerNames,
|
|
589
|
+
V as createEngine,
|
|
590
|
+
j as findIterateSource,
|
|
591
|
+
_ as isFromFeature,
|
|
592
|
+
at as joinWgsl,
|
|
593
|
+
st as maxBatchedFeatures,
|
|
594
|
+
B as resolveComputeParams,
|
|
595
|
+
N as resolveUniformMatrices,
|
|
596
|
+
v as resolveUniforms,
|
|
597
|
+
ft as runCompute
|
|
420
598
|
};
|
|
421
599
|
//# sourceMappingURL=autk-grammar.js.map
|