@urban-toolkit/autk-grammar 0.3.0 → 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 +3 -1
- package/dist/autk-grammar.js +232 -218
- package/dist/autk-grammar.js.map +1 -1
- package/dist/autk-grammar.umd.cjs +2 -2
- package/dist/autk-grammar.umd.cjs.map +1 -1
- package/dist/index.d.ts +16 -7
- package/package.json +6 -6
package/dist/autk-grammar.js
CHANGED
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
import { AutkDb as
|
|
2
|
-
import { AutkMap as
|
|
3
|
-
import { AutkPlot as
|
|
4
|
-
import { ColorMapDomainStrategy as
|
|
5
|
-
import { AutkComputeEngine as
|
|
6
|
-
function
|
|
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
7
|
const { spec: e, adapters: r } = t;
|
|
8
8
|
let a;
|
|
9
9
|
async function s() {
|
|
10
10
|
let l;
|
|
11
11
|
if (e.data)
|
|
12
|
-
for (const
|
|
13
|
-
l = await r.db.resolveSource(l,
|
|
12
|
+
for (const n of e.data)
|
|
13
|
+
l = await r.db.resolveSource(l, n);
|
|
14
14
|
if (e.compute)
|
|
15
|
-
for (const
|
|
16
|
-
l = await r.compute.resolveCompute(l,
|
|
15
|
+
for (const n of e.compute)
|
|
16
|
+
l = await r.compute.resolveCompute(l, n);
|
|
17
17
|
if (e.map)
|
|
18
18
|
if (Array.isArray(e.map))
|
|
19
|
-
for (let
|
|
20
|
-
let
|
|
21
|
-
await r.map.resolveMap(l,
|
|
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
24
|
await r.map.resolveMap(l, e.map);
|
|
25
25
|
if (e.plot)
|
|
26
26
|
if (Array.isArray(e.plot))
|
|
27
|
-
for (const
|
|
28
|
-
await r.plot.resolvePlot(l,
|
|
27
|
+
for (const n of e.plot)
|
|
28
|
+
await r.plot.resolvePlot(l, n);
|
|
29
29
|
else
|
|
30
30
|
await r.plot.resolvePlot(l, e.plot);
|
|
31
31
|
a = l;
|
|
32
32
|
}
|
|
33
33
|
function o(l) {
|
|
34
|
-
return console.log("Spec to update", l), new Promise((
|
|
35
|
-
|
|
34
|
+
return console.log("Spec to update", l), new Promise((n) => {
|
|
35
|
+
n();
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function i() {
|
|
39
39
|
console.log("Function not implemented yet");
|
|
40
40
|
}
|
|
41
|
-
return { run: s, updatedSpec: o, destroy:
|
|
41
|
+
return { run: s, updatedSpec: o, destroy: i, get context() {
|
|
42
42
|
return a;
|
|
43
43
|
} };
|
|
44
44
|
}
|
|
45
|
-
var
|
|
46
|
-
function
|
|
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
47
|
const { autoLoadLayers: e, ...r } = t;
|
|
48
48
|
return { ...r, autoLoadLayers: { layers: e?.layers ?? [] } };
|
|
49
49
|
}
|
|
50
|
-
function
|
|
50
|
+
function J(t, e) {
|
|
51
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 i = a.getTablesMetadata();
|
|
57
57
|
o.innerHTML += "<ul>";
|
|
58
|
-
for (const l of
|
|
58
|
+
for (const l of i)
|
|
59
59
|
o.innerHTML += `<li>${l.name}: (${l.source}, ${l.type}) </li>`;
|
|
60
|
-
o.innerHTML += "</ul>", o.innerHTML += `<p>Number of tables: ${
|
|
60
|
+
o.innerHTML += "</ul>", o.innerHTML += `<p>Number of tables: ${i.length}</p>`;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
return {
|
|
64
64
|
async resolveSource(a, s) {
|
|
65
65
|
let o = a;
|
|
66
|
-
o || (o = new
|
|
67
|
-
let { type:
|
|
68
|
-
switch (
|
|
66
|
+
o || (o = new Q(), await o.init());
|
|
67
|
+
let { type: i, ...l } = s;
|
|
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
72
|
return await o.loadCsv(l), r(o, t), o;
|
|
73
73
|
case "json":
|
|
74
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 n = l;
|
|
77
|
+
let u;
|
|
78
|
+
n.geojsonFileUrl ? u = await (await fetch(n.geojsonFileUrl)).json() : u = n.geojsonObject, e && u && e.set(n.outputTableName, u);
|
|
79
|
+
const c = u ? (() => {
|
|
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 (
|
|
85
|
+
} catch (f) {
|
|
86
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
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
|
-
...
|
|
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
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
|
-
...
|
|
115
|
+
tableRootName: n.tableRootName,
|
|
116
|
+
tableJoinName: n.tableJoinName,
|
|
117
|
+
...n.near && { near: n.near },
|
|
118
|
+
...n.groupBy && { groupBy: n.groupBy }
|
|
119
119
|
}), e) {
|
|
120
|
-
const
|
|
121
|
-
e.set(
|
|
120
|
+
const u = await o.getLayer(n.tableRootName);
|
|
121
|
+
e.set(n.tableRootName, u);
|
|
122
122
|
}
|
|
123
123
|
return r(o, t), o;
|
|
124
124
|
}
|
|
@@ -128,85 +128,85 @@ function W(t, e) {
|
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
|
-
function
|
|
132
|
-
return e && e.length > 0 ? { type:
|
|
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
|
|
137
|
+
function X(t, e) {
|
|
138
138
|
return e.split(".").reduce((r, a) => {
|
|
139
139
|
if (!(r == null || typeof r != "object"))
|
|
140
140
|
return r[a];
|
|
141
141
|
}, t);
|
|
142
142
|
}
|
|
143
|
-
function
|
|
143
|
+
function q(t, e, r) {
|
|
144
144
|
const a = e.split("."), s = { ...t };
|
|
145
145
|
let o = s;
|
|
146
|
-
for (let
|
|
147
|
-
o[a[
|
|
146
|
+
for (let i = 0; i < a.length - 1; i++)
|
|
147
|
+
o[a[i]] = { ...o[a[i]] ?? {} }, o = o[a[i]];
|
|
148
148
|
return o[a[a.length - 1]] = r, s;
|
|
149
149
|
}
|
|
150
|
-
function
|
|
150
|
+
function z(t, e) {
|
|
151
151
|
const a = t.features?.[0]?.properties?.bands ?? [];
|
|
152
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 a(s, o,
|
|
154
|
+
function Z(t, e, r) {
|
|
155
|
+
async function a(s, o, i) {
|
|
156
156
|
let l = {};
|
|
157
|
-
for (const
|
|
158
|
-
|
|
159
|
-
for (const
|
|
160
|
-
const
|
|
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
161
|
...p,
|
|
162
|
-
features: (p.features ?? []).filter((
|
|
162
|
+
features: (p.features ?? []).filter((h) => h.geometry != null)
|
|
163
163
|
};
|
|
164
|
-
c === "raster" ? s.loadCollection(
|
|
165
|
-
const { catchAllCategory: d, colorMapDomain:
|
|
166
|
-
let E = m,
|
|
167
|
-
if (
|
|
168
|
-
const
|
|
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
169
|
E = {
|
|
170
170
|
...m,
|
|
171
|
-
features: m.features.map((
|
|
172
|
-
const
|
|
173
|
-
return
|
|
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(
|
|
184
|
+
s.updateRenderInfo(u, { colormap: { config: h }, isColorMap: !0 });
|
|
185
185
|
}
|
|
186
|
-
if (
|
|
187
|
-
const
|
|
188
|
-
s.updateThematic(
|
|
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
|
-
async resolveMap(s, o,
|
|
193
|
+
async resolveMap(s, o, i = 0) {
|
|
194
194
|
if (t && t.map && s) {
|
|
195
195
|
let l;
|
|
196
|
-
if (Array.isArray(t.map) ? l = document.getElementById(t.map[
|
|
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
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
|
-
e.set(
|
|
204
|
-
|
|
200
|
+
const n = new $(l);
|
|
201
|
+
if (o.style && n.style.setPredefinedStyle(o.style), await n.init(), await a(n, s, o), e)
|
|
202
|
+
for (const u of o.layerRefs)
|
|
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,79 +217,79 @@ function z(t) {
|
|
|
217
217
|
heatmatrix: "heatmatrix"
|
|
218
218
|
}[t];
|
|
219
219
|
}
|
|
220
|
-
function
|
|
220
|
+
function et(t, e, r, a, s) {
|
|
221
221
|
return {
|
|
222
|
-
async resolvePlot(o,
|
|
222
|
+
async resolvePlot(o, i) {
|
|
223
223
|
if (!t || !t.plot) return;
|
|
224
224
|
const l = document.getElementById(t.plot);
|
|
225
225
|
if (!l) throw new Error(`Could not find plot target: ${t.plot}`);
|
|
226
|
-
const
|
|
227
|
-
if (!
|
|
228
|
-
const
|
|
229
|
-
type:
|
|
230
|
-
collection:
|
|
231
|
-
attributes: { axis:
|
|
232
|
-
labels: { axis:
|
|
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
|
+
collection: u,
|
|
231
|
+
attributes: { axis: i.axis, ...i.color && { color: i.color } },
|
|
232
|
+
labels: { axis: i.axis, title: i.title },
|
|
233
233
|
events: c,
|
|
234
|
-
...
|
|
235
|
-
...
|
|
236
|
-
...
|
|
237
|
-
...
|
|
234
|
+
...i.width && { width: i.width },
|
|
235
|
+
...i.height && { height: i.height },
|
|
236
|
+
...i.margins && { margins: i.margins },
|
|
237
|
+
...i.transform && { transform: i.transform }
|
|
238
238
|
});
|
|
239
|
-
if (r?.set(
|
|
240
|
-
const p = e.get(
|
|
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
241
|
if (p) {
|
|
242
|
-
p.updateRenderInfo(
|
|
243
|
-
|
|
242
|
+
p.updateRenderInfo(i.mapRef, { isPick: !0 }), p.events.on(P.PICKING, ({ selection: m }) => {
|
|
243
|
+
f.setSelection(m);
|
|
244
244
|
});
|
|
245
245
|
for (const m of c)
|
|
246
|
-
|
|
247
|
-
p.setHighlightedIds(
|
|
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
|
-
const
|
|
255
|
-
function
|
|
254
|
+
const G = 134217728, rt = 4, ot = 32;
|
|
255
|
+
function at(t) {
|
|
256
256
|
return Array.isArray(t) ? t.join(`
|
|
257
257
|
`) : t;
|
|
258
258
|
}
|
|
259
259
|
function _(t) {
|
|
260
260
|
return !!t && typeof t == "object" && !Array.isArray(t) && typeof t.fromFeature == "object" && t.fromFeature !== null;
|
|
261
261
|
}
|
|
262
|
-
function
|
|
262
|
+
function b(t, e) {
|
|
263
263
|
return t instanceof Map ? t.get(e) : t[e];
|
|
264
264
|
}
|
|
265
|
-
function
|
|
265
|
+
function S(t, e) {
|
|
266
266
|
return e.split(".").reduce((r, a) => {
|
|
267
267
|
if (!(r == null || typeof r != "object"))
|
|
268
268
|
return r[a];
|
|
269
269
|
}, t);
|
|
270
270
|
}
|
|
271
|
-
function
|
|
271
|
+
function D(t) {
|
|
272
272
|
const e = [];
|
|
273
273
|
for (const r of [t.uniforms, t.uniformMatrices])
|
|
274
274
|
for (const a of Object.values(r ?? {}))
|
|
275
275
|
_(a) && e.push(a);
|
|
276
276
|
return e;
|
|
277
277
|
}
|
|
278
|
-
function
|
|
279
|
-
return [.../* @__PURE__ */ new Set([t.dataRef, ...
|
|
278
|
+
function nt(t) {
|
|
279
|
+
return [.../* @__PURE__ */ new Set([t.dataRef, ...D(t).map((e) => e.fromFeature.layer)])];
|
|
280
280
|
}
|
|
281
|
-
function
|
|
282
|
-
for (const e of
|
|
281
|
+
function j(t) {
|
|
282
|
+
for (const e of D(t)) {
|
|
283
283
|
const { iterate: r, layer: a } = e.fromFeature;
|
|
284
284
|
if (r === "all" || r === "batched") return { mode: r, layer: a };
|
|
285
285
|
}
|
|
286
286
|
return null;
|
|
287
287
|
}
|
|
288
|
-
function
|
|
289
|
-
const a = t.fromFeature, s = r !== void 0 && a.iterate === "all" ? r : a.index ?? 0, o =
|
|
290
|
-
return o ?
|
|
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
291
|
}
|
|
292
|
-
function
|
|
292
|
+
function v(t, e, r) {
|
|
293
293
|
if (!t) return;
|
|
294
294
|
const a = {};
|
|
295
295
|
for (const [s, o] of Object.entries(t)) {
|
|
@@ -297,12 +297,12 @@ function N(t, e, r) {
|
|
|
297
297
|
a[s] = o;
|
|
298
298
|
continue;
|
|
299
299
|
}
|
|
300
|
-
const
|
|
301
|
-
Number.isFinite(
|
|
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
302
|
}
|
|
303
303
|
return a;
|
|
304
304
|
}
|
|
305
|
-
function
|
|
305
|
+
function N(t, e, r) {
|
|
306
306
|
if (!t) return;
|
|
307
307
|
const a = {};
|
|
308
308
|
for (const [s, o] of Object.entries(t)) {
|
|
@@ -310,123 +310,136 @@ function T(t, e, r) {
|
|
|
310
310
|
a[s] = o;
|
|
311
311
|
continue;
|
|
312
312
|
}
|
|
313
|
-
const
|
|
313
|
+
const i = x(o, e, r), l = Array.isArray(i) ? i : Array.isArray(o.default) ? o.default : void 0;
|
|
314
314
|
if (!l) continue;
|
|
315
|
-
const
|
|
316
|
-
|
|
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
317
|
}
|
|
318
318
|
return a;
|
|
319
319
|
}
|
|
320
|
-
function
|
|
320
|
+
function it(t) {
|
|
321
321
|
return t != null && !(typeof t == "number" && !Number.isFinite(t));
|
|
322
322
|
}
|
|
323
|
-
function
|
|
324
|
-
|
|
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 = [];
|
|
325
335
|
for (const n of [t, e])
|
|
326
|
-
for (const
|
|
327
|
-
_(
|
|
328
|
-
if (
|
|
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) {
|
|
329
339
|
const n = r.length;
|
|
330
|
-
r = r.filter((
|
|
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(", ")}`);
|
|
331
341
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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;
|
|
339
352
|
});
|
|
340
|
-
} else typeof
|
|
341
|
-
for (const [n,
|
|
342
|
-
if (!_(
|
|
343
|
-
const
|
|
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 = [];
|
|
344
357
|
for (const f of r) {
|
|
345
|
-
const
|
|
346
|
-
let
|
|
347
|
-
if (Array.isArray(
|
|
348
|
-
for (const
|
|
349
|
-
if (!Array.isArray(
|
|
350
|
-
const
|
|
351
|
-
!Number.isFinite(
|
|
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));
|
|
352
365
|
}
|
|
353
|
-
Number.isFinite(
|
|
366
|
+
Number.isFinite(m) || (m = 0, g = 0, d = 0, y = 0), c.push(m, g, d, g, d, y, m, y);
|
|
354
367
|
}
|
|
355
|
-
|
|
368
|
+
o[n] = c;
|
|
356
369
|
}
|
|
357
|
-
return
|
|
370
|
+
return s.num_features = r.length, { uniforms: s, uniformArrays: o };
|
|
358
371
|
}
|
|
359
|
-
function
|
|
360
|
-
const a =
|
|
372
|
+
function B(t, e, r) {
|
|
373
|
+
const a = b(e, t.dataRef);
|
|
361
374
|
if (!a) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
|
|
362
375
|
const s = {
|
|
363
376
|
collection: a,
|
|
364
377
|
variableMapping: t.attributes,
|
|
365
|
-
wgslBody:
|
|
378
|
+
wgslBody: at(t.wglsFunction)
|
|
366
379
|
};
|
|
367
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);
|
|
368
|
-
const o =
|
|
381
|
+
const o = j(t);
|
|
369
382
|
if (o?.mode === "batched") {
|
|
370
|
-
const
|
|
371
|
-
return s.uniforms = { ...
|
|
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;
|
|
372
385
|
}
|
|
373
|
-
const
|
|
374
|
-
return l && (s.uniforms = l),
|
|
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;
|
|
375
388
|
}
|
|
376
|
-
function
|
|
389
|
+
function T(t) {
|
|
377
390
|
if (t)
|
|
378
391
|
return Object.fromEntries(Object.entries(t).filter(([, e]) => !(_(e) && e.fromFeature.iterate === "batched")));
|
|
379
392
|
}
|
|
380
|
-
function
|
|
393
|
+
function ut(t) {
|
|
381
394
|
return t.outputColumns ?? (t.outputColumnName ? [t.outputColumnName] : []);
|
|
382
395
|
}
|
|
383
|
-
async function
|
|
384
|
-
const a =
|
|
385
|
-
if (a?.mode !== "all") return r(
|
|
386
|
-
const s =
|
|
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);
|
|
387
400
|
if (!s) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
|
|
388
|
-
const o =
|
|
389
|
-
for (const
|
|
390
|
-
const
|
|
391
|
-
for (const
|
|
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;
|
|
392
405
|
}
|
|
393
|
-
const l =
|
|
394
|
-
for (let
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
const p = c.properties?.compute, m =
|
|
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;
|
|
398
411
|
if (!(!p || !m))
|
|
399
|
-
for (const
|
|
400
|
-
const d = Number(m[
|
|
401
|
-
Number.isFinite(d) && (p[
|
|
412
|
+
for (const g of o) {
|
|
413
|
+
const d = Number(m[g]);
|
|
414
|
+
Number.isFinite(d) && (p[g] += d);
|
|
402
415
|
}
|
|
403
416
|
});
|
|
404
417
|
}
|
|
405
|
-
return
|
|
418
|
+
return i;
|
|
406
419
|
}
|
|
407
|
-
function
|
|
420
|
+
function ct(t) {
|
|
408
421
|
return {
|
|
409
422
|
async resolveCompute(e, r) {
|
|
410
423
|
if (e) {
|
|
411
424
|
const a = {};
|
|
412
|
-
for (const
|
|
413
|
-
const l = t?.get(
|
|
414
|
-
if (l) a[
|
|
415
|
-
else if (
|
|
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);
|
|
416
429
|
else
|
|
417
430
|
try {
|
|
418
|
-
a[
|
|
431
|
+
a[i] = await e.getLayer(i);
|
|
419
432
|
} catch {
|
|
420
|
-
a[
|
|
433
|
+
a[i] = void 0;
|
|
421
434
|
}
|
|
422
435
|
}
|
|
423
|
-
const s = new
|
|
436
|
+
const s = new H(), o = await ft(r, a, (i) => s.gpgpuPipeline(i));
|
|
424
437
|
return t && t.set(r.dataRef, o), e;
|
|
425
438
|
}
|
|
426
439
|
}
|
|
427
440
|
};
|
|
428
441
|
}
|
|
429
|
-
class
|
|
442
|
+
class pt {
|
|
430
443
|
_listeners = /* @__PURE__ */ new Map();
|
|
431
444
|
on(e, r) {
|
|
432
445
|
this._listeners.has(e) || this._listeners.set(e, /* @__PURE__ */ new Set());
|
|
@@ -438,7 +451,7 @@ class st {
|
|
|
438
451
|
this._listeners.get(e)?.forEach((a) => a(r));
|
|
439
452
|
}
|
|
440
453
|
}
|
|
441
|
-
class
|
|
454
|
+
class _t {
|
|
442
455
|
dataAdapter;
|
|
443
456
|
mapAdapter;
|
|
444
457
|
plotAdapter;
|
|
@@ -450,10 +463,10 @@ class mt {
|
|
|
450
463
|
_plotRegistry = /* @__PURE__ */ new Map();
|
|
451
464
|
_fwdCleanups = [];
|
|
452
465
|
_plotMapLinks = /* @__PURE__ */ new Map();
|
|
453
|
-
interactions = new
|
|
466
|
+
interactions = new pt();
|
|
454
467
|
constructor(e) {
|
|
455
468
|
const r = /* @__PURE__ */ new Map();
|
|
456
|
-
this.dataAdapter =
|
|
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);
|
|
457
470
|
}
|
|
458
471
|
/**
|
|
459
472
|
* The coordinate reference system used internally by the autk workspace.
|
|
@@ -478,7 +491,7 @@ class mt {
|
|
|
478
491
|
throw new Error("Plot adapter not initialized. Please call the constructor first.");
|
|
479
492
|
if (!this.computeAdapter)
|
|
480
493
|
throw new Error("Compute adapter not initialized. Please call the constructor first.");
|
|
481
|
-
this._mapRegistry.clear(), this._plotRegistry.clear(), this._plotMapLinks.clear(), this._computeCache.clear(), this.grammarEngine =
|
|
494
|
+
this._mapRegistry.clear(), this._plotRegistry.clear(), this._plotMapLinks.clear(), this._computeCache.clear(), this.grammarEngine = V({
|
|
482
495
|
spec: e,
|
|
483
496
|
adapters: {
|
|
484
497
|
db: this.dataAdapter,
|
|
@@ -554,11 +567,11 @@ class mt {
|
|
|
554
567
|
}
|
|
555
568
|
for (const [r, a] of this._plotRegistry)
|
|
556
569
|
for (const s of [A.CLICK, A.BRUSH, A.BRUSH_X, A.BRUSH_Y]) {
|
|
557
|
-
const o = ({ selection:
|
|
570
|
+
const o = ({ selection: i }) => {
|
|
558
571
|
this.interactions.emit("plot:selection", {
|
|
559
572
|
plotId: r,
|
|
560
573
|
event: s,
|
|
561
|
-
selection:
|
|
574
|
+
selection: i
|
|
562
575
|
});
|
|
563
576
|
};
|
|
564
577
|
a.events.on(s, o), this._fwdCleanups.push(() => a.events.off(s, o));
|
|
@@ -566,20 +579,21 @@ class mt {
|
|
|
566
579
|
}
|
|
567
580
|
}
|
|
568
581
|
export {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
M as MAX_BATCHED_FEATURES,
|
|
582
|
+
_t as AutkGrammar,
|
|
583
|
+
k as ColorMapInterpolator,
|
|
584
|
+
pt as GrammarEventEmitter,
|
|
573
585
|
O as NormalizationMode,
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
586
|
+
G as STORAGE_BUFFER_BINDING_SIZE,
|
|
587
|
+
lt as buildBatchedUniforms,
|
|
588
|
+
nt as computeLayerNames,
|
|
589
|
+
V as createEngine,
|
|
590
|
+
j as findIterateSource,
|
|
578
591
|
_ as isFromFeature,
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
N as
|
|
583
|
-
|
|
592
|
+
at as joinWgsl,
|
|
593
|
+
st as maxBatchedFeatures,
|
|
594
|
+
B as resolveComputeParams,
|
|
595
|
+
N as resolveUniformMatrices,
|
|
596
|
+
v as resolveUniforms,
|
|
597
|
+
ft as runCompute
|
|
584
598
|
};
|
|
585
599
|
//# sourceMappingURL=autk-grammar.js.map
|