expressive-charts 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +8 -8
  3. package/dist/{chunk-N5IF2RO2.js → chunk-7A7LXXT4.js} +6 -2
  4. package/dist/chunk-7A7LXXT4.js.map +1 -0
  5. package/dist/{chunk-V5IUTXRW.js → chunk-CJUQHEX6.js} +70 -23
  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-DWZIXIeR.d.cts → drawing-CdTgixMY.d.cts} +14 -2
  10. package/dist/{drawing-DWZIXIeR.d.ts → drawing-CdTgixMY.d.ts} +14 -2
  11. package/dist/{effect-CcGdU41j.d.cts → effect-Bu3MHHeg.d.ts} +4 -2
  12. package/dist/{effect-CZUckY0l.d.ts → effect-D4vmdYP4.d.cts} +4 -2
  13. package/dist/expressive-charts.css +6 -1
  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 +51 -46
  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 +839 -358
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +43 -15
  24. package/dist/index.d.ts +43 -15
  25. package/dist/index.js +700 -282
  26. package/dist/index.js.map +1 -1
  27. package/dist/testing.cjs +71 -37
  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-V5IUTXRW.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defineIcon
3
- } from "./chunk-N5IF2RO2.js";
3
+ } from "./chunk-7A7LXXT4.js";
4
4
  import {
5
5
  EFFECT_SLOTS,
6
6
  animated,
@@ -30,7 +30,7 @@ import {
30
30
  scaleDuration,
31
31
  tween,
32
32
  unease
33
- } from "./chunk-CVXP2L2J.js";
33
+ } from "./chunk-N2BLUETM.js";
34
34
  import {
35
35
  describe,
36
36
  formatNumber,
@@ -40,7 +40,7 @@ import {
40
40
  offset,
41
41
  parseTransform,
42
42
  samplesAlong
43
- } from "./chunk-V5IUTXRW.js";
43
+ } from "./chunk-CJUQHEX6.js";
44
44
 
45
45
  // src/charts/announce.ts
46
46
  var SORTED = {
@@ -51,16 +51,16 @@ var SORTED = {
51
51
  };
52
52
  var NAMED = 3;
53
53
  function changeText(facts) {
54
- const parts = [];
54
+ const parts2 = [];
55
55
  const { series } = facts;
56
- if (facts.label !== void 0) parts.push(facts.label);
57
- else if (series && !(series.length === 1 && series[0] === "value")) parts.push(`Showing ${list(series)}`);
58
- if (facts.sort) parts.push(SORTED[facts.sort]);
56
+ if (facts.label !== void 0) parts2.push(facts.label);
57
+ else if (series && !(series.length === 1 && series[0] === "value")) parts2.push(`Showing ${list(series)}`);
58
+ if (facts.sort) parts2.push(SORTED[facts.sort]);
59
59
  const { changed, added, removed } = facts;
60
- if (!series && changed.length > 0) parts.push(changed.length <= NAMED ? `${list(changed)} changed` : `${changed.length} of ${facts.count} changed`);
61
- if (added.length > 0) parts.push(`Added ${added.length <= NAMED ? list(added) : added.length}`);
62
- if (removed.length > 0) parts.push(`Removed ${removed.length <= NAMED ? list(removed) : removed.length}`);
63
- return parts.join(". ");
60
+ if (!series && changed.length > 0) parts2.push(changed.length <= NAMED ? `${list(changed)} changed` : `${changed.length} of ${facts.count} changed`);
61
+ if (added.length > 0) parts2.push(`Added ${added.length <= NAMED ? list(added) : added.length}`);
62
+ if (removed.length > 0) parts2.push(`Removed ${removed.length <= NAMED ? list(removed) : removed.length}`);
63
+ return parts2.join(". ");
64
64
  }
65
65
  function list(names) {
66
66
  if (names.length <= 1) return names.join("");
@@ -169,6 +169,7 @@ var TICK_SIZE = 11;
169
169
  var AXIS = 26;
170
170
  var TOP = 4;
171
171
  var PAD = 6;
172
+ var BOTH = { label: true, value: true };
172
173
  var CENTRE = 0.36;
173
174
  function barEncoding(options) {
174
175
  const { x, y, stack, data } = options;
@@ -218,13 +219,62 @@ function layoutBars(input) {
218
219
  const texts = rows2.map((row) => input.format(row.total));
219
220
  const ticks = domain.ticks.map(input.format);
220
221
  const frame = (input.encoding.orientation === "horizontal" ? horizontalFrame : verticalFrame)(input, rows2, domain, texts, ticks);
222
+ const labels = thinLabels(frame, rows2, texts, input.measure);
221
223
  return {
222
224
  width: frame.bands.width,
223
225
  height: frame.bands.height,
224
226
  orientation: frame.orientation,
225
227
  frame,
226
- rows: rows2.map((row, slot) => placeRow(frame, { ...row, slot, text: texts[slot] }, input.measure)),
227
- ticks: domain.ticks.map((value, i) => placeTick(frame, value, ticks[i]))
228
+ rows: rows2.map((row, slot) => placeRow(frame, { ...row, slot, text: texts[slot], drawn: { label: slot % labels.every === 0, value: labels.values } }, input.measure)),
229
+ ticks: domain.ticks.map((value, i) => placeTick(frame, value, ticks[i])),
230
+ labels
231
+ };
232
+ }
233
+ function thinLabels(frame, rows2, texts, measure) {
234
+ const placed2 = rows2.map((row, slot) => placeLabels(frame, slot, row.total, row.category, texts[slot]));
235
+ const horizontal = frame.orientation === "horizontal";
236
+ const values = !overlaps(boxesOf(placed2.map(({ value }) => value), measure, "ec-value", VALUE_SIZE), horizontal);
237
+ const categories = (every) => boxesOf(
238
+ placed2.filter((_, slot) => slot % every === 0).map(({ label: label2 }) => label2),
239
+ measure,
240
+ "ec-label",
241
+ LABEL_SIZE
242
+ );
243
+ let k = 0;
244
+ while (thinStep(k) < rows2.length && overlaps(categories(thinStep(k)), horizontal)) k++;
245
+ return { every: thinStep(k), values };
246
+ }
247
+ var thinStep = (k) => [1, 2, 5][k % 3] * 10 ** Math.floor(k / 3);
248
+ function boxesOf(labels, measure, className, size) {
249
+ return labels.filter((label2) => label2.text !== "").map((label2) => textBox(label2, measure, className, size));
250
+ }
251
+ function overlaps(boxes, horizontal) {
252
+ const along = horizontal ? boxes.map(({ x, y, width, height }) => ({ x: y, y: x, width: height, height: width })) : [...boxes];
253
+ along.sort((a, b) => a.x - b.x);
254
+ const open = [];
255
+ for (const box of along) {
256
+ for (let i = open.length - 1; i >= 0; i--) if (open[i].x + open[i].width <= box.x) open.splice(i, 1);
257
+ if (open.some((other) => other.y < box.y + box.height && box.y < other.y + other.height)) return true;
258
+ open.push(box);
259
+ }
260
+ return false;
261
+ }
262
+ function placeLabels(frame, slot, total2, category, text2) {
263
+ const { scale, bands } = frame;
264
+ const negative = total2 < 0;
265
+ const tip = position(scale)(total2);
266
+ const band = bands.start + slot * bands.band;
267
+ if (frame.orientation === "horizontal") {
268
+ const line = band + bands.band / 2 + LABEL_SIZE * CENTRE;
269
+ return {
270
+ label: { x: scale.label, y: line, anchor: "end", text: category },
271
+ value: { x: negative ? tip - PAD : tip + PAD, y: line, anchor: negative ? "end" : "start", text: text2 }
272
+ };
273
+ }
274
+ const centre = band + bands.band / 2;
275
+ return {
276
+ label: { x: centre, y: scale.label, anchor: "middle", text: category },
277
+ value: { x: centre, y: negative ? tip + PAD + VALUE_SIZE * 0.8 : tip - PAD, anchor: "middle", text: text2 }
228
278
  };
229
279
  }
230
280
  function placeRow(frame, row, measure) {
@@ -243,17 +293,11 @@ function placeRow(frame, row, measure) {
243
293
  gap: GAP,
244
294
  segments: row.values.map((v) => ({ series: v.series, size: Math.max(0, negative ? -v.value : v.value) * unit }))
245
295
  };
246
- const fields = { key: row.key, datum: row.datum, index: row.index, slot: row.slot, values: row.values, total: total2 };
247
- const boxes = (label3, value2) => {
248
- const out = [];
249
- if (label3.text !== "") out.push(textBox(label3, measure, "ec-label", LABEL_SIZE));
250
- if (value2.text !== "") out.push(textBox(value2, measure, "ec-value", VALUE_SIZE));
251
- return out;
252
- };
296
+ const drawn2 = row.drawn ?? BOTH;
297
+ const fields = { key: row.key, datum: row.datum, index: row.index, slot: row.slot, values: row.values, total: total2, category: row.category, drawn: drawn2 };
298
+ const { label: label2, value } = placeLabels(frame, row.slot, total2, drawn2.label ? row.category : "", drawn2.value ? row.text : "");
299
+ const boxes = () => [...boxesOf([label2], measure, "ec-label", LABEL_SIZE), ...boxesOf([value], measure, "ec-value", VALUE_SIZE)];
253
300
  if (frame.orientation === "horizontal") {
254
- const line = band + bands.band / 2 + LABEL_SIZE * CENTRE;
255
- const label3 = { x: scale.label, y: line, anchor: "end", text: row.category };
256
- const value2 = { x: negative ? tip - PAD : tip + PAD, y: line, anchor: negative ? "end" : "start", text: row.text };
257
301
  const geometry2 = describe.bar({
258
302
  ...bar,
259
303
  x: Math.min(zero, tip),
@@ -261,20 +305,18 @@ function placeRow(frame, row, measure) {
261
305
  width: Math.abs(tip - zero),
262
306
  height: bands.thickness,
263
307
  baseline: negative ? "right" : "left",
264
- labelBounds: boxes(label3, value2)
308
+ labelBounds: boxes()
265
309
  });
266
310
  return {
267
311
  ...fields,
268
312
  geometry: geometry2,
269
313
  data: barData(row.datum, total2, geometry2),
270
- label: label3,
271
- value: value2,
314
+ label: label2,
315
+ value,
272
316
  hit: { x: 0, y: band, width: bands.width, height: bands.band }
273
317
  };
274
318
  }
275
319
  const centre = band + bands.band / 2;
276
- const label2 = { x: centre, y: scale.label, anchor: "middle", text: row.category };
277
- const value = { x: centre, y: negative ? tip + PAD + VALUE_SIZE * 0.8 : tip - PAD, anchor: "middle", text: row.text };
278
320
  const geometry = describe.bar({
279
321
  ...bar,
280
322
  x: centre - bands.thickness / 2,
@@ -282,7 +324,7 @@ function placeRow(frame, row, measure) {
282
324
  width: bands.thickness,
283
325
  height: Math.abs(tip - zero),
284
326
  baseline: negative ? "top" : "bottom",
285
- labelBounds: boxes(label2, value)
327
+ labelBounds: boxes()
286
328
  });
287
329
  return {
288
330
  ...fields,
@@ -342,9 +384,9 @@ function niceDomain(values) {
342
384
  const ticks = Array.from({ length: count + 1 }, (_, i) => clean(lo + i * step2));
343
385
  return { lo, hi, ticks };
344
386
  }
345
- function niceStep(span) {
346
- const power = 10 ** Math.floor(Math.log10(span));
347
- const f = span / power;
387
+ function niceStep(span2) {
388
+ const power = 10 ** Math.floor(Math.log10(span2));
389
+ const f = span2 / power;
348
390
  return (f <= 1 ? 1 : f <= 2 ? 2 : f <= 5 ? 5 : 10) * power;
349
391
  }
350
392
  function horizontalFrame(input, rows2, domain, values, ticks) {
@@ -353,9 +395,10 @@ function horizontalFrame(input, rows2, domain, values, ticks) {
353
395
  const labelWidth = widest(rows2.map((row) => row.category), "ec-label", LABEL_SIZE, measure);
354
396
  const valueWidth = widest(values, "ec-value", VALUE_SIZE, measure);
355
397
  const tickWidth = widest(ticks, "ec-tick", TICK_SIZE, measure);
398
+ const { positive, negative } = reach(input, rows2);
356
399
  const negativeRoom = domain.lo < 0 ? valueWidth + PAD : 0;
357
- const left = Math.max(labelWidth + 10 + negativeRoom, tickWidth / 2 + 2);
358
- const right = Math.max(valueWidth + PAD + 4, tickWidth / 2 + 2);
400
+ const left = Math.max(labelWidth + 10 + negativeRoom + negative, tickWidth / 2 + 2);
401
+ const right = Math.max(valueWidth + PAD + 4 + positive, tickWidth / 2 + 2);
359
402
  const rowSize = input.height === void 0 || n === 0 ? ROW : Math.max(0, input.height - TOP - AXIS) / n;
360
403
  return {
361
404
  orientation: "horizontal",
@@ -368,8 +411,9 @@ function verticalFrame(input, rows2, domain, _values, ticks) {
368
411
  const n = rows2.length;
369
412
  const height = input.height ?? VERTICAL_HEIGHT;
370
413
  const tickWidth = widest(ticks, "ec-tick", TICK_SIZE, measure);
371
- const top = domain.hi > 0 ? VALUE_SIZE + PAD + 2 : TOP;
372
- const bottom = AXIS + (domain.lo < 0 ? VALUE_SIZE + PAD : 0);
414
+ const { positive, negative } = reach(input, rows2);
415
+ const top = (domain.hi > 0 ? VALUE_SIZE + PAD + 2 : TOP) + positive;
416
+ const bottom = AXIS + (domain.lo < 0 ? VALUE_SIZE + PAD : 0) + negative;
373
417
  const left = tickWidth + 8 + 2;
374
418
  const plot = { x: left, y: top, width: Math.max(0, width - left - 8), height: Math.max(0, height - top - bottom) };
375
419
  const band = n > 0 ? plot.width / n : 0;
@@ -380,6 +424,13 @@ function verticalFrame(input, rows2, domain, _values, ticks) {
380
424
  bands: { start: plot.x, band, thickness: Math.min(band * BAR / ROW, MAX_COLUMN), span: plot.width, width, height }
381
425
  };
382
426
  }
427
+ function reach(input, rows2) {
428
+ const room = input.room ?? 0;
429
+ return {
430
+ positive: rows2.some((row) => row.total > 0) ? room : 0,
431
+ negative: rows2.some((row) => row.total < 0) ? room : 0
432
+ };
433
+ }
383
434
  function barData(datum, total2, geometry) {
384
435
  const valueAt = (distance3) => geometry.length > 0 ? total2 * distance3 / geometry.length : 0;
385
436
  const data = {
@@ -526,6 +577,7 @@ ${TOKEN_RULES}
526
577
  :where(.ec-chart .ec-tick) { fill: var(--ec-text-muted, ${TOKENS["text-muted"]}); font-size: 11px; }
527
578
  :where(.ec-chart .ec-label) { fill: var(--ec-text, ${TOKENS.text}); font-size: 12.5px; }
528
579
  :where(.ec-chart .ec-value, .ec-chart .ec-text) { fill: var(--ec-text, ${TOKENS.text}); font-size: 12.5px; font-weight: 600; }
580
+ :where(.ec-overlay .ec-text) { fill: var(--ec-text, ${TOKENS.text}); font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
529
581
  :where(.ec-chart .ec-hit) { fill: transparent; }
530
582
  :where(.ec-chart .ec-mark:focus) { outline: none; }
531
583
  :where(.ec-chart .ec-focus) { pointer-events: none; }
@@ -539,6 +591,7 @@ ${TOKEN_RULES}
539
591
  :where(.ec-chart .ec-end) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; }
540
592
  :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; }
541
593
  :where(.ec-chart .ec-hot .ec-dot) { fill: var(--ec-mark-strong); opacity: 1; }
594
+ :where(.ec-chart .ec-alone .ec-dot) { opacity: 1; }
542
595
  :where(.ec-chart .ec-crosshair) { stroke: var(--ec-axis, ${TOKENS.axis}); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
543
596
  :where(.ec-chart .ec-column:focus) { outline: none; }
544
597
  :where(.ec-chart .ec-lines, .ec-chart .ec-points) { pointer-events: none; }
@@ -573,7 +626,10 @@ ${TOKEN_RULES}
573
626
  :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; }
574
627
  :where(.ec-tooltip-layer) { position: relative; height: 0; }
575
628
  :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); }
576
- :where(.ec-tooltip.ec-tooltip-shown) { opacity: 1; visibility: visible; transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
629
+ :where(.ec-tooltip.ec-tooltip-shown) { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
630
+ :where(.ec-tooltip-bridge) { position: absolute; left: 0; top: 0; z-index: 3; pointer-events: none; }
631
+ :where(.ec-tooltip-shown + .ec-tooltip-bridge) { pointer-events: auto; }
632
+ :where(.ec-tooltip-through > .ec-tooltip, .ec-tooltip-through > .ec-tooltip-bridge) { pointer-events: none; }
577
633
  :where(.ec-tooltip-title) { font-weight: 600; }
578
634
  :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}); }
579
635
  :where(.ec-legend-item) { display: inline-flex; align-items: center; gap: 6px; }
@@ -647,11 +703,11 @@ function checkLegendOption(option, chart) {
647
703
  var extras = (option) => typeof option === "object" ? option.entries ?? [] : [];
648
704
  function chartLegend(svg) {
649
705
  let legend;
650
- let drawn = "";
706
+ let drawn2 = "";
651
707
  const remove = () => {
652
708
  legend?.remove();
653
709
  legend = void 0;
654
- drawn = "";
710
+ drawn2 = "";
655
711
  };
656
712
  const draw = (entries, colors, attribute, more) => {
657
713
  const items = [
@@ -662,8 +718,8 @@ function chartLegend(svg) {
662
718
  legend ?? (legend = Object.assign(doc.createElement("div"), { className: "ec-legend" }));
663
719
  if (legend.nextSibling !== svg) svg.before(legend);
664
720
  const id = JSON.stringify([attribute, items]);
665
- if (id === drawn) return;
666
- drawn = id;
721
+ if (id === drawn2) return;
722
+ drawn2 = id;
667
723
  legend.replaceChildren(
668
724
  ...items.map(({ key, label: text2, styles }) => {
669
725
  const item = doc.createElement("span");
@@ -849,8 +905,8 @@ function maskedHalo() {
849
905
  group = void 0;
850
906
  };
851
907
  return {
852
- paint(container, parts, halo, transform) {
853
- if (!halo || !container || parts.length === 0) {
908
+ paint(container, parts2, halo, transform) {
909
+ if (!halo || !container || parts2.length === 0) {
854
910
  remove();
855
911
  return;
856
912
  }
@@ -862,12 +918,12 @@ function maskedHalo() {
862
918
  const id = `ec-halo-mask-${++haloMasks}`;
863
919
  const mask = svgElement("mask", { id, maskUnits: "userSpaceOnUse", x: -1e5, y: -1e5, width: 2e5, height: 2e5 }, group);
864
920
  svgElement("rect", { x: -1e5, y: -1e5, width: 2e5, height: 2e5, fill: "white" }, mask);
865
- for (const part of parts) {
921
+ for (const part of parts2) {
866
922
  const cut = part.stroke === void 0 ? { fill: "black" } : { fill: "none", stroke: "black", "stroke-width": part.stroke, "stroke-linejoin": "round" };
867
923
  svgElement("path", { d: part.d, ...cut }, mask);
868
924
  }
869
925
  setAttributes(group, { transform: transform && transformAttribute(transform) });
870
- for (const part of parts) {
926
+ for (const part of parts2) {
871
927
  const open = part.stroke !== void 0;
872
928
  const path = svgElement(
873
929
  "path",
@@ -889,24 +945,24 @@ function svgMarkHandle(target, options = {}) {
889
945
  const repaint = () => {
890
946
  const current = target();
891
947
  if (!current) return;
892
- const { body, parts } = current;
948
+ const { body, parts: parts2 } = current;
893
949
  setAttributes(body, {
894
950
  transform: style.transform && transformAttribute(style.transform),
895
951
  opacity: style.opacity
896
952
  });
897
953
  const emphasis = style.emphasis;
898
- for (const part of parts) {
954
+ for (const part of parts2) {
899
955
  setStyles(part.element, {
900
956
  [part.open ? "stroke" : "fill"]: emphasis === void 0 ? void 0 : mix(part.colors, emphasis),
901
957
  transition: emphasis === void 0 ? void 0 : "none"
902
958
  });
903
959
  }
904
- paintHalo(body, parts);
960
+ paintHalo(body, parts2);
905
961
  };
906
- const paintHalo = (body, parts) => {
962
+ const paintHalo = (body, parts2) => {
907
963
  const spec = style.halo;
908
964
  if (above) {
909
- const visible2 = parts.flatMap((part) => part.visible ? [{ d: part.d, color: part.colors.color, ...part.open ? { stroke: part.open.width } : {} }] : []);
965
+ const visible2 = parts2.flatMap((part) => part.visible ? [{ d: part.d, color: part.colors.color, ...part.open ? { stroke: part.open.width } : {} }] : []);
910
966
  above.paint(options.halos?.(), visible2, spec, style.transform);
911
967
  return;
912
968
  }
@@ -920,7 +976,7 @@ function svgMarkHandle(target, options = {}) {
920
976
  halo = svgElement("g", { class: "ec-halo" }, body);
921
977
  body.insertBefore(halo, body.firstChild);
922
978
  }
923
- const visible = parts.filter((part) => part.visible);
979
+ const visible = parts2.filter((part) => part.visible);
924
980
  while (halo.childElementCount > visible.length) halo.lastElementChild?.remove();
925
981
  visible.forEach((part, index) => {
926
982
  const path = halo.children[index] ?? svgElement("path", { "stroke-linejoin": "round" }, halo);
@@ -1021,7 +1077,9 @@ function drawShape(shape, parent) {
1021
1077
  "clip-path": clip && `url(#${clip})`,
1022
1078
  "stroke-width": shape.stroke === void 0 ? void 0 : shape.width ?? 1,
1023
1079
  "stroke-linecap": shape.linecap,
1024
- "stroke-linejoin": shape.linejoin
1080
+ "stroke-linejoin": shape.linejoin,
1081
+ "fill-rule": shape.fillRule,
1082
+ opacity: shape.opacity
1025
1083
  },
1026
1084
  parent
1027
1085
  );
@@ -1161,6 +1219,9 @@ function pointerHover(svg, options) {
1161
1219
  const doc = svg.ownerDocument;
1162
1220
  let current;
1163
1221
  let lastPointer = "mouse";
1222
+ let held;
1223
+ let watcher;
1224
+ let still;
1164
1225
  const enter = (target, source) => {
1165
1226
  if (target?.key === current) return;
1166
1227
  leave2();
@@ -1169,15 +1230,91 @@ function pointerHover(svg, options) {
1169
1230
  options.hover(target, source);
1170
1231
  };
1171
1232
  const leave2 = () => {
1233
+ letGo();
1172
1234
  if (current === void 0) return;
1173
1235
  current = void 0;
1174
1236
  options.leave();
1175
1237
  };
1238
+ const tooltipHolding = (node) => {
1239
+ const tip = options.tooltip?.();
1240
+ return tip?.element && node && tip.element.contains(node) ? tip : void 0;
1241
+ };
1242
+ const elementAt = (x, y) => {
1243
+ const root = svg.getRootNode();
1244
+ return typeof root.elementFromPoint === "function" ? root.elementFromPoint(x, y) : void 0;
1245
+ };
1246
+ const landing = (event) => event.relatedTarget ?? elementAt(event.clientX, event.clientY) ?? null;
1247
+ const arrive = (element, x, y) => {
1248
+ const tip = tooltipHolding(element);
1249
+ if (tip) hold(tip, x, y);
1250
+ else enter(element && svg.contains(element) ? options.find(element) : void 0, "pointer");
1251
+ };
1252
+ const hold = (tip, x, y) => {
1253
+ enter({ key: tip.key }, "pointer");
1254
+ const element = tip.element;
1255
+ if (held?.element === element) {
1256
+ held.x = x;
1257
+ held.y = y;
1258
+ return;
1259
+ }
1260
+ letGo();
1261
+ held = { element, x, y };
1262
+ element.addEventListener("pointermove", track);
1263
+ element.addEventListener("pointerleave", off);
1264
+ watcher = new MutationObserver(recheck);
1265
+ watcher.observe(element, { attributes: true, childList: true, characterData: true, subtree: true });
1266
+ };
1267
+ const letGo = () => {
1268
+ if (!held) return;
1269
+ held.element.removeEventListener("pointermove", track);
1270
+ held.element.removeEventListener("pointerleave", off);
1271
+ watcher?.disconnect();
1272
+ watcher = void 0;
1273
+ held = void 0;
1274
+ };
1275
+ const track = (event) => {
1276
+ if (!held || event.pointerType === "touch") return;
1277
+ held.x = event.clientX;
1278
+ held.y = event.clientY;
1279
+ };
1280
+ const off = (event) => {
1281
+ if (event.pointerType === "touch") return;
1282
+ letGo();
1283
+ arrive(landing(event), event.clientX, event.clientY);
1284
+ };
1285
+ const recheck = () => {
1286
+ if (!held) return;
1287
+ const { x, y } = held;
1288
+ const under = elementAt(x, y);
1289
+ if (under === void 0) return;
1290
+ const tip = options.tooltip?.();
1291
+ const onTip = tip?.element !== void 0 && under !== null && tip.element.contains(under);
1292
+ if (onTip && tip.key === current) return;
1293
+ letGo();
1294
+ if (!onTip && tip?.key !== current) {
1295
+ still = { x, y };
1296
+ leave2();
1297
+ return;
1298
+ }
1299
+ arrive(under, x, y);
1300
+ };
1301
+ const resting = (event) => {
1302
+ if (still && Math.abs(event.clientX - still.x) < 1 && Math.abs(event.clientY - still.y) < 1) return true;
1303
+ still = void 0;
1304
+ return false;
1305
+ };
1176
1306
  const over = (event) => {
1177
- if (event.pointerType !== "touch") enter(options.find(event.target), "pointer");
1307
+ if (event.pointerType === "touch" || resting(event)) return;
1308
+ letGo();
1309
+ enter(options.find(event.target), "pointer");
1178
1310
  };
1179
1311
  const out = (event) => {
1180
- if (event.pointerType !== "touch") leave2();
1312
+ if (event.pointerType === "touch") return;
1313
+ still = void 0;
1314
+ arrive(landing(event), event.clientX, event.clientY);
1315
+ };
1316
+ const move = (event) => {
1317
+ if (event.pointerType !== "touch") resting(event);
1181
1318
  };
1182
1319
  const down = (event) => {
1183
1320
  lastPointer = event.pointerType;
@@ -1186,10 +1323,13 @@ function pointerHover(svg, options) {
1186
1323
  if (lastPointer === "touch") enter(options.find(event.target), "touch");
1187
1324
  };
1188
1325
  const elsewhere = (event) => {
1189
- if (current !== void 0 && event.pointerType === "touch" && !svg.contains(event.target)) leave2();
1326
+ if (current === void 0 || event.pointerType !== "touch") return;
1327
+ const target = event.composedPath()[0] ?? event.target;
1328
+ if (!svg.contains(target) && !tooltipHolding(target)) leave2();
1190
1329
  };
1191
1330
  svg.addEventListener("pointerover", over);
1192
1331
  svg.addEventListener("pointerleave", out);
1332
+ svg.addEventListener("pointermove", move);
1193
1333
  svg.addEventListener("pointerdown", down);
1194
1334
  svg.addEventListener("click", click);
1195
1335
  doc.addEventListener("pointerdown", elsewhere, true);
@@ -1197,11 +1337,16 @@ function pointerHover(svg, options) {
1197
1337
  get current() {
1198
1338
  return current;
1199
1339
  },
1200
- clear: leave2,
1340
+ clear() {
1341
+ if (held) still = { x: held.x, y: held.y };
1342
+ leave2();
1343
+ },
1201
1344
  destroy() {
1345
+ letGo();
1202
1346
  current = void 0;
1203
1347
  svg.removeEventListener("pointerover", over);
1204
1348
  svg.removeEventListener("pointerleave", out);
1349
+ svg.removeEventListener("pointermove", move);
1205
1350
  svg.removeEventListener("pointerdown", down);
1206
1351
  svg.removeEventListener("click", click);
1207
1352
  doc.removeEventListener("pointerdown", elsewhere, true);
@@ -1289,6 +1434,13 @@ function keyboardFocus(svg, options) {
1289
1434
  case "ArrowLeft":
1290
1435
  next = keys[Math.max(0, index - 1)];
1291
1436
  break;
1437
+ case "PageDown":
1438
+ case "PageUp": {
1439
+ const by = event.key === "PageDown" ? 1 : -1;
1440
+ const paged = options.page?.(key, by);
1441
+ next = paged !== void 0 && keys.includes(paged) ? paged : keys[Math.min(keys.length - 1, Math.max(0, index + by * Math.ceil(keys.length / 10)))];
1442
+ break;
1443
+ }
1292
1444
  case "Home":
1293
1445
  next = keys[0];
1294
1446
  break;
@@ -1449,11 +1601,14 @@ function chartHover(options) {
1449
1601
  },
1450
1602
  leave() {
1451
1603
  if (hovered?.source === "pointer" || hovered?.source === "touch") endHover();
1452
- }
1604
+ },
1605
+ // The pointer can move onto the tooltip of the chart's own hover. A link's has none.
1606
+ tooltip: () => own(hovered) ? { key: hovered.keys[0], element: options.tooltip.element?.() } : void 0
1453
1607
  });
1454
1608
  const keyboard = keyboardFocus(() => svg, {
1455
1609
  find: (eventTarget) => options.find(eventTarget)?.key,
1456
1610
  order: options.order,
1611
+ page: (key, by) => options.page?.(key, by),
1457
1612
  element: options.element,
1458
1613
  focus(key, visible) {
1459
1614
  ringKey = visible ? key : void 0;
@@ -1629,9 +1784,9 @@ function checkTableOption(option, chart) {
1629
1784
  throw new TypeError(`${chart}: ${what}`);
1630
1785
  };
1631
1786
  if (typeof option !== "object" || option === null) fail('table must be true, false, "hidden" or an object of table options.');
1632
- const { hidden: hidden2, columns, category, total: total2, share, summary, series } = option;
1787
+ const { hidden: hidden2, columns, category, total: total2, share, summary: summary2, series } = option;
1633
1788
  if (hidden2 !== void 0 && typeof hidden2 !== "boolean") fail("table.hidden must be true or false.");
1634
- for (const [name, text2] of Object.entries({ category, total: total2, share, summary })) {
1789
+ for (const [name, text2] of Object.entries({ category, total: total2, share, summary: summary2 })) {
1635
1790
  if (text2 !== void 0 && typeof text2 !== "string") fail(`table.${name} must be a string.`);
1636
1791
  }
1637
1792
  if (series !== void 0) {
@@ -1650,6 +1805,7 @@ function checkTableOption(option, chart) {
1650
1805
  if (column.after !== void 0 && column.after !== "category" && column.after !== "values") fail(`table.columns[${i}].after must be "category" or "values".`);
1651
1806
  });
1652
1807
  }
1808
+ var MISSING = "missing";
1653
1809
  function tableModel(input) {
1654
1810
  const { option, format: format2 } = input;
1655
1811
  if (option === false) return void 0;
@@ -1679,7 +1835,7 @@ function tableModel(input) {
1679
1835
  cells: [
1680
1836
  { text: row.category, numeric: false },
1681
1837
  ...first.map((column) => columnCell(column, row, format2)),
1682
- ...input.series.map((series) => number2(values.get(series) ?? 0)),
1838
+ ...input.series.map((series) => row.missing?.has(series) ? { text: MISSING, numeric: true } : number2(values.get(series) ?? 0)),
1683
1839
  ...totals ? [number2(row.total)] : [],
1684
1840
  ...share(row.total),
1685
1841
  ...last.map((column) => columnCell(column, row, format2))
@@ -1720,14 +1876,14 @@ function columnCell(column, row, format2) {
1720
1876
  function chartTable(svg) {
1721
1877
  const doc = svg.ownerDocument;
1722
1878
  let wrapper;
1723
- let summary;
1879
+ let summary2;
1724
1880
  let table;
1725
1881
  let caption2;
1726
1882
  let head;
1727
1883
  let body;
1728
1884
  let foot;
1729
1885
  const rows2 = /* @__PURE__ */ new Map();
1730
- let drawn = "";
1886
+ let drawn2 = "";
1731
1887
  const element = (tag, className) => {
1732
1888
  const made = doc.createElement(tag);
1733
1889
  if (className) made.className = className;
@@ -1749,19 +1905,19 @@ function chartTable(svg) {
1749
1905
  const next = hidden2 ? element("div", "ec-table ec-visually-hidden") : element("details", "ec-table");
1750
1906
  const content = table ?? build();
1751
1907
  if (hidden2) {
1752
- summary = void 0;
1908
+ summary2 = void 0;
1753
1909
  next.appendChild(content);
1754
1910
  } else {
1755
- summary = element("summary");
1911
+ summary2 = element("summary");
1756
1912
  const scroll = element("div", "ec-table-scroll");
1757
1913
  scroll.appendChild(content);
1758
- next.append(summary, scroll);
1914
+ next.append(summary2, scroll);
1759
1915
  }
1760
1916
  if (wrapper?.isConnected) wrapper.replaceWith(next);
1761
1917
  wrapper = next;
1762
1918
  }
1763
1919
  if (!wrapper.isConnected) svg.after(wrapper);
1764
- if (summary && summary.textContent !== text2) summary.textContent = text2;
1920
+ if (summary2 && summary2.textContent !== text2) summary2.textContent = text2;
1765
1921
  }
1766
1922
  function fill(cell, { text: text2, numeric: numeric3 }) {
1767
1923
  if (cell.textContent !== text2) cell.textContent = text2;
@@ -1769,9 +1925,9 @@ function chartTable(svg) {
1769
1925
  }
1770
1926
  function remove() {
1771
1927
  wrapper?.remove();
1772
- wrapper = summary = table = caption2 = head = body = foot = void 0;
1928
+ wrapper = summary2 = table = caption2 = head = body = foot = void 0;
1773
1929
  rows2.clear();
1774
- drawn = "";
1930
+ drawn2 = "";
1775
1931
  }
1776
1932
  return {
1777
1933
  render(model) {
@@ -1782,8 +1938,8 @@ function chartTable(svg) {
1782
1938
  place(model.hidden, model.summary);
1783
1939
  if (caption2.textContent !== model.caption) caption2.textContent = model.caption;
1784
1940
  const headers = JSON.stringify(model.headers);
1785
- if (headers !== drawn) {
1786
- drawn = headers;
1941
+ if (headers !== drawn2) {
1942
+ drawn2 = headers;
1787
1943
  head.replaceChildren(
1788
1944
  ...model.headers.map((header) => {
1789
1945
  const th = element("th");
@@ -1971,7 +2127,9 @@ function playUpdate(options, arrange, announce) {
1971
2127
  options.leaving.sweep();
1972
2128
  });
1973
2129
  events.emitEach("exit", diff.exiting, onScreen);
1974
- runner.update(diff.changed.map(({ record, from }) => ({ ...input(record), from })));
2130
+ if (options.data || diff.changed.length > 0 || diff.entering.length > 0 || diff.exiting.length > 0) {
2131
+ runner.update(diff.changed.map(({ record, from }) => ({ ...input(record), from })));
2132
+ }
1975
2133
  events.emitEach("update", diff.changed, ({ record, from }) => ({ ...input(record), from }));
1976
2134
  runner.enter(diff.entering.map(input));
1977
2135
  events.emitEach("enter", diff.entering, input);
@@ -2039,6 +2197,7 @@ function watchHoverDuration(svg, motion2) {
2039
2197
 
2040
2198
  // src/charts/tooltip.ts
2041
2199
  var GAP2 = 12;
2200
+ var OVERLAP = 1;
2042
2201
  var FADE = 100;
2043
2202
  var described = 0;
2044
2203
  function placeTooltip(anchor, size, box, side) {
@@ -2060,27 +2219,54 @@ function summaryContent(category, values, format2, options = {}) {
2060
2219
  function chartTooltip(svg, options) {
2061
2220
  let layer;
2062
2221
  let box;
2222
+ let bridge;
2063
2223
  let texts = /* @__PURE__ */ new WeakMap();
2064
2224
  let rendered;
2065
- const timing = (element2) => element2.style.setProperty("--ec-hover-duration", `${options.motion.duration(FADE, "feedback")}ms`);
2066
- function element() {
2067
- if (!layer || !box) {
2225
+ let pointer;
2226
+ let through = false;
2227
+ let shape;
2228
+ const timing = (element) => element.style.setProperty("--ec-hover-duration", `${options.motion.duration(FADE, "feedback")}ms`);
2229
+ const shown = () => box?.classList.contains("ec-tooltip-shown") ?? false;
2230
+ const under = () => {
2231
+ if (!pointer || !box || !layer) return false;
2232
+ const { x, y } = pointer;
2233
+ const { left, right, top, bottom } = box.getBoundingClientRect();
2234
+ if (x > left && x < right && y > top && y < bottom) return true;
2235
+ if (!shape) return false;
2236
+ const origin = layer.getBoundingClientRect();
2237
+ return inside(shape, x - origin.left, y - origin.top);
2238
+ };
2239
+ const letThrough = (on) => {
2240
+ through = on;
2241
+ layer?.classList.toggle("ec-tooltip-through", on);
2242
+ };
2243
+ const track = (event) => {
2244
+ pointer = event.pointerType === "touch" ? void 0 : { x: event.clientX, y: event.clientY };
2245
+ if (through && !under()) letThrough(false);
2246
+ };
2247
+ svg.ownerDocument.addEventListener("pointerover", track, true);
2248
+ svg.ownerDocument.addEventListener("pointermove", track, true);
2249
+ function made() {
2250
+ if (!layer || !box || !bridge) {
2068
2251
  const doc = svg.ownerDocument;
2069
2252
  layer = doc.createElement("div");
2070
2253
  layer.className = "ec-tooltip-layer";
2071
2254
  box = doc.createElement("div");
2072
2255
  box.className = "ec-tooltip";
2073
2256
  box.setAttribute("aria-hidden", "true");
2074
- layer.appendChild(box);
2257
+ bridge = doc.createElement("div");
2258
+ bridge.className = "ec-tooltip-bridge";
2259
+ bridge.setAttribute("aria-hidden", "true");
2260
+ layer.append(box, bridge);
2075
2261
  }
2076
2262
  if (layer.previousSibling !== svg) svg.after(layer);
2077
2263
  return box;
2078
2264
  }
2079
- function contentFor(row, summary) {
2265
+ function contentFor(row, summary2) {
2080
2266
  const option = options.option();
2081
2267
  const known = texts.get(row);
2082
2268
  if (known && known.option === option) return known.content;
2083
- const content = text(option, row.datum, summary);
2269
+ const content = text(option, row.datum, summary2);
2084
2270
  texts.set(row, { option, content });
2085
2271
  return content;
2086
2272
  }
@@ -2088,14 +2274,16 @@ function chartTooltip(svg, options) {
2088
2274
  if (!box) return;
2089
2275
  timing(box);
2090
2276
  box.classList.remove("ec-tooltip-shown");
2277
+ letThrough(false);
2091
2278
  }
2092
- function place(row, summary, anchor, moved) {
2093
- const content = contentFor(row, summary);
2279
+ function place(row, summary2, anchor, moved) {
2280
+ const content = contentFor(row, summary2);
2094
2281
  if (content === void 0) {
2095
2282
  hide();
2096
2283
  return;
2097
2284
  }
2098
- const tip = element();
2285
+ const tip = made();
2286
+ const held = shown() && !through && under();
2099
2287
  const key = typeof content === "string" ? `text:${content}` : JSON.stringify(content);
2100
2288
  if (key !== rendered) {
2101
2289
  render(tip, content);
@@ -2107,29 +2295,39 @@ function chartTooltip(svg, options) {
2107
2295
  const toPx = { x: (x) => (x - view.x) * k, y: (y) => (y - view.y) * k };
2108
2296
  const area = chart.width > 0 ? { width: chart.width, height: chart.height } : { width: view.width, height: view.height };
2109
2297
  const size = { width: tip.offsetWidth, height: tip.offsetHeight };
2110
- const placed2 = placeTooltip(anchor(toPx, moved), size, area, moved ? placeTooltip(anchor(toPx, false), size, area).side : void 0);
2298
+ const near = anchor(toPx, moved);
2299
+ const placed2 = placeTooltip(near, size, area, moved ? placeTooltip(anchor(toPx, false), size, area).side : void 0);
2111
2300
  const origin = layer.getBoundingClientRect();
2112
- tip.style.left = `${Math.round(chart.left - origin.left + placed2.x)}px`;
2113
- tip.style.top = `${Math.round(chart.top - origin.top + placed2.y)}px`;
2301
+ const dx = chart.left - origin.left;
2302
+ const dy = chart.top - origin.top;
2303
+ const left = Math.round(dx + placed2.x);
2304
+ const top = Math.round(dy + placed2.y);
2305
+ tip.style.left = `${left}px`;
2306
+ tip.style.top = `${top}px`;
2114
2307
  tip.setAttribute("data-side", placed2.side);
2308
+ 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 };
2309
+ shape = span(bridge, { left, top, ...size }, mark, placed2.side);
2115
2310
  timing(tip);
2116
2311
  tip.classList.add("ec-tooltip-shown");
2312
+ letThrough(!held && under());
2117
2313
  }
2118
2314
  return {
2119
- show(mark, row, summary, transform) {
2315
+ show(mark, row, summary2, transform) {
2120
2316
  const anchor = (toPx, moved) => {
2121
2317
  const m = moved ? transform : void 0;
2122
2318
  const { x, y, width, height } = mark.bounds;
2123
- 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);
2319
+ 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);
2320
+ const xs = corners.map((corner) => corner.x);
2321
+ const ys = corners.map((corner) => corner.y);
2124
2322
  const center = m ? matrix.apply(m, mark.center) : mark.center;
2125
- return { x: toPx.x(center.x), top: toPx.y(Math.min(...ys)), bottom: toPx.y(Math.max(...ys)) };
2323
+ 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)) };
2126
2324
  };
2127
- place(row, summary, anchor, transform !== void 0);
2325
+ place(row, summary2, anchor, transform !== void 0);
2128
2326
  },
2129
- showAt(point, row, summary) {
2130
- place(row, summary, (toPx) => ({ x: toPx.x(point.x), top: toPx.y(point.top), bottom: toPx.y(point.bottom) }), false);
2327
+ showAt(point, row, summary2) {
2328
+ place(row, summary2, (toPx) => ({ x: toPx.x(point.x), top: toPx.y(point.top), bottom: toPx.y(point.bottom) }), false);
2131
2329
  },
2132
- describe(element2, row) {
2330
+ describe(element, row) {
2133
2331
  const own2 = options.description?.();
2134
2332
  let content;
2135
2333
  if (own2 === false) content = void 0;
@@ -2142,30 +2340,58 @@ function chartTooltip(svg, options) {
2142
2340
  content = void 0;
2143
2341
  }
2144
2342
  } else content = typeof options.option() === "function" ? contentFor(row, () => "") : void 0;
2145
- let desc = element2.querySelector(":scope > desc.ec-description");
2343
+ let desc = element.querySelector(":scope > desc.ec-description");
2146
2344
  if (typeof content !== "string") {
2147
2345
  if (!desc) return;
2148
- if (element2.getAttribute("aria-describedby") === desc.id) element2.removeAttribute("aria-describedby");
2346
+ if (element.getAttribute("aria-describedby") === desc.id) element.removeAttribute("aria-describedby");
2149
2347
  desc.remove();
2150
2348
  return;
2151
2349
  }
2152
- desc ?? (desc = svgElement("desc", { class: "ec-description", id: `ec-description-${++described}` }, element2));
2350
+ desc ?? (desc = svgElement("desc", { class: "ec-description", id: `ec-description-${++described}` }, element));
2153
2351
  if (desc.textContent !== content) desc.textContent = content;
2154
- element2.setAttribute("aria-describedby", desc.id);
2352
+ element.setAttribute("aria-describedby", desc.id);
2155
2353
  },
2354
+ element: () => shown() ? layer : void 0,
2156
2355
  hide,
2157
2356
  destroy() {
2357
+ svg.ownerDocument.removeEventListener("pointerover", track, true);
2358
+ svg.ownerDocument.removeEventListener("pointermove", track, true);
2158
2359
  layer?.remove();
2159
2360
  layer = void 0;
2160
2361
  box = void 0;
2362
+ bridge = void 0;
2363
+ shape = void 0;
2364
+ through = false;
2161
2365
  texts = /* @__PURE__ */ new WeakMap();
2162
2366
  rendered = void 0;
2163
2367
  }
2164
2368
  };
2165
2369
  }
2166
- function text(option, datum, summary) {
2370
+ function inside({ top, bottom, upper, lower }, x, y) {
2371
+ if (y <= top || y >= bottom) return false;
2372
+ const t = (y - top) / (bottom - top);
2373
+ return x > upper.left + (lower.left - upper.left) * t && x < upper.right + (lower.right - upper.right) * t;
2374
+ }
2375
+ function span(bridge, box, mark, side) {
2376
+ bridge.hidden = mark === void 0;
2377
+ if (!mark) return void 0;
2378
+ const edge = { left: box.left, right: box.left + box.width };
2379
+ 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];
2380
+ const left = Math.round(Math.min(upper.left, lower.left));
2381
+ const width = Math.round(Math.max(upper.right, lower.right)) - left;
2382
+ const height = Math.max(0, bottom - top);
2383
+ const x = (value) => `${Math.round(value) - left}px`;
2384
+ bridge.style.left = `${left}px`;
2385
+ bridge.style.top = `${top}px`;
2386
+ bridge.style.width = `${width}px`;
2387
+ bridge.style.height = `${height}px`;
2388
+ bridge.style.setProperty("clip-path", `polygon(${x(upper.left)} 0px, ${x(upper.right)} 0px, ${x(lower.right)} ${height}px, ${x(lower.left)} ${height}px)`);
2389
+ const round5 = (edge2) => ({ left: Math.round(edge2.left), right: Math.round(edge2.right) });
2390
+ return { top, bottom: top + height, upper: round5(upper), lower: round5(lower) };
2391
+ }
2392
+ function text(option, datum, summary2) {
2167
2393
  if (option === false) return void 0;
2168
- if (typeof option !== "function") return summary();
2394
+ if (typeof option !== "function") return summary2();
2169
2395
  try {
2170
2396
  const result = option(datum);
2171
2397
  return result === void 0 || result === null || result === "" ? void 0 : String(result);
@@ -2189,8 +2415,8 @@ function render(box, content) {
2189
2415
  box.replaceChildren(line(content.title, "ec-tooltip-title"), ...content.lines.map((value) => line(value)));
2190
2416
  }
2191
2417
  function viewBox(svg) {
2192
- const parts = (svg.getAttribute("viewBox") ?? "").split(/[\s,]+/).map(Number);
2193
- if (parts.length === 4 && parts.every(Number.isFinite)) return { x: parts[0], y: parts[1], width: parts[2], height: parts[3] };
2418
+ const parts2 = (svg.getAttribute("viewBox") ?? "").split(/[\s,]+/).map(Number);
2419
+ if (parts2.length === 4 && parts2.every(Number.isFinite)) return { x: parts2[0], y: parts2[1], width: parts2[2], height: parts2[3] };
2194
2420
  return { x: 0, y: 0, width: Number(svg.getAttribute("width")) || 0, height: Number(svg.getAttribute("height")) || 0 };
2195
2421
  }
2196
2422
 
@@ -2274,7 +2500,8 @@ function barChart(target, options, env2) {
2274
2500
  width: opts.width ?? measuredWidth,
2275
2501
  height: opts.height,
2276
2502
  format: format(opts),
2277
- measure
2503
+ measure,
2504
+ room: opts.room ?? 0
2278
2505
  });
2279
2506
  }
2280
2507
  function createRecord(row, entering) {
@@ -2335,8 +2562,8 @@ function barChart(target, options, env2) {
2335
2562
  element.remove();
2336
2563
  record.paths.delete(series);
2337
2564
  }
2338
- const drawn = Array.from(record.body.children).filter((child) => child.classList.contains("ec-segment"));
2339
- if (record.parts.some((part, i) => drawn[i] !== part.element)) for (const part of record.parts) record.body.appendChild(part.element);
2565
+ const drawn2 = Array.from(record.body.children).filter((child) => child.classList.contains("ec-segment"));
2566
+ if (record.parts.some((part, i) => drawn2[i] !== part.element)) for (const part of record.parts) record.body.appendChild(part.element);
2340
2567
  record.handle.repaint();
2341
2568
  if (record.parts[0]?.colors.color !== before) surface.recolor(record.key);
2342
2569
  if (record.key === hover.ringKey) drawRing(record.key);
@@ -2359,12 +2586,12 @@ function barChart(target, options, env2) {
2359
2586
  }
2360
2587
  function showTooltip(record) {
2361
2588
  const { row } = record;
2362
- tooltip.show(record.shown.geometry, row, () => summaryContent(row.label.text, labelled(row.values, current), format(current)), record.handle.style.transform);
2589
+ tooltip.show(record.shown.geometry, row, () => summaryContent(row.category, labelled(row.values, current), format(current)), record.handle.style.transform);
2363
2590
  }
2364
2591
  function syncLegend(next) {
2365
2592
  if (byCategory(current)) {
2366
2593
  legend.categories(
2367
- next.rows.map((row) => ({ key: row.key, label: row.label.text })),
2594
+ next.rows.map((row) => ({ key: row.key, label: row.category })),
2368
2595
  colors,
2369
2596
  current.legend
2370
2597
  );
@@ -2385,7 +2612,7 @@ function barChart(target, options, env2) {
2385
2612
  category: typeof field === "string" ? field : void 0,
2386
2613
  series: encoding.series.map((s) => s.series),
2387
2614
  label: (series) => seriesLabel(opts.seriesLabels, series),
2388
- rows: next.rows.map((row) => ({ key: row.key, category: row.label.text, datum: row.datum, index: row.index, values: row.values, total: row.total })),
2615
+ rows: next.rows.map((row) => ({ key: row.key, category: row.category, datum: row.datum, index: row.index, values: row.values, total: row.total })),
2389
2616
  format: format(opts)
2390
2617
  });
2391
2618
  }
@@ -2395,7 +2622,7 @@ function barChart(target, options, env2) {
2395
2622
  const series = barEncoding(current).series.map((s) => s.series);
2396
2623
  const before = barEncoding(previous).series.map((s) => s.series);
2397
2624
  const sort = sortName(current.sort);
2398
- const name = (record) => record.row.label.text;
2625
+ const name = (record) => record.row.category;
2399
2626
  const changed = diff.changed.map(({ record }) => record);
2400
2627
  const text2 = changeText({
2401
2628
  ...current.label !== previous.label ? { label: current.label } : {},
@@ -2413,8 +2640,8 @@ function barChart(target, options, env2) {
2413
2640
  }
2414
2641
  const key = (record) => record.key;
2415
2642
  try {
2416
- const said = option({ text: text2, changed: changed.map(key), added: diff.entering.map(key), removed: diff.exiting.map(key) });
2417
- if (said !== void 0 && said !== null) announcer.say(String(said));
2643
+ const said2 = option({ text: text2, changed: changed.map(key), added: diff.entering.map(key), removed: diff.exiting.map(key) });
2644
+ if (said2 !== void 0 && said2 !== null) announcer.say(String(said2));
2418
2645
  } catch (error) {
2419
2646
  report(error);
2420
2647
  }
@@ -2426,7 +2653,7 @@ function barChart(target, options, env2) {
2426
2653
  const values = record.series.map((series) => ({ series, value: now[series] ?? 0 }));
2427
2654
  const total2 = values.reduce((sum, v) => sum + v.value, 0);
2428
2655
  const text2 = record.count === void 0 ? row.value.text : format(current)(round(total2, record.count));
2429
- return placeRow(frame, { key: row.key, datum: row.datum, index: row.index, category: row.label.text, values, slot: record.slot.value, text: text2 }, measure);
2656
+ return placeRow(frame, { key: row.key, datum: row.datum, index: row.index, category: row.category, values, slot: record.slot.value, text: text2, drawn: row.drawn }, measure);
2430
2657
  }
2431
2658
  function addTick(value, opacity) {
2432
2659
  const tick = {
@@ -2606,7 +2833,8 @@ function barChart(target, options, env2) {
2606
2833
  const record = records.get(key);
2607
2834
  if (record) showTooltip(record);
2608
2835
  },
2609
- hide: () => tooltip.hide()
2836
+ hide: () => tooltip.hide(),
2837
+ element: () => tooltip.element()
2610
2838
  }
2611
2839
  });
2612
2840
  const unwatchHoverDuration = watchHoverDuration(svg, motion2);
@@ -2673,6 +2901,7 @@ function barChart(target, options, env2) {
2673
2901
  leaving,
2674
2902
  input,
2675
2903
  onScreen,
2904
+ data: "data" in next,
2676
2905
  ...swapping ? {
2677
2906
  swap: (diff) => {
2678
2907
  const entering = new Set(diff.entering);
@@ -2731,7 +2960,8 @@ function barChart(target, options, env2) {
2731
2960
  }
2732
2961
  function checkOptions(options) {
2733
2962
  checkChartOptions(options, "barChart");
2734
- const { colorBy } = options;
2963
+ const { colorBy, room } = options;
2964
+ 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)}.`);
2735
2965
  if (colorBy !== void 0 && colorBy !== "series" && colorBy !== "category") throw new TypeError(`barChart: colorBy must be "series" or "category", got ${String(colorBy)}.`);
2736
2966
  if (colorBy === "category" && options.stack !== void 0) {
2737
2967
  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.');
@@ -2744,10 +2974,10 @@ function markLabel(row, options) {
2744
2974
  const formatted = format(options);
2745
2975
  const values = labelled(row.values, options);
2746
2976
  const lone = values.length === 1 && values[0].series === "value" && values[0].label === "value";
2747
- const text2 = `${row.label.text}: ${values.map((v) => lone ? formatted(v.value) : `${formatted(v.value)} ${v.label}`).join(", ")}`;
2977
+ const text2 = `${row.category}: ${values.map((v) => lone ? formatted(v.value) : `${formatted(v.value)} ${v.label}`).join(", ")}`;
2748
2978
  if (!options.markLabel) return text2;
2749
2979
  try {
2750
- const named = options.markLabel(row.datum, { key: row.key, category: row.label.text, values, total: row.total, format: formatted, text: text2 });
2980
+ const named = options.markLabel(row.datum, { key: row.key, category: row.category, values, total: row.total, format: formatted, text: text2 });
2751
2981
  if (named !== void 0 && named !== null && String(named).trim() !== "") return String(named);
2752
2982
  } catch (error) {
2753
2983
  report(error);
@@ -2831,7 +3061,7 @@ function layoutDonut(input) {
2831
3061
  const end = i + 1 < rows2.length && total2 > 0 ? starts[i + 1] : total2 > 0 ? 1 : 0;
2832
3062
  return { ...row, series: input.encoding.series, share, start: starts[i] * TAU, end: end * TAU };
2833
3063
  });
2834
- const labels = placeLabels(frame, states, input.measure);
3064
+ const labels = placeLabels2(frame, states, input.measure);
2835
3065
  const centerText2 = input.center(total2);
2836
3066
  return {
2837
3067
  frame,
@@ -2865,7 +3095,7 @@ function placeSlice(frame, state, label2, measure) {
2865
3095
  });
2866
3096
  return { ...state, geometry, data: sliceData(state.datum, state.share, state.series) };
2867
3097
  }
2868
- function placeLabels(frame, slices, measure) {
3098
+ function placeLabels2(frame, slices, measure) {
2869
3099
  let previous;
2870
3100
  let first;
2871
3101
  const labels = slices.map((slice, i) => {
@@ -2873,7 +3103,7 @@ function placeLabels(frame, slices, measure) {
2873
3103
  const label2 = labelAt(frame, slice, measure);
2874
3104
  const { box } = label2;
2875
3105
  if (box.x < 0 || box.y < 0 || box.x + box.width > frame.width || box.y + box.height > frame.height) return void 0;
2876
- if (previous && overlaps(previous, box)) return void 0;
3106
+ if (previous && overlaps2(previous, box)) return void 0;
2877
3107
  previous = box;
2878
3108
  first ?? (first = i);
2879
3109
  return label2;
@@ -2881,7 +3111,7 @@ function placeLabels(frame, slices, measure) {
2881
3111
  for (let i = labels.length - 1; first !== void 0 && i > first; i--) {
2882
3112
  const label2 = labels[i];
2883
3113
  if (!label2) continue;
2884
- if (!overlaps(labels[first].box, label2.box)) break;
3114
+ if (!overlaps2(labels[first].box, label2.box)) break;
2885
3115
  labels[i] = void 0;
2886
3116
  }
2887
3117
  return labels;
@@ -2948,7 +3178,7 @@ function labelBoxes(label2, measure) {
2948
3178
  if (label2.share.text !== "") out.push(textBox(label2.share, measure, "ec-value", VALUE_SIZE2));
2949
3179
  return out;
2950
3180
  }
2951
- function overlaps(a, b) {
3181
+ function overlaps2(a, b) {
2952
3182
  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;
2953
3183
  }
2954
3184
  function sliceData(datum, share, series) {
@@ -3176,13 +3406,13 @@ function donutChart(target, options, env2) {
3176
3406
  }
3177
3407
  const key = (record) => record.key;
3178
3408
  try {
3179
- const said = option({ text: text2, changed: changed.map(key), added: diff.entering.map(key), removed: diff.exiting.map(key) });
3180
- if (said !== void 0 && said !== null) announcer.say(String(said));
3409
+ const said2 = option({ text: text2, changed: changed.map(key), added: diff.entering.map(key), removed: diff.exiting.map(key) });
3410
+ if (said2 !== void 0 && said2 !== null) announcer.say(String(said2));
3181
3411
  } catch (error) {
3182
3412
  report(error);
3183
3413
  }
3184
3414
  }
3185
- const drawn = (record) => records.get(record.key) === record || leaving.get(record.key) === record;
3415
+ const drawn2 = (record) => records.get(record.key) === record || leaving.get(record.key) === record;
3186
3416
  const valueOf = (record) => Math.max(0, record.value.value);
3187
3417
  function startsIn(slices, total2, value = valueOf) {
3188
3418
  const starts = /* @__PURE__ */ new Map();
@@ -3194,8 +3424,8 @@ function donutChart(target, options, env2) {
3194
3424
  return starts;
3195
3425
  }
3196
3426
  function angles() {
3197
- ring = ring.filter(drawn);
3198
- from = from.filter(drawn);
3427
+ ring = ring.filter(drawn2);
3428
+ from = from.filter(drawn2);
3199
3429
  const total2 = ring.reduce((sum, record) => sum + valueOf(record), 0);
3200
3430
  const to = startsIn(ring, total2);
3201
3431
  const was = startsIn(from, total2);
@@ -3214,7 +3444,7 @@ function donutChart(target, options, env2) {
3214
3444
  return out;
3215
3445
  }
3216
3446
  function currentSlices(f) {
3217
- const now = [...angles()].map(([record, { start, span }]) => {
3447
+ const now = [...angles()].map(([record, { start, span: span2 }]) => {
3218
3448
  const { row } = record;
3219
3449
  const state = {
3220
3450
  key: row.key,
@@ -3223,13 +3453,13 @@ function donutChart(target, options, env2) {
3223
3453
  category: row.category,
3224
3454
  series: row.series,
3225
3455
  value: valueOf(record),
3226
- share: span,
3456
+ share: span2,
3227
3457
  start: start * TAU2,
3228
- end: (start + span) * TAU2
3458
+ end: (start + span2) * TAU2
3229
3459
  };
3230
3460
  return { record, state };
3231
3461
  });
3232
- const labels = placeLabels(
3462
+ const labels = placeLabels2(
3233
3463
  f,
3234
3464
  now.map(({ state }) => state),
3235
3465
  measure
@@ -3251,7 +3481,7 @@ function donutChart(target, options, env2) {
3251
3481
  return counted.text;
3252
3482
  }
3253
3483
  function land() {
3254
- ring = ring.filter(drawn);
3484
+ ring = ring.filter(drawn2);
3255
3485
  from = ring;
3256
3486
  for (const record of ring) {
3257
3487
  record.turn.set(1);
@@ -3407,7 +3637,8 @@ function donutChart(target, options, env2) {
3407
3637
  const record = records.get(key);
3408
3638
  if (record) showTooltip(record);
3409
3639
  },
3410
- hide: () => tooltip.hide()
3640
+ hide: () => tooltip.hide(),
3641
+ element: () => tooltip.element()
3411
3642
  }
3412
3643
  });
3413
3644
  const unwatchHoverDuration = watchHoverDuration(svg, motion2);
@@ -3479,6 +3710,7 @@ function donutChart(target, options, env2) {
3479
3710
  leaving,
3480
3711
  input,
3481
3712
  onScreen,
3713
+ data: "data" in next,
3482
3714
  ...swapping ? {
3483
3715
  swap: (diff) => {
3484
3716
  const entering = new Set(diff.entering);
@@ -3638,9 +3870,9 @@ var FIELDS = {
3638
3870
  second: { hour: "numeric", minute: "2-digit", second: "2-digit" },
3639
3871
  millisecond: { hour: "numeric", minute: "2-digit", second: "2-digit", ...FRACTION }
3640
3872
  };
3641
- function timeStep(span) {
3642
- for (const step2 of STEPS) if (LONGEST[step2.unit] * step2.count >= span) return step2;
3643
- return { unit: "year", count: Math.max(1, niceStep(span / LONGEST.year)) };
3873
+ function timeStep(span2) {
3874
+ for (const step2 of STEPS) if (LONGEST[step2.unit] * step2.count >= span2) return step2;
3875
+ return { unit: "year", count: Math.max(1, niceStep(span2 / LONGEST.year)) };
3644
3876
  }
3645
3877
  function timeTicks(lo, hi, zone) {
3646
3878
  const word = tickWording(zone);
@@ -3666,9 +3898,9 @@ function boundaries(lo, hi, step2, zone) {
3666
3898
  const grain = unit === "hour" ? 15 * MINUTE : LONGEST[unit];
3667
3899
  let t = lo - start.ms - (unit === "second" ? 0 : start.seconds * SECOND) - (unit === "hour" ? start.minutes % 15 * MINUTE : 0);
3668
3900
  for (; t < hi; t += grain) {
3669
- const parts = partsOf(t, zone);
3670
- const whole = unit !== "hour" || parts.minutes === 0;
3671
- const field = unit === "second" ? parts.seconds : unit === "minute" ? parts.minutes : parts.hours;
3901
+ const parts2 = partsOf(t, zone);
3902
+ const whole = unit !== "hour" || parts2.minutes === 0;
3903
+ const field = unit === "second" ? parts2.seconds : unit === "minute" ? parts2.minutes : parts2.hours;
3672
3904
  if (t > lo && whole && field % count === 0) out.push(t);
3673
3905
  }
3674
3906
  return out;
@@ -3686,6 +3918,21 @@ function boundaries(lo, hi, step2, zone) {
3686
3918
  }
3687
3919
  return out;
3688
3920
  }
3921
+ function monthsOn(t, months, zone) {
3922
+ const { year, month, date, hours, minutes, seconds, ms } = partsOf(t, zone);
3923
+ const last = /* @__PURE__ */ new Date(0);
3924
+ last.setUTCFullYear(year, month + months + 1, 0);
3925
+ const day = Math.min(date, last.getUTCDate());
3926
+ const d = /* @__PURE__ */ new Date(0);
3927
+ if (zone === "UTC") {
3928
+ d.setUTCFullYear(year, month + months, day);
3929
+ d.setUTCHours(hours, minutes, seconds, ms);
3930
+ } else {
3931
+ d.setFullYear(year, month + months, day);
3932
+ d.setHours(hours, minutes, seconds, ms);
3933
+ }
3934
+ return d.getTime();
3935
+ }
3689
3936
  function timeLevel(t, zone) {
3690
3937
  const { ms, seconds, minutes, hours, date, month } = partsOf(t, zone);
3691
3938
  if (ms !== 0) return "millisecond";
@@ -3775,7 +4022,7 @@ function layoutLines(input) {
3775
4022
  const height = input.height ?? HEIGHT2;
3776
4023
  const { rows: rows2, time } = prepareRows2(input);
3777
4024
  const series = input.encoding.series.map((s) => s.series);
3778
- const domain = niceDomain(rows2.flatMap((row) => row.values.map((v) => v.value)));
4025
+ const domain = niceDomain(rows2.flatMap((row) => row.values.flatMap((v) => v.value === void 0 ? [] : [v.value])));
3779
4026
  const yTexts = domain.ticks.map(input.format);
3780
4027
  const xLo = rows2[0]?.x ?? 0;
3781
4028
  const xHi = rows2[rows2.length - 1]?.x ?? 0;
@@ -3792,7 +4039,7 @@ function layoutLines(input) {
3792
4039
  };
3793
4040
  const decimalsBy = {};
3794
4041
  for (const name of series) decimalsBy[name] = 0;
3795
- for (const row of rows2) for (const v of row.values) decimalsBy[v.series] = Math.max(decimalsBy[v.series], decimals(v.value));
4042
+ 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));
3796
4043
  const xTicks = xValues.map((value, i) => placeXTick(frame, value, xTexts[i]));
3797
4044
  return {
3798
4045
  width,
@@ -3828,34 +4075,60 @@ function placeLines(frame, rows2, series, through, time = false, labels) {
3828
4075
  const datas = /* @__PURE__ */ new Map();
3829
4076
  const related = (own2) => (name) => name === own2 ? void 0 : datas.get(name);
3830
4077
  const traced = series.map((name) => {
3831
- const vertices = shown.map((row) => ({ at: row.x, value: row.values[name] ?? 0 }));
3832
- if (share !== void 0) {
4078
+ const has = (row) => !row.missing?.has(name);
4079
+ const vertices = [];
4080
+ let gap = false;
4081
+ for (const row of shown) {
4082
+ if (!has(row)) gap = vertices.length > 0;
4083
+ else {
4084
+ vertices.push({ at: row.x, value: row.values[name] ?? 0, datum: row.datum, gapBefore: gap });
4085
+ gap = false;
4086
+ }
4087
+ }
4088
+ if (share !== void 0 && has(end) && has(next)) {
3833
4089
  const from = end.values[name] ?? 0;
3834
- vertices.push({ at: through, value: from + share * ((next.values[name] ?? 0) - from) });
4090
+ vertices.push({ at: through, value: from + share * ((next.values[name] ?? 0) - from), datum: end.datum, gapBefore: false });
3835
4091
  }
3836
- return { name, vertices, points: vertices.map((v) => ({ x: at.x(v.at), y: at.y(v.value) })) };
4092
+ 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) }];
4093
+ return { name, vertices, points };
3837
4094
  });
4095
+ const named = traced.filter(({ vertices }) => vertices.length > 0);
3838
4096
  const placed2 = labels ? placeEndLabels(
3839
4097
  frame,
3840
- traced.map(({ name, vertices, points }) => ({ ...points[points.length - 1], text: labels.text(name, vertices[vertices.length - 1].value) }))
4098
+ named.map(({ name, vertices, points }) => ({ ...points[points.length - 1], text: labels.text(name, vertices[vertices.length - 1].value) }))
3841
4099
  ) : [];
3842
- const lines = traced.map(({ name, vertices, points }, i) => {
3843
- const label2 = placed2[i];
4100
+ const lines = traced.map(({ name, vertices, points }) => {
4101
+ const tip = points[points.length - 1];
4102
+ const label2 = labels ? placed2[named.findIndex((line) => line.name === name)] ?? { x: tip.x + LABEL_GAP, y: tip.y + VALUE_SIZE3 * CENTRE3, anchor: "start", text: "" } : void 0;
3844
4103
  const labelBounds = labels ? label2 && label2.text !== "" ? [textBox(label2, labels.measure, "ec-value", VALUE_SIZE3)] : [] : void 0;
3845
- const geometry = describe.line({ key: name, series: name, points, width: LINE_WIDTH, ...labelBounds ? { labelBounds } : {} });
4104
+ const breaks = vertices.flatMap((v, j) => v.gapBefore ? [j] : []);
4105
+ const geometry = describe.line({ key: name, series: name, points, width: LINE_WIDTH, ...breaks.length > 0 ? { breaks } : {}, ...labelBounds ? { labelBounds } : {} });
3846
4106
  let distance3 = 0;
3847
4107
  const samples = vertices.map((v, j) => {
3848
4108
  if (j > 0) distance3 += Math.hypot(points[j].x - points[j - 1].x, points[j].y - points[j - 1].y);
3849
4109
  const t = geometry.length > 0 ? j === vertices.length - 1 ? 1 : Math.min(1, distance3 / geometry.length) : 0;
3850
- return { t, value: v.value, at: sampleAt(v.at, time) };
4110
+ return { t, value: v.value, at: sampleAt(v.at, time), ...v.gapBefore ? { gapBefore: true } : {} };
3851
4111
  });
3852
- const data = { datum: end.datum, samples, related: related(name) };
4112
+ const last2 = vertices[vertices.length - 1];
4113
+ const data = { datum: last2 ? last2.datum : end.datum, samples, related: related(name) };
3853
4114
  datas.set(name, data);
3854
- const tip = vertices[vertices.length - 1];
3855
- return { series: name, geometry, data, end: { ...points[points.length - 1], value: tip.value }, label: label2 };
4115
+ return { series: name, geometry, data, end: { ...tip, value: last2 ? last2.value : first.values[name] ?? 0 }, label: label2 };
3856
4116
  });
3857
4117
  return lines;
3858
4118
  }
4119
+ function loneValues(rows2, series) {
4120
+ const lone = /* @__PURE__ */ new Set();
4121
+ if (!rows2.some((row) => row.missing !== void 0 && row.missing.size > 0)) return lone;
4122
+ const has = (row, name) => row !== void 0 && !row.missing?.has(name);
4123
+ rows2.forEach((row, i) => {
4124
+ for (const name of series) {
4125
+ const before = rows2[i - 1];
4126
+ const after = rows2[i + 1];
4127
+ if (has(row, name) && !has(before, name) && !has(after, name) && (before !== void 0 || after !== void 0)) lone.add(pointKey(name, row.key));
4128
+ }
4129
+ });
4130
+ return lone;
4131
+ }
3859
4132
  function pointKey(series, row) {
3860
4133
  return `${series}@${row}`;
3861
4134
  }
@@ -3863,7 +4136,7 @@ function placePoints(frame, row, series, time = false) {
3863
4136
  const at = positions(frame);
3864
4137
  const x = at.x(row.x);
3865
4138
  const datas = /* @__PURE__ */ new Map();
3866
- return series.map((name) => {
4139
+ return series.filter((name) => !row.missing?.has(name)).map((name) => {
3867
4140
  const value = row.values[name] ?? 0;
3868
4141
  const key = pointKey(name, row.key);
3869
4142
  const data = { datum: row.datum, samples: [{ t: 0, value, at: sampleAt(row.x, time) }], related: (other) => other === name ? void 0 : datas.get(other) };
@@ -3897,8 +4170,8 @@ function spread(values, gap, min, max) {
3897
4170
  const clusters = [];
3898
4171
  const place = (members) => {
3899
4172
  const mean = members.reduce((sum, m) => sum + m.value, 0) / members.length;
3900
- const span = (members.length - 1) * gap;
3901
- return Math.max(min, Math.min(max - span, mean - span / 2));
4173
+ const span2 = (members.length - 1) * gap;
4174
+ return Math.max(min, Math.min(max - span2, mean - span2 / 2));
3902
4175
  };
3903
4176
  for (const item of order) {
3904
4177
  clusters.push({ members: [item], start: place([item]) });
@@ -3970,7 +4243,34 @@ function prepareRows2({ data, encoding }) {
3970
4243
  }
3971
4244
  }
3972
4245
  const word = xWording(encoding, time, read.map((row) => row.x));
3973
- return { rows: read.map((row) => ({ ...row, label: word(row.x) })), time };
4246
+ const levels = levelsOf(read, encoding.series.length);
4247
+ return {
4248
+ 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] })),
4249
+ time
4250
+ };
4251
+ }
4252
+ function levelsOf(rows2, count) {
4253
+ const levels = rows2.map(() => ({}));
4254
+ for (let s = 0; s < count; s++) {
4255
+ let before = -1;
4256
+ let after = -1;
4257
+ rows2.forEach((row, i) => {
4258
+ const { series, value } = row.values[s];
4259
+ if (value !== void 0) {
4260
+ levels[i][series] = value;
4261
+ before = i;
4262
+ return;
4263
+ }
4264
+ if (after <= i) {
4265
+ after = i + 1;
4266
+ while (after < rows2.length && rows2[after].values[s].value === void 0) after++;
4267
+ }
4268
+ const a = rows2[before]?.values[s].value;
4269
+ const b = rows2[after]?.values[s].value;
4270
+ 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;
4271
+ });
4272
+ }
4273
+ return levels;
3974
4274
  }
3975
4275
  function xOf(x, index, time) {
3976
4276
  if (x instanceof Date) {
@@ -3996,12 +4296,14 @@ function sampleAt(x, time) {
3996
4296
  }
3997
4297
  function numberOf3(value, series, key) {
3998
4298
  if (typeof value === "number" && Number.isFinite(value)) return value;
3999
- throw new RangeError(`lineChart: "${series}" for "${key}" must be a finite number, got ${show(value)}. Lines can't skip a value yet.`);
4299
+ if (value === null || value === void 0) return void 0;
4300
+ throw new RangeError(`lineChart: "${series}" for "${key}" must be a finite number, or null or undefined where it has no value, got ${show(value)}.`);
4000
4301
  }
4001
4302
  function distinctLabels(rows2, label2) {
4002
4303
  const shapes = /* @__PURE__ */ new Map();
4003
4304
  for (const row of rows2) {
4004
4305
  for (const { series, value } of row.values) {
4306
+ if (value === void 0) continue;
4005
4307
  const text2 = label2(series, value);
4006
4308
  const shape = text2.replace(/\d/g, "0");
4007
4309
  if (!shapes.has(shape)) shapes.set(shape, text2);
@@ -4171,12 +4473,13 @@ function lineChart(target, options, env2) {
4171
4473
  column,
4172
4474
  hit: svgElement("rect", { class: "ec-hit" }, column),
4173
4475
  x: animated(row.x, interpolateNumber, env3),
4174
- values: animated(valuesOf2(row.values), interpolateRecord, env3),
4476
+ values: animated(row.levels, interpolateRecord, env3),
4175
4477
  presence: animated(entering ? 0 : 1, interpolateNumber, env3),
4176
4478
  anchor: void 0,
4177
4479
  points: [],
4178
4480
  leaving: false,
4179
- shown: true
4481
+ shown: true,
4482
+ px: 0
4180
4483
  };
4181
4484
  byColumn.set(column, record);
4182
4485
  return record;
@@ -4223,7 +4526,7 @@ function lineChart(target, options, env2) {
4223
4526
  };
4224
4527
  return record;
4225
4528
  }
4226
- const drawn = (record) => findMark(record.key) === record;
4529
+ const drawn2 = (record) => findMark(record.key) === record;
4227
4530
  const livePoints = (record) => record.points.filter((point) => points.get(point.key) === point);
4228
4531
  const leavingLines = () => [...leaving.values()].filter((record) => record.kind === "line");
4229
4532
  const currentFrame = () => ({ scale: scale.value, box: box.value });
@@ -4248,7 +4551,7 @@ function lineChart(target, options, env2) {
4248
4551
  const drawnRows = [...rowOrder, ...[...leavingRows.values()].filter((record) => record.presence.value > 0 && record.anchor)];
4249
4552
  return drawnRows.map((record) => {
4250
4553
  const { x, values } = stateOf(record);
4251
- return { record, state: { key: record.key, datum: record.row.datum, x, values } };
4554
+ return { record, state: { key: record.key, datum: record.row.datum, x, values, missing: record.row.missing } };
4252
4555
  }).sort((a, b) => a.state.x - b.state.x);
4253
4556
  }
4254
4557
  function draw() {
@@ -4260,8 +4563,9 @@ function lineChart(target, options, env2) {
4260
4563
  paintLines(frame, states.map((s) => s.state));
4261
4564
  for (const { record, state } of states) {
4262
4565
  const placed2 = new Map(placePoints(frame, state, record.points.map((point) => point.series), laidOut.time).map((point) => [point.key, point]));
4263
- showAll(record.points.filter(drawn).map((point) => ({ record: point, placed: placed2.get(point.key) })));
4566
+ showAll(record.points.filter(drawn2).flatMap((point) => placed2.has(point.key) ? [{ record: point, placed: placed2.get(point.key) }] : []));
4264
4567
  }
4568
+ paintAlone(states.map((s) => s.state));
4265
4569
  paintColumns(frame, states);
4266
4570
  followHover();
4267
4571
  }
@@ -4280,7 +4584,7 @@ function lineChart(target, options, env2) {
4280
4584
  leavingRows.clear();
4281
4585
  for (const record of rowOrder) {
4282
4586
  record.anchor = void 0;
4283
- record.points = record.points.filter(drawn);
4587
+ record.points = record.points.filter(drawn2);
4284
4588
  }
4285
4589
  for (const [ticks, placedTicks] of [
4286
4590
  [yTicks, laidOut.yTicks],
@@ -4318,6 +4622,7 @@ function lineChart(target, options, env2) {
4318
4622
  paintLabels(new Map(lineOrder.flatMap((line) => placed2.lines.has(line.series) ? [[line, placed2.lines.get(line.series)]] : [])));
4319
4623
  const states = rowOrder.map((record) => ({ record, state: restState(record.row) }));
4320
4624
  for (const { record } of states) settle(livePoints(record), (point) => placed2.points.get(point.key));
4625
+ paintAlone(states.map((s) => s.state));
4321
4626
  paintColumns(frame, states);
4322
4627
  followHover();
4323
4628
  dirty = false;
@@ -4364,7 +4669,7 @@ function lineChart(target, options, env2) {
4364
4669
  record.shown = placed2;
4365
4670
  const { geometry } = placed2;
4366
4671
  paint(record, seriesColors(colors.slot(record.series)), { visible: geometry.length >= VISIBLE2, open: { width: geometry.thickness } });
4367
- setAttributes(record.end, { cx: geometry.end.x, cy: geometry.end.y });
4672
+ setAttributes(record.end, { cx: geometry.end.x, cy: geometry.end.y, visibility: placed2.data.samples.length === 0 ? "hidden" : void 0 });
4368
4673
  const presence = record.presence.value;
4369
4674
  setAttributes(record.group, { opacity: presence < 1 ? presence : void 0 });
4370
4675
  if (moved) runner.change(geometry, placed2.data);
@@ -4386,11 +4691,21 @@ function lineChart(target, options, env2) {
4386
4691
  record.handle.repaint();
4387
4692
  if (before && recolored) surface.recolor(record.key);
4388
4693
  }
4694
+ let anyAlone = false;
4695
+ function paintAlone(states) {
4696
+ const lone = loneValues(states, laidOut.series);
4697
+ if (lone.size === 0 && !anyAlone) return;
4698
+ for (const point of points.values()) point.group.classList.toggle("ec-alone", lone.has(point.key));
4699
+ anyAlone = lone.size > 0;
4700
+ }
4389
4701
  function paintColumns(frame, states) {
4390
4702
  const { x } = positions(frame);
4391
4703
  const shown = states.filter(({ record }) => revealed(record));
4392
4704
  const columns = placeColumns(frame, shown.map(({ state }) => x(state.x)));
4393
- shown.forEach(({ record }, i) => setAttributes(record.hit, { ...columns[i] }));
4705
+ shown.forEach(({ record, state }, i) => {
4706
+ setAttributes(record.hit, { ...columns[i] });
4707
+ record.px = x(state.x);
4708
+ });
4394
4709
  const visible = new Set(shown.map(({ record }) => record));
4395
4710
  for (const record of [...rowOrder, ...leavingRows.values()]) {
4396
4711
  const show3 = visible.has(record);
@@ -4409,10 +4724,9 @@ function lineChart(target, options, env2) {
4409
4724
  }
4410
4725
  function showHover(key) {
4411
4726
  const record = rows2.get(key);
4412
- const marks = record && revealed(record) ? livePoints(record) : [];
4413
- const first = marks[0];
4414
- if (!record || !first) return;
4415
- const x = first.shown.geometry.center.x;
4727
+ if (!record || !revealed(record)) return;
4728
+ const marks = livePoints(record);
4729
+ const x = marks[0]?.shown.geometry.center.x ?? record.px;
4416
4730
  setAttributes(crosshair, { ...placeCrosshair(drawnFrame, x), visibility: void 0 });
4417
4731
  const ys = marks.map((point) => {
4418
4732
  const { transform } = point.handle.style;
@@ -4420,19 +4734,26 @@ function lineChart(target, options, env2) {
4420
4734
  return (transform ? matrix.apply(transform, center) : center).y;
4421
4735
  });
4422
4736
  const { row } = record;
4423
- tooltip.showAt(
4424
- { x, top: Math.min(...ys) - DOT_RADIUS, bottom: Math.max(...ys) + DOT_RADIUS },
4425
- row,
4426
- () => summaryContent(row.label, labelled2(row.values, current), format(current), { total: false })
4427
- );
4737
+ 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 };
4738
+ tooltip.showAt({ x, ...at }, row, () => summary(row, current));
4428
4739
  }
4429
4740
  function hideHover() {
4430
4741
  crosshair.setAttribute("visibility", "hidden");
4431
4742
  tooltip.hide();
4432
4743
  }
4744
+ let ringLine;
4433
4745
  function drawRing(key) {
4434
4746
  const record = key === void 0 ? void 0 : rows2.get(key);
4435
- const marks = record && revealed(record) ? livePoints(record) : [];
4747
+ const live = record !== void 0 && revealed(record);
4748
+ const marks = live ? livePoints(record) : [];
4749
+ if (live && marks.length === 0) {
4750
+ ringLine ?? (ringLine = svgElement("line", { class: "ec-focus-ring", "stroke-width": RING3 }, ring));
4751
+ if (ring.childElementCount > 1 || ring.firstElementChild !== ringLine) ring.replaceChildren(ringLine);
4752
+ setAttributes(ringLine, placeCrosshair(drawnFrame, record.px));
4753
+ ring.removeAttribute("visibility");
4754
+ return;
4755
+ }
4756
+ ringLine?.remove();
4436
4757
  while (ring.childElementCount > marks.length) ring.lastElementChild.remove();
4437
4758
  marks.forEach((point, i) => {
4438
4759
  let group = ring.children[i];
@@ -4473,6 +4794,17 @@ function lineChart(target, options, env2) {
4473
4794
  return record !== void 0 && revealed(record);
4474
4795
  },
4475
4796
  order: () => rowOrder.filter(revealed).map((record) => record.key),
4797
+ // On a time axis a page is a calendar month in its zone: the first x a month or more on, or back,
4798
+ // or the last one that way. On numbers it's the keyboard's own.
4799
+ page(key, by) {
4800
+ const from = rows2.get(key);
4801
+ if (!laidOut.time || !from) return void 0;
4802
+ const stops = rowOrder.filter(revealed);
4803
+ const to = monthsOn(from.row.x, by, lineEncoding(current).timeZone);
4804
+ if (by > 0) return (stops.find((record) => record.row.x >= to) ?? stops[stops.length - 1])?.key;
4805
+ for (let i = stops.length - 1; i >= 0; i--) if (stops[i].row.x <= to) return stops[i].key;
4806
+ return stops[0]?.key;
4807
+ },
4476
4808
  marks: (key) => {
4477
4809
  const record = rows2.get(key);
4478
4810
  return record ? livePoints(record).map((point) => point.key) : [];
@@ -4484,7 +4816,7 @@ function lineChart(target, options, env2) {
4484
4816
  return record && onScreen(record);
4485
4817
  },
4486
4818
  ring: drawRing,
4487
- tooltip: { show: showHover, hide: hideHover }
4819
+ tooltip: { show: showHover, hide: hideHover, element: () => tooltip.element() }
4488
4820
  });
4489
4821
  const syncLegend = () => legend.update(
4490
4822
  laidOut.series.map((series) => ({ series, label: seriesLabel(current.seriesLabels, series) })),
@@ -4498,7 +4830,7 @@ function lineChart(target, options, env2) {
4498
4830
  category: typeof opts.x === "string" ? opts.x : void 0,
4499
4831
  series: next.series,
4500
4832
  label: (series) => seriesLabel(opts.seriesLabels, series),
4501
- rows: next.rows.map((row) => ({ key: row.key, category: row.label, datum: row.datum, index: row.index, values: row.values, total: total(row.values) })),
4833
+ 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) })),
4502
4834
  format: format(opts),
4503
4835
  total: false
4504
4836
  });
@@ -4528,8 +4860,8 @@ function lineChart(target, options, env2) {
4528
4860
  }
4529
4861
  const key = (record) => record.key;
4530
4862
  try {
4531
- const said = option({ text: text2, changed: values.map(key), added: added.map(key), removed: removed.map(key) });
4532
- if (said !== void 0 && said !== null) announcer.say(String(said));
4863
+ const said2 = option({ text: text2, changed: values.map(key), added: added.map(key), removed: removed.map(key) });
4864
+ if (said2 !== void 0 && said2 !== null) announcer.say(String(said2));
4533
4865
  } catch (error) {
4534
4866
  report(error);
4535
4867
  }
@@ -4543,17 +4875,19 @@ function lineChart(target, options, env2) {
4543
4875
  const changes = { changed: [], added: [], removed: [] };
4544
4876
  const before = rowOrder;
4545
4877
  const was = new Map(before.map((record) => [record, record.row]));
4878
+ const nextRows = new Map(next.rows.map((row) => [row.key, row]));
4546
4879
  const exitingLines = lineOrder.filter((line) => !series.includes(line.series));
4547
4880
  const exitingPoints = [];
4548
4881
  for (const record of before) {
4549
4882
  const goes = !keys.has(record.key);
4883
+ const missing = nextRows.get(record.key)?.missing;
4550
4884
  if (goes) {
4551
4885
  rows2.delete(record.key);
4552
4886
  record.leaving = true;
4553
4887
  leavingRows.set(record.key, record);
4554
4888
  changes.removed.push(record);
4555
4889
  }
4556
- for (const point of livePoints(record)) if (goes || !series.includes(point.series)) exitingPoints.push(point);
4890
+ for (const point of livePoints(record)) if (goes || !series.includes(point.series) || missing?.has(point.series)) exitingPoints.push(point);
4557
4891
  }
4558
4892
  for (const line of exitingLines) lines.delete(line.series);
4559
4893
  for (const point of exitingPoints) points.delete(point.key);
@@ -4572,7 +4906,7 @@ function lineChart(target, options, env2) {
4572
4906
  leavingRows.delete(row.key);
4573
4907
  record.leaving = false;
4574
4908
  record.x.set(row.x);
4575
- record.values.set(valuesOf2(row.values));
4909
+ record.values.set(row.levels);
4576
4910
  rows2.set(row.key, record);
4577
4911
  changes.added.push(record);
4578
4912
  rowsMoved = true;
@@ -4602,7 +4936,7 @@ function lineChart(target, options, env2) {
4602
4936
  });
4603
4937
  for (const record of rowOrder) {
4604
4938
  const old = stayed.has(record) ? was.get(record) : void 0;
4605
- const live = series.map((name) => {
4939
+ const live = series.filter((name) => !record.row.missing.has(name)).map((name) => {
4606
4940
  const key = pointKey(name, record.key);
4607
4941
  const target2 = placed2.points.get(key);
4608
4942
  let point = points.get(key);
@@ -4618,7 +4952,7 @@ function lineChart(target, options, env2) {
4618
4952
  return point;
4619
4953
  });
4620
4954
  const kept = new Set(live);
4621
- record.points = [...live, ...record.points.filter((point) => !kept.has(point) && drawn(point))];
4955
+ record.points = [...live, ...record.points.filter((point) => !kept.has(point) && drawn2(point))];
4622
4956
  }
4623
4957
  for (const record of rowOrder) labelColumn(record);
4624
4958
  orderElements(
@@ -4650,7 +4984,7 @@ function lineChart(target, options, env2) {
4650
4984
  for (const tick of next.xTicks) xTicks.get(tick.value).text = tick.label.text;
4651
4985
  const goingLines = leavingLines();
4652
4986
  const folding = [...leavingRows.values()];
4653
- const values = busy(scale, frame.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((line) => busy(line.presence, 1, same)) || goingLines.some((line) => busy(line.presence, 0, same));
4987
+ const values = busy(scale, frame.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((line) => busy(line.presence, 1, same)) || goingLines.some((line) => busy(line.presence, 0, same));
4654
4988
  const positions2 = busy(box, frame.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));
4655
4989
  let first;
4656
4990
  let second;
@@ -4671,7 +5005,7 @@ function lineChart(target, options, env2) {
4671
5005
  for (const tick of yTicks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, first);
4672
5006
  for (const tick of xTicks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, second);
4673
5007
  for (const record of rowOrder) {
4674
- move(record.values, valuesOf2(record.row.values), sameFields, first);
5008
+ move(record.values, record.row.levels, sameFields, first);
4675
5009
  move(record.x, record.row.x, same, second);
4676
5010
  move(record.presence, 1, same, record.anchor ? second : void 0);
4677
5011
  }
@@ -4729,7 +5063,7 @@ function lineChart(target, options, env2) {
4729
5063
  rowOrder = laidOut.rows.map((row) => {
4730
5064
  const record = createRow(row, false);
4731
5065
  rows2.set(row.key, record);
4732
- record.points = laidOut.series.map((name) => {
5066
+ record.points = laidOut.series.filter((name) => !row.missing.has(name)).map((name) => {
4733
5067
  const point = createPoint(record, placed2.points.get(pointKey(name, row.key)));
4734
5068
  points.set(point.key, point);
4735
5069
  return point;
@@ -4779,6 +5113,7 @@ function lineChart(target, options, env2) {
4779
5113
  leaving,
4780
5114
  input,
4781
5115
  onScreen,
5116
+ data: "data" in next,
4782
5117
  ...swapping ? {
4783
5118
  swap: (diff) => {
4784
5119
  const entering = new Set(diff.entering);
@@ -4851,16 +5186,16 @@ function lineChart(target, options, env2) {
4851
5186
  });
4852
5187
  }
4853
5188
  function restState(row) {
4854
- return { key: row.key, datum: row.datum, x: row.x, values: valuesOf2(row.values) };
5189
+ return { key: row.key, datum: row.datum, x: row.x, values: row.levels, missing: row.missing };
4855
5190
  }
4856
- function valuesOf2(values) {
4857
- return Object.fromEntries(values.map((v) => [v.series, v.value]));
5191
+ function present(values) {
5192
+ return values.flatMap((v) => v.value === void 0 ? [] : [{ series: v.series, value: v.value }]);
4858
5193
  }
4859
5194
  function valueIn(row, series) {
4860
5195
  return row.values.find((v) => v.series === series)?.value;
4861
5196
  }
4862
5197
  function total(values) {
4863
- return values.reduce((sum, v) => sum + v.value, 0);
5198
+ return values.reduce((sum, v) => sum + (v.value ?? 0), 0);
4864
5199
  }
4865
5200
  function nearest(order, i, among) {
4866
5201
  for (let j = i - 1; j >= 0; j--) if (among.has(order[j])) return order[j];
@@ -4874,21 +5209,32 @@ function sameData(a, b) {
4874
5209
  if (a.datum !== b.datum || a.samples.length !== b.samples.length) return false;
4875
5210
  return a.samples.every((s, i) => {
4876
5211
  const o = b.samples[i];
4877
- return s.t === o.t && s.value === o.value && sameAt(s.at, o.at);
5212
+ return s.t === o.t && s.value === o.value && sameAt(s.at, o.at) && s.gapBefore === o.gapBefore;
4878
5213
  });
4879
5214
  }
4880
5215
  function sameAt(a, b) {
4881
5216
  return a === b || a instanceof Date && b instanceof Date && a.getTime() === b.getTime();
4882
5217
  }
4883
5218
  function labelled2(values, options) {
4884
- return values.map((v) => ({ series: v.series, label: seriesLabel(options.seriesLabels, v.series), value: v.value }));
5219
+ return present(values).map((v) => ({ series: v.series, label: seriesLabel(options.seriesLabels, v.series), value: v.value }));
5220
+ }
5221
+ function said(values, options) {
5222
+ const formatted = format(options);
5223
+ return values.map((v) => {
5224
+ const label2 = seriesLabel(options.seriesLabels, v.series);
5225
+ return v.value === void 0 ? `${label2} missing` : `${formatted(v.value)} ${label2}`;
5226
+ });
5227
+ }
5228
+ function summary(row, options) {
5229
+ if (row.missing.size === 0) return summaryContent(row.label, labelled2(row.values, options), format(options), { total: false });
5230
+ return { title: row.label, lines: [said(row.values, options).join(" \xB7 ")] };
4885
5231
  }
4886
5232
  function namesFor2(options, layout) {
4887
5233
  const formatted = format(options);
4888
5234
  return new Map(
4889
5235
  layout.rows.map((row) => {
4890
5236
  const values = labelled2(row.values, options);
4891
- const text2 = `${row.label}: ${values.map((v) => `${formatted(v.value)} ${v.label}`).join(", ")}`;
5237
+ const text2 = `${row.label}: ${said(row.values, options).join(", ")}`;
4892
5238
  if (!options.markLabel) return [row.key, text2];
4893
5239
  try {
4894
5240
  const named = options.markLabel(row.datum, { key: row.key, category: row.label, values, total: total(row.values), format: formatted, text: text2 });
@@ -4927,20 +5273,20 @@ function baselines(boxes, option) {
4927
5273
  }
4928
5274
  return found;
4929
5275
  }
4930
- function describeRects(key, parts, baseline) {
4931
- const box = union(parts.map((part) => part.box));
4932
- const span = spanFrom(box, baseline);
4933
- 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);
5276
+ function describeRects(key, parts2, baseline) {
5277
+ const box = union(parts2.map((part) => part.box));
5278
+ const span2 = spanFrom(box, baseline);
5279
+ 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);
4934
5280
  let reached = 0;
4935
5281
  let gap = Infinity;
4936
5282
  const segments = order.map(({ index, near, far }) => {
4937
5283
  if (reached > 0 && far > near) gap = Math.min(gap, near - reached);
4938
5284
  const size = Math.max(0, far - reached);
4939
5285
  reached = Math.max(reached, far);
4940
- return { series: parts[index].series, size };
5286
+ return { series: parts2[index].series, size };
4941
5287
  });
4942
- const tip = parts[order[order.length - 1].index];
4943
- const single = parts.length === 1 ? parts[0].series : void 0;
5288
+ const tip = parts2[order[order.length - 1].index];
5289
+ const single = parts2.length === 1 ? parts2[0].series : void 0;
4944
5290
  const geometry = describe.bar({
4945
5291
  key,
4946
5292
  ...single === void 0 ? {} : { series: single },
@@ -5165,13 +5511,13 @@ function round3(value) {
5165
5511
  }
5166
5512
 
5167
5513
  // src/charts/adapter/host-style.ts
5168
- function hostMarkHandle(parts, edits, halos) {
5514
+ function hostMarkHandle(parts2, edits, halos) {
5169
5515
  let style = {};
5170
5516
  let hot = false;
5171
5517
  const halo = maskedHalo();
5172
5518
  const repaint = () => {
5173
5519
  const { transform, opacity, emphasis } = style;
5174
- for (const part of parts()) {
5520
+ for (const part of parts2()) {
5175
5521
  const { element, colors } = part;
5176
5522
  const moved = transform && part.parentInverse ? matrix.multiply(part.parentInverse, transform, part.parent, ownTransform(element)) : void 0;
5177
5523
  edits.style(element, "transform", moved && cssMatrix(moved));
@@ -5186,7 +5532,7 @@ function hostMarkHandle(parts, edits, halos) {
5186
5532
  paintHalo();
5187
5533
  };
5188
5534
  const paintHalo = () => {
5189
- const visible = parts().flatMap((part) => part.outline === void 0 ? [] : [{ ...part.outline, color: part.colors?.color }]);
5535
+ const visible = parts2().flatMap((part) => part.outline === void 0 ? [] : [{ ...part.outline, color: part.colors?.color }]);
5190
5536
  halo.paint(halos(), visible, style.halo, style.transform);
5191
5537
  };
5192
5538
  return {
@@ -5415,8 +5761,8 @@ function expressive(target, options, env2) {
5415
5761
  if (typeof geometry !== "object" || geometry === null || geometry.key !== key) {
5416
5762
  throw new TypeError(`expressive: geometry for "${key}" must be a MarkGeometry with the key "${key}". Build it with describe and the key passed in.`);
5417
5763
  }
5418
- const parts = pieces.map((p) => part(p, outlineOf(geometry, p.series, pieces.length), at));
5419
- return { key, geometry, parts, index };
5764
+ const parts2 = pieces.map((p) => part(p, outlineOf(geometry, p.series, pieces.length), at));
5765
+ return { key, geometry, parts: parts2, index };
5420
5766
  }
5421
5767
  function rectPiece(key, piece, at) {
5422
5768
  if (piece.element.localName !== "rect") {
@@ -5431,11 +5777,11 @@ function expressive(target, options, env2) {
5431
5777
  function rectMark(key, pieces, edge, index, at) {
5432
5778
  const { geometry, order: order2 } = describeRects(key, pieces.map((p) => p.rect), edge);
5433
5779
  const segments = geometry.segments ?? [];
5434
- const parts = order2.map((j, n) => {
5780
+ const parts2 = order2.map((j, n) => {
5435
5781
  const segment = segments[n];
5436
5782
  return part(pieces[j], segment && segment.length >= 0.5 ? { d: segment.outline.d } : void 0, at);
5437
5783
  });
5438
- return { key, geometry, parts, index, rect: { edge, box: union(pieces.map((p) => p.rect.box)) } };
5784
+ return { key, geometry, parts: parts2, index, rect: { edge, box: union(pieces.map((p) => p.rect.box)) } };
5439
5785
  }
5440
5786
  function part(piece, outline2, at) {
5441
5787
  const parent = between(at.common, piece.element.parentElement ?? at.svg, at.svg, at.screen);
@@ -5443,8 +5789,8 @@ function expressive(target, options, env2) {
5443
5789
  }
5444
5790
  function withData(marks) {
5445
5791
  return marks.map((mark) => {
5446
- const { key, geometry, parts } = mark;
5447
- const total2 = mark.rect ? totalOf(parts) : void 0;
5792
+ const { key, geometry, parts: parts2 } = mark;
5793
+ const total2 = mark.rect ? totalOf(parts2) : void 0;
5448
5794
  const samplesOf = (datum, of, series) => {
5449
5795
  if (options.samples) return checkSamples(options.samples(datum, of), series === void 0 ? `"${key}"` : `"${key}" (${series})`);
5450
5796
  return total2 === void 0 ? [] : barSamples(geometry, of, total2);
@@ -5452,10 +5798,10 @@ function expressive(target, options, env2) {
5452
5798
  const own2 = /* @__PURE__ */ new Map();
5453
5799
  const related = (series) => own2.get(series) ?? relatedOf(series, key);
5454
5800
  for (const series of ownSeries(mark)) {
5455
- const datum = (parts.find((p) => p.series === series) ?? parts[0]).datum;
5801
+ const datum = (parts2.find((p) => p.series === series) ?? parts2[0]).datum;
5456
5802
  own2.set(series, { datum, samples: samplesOf(datum, geometry.segments?.find((s) => s.series === series) ?? geometry, series), related });
5457
5803
  }
5458
- return { ...mark, data: { datum: parts[0].datum, samples: samplesOf(parts[0].datum, geometry), related } };
5804
+ return { ...mark, data: { datum: parts2[0].datum, samples: samplesOf(parts2[0].datum, geometry), related } };
5459
5805
  });
5460
5806
  }
5461
5807
  function checkNeeds3(marks) {
@@ -5490,10 +5836,10 @@ function expressive(target, options, env2) {
5490
5836
  if (series === void 0 || series === null || series === "") throw new TypeError(`expressive: segment returned ${String(series)} for a part of "${key}".`);
5491
5837
  return String(series);
5492
5838
  }
5493
- function labelOf(key, parts) {
5839
+ function labelOf(key, parts2) {
5494
5840
  if (!options.markLabel) return void 0;
5495
5841
  try {
5496
- const text2 = String(options.markLabel(parts[0].datum, { key, parts: parts.map(({ series, datum }) => ({ series, datum })) }) ?? "");
5842
+ const text2 = String(options.markLabel(parts2[0].datum, { key, parts: parts2.map(({ series, datum }) => ({ series, datum })) }) ?? "");
5497
5843
  return text2.trim() === "" ? void 0 : text2;
5498
5844
  } catch (error) {
5499
5845
  report(error);
@@ -5559,7 +5905,7 @@ function expressive(target, options, env2) {
5559
5905
  if (reading.root && reading.root !== root) moveTo(reading.root);
5560
5906
  ancestor = reading.ancestor ?? ancestor;
5561
5907
  const keys = new Set(reading.marks.map((mark) => mark.key));
5562
- const diff = { entering: [], exiting: [], changed: [], moved: [] };
5908
+ const diff = { entering: [], exiting: [], changed: [], moved: [], newRow: false };
5563
5909
  const recolor = [];
5564
5910
  for (const record of order) {
5565
5911
  if (keys.has(record.key)) continue;
@@ -5574,8 +5920,10 @@ function expressive(target, options, env2) {
5574
5920
  if (record) {
5575
5921
  const from = record.mark;
5576
5922
  const changed = options.value ? valuesChanged2(from.parts, mark.parts) : lengthsChanged(from.geometry, mark.geometry);
5923
+ const newRow = from.data.datum !== mark.data.datum;
5924
+ if (newRow) diff.newRow = true;
5577
5925
  if (changed) diff.changed.push({ record, from: from.geometry });
5578
- else if (geometryChanged2(from.geometry, mark.geometry) || from.data.datum !== mark.data.datum || samplesChanged(from.data.samples, mark.data.samples)) {
5926
+ else if (newRow || geometryChanged2(from.geometry, mark.geometry) || samplesChanged(from.data.samples, mark.data.samples)) {
5579
5927
  diff.moved.push(record);
5580
5928
  }
5581
5929
  if (from.parts[0]?.colors?.color !== mark.parts[0]?.colors?.color) recolor.push(mark.key);
@@ -5606,8 +5954,8 @@ function expressive(target, options, env2) {
5606
5954
  }
5607
5955
  function nameMark(record) {
5608
5956
  if (!options.markLabel) return;
5609
- const { label: label2, parts } = record.mark;
5610
- parts.forEach((part2, index) => {
5957
+ const { label: label2, parts: parts2 } = record.mark;
5958
+ parts2.forEach((part2, index) => {
5611
5959
  const named = label2 !== void 0 && index === 0;
5612
5960
  edits.attribute(part2.element, "role", named ? "img" : null);
5613
5961
  edits.attribute(part2.element, "aria-label", named ? label2 : null);
@@ -5823,7 +6171,7 @@ function expressive(target, options, env2) {
5823
6171
  function reread(changed) {
5824
6172
  const at = { svg: root, common: ancestor, screen: screenMatrices(), colors: (element) => owners.get(element)?.part.colors };
5825
6173
  const rowOf = rowsNow();
5826
- const piecesOf = ({ parts }) => parts.map((part2) => ({ element: part2.element, datum: rowOf(part2.element), series: part2.series, value: part2.value }));
6174
+ const piecesOf = ({ parts: parts2 }) => parts2.map((part2) => ({ element: part2.element, datum: rowOf(part2.element), series: part2.series, value: part2.value }));
5827
6175
  if (options.geometry) {
5828
6176
  const marks2 = changed.map(({ mark }) => ({ ...shapeMark(mark.key, piecesOf(mark), mark.index, at), label: mark.label }));
5829
6177
  return { records: [...changed], marks: withData(marks2) };
@@ -5912,7 +6260,9 @@ function expressive(target, options, env2) {
5912
6260
  dropGone();
5913
6261
  const exited = runner.exit(diff.exiting.map(input));
5914
6262
  emitEach("exit", diff.exiting);
5915
- runner.update(diff.changed.map(({ record, from }) => ({ ...input(record), from })));
6263
+ if (diff.newRow || diff.changed.length > 0 || diff.entering.length > 0 || diff.exiting.length > 0) {
6264
+ runner.update(diff.changed.map(({ record, from }) => ({ ...input(record), from })));
6265
+ }
5916
6266
  diff.changed.forEach(({ record, from }, index) => emit("update", { ...input(record), from, batch: { index, count: diff.changed.length } }));
5917
6267
  runner.enter(diff.entering.map(input));
5918
6268
  emitEach("enter", diff.entering);
@@ -5975,9 +6325,9 @@ function ownSeries(mark) {
5975
6325
  const names = [...(mark.geometry.segments ?? []).map((s) => s.series), ...mark.parts.map((p) => p.series)];
5976
6326
  return [...new Set(names.filter((name) => name !== void 0))];
5977
6327
  }
5978
- function totalOf(parts) {
6328
+ function totalOf(parts2) {
5979
6329
  let total2 = 0;
5980
- for (const { value } of parts) {
6330
+ for (const { value } of parts2) {
5981
6331
  if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
5982
6332
  total2 += value;
5983
6333
  }
@@ -6001,14 +6351,17 @@ function checkSamples(samples, mark) {
6001
6351
  if (!Array.isArray(samples)) throw new TypeError(`expressive: samples for ${mark} must return an array of { t, value }, got ${describeValue2(samples)}.`);
6002
6352
  let last = 0;
6003
6353
  return samples.map((sample, i) => {
6004
- const { t, value, at } = typeof sample === "object" && sample !== null ? sample : {};
6354
+ const { t, value, at, gapBefore } = typeof sample === "object" && sample !== null ? sample : {};
6005
6355
  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)}.`);
6006
6356
  if (t < last) throw new RangeError(`expressive: samples for ${mark} must be in t order: samples[${i}].t is ${t}, after ${last}.`);
6007
6357
  if (typeof value !== "number" || !Number.isFinite(value)) {
6008
6358
  throw new RangeError(`expressive: samples for ${mark}: samples[${i}].value must be a finite number, got ${describeValue2(value)}.`);
6009
6359
  }
6360
+ if (gapBefore !== void 0 && typeof gapBefore !== "boolean") {
6361
+ throw new RangeError(`expressive: samples for ${mark}: samples[${i}].gapBefore must be true or false, got ${describeValue2(gapBefore)}.`);
6362
+ }
6010
6363
  last = t;
6011
- return at === void 0 ? { t, value } : { t, value, at };
6364
+ return { t, value, ...at === void 0 ? {} : { at }, ...gapBefore ? { gapBefore } : {} };
6012
6365
  });
6013
6366
  }
6014
6367
  function describeValue2(value) {
@@ -6029,9 +6382,9 @@ function ringOrder(marks, geometryOf) {
6029
6382
  function distance2(a, b) {
6030
6383
  return Math.hypot(a.x - b.x, a.y - b.y);
6031
6384
  }
6032
- function outlineOf(geometry, series, parts) {
6385
+ function outlineOf(geometry, series, parts2) {
6033
6386
  const segment = series === void 0 ? void 0 : geometry.segments?.find((s) => s.series === series);
6034
- const shape = segment ?? (parts === 1 ? geometry : void 0);
6387
+ const shape = segment ?? (parts2 === 1 ? geometry : void 0);
6035
6388
  if (!shape || segment && segment.length < 0.5) return void 0;
6036
6389
  return shape.outline.closed ? { d: shape.outline.d } : { d: shape.outline.d, stroke: shape.thickness };
6037
6390
  }
@@ -6108,7 +6461,7 @@ function fromVegaView(view, options, env2) {
6108
6461
  let observed;
6109
6462
  let stopFrame;
6110
6463
  let destroyed = false;
6111
- const observer = typeof MutationObserver === "function" ? new MutationObserver((records) => records.some(drawn) && schedule()) : void 0;
6464
+ const observer = typeof MutationObserver === "function" ? new MutationObserver((records) => records.some(drawn2) && schedule()) : void 0;
6112
6465
  observe(current.root);
6113
6466
  function itemOf(element) {
6114
6467
  const item = current.items.get(element);
@@ -6171,12 +6524,12 @@ function fromVegaView(view, options, env2) {
6171
6524
  const elements = [];
6172
6525
  for (const i of visualOrder(boxes, edges)) {
6173
6526
  const key = keys[i];
6174
- const parts = groups.get(key);
6175
- const { geometry, order } = describeRects(key, parts.map((p) => p.part), edges[i]);
6527
+ const parts2 = groups.get(key);
6528
+ const { geometry, order } = describeRects(key, parts2.map((p) => p.part), edges[i]);
6176
6529
  read.geometry.set(key, geometry);
6177
- elements.push(...order.map((j) => parts[j].element));
6530
+ elements.push(...order.map((j) => parts2[j].element));
6178
6531
  if (options.sample) {
6179
- const values = order.map((j) => valueOf(read.items.get(parts[j].element)).value);
6532
+ const values = order.map((j) => valueOf(read.items.get(parts2[j].element)).value);
6180
6533
  const total2 = values.reduce((sum, v) => sum + v, 0);
6181
6534
  read.samples.set(geometry, [{ t: 0, value: 0 }, { t: 1, value: total2 }]);
6182
6535
  let reached = 0;
@@ -6208,7 +6561,7 @@ function fromVegaView(view, options, env2) {
6208
6561
  const end = at === void 0 ? { t: 1, value } : { t: 1, value, at };
6209
6562
  return type === "symbol" ? [{ ...end, t: 0 }] : geometry.length > 0 ? [{ t: 0, value: 0 }, end] : [{ ...end, t: 0 }];
6210
6563
  }
6211
- function drawn(record) {
6564
+ function drawn2(record) {
6212
6565
  const overlay = observed?.querySelector(":scope > .ec-overlay");
6213
6566
  const ours = (node) => node === overlay || (overlay?.contains(node) ?? false);
6214
6567
  if (ours(record.target)) return false;
@@ -6579,12 +6932,12 @@ function chartSwitch(target, options, env2) {
6579
6932
  if (!memory) return;
6580
6933
  const now = focused();
6581
6934
  if (now && now !== doc.body && now !== doc.documentElement && !wrapper.contains(now)) return;
6582
- const inside = () => to.chart.element.contains(focused());
6935
+ const inside3 = () => to.chart.element.contains(focused());
6583
6936
  if (memory.key !== void 0) to.chart.focus(memory.key);
6584
- if (inside()) return;
6937
+ if (inside3()) return;
6585
6938
  for (const mark of to.chart.marks()) {
6586
6939
  to.chart.focus(mark.key);
6587
- if (inside()) return;
6940
+ if (inside3()) return;
6588
6941
  }
6589
6942
  }
6590
6943
  function say(to) {
@@ -7100,7 +7453,7 @@ function travel(icon, options = {}) {
7100
7453
  const resolved = typeof icon === "string" ? ctx.icons.get(icon) : icon;
7101
7454
  if (!resolved) throw new RangeError(`travel: unknown icon "${String(icon)}". Register it with registerIcon(icon), or pass the icon itself.`);
7102
7455
  const walk = pick(mark, options.along);
7103
- if (!walk || !(walk.length >= MIN_WALK)) return void 0;
7456
+ if (!walk || !(drawn(walk) >= MIN_WALK)) return void 0;
7104
7457
  const scale = options.size === void 0 ? 1 : options.size === "fit" ? FIT * walk.thickness / resolved.box.height : options.size / resolved.size;
7105
7458
  if (!(scale > 0)) return void 0;
7106
7459
  return trip(walk, resolved, scale, options);
@@ -7108,18 +7461,18 @@ function travel(icon, options = {}) {
7108
7461
  function rider(mark, ctx) {
7109
7462
  let current = plan(mark, ctx);
7110
7463
  let handle;
7111
- let drawn;
7464
+ let drawn2;
7112
7465
  let progress = 0;
7113
7466
  const draw = () => {
7114
7467
  if (!current) {
7115
7468
  handle?.remove();
7116
- handle = drawn = void 0;
7469
+ handle = drawn2 = void 0;
7117
7470
  return;
7118
7471
  }
7119
- if (!handle || drawn?.icon !== current.icon || drawn.size !== current.size) {
7472
+ if (!handle || drawn2?.icon !== current.icon || drawn2.size !== current.size) {
7120
7473
  handle?.remove();
7121
7474
  handle = ctx.layer.icon(current.icon, { size: current.size });
7122
- drawn = { icon: current.icon, size: current.size };
7475
+ drawn2 = { icon: current.icon, size: current.size };
7123
7476
  }
7124
7477
  handle.place(current.transform(progress));
7125
7478
  };
@@ -7166,7 +7519,12 @@ function trip(walk, icon, scale, options) {
7166
7519
  const length = walk.length;
7167
7520
  const behind = icon.footprint[0] * scale;
7168
7521
  const ahead = icon.footprint[1] * scale;
7169
- const span = Math.max(0, length - behind - ahead);
7522
+ let span2 = 0;
7523
+ const legs = parts(walk).map(([from, to]) => {
7524
+ const leg = { from, to, span: Math.max(0, to - from - behind - ahead), before: span2 };
7525
+ span2 += leg.span;
7526
+ return leg;
7527
+ });
7170
7528
  const smoothing = Math.max(MIN_SMOOTHING, (behind + ahead) / 2);
7171
7529
  const radius = icon.radius ?? icon.box.height / 2;
7172
7530
  const { anchor } = icon;
@@ -7176,14 +7534,18 @@ function trip(walk, icon, scale, options) {
7176
7534
  return {
7177
7535
  icon,
7178
7536
  size: icon.size * scale,
7179
- span,
7180
- duration: Math.min(LONGEST2, Math.max(SHORTEST, span / SPEED * 1e3) * (gait.pace ?? 1)),
7537
+ span: span2,
7538
+ duration: Math.min(LONGEST2, Math.max(SHORTEST, span2 / SPEED * 1e3) * (gait.pace ?? 1)),
7181
7539
  gait,
7182
7540
  transform(progress) {
7183
- const distance3 = behind + progress * span;
7184
- const pose = gait({ distance: progress * span / scale, length: span / scale, progress, radius });
7541
+ const travelled = progress * span2;
7542
+ let index = legs.length - 1;
7543
+ while (index > 0 && legs[index].before > travelled) index--;
7544
+ const leg = legs[index];
7545
+ const distance3 = leg.from + behind + Math.min(leg.span, travelled - leg.before);
7546
+ const pose = gait({ distance: travelled / scale, length: span2 / scale, progress, radius });
7185
7547
  const at = pointAt(walk, distance3);
7186
- const direction = heading(walk, Math.min(distance3, length), smoothing);
7548
+ const direction = heading(walk, Math.min(distance3, length), smoothing, leg);
7187
7549
  const mirror = orient === "auto" && icon.upright === true && Math.cos(direction) < -1e-9;
7188
7550
  const turn2 = orient === "level" ? 0 : mirror ? normalizeAngle(direction - Math.PI) : direction;
7189
7551
  return matrix.multiply(
@@ -7201,16 +7563,31 @@ function pick(mark, along) {
7201
7563
  if (mark.segments) return mark.segments.find((segment) => segment.series === along);
7202
7564
  return mark.series === along ? mark : void 0;
7203
7565
  }
7566
+ function parts(walk) {
7567
+ const { length } = walk;
7568
+ const found = [];
7569
+ let at = 0;
7570
+ for (const [from, to] of walk.gaps ?? []) {
7571
+ if (!(to > from) || !(to > at)) continue;
7572
+ if (from > at) found.push([at * length, Math.min(1, from) * length]);
7573
+ at = Math.min(1, to);
7574
+ }
7575
+ found.push([at * length, length]);
7576
+ return found;
7577
+ }
7578
+ function drawn(walk) {
7579
+ return parts(walk).reduce((sum, [from, to]) => sum + (to - from), 0);
7580
+ }
7204
7581
  function pointAt(walk, distance3) {
7205
7582
  const { length } = walk;
7206
7583
  return distance3 <= length ? walk.path(distance3 / length) : offset(walk.end, walk.angle(1), distance3 - length);
7207
7584
  }
7208
- function heading(walk, distance3, window) {
7585
+ function heading(walk, distance3, window, leg) {
7209
7586
  const { length } = walk;
7210
- const reach = Math.min(window, distance3, length - distance3);
7211
- if (reach > 1e-6) {
7212
- const a = walk.path((distance3 - reach) / length);
7213
- const b = walk.path((distance3 + reach) / length);
7587
+ const reach2 = Math.min(window, distance3 - leg.from, leg.to - distance3);
7588
+ if (reach2 > 1e-6) {
7589
+ const a = walk.path((distance3 - reach2) / length);
7590
+ const b = walk.path((distance3 + reach2) / length);
7214
7591
  if (Math.hypot(b.x - a.x, b.y - a.y) > 1e-9) return Math.atan2(b.y - a.y, b.x - a.x);
7215
7592
  }
7216
7593
  return walk.angle(distance3 / length);
@@ -7332,10 +7709,10 @@ function wiggle(options = {}) {
7332
7709
  }
7333
7710
  function limit(mark, swing) {
7334
7711
  const { pivot } = mark;
7335
- let reach = 0;
7336
- for (const point of mark.outline.sample(SAMPLES)) reach = Math.max(reach, Math.hypot(point.x - pivot.x, point.y - pivot.y));
7337
- if (!(reach >= MIN_REACH)) return 0;
7338
- return Math.min(MAX_ANGLE, 2 * Math.asin(Math.min(1, swing / (2 * reach))));
7712
+ let reach2 = 0;
7713
+ for (const point of mark.outline.sample(SAMPLES)) reach2 = Math.max(reach2, Math.hypot(point.x - pivot.x, point.y - pivot.y));
7714
+ if (!(reach2 >= MIN_REACH)) return 0;
7715
+ return Math.min(MAX_ANGLE, 2 * Math.asin(Math.min(1, swing / (2 * reach2))));
7339
7716
  }
7340
7717
  function rock(t) {
7341
7718
  if (!(t > 0) || t >= 1) return 0;
@@ -7609,8 +7986,8 @@ function label(text2, options = {}) {
7609
7986
  const { color = "text" } = options;
7610
7987
  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)}.`);
7611
7988
  const words = (mark, data) => {
7612
- const said = text2(data, mark);
7613
- return said === void 0 || said === null ? void 0 : String(said);
7989
+ const said2 = text2(data, mark);
7990
+ return said2 === void 0 || said2 === null ? void 0 : String(said2);
7614
7991
  };
7615
7992
  return {
7616
7993
  kind: "data",
@@ -7638,15 +8015,15 @@ function threshold(options) {
7638
8015
  const paths = [];
7639
8016
  let latest = data;
7640
8017
  const draw = (current) => {
7641
- const parts = current.length >= MIN_WALK3 ? runs(latest.samples, reference(compareTo, latest), when) : [];
8018
+ const parts2 = current.length >= MIN_WALK3 ? runs(latest.samples, reference(compareTo, latest), when) : [];
7642
8019
  const paint = { stroke: color, width: current.thickness, linecap: "butt" };
7643
- parts.forEach(([t0, t1], i) => {
8020
+ parts2.forEach(([t0, t1], i) => {
7644
8021
  const d = current.slice(t0, t1);
7645
8022
  const path = paths[i];
7646
8023
  if (path) path.update(d, paint);
7647
8024
  else paths.push(ctx.layer.path(d, paint));
7648
8025
  });
7649
- for (const path of paths.splice(parts.length)) path.remove();
8026
+ for (const path of paths.splice(parts2.length)) path.remove();
7650
8027
  };
7651
8028
  ctx.onChange((next, nextData) => {
7652
8029
  latest = nextData ?? latest;
@@ -7672,7 +8049,37 @@ function reference(compareTo, data) {
7672
8049
  const byAt = data.samples.every((sample) => numeric2(sample.at) !== void 0) && related.samples.every((sample) => numeric2(sample.at) !== void 0);
7673
8050
  const place = byAt ? (sample) => numeric2(sample.at) : (sample) => sample.t;
7674
8051
  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);
7675
- return { place, valueAt: (u) => interpolate(points, u), bends: points.map((point) => point.u) };
8052
+ const gaps = gapsOf(related.samples, place);
8053
+ return { place, valueAt: (u) => inside2(gaps, u) ? void 0 : interpolate(points, u), bends: points.map((point) => point.u) };
8054
+ }
8055
+ function gapsOf(samples, place) {
8056
+ const gaps = [];
8057
+ samples.forEach((sample, i) => {
8058
+ const before = samples[i - 1];
8059
+ if (sample.gapBefore !== true || !before) return;
8060
+ const u = place(before);
8061
+ const v = place(sample);
8062
+ if (Number.isFinite(u) && Number.isFinite(v) && u !== v) gaps.push([Math.min(u, v), Math.max(u, v)]);
8063
+ });
8064
+ gaps.sort((a, b) => a[0] - b[0]);
8065
+ const merged = [];
8066
+ for (const gap of gaps) {
8067
+ const last = merged[merged.length - 1];
8068
+ if (last && gap[0] < last[1]) last[1] = Math.max(last[1], gap[1]);
8069
+ else merged.push(gap);
8070
+ }
8071
+ return merged;
8072
+ }
8073
+ function inside2(gaps, u) {
8074
+ let lo = 0;
8075
+ let hi = gaps.length;
8076
+ while (lo < hi) {
8077
+ const mid = lo + hi >> 1;
8078
+ if (gaps[mid][0] < u) lo = mid + 1;
8079
+ else hi = mid;
8080
+ }
8081
+ const gap = gaps[lo - 1];
8082
+ return gap !== void 0 && u < gap[1];
7676
8083
  }
7677
8084
  function numeric2(at) {
7678
8085
  const value = typeof at === "number" ? at : at instanceof Date ? at.getTime() : void 0;
@@ -7697,18 +8104,18 @@ function interpolate(points, u) {
7697
8104
  function runs(samples, ref, when) {
7698
8105
  if (!ref) return [];
7699
8106
  const sign = when === "below" ? 1 : -1;
7700
- const station = (t, u, value) => {
8107
+ const station = (t, u, value, joined = true) => {
7701
8108
  const level = ref.valueAt(u);
7702
- if (level === void 0 || !Number.isFinite(level) || !Number.isFinite(value) || !Number.isFinite(t)) return { t, past: void 0 };
8109
+ if (level === void 0 || !Number.isFinite(level) || !Number.isFinite(value) || !Number.isFinite(t)) return { t, u, past: void 0, joined };
7703
8110
  const past = sign * (level - value);
7704
- return { t, past: Math.abs(past) <= TIE2 * Math.max(Math.abs(level), Math.abs(value)) ? 0 : past };
8111
+ return { t, u, past: Math.abs(past) <= TIE2 * Math.max(Math.abs(level), Math.abs(value)) ? 0 : past, joined };
7705
8112
  };
7706
8113
  const stations = [];
7707
8114
  samples.forEach((sample, i) => {
7708
8115
  const u = ref.place(sample);
7709
- stations.push(station(sample.t, u, sample.value));
8116
+ stations.push(station(sample.t, u, sample.value, sample.gapBefore !== true));
7710
8117
  const next = samples[i + 1];
7711
- if (!next) return;
8118
+ if (!next || next.gapBefore === true) return;
7712
8119
  const v = ref.place(next);
7713
8120
  if (u === v || !Number.isFinite(u) || !Number.isFinite(v)) return;
7714
8121
  const shares = [];
@@ -7719,24 +8126,25 @@ function runs(samples, ref, when) {
7719
8126
  stations.push(station(sample.t + share * (next.t - sample.t), u + share * (v - u), sample.value + share * (next.value - sample.value)));
7720
8127
  }
7721
8128
  });
7722
- const parts = [];
8129
+ const parts2 = [];
7723
8130
  const add = (t0, t1) => {
7724
8131
  const from = clamp2(t0);
7725
8132
  const to = clamp2(t1);
7726
8133
  if (!(to > from)) return;
7727
- const last = parts[parts.length - 1];
8134
+ const last = parts2[parts2.length - 1];
7728
8135
  if (last && last[1] >= from) last[1] = Math.max(last[1], to);
7729
- else parts.push([from, to]);
8136
+ else parts2.push([from, to]);
7730
8137
  };
7731
8138
  for (let i = 1; i < stations.length; i++) {
7732
8139
  const a = stations[i - 1];
7733
8140
  const b = stations[i];
7734
- if (a.past === void 0 || b.past === void 0 || !(b.t > a.t)) continue;
8141
+ if (a.past === void 0 || b.past === void 0 || !b.joined || !(b.t > a.t)) continue;
8142
+ if (a.u !== b.u && ref.valueAt((a.u + b.u) / 2) === void 0) continue;
7735
8143
  if (a.past > 0 && b.past > 0) add(a.t, b.t);
7736
8144
  else if (a.past > 0) add(a.t, a.t + (b.t - a.t) * (a.past / (a.past - b.past)));
7737
8145
  else if (b.past > 0) add(a.t + (b.t - a.t) * (a.past / (a.past - b.past)), b.t);
7738
8146
  }
7739
- return parts;
8147
+ return parts2;
7740
8148
  }
7741
8149
  var clamp2 = (t) => Math.min(1, Math.max(0, t));
7742
8150
  function firstAbove(values, x) {
@@ -7880,18 +8288,18 @@ function checkOptions14(options) {
7880
8288
 
7881
8289
  // src/effects/combinators.ts
7882
8290
  function sequence(...effects) {
7883
- const parts = check("sequence", effects);
7884
- return combine(parts, async (start, ctx) => {
7885
- for (const part of parts) {
8291
+ const parts2 = check("sequence", effects);
8292
+ return combine(parts2, async (start, ctx) => {
8293
+ for (const part of parts2) {
7886
8294
  if (ctx.signal.aborted) return;
7887
8295
  await start(part);
7888
8296
  }
7889
8297
  });
7890
8298
  }
7891
8299
  function parallel(...effects) {
7892
- const parts = check("parallel", effects);
7893
- return combine(parts, async (start) => {
7894
- await Promise.all(parts.map(start));
8300
+ const parts2 = check("parallel", effects);
8301
+ return combine(parts2, async (start) => {
8302
+ await Promise.all(parts2.map(start));
7895
8303
  });
7896
8304
  }
7897
8305
  function only(filter, effect) {
@@ -7974,7 +8382,7 @@ function follow(mark, data, ctx) {
7974
8382
  });
7975
8383
  return () => latest;
7976
8384
  }
7977
- function combine(parts, play) {
8385
+ function combine(parts2, play) {
7978
8386
  const starter = (mark, data, ctx) => {
7979
8387
  const now = follow(mark, data, ctx);
7980
8388
  return (part) => {
@@ -7983,14 +8391,14 @@ function combine(parts, play) {
7983
8391
  };
7984
8392
  };
7985
8393
  const end = (mark, data, ctx) => {
7986
- for (const part of parts) {
8394
+ for (const part of parts2) {
7987
8395
  if (part.kind === "data") part.end(mark, data, ctx);
7988
8396
  else part.end(mark, ctx);
7989
8397
  }
7990
8398
  };
7991
8399
  const clear = (ctx) => {
7992
8400
  let failure;
7993
- for (const part of parts) {
8401
+ for (const part of parts2) {
7994
8402
  try {
7995
8403
  part.clear(ctx);
7996
8404
  } catch (error) {
@@ -7999,8 +8407,8 @@ function combine(parts, play) {
7999
8407
  }
8000
8408
  if (failure) throw failure.error;
8001
8409
  };
8002
- if (parts.some((part) => part.kind === "data")) {
8003
- const related = [...new Set(parts.flatMap((part) => part.kind === "data" ? part.needs?.related ?? [] : []))];
8410
+ if (parts2.some((part) => part.kind === "data")) {
8411
+ const related = [...new Set(parts2.flatMap((part) => part.kind === "data" ? part.needs?.related ?? [] : []))];
8004
8412
  const effect2 = {
8005
8413
  kind: "data",
8006
8414
  ...related.length > 0 ? { needs: { related } } : {},
@@ -8090,7 +8498,7 @@ function iconFromSvg(markup, spec) {
8090
8498
  if (typeof spec.size !== "number" || !(spec.size > 0) || !Number.isFinite(spec.size)) fail(`size must be more than 0, got ${String(spec.size)}`);
8091
8499
  scale = spec.size / box.width;
8092
8500
  }
8093
- root = { fill: "#000000", stroke: "none", width: 1, linecap: void 0, linejoin: void 0, transform: matrix.scale(scale) };
8501
+ root = { fill: "#000000", stroke: "none", width: 1, linecap: void 0, linejoin: void 0, fillRule: "nonzero", opacity: 1, transform: matrix.scale(scale) };
8094
8502
  }
8095
8503
  const parent = stack.length > 0 ? stack[stack.length - 1].state : first ? root : void 0;
8096
8504
  const state = parent && !hidden(attributes) ? inherit(parent, attributes) : void 0;
@@ -8161,6 +8569,10 @@ function pixels(value) {
8161
8569
  const number2 = match ? Number(match[1]) : NaN;
8162
8570
  return number2 > 0 && Number.isFinite(number2) ? number2 : void 0;
8163
8571
  }
8572
+ function alpha(value) {
8573
+ const match = /^\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)(%?)\s*$/i.exec(value ?? "");
8574
+ return match ? Math.min(1, Math.max(0, Number(match[1]) / (match[2] ? 100 : 1))) : 1;
8575
+ }
8164
8576
  function hidden(attributes) {
8165
8577
  return attributes.get("display")?.trim() === "none" || attributes.get("visibility")?.trim() === "hidden";
8166
8578
  }
@@ -8174,6 +8586,7 @@ function inherit(parent, attributes) {
8174
8586
  const width = Number.parseFloat(attributes.get("stroke-width") ?? "");
8175
8587
  const linecap = attributes.get("stroke-linecap")?.trim();
8176
8588
  const linejoin = attributes.get("stroke-linejoin")?.trim();
8589
+ const fillRule = attributes.get("fill-rule")?.trim().toLowerCase();
8177
8590
  const transform = attributes.get("transform");
8178
8591
  return {
8179
8592
  fill: paint("fill", parent.fill),
@@ -8181,26 +8594,31 @@ function inherit(parent, attributes) {
8181
8594
  width: width >= 0 ? width : parent.width,
8182
8595
  linecap: linecap === "butt" || linecap === "round" ? linecap : parent.linecap,
8183
8596
  linejoin: linejoin === "miter" || linejoin === "round" ? linejoin : parent.linejoin,
8597
+ fillRule: fillRule === "nonzero" || fillRule === "evenodd" ? fillRule : parent.fillRule,
8598
+ // Opacity isn't inherited in SVG: a group is drawn and then faded. Multiplying is the same unless its shapes overlap.
8599
+ opacity: parent.opacity * alpha(attributes.get("opacity")),
8184
8600
  transform: transform ? matrix.multiply(parent.transform, parseTransform(transform)) : parent.transform
8185
8601
  };
8186
8602
  }
8187
8603
  function toShape(tag, attributes, state) {
8188
8604
  const fill = state.fill === "none" ? void 0 : state.fill;
8189
8605
  const stroke2 = state.stroke === "none" || !(state.width > 0) ? void 0 : state.stroke;
8190
- if (fill === void 0 && stroke2 === void 0) return void 0;
8606
+ const opacity = round4(state.opacity);
8607
+ if (fill === void 0 && stroke2 === void 0 || !(opacity > 0)) return void 0;
8191
8608
  const commands = outline(tag, attributes);
8192
8609
  if (!commands.some((command) => command.op !== "M")) return void 0;
8193
8610
  const m = state.transform;
8194
8611
  return {
8195
8612
  d: formatPath(transformPath(commands, m)),
8196
- ...fill !== void 0 ? { fill } : {},
8613
+ ...fill !== void 0 ? { fill, ...state.fillRule === "evenodd" ? { fillRule: state.fillRule } : {} } : {},
8197
8614
  ...stroke2 !== void 0 ? {
8198
8615
  stroke: stroke2,
8199
8616
  // A stroke scales with the transform; for an uneven scale this is the average.
8200
8617
  width: round4(state.width * Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]))),
8201
8618
  ...state.linecap ? { linecap: state.linecap } : {},
8202
8619
  ...state.linejoin ? { linejoin: state.linejoin } : {}
8203
- } : {}
8620
+ } : {},
8621
+ ...opacity < 1 ? { opacity } : {}
8204
8622
  };
8205
8623
  }
8206
8624
  function outline(tag, attributes) {
@@ -8339,7 +8757,7 @@ function configure(options) {
8339
8757
  }
8340
8758
 
8341
8759
  // src/index.ts
8342
- var VERSION = "0.2.0";
8760
+ var VERSION = "0.3.0";
8343
8761
  var env = { presets: presetRegistry, icons: iconRegistry, motion };
8344
8762
  function barChart2(target, options) {
8345
8763
  return barChart(target, options, env);