@urban-toolkit/autk-grammar 0.2.0 → 0.3.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 +16 -0
- package/build/autk-grammar-schema.json +2084 -0
- package/dist/autk-grammar.js +397 -233
- 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 +401 -80
- package/package.json +9 -5
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 x, DEFAULT_WORKSPACE_COORDINATE_FORMAT as F } from "@urban-toolkit/autk-db";
|
|
2
|
+
import { AutkMap as U, MapEvent as P } from "@urban-toolkit/autk-map";
|
|
3
|
+
import { AutkPlot as Q, PlotEvent as A } from "@urban-toolkit/autk-plot";
|
|
4
|
+
import { ColorMapDomainStrategy as b } from "@urban-toolkit/autk-core";
|
|
5
|
+
import { AutkComputeEngine as $ } from "@urban-toolkit/autk-compute";
|
|
6
|
+
function H(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
|
|
21
|
-
await
|
|
10
|
+
let l;
|
|
11
|
+
if (e.data)
|
|
12
|
+
for (const i of e.data)
|
|
13
|
+
l = await r.db.resolveSource(l, i);
|
|
14
|
+
if (e.compute)
|
|
15
|
+
for (const i of e.compute)
|
|
16
|
+
l = await r.compute.resolveCompute(l, i);
|
|
17
|
+
if (e.map)
|
|
18
|
+
if (Array.isArray(e.map))
|
|
19
|
+
for (let i = 0; i < e.map.length; i++) {
|
|
20
|
+
let f = e.map[i];
|
|
21
|
+
await r.map.resolveMap(l, f, i);
|
|
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 i of e.plot)
|
|
28
|
+
await r.plot.resolvePlot(l, i);
|
|
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((i) => {
|
|
35
|
+
i();
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function n() {
|
|
39
39
|
console.log("Function not implemented yet");
|
|
40
40
|
}
|
|
41
|
-
return { run: s, updatedSpec: o, destroy:
|
|
42
|
-
return
|
|
41
|
+
return { run: s, updatedSpec: o, destroy: n, get context() {
|
|
42
|
+
return a;
|
|
43
43
|
} };
|
|
44
44
|
}
|
|
45
|
-
var
|
|
46
|
-
function
|
|
47
|
-
const { autoLoadLayers:
|
|
48
|
-
return { ...
|
|
45
|
+
var Y = /* @__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))(Y || {}), O = /* @__PURE__ */ ((t) => (t.MIN_MAX = "minMax", t.PERCENTILE = "percentile", t))(O || {});
|
|
46
|
+
function V(t) {
|
|
47
|
+
const { autoLoadLayers: e, ...r } = t;
|
|
48
|
+
return { ...r, autoLoadLayers: { layers: e?.layers ?? [] } };
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
function
|
|
50
|
+
function W(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
|
|
56
|
+
const n = a.getTablesMetadata();
|
|
57
57
|
o.innerHTML += "<ul>";
|
|
58
|
-
for (const
|
|
59
|
-
o.innerHTML += `<li>${
|
|
60
|
-
o.innerHTML += "</ul>", o.innerHTML += `<p>Number of tables: ${
|
|
58
|
+
for (const l of n)
|
|
59
|
+
o.innerHTML += `<li>${l.name}: (${l.source}, ${l.type}) </li>`;
|
|
60
|
+
o.innerHTML += "</ul>", o.innerHTML += `<p>Number of tables: ${n.length}</p>`;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
return {
|
|
64
|
-
async resolveSource(
|
|
65
|
-
let o =
|
|
66
|
-
o || (o = new
|
|
67
|
-
let { type:
|
|
68
|
-
switch (
|
|
64
|
+
async resolveSource(a, s) {
|
|
65
|
+
let o = a;
|
|
66
|
+
o || (o = new x(), await o.init());
|
|
67
|
+
let { type: n, ...l } = s;
|
|
68
|
+
switch (n) {
|
|
69
69
|
case "osm":
|
|
70
|
-
return await o.loadOsm(
|
|
70
|
+
return await o.loadOsm(V(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
|
|
77
|
-
let
|
|
78
|
-
|
|
79
|
-
const c =
|
|
80
|
-
const
|
|
81
|
-
return delete
|
|
82
|
-
})() :
|
|
76
|
+
const i = l;
|
|
77
|
+
let f;
|
|
78
|
+
i.geojsonFileUrl ? f = await (await fetch(i.geojsonFileUrl)).json() : f = i.geojsonObject, e && f && e.set(i.outputTableName, f);
|
|
79
|
+
const c = f ? (() => {
|
|
80
|
+
const u = { ...i, geojsonObject: f };
|
|
81
|
+
return delete u.geojsonFileUrl, u;
|
|
82
|
+
})() : i;
|
|
83
83
|
try {
|
|
84
84
|
await o.loadGeojson(c);
|
|
85
|
-
} catch (
|
|
86
|
-
const
|
|
85
|
+
} catch (u) {
|
|
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}": ${u instanceof Error ? u.message : String(u)}. ${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 u = await o.getBoundingBoxFromLayer(c.outputTableName), p = 25e6;
|
|
93
|
+
if (!isFinite(u.minLon) || !isFinite(u.minLat) || !isFinite(u.maxLon) || !isFinite(u.maxLat) || Math.abs(u.minLon) > p || Math.abs(u.maxLon) > p || Math.abs(u.minLat) > p || Math.abs(u.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: [${u.minLon}, ${u.minLat}, ${u.maxLon}, ${u.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 (u) {
|
|
98
|
+
if (u instanceof Error && u.message.includes("bounding box after transform")) throw u;
|
|
99
99
|
}
|
|
100
|
-
return
|
|
100
|
+
return r(o, t), o;
|
|
101
101
|
}
|
|
102
102
|
case "heatmap": {
|
|
103
|
-
const
|
|
103
|
+
const i = l;
|
|
104
104
|
return await o.buildHeatmap({
|
|
105
|
-
tableJoinName:
|
|
106
|
-
near: { distance:
|
|
107
|
-
outputTableName:
|
|
108
|
-
grid:
|
|
109
|
-
...
|
|
110
|
-
}),
|
|
105
|
+
tableJoinName: i.tableJoinName,
|
|
106
|
+
near: { distance: i.near.distance },
|
|
107
|
+
outputTableName: i.outputTableName,
|
|
108
|
+
grid: i.grid,
|
|
109
|
+
...i.groupBy && { groupBy: i.groupBy }
|
|
110
|
+
}), r(o, t), o;
|
|
111
111
|
}
|
|
112
112
|
case "join": {
|
|
113
|
-
const
|
|
113
|
+
const i = l;
|
|
114
114
|
if (await o.spatialQuery({
|
|
115
|
-
tableRootName:
|
|
116
|
-
tableJoinName:
|
|
117
|
-
...
|
|
118
|
-
...
|
|
119
|
-
}),
|
|
120
|
-
const
|
|
121
|
-
|
|
115
|
+
tableRootName: i.tableRootName,
|
|
116
|
+
tableJoinName: i.tableJoinName,
|
|
117
|
+
...i.near && { near: i.near },
|
|
118
|
+
...i.groupBy && { groupBy: i.groupBy }
|
|
119
|
+
}), e) {
|
|
120
|
+
const f = await o.getLayer(i.tableRootName);
|
|
121
|
+
e.set(i.tableRootName, f);
|
|
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: b.USER, params: e } : t?.mode === O.PERCENTILE ? t.lowerPercentile !== void 0 || t.upperPercentile !== void 0 ? {
|
|
133
|
+
type: b.PERCENTILE,
|
|
134
134
|
params: [t.lowerPercentile ?? 0, t.upperPercentile ?? 100]
|
|
135
|
-
} : { type:
|
|
135
|
+
} : { type: b.PERCENTILE } : { type: b.MIN_MAX };
|
|
136
136
|
}
|
|
137
|
-
function
|
|
138
|
-
return
|
|
139
|
-
if (!(
|
|
140
|
-
return
|
|
137
|
+
function J(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 K(t, e, r) {
|
|
144
|
+
const a = e.split("."), s = { ...t };
|
|
145
145
|
let o = s;
|
|
146
|
-
for (let
|
|
147
|
-
o[n
|
|
148
|
-
return o[
|
|
146
|
+
for (let n = 0; n < a.length - 1; n++)
|
|
147
|
+
o[a[n]] = { ...o[a[n]] ?? {} }, o = o[a[n]];
|
|
148
|
+
return o[a[a.length - 1]] = r, s;
|
|
149
149
|
}
|
|
150
|
-
function
|
|
151
|
-
const
|
|
152
|
-
return
|
|
150
|
+
function X(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
153
|
}
|
|
154
|
-
function
|
|
155
|
-
async function
|
|
156
|
-
let
|
|
157
|
-
for (const
|
|
158
|
-
|
|
159
|
-
for (const
|
|
160
|
-
const
|
|
161
|
-
...
|
|
162
|
-
features: (
|
|
154
|
+
function q(t, e, r) {
|
|
155
|
+
async function a(s, o, n) {
|
|
156
|
+
let l = {};
|
|
157
|
+
for (const i of o.getTablesMetadata())
|
|
158
|
+
i.type !== void 0 && (l[i.name] = i.type);
|
|
159
|
+
for (const i of n.layerRefs) {
|
|
160
|
+
const f = i.dataRef, c = l[f], u = i.getFnv, p = r?.get(f) ?? await o.getLayer(f), m = c === "raster" ? p : {
|
|
161
|
+
...p,
|
|
162
|
+
features: (p.features ?? []).filter((y) => y.geometry != null)
|
|
163
163
|
};
|
|
164
|
-
c === "raster" ? s.loadCollection(
|
|
165
|
-
const { catchAllCategory:
|
|
166
|
-
let
|
|
167
|
-
if (
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
...
|
|
171
|
-
features:
|
|
172
|
-
const
|
|
173
|
-
return
|
|
164
|
+
c === "raster" ? s.loadCollection(f, { collection: m, type: "raster", property: X(m, u) }) : s.loadCollection(f, { collection: m, type: c }), i.opacity != null && s.updateRenderInfo(f, { opacity: i.opacity }), (i.isColorMap ?? (u != null && c !== "raster")) && s.updateRenderInfo(f, { isColorMap: !0 }), i.isPick && s.updateRenderInfo(f, { isPick: !0 }), i.isSkip && s.updateRenderInfo(f, { isSkip: !0 });
|
|
165
|
+
const { catchAllCategory: d, colorMapDomain: g } = i;
|
|
166
|
+
let E = m, L = g;
|
|
167
|
+
if (u && d && g?.length) {
|
|
168
|
+
const y = new Set(g);
|
|
169
|
+
E = {
|
|
170
|
+
...m,
|
|
171
|
+
features: m.features.map((S) => {
|
|
172
|
+
const v = S.properties, C = J(v, u);
|
|
173
|
+
return C == null || !y.has(String(C)) ? { ...S, properties: K(v, u, d) } : S;
|
|
174
174
|
})
|
|
175
|
-
},
|
|
175
|
+
}, L = y.has(d) ? g : [...g, d];
|
|
176
176
|
}
|
|
177
|
-
if (
|
|
178
|
-
const
|
|
177
|
+
if (i.colorMapInterpolator) {
|
|
178
|
+
const y = {
|
|
179
179
|
// urban-grammar ColorMapInterpolator values are string-compatible
|
|
180
180
|
// with autk-core ColorMapInterpolator at runtime
|
|
181
|
-
interpolator:
|
|
182
|
-
domainSpec:
|
|
181
|
+
interpolator: i.colorMapInterpolator,
|
|
182
|
+
domainSpec: k(i.normalization, L)
|
|
183
183
|
};
|
|
184
|
-
s.updateRenderInfo(
|
|
184
|
+
s.updateRenderInfo(f, { colormap: { config: y }, isColorMap: !0 });
|
|
185
185
|
}
|
|
186
|
-
if (
|
|
187
|
-
const
|
|
188
|
-
s.updateThematic(
|
|
186
|
+
if (u && c !== "raster") {
|
|
187
|
+
const y = u.startsWith("properties.") ? u : `properties.${u}`;
|
|
188
|
+
s.updateThematic(f, { collection: E, property: y });
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
return {
|
|
193
|
-
async resolveMap(s, o,
|
|
193
|
+
async resolveMap(s, o, n = 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[n]) : 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 &&
|
|
202
|
-
for (const
|
|
203
|
-
|
|
204
|
-
|
|
200
|
+
const i = new U(l);
|
|
201
|
+
if (o.style && i.style.setPredefinedStyle(o.style), await i.init(), await a(i, s, o), e)
|
|
202
|
+
for (const f of o.layerRefs)
|
|
203
|
+
e.set(f.dataRef, i);
|
|
204
|
+
i.draw();
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
};
|
|
208
208
|
}
|
|
209
|
-
function
|
|
209
|
+
function z(t) {
|
|
210
210
|
return {
|
|
211
211
|
scatter: "scatterplot",
|
|
212
212
|
bar: "barchart",
|
|
@@ -217,74 +217,228 @@ function F(t) {
|
|
|
217
217
|
heatmatrix: "heatmatrix"
|
|
218
218
|
}[t];
|
|
219
219
|
}
|
|
220
|
-
function
|
|
220
|
+
function Z(t, e, r, a, s) {
|
|
221
221
|
return {
|
|
222
|
-
async resolvePlot(o,
|
|
222
|
+
async resolvePlot(o, n) {
|
|
223
223
|
if (!t || !t.plot) return;
|
|
224
|
-
const
|
|
225
|
-
if (!
|
|
226
|
-
const
|
|
227
|
-
if (!
|
|
228
|
-
const
|
|
229
|
-
type:
|
|
230
|
-
collection:
|
|
231
|
-
attributes: { axis:
|
|
232
|
-
labels: { axis:
|
|
224
|
+
const l = document.getElementById(t.plot);
|
|
225
|
+
if (!l) throw new Error(`Could not find plot target: ${t.plot}`);
|
|
226
|
+
const i = o;
|
|
227
|
+
if (!i) throw new Error("No data context available for plot.");
|
|
228
|
+
const f = s?.get(n.dataRef) ?? await i.getLayer(n.dataRef), c = n.events ?? [], u = new Q(l, {
|
|
229
|
+
type: z(n.mark),
|
|
230
|
+
collection: f,
|
|
231
|
+
attributes: { axis: n.axis, ...n.color && { color: n.color } },
|
|
232
|
+
labels: { axis: n.axis, title: n.title },
|
|
233
233
|
events: c,
|
|
234
|
-
...
|
|
235
|
-
...
|
|
236
|
-
...
|
|
237
|
-
...
|
|
234
|
+
...n.width && { width: n.width },
|
|
235
|
+
...n.height && { height: n.height },
|
|
236
|
+
...n.margins && { margins: n.margins },
|
|
237
|
+
...n.transform && { transform: n.transform }
|
|
238
238
|
});
|
|
239
|
-
if (
|
|
240
|
-
const
|
|
241
|
-
if (
|
|
242
|
-
|
|
243
|
-
|
|
239
|
+
if (r?.set(n.dataRef, u), n.mapRef && a?.set(n.dataRef, n.mapRef), n.mapRef && e) {
|
|
240
|
+
const p = e.get(n.mapRef);
|
|
241
|
+
if (p) {
|
|
242
|
+
p.updateRenderInfo(n.mapRef, { isPick: !0 }), p.events.on(P.PICKING, ({ selection: m }) => {
|
|
243
|
+
u.setSelection(m);
|
|
244
244
|
});
|
|
245
|
-
for (const
|
|
246
|
-
|
|
247
|
-
|
|
245
|
+
for (const m of c)
|
|
246
|
+
u.events.on(m, ({ selection: h }) => {
|
|
247
|
+
p.setHighlightedIds(n.mapRef, h);
|
|
248
248
|
});
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
};
|
|
253
253
|
}
|
|
254
|
-
|
|
254
|
+
const M = 2e3;
|
|
255
|
+
function tt(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 R(t, e) {
|
|
263
|
+
return t instanceof Map ? t.get(e) : t[e];
|
|
264
|
+
}
|
|
265
|
+
function w(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 G(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 et(t) {
|
|
279
|
+
return [.../* @__PURE__ */ new Set([t.dataRef, ...G(t).map((e) => e.fromFeature.layer)])];
|
|
280
|
+
}
|
|
281
|
+
function D(t) {
|
|
282
|
+
for (const e of G(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 j(t, e, r) {
|
|
289
|
+
const a = t.fromFeature, s = r !== void 0 && a.iterate === "all" ? r : a.index ?? 0, o = R(e, a.layer)?.features?.[s];
|
|
290
|
+
return o ? w(o, a.path) : void 0;
|
|
291
|
+
}
|
|
292
|
+
function N(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 n = Number(j(o, e, r) ?? NaN);
|
|
301
|
+
Number.isFinite(n) ? a[s] = n : typeof o.default == "number" && (a[s] = o.default);
|
|
302
|
+
}
|
|
303
|
+
return a;
|
|
304
|
+
}
|
|
305
|
+
function T(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 n = j(o, e, r), l = Array.isArray(n) ? n : Array.isArray(o.default) ? o.default : void 0;
|
|
314
|
+
if (!l) continue;
|
|
315
|
+
const i = o.cols ?? (Array.isArray(l[0]) ? l[0].length : 0);
|
|
316
|
+
i > 0 ? a[s] = { data: l, cols: i } : console.warn(`[autk-grammar] uniform matrix "${s}" has no column count; entry dropped`);
|
|
317
|
+
}
|
|
318
|
+
return a;
|
|
319
|
+
}
|
|
320
|
+
function rt(t) {
|
|
321
|
+
return t != null && !(typeof t == "number" && !Number.isFinite(t));
|
|
322
|
+
}
|
|
323
|
+
function ot(t, e, r) {
|
|
324
|
+
const a = {}, s = {}, o = [];
|
|
325
|
+
for (const n of [t, e])
|
|
326
|
+
for (const l of Object.values(n ?? {}))
|
|
327
|
+
_(l) && l.fromFeature.iterate === "batched" && l.fromFeature.required && o.push(l.fromFeature.path);
|
|
328
|
+
if (o.length > 0) {
|
|
329
|
+
const n = r.length;
|
|
330
|
+
r = r.filter((l) => o.every((i) => rt(w(l, i)))), r.length < n && console.info(`[autk-grammar] batched compute dropped ${n - r.length} feature(s) missing ${o.join(", ")}`);
|
|
331
|
+
}
|
|
332
|
+
r.length > M && (console.warn(`[autk-grammar] batched compute capped at ${M} features (got ${r.length})`), r = r.slice(0, M));
|
|
333
|
+
for (const [n, l] of Object.entries(t ?? {}))
|
|
334
|
+
if (_(l) && l.fromFeature.iterate === "batched") {
|
|
335
|
+
const i = typeof l.default == "number" ? l.default : void 0;
|
|
336
|
+
s[n] = r.map((f) => {
|
|
337
|
+
const c = Number(w(f, l.fromFeature.path) ?? i);
|
|
338
|
+
return Number.isFinite(c) ? c : 0;
|
|
339
|
+
});
|
|
340
|
+
} else typeof l == "number" && (a[n] = l);
|
|
341
|
+
for (const [n, l] of Object.entries(e ?? {})) {
|
|
342
|
+
if (!_(l) || l.fromFeature.iterate !== "batched") continue;
|
|
343
|
+
const i = [];
|
|
344
|
+
for (const f of r) {
|
|
345
|
+
const c = w(f, l.fromFeature.path);
|
|
346
|
+
let u = 1 / 0, p = 1 / 0, m = -1 / 0, h = -1 / 0;
|
|
347
|
+
if (Array.isArray(c))
|
|
348
|
+
for (const d of c) {
|
|
349
|
+
if (!Array.isArray(d) || d.length < 2) continue;
|
|
350
|
+
const g = Number(d[0]), E = Number(d[1]);
|
|
351
|
+
!Number.isFinite(g) || !Number.isFinite(E) || (u = Math.min(u, g), p = Math.min(p, E), m = Math.max(m, g), h = Math.max(h, E));
|
|
352
|
+
}
|
|
353
|
+
Number.isFinite(u) || (u = 0, p = 0, m = 0, h = 0), i.push(u, p, m, p, m, h, u, h);
|
|
354
|
+
}
|
|
355
|
+
s[n] = i;
|
|
356
|
+
}
|
|
357
|
+
return a.num_features = r.length, { uniforms: a, uniformArrays: s };
|
|
358
|
+
}
|
|
359
|
+
function I(t, e, r) {
|
|
360
|
+
const a = R(e, t.dataRef);
|
|
361
|
+
if (!a) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
|
|
362
|
+
const s = {
|
|
363
|
+
collection: a,
|
|
364
|
+
variableMapping: t.attributes,
|
|
365
|
+
wgslBody: tt(t.wglsFunction)
|
|
366
|
+
};
|
|
367
|
+
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);
|
|
368
|
+
const o = D(t);
|
|
369
|
+
if (o?.mode === "batched") {
|
|
370
|
+
const f = R(e, o.layer)?.features ?? [], c = ot(t.uniforms, t.uniformMatrices, f), u = N(B(t.uniforms), e) ?? {}, p = T(B(t.uniformMatrices), e);
|
|
371
|
+
return s.uniforms = { ...u, ...c.uniforms }, s.uniformArrays = { ...s.uniformArrays ?? {}, ...c.uniformArrays }, p && Object.keys(p).length > 0 && (s.uniformMatrices = p), s;
|
|
372
|
+
}
|
|
373
|
+
const n = o?.mode === "all" ? r : void 0, l = N(t.uniforms, e, n), i = T(t.uniformMatrices, e, n);
|
|
374
|
+
return l && (s.uniforms = l), i && (s.uniformMatrices = i), s;
|
|
375
|
+
}
|
|
376
|
+
function B(t) {
|
|
377
|
+
if (t)
|
|
378
|
+
return Object.fromEntries(Object.entries(t).filter(([, e]) => !(_(e) && e.fromFeature.iterate === "batched")));
|
|
379
|
+
}
|
|
380
|
+
function at(t) {
|
|
381
|
+
return t.outputColumns ?? (t.outputColumnName ? [t.outputColumnName] : []);
|
|
382
|
+
}
|
|
383
|
+
async function nt(t, e, r) {
|
|
384
|
+
const a = D(t);
|
|
385
|
+
if (a?.mode !== "all") return r(I(t, e));
|
|
386
|
+
const s = R(e, t.dataRef);
|
|
387
|
+
if (!s) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
|
|
388
|
+
const o = at(t), n = structuredClone(s);
|
|
389
|
+
for (const i of n.features) {
|
|
390
|
+
const f = i.properties ??= {}, c = f.compute ??= {};
|
|
391
|
+
for (const u of o) c[u] = 0;
|
|
392
|
+
}
|
|
393
|
+
const l = R(e, a.layer)?.features?.length ?? 0;
|
|
394
|
+
for (let i = 0; i < l; i++) {
|
|
395
|
+
const f = await r({ ...I(t, e, i), collection: n });
|
|
396
|
+
n.features.forEach((c, u) => {
|
|
397
|
+
const p = c.properties?.compute, m = f.features[u]?.properties?.compute;
|
|
398
|
+
if (!(!p || !m))
|
|
399
|
+
for (const h of o) {
|
|
400
|
+
const d = Number(m[h]);
|
|
401
|
+
Number.isFinite(d) && (p[h] += d);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
return n;
|
|
406
|
+
}
|
|
407
|
+
function it(t) {
|
|
255
408
|
return {
|
|
256
|
-
async resolveCompute(
|
|
257
|
-
if (
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
|
|
409
|
+
async resolveCompute(e, r) {
|
|
410
|
+
if (e) {
|
|
411
|
+
const a = {};
|
|
412
|
+
for (const n of et(r)) {
|
|
413
|
+
const l = t?.get(n);
|
|
414
|
+
if (l) a[n] = l;
|
|
415
|
+
else if (n === r.dataRef) a[n] = await e.getLayer(n);
|
|
416
|
+
else
|
|
417
|
+
try {
|
|
418
|
+
a[n] = await e.getLayer(n);
|
|
419
|
+
} catch {
|
|
420
|
+
a[n] = void 0;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
const s = new $(), o = await nt(r, a, (n) => s.gpgpuPipeline(n));
|
|
424
|
+
return t && t.set(r.dataRef, o), e;
|
|
271
425
|
}
|
|
272
426
|
}
|
|
273
427
|
};
|
|
274
428
|
}
|
|
275
|
-
class
|
|
429
|
+
class st {
|
|
276
430
|
_listeners = /* @__PURE__ */ new Map();
|
|
277
|
-
on(
|
|
278
|
-
this._listeners.has(
|
|
279
|
-
const
|
|
280
|
-
return
|
|
431
|
+
on(e, r) {
|
|
432
|
+
this._listeners.has(e) || this._listeners.set(e, /* @__PURE__ */ new Set());
|
|
433
|
+
const a = this._listeners.get(e);
|
|
434
|
+
return a.add(r), () => a.delete(r);
|
|
281
435
|
}
|
|
282
436
|
/** @internal */
|
|
283
|
-
emit(
|
|
284
|
-
this._listeners.get(
|
|
437
|
+
emit(e, r) {
|
|
438
|
+
this._listeners.get(e)?.forEach((a) => a(r));
|
|
285
439
|
}
|
|
286
440
|
}
|
|
287
|
-
class
|
|
441
|
+
class mt {
|
|
288
442
|
dataAdapter;
|
|
289
443
|
mapAdapter;
|
|
290
444
|
plotAdapter;
|
|
@@ -296,10 +450,10 @@ class X {
|
|
|
296
450
|
_plotRegistry = /* @__PURE__ */ new Map();
|
|
297
451
|
_fwdCleanups = [];
|
|
298
452
|
_plotMapLinks = /* @__PURE__ */ new Map();
|
|
299
|
-
interactions = new
|
|
300
|
-
constructor(
|
|
301
|
-
const
|
|
302
|
-
this.dataAdapter =
|
|
453
|
+
interactions = new st();
|
|
454
|
+
constructor(e) {
|
|
455
|
+
const r = /* @__PURE__ */ new Map();
|
|
456
|
+
this.dataAdapter = W(e, r), this.mapAdapter = q(e, this._mapRegistry, this._computeCache), this.plotAdapter = Z(e, this._mapRegistry, this._plotRegistry, this._plotMapLinks, r), this.computeAdapter = it(this._computeCache);
|
|
303
457
|
}
|
|
304
458
|
/**
|
|
305
459
|
* The coordinate reference system used internally by the autk workspace.
|
|
@@ -310,12 +464,12 @@ class X {
|
|
|
310
464
|
* instead of hard-coding a CRS string.
|
|
311
465
|
*/
|
|
312
466
|
get workspaceCrs() {
|
|
313
|
-
return
|
|
467
|
+
return F;
|
|
314
468
|
}
|
|
315
469
|
get data() {
|
|
316
470
|
return this._data;
|
|
317
471
|
}
|
|
318
|
-
async run(
|
|
472
|
+
async run(e) {
|
|
319
473
|
if (!this.dataAdapter)
|
|
320
474
|
throw new Error("Database adapter not initialized. Please call the constructor first.");
|
|
321
475
|
if (!this.mapAdapter)
|
|
@@ -324,8 +478,8 @@ class X {
|
|
|
324
478
|
throw new Error("Plot adapter not initialized. Please call the constructor first.");
|
|
325
479
|
if (!this.computeAdapter)
|
|
326
480
|
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:
|
|
481
|
+
this._mapRegistry.clear(), this._plotRegistry.clear(), this._plotMapLinks.clear(), this._computeCache.clear(), this.grammarEngine = H({
|
|
482
|
+
spec: e,
|
|
329
483
|
adapters: {
|
|
330
484
|
db: this.dataAdapter,
|
|
331
485
|
map: this.mapAdapter,
|
|
@@ -333,89 +487,99 @@ class X {
|
|
|
333
487
|
compute: this.computeAdapter
|
|
334
488
|
}
|
|
335
489
|
}), await this.grammarEngine.run(), this._rewireInteractions();
|
|
336
|
-
const
|
|
337
|
-
if (!
|
|
490
|
+
const r = this.grammarEngine.context;
|
|
491
|
+
if (!r) {
|
|
338
492
|
console.warn("Grammar engine produced no data context."), this._data = {};
|
|
339
493
|
return;
|
|
340
494
|
}
|
|
341
|
-
const
|
|
342
|
-
for (const s of
|
|
343
|
-
Object.defineProperty(
|
|
495
|
+
const a = {};
|
|
496
|
+
for (const s of r.getLayersMetadata())
|
|
497
|
+
Object.defineProperty(a, s.name, {
|
|
344
498
|
get: () => {
|
|
345
499
|
const o = this._computeCache.get(s.name);
|
|
346
|
-
return o ? Promise.resolve(o) :
|
|
500
|
+
return o ? Promise.resolve(o) : r.getLayer(s.name);
|
|
347
501
|
},
|
|
348
502
|
enumerable: !0,
|
|
349
503
|
configurable: !0
|
|
350
504
|
});
|
|
351
|
-
this._data =
|
|
505
|
+
this._data = a;
|
|
352
506
|
}
|
|
353
507
|
/**
|
|
354
508
|
* Highlights features on the map layer identified by `layerId`.
|
|
355
509
|
* If that layer is linked to a plot via `mapRef`, the plot selection is updated too.
|
|
356
510
|
*/
|
|
357
|
-
highlightOnMap(
|
|
358
|
-
this._mapRegistry.get(
|
|
359
|
-
for (const [
|
|
360
|
-
s ===
|
|
511
|
+
highlightOnMap(e, r) {
|
|
512
|
+
this._mapRegistry.get(e)?.setHighlightedIds(e, r);
|
|
513
|
+
for (const [a, s] of this._plotMapLinks)
|
|
514
|
+
s === e && this._plotRegistry.get(a)?.setSelection(r);
|
|
361
515
|
}
|
|
362
516
|
/**
|
|
363
517
|
* Clears highlighted features on the map layer identified by `layerId`.
|
|
364
518
|
* If that layer is linked to a plot via `mapRef`, the plot selection is cleared too.
|
|
365
519
|
*/
|
|
366
|
-
clearHighlightOnMap(
|
|
367
|
-
this._mapRegistry.get(
|
|
368
|
-
for (const [
|
|
369
|
-
|
|
520
|
+
clearHighlightOnMap(e) {
|
|
521
|
+
this._mapRegistry.get(e)?.clearHighlightedIds(e);
|
|
522
|
+
for (const [r, a] of this._plotMapLinks)
|
|
523
|
+
a === e && this._plotRegistry.get(r)?.setSelection([]);
|
|
370
524
|
}
|
|
371
525
|
/**
|
|
372
526
|
* Clears the selection on the plot identified by `plotId` (its dataRef).
|
|
373
527
|
* If that plot is linked to a map via `mapRef`, the map highlight is cleared too.
|
|
374
528
|
*/
|
|
375
|
-
clearHighlightOnPlot(
|
|
376
|
-
this._plotRegistry.get(
|
|
377
|
-
const
|
|
378
|
-
|
|
529
|
+
clearHighlightOnPlot(e) {
|
|
530
|
+
this._plotRegistry.get(e)?.setSelection([]);
|
|
531
|
+
const r = this._plotMapLinks.get(e);
|
|
532
|
+
r && this._mapRegistry.get(r)?.clearHighlightedIds(r);
|
|
379
533
|
}
|
|
380
534
|
/**
|
|
381
535
|
* Applies a selection to the plot identified by `plotId` (its dataRef).
|
|
382
536
|
* If that plot is linked to a map via `mapRef`, the map highlight is updated too.
|
|
383
537
|
*/
|
|
384
|
-
setPlotSelection(
|
|
385
|
-
this._plotRegistry.get(
|
|
386
|
-
const
|
|
387
|
-
|
|
538
|
+
setPlotSelection(e, r) {
|
|
539
|
+
this._plotRegistry.get(e)?.setSelection(r);
|
|
540
|
+
const a = this._plotMapLinks.get(e);
|
|
541
|
+
a && this._mapRegistry.get(a)?.setHighlightedIds(a, r);
|
|
388
542
|
}
|
|
389
543
|
_rewireInteractions() {
|
|
390
|
-
for (const
|
|
544
|
+
for (const r of this._fwdCleanups) r();
|
|
391
545
|
this._fwdCleanups = [];
|
|
392
|
-
const
|
|
393
|
-
for (const [
|
|
394
|
-
if (
|
|
395
|
-
|
|
546
|
+
const e = /* @__PURE__ */ new Set();
|
|
547
|
+
for (const [r, a] of this._mapRegistry) {
|
|
548
|
+
if (e.has(a)) continue;
|
|
549
|
+
e.add(a);
|
|
396
550
|
const s = ({ selection: o }) => {
|
|
397
|
-
this.interactions.emit("map:picking", { layerId:
|
|
551
|
+
this.interactions.emit("map:picking", { layerId: r, selection: o });
|
|
398
552
|
};
|
|
399
|
-
|
|
553
|
+
a.events.on(P.PICKING, s), this._fwdCleanups.push(() => a.events.off(P.PICKING, s));
|
|
400
554
|
}
|
|
401
|
-
for (const [
|
|
402
|
-
for (const s of [
|
|
403
|
-
const o = ({ selection:
|
|
555
|
+
for (const [r, a] of this._plotRegistry)
|
|
556
|
+
for (const s of [A.CLICK, A.BRUSH, A.BRUSH_X, A.BRUSH_Y]) {
|
|
557
|
+
const o = ({ selection: n }) => {
|
|
404
558
|
this.interactions.emit("plot:selection", {
|
|
405
|
-
plotId:
|
|
559
|
+
plotId: r,
|
|
406
560
|
event: s,
|
|
407
|
-
selection:
|
|
561
|
+
selection: n
|
|
408
562
|
});
|
|
409
563
|
};
|
|
410
|
-
|
|
564
|
+
a.events.on(s, o), this._fwdCleanups.push(() => a.events.off(s, o));
|
|
411
565
|
}
|
|
412
566
|
}
|
|
413
567
|
}
|
|
414
568
|
export {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
M as
|
|
419
|
-
|
|
569
|
+
mt as AutkGrammar,
|
|
570
|
+
Y as ColorMapInterpolator,
|
|
571
|
+
st as GrammarEventEmitter,
|
|
572
|
+
M as MAX_BATCHED_FEATURES,
|
|
573
|
+
O as NormalizationMode,
|
|
574
|
+
ot as buildBatchedUniforms,
|
|
575
|
+
et as computeLayerNames,
|
|
576
|
+
H as createEngine,
|
|
577
|
+
D as findIterateSource,
|
|
578
|
+
_ as isFromFeature,
|
|
579
|
+
tt as joinWgsl,
|
|
580
|
+
I as resolveComputeParams,
|
|
581
|
+
T as resolveUniformMatrices,
|
|
582
|
+
N as resolveUniforms,
|
|
583
|
+
nt as runCompute
|
|
420
584
|
};
|
|
421
585
|
//# sourceMappingURL=autk-grammar.js.map
|