phoria2 1.0.0 → 1.2.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.
Files changed (76) hide show
  1. package/README.md +71 -13
  2. package/dist/bloom.js +1 -1
  3. package/dist/charts.js +397 -384
  4. package/dist/charts.js.map +1 -1
  5. package/dist/core.js +4451 -3568
  6. package/dist/core.js.map +1 -1
  7. package/dist/edit.js +67 -67
  8. package/dist/edit.js.map +1 -1
  9. package/dist/explain.js +6 -2
  10. package/dist/explain.js.map +1 -1
  11. package/dist/gltf.js +211 -166
  12. package/dist/gltf.js.map +1 -1
  13. package/dist/motion.js +26 -26
  14. package/dist/motion.js.map +1 -1
  15. package/dist/particles.js +49 -49
  16. package/dist/particles.js.map +1 -1
  17. package/dist/passes.js +188 -86
  18. package/dist/passes.js.map +1 -1
  19. package/dist/phoria2.js +1 -1
  20. package/dist/picking.js +8 -13
  21. package/dist/picking.js.map +1 -1
  22. package/dist/snapshot.js +1 -1
  23. package/dist/tooltip.js +3 -3
  24. package/dist/tooltip.js.map +1 -1
  25. package/dist/types/OrbitControl.d.ts +6 -2
  26. package/dist/types/Raycaster.d.ts +10 -0
  27. package/dist/types/View.d.ts +64 -1
  28. package/dist/types/charts/Chart.d.ts +7 -0
  29. package/dist/types/explain.d.ts +3 -0
  30. package/dist/types/frame.d.ts +7 -0
  31. package/dist/types/geometry/Geometry.d.ts +14 -2
  32. package/dist/types/keyboard.d.ts +48 -0
  33. package/dist/types/labels.d.ts +4 -0
  34. package/dist/types/material/Material.d.ts +125 -0
  35. package/dist/types/material/Texture.d.ts +37 -5
  36. package/dist/types/scene/Node.d.ts +19 -14
  37. package/dist/types/scene/drawables.d.ts +32 -14
  38. package/dist/types/scene/lights.d.ts +16 -2
  39. package/dist/types/shadow.d.ts +2 -1
  40. package/dist/types/types.d.ts +14 -0
  41. package/dist/types/value/Color.d.ts +0 -4
  42. package/dist/types/value/Quat.d.ts +4 -2
  43. package/dist/types/webgl/WebGLRenderer.d.ts +6 -0
  44. package/dist/types/webgl/passes.d.ts +37 -13
  45. package/dist/types/webgl/resources.d.ts +24 -2
  46. package/dist/types/webgl/shaders.d.ts +4 -2
  47. package/llms-full.txt +153 -15
  48. package/package.json +4 -1
  49. package/schema/scene.schema.json +146 -1
  50. package/src/OrbitControl.js +7 -3
  51. package/src/Raycaster.js +58 -0
  52. package/src/View.js +207 -42
  53. package/src/charts/Chart.js +20 -2
  54. package/src/explain.js +6 -2
  55. package/src/frame.js +29 -9
  56. package/src/geometry/Geometry.js +24 -4
  57. package/src/gltf/load.js +50 -6
  58. package/src/keyboard.js +298 -0
  59. package/src/labels.js +4 -1
  60. package/src/material/Material.js +104 -19
  61. package/src/material/Texture.js +116 -11
  62. package/src/scene/Node.js +20 -9
  63. package/src/scene/Scene.js +2 -0
  64. package/src/scene/cameras.js +4 -1
  65. package/src/scene/drawables.js +48 -12
  66. package/src/scene/lights.js +40 -6
  67. package/src/shadow.js +27 -4
  68. package/src/types.js +6 -0
  69. package/src/value/Color.js +21 -0
  70. package/src/value/Quat.js +15 -6
  71. package/src/watch.js +25 -1
  72. package/src/webgl/WebGLRenderer.js +51 -12
  73. package/src/webgl/passes.js +190 -32
  74. package/src/webgl/picking.js +0 -1
  75. package/src/webgl/resources.js +89 -8
  76. package/src/webgl/shaders.js +350 -48
package/dist/charts.js CHANGED
@@ -1,32 +1,32 @@
1
- import { C as e, Dt as t, L as n, Ot as r, Pt as i, S as a, X as o, b as s, gt as c, kt as l, l as u, m as d, n as f, nt as p, rt as m, w as h, wt as g, x as _ } from "./core.js";
1
+ import { $ as e, At as t, Ft as n, Ot as r, Q as i, Tt as a, V as o, Z as s, _t as c, ct as l, et as u, kt as d, l as f, m as p, n as m, nt as h, rt as g, tt as _ } from "./core.js";
2
2
  // src/charts/axes.js
3
3
  var v = .97, y = .08, b = /* @__PURE__ */ new Float32Array(16);
4
- function x(e, t, n) {
5
- let r = t.worldPosition;
6
- i(b, e.worldMatrix);
7
- let a = b[0] * r[0] + b[4] * r[1] + b[8] * r[2] + b[12], o = b[1] * r[0] + b[5] * r[1] + b[9] * r[2] + b[13] - n, s = b[2] * r[0] + b[6] * r[1] + b[10] * r[2] + b[14], c = Math.hypot(a, o, s) || 1;
4
+ function x(e, t, r) {
5
+ let i = t.worldPosition;
6
+ n(b, e.worldMatrix);
7
+ let a = b[0] * i[0] + b[4] * i[1] + b[8] * i[2] + b[12], o = b[1] * i[0] + b[5] * i[1] + b[9] * i[2] + b[13] - r, s = b[2] * i[0] + b[6] * i[1] + b[10] * i[2] + b[14], c = Math.hypot(a, o, s) || 1;
8
8
  return [
9
9
  a / c,
10
10
  o / c,
11
11
  s / c
12
12
  ];
13
13
  }
14
- function S({ box: e, axes: t, theme: r, overlap: i }) {
15
- let [o, s, c] = e, l = new p({
14
+ function S({ box: t, axes: n, theme: r, overlap: a }) {
15
+ let [o, s, c] = t, u = new h({
16
16
  name: "axes",
17
17
  pickable: !1
18
- }), u = (e) => x(l, e, s / 2), d = r === "light" ? "#c3c8d2" : "#3a3d47", f = (e) => {
18
+ }), d = (e) => x(u, e, s / 2), f = r === "light" ? "#c3c8d2" : "#3a3d47", p = (e) => {
19
19
  let t = e.channel?.axis?.ticks;
20
20
  if (!Array.isArray(t)) return e.scale.kind === "band" ? e.scale.ticks() : e.scale.ticks(t ?? 5);
21
21
  let [n, r] = e.scale.range, i = Math.min(n, r), a = Math.max(n, r);
22
22
  return t.filter((t) => e.scale(t) >= i - 1e-9 && e.scale(t) <= a + 1e-9);
23
- }, m = (e) => e && e.scale.kind !== "band" && e.channel?.axis !== !1 ? f(e) : [], h = m(t.x), g = m(t.y), b = m(t.z), S = (e, r) => {
24
- let i = [], f = (e, t) => i.push(...e, ...t), p = (e) => r < 0 ? -e / 2 : e / 2;
25
- if (e === "y") {
23
+ }, m = (e) => e && e.scale.kind !== "band" && e.channel?.axis !== !1 ? p(e) : [], g = m(n.x), _ = m(n.y), b = m(n.z), S = (t, r) => {
24
+ let i = [], a = (e, t) => i.push(...e, ...t), p = (e) => r < 0 ? -e / 2 : e / 2;
25
+ if (t === "y") {
26
26
  let e = r < 0 ? 0 : s;
27
- for (let n of h) {
28
- let r = t.x.scale(n);
29
- f([
27
+ for (let t of g) {
28
+ let r = n.x.scale(t);
29
+ a([
30
30
  r,
31
31
  e,
32
32
  -c / 2
@@ -36,9 +36,9 @@ function S({ box: e, axes: t, theme: r, overlap: i }) {
36
36
  c / 2
37
37
  ]);
38
38
  }
39
- for (let n of b) {
40
- let r = t.z.scale(n);
41
- f([
39
+ for (let t of b) {
40
+ let r = n.z.scale(t);
41
+ a([
42
42
  -o / 2,
43
43
  e,
44
44
  r
@@ -48,7 +48,7 @@ function S({ box: e, axes: t, theme: r, overlap: i }) {
48
48
  r
49
49
  ]);
50
50
  }
51
- C(f, [
51
+ C(a, [
52
52
  -o / 2,
53
53
  e,
54
54
  -c / 2
@@ -65,11 +65,11 @@ function S({ box: e, axes: t, theme: r, overlap: i }) {
65
65
  e,
66
66
  c / 2
67
67
  ]);
68
- } else if (e === "x") {
68
+ } else if (t === "x") {
69
69
  let e = p(o);
70
- for (let n of g) {
71
- let r = t.y.scale(n);
72
- f([
70
+ for (let t of _) {
71
+ let r = n.y.scale(t);
72
+ a([
73
73
  e,
74
74
  r,
75
75
  -c / 2
@@ -79,9 +79,9 @@ function S({ box: e, axes: t, theme: r, overlap: i }) {
79
79
  c / 2
80
80
  ]);
81
81
  }
82
- for (let n of b) {
83
- let r = t.z.scale(n);
84
- f([
82
+ for (let t of b) {
83
+ let r = n.z.scale(t);
84
+ a([
85
85
  e,
86
86
  0,
87
87
  r
@@ -91,7 +91,7 @@ function S({ box: e, axes: t, theme: r, overlap: i }) {
91
91
  r
92
92
  ]);
93
93
  }
94
- C(f, [
94
+ C(a, [
95
95
  e,
96
96
  0,
97
97
  -c / 2
@@ -110,9 +110,9 @@ function S({ box: e, axes: t, theme: r, overlap: i }) {
110
110
  ]);
111
111
  } else {
112
112
  let e = p(c);
113
- for (let n of g) {
114
- let r = t.y.scale(n);
115
- f([
113
+ for (let t of _) {
114
+ let r = n.y.scale(t);
115
+ a([
116
116
  -o / 2,
117
117
  r,
118
118
  e
@@ -122,9 +122,9 @@ function S({ box: e, axes: t, theme: r, overlap: i }) {
122
122
  e
123
123
  ]);
124
124
  }
125
- for (let n of h) {
126
- let r = t.x.scale(n);
127
- f([
125
+ for (let t of g) {
126
+ let r = n.x.scale(t);
127
+ a([
128
128
  r,
129
129
  0,
130
130
  e
@@ -134,7 +134,7 @@ function S({ box: e, axes: t, theme: r, overlap: i }) {
134
134
  e
135
135
  ]);
136
136
  }
137
- C(f, [
137
+ C(a, [
138
138
  -o / 2,
139
139
  0,
140
140
  e
@@ -152,12 +152,12 @@ function S({ box: e, axes: t, theme: r, overlap: i }) {
152
152
  e
153
153
  ]);
154
154
  }
155
- let m = "xyz".indexOf(e);
156
- l.add(new a({
157
- geometry: new n({ positions: i }),
158
- material: { color: d },
155
+ let m = "xyz".indexOf(t);
156
+ u.add(new e({
157
+ geometry: new l({ positions: i }),
158
+ material: { color: f },
159
159
  pickable: !1,
160
- showFrom: (e) => -r * u(e)[m] > y
160
+ showFrom: (e) => -r * d(e)[m] > y
161
161
  }));
162
162
  };
163
163
  for (let e of [
@@ -165,30 +165,30 @@ function S({ box: e, axes: t, theme: r, overlap: i }) {
165
165
  "y",
166
166
  "z"
167
167
  ]) for (let t of [-1, 1]) S(e, t);
168
- let w = Math.max(o, s, c) * .04, T = (e) => `phoria-axis-${e} phoria-${r}`, E = (e, n, r) => {
169
- let a = t[e];
170
- if (!a || a.channel?.axis === !1) return;
171
- let o = "xyz".indexOf(e), s = f(a);
172
- for (let e of n) {
173
- let t = l.add(new p({ showFrom: (t) => {
174
- let n = u(t);
175
- return Math.abs(n[o]) < v && e.when(n);
168
+ let w = Math.max(o, s, c) * .04, T = (e) => `phoria-axis-${e} phoria-${r}`, E = (e, t, r) => {
169
+ let o = n[e];
170
+ if (!o || o.channel?.axis === !1) return;
171
+ let s = "xyz".indexOf(e), c = p(o);
172
+ for (let e of t) {
173
+ let t = u.add(new h({ showFrom: (t) => {
174
+ let n = d(t);
175
+ return Math.abs(n[s]) < v && e.when(n);
176
176
  } }));
177
- for (let n of s) t.add(new _({
178
- text: a.scale.format(n),
179
- position: e.at(a.scale(n), w),
177
+ for (let n of c) t.add(new i({
178
+ text: o.scale.format(n),
179
+ position: e.at(o.scale(n), w),
180
180
  place: r,
181
181
  className: T("tick"),
182
182
  priority: 1,
183
- overlap: i
183
+ overlap: a
184
184
  }));
185
- a.title && t.add(new _({
186
- text: a.title,
185
+ o.title && t.add(new i({
186
+ text: o.title,
187
187
  position: e.title(w),
188
188
  place: r,
189
189
  className: T("title"),
190
190
  priority: 2,
191
- overlap: i
191
+ overlap: a
192
192
  }));
193
193
  }
194
194
  }, D = (e) => e[1] >= -.08, O = (e) => e >= -.1 ? 1 : -1;
@@ -228,7 +228,7 @@ function S({ box: e, axes: t, theme: r, overlap: i }) {
228
228
  s + n * 2,
229
229
  t * c / 2
230
230
  ]
231
- }))), "left"), l;
231
+ }))), "left"), u;
232
232
  }
233
233
  function C(e, t, n, r, i) {
234
234
  e(t, n), e(n, r), e(r, i), e(i, t);
@@ -239,13 +239,13 @@ function T(e, t) {
239
239
  let n = e / Math.max(1, t), r = 10 ** Math.floor(Math.log(n) / w), i = n / r;
240
240
  return r * (i >= 7.07 ? 10 : i >= 3.16 ? 5 : i >= 1.41 ? 2 : 1);
241
241
  }
242
- function E(e, n, r = !1) {
242
+ function E(e, n, i = !1) {
243
243
  if (typeof e == "function") return e;
244
244
  if (e && typeof e == "object") {
245
- let t = r ? new Intl.DateTimeFormat(void 0, e) : new Intl.NumberFormat(void 0, e);
245
+ let t = i ? new Intl.DateTimeFormat(void 0, e) : new Intl.NumberFormat(void 0, e);
246
246
  return (e) => t.format(e);
247
247
  }
248
- return e !== void 0 && l("charts", `'format' must be Intl format options or a function, got ${t(e)}`), n;
248
+ return e !== void 0 && t("charts", `'format' must be Intl format options or a function, got ${r(e)}`), n;
249
249
  }
250
250
  function D(e, t) {
251
251
  let n = Math.max(0, Math.min(6, -Math.floor(Math.log(e || 1) / w))), r = new Intl.NumberFormat(void 0, { maximumFractionDigits: n }), i = new Intl.NumberFormat(void 0, {
@@ -255,7 +255,7 @@ function D(e, t) {
255
255
  return (e) => (a ? i : r).format(e);
256
256
  }
257
257
  function O(e, n) {
258
- return Array.isArray(e) && e.length === 2 && e.every((e) => typeof e == "number" && Number.isFinite(e)) || l("charts", `'${n}' must be [min, max] numbers, got ${t(e)}`), [e[0], e[1]];
258
+ return Array.isArray(e) && e.length === 2 && e.every((e) => typeof e == "number" && Number.isFinite(e)) || t("charts", `'${n}' must be [min, max] numbers, got ${r(e)}`), [e[0], e[1]];
259
259
  }
260
260
  function k({ domain: e, range: t = [0, 1], nice: n = !1, zero: r = !1, clamp: i = !1, format: a }) {
261
261
  let [o, s] = O(e, "domain"), [c, l] = O(t, "range");
@@ -273,28 +273,28 @@ function k({ domain: e, range: t = [0, 1], nice: n = !1, zero: r = !1, clamp: i
273
273
  return n;
274
274
  }, d.format = E(a, D(T(s - o, 5), Math.max(Math.abs(o), Math.abs(s)))), d;
275
275
  }
276
- function A({ domain: e, range: t = [0, 1], format: n }) {
277
- let [r, i] = O(e, "domain");
278
- (r <= 0 || i <= 0) && l("charts", `a log scale needs a domain above 0, got [${r}, ${i}] - use a linear scale for zero or negative values`);
279
- let a = k({
280
- domain: [Math.log10(r), Math.log10(i)],
281
- range: t
282
- }), o = ((e) => a(Math.log10(e)));
283
- return o.kind = "log", o.domain = [r, i], o.range = a.range, o.invert = (e) => 10 ** a.invert?.(e), o.ticks = () => {
276
+ function A({ domain: e, range: n = [0, 1], format: r }) {
277
+ let [i, a] = O(e, "domain");
278
+ (i <= 0 || a <= 0) && t("charts", `a log scale needs a domain above 0, got [${i}, ${a}] - use a linear scale for zero or negative values`);
279
+ let o = k({
280
+ domain: [Math.log10(i), Math.log10(a)],
281
+ range: n
282
+ }), s = ((e) => o(Math.log10(e)));
283
+ return s.kind = "log", s.domain = [i, a], s.range = o.range, s.invert = (e) => 10 ** o.invert?.(e), s.ticks = () => {
284
284
  let e = [];
285
- for (let t = Math.floor(Math.log10(r)); t <= Math.ceil(Math.log10(i)); t++) for (let n of [
285
+ for (let t = Math.floor(Math.log10(i)); t <= Math.ceil(Math.log10(a)); t++) for (let n of [
286
286
  1,
287
287
  2,
288
288
  5
289
289
  ]) {
290
- let a = n * 10 ** t;
291
- a >= r * .999 && a <= i * 1.001 && e.push(a);
290
+ let r = n * 10 ** t;
291
+ r >= i * .999 && r <= a * 1.001 && e.push(r);
292
292
  }
293
293
  return e;
294
- }, o.format = E(n, (e) => new Intl.NumberFormat(void 0, {
294
+ }, s.format = E(r, (e) => new Intl.NumberFormat(void 0, {
295
295
  notation: "compact",
296
296
  maximumFractionDigits: 1
297
- }).format(e)), o;
297
+ }).format(e)), s;
298
298
  }
299
299
  var j = 1e3, M = 60 * j, N = 60 * M, P = 24 * N, F = [
300
300
  [j, "s"],
@@ -390,7 +390,7 @@ var j = 1e3, M = 60 * j, N = 60 * M, P = 24 * N, F = [
390
390
  };
391
391
  function I(e) {
392
392
  let n = e instanceof Date ? e : new Date(e);
393
- return Number.isNaN(n.getTime()) && l("charts", `${t(e)} isn't a date - use Date objects, timestamps or ISO strings like '2026-10-25'`), n;
393
+ return Number.isNaN(n.getTime()) && t("charts", `${r(e)} isn't a date - use Date objects, timestamps or ISO strings like '2026-10-25'`), n;
394
394
  }
395
395
  function ne({ domain: e, range: t = [0, 1], format: n }) {
396
396
  let r = I(e[0]).getTime(), i = I(e[1]).getTime(), a = k({
@@ -419,13 +419,13 @@ function ne({ domain: e, range: t = [0, 1], format: n }) {
419
419
  let l = new Intl.DateTimeFormat(void 0, te[s(6)[1]]);
420
420
  return c.format = E(n, (e) => l.format(I(e)), !0), c;
421
421
  }
422
- function re({ domain: e, range: n = [0, 1], padding: r = .2, format: i }) {
423
- Array.isArray(e) || l("charts", `a band scale's domain is a list of categories, got ${t(e)}`);
424
- let [a, o] = O(n, "range"), s = new Map(e.map((e, t) => [String(e), t])), c = (o - a) / Math.max(1, e.length), u = ((e) => {
425
- let t = s.get(String(e));
426
- return t === void 0 ? NaN : a + c * (t + .5);
422
+ function re({ domain: e, range: n = [0, 1], padding: i = .2, format: a }) {
423
+ Array.isArray(e) || t("charts", `a band scale's domain is a list of categories, got ${r(e)}`);
424
+ let [o, s] = O(n, "range"), c = new Map(e.map((e, t) => [String(e), t])), l = (s - o) / Math.max(1, e.length), u = ((e) => {
425
+ let t = c.get(String(e));
426
+ return t === void 0 ? NaN : o + l * (t + .5);
427
427
  });
428
- return u.kind = "band", u.domain = e, u.range = [a, o], u.step = c, u.bandwidth = Math.abs(c) * (1 - r), u.ticks = () => e, u.format = E(i, (e) => String(e)), u;
428
+ return u.kind = "band", u.domain = e, u.range = [o, s], u.step = l, u.bandwidth = Math.abs(l) * (1 - i), u.ticks = () => e, u.format = E(a, (e) => String(e)), u;
429
429
  }
430
430
  var L = {
431
431
  category: [
@@ -476,31 +476,31 @@ var L = {
476
476
  "#2166ac"
477
477
  ]
478
478
  };
479
- function R({ domain: e, scheme: n, range: r, kind: i }) {
480
- n !== void 0 && !(n in L) && l("charts", `colour scheme '${n}' isn't one we have - use ${Object.keys(L).map((e) => `'${e}'`).join(", ")}, or a range of colours`);
481
- let a = i ? i === "sequential" : e.length === 2 && e.every((e) => typeof e == "number");
482
- a && (e.length < 2 || e.some((e) => typeof e != "number")) && l("charts", `a sequential colour scale needs two or more numbers in its domain, got ${t(e)}`);
483
- let o = (r ?? L[n ?? (a ? "viridis" : "category")]).map((e) => c.fromInput(e, "charts")), s;
484
- if (a) {
479
+ function R({ domain: e, scheme: n, range: i, kind: a }) {
480
+ n !== void 0 && !(n in L) && t("charts", `colour scheme '${n}' isn't one we have - use ${Object.keys(L).map((e) => `'${e}'`).join(", ")}, or a range of colours`);
481
+ let o = a ? a === "sequential" : e.length === 2 && e.every((e) => typeof e == "number");
482
+ o && (e.length < 2 || e.some((e) => typeof e != "number")) && t("charts", `a sequential colour scale needs two or more numbers in its domain, got ${r(e)}`);
483
+ let s = (i ?? L[n ?? (o ? "viridis" : "category")]).map((e) => c.fromInput(e, "charts")), l;
484
+ if (o) {
485
485
  let t = (t) => {
486
486
  let n = e.length - 1, r = 0;
487
487
  for (; r < n - 1 && t > e[r + 1];) r++;
488
488
  let i = (t - e[r]) / (e[r + 1] - e[r] || 1);
489
489
  return Math.min(1, Math.max(0, (r + i) / n));
490
490
  };
491
- s = ((e) => {
492
- if (o.length < 2) return o[0].clone();
493
- let n = t(e) * (o.length - 1), r = Math.min(o.length - 2, Math.floor(n));
494
- return o[r].clone().lerp(o[r + 1], n - r);
495
- }), s.kind = "sequential", s.colors = () => [];
491
+ l = ((e) => {
492
+ if (s.length < 2) return s[0].clone();
493
+ let n = t(e) * (s.length - 1), r = Math.min(s.length - 2, Math.floor(n));
494
+ return s[r].clone().lerp(s[r + 1], n - r);
495
+ }), l.kind = "sequential", l.colors = () => [];
496
496
  } else {
497
497
  let t = new Map(e.map((e, t) => [String(e), t]));
498
- s = ((e) => o[(t.get(String(e)) ?? 0) % o.length].clone()), s.kind = "categorical", s.colors = () => e.map((e) => ({
498
+ l = ((e) => s[(t.get(String(e)) ?? 0) % s.length].clone()), l.kind = "categorical", l.colors = () => e.map((e) => ({
499
499
  value: e,
500
- color: s(e)
500
+ color: l(e)
501
501
  }));
502
502
  }
503
- return s.domain = e, s.range = o.map((e) => e.getStyle()), s;
503
+ return l.domain = e, l.range = s.map((e) => e.getStyle()), l;
504
504
  }
505
505
  function z(e) {
506
506
  let t = [...new Map(e.map((e) => [e instanceof Date ? e.getTime() : e, e])).values()];
@@ -625,7 +625,7 @@ function oe(e) {
625
625
  }
626
626
  function U(e, t) {
627
627
  let n = new s({
628
- geometry: u(1),
628
+ geometry: f(1),
629
629
  material: { roughness: .55 },
630
630
  count: e,
631
631
  labels: V(t, "above")
@@ -641,14 +641,14 @@ function se(e) {
641
641
  roughness: .4,
642
642
  ...r === void 0 ? {} : { opacity: r }
643
643
  }, a = t ? new s({
644
- geometry: d({
644
+ geometry: p({
645
645
  radius: 1,
646
646
  detail: 1
647
647
  }),
648
648
  material: i,
649
649
  count: 64,
650
650
  labels: V(e, "above")
651
- }) : new h({
651
+ }) : new _({
652
652
  geometry: G(64),
653
653
  material: {
654
654
  size: e.spec.channels.size?.value ?? n * 1.4,
@@ -724,15 +724,15 @@ function se(e) {
724
724
  return o;
725
725
  }
726
726
  function G(e) {
727
- let t = new n({
727
+ let t = new l({
728
728
  positions: new Float32Array(e * 3),
729
729
  colors: new Float32Array(e * 3)
730
730
  });
731
731
  return t.drawCount = 0, t;
732
732
  }
733
- function ce(t, r) {
734
- let i = new a({
735
- geometry: new n({ positions: [
733
+ function ce(t, n) {
734
+ let r = new e({
735
+ geometry: new l({ positions: [
736
736
  0,
737
737
  0,
738
738
  0,
@@ -745,7 +745,7 @@ function ce(t, r) {
745
745
  vertexColors: !0
746
746
  },
747
747
  pickable: !1
748
- }), o = new h({
748
+ }), i = new _({
749
749
  geometry: G(8),
750
750
  material: {
751
751
  size: 7,
@@ -753,8 +753,8 @@ function ce(t, r) {
753
753
  vertexColors: !0
754
754
  },
755
755
  labels: V(t, "above")
756
- }), s = r ? new e({
757
- geometry: new n({ positions: [
756
+ }), a = n ? new u({
757
+ geometry: new l({ positions: [
758
758
  0,
759
759
  0,
760
760
  0,
@@ -774,11 +774,11 @@ function ce(t, r) {
774
774
  pickable: !1
775
775
  }) : null;
776
776
  return {
777
- nodes: s ? [
778
- s,
779
- i,
780
- o
781
- ] : [i, o],
777
+ nodes: a ? [
778
+ a,
779
+ r,
780
+ i
781
+ ] : [r, i],
782
782
  layout(e) {
783
783
  let { x: n, y: r, z: i } = t.scales, a = t.spec.channels, o = a.color?.field ? a.color : a.detail ?? (a.z?.field ? a.z : null), s = /* @__PURE__ */ new Map();
784
784
  for (let t of e) {
@@ -807,18 +807,18 @@ function ce(t, r) {
807
807
  };
808
808
  },
809
809
  apply(e, t) {
810
- let { lengths: n, colors: r } = t.shape, a = [], c = [], l = [], u = [], d = [], f = [], p = [], m = 0;
810
+ let { lengths: n, colors: o } = t.shape, s = [], c = [], l = [], u = [], d = [], f = [], p = [], m = 0;
811
811
  n.forEach((t, n) => {
812
- let i = r[n];
812
+ let r = o[n];
813
813
  for (let n = 0; n < t; n++, m++) {
814
- let [t, r, o, h] = e.subarray(m * 4, m * 4 + 4);
815
- if (l.push(t, r, o), u.push(...i), n > 0 && (a.push(...e.subarray((m - 1) * 4, (m - 1) * 4 + 3), t, r, o), c.push(...i, ...i)), s) {
814
+ let [t, i, o, h] = e.subarray(m * 4, m * 4 + 4);
815
+ if (l.push(t, i, o), u.push(...r), n > 0 && (s.push(...e.subarray((m - 1) * 4, (m - 1) * 4 + 3), t, i, o), c.push(...r, ...r)), a) {
816
816
  let e = f.length / 3;
817
- d.push(t, r, o, t, h, o), f.push(...i, ...i), n > 0 && p.push(e - 2, e - 1, e, e - 1, e + 1, e);
817
+ d.push(t, i, o, t, h, o), f.push(...r, ...r), n > 0 && p.push(e - 2, e - 1, e, e - 1, e + 1, e);
818
818
  }
819
819
  }
820
- }), i.geometry = K(i.geometry, a.length ? {
821
- positions: a,
820
+ }), r.geometry = K(r.geometry, s.length ? {
821
+ positions: s,
822
822
  colors: c
823
823
  } : { positions: [
824
824
  0,
@@ -827,7 +827,7 @@ function ce(t, r) {
827
827
  0,
828
828
  0,
829
829
  0
830
- ] }), o.geometry = K(o.geometry, {
830
+ ] }), i.geometry = K(i.geometry, {
831
831
  positions: l.length ? l : [
832
832
  0,
833
833
  0,
@@ -838,7 +838,7 @@ function ce(t, r) {
838
838
  0,
839
839
  0
840
840
  ]
841
- }), o.geometry.drawCount = l.length / 3, o.material.size = Math.max(...n, 0) > 40 ? 4 : 7, o.data = t.rows, s && (s.geometry = K(s.geometry, p.length ? {
841
+ }), i.geometry.drawCount = l.length / 3, i.material.size = Math.max(...n, 0) > 40 ? 4 : 7, i.data = t.rows, a && (a.geometry = K(a.geometry, p.length ? {
842
842
  positions: d,
843
843
  colors: f,
844
844
  indices: p
@@ -857,11 +857,11 @@ function ce(t, r) {
857
857
  };
858
858
  }
859
859
  function K(e, t) {
860
- return e.dispose(), new n(t);
860
+ return e.dispose(), new l(t);
861
861
  }
862
- function le(t) {
863
- let r = new e({
864
- geometry: new n({ positions: [
862
+ function le(e) {
863
+ let n = new u({
864
+ geometry: new l({ positions: [
865
865
  0,
866
866
  0,
867
867
  0,
@@ -879,21 +879,21 @@ function le(t) {
879
879
  }
880
880
  });
881
881
  return {
882
- nodes: [r],
883
- layout(e) {
884
- let { x: n, y: r, z: i } = t.scales, a = t.spec.channels, o = z(e.map((e) => a.x.get(e))), s = z(e.map((e) => a.z.get(e))), c = new Map(e.map((e) => [`${+a.x.get(e)}|${+a.z.get(e)}|${a.x.get(e)}|${a.z.get(e)}`, e])), u = (e, t) => c.get(`${+e}|${+t}|${e}|${t}`), d = o.length * s.length - c.size;
882
+ nodes: [n],
883
+ layout(n) {
884
+ let { x: r, y: i, z: a } = e.scales, o = e.spec.channels, s = z(n.map((e) => o.x.get(e))), c = z(n.map((e) => o.z.get(e))), l = new Map(n.map((e) => [`${+o.x.get(e)}|${+o.z.get(e)}|${o.x.get(e)}|${o.z.get(e)}`, e])), u = (e, t) => l.get(`${+e}|${+t}|${e}|${t}`), d = s.length * c.length - l.size;
885
885
  if (d > 0) {
886
- let e = o.flatMap((e) => s.map((t) => [e, t])).find(([e, t]) => !u(e, t));
887
- l("chart()", `a surface needs a value for every x and z pair - ${d} of ${o.length * s.length} are missing (first: x ${e[0]}, z ${e[1]})`);
886
+ let e = s.flatMap((e) => c.map((t) => [e, t])).find(([e, t]) => !u(e, t));
887
+ t("chart()", `a surface needs a value for every x and z pair - ${d} of ${s.length * c.length} are missing (first: x ${e[0]}, z ${e[1]})`);
888
888
  }
889
- let f = [], p = new Float32Array(o.length * s.length * 6), m = 0;
890
- for (let e of s) for (let s of o) {
891
- let o = u(s, e);
892
- f.push(o), p.set([
893
- n(s),
894
- r(Number(a.y.get(o)) || 0),
895
- i(e),
896
- ...t.rgb(o)
889
+ let f = [], p = new Float32Array(s.length * c.length * 6), m = 0;
890
+ for (let t of c) for (let n of s) {
891
+ let s = u(n, t);
892
+ f.push(s), p.set([
893
+ r(n),
894
+ i(Number(o.y.get(s)) || 0),
895
+ a(t),
896
+ ...e.rgb(s)
897
897
  ], m++ * 6);
898
898
  }
899
899
  return {
@@ -902,23 +902,23 @@ function le(t) {
902
902
  state: p,
903
903
  stride: 6,
904
904
  shape: {
905
- nx: o.length,
906
- nz: s.length
905
+ nx: s.length,
906
+ nz: c.length
907
907
  }
908
908
  };
909
909
  },
910
910
  apply(e, t) {
911
- let { nx: n, nz: i } = t.shape, a = [], o = [], s = [];
912
- for (let t = 0; t < n * i; t++) a.push(...e.subarray(t * 6, t * 6 + 3)), o.push(...e.subarray(t * 6 + 3, t * 6 + 6));
913
- for (let e = 0; e < i - 1; e++) for (let t = 0; t < n - 1; t++) {
914
- let r = e * n + t, i = r + 1, a = r + n, o = a + 1;
915
- s.push(r, a, i, i, a, o);
911
+ let { nx: r, nz: i } = t.shape, a = [], o = [], s = [];
912
+ for (let t = 0; t < r * i; t++) a.push(...e.subarray(t * 6, t * 6 + 3)), o.push(...e.subarray(t * 6 + 3, t * 6 + 6));
913
+ for (let e = 0; e < i - 1; e++) for (let t = 0; t < r - 1; t++) {
914
+ let n = e * r + t, i = n + 1, a = n + r, o = a + 1;
915
+ s.push(n, a, i, i, a, o);
916
916
  }
917
- r.geometry = K(r.geometry, {
917
+ n.geometry = K(n.geometry, {
918
918
  positions: a,
919
919
  colors: o,
920
920
  indices: s
921
- }), r.data = t.rows;
921
+ }), n.data = t.rows;
922
922
  }
923
923
  };
924
924
  }
@@ -935,19 +935,19 @@ var de = [
935
935
  2.5,
936
936
  4.5
937
937
  ];
938
- function fe(e) {
939
- let r = e.spec.options, i = me(e), o = e.spec.link, u = r.source ?? "source", f = r.target ?? "target", p = /* @__PURE__ */ new Map(), m = (t) => new s({
940
- geometry: d({
938
+ function fe(n) {
939
+ let i = n.spec.options, a = me(n), o = n.spec.link, u = i.source ?? "source", d = i.target ?? "target", f = /* @__PURE__ */ new Map(), m = (e) => new s({
940
+ geometry: p({
941
941
  radius: 1,
942
942
  detail: 2
943
943
  }),
944
944
  material: { roughness: .35 },
945
- count: t,
946
- labels: V(e, "above")
947
- }), g = m(Math.max(8, e.spec.rows.length * 2));
948
- g.count = 0;
949
- let _ = de.map((e) => new a({
950
- geometry: new n({ positions: [
945
+ count: e,
946
+ labels: V(n, "above")
947
+ }), h = m(Math.max(8, n.spec.rows.length * 2));
948
+ h.count = 0;
949
+ let g = de.map((t) => new e({
950
+ geometry: new l({ positions: [
951
951
  0,
952
952
  0,
953
953
  0,
@@ -956,67 +956,67 @@ function fe(e) {
956
956
  0
957
957
  ] }),
958
958
  material: {
959
- width: e,
959
+ width: t,
960
960
  vertexColors: !0
961
961
  },
962
962
  data: []
963
- })), v = new a({
964
- geometry: new n({ positions: [] }),
963
+ })), v = new e({
964
+ geometry: new l({ positions: [] }),
965
965
  material: {
966
966
  width: 4,
967
967
  color: "#7fd3ff"
968
968
  },
969
969
  pickable: !1,
970
970
  visible: !1
971
- }), y = o.flow ? new h({
972
- geometry: new n({ positions: [] }),
971
+ }), y = o.flow ? new _({
972
+ geometry: new l({ positions: [] }),
973
973
  material: {
974
- size: .012 * Math.min(...e.box),
974
+ size: .012 * Math.min(...n.box),
975
975
  color: "#bff0ff"
976
976
  },
977
977
  pickable: !1
978
978
  }) : null, b = [], x = [], S = [], C = [], w = null, T = {
979
979
  nodes: [
980
- ..._,
980
+ ...g,
981
981
  v,
982
- g,
982
+ h,
983
983
  ...y ? [y] : []
984
984
  ],
985
- layout(n) {
986
- let r = n.map(i), a = new Map(r.map((e, t) => [e, t]));
987
- S = e.spec.links.filter((n, r) => {
988
- let o = n[u], s = n[f];
989
- return (o === void 0 || s === void 0) && l("chart()", `link ${r} has no '${o === void 0 ? u : f}' - links name their ends with source: '${u}', target: '${f}' (set 'source' and 'target' to your field names)`), e.spec.rows.some((e) => i(e) === o) || l("chart()", `link ${r}: ${u} ${t(o)} names no node`), e.spec.rows.some((e) => i(e) === s) || l("chart()", `link ${r}: ${f} ${t(s)} names no node`), a.has(o) && a.has(s);
985
+ layout(e) {
986
+ let i = e.map(a), o = new Map(i.map((e, t) => [e, t]));
987
+ S = n.spec.links.filter((e, i) => {
988
+ let s = e[u], c = e[d];
989
+ return (s === void 0 || c === void 0) && t("chart()", `link ${i} has no '${s === void 0 ? u : d}' - links name their ends with source: '${u}', target: '${d}' (set 'source' and 'target' to your field names)`), n.spec.rows.some((e) => a(e) === s) || t("chart()", `link ${i}: ${u} ${r(s)} names no node`), n.spec.rows.some((e) => a(e) === c) || t("chart()", `link ${i}: ${d} ${r(c)} names no node`), o.has(s) && o.has(c);
990
990
  });
991
- let o = N(n, r, S.map((e) => [a.get(e[u]), a.get(e[f])])), s = new Float32Array(n.length * 7);
992
- return n.forEach((t, n) => s.set([
993
- ...o[n],
994
- e.size ? e.size(e.spec.channels.size.get(t)) : .06 * Math.min(...e.box),
995
- ...e.rgb(t)
996
- ], n * 7)), {
997
- rows: n,
998
- keys: r,
999
- state: s,
991
+ let s = N(e, i, S.map((e) => [o.get(e[u]), o.get(e[d])])), c = new Float32Array(e.length * 7);
992
+ return e.forEach((e, t) => c.set([
993
+ ...s[t],
994
+ n.size ? n.size(n.spec.channels.size.get(e)) : .06 * Math.min(...n.box),
995
+ ...n.rgb(e)
996
+ ], t * 7)), {
997
+ rows: e,
998
+ keys: i,
999
+ state: c,
1000
1000
  stride: 7,
1001
- shape: { pairs: S.map((e) => [e[u], e[f]]) }
1001
+ shape: { pairs: S.map((e) => [e[u], e[d]]) }
1002
1002
  };
1003
1003
  },
1004
1004
  apply(e, t) {
1005
- let r = e.length / t.stride;
1006
- if (C = t.rows, w !== null && !C.some((e) => i(e) === w) && (w = null, v.visible = !1), r > g.instanceMatrices.length / 16) {
1007
- let e = m(r * 2);
1008
- E && e.on("hover", D), g.parent?.add(e), g.parent?.remove(g), g.dispose(), T.nodes[T.nodes.indexOf(g)] = e, g = e;
1005
+ let n = e.length / t.stride;
1006
+ if (C = t.rows, w !== null && !C.some((e) => a(e) === w) && (w = null, v.visible = !1), n > h.instanceMatrices.length / 16) {
1007
+ let e = m(n * 2);
1008
+ E && e.on("hover", D), h.parent?.add(e), h.parent?.remove(h), h.dispose(), T.nodes[T.nodes.indexOf(h)] = e, h = e;
1009
1009
  }
1010
- g.count = r, g.data = t.rows;
1011
- let a = t.rows.map(i), s = new Map(a.map((e, t) => [e, t]));
1010
+ h.count = n, h.data = t.rows;
1011
+ let r = t.rows.map(a), i = new Map(r.map((e, t) => [e, t]));
1012
1012
  x = [];
1013
- for (let t = 0; t < r; t++) {
1013
+ for (let t = 0; t < n; t++) {
1014
1014
  let [n, r, i, a, o, s, c] = e.subarray(t * 7, t * 7 + 7);
1015
1015
  x.push([
1016
1016
  n,
1017
1017
  r,
1018
1018
  i
1019
- ]), g.setInstance(t, {
1019
+ ]), h.setInstance(t, {
1020
1020
  position: [
1021
1021
  n,
1022
1022
  r,
@@ -1030,26 +1030,26 @@ function fe(e) {
1030
1030
  ])
1031
1031
  });
1032
1032
  }
1033
- let c = de.map(() => ({
1033
+ let s = de.map(() => ({
1034
1034
  positions: [],
1035
1035
  colors: [],
1036
1036
  rows: []
1037
1037
  }));
1038
1038
  b = [], S.forEach((e, t) => {
1039
- let n = s.get(e[u]), r = s.get(e[f]);
1039
+ let n = i.get(e[u]), r = i.get(e[d]);
1040
1040
  if (n === void 0 || r === void 0) return;
1041
- let i = c[A(e)], a = j(e);
1042
- i.positions.push(...x[n], ...x[r]), i.colors.push(...a, ...a), i.rows.push(e), o.flow && b.push({
1041
+ let a = s[A(e)], c = j(e);
1042
+ a.positions.push(...x[n], ...x[r]), a.colors.push(...c, ...c), a.rows.push(e), o.flow && b.push({
1043
1043
  a: n,
1044
1044
  b: r,
1045
1045
  speed: M(e),
1046
1046
  phase: t * .618 % 1
1047
1047
  });
1048
- }), _.forEach((e, t) => {
1049
- let r = c[t];
1050
- e.geometry.dispose(), e.geometry = new n(r.positions.length ? {
1051
- positions: r.positions,
1052
- colors: r.colors
1048
+ }), g.forEach((e, t) => {
1049
+ let n = s[t];
1050
+ e.geometry.dispose(), e.geometry = new l(n.positions.length ? {
1051
+ positions: n.positions,
1052
+ colors: n.colors
1053
1053
  } : { positions: [
1054
1054
  0,
1055
1055
  0,
@@ -1057,7 +1057,7 @@ function fe(e) {
1057
1057
  0,
1058
1058
  0,
1059
1059
  0
1060
- ] }), e.visible = r.positions.length > 0, e.data = r.rows;
1060
+ ] }), e.visible = n.positions.length > 0, e.data = n.rows;
1061
1061
  }), w !== null && O(w);
1062
1062
  },
1063
1063
  enter(e) {
@@ -1070,68 +1070,68 @@ function fe(e) {
1070
1070
  n.phase = (n.phase + e * n.speed) % 1;
1071
1071
  let i = x[n.a], a = x[n.b];
1072
1072
  for (let e = 0; e < 3; e++) t[r * 3 + e] = i[e] + (a[e] - i[e]) * n.phase;
1073
- }), y.geometry.vertexCount === b.length ? (y.geometry.positions.set(t), y.geometry.needsUpdate()) : (y.geometry.dispose(), y.geometry = new n({ positions: t }));
1073
+ }), y.geometry.vertexCount === b.length ? (y.geometry.positions.set(t), y.geometry.needsUpdate()) : (y.geometry.dispose(), y.geometry = new l({ positions: t }));
1074
1074
  },
1075
1075
  tooltipRows(e) {
1076
- return _.includes(e.node) ? "link" : "node";
1076
+ return g.includes(e.node) ? "link" : "node";
1077
1077
  }
1078
- }, E = (r.highlight ?? "neighbours") === "neighbours";
1079
- E && g.on("hover", D);
1080
- function D(t) {
1081
- let n = t && t.node === g && t.instance !== null ? i(C[t.instance]) : null;
1082
- if (n !== w) {
1083
- w = n, v.visible = n !== null, n !== null && O(n);
1084
- for (let t = 0; t < g.count; t++) g.setColor(t, k(t, e.rgb(C[t])));
1078
+ }, E = (i.highlight ?? "neighbours") === "neighbours";
1079
+ E && h.on("hover", D);
1080
+ function D(e) {
1081
+ let t = e && e.node === h && e.instance !== null ? a(C[e.instance]) : null;
1082
+ if (t !== w) {
1083
+ w = t, v.visible = t !== null, t !== null && O(t);
1084
+ for (let e = 0; e < h.count; e++) h.setColor(e, k(e, n.rgb(C[e])));
1085
1085
  }
1086
1086
  }
1087
1087
  function O(e) {
1088
1088
  let t = [];
1089
1089
  for (let n of S) {
1090
- if (n[u] !== e && n[f] !== e) continue;
1091
- let r = C.findIndex((e) => i(e) === n[u]), a = C.findIndex((e) => i(e) === n[f]);
1092
- r >= 0 && a >= 0 && t.push(...x[r], ...x[a]);
1090
+ if (n[u] !== e && n[d] !== e) continue;
1091
+ let r = C.findIndex((e) => a(e) === n[u]), i = C.findIndex((e) => a(e) === n[d]);
1092
+ r >= 0 && i >= 0 && t.push(...x[r], ...x[i]);
1093
1093
  }
1094
- v.geometry.dispose(), v.geometry = new n({ positions: t });
1094
+ v.geometry.dispose(), v.geometry = new l({ positions: t });
1095
1095
  }
1096
- function k(t, n) {
1097
- if (w === null || !E) return n;
1098
- let r = i(C[t]);
1099
- return r === w || S.some((e) => e[u] === w && e[f] === r || e[f] === w && e[u] === r) ? n : new c().setSRGB(n[0], n[1], n[2]).lerp(e.theme === "light" ? "#ffffff" : "#202024", .65).toSRGB();
1096
+ function k(e, t) {
1097
+ if (w === null || !E) return t;
1098
+ let r = a(C[e]);
1099
+ return r === w || S.some((e) => e[u] === w && e[d] === r || e[d] === w && e[u] === r) ? t : new c().setSRGB(t[0], t[1], t[2]).lerp(n.theme === "light" ? "#ffffff" : "#202024", .65).toSRGB();
1100
1100
  }
1101
- function A(t) {
1102
- let n = o.width;
1103
- if (!n) return 0;
1104
- if (n.field === null) return n.value >= 3.5 ? 2 : +(n.value >= 2);
1105
- let r = e.spec.links.map((e) => Number(n.get(e)) || 0), i = Math.max(...r) || 1;
1106
- return Math.min(2, Math.floor((Number(n.get(t)) || 0) / i * 2.999));
1101
+ function A(e) {
1102
+ let t = o.width;
1103
+ if (!t) return 0;
1104
+ if (t.field === null) return t.value >= 3.5 ? 2 : +(t.value >= 2);
1105
+ let r = n.spec.links.map((e) => Number(t.get(e)) || 0), i = Math.max(...r) || 1;
1106
+ return Math.min(2, Math.floor((Number(t.get(e)) || 0) / i * 2.999));
1107
1107
  }
1108
- function j(t) {
1109
- let n = o.color, r = e.theme === "light" ? "#9aa3b2" : "#4a5266";
1110
- return n ? n.field === null ? c.fromInput(n.value).toSRGB() : e.linkColor(n.get(t)).toSRGB() : c.fromInput(r).toSRGB();
1108
+ function j(e) {
1109
+ let t = o.color, r = n.theme === "light" ? "#9aa3b2" : "#4a5266";
1110
+ return t ? t.field === null ? c.fromInput(t.value).toSRGB() : n.linkColor(t.get(e)).toSRGB() : c.fromInput(r).toSRGB();
1111
1111
  }
1112
- function M(t) {
1113
- let n = o.flow;
1114
- if (n.field === null) return .4;
1115
- let r = Math.max(...e.spec.links.map((e) => Number(n.get(e)) || 0)) || 1;
1116
- return .15 + .6 * (Number(n.get(t)) || 0) / r;
1112
+ function M(e) {
1113
+ let t = o.flow;
1114
+ if (t.field === null) return .4;
1115
+ let r = Math.max(...n.spec.links.map((e) => Number(t.get(e)) || 0)) || 1;
1116
+ return .15 + .6 * (Number(t.get(e)) || 0) / r;
1117
1117
  }
1118
- function N(n, i, a) {
1119
- let [o, s, c] = e.box, u = r.layout ?? "force";
1118
+ function N(e, a, o) {
1119
+ let [s, c, l] = n.box, u = i.layout ?? "force";
1120
1120
  if (u === "given") {
1121
- let { x: t, y: r, z: i } = e.scales, a = e.spec.channels;
1122
- return n.map((e) => [
1121
+ let { x: t, y: r, z: i } = n.scales, a = n.spec.channels;
1122
+ return e.map((e) => [
1123
1123
  t && a.x ? t(a.x.get(e)) : 0,
1124
- r && a.y ? r(a.y.get(e)) : s / 2,
1124
+ r && a.y ? r(a.y.get(e)) : c / 2,
1125
1125
  i && a.z ? i(a.z.get(e)) : 0
1126
1126
  ]);
1127
1127
  }
1128
- if (u && typeof u == "object" && "tiers" in u) return pe(n, i, a, u, [
1129
- o,
1128
+ if (u && typeof u == "object" && "tiers" in u) return pe(e, a, o, u, [
1130
1129
  s,
1131
- c
1130
+ c,
1131
+ l
1132
1132
  ]);
1133
- u !== "force" && l("chart()", `layout ${t(u)} - expected 'force', 'given' or { tiers: 'field' }`);
1134
- let d = P(i, a), f = [
1133
+ u !== "force" && t("chart()", `layout ${r(u)} - expected 'force', 'given' or { tiers: 'field' }`);
1134
+ let d = P(a, o), f = [
1135
1135
  Infinity,
1136
1136
  Infinity,
1137
1137
  Infinity
@@ -1141,19 +1141,19 @@ function fe(e) {
1141
1141
  -Infinity
1142
1142
  ];
1143
1143
  for (let e of d) for (let t = 0; t < 3; t++) f[t] = Math.min(f[t], e[t]), p[t] = Math.max(p[t], e[t]);
1144
- let m = Math.max(...p.map((e, t) => e - f[t]), 1e-6), h = Math.min(o, r.flat ? c : Math.min(s, c)) * .9 / m, g = p.map((e, t) => (e + f[t]) / 2);
1144
+ let m = Math.max(...p.map((e, t) => e - f[t]), 1e-6), h = Math.min(s, i.flat ? l : Math.min(c, l)) * .9 / m, g = p.map((e, t) => (e + f[t]) / 2);
1145
1145
  return d.map((e) => [
1146
1146
  (e[0] - g[0]) * h,
1147
- r.flat ? 0 : (e[1] - g[1]) * h + s / 2,
1147
+ i.flat ? 0 : (e[1] - g[1]) * h + c / 2,
1148
1148
  (e[2] - g[2]) * h
1149
1149
  ]);
1150
1150
  }
1151
1151
  function P(e, t) {
1152
- let n = e.length, i = ue(r.seed ?? 1), a = r.flat ? [0, 2] : [
1152
+ let n = e.length, r = ue(i.seed ?? 1), a = i.flat ? [0, 2] : [
1153
1153
  0,
1154
1154
  1,
1155
1155
  2
1156
- ], o = e.some((e) => p.has(e)), s = r.steps ?? (o ? 60 : 300), c = e.map(() => []);
1156
+ ], o = e.some((e) => f.has(e)), s = i.steps ?? (o ? 60 : 300), c = e.map(() => []);
1157
1157
  for (let [e, n] of t) c[e].push(n), c[n].push(e);
1158
1158
  let l = new Float32Array(n * n).fill(Infinity), u = 1;
1159
1159
  for (let e = 0; e < n; e++) {
@@ -1165,61 +1165,61 @@ function fe(e) {
1165
1165
  }
1166
1166
  }
1167
1167
  let d = e.map((t, a) => {
1168
- if (p.has(t)) return [...p.get(t)];
1169
- let o = c[a].find((t) => p.has(e[t])), s = o === void 0 ? [
1168
+ if (f.has(t)) return [...f.get(t)];
1169
+ let o = c[a].find((t) => f.has(e[t])), s = o === void 0 ? [
1170
1170
  0,
1171
1171
  0,
1172
1172
  0
1173
- ] : p.get(e[o]), l = o === void 0 ? Math.sqrt(n) : .5;
1173
+ ] : f.get(e[o]), l = o === void 0 ? Math.sqrt(n) : .5;
1174
1174
  return [
1175
- s[0] + (i() - .5) * l,
1176
- r.flat ? 0 : s[1] + (i() - .5) * l,
1177
- s[2] + (i() - .5) * l
1175
+ s[0] + (r() - .5) * l,
1176
+ i.flat ? 0 : s[1] + (r() - .5) * l,
1177
+ s[2] + (r() - .5) * l
1178
1178
  ];
1179
- }), f = [
1179
+ }), p = [
1180
1180
  0,
1181
1181
  0,
1182
1182
  0
1183
1183
  ];
1184
1184
  for (let e = 0; e < s; e++) for (let e = 0; e < n; e++) {
1185
- f.fill(0);
1185
+ p.fill(0);
1186
1186
  let t = 0;
1187
1187
  for (let r = 0; r < n; r++) {
1188
1188
  if (e === r) continue;
1189
- let i = l[e * n + r], a = i === Infinity ? u + 1 : i, o = 1 / (a * a), s = d[e][0] - d[r][0], c = d[e][1] - d[r][1], p = d[e][2] - d[r][2], m = Math.hypot(s, c, p) || 1e-6;
1190
- f[0] += o * (d[r][0] + a * s / m), f[1] += o * (d[r][1] + a * c / m), f[2] += o * (d[r][2] + a * p / m), t += o;
1189
+ let i = l[e * n + r], a = i === Infinity ? u + 1 : i, o = 1 / (a * a), s = d[e][0] - d[r][0], c = d[e][1] - d[r][1], f = d[e][2] - d[r][2], m = Math.hypot(s, c, f) || 1e-6;
1190
+ p[0] += o * (d[r][0] + a * s / m), p[1] += o * (d[r][1] + a * c / m), p[2] += o * (d[r][2] + a * f / m), t += o;
1191
1191
  }
1192
- if (t) for (let n of a) d[e][n] = f[n] / t;
1192
+ if (t) for (let n of a) d[e][n] = p[n] / t;
1193
1193
  }
1194
- return p = new Map(e.map((e, t) => [e, d[t]])), d;
1194
+ return f = new Map(e.map((e, t) => [e, d[t]])), d;
1195
1195
  }
1196
1196
  return T;
1197
1197
  }
1198
- function pe(e, t, n, r, [i, a, o]) {
1199
- let s = r.tiers;
1198
+ function pe(e, n, r, i, [a, o, s]) {
1199
+ let c = i.tiers;
1200
1200
  if (!e.length) return [];
1201
- s in e[0] || l("chart()", `layout: { tiers: '${s}' } - '${s}' isn't a node field`);
1202
- let c = r.order ?? [...new Set(e.map((e) => e[s]))], u = e.map((e) => Math.max(0, c.indexOf(e[s]))), d = Math.max(...u) + 1, f = Array(e.length).fill(0), p = Array(e.length), m = Math.min(i, o) / 2 * .92;
1201
+ c in e[0] || t("chart()", `layout: { tiers: '${c}' } - '${c}' isn't a node field`);
1202
+ let l = i.order ?? [...new Set(e.map((e) => e[c]))], u = e.map((e) => Math.max(0, l.indexOf(e[c]))), d = Math.max(...u) + 1, f = Array(e.length).fill(0), p = Array(e.length), m = Math.min(a, s) / 2 * .92;
1203
1203
  for (let t = 0; t < d; t++) {
1204
- let r = e.map((e, t) => t).filter((e) => u[e] === t), i = (e) => {
1205
- let i = n.filter(([t, n]) => t === e || n === e).map(([t, n]) => t === e ? n : t).filter((e) => u[e] < t);
1206
- return i.length ? i.reduce((e, t) => e + f[t], 0) / i.length : r.indexOf(e);
1204
+ let n = e.map((e, t) => t).filter((e) => u[e] === t), i = (e) => {
1205
+ let i = r.filter(([t, n]) => t === e || n === e).map(([t, n]) => t === e ? n : t).filter((e) => u[e] < t);
1206
+ return i.length ? i.reduce((e, t) => e + f[t], 0) / i.length : n.indexOf(e);
1207
1207
  };
1208
- t > 0 && r.sort((e, t) => i(e) - i(t));
1209
- let o = r.length === 1 ? 0 : t === 0 ? m * .25 : m * (.35 + .65 * t / Math.max(1, d - 1));
1210
- r.forEach((e, n) => {
1211
- f[e] = (n + .5) / r.length * Math.PI * 2, p[e] = [
1212
- Math.cos(f[e]) * o,
1213
- a * (1 - t / Math.max(1, d - 1)),
1214
- Math.sin(f[e]) * o
1208
+ t > 0 && n.sort((e, t) => i(e) - i(t));
1209
+ let a = n.length === 1 ? 0 : t === 0 ? m * .25 : m * (.35 + .65 * t / Math.max(1, d - 1));
1210
+ n.forEach((e, r) => {
1211
+ f[e] = (r + .5) / n.length * Math.PI * 2, p[e] = [
1212
+ Math.cos(f[e]) * a,
1213
+ o * (1 - t / Math.max(1, d - 1)),
1214
+ Math.sin(f[e]) * a
1215
1215
  ];
1216
1216
  });
1217
1217
  }
1218
1218
  return p;
1219
1219
  }
1220
1220
  function me(e) {
1221
- let t = e.spec.channels.key;
1222
- return t ? (e) => t.get(e) : (e.spec.rows.length && !("id" in e.spec.rows[0]) && l("chart()", "network nodes need an 'id' field, or key: 'yourIdField' - links name nodes by it"), (e) => e.id);
1221
+ let n = e.spec.channels.key;
1222
+ return n ? (e) => n.get(e) : (e.spec.rows.length && !("id" in e.spec.rows[0]) && t("chart()", "network nodes need an 'id' field, or key: 'yourIdField' - links name nodes by it"), (e) => e.id);
1223
1223
  }
1224
1224
  // src/charts/spec.js
1225
1225
  var q = [
@@ -1317,78 +1317,78 @@ var q = [
1317
1317
  stack: "stacking is the chart's option: stack: true"
1318
1318
  };
1319
1319
  function ye(e) {
1320
- (!e || typeof e != "object" || Array.isArray(e)) && l("chart()", `expected a spec such as { mark: 'bar', data, x, y }, got ${t(e)}`);
1321
- for (let t of Object.keys(e)) Y.includes(t) || l("chart()", `unknown option '${t}' - ${ge[t] ?? `expected ${Y.filter((e) => e[0] !== "$").join(", ")}${r(t, Y)}`}`);
1322
- typeof e.width == "number" && e.width > 1 && l("chart()", "'width' is a bar's share of its band (0-1); in Vega-Lite it is pixels - here the canvas sets the size");
1323
- let n = be(e.mark), { rows: i, links: a } = xe(e.data, n), o = Se(i), s = { ...e.encoding ?? {} };
1324
- for (let e of Object.keys(s)) !J.includes(e) && e !== "tooltip" && l("chart()", `encoding '${e}' isn't a channel we have - channels are ${J.join(", ")}, tooltip`);
1325
- let c = {};
1320
+ (!e || typeof e != "object" || Array.isArray(e)) && t("chart()", `expected a spec such as { mark: 'bar', data, x, y }, got ${r(e)}`);
1321
+ for (let n of Object.keys(e)) Y.includes(n) || t("chart()", `unknown option '${n}' - ${ge[n] ?? `expected ${Y.filter((e) => e[0] !== "$").join(", ")}${d(n, Y)}`}`);
1322
+ typeof e.width == "number" && e.width > 1 && t("chart()", "'width' is a bar's share of its band (0-1); in Vega-Lite it is pixels - here the canvas sets the size");
1323
+ let n = be(e.mark), { rows: i, links: o } = xe(e.data, n), s = Se(i), c = { ...e.encoding ?? {} };
1324
+ for (let e of Object.keys(c)) !J.includes(e) && e !== "tooltip" && t("chart()", `encoding '${e}' isn't a channel we have - channels are ${J.join(", ")}, tooltip`);
1325
+ let l = {};
1326
1326
  for (let t of J) {
1327
- let n = e[t] ?? s[t];
1328
- n != null && (c[t] = X(t, n, i, o));
1327
+ let n = e[t] ?? c[t];
1328
+ n != null && (l[t] = X(t, n, i, s));
1329
1329
  }
1330
- if (n === "network") for (let t of [
1330
+ if (n === "network") for (let n of [
1331
1331
  "x",
1332
1332
  "y",
1333
1333
  "z"
1334
- ]) c[t] && e.layout !== "given" && l("chart()", `${t} on a 'network' places its nodes - add layout: 'given' to use positions from the data`);
1334
+ ]) l[n] && e.layout !== "given" && t("chart()", `${n} on a 'network' places its nodes - add layout: 'given' to use positions from the data`);
1335
1335
  else for (let e of n === "surface" ? [
1336
1336
  "x",
1337
1337
  "z",
1338
1338
  "y"
1339
- ] : ["x", "y"]) c[e] || l("chart()", `a '${n}' chart needs ${e} - e.g. ${e}: '${o[0] ?? "field"}'`), n !== "point" && c[e].field === null && l("chart()", `${e} on a '${n}' chart lays its marks out along a scale - it needs a field, not a constant value - e.g. ${e}: '${o[0] ?? "field"}'`);
1340
- let u = e.tooltip ?? s.tooltip, d = typeof e.mark == "object" ? e.mark.tooltip : void 0, f = Ee(u ?? (d !== !1 && void 0), c, i, o), p = {};
1339
+ ] : ["x", "y"]) l[e] || t("chart()", `a '${n}' chart needs ${e} - e.g. ${e}: '${s[0] ?? "field"}'`), n !== "point" && l[e].field === null && t("chart()", `${e} on a '${n}' chart lays its marks out along a scale - it needs a field, not a constant value - e.g. ${e}: '${s[0] ?? "field"}'`);
1340
+ let u = e.tooltip ?? c.tooltip, f = typeof e.mark == "object" ? e.mark.tooltip : void 0, p = Ee(u ?? (f !== !1 && void 0), l, i, s), m = {};
1341
1341
  if (e.link !== void 0) {
1342
- n !== "network" && l("chart()", "'link' sets a network's link channels - it needs mark: 'network'");
1343
- let t = Se(a);
1344
- for (let [n, r] of Object.entries(e.link)) [
1342
+ n !== "network" && t("chart()", "'link' sets a network's link channels - it needs mark: 'network'");
1343
+ let r = Se(o);
1344
+ for (let [n, i] of Object.entries(e.link)) [
1345
1345
  "width",
1346
1346
  "color",
1347
1347
  "opacity",
1348
1348
  "flow",
1349
1349
  "tooltip"
1350
- ].includes(n) || l("chart()", `link has no '${n}' - link channels are width, color, opacity, flow, tooltip`), n !== "tooltip" && (p[n] = X(`link.${n}`, r, a, t));
1351
- e.link.tooltip !== void 0 && (p.tooltip = Ee(e.link.tooltip, {}, a, t));
1350
+ ].includes(n) || t("chart()", `link has no '${n}' - link channels are width, color, opacity, flow, tooltip`), n !== "tooltip" && (m[n] = X(`link.${n}`, i, o, r));
1351
+ e.link.tooltip !== void 0 && (m.tooltip = Ee(e.link.tooltip, {}, o, r));
1352
1352
  }
1353
- let m = {};
1353
+ let h = {};
1354
1354
  for (let t of Y) !J.includes(t) && ![
1355
1355
  "mark",
1356
1356
  "data",
1357
1357
  "encoding",
1358
1358
  "tooltip",
1359
1359
  "link"
1360
- ].includes(t) && e[t] !== void 0 && (m[t] = e[t]);
1361
- return m.steps !== void 0 && (!Number.isInteger(m.steps) || m.steps < 1) && l("chart()", `'steps' is how many steps the force layout takes, a whole number of 1 or more, got ${t(m.steps)}`), m.seed !== void 0 && g("chart()", "seed", m.seed), m.legend?.ticks !== void 0 && we("legend", m.legend.ticks), m.box === void 0 || Array.isArray(m.box) && m.box.length === 3 && m.box.every((e) => e > 0) || l("chart()", `'box' is the chart's size in the scene, [x, y, z] above 0, got ${t(m.box)}`), {
1360
+ ].includes(t) && e[t] !== void 0 && (h[t] = e[t]);
1361
+ return h.steps !== void 0 && (!Number.isInteger(h.steps) || h.steps < 1) && t("chart()", `'steps' is how many steps the force layout takes, a whole number of 1 or more, got ${r(h.steps)}`), h.seed !== void 0 && a("chart()", "seed", h.seed), h.legend?.ticks !== void 0 && we("legend", h.legend.ticks), h.box === void 0 || Array.isArray(h.box) && h.box.length === 3 && h.box.every((e) => e > 0) || t("chart()", `'box' is the chart's size in the scene, [x, y, z] above 0, got ${r(h.box)}`), {
1362
1362
  mark: n,
1363
1363
  rows: i,
1364
- links: a,
1365
- fields: o,
1366
- channels: c,
1367
- tooltip: f,
1368
- link: p,
1369
- options: m
1364
+ links: o,
1365
+ fields: s,
1366
+ channels: l,
1367
+ tooltip: p,
1368
+ link: m,
1369
+ options: h
1370
1370
  };
1371
1371
  }
1372
1372
  function be(e) {
1373
- let t = e;
1374
- if (t && typeof t == "object") {
1375
- for (let e of Object.keys(t)) e !== "type" && e !== "tooltip" && l("chart()", `mark option '${e}' isn't supported - use the chart's options (width, stack, ...) or style the chart's nodes`);
1376
- t = t.type;
1373
+ let n = e;
1374
+ if (n && typeof n == "object") {
1375
+ for (let e of Object.keys(n)) e !== "type" && e !== "tooltip" && t("chart()", `mark option '${e}' isn't supported - use the chart's options (width, stack, ...) or style the chart's nodes`);
1376
+ n = n.type;
1377
1377
  }
1378
- if (typeof t != "string" && l("chart()", `'mark' is required: one of ${q.map((e) => `'${e}'`).join(", ")}`), !q.includes(t)) {
1379
- let e = _e[t];
1380
- (t === "pie" || t === "arc" || t === "donut") && l("chart()", "pie and donut charts aren't supported - in 3D they distort values; use mark: 'bar'"), l("chart()", `mark '${t}' - ${e ? `use '${e}'` : `expected one of ${q.map((e) => `'${e}'`).join(", ")}${r(t, q)}`}`);
1378
+ if (typeof n != "string" && t("chart()", `'mark' is required: one of ${q.map((e) => `'${e}'`).join(", ")}`), !q.includes(n)) {
1379
+ let e = _e[n];
1380
+ (n === "pie" || n === "arc" || n === "donut") && t("chart()", "pie and donut charts aren't supported - in 3D they distort values; use mark: 'bar'"), t("chart()", `mark '${n}' - ${e ? `use '${e}'` : `expected one of ${q.map((e) => `'${e}'`).join(", ")}${d(n, q)}`}`);
1381
1381
  }
1382
- return t;
1382
+ return n;
1383
1383
  }
1384
1384
  function xe(e, n) {
1385
- if (e && typeof e == "object" && !Array.isArray(e) && "url" in e && l("chart()", "data: { url } isn't loaded for you - fetch the rows and pass data: rows"), n === "network") return e && Array.isArray(e.nodes) && Array.isArray(e.links) || l("chart()", `a network's data is { nodes: [...], links: [...] }, got ${t(e)}`), {
1385
+ if (e && typeof e == "object" && !Array.isArray(e) && "url" in e && t("chart()", "data: { url } isn't loaded for you - fetch the rows and pass data: rows"), n === "network") return e && Array.isArray(e.nodes) && Array.isArray(e.links) || t("chart()", `a network's data is { nodes: [...], links: [...] }, got ${r(e)}`), {
1386
1386
  rows: e.nodes,
1387
1387
  links: e.links
1388
1388
  };
1389
- let r = Array.isArray(e) ? e : e && Array.isArray(e.values) ? e.values : null;
1390
- return r || l("chart()", `'data' must be an array of rows (objects), or { values: [...] }, got ${t(e)}`), r.some((e) => !e || typeof e != "object") && l("chart()", "every row in 'data' must be an object, such as { month: 'Jan', sales: 41 }"), {
1391
- rows: r,
1389
+ let i = Array.isArray(e) ? e : e && Array.isArray(e.values) ? e.values : null;
1390
+ return i || t("chart()", `'data' must be an array of rows (objects), or { values: [...] }, got ${r(e)}`), i.some((e) => !e || typeof e != "object") && t("chart()", "every row in 'data' must be an object, such as { month: 'Jan', sales: 41 }"), {
1391
+ rows: i,
1392
1392
  links: []
1393
1393
  };
1394
1394
  }
@@ -1403,7 +1403,7 @@ function Ce(e, t) {
1403
1403
  }
1404
1404
  function X(e, n, i, a) {
1405
1405
  let o = "chart()", s;
1406
- if (typeof n == "string") a.includes(n) ? s = { field: n } : /color|colour/.test(e) && Te(n) ? s = { value: n } : l(o, `${e}: field '${n}' isn't in the data - fields are ${a.join(", ") || "(none)"}${r(n, a)}`);
1406
+ if (typeof n == "string") a.includes(n) ? s = { field: n } : /color|colour/.test(e) && Te(n) ? s = { value: n } : t(o, `${e}: field '${n}' isn't in the data - fields are ${a.join(", ") || "(none)"}${d(n, a)}`);
1407
1407
  else if (typeof n == "number" && [
1408
1408
  "size",
1409
1409
  "opacity",
@@ -1413,37 +1413,37 @@ function X(e, n, i, a) {
1413
1413
  ].includes(e)) s = { value: n };
1414
1414
  else if (n && typeof n == "object" && !Array.isArray(n)) {
1415
1415
  s = n;
1416
- for (let t of Object.keys(s)) he.includes(t) || l(o, `${e}: '${t}' - ${ve[t] ?? `unknown; a channel takes ${he.join(", ")}`}`);
1417
- s.field !== void 0 && !a.includes(s.field) && l(o, `${e}: field '${s.field}' isn't in the data - fields are ${a.join(", ") || "(none)"}${r(String(s.field), a)}`), s.field === void 0 && s.value === void 0 && l(o, `${e} needs a field (or a constant value)`);
1418
- } else return e === "size" && Array.isArray(n) && l(o, "'size' is a channel - the chart's size in the scene is 'box: [x, y, z]'"), l(o, `${e} must be a field name or { field, ... }, got ${t(n)}`);
1416
+ for (let n of Object.keys(s)) he.includes(n) || t(o, `${e}: '${n}' - ${ve[n] ?? `unknown; a channel takes ${he.join(", ")}`}`);
1417
+ s.field !== void 0 && !a.includes(s.field) && t(o, `${e}: field '${s.field}' isn't in the data - fields are ${a.join(", ") || "(none)"}${d(String(s.field), a)}`), s.field === void 0 && s.value === void 0 && t(o, `${e} needs a field (or a constant value)`);
1418
+ } else return e === "size" && Array.isArray(n) && t(o, "'size' is a channel - the chart's size in the scene is 'box: [x, y, z]'"), t(o, `${e} must be a field name or { field, ... }, got ${r(n)}`);
1419
1419
  s.axis?.ticks !== void 0 && we(`${e}: axis`, s.axis.ticks);
1420
- let c = s.field ?? null, u = s.type ?? (c ? Ce(i, c) : "nominal");
1420
+ let c = s.field ?? null, l = s.type ?? (c ? Ce(i, c) : "nominal");
1421
1421
  [
1422
1422
  "quantitative",
1423
1423
  "nominal",
1424
1424
  "ordinal",
1425
1425
  "temporal"
1426
- ].includes(u) || l(o, `${e}: type '${u}' - expected 'quantitative', 'nominal', 'ordinal' or 'temporal'${r(String(u), [
1426
+ ].includes(l) || t(o, `${e}: type '${l}' - expected 'quantitative', 'nominal', 'ordinal' or 'temporal'${d(String(l), [
1427
1427
  "quantitative",
1428
1428
  "nominal",
1429
1429
  "ordinal",
1430
1430
  "temporal"
1431
1431
  ])}`);
1432
- let d = c === null ? () => s.value : u === "temporal" ? (e) => I(e[c]) : (e) => e[c];
1432
+ let u = c === null ? () => s.value : l === "temporal" ? (e) => I(e[c]) : (e) => e[c];
1433
1433
  return {
1434
1434
  field: c,
1435
1435
  value: s.value,
1436
- type: u,
1436
+ type: l,
1437
1437
  title: s.title ?? c ?? e,
1438
1438
  format: s.format,
1439
1439
  scale: s.scale ?? {},
1440
1440
  axis: s.axis ?? {},
1441
- get: d,
1441
+ get: u,
1442
1442
  priority: s.priority
1443
1443
  };
1444
1444
  }
1445
1445
  function we(e, n) {
1446
- Array.isArray(n) || Number.isInteger(n) && n > 0 || l("chart()", `${e} ticks are a list of the values to mark, such as [0, 25, 50, 75, 100], or about how many, got ${t(n)}`);
1446
+ Array.isArray(n) || Number.isInteger(n) && n > 0 || t("chart()", `${e} ticks are a list of the values to mark, such as [0, 25, 50, 75, 100], or about how many, got ${r(n)}`);
1447
1447
  }
1448
1448
  function Te(e) {
1449
1449
  try {
@@ -1470,7 +1470,7 @@ function Oe() {
1470
1470
  e.id = "phoria-chart-style", e.textContent = De, document.head.prepend(e);
1471
1471
  }
1472
1472
  // src/charts/Chart.js
1473
- var ke = m.filter((e) => ![
1473
+ var ke = g.filter((e) => ![
1474
1474
  "children",
1475
1475
  "tooltip",
1476
1476
  "highlight"
@@ -1478,10 +1478,10 @@ var ke = m.filter((e) => ![
1478
1478
  function Ae(e) {
1479
1479
  return new Z(e);
1480
1480
  }
1481
- var Z = class e extends p {
1481
+ var Z = class e extends h {
1482
1482
  static type = "chart";
1483
1483
  static get OPTIONS() {
1484
- return m;
1484
+ return g;
1485
1485
  }
1486
1486
  scales = {};
1487
1487
  #e;
@@ -1497,10 +1497,10 @@ var Z = class e extends p {
1497
1497
  #u = null;
1498
1498
  #d = null;
1499
1499
  constructor(e) {
1500
- (!e || typeof e != "object" || Array.isArray(e)) && l("chart()", `expected a spec such as { mark: 'bar', data, x, y }, got ${t(e)}`);
1501
- let n = {}, r = {};
1502
- for (let [t, i] of Object.entries(e)) (ke.includes(t) ? n : r)[t] = i;
1503
- e.children && l("chart()", "a chart makes its own children - add other nodes to a Group beside it"), super(n), Oe(), this.#e = r, this.#i = {}, this.#f(!0), this.onUpdate((e, t) => this.#_(t));
1500
+ (!e || typeof e != "object" || Array.isArray(e)) && t("chart()", `expected a spec such as { mark: 'bar', data, x, y }, got ${r(e)}`);
1501
+ let n = {}, i = {};
1502
+ for (let [t, r] of Object.entries(e)) (ke.includes(t) ? n : i)[t] = r;
1503
+ e.children && t("chart()", "a chart makes its own children - add other nodes to a Group beside it"), super(n), Oe(), this.#e = i, this.#i = {}, this.#f(!0), this.onUpdate((e, t) => this.#_(t));
1504
1504
  }
1505
1505
  get spec() {
1506
1506
  let e = this.#t;
@@ -1527,7 +1527,7 @@ var Z = class e extends p {
1527
1527
  }, this.#f(!0), this;
1528
1528
  }
1529
1529
  filter(e) {
1530
- return e !== null && typeof e != "function" && l("Chart", `filter() takes (row) => boolean, or null, got ${t(e)}`), this.#c = e, this.#f(!0), this;
1530
+ return e !== null && typeof e != "function" && t("Chart", `filter() takes (row) => boolean, or null, got ${r(e)}`), this.#c = e, this.#f(!0), this;
1531
1531
  }
1532
1532
  explain() {
1533
1533
  let e = this.#t, t = [
@@ -1540,6 +1540,18 @@ var Z = class e extends p {
1540
1540
  }), n = this.#u?.rows.length ?? 0;
1541
1541
  return `Chart (${e.mark}): ${n} of ${e.rows.length} rows shown${t.length ? `; ${t.join(", ")}` : ""}${e.links.length ? `; ${e.links.length} links` : ""}`;
1542
1542
  }
1543
+ summary() {
1544
+ let e = this.#t, t = e.options;
1545
+ if (t.description) return String(t.description);
1546
+ let n = [...new Set([
1547
+ "x",
1548
+ "y",
1549
+ "z",
1550
+ "color",
1551
+ "size"
1552
+ ].map((t) => e.channels[t]).filter((e) => e?.field).map((e) => e.title))], r = (e, t) => `${e} ${e === 1 ? t : `${t}s`}`, i = `${e.mark} chart of ${r(e.rows.length, "row")}${n.length ? ` by ${n.join(", ")}` : ""}${e.links.length ? ` and ${r(e.links.length, "link")}` : ""}`;
1553
+ return t.title ? `${t.title}: ${i}` : i;
1554
+ }
1543
1555
  jsonOptions() {
1544
1556
  return { ...this.#e };
1545
1557
  }
@@ -1567,89 +1579,89 @@ var Z = class e extends p {
1567
1579
  return m.userData = structuredClone(this.userData), m.matrixAutoUpdate = this.matrixAutoUpdate, m.matrixAutoUpdate || m.matrix.copy(this.matrix), m;
1568
1580
  }
1569
1581
  #f(e) {
1570
- let t = ye(this.#e), n = t.options, r = t.channels;
1571
- this.#t = t;
1572
- let i = n.box ?? Ne(t), a = n.theme ?? "dark";
1573
- a !== "dark" && a !== "light" && l("chart()", `theme '${a}' - expected 'dark' or 'light'`);
1574
- let o = n.overlap ?? "dim";
1582
+ let n = ye(this.#e), r = n.options, a = n.channels;
1583
+ this.#t = n;
1584
+ let o = r.box ?? Ne(n), s = r.theme ?? "dark";
1585
+ s !== "dark" && s !== "light" && t("chart()", `theme '${s}' - expected 'dark' or 'light'`);
1586
+ let l = r.overlap ?? "dim";
1575
1587
  [
1576
1588
  "dim",
1577
1589
  "hide",
1578
1590
  "show"
1579
- ].includes(o) || l("chart()", `overlap '${o}' - expected 'dim', 'hide' or 'show'`);
1580
- let s = t.rows.filter((e) => (!this.#c || this.#c(e)) && (!r.color?.field || !this.#s.has(String(r.color.get(e)))));
1581
- this.scales = Le(t, i);
1582
- let u = this.scales.color, d = c.fromInput(r.color?.field ? L.category[0] : r.color?.value ?? L.category[0], "chart()").toSRGB(), f = t.link.color?.field ? Fe(t.link.color, t.links.map((e) => t.link.color.get(e))) : null;
1591
+ ].includes(l) || t("chart()", `overlap '${l}' - expected 'dim', 'hide' or 'show'`);
1592
+ let u = n.rows.filter((e) => (!this.#c || this.#c(e)) && (!a.color?.field || !this.#s.has(String(a.color.get(e)))));
1593
+ this.scales = Le(n, o);
1594
+ let d = this.scales.color, f = c.fromInput(a.color?.field ? L.category[0] : a.color?.value ?? L.category[0], "chart()").toSRGB(), p = n.link.color?.field ? Fe(n.link.color, n.links.map((e) => n.link.color.get(e))) : null;
1583
1595
  Object.assign(this.#i, {
1584
- spec: t,
1585
- box: i,
1586
- theme: a,
1587
- overlap: o,
1596
+ spec: n,
1597
+ box: o,
1598
+ theme: s,
1599
+ overlap: l,
1588
1600
  scales: this.scales,
1589
1601
  size: this.scales.size ?? null,
1590
- rgb: (e) => u ? u(Ie(t, e)).toSRGB() : d,
1602
+ rgb: (e) => d ? d(Ie(n, e)).toSRGB() : f,
1591
1603
  format: $,
1592
- linkColor: (e) => f(e)
1604
+ linkColor: (e) => p(e)
1593
1605
  });
1594
- let p = JSON.stringify([
1595
- t.mark,
1596
- Object.entries(r).map(([e, t]) => [
1606
+ let m = JSON.stringify([
1607
+ n.mark,
1608
+ Object.entries(a).map(([e, t]) => [
1597
1609
  e,
1598
1610
  t.field,
1599
1611
  t.type
1600
1612
  ]),
1601
- i,
1602
- a,
1603
1613
  o,
1604
- n.stack,
1605
- n.layout,
1606
- n.flat,
1607
- Object.keys(t.link)
1614
+ s,
1615
+ l,
1616
+ r.stack,
1617
+ r.layout,
1618
+ r.flat,
1619
+ Object.keys(n.link)
1608
1620
  ]);
1609
- if (p !== this.#r) {
1610
- this.#r = p, this.#n && this.remove(...this.#n.nodes), this.#n = Me(t.mark, this.#i);
1621
+ if (m !== this.#r) {
1622
+ this.#r = m, this.#n && this.remove(...this.#n.nodes), this.#n = Me(n.mark, this.#i);
1611
1623
  for (let e of this.#n.nodes) this.add(e);
1612
1624
  this.#l = this.#u = null, this.#d = null;
1613
1625
  }
1614
- this.#a && this.remove(this.#a), this.#a = t.mark === "network" && n.layout !== "given" ? null : this.add(S({
1615
- box: i,
1616
- theme: a,
1617
- overlap: o,
1618
- axes: ze(t, this.scales)
1619
- })), this.#o && this.remove(this.#o), this.#o = n.title ? this.add(new _({
1620
- text: String(n.title),
1626
+ this.#a && this.remove(this.#a), this.#a = n.mark === "network" && r.layout !== "given" ? null : this.add(S({
1627
+ box: o,
1628
+ theme: s,
1629
+ overlap: l,
1630
+ axes: ze(n, this.scales)
1631
+ })), this.#o && this.remove(this.#o), this.#o = r.title ? this.add(new i({
1632
+ text: String(r.title),
1621
1633
  position: [
1622
1634
  0,
1623
- i[1] * 1.12,
1624
- -i[2] / 2
1635
+ o[1] * 1.12,
1636
+ -o[2] / 2
1625
1637
  ],
1626
- className: `phoria-axis-title phoria-${a}`,
1638
+ className: `phoria-axis-title phoria-${s}`,
1627
1639
  overlap: "show"
1628
- })) : null, this.#p(t, a), this.tooltip = t.tooltip === null && !t.link.tooltip ? null : (e) => this.#m(e);
1629
- let m = n.highlight;
1630
- this.highlight = m === !1 ? null : c.fromInput(m === void 0 || m === "neighbours" || m === "node" ? "#ffffff" : m, "chart()"), this.#h(this.#n.layout(s), e && n.transition !== !1);
1640
+ })) : null, this.#p(n, s), this.tooltip = n.tooltip === null && !n.link.tooltip ? null : (e) => this.#m(e);
1641
+ let h = r.highlight;
1642
+ this.highlight = h === !1 ? null : c.fromInput(h === void 0 || h === "neighbours" || h === "node" ? "#ffffff" : h, "chart()"), this.#h(this.#n.layout(u), e && r.transition !== !1);
1631
1643
  }
1632
1644
  #p(e, n) {
1633
1645
  this.overlay?.remove(), this.overlay = null;
1634
- let r = e.channels.color, i = e.options.legend;
1635
- if (!r?.field || i === !1 || !this.scales.color || typeof document > "u") return;
1636
- let a = ie(this.scales.color, {
1637
- title: r.title,
1646
+ let i = e.channels.color, a = e.options.legend;
1647
+ if (!i?.field || a === !1 || !this.scales.color || typeof document > "u") return;
1648
+ let o = ie(this.scales.color, {
1649
+ title: i.title,
1638
1650
  theme: n,
1639
- position: i?.position,
1640
- ticks: i?.ticks,
1641
- format: (e) => $(r, e),
1651
+ position: a?.position,
1652
+ ticks: a?.ticks,
1653
+ format: (e) => $(i, e),
1642
1654
  onToggle: (e, t) => {
1643
1655
  t ? this.#s.delete(String(e)) : this.#s.add(String(e)), this.#f(!0);
1644
1656
  }
1645
1657
  });
1646
- a.querySelectorAll(".phoria-legend-item").forEach((e, t) => {
1658
+ o.querySelectorAll(".phoria-legend-item").forEach((e, t) => {
1647
1659
  this.#s.has(String(this.scales.color?.domain[t])) && e.classList.add("off");
1648
1660
  });
1649
- let o = i?.container;
1650
- if (o) {
1651
- let e = typeof o == "string" ? document.querySelector(o) : o;
1652
- e || l("chart()", `legend container ${t(o)} not found`), a.classList.remove(`phoria-legend-${i?.position ?? "top-right"}`), Object.assign(a.style, {
1661
+ let s = a?.container;
1662
+ if (s) {
1663
+ let e = typeof s == "string" ? document.querySelector(s) : s;
1664
+ e || t("chart()", `legend container ${r(s)} not found`), o.classList.remove(`phoria-legend-${a?.position ?? "top-right"}`), Object.assign(o.style, {
1653
1665
  position: "static",
1654
1666
  flexDirection: "row",
1655
1667
  flexWrap: "wrap",
@@ -1657,8 +1669,8 @@ var Z = class e extends p {
1657
1669
  columnGap: "12px",
1658
1670
  maxHeight: "none",
1659
1671
  overflow: "visible"
1660
- }), e.replaceChildren(a);
1661
- } else this.overlay = a;
1672
+ }), e.replaceChildren(o);
1673
+ } else this.overlay = o;
1662
1674
  }
1663
1675
  #m(e) {
1664
1676
  let t = this.#t, n = e.datum;
@@ -1714,18 +1726,19 @@ var Z = class e extends p {
1714
1726
  this.#n.apply(e, t), this.#l = e.slice(), this.#u = n;
1715
1727
  }
1716
1728
  #_(e) {
1717
- this.#n?.tick?.(e);
1718
- let t = this.#d;
1719
- if (!t) return;
1720
- let n = this.#e.transition ?? {}, r = n.duration ?? .5, i = o[n.ease ?? "out"];
1721
- i || l("chart()", `transition ease '${n.ease}' - expected ${Object.keys(o).map((e) => `'${e}'`).join(", ")}`), t.t = Math.min(1, t.t + e / r);
1722
- let a = i(t.t), s = new Float32Array(t.from.length);
1723
- for (let e = 0; e < s.length; e++) s[e] = t.from[e] + (t.to[e] - t.from[e]) * a;
1724
- if (t.t < 1) return this.#g(s, t.frame, t.frame);
1725
- this.#d = null, this.#g(t.final.state, t.final, t.final);
1729
+ let n = this.root.motionReduced === !0;
1730
+ n || this.#n?.tick?.(e);
1731
+ let r = this.#d;
1732
+ if (!r) return;
1733
+ let i = this.#e.transition ?? {}, a = i.duration ?? .5, s = o[i.ease ?? "out"];
1734
+ s || t("chart()", `transition ease '${i.ease}' - expected ${Object.keys(o).map((e) => `'${e}'`).join(", ")}`), r.t = n ? 1 : Math.min(1, r.t + e / a);
1735
+ let c = s(r.t), l = new Float32Array(r.from.length);
1736
+ for (let e = 0; e < l.length; e++) l[e] = r.from[e] + (r.to[e] - r.from[e]) * c;
1737
+ if (r.t < 1) return this.#g(l, r.frame, r.frame);
1738
+ this.#d = null, this.#g(r.final.state, r.final, r.final);
1726
1739
  }
1727
1740
  };
1728
- f(Z);
1741
+ m(Z);
1729
1742
  function je(e, t) {
1730
1743
  let n = (e) => JSON.stringify(e ? {
1731
1744
  lengths: e.lengths,