@preschen/gen-vis 0.4.0 → 0.6.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.
@@ -0,0 +1,1149 @@
1
+ (() => { const s = document.createElement("style"); s.textContent = "@layer gen-vis {\n.hover[data-v-364032d4]{font-size:13px;position:absolute;top:0}.hover .title[data-v-364032d4]{text-align:center;border-bottom:2px solid #000;padding:1px 3px;font-weight:700}.hover[data-v-364032d4]{background-color:#fffc;top:40%}.hover[data-v-364032d4] table{border-collapse:collapse}.hover[data-v-364032d4] table tr.nearest{font-weight:700}.hover[data-v-364032d4] table tr td{text-align:left;padding:1px 5px}.hover[data-v-364032d4] table tr td.value,.hover[data-v-364032d4] table tr td.y{text-align:right}.hover[data-v-364032d4] table tr td:first-child{border-left:0}.hover[data-v-364032d4] table{margin-left:auto;margin-right:auto}.hover[data-v-364032d4]{pointer-events:none}.vis-inner[data-v-1f05a06e]{display:inline-block;position:relative}.vis-inner .debug[data-v-1f05a06e]{font-size:12px}.vis-inner[data-v-1f05a06e] svg g.axis-position-top g.tick line{transform:translateY(5px)}.vis-inner[data-v-1f05a06e] svg g.axis-position-right g.tick line{transform:translate(-4px)}.vis-inner[data-v-1f05a06e] svg g.axis-position-bottom g.tick line{transform:translateY(-4px)}.vis-inner[data-v-1f05a06e] svg g.axis-position-left g.tick line{transform:translate(5px)}.vis-inner[data-v-1f05a06e] svg g.tick text,.vis-inner[data-v-1f05a06e] svg .axis-title{font-size:13px}.vis-inner[data-v-1f05a06e] svg g.group[data-visible=false],.vis-inner[data-v-1f05a06e] svg path[data-visible=false]{opacity:.01}.vis-inner[data-v-1f05a06e] svg g.grid{stroke:#ccc;stroke-width:.75px}.vis-inner[data-v-1f05a06e] svg g.hoverMarker line{stroke-width:.75px;stroke:#aaa}svg[data-v-ce0e972e]{margin-right:5px;display:inline-block}.legend .title[data-v-1bc8d55f]{margin:3px;font-size:13px;font-weight:700;position:relative}.legend .entries>div[data-v-1bc8d55f]{cursor:pointer;margin:0 5px;display:inline-block}.legend .entries>div[data-visible=false][data-v-1bc8d55f]{opacity:.3}.legend .entries>div span[data-v-1bc8d55f]{font-size:13px;display:inline-block;position:relative;top:-4px}.legend .entries>div.bold[data-v-1bc8d55f]{font-weight:700}.formElement[data-v-ec3facd5]{margin:2px 16px 2px 4px;font-size:13px;display:inline-block}.formElement .title[data-v-ec3facd5]{margin-right:5px;font-weight:700;display:inline-block}.formElement .entries[data-v-ec3facd5]{display:inline-block}.formElement .entries>div[data-v-ec3facd5]{margin-right:5px;display:inline-block}.formElement .entries>div input[data-v-ec3facd5]{display:inline-block;position:relative;top:1px}.vis[data-v-b07c17d2] text,.vis[data-v-b07c17d2] span,.vis[data-v-b07c17d2] div{font-family:var(--gen-vis-font-family,Century Gothic, sans-serif)}.vis-header .title[data-v-b07c17d2]{font-size:22px;font-weight:700}.vis-header .subtitle[data-v-b07c17d2]{margin-top:3px;font-size:13px}.vis-header[data-v-b07c17d2]{margin-bottom:10px}.vis-footer span[data-v-b07c17d2]{font-size:13px}.facet-title[data-v-b07c17d2]{margin-top:8px;font-size:13px;font-weight:700}.vis-error[data-v-a9d47434]{color:#b00;font-size:13px}\n/*$vite$:1*/\n}"; document.head.appendChild(s); })();
2
+ import { Fragment as e, createApp as t, createBlock as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, markRaw as o, mergeProps as s, normalizeStyle as c, openBlock as l, reactive as u, renderList as d, resolveComponent as f, toDisplayString as p, toRaw as ee } from "vue";
3
+ import * as m from "d3";
4
+ import h from "deepmerge";
5
+ //#region src/utils/data.js
6
+ var g = (e) => typeof e == "string" ? (e = e.replace(/^/, ""), /^\s*\[/.test(e) ? JSON.parse(e) : m.csvParse(e)) : e, _ = (e) => e == null || e === "", te = {
7
+ numeric: (e) => {
8
+ let t = _(e) ? NaN : +e;
9
+ return isNaN(t) ? null : t;
10
+ },
11
+ date: (e) => {
12
+ let t = _(e) ? NaN : typeof e == "number" ? e : Date.parse(e);
13
+ return isNaN(t) ? null : t;
14
+ }
15
+ }, ne = (e, t) => {
16
+ let n = Object.keys(t.mapping).map((e) => ({
17
+ name: e,
18
+ column: t.mapping[e].column,
19
+ convert: te[t.mapping[e].type] ?? ((e) => e)
20
+ }));
21
+ return e.map((e) => {
22
+ let t = {};
23
+ return n.forEach((n) => {
24
+ t[n.name] = n.convert(e[n.column]);
25
+ }), t;
26
+ });
27
+ }, re = (e, t) => {
28
+ e.values = [...new Set(t.map((t) => t[e.dim]))], (e.mapping.type == "numeric" || e.mapping.type == "date") && (e.values = e.values.filter((e) => e !== null).sort((e, t) => e - t), e.extent = e.mapping.stacked ? m.extent(t.map((t) => t[`${e.dim}:st:e`])) : m.extent(e.values));
29
+ }, ie = (e) => {
30
+ let t = e.map(({ dim: e, keys: t }) => ({
31
+ dim: e,
32
+ rank: new Map(t.map((e, t) => [e, t]))
33
+ }));
34
+ return (e, n) => {
35
+ for (let { dim: r, rank: i } of t) {
36
+ let t = (i.get(e[r]) ?? Infinity) - (i.get(n[r]) ?? Infinity);
37
+ if (t) return t;
38
+ }
39
+ return 0;
40
+ };
41
+ }, ae = (e, t, n = [], r = null) => {
42
+ y(e, [...n, t.h]).forEach((e) => {
43
+ let n = 0, i = 0;
44
+ (r ? [...e.entries].sort(r) : e.entries).forEach((e) => {
45
+ let r = e[t.v];
46
+ r >= 0 ? (e[`${t.v}:st:s`] = n, n += r, e[`${t.v}:st:e`] = n) : (e[`${t.v}:st:s`] = i, i += r, e[`${t.v}:st:e`] = i);
47
+ });
48
+ });
49
+ }, v = (e, t) => {
50
+ e.forEach((e) => {
51
+ Object.values(t).forEach((t) => {
52
+ e[`${t.dim}:scaled`] = t.scale(e[t.dim]), e[`${t.dim}:scaled:min`] = t.scale(t.domain[0]), e[`${t.dim}:scaled:0`] = t.scale(0), e[`${t.dim}:scaled:max`] = t.scale(t.domain[1]), t.mapping.stacked && (e[`${t.dim}:st:e:scaled`] = t.scale(e[`${t.dim}:st:e`]), e[`${t.dim}:st:s:scaled`] = t.scale(e[`${t.dim}:st:s`]), e[`${t.dim}:st:h:scaled`] = e[`${t.dim}:st:s:scaled`] - e[`${t.dim}:st:e:scaled`]);
53
+ });
54
+ });
55
+ }, y = (e, t) => {
56
+ let n = /* @__PURE__ */ new Map();
57
+ return e.forEach((e) => {
58
+ let r = JSON.stringify(t.map((t) => e[t]));
59
+ n.has(r) || n.set(r, {
60
+ group: Object.fromEntries(t.map((t) => [t, e[t]])),
61
+ entries: []
62
+ }), n.get(r).entries.push(e);
63
+ }), [...n.values()];
64
+ }, b = (e, t) => t.length == 0 ? [...e] : e.filter((e) => t.reduce((t, n) => Array.isArray(n.key) ? t && n.key.includes(e[n.dim]) : typeof n.key == "function" ? t && n.key(e[n.dim]) : t && e[n.dim] == n.key, !0)), oe = (e, t, n) => t, x = (e) => h.all(e, { arrayMerge: oe }), S = (e, t) => e == t || JSON.stringify(e) == JSON.stringify(t), C = (e, t) => Object.fromEntries(Object.entries(e).map(([e, n], r) => [e, t(n, e)])), se = (e, t) => Array.isArray(e) ? e.map(t) : C(e, t), ce = (e, t, n, r) => e.map((e) => ({
65
+ group: Object.keys(e.group).map((t) => ({
66
+ dim: t,
67
+ key: e.group[t]
68
+ })),
69
+ props: t._fill(Object.assign({}, n, ...Object.keys(e.group).map((t) => r[t].props[e.group[t]]))),
70
+ values: e.entries
71
+ })), le = (e, t, n = !0, r = !1) => {
72
+ if (e.value === void 0 || e.value === null || r) {
73
+ if (e.prop == "ref") {
74
+ let n = t[e.ref];
75
+ n !== void 0 && (e.value = n);
76
+ }
77
+ if (e.prop == "relative") {
78
+ let n = t[e.ref];
79
+ n !== void 0 && (e.value = e.ratio * n);
80
+ }
81
+ if (e.prop == "steps") {
82
+ let n = t[e.ref];
83
+ n !== void 0 && e.steps.forEach((t) => {
84
+ n > t.cut && (e.value = t.value);
85
+ });
86
+ }
87
+ }
88
+ return n ? e.value : e;
89
+ }, w = (e, t) => le({ ...k(e) }, t, !0), T = (e, t, n = !0) => E(se(e, k), t, n), E = (e, t, n = !1) => se(e, (e) => le({ ...e }, t, n)), D = (e) => e.prop !== void 0, O = (e) => Object.values(e).flatMap((e) => typeof e != "object" || !e ? [] : D(e) ? typeof e.ref == "string" ? [e.ref.split(":")[0]] : [] : O(e)), k = (e) => {
90
+ if (typeof e == "object" && !Array.isArray(e) && e !== null) return D(e) ? e : C(e, k);
91
+ if (typeof e == "string" && e.charAt() == "@") {
92
+ let t = e.substring(1);
93
+ return {
94
+ prop: "ref",
95
+ ref: t,
96
+ parts: t.split(":")
97
+ };
98
+ }
99
+ return {
100
+ prop: "fixed",
101
+ value: e
102
+ };
103
+ }, A = (e) => {
104
+ if (e.props) {
105
+ let t = e.props;
106
+ e.props = Object.fromEntries(Object.keys(t.manual).map((e) => {
107
+ let n = Object.assign({}, t.common, t.manual[e]);
108
+ return n.name ??= e, n.visible ??= !0, [e, n];
109
+ }));
110
+ }
111
+ return e.scale && (e.scale.type ??= "linear", e.scale.domain ??= [null, null], e.scale.domainAbs || (e.scale.domainRel ??= e.scale.domain.map((e, t) => e === null ? (t == 0 ? -1 : 1) * .02 : 0)), e.scale.domainAbs ??= [0, 0], Array.isArray(e.scale.range) || (e.scale.orientation == "horizontal" ? e.scale.range = [0, "@width"] : e.scale.orientation == "vertical" && (e.scale.range = ["@height", 0]))), e.axis && (e.axis.padding ??= 3), e.hover !== void 0 && e.axis !== void 0 && (e.hover.format ??= e.axis.format), e.legend && (e.legend.props === void 0 && (e.legend.props = {}), "name" in e.legend.props || (e.legend.props.name = "@name")), e.hover && (e.hover.props === void 0 && (e.hover.props = {}), "name" in e.hover.props || (e.hover.props.name = "@name")), e;
112
+ }, ue = (e) => (Object.values(e.mapping).forEach(A), Array.isArray(e.plot) || (e.plot = [e.plot]), e.facets && Array.isArray(e.facets.dim) && (e.facets.dim = e.facets.dim[0]), e.plot.forEach((e, t) => {
113
+ e.categories ??= [], e.id ??= `plot-${t}`, e.highlightProps = Object.keys(e.props).filter((e) => e.startsWith("highlight-")).map((e) => e.substring(10));
114
+ }), e.plot.forEach((e) => {
115
+ e.props = C(e.props, k), e._fill = (t) => E(e.props, t);
116
+ }), e), j = (e) => typeof e == "string" ? [...e.matchAll(/\{(\w+)\}/g)].map((e) => e[1]) : [], de = (e, t = {}) => e.replace(/\{(\w+)\}/g, (e, n) => n in t ? String(t[n]) : e), M = (e, t) => {
117
+ let n = e.formElements ?? [], r = /* @__PURE__ */ new Set([...n.flatMap((e) => e.values.flatMap((e) => Object.keys(e.mapping ?? {}))), ...Object.keys(t.mapping ?? {}).filter((e) => j(t.mapping[e].column).length > 0)]);
118
+ if (r.size == 0) return !1;
119
+ let i = n.map((t) => t.values.find((n) => S(n.value, e.globals?.[t.ref]))).filter((e) => e && e.mapping);
120
+ return r.forEach((n) => {
121
+ let r = i.filter((e) => e.mapping[n]).map((e) => e.mapping[n]), a = x([t.mapping[n] ?? {}, ...r]);
122
+ typeof a.column == "string" && (a.column = de(a.column, e.globals));
123
+ let o = A(a);
124
+ e.mapping[n] && "props" in e.mapping[n] && (o.props = e.mapping[n].props), e.mapping[n] = o;
125
+ }), !0;
126
+ }, N = (e) => e.charAt(0).toUpperCase() + e.slice(1), P = {
127
+ de: {
128
+ number: {
129
+ decimal: ",",
130
+ thousands: ".",
131
+ grouping: [3],
132
+ currency: ["", " €"]
133
+ },
134
+ time: {
135
+ dateTime: "%A, der %e. %B %Y, %X",
136
+ date: "%d.%m.%Y",
137
+ time: "%H:%M:%S",
138
+ periods: ["AM", "PM"],
139
+ days: [
140
+ "Sonntag",
141
+ "Montag",
142
+ "Dienstag",
143
+ "Mittwoch",
144
+ "Donnerstag",
145
+ "Freitag",
146
+ "Samstag"
147
+ ],
148
+ shortDays: [
149
+ "So",
150
+ "Mo",
151
+ "Di",
152
+ "Mi",
153
+ "Do",
154
+ "Fr",
155
+ "Sa"
156
+ ],
157
+ months: [
158
+ "Januar",
159
+ "Februar",
160
+ "März",
161
+ "April",
162
+ "Mai",
163
+ "Juni",
164
+ "Juli",
165
+ "August",
166
+ "September",
167
+ "Oktober",
168
+ "November",
169
+ "Dezember"
170
+ ],
171
+ shortMonths: [
172
+ "Jan",
173
+ "Feb",
174
+ "Mrz",
175
+ "Apr",
176
+ "Mai",
177
+ "Jun",
178
+ "Jul",
179
+ "Aug",
180
+ "Sep",
181
+ "Okt",
182
+ "Nov",
183
+ "Dez"
184
+ ]
185
+ },
186
+ timeTicks: {
187
+ millisecond: ".%L",
188
+ second: ":%S",
189
+ minute: "%H:%M",
190
+ hour: "%H:%M",
191
+ day: "%a %d",
192
+ week: "%d. %b",
193
+ month: "%B",
194
+ year: "%Y"
195
+ }
196
+ },
197
+ en: {
198
+ number: {
199
+ decimal: ".",
200
+ thousands: ",",
201
+ grouping: [3],
202
+ currency: ["$", ""]
203
+ },
204
+ time: {
205
+ dateTime: "%x, %X",
206
+ date: "%-m/%-d/%Y",
207
+ time: "%-I:%M:%S %p",
208
+ periods: ["AM", "PM"],
209
+ days: [
210
+ "Sunday",
211
+ "Monday",
212
+ "Tuesday",
213
+ "Wednesday",
214
+ "Thursday",
215
+ "Friday",
216
+ "Saturday"
217
+ ],
218
+ shortDays: [
219
+ "Sun",
220
+ "Mon",
221
+ "Tue",
222
+ "Wed",
223
+ "Thu",
224
+ "Fri",
225
+ "Sat"
226
+ ],
227
+ months: [
228
+ "January",
229
+ "February",
230
+ "March",
231
+ "April",
232
+ "May",
233
+ "June",
234
+ "July",
235
+ "August",
236
+ "September",
237
+ "October",
238
+ "November",
239
+ "December"
240
+ ],
241
+ shortMonths: [
242
+ "Jan",
243
+ "Feb",
244
+ "Mar",
245
+ "Apr",
246
+ "May",
247
+ "Jun",
248
+ "Jul",
249
+ "Aug",
250
+ "Sep",
251
+ "Oct",
252
+ "Nov",
253
+ "Dec"
254
+ ]
255
+ },
256
+ timeTicks: {
257
+ millisecond: ".%L",
258
+ second: ":%S",
259
+ minute: "%I:%M",
260
+ hour: "%I %p",
261
+ day: "%a %d",
262
+ week: "%b %d",
263
+ month: "%B",
264
+ year: "%Y"
265
+ }
266
+ }
267
+ }, fe = Object.keys(P), F = {
268
+ time: [
269
+ m.timeSecond,
270
+ m.timeMinute,
271
+ m.timeHour,
272
+ m.timeDay,
273
+ m.timeWeek,
274
+ m.timeMonth,
275
+ m.timeYear
276
+ ],
277
+ utc: [
278
+ m.utcSecond,
279
+ m.utcMinute,
280
+ m.utcHour,
281
+ m.utcDay,
282
+ m.utcWeek,
283
+ m.utcMonth,
284
+ m.utcYear
285
+ ]
286
+ }, I = (e, t, n) => {
287
+ let r = Object.fromEntries(Object.entries(t).map(([t, n]) => [t, e(n)])), [i, a, o, s, c, l, u] = n;
288
+ return (e) => (i(e) < e ? r.millisecond : a(e) < e ? r.second : o(e) < e ? r.minute : s(e) < e ? r.hour : l(e) < e ? c(e) < e ? r.day : r.week : u(e) < e ? r.month : r.year)(e);
289
+ }, pe = (e = "de") => {
290
+ let t = typeof e == "string" ? { base: e } : e, n = P[t.base ?? "de"];
291
+ if (!n) throw Error(`Unknown locale '${t.base}', expected one of ${fe.map((e) => `'${e}'`).join(", ")}`);
292
+ let r = m.formatLocale({
293
+ ...n.number,
294
+ ...t.number
295
+ }), i = m.timeFormatLocale({
296
+ ...n.time,
297
+ ...t.time
298
+ }), a = {
299
+ ...n.timeTicks,
300
+ ...t.timeTicks
301
+ };
302
+ return {
303
+ number: r,
304
+ time: i,
305
+ tickFormat(e, t, n = 10) {
306
+ if ([
307
+ "linear",
308
+ "pow",
309
+ "sqrt"
310
+ ].includes(t)) {
311
+ let [t, i] = e.domain(), a = m.precisionFixed(m.tickStep(t, i, n));
312
+ return r.format(`,.${Number.isFinite(a) ? a : 0}f`);
313
+ }
314
+ return t == "time" ? I(i.format, a, F.time) : t == "utc" ? I(i.utcFormat, a, F.utc) : null;
315
+ }
316
+ };
317
+ }, L = [
318
+ "svg:path",
319
+ "svg:circle",
320
+ "svg:line",
321
+ "svg:rect",
322
+ "svg:text",
323
+ "base:area",
324
+ "bar",
325
+ "stackedBar"
326
+ ], R = [
327
+ "numeric",
328
+ "date",
329
+ "categorical"
330
+ ], z = ["horizontal", "vertical"], B = [
331
+ "top",
332
+ "bottom",
333
+ "left",
334
+ "right"
335
+ ], V = [
336
+ "fixed",
337
+ "ref",
338
+ "relative",
339
+ "steps"
340
+ ], H = (e) => e.map((e) => `'${e}'`).join(", "), U = (e, t, n) => {
341
+ if (typeof e != "object" || !e || Array.isArray(e)) return;
342
+ if ("prop" in e) {
343
+ V.includes(e.prop) ? e.prop != "fixed" && typeof e.ref != "string" && n(t, `a '${e.prop}' prop needs a 'ref'`) : n(t, `unknown prop '${e.prop}', expected one of ${H(V)}`);
344
+ return;
345
+ }
346
+ let r = [
347
+ "ratio",
348
+ "steps",
349
+ "ref",
350
+ "mode"
351
+ ].filter((t) => t in e);
352
+ if (r.length > 0) return n(t, `has ${H(r)} but no 'prop', so it is not evaluated`);
353
+ Object.entries(e).forEach(([e, r]) => U(r, `${t}.${e}`, n));
354
+ }, me = (e) => {
355
+ let t = [], n = (e, n) => t.push(`${e}: ${n}`), r = e.mapping ?? {};
356
+ e.mapping || n("mapping", "missing"), Object.entries(r).forEach(([e, t]) => {
357
+ let r = `mapping.${e}`;
358
+ if (typeof t.column != "string" && n(r, "no 'column'"), t.type !== void 0 && !R.includes(t.type) && n(`${r}.type`, `unknown type '${t.type}', expected one of ${H(R)}`), t.props && !t.props.manual && n(`${r}.props`, "expected 'manual' (and optional 'common') entries"), t.scale) {
359
+ let e = t.scale.type ?? "linear", i = m[`scale${N(e)}`];
360
+ typeof i == "function" ? typeof i().ticks == "function" != ["numeric", "date"].includes(t.type) && n(`${r}.scale.type`, `a ${e} scale does not fit the type '${t.type}'`) : n(`${r}.scale.type`, `unknown d3 scale '${e}'`), t.scale.orientation !== void 0 && !z.includes(t.scale.orientation) && n(`${r}.scale.orientation`, `unknown orientation '${t.scale.orientation}', expected one of ${H(z)}`);
361
+ }
362
+ t.axis && (t.scale || n(`${r}.axis`, "an axis needs a 'scale'"), B.includes(t.axis.position) || n(`${r}.axis.position`, `unknown position '${t.axis.position}', expected one of ${H(B)}`), U(t.axis.ticks, `${r}.axis.ticks`, n));
363
+ });
364
+ let i = [].concat(e.plot ?? []);
365
+ if (i.length == 0 && n("plot", "missing"), i.forEach((e, t) => {
366
+ let i = `plot[${t}]`;
367
+ L.includes(e.type) || n(`${i}.type`, `unknown type '${e.type}', expected one of ${H(L)}`), (e.categories ?? []).filter((e) => !(e in r)).forEach((e) => n(`${i}.categories`, `unknown mapping '${e}'`)), U(e.props, `${i}.props`, n);
368
+ }), e.facets) {
369
+ let t = [].concat(e.facets.dim ?? []);
370
+ t.length != 1 && n("facets.dim", "expected the name of one mapping"), t.filter((e) => !(e in r)).forEach((e) => n("facets.dim", `unknown mapping '${e}'`));
371
+ }
372
+ let a = (t, r) => j(t).filter((t) => !(t in (e.globals ?? {}))).forEach((e) => n(r, `unknown global '${e}' in the column template`));
373
+ return Object.entries(r).forEach(([e, t]) => a(t.column, `mapping.${e}.column`)), (e.formElements ?? []).forEach((e, t) => (e.values ?? []).forEach((e, n) => Object.entries(e.mapping ?? {}).forEach(([e, r]) => a(r.column, `formElements[${t}].values[${n}].mapping.${e}.column`)))), U(e.options?.height, "options.height", n), U(e.facets?.cols, "facets.cols", n), t;
374
+ }, W = (e, t = document.baseURI) => new URL(e, t).href, G = async (e) => {
375
+ try {
376
+ return await m.text(e);
377
+ } catch (t) {
378
+ throw Error(`Could not load '${e}': ${t.message}`);
379
+ }
380
+ }, K = (e, t) => {
381
+ try {
382
+ return JSON.parse(e);
383
+ } catch (e) {
384
+ throw Error(`Invalid JSON in definition ${t}: ${e.message}`);
385
+ }
386
+ }, he = async (e, t, n = G) => {
387
+ let r = [e], i = /* @__PURE__ */ new Set();
388
+ for (; e.parent;) {
389
+ if (t = W(e.parent, t), i.has(t)) throw Error(`Cyclic parent definition '${t}'`);
390
+ i.add(t), e = K(await n(t), `'${t}'`), r.unshift(e);
391
+ }
392
+ return x(r);
393
+ }, q = (e) => o(Array.from(ee(e))), ge = async ({ def: e = null, defUrl: t = null, data: n = null }) => {
394
+ let r;
395
+ e === null ? (r = W(t), e = K(await G(r), `'${r}'`)) : typeof e == "string" && (e = K(e, "attribute"));
396
+ let i = await he(JSON.parse(JSON.stringify(e)), r);
397
+ me(i).forEach((e) => console.warn(`gen-vis ${r ?? "inline definition"}: ${e}`));
398
+ let a = ue(JSON.parse(JSON.stringify(i)));
399
+ if (M(a, i), n === null) {
400
+ if (!i.data) throw Error("No data given, neither in the definition nor as attribute.");
401
+ n = await G(W(i.data, r));
402
+ }
403
+ let s = q(g(n));
404
+ return {
405
+ defUrl: r ?? null,
406
+ defOrg: i,
407
+ locale: o(pe(i.options?.locale)),
408
+ rows: s,
409
+ def: a,
410
+ data: q(ne(s, a))
411
+ };
412
+ }, _e = class {
413
+ defUrl = null;
414
+ defOrg = null;
415
+ locale = null;
416
+ def = null;
417
+ rows = null;
418
+ data = null;
419
+ runs = 0;
420
+ get loaded() {
421
+ return this.def !== null && this.data !== null;
422
+ }
423
+ get axis() {
424
+ let e = {};
425
+ return this.mappingNamesWithKey("scale").forEach((t) => {
426
+ let n = this.mapping(t).scale.orientation;
427
+ n == "horizontal" && (e.h = t), n == "vertical" && (e.v = t);
428
+ }), e;
429
+ }
430
+ formatter(e) {
431
+ return e == "time" ? this.locale.time.format : e == "utc" ? this.locale.time.utcFormat : this.locale.number.format;
432
+ }
433
+ mapping(e) {
434
+ return this.def.mapping[e];
435
+ }
436
+ prop(e, t) {
437
+ return this.def.mapping[e].props[t];
438
+ }
439
+ mappingNamesWithKey(e) {
440
+ return Object.keys(this.def.mapping).filter((t) => e in this.def.mapping[t]);
441
+ }
442
+ async init(e) {
443
+ let t = ++this.runs;
444
+ this.def = this.data = null;
445
+ try {
446
+ let n = await ge(e);
447
+ t == this.runs && Object.assign(this, n);
448
+ } catch (e) {
449
+ if (t == this.runs) throw e;
450
+ }
451
+ }
452
+ applyFormElements() {
453
+ M(this.def, this.defOrg) && (this.data = q(ne(this.rows, this.def)));
454
+ }
455
+ }, ve = () => u(new _e()), J = (e, t) => {
456
+ let n = e.mapping.scale, r = m[`scale${N(n.type)}`]();
457
+ if (r.range(T(n.range, t)), e.extent) {
458
+ e.domain = [...n.domain], e.domainRel = [...n.domainRel ? n.domainRel : [0, 0]], e.domainAbs = n.domainAbs, e.domain[0] ??= e.extent[0], e.domain[1] ??= e.extent[1];
459
+ let t = e.domain[1] - e.domain[0];
460
+ e.domain[0] += t * e.domainRel[0], e.domain[1] += t * e.domainRel[1], e.domain[0] += e.domainAbs[0], e.domain[1] += e.domainAbs[1], r.invertCustom = (t) => e.values[m.bisectCenter(e.values, r.invert(t))];
461
+ } else e.domain = e.values, n.padding ??= .4, r.padding(n.padding), r.invertCustom = (e) => {
462
+ let t = Math.floor(e / r.step());
463
+ return r.domain()[Math.max(0, Math.min(t, r.domain().length - 1))];
464
+ };
465
+ r.domain(e.domain), e.scale = r;
466
+ }, Y = function(e) {
467
+ let t = m.select(this);
468
+ Object.entries(e).forEach(([e, n], r) => {
469
+ if (n instanceof Object) {
470
+ if (!D(n)) return;
471
+ n = n.value;
472
+ }
473
+ if (e == "text") {
474
+ t.text(n);
475
+ return;
476
+ }
477
+ t.attr(e, n);
478
+ });
479
+ }, ye = function(e) {
480
+ let t = m.select(this);
481
+ e.group.forEach((e) => {
482
+ t.attr(`data-group-${e.dim}`, e.key);
483
+ }), e.group.forEach((e) => {
484
+ t.attr(`data-visible-${e.dim}`, e.visible);
485
+ }), t.attr("data-visible", e.group.reduce((e, t) => e && t.visible, !0));
486
+ }, be = (e, t, n) => {
487
+ let r = t.categories.filter((e) => e in n).map((e) => ({
488
+ attr: `data-group-${e}`,
489
+ value: String(n[e])
490
+ }));
491
+ return r.length == 0 ? null : e.selectAll(`g.plotGroup.${t.id} [${r[0].attr}]`).filter(function() {
492
+ return r.every((e) => this.getAttribute(e.attr) === e.value);
493
+ });
494
+ }, X = (e, t, n = null) => {
495
+ t.filter((e) => e.highlightProps.length > 0).forEach((t) => {
496
+ e.selectAll(`g.plotGroup.${t.id} .highlight`).classed("highlight", !1).each(function() {
497
+ let e = m.select(this);
498
+ t.highlightProps.forEach((t) => e.attr(t, e.attr(`default-${t}`)));
499
+ });
500
+ let r = n && be(e, t, n);
501
+ r && r.classed("highlight", !0).raise().each(function() {
502
+ let e = m.select(this);
503
+ t.highlightProps.forEach((t) => {
504
+ e.attr(`default-${t}`, e.attr(t)).attr(t, e.attr(`highlight-${t}`));
505
+ });
506
+ });
507
+ });
508
+ }, Z = (e, t) => {
509
+ let n = e.__vccOpts || e;
510
+ for (let [e, r] of t) n[e] = r;
511
+ return n;
512
+ }, xe = {
513
+ props: [
514
+ "title",
515
+ "axis",
516
+ "side",
517
+ "data"
518
+ ],
519
+ data: () => ({ space: 20 }),
520
+ computed: {
521
+ left() {
522
+ return this.side == "left" ? `${this.axis.h.value - this.space}px` : `${this.axis.h.value + this.space}px`;
523
+ },
524
+ transform() {
525
+ return this.side == "left" ? "translate(-100%, -50%)" : "translate(0, -50%)";
526
+ }
527
+ },
528
+ mounted() {
529
+ this.render();
530
+ },
531
+ watch: { data: "render" },
532
+ methods: { render() {
533
+ if (!this.$refs.entries || !this.data) return;
534
+ let e = [...this.data].sort((e, t) => t.entries[this.axis.v.col].value - e.entries[this.axis.v.col].value), t = m.select(this.$refs.entries).selectAll("tr.entry").data(e).join("tr").attr("class", "entry").classed("nearest", (e) => e.nearest);
535
+ t.selectAll("td").remove(), t.selectAll("td").data((e) => Object.entries(e.entries)).join("td").attr("class", (e) => e[0]).html((e) => typeof e[1] == "object" ? e[1].name : e[1]);
536
+ } }
537
+ }, Se = { class: "title" }, Ce = {
538
+ class: "entries",
539
+ ref: "entries"
540
+ };
541
+ function we(e, t, n, o, s, u) {
542
+ return n.axis && n.axis.h ? (l(), i("div", {
543
+ key: 0,
544
+ class: "hover",
545
+ ref: "hover",
546
+ style: c({
547
+ left: u.left,
548
+ transform: u.transform
549
+ })
550
+ }, [a("div", Se, p(n.axis.h.name), 1), a("table", Ce, null, 512)], 4)) : r("", !0);
551
+ }
552
+ var Te = /*#__PURE__*/ Z(xe, [["render", we], ["__scopeId", "data-v-364032d4"]]), Ee = (...e) => e.every((e) => Number.isFinite(e)), De = {
553
+ props: [
554
+ "filter",
555
+ "shared",
556
+ "height",
557
+ "width",
558
+ "margins",
559
+ "data"
560
+ ],
561
+ inject: ["store"],
562
+ data: () => ({
563
+ info: {},
564
+ debug: null,
565
+ def: null,
566
+ hover: { visible: !1 }
567
+ }),
568
+ computed: {
569
+ innerWidth() {
570
+ return this.width - (this.margins.left + this.margins.right);
571
+ },
572
+ innerHeight() {
573
+ return this.height - (this.margins.top + this.margins.bottom);
574
+ },
575
+ relativeBases() {
576
+ return {
577
+ width: this.width,
578
+ innerWidth: this.innerWidth,
579
+ height: this.height,
580
+ innerHeight: this.innerHeight
581
+ };
582
+ }
583
+ },
584
+ components: { Hover: Te },
585
+ created() {
586
+ this.def = this.store.def;
587
+ },
588
+ mounted() {
589
+ this.inner = m.select(this.$refs.inner), this.scales(), this.axis(), this.plot(), this.hoverInit();
590
+ },
591
+ unmounted() {
592
+ document.removeEventListener("pointerdown", this.hideOnPointerOutside);
593
+ },
594
+ methods: {
595
+ plot() {
596
+ this.def.plot.forEach((e) => {
597
+ let t = ce(y(this.data, e.categories), e, this.relativeBases, this.def.mapping), n = this.inner.append("g").classed("plotGroup", !0).classed(e.id, !0);
598
+ this[e.type](t, n);
599
+ });
600
+ },
601
+ _groupwise: function(e, t) {
602
+ return t.classed("paths", !0).selectAll("path").data(e).enter().append("path").each(function(e) {
603
+ Y.call(this, e.props);
604
+ }).each(ye);
605
+ },
606
+ _pointwise(e, t, n, r = (e) => e) {
607
+ return t.classed(n, !0).selectAll("g.group").data(e).enter().append("g").attr("class", "group").each(ye).selectAll(n).data((e) => {
608
+ let t = O(e.props);
609
+ return e.values.filter((e) => t.every((t) => e[t] !== null)).map((t) => r(E(e.props, t)));
610
+ }).enter().append(n).each(Y);
611
+ },
612
+ "svg:path": function(e, t) {
613
+ this._groupwise(e, t).attr("d", (e) => m.line().defined((e) => Ee(e.x, e.y)).x((e) => e.x).y((e) => e.y)(e.values.map((t) => E(e.props.d, t, !0))));
614
+ },
615
+ "svg:circle": function(e, t) {
616
+ this._pointwise(e, t, "circle");
617
+ },
618
+ "svg:line": function(e, t) {
619
+ this._pointwise(e, t, "line");
620
+ },
621
+ "svg:rect": function(e, t) {
622
+ this._pointwise(e, t, "rect");
623
+ },
624
+ "svg:text": function(e, t) {
625
+ this._pointwise(e, t, "text");
626
+ },
627
+ "base:area": function(e, t) {
628
+ this._groupwise(e, t).attr("d", (e) => m.area().defined((e) => Ee(e.x, e.y0, e.y1)).x((e) => e.x).y1((e) => e.y1).y0((e) => e.y0)(e.values.map((t) => E(e.props.d, t, !0))));
629
+ },
630
+ bar(e, t) {
631
+ let n = this;
632
+ this._pointwise(e, t, "rect", (e) => {
633
+ let t = e.height.parts[0], r = n.info[t].scale(0);
634
+ if (e.width === void 0) {
635
+ let t = e.cx.parts[0];
636
+ e.width = k(n.info[t].scale.step() * (1 - n.info[t].scale.padding()));
637
+ }
638
+ return e.x = k(e.cx.value - e.width.value / 2), delete e.cx, e.y = k(e.height.value), e.height = k(r - e.height.value), e;
639
+ });
640
+ },
641
+ stackedBar(e, t) {
642
+ e.forEach((e) => {
643
+ let t = e.props.x.ref, n = e.props.y.ref;
644
+ e.props.x = k(`@${t}:scaled`), e.props.y = k(`@${n}:st:e:scaled`), e.props.height = k(`@${n}:st:h:scaled`), e.props.transform = k(`translate(-${e.props.width.value / 2} 0)`);
645
+ }), this._pointwise(e, t, "rect", (e) => (e.height.value < 0 && (e.y.value += e.height.value, e.height.value = -e.height.value), e));
646
+ },
647
+ scales() {
648
+ let e = {};
649
+ this.store.mappingNamesWithKey("scale").filter((e) => !Object.keys(this.shared).includes(e)).forEach((t) => {
650
+ let n = {
651
+ dim: t,
652
+ mapping: this.store.mapping(t)
653
+ };
654
+ re(n, this.data), J(n, {
655
+ width: this.innerWidth,
656
+ height: this.innerHeight
657
+ }), e[t] = n;
658
+ }), v(this.data, e), this.info = {
659
+ ...this.shared,
660
+ ...e
661
+ };
662
+ },
663
+ axis() {
664
+ this.store.mappingNamesWithKey("axis").forEach((e) => {
665
+ let t = this.store.mapping(e), n = t.axis, r = this.info[e].scale, i = w(n.ticks, this.relativeBases), a = m[`axis${N(n.position)}`](r).tickSizeInner(9).tickSizeOuter(0).ticks(i).tickPadding(n.padding);
666
+ if (n.format) a.tickFormat(this.store.formatter(t.scale.type)(n.format));
667
+ else if (!n.values) {
668
+ let e = this.store.locale.tickFormat(r, t.scale.type, i);
669
+ e && a.tickFormat(e);
670
+ }
671
+ if (n.values && a.tickValues(n.values), n.grid) {
672
+ let e = n.values ?? (r.ticks ? r.ticks(i) : r.domain());
673
+ this.grid(r, e, ["left", "right"].includes(n.position));
674
+ }
675
+ let o = this.inner.append("g").attr("class", `axis-name-${e} axis-position-${n.position}`).call(a);
676
+ if (n.position == "bottom" && o.attr("transform", `translate(0, ${this.innerHeight})`), n.position == "right" && o.attr("transform", `translate(${this.innerWidth}, 0)`), n.rotate && o.selectAll("text").attr("text-anchor", n.rotate > 0 ? "end" : "start").attr("transform", `rotate(${-n.rotate})`), n.title) {
677
+ let e = this.inner.append("text").attr("class", "axis-title").attr("y", 0).attr("x", 0).attr("text-anchor", "middle").attr("dominant-baseline", "middle").text(n.title.name);
678
+ n.position == "left" && e.attr("transform", `rotate(-90) translate(-${this.innerHeight / 2} -${n.title.offset})`), n.position == "right" && e.attr("transform", `rotate(90) translate(${this.innerHeight / 2} -${this.innerWidth + n.title.offset})`), n.position == "top" && e.attr("transform", `translate(${this.innerWidth / 2} -${n.title.offset})`), n.position == "bottom" && e.attr("transform", `translate(${this.innerWidth / 2} ${this.innerHeight + n.title.offset})`);
679
+ }
680
+ });
681
+ },
682
+ grid(e, t, n) {
683
+ let r = e.bandwidth ? e.bandwidth() / 2 : 0, i = this.inner.append("g").attr("class", "grid").selectAll("line").data(t).enter().append("line");
684
+ n ? i.attr("x1", 0).attr("x2", this.innerWidth).attr("y1", (t) => e(t) + r).attr("y2", (t) => e(t) + r) : i.attr("y1", 0).attr("y2", this.innerHeight).attr("x1", (t) => e(t) + r).attr("x2", (t) => e(t) + r);
685
+ },
686
+ hoverInit() {
687
+ let e = this, t = this.store.axis;
688
+ if (!t.h || !t.v) return;
689
+ let n = Object.fromEntries(Object.entries(t).map(([e, t]) => {
690
+ let n = this.def.mapping[t], r = n.hover?.format ?? n.axis?.format ?? (["time", "utc"].includes(n.scale.type) ? "%x" : "c");
691
+ return [e, {
692
+ axis: e,
693
+ name: t,
694
+ formatter: this.store.formatter(n.scale.type)(r)
695
+ }];
696
+ })), r = this.store.mappingNamesWithKey("hover").filter((e) => e != t.h && e != t.v && this.store.mapping(e).props), i = m.select(this.$refs.hoverMarker).select("line"), a = () => {
697
+ e.hover.visible = !1, X(e.inner, e.def.plot);
698
+ };
699
+ this.hideOnPointerOutside = (t) => {
700
+ e.hover.visible && !e.$refs.svg.contains(t.target) && a();
701
+ }, document.addEventListener("pointerdown", this.hideOnPointerOutside), this.inner.append("rect").attr("class", "events").attr("width", this.innerWidth).attr("height", this.innerHeight).attr("opacity", 0).style("touch-action", "pan-y").on("pointerdown pointermove", function(t) {
702
+ e.hover.visible = !0;
703
+ let a = m.pointer(t), o = e.info[n.h.name], s = o.scale.invertCustom(a[0]);
704
+ if (s === void 0) return;
705
+ let c = o.scale(s);
706
+ i.attr("x1", c).attr("x2", c).attr("y1", 0).attr("y2", e.innerHeight);
707
+ let l = b(e.data, [{
708
+ dim: n.h.name,
709
+ key: s
710
+ }]).filter((e) => e[n.v.name] !== null).map((t) => {
711
+ let i = {
712
+ entries: {},
713
+ data: t,
714
+ nearest: !1
715
+ };
716
+ return r.forEach((n) => {
717
+ i.entries[n] = T(e.store.mapping(n).hover.props, e.store.prop(n, t[n]));
718
+ }), i.entries[n.v.name] = {
719
+ value: t[n.v.name],
720
+ name: n.v.formatter(t[n.v.name])
721
+ }, i;
722
+ }), u = e.info[n.v.name].scale.invert(a[1]), d = n.v.name, f;
723
+ f = e.store.mapping(d).stacked ? m.least(l, (e) => {
724
+ let [t, n] = m.extent([e.data[`${d}:st:s`], e.data[`${d}:st:e`]]);
725
+ return u < t ? t - u : u > n ? u - n : 0;
726
+ }) : m.least(l, (e) => Math.abs(e.data[d] - u)), f && (f.nearest = !0), X(e.inner, e.def.plot, f?.data), e.hover.data = l, e.hover.axis = {
727
+ h: {
728
+ col: n.h.name,
729
+ value: c,
730
+ name: n.h.formatter(s)
731
+ },
732
+ v: {
733
+ col: n.v.name,
734
+ value: u
735
+ }
736
+ }, e.hover.side = c > e.innerWidth / 2 ? "left" : "right";
737
+ }).on("pointerleave", (e) => {
738
+ e.pointerType != "touch" && a();
739
+ }).on("pointercancel", a);
740
+ }
741
+ }
742
+ }, Oe = ["width", "height"], ke = ["transform"], Ae = ["visibility"], je = {
743
+ key: 0,
744
+ class: "debug"
745
+ };
746
+ function Me(e, t, o, s, u, d) {
747
+ let ee = f("hover");
748
+ return l(), i("div", {
749
+ style: c(`width: ${o.width}px;`),
750
+ class: "vis-inner"
751
+ }, [
752
+ (l(), i("svg", {
753
+ ref: "svg",
754
+ width: o.width,
755
+ height: o.height,
756
+ class: "facet"
757
+ }, [a("g", {
758
+ ref: "inner",
759
+ transform: `translate(${o.margins.left} ${o.margins.top})`
760
+ }, [a("g", {
761
+ visibility: e.hover.visible ? "visible" : "hidden",
762
+ class: "hoverMarker",
763
+ ref: "hoverMarker"
764
+ }, [...t[0] ||= [a("line", null, null, -1)]], 8, Ae)], 8, ke)], 8, Oe)),
765
+ a("div", { style: c(`transform: translate(${o.margins.left}px, ${o.margins.top + d.innerHeight / 2}px); position: absolute; top: 0; left: 0;`) }, [e.hover.visible ? (l(), n(ee, {
766
+ key: 0,
767
+ data: e.hover.data,
768
+ side: e.hover.side,
769
+ axis: e.hover.axis
770
+ }, null, 8, [
771
+ "data",
772
+ "side",
773
+ "axis"
774
+ ])) : r("", !0)], 4),
775
+ e.debug ? (l(), i("span", je, p(e.debug), 1)) : r("", !0)
776
+ ], 4);
777
+ }
778
+ var Ne = /*#__PURE__*/ Z(De, [["render", Me], ["__scopeId", "data-v-1f05a06e"]]), Pe = {
779
+ props: ["info", "props"],
780
+ mounted() {
781
+ let e = m.select(this.$refs.legendSymbol);
782
+ this.info.elements.forEach((t) => {
783
+ let n = e.append(t.type);
784
+ Y.call(n.node(), T(t.props, this.props));
785
+ });
786
+ }
787
+ }, Fe = ["width", "height"];
788
+ function Ie(e, t, n, r, a, o) {
789
+ return l(), i("svg", {
790
+ width: n.info.size,
791
+ height: n.info.size,
792
+ ref: "legendSymbol"
793
+ }, null, 8, Fe);
794
+ }
795
+ //#endregion
796
+ //#region src/comp/Legend.vue
797
+ var Le = {
798
+ props: ["legend"],
799
+ inject: ["store"],
800
+ data: () => ({
801
+ info: {},
802
+ entries: []
803
+ }),
804
+ components: { LegendSymbol: /* @__PURE__ */ Z(Pe, [["render", Ie], ["__scopeId", "data-v-ce0e972e"]]) },
805
+ mounted() {
806
+ this.info = this.store.mapping(this.legend), this.entries = Object.keys(this.info.props).map((e) => ({
807
+ key: e,
808
+ props: this.info.props[e],
809
+ filled: T(this.info.legend.props, this.info.props[e])
810
+ }));
811
+ },
812
+ methods: { switched(e) {
813
+ e.props.visible = !e.props.visible, this.$emit("changeSelected", {
814
+ dim: this.legend,
815
+ key: e.key,
816
+ selected: e.props.visible
817
+ });
818
+ } }
819
+ }, Re = ["data-dim"], ze = { class: "title" }, Be = { class: "entries" }, Ve = [
820
+ "data-visible",
821
+ "data-key",
822
+ "onClick",
823
+ "onMouseenter"
824
+ ], He = ["innerHTML"];
825
+ function Ue(t, o, c, u, ee, m) {
826
+ let h = f("LegendSymbol");
827
+ return l(), i("div", {
828
+ class: "legend",
829
+ "data-dim": c.legend
830
+ }, [a("div", ze, p(t.info.name), 1), a("div", Be, [(l(!0), i(e, null, d(t.entries, (e) => (l(), i("div", s({
831
+ "data-visible": e.props.visible,
832
+ "data-key": e.key
833
+ }, { ref_for: !0 }, Object.assign({ ...e.filled }, { name: null }), {
834
+ onClick: (t) => m.switched(e),
835
+ onMouseenter: (n) => t.$emit("highlight", {
836
+ dim: this.legend,
837
+ key: e.key
838
+ }),
839
+ onMouseleave: o[0] ||= (e) => t.$emit("highlight", {})
840
+ }), [t.info.legend.symbol ? (l(), n(h, {
841
+ key: 0,
842
+ info: t.info.legend.symbol,
843
+ props: e.props
844
+ }, null, 8, ["info", "props"])) : r("", !0), a("span", { innerHTML: e.filled.name }, null, 8, He)], 16, Ve))), 256))])], 8, Re);
845
+ }
846
+ var We = /*#__PURE__*/ Z(Le, [["render", Ue], ["__scopeId", "data-v-1bc8d55f"]]), Ge = {
847
+ props: ["element", "globals"],
848
+ computed: { vg() {
849
+ return this.globals[this.element.ref];
850
+ } },
851
+ methods: {
852
+ switched(e) {
853
+ this.globals[this.element.ref] = e.value, this.$emit("changeSelected", {});
854
+ },
855
+ equal(e) {
856
+ return S(e, this.vg);
857
+ }
858
+ }
859
+ }, Ke = ["id"], qe = { class: "title" }, Je = {
860
+ key: 0,
861
+ class: "entries"
862
+ }, Ye = ["id", "onClick"], Xe = [
863
+ "name",
864
+ "value",
865
+ "checked"
866
+ ], Ze = ["for"];
867
+ function Qe(t, n, o, s, c, u) {
868
+ return l(), i("div", {
869
+ class: "formElement",
870
+ id: `container-${o.element.id}`
871
+ }, [a("div", qe, p(o.element.name) + ":", 1), o.element.type == "switch" ? (l(), i("div", Je, [(l(!0), i(e, null, d(o.element.values, (e) => (l(), i("div", {
872
+ id: `container-${e.id}`,
873
+ onClick: (t) => u.switched(e)
874
+ }, [a("input", {
875
+ type: "radio",
876
+ name: o.element.id,
877
+ value: e.id,
878
+ checked: u.equal(e.value)
879
+ }, null, 8, Xe), a("label", { for: e.id }, p(e.name), 9, Ze)], 8, Ye))), 256))])) : r("", !0)], 8, Ke);
880
+ }
881
+ //#endregion
882
+ //#region src/comp/Vis.vue
883
+ var $e = {
884
+ inject: ["store"],
885
+ data: () => ({
886
+ initialized: !1,
887
+ options: {},
888
+ globals: {},
889
+ legends: [],
890
+ formElements: [],
891
+ filter: [],
892
+ data: [],
893
+ facets: {
894
+ shared: {},
895
+ entries: [],
896
+ height: 0,
897
+ width: 0,
898
+ margins: {
899
+ top: 0,
900
+ right: 0,
901
+ bottom: 0,
902
+ left: 0
903
+ }
904
+ }
905
+ }),
906
+ computed: {
907
+ innerWidth() {
908
+ return this.options.width - (this.options.margins.left + this.options.margins.right);
909
+ },
910
+ innerHeight() {
911
+ return this.options.height - (this.options.margins.top + this.options.margins.bottom);
912
+ }
913
+ },
914
+ components: {
915
+ Facet: Ne,
916
+ LegendEntry: We,
917
+ FormElement: /* @__PURE__ */ Z(Ge, [["render", Qe], ["__scopeId", "data-v-ec3facd5"]])
918
+ },
919
+ mounted() {
920
+ this.baseInit(), this.dataInit(), this.scales(), this.store.def.options.width || (this.resizeObserver = new ResizeObserver(() => {
921
+ clearTimeout(this.resizeTimeout), this.resizeTimeout = setTimeout(this.resized, 100);
922
+ }), this.resizeObserver.observe(this.$refs.vis));
923
+ },
924
+ unmounted() {
925
+ this.resizeObserver?.disconnect(), clearTimeout(this.resizeTimeout);
926
+ },
927
+ methods: {
928
+ baseInit() {
929
+ this.legends = this.store.mappingNamesWithKey("legend"), this.formElements = this.store.def.formElements, this.globals = this.store.def.globals, this.options = Object.assign({}, this.store.def.options), this.measure();
930
+ },
931
+ measure() {
932
+ let e = this.store.def.options;
933
+ this.options.width = e.width || this.$refs.vis.getBoundingClientRect().width, this.options.height = w(e.height, { totalWidth: this.options.width });
934
+ },
935
+ resized() {
936
+ let e = this.$refs.vis?.getBoundingClientRect().width;
937
+ e && e != this.options.width && (this.measure(), this.dataInit(), this.scales());
938
+ },
939
+ dataInit() {
940
+ let e = this.store.def, t = this.store.axis;
941
+ if (this.filter = this.store.mappingNamesWithKey("props").map((e) => ({
942
+ dim: e,
943
+ key: Object.keys(this.store.mapping(e).props).filter((t) => this.store.mapping(e).props[t].visible)
944
+ })), this.data = o(b(this.store.data, this.filter)), t.v && this.store.mapping(t.v).stacked) {
945
+ let n = ie(this.filter.map((e) => ({
946
+ dim: e.dim,
947
+ keys: e.key
948
+ })));
949
+ ae(this.data, t, e.facets ? [e.facets.dim] : [], n);
950
+ }
951
+ if (e.facets) {
952
+ this.facets.margins = this.options.margins, this.facets.height = this.options.height;
953
+ let t = w(e.facets.cols, { totalWidth: this.options.width });
954
+ this.facets.width = this.options.width / t;
955
+ let n = e.facets.dim, r = Object.keys(this.store.mapping(n).props), i = y(this.data, [n]);
956
+ this.facets.entries = i.filter((e) => r.includes(e.group[n])).sort((e, t) => r.indexOf(e.group[n]) - r.indexOf(t.group[n])).map((e) => ({
957
+ filter: {
958
+ dim: e.group[n],
959
+ key: n,
960
+ name: this.store.mapping(n).props[e.group[n]].name
961
+ },
962
+ data: o(e.entries)
963
+ }));
964
+ }
965
+ },
966
+ scales() {
967
+ let e = this.store.def;
968
+ if (e.facets && e.facets.scales) {
969
+ let t = w(e.facets.scales, e.globals).map((e) => {
970
+ let t = {
971
+ dim: e,
972
+ mapping: this.store.mapping(e)
973
+ };
974
+ return re(t, this.data), J(t, {
975
+ width: this.facets.width - (this.facets.margins.left + this.facets.margins.right),
976
+ height: this.facets.height - (this.facets.margins.top + this.facets.margins.bottom)
977
+ }), t;
978
+ });
979
+ v(this.data, t), this.facets.shared = Object.fromEntries(t.map((e) => [e.dim, e]));
980
+ }
981
+ this.initialized = !0;
982
+ },
983
+ changeSelected(e) {
984
+ this.dataInit(), this.scales();
985
+ },
986
+ formChanged(e) {
987
+ this.store.applyFormElements(), this.changeSelected(e);
988
+ },
989
+ highlight(e) {
990
+ X(m.select(this.$refs.vis), this.store.def.plot, { [e.dim]: e.key });
991
+ }
992
+ }
993
+ }, et = { class: "vis-header" }, tt = { class: "title" }, nt = { class: "subtitle" }, rt = {
994
+ ref: "form",
995
+ class: "vis-form-elements"
996
+ }, it = {
997
+ ref: "legends",
998
+ class: "vis-legends"
999
+ }, at = {
1000
+ key: 0,
1001
+ class: "vis-body"
1002
+ }, ot = { class: "vis-footer" }, st = ["innerHTML"];
1003
+ function ct(t, o, s, u, ee, m) {
1004
+ let h = f("form-element"), g = f("legend-entry"), _ = f("facet");
1005
+ return l(), i("div", {
1006
+ class: "vis",
1007
+ ref: "vis",
1008
+ style: c({ "--gen-vis-font-family": t.options.fontFamily })
1009
+ }, [
1010
+ a("div", et, [a("div", tt, p(t.options.title), 1), a("div", nt, p(t.options.subtitle), 1)]),
1011
+ a("div", rt, [(l(!0), i(e, null, d(t.formElements, (e) => (l(), n(h, {
1012
+ element: e,
1013
+ globals: t.globals,
1014
+ onChangeSelected: m.formChanged
1015
+ }, null, 8, [
1016
+ "element",
1017
+ "globals",
1018
+ "onChangeSelected"
1019
+ ]))), 256))], 512),
1020
+ a("div", it, [(l(!0), i(e, null, d(t.legends, (e) => (l(), n(g, {
1021
+ legend: e,
1022
+ onChangeSelected: m.changeSelected,
1023
+ onHighlight: m.highlight
1024
+ }, null, 8, [
1025
+ "legend",
1026
+ "onChangeSelected",
1027
+ "onHighlight"
1028
+ ]))), 256))], 512),
1029
+ t.initialized ? (l(), i("div", at, [t.facets.entries.length > 0 ? (l(!0), i(e, { key: 0 }, d(t.facets.entries, (e) => (l(), i("div", { style: c(`width: ${t.facets.width}px; display: inline-block;`) }, [a("div", {
1030
+ class: "facet-title",
1031
+ style: c(`margin-left: ${t.facets.margins.left}px`)
1032
+ }, p(e.filter.name), 5), (l(), n(_, {
1033
+ key: e.data,
1034
+ data: e.data,
1035
+ shared: t.facets.shared,
1036
+ height: t.facets.height,
1037
+ width: t.facets.width,
1038
+ margins: t.facets.margins
1039
+ }, null, 8, [
1040
+ "data",
1041
+ "shared",
1042
+ "height",
1043
+ "width",
1044
+ "margins"
1045
+ ]))], 4))), 256)) : (l(), n(_, {
1046
+ key: t.data,
1047
+ data: t.data,
1048
+ shared: {},
1049
+ height: t.options.height,
1050
+ width: t.options.width,
1051
+ margins: t.options.margins
1052
+ }, null, 8, [
1053
+ "data",
1054
+ "height",
1055
+ "width",
1056
+ "margins"
1057
+ ]))])) : r("", !0),
1058
+ a("div", ot, [a("span", { innerHTML: t.options.footer }, null, 8, st)])
1059
+ ], 4);
1060
+ }
1061
+ //#endregion
1062
+ //#region src/comp/App.vue
1063
+ var lt = {
1064
+ name: "GenVis",
1065
+ props: {
1066
+ debug: {
1067
+ type: Boolean,
1068
+ default: !1
1069
+ },
1070
+ defFile: {
1071
+ type: String,
1072
+ default: null
1073
+ },
1074
+ def: {
1075
+ type: [Object, String],
1076
+ default: null
1077
+ },
1078
+ data: {
1079
+ type: [Array, String],
1080
+ default: null
1081
+ }
1082
+ },
1083
+ data: () => ({
1084
+ store: ve(),
1085
+ error: null
1086
+ }),
1087
+ provide() {
1088
+ return { store: this.store };
1089
+ },
1090
+ components: { VisBase: /* @__PURE__ */ Z($e, [["render", ct], ["__scopeId", "data-v-b07c17d2"]]) },
1091
+ watch: {
1092
+ def: "init",
1093
+ defFile: "init",
1094
+ data: "init"
1095
+ },
1096
+ mounted() {
1097
+ this.init();
1098
+ },
1099
+ errorCaptured(e) {
1100
+ return this.showError(e), !1;
1101
+ },
1102
+ methods: {
1103
+ async init() {
1104
+ if (this.error = null, this.def === null && this.defFile === null) return this.showError(/* @__PURE__ */ Error("No definition given."));
1105
+ try {
1106
+ await this.store.init({
1107
+ def: this.def,
1108
+ defUrl: this.defFile,
1109
+ data: this.data
1110
+ });
1111
+ } catch (e) {
1112
+ this.showError(e);
1113
+ }
1114
+ },
1115
+ showError(e) {
1116
+ console.error(e), this.error = e.message;
1117
+ }
1118
+ }
1119
+ }, ut = { class: "vis-outer" }, dt = {
1120
+ key: 0,
1121
+ class: "vis-error"
1122
+ }, ft = { key: 2 }, pt = { style: {
1123
+ height: "500px",
1124
+ overflow: "auto",
1125
+ "font-size": "11px"
1126
+ } }, mt = { style: {
1127
+ height: "500px",
1128
+ overflow: "auto",
1129
+ "font-size": "11px"
1130
+ } };
1131
+ function ht(e, t, o, s, c, u) {
1132
+ let d = f("vis-base");
1133
+ return l(), i("div", ut, [e.error ? (l(), i("div", dt, p(e.error), 1)) : e.store.loaded ? (l(), n(d, { key: 1 })) : r("", !0), o.debug && e.store.def ? (l(), i("div", ft, [
1134
+ t[0] ||= a("h3", null, "prepared:", -1),
1135
+ a("pre", pt, p(JSON.stringify(e.store.def, null, 4)), 1),
1136
+ t[1] ||= a("h3", null, "org:", -1),
1137
+ a("pre", mt, p(JSON.stringify(e.store.defOrg, null, 4)), 1)
1138
+ ])) : r("", !0)]);
1139
+ }
1140
+ var Q = /*#__PURE__*/ Z(lt, [["render", ht], ["__scopeId", "data-v-a9d47434"]]), gt = { install(e) {
1141
+ e.component("GenVis", Q);
1142
+ } }, $ = (e) => {
1143
+ let n = Object.fromEntries(e.getAttributeNames().filter((e) => e.startsWith("data-")).map((t) => [t.substring(5), e.getAttribute(t)]));
1144
+ return t(Q, n).mount(e);
1145
+ }, _t = (e) => {
1146
+ for (let t of document.getElementsByClassName(e)) t.classList.contains("gen-vis-attached") || (t.classList.add("gen-vis-attached"), $(t));
1147
+ };
1148
+ //#endregion
1149
+ export { Q as GenVis, gt as default, _t as mountGenVisByClass, $ as mountGenVisElement };