expressive-charts 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -33,6 +33,7 @@ __export(src_exports, {
33
33
  defineDataEffect: () => defineDataEffect,
34
34
  defineEffect: () => defineEffect,
35
35
  defineIcon: () => defineIcon,
36
+ delta: () => delta,
36
37
  describe: () => describe,
37
38
  donutChart: () => donutChart2,
38
39
  easeInOutCubic: () => easeInOutCubic,
@@ -46,8 +47,10 @@ __export(src_exports, {
46
47
  interpolateNumber: () => interpolateNumber,
47
48
  interpolatePoint: () => interpolatePoint,
48
49
  interpolateRecord: () => interpolateRecord,
50
+ label: () => label,
49
51
  lineChart: () => lineChart2,
50
52
  linear: () => linear,
53
+ link: () => link,
51
54
  manualClock: () => manualClock,
52
55
  matrix: () => matrix,
53
56
  mediaReducedMotion: () => mediaReducedMotion,
@@ -68,6 +71,7 @@ __export(src_exports, {
68
71
  sequence: () => sequence,
69
72
  stagger: () => stagger,
70
73
  threshold: () => threshold,
74
+ trace: () => trace,
71
75
  travel: () => travel,
72
76
  tween: () => tween,
73
77
  wiggle: () => wiggle
@@ -843,7 +847,7 @@ function checkCount(n, multiple) {
843
847
  }
844
848
 
845
849
  // src/core/geometry/describe/mark.ts
846
- function assemble({ key, series, walk, thickness, outline: outline2, bounds, center, pivot, segments }) {
850
+ function assemble({ key, series, walk, thickness, outline: outline2, bounds, center, pivot, labelBounds, segments }) {
847
851
  return {
848
852
  key,
849
853
  ...series === void 0 ? {} : { series },
@@ -858,6 +862,7 @@ function assemble({ key, series, walk, thickness, outline: outline2, bounds, cen
858
862
  bounds,
859
863
  center,
860
864
  pivot,
865
+ ...labelBounds === void 0 ? {} : { labelBounds },
861
866
  ...segments === void 0 ? {} : { segments }
862
867
  };
863
868
  }
@@ -865,6 +870,18 @@ function finite(builder, field, value) {
865
870
  if (!Number.isFinite(value)) throw new RangeError(`describe.${builder}: ${field} must be a finite number, got ${value}.`);
866
871
  return value;
867
872
  }
873
+ function labelBoxes(builder, boxes) {
874
+ if (!boxes) return boxes;
875
+ for (let i = 0; i < boxes.length; i++) {
876
+ const { x, y, width, height } = boxes[i];
877
+ if (Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(width) && width >= 0 && Number.isFinite(height) && height >= 0) continue;
878
+ finite(builder, `labelBounds[${i}].x`, x);
879
+ finite(builder, `labelBounds[${i}].y`, y);
880
+ size(builder, `labelBounds[${i}].width`, width);
881
+ size(builder, `labelBounds[${i}].height`, height);
882
+ }
883
+ return boxes;
884
+ }
868
885
  function size(builder, field, value) {
869
886
  if (!(Number.isFinite(value) && value >= 0)) {
870
887
  throw new RangeError(`describe.${builder}: ${field} must be a finite number \u2265 0, got ${value}.`);
@@ -899,7 +916,8 @@ function describeArc(spec) {
899
916
  outline: closedOutline(sides),
900
917
  bounds: boundsOf(sides.flat().flatMap(extremes)),
901
918
  center: walk.point(0.5),
902
- pivot: center
919
+ pivot: center,
920
+ labelBounds: labelBoxes("arc", spec.labelBounds)
903
921
  });
904
922
  }
905
923
 
@@ -916,6 +934,7 @@ function describeBar(spec) {
916
934
  size("bar", "height", height);
917
935
  const radius = size("bar", "radius", spec.radius ?? 0);
918
936
  const gap = size("bar", "gap", spec.gap ?? 0);
937
+ const labelBounds = labelBoxes("bar", spec.labelBounds);
919
938
  const horizontal = baseline === "left" || baseline === "right";
920
939
  const length = horizontal ? width : height;
921
940
  const thickness = horizontal ? height : width;
@@ -968,7 +987,7 @@ function describeBar(spec) {
968
987
  })
969
988
  )
970
989
  );
971
- return part(0, length, radius, { key, series, bounds: { x, y, width, height }, segments });
990
+ return part(0, length, radius, { key, series, bounds: { x, y, width, height }, labelBounds, segments });
972
991
  }
973
992
  function frame({ x, y, width: w, height: h, baseline }) {
974
993
  switch (baseline) {
@@ -1009,7 +1028,8 @@ function describeLine(spec) {
1009
1028
  outline: openOutline(walk),
1010
1029
  bounds: { x: box.x - pad, y: box.y - pad, width: box.width + width, height: box.height + width },
1011
1030
  center: walk.point(0.5),
1012
- pivot: first
1031
+ pivot: first,
1032
+ labelBounds: labelBoxes("line", spec.labelBounds)
1013
1033
  });
1014
1034
  }
1015
1035
 
@@ -1032,7 +1052,8 @@ function describePoint(spec) {
1032
1052
  ]),
1033
1053
  bounds: { x: center.x - r, y: center.y - r, width: 2 * r, height: 2 * r },
1034
1054
  center,
1035
- pivot: center
1055
+ pivot: center,
1056
+ labelBounds: labelBoxes("point", spec.labelBounds)
1036
1057
  });
1037
1058
  }
1038
1059
 
@@ -1265,9 +1286,9 @@ function runScope(options) {
1265
1286
  batch: options.batch,
1266
1287
  ...options.previous ? { previous: options.previous } : {},
1267
1288
  tween(tweenOptions) {
1268
- const own = tweenOptions.signal;
1269
- const running = tween({ ...tweenOptions, signal: own ?? controller.signal }, { clock, motion: motion2 });
1270
- if (own && own !== controller.signal) {
1289
+ const own2 = tweenOptions.signal;
1290
+ const running = tween({ ...tweenOptions, signal: own2 ?? controller.signal }, { clock, motion: motion2 });
1291
+ if (own2 && own2 !== controller.signal) {
1271
1292
  if (controller.signal.aborted) running.cancel();
1272
1293
  else controller.signal.addEventListener("abort", () => running.cancel(), { once: true });
1273
1294
  }
@@ -1418,16 +1439,16 @@ function createRunner(options) {
1418
1439
  }
1419
1440
  };
1420
1441
  }
1421
- function runMark(own) {
1442
+ function runMark(own2) {
1422
1443
  return {
1423
1444
  set(style) {
1424
- const run = own();
1445
+ const run = own2();
1425
1446
  if (run.state === "cleared") return;
1426
1447
  run.style = mergeFields(run.style, style);
1427
1448
  applyStyle(run.entry);
1428
1449
  },
1429
1450
  reset() {
1430
- const run = own();
1451
+ const run = own2();
1431
1452
  if (Object.keys(run.style).length === 0) return;
1432
1453
  run.style = {};
1433
1454
  applyStyle(run.entry);
@@ -1676,6 +1697,76 @@ function chartAnnouncer(svg) {
1676
1697
  };
1677
1698
  }
1678
1699
 
1700
+ // src/charts/render/svg.ts
1701
+ var SVG_NS = "http://www.w3.org/2000/svg";
1702
+ function svgElement(tag, attributes = {}, parent) {
1703
+ const doc = parent?.ownerDocument ?? document;
1704
+ const element = doc.createElementNS(SVG_NS, tag);
1705
+ setAttributes(element, attributes);
1706
+ parent?.appendChild(element);
1707
+ return element;
1708
+ }
1709
+ function setAttributes(element, attributes) {
1710
+ for (const [name, value] of Object.entries(attributes)) {
1711
+ if (value === void 0) element.removeAttribute(name);
1712
+ else element.setAttribute(name, typeof value === "number" ? formatNumber(value) : value);
1713
+ }
1714
+ }
1715
+ function setStyles(element, styles) {
1716
+ for (const [name, value] of Object.entries(styles)) {
1717
+ if (value === void 0) element.style.removeProperty(name);
1718
+ else element.style.setProperty(name, value);
1719
+ }
1720
+ }
1721
+ function sizeAttributes({ width, height }) {
1722
+ return { width, height, viewBox: `0 0 ${formatNumber(width)} ${formatNumber(height)}` };
1723
+ }
1724
+ function transformAttribute(m) {
1725
+ const [a, b, c, d, e, f] = m;
1726
+ return `matrix(${[a, b, c, d].map(linear2).join(" ")} ${formatNumber(e)} ${formatNumber(f)})`;
1727
+ }
1728
+ function linear2(value) {
1729
+ const rounded = Math.round(value * 1e6) / 1e6;
1730
+ return rounded === 0 ? "0" : String(rounded);
1731
+ }
1732
+
1733
+ // src/charts/render/text.ts
1734
+ var ASCENT = 1.05;
1735
+ var DESCENT = 0.25;
1736
+ var SIDE = 0.16;
1737
+ function textBox(placement, measure, className, size2) {
1738
+ const width = measure(placement.text.replace(/\d/g, "0"), className, size2);
1739
+ const start = placement.anchor === "start" ? placement.x : placement.anchor === "end" ? placement.x - width : placement.x - width / 2;
1740
+ return { x: start - SIDE * size2, y: placement.y - ASCENT * size2, width: width + 2 * SIDE * size2, height: (ASCENT + DESCENT) * size2 };
1741
+ }
1742
+ function placeText(element, placement) {
1743
+ setAttributes(element, { x: placement.x, y: placement.y, "text-anchor": placement.anchor });
1744
+ if (element.textContent !== placement.text) element.textContent = placement.text;
1745
+ }
1746
+ var AVERAGE_WIDTH = 0.6;
1747
+ function textMeasure(svg) {
1748
+ const cache = /* @__PURE__ */ new Map();
1749
+ const measure = (text2, className, size2) => {
1750
+ if (text2 === "") return 0;
1751
+ const id = `${className}
1752
+ ${size2}
1753
+ ${text2}`;
1754
+ const cached = cache.get(id);
1755
+ if (cached !== void 0) return cached;
1756
+ let width = 0;
1757
+ const probe = svgElement("text", { class: className, visibility: "hidden", "aria-hidden": "true" }, svg);
1758
+ if (typeof probe.getComputedTextLength === "function" && svg.isConnected) {
1759
+ probe.textContent = text2;
1760
+ width = probe.getComputedTextLength();
1761
+ }
1762
+ probe.remove();
1763
+ if (!(width > 0)) return text2.length * size2 * AVERAGE_WIDTH;
1764
+ cache.set(id, width);
1765
+ return width;
1766
+ };
1767
+ return Object.assign(measure, { clear: () => cache.clear() });
1768
+ }
1769
+
1679
1770
  // src/charts/bar-layout.ts
1680
1771
  var ROW = 34;
1681
1772
  var BAR = 20;
@@ -1743,11 +1834,11 @@ function layoutBars(input) {
1743
1834
  height: frame2.bands.height,
1744
1835
  orientation: frame2.orientation,
1745
1836
  frame: frame2,
1746
- rows: rows2.map((row, slot) => placeRow(frame2, { ...row, slot, text: texts[slot] })),
1837
+ rows: rows2.map((row, slot) => placeRow(frame2, { ...row, slot, text: texts[slot] }, input.measure)),
1747
1838
  ticks: domain.ticks.map((value, i) => placeTick(frame2, value, ticks[i]))
1748
1839
  };
1749
1840
  }
1750
- function placeRow(frame2, row) {
1841
+ function placeRow(frame2, row, measure) {
1751
1842
  const { scale: scale2, bands } = frame2;
1752
1843
  const at = position(scale2);
1753
1844
  const unit = Math.abs(scale2.extent / (scale2.hi - scale2.lo));
@@ -1764,40 +1855,52 @@ function placeRow(frame2, row) {
1764
1855
  segments: row.values.map((v) => ({ series: v.series, size: Math.max(0, negative ? -v.value : v.value) * unit }))
1765
1856
  };
1766
1857
  const fields = { key: row.key, datum: row.datum, index: row.index, slot: row.slot, values: row.values, total: total2 };
1858
+ const boxes = (label3, value2) => {
1859
+ const out = [];
1860
+ if (label3.text !== "") out.push(textBox(label3, measure, "ec-label", LABEL_SIZE));
1861
+ if (value2.text !== "") out.push(textBox(value2, measure, "ec-value", VALUE_SIZE));
1862
+ return out;
1863
+ };
1767
1864
  if (frame2.orientation === "horizontal") {
1865
+ const line2 = band + bands.band / 2 + LABEL_SIZE * CENTRE;
1866
+ const label3 = { x: scale2.label, y: line2, anchor: "end", text: row.category };
1867
+ const value2 = { x: negative ? tip - PAD : tip + PAD, y: line2, anchor: negative ? "end" : "start", text: row.text };
1768
1868
  const geometry2 = describe.bar({
1769
1869
  ...bar,
1770
1870
  x: Math.min(zero, tip),
1771
1871
  y: band + (bands.band - bands.thickness) / 2,
1772
1872
  width: Math.abs(tip - zero),
1773
1873
  height: bands.thickness,
1774
- baseline: negative ? "right" : "left"
1874
+ baseline: negative ? "right" : "left",
1875
+ labelBounds: boxes(label3, value2)
1775
1876
  });
1776
- const line2 = band + bands.band / 2 + LABEL_SIZE * CENTRE;
1777
1877
  return {
1778
1878
  ...fields,
1779
1879
  geometry: geometry2,
1780
1880
  data: barData(row.datum, total2, geometry2),
1781
- label: { x: scale2.label, y: line2, anchor: "end", text: row.category },
1782
- value: { x: negative ? tip - PAD : tip + PAD, y: line2, anchor: negative ? "end" : "start", text: row.text },
1881
+ label: label3,
1882
+ value: value2,
1783
1883
  hit: { x: 0, y: band, width: bands.width, height: bands.band }
1784
1884
  };
1785
1885
  }
1786
1886
  const centre = band + bands.band / 2;
1887
+ const label2 = { x: centre, y: scale2.label, anchor: "middle", text: row.category };
1888
+ const value = { x: centre, y: negative ? tip + PAD + VALUE_SIZE * 0.8 : tip - PAD, anchor: "middle", text: row.text };
1787
1889
  const geometry = describe.bar({
1788
1890
  ...bar,
1789
1891
  x: centre - bands.thickness / 2,
1790
1892
  y: Math.min(zero, tip),
1791
1893
  width: bands.thickness,
1792
1894
  height: Math.abs(tip - zero),
1793
- baseline: negative ? "top" : "bottom"
1895
+ baseline: negative ? "top" : "bottom",
1896
+ labelBounds: boxes(label2, value)
1794
1897
  });
1795
1898
  return {
1796
1899
  ...fields,
1797
1900
  geometry,
1798
1901
  data: barData(row.datum, total2, geometry),
1799
- label: { x: centre, y: scale2.label, anchor: "middle", text: row.category },
1800
- value: { x: centre, y: negative ? tip + PAD + VALUE_SIZE * 0.8 : tip - PAD, anchor: "middle", text: row.text },
1902
+ label: label2,
1903
+ value,
1801
1904
  hit: { x: band, y: 0, width: bands.band, height: bands.height }
1802
1905
  };
1803
1906
  }
@@ -2039,10 +2142,10 @@ ${TOKEN_RULES}
2039
2142
  :where(.ec-chart .ec-focus) { pointer-events: none; }
2040
2143
  :where(.ec-chart .ec-focus-ring) { fill: none; stroke: var(--ec-focus, ${TOKENS.focus}); }
2041
2144
  :where(.ec-chart .ec-focus-gap) { fill: var(--ec-surface, ${TOKENS.surface}); stroke: var(--ec-surface, ${TOKENS.surface}); }
2042
- :where(.ec-chart .ec-mark) { transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
2043
- :where(.ec-chart .ec-segment) { fill: var(--ec-mark); transition: fill var(--ec-hover-duration, 100ms) ease-out; }
2145
+ :where(.ec-chart .ec-body > *) { transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
2146
+ :where(.ec-chart .ec-segment) { fill: var(--ec-mark); transition: fill var(--ec-hover-duration, 100ms) ease-out, opacity var(--ec-hover-duration, 100ms) ease-out; }
2044
2147
  :where(.ec-chart .ec-hot .ec-segment) { fill: var(--ec-mark-strong); }
2045
- :where(.ec-chart .ec-stroke) { fill: none; stroke: var(--ec-mark); stroke-linejoin: round; transition: stroke var(--ec-hover-duration, 100ms) ease-out; }
2148
+ :where(.ec-chart .ec-stroke) { fill: none; stroke: var(--ec-mark); stroke-linejoin: round; transition: stroke var(--ec-hover-duration, 100ms) ease-out, opacity var(--ec-hover-duration, 100ms) ease-out; }
2046
2149
  :where(.ec-chart .ec-hot .ec-stroke) { stroke: var(--ec-mark-strong); }
2047
2150
  :where(.ec-chart .ec-end) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; }
2048
2151
  :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; }
@@ -2050,11 +2153,11 @@ ${TOKEN_RULES}
2050
2153
  :where(.ec-chart .ec-crosshair) { stroke: var(--ec-axis, ${TOKENS.axis}); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
2051
2154
  :where(.ec-chart .ec-column:focus) { outline: none; }
2052
2155
  :where(.ec-chart .ec-lines, .ec-chart .ec-points) { pointer-events: none; }
2053
- :where(.ec-chart .ec-slice) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; stroke-linejoin: round; transition: fill var(--ec-hover-duration, 100ms) ease-out; }
2156
+ :where(.ec-chart .ec-slice) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; stroke-linejoin: round; transition: fill var(--ec-hover-duration, 100ms) ease-out, opacity var(--ec-hover-duration, 100ms) ease-out; }
2054
2157
  :where(.ec-chart .ec-hot .ec-slice) { fill: var(--ec-mark-strong); }
2055
2158
  :where(.ec-chart .ec-center-value) { fill: var(--ec-text, ${TOKENS.text}); font-size: 26px; font-weight: 600; }
2056
2159
  :where(.ec-chart .ec-center-label) { fill: var(--ec-text-muted, ${TOKENS["text-muted"]}); font-size: 12.5px; }
2057
- :where(.ec-chart.ec-hovering .ec-mark:not(.ec-hot)) { opacity: var(--ec-dim-opacity, 0.3); }
2160
+ :where(.ec-chart.ec-hovering .ec-mark:not(.ec-hot) > .ec-body > *) { opacity: var(--ec-dim-opacity, 0.3); }
2058
2161
  :where(.ec-chart.ec-morphing .ec-marks) { visibility: hidden; }
2059
2162
  :where(.ec-switch) { display: grid; grid-template-columns: minmax(0, 1fr); position: relative; }
2060
2163
  :where(.ec-switch-view) { grid-area: 1 / 1; min-width: 0; }
@@ -2146,8 +2249,8 @@ function checkLegendOption(option, chart) {
2146
2249
  if (entries === void 0) return;
2147
2250
  if (!Array.isArray(entries)) fail("legend.entries must be an array of { label, color }.");
2148
2251
  entries.forEach((entry, i) => {
2149
- const { label, color } = typeof entry === "object" && entry !== null ? entry : fail(`legend.entries[${i}] must be an object with a label and a color.`);
2150
- if (typeof label !== "string" || label.trim() === "") fail(`legend.entries[${i}].label must be a non-empty string: the entry's name.`);
2252
+ const { label: label2, color } = typeof entry === "object" && entry !== null ? entry : fail(`legend.entries[${i}] must be an object with a label and a color.`);
2253
+ if (typeof label2 !== "string" || label2.trim() === "") fail(`legend.entries[${i}].label must be a non-empty string: the entry's name.`);
2151
2254
  if (typeof color !== "string" || color.trim() === "") fail(`legend.entries[${i}].color must be a theme token or a CSS colour.`);
2152
2255
  if (color === "mark" || color === "mark-strong") fail(`legend.entries[${i}].color can't be "${color}": an entry has no mark. Use a theme token or a CSS colour.`);
2153
2256
  });
@@ -2163,8 +2266,8 @@ function chartLegend(svg) {
2163
2266
  };
2164
2267
  const draw = (entries, colors, attribute, more) => {
2165
2268
  const items = [
2166
- ...entries.map(({ key, label }) => ({ key, label, styles: markColorStyles(seriesColors(colors.slot(key))) })),
2167
- ...more.map(({ label, color }) => ({ key: void 0, label, styles: { "--ec-mark": cssColor(color) } }))
2269
+ ...entries.map(({ key, label: label2 }) => ({ key, label: label2, styles: markColorStyles(seriesColors(colors.slot(key))) })),
2270
+ ...more.map(({ label: label2, color }) => ({ key: void 0, label: label2, styles: { "--ec-mark": cssColor(color) } }))
2168
2271
  ];
2169
2272
  const doc = svg.ownerDocument;
2170
2273
  legend ?? (legend = Object.assign(doc.createElement("div"), { className: "ec-legend" }));
@@ -2180,10 +2283,10 @@ function chartLegend(svg) {
2180
2283
  for (const [property, value] of Object.entries(styles)) if (value !== void 0) item.style.setProperty(property, value);
2181
2284
  const swatch = doc.createElement("span");
2182
2285
  swatch.className = "ec-legend-swatch";
2183
- const label = doc.createElement("span");
2184
- label.className = "ec-legend-label";
2185
- label.textContent = text2;
2186
- item.append(swatch, label);
2286
+ const label2 = doc.createElement("span");
2287
+ label2.className = "ec-legend-label";
2288
+ label2.textContent = text2;
2289
+ item.append(swatch, label2);
2187
2290
  return item;
2188
2291
  })
2189
2292
  );
@@ -2192,7 +2295,7 @@ function chartLegend(svg) {
2192
2295
  update(series, colors, option) {
2193
2296
  const more = extras(option);
2194
2297
  if (option === false || series.length + more.length < 2) remove();
2195
- else draw(series.map(({ series: key, label }) => ({ key, label })), colors, "data-series", more);
2298
+ else draw(series.map(({ series: key, label: label2 }) => ({ key, label: label2 })), colors, "data-series", more);
2196
2299
  },
2197
2300
  categories(categories, colors, option) {
2198
2301
  if (option === false || categories.length === 0) remove();
@@ -2202,6 +2305,100 @@ function chartLegend(svg) {
2202
2305
  };
2203
2306
  }
2204
2307
 
2308
+ // src/charts/link.ts
2309
+ var own = (hovered) => hovered !== void 0 && hovered.source !== "linked";
2310
+ var ports = /* @__PURE__ */ new WeakMap();
2311
+ var linked = /* @__PURE__ */ new WeakSet();
2312
+ function linkable(port, handle) {
2313
+ ports.set(handle, port);
2314
+ return handle;
2315
+ }
2316
+ var portOf = (handle) => ports.get(handle);
2317
+ function link(sources, options = {}) {
2318
+ if (!Array.isArray(sources)) throw new TypeError("link needs an array of charts and attachments: link([columns, line]).");
2319
+ if (typeof options !== "object" || options === null) throw new TypeError("link: options must be an object, such as { by: (event) => event.data.datum.week }.");
2320
+ const { by, effects = true } = options;
2321
+ if (by !== void 0 && typeof by !== "function") throw new TypeError("link: by must be a function, such as (event) => event.data.datum.week.");
2322
+ if (typeof effects !== "boolean") throw new TypeError(`link: effects must be true or false, got ${String(effects)}.`);
2323
+ const members = [];
2324
+ for (const source of sources) {
2325
+ const port = typeof source === "object" && source !== null ? ports.get(source) : void 0;
2326
+ if (!port) {
2327
+ throw new TypeError("link: each source must be a chart (barChart, donutChart or lineChart) or an attachment (expressive or fromVegaView). A chartSwitch can't be linked yet.");
2328
+ }
2329
+ if (linked.has(port) || members.includes(port)) throw new TypeError("link: a chart or attachment can be in one link at a time. Destroy the link it's in first.");
2330
+ members.push(port);
2331
+ }
2332
+ const live = /* @__PURE__ */ new Set();
2333
+ let origin;
2334
+ function valueOf(input) {
2335
+ let value;
2336
+ if (by) {
2337
+ try {
2338
+ value = by(input);
2339
+ } catch (error) {
2340
+ report(error);
2341
+ return void 0;
2342
+ }
2343
+ } else {
2344
+ const { samples } = input.data;
2345
+ value = samples[samples.length - 1]?.at ?? input.mark.key;
2346
+ }
2347
+ if (value instanceof Date) return Number.isNaN(value.getTime()) ? void 0 : value.toISOString();
2348
+ return value === void 0 || value === null ? void 0 : String(value);
2349
+ }
2350
+ function hovered(from, marks) {
2351
+ origin = from;
2352
+ const values = new Set(marks.map(valueOf));
2353
+ values.delete(void 0);
2354
+ const matches = (target) => target.some((mark) => {
2355
+ const value = valueOf(mark);
2356
+ return value !== void 0 && values.has(value);
2357
+ });
2358
+ for (const port of live) {
2359
+ if (port === from) continue;
2360
+ const keys = values.size === 0 ? [] : port.targets().flatMap((target) => matches(target.marks) ? [target.key] : []);
2361
+ port.hover(keys, effects);
2362
+ if (origin !== from) return;
2363
+ }
2364
+ }
2365
+ function left(from) {
2366
+ if (origin !== from) return;
2367
+ origin = void 0;
2368
+ for (const port of live) port.unlink();
2369
+ }
2370
+ for (const port of members) {
2371
+ const listening = port.listen({
2372
+ hover: (marks) => hovered(port, marks),
2373
+ leave: () => left(port),
2374
+ dismiss() {
2375
+ const from = origin;
2376
+ from?.leave();
2377
+ if (from) left(from);
2378
+ },
2379
+ gone() {
2380
+ live.delete(port);
2381
+ linked.delete(port);
2382
+ left(port);
2383
+ }
2384
+ });
2385
+ if (!listening) continue;
2386
+ live.add(port);
2387
+ linked.add(port);
2388
+ }
2389
+ return {
2390
+ destroy() {
2391
+ for (const port of live) {
2392
+ port.listen(void 0);
2393
+ port.unlink();
2394
+ linked.delete(port);
2395
+ }
2396
+ live.clear();
2397
+ origin = void 0;
2398
+ }
2399
+ };
2400
+ }
2401
+
2205
2402
  // src/charts/motion.ts
2206
2403
  var MODES2 = ["presentation", "analysis", "off"];
2207
2404
  function chartMotion(option, page) {
@@ -2224,39 +2421,6 @@ function chartMotion(option, page) {
2224
2421
  };
2225
2422
  }
2226
2423
 
2227
- // src/charts/render/svg.ts
2228
- var SVG_NS = "http://www.w3.org/2000/svg";
2229
- function svgElement(tag, attributes = {}, parent) {
2230
- const doc = parent?.ownerDocument ?? document;
2231
- const element = doc.createElementNS(SVG_NS, tag);
2232
- setAttributes(element, attributes);
2233
- parent?.appendChild(element);
2234
- return element;
2235
- }
2236
- function setAttributes(element, attributes) {
2237
- for (const [name, value] of Object.entries(attributes)) {
2238
- if (value === void 0) element.removeAttribute(name);
2239
- else element.setAttribute(name, typeof value === "number" ? formatNumber(value) : value);
2240
- }
2241
- }
2242
- function setStyles(element, styles) {
2243
- for (const [name, value] of Object.entries(styles)) {
2244
- if (value === void 0) element.style.removeProperty(name);
2245
- else element.style.setProperty(name, value);
2246
- }
2247
- }
2248
- function sizeAttributes({ width, height }) {
2249
- return { width, height, viewBox: `0 0 ${formatNumber(width)} ${formatNumber(height)}` };
2250
- }
2251
- function transformAttribute(m) {
2252
- const [a, b, c, d, e, f] = m;
2253
- return `matrix(${[a, b, c, d].map(linear2).join(" ")} ${formatNumber(e)} ${formatNumber(f)})`;
2254
- }
2255
- function linear2(value) {
2256
- const rounded = Math.round(value * 1e6) / 1e6;
2257
- return rounded === 0 ? "0" : String(rounded);
2258
- }
2259
-
2260
2424
  // src/charts/render/outside.ts
2261
2425
  var RING_GAP = 2;
2262
2426
  var RING = 2;
@@ -2409,15 +2573,15 @@ function svgLayer(group) {
2409
2573
  icon(icon, options) {
2410
2574
  const size2 = options?.size;
2411
2575
  if (size2 !== void 0 && !(size2 >= 0)) throw new RangeError(`layer.icon: size must be a non-negative number, got ${String(size2)}.`);
2412
- const placed = svgElement("g", { class: "ec-icon", "data-icon": icon.name, visibility: "hidden" }, group);
2576
+ const placed2 = svgElement("g", { class: "ec-icon", "data-icon": icon.name, visibility: "hidden" }, group);
2413
2577
  const k = size2 === void 0 || !(icon.size > 0) ? 1 : size2 / icon.size;
2414
- const body = k === 1 ? placed : svgElement("g", { transform: transformAttribute(matrix.scale(k, k, icon.anchor)) }, placed);
2578
+ const body = k === 1 ? placed2 : svgElement("g", { transform: transformAttribute(matrix.scale(k, k, icon.anchor)) }, placed2);
2415
2579
  for (const shape of icon.shapes) drawShape(shape, body);
2416
2580
  const handle = {
2417
2581
  place(transform) {
2418
- setAttributes(placed, { transform: transformAttribute(transform), visibility: void 0 });
2582
+ setAttributes(placed2, { transform: transformAttribute(transform), visibility: void 0 });
2419
2583
  },
2420
- remove: () => placed.remove()
2584
+ remove: () => placed2.remove()
2421
2585
  };
2422
2586
  return handle;
2423
2587
  },
@@ -2536,35 +2700,6 @@ function svgSurface(options) {
2536
2700
  };
2537
2701
  }
2538
2702
 
2539
- // src/charts/render/text.ts
2540
- function placeText(element, placement) {
2541
- setAttributes(element, { x: placement.x, y: placement.y, "text-anchor": placement.anchor });
2542
- if (element.textContent !== placement.text) element.textContent = placement.text;
2543
- }
2544
- var AVERAGE_WIDTH = 0.6;
2545
- function textMeasure(svg) {
2546
- const cache = /* @__PURE__ */ new Map();
2547
- const measure = (text2, className, size2) => {
2548
- if (text2 === "") return 0;
2549
- const id = `${className}
2550
- ${size2}
2551
- ${text2}`;
2552
- const cached = cache.get(id);
2553
- if (cached !== void 0) return cached;
2554
- let width = 0;
2555
- const probe = svgElement("text", { class: className, visibility: "hidden", "aria-hidden": "true" }, svg);
2556
- if (typeof probe.getComputedTextLength === "function" && svg.isConnected) {
2557
- probe.textContent = text2;
2558
- width = probe.getComputedTextLength();
2559
- }
2560
- probe.remove();
2561
- if (!(width > 0)) return text2.length * size2 * AVERAGE_WIDTH;
2562
- cache.set(id, width);
2563
- return width;
2564
- };
2565
- return Object.assign(measure, { clear: () => cache.clear() });
2566
- }
2567
-
2568
2703
  // src/charts/series.ts
2569
2704
  function seriesLabel(labels, series) {
2570
2705
  return labels !== void 0 && Object.prototype.hasOwnProperty.call(labels, series) ? labels[series] ?? series : series;
@@ -2572,8 +2707,8 @@ function seriesLabel(labels, series) {
2572
2707
  function checkSeriesLabels(option, chart) {
2573
2708
  if (option === void 0) return;
2574
2709
  if (typeof option !== "object" || option === null || Array.isArray(option)) throw new TypeError(`${chart}: seriesLabels must be an object of names by series, as { goals: "Goals" }.`);
2575
- for (const [series, label] of Object.entries(option)) {
2576
- if (typeof label !== "string" || label.trim() === "") throw new TypeError(`${chart}: seriesLabels.${series} must be a name, not ${typeof label === "string" ? "blank" : String(label)}.`);
2710
+ for (const [series, label2] of Object.entries(option)) {
2711
+ if (typeof label2 !== "string" || label2.trim() === "") throw new TypeError(`${chart}: seriesLabels.${series} must be a name, not ${typeof label2 === "string" ? "blank" : String(label2)}.`);
2577
2712
  }
2578
2713
  }
2579
2714
 
@@ -2726,10 +2861,10 @@ function keyboardFocus(svg, options) {
2726
2861
  leave2();
2727
2862
  return;
2728
2863
  }
2729
- const own = options.element(key);
2730
- if (own && own !== event.target && event.target.getAttribute("aria-hidden") === "true") {
2731
- own.focus();
2732
- if (on?.scope.activeElement === own) return;
2864
+ const own2 = options.element(key);
2865
+ if (own2 && own2 !== event.target && event.target.getAttribute("aria-hidden") === "true") {
2866
+ own2.focus();
2867
+ if (on?.scope.activeElement === own2) return;
2733
2868
  }
2734
2869
  focused = { key, element: event.target };
2735
2870
  if (key === current) return;
@@ -2859,13 +2994,16 @@ function chartHover(options) {
2859
2994
  const markElement = (key) => (options.markElement ?? options.element)(key);
2860
2995
  let hovered;
2861
2996
  let ringKey;
2997
+ let linked2;
2998
+ let destroyed = false;
2862
2999
  const onScreen = (keys) => keys.flatMap((key) => {
2863
3000
  const input = options.onScreen(key);
2864
3001
  return input ? [{ key, input }] : [];
2865
3002
  });
2866
- function hoverMarks(marks, source, segment) {
3003
+ const marksFor = (keys) => keys.length === 1 ? marksOf(keys[0]) : [...new Set(keys.flatMap(marksOf))];
3004
+ function hoverMarks(marks, source, effects, segment) {
2867
3005
  if (marks.length === 0) return;
2868
- runner.hover(marks.map(({ input }) => input));
3006
+ if (effects) runner.hover(marks.map(({ input }) => input));
2869
3007
  const count = marks.length;
2870
3008
  marks.forEach(({ input }, index) => events.emit("hover", { ...input, batch: { index, count }, source, ...segment === void 0 ? {} : { segment } }));
2871
3009
  }
@@ -2877,22 +3015,27 @@ function chartHover(options) {
2877
3015
  const count = marks.length;
2878
3016
  marks.forEach(({ input }, index) => events.emit("leave", { ...input, batch: { index, count } }));
2879
3017
  }
2880
- function startHover(key, source, segment) {
2881
- const marks = onScreen(marksOf(key));
2882
- hovered = { key, source, marks: marks.map((mark) => mark.key) };
3018
+ function startHover(keys, source, segment, effects = true) {
3019
+ const marks = onScreen(marksFor(keys));
3020
+ const started = { keys, source, marks: marks.map((mark) => mark.key), effects };
3021
+ hovered = started;
2883
3022
  for (const { key: mark } of marks) markElement(mark)?.classList.add("ec-hot");
2884
3023
  if (options.dim()) svg.classList.add("ec-hovering");
2885
- options.tooltip.show(key);
2886
- listenForEscape(true);
2887
- hoverMarks(marks, source, segment);
3024
+ if (source !== "linked") {
3025
+ options.tooltip.show(keys[0]);
3026
+ listenForEscape(true);
3027
+ }
3028
+ hoverMarks(marks, source, effects, segment);
3029
+ if (source !== "linked" && hovered === started) linked2?.hover(marks.map(({ input }) => input));
2888
3030
  }
2889
3031
  function endHover() {
2890
- const marks = hovered?.marks ?? [];
3032
+ const ended = hovered;
2891
3033
  hovered = void 0;
2892
3034
  listenForEscape(false);
2893
3035
  svg.classList.remove("ec-hovering");
2894
3036
  options.tooltip.hide();
2895
- leaveMarks(marks);
3037
+ leaveMarks(ended?.marks ?? []);
3038
+ if (own(ended)) linked2?.leave();
2896
3039
  }
2897
3040
  let escapeDoc;
2898
3041
  const dismiss = (event) => {
@@ -2911,12 +3054,12 @@ function chartHover(options) {
2911
3054
  const interaction = pointerHover(svg, {
2912
3055
  find: options.find,
2913
3056
  hover(target, source) {
2914
- if (!options.live(target.key) || hovered?.key === target.key) return;
3057
+ if (!options.live(target.key) || own(hovered) && hovered.keys[0] === target.key) return;
2915
3058
  endHover();
2916
- startHover(target.key, source, target.segment);
3059
+ startHover([target.key], source, target.segment);
2917
3060
  },
2918
3061
  leave() {
2919
- if (hovered?.source !== "keyboard") endHover();
3062
+ if (hovered?.source === "pointer" || hovered?.source === "touch") endHover();
2920
3063
  }
2921
3064
  });
2922
3065
  const keyboard = keyboardFocus(() => svg, {
@@ -2928,40 +3071,60 @@ function chartHover(options) {
2928
3071
  options.ring(ringKey);
2929
3072
  if (!options.live(key)) return;
2930
3073
  if (!visible) {
2931
- if (hovered?.source === "keyboard" && hovered.key !== key) endHover();
3074
+ if (hovered?.source === "keyboard" && hovered.keys[0] !== key) endHover();
2932
3075
  return;
2933
3076
  }
2934
- if (hovered?.key === key) {
3077
+ if (own(hovered) && hovered.keys[0] === key) {
2935
3078
  hovered = { ...hovered, source: "keyboard" };
2936
3079
  return;
2937
3080
  }
2938
3081
  endHover();
2939
- startHover(key, "keyboard");
3082
+ startHover([key], "keyboard");
2940
3083
  },
2941
3084
  blur() {
2942
3085
  ringKey = void 0;
2943
3086
  options.ring(ringKey);
2944
3087
  if (hovered?.source !== "keyboard") return;
2945
- if (interaction.current === hovered.key) hovered = { ...hovered, source: "pointer" };
3088
+ if (interaction.current === hovered.keys[0]) hovered = { ...hovered, source: "pointer" };
2946
3089
  else endHover();
2947
3090
  },
2948
3091
  escape() {
2949
3092
  if (!hovered) return false;
2950
- endHover();
3093
+ if (hovered.source === "linked" && linked2) linked2.dismiss();
3094
+ else endHover();
2951
3095
  return true;
2952
3096
  }
2953
3097
  });
3098
+ const link2 = {
3099
+ targets: () => options.order().map((key) => ({ key, marks: onScreen(marksOf(key)).map(({ input }) => input) })),
3100
+ hover(keys, effects) {
3101
+ if (hovered !== void 0) endHover();
3102
+ const live = keys.filter(options.live);
3103
+ if (live.length > 0) startHover(live, "linked", void 0, effects);
3104
+ },
3105
+ unlink() {
3106
+ if (hovered?.source === "linked") endHover();
3107
+ },
3108
+ leave: leave2,
3109
+ listen(listener) {
3110
+ if (destroyed) return false;
3111
+ linked2 = listener;
3112
+ return true;
3113
+ }
3114
+ };
2954
3115
  return {
2955
3116
  get key() {
2956
- return hovered?.key;
3117
+ return own(hovered) ? hovered.keys[0] : void 0;
2957
3118
  },
2958
3119
  get ringKey() {
2959
3120
  return ringKey;
2960
3121
  },
3122
+ link: link2,
2961
3123
  active: () => keyboard.active(),
2962
3124
  restyled(key) {
2963
3125
  if (ringKey !== void 0 && within(ringKey, key)) options.ring(ringKey);
2964
- if (hovered !== void 0 && (hovered.marks.includes(key) || key === hovered.key) && options.live(hovered.key)) options.tooltip.show(hovered.key);
3126
+ const target = own(hovered) ? hovered.keys[0] : void 0;
3127
+ if (target !== void 0 && (hovered?.marks.includes(key) || key === target) && options.live(target)) options.tooltip.show(target);
2965
3128
  },
2966
3129
  syncDim() {
2967
3130
  if (!options.dim()) svg.classList.remove("ec-hovering");
@@ -2969,22 +3132,24 @@ function chartHover(options) {
2969
3132
  },
2970
3133
  dropGone() {
2971
3134
  if (hovered === void 0) return;
2972
- if (!options.live(hovered.key)) {
3135
+ const keys = hovered.keys.filter(options.live);
3136
+ if (keys.length === 0) {
2973
3137
  interaction.clear();
2974
3138
  endHover();
2975
3139
  return;
2976
3140
  }
2977
- const { source, marks: before } = hovered;
2978
- const now = onScreen(marksOf(hovered.key));
3141
+ const { source, marks: before, effects } = hovered;
3142
+ const now = onScreen(marksFor(keys));
3143
+ hovered = { ...hovered, keys };
2979
3144
  if (now.length === before.length && now.every((mark, i) => mark.key === before[i])) return;
2980
3145
  const had = new Set(before);
2981
- const keys = new Set(now.map((mark) => mark.key));
2982
- const gone = onScreen(before.filter((key) => !keys.has(key)));
3146
+ const kept = new Set(now.map((mark) => mark.key));
3147
+ const gone = onScreen(before.filter((key) => !kept.has(key)));
2983
3148
  hovered = { ...hovered, marks: now.map((mark) => mark.key) };
2984
3149
  for (const { key } of gone) markElement(key)?.classList.remove("ec-hot");
2985
3150
  for (const { key } of now) if (!had.has(key)) markElement(key)?.classList.add("ec-hot");
2986
3151
  runner.leave(before);
2987
- runner.hover(now.map(({ input }) => input));
3152
+ if (effects) runner.hover(now.map(({ input }) => input));
2988
3153
  gone.forEach(({ input }, index) => events.emit("leave", { ...input, batch: { index, count: gone.length } }));
2989
3154
  const count = now.length;
2990
3155
  now.forEach(({ key, input }, index) => {
@@ -2997,6 +3162,9 @@ function chartHover(options) {
2997
3162
  },
2998
3163
  leave: leave2,
2999
3164
  destroy() {
3165
+ destroyed = true;
3166
+ linked2?.gone();
3167
+ linked2 = void 0;
3000
3168
  listenForEscape(false);
3001
3169
  interaction.destroy();
3002
3170
  keyboard.destroy();
@@ -3105,12 +3273,12 @@ function tableModel(input) {
3105
3273
  const grand = input.rows.reduce((sum2, row) => sum2 + row.total, 0);
3106
3274
  const share = (value) => input.shares ? [{ text: percent(grand > 0 ? value / grand : 0), numeric: true }] : [];
3107
3275
  const header = (column) => ({ text: column.label, numeric: false });
3108
- const own = (series) => options.series && Object.prototype.hasOwnProperty.call(options.series, series) ? options.series[series] : void 0;
3276
+ const own2 = (series) => options.series && Object.prototype.hasOwnProperty.call(options.series, series) ? options.series[series] : void 0;
3109
3277
  const blank = () => ({ text: "", numeric: false });
3110
3278
  const headers = [
3111
3279
  { text: options.category ?? input.category ?? "Category", numeric: false },
3112
3280
  ...first.map(header),
3113
- ...input.series.map((series) => ({ text: own(series) ?? input.label?.(series) ?? series, numeric: true })),
3281
+ ...input.series.map((series) => ({ text: own2(series) ?? input.label?.(series) ?? series, numeric: true })),
3114
3282
  ...totals ? [{ text: options.total ?? "Total", numeric: true }] : [],
3115
3283
  ...input.shares ? [{ text: options.share ?? "Share", numeric: true }] : [],
3116
3284
  ...last.map(header)
@@ -3165,7 +3333,7 @@ function chartTable(svg) {
3165
3333
  let wrapper;
3166
3334
  let summary;
3167
3335
  let table;
3168
- let caption;
3336
+ let caption2;
3169
3337
  let head;
3170
3338
  let body;
3171
3339
  let foot;
@@ -3178,12 +3346,12 @@ function chartTable(svg) {
3178
3346
  };
3179
3347
  function build() {
3180
3348
  table = element("table");
3181
- caption = element("caption", "ec-table-caption");
3349
+ caption2 = element("caption", "ec-table-caption");
3182
3350
  const thead = element("thead");
3183
3351
  head = element("tr");
3184
3352
  thead.appendChild(head);
3185
3353
  body = element("tbody");
3186
- table.append(caption, thead, body);
3354
+ table.append(caption2, thead, body);
3187
3355
  return table;
3188
3356
  }
3189
3357
  function place(hidden2, text2) {
@@ -3212,7 +3380,7 @@ function chartTable(svg) {
3212
3380
  }
3213
3381
  function remove() {
3214
3382
  wrapper?.remove();
3215
- wrapper = summary = table = caption = head = body = foot = void 0;
3383
+ wrapper = summary = table = caption2 = head = body = foot = void 0;
3216
3384
  rows2.clear();
3217
3385
  drawn = "";
3218
3386
  }
@@ -3223,7 +3391,7 @@ function chartTable(svg) {
3223
3391
  return;
3224
3392
  }
3225
3393
  place(model.hidden, model.summary);
3226
- if (caption.textContent !== model.caption) caption.textContent = model.caption;
3394
+ if (caption2.textContent !== model.caption) caption2.textContent = model.caption;
3227
3395
  const headers = JSON.stringify(model.headers);
3228
3396
  if (headers !== drawn) {
3229
3397
  drawn = headers;
@@ -3387,10 +3555,10 @@ function chartTransitions(options) {
3387
3555
  });
3388
3556
  },
3389
3557
  supersede: () => supersede?.(),
3390
- wait(settled, leaves) {
3558
+ wait(settled, leaves2) {
3391
3559
  return new Promise((resolve) => {
3392
3560
  supersede = resolve;
3393
- void settled.then(() => Promise.all(leaves.map((leave2) => leave2.gone))).then(() => resolve());
3561
+ void settled.then(() => Promise.all(leaves2.map((leave2) => leave2.gone))).then(() => resolve());
3394
3562
  });
3395
3563
  },
3396
3564
  destroy() {
@@ -3407,10 +3575,10 @@ function playUpdate(options, arrange, announce) {
3407
3575
  const diff = arrange();
3408
3576
  options.swap?.(diff);
3409
3577
  options.hover.dropGone();
3410
- const leaves = diff.exiting.map((record) => record.leave);
3578
+ const leaves2 = diff.exiting.map((record) => record.leave);
3411
3579
  const exited = runner.exit(diff.exiting.map(onScreen));
3412
3580
  void exited.then(() => {
3413
- for (const leave2 of leaves) leave2.exited = true;
3581
+ for (const leave2 of leaves2) leave2.exited = true;
3414
3582
  options.leaving.sweep();
3415
3583
  });
3416
3584
  events.emitEach("exit", diff.exiting, onScreen);
@@ -3420,7 +3588,7 @@ function playUpdate(options, arrange, announce) {
3420
3588
  events.emitEach("enter", diff.entering, input);
3421
3589
  announce(diff);
3422
3590
  options.hover.sync();
3423
- return leaves;
3591
+ return leaves2;
3424
3592
  }
3425
3593
  function busy(value, to, equal) {
3426
3594
  return value.animating || !equal(value.value, to);
@@ -3431,11 +3599,18 @@ function sameFields(a, b) {
3431
3599
  return keys.length === Object.keys(b).length && keys.every((key) => a[key] === b[key]);
3432
3600
  }
3433
3601
  function geometryChanged(from, to) {
3434
- if (from.outline.d !== to.outline.d) return true;
3602
+ if (from.outline.d !== to.outline.d || labelsMoved(from, to)) return true;
3435
3603
  const a = from.segments ?? [];
3436
3604
  const b = to.segments ?? [];
3437
3605
  return a.length !== b.length || a.some((segment, i) => segment.key !== b[i].key || segment.outline.d !== b[i].outline.d);
3438
3606
  }
3607
+ function labelsMoved(from, to) {
3608
+ const a = from.labelBounds;
3609
+ const b = to.labelBounds;
3610
+ if (a === b) return false;
3611
+ if (!a || !b || a.length !== b.length) return true;
3612
+ return a.some((box, i) => box.x !== b[i].x || box.y !== b[i].y || box.width !== b[i].width || box.height !== b[i].height);
3613
+ }
3439
3614
 
3440
3615
  // src/charts/shell/watch.ts
3441
3616
  function watchWidth(container, clock, width, resize) {
@@ -3543,11 +3718,11 @@ function chartTooltip(svg, options) {
3543
3718
  const toPx = { x: (x) => (x - view.x) * k, y: (y) => (y - view.y) * k };
3544
3719
  const area = chart.width > 0 ? { width: chart.width, height: chart.height } : { width: view.width, height: view.height };
3545
3720
  const size2 = { width: tip.offsetWidth, height: tip.offsetHeight };
3546
- const placed = placeTooltip(anchor(toPx, moved), size2, area, moved ? placeTooltip(anchor(toPx, false), size2, area).side : void 0);
3721
+ const placed2 = placeTooltip(anchor(toPx, moved), size2, area, moved ? placeTooltip(anchor(toPx, false), size2, area).side : void 0);
3547
3722
  const origin = layer.getBoundingClientRect();
3548
- tip.style.left = `${Math.round(chart.left - origin.left + placed.x)}px`;
3549
- tip.style.top = `${Math.round(chart.top - origin.top + placed.y)}px`;
3550
- tip.setAttribute("data-side", placed.side);
3723
+ tip.style.left = `${Math.round(chart.left - origin.left + placed2.x)}px`;
3724
+ tip.style.top = `${Math.round(chart.top - origin.top + placed2.y)}px`;
3725
+ tip.setAttribute("data-side", placed2.side);
3551
3726
  timing(tip);
3552
3727
  tip.classList.add("ec-tooltip-shown");
3553
3728
  }
@@ -3566,12 +3741,12 @@ function chartTooltip(svg, options) {
3566
3741
  place(row, summary, (toPx) => ({ x: toPx.x(point.x), top: toPx.y(point.top), bottom: toPx.y(point.bottom) }), false);
3567
3742
  },
3568
3743
  describe(element2, row) {
3569
- const own = options.description?.();
3744
+ const own2 = options.description?.();
3570
3745
  let content;
3571
- if (own === false) content = void 0;
3572
- else if (typeof own === "function") {
3746
+ if (own2 === false) content = void 0;
3747
+ else if (typeof own2 === "function") {
3573
3748
  try {
3574
- const text2 = own(row.datum);
3749
+ const text2 = own2(row.datum);
3575
3750
  content = typeof text2 === "string" && text2 !== "" ? text2 : void 0;
3576
3751
  } catch (error) {
3577
3752
  report(error);
@@ -3788,7 +3963,7 @@ function barChart(target, options, env2) {
3788
3963
  setAttributes(ring, { transform: transform && transformAttribute(transform), visibility: void 0 });
3789
3964
  }
3790
3965
  function show3(record, row) {
3791
- const moved = geometryChanged(record.shown.geometry, row.geometry);
3966
+ const moved = geometryChanged(record.shown.geometry, row.geometry) || record.shown.datum !== row.datum;
3792
3967
  drawMark(record, row);
3793
3968
  if (moved) runner.change(row.geometry, row.data);
3794
3969
  if (record.key === hover.key) showTooltip(record);
@@ -3862,7 +4037,7 @@ function barChart(target, options, env2) {
3862
4037
  const values = record.series.map((series) => ({ series, value: now[series] ?? 0 }));
3863
4038
  const total2 = values.reduce((sum, v) => sum + v.value, 0);
3864
4039
  const text2 = record.count === void 0 ? row.value.text : format(current)(round(total2, record.count));
3865
- return placeRow(frame2, { key: row.key, datum: row.datum, index: row.index, category: row.label.text, values, slot: record.slot.value, text: text2 });
4040
+ return placeRow(frame2, { key: row.key, datum: row.datum, index: row.index, category: row.label.text, values, slot: record.slot.value, text: text2 }, measure);
3866
4041
  }
3867
4042
  function addTick(value, opacity) {
3868
4043
  const tick = {
@@ -3879,10 +4054,10 @@ function barChart(target, options, env2) {
3879
4054
  }
3880
4055
  }
3881
4056
  function drawTick(tick, frame2) {
3882
- const placed = placeTick(frame2, tick.value, format(current)(tick.value));
4057
+ const placed2 = placeTick(frame2, tick.value, format(current)(tick.value));
3883
4058
  const opacity = tick.opacity.value < 1 ? tick.opacity.value : void 0;
3884
- setAttributes(tick.line, { ...placed.line, opacity });
3885
- placeText(tick.label, placed.label);
4059
+ setAttributes(tick.line, { ...placed2.line, opacity });
4060
+ placeText(tick.label, placed2.label);
3886
4061
  setAttributes(tick.label, { opacity });
3887
4062
  }
3888
4063
  function draw() {
@@ -3904,11 +4079,11 @@ function barChart(target, options, env2) {
3904
4079
  tick.label.remove();
3905
4080
  ticks.delete(tick.value);
3906
4081
  }
3907
- for (const placed of laidOut.ticks) {
3908
- const tick = ticks.get(placed.value);
4082
+ for (const placed2 of laidOut.ticks) {
4083
+ const tick = ticks.get(placed2.value);
3909
4084
  if (!tick) continue;
3910
- setAttributes(tick.line, { ...placed.line, opacity: void 0 });
3911
- placeText(tick.label, placed.label);
4085
+ setAttributes(tick.line, { ...placed2.line, opacity: void 0 });
4086
+ placeText(tick.label, placed2.label);
3912
4087
  tick.label.removeAttribute("opacity");
3913
4088
  }
3914
4089
  for (const record of order) {
@@ -4075,7 +4250,7 @@ function barChart(target, options, env2) {
4075
4250
  });
4076
4251
  hover.sync();
4077
4252
  runner.enter(order.map(input));
4078
- return {
4253
+ return linkable(hover.link, {
4079
4254
  element: svg,
4080
4255
  async update(next) {
4081
4256
  if (destroyed) return;
@@ -4101,7 +4276,7 @@ function barChart(target, options, env2) {
4101
4276
  transitions.supersede();
4102
4277
  const swapping = swapped !== effects;
4103
4278
  effects = swapped;
4104
- const leaves = playUpdate(
4279
+ const leaves2 = playUpdate(
4105
4280
  {
4106
4281
  runner,
4107
4282
  events,
@@ -4123,7 +4298,7 @@ function barChart(target, options, env2) {
4123
4298
  );
4124
4299
  if (byCategory(current) !== byCategory(previous)) for (const record of [...order, ...leaving.values()]) dirty.add(record);
4125
4300
  const settled = transitionTo(nextLayout, motion2.mode === "off" || nextLayout.orientation !== orientation);
4126
- await transitions.wait(settled, leaves);
4301
+ await transitions.wait(settled, leaves2);
4127
4302
  },
4128
4303
  on: events.on,
4129
4304
  marks: () => order.map((record) => record.shown.geometry),
@@ -4163,7 +4338,7 @@ function barChart(target, options, env2) {
4163
4338
  order = [];
4164
4339
  svg.remove();
4165
4340
  }
4166
- };
4341
+ });
4167
4342
  }
4168
4343
  function checkOptions2(options) {
4169
4344
  checkChartOptions(options, "barChart");
@@ -4231,9 +4406,9 @@ var GAP3 = 10;
4231
4406
  var LABEL_ANGLE = Math.PI / 12;
4232
4407
  var LABEL_SIZE2 = 12.5;
4233
4408
  var VALUE_SIZE2 = 12.5;
4234
- var ASCENT = 10;
4409
+ var ASCENT2 = 10;
4235
4410
  var LINE = 15;
4236
- var BLOCK = ASCENT + LINE + 3;
4411
+ var BLOCK = ASCENT2 + LINE + 3;
4237
4412
  var LABEL_SPACE = 2;
4238
4413
  var CENTER_SIZE = 26;
4239
4414
  var CENTER_MIN = 14;
@@ -4262,17 +4437,18 @@ function layoutDonut(input) {
4262
4437
  const frame2 = donutFrame(input, rows2);
4263
4438
  const total2 = rows2.reduce((sum, row) => sum + row.value, 0);
4264
4439
  const starts = joinedStarts(rows2.map((row) => row.value));
4265
- const slices = rows2.map((row, i) => {
4440
+ const states = rows2.map((row, i) => {
4266
4441
  const share = total2 > 0 ? row.value / total2 : 0;
4267
4442
  const end = i + 1 < rows2.length && total2 > 0 ? starts[i + 1] : total2 > 0 ? 1 : 0;
4268
- return placeSlice(frame2, { ...row, series: input.encoding.series, share, start: starts[i] * TAU2, end: end * TAU2 });
4443
+ return { ...row, series: input.encoding.series, share, start: starts[i] * TAU2, end: end * TAU2 };
4269
4444
  });
4445
+ const labels = placeLabels(frame2, states, input.measure);
4270
4446
  const centerText2 = input.center(total2);
4271
4447
  return {
4272
4448
  frame: frame2,
4273
4449
  total: total2,
4274
- slices,
4275
- labels: placeLabels(frame2, slices, input.measure),
4450
+ slices: states.map((state, i) => placeSlice(frame2, state, labels[i], input.measure)),
4451
+ labels,
4276
4452
  centerText: centerText2,
4277
4453
  center: placeCenter(frame2, centerText2, input.measure)
4278
4454
  };
@@ -4286,7 +4462,7 @@ function joinedStarts(values) {
4286
4462
  return start;
4287
4463
  });
4288
4464
  }
4289
- function placeSlice(frame2, state) {
4465
+ function placeSlice(frame2, state, label2, measure) {
4290
4466
  const geometry = describe.arc({
4291
4467
  key: state.key,
4292
4468
  series: state.series,
@@ -4295,7 +4471,8 @@ function placeSlice(frame2, state) {
4295
4471
  inner: frame2.inner,
4296
4472
  outer: frame2.outer,
4297
4473
  start: state.start,
4298
- end: state.end
4474
+ end: state.end,
4475
+ labelBounds: label2 && measure ? labelBoxes2(label2, measure) : []
4299
4476
  });
4300
4477
  return { ...state, geometry, data: sliceData(state.datum, state.share, state.series) };
4301
4478
  }
@@ -4304,18 +4481,18 @@ function placeLabels(frame2, slices, measure) {
4304
4481
  let first;
4305
4482
  const labels = slices.map((slice, i) => {
4306
4483
  if (slice.end - slice.start < LABEL_ANGLE - 1e-9) return void 0;
4307
- const label = labelAt(frame2, slice, measure);
4308
- const { box } = label;
4484
+ const label2 = labelAt(frame2, slice, measure);
4485
+ const { box } = label2;
4309
4486
  if (box.x < 0 || box.y < 0 || box.x + box.width > frame2.width || box.y + box.height > frame2.height) return void 0;
4310
4487
  if (previous && overlaps(previous, box)) return void 0;
4311
4488
  previous = box;
4312
4489
  first ?? (first = i);
4313
- return label;
4490
+ return label2;
4314
4491
  });
4315
4492
  for (let i = labels.length - 1; first !== void 0 && i > first; i--) {
4316
- const label = labels[i];
4317
- if (!label) continue;
4318
- if (!overlaps(labels[first].box, label.box)) break;
4493
+ const label2 = labels[i];
4494
+ if (!label2) continue;
4495
+ if (!overlaps(labels[first].box, label2.box)) break;
4319
4496
  labels[i] = void 0;
4320
4497
  }
4321
4498
  return labels;
@@ -4371,11 +4548,17 @@ function labelAt(frame2, slice, measure) {
4371
4548
  const top = y - BLOCK * (cos + 1) / 2;
4372
4549
  const along = (w) => x + sin * w / 2;
4373
4550
  return {
4374
- category: { x: along(widths[0]), y: top + ASCENT, anchor: "middle", text: slice.category },
4375
- share: { x: along(widths[1]), y: top + ASCENT + LINE, anchor: "middle", text: share },
4551
+ category: { x: along(widths[0]), y: top + ASCENT2, anchor: "middle", text: slice.category },
4552
+ share: { x: along(widths[1]), y: top + ASCENT2 + LINE, anchor: "middle", text: share },
4376
4553
  box: { x: along(width) - width / 2, y: top, width, height: BLOCK }
4377
4554
  };
4378
4555
  }
4556
+ function labelBoxes2(label2, measure) {
4557
+ const out = [];
4558
+ if (label2.category.text !== "") out.push(textBox(label2.category, measure, "ec-label", LABEL_SIZE2));
4559
+ if (label2.share.text !== "") out.push(textBox(label2.share, measure, "ec-value", VALUE_SIZE2));
4560
+ return out;
4561
+ }
4379
4562
  function overlaps(a, b) {
4380
4563
  return a.x < b.x + b.width + LABEL_SPACE && b.x < a.x + a.width + LABEL_SPACE && a.y < b.y + b.height + LABEL_SPACE && b.y < a.y + a.height + LABEL_SPACE;
4381
4564
  }
@@ -4511,7 +4694,7 @@ function donutChart(target, options, env2) {
4511
4694
  byGroup.set(group, record);
4512
4695
  return record;
4513
4696
  }
4514
- function drawMark(record, slice, label) {
4697
+ function drawMark(record, slice, label2) {
4515
4698
  const before = record.parts[0]?.colors.color;
4516
4699
  record.shown = slice;
4517
4700
  const { outline: outline2 } = slice.geometry;
@@ -4524,10 +4707,10 @@ function donutChart(target, options, env2) {
4524
4707
  record.parts = [{ element: record.path, d: outline2.d, colors: sliceColors, visible }];
4525
4708
  const presence = record.presence.value;
4526
4709
  const opacity = presence < 1 ? presence : void 0;
4527
- record.drawnLabel = label;
4710
+ record.drawnLabel = label2;
4528
4711
  for (const [text2, placement] of [
4529
- [record.label, label?.category],
4530
- [record.share, label?.share]
4712
+ [record.label, label2?.category],
4713
+ [record.share, label2?.share]
4531
4714
  ]) {
4532
4715
  if (placement) placeText(text2, placement);
4533
4716
  setAttributes(text2, { visibility: placement ? void 0 : "hidden", opacity });
@@ -4540,9 +4723,9 @@ function donutChart(target, options, env2) {
4540
4723
  const record = key === void 0 ? void 0 : records.get(key);
4541
4724
  focusRing.draw(record && { outline: record.shown.geometry.outline, thickness: record.shown.geometry.thickness, transform: record.handle.style.transform });
4542
4725
  }
4543
- function show3(record, slice, label) {
4544
- const moved = geometryChanged(record.shown.geometry, slice.geometry);
4545
- drawMark(record, slice, label);
4726
+ function show3(record, slice, label2) {
4727
+ const moved = geometryChanged(record.shown.geometry, slice.geometry) || record.shown.datum !== slice.datum;
4728
+ drawMark(record, slice, label2);
4546
4729
  if (moved) runner.change(slice.geometry, slice.data);
4547
4730
  if (record.key === hover.key) showTooltip(record);
4548
4731
  }
@@ -4642,9 +4825,9 @@ function donutChart(target, options, env2) {
4642
4825
  return out;
4643
4826
  }
4644
4827
  function currentSlices(f) {
4645
- return [...angles()].map(([record, { start, span }]) => {
4828
+ const now = [...angles()].map(([record, { start, span }]) => {
4646
4829
  const { row } = record;
4647
- const slice = placeSlice(f, {
4830
+ const state = {
4648
4831
  key: row.key,
4649
4832
  datum: row.datum,
4650
4833
  index: row.index,
@@ -4654,9 +4837,15 @@ function donutChart(target, options, env2) {
4654
4837
  share: span,
4655
4838
  start: start * TAU3,
4656
4839
  end: (start + span) * TAU3
4657
- });
4658
- return { record, slice };
4840
+ };
4841
+ return { record, state };
4659
4842
  });
4843
+ const labels = placeLabels(
4844
+ f,
4845
+ now.map(({ state }) => state),
4846
+ measure
4847
+ );
4848
+ return now.map(({ record, state }, i) => ({ record, slice: placeSlice(f, state, labels[i], measure), label: labels[i] }));
4660
4849
  }
4661
4850
  function draw() {
4662
4851
  if (!dirty) return;
@@ -4664,12 +4853,7 @@ function donutChart(target, options, env2) {
4664
4853
  const f = frame2.value;
4665
4854
  setAttributes(svg, sizeAttributes(f));
4666
4855
  const slices = currentSlices(f);
4667
- const labels = placeLabels(
4668
- f,
4669
- slices.map(({ slice }) => slice),
4670
- measure
4671
- );
4672
- slices.forEach(({ record, slice }, i) => show3(record, slice, labels[i]));
4856
+ for (const { record, slice, label: label2 } of slices) show3(record, slice, label2);
4673
4857
  const total2 = slices.reduce((sum, { slice }) => sum + slice.value, 0);
4674
4858
  drawCenter(placeCenter(f, count === void 0 ? laidOut.centerText : counting(round(total2, count)), measure));
4675
4859
  }
@@ -4868,7 +5052,7 @@ function donutChart(target, options, env2) {
4868
5052
  drawCenter(laidOut.center);
4869
5053
  hover.sync();
4870
5054
  runner.enter(order.map(input));
4871
- return {
5055
+ return linkable(hover.link, {
4872
5056
  element: svg,
4873
5057
  async update(next) {
4874
5058
  if (destroyed) return;
@@ -4898,7 +5082,7 @@ function donutChart(target, options, env2) {
4898
5082
  transitions.supersede();
4899
5083
  const swapping = swapped !== effects;
4900
5084
  effects = swapped;
4901
- const leaves = playUpdate(
5085
+ const leaves2 = playUpdate(
4902
5086
  {
4903
5087
  runner,
4904
5088
  events,
@@ -4920,7 +5104,7 @@ function donutChart(target, options, env2) {
4920
5104
  );
4921
5105
  count = nextLayout.total === totalBefore ? void 0 : Math.max(decimals(totalBefore), decimals(nextLayout.total));
4922
5106
  const settled = transitionTo(nextLayout, motion2.mode === "off");
4923
- await transitions.wait(settled, leaves);
5107
+ await transitions.wait(settled, leaves2);
4924
5108
  },
4925
5109
  on: events.on,
4926
5110
  marks: () => order.map((record) => record.shown.geometry),
@@ -4959,7 +5143,7 @@ function donutChart(target, options, env2) {
4959
5143
  order = ring = from = [];
4960
5144
  svg.remove();
4961
5145
  }
4962
- };
5146
+ });
4963
5147
  }
4964
5148
  function checkOptions3(options) {
4965
5149
  checkChartOptions(options, "donutChart");
@@ -4969,8 +5153,8 @@ function checkOptions3(options) {
4969
5153
  }
4970
5154
  function valueText(slice, options) {
4971
5155
  const formatted = format(options)(slice.value);
4972
- const label = seriesLabel(options.seriesLabels, slice.series);
4973
- return slice.series === "value" && label === "value" ? formatted : `${formatted} ${label}`;
5156
+ const label2 = seriesLabel(options.seriesLabels, slice.series);
5157
+ return slice.series === "value" && label2 === "value" ? formatted : `${formatted} ${label2}`;
4974
5158
  }
4975
5159
  function namesFor(options, layout) {
4976
5160
  return new Map(layout.slices.map((slice) => [slice.key, markLabel2(slice, options)]));
@@ -5000,9 +5184,9 @@ function centerText(options, series, total2) {
5000
5184
  const formatted = format(options);
5001
5185
  if (center === false) return "";
5002
5186
  if (center === void 0) {
5003
- const label = seriesLabel(options.seriesLabels, series);
5004
- return series === "value" && label === "value" ? formatted(total2) : `${formatted(total2)}
5005
- ${label}`;
5187
+ const label2 = seriesLabel(options.seriesLabels, series);
5188
+ return series === "value" && label2 === "value" ? formatted(total2) : `${formatted(total2)}
5189
+ ${label2}`;
5006
5190
  }
5007
5191
  try {
5008
5192
  const text2 = center(total2, formatted);
@@ -5012,10 +5196,10 @@ ${label}`;
5012
5196
  return "";
5013
5197
  }
5014
5198
  }
5015
- function description(own, center) {
5199
+ function description(own2, center) {
5016
5200
  const text2 = center.split("\n").join(" ").trim();
5017
- const mine = own?.trim();
5018
- if (text2 === "") return own;
5201
+ const mine = own2?.trim();
5202
+ if (text2 === "") return own2;
5019
5203
  if (!mine) return text2;
5020
5204
  return /[.!?:;]$/.test(mine) ? `${mine} ${text2}` : `${mine}. ${text2}`;
5021
5205
  }
@@ -5133,9 +5317,9 @@ function timeName(times, zone) {
5133
5317
  function tickWording(zone) {
5134
5318
  const formats = /* @__PURE__ */ new Map();
5135
5319
  return (t, upTo) => {
5136
- const own = LEVELS.indexOf(timeLevel(t, zone));
5320
+ const own2 = LEVELS.indexOf(timeLevel(t, zone));
5137
5321
  const fields = {};
5138
- for (let i = Math.min(own, LEVELS.indexOf(upTo)); i <= own; i++) Object.assign(fields, FIELDS[LEVELS[i]]);
5322
+ for (let i = Math.min(own2, LEVELS.indexOf(upTo)); i <= own2; i++) Object.assign(fields, FIELDS[LEVELS[i]]);
5139
5323
  const id = JSON.stringify(fields);
5140
5324
  let format2 = formats.get(id);
5141
5325
  if (!format2) formats.set(id, format2 = new Intl.DateTimeFormat(void 0, { ...fields, timeZone: zoneOption(zone) }));
@@ -5242,7 +5426,7 @@ function positions(frame2) {
5242
5426
  y: (value) => ySpan > 0 ? box.bottom - (value - scale2.lo) / ySpan * (box.bottom - box.top) : box.bottom
5243
5427
  };
5244
5428
  }
5245
- function placeLines(frame2, rows2, series, through, time = false) {
5429
+ function placeLines(frame2, rows2, series, through, time = false, labels) {
5246
5430
  const first = rows2[0];
5247
5431
  if (!first) return [];
5248
5432
  const at = positions(frame2);
@@ -5253,15 +5437,23 @@ function placeLines(frame2, rows2, series, through, time = false) {
5253
5437
  const share = next && next.x > end.x && through > end.x ? (through - end.x) / (next.x - end.x) : void 0;
5254
5438
  const shown = rows2.slice(0, last + 1);
5255
5439
  const datas = /* @__PURE__ */ new Map();
5256
- const related = (own) => (name) => name === own ? void 0 : datas.get(name);
5257
- const lines = series.map((name) => {
5440
+ const related = (own2) => (name) => name === own2 ? void 0 : datas.get(name);
5441
+ const traced = series.map((name) => {
5258
5442
  const vertices = shown.map((row) => ({ at: row.x, value: row.values[name] ?? 0 }));
5259
5443
  if (share !== void 0) {
5260
5444
  const from = end.values[name] ?? 0;
5261
5445
  vertices.push({ at: through, value: from + share * ((next.values[name] ?? 0) - from) });
5262
5446
  }
5263
- const points = vertices.map((v) => ({ x: at.x(v.at), y: at.y(v.value) }));
5264
- const geometry = describe.line({ key: name, series: name, points, width: LINE_WIDTH });
5447
+ return { name, vertices, points: vertices.map((v) => ({ x: at.x(v.at), y: at.y(v.value) })) };
5448
+ });
5449
+ const placed2 = labels ? placeEndLabels(
5450
+ frame2,
5451
+ traced.map(({ name, vertices, points }) => ({ ...points[points.length - 1], text: labels.text(name, vertices[vertices.length - 1].value) }))
5452
+ ) : [];
5453
+ const lines = traced.map(({ name, vertices, points }, i) => {
5454
+ const label2 = placed2[i];
5455
+ const labelBounds = labels ? label2 && label2.text !== "" ? [textBox(label2, labels.measure, "ec-value", VALUE_SIZE3)] : [] : void 0;
5456
+ const geometry = describe.line({ key: name, series: name, points, width: LINE_WIDTH, ...labelBounds ? { labelBounds } : {} });
5265
5457
  let distance3 = 0;
5266
5458
  const samples = vertices.map((v, j) => {
5267
5459
  if (j > 0) distance3 += Math.hypot(points[j].x - points[j - 1].x, points[j].y - points[j - 1].y);
@@ -5271,7 +5463,7 @@ function placeLines(frame2, rows2, series, through, time = false) {
5271
5463
  const data = { datum: end.datum, samples, related: related(name) };
5272
5464
  datas.set(name, data);
5273
5465
  const tip = vertices[vertices.length - 1];
5274
- return { series: name, geometry, data, end: { ...points[points.length - 1], value: tip.value } };
5466
+ return { series: name, geometry, data, end: { ...points[points.length - 1], value: tip.value }, label: label2 };
5275
5467
  });
5276
5468
  return lines;
5277
5469
  }
@@ -5417,11 +5609,11 @@ function numberOf3(value, series, key) {
5417
5609
  if (typeof value === "number" && Number.isFinite(value)) return value;
5418
5610
  throw new RangeError(`lineChart: "${series}" for "${key}" must be a finite number, got ${show(value)}. Lines can't skip a value yet.`);
5419
5611
  }
5420
- function distinctLabels(rows2, label) {
5612
+ function distinctLabels(rows2, label2) {
5421
5613
  const shapes = /* @__PURE__ */ new Map();
5422
5614
  for (const row of rows2) {
5423
5615
  for (const { series, value } of row.values) {
5424
- const text2 = label(series, value);
5616
+ const text2 = label2(series, value);
5425
5617
  const shape = text2.replace(/\d/g, "0");
5426
5618
  if (!shapes.has(shape)) shapes.set(shape, text2);
5427
5619
  }
@@ -5548,8 +5740,8 @@ function lineChart(target, options, env2) {
5548
5740
  const text2 = `${formatted(value)} ${seriesLabel(opts.seriesLabels, series)}`;
5549
5741
  if (typeof labels !== "function") return text2;
5550
5742
  try {
5551
- const own = labels(value, series, formatted);
5552
- return own === void 0 || own === null ? "" : String(own);
5743
+ const own2 = labels(value, series, formatted);
5744
+ return own2 === void 0 || own2 === null ? "" : String(own2);
5553
5745
  } catch (error) {
5554
5746
  if (!quiet && !labelFailures.has(labels)) {
5555
5747
  labelFailures.add(labels);
@@ -5559,10 +5751,15 @@ function lineChart(target, options, env2) {
5559
5751
  }
5560
5752
  };
5561
5753
  }
5754
+ function endLabels(given) {
5755
+ const label2 = labeler(current);
5756
+ if (!label2) return void 0;
5757
+ return { text: (series, value) => label2(series, round(value, given[series] ?? decimals(value))), measure };
5758
+ }
5562
5759
  function placedFor(next) {
5563
5760
  const states = next.rows.map(restState);
5564
5761
  return {
5565
- lines: new Map(placeLines(next.frame, states, next.series, drawnThrough(next), next.time).map((line2) => [line2.series, line2])),
5762
+ lines: new Map(placeLines(next.frame, states, next.series, drawnThrough(next), next.time, endLabels(next.decimals)).map((line2) => [line2.series, line2])),
5566
5763
  points: new Map(states.flatMap((state) => placePoints(next.frame, state, next.series, next.time)).map((point) => [point.key, point]))
5567
5764
  };
5568
5765
  }
@@ -5595,7 +5792,7 @@ function lineChart(target, options, env2) {
5595
5792
  byColumn.set(column, record);
5596
5793
  return record;
5597
5794
  }
5598
- function createLine(series, placed, entering) {
5795
+ function createLine(series, placed2, entering) {
5599
5796
  const group = svgElement("g", { class: "ec-line", "data-key": series, "data-series": series }, linesLayer);
5600
5797
  const body = svgElement("g", { class: "ec-body" }, group);
5601
5798
  const record = {
@@ -5610,28 +5807,28 @@ function lineChart(target, options, env2) {
5610
5807
  drawnLabel: void 0,
5611
5808
  parts: [],
5612
5809
  handle: svgMarkHandle(() => record),
5613
- target: placed,
5614
- shown: placed,
5810
+ target: placed2,
5811
+ shown: placed2,
5615
5812
  presence: animated(entering ? 0 : 1, interpolateNumber, { clock, motion: motion2, onChange: changed }),
5616
5813
  leave: void 0
5617
5814
  };
5618
5815
  return record;
5619
5816
  }
5620
- function createPoint(row, placed) {
5621
- const group = svgElement("g", { class: "ec-point", "data-key": placed.key, "data-series": placed.series }, pointsLayer);
5817
+ function createPoint(row, placed2) {
5818
+ const group = svgElement("g", { class: "ec-point", "data-key": placed2.key, "data-series": placed2.series }, pointsLayer);
5622
5819
  const body = svgElement("g", { class: "ec-body" }, group);
5623
5820
  const record = {
5624
5821
  kind: "point",
5625
- key: placed.key,
5626
- series: placed.series,
5822
+ key: placed2.key,
5823
+ series: placed2.series,
5627
5824
  row,
5628
5825
  group,
5629
5826
  body,
5630
5827
  path: svgElement("path", { class: "ec-dot" }, body),
5631
5828
  parts: [],
5632
5829
  handle: svgMarkHandle(() => record),
5633
- target: placed,
5634
- shown: placed,
5830
+ target: placed2,
5831
+ shown: placed2,
5635
5832
  hidden: void 0,
5636
5833
  leave: void 0
5637
5834
  };
@@ -5642,14 +5839,14 @@ function lineChart(target, options, env2) {
5642
5839
  const leavingLines = () => [...leaving.values()].filter((record) => record.kind === "line");
5643
5840
  const currentFrame = () => ({ scale: scale2.value, box: box.value });
5644
5841
  function currentRows() {
5645
- const own = (record) => ({ x: record.x.value, values: record.values.value });
5842
+ const own2 = (record) => ({ x: record.x.value, values: record.values.value });
5646
5843
  const states = /* @__PURE__ */ new Map();
5647
5844
  const visiting = /* @__PURE__ */ new Set();
5648
5845
  const stateOf = (record) => {
5649
5846
  const known = states.get(record);
5650
5847
  if (known) return known;
5651
5848
  const p = record.presence.value;
5652
- let state = own(record);
5849
+ let state = own2(record);
5653
5850
  if (record.anchor && p < 1 && !visiting.has(record)) {
5654
5851
  visiting.add(record);
5655
5852
  const from = stateOf(record.anchor);
@@ -5673,8 +5870,8 @@ function lineChart(target, options, env2) {
5673
5870
  paintFrame(frame2);
5674
5871
  paintLines(frame2, states.map((s) => s.state));
5675
5872
  for (const { record, state } of states) {
5676
- const placed = new Map(placePoints(frame2, state, record.points.map((point) => point.series), laidOut.time).map((point) => [point.key, point]));
5677
- showAll(record.points.filter(drawn).map((point) => ({ record: point, placed: placed.get(point.key) })));
5873
+ const placed2 = new Map(placePoints(frame2, state, record.points.map((point) => point.series), laidOut.time).map((point) => [point.key, point]));
5874
+ showAll(record.points.filter(drawn).map((point) => ({ record: point, placed: placed2.get(point.key) })));
5678
5875
  }
5679
5876
  paintColumns(frame2, states);
5680
5877
  followHover();
@@ -5706,11 +5903,11 @@ function lineChart(target, options, env2) {
5706
5903
  tick.label.remove();
5707
5904
  ticks.delete(tick.value);
5708
5905
  }
5709
- for (const placed2 of placedTicks) {
5710
- const tick = ticks.get(placed2.value);
5906
+ for (const placed3 of placedTicks) {
5907
+ const tick = ticks.get(placed3.value);
5711
5908
  if (!tick) continue;
5712
- if (tick.line && "line" in placed2) setAttributes(tick.line, { ...placed2.line, opacity: void 0 });
5713
- placeText(tick.label, placed2.label);
5909
+ if (tick.line && "line" in placed3) setAttributes(tick.line, { ...placed3.line, opacity: void 0 });
5910
+ placeText(tick.label, placed3.label);
5714
5911
  tick.label.removeAttribute("opacity");
5715
5912
  }
5716
5913
  }
@@ -5718,7 +5915,7 @@ function lineChart(target, options, env2) {
5718
5915
  const { frame: frame2 } = laidOut;
5719
5916
  setAttributes(svg, sizeAttributes(frame2.box));
5720
5917
  drawnFrame = frame2;
5721
- const placed = placedFor(laidOut);
5918
+ const placed2 = placedFor(laidOut);
5722
5919
  const settle = (records, next) => {
5723
5920
  const pairs = records.flatMap((record) => {
5724
5921
  const to = next(record);
@@ -5728,10 +5925,10 @@ function lineChart(target, options, env2) {
5728
5925
  if (!kept) for (const { record, to } of pairs) record.target = to;
5729
5926
  showAll(pairs.map(({ record }) => ({ record, placed: record.target })));
5730
5927
  };
5731
- settle(lineOrder, (line2) => placed.lines.get(line2.series));
5732
- paintLabels(frame2, new Map(lineOrder.flatMap((line2) => placed.lines.has(line2.series) ? [[line2, placed.lines.get(line2.series)]] : [])));
5928
+ settle(lineOrder, (line2) => placed2.lines.get(line2.series));
5929
+ paintLabels(new Map(lineOrder.flatMap((line2) => placed2.lines.has(line2.series) ? [[line2, placed2.lines.get(line2.series)]] : [])));
5733
5930
  const states = rowOrder.map((record) => ({ record, state: restState(record.row) }));
5734
- for (const { record } of states) settle(livePoints(record), (point) => placed.points.get(point.key));
5931
+ for (const { record } of states) settle(livePoints(record), (point) => placed2.points.get(point.key));
5735
5932
  paintColumns(frame2, states);
5736
5933
  followHover();
5737
5934
  dirty = false;
@@ -5741,10 +5938,10 @@ function lineChart(target, options, env2) {
5741
5938
  setAttributes(svg, sizeAttributes(frame2.box));
5742
5939
  const formatted = format(current);
5743
5940
  for (const tick of yTicks.values()) {
5744
- const placed = placeYTick(frame2, tick.value, formatted(tick.value));
5941
+ const placed2 = placeYTick(frame2, tick.value, formatted(tick.value));
5745
5942
  const opacity = tick.opacity.value < 1 ? tick.opacity.value : void 0;
5746
- setAttributes(tick.line, { ...placed.line, opacity });
5747
- placeText(tick.label, placed.label);
5943
+ setAttributes(tick.line, { ...placed2.line, opacity });
5944
+ placeText(tick.label, placed2.label);
5748
5945
  setAttributes(tick.label, { opacity });
5749
5946
  }
5750
5947
  for (const tick of xTicks.values()) {
@@ -5755,46 +5952,39 @@ function lineChart(target, options, env2) {
5755
5952
  function paintLines(frame2, states) {
5756
5953
  const drawnLines = [...lineOrder, ...leavingLines()];
5757
5954
  if (states.length === 0 || drawnLines.length === 0) return;
5758
- const placed = placeLines(frame2, states, drawnLines.map((line2) => line2.series), drawnThrough(laidOut), laidOut.time);
5759
- showAll(drawnLines.map((line2, i) => ({ record: line2, placed: placed[i] })));
5760
- paintLabels(frame2, new Map(drawnLines.map((line2, i) => [line2, placed[i]])));
5761
- }
5762
- function paintLabels(frame2, ends) {
5763
- const label = labeler(current);
5764
- const entries = [...ends];
5765
- const placed = label ? placeEndLabels(
5766
- frame2,
5767
- entries.map(([line2, { end }]) => ({ x: end.x, y: end.y, text: label(line2.series, round(end.value, counting[line2.series] ?? decimals(end.value))) }))
5768
- ) : [];
5769
- entries.forEach(([line2], i) => {
5770
- const text2 = placed[i];
5955
+ const placed2 = placeLines(frame2, states, drawnLines.map((line2) => line2.series), drawnThrough(laidOut), laidOut.time, endLabels(counting));
5956
+ showAll(drawnLines.map((line2, i) => ({ record: line2, placed: placed2[i] })));
5957
+ paintLabels(new Map(drawnLines.map((line2, i) => [line2, placed2[i]])));
5958
+ }
5959
+ function paintLabels(ends) {
5960
+ for (const [line2, { label: text2 }] of ends) {
5771
5961
  if (text2) placeText(line2.label, text2);
5772
5962
  line2.drawnLabel = text2 && text2.text !== "" ? text2 : void 0;
5773
5963
  setAttributes(line2.label, { visibility: line2.drawnLabel ? void 0 : "hidden" });
5774
- });
5964
+ }
5775
5965
  }
5776
5966
  function showAll(marks) {
5777
- const related = marks.some(({ record, placed }) => !sameData(record.shown.data, placed.data));
5778
- for (const { record, placed } of marks) {
5779
- if (record.kind === "line") showLine(record, placed, related);
5780
- else showPoint(record, placed, related);
5967
+ const related = marks.some(({ record, placed: placed2 }) => !sameData(record.shown.data, placed2.data));
5968
+ for (const { record, placed: placed2 } of marks) {
5969
+ if (record.kind === "line") showLine(record, placed2, related);
5970
+ else showPoint(record, placed2, related);
5781
5971
  }
5782
5972
  }
5783
- function showLine(record, placed, related) {
5784
- const moved = related || geometryChanged(record.shown.geometry, placed.geometry);
5785
- record.shown = placed;
5786
- const { geometry } = placed;
5973
+ function showLine(record, placed2, related) {
5974
+ const moved = related || geometryChanged(record.shown.geometry, placed2.geometry);
5975
+ record.shown = placed2;
5976
+ const { geometry } = placed2;
5787
5977
  paint(record, seriesColors(colors.slot(record.series)), { visible: geometry.length >= VISIBLE2, open: { width: geometry.thickness } });
5788
5978
  setAttributes(record.end, { cx: geometry.end.x, cy: geometry.end.y });
5789
5979
  const presence = record.presence.value;
5790
5980
  setAttributes(record.group, { opacity: presence < 1 ? presence : void 0 });
5791
- if (moved) runner.change(geometry, placed.data);
5981
+ if (moved) runner.change(geometry, placed2.data);
5792
5982
  }
5793
- function showPoint(record, placed, related) {
5794
- const moved = related || geometryChanged(record.shown.geometry, placed.geometry);
5795
- record.shown = placed;
5983
+ function showPoint(record, placed2, related) {
5984
+ const moved = related || geometryChanged(record.shown.geometry, placed2.geometry);
5985
+ record.shown = placed2;
5796
5986
  paint(record, seriesColors(colors.slot(record.series)), { visible: true });
5797
- if (moved) runner.change(placed.geometry, placed.data);
5987
+ if (moved) runner.change(placed2.geometry, placed2.data);
5798
5988
  }
5799
5989
  function paint(record, markColors, part) {
5800
5990
  const before = record.parts[0];
@@ -5957,7 +6147,7 @@ function lineChart(target, options, env2) {
5957
6147
  }
5958
6148
  function arrange(next) {
5959
6149
  laidOut = next;
5960
- const placed = placedFor(next);
6150
+ const placed2 = placedFor(next);
5961
6151
  const diff = { entering: [], exiting: [], changed: [] };
5962
6152
  const keys = new Set(next.rows.map((row) => row.key));
5963
6153
  const series = next.rows.length > 0 ? next.series : [];
@@ -6009,7 +6199,7 @@ function lineChart(target, options, env2) {
6009
6199
  const previousLines = lineOrder;
6010
6200
  lineOrder = series.map((name) => {
6011
6201
  let line2 = lines.get(name);
6012
- const target2 = placed.lines.get(name);
6202
+ const target2 = placed2.lines.get(name);
6013
6203
  if (line2) {
6014
6204
  const values = [...stayed].some((record) => valueIn(was.get(record), name) !== valueIn(record.row, name));
6015
6205
  if (rowsMoved || values) diff.changed.push({ record: line2, from: line2.shown.geometry });
@@ -6025,7 +6215,7 @@ function lineChart(target, options, env2) {
6025
6215
  const old = stayed.has(record) ? was.get(record) : void 0;
6026
6216
  const live = series.map((name) => {
6027
6217
  const key = pointKey(name, record.key);
6028
- const target2 = placed.points.get(key);
6218
+ const target2 = placed2.points.get(key);
6029
6219
  let point = points.get(key);
6030
6220
  if (point) {
6031
6221
  if (old && valueIn(old, name) !== valueIn(record.row, name)) diff.changed.push({ record: point, from: point.shown.geometry });
@@ -6060,11 +6250,11 @@ function lineChart(target, options, env2) {
6060
6250
  function retarget(next, jump) {
6061
6251
  dirty = true;
6062
6252
  const { frame: frame2 } = next;
6063
- for (const [ticks, placed, lined] of [
6253
+ for (const [ticks, placed2, lined] of [
6064
6254
  [yTicks, next.yTicks, true],
6065
6255
  [xTicks, next.xTicks, false]
6066
6256
  ]) {
6067
- const wanted = new Set(placed.map((tick) => tick.value));
6257
+ const wanted = new Set(placed2.map((tick) => tick.value));
6068
6258
  for (const value of wanted) if (!ticks.has(value)) addTick(ticks, value, 0, lined);
6069
6259
  for (const tick of ticks.values()) tick.wanted = wanted.has(tick.value);
6070
6260
  }
@@ -6127,9 +6317,9 @@ function lineChart(target, options, env2) {
6127
6317
  const next = layout(current);
6128
6318
  const byKey = new Map(next.rows.map((row) => [row.key, row]));
6129
6319
  for (const record of rowOrder) record.row = byKey.get(record.key) ?? record.row;
6130
- const placed = placedFor(next);
6131
- for (const line2 of lineOrder) line2.target = placed.lines.get(line2.series) ?? line2.target;
6132
- for (const point of points.values()) point.target = placed.points.get(point.key) ?? point.target;
6320
+ const placed2 = placedFor(next);
6321
+ for (const line2 of lineOrder) line2.target = placed2.lines.get(line2.series) ?? line2.target;
6322
+ for (const point of points.values()) point.target = placed2.points.get(point.key) ?? point.target;
6133
6323
  void transitionTo(next, true);
6134
6324
  }
6135
6325
  const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
@@ -6144,28 +6334,28 @@ function lineChart(target, options, env2) {
6144
6334
  syncLegend();
6145
6335
  table.render(firstTable);
6146
6336
  {
6147
- const placed = placedFor(laidOut);
6337
+ const placed2 = placedFor(laidOut);
6148
6338
  for (const tick of laidOut.yTicks) addTick(yTicks, tick.value, 1, true);
6149
6339
  for (const tick of laidOut.xTicks) addTick(xTicks, tick.value, 1, false, tick.label.text);
6150
6340
  rowOrder = laidOut.rows.map((row) => {
6151
6341
  const record = createRow(row, false);
6152
6342
  rows2.set(row.key, record);
6153
6343
  record.points = laidOut.series.map((name) => {
6154
- const point = createPoint(record, placed.points.get(pointKey(name, row.key)));
6344
+ const point = createPoint(record, placed2.points.get(pointKey(name, row.key)));
6155
6345
  points.set(point.key, point);
6156
6346
  return point;
6157
6347
  });
6158
6348
  labelColumn(record);
6159
6349
  return record;
6160
6350
  });
6161
- lineOrder = laidOut.rows.length > 0 ? laidOut.series.map((name) => createLine(name, placed.lines.get(name), false)) : [];
6351
+ lineOrder = laidOut.rows.length > 0 ? laidOut.series.map((name) => createLine(name, placed2.lines.get(name), false)) : [];
6162
6352
  for (const line2 of lineOrder) lines.set(line2.series, line2);
6163
6353
  land();
6164
6354
  }
6165
6355
  const liveMarks = () => [...lineOrder, ...rowOrder.flatMap(livePoints)];
6166
6356
  hover.sync();
6167
6357
  runner.enter(liveMarks().map(input));
6168
- return {
6358
+ return linkable(hover.link, {
6169
6359
  element: svg,
6170
6360
  async update(next) {
6171
6361
  if (destroyed) return;
@@ -6192,7 +6382,7 @@ function lineChart(target, options, env2) {
6192
6382
  transitions.supersede();
6193
6383
  const swapping = swapped !== effects;
6194
6384
  effects = swapped;
6195
- const leaves = playUpdate(
6385
+ const leaves2 = playUpdate(
6196
6386
  {
6197
6387
  runner,
6198
6388
  events,
@@ -6214,7 +6404,7 @@ function lineChart(target, options, env2) {
6214
6404
  );
6215
6405
  syncLegend();
6216
6406
  const settled = transitionTo(nextLayout, motion2.mode === "off");
6217
- await transitions.wait(settled, leaves);
6407
+ await transitions.wait(settled, leaves2);
6218
6408
  },
6219
6409
  reveal(x) {
6220
6410
  if (destroyed) return;
@@ -6269,7 +6459,7 @@ function lineChart(target, options, env2) {
6269
6459
  lineOrder = [];
6270
6460
  svg.remove();
6271
6461
  }
6272
- };
6462
+ });
6273
6463
  }
6274
6464
  function restState(row) {
6275
6465
  return { key: row.key, datum: row.datum, x: row.x, values: valuesOf2(row.values) };
@@ -6785,7 +6975,6 @@ function watchHost(doc, clock, onChanges) {
6785
6975
 
6786
6976
  // src/charts/adapter/expressive.ts
6787
6977
  var SVG_NS2 = "http://www.w3.org/2000/svg";
6788
- var ONE = { index: 0, count: 1 };
6789
6978
  var WRAPPING_ROLES = /* @__PURE__ */ new Set(["img", "image", "graphics-symbol", "graphics-object"]);
6790
6979
  function expressive(target, options, env2) {
6791
6980
  checkOptions4(options);
@@ -6871,11 +7060,11 @@ function expressive(target, options, env2) {
6871
7060
  if (options.samples) return checkSamples(options.samples(datum, of), series === void 0 ? `"${key}"` : `"${key}" (${series})`);
6872
7061
  return total2 === void 0 ? [] : barSamples(geometry, of, total2);
6873
7062
  };
6874
- const own = /* @__PURE__ */ new Map();
6875
- const related = (series) => own.get(series) ?? relatedOf(series, key);
7063
+ const own2 = /* @__PURE__ */ new Map();
7064
+ const related = (series) => own2.get(series) ?? relatedOf(series, key);
6876
7065
  for (const series of ownSeries(mark)) {
6877
7066
  const datum = (parts.find((p) => p.series === series) ?? parts[0]).datum;
6878
- own.set(series, { datum, samples: samplesOf(datum, geometry.segments?.find((s) => s.series === series) ?? geometry, series), related });
7067
+ own2.set(series, { datum, samples: samplesOf(datum, geometry.segments?.find((s) => s.series === series) ?? geometry, series), related });
6879
7068
  }
6880
7069
  return { ...mark, data: { datum: parts[0].datum, samples: samplesOf(parts[0].datum, geometry), related } };
6881
7070
  });
@@ -6943,6 +7132,7 @@ function expressive(target, options, env2) {
6943
7132
  let hovered;
6944
7133
  let ringKey;
6945
7134
  let interaction;
7135
+ let linked2;
6946
7136
  let destroyed = false;
6947
7137
  const make = (tag, attributes, parent) => {
6948
7138
  const created = doc.createElementNS(SVG_NS2, tag);
@@ -7027,13 +7217,13 @@ function expressive(target, options, env2) {
7027
7217
  }
7028
7218
  function nameMark(record) {
7029
7219
  if (!options.markLabel) return;
7030
- const { label, parts } = record.mark;
7220
+ const { label: label2, parts } = record.mark;
7031
7221
  parts.forEach((part2, index) => {
7032
- const named = label !== void 0 && index === 0;
7222
+ const named = label2 !== void 0 && index === 0;
7033
7223
  edits.attribute(part2.element, "role", named ? "img" : null);
7034
- edits.attribute(part2.element, "aria-label", named ? label : null);
7224
+ edits.attribute(part2.element, "aria-label", named ? label2 : null);
7035
7225
  if (named) edits.remove(part2.element, "aria-hidden");
7036
- else edits.attribute(part2.element, "aria-hidden", label === void 0 ? null : "true");
7226
+ else edits.attribute(part2.element, "aria-hidden", label2 === void 0 ? null : "true");
7037
7227
  });
7038
7228
  }
7039
7229
  function unwrapNames() {
@@ -7084,12 +7274,12 @@ function expressive(target, options, env2) {
7084
7274
  },
7085
7275
  hover(hoverTarget, from) {
7086
7276
  const record = records.get(hoverTarget.key);
7087
- if (!record || hovered?.key === hoverTarget.key) return;
7277
+ if (!record || own(hovered) && hovered.keys[0] === hoverTarget.key) return;
7088
7278
  endHover();
7089
- startHover(record, from, hoverTarget.segment);
7279
+ startHover([record], from, hoverTarget.segment);
7090
7280
  },
7091
7281
  leave() {
7092
- if (hovered?.source !== "keyboard") endHover();
7282
+ if (hovered?.source === "pointer" || hovered?.source === "touch") endHover();
7093
7283
  }
7094
7284
  });
7095
7285
  }
@@ -7106,26 +7296,45 @@ function expressive(target, options, env2) {
7106
7296
  }
7107
7297
  return void 0;
7108
7298
  }
7109
- function startHover(record, from, segment) {
7110
- hovered = { key: record.key, source: from };
7299
+ function startHover(marks, from, segment, effects2 = true) {
7300
+ const started = { keys: marks.map((record) => record.key), source: from, effects: effects2 };
7301
+ hovered = started;
7111
7302
  applyDim();
7112
- runner.hover([input(record)]);
7113
- emit("hover", { ...input(record), batch: ONE, source: from, ...segment === void 0 ? {} : { segment } });
7303
+ if (effects2) runner.hover(marks.map(input));
7304
+ marks.forEach((record, index) => emit("hover", { ...input(record), batch: { index, count: marks.length }, source: from, ...segment === void 0 ? {} : { segment } }));
7305
+ if (from !== "linked" && hovered === started) linked2?.hover(marks.map(input));
7114
7306
  }
7115
7307
  function endHover() {
7116
7308
  const current = hovered;
7117
7309
  if (!current) return;
7118
7310
  hovered = void 0;
7119
- const record = find(current.key);
7120
7311
  applyDim();
7121
- runner.leave([current.key]);
7122
- if (record) emit("leave", { ...input(record), batch: ONE });
7312
+ leaveMarks(current.keys);
7313
+ if (own(current)) linked2?.leave();
7314
+ }
7315
+ function leaveMarks(keys) {
7316
+ const marks = keys.flatMap((key) => find(key) ?? []);
7317
+ runner.leave(keys);
7318
+ marks.forEach((record, index) => emit("leave", { ...input(record), batch: { index, count: marks.length } }));
7319
+ }
7320
+ function dropGone() {
7321
+ if (hovered === void 0) return;
7322
+ const keys = hovered.keys.filter((key) => records.has(key));
7323
+ if (keys.length === hovered.keys.length) return;
7324
+ if (keys.length === 0) {
7325
+ interaction?.clear();
7326
+ endHover();
7327
+ return;
7328
+ }
7329
+ const gone = hovered.keys.filter((key) => !records.has(key));
7330
+ hovered = { ...hovered, keys };
7331
+ leaveMarks(gone);
7123
7332
  }
7124
7333
  function applyDim() {
7125
7334
  if (!dim) return;
7126
7335
  const duration = `${motion2.duration(100, "feedback")}ms`;
7127
7336
  for (const record of order) {
7128
- const hot = hovered?.key === record.key;
7337
+ const hot = hovered?.keys.includes(record.key) === true;
7129
7338
  for (const part2 of record.mark.parts) {
7130
7339
  edits.toggleClass(part2.element, "ec-attached", true);
7131
7340
  edits.toggleClass(part2.element, "ec-dimmed", hovered !== void 0 && !hot);
@@ -7164,26 +7373,27 @@ function expressive(target, options, env2) {
7164
7373
  const record = records.get(key);
7165
7374
  if (!record) return;
7166
7375
  if (!visible) {
7167
- if (hovered?.source === "keyboard" && hovered.key !== key) endHover();
7376
+ if (hovered?.source === "keyboard" && hovered.keys[0] !== key) endHover();
7168
7377
  return;
7169
7378
  }
7170
- if (hovered?.key === key) {
7171
- hovered = { key, source: "keyboard" };
7379
+ if (own(hovered) && hovered.keys[0] === key) {
7380
+ hovered = { ...hovered, source: "keyboard" };
7172
7381
  return;
7173
7382
  }
7174
7383
  endHover();
7175
- startHover(record, "keyboard");
7384
+ startHover([record], "keyboard");
7176
7385
  },
7177
7386
  blur() {
7178
7387
  ringKey = void 0;
7179
7388
  drawRing();
7180
7389
  if (hovered?.source !== "keyboard") return;
7181
- if (interaction?.current === hovered.key) hovered = { key: hovered.key, source: "pointer" };
7390
+ if (interaction?.current === hovered.keys[0]) hovered = { ...hovered, source: "pointer" };
7182
7391
  else endHover();
7183
7392
  },
7184
7393
  escape() {
7185
7394
  if (!hovered) return false;
7186
- endHover();
7395
+ if (hovered.source === "linked" && linked2) linked2.dismiss();
7396
+ else endHover();
7187
7397
  return true;
7188
7398
  }
7189
7399
  }) : void 0;
@@ -7282,7 +7492,27 @@ function expressive(target, options, env2) {
7282
7492
  runner.enter(apply2(first).entering.map(input));
7283
7493
  keyboard?.sync();
7284
7494
  watchMarks();
7285
- return {
7495
+ const link2 = {
7496
+ targets: () => order.map((record) => ({ key: record.key, marks: [input(record)] })),
7497
+ hover(keys, effects2) {
7498
+ endHover();
7499
+ const marks = keys.flatMap((key) => records.get(key) ?? []);
7500
+ if (marks.length > 0) startHover(marks, "linked", void 0, effects2);
7501
+ },
7502
+ unlink() {
7503
+ if (hovered?.source === "linked") endHover();
7504
+ },
7505
+ leave() {
7506
+ interaction?.clear();
7507
+ endHover();
7508
+ },
7509
+ listen(listener) {
7510
+ if (destroyed) return false;
7511
+ linked2 = listener;
7512
+ return true;
7513
+ }
7514
+ };
7515
+ return linkable(link2, {
7286
7516
  refresh(next) {
7287
7517
  if (destroyed) return;
7288
7518
  const reading = read(next ?? source);
@@ -7290,10 +7520,7 @@ function expressive(target, options, env2) {
7290
7520
  runner.interrupt();
7291
7521
  const diff = apply2(reading);
7292
7522
  watchMarks();
7293
- if (hovered !== void 0 && !records.has(hovered.key)) {
7294
- interaction?.clear();
7295
- endHover();
7296
- }
7523
+ dropGone();
7297
7524
  const exited = runner.exit(diff.exiting.map(input));
7298
7525
  emitEach("exit", diff.exiting);
7299
7526
  runner.update(diff.changed.map(({ record, from }) => ({ ...input(record), from })));
@@ -7328,6 +7555,8 @@ function expressive(target, options, env2) {
7328
7555
  if (destroyed) return;
7329
7556
  destroyed = true;
7330
7557
  hovered = void 0;
7558
+ linked2?.gone();
7559
+ linked2 = void 0;
7331
7560
  watching?.destroy();
7332
7561
  runner.destroy();
7333
7562
  unsubscribeMotion?.();
@@ -7341,7 +7570,7 @@ function expressive(target, options, env2) {
7341
7570
  order = [];
7342
7571
  owners = /* @__PURE__ */ new Map();
7343
7572
  }
7344
- };
7573
+ });
7345
7574
  }
7346
7575
  function checkOptions4(options) {
7347
7576
  if (typeof options !== "object" || options === null) throw new TypeError("expressive needs options, with at least a key: { key: (d) => d.name }.");
@@ -7452,7 +7681,7 @@ function samplesChanged(from, to) {
7452
7681
  return from.length !== to.length || from.some((a, i) => a.t !== to[i].t || a.value !== to[i].value || !sameAt2(a.at, to[i].at));
7453
7682
  }
7454
7683
  function geometryChanged2(from, to) {
7455
- if (from.outline.d !== to.outline.d || from.thickness !== to.thickness) return true;
7684
+ if (from.outline.d !== to.outline.d || from.thickness !== to.thickness || labelsMoved(from, to)) return true;
7456
7685
  const a = from.segments ?? [];
7457
7686
  const b = to.segments ?? [];
7458
7687
  return a.length !== b.length || a.some((segment, i) => segment.key !== b[i].key || segment.outline.d !== b[i].outline.d);
@@ -7629,7 +7858,7 @@ function fromVegaView(view, options, env2) {
7629
7858
  }
7630
7859
  observe(next.root);
7631
7860
  }
7632
- return {
7861
+ return linkable(portOf(attachment), {
7633
7862
  refresh,
7634
7863
  on: attachment.on,
7635
7864
  marks: attachment.marks,
@@ -7642,7 +7871,7 @@ function fromVegaView(view, options, env2) {
7642
7871
  stopFrame = void 0;
7643
7872
  attachment.destroy();
7644
7873
  }
7645
- };
7874
+ });
7646
7875
  }
7647
7876
  function checkView(view) {
7648
7877
  if (typeof view !== "object" || view === null || typeof view.renderer !== "function" || typeof view.scenegraph !== "function" || typeof view.container !== "function") {
@@ -8206,20 +8435,20 @@ function chartSwitch(target, options, env2) {
8206
8435
  const drawings = [];
8207
8436
  for (const mark of from) if (!toKeys.has(mark.key)) drawings.push(fadeMark(mark, fadeOut));
8208
8437
  for (const mark of to) if (!fromByKey.has(mark.key)) drawings.push(fadeMark(mark, fadeIn));
8209
- const id = (label) => `${label.role}
8210
- ${label.key}`;
8438
+ const id = (label2) => `${label2.role}
8439
+ ${label2.key}`;
8211
8440
  const labelsA = a.chart.labels();
8212
8441
  const labelsB = b.chart.labels();
8213
- const byId = new Map(labelsA.map((label) => [id(label), label]));
8442
+ const byId = new Map(labelsA.map((label2) => [id(label2), label2]));
8214
8443
  const matched = /* @__PURE__ */ new Set();
8215
- for (const label of labelsB) {
8216
- const partner = byId.get(id(label));
8444
+ for (const label2 of labelsB) {
8445
+ const partner = byId.get(id(label2));
8217
8446
  if (!partner) continue;
8218
- matched.add(id(label));
8219
- drawings.push(moveLabel(copyLabel(partner, toA), copyLabel(label, toB)));
8447
+ matched.add(id(label2));
8448
+ drawings.push(moveLabel(copyLabel(partner, toA), copyLabel(label2, toB)));
8220
8449
  }
8221
- for (const label of labelsA) if (!matched.has(id(label))) drawings.push(fadeLabel(copyLabel(label, toA), fadeOut));
8222
- for (const label of labelsB) if (!byId.has(id(label))) drawings.push(fadeLabel(copyLabel(label, toB), fadeIn));
8450
+ for (const label2 of labelsA) if (!matched.has(id(label2))) drawings.push(fadeLabel(copyLabel(label2, toA), fadeOut));
8451
+ for (const label2 of labelsB) if (!byId.has(id(label2))) drawings.push(fadeLabel(copyLabel(label2, toB), fadeIn));
8223
8452
  drawings.push((s) => {
8224
8453
  setOpacity(a.container, 1 - clamp(s / OUT_BY));
8225
8454
  setOpacity(b.container, clamp((s - HALF) / (1 - HALF)));
@@ -8244,12 +8473,12 @@ ${label.key}`;
8244
8473
  svgLayer(group).path(mark.outline.d, mark.outline.closed ? { fill: "mark" } : { stroke: "mark", width: mark.thickness });
8245
8474
  return (s) => setAttributes(group, { opacity: opacity(s) });
8246
8475
  }
8247
- function copyLabel(label, m) {
8248
- const text2 = label.element.cloneNode(true);
8476
+ function copyLabel(label2, m) {
8477
+ const text2 = label2.element.cloneNode(true);
8249
8478
  for (const name of ["id", "opacity", "visibility", "aria-hidden"]) text2.removeAttribute(name);
8250
- text2.textContent = label.text;
8251
- const at = matrix.apply(m, label);
8252
- setAttributes(text2, { x: at.x, y: at.y, "text-anchor": label.anchor });
8479
+ text2.textContent = label2.text;
8480
+ const at = matrix.apply(m, label2);
8481
+ setAttributes(text2, { x: at.x, y: at.y, "text-anchor": label2.anchor });
8253
8482
  labelsLayer.appendChild(text2);
8254
8483
  return { text: text2, at };
8255
8484
  }
@@ -8340,8 +8569,8 @@ function moveLabel(a, b) {
8340
8569
  setAttributes(b.text, { x, y, visibility: second ? void 0 : "hidden" });
8341
8570
  };
8342
8571
  }
8343
- function fadeLabel(label, opacity) {
8344
- return (s) => setAttributes(label.text, { opacity: opacity(s) });
8572
+ function fadeLabel(label2, opacity) {
8573
+ return (s) => setAttributes(label2.text, { opacity: opacity(s) });
8345
8574
  }
8346
8575
  var fadeOut = (s) => 1 - clamp(s / HALF);
8347
8576
  var fadeIn = (s) => clamp((s - HALF) / (1 - HALF));
@@ -8435,10 +8664,10 @@ function motionSwitch(target, motion2, options = {}) {
8435
8664
  root.setAttribute("role", "group");
8436
8665
  root.setAttribute("aria-labelledby", `${id}-label`);
8437
8666
  root.setAttribute("aria-describedby", `${id}-hint`);
8438
- const label = root.appendChild(doc.createElement("span"));
8439
- label.className = "ec-motion-label";
8440
- label.id = `${id}-label`;
8441
- label.textContent = options.label ?? "Motion";
8667
+ const label2 = root.appendChild(doc.createElement("span"));
8668
+ label2.className = "ec-motion-label";
8669
+ label2.id = `${id}-label`;
8670
+ label2.textContent = options.label ?? "Motion";
8442
8671
  const modes = root.appendChild(doc.createElement("span"));
8443
8672
  modes.className = "ec-motion-modes";
8444
8673
  const buttons = MODES3.map((mode) => {
@@ -8506,8 +8735,8 @@ function checkMotion(motion2) {
8506
8735
  }
8507
8736
  }
8508
8737
  function checkOptions6(options) {
8509
- const { label, labels, hints, persist } = options;
8510
- if (label !== void 0 && typeof label !== "string") throw new TypeError(`motionSwitch: label must be a string, got ${typeof label}.`);
8738
+ const { label: label2, labels, hints, persist } = options;
8739
+ if (label2 !== void 0 && typeof label2 !== "string") throw new TypeError(`motionSwitch: label must be a string, got ${typeof label2}.`);
8511
8740
  for (const [name, texts] of [["labels", labels], ["hints", hints]]) {
8512
8741
  if (texts === void 0) continue;
8513
8742
  for (const [key, text2] of Object.entries(texts)) {
@@ -8604,6 +8833,7 @@ var gaits = { roll, step, slide };
8604
8833
  // src/effects/travel.ts
8605
8834
  var SPEED = 360;
8606
8835
  var SHORTEST = 260;
8836
+ var LONGEST2 = 4e3;
8607
8837
  var MIN_WALK = 0.5;
8608
8838
  var FIT = 0.85;
8609
8839
  var MIN_SMOOTHING = 2;
@@ -8693,7 +8923,7 @@ function trip(walk, icon, scale2, options) {
8693
8923
  icon,
8694
8924
  size: icon.size * scale2,
8695
8925
  span,
8696
- duration: Math.max(SHORTEST, span / SPEED * 1e3) * (gait.pace ?? 1),
8926
+ duration: Math.min(LONGEST2, Math.max(SHORTEST, span / SPEED * 1e3) * (gait.pace ?? 1)),
8697
8927
  gait,
8698
8928
  transform(progress) {
8699
8929
  const distance3 = behind + progress * span;
@@ -8915,12 +9145,238 @@ function checkOptions11(options) {
8915
9145
  }
8916
9146
  }
8917
9147
 
8918
- // src/effects/threshold.ts
9148
+ // src/effects/trace.ts
9149
+ var DURATION5 = 500;
9150
+ var WIDTH3 = 3;
9151
+ var OPACITY3 = 0.5;
8919
9152
  var MIN_WALK2 = 0.5;
9153
+ function trace(options = {}) {
9154
+ checkOptions12(options);
9155
+ const duration = options.duration ?? DURATION5;
9156
+ const paint = { stroke: options.color ?? "mark", width: options.width ?? WIDTH3, opacity: options.opacity ?? OPACITY3, linecap: "round" };
9157
+ const stroke2 = (mark, ctx) => {
9158
+ let current = mark;
9159
+ let progress = 0;
9160
+ let path;
9161
+ const draw = () => {
9162
+ if (!(current.length >= MIN_WALK2)) {
9163
+ path?.remove();
9164
+ path = void 0;
9165
+ return;
9166
+ }
9167
+ const d = current.slice(0, progress);
9168
+ if (path) path.update(d);
9169
+ else path = ctx.layer.path(d, paint);
9170
+ };
9171
+ ctx.onChange((next) => {
9172
+ current = next;
9173
+ draw();
9174
+ });
9175
+ draw();
9176
+ return (p) => {
9177
+ progress = p;
9178
+ draw();
9179
+ };
9180
+ };
9181
+ return {
9182
+ kind: "geometry",
9183
+ async run(mark, ctx) {
9184
+ if (ctx.signal.aborted) return;
9185
+ const show3 = stroke2(mark, ctx);
9186
+ if (!(mark.length >= MIN_WALK2)) {
9187
+ show3(1);
9188
+ return;
9189
+ }
9190
+ await ctx.tween({ duration, timing: "effect", ease: easeInOutCubic, update: show3 }).finished;
9191
+ },
9192
+ end(mark, ctx) {
9193
+ stroke2(mark, ctx)(1);
9194
+ },
9195
+ clear() {
9196
+ }
9197
+ };
9198
+ }
9199
+ function checkOptions12(options) {
9200
+ const { color, width, opacity, duration } = options;
9201
+ if (color !== void 0 && (typeof color !== "string" || color === "")) {
9202
+ throw new RangeError(`trace: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
9203
+ }
9204
+ if (width !== void 0 && !(typeof width === "number" && width >= 0 && Number.isFinite(width))) {
9205
+ throw new RangeError(`trace: width must be 0 px or more, got ${String(width)}.`);
9206
+ }
9207
+ if (opacity !== void 0 && !(typeof opacity === "number" && opacity >= 0 && opacity <= 1)) {
9208
+ throw new RangeError(`trace: opacity must be from 0 to 1, got ${String(opacity)}.`);
9209
+ }
9210
+ if (duration !== void 0 && !(typeof duration === "number" && duration >= 0 && Number.isFinite(duration))) {
9211
+ throw new RangeError(`trace: duration must be 0 ms or more, got ${String(duration)}.`);
9212
+ }
9213
+ }
9214
+
9215
+ // src/effects/caption.ts
9216
+ var PAST_END = 10;
9217
+ var PAST_LABEL = 6;
9218
+ var RISE = 8;
9219
+ var TEXT = 12.5;
9220
+ var CENTRE4 = 0.36;
9221
+ var HANG = 0.8;
9222
+ function captionPlace(mark) {
9223
+ const boxes = mark.labelBounds ?? [];
9224
+ const heading2 = mark.angle(1);
9225
+ const along = farthest(mark.end, heading2, boxes);
9226
+ if (along === void 0 && boxes.length > 0) {
9227
+ const up = mark.angle(0.5) - Math.PI / 2;
9228
+ const out = farthest(mark.center, up, boxes);
9229
+ if (out !== void 0) return placed(mark.center, up, out);
9230
+ }
9231
+ return placed(mark.end, heading2, Math.max(PAST_END, along ?? -Infinity));
9232
+ }
9233
+ function placed(from, toward, distance3) {
9234
+ const cos = Math.cos(toward);
9235
+ const sin = Math.sin(toward);
9236
+ const point = offset(from, toward, distance3);
9237
+ const drop = TEXT * (sin < 0 ? CENTRE4 * (1 + sin) : CENTRE4 + (HANG - CENTRE4) * sin);
9238
+ const anchor = Math.abs(cos) <= Math.SQRT1_2 + 1e-9 ? "middle" : cos > 0 ? "start" : "end";
9239
+ return { at: { x: point.x, y: point.y + drop }, anchor, toward };
9240
+ }
9241
+ function farthest(from, toward, boxes) {
9242
+ const cos = Math.cos(toward);
9243
+ const sin = Math.sin(toward);
9244
+ let exit;
9245
+ for (const { x, y, width, height } of boxes) {
9246
+ const grown = { x: x - PAST_LABEL, y: y - PAST_LABEL, width: width + 2 * PAST_LABEL, height: height + 2 * PAST_LABEL };
9247
+ const leaving = leaves(from, cos, sin, grown);
9248
+ if (leaving !== void 0) exit = Math.max(exit ?? leaving, leaving);
9249
+ }
9250
+ return exit;
9251
+ }
9252
+ function leaves(from, cos, sin, box) {
9253
+ let near = 0;
9254
+ let far = Infinity;
9255
+ for (const [origin, step2, lo, hi] of [
9256
+ [from.x, cos, box.x, box.x + box.width],
9257
+ [from.y, sin, box.y, box.y + box.height]
9258
+ ]) {
9259
+ if (Math.abs(step2) < 1e-12) {
9260
+ if (origin < lo || origin > hi) return void 0;
9261
+ continue;
9262
+ }
9263
+ const a = (lo - origin) / step2;
9264
+ const b = (hi - origin) / step2;
9265
+ near = Math.max(near, Math.min(a, b));
9266
+ far = Math.min(far, Math.max(a, b));
9267
+ }
9268
+ return far >= near ? far : void 0;
9269
+ }
9270
+ function caption(mark, data, ctx, color, words) {
9271
+ let current = mark;
9272
+ let content = words(mark, data) ?? "";
9273
+ let latest = data;
9274
+ let progress = 0;
9275
+ let handle;
9276
+ const draw = () => {
9277
+ if (content === "") {
9278
+ handle?.remove();
9279
+ handle = void 0;
9280
+ return;
9281
+ }
9282
+ const { at, anchor, toward } = captionPlace(current);
9283
+ const style = { at: offset(at, toward - Math.PI / 2, -RISE * (1 - progress)), anchor, color, opacity: progress };
9284
+ if (handle) handle.update(style, content);
9285
+ else handle = ctx.layer.text(content, style);
9286
+ };
9287
+ ctx.onChange((next, nextData) => {
9288
+ current = next;
9289
+ latest = nextData ?? latest;
9290
+ content = words(current, latest) ?? "";
9291
+ draw();
9292
+ });
9293
+ draw();
9294
+ return (p) => {
9295
+ progress = p;
9296
+ draw();
9297
+ };
9298
+ }
9299
+
9300
+ // src/effects/delta.ts
9301
+ var DURATION6 = 400;
8920
9302
  var TIE = 1e-9;
9303
+ var lastSample = (data) => {
9304
+ const { samples } = data;
9305
+ return samples[samples.length - 1]?.value ?? Number.NaN;
9306
+ };
9307
+ var wording;
9308
+ var signed = (change) => {
9309
+ wording ?? (wording = new Intl.NumberFormat(void 0, { signDisplay: "always", maximumFractionDigits: 2 }));
9310
+ return wording.format(change);
9311
+ };
9312
+ function delta(options = {}) {
9313
+ checkOptions13(options);
9314
+ const value = options.value ?? lastSample;
9315
+ const format2 = options.format ?? signed;
9316
+ const color = options.color ?? "text";
9317
+ const words = (data) => {
9318
+ if (!data.previous) return void 0;
9319
+ const now = value(data);
9320
+ const before = value(data.previous);
9321
+ const change = now - before;
9322
+ if (!Number.isFinite(change) || Math.abs(change) <= TIE * Math.max(Math.abs(now), Math.abs(before))) return void 0;
9323
+ return format2(change);
9324
+ };
9325
+ return {
9326
+ kind: "data",
9327
+ run: async (mark, data, ctx) => {
9328
+ if (ctx.signal.aborted) return;
9329
+ const text2 = words(data);
9330
+ if (text2 === void 0 || text2 === "") return;
9331
+ const show3 = caption(mark, data, ctx, color, () => text2);
9332
+ await ctx.tween({ duration: DURATION6, timing: "effect", update: show3 }).finished;
9333
+ },
9334
+ end: (mark, data, ctx) => {
9335
+ const text2 = words(data);
9336
+ if (text2 !== void 0 && text2 !== "") caption(mark, data, ctx, color, () => text2)(1);
9337
+ },
9338
+ clear() {
9339
+ }
9340
+ };
9341
+ }
9342
+ function checkOptions13(options) {
9343
+ const { value, format: format2, color } = options;
9344
+ if (value !== void 0 && typeof value !== "function") throw new TypeError(`delta: value must be a function that reads the mark's value from its data, got ${typeof value}.`);
9345
+ if (format2 !== void 0 && typeof format2 !== "function") throw new TypeError(`delta: format must be a function that words the change, got ${typeof format2}.`);
9346
+ if (color !== void 0 && (typeof color !== "string" || color === "")) {
9347
+ throw new RangeError(`delta: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
9348
+ }
9349
+ }
9350
+
9351
+ // src/effects/label.ts
9352
+ var DURATION7 = 400;
9353
+ function label(text2, options = {}) {
9354
+ if (typeof text2 !== "function") throw new TypeError(`label needs a function that returns the text from the mark's data, got ${typeof text2}.`);
9355
+ const { color = "text" } = options;
9356
+ 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)}.`);
9357
+ const words = (mark, data) => {
9358
+ const said = text2(data, mark);
9359
+ return said === void 0 || said === null ? void 0 : String(said);
9360
+ };
9361
+ return {
9362
+ kind: "data",
9363
+ run: async (mark, data, ctx) => {
9364
+ if (ctx.signal.aborted) return;
9365
+ const show3 = caption(mark, data, ctx, color, words);
9366
+ await ctx.tween({ duration: DURATION7, timing: "effect", update: show3 }).finished;
9367
+ },
9368
+ end: (mark, data, ctx) => caption(mark, data, ctx, color, words)(1),
9369
+ clear() {
9370
+ }
9371
+ };
9372
+ }
9373
+
9374
+ // src/effects/threshold.ts
9375
+ var MIN_WALK3 = 0.5;
9376
+ var TIE2 = 1e-9;
8921
9377
  var WHENS = ["below", "above"];
8922
9378
  function threshold(options) {
8923
- checkOptions12(options);
9379
+ checkOptions14(options);
8924
9380
  const { compareTo } = options;
8925
9381
  const when = options.when ?? "below";
8926
9382
  const color = options.color ?? "negative";
@@ -8928,7 +9384,7 @@ function threshold(options) {
8928
9384
  const paths = [];
8929
9385
  let latest = data;
8930
9386
  const draw = (current) => {
8931
- const parts = current.length >= MIN_WALK2 ? runs(latest.samples, reference(compareTo, latest), when) : [];
9387
+ const parts = current.length >= MIN_WALK3 ? runs(latest.samples, reference(compareTo, latest), when) : [];
8932
9388
  const paint = { stroke: color, width: current.thickness, linecap: "butt" };
8933
9389
  parts.forEach(([t0, t1], i) => {
8934
9390
  const d = current.slice(t0, t1);
@@ -8991,7 +9447,7 @@ function runs(samples, ref, when) {
8991
9447
  const level = ref.valueAt(u);
8992
9448
  if (level === void 0 || !Number.isFinite(level) || !Number.isFinite(value) || !Number.isFinite(t)) return { t, past: void 0 };
8993
9449
  const past = sign * (level - value);
8994
- return { t, past: Math.abs(past) <= TIE * Math.max(Math.abs(level), Math.abs(value)) ? 0 : past };
9450
+ return { t, past: Math.abs(past) <= TIE2 * Math.max(Math.abs(level), Math.abs(value)) ? 0 : past };
8995
9451
  };
8996
9452
  const stations = [];
8997
9453
  samples.forEach((sample, i) => {
@@ -9039,7 +9495,7 @@ function firstAbove(values, x) {
9039
9495
  }
9040
9496
  return lo;
9041
9497
  }
9042
- function checkOptions12(options) {
9498
+ function checkOptions14(options) {
9043
9499
  const { compareTo, when, color } = options ?? {};
9044
9500
  if (!(typeof compareTo === "string" ? compareTo !== "" : typeof compareTo === "number" && Number.isFinite(compareTo))) {
9045
9501
  throw new RangeError(`threshold: compareTo must be a finite number or a series name, got ${show2(compareTo)}.`);
@@ -9052,11 +9508,11 @@ function checkOptions12(options) {
9052
9508
  var show2 = (value) => typeof value === "string" ? JSON.stringify(value) : String(value);
9053
9509
 
9054
9510
  // src/effects/morph.ts
9055
- var DURATION5 = 950;
9511
+ var DURATION8 = 950;
9056
9512
  var POINTS = 160;
9057
9513
  var ALIGNS = ["unroll", "drop"];
9058
9514
  function morph(options = {}) {
9059
- checkOptions13(options);
9515
+ checkOptions15(options);
9060
9516
  const points = options?.points ?? POINTS;
9061
9517
  const align = options?.align ?? "unroll";
9062
9518
  return {
@@ -9072,7 +9528,7 @@ function morph(options = {}) {
9072
9528
  const begun = unease(start);
9073
9529
  let running;
9074
9530
  running = ctx.tween({
9075
- duration: DURATION5,
9531
+ duration: DURATION8,
9076
9532
  timing: "transition",
9077
9533
  ease: linear,
9078
9534
  update: (k) => {
@@ -9160,7 +9616,7 @@ function turn(from, to, points) {
9160
9616
  function startOf(start) {
9161
9617
  return typeof start === "number" && start > 0 ? Math.min(1, start) : 0;
9162
9618
  }
9163
- function checkOptions13(options) {
9619
+ function checkOptions15(options) {
9164
9620
  const { points, align } = options ?? {};
9165
9621
  if (points !== void 0 && !(Number.isInteger(points) && points >= 4 && points % 4 === 0)) {
9166
9622
  throw new RangeError(`morph: points must be a whole multiple of 4, got ${String(points)}.`);
@@ -9416,9 +9872,9 @@ var ATTRIBUTE = /([^\s=/<>]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'<>]+)))?/g;
9416
9872
  var COLOR = /^(?:#[0-9a-fA-F]{3,8}|[a-zA-Z][a-zA-Z0-9-]*|(?:rgba?|hsla?)\([\d\s.,%+\-/]*\))$/;
9417
9873
  function iconFromSvg(markup, spec) {
9418
9874
  if (typeof markup !== "string") throw new TypeError("iconFromSvg needs SVG markup as a string.");
9419
- const label = typeof spec?.name === "string" ? `"${spec.name}"` : "an icon";
9875
+ const label2 = typeof spec?.name === "string" ? `"${spec.name}"` : "an icon";
9420
9876
  const fail = (problem) => {
9421
- throw new RangeError(`iconFromSvg: ${label} ${problem}.`);
9877
+ throw new RangeError(`iconFromSvg: ${label2} ${problem}.`);
9422
9878
  };
9423
9879
  let box;
9424
9880
  let scale2 = 1;
@@ -9691,7 +10147,7 @@ function configure(options) {
9691
10147
  }
9692
10148
 
9693
10149
  // src/index.ts
9694
- var VERSION = "0.1.0";
10150
+ var VERSION = "0.2.0";
9695
10151
  var env = { presets: presetRegistry, icons: iconRegistry, motion };
9696
10152
  function barChart2(target, options) {
9697
10153
  return barChart(target, options, env);
@@ -9730,6 +10186,7 @@ function motionSwitch2(target, motion2 = motion, options) {
9730
10186
  defineDataEffect,
9731
10187
  defineEffect,
9732
10188
  defineIcon,
10189
+ delta,
9733
10190
  describe,
9734
10191
  donutChart,
9735
10192
  easeInOutCubic,
@@ -9743,8 +10200,10 @@ function motionSwitch2(target, motion2 = motion, options) {
9743
10200
  interpolateNumber,
9744
10201
  interpolatePoint,
9745
10202
  interpolateRecord,
10203
+ label,
9746
10204
  lineChart,
9747
10205
  linear,
10206
+ link,
9748
10207
  manualClock,
9749
10208
  matrix,
9750
10209
  mediaReducedMotion,
@@ -9765,6 +10224,7 @@ function motionSwitch2(target, motion2 = motion, options) {
9765
10224
  sequence,
9766
10225
  stagger,
9767
10226
  threshold,
10227
+ trace,
9768
10228
  travel,
9769
10229
  tween,
9770
10230
  wiggle