expressive-charts 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +14 -13
  3. package/dist/{chunk-N5IF2RO2.js → chunk-7A7LXXT4.js} +6 -2
  4. package/dist/chunk-7A7LXXT4.js.map +1 -0
  5. package/dist/{chunk-ZIGBM4NY.js → chunk-CJUQHEX6.js} +92 -28
  6. package/dist/chunk-CJUQHEX6.js.map +1 -0
  7. package/dist/{chunk-CVXP2L2J.js → chunk-N2BLUETM.js} +17 -5
  8. package/dist/chunk-N2BLUETM.js.map +1 -0
  9. package/dist/{drawing-Du6DAgrW.d.cts → drawing-CdTgixMY.d.cts} +20 -2
  10. package/dist/{drawing-Du6DAgrW.d.ts → drawing-CdTgixMY.d.ts} +20 -2
  11. package/dist/{effect-dPmXiWlL.d.cts → effect-Bu3MHHeg.d.ts} +4 -2
  12. package/dist/{effect-OcyvtfZi.d.ts → effect-D4vmdYP4.d.cts} +4 -2
  13. package/dist/expressive-charts.css +11 -6
  14. package/dist/expressive-charts.css.d.cts +2 -0
  15. package/dist/expressive-charts.css.d.ts +2 -0
  16. package/dist/expressive-charts.global.js +29 -24
  17. package/dist/expressive-charts.global.js.map +1 -1
  18. package/dist/icons/sport.cjs +5 -1
  19. package/dist/icons/sport.cjs.map +1 -1
  20. package/dist/icons/sport.js +2 -2
  21. package/dist/index.cjs +1610 -669
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +143 -18
  24. package/dist/index.d.ts +143 -18
  25. package/dist/index.js +1448 -591
  26. package/dist/index.js.map +1 -1
  27. package/dist/testing.cjs +93 -42
  28. package/dist/testing.cjs.map +1 -1
  29. package/dist/testing.d.cts +2 -2
  30. package/dist/testing.d.ts +2 -2
  31. package/dist/testing.js +6 -8
  32. package/dist/testing.js.map +1 -1
  33. package/package.json +16 -4
  34. package/dist/chunk-CVXP2L2J.js.map +0 -1
  35. package/dist/chunk-N5IF2RO2.js.map +0 -1
  36. package/dist/chunk-ZIGBM4NY.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -33,6 +33,7 @@ __export(src_exports, {
33
33
  defineDataEffect: () => defineDataEffect,
34
34
  defineEffect: () => defineEffect,
35
35
  defineIcon: () => defineIcon,
36
+ delta: () => delta,
36
37
  describe: () => describe,
37
38
  donutChart: () => donutChart2,
38
39
  easeInOutCubic: () => easeInOutCubic,
@@ -46,8 +47,10 @@ __export(src_exports, {
46
47
  interpolateNumber: () => interpolateNumber,
47
48
  interpolatePoint: () => interpolatePoint,
48
49
  interpolateRecord: () => interpolateRecord,
50
+ label: () => label,
49
51
  lineChart: () => lineChart2,
50
52
  linear: () => linear,
53
+ link: () => link,
51
54
  manualClock: () => manualClock,
52
55
  matrix: () => matrix,
53
56
  mediaReducedMotion: () => mediaReducedMotion,
@@ -68,6 +71,7 @@ __export(src_exports, {
68
71
  sequence: () => sequence,
69
72
  stagger: () => stagger,
70
73
  threshold: () => threshold,
74
+ trace: () => trace,
71
75
  travel: () => travel,
72
76
  tween: () => tween,
73
77
  wiggle: () => wiggle
@@ -742,7 +746,8 @@ function pathData(segments, closed = false) {
742
746
 
743
747
  // src/core/geometry/walk.ts
744
748
  var clamp01 = (t) => t > 0 ? t < 1 ? t : 1 : 0;
745
- function createWalk(segments) {
749
+ var NONE = Object.freeze([]);
750
+ function createWalk(segments, gaps = NONE) {
746
751
  const first = segments[0];
747
752
  const last = segments[segments.length - 1];
748
753
  if (!first || !last) throw new RangeError("A walk needs at least one segment.");
@@ -774,40 +779,54 @@ function createWalk(segments) {
774
779
  const { index, u } = locate(at * length);
775
780
  return pointOn(segments[index], u);
776
781
  };
782
+ const draw = (from, to) => {
783
+ let d = moveTo(point(from));
784
+ const a = from * length;
785
+ const b = to * length;
786
+ if (!(b > a)) return d;
787
+ const first2 = locate(a);
788
+ for (let i = first2.index; i < segments.length && cumulative[i] < b; i++) {
789
+ const segment = segments[i];
790
+ if (!(segment.length > 0)) continue;
791
+ const u0 = i === first2.index ? first2.u : 0;
792
+ const u1 = cumulative[i + 1] > b ? Math.min(1, (b - cumulative[i]) / segment.length) : 1;
793
+ if (u1 > u0) d += drawTo(segment, u0, u1);
794
+ }
795
+ return d;
796
+ };
797
+ const slice = (t0, t1) => {
798
+ const from = clamp01(Math.min(t0, t1));
799
+ const to = clamp01(Math.max(t0, t1));
800
+ if (gaps.length === 0) return draw(from, to);
801
+ let d = "";
802
+ let at = from;
803
+ for (const [a, b] of gaps) {
804
+ if (a >= to) break;
805
+ if (a > at) d += draw(at, a);
806
+ if (b > at) at = b;
807
+ }
808
+ if (to > at) d += draw(at, to);
809
+ return d === "" ? moveTo(point(from)) : d;
810
+ };
777
811
  return {
778
812
  segments,
779
813
  length,
780
814
  start,
781
815
  end,
816
+ gaps,
782
817
  point,
783
818
  angle(t) {
784
819
  const { index, u } = locate(clamp01(t) * length);
785
820
  return angleOn(segments[index], u);
786
821
  },
787
- slice(t0, t1) {
788
- const from = clamp01(Math.min(t0, t1));
789
- const to = clamp01(Math.max(t0, t1));
790
- let d = moveTo(point(from));
791
- const a = from * length;
792
- const b = to * length;
793
- if (!(b > a)) return d;
794
- const first2 = locate(a);
795
- for (let i = first2.index; i < segments.length && cumulative[i] < b; i++) {
796
- const segment = segments[i];
797
- if (!(segment.length > 0)) continue;
798
- const u0 = i === first2.index ? first2.u : 0;
799
- const u1 = cumulative[i + 1] > b ? Math.min(1, (b - cumulative[i]) / segment.length) : 1;
800
- if (u1 > u0) d += drawTo(segment, u0, u1);
801
- }
802
- return d;
803
- },
804
- d: pathData(segments)
822
+ slice,
823
+ d: gaps.length === 0 ? pathData(segments) : slice(0, 1)
805
824
  };
806
825
  }
807
826
 
808
827
  // src/core/geometry/outline.ts
809
828
  function closedOutline(sides) {
810
- const walks = sides.map(createWalk);
829
+ const walks = sides.map((side) => createWalk(side));
811
830
  return {
812
831
  d: pathData(sides.flat(), true),
813
832
  closed: true,
@@ -843,7 +862,7 @@ function checkCount(n, multiple) {
843
862
  }
844
863
 
845
864
  // src/core/geometry/describe/mark.ts
846
- function assemble({ key, series, walk, thickness, outline: outline2, bounds, center, pivot, segments }) {
865
+ function assemble({ key, series, walk, thickness, outline: outline2, bounds, center, pivot, labelBounds, segments }) {
847
866
  return {
848
867
  key,
849
868
  ...series === void 0 ? {} : { series },
@@ -853,11 +872,13 @@ function assemble({ key, series, walk, thickness, outline: outline2, bounds, cen
853
872
  path: (t) => walk.point(t),
854
873
  angle: (t) => walk.angle(t),
855
874
  slice: (t0, t1) => walk.slice(t0, t1),
875
+ ...walk.gaps.length === 0 ? {} : { gaps: walk.gaps },
856
876
  thickness,
857
877
  outline: outline2,
858
878
  bounds,
859
879
  center,
860
880
  pivot,
881
+ ...labelBounds === void 0 ? {} : { labelBounds },
861
882
  ...segments === void 0 ? {} : { segments }
862
883
  };
863
884
  }
@@ -865,6 +886,18 @@ function finite(builder, field, value) {
865
886
  if (!Number.isFinite(value)) throw new RangeError(`describe.${builder}: ${field} must be a finite number, got ${value}.`);
866
887
  return value;
867
888
  }
889
+ function labelBoxes(builder, boxes) {
890
+ if (!boxes) return boxes;
891
+ for (let i = 0; i < boxes.length; i++) {
892
+ const { x, y, width, height } = boxes[i];
893
+ if (Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(width) && width >= 0 && Number.isFinite(height) && height >= 0) continue;
894
+ finite(builder, `labelBounds[${i}].x`, x);
895
+ finite(builder, `labelBounds[${i}].y`, y);
896
+ size(builder, `labelBounds[${i}].width`, width);
897
+ size(builder, `labelBounds[${i}].height`, height);
898
+ }
899
+ return boxes;
900
+ }
868
901
  function size(builder, field, value) {
869
902
  if (!(Number.isFinite(value) && value >= 0)) {
870
903
  throw new RangeError(`describe.${builder}: ${field} must be a finite number \u2265 0, got ${value}.`);
@@ -899,7 +932,8 @@ function describeArc(spec) {
899
932
  outline: closedOutline(sides),
900
933
  bounds: boundsOf(sides.flat().flatMap(extremes)),
901
934
  center: walk.point(0.5),
902
- pivot: center
935
+ pivot: center,
936
+ labelBounds: labelBoxes("arc", spec.labelBounds)
903
937
  });
904
938
  }
905
939
 
@@ -916,6 +950,7 @@ function describeBar(spec) {
916
950
  size("bar", "height", height);
917
951
  const radius = size("bar", "radius", spec.radius ?? 0);
918
952
  const gap = size("bar", "gap", spec.gap ?? 0);
953
+ const labelBounds = labelBoxes("bar", spec.labelBounds);
919
954
  const horizontal = baseline === "left" || baseline === "right";
920
955
  const length = horizontal ? width : height;
921
956
  const thickness = horizontal ? height : width;
@@ -968,7 +1003,7 @@ function describeBar(spec) {
968
1003
  })
969
1004
  )
970
1005
  );
971
- return part(0, length, radius, { key, series, bounds: { x, y, width, height }, segments });
1006
+ return part(0, length, radius, { key, series, bounds: { x, y, width, height }, labelBounds, segments });
972
1007
  }
973
1008
  function frame({ x, y, width: w, height: h, baseline }) {
974
1009
  switch (baseline) {
@@ -993,12 +1028,13 @@ function describeLine(spec) {
993
1028
  finite("line", `points[${i}].x`, p.x);
994
1029
  finite("line", `points[${i}].y`, p.y);
995
1030
  });
1031
+ const breaks = checkBreaks(spec.breaks, points.length);
996
1032
  const segments = [];
997
1033
  for (let i = 1; i < points.length; i++) {
998
1034
  segments.push(line(points[i - 1], points[i], segments[segments.length - 1]?.angle ?? 0));
999
1035
  }
1000
1036
  if (segments.length === 0) segments.push(line(first, first));
1001
- const walk = createWalk(segments);
1037
+ const walk = createWalk(segments, gapsAt(breaks, segments));
1002
1038
  const box = boundsOf(points);
1003
1039
  const pad = width / 2;
1004
1040
  return assemble({
@@ -1009,9 +1045,29 @@ function describeLine(spec) {
1009
1045
  outline: openOutline(walk),
1010
1046
  bounds: { x: box.x - pad, y: box.y - pad, width: box.width + width, height: box.height + width },
1011
1047
  center: walk.point(0.5),
1012
- pivot: first
1048
+ pivot: first,
1049
+ labelBounds: labelBoxes("line", spec.labelBounds)
1050
+ });
1051
+ }
1052
+ function gapsAt(breaks, segments) {
1053
+ const along = [0];
1054
+ for (const segment of segments) along.push(along[along.length - 1] + segment.length);
1055
+ const length = along[along.length - 1];
1056
+ return breaks.filter((i) => along[i] > along[i - 1]).map((i) => [along[i - 1] / length, along[i] / length]);
1057
+ }
1058
+ function checkBreaks(breaks, count) {
1059
+ if (breaks === void 0) return [];
1060
+ if (!Array.isArray(breaks)) throw new RangeError(`describe.line: breaks must be an array of point indices, got ${show(breaks)}.`);
1061
+ let after = 0;
1062
+ breaks.forEach((index, i) => {
1063
+ if (!(Number.isInteger(index) && index > after && index < count)) {
1064
+ throw new RangeError(`describe.line: breaks[${i}] must be a whole number more than ${after} and less than ${count}, the number of points, got ${show(index)}.`);
1065
+ }
1066
+ after = index;
1013
1067
  });
1068
+ return breaks;
1014
1069
  }
1070
+ var show = (value) => typeof value === "string" ? JSON.stringify(value) : String(value);
1015
1071
 
1016
1072
  // src/core/geometry/describe/point.ts
1017
1073
  function describePoint(spec) {
@@ -1032,7 +1088,8 @@ function describePoint(spec) {
1032
1088
  ]),
1033
1089
  bounds: { x: center.x - r, y: center.y - r, width: 2 * r, height: 2 * r },
1034
1090
  center,
1035
- pivot: center
1091
+ pivot: center,
1092
+ labelBounds: labelBoxes("point", spec.labelBounds)
1036
1093
  });
1037
1094
  }
1038
1095
 
@@ -1090,7 +1147,7 @@ function invert(m) {
1090
1147
  return [d / det, -b / det, -c / det, a / det, (c * f - d * e) / det, (b * e - a * f) / det];
1091
1148
  }
1092
1149
  function parseTransform(source) {
1093
- const parts = [];
1150
+ const parts2 = [];
1094
1151
  for (const [, name, rawArgs = ""] of source.matchAll(/(matrix|translate|scale|rotate|skewX|skewY)\s*\(([^)]*)\)/g)) {
1095
1152
  const args = rawArgs.trim().split(/[\s,]+/).filter(Boolean).map(Number);
1096
1153
  if (!args.every(Number.isFinite)) continue;
@@ -1098,26 +1155,26 @@ function parseTransform(source) {
1098
1155
  const radians = (degrees) => degrees * Math.PI / 180;
1099
1156
  switch (name) {
1100
1157
  case "matrix":
1101
- if (args.length === 6) parts.push([a, b, c, d, e, f]);
1158
+ if (args.length === 6) parts2.push([a, b, c, d, e, f]);
1102
1159
  break;
1103
1160
  case "translate":
1104
- parts.push(translate(a, b ?? 0));
1161
+ parts2.push(translate(a, b ?? 0));
1105
1162
  break;
1106
1163
  case "scale":
1107
- parts.push(scale(a, b ?? a));
1164
+ parts2.push(scale(a, b ?? a));
1108
1165
  break;
1109
1166
  case "rotate":
1110
- parts.push(rotate(radians(a), b !== void 0 && c !== void 0 ? { x: b, y: c } : void 0));
1167
+ parts2.push(rotate(radians(a), b !== void 0 && c !== void 0 ? { x: b, y: c } : void 0));
1111
1168
  break;
1112
1169
  case "skewX":
1113
- parts.push([1, 0, Math.tan(radians(a)), 1, 0, 0]);
1170
+ parts2.push([1, 0, Math.tan(radians(a)), 1, 0, 0]);
1114
1171
  break;
1115
1172
  case "skewY":
1116
- parts.push([1, Math.tan(radians(a)), 0, 1, 0, 0]);
1173
+ parts2.push([1, Math.tan(radians(a)), 0, 1, 0, 0]);
1117
1174
  break;
1118
1175
  }
1119
1176
  }
1120
- return multiply(...parts);
1177
+ return multiply(...parts2);
1121
1178
  }
1122
1179
  function offset(point, angle, distance3) {
1123
1180
  return { x: point.x + distance3 * Math.cos(angle), y: point.y + distance3 * Math.sin(angle) };
@@ -1140,7 +1197,18 @@ function samplesAlong(mark, points) {
1140
1197
  });
1141
1198
  const n = mark.length > 0 ? Math.min(MAX_GRID, Math.ceil(mark.length) + 1) : 1;
1142
1199
  const grid = Array.from({ length: n }, (_, i) => mark.path(n === 1 ? 0 : i / (n - 1)));
1143
- return points.map((p, index) => ({ index, sample: { t: nearest(mark, grid, p), value: p.value, ...p.at === void 0 ? {} : { at: p.at } } })).sort((a, b) => a.sample.t - b.sample.t || a.index - b.index).map(({ sample }) => sample);
1200
+ const samples = points.map((p, index) => ({ index, sample: { t: nearest(mark, grid, p), value: p.value, ...p.at === void 0 ? {} : { at: p.at } } })).sort((a, b) => a.sample.t - b.sample.t || a.index - b.index).map(({ sample }) => sample);
1201
+ return mark.gaps && mark.gaps.length > 0 ? gapped(samples, mark.gaps) : samples;
1202
+ }
1203
+ function gapped(samples, gaps) {
1204
+ const middles = gaps.map(([from, to]) => (from + to) / 2).sort((a, b) => a - b);
1205
+ let next = 0;
1206
+ return samples.map((sample, k) => {
1207
+ if (k === 0) return sample;
1208
+ const before = samples[k - 1].t;
1209
+ while (next < middles.length && middles[next] <= before) next++;
1210
+ return next < middles.length && middles[next] <= sample.t ? { ...sample, gapBefore: true } : sample;
1211
+ });
1144
1212
  }
1145
1213
  function nearest(mark, grid, p) {
1146
1214
  const n = grid.length;
@@ -1265,9 +1333,9 @@ function runScope(options) {
1265
1333
  batch: options.batch,
1266
1334
  ...options.previous ? { previous: options.previous } : {},
1267
1335
  tween(tweenOptions) {
1268
- const own = tweenOptions.signal;
1269
- const running = tween({ ...tweenOptions, signal: own ?? controller.signal }, { clock, motion: motion2 });
1270
- if (own && own !== controller.signal) {
1336
+ const own2 = tweenOptions.signal;
1337
+ const running = tween({ ...tweenOptions, signal: own2 ?? controller.signal }, { clock, motion: motion2 });
1338
+ if (own2 && own2 !== controller.signal) {
1271
1339
  if (controller.signal.aborted) running.cancel();
1272
1340
  else controller.signal.addEventListener("abort", () => running.cancel(), { once: true });
1273
1341
  }
@@ -1321,7 +1389,7 @@ function createRunner(options) {
1321
1389
  entry.data = input.data;
1322
1390
  return entry;
1323
1391
  }
1324
- const created = { key, mark: input.mark, data: input.data, runs: /* @__PURE__ */ new Map(), applied: {}, handle: void 0, exiting: void 0 };
1392
+ const created = { key, mark: input.mark, data: input.data, resting: input.data, runs: /* @__PURE__ */ new Map(), applied: {}, handle: void 0, exiting: void 0 };
1325
1393
  entries.set(key, created);
1326
1394
  return created;
1327
1395
  }
@@ -1412,22 +1480,22 @@ function createRunner(options) {
1412
1480
  path: (d, paint) => target()?.path(d, paint) ?? INERT,
1413
1481
  text: (content, style) => target()?.text(content, style) ?? INERT,
1414
1482
  clear() {
1415
- const drawn = group;
1483
+ const drawn2 = group;
1416
1484
  group = void 0;
1417
- drawn?.clear();
1485
+ drawn2?.clear();
1418
1486
  }
1419
1487
  };
1420
1488
  }
1421
- function runMark(own) {
1489
+ function runMark(own2) {
1422
1490
  return {
1423
1491
  set(style) {
1424
- const run = own();
1492
+ const run = own2();
1425
1493
  if (run.state === "cleared") return;
1426
1494
  run.style = mergeFields(run.style, style);
1427
1495
  applyStyle(run.entry);
1428
1496
  },
1429
1497
  reset() {
1430
- const run = own();
1498
+ const run = own2();
1431
1499
  if (Object.keys(run.style).length === 0) return;
1432
1500
  run.style = {};
1433
1501
  applyStyle(run.entry);
@@ -1501,6 +1569,7 @@ function createRunner(options) {
1501
1569
  if (destroyed) return;
1502
1570
  marks.forEach((input, index) => {
1503
1571
  const entry = track(input);
1572
+ entry.resting = input.data;
1504
1573
  cancelExit(entry);
1505
1574
  const batch = { index, count: marks.length };
1506
1575
  start(entry, "decorate", input.data, batch);
@@ -1509,11 +1578,18 @@ function createRunner(options) {
1509
1578
  },
1510
1579
  update(marks) {
1511
1580
  if (destroyed) return;
1581
+ const changing = new Set(marks.map((input) => input.mark.key));
1582
+ for (const entry of [...entries.values()]) {
1583
+ const run = entry.runs.get("update");
1584
+ if (run && !changing.has(entry.key)) clearRun(run);
1585
+ }
1512
1586
  marks.forEach((input, index) => {
1513
1587
  const known = entries.get(input.mark.key);
1514
1588
  const previous = input.from ?? known?.mark;
1515
- const data = known && !input.data.previous ? withPrevious(input.data, known.data) : input.data;
1516
- start(track(input), "update", data, { index, count: marks.length }, { previous });
1589
+ const data = known && !input.data.previous ? withPrevious(input.data, known.resting) : input.data;
1590
+ const entry = track(input);
1591
+ entry.resting = input.data;
1592
+ start(entry, "update", data, { index, count: marks.length }, { previous });
1517
1593
  });
1518
1594
  },
1519
1595
  exit(marks) {
@@ -1558,7 +1634,10 @@ function createRunner(options) {
1558
1634
  const entry = entries.get(mark.key);
1559
1635
  if (!entry) return;
1560
1636
  entry.mark = mark;
1561
- if (data) entry.data = data;
1637
+ if (data) {
1638
+ entry.data = data;
1639
+ if (!transitioning) entry.resting = data;
1640
+ }
1562
1641
  for (const run of [...entry.runs.values()]) {
1563
1642
  if (run.state === "cleared") continue;
1564
1643
  try {
@@ -1580,6 +1659,7 @@ function createRunner(options) {
1580
1659
  settle() {
1581
1660
  if (!transitioning) return;
1582
1661
  transitioning = false;
1662
+ for (const entry of entries.values()) if (!entry.exiting) entry.resting = entry.data;
1583
1663
  const keys = [...hovered];
1584
1664
  keys.forEach((key, index) => {
1585
1665
  const entry = entries.get(key);
@@ -1641,16 +1721,16 @@ var SORTED = {
1641
1721
  };
1642
1722
  var NAMED = 3;
1643
1723
  function changeText(facts) {
1644
- const parts = [];
1724
+ const parts2 = [];
1645
1725
  const { series } = facts;
1646
- if (facts.label !== void 0) parts.push(facts.label);
1647
- else if (series && !(series.length === 1 && series[0] === "value")) parts.push(`Showing ${list(series)}`);
1648
- if (facts.sort) parts.push(SORTED[facts.sort]);
1726
+ if (facts.label !== void 0) parts2.push(facts.label);
1727
+ else if (series && !(series.length === 1 && series[0] === "value")) parts2.push(`Showing ${list(series)}`);
1728
+ if (facts.sort) parts2.push(SORTED[facts.sort]);
1649
1729
  const { changed, added, removed } = facts;
1650
- if (!series && changed.length > 0) parts.push(changed.length <= NAMED ? `${list(changed)} changed` : `${changed.length} of ${facts.count} changed`);
1651
- if (added.length > 0) parts.push(`Added ${added.length <= NAMED ? list(added) : added.length}`);
1652
- if (removed.length > 0) parts.push(`Removed ${removed.length <= NAMED ? list(removed) : removed.length}`);
1653
- return parts.join(". ");
1730
+ if (!series && changed.length > 0) parts2.push(changed.length <= NAMED ? `${list(changed)} changed` : `${changed.length} of ${facts.count} changed`);
1731
+ if (added.length > 0) parts2.push(`Added ${added.length <= NAMED ? list(added) : added.length}`);
1732
+ if (removed.length > 0) parts2.push(`Removed ${removed.length <= NAMED ? list(removed) : removed.length}`);
1733
+ return parts2.join(". ");
1654
1734
  }
1655
1735
  function list(names) {
1656
1736
  if (names.length <= 1) return names.join("");
@@ -1676,6 +1756,76 @@ function chartAnnouncer(svg) {
1676
1756
  };
1677
1757
  }
1678
1758
 
1759
+ // src/charts/render/svg.ts
1760
+ var SVG_NS = "http://www.w3.org/2000/svg";
1761
+ function svgElement(tag, attributes = {}, parent) {
1762
+ const doc = parent?.ownerDocument ?? document;
1763
+ const element = doc.createElementNS(SVG_NS, tag);
1764
+ setAttributes(element, attributes);
1765
+ parent?.appendChild(element);
1766
+ return element;
1767
+ }
1768
+ function setAttributes(element, attributes) {
1769
+ for (const [name, value] of Object.entries(attributes)) {
1770
+ if (value === void 0) element.removeAttribute(name);
1771
+ else element.setAttribute(name, typeof value === "number" ? formatNumber(value) : value);
1772
+ }
1773
+ }
1774
+ function setStyles(element, styles) {
1775
+ for (const [name, value] of Object.entries(styles)) {
1776
+ if (value === void 0) element.style.removeProperty(name);
1777
+ else element.style.setProperty(name, value);
1778
+ }
1779
+ }
1780
+ function sizeAttributes({ width, height }) {
1781
+ return { width, height, viewBox: `0 0 ${formatNumber(width)} ${formatNumber(height)}` };
1782
+ }
1783
+ function transformAttribute(m) {
1784
+ const [a, b, c, d, e, f] = m;
1785
+ return `matrix(${[a, b, c, d].map(linear2).join(" ")} ${formatNumber(e)} ${formatNumber(f)})`;
1786
+ }
1787
+ function linear2(value) {
1788
+ const rounded = Math.round(value * 1e6) / 1e6;
1789
+ return rounded === 0 ? "0" : String(rounded);
1790
+ }
1791
+
1792
+ // src/charts/render/text.ts
1793
+ var ASCENT = 1.05;
1794
+ var DESCENT = 0.25;
1795
+ var SIDE = 0.16;
1796
+ function textBox(placement, measure, className, size2) {
1797
+ const width = measure(placement.text.replace(/\d/g, "0"), className, size2);
1798
+ const start = placement.anchor === "start" ? placement.x : placement.anchor === "end" ? placement.x - width : placement.x - width / 2;
1799
+ return { x: start - SIDE * size2, y: placement.y - ASCENT * size2, width: width + 2 * SIDE * size2, height: (ASCENT + DESCENT) * size2 };
1800
+ }
1801
+ function placeText(element, placement) {
1802
+ setAttributes(element, { x: placement.x, y: placement.y, "text-anchor": placement.anchor });
1803
+ if (element.textContent !== placement.text) element.textContent = placement.text;
1804
+ }
1805
+ var AVERAGE_WIDTH = 0.6;
1806
+ function textMeasure(svg) {
1807
+ const cache = /* @__PURE__ */ new Map();
1808
+ const measure = (text2, className, size2) => {
1809
+ if (text2 === "") return 0;
1810
+ const id = `${className}
1811
+ ${size2}
1812
+ ${text2}`;
1813
+ const cached = cache.get(id);
1814
+ if (cached !== void 0) return cached;
1815
+ let width = 0;
1816
+ const probe = svgElement("text", { class: className, visibility: "hidden", "aria-hidden": "true" }, svg);
1817
+ if (typeof probe.getComputedTextLength === "function" && svg.isConnected) {
1818
+ probe.textContent = text2;
1819
+ width = probe.getComputedTextLength();
1820
+ }
1821
+ probe.remove();
1822
+ if (!(width > 0)) return text2.length * size2 * AVERAGE_WIDTH;
1823
+ cache.set(id, width);
1824
+ return width;
1825
+ };
1826
+ return Object.assign(measure, { clear: () => cache.clear() });
1827
+ }
1828
+
1679
1829
  // src/charts/bar-layout.ts
1680
1830
  var ROW = 34;
1681
1831
  var BAR = 20;
@@ -1689,6 +1839,7 @@ var TICK_SIZE = 11;
1689
1839
  var AXIS = 26;
1690
1840
  var TOP = 4;
1691
1841
  var PAD = 6;
1842
+ var BOTH = { label: true, value: true };
1692
1843
  var CENTRE = 0.36;
1693
1844
  function barEncoding(options) {
1694
1845
  const { x, y, stack, data } = options;
@@ -1738,16 +1889,65 @@ function layoutBars(input) {
1738
1889
  const texts = rows2.map((row) => input.format(row.total));
1739
1890
  const ticks = domain.ticks.map(input.format);
1740
1891
  const frame2 = (input.encoding.orientation === "horizontal" ? horizontalFrame : verticalFrame)(input, rows2, domain, texts, ticks);
1892
+ const labels = thinLabels(frame2, rows2, texts, input.measure);
1741
1893
  return {
1742
1894
  width: frame2.bands.width,
1743
1895
  height: frame2.bands.height,
1744
1896
  orientation: frame2.orientation,
1745
1897
  frame: frame2,
1746
- rows: rows2.map((row, slot) => placeRow(frame2, { ...row, slot, text: texts[slot] })),
1747
- ticks: domain.ticks.map((value, i) => placeTick(frame2, value, ticks[i]))
1898
+ rows: rows2.map((row, slot) => placeRow(frame2, { ...row, slot, text: texts[slot], drawn: { label: slot % labels.every === 0, value: labels.values } }, input.measure)),
1899
+ ticks: domain.ticks.map((value, i) => placeTick(frame2, value, ticks[i])),
1900
+ labels
1901
+ };
1902
+ }
1903
+ function thinLabels(frame2, rows2, texts, measure) {
1904
+ const placed2 = rows2.map((row, slot) => placeLabels(frame2, slot, row.total, row.category, texts[slot]));
1905
+ const horizontal = frame2.orientation === "horizontal";
1906
+ const values = !overlaps(boxesOf(placed2.map(({ value }) => value), measure, "ec-value", VALUE_SIZE), horizontal);
1907
+ const categories = (every) => boxesOf(
1908
+ placed2.filter((_, slot) => slot % every === 0).map(({ label: label2 }) => label2),
1909
+ measure,
1910
+ "ec-label",
1911
+ LABEL_SIZE
1912
+ );
1913
+ let k = 0;
1914
+ while (thinStep(k) < rows2.length && overlaps(categories(thinStep(k)), horizontal)) k++;
1915
+ return { every: thinStep(k), values };
1916
+ }
1917
+ var thinStep = (k) => [1, 2, 5][k % 3] * 10 ** Math.floor(k / 3);
1918
+ function boxesOf(labels, measure, className, size2) {
1919
+ return labels.filter((label2) => label2.text !== "").map((label2) => textBox(label2, measure, className, size2));
1920
+ }
1921
+ function overlaps(boxes, horizontal) {
1922
+ const along = horizontal ? boxes.map(({ x, y, width, height }) => ({ x: y, y: x, width: height, height: width })) : [...boxes];
1923
+ along.sort((a, b) => a.x - b.x);
1924
+ const open = [];
1925
+ for (const box of along) {
1926
+ for (let i = open.length - 1; i >= 0; i--) if (open[i].x + open[i].width <= box.x) open.splice(i, 1);
1927
+ if (open.some((other) => other.y < box.y + box.height && box.y < other.y + other.height)) return true;
1928
+ open.push(box);
1929
+ }
1930
+ return false;
1931
+ }
1932
+ function placeLabels(frame2, slot, total2, category, text2) {
1933
+ const { scale: scale2, bands } = frame2;
1934
+ const negative = total2 < 0;
1935
+ const tip = position(scale2)(total2);
1936
+ const band = bands.start + slot * bands.band;
1937
+ if (frame2.orientation === "horizontal") {
1938
+ const line2 = band + bands.band / 2 + LABEL_SIZE * CENTRE;
1939
+ return {
1940
+ label: { x: scale2.label, y: line2, anchor: "end", text: category },
1941
+ value: { x: negative ? tip - PAD : tip + PAD, y: line2, anchor: negative ? "end" : "start", text: text2 }
1942
+ };
1943
+ }
1944
+ const centre = band + bands.band / 2;
1945
+ return {
1946
+ label: { x: centre, y: scale2.label, anchor: "middle", text: category },
1947
+ value: { x: centre, y: negative ? tip + PAD + VALUE_SIZE * 0.8 : tip - PAD, anchor: "middle", text: text2 }
1748
1948
  };
1749
1949
  }
1750
- function placeRow(frame2, row) {
1950
+ function placeRow(frame2, row, measure) {
1751
1951
  const { scale: scale2, bands } = frame2;
1752
1952
  const at = position(scale2);
1753
1953
  const unit = Math.abs(scale2.extent / (scale2.hi - scale2.lo));
@@ -1763,7 +1963,10 @@ function placeRow(frame2, row) {
1763
1963
  gap: GAP,
1764
1964
  segments: row.values.map((v) => ({ series: v.series, size: Math.max(0, negative ? -v.value : v.value) * unit }))
1765
1965
  };
1766
- const fields = { key: row.key, datum: row.datum, index: row.index, slot: row.slot, values: row.values, total: total2 };
1966
+ const drawn2 = row.drawn ?? BOTH;
1967
+ const fields = { key: row.key, datum: row.datum, index: row.index, slot: row.slot, values: row.values, total: total2, category: row.category, drawn: drawn2 };
1968
+ const { label: label2, value } = placeLabels(frame2, row.slot, total2, drawn2.label ? row.category : "", drawn2.value ? row.text : "");
1969
+ const boxes = () => [...boxesOf([label2], measure, "ec-label", LABEL_SIZE), ...boxesOf([value], measure, "ec-value", VALUE_SIZE)];
1767
1970
  if (frame2.orientation === "horizontal") {
1768
1971
  const geometry2 = describe.bar({
1769
1972
  ...bar,
@@ -1771,15 +1974,15 @@ function placeRow(frame2, row) {
1771
1974
  y: band + (bands.band - bands.thickness) / 2,
1772
1975
  width: Math.abs(tip - zero),
1773
1976
  height: bands.thickness,
1774
- baseline: negative ? "right" : "left"
1977
+ baseline: negative ? "right" : "left",
1978
+ labelBounds: boxes()
1775
1979
  });
1776
- const line2 = band + bands.band / 2 + LABEL_SIZE * CENTRE;
1777
1980
  return {
1778
1981
  ...fields,
1779
1982
  geometry: geometry2,
1780
1983
  data: barData(row.datum, total2, geometry2),
1781
- label: { x: scale2.label, y: line2, anchor: "end", text: row.category },
1782
- value: { x: negative ? tip - PAD : tip + PAD, y: line2, anchor: negative ? "end" : "start", text: row.text },
1984
+ label: label2,
1985
+ value,
1783
1986
  hit: { x: 0, y: band, width: bands.width, height: bands.band }
1784
1987
  };
1785
1988
  }
@@ -1790,14 +1993,15 @@ function placeRow(frame2, row) {
1790
1993
  y: Math.min(zero, tip),
1791
1994
  width: bands.thickness,
1792
1995
  height: Math.abs(tip - zero),
1793
- baseline: negative ? "top" : "bottom"
1996
+ baseline: negative ? "top" : "bottom",
1997
+ labelBounds: boxes()
1794
1998
  });
1795
1999
  return {
1796
2000
  ...fields,
1797
2001
  geometry,
1798
2002
  data: barData(row.datum, total2, geometry),
1799
- label: { x: centre, y: scale2.label, anchor: "middle", text: row.category },
1800
- value: { x: centre, y: negative ? tip + PAD + VALUE_SIZE * 0.8 : tip - PAD, anchor: "middle", text: row.text },
2003
+ label: label2,
2004
+ value,
1801
2005
  hit: { x: band, y: 0, width: bands.band, height: bands.height }
1802
2006
  };
1803
2007
  }
@@ -1850,9 +2054,9 @@ function niceDomain(values) {
1850
2054
  const ticks = Array.from({ length: count + 1 }, (_, i) => clean(lo + i * step2));
1851
2055
  return { lo, hi, ticks };
1852
2056
  }
1853
- function niceStep(span) {
1854
- const power = 10 ** Math.floor(Math.log10(span));
1855
- const f = span / power;
2057
+ function niceStep(span2) {
2058
+ const power = 10 ** Math.floor(Math.log10(span2));
2059
+ const f = span2 / power;
1856
2060
  return (f <= 1 ? 1 : f <= 2 ? 2 : f <= 5 ? 5 : 10) * power;
1857
2061
  }
1858
2062
  function horizontalFrame(input, rows2, domain, values, ticks) {
@@ -1861,9 +2065,10 @@ function horizontalFrame(input, rows2, domain, values, ticks) {
1861
2065
  const labelWidth = widest(rows2.map((row) => row.category), "ec-label", LABEL_SIZE, measure);
1862
2066
  const valueWidth = widest(values, "ec-value", VALUE_SIZE, measure);
1863
2067
  const tickWidth = widest(ticks, "ec-tick", TICK_SIZE, measure);
2068
+ const { positive, negative } = reach(input, rows2);
1864
2069
  const negativeRoom = domain.lo < 0 ? valueWidth + PAD : 0;
1865
- const left = Math.max(labelWidth + 10 + negativeRoom, tickWidth / 2 + 2);
1866
- const right = Math.max(valueWidth + PAD + 4, tickWidth / 2 + 2);
2070
+ const left = Math.max(labelWidth + 10 + negativeRoom + negative, tickWidth / 2 + 2);
2071
+ const right = Math.max(valueWidth + PAD + 4 + positive, tickWidth / 2 + 2);
1867
2072
  const rowSize = input.height === void 0 || n === 0 ? ROW : Math.max(0, input.height - TOP - AXIS) / n;
1868
2073
  return {
1869
2074
  orientation: "horizontal",
@@ -1876,8 +2081,9 @@ function verticalFrame(input, rows2, domain, _values, ticks) {
1876
2081
  const n = rows2.length;
1877
2082
  const height = input.height ?? VERTICAL_HEIGHT;
1878
2083
  const tickWidth = widest(ticks, "ec-tick", TICK_SIZE, measure);
1879
- const top = domain.hi > 0 ? VALUE_SIZE + PAD + 2 : TOP;
1880
- const bottom = AXIS + (domain.lo < 0 ? VALUE_SIZE + PAD : 0);
2084
+ const { positive, negative } = reach(input, rows2);
2085
+ const top = (domain.hi > 0 ? VALUE_SIZE + PAD + 2 : TOP) + positive;
2086
+ const bottom = AXIS + (domain.lo < 0 ? VALUE_SIZE + PAD : 0) + negative;
1881
2087
  const left = tickWidth + 8 + 2;
1882
2088
  const plot = { x: left, y: top, width: Math.max(0, width - left - 8), height: Math.max(0, height - top - bottom) };
1883
2089
  const band = n > 0 ? plot.width / n : 0;
@@ -1888,6 +2094,13 @@ function verticalFrame(input, rows2, domain, _values, ticks) {
1888
2094
  bands: { start: plot.x, band, thickness: Math.min(band * BAR / ROW, MAX_COLUMN), span: plot.width, width, height }
1889
2095
  };
1890
2096
  }
2097
+ function reach(input, rows2) {
2098
+ const room = input.room ?? 0;
2099
+ return {
2100
+ positive: rows2.some((row) => row.total > 0) ? room : 0,
2101
+ negative: rows2.some((row) => row.total < 0) ? room : 0
2102
+ };
2103
+ }
1891
2104
  function barData(datum, total2, geometry) {
1892
2105
  const valueAt = (distance3) => geometry.length > 0 ? total2 * distance3 / geometry.length : 0;
1893
2106
  const data = {
@@ -2034,27 +2247,29 @@ ${TOKEN_RULES}
2034
2247
  :where(.ec-chart .ec-tick) { fill: var(--ec-text-muted, ${TOKENS["text-muted"]}); font-size: 11px; }
2035
2248
  :where(.ec-chart .ec-label) { fill: var(--ec-text, ${TOKENS.text}); font-size: 12.5px; }
2036
2249
  :where(.ec-chart .ec-value, .ec-chart .ec-text) { fill: var(--ec-text, ${TOKENS.text}); font-size: 12.5px; font-weight: 600; }
2250
+ :where(.ec-overlay .ec-text) { fill: var(--ec-text, ${TOKENS.text}); font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
2037
2251
  :where(.ec-chart .ec-hit) { fill: transparent; }
2038
2252
  :where(.ec-chart .ec-mark:focus) { outline: none; }
2039
2253
  :where(.ec-chart .ec-focus) { pointer-events: none; }
2040
2254
  :where(.ec-chart .ec-focus-ring) { fill: none; stroke: var(--ec-focus, ${TOKENS.focus}); }
2041
2255
  :where(.ec-chart .ec-focus-gap) { fill: var(--ec-surface, ${TOKENS.surface}); stroke: var(--ec-surface, ${TOKENS.surface}); }
2042
- :where(.ec-chart .ec-mark) { transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
2043
- :where(.ec-chart .ec-segment) { fill: var(--ec-mark); transition: fill var(--ec-hover-duration, 100ms) ease-out; }
2256
+ :where(.ec-chart .ec-body > *) { transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
2257
+ :where(.ec-chart .ec-segment) { fill: var(--ec-mark); transition: fill var(--ec-hover-duration, 100ms) ease-out, opacity var(--ec-hover-duration, 100ms) ease-out; }
2044
2258
  :where(.ec-chart .ec-hot .ec-segment) { fill: var(--ec-mark-strong); }
2045
- :where(.ec-chart .ec-stroke) { fill: none; stroke: var(--ec-mark); stroke-linejoin: round; transition: stroke var(--ec-hover-duration, 100ms) ease-out; }
2259
+ :where(.ec-chart .ec-stroke) { fill: none; stroke: var(--ec-mark); stroke-linejoin: round; transition: stroke var(--ec-hover-duration, 100ms) ease-out, opacity var(--ec-hover-duration, 100ms) ease-out; }
2046
2260
  :where(.ec-chart .ec-hot .ec-stroke) { stroke: var(--ec-mark-strong); }
2047
2261
  :where(.ec-chart .ec-end) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; }
2048
2262
  :where(.ec-chart .ec-dot) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; opacity: 0; transition: opacity var(--ec-hover-duration, 100ms) ease-out, fill var(--ec-hover-duration, 100ms) ease-out; }
2049
2263
  :where(.ec-chart .ec-hot .ec-dot) { fill: var(--ec-mark-strong); opacity: 1; }
2264
+ :where(.ec-chart .ec-alone .ec-dot) { opacity: 1; }
2050
2265
  :where(.ec-chart .ec-crosshair) { stroke: var(--ec-axis, ${TOKENS.axis}); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
2051
2266
  :where(.ec-chart .ec-column:focus) { outline: none; }
2052
2267
  :where(.ec-chart .ec-lines, .ec-chart .ec-points) { pointer-events: none; }
2053
- :where(.ec-chart .ec-slice) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; stroke-linejoin: round; transition: fill var(--ec-hover-duration, 100ms) ease-out; }
2268
+ :where(.ec-chart .ec-slice) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; stroke-linejoin: round; transition: fill var(--ec-hover-duration, 100ms) ease-out, opacity var(--ec-hover-duration, 100ms) ease-out; }
2054
2269
  :where(.ec-chart .ec-hot .ec-slice) { fill: var(--ec-mark-strong); }
2055
2270
  :where(.ec-chart .ec-center-value) { fill: var(--ec-text, ${TOKENS.text}); font-size: 26px; font-weight: 600; }
2056
2271
  :where(.ec-chart .ec-center-label) { fill: var(--ec-text-muted, ${TOKENS["text-muted"]}); font-size: 12.5px; }
2057
- :where(.ec-chart.ec-hovering .ec-mark:not(.ec-hot)) { opacity: var(--ec-dim-opacity, 0.3); }
2272
+ :where(.ec-chart.ec-hovering .ec-mark:not(.ec-hot) > .ec-body > *) { opacity: var(--ec-dim-opacity, 0.3); }
2058
2273
  :where(.ec-chart.ec-morphing .ec-marks) { visibility: hidden; }
2059
2274
  :where(.ec-switch) { display: grid; grid-template-columns: minmax(0, 1fr); position: relative; }
2060
2275
  :where(.ec-switch-view) { grid-area: 1 / 1; min-width: 0; }
@@ -2081,7 +2296,10 @@ ${TOKEN_RULES}
2081
2296
  :where(.ec-attached) { transition: opacity var(--ec-hover-duration, 100ms) ease-out, fill var(--ec-hover-duration, 100ms) ease-out, stroke var(--ec-hover-duration, 100ms) ease-out; }
2082
2297
  :where(.ec-tooltip-layer) { position: relative; height: 0; }
2083
2298
  :where(.ec-tooltip) { position: absolute; left: 0; top: 0; z-index: 3; box-sizing: border-box; width: max-content; max-width: 24em; padding: 8px 10px; border: 1px solid var(--ec-ring, color-mix(in srgb, currentColor 12%, transparent)); border-radius: 8px; background: var(--ec-surface, ${TOKENS.surface}); color: var(--ec-text, ${TOKENS.text}); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12); font-size: 13px; line-height: 1.35; white-space: pre-line; font-variant-numeric: tabular-nums; pointer-events: none; opacity: 0; visibility: hidden; transition: opacity var(--ec-hover-duration, 100ms) ease-out, visibility 0s linear var(--ec-hover-duration, 100ms); }
2084
- :where(.ec-tooltip.ec-tooltip-shown) { opacity: 1; visibility: visible; transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
2299
+ :where(.ec-tooltip.ec-tooltip-shown) { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
2300
+ :where(.ec-tooltip-bridge) { position: absolute; left: 0; top: 0; z-index: 3; pointer-events: none; }
2301
+ :where(.ec-tooltip-shown + .ec-tooltip-bridge) { pointer-events: auto; }
2302
+ :where(.ec-tooltip-through > .ec-tooltip, .ec-tooltip-through > .ec-tooltip-bridge) { pointer-events: none; }
2085
2303
  :where(.ec-tooltip-title) { font-weight: 600; }
2086
2304
  :where(.ec-legend) { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 8px; font-size: 13px; line-height: 1.4; color: var(--ec-text, ${TOKENS.text}); }
2087
2305
  :where(.ec-legend-item) { display: inline-flex; align-items: center; gap: 6px; }
@@ -2146,8 +2364,8 @@ function checkLegendOption(option, chart) {
2146
2364
  if (entries === void 0) return;
2147
2365
  if (!Array.isArray(entries)) fail("legend.entries must be an array of { label, color }.");
2148
2366
  entries.forEach((entry, i) => {
2149
- const { label, color } = typeof entry === "object" && entry !== null ? entry : fail(`legend.entries[${i}] must be an object with a label and a color.`);
2150
- if (typeof label !== "string" || label.trim() === "") fail(`legend.entries[${i}].label must be a non-empty string: the entry's name.`);
2367
+ const { label: label2, color } = typeof entry === "object" && entry !== null ? entry : fail(`legend.entries[${i}] must be an object with a label and a color.`);
2368
+ if (typeof label2 !== "string" || label2.trim() === "") fail(`legend.entries[${i}].label must be a non-empty string: the entry's name.`);
2151
2369
  if (typeof color !== "string" || color.trim() === "") fail(`legend.entries[${i}].color must be a theme token or a CSS colour.`);
2152
2370
  if (color === "mark" || color === "mark-strong") fail(`legend.entries[${i}].color can't be "${color}": an entry has no mark. Use a theme token or a CSS colour.`);
2153
2371
  });
@@ -2155,23 +2373,23 @@ function checkLegendOption(option, chart) {
2155
2373
  var extras = (option) => typeof option === "object" ? option.entries ?? [] : [];
2156
2374
  function chartLegend(svg) {
2157
2375
  let legend;
2158
- let drawn = "";
2376
+ let drawn2 = "";
2159
2377
  const remove = () => {
2160
2378
  legend?.remove();
2161
2379
  legend = void 0;
2162
- drawn = "";
2380
+ drawn2 = "";
2163
2381
  };
2164
2382
  const draw = (entries, colors, attribute, more) => {
2165
2383
  const items = [
2166
- ...entries.map(({ key, label }) => ({ key, label, styles: markColorStyles(seriesColors(colors.slot(key))) })),
2167
- ...more.map(({ label, color }) => ({ key: void 0, label, styles: { "--ec-mark": cssColor(color) } }))
2384
+ ...entries.map(({ key, label: label2 }) => ({ key, label: label2, styles: markColorStyles(seriesColors(colors.slot(key))) })),
2385
+ ...more.map(({ label: label2, color }) => ({ key: void 0, label: label2, styles: { "--ec-mark": cssColor(color) } }))
2168
2386
  ];
2169
2387
  const doc = svg.ownerDocument;
2170
2388
  legend ?? (legend = Object.assign(doc.createElement("div"), { className: "ec-legend" }));
2171
2389
  if (legend.nextSibling !== svg) svg.before(legend);
2172
2390
  const id = JSON.stringify([attribute, items]);
2173
- if (id === drawn) return;
2174
- drawn = id;
2391
+ if (id === drawn2) return;
2392
+ drawn2 = id;
2175
2393
  legend.replaceChildren(
2176
2394
  ...items.map(({ key, label: text2, styles }) => {
2177
2395
  const item = doc.createElement("span");
@@ -2180,10 +2398,10 @@ function chartLegend(svg) {
2180
2398
  for (const [property, value] of Object.entries(styles)) if (value !== void 0) item.style.setProperty(property, value);
2181
2399
  const swatch = doc.createElement("span");
2182
2400
  swatch.className = "ec-legend-swatch";
2183
- const label = doc.createElement("span");
2184
- label.className = "ec-legend-label";
2185
- label.textContent = text2;
2186
- item.append(swatch, label);
2401
+ const label2 = doc.createElement("span");
2402
+ label2.className = "ec-legend-label";
2403
+ label2.textContent = text2;
2404
+ item.append(swatch, label2);
2187
2405
  return item;
2188
2406
  })
2189
2407
  );
@@ -2192,7 +2410,7 @@ function chartLegend(svg) {
2192
2410
  update(series, colors, option) {
2193
2411
  const more = extras(option);
2194
2412
  if (option === false || series.length + more.length < 2) remove();
2195
- else draw(series.map(({ series: key, label }) => ({ key, label })), colors, "data-series", more);
2413
+ else draw(series.map(({ series: key, label: label2 }) => ({ key, label: label2 })), colors, "data-series", more);
2196
2414
  },
2197
2415
  categories(categories, colors, option) {
2198
2416
  if (option === false || categories.length === 0) remove();
@@ -2202,6 +2420,100 @@ function chartLegend(svg) {
2202
2420
  };
2203
2421
  }
2204
2422
 
2423
+ // src/charts/link.ts
2424
+ var own = (hovered) => hovered !== void 0 && hovered.source !== "linked";
2425
+ var ports = /* @__PURE__ */ new WeakMap();
2426
+ var linked = /* @__PURE__ */ new WeakSet();
2427
+ function linkable(port, handle) {
2428
+ ports.set(handle, port);
2429
+ return handle;
2430
+ }
2431
+ var portOf = (handle) => ports.get(handle);
2432
+ function link(sources, options = {}) {
2433
+ if (!Array.isArray(sources)) throw new TypeError("link needs an array of charts and attachments: link([columns, line]).");
2434
+ if (typeof options !== "object" || options === null) throw new TypeError("link: options must be an object, such as { by: (event) => event.data.datum.week }.");
2435
+ const { by, effects = true } = options;
2436
+ if (by !== void 0 && typeof by !== "function") throw new TypeError("link: by must be a function, such as (event) => event.data.datum.week.");
2437
+ if (typeof effects !== "boolean") throw new TypeError(`link: effects must be true or false, got ${String(effects)}.`);
2438
+ const members = [];
2439
+ for (const source of sources) {
2440
+ const port = typeof source === "object" && source !== null ? ports.get(source) : void 0;
2441
+ if (!port) {
2442
+ throw new TypeError("link: each source must be a chart (barChart, donutChart or lineChart) or an attachment (expressive or fromVegaView). A chartSwitch can't be linked yet.");
2443
+ }
2444
+ if (linked.has(port) || members.includes(port)) throw new TypeError("link: a chart or attachment can be in one link at a time. Destroy the link it's in first.");
2445
+ members.push(port);
2446
+ }
2447
+ const live = /* @__PURE__ */ new Set();
2448
+ let origin;
2449
+ function valueOf(input) {
2450
+ let value;
2451
+ if (by) {
2452
+ try {
2453
+ value = by(input);
2454
+ } catch (error) {
2455
+ report(error);
2456
+ return void 0;
2457
+ }
2458
+ } else {
2459
+ const { samples } = input.data;
2460
+ value = samples[samples.length - 1]?.at ?? input.mark.key;
2461
+ }
2462
+ if (value instanceof Date) return Number.isNaN(value.getTime()) ? void 0 : value.toISOString();
2463
+ return value === void 0 || value === null ? void 0 : String(value);
2464
+ }
2465
+ function hovered(from, marks) {
2466
+ origin = from;
2467
+ const values = new Set(marks.map(valueOf));
2468
+ values.delete(void 0);
2469
+ const matches = (target) => target.some((mark) => {
2470
+ const value = valueOf(mark);
2471
+ return value !== void 0 && values.has(value);
2472
+ });
2473
+ for (const port of live) {
2474
+ if (port === from) continue;
2475
+ const keys = values.size === 0 ? [] : port.targets().flatMap((target) => matches(target.marks) ? [target.key] : []);
2476
+ port.hover(keys, effects);
2477
+ if (origin !== from) return;
2478
+ }
2479
+ }
2480
+ function left(from) {
2481
+ if (origin !== from) return;
2482
+ origin = void 0;
2483
+ for (const port of live) port.unlink();
2484
+ }
2485
+ for (const port of members) {
2486
+ const listening = port.listen({
2487
+ hover: (marks) => hovered(port, marks),
2488
+ leave: () => left(port),
2489
+ dismiss() {
2490
+ const from = origin;
2491
+ from?.leave();
2492
+ if (from) left(from);
2493
+ },
2494
+ gone() {
2495
+ live.delete(port);
2496
+ linked.delete(port);
2497
+ left(port);
2498
+ }
2499
+ });
2500
+ if (!listening) continue;
2501
+ live.add(port);
2502
+ linked.add(port);
2503
+ }
2504
+ return {
2505
+ destroy() {
2506
+ for (const port of live) {
2507
+ port.listen(void 0);
2508
+ port.unlink();
2509
+ linked.delete(port);
2510
+ }
2511
+ live.clear();
2512
+ origin = void 0;
2513
+ }
2514
+ };
2515
+ }
2516
+
2205
2517
  // src/charts/motion.ts
2206
2518
  var MODES2 = ["presentation", "analysis", "off"];
2207
2519
  function chartMotion(option, page) {
@@ -2224,39 +2536,6 @@ function chartMotion(option, page) {
2224
2536
  };
2225
2537
  }
2226
2538
 
2227
- // src/charts/render/svg.ts
2228
- var SVG_NS = "http://www.w3.org/2000/svg";
2229
- function svgElement(tag, attributes = {}, parent) {
2230
- const doc = parent?.ownerDocument ?? document;
2231
- const element = doc.createElementNS(SVG_NS, tag);
2232
- setAttributes(element, attributes);
2233
- parent?.appendChild(element);
2234
- return element;
2235
- }
2236
- function setAttributes(element, attributes) {
2237
- for (const [name, value] of Object.entries(attributes)) {
2238
- if (value === void 0) element.removeAttribute(name);
2239
- else element.setAttribute(name, typeof value === "number" ? formatNumber(value) : value);
2240
- }
2241
- }
2242
- function setStyles(element, styles) {
2243
- for (const [name, value] of Object.entries(styles)) {
2244
- if (value === void 0) element.style.removeProperty(name);
2245
- else element.style.setProperty(name, value);
2246
- }
2247
- }
2248
- function sizeAttributes({ width, height }) {
2249
- return { width, height, viewBox: `0 0 ${formatNumber(width)} ${formatNumber(height)}` };
2250
- }
2251
- function transformAttribute(m) {
2252
- const [a, b, c, d, e, f] = m;
2253
- return `matrix(${[a, b, c, d].map(linear2).join(" ")} ${formatNumber(e)} ${formatNumber(f)})`;
2254
- }
2255
- function linear2(value) {
2256
- const rounded = Math.round(value * 1e6) / 1e6;
2257
- return rounded === 0 ? "0" : String(rounded);
2258
- }
2259
-
2260
2539
  // src/charts/render/outside.ts
2261
2540
  var RING_GAP = 2;
2262
2541
  var RING = 2;
@@ -2296,8 +2575,8 @@ function maskedHalo() {
2296
2575
  group = void 0;
2297
2576
  };
2298
2577
  return {
2299
- paint(container, parts, halo, transform) {
2300
- if (!halo || !container || parts.length === 0) {
2578
+ paint(container, parts2, halo, transform) {
2579
+ if (!halo || !container || parts2.length === 0) {
2301
2580
  remove();
2302
2581
  return;
2303
2582
  }
@@ -2309,12 +2588,12 @@ function maskedHalo() {
2309
2588
  const id = `ec-halo-mask-${++haloMasks}`;
2310
2589
  const mask = svgElement("mask", { id, maskUnits: "userSpaceOnUse", x: -1e5, y: -1e5, width: 2e5, height: 2e5 }, group);
2311
2590
  svgElement("rect", { x: -1e5, y: -1e5, width: 2e5, height: 2e5, fill: "white" }, mask);
2312
- for (const part of parts) {
2591
+ for (const part of parts2) {
2313
2592
  const cut = part.stroke === void 0 ? { fill: "black" } : { fill: "none", stroke: "black", "stroke-width": part.stroke, "stroke-linejoin": "round" };
2314
2593
  svgElement("path", { d: part.d, ...cut }, mask);
2315
2594
  }
2316
2595
  setAttributes(group, { transform: transform && transformAttribute(transform) });
2317
- for (const part of parts) {
2596
+ for (const part of parts2) {
2318
2597
  const open = part.stroke !== void 0;
2319
2598
  const path = svgElement(
2320
2599
  "path",
@@ -2336,24 +2615,24 @@ function svgMarkHandle(target, options = {}) {
2336
2615
  const repaint = () => {
2337
2616
  const current = target();
2338
2617
  if (!current) return;
2339
- const { body, parts } = current;
2618
+ const { body, parts: parts2 } = current;
2340
2619
  setAttributes(body, {
2341
2620
  transform: style.transform && transformAttribute(style.transform),
2342
2621
  opacity: style.opacity
2343
2622
  });
2344
2623
  const emphasis = style.emphasis;
2345
- for (const part of parts) {
2624
+ for (const part of parts2) {
2346
2625
  setStyles(part.element, {
2347
2626
  [part.open ? "stroke" : "fill"]: emphasis === void 0 ? void 0 : mix(part.colors, emphasis),
2348
2627
  transition: emphasis === void 0 ? void 0 : "none"
2349
2628
  });
2350
2629
  }
2351
- paintHalo(body, parts);
2630
+ paintHalo(body, parts2);
2352
2631
  };
2353
- const paintHalo = (body, parts) => {
2632
+ const paintHalo = (body, parts2) => {
2354
2633
  const spec = style.halo;
2355
2634
  if (above) {
2356
- const visible2 = parts.flatMap((part) => part.visible ? [{ d: part.d, color: part.colors.color, ...part.open ? { stroke: part.open.width } : {} }] : []);
2635
+ const visible2 = parts2.flatMap((part) => part.visible ? [{ d: part.d, color: part.colors.color, ...part.open ? { stroke: part.open.width } : {} }] : []);
2357
2636
  above.paint(options.halos?.(), visible2, spec, style.transform);
2358
2637
  return;
2359
2638
  }
@@ -2367,7 +2646,7 @@ function svgMarkHandle(target, options = {}) {
2367
2646
  halo = svgElement("g", { class: "ec-halo" }, body);
2368
2647
  body.insertBefore(halo, body.firstChild);
2369
2648
  }
2370
- const visible = parts.filter((part) => part.visible);
2649
+ const visible = parts2.filter((part) => part.visible);
2371
2650
  while (halo.childElementCount > visible.length) halo.lastElementChild?.remove();
2372
2651
  visible.forEach((part, index) => {
2373
2652
  const path = halo.children[index] ?? svgElement("path", { "stroke-linejoin": "round" }, halo);
@@ -2409,15 +2688,15 @@ function svgLayer(group) {
2409
2688
  icon(icon, options) {
2410
2689
  const size2 = options?.size;
2411
2690
  if (size2 !== void 0 && !(size2 >= 0)) throw new RangeError(`layer.icon: size must be a non-negative number, got ${String(size2)}.`);
2412
- const placed = svgElement("g", { class: "ec-icon", "data-icon": icon.name, visibility: "hidden" }, group);
2691
+ const placed2 = svgElement("g", { class: "ec-icon", "data-icon": icon.name, visibility: "hidden" }, group);
2413
2692
  const k = size2 === void 0 || !(icon.size > 0) ? 1 : size2 / icon.size;
2414
- const body = k === 1 ? placed : svgElement("g", { transform: transformAttribute(matrix.scale(k, k, icon.anchor)) }, placed);
2693
+ const body = k === 1 ? placed2 : svgElement("g", { transform: transformAttribute(matrix.scale(k, k, icon.anchor)) }, placed2);
2415
2694
  for (const shape of icon.shapes) drawShape(shape, body);
2416
2695
  const handle = {
2417
2696
  place(transform) {
2418
- setAttributes(placed, { transform: transformAttribute(transform), visibility: void 0 });
2697
+ setAttributes(placed2, { transform: transformAttribute(transform), visibility: void 0 });
2419
2698
  },
2420
- remove: () => placed.remove()
2699
+ remove: () => placed2.remove()
2421
2700
  };
2422
2701
  return handle;
2423
2702
  },
@@ -2468,7 +2747,9 @@ function drawShape(shape, parent) {
2468
2747
  "clip-path": clip && `url(#${clip})`,
2469
2748
  "stroke-width": shape.stroke === void 0 ? void 0 : shape.width ?? 1,
2470
2749
  "stroke-linecap": shape.linecap,
2471
- "stroke-linejoin": shape.linejoin
2750
+ "stroke-linejoin": shape.linejoin,
2751
+ "fill-rule": shape.fillRule,
2752
+ opacity: shape.opacity
2472
2753
  },
2473
2754
  parent
2474
2755
  );
@@ -2536,35 +2817,6 @@ function svgSurface(options) {
2536
2817
  };
2537
2818
  }
2538
2819
 
2539
- // src/charts/render/text.ts
2540
- function placeText(element, placement) {
2541
- setAttributes(element, { x: placement.x, y: placement.y, "text-anchor": placement.anchor });
2542
- if (element.textContent !== placement.text) element.textContent = placement.text;
2543
- }
2544
- var AVERAGE_WIDTH = 0.6;
2545
- function textMeasure(svg) {
2546
- const cache = /* @__PURE__ */ new Map();
2547
- const measure = (text2, className, size2) => {
2548
- if (text2 === "") return 0;
2549
- const id = `${className}
2550
- ${size2}
2551
- ${text2}`;
2552
- const cached = cache.get(id);
2553
- if (cached !== void 0) return cached;
2554
- let width = 0;
2555
- const probe = svgElement("text", { class: className, visibility: "hidden", "aria-hidden": "true" }, svg);
2556
- if (typeof probe.getComputedTextLength === "function" && svg.isConnected) {
2557
- probe.textContent = text2;
2558
- width = probe.getComputedTextLength();
2559
- }
2560
- probe.remove();
2561
- if (!(width > 0)) return text2.length * size2 * AVERAGE_WIDTH;
2562
- cache.set(id, width);
2563
- return width;
2564
- };
2565
- return Object.assign(measure, { clear: () => cache.clear() });
2566
- }
2567
-
2568
2820
  // src/charts/series.ts
2569
2821
  function seriesLabel(labels, series) {
2570
2822
  return labels !== void 0 && Object.prototype.hasOwnProperty.call(labels, series) ? labels[series] ?? series : series;
@@ -2572,8 +2824,8 @@ function seriesLabel(labels, series) {
2572
2824
  function checkSeriesLabels(option, chart) {
2573
2825
  if (option === void 0) return;
2574
2826
  if (typeof option !== "object" || option === null || Array.isArray(option)) throw new TypeError(`${chart}: seriesLabels must be an object of names by series, as { goals: "Goals" }.`);
2575
- for (const [series, label] of Object.entries(option)) {
2576
- if (typeof label !== "string" || label.trim() === "") throw new TypeError(`${chart}: seriesLabels.${series} must be a name, not ${typeof label === "string" ? "blank" : String(label)}.`);
2827
+ for (const [series, label2] of Object.entries(option)) {
2828
+ if (typeof label2 !== "string" || label2.trim() === "") throw new TypeError(`${chart}: seriesLabels.${series} must be a name, not ${typeof label2 === "string" ? "blank" : String(label2)}.`);
2577
2829
  }
2578
2830
  }
2579
2831
 
@@ -2637,6 +2889,9 @@ function pointerHover(svg, options) {
2637
2889
  const doc = svg.ownerDocument;
2638
2890
  let current;
2639
2891
  let lastPointer = "mouse";
2892
+ let held;
2893
+ let watcher;
2894
+ let still;
2640
2895
  const enter = (target, source) => {
2641
2896
  if (target?.key === current) return;
2642
2897
  leave2();
@@ -2645,15 +2900,91 @@ function pointerHover(svg, options) {
2645
2900
  options.hover(target, source);
2646
2901
  };
2647
2902
  const leave2 = () => {
2903
+ letGo();
2648
2904
  if (current === void 0) return;
2649
2905
  current = void 0;
2650
2906
  options.leave();
2651
2907
  };
2908
+ const tooltipHolding = (node) => {
2909
+ const tip = options.tooltip?.();
2910
+ return tip?.element && node && tip.element.contains(node) ? tip : void 0;
2911
+ };
2912
+ const elementAt = (x, y) => {
2913
+ const root = svg.getRootNode();
2914
+ return typeof root.elementFromPoint === "function" ? root.elementFromPoint(x, y) : void 0;
2915
+ };
2916
+ const landing = (event) => event.relatedTarget ?? elementAt(event.clientX, event.clientY) ?? null;
2917
+ const arrive = (element, x, y) => {
2918
+ const tip = tooltipHolding(element);
2919
+ if (tip) hold(tip, x, y);
2920
+ else enter(element && svg.contains(element) ? options.find(element) : void 0, "pointer");
2921
+ };
2922
+ const hold = (tip, x, y) => {
2923
+ enter({ key: tip.key }, "pointer");
2924
+ const element = tip.element;
2925
+ if (held?.element === element) {
2926
+ held.x = x;
2927
+ held.y = y;
2928
+ return;
2929
+ }
2930
+ letGo();
2931
+ held = { element, x, y };
2932
+ element.addEventListener("pointermove", track);
2933
+ element.addEventListener("pointerleave", off);
2934
+ watcher = new MutationObserver(recheck);
2935
+ watcher.observe(element, { attributes: true, childList: true, characterData: true, subtree: true });
2936
+ };
2937
+ const letGo = () => {
2938
+ if (!held) return;
2939
+ held.element.removeEventListener("pointermove", track);
2940
+ held.element.removeEventListener("pointerleave", off);
2941
+ watcher?.disconnect();
2942
+ watcher = void 0;
2943
+ held = void 0;
2944
+ };
2945
+ const track = (event) => {
2946
+ if (!held || event.pointerType === "touch") return;
2947
+ held.x = event.clientX;
2948
+ held.y = event.clientY;
2949
+ };
2950
+ const off = (event) => {
2951
+ if (event.pointerType === "touch") return;
2952
+ letGo();
2953
+ arrive(landing(event), event.clientX, event.clientY);
2954
+ };
2955
+ const recheck = () => {
2956
+ if (!held) return;
2957
+ const { x, y } = held;
2958
+ const under = elementAt(x, y);
2959
+ if (under === void 0) return;
2960
+ const tip = options.tooltip?.();
2961
+ const onTip = tip?.element !== void 0 && under !== null && tip.element.contains(under);
2962
+ if (onTip && tip.key === current) return;
2963
+ letGo();
2964
+ if (!onTip && tip?.key !== current) {
2965
+ still = { x, y };
2966
+ leave2();
2967
+ return;
2968
+ }
2969
+ arrive(under, x, y);
2970
+ };
2971
+ const resting = (event) => {
2972
+ if (still && Math.abs(event.clientX - still.x) < 1 && Math.abs(event.clientY - still.y) < 1) return true;
2973
+ still = void 0;
2974
+ return false;
2975
+ };
2652
2976
  const over = (event) => {
2653
- if (event.pointerType !== "touch") enter(options.find(event.target), "pointer");
2977
+ if (event.pointerType === "touch" || resting(event)) return;
2978
+ letGo();
2979
+ enter(options.find(event.target), "pointer");
2654
2980
  };
2655
2981
  const out = (event) => {
2656
- if (event.pointerType !== "touch") leave2();
2982
+ if (event.pointerType === "touch") return;
2983
+ still = void 0;
2984
+ arrive(landing(event), event.clientX, event.clientY);
2985
+ };
2986
+ const move = (event) => {
2987
+ if (event.pointerType !== "touch") resting(event);
2657
2988
  };
2658
2989
  const down = (event) => {
2659
2990
  lastPointer = event.pointerType;
@@ -2662,10 +2993,13 @@ function pointerHover(svg, options) {
2662
2993
  if (lastPointer === "touch") enter(options.find(event.target), "touch");
2663
2994
  };
2664
2995
  const elsewhere = (event) => {
2665
- if (current !== void 0 && event.pointerType === "touch" && !svg.contains(event.target)) leave2();
2996
+ if (current === void 0 || event.pointerType !== "touch") return;
2997
+ const target = event.composedPath()[0] ?? event.target;
2998
+ if (!svg.contains(target) && !tooltipHolding(target)) leave2();
2666
2999
  };
2667
3000
  svg.addEventListener("pointerover", over);
2668
3001
  svg.addEventListener("pointerleave", out);
3002
+ svg.addEventListener("pointermove", move);
2669
3003
  svg.addEventListener("pointerdown", down);
2670
3004
  svg.addEventListener("click", click);
2671
3005
  doc.addEventListener("pointerdown", elsewhere, true);
@@ -2673,11 +3007,16 @@ function pointerHover(svg, options) {
2673
3007
  get current() {
2674
3008
  return current;
2675
3009
  },
2676
- clear: leave2,
3010
+ clear() {
3011
+ if (held) still = { x: held.x, y: held.y };
3012
+ leave2();
3013
+ },
2677
3014
  destroy() {
3015
+ letGo();
2678
3016
  current = void 0;
2679
3017
  svg.removeEventListener("pointerover", over);
2680
3018
  svg.removeEventListener("pointerleave", out);
3019
+ svg.removeEventListener("pointermove", move);
2681
3020
  svg.removeEventListener("pointerdown", down);
2682
3021
  svg.removeEventListener("click", click);
2683
3022
  doc.removeEventListener("pointerdown", elsewhere, true);
@@ -2726,10 +3065,10 @@ function keyboardFocus(svg, options) {
2726
3065
  leave2();
2727
3066
  return;
2728
3067
  }
2729
- const own = options.element(key);
2730
- if (own && own !== event.target && event.target.getAttribute("aria-hidden") === "true") {
2731
- own.focus();
2732
- if (on?.scope.activeElement === own) return;
3068
+ const own2 = options.element(key);
3069
+ if (own2 && own2 !== event.target && event.target.getAttribute("aria-hidden") === "true") {
3070
+ own2.focus();
3071
+ if (on?.scope.activeElement === own2) return;
2733
3072
  }
2734
3073
  focused = { key, element: event.target };
2735
3074
  if (key === current) return;
@@ -2765,6 +3104,13 @@ function keyboardFocus(svg, options) {
2765
3104
  case "ArrowLeft":
2766
3105
  next = keys[Math.max(0, index - 1)];
2767
3106
  break;
3107
+ case "PageDown":
3108
+ case "PageUp": {
3109
+ const by = event.key === "PageDown" ? 1 : -1;
3110
+ const paged = options.page?.(key, by);
3111
+ next = paged !== void 0 && keys.includes(paged) ? paged : keys[Math.min(keys.length - 1, Math.max(0, index + by * Math.ceil(keys.length / 10)))];
3112
+ break;
3113
+ }
2768
3114
  case "Home":
2769
3115
  next = keys[0];
2770
3116
  break;
@@ -2859,13 +3205,16 @@ function chartHover(options) {
2859
3205
  const markElement = (key) => (options.markElement ?? options.element)(key);
2860
3206
  let hovered;
2861
3207
  let ringKey;
3208
+ let linked2;
3209
+ let destroyed = false;
2862
3210
  const onScreen = (keys) => keys.flatMap((key) => {
2863
3211
  const input = options.onScreen(key);
2864
3212
  return input ? [{ key, input }] : [];
2865
3213
  });
2866
- function hoverMarks(marks, source, segment) {
3214
+ const marksFor = (keys) => keys.length === 1 ? marksOf(keys[0]) : [...new Set(keys.flatMap(marksOf))];
3215
+ function hoverMarks(marks, source, effects, segment) {
2867
3216
  if (marks.length === 0) return;
2868
- runner.hover(marks.map(({ input }) => input));
3217
+ if (effects) runner.hover(marks.map(({ input }) => input));
2869
3218
  const count = marks.length;
2870
3219
  marks.forEach(({ input }, index) => events.emit("hover", { ...input, batch: { index, count }, source, ...segment === void 0 ? {} : { segment } }));
2871
3220
  }
@@ -2877,22 +3226,27 @@ function chartHover(options) {
2877
3226
  const count = marks.length;
2878
3227
  marks.forEach(({ input }, index) => events.emit("leave", { ...input, batch: { index, count } }));
2879
3228
  }
2880
- function startHover(key, source, segment) {
2881
- const marks = onScreen(marksOf(key));
2882
- hovered = { key, source, marks: marks.map((mark) => mark.key) };
3229
+ function startHover(keys, source, segment, effects = true) {
3230
+ const marks = onScreen(marksFor(keys));
3231
+ const started = { keys, source, marks: marks.map((mark) => mark.key), effects };
3232
+ hovered = started;
2883
3233
  for (const { key: mark } of marks) markElement(mark)?.classList.add("ec-hot");
2884
3234
  if (options.dim()) svg.classList.add("ec-hovering");
2885
- options.tooltip.show(key);
2886
- listenForEscape(true);
2887
- hoverMarks(marks, source, segment);
3235
+ if (source !== "linked") {
3236
+ options.tooltip.show(keys[0]);
3237
+ listenForEscape(true);
3238
+ }
3239
+ hoverMarks(marks, source, effects, segment);
3240
+ if (source !== "linked" && hovered === started) linked2?.hover(marks.map(({ input }) => input));
2888
3241
  }
2889
3242
  function endHover() {
2890
- const marks = hovered?.marks ?? [];
3243
+ const ended = hovered;
2891
3244
  hovered = void 0;
2892
3245
  listenForEscape(false);
2893
3246
  svg.classList.remove("ec-hovering");
2894
3247
  options.tooltip.hide();
2895
- leaveMarks(marks);
3248
+ leaveMarks(ended?.marks ?? []);
3249
+ if (own(ended)) linked2?.leave();
2896
3250
  }
2897
3251
  let escapeDoc;
2898
3252
  const dismiss = (event) => {
@@ -2911,57 +3265,80 @@ function chartHover(options) {
2911
3265
  const interaction = pointerHover(svg, {
2912
3266
  find: options.find,
2913
3267
  hover(target, source) {
2914
- if (!options.live(target.key) || hovered?.key === target.key) return;
3268
+ if (!options.live(target.key) || own(hovered) && hovered.keys[0] === target.key) return;
2915
3269
  endHover();
2916
- startHover(target.key, source, target.segment);
3270
+ startHover([target.key], source, target.segment);
2917
3271
  },
2918
3272
  leave() {
2919
- if (hovered?.source !== "keyboard") endHover();
2920
- }
3273
+ if (hovered?.source === "pointer" || hovered?.source === "touch") endHover();
3274
+ },
3275
+ // The pointer can move onto the tooltip of the chart's own hover. A link's has none.
3276
+ tooltip: () => own(hovered) ? { key: hovered.keys[0], element: options.tooltip.element?.() } : void 0
2921
3277
  });
2922
3278
  const keyboard = keyboardFocus(() => svg, {
2923
3279
  find: (eventTarget) => options.find(eventTarget)?.key,
2924
3280
  order: options.order,
3281
+ page: (key, by) => options.page?.(key, by),
2925
3282
  element: options.element,
2926
3283
  focus(key, visible) {
2927
3284
  ringKey = visible ? key : void 0;
2928
3285
  options.ring(ringKey);
2929
3286
  if (!options.live(key)) return;
2930
3287
  if (!visible) {
2931
- if (hovered?.source === "keyboard" && hovered.key !== key) endHover();
3288
+ if (hovered?.source === "keyboard" && hovered.keys[0] !== key) endHover();
2932
3289
  return;
2933
3290
  }
2934
- if (hovered?.key === key) {
3291
+ if (own(hovered) && hovered.keys[0] === key) {
2935
3292
  hovered = { ...hovered, source: "keyboard" };
2936
3293
  return;
2937
3294
  }
2938
3295
  endHover();
2939
- startHover(key, "keyboard");
3296
+ startHover([key], "keyboard");
2940
3297
  },
2941
3298
  blur() {
2942
3299
  ringKey = void 0;
2943
3300
  options.ring(ringKey);
2944
3301
  if (hovered?.source !== "keyboard") return;
2945
- if (interaction.current === hovered.key) hovered = { ...hovered, source: "pointer" };
3302
+ if (interaction.current === hovered.keys[0]) hovered = { ...hovered, source: "pointer" };
2946
3303
  else endHover();
2947
3304
  },
2948
3305
  escape() {
2949
3306
  if (!hovered) return false;
2950
- endHover();
3307
+ if (hovered.source === "linked" && linked2) linked2.dismiss();
3308
+ else endHover();
2951
3309
  return true;
2952
3310
  }
2953
3311
  });
3312
+ const link2 = {
3313
+ targets: () => options.order().map((key) => ({ key, marks: onScreen(marksOf(key)).map(({ input }) => input) })),
3314
+ hover(keys, effects) {
3315
+ if (hovered !== void 0) endHover();
3316
+ const live = keys.filter(options.live);
3317
+ if (live.length > 0) startHover(live, "linked", void 0, effects);
3318
+ },
3319
+ unlink() {
3320
+ if (hovered?.source === "linked") endHover();
3321
+ },
3322
+ leave: leave2,
3323
+ listen(listener) {
3324
+ if (destroyed) return false;
3325
+ linked2 = listener;
3326
+ return true;
3327
+ }
3328
+ };
2954
3329
  return {
2955
3330
  get key() {
2956
- return hovered?.key;
3331
+ return own(hovered) ? hovered.keys[0] : void 0;
2957
3332
  },
2958
3333
  get ringKey() {
2959
3334
  return ringKey;
2960
3335
  },
3336
+ link: link2,
2961
3337
  active: () => keyboard.active(),
2962
3338
  restyled(key) {
2963
3339
  if (ringKey !== void 0 && within(ringKey, key)) options.ring(ringKey);
2964
- if (hovered !== void 0 && (hovered.marks.includes(key) || key === hovered.key) && options.live(hovered.key)) options.tooltip.show(hovered.key);
3340
+ const target = own(hovered) ? hovered.keys[0] : void 0;
3341
+ if (target !== void 0 && (hovered?.marks.includes(key) || key === target) && options.live(target)) options.tooltip.show(target);
2965
3342
  },
2966
3343
  syncDim() {
2967
3344
  if (!options.dim()) svg.classList.remove("ec-hovering");
@@ -2969,22 +3346,24 @@ function chartHover(options) {
2969
3346
  },
2970
3347
  dropGone() {
2971
3348
  if (hovered === void 0) return;
2972
- if (!options.live(hovered.key)) {
3349
+ const keys = hovered.keys.filter(options.live);
3350
+ if (keys.length === 0) {
2973
3351
  interaction.clear();
2974
3352
  endHover();
2975
3353
  return;
2976
3354
  }
2977
- const { source, marks: before } = hovered;
2978
- const now = onScreen(marksOf(hovered.key));
3355
+ const { source, marks: before, effects } = hovered;
3356
+ const now = onScreen(marksFor(keys));
3357
+ hovered = { ...hovered, keys };
2979
3358
  if (now.length === before.length && now.every((mark, i) => mark.key === before[i])) return;
2980
3359
  const had = new Set(before);
2981
- const keys = new Set(now.map((mark) => mark.key));
2982
- const gone = onScreen(before.filter((key) => !keys.has(key)));
3360
+ const kept = new Set(now.map((mark) => mark.key));
3361
+ const gone = onScreen(before.filter((key) => !kept.has(key)));
2983
3362
  hovered = { ...hovered, marks: now.map((mark) => mark.key) };
2984
3363
  for (const { key } of gone) markElement(key)?.classList.remove("ec-hot");
2985
3364
  for (const { key } of now) if (!had.has(key)) markElement(key)?.classList.add("ec-hot");
2986
3365
  runner.leave(before);
2987
- runner.hover(now.map(({ input }) => input));
3366
+ if (effects) runner.hover(now.map(({ input }) => input));
2988
3367
  gone.forEach(({ input }, index) => events.emit("leave", { ...input, batch: { index, count: gone.length } }));
2989
3368
  const count = now.length;
2990
3369
  now.forEach(({ key, input }, index) => {
@@ -2997,6 +3376,9 @@ function chartHover(options) {
2997
3376
  },
2998
3377
  leave: leave2,
2999
3378
  destroy() {
3379
+ destroyed = true;
3380
+ linked2?.gone();
3381
+ linked2 = void 0;
3000
3382
  listenForEscape(false);
3001
3383
  interaction.destroy();
3002
3384
  keyboard.destroy();
@@ -3072,9 +3454,9 @@ function checkTableOption(option, chart) {
3072
3454
  throw new TypeError(`${chart}: ${what}`);
3073
3455
  };
3074
3456
  if (typeof option !== "object" || option === null) fail('table must be true, false, "hidden" or an object of table options.');
3075
- const { hidden: hidden2, columns, category, total: total2, share, summary, series } = option;
3457
+ const { hidden: hidden2, columns, category, total: total2, share, summary: summary2, series } = option;
3076
3458
  if (hidden2 !== void 0 && typeof hidden2 !== "boolean") fail("table.hidden must be true or false.");
3077
- for (const [name, text2] of Object.entries({ category, total: total2, share, summary })) {
3459
+ for (const [name, text2] of Object.entries({ category, total: total2, share, summary: summary2 })) {
3078
3460
  if (text2 !== void 0 && typeof text2 !== "string") fail(`table.${name} must be a string.`);
3079
3461
  }
3080
3462
  if (series !== void 0) {
@@ -3093,6 +3475,7 @@ function checkTableOption(option, chart) {
3093
3475
  if (column.after !== void 0 && column.after !== "category" && column.after !== "values") fail(`table.columns[${i}].after must be "category" or "values".`);
3094
3476
  });
3095
3477
  }
3478
+ var MISSING = "missing";
3096
3479
  function tableModel(input) {
3097
3480
  const { option, format: format2 } = input;
3098
3481
  if (option === false) return void 0;
@@ -3105,12 +3488,12 @@ function tableModel(input) {
3105
3488
  const grand = input.rows.reduce((sum2, row) => sum2 + row.total, 0);
3106
3489
  const share = (value) => input.shares ? [{ text: percent(grand > 0 ? value / grand : 0), numeric: true }] : [];
3107
3490
  const header = (column) => ({ text: column.label, numeric: false });
3108
- const own = (series) => options.series && Object.prototype.hasOwnProperty.call(options.series, series) ? options.series[series] : void 0;
3491
+ const own2 = (series) => options.series && Object.prototype.hasOwnProperty.call(options.series, series) ? options.series[series] : void 0;
3109
3492
  const blank = () => ({ text: "", numeric: false });
3110
3493
  const headers = [
3111
3494
  { text: options.category ?? input.category ?? "Category", numeric: false },
3112
3495
  ...first.map(header),
3113
- ...input.series.map((series) => ({ text: own(series) ?? input.label?.(series) ?? series, numeric: true })),
3496
+ ...input.series.map((series) => ({ text: own2(series) ?? input.label?.(series) ?? series, numeric: true })),
3114
3497
  ...totals ? [{ text: options.total ?? "Total", numeric: true }] : [],
3115
3498
  ...input.shares ? [{ text: options.share ?? "Share", numeric: true }] : [],
3116
3499
  ...last.map(header)
@@ -3122,7 +3505,7 @@ function tableModel(input) {
3122
3505
  cells: [
3123
3506
  { text: row.category, numeric: false },
3124
3507
  ...first.map((column) => columnCell(column, row, format2)),
3125
- ...input.series.map((series) => number2(values.get(series) ?? 0)),
3508
+ ...input.series.map((series) => row.missing?.has(series) ? { text: MISSING, numeric: true } : number2(values.get(series) ?? 0)),
3126
3509
  ...totals ? [number2(row.total)] : [],
3127
3510
  ...share(row.total),
3128
3511
  ...last.map((column) => columnCell(column, row, format2))
@@ -3163,14 +3546,14 @@ function columnCell(column, row, format2) {
3163
3546
  function chartTable(svg) {
3164
3547
  const doc = svg.ownerDocument;
3165
3548
  let wrapper;
3166
- let summary;
3549
+ let summary2;
3167
3550
  let table;
3168
- let caption;
3551
+ let caption2;
3169
3552
  let head;
3170
3553
  let body;
3171
3554
  let foot;
3172
3555
  const rows2 = /* @__PURE__ */ new Map();
3173
- let drawn = "";
3556
+ let drawn2 = "";
3174
3557
  const element = (tag, className) => {
3175
3558
  const made = doc.createElement(tag);
3176
3559
  if (className) made.className = className;
@@ -3178,12 +3561,12 @@ function chartTable(svg) {
3178
3561
  };
3179
3562
  function build() {
3180
3563
  table = element("table");
3181
- caption = element("caption", "ec-table-caption");
3564
+ caption2 = element("caption", "ec-table-caption");
3182
3565
  const thead = element("thead");
3183
3566
  head = element("tr");
3184
3567
  thead.appendChild(head);
3185
3568
  body = element("tbody");
3186
- table.append(caption, thead, body);
3569
+ table.append(caption2, thead, body);
3187
3570
  return table;
3188
3571
  }
3189
3572
  function place(hidden2, text2) {
@@ -3192,19 +3575,19 @@ function chartTable(svg) {
3192
3575
  const next = hidden2 ? element("div", "ec-table ec-visually-hidden") : element("details", "ec-table");
3193
3576
  const content = table ?? build();
3194
3577
  if (hidden2) {
3195
- summary = void 0;
3578
+ summary2 = void 0;
3196
3579
  next.appendChild(content);
3197
3580
  } else {
3198
- summary = element("summary");
3581
+ summary2 = element("summary");
3199
3582
  const scroll = element("div", "ec-table-scroll");
3200
3583
  scroll.appendChild(content);
3201
- next.append(summary, scroll);
3584
+ next.append(summary2, scroll);
3202
3585
  }
3203
3586
  if (wrapper?.isConnected) wrapper.replaceWith(next);
3204
3587
  wrapper = next;
3205
3588
  }
3206
3589
  if (!wrapper.isConnected) svg.after(wrapper);
3207
- if (summary && summary.textContent !== text2) summary.textContent = text2;
3590
+ if (summary2 && summary2.textContent !== text2) summary2.textContent = text2;
3208
3591
  }
3209
3592
  function fill(cell, { text: text2, numeric: numeric3 }) {
3210
3593
  if (cell.textContent !== text2) cell.textContent = text2;
@@ -3212,9 +3595,9 @@ function chartTable(svg) {
3212
3595
  }
3213
3596
  function remove() {
3214
3597
  wrapper?.remove();
3215
- wrapper = summary = table = caption = head = body = foot = void 0;
3598
+ wrapper = summary2 = table = caption2 = head = body = foot = void 0;
3216
3599
  rows2.clear();
3217
- drawn = "";
3600
+ drawn2 = "";
3218
3601
  }
3219
3602
  return {
3220
3603
  render(model) {
@@ -3223,10 +3606,10 @@ function chartTable(svg) {
3223
3606
  return;
3224
3607
  }
3225
3608
  place(model.hidden, model.summary);
3226
- if (caption.textContent !== model.caption) caption.textContent = model.caption;
3609
+ if (caption2.textContent !== model.caption) caption2.textContent = model.caption;
3227
3610
  const headers = JSON.stringify(model.headers);
3228
- if (headers !== drawn) {
3229
- drawn = headers;
3611
+ if (headers !== drawn2) {
3612
+ drawn2 = headers;
3230
3613
  head.replaceChildren(
3231
3614
  ...model.headers.map((header) => {
3232
3615
  const th = element("th");
@@ -3387,10 +3770,10 @@ function chartTransitions(options) {
3387
3770
  });
3388
3771
  },
3389
3772
  supersede: () => supersede?.(),
3390
- wait(settled, leaves) {
3773
+ wait(settled, leaves2) {
3391
3774
  return new Promise((resolve) => {
3392
3775
  supersede = resolve;
3393
- void settled.then(() => Promise.all(leaves.map((leave2) => leave2.gone))).then(() => resolve());
3776
+ void settled.then(() => Promise.all(leaves2.map((leave2) => leave2.gone))).then(() => resolve());
3394
3777
  });
3395
3778
  },
3396
3779
  destroy() {
@@ -3407,20 +3790,22 @@ function playUpdate(options, arrange, announce) {
3407
3790
  const diff = arrange();
3408
3791
  options.swap?.(diff);
3409
3792
  options.hover.dropGone();
3410
- const leaves = diff.exiting.map((record) => record.leave);
3793
+ const leaves2 = diff.exiting.map((record) => record.leave);
3411
3794
  const exited = runner.exit(diff.exiting.map(onScreen));
3412
3795
  void exited.then(() => {
3413
- for (const leave2 of leaves) leave2.exited = true;
3796
+ for (const leave2 of leaves2) leave2.exited = true;
3414
3797
  options.leaving.sweep();
3415
3798
  });
3416
3799
  events.emitEach("exit", diff.exiting, onScreen);
3417
- runner.update(diff.changed.map(({ record, from }) => ({ ...input(record), from })));
3800
+ if (options.data || diff.changed.length > 0 || diff.entering.length > 0 || diff.exiting.length > 0) {
3801
+ runner.update(diff.changed.map(({ record, from }) => ({ ...input(record), from })));
3802
+ }
3418
3803
  events.emitEach("update", diff.changed, ({ record, from }) => ({ ...input(record), from }));
3419
3804
  runner.enter(diff.entering.map(input));
3420
3805
  events.emitEach("enter", diff.entering, input);
3421
3806
  announce(diff);
3422
3807
  options.hover.sync();
3423
- return leaves;
3808
+ return leaves2;
3424
3809
  }
3425
3810
  function busy(value, to, equal) {
3426
3811
  return value.animating || !equal(value.value, to);
@@ -3431,11 +3816,18 @@ function sameFields(a, b) {
3431
3816
  return keys.length === Object.keys(b).length && keys.every((key) => a[key] === b[key]);
3432
3817
  }
3433
3818
  function geometryChanged(from, to) {
3434
- if (from.outline.d !== to.outline.d) return true;
3819
+ if (from.outline.d !== to.outline.d || labelsMoved(from, to)) return true;
3435
3820
  const a = from.segments ?? [];
3436
3821
  const b = to.segments ?? [];
3437
3822
  return a.length !== b.length || a.some((segment, i) => segment.key !== b[i].key || segment.outline.d !== b[i].outline.d);
3438
3823
  }
3824
+ function labelsMoved(from, to) {
3825
+ const a = from.labelBounds;
3826
+ const b = to.labelBounds;
3827
+ if (a === b) return false;
3828
+ if (!a || !b || a.length !== b.length) return true;
3829
+ return a.some((box, i) => box.x !== b[i].x || box.y !== b[i].y || box.width !== b[i].width || box.height !== b[i].height);
3830
+ }
3439
3831
 
3440
3832
  // src/charts/shell/watch.ts
3441
3833
  function watchWidth(container, clock, width, resize) {
@@ -3475,6 +3867,7 @@ function watchHoverDuration(svg, motion2) {
3475
3867
 
3476
3868
  // src/charts/tooltip.ts
3477
3869
  var GAP2 = 12;
3870
+ var OVERLAP = 1;
3478
3871
  var FADE = 100;
3479
3872
  var described = 0;
3480
3873
  function placeTooltip(anchor, size2, box, side) {
@@ -3496,27 +3889,54 @@ function summaryContent(category, values, format2, options = {}) {
3496
3889
  function chartTooltip(svg, options) {
3497
3890
  let layer;
3498
3891
  let box;
3892
+ let bridge;
3499
3893
  let texts = /* @__PURE__ */ new WeakMap();
3500
3894
  let rendered;
3501
- const timing = (element2) => element2.style.setProperty("--ec-hover-duration", `${options.motion.duration(FADE, "feedback")}ms`);
3502
- function element() {
3503
- if (!layer || !box) {
3895
+ let pointer;
3896
+ let through = false;
3897
+ let shape;
3898
+ const timing = (element) => element.style.setProperty("--ec-hover-duration", `${options.motion.duration(FADE, "feedback")}ms`);
3899
+ const shown = () => box?.classList.contains("ec-tooltip-shown") ?? false;
3900
+ const under = () => {
3901
+ if (!pointer || !box || !layer) return false;
3902
+ const { x, y } = pointer;
3903
+ const { left, right, top, bottom } = box.getBoundingClientRect();
3904
+ if (x > left && x < right && y > top && y < bottom) return true;
3905
+ if (!shape) return false;
3906
+ const origin = layer.getBoundingClientRect();
3907
+ return inside(shape, x - origin.left, y - origin.top);
3908
+ };
3909
+ const letThrough = (on) => {
3910
+ through = on;
3911
+ layer?.classList.toggle("ec-tooltip-through", on);
3912
+ };
3913
+ const track = (event) => {
3914
+ pointer = event.pointerType === "touch" ? void 0 : { x: event.clientX, y: event.clientY };
3915
+ if (through && !under()) letThrough(false);
3916
+ };
3917
+ svg.ownerDocument.addEventListener("pointerover", track, true);
3918
+ svg.ownerDocument.addEventListener("pointermove", track, true);
3919
+ function made() {
3920
+ if (!layer || !box || !bridge) {
3504
3921
  const doc = svg.ownerDocument;
3505
3922
  layer = doc.createElement("div");
3506
3923
  layer.className = "ec-tooltip-layer";
3507
3924
  box = doc.createElement("div");
3508
3925
  box.className = "ec-tooltip";
3509
3926
  box.setAttribute("aria-hidden", "true");
3510
- layer.appendChild(box);
3927
+ bridge = doc.createElement("div");
3928
+ bridge.className = "ec-tooltip-bridge";
3929
+ bridge.setAttribute("aria-hidden", "true");
3930
+ layer.append(box, bridge);
3511
3931
  }
3512
3932
  if (layer.previousSibling !== svg) svg.after(layer);
3513
3933
  return box;
3514
3934
  }
3515
- function contentFor(row, summary) {
3935
+ function contentFor(row, summary2) {
3516
3936
  const option = options.option();
3517
3937
  const known = texts.get(row);
3518
3938
  if (known && known.option === option) return known.content;
3519
- const content = text(option, row.datum, summary);
3939
+ const content = text(option, row.datum, summary2);
3520
3940
  texts.set(row, { option, content });
3521
3941
  return content;
3522
3942
  }
@@ -3524,14 +3944,16 @@ function chartTooltip(svg, options) {
3524
3944
  if (!box) return;
3525
3945
  timing(box);
3526
3946
  box.classList.remove("ec-tooltip-shown");
3947
+ letThrough(false);
3527
3948
  }
3528
- function place(row, summary, anchor, moved) {
3529
- const content = contentFor(row, summary);
3949
+ function place(row, summary2, anchor, moved) {
3950
+ const content = contentFor(row, summary2);
3530
3951
  if (content === void 0) {
3531
3952
  hide();
3532
3953
  return;
3533
3954
  }
3534
- const tip = element();
3955
+ const tip = made();
3956
+ const held = shown() && !through && under();
3535
3957
  const key = typeof content === "string" ? `text:${content}` : JSON.stringify(content);
3536
3958
  if (key !== rendered) {
3537
3959
  render(tip, content);
@@ -3543,65 +3965,103 @@ function chartTooltip(svg, options) {
3543
3965
  const toPx = { x: (x) => (x - view.x) * k, y: (y) => (y - view.y) * k };
3544
3966
  const area = chart.width > 0 ? { width: chart.width, height: chart.height } : { width: view.width, height: view.height };
3545
3967
  const size2 = { width: tip.offsetWidth, height: tip.offsetHeight };
3546
- const placed = placeTooltip(anchor(toPx, moved), size2, area, moved ? placeTooltip(anchor(toPx, false), size2, area).side : void 0);
3968
+ const near = anchor(toPx, moved);
3969
+ const placed2 = placeTooltip(near, size2, area, moved ? placeTooltip(anchor(toPx, false), size2, area).side : void 0);
3547
3970
  const origin = layer.getBoundingClientRect();
3548
- tip.style.left = `${Math.round(chart.left - origin.left + placed.x)}px`;
3549
- tip.style.top = `${Math.round(chart.top - origin.top + placed.y)}px`;
3550
- tip.setAttribute("data-side", placed.side);
3971
+ const dx = chart.left - origin.left;
3972
+ const dy = chart.top - origin.top;
3973
+ const left = Math.round(dx + placed2.x);
3974
+ const top = Math.round(dy + placed2.y);
3975
+ tip.style.left = `${left}px`;
3976
+ tip.style.top = `${top}px`;
3977
+ tip.setAttribute("data-side", placed2.side);
3978
+ const mark = near.left === void 0 || near.right === void 0 ? void 0 : { left: dx + near.left, right: dx + near.right, top: dy + near.top, bottom: dy + near.bottom };
3979
+ shape = span(bridge, { left, top, ...size2 }, mark, placed2.side);
3551
3980
  timing(tip);
3552
3981
  tip.classList.add("ec-tooltip-shown");
3982
+ letThrough(!held && under());
3553
3983
  }
3554
3984
  return {
3555
- show(mark, row, summary, transform) {
3985
+ show(mark, row, summary2, transform) {
3556
3986
  const anchor = (toPx, moved) => {
3557
3987
  const m = moved ? transform : void 0;
3558
3988
  const { x, y, width, height } = mark.bounds;
3559
- const ys = [{ x, y }, { x: x + width, y }, { x, y: y + height }, { x: x + width, y: y + height }].map((corner) => m ? matrix.apply(m, corner).y : corner.y);
3989
+ const corners = [{ x, y }, { x: x + width, y }, { x, y: y + height }, { x: x + width, y: y + height }].map((corner) => m ? matrix.apply(m, corner) : corner);
3990
+ const xs = corners.map((corner) => corner.x);
3991
+ const ys = corners.map((corner) => corner.y);
3560
3992
  const center = m ? matrix.apply(m, mark.center) : mark.center;
3561
- return { x: toPx.x(center.x), top: toPx.y(Math.min(...ys)), bottom: toPx.y(Math.max(...ys)) };
3993
+ return { x: toPx.x(center.x), top: toPx.y(Math.min(...ys)), bottom: toPx.y(Math.max(...ys)), left: toPx.x(Math.min(...xs)), right: toPx.x(Math.max(...xs)) };
3562
3994
  };
3563
- place(row, summary, anchor, transform !== void 0);
3995
+ place(row, summary2, anchor, transform !== void 0);
3564
3996
  },
3565
- showAt(point, row, summary) {
3566
- place(row, summary, (toPx) => ({ x: toPx.x(point.x), top: toPx.y(point.top), bottom: toPx.y(point.bottom) }), false);
3997
+ showAt(point, row, summary2) {
3998
+ place(row, summary2, (toPx) => ({ x: toPx.x(point.x), top: toPx.y(point.top), bottom: toPx.y(point.bottom) }), false);
3567
3999
  },
3568
- describe(element2, row) {
3569
- const own = options.description?.();
4000
+ describe(element, row) {
4001
+ const own2 = options.description?.();
3570
4002
  let content;
3571
- if (own === false) content = void 0;
3572
- else if (typeof own === "function") {
4003
+ if (own2 === false) content = void 0;
4004
+ else if (typeof own2 === "function") {
3573
4005
  try {
3574
- const text2 = own(row.datum);
4006
+ const text2 = own2(row.datum);
3575
4007
  content = typeof text2 === "string" && text2 !== "" ? text2 : void 0;
3576
4008
  } catch (error) {
3577
4009
  report(error);
3578
4010
  content = void 0;
3579
4011
  }
3580
4012
  } else content = typeof options.option() === "function" ? contentFor(row, () => "") : void 0;
3581
- let desc = element2.querySelector(":scope > desc.ec-description");
4013
+ let desc = element.querySelector(":scope > desc.ec-description");
3582
4014
  if (typeof content !== "string") {
3583
4015
  if (!desc) return;
3584
- if (element2.getAttribute("aria-describedby") === desc.id) element2.removeAttribute("aria-describedby");
4016
+ if (element.getAttribute("aria-describedby") === desc.id) element.removeAttribute("aria-describedby");
3585
4017
  desc.remove();
3586
4018
  return;
3587
4019
  }
3588
- desc ?? (desc = svgElement("desc", { class: "ec-description", id: `ec-description-${++described}` }, element2));
4020
+ desc ?? (desc = svgElement("desc", { class: "ec-description", id: `ec-description-${++described}` }, element));
3589
4021
  if (desc.textContent !== content) desc.textContent = content;
3590
- element2.setAttribute("aria-describedby", desc.id);
4022
+ element.setAttribute("aria-describedby", desc.id);
3591
4023
  },
4024
+ element: () => shown() ? layer : void 0,
3592
4025
  hide,
3593
4026
  destroy() {
4027
+ svg.ownerDocument.removeEventListener("pointerover", track, true);
4028
+ svg.ownerDocument.removeEventListener("pointermove", track, true);
3594
4029
  layer?.remove();
3595
4030
  layer = void 0;
3596
4031
  box = void 0;
4032
+ bridge = void 0;
4033
+ shape = void 0;
4034
+ through = false;
3597
4035
  texts = /* @__PURE__ */ new WeakMap();
3598
4036
  rendered = void 0;
3599
4037
  }
3600
4038
  };
3601
4039
  }
3602
- function text(option, datum, summary) {
4040
+ function inside({ top, bottom, upper, lower }, x, y) {
4041
+ if (y <= top || y >= bottom) return false;
4042
+ const t = (y - top) / (bottom - top);
4043
+ return x > upper.left + (lower.left - upper.left) * t && x < upper.right + (lower.right - upper.right) * t;
4044
+ }
4045
+ function span(bridge, box, mark, side) {
4046
+ bridge.hidden = mark === void 0;
4047
+ if (!mark) return void 0;
4048
+ const edge = { left: box.left, right: box.left + box.width };
4049
+ const [upper, lower, top, bottom] = side === "above" ? [edge, mark, box.top + box.height, Math.round(mark.top + OVERLAP)] : [mark, edge, Math.round(mark.bottom - OVERLAP), box.top];
4050
+ const left = Math.round(Math.min(upper.left, lower.left));
4051
+ const width = Math.round(Math.max(upper.right, lower.right)) - left;
4052
+ const height = Math.max(0, bottom - top);
4053
+ const x = (value) => `${Math.round(value) - left}px`;
4054
+ bridge.style.left = `${left}px`;
4055
+ bridge.style.top = `${top}px`;
4056
+ bridge.style.width = `${width}px`;
4057
+ bridge.style.height = `${height}px`;
4058
+ bridge.style.setProperty("clip-path", `polygon(${x(upper.left)} 0px, ${x(upper.right)} 0px, ${x(lower.right)} ${height}px, ${x(lower.left)} ${height}px)`);
4059
+ const round5 = (edge2) => ({ left: Math.round(edge2.left), right: Math.round(edge2.right) });
4060
+ return { top, bottom: top + height, upper: round5(upper), lower: round5(lower) };
4061
+ }
4062
+ function text(option, datum, summary2) {
3603
4063
  if (option === false) return void 0;
3604
- if (typeof option !== "function") return summary();
4064
+ if (typeof option !== "function") return summary2();
3605
4065
  try {
3606
4066
  const result = option(datum);
3607
4067
  return result === void 0 || result === null || result === "" ? void 0 : String(result);
@@ -3625,8 +4085,8 @@ function render(box, content) {
3625
4085
  box.replaceChildren(line2(content.title, "ec-tooltip-title"), ...content.lines.map((value) => line2(value)));
3626
4086
  }
3627
4087
  function viewBox(svg) {
3628
- const parts = (svg.getAttribute("viewBox") ?? "").split(/[\s,]+/).map(Number);
3629
- if (parts.length === 4 && parts.every(Number.isFinite)) return { x: parts[0], y: parts[1], width: parts[2], height: parts[3] };
4088
+ const parts2 = (svg.getAttribute("viewBox") ?? "").split(/[\s,]+/).map(Number);
4089
+ if (parts2.length === 4 && parts2.every(Number.isFinite)) return { x: parts2[0], y: parts2[1], width: parts2[2], height: parts2[3] };
3630
4090
  return { x: 0, y: 0, width: Number(svg.getAttribute("width")) || 0, height: Number(svg.getAttribute("height")) || 0 };
3631
4091
  }
3632
4092
 
@@ -3710,7 +4170,8 @@ function barChart(target, options, env2) {
3710
4170
  width: opts.width ?? measuredWidth,
3711
4171
  height: opts.height,
3712
4172
  format: format(opts),
3713
- measure
4173
+ measure,
4174
+ room: opts.room ?? 0
3714
4175
  });
3715
4176
  }
3716
4177
  function createRecord(row, entering) {
@@ -3771,8 +4232,8 @@ function barChart(target, options, env2) {
3771
4232
  element.remove();
3772
4233
  record.paths.delete(series);
3773
4234
  }
3774
- const drawn = Array.from(record.body.children).filter((child) => child.classList.contains("ec-segment"));
3775
- if (record.parts.some((part, i) => drawn[i] !== part.element)) for (const part of record.parts) record.body.appendChild(part.element);
4235
+ const drawn2 = Array.from(record.body.children).filter((child) => child.classList.contains("ec-segment"));
4236
+ if (record.parts.some((part, i) => drawn2[i] !== part.element)) for (const part of record.parts) record.body.appendChild(part.element);
3776
4237
  record.handle.repaint();
3777
4238
  if (record.parts[0]?.colors.color !== before) surface.recolor(record.key);
3778
4239
  if (record.key === hover.ringKey) drawRing(record.key);
@@ -3787,20 +4248,20 @@ function barChart(target, options, env2) {
3787
4248
  const { transform } = record.handle.style;
3788
4249
  setAttributes(ring, { transform: transform && transformAttribute(transform), visibility: void 0 });
3789
4250
  }
3790
- function show3(record, row) {
3791
- const moved = geometryChanged(record.shown.geometry, row.geometry);
4251
+ function show4(record, row) {
4252
+ const moved = geometryChanged(record.shown.geometry, row.geometry) || record.shown.datum !== row.datum;
3792
4253
  drawMark(record, row);
3793
4254
  if (moved) runner.change(row.geometry, row.data);
3794
4255
  if (record.key === hover.key) showTooltip(record);
3795
4256
  }
3796
4257
  function showTooltip(record) {
3797
4258
  const { row } = record;
3798
- tooltip.show(record.shown.geometry, row, () => summaryContent(row.label.text, labelled(row.values, current), format(current)), record.handle.style.transform);
4259
+ tooltip.show(record.shown.geometry, row, () => summaryContent(row.category, labelled(row.values, current), format(current)), record.handle.style.transform);
3799
4260
  }
3800
4261
  function syncLegend(next) {
3801
4262
  if (byCategory(current)) {
3802
4263
  legend.categories(
3803
- next.rows.map((row) => ({ key: row.key, label: row.label.text })),
4264
+ next.rows.map((row) => ({ key: row.key, label: row.category })),
3804
4265
  colors,
3805
4266
  current.legend
3806
4267
  );
@@ -3821,7 +4282,7 @@ function barChart(target, options, env2) {
3821
4282
  category: typeof field === "string" ? field : void 0,
3822
4283
  series: encoding.series.map((s) => s.series),
3823
4284
  label: (series) => seriesLabel(opts.seriesLabels, series),
3824
- rows: next.rows.map((row) => ({ key: row.key, category: row.label.text, datum: row.datum, index: row.index, values: row.values, total: row.total })),
4285
+ rows: next.rows.map((row) => ({ key: row.key, category: row.category, datum: row.datum, index: row.index, values: row.values, total: row.total })),
3825
4286
  format: format(opts)
3826
4287
  });
3827
4288
  }
@@ -3831,7 +4292,7 @@ function barChart(target, options, env2) {
3831
4292
  const series = barEncoding(current).series.map((s) => s.series);
3832
4293
  const before = barEncoding(previous).series.map((s) => s.series);
3833
4294
  const sort = sortName(current.sort);
3834
- const name = (record) => record.row.label.text;
4295
+ const name = (record) => record.row.category;
3835
4296
  const changed = diff.changed.map(({ record }) => record);
3836
4297
  const text2 = changeText({
3837
4298
  ...current.label !== previous.label ? { label: current.label } : {},
@@ -3849,8 +4310,8 @@ function barChart(target, options, env2) {
3849
4310
  }
3850
4311
  const key = (record) => record.key;
3851
4312
  try {
3852
- const said = option({ text: text2, changed: changed.map(key), added: diff.entering.map(key), removed: diff.exiting.map(key) });
3853
- if (said !== void 0 && said !== null) announcer.say(String(said));
4313
+ const said2 = option({ text: text2, changed: changed.map(key), added: diff.entering.map(key), removed: diff.exiting.map(key) });
4314
+ if (said2 !== void 0 && said2 !== null) announcer.say(String(said2));
3854
4315
  } catch (error) {
3855
4316
  report(error);
3856
4317
  }
@@ -3862,7 +4323,7 @@ function barChart(target, options, env2) {
3862
4323
  const values = record.series.map((series) => ({ series, value: now[series] ?? 0 }));
3863
4324
  const total2 = values.reduce((sum, v) => sum + v.value, 0);
3864
4325
  const text2 = record.count === void 0 ? row.value.text : format(current)(round(total2, record.count));
3865
- return placeRow(frame2, { key: row.key, datum: row.datum, index: row.index, category: row.label.text, values, slot: record.slot.value, text: text2 });
4326
+ return placeRow(frame2, { key: row.key, datum: row.datum, index: row.index, category: row.category, values, slot: record.slot.value, text: text2, drawn: row.drawn }, measure);
3866
4327
  }
3867
4328
  function addTick(value, opacity) {
3868
4329
  const tick = {
@@ -3879,10 +4340,10 @@ function barChart(target, options, env2) {
3879
4340
  }
3880
4341
  }
3881
4342
  function drawTick(tick, frame2) {
3882
- const placed = placeTick(frame2, tick.value, format(current)(tick.value));
4343
+ const placed2 = placeTick(frame2, tick.value, format(current)(tick.value));
3883
4344
  const opacity = tick.opacity.value < 1 ? tick.opacity.value : void 0;
3884
- setAttributes(tick.line, { ...placed.line, opacity });
3885
- placeText(tick.label, placed.label);
4345
+ setAttributes(tick.line, { ...placed2.line, opacity });
4346
+ placeText(tick.label, placed2.label);
3886
4347
  setAttributes(tick.label, { opacity });
3887
4348
  }
3888
4349
  function draw() {
@@ -3890,7 +4351,7 @@ function barChart(target, options, env2) {
3890
4351
  if (frameMoved) setAttributes(svg, sizeAttributes(frame2.bands));
3891
4352
  if (frameMoved || ticksFaded) for (const tick of ticks.values()) drawTick(tick, frame2);
3892
4353
  for (const record of [...order, ...leaving.values()]) {
3893
- if (frameMoved || dirty.has(record)) show3(record, currentRow(record, frame2));
4354
+ if (frameMoved || dirty.has(record)) show4(record, currentRow(record, frame2));
3894
4355
  }
3895
4356
  frameMoved = false;
3896
4357
  ticksFaded = false;
@@ -3904,17 +4365,17 @@ function barChart(target, options, env2) {
3904
4365
  tick.label.remove();
3905
4366
  ticks.delete(tick.value);
3906
4367
  }
3907
- for (const placed of laidOut.ticks) {
3908
- const tick = ticks.get(placed.value);
4368
+ for (const placed2 of laidOut.ticks) {
4369
+ const tick = ticks.get(placed2.value);
3909
4370
  if (!tick) continue;
3910
- setAttributes(tick.line, { ...placed.line, opacity: void 0 });
3911
- placeText(tick.label, placed.label);
4371
+ setAttributes(tick.line, { ...placed2.line, opacity: void 0 });
4372
+ placeText(tick.label, placed2.label);
3912
4373
  tick.label.removeAttribute("opacity");
3913
4374
  }
3914
4375
  for (const record of order) {
3915
4376
  record.series = record.row.values.map((v) => v.series);
3916
4377
  record.count = void 0;
3917
- show3(record, record.row);
4378
+ show4(record, record.row);
3918
4379
  }
3919
4380
  frameMoved = false;
3920
4381
  ticksFaded = false;
@@ -4042,7 +4503,8 @@ function barChart(target, options, env2) {
4042
4503
  const record = records.get(key);
4043
4504
  if (record) showTooltip(record);
4044
4505
  },
4045
- hide: () => tooltip.hide()
4506
+ hide: () => tooltip.hide(),
4507
+ element: () => tooltip.element()
4046
4508
  }
4047
4509
  });
4048
4510
  const unwatchHoverDuration = watchHoverDuration(svg, motion2);
@@ -4075,7 +4537,7 @@ function barChart(target, options, env2) {
4075
4537
  });
4076
4538
  hover.sync();
4077
4539
  runner.enter(order.map(input));
4078
- return {
4540
+ return linkable(hover.link, {
4079
4541
  element: svg,
4080
4542
  async update(next) {
4081
4543
  if (destroyed) return;
@@ -4101,7 +4563,7 @@ function barChart(target, options, env2) {
4101
4563
  transitions.supersede();
4102
4564
  const swapping = swapped !== effects;
4103
4565
  effects = swapped;
4104
- const leaves = playUpdate(
4566
+ const leaves2 = playUpdate(
4105
4567
  {
4106
4568
  runner,
4107
4569
  events,
@@ -4109,6 +4571,7 @@ function barChart(target, options, env2) {
4109
4571
  leaving,
4110
4572
  input,
4111
4573
  onScreen,
4574
+ data: "data" in next,
4112
4575
  ...swapping ? {
4113
4576
  swap: (diff) => {
4114
4577
  const entering = new Set(diff.entering);
@@ -4123,7 +4586,7 @@ function barChart(target, options, env2) {
4123
4586
  );
4124
4587
  if (byCategory(current) !== byCategory(previous)) for (const record of [...order, ...leaving.values()]) dirty.add(record);
4125
4588
  const settled = transitionTo(nextLayout, motion2.mode === "off" || nextLayout.orientation !== orientation);
4126
- await transitions.wait(settled, leaves);
4589
+ await transitions.wait(settled, leaves2);
4127
4590
  },
4128
4591
  on: events.on,
4129
4592
  marks: () => order.map((record) => record.shown.geometry),
@@ -4163,11 +4626,12 @@ function barChart(target, options, env2) {
4163
4626
  order = [];
4164
4627
  svg.remove();
4165
4628
  }
4166
- };
4629
+ });
4167
4630
  }
4168
4631
  function checkOptions2(options) {
4169
4632
  checkChartOptions(options, "barChart");
4170
- const { colorBy } = options;
4633
+ const { colorBy, room } = options;
4634
+ if (room !== void 0 && !(typeof room === "number" && Number.isFinite(room) && room >= 0)) throw new RangeError(`barChart: room must be a number of px, 0 or more, got ${String(room)}.`);
4171
4635
  if (colorBy !== void 0 && colorBy !== "series" && colorBy !== "category") throw new TypeError(`barChart: colorBy must be "series" or "category", got ${String(colorBy)}.`);
4172
4636
  if (colorBy === "category" && options.stack !== void 0) {
4173
4637
  throw new TypeError('barChart: colorBy: "category" gives each bar one colour, so it needs one series, not a stack. A stack colours its segments by series.');
@@ -4180,10 +4644,10 @@ function markLabel(row, options) {
4180
4644
  const formatted = format(options);
4181
4645
  const values = labelled(row.values, options);
4182
4646
  const lone = values.length === 1 && values[0].series === "value" && values[0].label === "value";
4183
- const text2 = `${row.label.text}: ${values.map((v) => lone ? formatted(v.value) : `${formatted(v.value)} ${v.label}`).join(", ")}`;
4647
+ const text2 = `${row.category}: ${values.map((v) => lone ? formatted(v.value) : `${formatted(v.value)} ${v.label}`).join(", ")}`;
4184
4648
  if (!options.markLabel) return text2;
4185
4649
  try {
4186
- const named = options.markLabel(row.datum, { key: row.key, category: row.label.text, values, total: row.total, format: formatted, text: text2 });
4650
+ const named = options.markLabel(row.datum, { key: row.key, category: row.category, values, total: row.total, format: formatted, text: text2 });
4187
4651
  if (named !== void 0 && named !== null && String(named).trim() !== "") return String(named);
4188
4652
  } catch (error) {
4189
4653
  report(error);
@@ -4231,9 +4695,9 @@ var GAP3 = 10;
4231
4695
  var LABEL_ANGLE = Math.PI / 12;
4232
4696
  var LABEL_SIZE2 = 12.5;
4233
4697
  var VALUE_SIZE2 = 12.5;
4234
- var ASCENT = 10;
4698
+ var ASCENT2 = 10;
4235
4699
  var LINE = 15;
4236
- var BLOCK = ASCENT + LINE + 3;
4700
+ var BLOCK = ASCENT2 + LINE + 3;
4237
4701
  var LABEL_SPACE = 2;
4238
4702
  var CENTER_SIZE = 26;
4239
4703
  var CENTER_MIN = 14;
@@ -4262,17 +4726,18 @@ function layoutDonut(input) {
4262
4726
  const frame2 = donutFrame(input, rows2);
4263
4727
  const total2 = rows2.reduce((sum, row) => sum + row.value, 0);
4264
4728
  const starts = joinedStarts(rows2.map((row) => row.value));
4265
- const slices = rows2.map((row, i) => {
4729
+ const states = rows2.map((row, i) => {
4266
4730
  const share = total2 > 0 ? row.value / total2 : 0;
4267
4731
  const end = i + 1 < rows2.length && total2 > 0 ? starts[i + 1] : total2 > 0 ? 1 : 0;
4268
- return placeSlice(frame2, { ...row, series: input.encoding.series, share, start: starts[i] * TAU2, end: end * TAU2 });
4732
+ return { ...row, series: input.encoding.series, share, start: starts[i] * TAU2, end: end * TAU2 };
4269
4733
  });
4734
+ const labels = placeLabels2(frame2, states, input.measure);
4270
4735
  const centerText2 = input.center(total2);
4271
4736
  return {
4272
4737
  frame: frame2,
4273
4738
  total: total2,
4274
- slices,
4275
- labels: placeLabels(frame2, slices, input.measure),
4739
+ slices: states.map((state, i) => placeSlice(frame2, state, labels[i], input.measure)),
4740
+ labels,
4276
4741
  centerText: centerText2,
4277
4742
  center: placeCenter(frame2, centerText2, input.measure)
4278
4743
  };
@@ -4286,7 +4751,7 @@ function joinedStarts(values) {
4286
4751
  return start;
4287
4752
  });
4288
4753
  }
4289
- function placeSlice(frame2, state) {
4754
+ function placeSlice(frame2, state, label2, measure) {
4290
4755
  const geometry = describe.arc({
4291
4756
  key: state.key,
4292
4757
  series: state.series,
@@ -4295,27 +4760,28 @@ function placeSlice(frame2, state) {
4295
4760
  inner: frame2.inner,
4296
4761
  outer: frame2.outer,
4297
4762
  start: state.start,
4298
- end: state.end
4763
+ end: state.end,
4764
+ labelBounds: label2 && measure ? labelBoxes2(label2, measure) : []
4299
4765
  });
4300
4766
  return { ...state, geometry, data: sliceData(state.datum, state.share, state.series) };
4301
4767
  }
4302
- function placeLabels(frame2, slices, measure) {
4768
+ function placeLabels2(frame2, slices, measure) {
4303
4769
  let previous;
4304
4770
  let first;
4305
4771
  const labels = slices.map((slice, i) => {
4306
4772
  if (slice.end - slice.start < LABEL_ANGLE - 1e-9) return void 0;
4307
- const label = labelAt(frame2, slice, measure);
4308
- const { box } = label;
4773
+ const label2 = labelAt(frame2, slice, measure);
4774
+ const { box } = label2;
4309
4775
  if (box.x < 0 || box.y < 0 || box.x + box.width > frame2.width || box.y + box.height > frame2.height) return void 0;
4310
- if (previous && overlaps(previous, box)) return void 0;
4776
+ if (previous && overlaps2(previous, box)) return void 0;
4311
4777
  previous = box;
4312
4778
  first ?? (first = i);
4313
- return label;
4779
+ return label2;
4314
4780
  });
4315
4781
  for (let i = labels.length - 1; first !== void 0 && i > first; i--) {
4316
- const label = labels[i];
4317
- if (!label) continue;
4318
- if (!overlaps(labels[first].box, label.box)) break;
4782
+ const label2 = labels[i];
4783
+ if (!label2) continue;
4784
+ if (!overlaps2(labels[first].box, label2.box)) break;
4319
4785
  labels[i] = void 0;
4320
4786
  }
4321
4787
  return labels;
@@ -4371,12 +4837,18 @@ function labelAt(frame2, slice, measure) {
4371
4837
  const top = y - BLOCK * (cos + 1) / 2;
4372
4838
  const along = (w) => x + sin * w / 2;
4373
4839
  return {
4374
- category: { x: along(widths[0]), y: top + ASCENT, anchor: "middle", text: slice.category },
4375
- share: { x: along(widths[1]), y: top + ASCENT + LINE, anchor: "middle", text: share },
4840
+ category: { x: along(widths[0]), y: top + ASCENT2, anchor: "middle", text: slice.category },
4841
+ share: { x: along(widths[1]), y: top + ASCENT2 + LINE, anchor: "middle", text: share },
4376
4842
  box: { x: along(width) - width / 2, y: top, width, height: BLOCK }
4377
4843
  };
4378
4844
  }
4379
- function overlaps(a, b) {
4845
+ function labelBoxes2(label2, measure) {
4846
+ const out = [];
4847
+ if (label2.category.text !== "") out.push(textBox(label2.category, measure, "ec-label", LABEL_SIZE2));
4848
+ if (label2.share.text !== "") out.push(textBox(label2.share, measure, "ec-value", VALUE_SIZE2));
4849
+ return out;
4850
+ }
4851
+ function overlaps2(a, b) {
4380
4852
  return a.x < b.x + b.width + LABEL_SPACE && b.x < a.x + a.width + LABEL_SPACE && a.y < b.y + b.height + LABEL_SPACE && b.y < a.y + a.height + LABEL_SPACE;
4381
4853
  }
4382
4854
  function sliceData(datum, share, series) {
@@ -4511,7 +4983,7 @@ function donutChart(target, options, env2) {
4511
4983
  byGroup.set(group, record);
4512
4984
  return record;
4513
4985
  }
4514
- function drawMark(record, slice, label) {
4986
+ function drawMark(record, slice, label2) {
4515
4987
  const before = record.parts[0]?.colors.color;
4516
4988
  record.shown = slice;
4517
4989
  const { outline: outline2 } = slice.geometry;
@@ -4524,10 +4996,10 @@ function donutChart(target, options, env2) {
4524
4996
  record.parts = [{ element: record.path, d: outline2.d, colors: sliceColors, visible }];
4525
4997
  const presence = record.presence.value;
4526
4998
  const opacity = presence < 1 ? presence : void 0;
4527
- record.drawnLabel = label;
4999
+ record.drawnLabel = label2;
4528
5000
  for (const [text2, placement] of [
4529
- [record.label, label?.category],
4530
- [record.share, label?.share]
5001
+ [record.label, label2?.category],
5002
+ [record.share, label2?.share]
4531
5003
  ]) {
4532
5004
  if (placement) placeText(text2, placement);
4533
5005
  setAttributes(text2, { visibility: placement ? void 0 : "hidden", opacity });
@@ -4540,9 +5012,9 @@ function donutChart(target, options, env2) {
4540
5012
  const record = key === void 0 ? void 0 : records.get(key);
4541
5013
  focusRing.draw(record && { outline: record.shown.geometry.outline, thickness: record.shown.geometry.thickness, transform: record.handle.style.transform });
4542
5014
  }
4543
- function show3(record, slice, label) {
4544
- const moved = geometryChanged(record.shown.geometry, slice.geometry);
4545
- drawMark(record, slice, label);
5015
+ function show4(record, slice, label2) {
5016
+ const moved = geometryChanged(record.shown.geometry, slice.geometry) || record.shown.datum !== slice.datum;
5017
+ drawMark(record, slice, label2);
4546
5018
  if (moved) runner.change(slice.geometry, slice.data);
4547
5019
  if (record.key === hover.key) showTooltip(record);
4548
5020
  }
@@ -4604,13 +5076,13 @@ function donutChart(target, options, env2) {
4604
5076
  }
4605
5077
  const key = (record) => record.key;
4606
5078
  try {
4607
- const said = option({ text: text2, changed: changed.map(key), added: diff.entering.map(key), removed: diff.exiting.map(key) });
4608
- if (said !== void 0 && said !== null) announcer.say(String(said));
5079
+ const said2 = option({ text: text2, changed: changed.map(key), added: diff.entering.map(key), removed: diff.exiting.map(key) });
5080
+ if (said2 !== void 0 && said2 !== null) announcer.say(String(said2));
4609
5081
  } catch (error) {
4610
5082
  report(error);
4611
5083
  }
4612
5084
  }
4613
- const drawn = (record) => records.get(record.key) === record || leaving.get(record.key) === record;
5085
+ const drawn2 = (record) => records.get(record.key) === record || leaving.get(record.key) === record;
4614
5086
  const valueOf = (record) => Math.max(0, record.value.value);
4615
5087
  function startsIn(slices, total2, value = valueOf) {
4616
5088
  const starts = /* @__PURE__ */ new Map();
@@ -4622,8 +5094,8 @@ function donutChart(target, options, env2) {
4622
5094
  return starts;
4623
5095
  }
4624
5096
  function angles() {
4625
- ring = ring.filter(drawn);
4626
- from = from.filter(drawn);
5097
+ ring = ring.filter(drawn2);
5098
+ from = from.filter(drawn2);
4627
5099
  const total2 = ring.reduce((sum, record) => sum + valueOf(record), 0);
4628
5100
  const to = startsIn(ring, total2);
4629
5101
  const was = startsIn(from, total2);
@@ -4642,21 +5114,27 @@ function donutChart(target, options, env2) {
4642
5114
  return out;
4643
5115
  }
4644
5116
  function currentSlices(f) {
4645
- return [...angles()].map(([record, { start, span }]) => {
5117
+ const now = [...angles()].map(([record, { start, span: span2 }]) => {
4646
5118
  const { row } = record;
4647
- const slice = placeSlice(f, {
5119
+ const state = {
4648
5120
  key: row.key,
4649
5121
  datum: row.datum,
4650
5122
  index: row.index,
4651
5123
  category: row.category,
4652
5124
  series: row.series,
4653
5125
  value: valueOf(record),
4654
- share: span,
5126
+ share: span2,
4655
5127
  start: start * TAU3,
4656
- end: (start + span) * TAU3
4657
- });
4658
- return { record, slice };
5128
+ end: (start + span2) * TAU3
5129
+ };
5130
+ return { record, state };
4659
5131
  });
5132
+ const labels = placeLabels2(
5133
+ f,
5134
+ now.map(({ state }) => state),
5135
+ measure
5136
+ );
5137
+ return now.map(({ record, state }, i) => ({ record, slice: placeSlice(f, state, labels[i], measure), label: labels[i] }));
4660
5138
  }
4661
5139
  function draw() {
4662
5140
  if (!dirty) return;
@@ -4664,12 +5142,7 @@ function donutChart(target, options, env2) {
4664
5142
  const f = frame2.value;
4665
5143
  setAttributes(svg, sizeAttributes(f));
4666
5144
  const slices = currentSlices(f);
4667
- const labels = placeLabels(
4668
- f,
4669
- slices.map(({ slice }) => slice),
4670
- measure
4671
- );
4672
- slices.forEach(({ record, slice }, i) => show3(record, slice, labels[i]));
5145
+ for (const { record, slice, label: label2 } of slices) show4(record, slice, label2);
4673
5146
  const total2 = slices.reduce((sum, { slice }) => sum + slice.value, 0);
4674
5147
  drawCenter(placeCenter(f, count === void 0 ? laidOut.centerText : counting(round(total2, count)), measure));
4675
5148
  }
@@ -4678,7 +5151,7 @@ function donutChart(target, options, env2) {
4678
5151
  return counted.text;
4679
5152
  }
4680
5153
  function land() {
4681
- ring = ring.filter(drawn);
5154
+ ring = ring.filter(drawn2);
4682
5155
  from = ring;
4683
5156
  for (const record of ring) {
4684
5157
  record.turn.set(1);
@@ -4688,7 +5161,7 @@ function donutChart(target, options, env2) {
4688
5161
  count = void 0;
4689
5162
  counted = void 0;
4690
5163
  setAttributes(svg, sizeAttributes(laidOut.frame));
4691
- laidOut.slices.forEach((slice, i) => show3(records.get(slice.key), slice, laidOut.labels[i]));
5164
+ laidOut.slices.forEach((slice, i) => show4(records.get(slice.key), slice, laidOut.labels[i]));
4692
5165
  drawCenter(laidOut.center);
4693
5166
  dirty = false;
4694
5167
  }
@@ -4834,7 +5307,8 @@ function donutChart(target, options, env2) {
4834
5307
  const record = records.get(key);
4835
5308
  if (record) showTooltip(record);
4836
5309
  },
4837
- hide: () => tooltip.hide()
5310
+ hide: () => tooltip.hide(),
5311
+ element: () => tooltip.element()
4838
5312
  }
4839
5313
  });
4840
5314
  const unwatchHoverDuration = watchHoverDuration(svg, motion2);
@@ -4868,7 +5342,7 @@ function donutChart(target, options, env2) {
4868
5342
  drawCenter(laidOut.center);
4869
5343
  hover.sync();
4870
5344
  runner.enter(order.map(input));
4871
- return {
5345
+ return linkable(hover.link, {
4872
5346
  element: svg,
4873
5347
  async update(next) {
4874
5348
  if (destroyed) return;
@@ -4898,7 +5372,7 @@ function donutChart(target, options, env2) {
4898
5372
  transitions.supersede();
4899
5373
  const swapping = swapped !== effects;
4900
5374
  effects = swapped;
4901
- const leaves = playUpdate(
5375
+ const leaves2 = playUpdate(
4902
5376
  {
4903
5377
  runner,
4904
5378
  events,
@@ -4906,6 +5380,7 @@ function donutChart(target, options, env2) {
4906
5380
  leaving,
4907
5381
  input,
4908
5382
  onScreen,
5383
+ data: "data" in next,
4909
5384
  ...swapping ? {
4910
5385
  swap: (diff) => {
4911
5386
  const entering = new Set(diff.entering);
@@ -4920,7 +5395,7 @@ function donutChart(target, options, env2) {
4920
5395
  );
4921
5396
  count = nextLayout.total === totalBefore ? void 0 : Math.max(decimals(totalBefore), decimals(nextLayout.total));
4922
5397
  const settled = transitionTo(nextLayout, motion2.mode === "off");
4923
- await transitions.wait(settled, leaves);
5398
+ await transitions.wait(settled, leaves2);
4924
5399
  },
4925
5400
  on: events.on,
4926
5401
  marks: () => order.map((record) => record.shown.geometry),
@@ -4959,7 +5434,7 @@ function donutChart(target, options, env2) {
4959
5434
  order = ring = from = [];
4960
5435
  svg.remove();
4961
5436
  }
4962
- };
5437
+ });
4963
5438
  }
4964
5439
  function checkOptions3(options) {
4965
5440
  checkChartOptions(options, "donutChart");
@@ -4969,8 +5444,8 @@ function checkOptions3(options) {
4969
5444
  }
4970
5445
  function valueText(slice, options) {
4971
5446
  const formatted = format(options)(slice.value);
4972
- const label = seriesLabel(options.seriesLabels, slice.series);
4973
- return slice.series === "value" && label === "value" ? formatted : `${formatted} ${label}`;
5447
+ const label2 = seriesLabel(options.seriesLabels, slice.series);
5448
+ return slice.series === "value" && label2 === "value" ? formatted : `${formatted} ${label2}`;
4974
5449
  }
4975
5450
  function namesFor(options, layout) {
4976
5451
  return new Map(layout.slices.map((slice) => [slice.key, markLabel2(slice, options)]));
@@ -5000,9 +5475,9 @@ function centerText(options, series, total2) {
5000
5475
  const formatted = format(options);
5001
5476
  if (center === false) return "";
5002
5477
  if (center === void 0) {
5003
- const label = seriesLabel(options.seriesLabels, series);
5004
- return series === "value" && label === "value" ? formatted(total2) : `${formatted(total2)}
5005
- ${label}`;
5478
+ const label2 = seriesLabel(options.seriesLabels, series);
5479
+ return series === "value" && label2 === "value" ? formatted(total2) : `${formatted(total2)}
5480
+ ${label2}`;
5006
5481
  }
5007
5482
  try {
5008
5483
  const text2 = center(total2, formatted);
@@ -5012,10 +5487,10 @@ ${label}`;
5012
5487
  return "";
5013
5488
  }
5014
5489
  }
5015
- function description(own, center) {
5490
+ function description(own2, center) {
5016
5491
  const text2 = center.split("\n").join(" ").trim();
5017
- const mine = own?.trim();
5018
- if (text2 === "") return own;
5492
+ const mine = own2?.trim();
5493
+ if (text2 === "") return own2;
5019
5494
  if (!mine) return text2;
5020
5495
  return /[.!?:;]$/.test(mine) ? `${mine} ${text2}` : `${mine}. ${text2}`;
5021
5496
  }
@@ -5065,9 +5540,9 @@ var FIELDS = {
5065
5540
  second: { hour: "numeric", minute: "2-digit", second: "2-digit" },
5066
5541
  millisecond: { hour: "numeric", minute: "2-digit", second: "2-digit", ...FRACTION }
5067
5542
  };
5068
- function timeStep(span) {
5069
- for (const step2 of STEPS) if (LONGEST[step2.unit] * step2.count >= span) return step2;
5070
- return { unit: "year", count: Math.max(1, niceStep(span / LONGEST.year)) };
5543
+ function timeStep(span2) {
5544
+ for (const step2 of STEPS) if (LONGEST[step2.unit] * step2.count >= span2) return step2;
5545
+ return { unit: "year", count: Math.max(1, niceStep(span2 / LONGEST.year)) };
5071
5546
  }
5072
5547
  function timeTicks(lo, hi, zone) {
5073
5548
  const word = tickWording(zone);
@@ -5093,9 +5568,9 @@ function boundaries(lo, hi, step2, zone) {
5093
5568
  const grain = unit === "hour" ? 15 * MINUTE : LONGEST[unit];
5094
5569
  let t = lo - start.ms - (unit === "second" ? 0 : start.seconds * SECOND) - (unit === "hour" ? start.minutes % 15 * MINUTE : 0);
5095
5570
  for (; t < hi; t += grain) {
5096
- const parts = partsOf(t, zone);
5097
- const whole = unit !== "hour" || parts.minutes === 0;
5098
- const field = unit === "second" ? parts.seconds : unit === "minute" ? parts.minutes : parts.hours;
5571
+ const parts2 = partsOf(t, zone);
5572
+ const whole = unit !== "hour" || parts2.minutes === 0;
5573
+ const field = unit === "second" ? parts2.seconds : unit === "minute" ? parts2.minutes : parts2.hours;
5099
5574
  if (t > lo && whole && field % count === 0) out.push(t);
5100
5575
  }
5101
5576
  return out;
@@ -5113,6 +5588,21 @@ function boundaries(lo, hi, step2, zone) {
5113
5588
  }
5114
5589
  return out;
5115
5590
  }
5591
+ function monthsOn(t, months, zone) {
5592
+ const { year, month, date, hours, minutes, seconds, ms } = partsOf(t, zone);
5593
+ const last = /* @__PURE__ */ new Date(0);
5594
+ last.setUTCFullYear(year, month + months + 1, 0);
5595
+ const day = Math.min(date, last.getUTCDate());
5596
+ const d = /* @__PURE__ */ new Date(0);
5597
+ if (zone === "UTC") {
5598
+ d.setUTCFullYear(year, month + months, day);
5599
+ d.setUTCHours(hours, minutes, seconds, ms);
5600
+ } else {
5601
+ d.setFullYear(year, month + months, day);
5602
+ d.setHours(hours, minutes, seconds, ms);
5603
+ }
5604
+ return d.getTime();
5605
+ }
5116
5606
  function timeLevel(t, zone) {
5117
5607
  const { ms, seconds, minutes, hours, date, month } = partsOf(t, zone);
5118
5608
  if (ms !== 0) return "millisecond";
@@ -5133,9 +5623,9 @@ function timeName(times, zone) {
5133
5623
  function tickWording(zone) {
5134
5624
  const formats = /* @__PURE__ */ new Map();
5135
5625
  return (t, upTo) => {
5136
- const own = LEVELS.indexOf(timeLevel(t, zone));
5626
+ const own2 = LEVELS.indexOf(timeLevel(t, zone));
5137
5627
  const fields = {};
5138
- for (let i = Math.min(own, LEVELS.indexOf(upTo)); i <= own; i++) Object.assign(fields, FIELDS[LEVELS[i]]);
5628
+ for (let i = Math.min(own2, LEVELS.indexOf(upTo)); i <= own2; i++) Object.assign(fields, FIELDS[LEVELS[i]]);
5139
5629
  const id = JSON.stringify(fields);
5140
5630
  let format2 = formats.get(id);
5141
5631
  if (!format2) formats.set(id, format2 = new Intl.DateTimeFormat(void 0, { ...fields, timeZone: zoneOption(zone) }));
@@ -5178,7 +5668,7 @@ function lineEncoding(options) {
5178
5668
  if (!Array.isArray(series) || series.length === 0) throw new TypeError("lineChart needs series: the numeric fields to draw as lines.");
5179
5669
  const seen = /* @__PURE__ */ new Set();
5180
5670
  for (const field of series) {
5181
- if (typeof field !== "string" || field === "") throw new TypeError(`lineChart: each series must be a field name, got ${show(field)}.`);
5671
+ if (typeof field !== "string" || field === "") throw new TypeError(`lineChart: each series must be a field name, got ${show2(field)}.`);
5182
5672
  if (seen.has(field)) throw new TypeError(`lineChart: "${field}" appears twice in series.`);
5183
5673
  seen.add(field);
5184
5674
  }
@@ -5186,7 +5676,7 @@ function lineEncoding(options) {
5186
5676
  const labels = options.labels;
5187
5677
  if (labels !== void 0 && labels !== false && typeof labels !== "function") throw new TypeError("lineChart: labels must be false or a function that returns a line's end label.");
5188
5678
  const timeZone = options.timeZone ?? "UTC";
5189
- if (!TIME_ZONES.includes(timeZone)) throw new TypeError(`lineChart: timeZone must be "UTC" or "local", got ${show(timeZone)}.`);
5679
+ if (!TIME_ZONES.includes(timeZone)) throw new TypeError(`lineChart: timeZone must be "UTC" or "local", got ${show2(timeZone)}.`);
5190
5680
  const xFormat = options.xFormat;
5191
5681
  if (xFormat !== void 0 && typeof xFormat !== "function") throw new TypeError("lineChart: xFormat must be a function that turns an x into text.");
5192
5682
  return {
@@ -5202,7 +5692,7 @@ function layoutLines(input) {
5202
5692
  const height = input.height ?? HEIGHT2;
5203
5693
  const { rows: rows2, time } = prepareRows2(input);
5204
5694
  const series = input.encoding.series.map((s) => s.series);
5205
- const domain = niceDomain(rows2.flatMap((row) => row.values.map((v) => v.value)));
5695
+ const domain = niceDomain(rows2.flatMap((row) => row.values.flatMap((v) => v.value === void 0 ? [] : [v.value])));
5206
5696
  const yTexts = domain.ticks.map(input.format);
5207
5697
  const xLo = rows2[0]?.x ?? 0;
5208
5698
  const xHi = rows2[rows2.length - 1]?.x ?? 0;
@@ -5219,7 +5709,7 @@ function layoutLines(input) {
5219
5709
  };
5220
5710
  const decimalsBy = {};
5221
5711
  for (const name of series) decimalsBy[name] = 0;
5222
- for (const row of rows2) for (const v of row.values) decimalsBy[v.series] = Math.max(decimalsBy[v.series], decimals(v.value));
5712
+ for (const row of rows2) for (const v of row.values) if (v.value !== void 0) decimalsBy[v.series] = Math.max(decimalsBy[v.series], decimals(v.value));
5223
5713
  const xTicks = xValues.map((value, i) => placeXTick(frame2, value, xTexts[i]));
5224
5714
  return {
5225
5715
  width,
@@ -5242,7 +5732,7 @@ function positions(frame2) {
5242
5732
  y: (value) => ySpan > 0 ? box.bottom - (value - scale2.lo) / ySpan * (box.bottom - box.top) : box.bottom
5243
5733
  };
5244
5734
  }
5245
- function placeLines(frame2, rows2, series, through, time = false) {
5735
+ function placeLines(frame2, rows2, series, through, time = false, labels) {
5246
5736
  const first = rows2[0];
5247
5737
  if (!first) return [];
5248
5738
  const at = positions(frame2);
@@ -5253,28 +5743,62 @@ function placeLines(frame2, rows2, series, through, time = false) {
5253
5743
  const share = next && next.x > end.x && through > end.x ? (through - end.x) / (next.x - end.x) : void 0;
5254
5744
  const shown = rows2.slice(0, last + 1);
5255
5745
  const datas = /* @__PURE__ */ new Map();
5256
- const related = (own) => (name) => name === own ? void 0 : datas.get(name);
5257
- const lines = series.map((name) => {
5258
- const vertices = shown.map((row) => ({ at: row.x, value: row.values[name] ?? 0 }));
5259
- if (share !== void 0) {
5746
+ const related = (own2) => (name) => name === own2 ? void 0 : datas.get(name);
5747
+ const traced = series.map((name) => {
5748
+ const has = (row) => !row.missing?.has(name);
5749
+ const vertices = [];
5750
+ let gap = false;
5751
+ for (const row of shown) {
5752
+ if (!has(row)) gap = vertices.length > 0;
5753
+ else {
5754
+ vertices.push({ at: row.x, value: row.values[name] ?? 0, datum: row.datum, gapBefore: gap });
5755
+ gap = false;
5756
+ }
5757
+ }
5758
+ if (share !== void 0 && has(end) && has(next)) {
5260
5759
  const from = end.values[name] ?? 0;
5261
- vertices.push({ at: through, value: from + share * ((next.values[name] ?? 0) - from) });
5760
+ vertices.push({ at: through, value: from + share * ((next.values[name] ?? 0) - from), datum: end.datum, gapBefore: false });
5262
5761
  }
5263
- const points = vertices.map((v) => ({ x: at.x(v.at), y: at.y(v.value) }));
5264
- const geometry = describe.line({ key: name, series: name, points, width: LINE_WIDTH });
5762
+ const points = vertices.length > 0 ? vertices.map((v) => ({ x: at.x(v.at), y: at.y(v.value) })) : [{ x: at.x(first.x), y: at.y(first.values[name] ?? 0) }];
5763
+ return { name, vertices, points };
5764
+ });
5765
+ const named = traced.filter(({ vertices }) => vertices.length > 0);
5766
+ const placed2 = labels ? placeEndLabels(
5767
+ frame2,
5768
+ named.map(({ name, vertices, points }) => ({ ...points[points.length - 1], text: labels.text(name, vertices[vertices.length - 1].value) }))
5769
+ ) : [];
5770
+ const lines = traced.map(({ name, vertices, points }) => {
5771
+ const tip = points[points.length - 1];
5772
+ const label2 = labels ? placed2[named.findIndex((line2) => line2.name === name)] ?? { x: tip.x + LABEL_GAP, y: tip.y + VALUE_SIZE3 * CENTRE3, anchor: "start", text: "" } : void 0;
5773
+ const labelBounds = labels ? label2 && label2.text !== "" ? [textBox(label2, labels.measure, "ec-value", VALUE_SIZE3)] : [] : void 0;
5774
+ const breaks = vertices.flatMap((v, j) => v.gapBefore ? [j] : []);
5775
+ const geometry = describe.line({ key: name, series: name, points, width: LINE_WIDTH, ...breaks.length > 0 ? { breaks } : {}, ...labelBounds ? { labelBounds } : {} });
5265
5776
  let distance3 = 0;
5266
5777
  const samples = vertices.map((v, j) => {
5267
5778
  if (j > 0) distance3 += Math.hypot(points[j].x - points[j - 1].x, points[j].y - points[j - 1].y);
5268
5779
  const t = geometry.length > 0 ? j === vertices.length - 1 ? 1 : Math.min(1, distance3 / geometry.length) : 0;
5269
- return { t, value: v.value, at: sampleAt(v.at, time) };
5780
+ return { t, value: v.value, at: sampleAt(v.at, time), ...v.gapBefore ? { gapBefore: true } : {} };
5270
5781
  });
5271
- const data = { datum: end.datum, samples, related: related(name) };
5782
+ const last2 = vertices[vertices.length - 1];
5783
+ const data = { datum: last2 ? last2.datum : end.datum, samples, related: related(name) };
5272
5784
  datas.set(name, data);
5273
- const tip = vertices[vertices.length - 1];
5274
- return { series: name, geometry, data, end: { ...points[points.length - 1], value: tip.value } };
5785
+ return { series: name, geometry, data, end: { ...tip, value: last2 ? last2.value : first.values[name] ?? 0 }, label: label2 };
5275
5786
  });
5276
5787
  return lines;
5277
5788
  }
5789
+ function loneValues(rows2, series) {
5790
+ const lone = /* @__PURE__ */ new Set();
5791
+ if (!rows2.some((row) => row.missing !== void 0 && row.missing.size > 0)) return lone;
5792
+ const has = (row, name) => row !== void 0 && !row.missing?.has(name);
5793
+ rows2.forEach((row, i) => {
5794
+ for (const name of series) {
5795
+ const before = rows2[i - 1];
5796
+ const after = rows2[i + 1];
5797
+ if (has(row, name) && !has(before, name) && !has(after, name) && (before !== void 0 || after !== void 0)) lone.add(pointKey(name, row.key));
5798
+ }
5799
+ });
5800
+ return lone;
5801
+ }
5278
5802
  function pointKey(series, row) {
5279
5803
  return `${series}@${row}`;
5280
5804
  }
@@ -5282,7 +5806,7 @@ function placePoints(frame2, row, series, time = false) {
5282
5806
  const at = positions(frame2);
5283
5807
  const x = at.x(row.x);
5284
5808
  const datas = /* @__PURE__ */ new Map();
5285
- return series.map((name) => {
5809
+ return series.filter((name) => !row.missing?.has(name)).map((name) => {
5286
5810
  const value = row.values[name] ?? 0;
5287
5811
  const key = pointKey(name, row.key);
5288
5812
  const data = { datum: row.datum, samples: [{ t: 0, value, at: sampleAt(row.x, time) }], related: (other) => other === name ? void 0 : datas.get(other) };
@@ -5316,8 +5840,8 @@ function spread(values, gap, min, max) {
5316
5840
  const clusters = [];
5317
5841
  const place = (members) => {
5318
5842
  const mean = members.reduce((sum, m) => sum + m.value, 0) / members.length;
5319
- const span = (members.length - 1) * gap;
5320
- return Math.max(min, Math.min(max - span, mean - span / 2));
5843
+ const span2 = (members.length - 1) * gap;
5844
+ return Math.max(min, Math.min(max - span2, mean - span2 / 2));
5321
5845
  };
5322
5846
  for (const item of order) {
5323
5847
  clusters.push({ members: [item], start: place([item]) });
@@ -5389,7 +5913,34 @@ function prepareRows2({ data, encoding }) {
5389
5913
  }
5390
5914
  }
5391
5915
  const word = xWording(encoding, time, read.map((row) => row.x));
5392
- return { rows: read.map((row) => ({ ...row, label: word(row.x) })), time };
5916
+ const levels = levelsOf(read, encoding.series.length);
5917
+ return {
5918
+ rows: read.map((row, i) => ({ ...row, label: word(row.x), missing: new Set(row.values.flatMap((v) => v.value === void 0 ? [v.series] : [])), levels: levels[i] })),
5919
+ time
5920
+ };
5921
+ }
5922
+ function levelsOf(rows2, count) {
5923
+ const levels = rows2.map(() => ({}));
5924
+ for (let s = 0; s < count; s++) {
5925
+ let before = -1;
5926
+ let after = -1;
5927
+ rows2.forEach((row, i) => {
5928
+ const { series, value } = row.values[s];
5929
+ if (value !== void 0) {
5930
+ levels[i][series] = value;
5931
+ before = i;
5932
+ return;
5933
+ }
5934
+ if (after <= i) {
5935
+ after = i + 1;
5936
+ while (after < rows2.length && rows2[after].values[s].value === void 0) after++;
5937
+ }
5938
+ const a = rows2[before]?.values[s].value;
5939
+ const b = rows2[after]?.values[s].value;
5940
+ levels[i][series] = a !== void 0 && b !== void 0 ? a + (row.x - rows2[before].x) / (rows2[after].x - rows2[before].x) * (b - a) : a ?? b ?? 0;
5941
+ });
5942
+ }
5943
+ return levels;
5393
5944
  }
5394
5945
  function xOf(x, index, time) {
5395
5946
  if (x instanceof Date) {
@@ -5400,9 +5951,9 @@ function xOf(x, index, time) {
5400
5951
  }
5401
5952
  if (time) {
5402
5953
  if (typeof x === "number") throw new TypeError(`lineChart: x must be all numbers or all Dates, but row 0's is a Date and row ${index}'s a number.`);
5403
- throw new TypeError(`lineChart: x must be a valid Date, got ${show(x)} in row ${index}.`);
5954
+ throw new TypeError(`lineChart: x must be a valid Date, got ${show2(x)} in row ${index}.`);
5404
5955
  }
5405
- if (typeof x !== "number" || !Number.isFinite(x)) throw new RangeError(`lineChart: x must be a finite number, got ${show(x)} in row ${index}.`);
5956
+ if (typeof x !== "number" || !Number.isFinite(x)) throw new RangeError(`lineChart: x must be a finite number, got ${show2(x)} in row ${index}.`);
5406
5957
  return x;
5407
5958
  }
5408
5959
  function xWording(encoding, time, xs) {
@@ -5415,13 +5966,15 @@ function sampleAt(x, time) {
5415
5966
  }
5416
5967
  function numberOf3(value, series, key) {
5417
5968
  if (typeof value === "number" && Number.isFinite(value)) return value;
5418
- throw new RangeError(`lineChart: "${series}" for "${key}" must be a finite number, got ${show(value)}. Lines can't skip a value yet.`);
5969
+ if (value === null || value === void 0) return void 0;
5970
+ throw new RangeError(`lineChart: "${series}" for "${key}" must be a finite number, or null or undefined where it has no value, got ${show2(value)}.`);
5419
5971
  }
5420
- function distinctLabels(rows2, label) {
5972
+ function distinctLabels(rows2, label2) {
5421
5973
  const shapes = /* @__PURE__ */ new Map();
5422
5974
  for (const row of rows2) {
5423
5975
  for (const { series, value } of row.values) {
5424
- const text2 = label(series, value);
5976
+ if (value === void 0) continue;
5977
+ const text2 = label2(series, value);
5425
5978
  const shape = text2.replace(/\d/g, "0");
5426
5979
  if (!shapes.has(shape)) shapes.set(shape, text2);
5427
5980
  }
@@ -5435,7 +5988,7 @@ function accessor3(option) {
5435
5988
  if (typeof option === "function") return option;
5436
5989
  return (d) => d[option];
5437
5990
  }
5438
- var show = (value) => typeof value === "string" ? JSON.stringify(value) : String(value);
5991
+ var show2 = (value) => typeof value === "string" ? JSON.stringify(value) : String(value);
5439
5992
 
5440
5993
  // src/charts/line.ts
5441
5994
  var STAGE3 = 500;
@@ -5548,8 +6101,8 @@ function lineChart(target, options, env2) {
5548
6101
  const text2 = `${formatted(value)} ${seriesLabel(opts.seriesLabels, series)}`;
5549
6102
  if (typeof labels !== "function") return text2;
5550
6103
  try {
5551
- const own = labels(value, series, formatted);
5552
- return own === void 0 || own === null ? "" : String(own);
6104
+ const own2 = labels(value, series, formatted);
6105
+ return own2 === void 0 || own2 === null ? "" : String(own2);
5553
6106
  } catch (error) {
5554
6107
  if (!quiet && !labelFailures.has(labels)) {
5555
6108
  labelFailures.add(labels);
@@ -5559,10 +6112,15 @@ function lineChart(target, options, env2) {
5559
6112
  }
5560
6113
  };
5561
6114
  }
6115
+ function endLabels(given) {
6116
+ const label2 = labeler(current);
6117
+ if (!label2) return void 0;
6118
+ return { text: (series, value) => label2(series, round(value, given[series] ?? decimals(value))), measure };
6119
+ }
5562
6120
  function placedFor(next) {
5563
6121
  const states = next.rows.map(restState);
5564
6122
  return {
5565
- lines: new Map(placeLines(next.frame, states, next.series, drawnThrough(next), next.time).map((line2) => [line2.series, line2])),
6123
+ lines: new Map(placeLines(next.frame, states, next.series, drawnThrough(next), next.time, endLabels(next.decimals)).map((line2) => [line2.series, line2])),
5566
6124
  points: new Map(states.flatMap((state) => placePoints(next.frame, state, next.series, next.time)).map((point) => [point.key, point]))
5567
6125
  };
5568
6126
  }
@@ -5585,17 +6143,18 @@ function lineChart(target, options, env2) {
5585
6143
  column,
5586
6144
  hit: svgElement("rect", { class: "ec-hit" }, column),
5587
6145
  x: animated(row.x, interpolateNumber, env3),
5588
- values: animated(valuesOf2(row.values), interpolateRecord, env3),
6146
+ values: animated(row.levels, interpolateRecord, env3),
5589
6147
  presence: animated(entering ? 0 : 1, interpolateNumber, env3),
5590
6148
  anchor: void 0,
5591
6149
  points: [],
5592
6150
  leaving: false,
5593
- shown: true
6151
+ shown: true,
6152
+ px: 0
5594
6153
  };
5595
6154
  byColumn.set(column, record);
5596
6155
  return record;
5597
6156
  }
5598
- function createLine(series, placed, entering) {
6157
+ function createLine(series, placed2, entering) {
5599
6158
  const group = svgElement("g", { class: "ec-line", "data-key": series, "data-series": series }, linesLayer);
5600
6159
  const body = svgElement("g", { class: "ec-body" }, group);
5601
6160
  const record = {
@@ -5610,46 +6169,46 @@ function lineChart(target, options, env2) {
5610
6169
  drawnLabel: void 0,
5611
6170
  parts: [],
5612
6171
  handle: svgMarkHandle(() => record),
5613
- target: placed,
5614
- shown: placed,
6172
+ target: placed2,
6173
+ shown: placed2,
5615
6174
  presence: animated(entering ? 0 : 1, interpolateNumber, { clock, motion: motion2, onChange: changed }),
5616
6175
  leave: void 0
5617
6176
  };
5618
6177
  return record;
5619
6178
  }
5620
- function createPoint(row, placed) {
5621
- const group = svgElement("g", { class: "ec-point", "data-key": placed.key, "data-series": placed.series }, pointsLayer);
6179
+ function createPoint(row, placed2) {
6180
+ const group = svgElement("g", { class: "ec-point", "data-key": placed2.key, "data-series": placed2.series }, pointsLayer);
5622
6181
  const body = svgElement("g", { class: "ec-body" }, group);
5623
6182
  const record = {
5624
6183
  kind: "point",
5625
- key: placed.key,
5626
- series: placed.series,
6184
+ key: placed2.key,
6185
+ series: placed2.series,
5627
6186
  row,
5628
6187
  group,
5629
6188
  body,
5630
6189
  path: svgElement("path", { class: "ec-dot" }, body),
5631
6190
  parts: [],
5632
6191
  handle: svgMarkHandle(() => record),
5633
- target: placed,
5634
- shown: placed,
6192
+ target: placed2,
6193
+ shown: placed2,
5635
6194
  hidden: void 0,
5636
6195
  leave: void 0
5637
6196
  };
5638
6197
  return record;
5639
6198
  }
5640
- const drawn = (record) => findMark(record.key) === record;
6199
+ const drawn2 = (record) => findMark(record.key) === record;
5641
6200
  const livePoints = (record) => record.points.filter((point) => points.get(point.key) === point);
5642
6201
  const leavingLines = () => [...leaving.values()].filter((record) => record.kind === "line");
5643
6202
  const currentFrame = () => ({ scale: scale2.value, box: box.value });
5644
6203
  function currentRows() {
5645
- const own = (record) => ({ x: record.x.value, values: record.values.value });
6204
+ const own2 = (record) => ({ x: record.x.value, values: record.values.value });
5646
6205
  const states = /* @__PURE__ */ new Map();
5647
6206
  const visiting = /* @__PURE__ */ new Set();
5648
6207
  const stateOf = (record) => {
5649
6208
  const known = states.get(record);
5650
6209
  if (known) return known;
5651
6210
  const p = record.presence.value;
5652
- let state = own(record);
6211
+ let state = own2(record);
5653
6212
  if (record.anchor && p < 1 && !visiting.has(record)) {
5654
6213
  visiting.add(record);
5655
6214
  const from = stateOf(record.anchor);
@@ -5662,7 +6221,7 @@ function lineChart(target, options, env2) {
5662
6221
  const drawnRows = [...rowOrder, ...[...leavingRows.values()].filter((record) => record.presence.value > 0 && record.anchor)];
5663
6222
  return drawnRows.map((record) => {
5664
6223
  const { x, values } = stateOf(record);
5665
- return { record, state: { key: record.key, datum: record.row.datum, x, values } };
6224
+ return { record, state: { key: record.key, datum: record.row.datum, x, values, missing: record.row.missing } };
5666
6225
  }).sort((a, b) => a.state.x - b.state.x);
5667
6226
  }
5668
6227
  function draw() {
@@ -5673,9 +6232,10 @@ function lineChart(target, options, env2) {
5673
6232
  paintFrame(frame2);
5674
6233
  paintLines(frame2, states.map((s) => s.state));
5675
6234
  for (const { record, state } of states) {
5676
- const placed = new Map(placePoints(frame2, state, record.points.map((point) => point.series), laidOut.time).map((point) => [point.key, point]));
5677
- showAll(record.points.filter(drawn).map((point) => ({ record: point, placed: placed.get(point.key) })));
6235
+ const placed2 = new Map(placePoints(frame2, state, record.points.map((point) => point.series), laidOut.time).map((point) => [point.key, point]));
6236
+ showAll(record.points.filter(drawn2).flatMap((point) => placed2.has(point.key) ? [{ record: point, placed: placed2.get(point.key) }] : []));
5678
6237
  }
6238
+ paintAlone(states.map((s) => s.state));
5679
6239
  paintColumns(frame2, states);
5680
6240
  followHover();
5681
6241
  }
@@ -5694,7 +6254,7 @@ function lineChart(target, options, env2) {
5694
6254
  leavingRows.clear();
5695
6255
  for (const record of rowOrder) {
5696
6256
  record.anchor = void 0;
5697
- record.points = record.points.filter(drawn);
6257
+ record.points = record.points.filter(drawn2);
5698
6258
  }
5699
6259
  for (const [ticks, placedTicks] of [
5700
6260
  [yTicks, laidOut.yTicks],
@@ -5706,11 +6266,11 @@ function lineChart(target, options, env2) {
5706
6266
  tick.label.remove();
5707
6267
  ticks.delete(tick.value);
5708
6268
  }
5709
- for (const placed2 of placedTicks) {
5710
- const tick = ticks.get(placed2.value);
6269
+ for (const placed3 of placedTicks) {
6270
+ const tick = ticks.get(placed3.value);
5711
6271
  if (!tick) continue;
5712
- if (tick.line && "line" in placed2) setAttributes(tick.line, { ...placed2.line, opacity: void 0 });
5713
- placeText(tick.label, placed2.label);
6272
+ if (tick.line && "line" in placed3) setAttributes(tick.line, { ...placed3.line, opacity: void 0 });
6273
+ placeText(tick.label, placed3.label);
5714
6274
  tick.label.removeAttribute("opacity");
5715
6275
  }
5716
6276
  }
@@ -5718,7 +6278,7 @@ function lineChart(target, options, env2) {
5718
6278
  const { frame: frame2 } = laidOut;
5719
6279
  setAttributes(svg, sizeAttributes(frame2.box));
5720
6280
  drawnFrame = frame2;
5721
- const placed = placedFor(laidOut);
6281
+ const placed2 = placedFor(laidOut);
5722
6282
  const settle = (records, next) => {
5723
6283
  const pairs = records.flatMap((record) => {
5724
6284
  const to = next(record);
@@ -5728,10 +6288,11 @@ function lineChart(target, options, env2) {
5728
6288
  if (!kept) for (const { record, to } of pairs) record.target = to;
5729
6289
  showAll(pairs.map(({ record }) => ({ record, placed: record.target })));
5730
6290
  };
5731
- settle(lineOrder, (line2) => placed.lines.get(line2.series));
5732
- paintLabels(frame2, new Map(lineOrder.flatMap((line2) => placed.lines.has(line2.series) ? [[line2, placed.lines.get(line2.series)]] : [])));
6291
+ settle(lineOrder, (line2) => placed2.lines.get(line2.series));
6292
+ paintLabels(new Map(lineOrder.flatMap((line2) => placed2.lines.has(line2.series) ? [[line2, placed2.lines.get(line2.series)]] : [])));
5733
6293
  const states = rowOrder.map((record) => ({ record, state: restState(record.row) }));
5734
- for (const { record } of states) settle(livePoints(record), (point) => placed.points.get(point.key));
6294
+ for (const { record } of states) settle(livePoints(record), (point) => placed2.points.get(point.key));
6295
+ paintAlone(states.map((s) => s.state));
5735
6296
  paintColumns(frame2, states);
5736
6297
  followHover();
5737
6298
  dirty = false;
@@ -5741,10 +6302,10 @@ function lineChart(target, options, env2) {
5741
6302
  setAttributes(svg, sizeAttributes(frame2.box));
5742
6303
  const formatted = format(current);
5743
6304
  for (const tick of yTicks.values()) {
5744
- const placed = placeYTick(frame2, tick.value, formatted(tick.value));
6305
+ const placed2 = placeYTick(frame2, tick.value, formatted(tick.value));
5745
6306
  const opacity = tick.opacity.value < 1 ? tick.opacity.value : void 0;
5746
- setAttributes(tick.line, { ...placed.line, opacity });
5747
- placeText(tick.label, placed.label);
6307
+ setAttributes(tick.line, { ...placed2.line, opacity });
6308
+ placeText(tick.label, placed2.label);
5748
6309
  setAttributes(tick.label, { opacity });
5749
6310
  }
5750
6311
  for (const tick of xTicks.values()) {
@@ -5755,46 +6316,39 @@ function lineChart(target, options, env2) {
5755
6316
  function paintLines(frame2, states) {
5756
6317
  const drawnLines = [...lineOrder, ...leavingLines()];
5757
6318
  if (states.length === 0 || drawnLines.length === 0) return;
5758
- const placed = placeLines(frame2, states, drawnLines.map((line2) => line2.series), drawnThrough(laidOut), laidOut.time);
5759
- showAll(drawnLines.map((line2, i) => ({ record: line2, placed: placed[i] })));
5760
- paintLabels(frame2, new Map(drawnLines.map((line2, i) => [line2, placed[i]])));
5761
- }
5762
- function paintLabels(frame2, ends) {
5763
- const label = labeler(current);
5764
- const entries = [...ends];
5765
- const placed = label ? placeEndLabels(
5766
- frame2,
5767
- entries.map(([line2, { end }]) => ({ x: end.x, y: end.y, text: label(line2.series, round(end.value, counting[line2.series] ?? decimals(end.value))) }))
5768
- ) : [];
5769
- entries.forEach(([line2], i) => {
5770
- const text2 = placed[i];
6319
+ const placed2 = placeLines(frame2, states, drawnLines.map((line2) => line2.series), drawnThrough(laidOut), laidOut.time, endLabels(counting));
6320
+ showAll(drawnLines.map((line2, i) => ({ record: line2, placed: placed2[i] })));
6321
+ paintLabels(new Map(drawnLines.map((line2, i) => [line2, placed2[i]])));
6322
+ }
6323
+ function paintLabels(ends) {
6324
+ for (const [line2, { label: text2 }] of ends) {
5771
6325
  if (text2) placeText(line2.label, text2);
5772
6326
  line2.drawnLabel = text2 && text2.text !== "" ? text2 : void 0;
5773
6327
  setAttributes(line2.label, { visibility: line2.drawnLabel ? void 0 : "hidden" });
5774
- });
6328
+ }
5775
6329
  }
5776
6330
  function showAll(marks) {
5777
- const related = marks.some(({ record, placed }) => !sameData(record.shown.data, placed.data));
5778
- for (const { record, placed } of marks) {
5779
- if (record.kind === "line") showLine(record, placed, related);
5780
- else showPoint(record, placed, related);
6331
+ const related = marks.some(({ record, placed: placed2 }) => !sameData(record.shown.data, placed2.data));
6332
+ for (const { record, placed: placed2 } of marks) {
6333
+ if (record.kind === "line") showLine(record, placed2, related);
6334
+ else showPoint(record, placed2, related);
5781
6335
  }
5782
6336
  }
5783
- function showLine(record, placed, related) {
5784
- const moved = related || geometryChanged(record.shown.geometry, placed.geometry);
5785
- record.shown = placed;
5786
- const { geometry } = placed;
6337
+ function showLine(record, placed2, related) {
6338
+ const moved = related || geometryChanged(record.shown.geometry, placed2.geometry);
6339
+ record.shown = placed2;
6340
+ const { geometry } = placed2;
5787
6341
  paint(record, seriesColors(colors.slot(record.series)), { visible: geometry.length >= VISIBLE2, open: { width: geometry.thickness } });
5788
- setAttributes(record.end, { cx: geometry.end.x, cy: geometry.end.y });
6342
+ setAttributes(record.end, { cx: geometry.end.x, cy: geometry.end.y, visibility: placed2.data.samples.length === 0 ? "hidden" : void 0 });
5789
6343
  const presence = record.presence.value;
5790
6344
  setAttributes(record.group, { opacity: presence < 1 ? presence : void 0 });
5791
- if (moved) runner.change(geometry, placed.data);
6345
+ if (moved) runner.change(geometry, placed2.data);
5792
6346
  }
5793
- function showPoint(record, placed, related) {
5794
- const moved = related || geometryChanged(record.shown.geometry, placed.geometry);
5795
- record.shown = placed;
6347
+ function showPoint(record, placed2, related) {
6348
+ const moved = related || geometryChanged(record.shown.geometry, placed2.geometry);
6349
+ record.shown = placed2;
5796
6350
  paint(record, seriesColors(colors.slot(record.series)), { visible: true });
5797
- if (moved) runner.change(placed.geometry, placed.data);
6351
+ if (moved) runner.change(placed2.geometry, placed2.data);
5798
6352
  }
5799
6353
  function paint(record, markColors, part) {
5800
6354
  const before = record.parts[0];
@@ -5807,17 +6361,27 @@ function lineChart(target, options, env2) {
5807
6361
  record.handle.repaint();
5808
6362
  if (before && recolored) surface.recolor(record.key);
5809
6363
  }
6364
+ let anyAlone = false;
6365
+ function paintAlone(states) {
6366
+ const lone = loneValues(states, laidOut.series);
6367
+ if (lone.size === 0 && !anyAlone) return;
6368
+ for (const point of points.values()) point.group.classList.toggle("ec-alone", lone.has(point.key));
6369
+ anyAlone = lone.size > 0;
6370
+ }
5810
6371
  function paintColumns(frame2, states) {
5811
6372
  const { x } = positions(frame2);
5812
6373
  const shown = states.filter(({ record }) => revealed(record));
5813
6374
  const columns = placeColumns(frame2, shown.map(({ state }) => x(state.x)));
5814
- shown.forEach(({ record }, i) => setAttributes(record.hit, { ...columns[i] }));
6375
+ shown.forEach(({ record, state }, i) => {
6376
+ setAttributes(record.hit, { ...columns[i] });
6377
+ record.px = x(state.x);
6378
+ });
5815
6379
  const visible = new Set(shown.map(({ record }) => record));
5816
6380
  for (const record of [...rowOrder, ...leavingRows.values()]) {
5817
- const show3 = visible.has(record);
5818
- if (record.shown !== show3) {
5819
- record.shown = show3;
5820
- setAttributes(record.column, { visibility: show3 ? void 0 : "hidden", "aria-hidden": record.leaving ? "true" : void 0 });
6381
+ const show4 = visible.has(record);
6382
+ if (record.shown !== show4) {
6383
+ record.shown = show4;
6384
+ setAttributes(record.column, { visibility: show4 ? void 0 : "hidden", "aria-hidden": record.leaving ? "true" : void 0 });
5821
6385
  }
5822
6386
  const hidden2 = !revealed(record);
5823
6387
  for (const point of record.points) {
@@ -5830,10 +6394,9 @@ function lineChart(target, options, env2) {
5830
6394
  }
5831
6395
  function showHover(key) {
5832
6396
  const record = rows2.get(key);
5833
- const marks = record && revealed(record) ? livePoints(record) : [];
5834
- const first = marks[0];
5835
- if (!record || !first) return;
5836
- const x = first.shown.geometry.center.x;
6397
+ if (!record || !revealed(record)) return;
6398
+ const marks = livePoints(record);
6399
+ const x = marks[0]?.shown.geometry.center.x ?? record.px;
5837
6400
  setAttributes(crosshair, { ...placeCrosshair(drawnFrame, x), visibility: void 0 });
5838
6401
  const ys = marks.map((point) => {
5839
6402
  const { transform } = point.handle.style;
@@ -5841,19 +6404,26 @@ function lineChart(target, options, env2) {
5841
6404
  return (transform ? matrix.apply(transform, center) : center).y;
5842
6405
  });
5843
6406
  const { row } = record;
5844
- tooltip.showAt(
5845
- { x, top: Math.min(...ys) - DOT_RADIUS, bottom: Math.max(...ys) + DOT_RADIUS },
5846
- row,
5847
- () => summaryContent(row.label, labelled2(row.values, current), format(current), { total: false })
5848
- );
6407
+ const at = ys.length > 0 ? { top: Math.min(...ys) - DOT_RADIUS, bottom: Math.max(...ys) + DOT_RADIUS } : { top: drawnFrame.box.top, bottom: drawnFrame.box.top };
6408
+ tooltip.showAt({ x, ...at }, row, () => summary(row, current));
5849
6409
  }
5850
6410
  function hideHover() {
5851
6411
  crosshair.setAttribute("visibility", "hidden");
5852
6412
  tooltip.hide();
5853
6413
  }
6414
+ let ringLine;
5854
6415
  function drawRing(key) {
5855
6416
  const record = key === void 0 ? void 0 : rows2.get(key);
5856
- const marks = record && revealed(record) ? livePoints(record) : [];
6417
+ const live = record !== void 0 && revealed(record);
6418
+ const marks = live ? livePoints(record) : [];
6419
+ if (live && marks.length === 0) {
6420
+ ringLine ?? (ringLine = svgElement("line", { class: "ec-focus-ring", "stroke-width": RING3 }, ring));
6421
+ if (ring.childElementCount > 1 || ring.firstElementChild !== ringLine) ring.replaceChildren(ringLine);
6422
+ setAttributes(ringLine, placeCrosshair(drawnFrame, record.px));
6423
+ ring.removeAttribute("visibility");
6424
+ return;
6425
+ }
6426
+ ringLine?.remove();
5857
6427
  while (ring.childElementCount > marks.length) ring.lastElementChild.remove();
5858
6428
  marks.forEach((point, i) => {
5859
6429
  let group = ring.children[i];
@@ -5894,6 +6464,17 @@ function lineChart(target, options, env2) {
5894
6464
  return record !== void 0 && revealed(record);
5895
6465
  },
5896
6466
  order: () => rowOrder.filter(revealed).map((record) => record.key),
6467
+ // On a time axis a page is a calendar month in its zone: the first x a month or more on, or back,
6468
+ // or the last one that way. On numbers it's the keyboard's own.
6469
+ page(key, by) {
6470
+ const from = rows2.get(key);
6471
+ if (!laidOut.time || !from) return void 0;
6472
+ const stops = rowOrder.filter(revealed);
6473
+ const to = monthsOn(from.row.x, by, lineEncoding(current).timeZone);
6474
+ if (by > 0) return (stops.find((record) => record.row.x >= to) ?? stops[stops.length - 1])?.key;
6475
+ for (let i = stops.length - 1; i >= 0; i--) if (stops[i].row.x <= to) return stops[i].key;
6476
+ return stops[0]?.key;
6477
+ },
5897
6478
  marks: (key) => {
5898
6479
  const record = rows2.get(key);
5899
6480
  return record ? livePoints(record).map((point) => point.key) : [];
@@ -5905,7 +6486,7 @@ function lineChart(target, options, env2) {
5905
6486
  return record && onScreen(record);
5906
6487
  },
5907
6488
  ring: drawRing,
5908
- tooltip: { show: showHover, hide: hideHover }
6489
+ tooltip: { show: showHover, hide: hideHover, element: () => tooltip.element() }
5909
6490
  });
5910
6491
  const syncLegend = () => legend.update(
5911
6492
  laidOut.series.map((series) => ({ series, label: seriesLabel(current.seriesLabels, series) })),
@@ -5919,7 +6500,7 @@ function lineChart(target, options, env2) {
5919
6500
  category: typeof opts.x === "string" ? opts.x : void 0,
5920
6501
  series: next.series,
5921
6502
  label: (series) => seriesLabel(opts.seriesLabels, series),
5922
- rows: next.rows.map((row) => ({ key: row.key, category: row.label, datum: row.datum, index: row.index, values: row.values, total: total(row.values) })),
6503
+ rows: next.rows.map((row) => ({ key: row.key, category: row.label, datum: row.datum, index: row.index, values: present(row.values), missing: row.missing, total: total(row.values) })),
5923
6504
  format: format(opts),
5924
6505
  total: false
5925
6506
  });
@@ -5949,32 +6530,34 @@ function lineChart(target, options, env2) {
5949
6530
  }
5950
6531
  const key = (record) => record.key;
5951
6532
  try {
5952
- const said = option({ text: text2, changed: values.map(key), added: added.map(key), removed: removed.map(key) });
5953
- if (said !== void 0 && said !== null) announcer.say(String(said));
6533
+ const said2 = option({ text: text2, changed: values.map(key), added: added.map(key), removed: removed.map(key) });
6534
+ if (said2 !== void 0 && said2 !== null) announcer.say(String(said2));
5954
6535
  } catch (error) {
5955
6536
  report(error);
5956
6537
  }
5957
6538
  }
5958
6539
  function arrange(next) {
5959
6540
  laidOut = next;
5960
- const placed = placedFor(next);
6541
+ const placed2 = placedFor(next);
5961
6542
  const diff = { entering: [], exiting: [], changed: [] };
5962
6543
  const keys = new Set(next.rows.map((row) => row.key));
5963
6544
  const series = next.rows.length > 0 ? next.series : [];
5964
6545
  const changes = { changed: [], added: [], removed: [] };
5965
6546
  const before = rowOrder;
5966
6547
  const was = new Map(before.map((record) => [record, record.row]));
6548
+ const nextRows = new Map(next.rows.map((row) => [row.key, row]));
5967
6549
  const exitingLines = lineOrder.filter((line2) => !series.includes(line2.series));
5968
6550
  const exitingPoints = [];
5969
6551
  for (const record of before) {
5970
6552
  const goes = !keys.has(record.key);
6553
+ const missing = nextRows.get(record.key)?.missing;
5971
6554
  if (goes) {
5972
6555
  rows2.delete(record.key);
5973
6556
  record.leaving = true;
5974
6557
  leavingRows.set(record.key, record);
5975
6558
  changes.removed.push(record);
5976
6559
  }
5977
- for (const point of livePoints(record)) if (goes || !series.includes(point.series)) exitingPoints.push(point);
6560
+ for (const point of livePoints(record)) if (goes || !series.includes(point.series) || missing?.has(point.series)) exitingPoints.push(point);
5978
6561
  }
5979
6562
  for (const line2 of exitingLines) lines.delete(line2.series);
5980
6563
  for (const point of exitingPoints) points.delete(point.key);
@@ -5993,7 +6576,7 @@ function lineChart(target, options, env2) {
5993
6576
  leavingRows.delete(row.key);
5994
6577
  record.leaving = false;
5995
6578
  record.x.set(row.x);
5996
- record.values.set(valuesOf2(row.values));
6579
+ record.values.set(row.levels);
5997
6580
  rows2.set(row.key, record);
5998
6581
  changes.added.push(record);
5999
6582
  rowsMoved = true;
@@ -6009,7 +6592,7 @@ function lineChart(target, options, env2) {
6009
6592
  const previousLines = lineOrder;
6010
6593
  lineOrder = series.map((name) => {
6011
6594
  let line2 = lines.get(name);
6012
- const target2 = placed.lines.get(name);
6595
+ const target2 = placed2.lines.get(name);
6013
6596
  if (line2) {
6014
6597
  const values = [...stayed].some((record) => valueIn(was.get(record), name) !== valueIn(record.row, name));
6015
6598
  if (rowsMoved || values) diff.changed.push({ record: line2, from: line2.shown.geometry });
@@ -6023,9 +6606,9 @@ function lineChart(target, options, env2) {
6023
6606
  });
6024
6607
  for (const record of rowOrder) {
6025
6608
  const old = stayed.has(record) ? was.get(record) : void 0;
6026
- const live = series.map((name) => {
6609
+ const live = series.filter((name) => !record.row.missing.has(name)).map((name) => {
6027
6610
  const key = pointKey(name, record.key);
6028
- const target2 = placed.points.get(key);
6611
+ const target2 = placed2.points.get(key);
6029
6612
  let point = points.get(key);
6030
6613
  if (point) {
6031
6614
  if (old && valueIn(old, name) !== valueIn(record.row, name)) diff.changed.push({ record: point, from: point.shown.geometry });
@@ -6039,7 +6622,7 @@ function lineChart(target, options, env2) {
6039
6622
  return point;
6040
6623
  });
6041
6624
  const kept = new Set(live);
6042
- record.points = [...live, ...record.points.filter((point) => !kept.has(point) && drawn(point))];
6625
+ record.points = [...live, ...record.points.filter((point) => !kept.has(point) && drawn2(point))];
6043
6626
  }
6044
6627
  for (const record of rowOrder) labelColumn(record);
6045
6628
  orderElements(
@@ -6060,18 +6643,18 @@ function lineChart(target, options, env2) {
6060
6643
  function retarget(next, jump) {
6061
6644
  dirty = true;
6062
6645
  const { frame: frame2 } = next;
6063
- for (const [ticks, placed, lined] of [
6646
+ for (const [ticks, placed2, lined] of [
6064
6647
  [yTicks, next.yTicks, true],
6065
6648
  [xTicks, next.xTicks, false]
6066
6649
  ]) {
6067
- const wanted = new Set(placed.map((tick) => tick.value));
6650
+ const wanted = new Set(placed2.map((tick) => tick.value));
6068
6651
  for (const value of wanted) if (!ticks.has(value)) addTick(ticks, value, 0, lined);
6069
6652
  for (const tick of ticks.values()) tick.wanted = wanted.has(tick.value);
6070
6653
  }
6071
6654
  for (const tick of next.xTicks) xTicks.get(tick.value).text = tick.label.text;
6072
6655
  const goingLines = leavingLines();
6073
6656
  const folding = [...leavingRows.values()];
6074
- const values = busy(scale2, frame2.scale, sameFields) || [...yTicks.values()].some((tick) => busy(tick.opacity, tick.wanted ? 1 : 0, same)) || rowOrder.some((record) => busy(record.values, valuesOf2(record.row.values), sameFields)) || lineOrder.some((line2) => busy(line2.presence, 1, same)) || goingLines.some((line2) => busy(line2.presence, 0, same));
6657
+ const values = busy(scale2, frame2.scale, sameFields) || [...yTicks.values()].some((tick) => busy(tick.opacity, tick.wanted ? 1 : 0, same)) || rowOrder.some((record) => busy(record.values, record.row.levels, sameFields)) || lineOrder.some((line2) => busy(line2.presence, 1, same)) || goingLines.some((line2) => busy(line2.presence, 0, same));
6075
6658
  const positions2 = busy(box, frame2.box, sameFields) || [...xTicks.values()].some((tick) => busy(tick.opacity, tick.wanted ? 1 : 0, same)) || rowOrder.some((record) => busy(record.x, record.row.x, same) || record.anchor !== void 0 && busy(record.presence, 1, same)) || folding.some((record) => record.anchor !== void 0 && busy(record.presence, 0, same));
6076
6659
  let first;
6077
6660
  let second;
@@ -6092,7 +6675,7 @@ function lineChart(target, options, env2) {
6092
6675
  for (const tick of yTicks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, first);
6093
6676
  for (const tick of xTicks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, second);
6094
6677
  for (const record of rowOrder) {
6095
- move(record.values, valuesOf2(record.row.values), sameFields, first);
6678
+ move(record.values, record.row.levels, sameFields, first);
6096
6679
  move(record.x, record.row.x, same, second);
6097
6680
  move(record.presence, 1, same, record.anchor ? second : void 0);
6098
6681
  }
@@ -6127,9 +6710,9 @@ function lineChart(target, options, env2) {
6127
6710
  const next = layout(current);
6128
6711
  const byKey = new Map(next.rows.map((row) => [row.key, row]));
6129
6712
  for (const record of rowOrder) record.row = byKey.get(record.key) ?? record.row;
6130
- const placed = placedFor(next);
6131
- for (const line2 of lineOrder) line2.target = placed.lines.get(line2.series) ?? line2.target;
6132
- for (const point of points.values()) point.target = placed.points.get(point.key) ?? point.target;
6713
+ const placed2 = placedFor(next);
6714
+ for (const line2 of lineOrder) line2.target = placed2.lines.get(line2.series) ?? line2.target;
6715
+ for (const point of points.values()) point.target = placed2.points.get(point.key) ?? point.target;
6133
6716
  void transitionTo(next, true);
6134
6717
  }
6135
6718
  const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
@@ -6144,28 +6727,28 @@ function lineChart(target, options, env2) {
6144
6727
  syncLegend();
6145
6728
  table.render(firstTable);
6146
6729
  {
6147
- const placed = placedFor(laidOut);
6730
+ const placed2 = placedFor(laidOut);
6148
6731
  for (const tick of laidOut.yTicks) addTick(yTicks, tick.value, 1, true);
6149
6732
  for (const tick of laidOut.xTicks) addTick(xTicks, tick.value, 1, false, tick.label.text);
6150
6733
  rowOrder = laidOut.rows.map((row) => {
6151
6734
  const record = createRow(row, false);
6152
6735
  rows2.set(row.key, record);
6153
- record.points = laidOut.series.map((name) => {
6154
- const point = createPoint(record, placed.points.get(pointKey(name, row.key)));
6736
+ record.points = laidOut.series.filter((name) => !row.missing.has(name)).map((name) => {
6737
+ const point = createPoint(record, placed2.points.get(pointKey(name, row.key)));
6155
6738
  points.set(point.key, point);
6156
6739
  return point;
6157
6740
  });
6158
6741
  labelColumn(record);
6159
6742
  return record;
6160
6743
  });
6161
- lineOrder = laidOut.rows.length > 0 ? laidOut.series.map((name) => createLine(name, placed.lines.get(name), false)) : [];
6744
+ lineOrder = laidOut.rows.length > 0 ? laidOut.series.map((name) => createLine(name, placed2.lines.get(name), false)) : [];
6162
6745
  for (const line2 of lineOrder) lines.set(line2.series, line2);
6163
6746
  land();
6164
6747
  }
6165
6748
  const liveMarks = () => [...lineOrder, ...rowOrder.flatMap(livePoints)];
6166
6749
  hover.sync();
6167
6750
  runner.enter(liveMarks().map(input));
6168
- return {
6751
+ return linkable(hover.link, {
6169
6752
  element: svg,
6170
6753
  async update(next) {
6171
6754
  if (destroyed) return;
@@ -6192,7 +6775,7 @@ function lineChart(target, options, env2) {
6192
6775
  transitions.supersede();
6193
6776
  const swapping = swapped !== effects;
6194
6777
  effects = swapped;
6195
- const leaves = playUpdate(
6778
+ const leaves2 = playUpdate(
6196
6779
  {
6197
6780
  runner,
6198
6781
  events,
@@ -6200,6 +6783,7 @@ function lineChart(target, options, env2) {
6200
6783
  leaving,
6201
6784
  input,
6202
6785
  onScreen,
6786
+ data: "data" in next,
6203
6787
  ...swapping ? {
6204
6788
  swap: (diff) => {
6205
6789
  const entering = new Set(diff.entering);
@@ -6214,7 +6798,7 @@ function lineChart(target, options, env2) {
6214
6798
  );
6215
6799
  syncLegend();
6216
6800
  const settled = transitionTo(nextLayout, motion2.mode === "off");
6217
- await transitions.wait(settled, leaves);
6801
+ await transitions.wait(settled, leaves2);
6218
6802
  },
6219
6803
  reveal(x) {
6220
6804
  if (destroyed) return;
@@ -6269,19 +6853,19 @@ function lineChart(target, options, env2) {
6269
6853
  lineOrder = [];
6270
6854
  svg.remove();
6271
6855
  }
6272
- };
6856
+ });
6273
6857
  }
6274
6858
  function restState(row) {
6275
- return { key: row.key, datum: row.datum, x: row.x, values: valuesOf2(row.values) };
6859
+ return { key: row.key, datum: row.datum, x: row.x, values: row.levels, missing: row.missing };
6276
6860
  }
6277
- function valuesOf2(values) {
6278
- return Object.fromEntries(values.map((v) => [v.series, v.value]));
6861
+ function present(values) {
6862
+ return values.flatMap((v) => v.value === void 0 ? [] : [{ series: v.series, value: v.value }]);
6279
6863
  }
6280
6864
  function valueIn(row, series) {
6281
6865
  return row.values.find((v) => v.series === series)?.value;
6282
6866
  }
6283
6867
  function total(values) {
6284
- return values.reduce((sum, v) => sum + v.value, 0);
6868
+ return values.reduce((sum, v) => sum + (v.value ?? 0), 0);
6285
6869
  }
6286
6870
  function nearest2(order, i, among) {
6287
6871
  for (let j = i - 1; j >= 0; j--) if (among.has(order[j])) return order[j];
@@ -6295,21 +6879,32 @@ function sameData(a, b) {
6295
6879
  if (a.datum !== b.datum || a.samples.length !== b.samples.length) return false;
6296
6880
  return a.samples.every((s, i) => {
6297
6881
  const o = b.samples[i];
6298
- return s.t === o.t && s.value === o.value && sameAt(s.at, o.at);
6882
+ return s.t === o.t && s.value === o.value && sameAt(s.at, o.at) && s.gapBefore === o.gapBefore;
6299
6883
  });
6300
6884
  }
6301
6885
  function sameAt(a, b) {
6302
6886
  return a === b || a instanceof Date && b instanceof Date && a.getTime() === b.getTime();
6303
6887
  }
6304
6888
  function labelled2(values, options) {
6305
- return values.map((v) => ({ series: v.series, label: seriesLabel(options.seriesLabels, v.series), value: v.value }));
6889
+ return present(values).map((v) => ({ series: v.series, label: seriesLabel(options.seriesLabels, v.series), value: v.value }));
6890
+ }
6891
+ function said(values, options) {
6892
+ const formatted = format(options);
6893
+ return values.map((v) => {
6894
+ const label2 = seriesLabel(options.seriesLabels, v.series);
6895
+ return v.value === void 0 ? `${label2} missing` : `${formatted(v.value)} ${label2}`;
6896
+ });
6897
+ }
6898
+ function summary(row, options) {
6899
+ if (row.missing.size === 0) return summaryContent(row.label, labelled2(row.values, options), format(options), { total: false });
6900
+ return { title: row.label, lines: [said(row.values, options).join(" \xB7 ")] };
6306
6901
  }
6307
6902
  function namesFor2(options, layout) {
6308
6903
  const formatted = format(options);
6309
6904
  return new Map(
6310
6905
  layout.rows.map((row) => {
6311
6906
  const values = labelled2(row.values, options);
6312
- const text2 = `${row.label}: ${values.map((v) => `${formatted(v.value)} ${v.label}`).join(", ")}`;
6907
+ const text2 = `${row.label}: ${said(row.values, options).join(", ")}`;
6313
6908
  if (!options.markLabel) return [row.key, text2];
6314
6909
  try {
6315
6910
  const named = options.markLabel(row.datum, { key: row.key, category: row.label, values, total: total(row.values), format: formatted, text: text2 });
@@ -6348,20 +6943,20 @@ function baselines(boxes, option) {
6348
6943
  }
6349
6944
  return found;
6350
6945
  }
6351
- function describeRects(key, parts, baseline) {
6352
- const box = union(parts.map((part) => part.box));
6353
- const span = spanFrom(box, baseline);
6354
- const order = parts.map((part, index) => ({ index, ...span(part.box) })).sort((a, b) => a.near - b.near || a.far - b.far || a.index - b.index);
6946
+ function describeRects(key, parts2, baseline) {
6947
+ const box = union(parts2.map((part) => part.box));
6948
+ const span2 = spanFrom(box, baseline);
6949
+ const order = parts2.map((part, index) => ({ index, ...span2(part.box) })).sort((a, b) => a.near - b.near || a.far - b.far || a.index - b.index);
6355
6950
  let reached = 0;
6356
6951
  let gap = Infinity;
6357
6952
  const segments = order.map(({ index, near, far }) => {
6358
6953
  if (reached > 0 && far > near) gap = Math.min(gap, near - reached);
6359
6954
  const size2 = Math.max(0, far - reached);
6360
6955
  reached = Math.max(reached, far);
6361
- return { series: parts[index].series, size: size2 };
6956
+ return { series: parts2[index].series, size: size2 };
6362
6957
  });
6363
- const tip = parts[order[order.length - 1].index];
6364
- const single = parts.length === 1 ? parts[0].series : void 0;
6958
+ const tip = parts2[order[order.length - 1].index];
6959
+ const single = parts2.length === 1 ? parts2[0].series : void 0;
6365
6960
  const geometry = describe.bar({
6366
6961
  key,
6367
6962
  ...single === void 0 ? {} : { series: single },
@@ -6586,13 +7181,13 @@ function round3(value) {
6586
7181
  }
6587
7182
 
6588
7183
  // src/charts/adapter/host-style.ts
6589
- function hostMarkHandle(parts, edits, halos) {
7184
+ function hostMarkHandle(parts2, edits, halos) {
6590
7185
  let style = {};
6591
7186
  let hot = false;
6592
7187
  const halo = maskedHalo();
6593
7188
  const repaint = () => {
6594
7189
  const { transform, opacity, emphasis } = style;
6595
- for (const part of parts()) {
7190
+ for (const part of parts2()) {
6596
7191
  const { element, colors } = part;
6597
7192
  const moved = transform && part.parentInverse ? matrix.multiply(part.parentInverse, transform, part.parent, ownTransform(element)) : void 0;
6598
7193
  edits.style(element, "transform", moved && cssMatrix(moved));
@@ -6607,7 +7202,7 @@ function hostMarkHandle(parts, edits, halos) {
6607
7202
  paintHalo();
6608
7203
  };
6609
7204
  const paintHalo = () => {
6610
- const visible = parts().flatMap((part) => part.outline === void 0 ? [] : [{ ...part.outline, color: part.colors?.color }]);
7205
+ const visible = parts2().flatMap((part) => part.outline === void 0 ? [] : [{ ...part.outline, color: part.colors?.color }]);
6611
7206
  halo.paint(halos(), visible, style.halo, style.transform);
6612
7207
  };
6613
7208
  return {
@@ -6632,13 +7227,13 @@ function hostMarkHandle(parts, edits, halos) {
6632
7227
  }
6633
7228
  function hostColors(element, root) {
6634
7229
  const fill = paintOf(element, root, "fill");
6635
- const paint = fill === NONE ? "stroke" : "fill";
7230
+ const paint = fill === NONE2 ? "stroke" : "fill";
6636
7231
  const color = paint === "fill" ? fill : paintOf(element, root, "stroke");
6637
- if (color === void 0 || color === NONE) return void 0;
7232
+ if (color === void 0 || color === NONE2) return void 0;
6638
7233
  return { color, strong: `color-mix(in oklab, ${color}, ${cssColor("text")} ${STRONG})`, paint };
6639
7234
  }
6640
7235
  var STRONG = "25%";
6641
- var NONE = "none";
7236
+ var NONE2 = "none";
6642
7237
  function paintOf(element, root, property) {
6643
7238
  let declared;
6644
7239
  for (let node = element; node && declared === void 0; node = node === root ? null : node.parentElement) {
@@ -6646,13 +7241,13 @@ function paintOf(element, root, property) {
6646
7241
  if (value) declared = value;
6647
7242
  }
6648
7243
  const computed = kind(element.ownerDocument.defaultView?.getComputedStyle?.(element).getPropertyValue(property));
6649
- const initial = property === "fill" ? computed?.replace(/\s/g, "") === "rgb(0,0,0)" : computed === NONE;
7244
+ const initial = property === "fill" ? computed?.replace(/\s/g, "") === "rgb(0,0,0)" : computed === NONE2;
6650
7245
  return computed !== void 0 && !(initial && declared !== void 0) ? computed : kind(declared);
6651
7246
  }
6652
7247
  function kind(value) {
6653
7248
  const v = value?.trim().toLowerCase();
6654
7249
  if (!v || v === "inherit" || v.startsWith("url(")) return void 0;
6655
- if (v === NONE || v === "transparent" || /^rgba\((?:[^,]+,){3}\s*0(?:\.0*)?\s*\)$/.test(v)) return NONE;
7250
+ if (v === NONE2 || v === "transparent" || /^rgba\((?:[^,]+,){3}\s*0(?:\.0*)?\s*\)$/.test(v)) return NONE2;
6656
7251
  return value.trim();
6657
7252
  }
6658
7253
  function mix2(colors, emphasis) {
@@ -6785,7 +7380,6 @@ function watchHost(doc, clock, onChanges) {
6785
7380
 
6786
7381
  // src/charts/adapter/expressive.ts
6787
7382
  var SVG_NS2 = "http://www.w3.org/2000/svg";
6788
- var ONE = { index: 0, count: 1 };
6789
7383
  var WRAPPING_ROLES = /* @__PURE__ */ new Set(["img", "image", "graphics-symbol", "graphics-object"]);
6790
7384
  function expressive(target, options, env2) {
6791
7385
  checkOptions4(options);
@@ -6837,8 +7431,8 @@ function expressive(target, options, env2) {
6837
7431
  if (typeof geometry !== "object" || geometry === null || geometry.key !== key) {
6838
7432
  throw new TypeError(`expressive: geometry for "${key}" must be a MarkGeometry with the key "${key}". Build it with describe and the key passed in.`);
6839
7433
  }
6840
- const parts = pieces.map((p) => part(p, outlineOf(geometry, p.series, pieces.length), at));
6841
- return { key, geometry, parts, index };
7434
+ const parts2 = pieces.map((p) => part(p, outlineOf(geometry, p.series, pieces.length), at));
7435
+ return { key, geometry, parts: parts2, index };
6842
7436
  }
6843
7437
  function rectPiece(key, piece, at) {
6844
7438
  if (piece.element.localName !== "rect") {
@@ -6853,11 +7447,11 @@ function expressive(target, options, env2) {
6853
7447
  function rectMark(key, pieces, edge, index, at) {
6854
7448
  const { geometry, order: order2 } = describeRects(key, pieces.map((p) => p.rect), edge);
6855
7449
  const segments = geometry.segments ?? [];
6856
- const parts = order2.map((j, n) => {
7450
+ const parts2 = order2.map((j, n) => {
6857
7451
  const segment = segments[n];
6858
7452
  return part(pieces[j], segment && segment.length >= 0.5 ? { d: segment.outline.d } : void 0, at);
6859
7453
  });
6860
- return { key, geometry, parts, index, rect: { edge, box: union(pieces.map((p) => p.rect.box)) } };
7454
+ return { key, geometry, parts: parts2, index, rect: { edge, box: union(pieces.map((p) => p.rect.box)) } };
6861
7455
  }
6862
7456
  function part(piece, outline2, at) {
6863
7457
  const parent = between(at.common, piece.element.parentElement ?? at.svg, at.svg, at.screen);
@@ -6865,19 +7459,19 @@ function expressive(target, options, env2) {
6865
7459
  }
6866
7460
  function withData(marks) {
6867
7461
  return marks.map((mark) => {
6868
- const { key, geometry, parts } = mark;
6869
- const total2 = mark.rect ? totalOf(parts) : void 0;
7462
+ const { key, geometry, parts: parts2 } = mark;
7463
+ const total2 = mark.rect ? totalOf(parts2) : void 0;
6870
7464
  const samplesOf = (datum, of, series) => {
6871
7465
  if (options.samples) return checkSamples(options.samples(datum, of), series === void 0 ? `"${key}"` : `"${key}" (${series})`);
6872
7466
  return total2 === void 0 ? [] : barSamples(geometry, of, total2);
6873
7467
  };
6874
- const own = /* @__PURE__ */ new Map();
6875
- const related = (series) => own.get(series) ?? relatedOf(series, key);
7468
+ const own2 = /* @__PURE__ */ new Map();
7469
+ const related = (series) => own2.get(series) ?? relatedOf(series, key);
6876
7470
  for (const series of ownSeries(mark)) {
6877
- const datum = (parts.find((p) => p.series === series) ?? parts[0]).datum;
6878
- own.set(series, { datum, samples: samplesOf(datum, geometry.segments?.find((s) => s.series === series) ?? geometry, series), related });
7471
+ const datum = (parts2.find((p) => p.series === series) ?? parts2[0]).datum;
7472
+ own2.set(series, { datum, samples: samplesOf(datum, geometry.segments?.find((s) => s.series === series) ?? geometry, series), related });
6879
7473
  }
6880
- return { ...mark, data: { datum: parts[0].datum, samples: samplesOf(parts[0].datum, geometry), related } };
7474
+ return { ...mark, data: { datum: parts2[0].datum, samples: samplesOf(parts2[0].datum, geometry), related } };
6881
7475
  });
6882
7476
  }
6883
7477
  function checkNeeds3(marks) {
@@ -6912,10 +7506,10 @@ function expressive(target, options, env2) {
6912
7506
  if (series === void 0 || series === null || series === "") throw new TypeError(`expressive: segment returned ${String(series)} for a part of "${key}".`);
6913
7507
  return String(series);
6914
7508
  }
6915
- function labelOf(key, parts) {
7509
+ function labelOf(key, parts2) {
6916
7510
  if (!options.markLabel) return void 0;
6917
7511
  try {
6918
- const text2 = String(options.markLabel(parts[0].datum, { key, parts: parts.map(({ series, datum }) => ({ series, datum })) }) ?? "");
7512
+ const text2 = String(options.markLabel(parts2[0].datum, { key, parts: parts2.map(({ series, datum }) => ({ series, datum })) }) ?? "");
6919
7513
  return text2.trim() === "" ? void 0 : text2;
6920
7514
  } catch (error) {
6921
7515
  report(error);
@@ -6943,6 +7537,7 @@ function expressive(target, options, env2) {
6943
7537
  let hovered;
6944
7538
  let ringKey;
6945
7539
  let interaction;
7540
+ let linked2;
6946
7541
  let destroyed = false;
6947
7542
  const make = (tag, attributes, parent) => {
6948
7543
  const created = doc.createElementNS(SVG_NS2, tag);
@@ -6980,7 +7575,7 @@ function expressive(target, options, env2) {
6980
7575
  if (reading.root && reading.root !== root) moveTo2(reading.root);
6981
7576
  ancestor = reading.ancestor ?? ancestor;
6982
7577
  const keys = new Set(reading.marks.map((mark) => mark.key));
6983
- const diff = { entering: [], exiting: [], changed: [], moved: [] };
7578
+ const diff = { entering: [], exiting: [], changed: [], moved: [], newRow: false };
6984
7579
  const recolor = [];
6985
7580
  for (const record of order) {
6986
7581
  if (keys.has(record.key)) continue;
@@ -6995,8 +7590,10 @@ function expressive(target, options, env2) {
6995
7590
  if (record) {
6996
7591
  const from = record.mark;
6997
7592
  const changed = options.value ? valuesChanged2(from.parts, mark.parts) : lengthsChanged(from.geometry, mark.geometry);
7593
+ const newRow = from.data.datum !== mark.data.datum;
7594
+ if (newRow) diff.newRow = true;
6998
7595
  if (changed) diff.changed.push({ record, from: from.geometry });
6999
- else if (geometryChanged2(from.geometry, mark.geometry) || from.data.datum !== mark.data.datum || samplesChanged(from.data.samples, mark.data.samples)) {
7596
+ else if (newRow || geometryChanged2(from.geometry, mark.geometry) || samplesChanged(from.data.samples, mark.data.samples)) {
7000
7597
  diff.moved.push(record);
7001
7598
  }
7002
7599
  if (from.parts[0]?.colors?.color !== mark.parts[0]?.colors?.color) recolor.push(mark.key);
@@ -7027,13 +7624,13 @@ function expressive(target, options, env2) {
7027
7624
  }
7028
7625
  function nameMark(record) {
7029
7626
  if (!options.markLabel) return;
7030
- const { label, parts } = record.mark;
7031
- parts.forEach((part2, index) => {
7032
- const named = label !== void 0 && index === 0;
7627
+ const { label: label2, parts: parts2 } = record.mark;
7628
+ parts2.forEach((part2, index) => {
7629
+ const named = label2 !== void 0 && index === 0;
7033
7630
  edits.attribute(part2.element, "role", named ? "img" : null);
7034
- edits.attribute(part2.element, "aria-label", named ? label : null);
7631
+ edits.attribute(part2.element, "aria-label", named ? label2 : null);
7035
7632
  if (named) edits.remove(part2.element, "aria-hidden");
7036
- else edits.attribute(part2.element, "aria-hidden", label === void 0 ? null : "true");
7633
+ else edits.attribute(part2.element, "aria-hidden", label2 === void 0 ? null : "true");
7037
7634
  });
7038
7635
  }
7039
7636
  function unwrapNames() {
@@ -7084,12 +7681,12 @@ function expressive(target, options, env2) {
7084
7681
  },
7085
7682
  hover(hoverTarget, from) {
7086
7683
  const record = records.get(hoverTarget.key);
7087
- if (!record || hovered?.key === hoverTarget.key) return;
7684
+ if (!record || own(hovered) && hovered.keys[0] === hoverTarget.key) return;
7088
7685
  endHover();
7089
- startHover(record, from, hoverTarget.segment);
7686
+ startHover([record], from, hoverTarget.segment);
7090
7687
  },
7091
7688
  leave() {
7092
- if (hovered?.source !== "keyboard") endHover();
7689
+ if (hovered?.source === "pointer" || hovered?.source === "touch") endHover();
7093
7690
  }
7094
7691
  });
7095
7692
  }
@@ -7106,26 +7703,45 @@ function expressive(target, options, env2) {
7106
7703
  }
7107
7704
  return void 0;
7108
7705
  }
7109
- function startHover(record, from, segment) {
7110
- hovered = { key: record.key, source: from };
7706
+ function startHover(marks, from, segment, effects2 = true) {
7707
+ const started = { keys: marks.map((record) => record.key), source: from, effects: effects2 };
7708
+ hovered = started;
7111
7709
  applyDim();
7112
- runner.hover([input(record)]);
7113
- emit("hover", { ...input(record), batch: ONE, source: from, ...segment === void 0 ? {} : { segment } });
7710
+ if (effects2) runner.hover(marks.map(input));
7711
+ marks.forEach((record, index) => emit("hover", { ...input(record), batch: { index, count: marks.length }, source: from, ...segment === void 0 ? {} : { segment } }));
7712
+ if (from !== "linked" && hovered === started) linked2?.hover(marks.map(input));
7114
7713
  }
7115
7714
  function endHover() {
7116
7715
  const current = hovered;
7117
7716
  if (!current) return;
7118
7717
  hovered = void 0;
7119
- const record = find(current.key);
7120
7718
  applyDim();
7121
- runner.leave([current.key]);
7122
- if (record) emit("leave", { ...input(record), batch: ONE });
7719
+ leaveMarks(current.keys);
7720
+ if (own(current)) linked2?.leave();
7721
+ }
7722
+ function leaveMarks(keys) {
7723
+ const marks = keys.flatMap((key) => find(key) ?? []);
7724
+ runner.leave(keys);
7725
+ marks.forEach((record, index) => emit("leave", { ...input(record), batch: { index, count: marks.length } }));
7726
+ }
7727
+ function dropGone() {
7728
+ if (hovered === void 0) return;
7729
+ const keys = hovered.keys.filter((key) => records.has(key));
7730
+ if (keys.length === hovered.keys.length) return;
7731
+ if (keys.length === 0) {
7732
+ interaction?.clear();
7733
+ endHover();
7734
+ return;
7735
+ }
7736
+ const gone = hovered.keys.filter((key) => !records.has(key));
7737
+ hovered = { ...hovered, keys };
7738
+ leaveMarks(gone);
7123
7739
  }
7124
7740
  function applyDim() {
7125
7741
  if (!dim) return;
7126
7742
  const duration = `${motion2.duration(100, "feedback")}ms`;
7127
7743
  for (const record of order) {
7128
- const hot = hovered?.key === record.key;
7744
+ const hot = hovered?.keys.includes(record.key) === true;
7129
7745
  for (const part2 of record.mark.parts) {
7130
7746
  edits.toggleClass(part2.element, "ec-attached", true);
7131
7747
  edits.toggleClass(part2.element, "ec-dimmed", hovered !== void 0 && !hot);
@@ -7164,26 +7780,27 @@ function expressive(target, options, env2) {
7164
7780
  const record = records.get(key);
7165
7781
  if (!record) return;
7166
7782
  if (!visible) {
7167
- if (hovered?.source === "keyboard" && hovered.key !== key) endHover();
7783
+ if (hovered?.source === "keyboard" && hovered.keys[0] !== key) endHover();
7168
7784
  return;
7169
7785
  }
7170
- if (hovered?.key === key) {
7171
- hovered = { key, source: "keyboard" };
7786
+ if (own(hovered) && hovered.keys[0] === key) {
7787
+ hovered = { ...hovered, source: "keyboard" };
7172
7788
  return;
7173
7789
  }
7174
7790
  endHover();
7175
- startHover(record, "keyboard");
7791
+ startHover([record], "keyboard");
7176
7792
  },
7177
7793
  blur() {
7178
7794
  ringKey = void 0;
7179
7795
  drawRing();
7180
7796
  if (hovered?.source !== "keyboard") return;
7181
- if (interaction?.current === hovered.key) hovered = { key: hovered.key, source: "pointer" };
7797
+ if (interaction?.current === hovered.keys[0]) hovered = { ...hovered, source: "pointer" };
7182
7798
  else endHover();
7183
7799
  },
7184
7800
  escape() {
7185
7801
  if (!hovered) return false;
7186
- endHover();
7802
+ if (hovered.source === "linked" && linked2) linked2.dismiss();
7803
+ else endHover();
7187
7804
  return true;
7188
7805
  }
7189
7806
  }) : void 0;
@@ -7224,7 +7841,7 @@ function expressive(target, options, env2) {
7224
7841
  function reread(changed) {
7225
7842
  const at = { svg: root, common: ancestor, screen: screenMatrices(), colors: (element) => owners.get(element)?.part.colors };
7226
7843
  const rowOf = rowsNow();
7227
- const piecesOf = ({ parts }) => parts.map((part2) => ({ element: part2.element, datum: rowOf(part2.element), series: part2.series, value: part2.value }));
7844
+ const piecesOf = ({ parts: parts2 }) => parts2.map((part2) => ({ element: part2.element, datum: rowOf(part2.element), series: part2.series, value: part2.value }));
7228
7845
  if (options.geometry) {
7229
7846
  const marks2 = changed.map(({ mark }) => ({ ...shapeMark(mark.key, piecesOf(mark), mark.index, at), label: mark.label }));
7230
7847
  return { records: [...changed], marks: withData(marks2) };
@@ -7282,7 +7899,27 @@ function expressive(target, options, env2) {
7282
7899
  runner.enter(apply2(first).entering.map(input));
7283
7900
  keyboard?.sync();
7284
7901
  watchMarks();
7285
- return {
7902
+ const link2 = {
7903
+ targets: () => order.map((record) => ({ key: record.key, marks: [input(record)] })),
7904
+ hover(keys, effects2) {
7905
+ endHover();
7906
+ const marks = keys.flatMap((key) => records.get(key) ?? []);
7907
+ if (marks.length > 0) startHover(marks, "linked", void 0, effects2);
7908
+ },
7909
+ unlink() {
7910
+ if (hovered?.source === "linked") endHover();
7911
+ },
7912
+ leave() {
7913
+ interaction?.clear();
7914
+ endHover();
7915
+ },
7916
+ listen(listener) {
7917
+ if (destroyed) return false;
7918
+ linked2 = listener;
7919
+ return true;
7920
+ }
7921
+ };
7922
+ return linkable(link2, {
7286
7923
  refresh(next) {
7287
7924
  if (destroyed) return;
7288
7925
  const reading = read(next ?? source);
@@ -7290,13 +7927,12 @@ function expressive(target, options, env2) {
7290
7927
  runner.interrupt();
7291
7928
  const diff = apply2(reading);
7292
7929
  watchMarks();
7293
- if (hovered !== void 0 && !records.has(hovered.key)) {
7294
- interaction?.clear();
7295
- endHover();
7296
- }
7930
+ dropGone();
7297
7931
  const exited = runner.exit(diff.exiting.map(input));
7298
7932
  emitEach("exit", diff.exiting);
7299
- runner.update(diff.changed.map(({ record, from }) => ({ ...input(record), from })));
7933
+ if (diff.newRow || diff.changed.length > 0 || diff.entering.length > 0 || diff.exiting.length > 0) {
7934
+ runner.update(diff.changed.map(({ record, from }) => ({ ...input(record), from })));
7935
+ }
7300
7936
  diff.changed.forEach(({ record, from }, index) => emit("update", { ...input(record), from, batch: { index, count: diff.changed.length } }));
7301
7937
  runner.enter(diff.entering.map(input));
7302
7938
  emitEach("enter", diff.entering);
@@ -7328,6 +7964,8 @@ function expressive(target, options, env2) {
7328
7964
  if (destroyed) return;
7329
7965
  destroyed = true;
7330
7966
  hovered = void 0;
7967
+ linked2?.gone();
7968
+ linked2 = void 0;
7331
7969
  watching?.destroy();
7332
7970
  runner.destroy();
7333
7971
  unsubscribeMotion?.();
@@ -7341,7 +7979,7 @@ function expressive(target, options, env2) {
7341
7979
  order = [];
7342
7980
  owners = /* @__PURE__ */ new Map();
7343
7981
  }
7344
- };
7982
+ });
7345
7983
  }
7346
7984
  function checkOptions4(options) {
7347
7985
  if (typeof options !== "object" || options === null) throw new TypeError("expressive needs options, with at least a key: { key: (d) => d.name }.");
@@ -7357,9 +7995,9 @@ function ownSeries(mark) {
7357
7995
  const names = [...(mark.geometry.segments ?? []).map((s) => s.series), ...mark.parts.map((p) => p.series)];
7358
7996
  return [...new Set(names.filter((name) => name !== void 0))];
7359
7997
  }
7360
- function totalOf(parts) {
7998
+ function totalOf(parts2) {
7361
7999
  let total2 = 0;
7362
- for (const { value } of parts) {
8000
+ for (const { value } of parts2) {
7363
8001
  if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
7364
8002
  total2 += value;
7365
8003
  }
@@ -7383,14 +8021,17 @@ function checkSamples(samples, mark) {
7383
8021
  if (!Array.isArray(samples)) throw new TypeError(`expressive: samples for ${mark} must return an array of { t, value }, got ${describeValue2(samples)}.`);
7384
8022
  let last = 0;
7385
8023
  return samples.map((sample, i) => {
7386
- const { t, value, at } = typeof sample === "object" && sample !== null ? sample : {};
8024
+ const { t, value, at, gapBefore } = typeof sample === "object" && sample !== null ? sample : {};
7387
8025
  if (typeof t !== "number" || !(t >= 0 && t <= 1)) throw new RangeError(`expressive: samples for ${mark}: samples[${i}].t must be in [0, 1], got ${describeValue2(t)}.`);
7388
8026
  if (t < last) throw new RangeError(`expressive: samples for ${mark} must be in t order: samples[${i}].t is ${t}, after ${last}.`);
7389
8027
  if (typeof value !== "number" || !Number.isFinite(value)) {
7390
8028
  throw new RangeError(`expressive: samples for ${mark}: samples[${i}].value must be a finite number, got ${describeValue2(value)}.`);
7391
8029
  }
8030
+ if (gapBefore !== void 0 && typeof gapBefore !== "boolean") {
8031
+ throw new RangeError(`expressive: samples for ${mark}: samples[${i}].gapBefore must be true or false, got ${describeValue2(gapBefore)}.`);
8032
+ }
7392
8033
  last = t;
7393
- return at === void 0 ? { t, value } : { t, value, at };
8034
+ return { t, value, ...at === void 0 ? {} : { at }, ...gapBefore ? { gapBefore } : {} };
7394
8035
  });
7395
8036
  }
7396
8037
  function describeValue2(value) {
@@ -7411,9 +8052,9 @@ function ringOrder(marks, geometryOf) {
7411
8052
  function distance2(a, b) {
7412
8053
  return Math.hypot(a.x - b.x, a.y - b.y);
7413
8054
  }
7414
- function outlineOf(geometry, series, parts) {
8055
+ function outlineOf(geometry, series, parts2) {
7415
8056
  const segment = series === void 0 ? void 0 : geometry.segments?.find((s) => s.series === series);
7416
- const shape = segment ?? (parts === 1 ? geometry : void 0);
8057
+ const shape = segment ?? (parts2 === 1 ? geometry : void 0);
7417
8058
  if (!shape || segment && segment.length < 0.5) return void 0;
7418
8059
  return shape.outline.closed ? { d: shape.outline.d } : { d: shape.outline.d, stroke: shape.thickness };
7419
8060
  }
@@ -7452,7 +8093,7 @@ function samplesChanged(from, to) {
7452
8093
  return from.length !== to.length || from.some((a, i) => a.t !== to[i].t || a.value !== to[i].value || !sameAt2(a.at, to[i].at));
7453
8094
  }
7454
8095
  function geometryChanged2(from, to) {
7455
- if (from.outline.d !== to.outline.d || from.thickness !== to.thickness) return true;
8096
+ if (from.outline.d !== to.outline.d || from.thickness !== to.thickness || labelsMoved(from, to)) return true;
7456
8097
  const a = from.segments ?? [];
7457
8098
  const b = to.segments ?? [];
7458
8099
  return a.length !== b.length || a.some((segment, i) => segment.key !== b[i].key || segment.outline.d !== b[i].outline.d);
@@ -7490,7 +8131,7 @@ function fromVegaView(view, options, env2) {
7490
8131
  let observed;
7491
8132
  let stopFrame;
7492
8133
  let destroyed = false;
7493
- const observer = typeof MutationObserver === "function" ? new MutationObserver((records) => records.some(drawn) && schedule()) : void 0;
8134
+ const observer = typeof MutationObserver === "function" ? new MutationObserver((records) => records.some(drawn2) && schedule()) : void 0;
7494
8135
  observe(current.root);
7495
8136
  function itemOf(element) {
7496
8137
  const item = current.items.get(element);
@@ -7553,12 +8194,12 @@ function fromVegaView(view, options, env2) {
7553
8194
  const elements = [];
7554
8195
  for (const i of visualOrder(boxes, edges)) {
7555
8196
  const key = keys[i];
7556
- const parts = groups.get(key);
7557
- const { geometry, order } = describeRects(key, parts.map((p) => p.part), edges[i]);
8197
+ const parts2 = groups.get(key);
8198
+ const { geometry, order } = describeRects(key, parts2.map((p) => p.part), edges[i]);
7558
8199
  read.geometry.set(key, geometry);
7559
- elements.push(...order.map((j) => parts[j].element));
8200
+ elements.push(...order.map((j) => parts2[j].element));
7560
8201
  if (options.sample) {
7561
- const values = order.map((j) => valueOf(read.items.get(parts[j].element)).value);
8202
+ const values = order.map((j) => valueOf(read.items.get(parts2[j].element)).value);
7562
8203
  const total2 = values.reduce((sum, v) => sum + v, 0);
7563
8204
  read.samples.set(geometry, [{ t: 0, value: 0 }, { t: 1, value: total2 }]);
7564
8205
  let reached = 0;
@@ -7590,7 +8231,7 @@ function fromVegaView(view, options, env2) {
7590
8231
  const end = at === void 0 ? { t: 1, value } : { t: 1, value, at };
7591
8232
  return type === "symbol" ? [{ ...end, t: 0 }] : geometry.length > 0 ? [{ t: 0, value: 0 }, end] : [{ ...end, t: 0 }];
7592
8233
  }
7593
- function drawn(record) {
8234
+ function drawn2(record) {
7594
8235
  const overlay = observed?.querySelector(":scope > .ec-overlay");
7595
8236
  const ours = (node) => node === overlay || (overlay?.contains(node) ?? false);
7596
8237
  if (ours(record.target)) return false;
@@ -7629,7 +8270,7 @@ function fromVegaView(view, options, env2) {
7629
8270
  }
7630
8271
  observe(next.root);
7631
8272
  }
7632
- return {
8273
+ return linkable(portOf(attachment), {
7633
8274
  refresh,
7634
8275
  on: attachment.on,
7635
8276
  marks: attachment.marks,
@@ -7642,7 +8283,7 @@ function fromVegaView(view, options, env2) {
7642
8283
  stopFrame = void 0;
7643
8284
  attachment.destroy();
7644
8285
  }
7645
- };
8286
+ });
7646
8287
  }
7647
8288
  function checkView(view) {
7648
8289
  if (typeof view !== "object" || view === null || typeof view.renderer !== "function" || typeof view.scenegraph !== "function" || typeof view.container !== "function") {
@@ -7985,9 +8626,9 @@ function playTransition(pairs, options) {
7985
8626
  path: (d, paint) => target()?.path(d, paint) ?? INERT2,
7986
8627
  text: (content, style) => target()?.text(content, style) ?? INERT2,
7987
8628
  clear() {
7988
- const drawn = group;
8629
+ const drawn2 = group;
7989
8630
  group = void 0;
7990
- drawn?.clear();
8631
+ drawn2?.clear();
7991
8632
  }
7992
8633
  };
7993
8634
  }
@@ -8096,12 +8737,12 @@ function chartSwitch(target, options, env2) {
8096
8737
  if (!memory) return;
8097
8738
  const now = focused();
8098
8739
  if (now && now !== doc.body && now !== doc.documentElement && !wrapper.contains(now)) return;
8099
- const inside = () => to.chart.element.contains(focused());
8740
+ const inside3 = () => to.chart.element.contains(focused());
8100
8741
  if (memory.key !== void 0) to.chart.focus(memory.key);
8101
- if (inside()) return;
8742
+ if (inside3()) return;
8102
8743
  for (const mark of to.chart.marks()) {
8103
8744
  to.chart.focus(mark.key);
8104
- if (inside()) return;
8745
+ if (inside3()) return;
8105
8746
  }
8106
8747
  }
8107
8748
  function say(to) {
@@ -8206,20 +8847,20 @@ function chartSwitch(target, options, env2) {
8206
8847
  const drawings = [];
8207
8848
  for (const mark of from) if (!toKeys.has(mark.key)) drawings.push(fadeMark(mark, fadeOut));
8208
8849
  for (const mark of to) if (!fromByKey.has(mark.key)) drawings.push(fadeMark(mark, fadeIn));
8209
- const id = (label) => `${label.role}
8210
- ${label.key}`;
8850
+ const id = (label2) => `${label2.role}
8851
+ ${label2.key}`;
8211
8852
  const labelsA = a.chart.labels();
8212
8853
  const labelsB = b.chart.labels();
8213
- const byId = new Map(labelsA.map((label) => [id(label), label]));
8854
+ const byId = new Map(labelsA.map((label2) => [id(label2), label2]));
8214
8855
  const matched = /* @__PURE__ */ new Set();
8215
- for (const label of labelsB) {
8216
- const partner = byId.get(id(label));
8856
+ for (const label2 of labelsB) {
8857
+ const partner = byId.get(id(label2));
8217
8858
  if (!partner) continue;
8218
- matched.add(id(label));
8219
- drawings.push(moveLabel(copyLabel(partner, toA), copyLabel(label, toB)));
8859
+ matched.add(id(label2));
8860
+ drawings.push(moveLabel(copyLabel(partner, toA), copyLabel(label2, toB)));
8220
8861
  }
8221
- for (const label of labelsA) if (!matched.has(id(label))) drawings.push(fadeLabel(copyLabel(label, toA), fadeOut));
8222
- for (const label of labelsB) if (!byId.has(id(label))) drawings.push(fadeLabel(copyLabel(label, toB), fadeIn));
8862
+ for (const label2 of labelsA) if (!matched.has(id(label2))) drawings.push(fadeLabel(copyLabel(label2, toA), fadeOut));
8863
+ for (const label2 of labelsB) if (!byId.has(id(label2))) drawings.push(fadeLabel(copyLabel(label2, toB), fadeIn));
8223
8864
  drawings.push((s) => {
8224
8865
  setOpacity(a.container, 1 - clamp(s / OUT_BY));
8225
8866
  setOpacity(b.container, clamp((s - HALF) / (1 - HALF)));
@@ -8244,12 +8885,12 @@ ${label.key}`;
8244
8885
  svgLayer(group).path(mark.outline.d, mark.outline.closed ? { fill: "mark" } : { stroke: "mark", width: mark.thickness });
8245
8886
  return (s) => setAttributes(group, { opacity: opacity(s) });
8246
8887
  }
8247
- function copyLabel(label, m) {
8248
- const text2 = label.element.cloneNode(true);
8888
+ function copyLabel(label2, m) {
8889
+ const text2 = label2.element.cloneNode(true);
8249
8890
  for (const name of ["id", "opacity", "visibility", "aria-hidden"]) text2.removeAttribute(name);
8250
- text2.textContent = label.text;
8251
- const at = matrix.apply(m, label);
8252
- setAttributes(text2, { x: at.x, y: at.y, "text-anchor": label.anchor });
8891
+ text2.textContent = label2.text;
8892
+ const at = matrix.apply(m, label2);
8893
+ setAttributes(text2, { x: at.x, y: at.y, "text-anchor": label2.anchor });
8253
8894
  labelsLayer.appendChild(text2);
8254
8895
  return { text: text2, at };
8255
8896
  }
@@ -8340,8 +8981,8 @@ function moveLabel(a, b) {
8340
8981
  setAttributes(b.text, { x, y, visibility: second ? void 0 : "hidden" });
8341
8982
  };
8342
8983
  }
8343
- function fadeLabel(label, opacity) {
8344
- return (s) => setAttributes(label.text, { opacity: opacity(s) });
8984
+ function fadeLabel(label2, opacity) {
8985
+ return (s) => setAttributes(label2.text, { opacity: opacity(s) });
8345
8986
  }
8346
8987
  var fadeOut = (s) => 1 - clamp(s / HALF);
8347
8988
  var fadeIn = (s) => clamp((s - HALF) / (1 - HALF));
@@ -8435,10 +9076,10 @@ function motionSwitch(target, motion2, options = {}) {
8435
9076
  root.setAttribute("role", "group");
8436
9077
  root.setAttribute("aria-labelledby", `${id}-label`);
8437
9078
  root.setAttribute("aria-describedby", `${id}-hint`);
8438
- const label = root.appendChild(doc.createElement("span"));
8439
- label.className = "ec-motion-label";
8440
- label.id = `${id}-label`;
8441
- label.textContent = options.label ?? "Motion";
9079
+ const label2 = root.appendChild(doc.createElement("span"));
9080
+ label2.className = "ec-motion-label";
9081
+ label2.id = `${id}-label`;
9082
+ label2.textContent = options.label ?? "Motion";
8442
9083
  const modes = root.appendChild(doc.createElement("span"));
8443
9084
  modes.className = "ec-motion-modes";
8444
9085
  const buttons = MODES3.map((mode) => {
@@ -8506,8 +9147,8 @@ function checkMotion(motion2) {
8506
9147
  }
8507
9148
  }
8508
9149
  function checkOptions6(options) {
8509
- const { label, labels, hints, persist } = options;
8510
- if (label !== void 0 && typeof label !== "string") throw new TypeError(`motionSwitch: label must be a string, got ${typeof label}.`);
9150
+ const { label: label2, labels, hints, persist } = options;
9151
+ if (label2 !== void 0 && typeof label2 !== "string") throw new TypeError(`motionSwitch: label must be a string, got ${typeof label2}.`);
8511
9152
  for (const [name, texts] of [["labels", labels], ["hints", hints]]) {
8512
9153
  if (texts === void 0) continue;
8513
9154
  for (const [key, text2] of Object.entries(texts)) {
@@ -8604,6 +9245,7 @@ var gaits = { roll, step, slide };
8604
9245
  // src/effects/travel.ts
8605
9246
  var SPEED = 360;
8606
9247
  var SHORTEST = 260;
9248
+ var LONGEST2 = 4e3;
8607
9249
  var MIN_WALK = 0.5;
8608
9250
  var FIT = 0.85;
8609
9251
  var MIN_SMOOTHING = 2;
@@ -8616,7 +9258,7 @@ function travel(icon, options = {}) {
8616
9258
  const resolved = typeof icon === "string" ? ctx.icons.get(icon) : icon;
8617
9259
  if (!resolved) throw new RangeError(`travel: unknown icon "${String(icon)}". Register it with registerIcon(icon), or pass the icon itself.`);
8618
9260
  const walk = pick(mark, options.along);
8619
- if (!walk || !(walk.length >= MIN_WALK)) return void 0;
9261
+ if (!walk || !(drawn(walk) >= MIN_WALK)) return void 0;
8620
9262
  const scale2 = options.size === void 0 ? 1 : options.size === "fit" ? FIT * walk.thickness / resolved.box.height : options.size / resolved.size;
8621
9263
  if (!(scale2 > 0)) return void 0;
8622
9264
  return trip(walk, resolved, scale2, options);
@@ -8624,18 +9266,18 @@ function travel(icon, options = {}) {
8624
9266
  function rider(mark, ctx) {
8625
9267
  let current = plan(mark, ctx);
8626
9268
  let handle;
8627
- let drawn;
9269
+ let drawn2;
8628
9270
  let progress = 0;
8629
9271
  const draw = () => {
8630
9272
  if (!current) {
8631
9273
  handle?.remove();
8632
- handle = drawn = void 0;
9274
+ handle = drawn2 = void 0;
8633
9275
  return;
8634
9276
  }
8635
- if (!handle || drawn?.icon !== current.icon || drawn.size !== current.size) {
9277
+ if (!handle || drawn2?.icon !== current.icon || drawn2.size !== current.size) {
8636
9278
  handle?.remove();
8637
9279
  handle = ctx.layer.icon(current.icon, { size: current.size });
8638
- drawn = { icon: current.icon, size: current.size };
9280
+ drawn2 = { icon: current.icon, size: current.size };
8639
9281
  }
8640
9282
  handle.place(current.transform(progress));
8641
9283
  };
@@ -8682,7 +9324,12 @@ function trip(walk, icon, scale2, options) {
8682
9324
  const length = walk.length;
8683
9325
  const behind = icon.footprint[0] * scale2;
8684
9326
  const ahead = icon.footprint[1] * scale2;
8685
- const span = Math.max(0, length - behind - ahead);
9327
+ let span2 = 0;
9328
+ const legs = parts(walk).map(([from, to]) => {
9329
+ const leg = { from, to, span: Math.max(0, to - from - behind - ahead), before: span2 };
9330
+ span2 += leg.span;
9331
+ return leg;
9332
+ });
8686
9333
  const smoothing = Math.max(MIN_SMOOTHING, (behind + ahead) / 2);
8687
9334
  const radius = icon.radius ?? icon.box.height / 2;
8688
9335
  const { anchor } = icon;
@@ -8692,14 +9339,18 @@ function trip(walk, icon, scale2, options) {
8692
9339
  return {
8693
9340
  icon,
8694
9341
  size: icon.size * scale2,
8695
- span,
8696
- duration: Math.max(SHORTEST, span / SPEED * 1e3) * (gait.pace ?? 1),
9342
+ span: span2,
9343
+ duration: Math.min(LONGEST2, Math.max(SHORTEST, span2 / SPEED * 1e3) * (gait.pace ?? 1)),
8697
9344
  gait,
8698
9345
  transform(progress) {
8699
- const distance3 = behind + progress * span;
8700
- const pose = gait({ distance: progress * span / scale2, length: span / scale2, progress, radius });
9346
+ const travelled = progress * span2;
9347
+ let index = legs.length - 1;
9348
+ while (index > 0 && legs[index].before > travelled) index--;
9349
+ const leg = legs[index];
9350
+ const distance3 = leg.from + behind + Math.min(leg.span, travelled - leg.before);
9351
+ const pose = gait({ distance: travelled / scale2, length: span2 / scale2, progress, radius });
8701
9352
  const at = pointAt(walk, distance3);
8702
- const direction = heading(walk, Math.min(distance3, length), smoothing);
9353
+ const direction = heading(walk, Math.min(distance3, length), smoothing, leg);
8703
9354
  const mirror = orient === "auto" && icon.upright === true && Math.cos(direction) < -1e-9;
8704
9355
  const turn2 = orient === "level" ? 0 : mirror ? normalizeAngle(direction - Math.PI) : direction;
8705
9356
  return matrix.multiply(
@@ -8717,16 +9368,31 @@ function pick(mark, along) {
8717
9368
  if (mark.segments) return mark.segments.find((segment) => segment.series === along);
8718
9369
  return mark.series === along ? mark : void 0;
8719
9370
  }
9371
+ function parts(walk) {
9372
+ const { length } = walk;
9373
+ const found = [];
9374
+ let at = 0;
9375
+ for (const [from, to] of walk.gaps ?? []) {
9376
+ if (!(to > from) || !(to > at)) continue;
9377
+ if (from > at) found.push([at * length, Math.min(1, from) * length]);
9378
+ at = Math.min(1, to);
9379
+ }
9380
+ found.push([at * length, length]);
9381
+ return found;
9382
+ }
9383
+ function drawn(walk) {
9384
+ return parts(walk).reduce((sum, [from, to]) => sum + (to - from), 0);
9385
+ }
8720
9386
  function pointAt(walk, distance3) {
8721
9387
  const { length } = walk;
8722
9388
  return distance3 <= length ? walk.path(distance3 / length) : offset(walk.end, walk.angle(1), distance3 - length);
8723
9389
  }
8724
- function heading(walk, distance3, window) {
9390
+ function heading(walk, distance3, window, leg) {
8725
9391
  const { length } = walk;
8726
- const reach = Math.min(window, distance3, length - distance3);
8727
- if (reach > 1e-6) {
8728
- const a = walk.path((distance3 - reach) / length);
8729
- const b = walk.path((distance3 + reach) / length);
9392
+ const reach2 = Math.min(window, distance3 - leg.from, leg.to - distance3);
9393
+ if (reach2 > 1e-6) {
9394
+ const a = walk.path((distance3 - reach2) / length);
9395
+ const b = walk.path((distance3 + reach2) / length);
8730
9396
  if (Math.hypot(b.x - a.x, b.y - a.y) > 1e-9) return Math.atan2(b.y - a.y, b.x - a.x);
8731
9397
  }
8732
9398
  return walk.angle(distance3 / length);
@@ -8758,7 +9424,7 @@ function flash(options = {}) {
8758
9424
  const width = options.width ?? WIDTH;
8759
9425
  const opacity = options.opacity ?? OPACITY;
8760
9426
  const { color } = options;
8761
- const show3 = (ctx, progress) => {
9427
+ const show4 = (ctx, progress) => {
8762
9428
  const stroke2 = width * blink(progress);
8763
9429
  ctx.mark.set({ halo: stroke2 > 0 ? { width: stroke2, opacity, ...color === void 0 ? {} : { color } } : void 0 });
8764
9430
  };
@@ -8766,7 +9432,7 @@ function flash(options = {}) {
8766
9432
  kind: "geometry",
8767
9433
  async run(_mark, ctx) {
8768
9434
  if (ctx.signal.aborted) return;
8769
- await ctx.tween({ duration: DURATION2, timing: "effect", ease: linear, update: (p) => show3(ctx, p) }).finished;
9435
+ await ctx.tween({ duration: DURATION2, timing: "effect", ease: linear, update: (p) => show4(ctx, p) }).finished;
8770
9436
  },
8771
9437
  end() {
8772
9438
  },
@@ -8821,14 +9487,14 @@ function wiggle(options = {}) {
8821
9487
  let current = mark;
8822
9488
  let cap = limit(mark, swing);
8823
9489
  let progress = 0;
8824
- const show3 = () => {
9490
+ const show4 = () => {
8825
9491
  const angle = cap * rock(progress);
8826
9492
  ctx.mark.set({ transform: angle === 0 ? void 0 : matrix.rotate(angle, current.pivot) });
8827
9493
  };
8828
9494
  ctx.onChange((next) => {
8829
9495
  current = next;
8830
9496
  cap = limit(next, swing);
8831
- show3();
9497
+ show4();
8832
9498
  });
8833
9499
  await ctx.tween({
8834
9500
  duration: DURATION3,
@@ -8836,7 +9502,7 @@ function wiggle(options = {}) {
8836
9502
  ease: linear,
8837
9503
  update: (p) => {
8838
9504
  progress = p;
8839
- show3();
9505
+ show4();
8840
9506
  }
8841
9507
  }).finished;
8842
9508
  },
@@ -8848,10 +9514,10 @@ function wiggle(options = {}) {
8848
9514
  }
8849
9515
  function limit(mark, swing) {
8850
9516
  const { pivot } = mark;
8851
- let reach = 0;
8852
- for (const point of mark.outline.sample(SAMPLES)) reach = Math.max(reach, Math.hypot(point.x - pivot.x, point.y - pivot.y));
8853
- if (!(reach >= MIN_REACH)) return 0;
8854
- return Math.min(MAX_ANGLE, 2 * Math.asin(Math.min(1, swing / (2 * reach))));
9517
+ let reach2 = 0;
9518
+ for (const point of mark.outline.sample(SAMPLES)) reach2 = Math.max(reach2, Math.hypot(point.x - pivot.x, point.y - pivot.y));
9519
+ if (!(reach2 >= MIN_REACH)) return 0;
9520
+ return Math.min(MAX_ANGLE, 2 * Math.asin(Math.min(1, swing / (2 * reach2))));
8855
9521
  }
8856
9522
  function rock(t) {
8857
9523
  if (!(t > 0) || t >= 1) return 0;
@@ -8878,7 +9544,7 @@ function pulse(options = {}) {
8878
9544
  const times = options.times ?? TIMES;
8879
9545
  const width = options.width ?? WIDTH2;
8880
9546
  const { color } = options;
8881
- const show3 = (ctx, t) => {
9547
+ const show4 = (ctx, t) => {
8882
9548
  const visible = t > 0 && t < 1;
8883
9549
  ctx.mark.set({
8884
9550
  halo: visible ? { width: width * easeOutCubic(t), opacity: OPACITY2 * (1 - t), ...color === void 0 ? {} : { color } } : void 0
@@ -8893,7 +9559,7 @@ function pulse(options = {}) {
8893
9559
  const length = ctx.motion.duration(DURATION4, "effect");
8894
9560
  if (total2 + length >= LIMIT) return;
8895
9561
  total2 += length;
8896
- await ctx.tween({ duration: DURATION4, timing: "effect", ease: linear, update: (t) => show3(ctx, t) }).finished;
9562
+ await ctx.tween({ duration: DURATION4, timing: "effect", ease: linear, update: (t) => show4(ctx, t) }).finished;
8897
9563
  }
8898
9564
  },
8899
9565
  end() {
@@ -8915,12 +9581,238 @@ function checkOptions11(options) {
8915
9581
  }
8916
9582
  }
8917
9583
 
8918
- // src/effects/threshold.ts
9584
+ // src/effects/trace.ts
9585
+ var DURATION5 = 500;
9586
+ var WIDTH3 = 3;
9587
+ var OPACITY3 = 0.5;
8919
9588
  var MIN_WALK2 = 0.5;
9589
+ function trace(options = {}) {
9590
+ checkOptions12(options);
9591
+ const duration = options.duration ?? DURATION5;
9592
+ const paint = { stroke: options.color ?? "mark", width: options.width ?? WIDTH3, opacity: options.opacity ?? OPACITY3, linecap: "round" };
9593
+ const stroke2 = (mark, ctx) => {
9594
+ let current = mark;
9595
+ let progress = 0;
9596
+ let path;
9597
+ const draw = () => {
9598
+ if (!(current.length >= MIN_WALK2)) {
9599
+ path?.remove();
9600
+ path = void 0;
9601
+ return;
9602
+ }
9603
+ const d = current.slice(0, progress);
9604
+ if (path) path.update(d);
9605
+ else path = ctx.layer.path(d, paint);
9606
+ };
9607
+ ctx.onChange((next) => {
9608
+ current = next;
9609
+ draw();
9610
+ });
9611
+ draw();
9612
+ return (p) => {
9613
+ progress = p;
9614
+ draw();
9615
+ };
9616
+ };
9617
+ return {
9618
+ kind: "geometry",
9619
+ async run(mark, ctx) {
9620
+ if (ctx.signal.aborted) return;
9621
+ const show4 = stroke2(mark, ctx);
9622
+ if (!(mark.length >= MIN_WALK2)) {
9623
+ show4(1);
9624
+ return;
9625
+ }
9626
+ await ctx.tween({ duration, timing: "effect", ease: easeInOutCubic, update: show4 }).finished;
9627
+ },
9628
+ end(mark, ctx) {
9629
+ stroke2(mark, ctx)(1);
9630
+ },
9631
+ clear() {
9632
+ }
9633
+ };
9634
+ }
9635
+ function checkOptions12(options) {
9636
+ const { color, width, opacity, duration } = options;
9637
+ if (color !== void 0 && (typeof color !== "string" || color === "")) {
9638
+ throw new RangeError(`trace: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
9639
+ }
9640
+ if (width !== void 0 && !(typeof width === "number" && width >= 0 && Number.isFinite(width))) {
9641
+ throw new RangeError(`trace: width must be 0 px or more, got ${String(width)}.`);
9642
+ }
9643
+ if (opacity !== void 0 && !(typeof opacity === "number" && opacity >= 0 && opacity <= 1)) {
9644
+ throw new RangeError(`trace: opacity must be from 0 to 1, got ${String(opacity)}.`);
9645
+ }
9646
+ if (duration !== void 0 && !(typeof duration === "number" && duration >= 0 && Number.isFinite(duration))) {
9647
+ throw new RangeError(`trace: duration must be 0 ms or more, got ${String(duration)}.`);
9648
+ }
9649
+ }
9650
+
9651
+ // src/effects/caption.ts
9652
+ var PAST_END = 10;
9653
+ var PAST_LABEL = 6;
9654
+ var RISE = 8;
9655
+ var TEXT = 12.5;
9656
+ var CENTRE4 = 0.36;
9657
+ var HANG = 0.8;
9658
+ function captionPlace(mark) {
9659
+ const boxes = mark.labelBounds ?? [];
9660
+ const heading2 = mark.angle(1);
9661
+ const along = farthest(mark.end, heading2, boxes);
9662
+ if (along === void 0 && boxes.length > 0) {
9663
+ const up = mark.angle(0.5) - Math.PI / 2;
9664
+ const out = farthest(mark.center, up, boxes);
9665
+ if (out !== void 0) return placed(mark.center, up, out);
9666
+ }
9667
+ return placed(mark.end, heading2, Math.max(PAST_END, along ?? -Infinity));
9668
+ }
9669
+ function placed(from, toward, distance3) {
9670
+ const cos = Math.cos(toward);
9671
+ const sin = Math.sin(toward);
9672
+ const point = offset(from, toward, distance3);
9673
+ const drop = TEXT * (sin < 0 ? CENTRE4 * (1 + sin) : CENTRE4 + (HANG - CENTRE4) * sin);
9674
+ const anchor = Math.abs(cos) <= Math.SQRT1_2 + 1e-9 ? "middle" : cos > 0 ? "start" : "end";
9675
+ return { at: { x: point.x, y: point.y + drop }, anchor, toward };
9676
+ }
9677
+ function farthest(from, toward, boxes) {
9678
+ const cos = Math.cos(toward);
9679
+ const sin = Math.sin(toward);
9680
+ let exit;
9681
+ for (const { x, y, width, height } of boxes) {
9682
+ const grown = { x: x - PAST_LABEL, y: y - PAST_LABEL, width: width + 2 * PAST_LABEL, height: height + 2 * PAST_LABEL };
9683
+ const leaving = leaves(from, cos, sin, grown);
9684
+ if (leaving !== void 0) exit = Math.max(exit ?? leaving, leaving);
9685
+ }
9686
+ return exit;
9687
+ }
9688
+ function leaves(from, cos, sin, box) {
9689
+ let near = 0;
9690
+ let far = Infinity;
9691
+ for (const [origin, step2, lo, hi] of [
9692
+ [from.x, cos, box.x, box.x + box.width],
9693
+ [from.y, sin, box.y, box.y + box.height]
9694
+ ]) {
9695
+ if (Math.abs(step2) < 1e-12) {
9696
+ if (origin < lo || origin > hi) return void 0;
9697
+ continue;
9698
+ }
9699
+ const a = (lo - origin) / step2;
9700
+ const b = (hi - origin) / step2;
9701
+ near = Math.max(near, Math.min(a, b));
9702
+ far = Math.min(far, Math.max(a, b));
9703
+ }
9704
+ return far >= near ? far : void 0;
9705
+ }
9706
+ function caption(mark, data, ctx, color, words) {
9707
+ let current = mark;
9708
+ let content = words(mark, data) ?? "";
9709
+ let latest = data;
9710
+ let progress = 0;
9711
+ let handle;
9712
+ const draw = () => {
9713
+ if (content === "") {
9714
+ handle?.remove();
9715
+ handle = void 0;
9716
+ return;
9717
+ }
9718
+ const { at, anchor, toward } = captionPlace(current);
9719
+ const style = { at: offset(at, toward - Math.PI / 2, -RISE * (1 - progress)), anchor, color, opacity: progress };
9720
+ if (handle) handle.update(style, content);
9721
+ else handle = ctx.layer.text(content, style);
9722
+ };
9723
+ ctx.onChange((next, nextData) => {
9724
+ current = next;
9725
+ latest = nextData ?? latest;
9726
+ content = words(current, latest) ?? "";
9727
+ draw();
9728
+ });
9729
+ draw();
9730
+ return (p) => {
9731
+ progress = p;
9732
+ draw();
9733
+ };
9734
+ }
9735
+
9736
+ // src/effects/delta.ts
9737
+ var DURATION6 = 400;
8920
9738
  var TIE = 1e-9;
9739
+ var lastSample = (data) => {
9740
+ const { samples } = data;
9741
+ return samples[samples.length - 1]?.value ?? Number.NaN;
9742
+ };
9743
+ var wording;
9744
+ var signed = (change) => {
9745
+ wording ?? (wording = new Intl.NumberFormat(void 0, { signDisplay: "always", maximumFractionDigits: 2 }));
9746
+ return wording.format(change);
9747
+ };
9748
+ function delta(options = {}) {
9749
+ checkOptions13(options);
9750
+ const value = options.value ?? lastSample;
9751
+ const format2 = options.format ?? signed;
9752
+ const color = options.color ?? "text";
9753
+ const words = (data) => {
9754
+ if (!data.previous) return void 0;
9755
+ const now = value(data);
9756
+ const before = value(data.previous);
9757
+ const change = now - before;
9758
+ if (!Number.isFinite(change) || Math.abs(change) <= TIE * Math.max(Math.abs(now), Math.abs(before))) return void 0;
9759
+ return format2(change);
9760
+ };
9761
+ return {
9762
+ kind: "data",
9763
+ run: async (mark, data, ctx) => {
9764
+ if (ctx.signal.aborted) return;
9765
+ const text2 = words(data);
9766
+ if (text2 === void 0 || text2 === "") return;
9767
+ const show4 = caption(mark, data, ctx, color, () => text2);
9768
+ await ctx.tween({ duration: DURATION6, timing: "effect", update: show4 }).finished;
9769
+ },
9770
+ end: (mark, data, ctx) => {
9771
+ const text2 = words(data);
9772
+ if (text2 !== void 0 && text2 !== "") caption(mark, data, ctx, color, () => text2)(1);
9773
+ },
9774
+ clear() {
9775
+ }
9776
+ };
9777
+ }
9778
+ function checkOptions13(options) {
9779
+ const { value, format: format2, color } = options;
9780
+ if (value !== void 0 && typeof value !== "function") throw new TypeError(`delta: value must be a function that reads the mark's value from its data, got ${typeof value}.`);
9781
+ if (format2 !== void 0 && typeof format2 !== "function") throw new TypeError(`delta: format must be a function that words the change, got ${typeof format2}.`);
9782
+ if (color !== void 0 && (typeof color !== "string" || color === "")) {
9783
+ throw new RangeError(`delta: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
9784
+ }
9785
+ }
9786
+
9787
+ // src/effects/label.ts
9788
+ var DURATION7 = 400;
9789
+ function label(text2, options = {}) {
9790
+ if (typeof text2 !== "function") throw new TypeError(`label needs a function that returns the text from the mark's data, got ${typeof text2}.`);
9791
+ const { color = "text" } = options;
9792
+ if (typeof color !== "string" || color === "") throw new RangeError(`label: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
9793
+ const words = (mark, data) => {
9794
+ const said2 = text2(data, mark);
9795
+ return said2 === void 0 || said2 === null ? void 0 : String(said2);
9796
+ };
9797
+ return {
9798
+ kind: "data",
9799
+ run: async (mark, data, ctx) => {
9800
+ if (ctx.signal.aborted) return;
9801
+ const show4 = caption(mark, data, ctx, color, words);
9802
+ await ctx.tween({ duration: DURATION7, timing: "effect", update: show4 }).finished;
9803
+ },
9804
+ end: (mark, data, ctx) => caption(mark, data, ctx, color, words)(1),
9805
+ clear() {
9806
+ }
9807
+ };
9808
+ }
9809
+
9810
+ // src/effects/threshold.ts
9811
+ var MIN_WALK3 = 0.5;
9812
+ var TIE2 = 1e-9;
8921
9813
  var WHENS = ["below", "above"];
8922
9814
  function threshold(options) {
8923
- checkOptions12(options);
9815
+ checkOptions14(options);
8924
9816
  const { compareTo } = options;
8925
9817
  const when = options.when ?? "below";
8926
9818
  const color = options.color ?? "negative";
@@ -8928,15 +9820,15 @@ function threshold(options) {
8928
9820
  const paths = [];
8929
9821
  let latest = data;
8930
9822
  const draw = (current) => {
8931
- const parts = current.length >= MIN_WALK2 ? runs(latest.samples, reference(compareTo, latest), when) : [];
9823
+ const parts2 = current.length >= MIN_WALK3 ? runs(latest.samples, reference(compareTo, latest), when) : [];
8932
9824
  const paint = { stroke: color, width: current.thickness, linecap: "butt" };
8933
- parts.forEach(([t0, t1], i) => {
9825
+ parts2.forEach(([t0, t1], i) => {
8934
9826
  const d = current.slice(t0, t1);
8935
9827
  const path = paths[i];
8936
9828
  if (path) path.update(d, paint);
8937
9829
  else paths.push(ctx.layer.path(d, paint));
8938
9830
  });
8939
- for (const path of paths.splice(parts.length)) path.remove();
9831
+ for (const path of paths.splice(parts2.length)) path.remove();
8940
9832
  };
8941
9833
  ctx.onChange((next, nextData) => {
8942
9834
  latest = nextData ?? latest;
@@ -8962,7 +9854,37 @@ function reference(compareTo, data) {
8962
9854
  const byAt = data.samples.every((sample) => numeric2(sample.at) !== void 0) && related.samples.every((sample) => numeric2(sample.at) !== void 0);
8963
9855
  const place = byAt ? (sample) => numeric2(sample.at) : (sample) => sample.t;
8964
9856
  const points = related.samples.map((sample) => ({ u: place(sample), value: sample.value })).filter((point) => Number.isFinite(point.u)).sort((a, b) => a.u - b.u);
8965
- return { place, valueAt: (u) => interpolate(points, u), bends: points.map((point) => point.u) };
9857
+ const gaps = gapsOf(related.samples, place);
9858
+ return { place, valueAt: (u) => inside2(gaps, u) ? void 0 : interpolate(points, u), bends: points.map((point) => point.u) };
9859
+ }
9860
+ function gapsOf(samples, place) {
9861
+ const gaps = [];
9862
+ samples.forEach((sample, i) => {
9863
+ const before = samples[i - 1];
9864
+ if (sample.gapBefore !== true || !before) return;
9865
+ const u = place(before);
9866
+ const v = place(sample);
9867
+ if (Number.isFinite(u) && Number.isFinite(v) && u !== v) gaps.push([Math.min(u, v), Math.max(u, v)]);
9868
+ });
9869
+ gaps.sort((a, b) => a[0] - b[0]);
9870
+ const merged = [];
9871
+ for (const gap of gaps) {
9872
+ const last = merged[merged.length - 1];
9873
+ if (last && gap[0] < last[1]) last[1] = Math.max(last[1], gap[1]);
9874
+ else merged.push(gap);
9875
+ }
9876
+ return merged;
9877
+ }
9878
+ function inside2(gaps, u) {
9879
+ let lo = 0;
9880
+ let hi = gaps.length;
9881
+ while (lo < hi) {
9882
+ const mid = lo + hi >> 1;
9883
+ if (gaps[mid][0] < u) lo = mid + 1;
9884
+ else hi = mid;
9885
+ }
9886
+ const gap = gaps[lo - 1];
9887
+ return gap !== void 0 && u < gap[1];
8966
9888
  }
8967
9889
  function numeric2(at) {
8968
9890
  const value = typeof at === "number" ? at : at instanceof Date ? at.getTime() : void 0;
@@ -8987,18 +9909,18 @@ function interpolate(points, u) {
8987
9909
  function runs(samples, ref, when) {
8988
9910
  if (!ref) return [];
8989
9911
  const sign = when === "below" ? 1 : -1;
8990
- const station = (t, u, value) => {
9912
+ const station = (t, u, value, joined = true) => {
8991
9913
  const level = ref.valueAt(u);
8992
- if (level === void 0 || !Number.isFinite(level) || !Number.isFinite(value) || !Number.isFinite(t)) return { t, past: void 0 };
9914
+ if (level === void 0 || !Number.isFinite(level) || !Number.isFinite(value) || !Number.isFinite(t)) return { t, u, past: void 0, joined };
8993
9915
  const past = sign * (level - value);
8994
- return { t, past: Math.abs(past) <= TIE * Math.max(Math.abs(level), Math.abs(value)) ? 0 : past };
9916
+ return { t, u, past: Math.abs(past) <= TIE2 * Math.max(Math.abs(level), Math.abs(value)) ? 0 : past, joined };
8995
9917
  };
8996
9918
  const stations = [];
8997
9919
  samples.forEach((sample, i) => {
8998
9920
  const u = ref.place(sample);
8999
- stations.push(station(sample.t, u, sample.value));
9921
+ stations.push(station(sample.t, u, sample.value, sample.gapBefore !== true));
9000
9922
  const next = samples[i + 1];
9001
- if (!next) return;
9923
+ if (!next || next.gapBefore === true) return;
9002
9924
  const v = ref.place(next);
9003
9925
  if (u === v || !Number.isFinite(u) || !Number.isFinite(v)) return;
9004
9926
  const shares = [];
@@ -9009,24 +9931,25 @@ function runs(samples, ref, when) {
9009
9931
  stations.push(station(sample.t + share * (next.t - sample.t), u + share * (v - u), sample.value + share * (next.value - sample.value)));
9010
9932
  }
9011
9933
  });
9012
- const parts = [];
9934
+ const parts2 = [];
9013
9935
  const add = (t0, t1) => {
9014
9936
  const from = clamp2(t0);
9015
9937
  const to = clamp2(t1);
9016
9938
  if (!(to > from)) return;
9017
- const last = parts[parts.length - 1];
9939
+ const last = parts2[parts2.length - 1];
9018
9940
  if (last && last[1] >= from) last[1] = Math.max(last[1], to);
9019
- else parts.push([from, to]);
9941
+ else parts2.push([from, to]);
9020
9942
  };
9021
9943
  for (let i = 1; i < stations.length; i++) {
9022
9944
  const a = stations[i - 1];
9023
9945
  const b = stations[i];
9024
- if (a.past === void 0 || b.past === void 0 || !(b.t > a.t)) continue;
9946
+ if (a.past === void 0 || b.past === void 0 || !b.joined || !(b.t > a.t)) continue;
9947
+ if (a.u !== b.u && ref.valueAt((a.u + b.u) / 2) === void 0) continue;
9025
9948
  if (a.past > 0 && b.past > 0) add(a.t, b.t);
9026
9949
  else if (a.past > 0) add(a.t, a.t + (b.t - a.t) * (a.past / (a.past - b.past)));
9027
9950
  else if (b.past > 0) add(a.t + (b.t - a.t) * (a.past / (a.past - b.past)), b.t);
9028
9951
  }
9029
- return parts;
9952
+ return parts2;
9030
9953
  }
9031
9954
  var clamp2 = (t) => Math.min(1, Math.max(0, t));
9032
9955
  function firstAbove(values, x) {
@@ -9039,24 +9962,24 @@ function firstAbove(values, x) {
9039
9962
  }
9040
9963
  return lo;
9041
9964
  }
9042
- function checkOptions12(options) {
9965
+ function checkOptions14(options) {
9043
9966
  const { compareTo, when, color } = options ?? {};
9044
9967
  if (!(typeof compareTo === "string" ? compareTo !== "" : typeof compareTo === "number" && Number.isFinite(compareTo))) {
9045
- throw new RangeError(`threshold: compareTo must be a finite number or a series name, got ${show2(compareTo)}.`);
9968
+ throw new RangeError(`threshold: compareTo must be a finite number or a series name, got ${show3(compareTo)}.`);
9046
9969
  }
9047
- if (when !== void 0 && !WHENS.includes(when)) throw new RangeError(`threshold: when must be "below" or "above", got ${show2(when)}.`);
9970
+ if (when !== void 0 && !WHENS.includes(when)) throw new RangeError(`threshold: when must be "below" or "above", got ${show3(when)}.`);
9048
9971
  if (color !== void 0 && (typeof color !== "string" || color === "")) {
9049
- throw new RangeError(`threshold: color must be a theme token or a CSS colour, got ${show2(color)}.`);
9972
+ throw new RangeError(`threshold: color must be a theme token or a CSS colour, got ${show3(color)}.`);
9050
9973
  }
9051
9974
  }
9052
- var show2 = (value) => typeof value === "string" ? JSON.stringify(value) : String(value);
9975
+ var show3 = (value) => typeof value === "string" ? JSON.stringify(value) : String(value);
9053
9976
 
9054
9977
  // src/effects/morph.ts
9055
- var DURATION5 = 950;
9978
+ var DURATION8 = 950;
9056
9979
  var POINTS = 160;
9057
9980
  var ALIGNS = ["unroll", "drop"];
9058
9981
  function morph(options = {}) {
9059
- checkOptions13(options);
9982
+ checkOptions15(options);
9060
9983
  const points = options?.points ?? POINTS;
9061
9984
  const align = options?.align ?? "unroll";
9062
9985
  return {
@@ -9072,7 +9995,7 @@ function morph(options = {}) {
9072
9995
  const begun = unease(start);
9073
9996
  let running;
9074
9997
  running = ctx.tween({
9075
- duration: DURATION5,
9998
+ duration: DURATION8,
9076
9999
  timing: "transition",
9077
10000
  ease: linear,
9078
10001
  update: (k) => {
@@ -9160,7 +10083,7 @@ function turn(from, to, points) {
9160
10083
  function startOf(start) {
9161
10084
  return typeof start === "number" && start > 0 ? Math.min(1, start) : 0;
9162
10085
  }
9163
- function checkOptions13(options) {
10086
+ function checkOptions15(options) {
9164
10087
  const { points, align } = options ?? {};
9165
10088
  if (points !== void 0 && !(Number.isInteger(points) && points >= 4 && points % 4 === 0)) {
9166
10089
  throw new RangeError(`morph: points must be a whole multiple of 4, got ${String(points)}.`);
@@ -9170,18 +10093,18 @@ function checkOptions13(options) {
9170
10093
 
9171
10094
  // src/effects/combinators.ts
9172
10095
  function sequence(...effects) {
9173
- const parts = check("sequence", effects);
9174
- return combine(parts, async (start, ctx) => {
9175
- for (const part of parts) {
10096
+ const parts2 = check("sequence", effects);
10097
+ return combine(parts2, async (start, ctx) => {
10098
+ for (const part of parts2) {
9176
10099
  if (ctx.signal.aborted) return;
9177
10100
  await start(part);
9178
10101
  }
9179
10102
  });
9180
10103
  }
9181
10104
  function parallel(...effects) {
9182
- const parts = check("parallel", effects);
9183
- return combine(parts, async (start) => {
9184
- await Promise.all(parts.map(start));
10105
+ const parts2 = check("parallel", effects);
10106
+ return combine(parts2, async (start) => {
10107
+ await Promise.all(parts2.map(start));
9185
10108
  });
9186
10109
  }
9187
10110
  function only(filter, effect) {
@@ -9264,7 +10187,7 @@ function follow(mark, data, ctx) {
9264
10187
  });
9265
10188
  return () => latest;
9266
10189
  }
9267
- function combine(parts, play) {
10190
+ function combine(parts2, play) {
9268
10191
  const starter = (mark, data, ctx) => {
9269
10192
  const now = follow(mark, data, ctx);
9270
10193
  return (part) => {
@@ -9273,14 +10196,14 @@ function combine(parts, play) {
9273
10196
  };
9274
10197
  };
9275
10198
  const end = (mark, data, ctx) => {
9276
- for (const part of parts) {
10199
+ for (const part of parts2) {
9277
10200
  if (part.kind === "data") part.end(mark, data, ctx);
9278
10201
  else part.end(mark, ctx);
9279
10202
  }
9280
10203
  };
9281
10204
  const clear = (ctx) => {
9282
10205
  let failure;
9283
- for (const part of parts) {
10206
+ for (const part of parts2) {
9284
10207
  try {
9285
10208
  part.clear(ctx);
9286
10209
  } catch (error) {
@@ -9289,8 +10212,8 @@ function combine(parts, play) {
9289
10212
  }
9290
10213
  if (failure) throw failure.error;
9291
10214
  };
9292
- if (parts.some((part) => part.kind === "data")) {
9293
- const related = [...new Set(parts.flatMap((part) => part.kind === "data" ? part.needs?.related ?? [] : []))];
10215
+ if (parts2.some((part) => part.kind === "data")) {
10216
+ const related = [...new Set(parts2.flatMap((part) => part.kind === "data" ? part.needs?.related ?? [] : []))];
9294
10217
  const effect2 = {
9295
10218
  kind: "data",
9296
10219
  ...related.length > 0 ? { needs: { related } } : {},
@@ -9350,6 +10273,7 @@ function checkNeeds2(needs) {
9350
10273
  var GAITS = ["roll", "step", "slide"];
9351
10274
  var LINECAPS = ["butt", "round"];
9352
10275
  var LINEJOINS = ["miter", "round"];
10276
+ var FILL_RULES = ["nonzero", "evenodd"];
9353
10277
  var PATH_DATA = /^\s*[Mm][MmLlHhVvCcSsQqTtAaZz0-9eE.,+\-\s]*$/;
9354
10278
  function defineIcon(spec) {
9355
10279
  const name = spec?.name;
@@ -9369,8 +10293,8 @@ function defineIcon(spec) {
9369
10293
  const pivot = spec.pivot === void 0 ? anchor : point("pivot", spec.pivot);
9370
10294
  const footprint = spec.footprint ?? [Math.max(0, anchor.x - box.x), Math.max(0, box.x + box.width - anchor.x)];
9371
10295
  if (!Array.isArray(footprint) || footprint.length !== 2) fail("footprint", "must be [behind, ahead]");
9372
- footprint.forEach((reach, i) => {
9373
- if (finite2(`footprint[${i}]`, reach) < 0) fail(`footprint[${i}]`, `can't be negative, got ${reach}`);
10296
+ footprint.forEach((reach2, i) => {
10297
+ if (finite2(`footprint[${i}]`, reach2) < 0) fail(`footprint[${i}]`, `can't be negative, got ${reach2}`);
9374
10298
  });
9375
10299
  const size2 = spec.size === void 0 ? box.width : positive("size", spec.size);
9376
10300
  const radius = spec.radius === void 0 ? box.height / 2 : positive("radius", spec.radius);
@@ -9400,8 +10324,11 @@ function checkShape(shape, field, fail, finite2) {
9400
10324
  if (shape.width !== void 0 && finite2(`${field}.width`, shape.width) < 0) fail(`${field}.width`, `can't be negative, got ${shape.width}`);
9401
10325
  if (shape.linecap !== void 0 && !LINECAPS.includes(shape.linecap)) fail(`${field}.linecap`, `must be butt or round, got ${String(shape.linecap)}`);
9402
10326
  if (shape.linejoin !== void 0 && !LINEJOINS.includes(shape.linejoin)) fail(`${field}.linejoin`, `must be miter or round, got ${String(shape.linejoin)}`);
10327
+ if (shape.fillRule !== void 0 && !FILL_RULES.includes(shape.fillRule)) fail(`${field}.fillRule`, `must be nonzero or evenodd, got ${String(shape.fillRule)}`);
10328
+ const opacity = shape.opacity === void 0 ? 1 : finite2(`${field}.opacity`, shape.opacity);
10329
+ if (opacity < 0 || opacity > 1) fail(`${field}.opacity`, `must be from 0 to 1, got ${opacity}`);
9403
10330
  const copy = { d: shape.d };
9404
- for (const key of ["fill", "stroke", "width", "linecap", "linejoin", "clip"]) {
10331
+ for (const key of ["fill", "stroke", "width", "linecap", "linejoin", "clip", "fillRule", "opacity"]) {
9405
10332
  if (shape[key] !== void 0) copy[key] = shape[key];
9406
10333
  }
9407
10334
  return freeze(copy);
@@ -9416,9 +10343,9 @@ var ATTRIBUTE = /([^\s=/<>]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'<>]+)))?/g;
9416
10343
  var COLOR = /^(?:#[0-9a-fA-F]{3,8}|[a-zA-Z][a-zA-Z0-9-]*|(?:rgba?|hsla?)\([\d\s.,%+\-/]*\))$/;
9417
10344
  function iconFromSvg(markup, spec) {
9418
10345
  if (typeof markup !== "string") throw new TypeError("iconFromSvg needs SVG markup as a string.");
9419
- const label = typeof spec?.name === "string" ? `"${spec.name}"` : "an icon";
10346
+ const label2 = typeof spec?.name === "string" ? `"${spec.name}"` : "an icon";
9420
10347
  const fail = (problem) => {
9421
- throw new RangeError(`iconFromSvg: ${label} ${problem}.`);
10348
+ throw new RangeError(`iconFromSvg: ${label2} ${problem}.`);
9422
10349
  };
9423
10350
  let box;
9424
10351
  let scale2 = 1;
@@ -9442,7 +10369,7 @@ function iconFromSvg(markup, spec) {
9442
10369
  if (typeof spec.size !== "number" || !(spec.size > 0) || !Number.isFinite(spec.size)) fail(`size must be more than 0, got ${String(spec.size)}`);
9443
10370
  scale2 = spec.size / box.width;
9444
10371
  }
9445
- root = { fill: "#000000", stroke: "none", width: 1, linecap: void 0, linejoin: void 0, transform: matrix.scale(scale2) };
10372
+ root = { fill: "#000000", stroke: "none", width: 1, linecap: void 0, linejoin: void 0, fillRule: "nonzero", opacity: 1, transform: matrix.scale(scale2) };
9446
10373
  }
9447
10374
  const parent = stack.length > 0 ? stack[stack.length - 1].state : first ? root : void 0;
9448
10375
  const state = parent && !hidden(attributes) ? inherit(parent, attributes) : void 0;
@@ -9513,6 +10440,10 @@ function pixels(value) {
9513
10440
  const number2 = match ? Number(match[1]) : NaN;
9514
10441
  return number2 > 0 && Number.isFinite(number2) ? number2 : void 0;
9515
10442
  }
10443
+ function alpha(value) {
10444
+ const match = /^\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)(%?)\s*$/i.exec(value ?? "");
10445
+ return match ? Math.min(1, Math.max(0, Number(match[1]) / (match[2] ? 100 : 1))) : 1;
10446
+ }
9516
10447
  function hidden(attributes) {
9517
10448
  return attributes.get("display")?.trim() === "none" || attributes.get("visibility")?.trim() === "hidden";
9518
10449
  }
@@ -9526,6 +10457,7 @@ function inherit(parent, attributes) {
9526
10457
  const width = Number.parseFloat(attributes.get("stroke-width") ?? "");
9527
10458
  const linecap = attributes.get("stroke-linecap")?.trim();
9528
10459
  const linejoin = attributes.get("stroke-linejoin")?.trim();
10460
+ const fillRule = attributes.get("fill-rule")?.trim().toLowerCase();
9529
10461
  const transform = attributes.get("transform");
9530
10462
  return {
9531
10463
  fill: paint("fill", parent.fill),
@@ -9533,26 +10465,31 @@ function inherit(parent, attributes) {
9533
10465
  width: width >= 0 ? width : parent.width,
9534
10466
  linecap: linecap === "butt" || linecap === "round" ? linecap : parent.linecap,
9535
10467
  linejoin: linejoin === "miter" || linejoin === "round" ? linejoin : parent.linejoin,
10468
+ fillRule: fillRule === "nonzero" || fillRule === "evenodd" ? fillRule : parent.fillRule,
10469
+ // Opacity isn't inherited in SVG: a group is drawn and then faded. Multiplying is the same unless its shapes overlap.
10470
+ opacity: parent.opacity * alpha(attributes.get("opacity")),
9536
10471
  transform: transform ? matrix.multiply(parent.transform, parseTransform(transform)) : parent.transform
9537
10472
  };
9538
10473
  }
9539
10474
  function toShape(tag, attributes, state) {
9540
10475
  const fill = state.fill === "none" ? void 0 : state.fill;
9541
10476
  const stroke2 = state.stroke === "none" || !(state.width > 0) ? void 0 : state.stroke;
9542
- if (fill === void 0 && stroke2 === void 0) return void 0;
10477
+ const opacity = round4(state.opacity);
10478
+ if (fill === void 0 && stroke2 === void 0 || !(opacity > 0)) return void 0;
9543
10479
  const commands = outline(tag, attributes);
9544
10480
  if (!commands.some((command) => command.op !== "M")) return void 0;
9545
10481
  const m = state.transform;
9546
10482
  return {
9547
10483
  d: formatPath(transformPath(commands, m)),
9548
- ...fill !== void 0 ? { fill } : {},
10484
+ ...fill !== void 0 ? { fill, ...state.fillRule === "evenodd" ? { fillRule: state.fillRule } : {} } : {},
9549
10485
  ...stroke2 !== void 0 ? {
9550
10486
  stroke: stroke2,
9551
10487
  // A stroke scales with the transform; for an uneven scale this is the average.
9552
10488
  width: round4(state.width * Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]))),
9553
10489
  ...state.linecap ? { linecap: state.linecap } : {},
9554
10490
  ...state.linejoin ? { linejoin: state.linejoin } : {}
9555
- } : {}
10491
+ } : {},
10492
+ ...opacity < 1 ? { opacity } : {}
9556
10493
  };
9557
10494
  }
9558
10495
  function outline(tag, attributes) {
@@ -9691,7 +10628,7 @@ function configure(options) {
9691
10628
  }
9692
10629
 
9693
10630
  // src/index.ts
9694
- var VERSION = "0.1.0";
10631
+ var VERSION = "0.3.0";
9695
10632
  var env = { presets: presetRegistry, icons: iconRegistry, motion };
9696
10633
  function barChart2(target, options) {
9697
10634
  return barChart(target, options, env);
@@ -9730,6 +10667,7 @@ function motionSwitch2(target, motion2 = motion, options) {
9730
10667
  defineDataEffect,
9731
10668
  defineEffect,
9732
10669
  defineIcon,
10670
+ delta,
9733
10671
  describe,
9734
10672
  donutChart,
9735
10673
  easeInOutCubic,
@@ -9743,8 +10681,10 @@ function motionSwitch2(target, motion2 = motion, options) {
9743
10681
  interpolateNumber,
9744
10682
  interpolatePoint,
9745
10683
  interpolateRecord,
10684
+ label,
9746
10685
  lineChart,
9747
10686
  linear,
10687
+ link,
9748
10688
  manualClock,
9749
10689
  matrix,
9750
10690
  mediaReducedMotion,
@@ -9765,6 +10705,7 @@ function motionSwitch2(target, motion2 = motion, options) {
9765
10705
  sequence,
9766
10706
  stagger,
9767
10707
  threshold,
10708
+ trace,
9768
10709
  travel,
9769
10710
  tween,
9770
10711
  wiggle