expressive-charts 0.4.0 → 0.5.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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as linear, C as createMotion, D as scaleDuration, E as motion, F as report, M as createClock, N as defaultClock, O as easeInOutCubic, P as manualClock, S as TIMINGS, T as mediaReducedMotion, _ as describePoint, a as mergeFields, b as describeArc, c as describeValue$1, d as describe, f as describeShape, g as transformPath, h as shapeOutline, j as unease, k as easeOutCubic, l as isMarkEffect, m as parsePath, n as playTransition, o as EFFECT_SLOTS, p as formatPath, r as createRunner, s as createRegistry, t as isTransitionEffect, u as resolveEffects, v as describeLine, w as defaultScaling, x as tween, y as describeBar } from "./transition-DSRt2DH3.js";
1
+ import { A as easeInOutCubic, C as tween, D as mediaReducedMotion, E as defaultScaling, F as defaultClock, I as manualClock, L as report, M as linear, N as unease, O as motion, P as createClock, S as describeArc, T as createMotion, _ as FLAT, a as mergeFields, b as describeLine, c as describeValue$1, d as describe, f as describeShape, g as transformPath, h as shapeOutline, j as easeOutCubic, k as scaleDuration, l as isMarkEffect, m as parsePath, n as playTransition, o as EFFECT_SLOTS, p as formatPath, r as createRunner, s as createRegistry, t as isTransitionEffect, u as resolveEffects, v as cubicPieces, w as TIMINGS, x as describeBar, y as describePoint } from "./transition-Bu1NsQor.js";
2
2
  import { d as normalizeAngle, n as formatNumber } from "./path-data-DnEckjY8.js";
3
3
  import { t as defineIcon } from "./define-DeZLs1h7.js";
4
4
  // src/core/animated.ts
@@ -397,7 +397,7 @@ function offset(point, angle, distance) {
397
397
  // src/core/geometry/samples.ts
398
398
  const MAX_GRID = 4096;
399
399
  const REFINE = 48;
400
- const GOLDEN = (Math.sqrt(5) - 1) / 2;
400
+ const GOLDEN = /* @__PURE__ */ (() => (Math.sqrt(5) - 1) / 2)();
401
401
  function samplesAlong(mark, points) {
402
402
  if (typeof mark !== "object" || mark === null || typeof mark.path !== "function" || !Number.isFinite(mark.length)) throw new TypeError("samplesAlong needs a MarkGeometry, as describe builds it.");
403
403
  if (!Array.isArray(points)) throw new TypeError("samplesAlong needs an array of points { x, y, value, at? }.");
@@ -966,7 +966,8 @@ function verticalFrame(input, rows, domain, _values, ticks) {
966
966
  const tickWidth = widest$1(ticks, "ec-tick", TICK_SIZE$1, measure);
967
967
  const { positive, negative } = reach(input, rows);
968
968
  const top = (domain.hi > 0 ? 20.5 : TOP$1) + positive;
969
- const bottom = AXIS$1 + (domain.lo < 0 ? 18.5 : 0) + negative;
969
+ const values = domain.lo < 0 ? 18.5 : 0;
970
+ const bottom = AXIS$1 + values + negative;
970
971
  const left = tickWidth + 8 + 2;
971
972
  const plot = {
972
973
  x: left,
@@ -983,7 +984,7 @@ function verticalFrame(input, rows, domain, _values, ticks) {
983
984
  hi: domain.hi,
984
985
  from: base,
985
986
  extent: -plot.height,
986
- label: base + 18
987
+ label: base + values + 18
987
988
  },
988
989
  bands: {
989
990
  start: plot.x,
@@ -1111,7 +1112,7 @@ const COLOR_TOKENS = [
1111
1112
  "focus",
1112
1113
  "negative"
1113
1114
  ];
1114
- const TOKENS = Object.fromEntries(COLOR_TOKENS.map((name) => [name, themes.light[name]]));
1115
+ const TOKENS = /* @__PURE__ */ Object.fromEntries(/* @__PURE__ */ COLOR_TOKENS.map((name) => [name, themes.light[name]]));
1115
1116
  function seriesColors(slot) {
1116
1117
  const n = (Math.max(1, Math.floor(slot)) - 1) % 8 + 1;
1117
1118
  const [color, strong] = themes.light.series[n - 1];
@@ -1147,8 +1148,7 @@ function declarations(theme, indent) {
1147
1148
  theme.series.forEach(([color, strong], i) => lines.push(`--ec-series-${i + 1}: ${color};`, `--ec-series-${i + 1}-strong: ${strong};`));
1148
1149
  return lines.map((line) => indent + line).join("\n");
1149
1150
  }
1150
- const STYLES = `/* expressive-charts: theme tokens and default styles. Every rule has zero specificity, so your CSS wins. */
1151
- ${`:where(:root, [data-theme="light"]) {
1151
+ const TOKEN_RULES = /* @__PURE__ */ (() => `:where(:root, [data-theme="light"]) {
1152
1152
  ${declarations(themes.light, " ")}
1153
1153
  }
1154
1154
  @media (prefers-color-scheme: dark) {
@@ -1158,7 +1158,9 @@ ${declarations(themes.dark, " ")}
1158
1158
  }
1159
1159
  :where([data-theme="dark"]) {
1160
1160
  ${declarations(themes.dark, " ")}
1161
- }`}
1161
+ }`)();
1162
+ const STYLES = /* @__PURE__ */ (() => `/* expressive-charts: theme tokens and default styles. Every rule has zero specificity, so your CSS wins. */
1163
+ ${TOKEN_RULES}
1162
1164
  :where(.ec-chart) { display: block; max-width: 100%; height: auto; overflow: visible; touch-action: pan-y; -webkit-tap-highlight-color: transparent; }
1163
1165
  :where(.ec-chart text) { font-variant-numeric: tabular-nums; }
1164
1166
  :where(.ec-chart .ec-gridline) { stroke: var(--ec-grid, ${TOKENS.grid}); stroke-width: 1; }
@@ -1177,18 +1179,19 @@ ${declarations(themes.dark, " ")}
1177
1179
  :where(.ec-chart .ec-hot .ec-segment) { fill: var(--ec-mark-strong); }
1178
1180
  :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; }
1179
1181
  :where(.ec-chart .ec-hot .ec-stroke) { stroke: var(--ec-mark-strong); }
1180
- :where(.ec-chart .ec-end) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; }
1182
+ :where(.ec-chart .ec-end) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
1181
1183
  :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; }
1182
1184
  :where(.ec-chart .ec-hot .ec-dot) { fill: var(--ec-mark-strong); opacity: 1; }
1183
1185
  :where(.ec-chart .ec-alone .ec-dot) { opacity: 1; }
1184
1186
  :where(.ec-chart .ec-crosshair) { stroke: var(--ec-axis, ${TOKENS.axis}); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
1185
- :where(.ec-chart .ec-column:focus) { outline: none; }
1187
+ :where(.ec-chart .ec-column:focus, .ec-chart .ec-stop:focus) { outline: none; }
1186
1188
  :where(.ec-chart .ec-lines, .ec-chart .ec-points) { pointer-events: none; }
1187
1189
  :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; }
1188
1190
  :where(.ec-chart .ec-hot .ec-slice) { fill: var(--ec-mark-strong); }
1189
1191
  :where(.ec-chart .ec-center-value) { fill: var(--ec-text, ${TOKENS.text}); font-size: 26px; font-weight: 600; }
1190
1192
  :where(.ec-chart .ec-center-label) { fill: var(--ec-text-muted, ${TOKENS["text-muted"]}); font-size: 12.5px; }
1191
1193
  :where(.ec-chart.ec-hovering .ec-mark:not(.ec-hot) > .ec-body > *) { opacity: var(--ec-dim-opacity, 0.3); }
1194
+ :where(.ec-chart.ec-hovering .ec-line:not(.ec-hot-line) > .ec-body > *, .ec-chart.ec-hovering .ec-alone:not(.ec-hot) > .ec-body > *) { opacity: var(--ec-dim-opacity, 0.3); }
1192
1195
  :where(.ec-hovering .ec-run:not(.ec-hot) > .ec-follow) { opacity: var(--ec-dim-opacity, 0.3); }
1193
1196
  :where(.ec-follow) { transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
1194
1197
  :where(.ec-chart.ec-morphing .ec-marks) { visibility: hidden; }
@@ -1234,7 +1237,7 @@ ${declarations(themes.dark, " ")}
1234
1237
  :where(.ec-table thead th) { color: var(--ec-text-muted, ${TOKENS["text-muted"]}); font-size: 12px; font-weight: 600; }
1235
1238
  :where(.ec-table .ec-num) { text-align: right; }
1236
1239
  :where(.ec-table-caption, .ec-visually-hidden) { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
1237
- `;
1240
+ `)();
1238
1241
  const MARKER = "data-expressive-charts";
1239
1242
  const styleOptions = {};
1240
1243
  function injectStyles(doc) {
@@ -1926,7 +1929,9 @@ function pointerHover(svg, options) {
1926
1929
  let held;
1927
1930
  let watcher;
1928
1931
  let still;
1932
+ let under;
1929
1933
  const enter = (target, source) => {
1934
+ under = target?.key;
1930
1935
  if (target?.key === current) return;
1931
1936
  leave();
1932
1937
  if (!target) return;
@@ -1951,8 +1956,15 @@ function pointerHover(svg, options) {
1951
1956
  const arrive = (element, x, y) => {
1952
1957
  const tip = tooltipHolding(element);
1953
1958
  if (tip) hold(tip, x, y);
1954
- else enter(element && svg.contains(element) ? options.find(element) : void 0, "pointer");
1959
+ else enter(element && svg.contains(element) ? options.find(element, {
1960
+ x,
1961
+ y
1962
+ }) : void 0, "pointer");
1955
1963
  };
1964
+ const at = (event) => options.find(event.target, {
1965
+ x: event.clientX,
1966
+ y: event.clientY
1967
+ });
1956
1968
  const hold = (tip, x, y) => {
1957
1969
  enter({ key: tip.key }, "pointer");
1958
1970
  const element = tip.element;
@@ -2022,7 +2034,8 @@ function pointerHover(svg, options) {
2022
2034
  const over = (event) => {
2023
2035
  if (event.pointerType === "touch" || resting(event)) return;
2024
2036
  letGo();
2025
- enter(options.find(event.target), "pointer");
2037
+ const target = at(event);
2038
+ if (!options.moves?.() || target?.key !== under) enter(target, "pointer");
2026
2039
  };
2027
2040
  const out = (event) => {
2028
2041
  if (event.pointerType === "touch") return;
@@ -2030,13 +2043,17 @@ function pointerHover(svg, options) {
2030
2043
  arrive(landing(event), event.clientX, event.clientY);
2031
2044
  };
2032
2045
  const move = (event) => {
2033
- if (event.pointerType !== "touch") resting(event);
2046
+ if (event.pointerType === "touch" || resting(event) || !options.moves?.()) return;
2047
+ const target = at(event);
2048
+ if (target?.key === under) return;
2049
+ letGo();
2050
+ enter(target, "pointer");
2034
2051
  };
2035
2052
  const down = (event) => {
2036
2053
  lastPointer = event.pointerType;
2037
2054
  };
2038
2055
  const click = (event) => {
2039
- if (lastPointer === "touch") enter(options.find(event.target), "touch");
2056
+ if (lastPointer === "touch") enter(at(event), "touch");
2040
2057
  };
2041
2058
  const elsewhere = (event) => {
2042
2059
  if (current === void 0 || event.pointerType !== "touch") return;
@@ -2144,15 +2161,19 @@ function keyboardFocus(svg, options) {
2144
2161
  if (key === void 0 || event.altKey || event.ctrlKey || event.metaKey) return;
2145
2162
  const keys = options.order();
2146
2163
  const index = keys.indexOf(key);
2164
+ const moved = (press, fallback) => {
2165
+ const to = options.move?.(key, press);
2166
+ return to !== void 0 && keys.includes(to) ? to : fallback;
2167
+ };
2147
2168
  let next;
2148
2169
  switch (event.key) {
2149
2170
  case "ArrowDown":
2150
2171
  case "ArrowRight":
2151
- next = keys[Math.min(keys.length - 1, index + 1)];
2172
+ next = moved(event.key, keys[Math.min(keys.length - 1, index + 1)]);
2152
2173
  break;
2153
2174
  case "ArrowUp":
2154
2175
  case "ArrowLeft":
2155
- next = keys[Math.max(0, index - 1)];
2176
+ next = moved(event.key, keys[Math.max(0, index - 1)]);
2156
2177
  break;
2157
2178
  case "PageDown":
2158
2179
  case "PageUp": {
@@ -2162,10 +2183,10 @@ function keyboardFocus(svg, options) {
2162
2183
  break;
2163
2184
  }
2164
2185
  case "Home":
2165
- next = keys[0];
2186
+ next = moved(event.key, keys[0]);
2166
2187
  break;
2167
2188
  case "End":
2168
- next = keys[keys.length - 1];
2189
+ next = moved(event.key, keys[keys.length - 1]);
2169
2190
  break;
2170
2191
  case "Escape":
2171
2192
  if (options.escape(key)) event.preventDefault();
@@ -2229,6 +2250,28 @@ function keyboardFocus(svg, options) {
2229
2250
  for (const key of gone) setTabIndex(key, void 0);
2230
2251
  last = keys;
2231
2252
  },
2253
+ retarget(to) {
2254
+ listen();
2255
+ const keys = options.order();
2256
+ const live = new Set(keys);
2257
+ const active = on?.scope.activeElement ?? null;
2258
+ const had = focused?.element === active ? focused.key : last.find((key) => options.element(key) === active);
2259
+ const from = had ?? tabStop;
2260
+ const moved = from === void 0 ? void 0 : to(from);
2261
+ tabStop = moved !== void 0 && live.has(moved) ? moved : keys[0];
2262
+ applyTabIndex(keys);
2263
+ if (had !== void 0) {
2264
+ current = tabStop;
2265
+ if (tabStop !== void 0) options.element(tabStop)?.focus();
2266
+ else {
2267
+ active.blur();
2268
+ focused = void 0;
2269
+ }
2270
+ }
2271
+ for (const key of last) if (!live.has(key)) setTabIndex(key, void 0);
2272
+ last = keys;
2273
+ return had === void 0 ? void 0 : current;
2274
+ },
2232
2275
  destroy() {
2233
2276
  current = void 0;
2234
2277
  focused = void 0;
@@ -2337,6 +2380,7 @@ function chartHover(options) {
2337
2380
  const within = (target, key) => key === target || options.live(target) && marksOf(target).includes(key);
2338
2381
  const interaction = pointerHover(svg, {
2339
2382
  find: options.find,
2383
+ moves: () => options.moves?.() ?? false,
2340
2384
  hover(target, source) {
2341
2385
  if (!options.live(target.key) || own(hovered) && hovered.keys[0] === target.key) return;
2342
2386
  endHover();
@@ -2354,6 +2398,7 @@ function chartHover(options) {
2354
2398
  find: (eventTarget) => options.find(eventTarget)?.key,
2355
2399
  order: options.order,
2356
2400
  page: (key, by) => options.page?.(key, by),
2401
+ move: (key, press) => options.move?.(key, press),
2357
2402
  element: options.element,
2358
2403
  focus(key, visible) {
2359
2404
  ringKey = visible ? key : void 0;
@@ -2473,6 +2518,14 @@ function chartHover(options) {
2473
2518
  });
2474
2519
  },
2475
2520
  sync: () => keyboard.sync(),
2521
+ retarget(to) {
2522
+ const key = keyboard.retarget(to);
2523
+ if (ringKey !== void 0) {
2524
+ ringKey = key;
2525
+ options.ring(ringKey);
2526
+ }
2527
+ linked?.shown();
2528
+ },
2476
2529
  focus(key) {
2477
2530
  if (options.live(key)) keyboard.focus(key);
2478
2531
  },
@@ -2978,8 +3031,9 @@ function geometryChanged$1(from, to) {
2978
3031
  return a.length !== b.length || a.some((segment, i) => segment.key !== b[i].key || segment.outline.d !== b[i].outline.d);
2979
3032
  }
2980
3033
  function labelsMoved(from, to) {
2981
- const a = from.labelBounds;
2982
- const b = to.labelBounds;
3034
+ return boxesMoved(from.labelBounds, to.labelBounds) || boxesMoved(from.nearbyLabels, to.nearbyLabels);
3035
+ }
3036
+ function boxesMoved(a, b) {
2983
3037
  if (a === b) return false;
2984
3038
  if (!a || !b || a.length !== b.length) return true;
2985
3039
  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);
@@ -3095,7 +3149,7 @@ function chartTooltip(svg, options) {
3095
3149
  const option = options.option();
3096
3150
  const known = texts.get(row);
3097
3151
  if (known && known.option === option) return known.content;
3098
- const content = text(option, row.datum, summary);
3152
+ const content = text(option, row.datum, summary, row.series);
3099
3153
  texts.set(row, {
3100
3154
  option,
3101
3155
  content
@@ -3264,13 +3318,13 @@ function span(bridge, box, mark, side) {
3264
3318
  const [upper, lower, top, bottom] = side === "above" ? [
3265
3319
  edge,
3266
3320
  mark,
3267
- box.top + box.height,
3321
+ box.top + box.height - OVERLAP,
3268
3322
  Math.round(mark.top + OVERLAP)
3269
3323
  ] : [
3270
3324
  mark,
3271
3325
  edge,
3272
3326
  Math.round(mark.bottom - OVERLAP),
3273
- box.top
3327
+ box.top + OVERLAP
3274
3328
  ];
3275
3329
  const left = Math.round(Math.min(upper.left, lower.left));
3276
3330
  const width = Math.round(Math.max(upper.right, lower.right)) - left;
@@ -3292,11 +3346,11 @@ function span(bridge, box, mark, side) {
3292
3346
  lower: round(lower)
3293
3347
  };
3294
3348
  }
3295
- function text(option, datum, summary) {
3349
+ function text(option, datum, summary, series) {
3296
3350
  if (option === false) return void 0;
3297
3351
  if (typeof option !== "function") return summary();
3298
3352
  try {
3299
- const result = option(datum);
3353
+ const result = series === void 0 ? option(datum) : option(datum, { series });
3300
3354
  return result === void 0 || result === null || result === "" ? void 0 : String(result);
3301
3355
  } catch (error) {
3302
3356
  report(error);
@@ -4101,7 +4155,7 @@ function layoutDonut(input) {
4101
4155
  return {
4102
4156
  frame,
4103
4157
  total,
4104
- slices: states.map((state, i) => placeSlice(frame, state, labels[i], input.measure)),
4158
+ slices: placeSlices(frame, states, labels, input.measure),
4105
4159
  labels,
4106
4160
  centerText,
4107
4161
  center: placeCenter(frame, centerText, input.measure)
@@ -4116,7 +4170,29 @@ function joinedStarts(values) {
4116
4170
  return start;
4117
4171
  });
4118
4172
  }
4119
- function placeSlice(frame, state, label, measure) {
4173
+ function placeSlices(frame, states, labels, measure) {
4174
+ const boxes = labels.map((label) => label ? labelBoxes(label, measure) : void 0);
4175
+ const labelled = boxes.flatMap((box, i) => box ? [i] : []);
4176
+ const first = labelled[0];
4177
+ const last = labelled[labelled.length - 1];
4178
+ const before = [];
4179
+ const after = [];
4180
+ let seen;
4181
+ for (let i = 0; i < states.length; i++) {
4182
+ before[i] = seen ?? (last === i ? void 0 : last);
4183
+ if (boxes[i]) seen = i;
4184
+ }
4185
+ seen = void 0;
4186
+ for (let i = states.length - 1; i >= 0; i--) {
4187
+ after[i] = seen ?? (first === i ? void 0 : first);
4188
+ if (boxes[i]) seen = i;
4189
+ }
4190
+ return states.map((state, i) => {
4191
+ const sides = before[i] === after[i] ? [before[i]] : [before[i], after[i]];
4192
+ return placeSlice(frame, state, labels[i], measure, sides.flatMap((j) => j === void 0 ? [] : boxes[j]));
4193
+ });
4194
+ }
4195
+ function placeSlice(frame, state, label, measure, nearby) {
4120
4196
  const geometry = describeArc({
4121
4197
  key: state.key,
4122
4198
  series: state.series,
@@ -4126,7 +4202,8 @@ function placeSlice(frame, state, label, measure) {
4126
4202
  outer: frame.outer,
4127
4203
  start: state.start,
4128
4204
  end: state.end,
4129
- labelBounds: label && measure ? labelBoxes(label, measure) : []
4205
+ labelBounds: label && measure ? labelBoxes(label, measure) : [],
4206
+ ...nearby ? { nearbyLabels: nearby } : {}
4130
4207
  });
4131
4208
  return {
4132
4209
  ...state,
@@ -4617,9 +4694,10 @@ function donutChart$1(target, options, env) {
4617
4694
  };
4618
4695
  });
4619
4696
  const labels = placeLabels(f, now.map(({ state }) => state), measure);
4620
- return now.map(({ record, state }, i) => ({
4697
+ const slices = placeSlices(f, now.map(({ state }) => state), labels, measure);
4698
+ return now.map(({ record }, i) => ({
4621
4699
  record,
4622
- slice: placeSlice(f, state, labels[i], measure),
4700
+ slice: slices[i],
4623
4701
  label: labels[i]
4624
4702
  }));
4625
4703
  }
@@ -5012,6 +5090,165 @@ function mergeRing(shown, next) {
5012
5090
  });
5013
5091
  return out;
5014
5092
  }
5093
+ // src/charts/curve.ts
5094
+ const CURVES = ["linear", "monotone"];
5095
+ function bendOf(curve) {
5096
+ return curve === "monotone" ? 1 : 0;
5097
+ }
5098
+ function lineCurve(xs, values, amount, scales, presence) {
5099
+ const knotOf = new Int32Array(xs.length).fill(-1);
5100
+ const kx = [];
5101
+ const kv = [];
5102
+ const run = [];
5103
+ const kp = [];
5104
+ let runs = 0;
5105
+ let joined = false;
5106
+ for (let i = 0; i < xs.length; i++) {
5107
+ const value = values[i];
5108
+ if (value === void 0) {
5109
+ joined = false;
5110
+ continue;
5111
+ }
5112
+ const k = kx.length - 1;
5113
+ if (joined && xs[i] === kx[k] && value === kv[k]) {
5114
+ knotOf[i] = k;
5115
+ kp[k] = Math.max(kp[k], presence?.[i] ?? 1);
5116
+ continue;
5117
+ }
5118
+ if (!joined || xs[i] === kx[k]) runs++;
5119
+ kx.push(xs[i]);
5120
+ kv.push(value);
5121
+ run.push(runs);
5122
+ kp.push(presence?.[i] ?? 1);
5123
+ knotOf[i] = k + 1;
5124
+ joined = true;
5125
+ }
5126
+ const tangents = amount > 0 ? new Float64Array(kx.length) : void 0;
5127
+ if (tangents) for (let start = 0; start < kx.length;) {
5128
+ let end = start + 1;
5129
+ while (end < kx.length && run[end] === run[start]) end++;
5130
+ monotoneTangents(kx, kv, start, end, tangents);
5131
+ if (presence) fade(kx, kv, kp, start, end, tangents);
5132
+ start = end;
5133
+ }
5134
+ const piece = (from, to) => {
5135
+ const k = knotOf[from];
5136
+ if (k < 0 || knotOf[to] !== k + 1 || run[k + 1] !== run[k]) return void 0;
5137
+ const h = kx[k + 1] - kx[k];
5138
+ const v0 = kv[k];
5139
+ const v1 = kv[k + 1];
5140
+ const slope = (v1 - v0) / h;
5141
+ const [lo, hi] = slope < 0 ? [3 * slope, 0] : [0, 3 * slope];
5142
+ const ease = (tangent) => Math.min(hi, Math.max(lo, amount === 1 ? tangent : slope + amount * (tangent - slope)));
5143
+ const a = tangents ? ease(tangents[k]) : slope;
5144
+ const b = tangents ? ease(tangents[k + 1]) : slope;
5145
+ return [
5146
+ v0,
5147
+ v0 + h * a / 3,
5148
+ v1 - h * b / 3,
5149
+ v1,
5150
+ k
5151
+ ];
5152
+ };
5153
+ return {
5154
+ between(from, to, through = Infinity) {
5155
+ const p = piece(from, to);
5156
+ if (!p || !tangents) return [];
5157
+ const [v0, c1, c2, v1, k] = p;
5158
+ const x0 = kx[k];
5159
+ const h = kx[k + 1] - x0;
5160
+ const left = scales.x(x0);
5161
+ const right = scales.x(kx[k + 1]);
5162
+ const n = Math.min(cubicPieces({
5163
+ x: left,
5164
+ y: scales.y(v0)
5165
+ }, {
5166
+ x: left + (right - left) / 3,
5167
+ y: scales.y(c1)
5168
+ }, {
5169
+ x: right - (right - left) / 3,
5170
+ y: scales.y(c2)
5171
+ }, {
5172
+ x: right,
5173
+ y: scales.y(v1)
5174
+ }), Math.max(1, Math.ceil(Math.abs(right - left) / FLAT)));
5175
+ const bends = [];
5176
+ for (let j = 1; j < n; j++) {
5177
+ const x = x0 + j / n * h;
5178
+ if (!(x < through)) break;
5179
+ bends.push({
5180
+ x,
5181
+ value: cubic(v0, c1, c2, v1, j / n)
5182
+ });
5183
+ }
5184
+ return bends;
5185
+ },
5186
+ valueAt(from, to, x) {
5187
+ const p = piece(from, to);
5188
+ if (!p) return values[from] ?? 0;
5189
+ const [v0, c1, c2, v1, k] = p;
5190
+ return cubic(v0, c1, c2, v1, (x - kx[k]) / (kx[k + 1] - kx[k]));
5191
+ }
5192
+ };
5193
+ }
5194
+ function monotoneTangents(xs, values, start, end, out) {
5195
+ const count = end - start;
5196
+ if (count < 2) {
5197
+ if (count === 1) out[start] = 0;
5198
+ return;
5199
+ }
5200
+ const slope = (k) => (values[k + 1] - values[k]) / (xs[k + 1] - xs[k]);
5201
+ if (count === 2) {
5202
+ out[start] = out[start + 1] = slope(start);
5203
+ return;
5204
+ }
5205
+ for (let k = start + 1; k < end - 1; k++) {
5206
+ const h0 = xs[k] - xs[k - 1];
5207
+ const h1 = xs[k + 1] - xs[k];
5208
+ const s0 = slope(k - 1);
5209
+ const s1 = slope(k);
5210
+ const p = (s0 * h1 + s1 * h0) / (h0 + h1);
5211
+ out[k] = (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), .5 * Math.abs(p)) || 0;
5212
+ }
5213
+ out[start] = (3 * slope(start) - out[start + 1]) / 2;
5214
+ out[end - 1] = (3 * slope(end - 2) - out[end - 2]) / 2;
5215
+ }
5216
+ function fade(xs, values, presence, start, end, tangents) {
5217
+ const kept = [];
5218
+ for (let k = start; k < end; k++) if (presence[k] >= 1) kept.push(k);
5219
+ if (kept.length === end - start || kept.length < 2) return;
5220
+ const kx = kept.map((k) => xs[k]);
5221
+ const kv = kept.map((k) => values[k]);
5222
+ const without = new Float64Array(kept.length);
5223
+ monotoneTangents(kx, kv, 0, kept.length, without);
5224
+ const eased = new Float64Array(end - start);
5225
+ let j = 0;
5226
+ let i = 0;
5227
+ for (let k = start; k < end; k++) {
5228
+ while (j < kx.length - 2 && kx[j + 1] <= xs[k]) j++;
5229
+ const own = kept[i] === k ? i++ : -1;
5230
+ let least = 1;
5231
+ for (let n = Math.max(start, k - 2); n < Math.min(end, k + 3); n++) least = Math.min(least, presence[n]);
5232
+ if (least >= 1) {
5233
+ eased[k - start] = tangents[k];
5234
+ continue;
5235
+ }
5236
+ let slope;
5237
+ if (own >= 0) slope = without[own];
5238
+ else {
5239
+ const h = kx[j + 1] - kx[j];
5240
+ const u = Math.min(1, Math.max(0, (xs[k] - kx[j]) / h));
5241
+ slope = (6 * u * u - 6 * u) * (kv[j] - kv[j + 1]) / h + (3 * u * u - 4 * u + 1) * without[j] + (3 * u * u - 2 * u) * without[j + 1];
5242
+ }
5243
+ eased[k - start] = least * tangents[k] + (1 - least) * slope;
5244
+ }
5245
+ tangents.set(eased, start);
5246
+ }
5247
+ const sign = (x) => x < 0 ? -1 : 1;
5248
+ function cubic(v0, c1, c2, v1, u) {
5249
+ const s = 1 - u;
5250
+ return s * s * s * v0 + 3 * s * s * u * c1 + 3 * s * u * u * c2 + u * u * u * v1;
5251
+ }
5015
5252
  // src/charts/time.ts
5016
5253
  const TIME_ZONES = ["UTC", "local"];
5017
5254
  const SECOND = 1e3;
@@ -5027,7 +5264,7 @@ const LONGEST$1 = {
5027
5264
  month: 31 * DAY,
5028
5265
  year: 366 * DAY
5029
5266
  };
5030
- const STEPS = [
5267
+ const STEPS = /* @__PURE__ */ (() => [
5031
5268
  ...[
5032
5269
  1,
5033
5270
  5,
@@ -5075,7 +5312,7 @@ const STEPS = [
5075
5312
  unit: "month",
5076
5313
  count: 3
5077
5314
  }
5078
- ];
5315
+ ])();
5079
5316
  const LEVELS = [
5080
5317
  "year",
5081
5318
  "month",
@@ -5305,6 +5542,8 @@ function lineEncoding(options) {
5305
5542
  if (!TIME_ZONES.includes(timeZone)) throw new TypeError(`lineChart: timeZone must be "UTC" or "local", got ${show$1(timeZone)}.`);
5306
5543
  const xFormat = options.xFormat;
5307
5544
  if (xFormat !== void 0 && typeof xFormat !== "function") throw new TypeError("lineChart: xFormat must be a function that turns an x into text.");
5545
+ const curve = options.curve ?? "linear";
5546
+ if (!CURVES.includes(curve)) throw new TypeError(`lineChart: curve must be "linear" or "monotone", got ${show$1(curve)}.`);
5308
5547
  return {
5309
5548
  x: accessor(x),
5310
5549
  key: key === void 0 ? void 0 : accessor(key),
@@ -5313,7 +5552,8 @@ function lineEncoding(options) {
5313
5552
  value: accessor(field)
5314
5553
  })),
5315
5554
  timeZone,
5316
- xFormat: options.xFormat
5555
+ xFormat: options.xFormat,
5556
+ curve
5317
5557
  };
5318
5558
  }
5319
5559
  function layoutLines(input) {
@@ -5364,7 +5604,8 @@ function layoutLines(input) {
5364
5604
  series,
5365
5605
  yTicks: domain.ticks.map((value, i) => placeYTick(frame, value, yTexts[i])),
5366
5606
  xTicks: spaced(xTicks, xWidths),
5367
- decimals: decimalsBy
5607
+ decimals: decimalsBy,
5608
+ curve: input.encoding.curve
5368
5609
  };
5369
5610
  }
5370
5611
  function positions(frame) {
@@ -5376,7 +5617,7 @@ function positions(frame) {
5376
5617
  y: (value) => ySpan > 0 ? box.bottom - (value - scale.lo) / ySpan * (box.bottom - box.top) : box.bottom
5377
5618
  };
5378
5619
  }
5379
- function placeLines(frame, rows, series, through, time = false, labels) {
5620
+ function placeLines(frame, rows, series, through, time = false, labels, bend = 0) {
5380
5621
  const first = rows[0];
5381
5622
  if (!first) return [];
5382
5623
  const at = positions(frame);
@@ -5386,27 +5627,47 @@ function placeLines(frame, rows, series, through, time = false, labels) {
5386
5627
  const next = rows[last + 1];
5387
5628
  const share = next && next.x > end.x && through > end.x ? (through - end.x) / (next.x - end.x) : void 0;
5388
5629
  const shown = rows.slice(0, last + 1);
5630
+ const xs = bend > 0 ? rows.map((row) => row.x) : [];
5631
+ const presence = bend > 0 && rows.some((row) => row.presence !== void 0 && row.presence < 1) ? rows.map((row) => row.presence ?? 1) : void 0;
5389
5632
  const datas = /* @__PURE__ */ new Map();
5390
5633
  const related = (own) => (name) => name === own ? void 0 : datas.get(name);
5391
5634
  const traced = series.map((name) => {
5392
5635
  const has = (row) => !row.missing?.has(name);
5636
+ const curve = bend > 0 ? lineCurve(xs, rows.map((row) => has(row) ? row.values[name] ?? 0 : void 0), bend, at, presence) : void 0;
5393
5637
  const vertices = [];
5394
5638
  let gap = false;
5395
- for (const row of shown) if (!has(row)) gap = vertices.length > 0;
5396
- else {
5397
- vertices.push({
5398
- at: row.x,
5399
- value: row.values[name] ?? 0,
5400
- datum: row.datum,
5401
- gapBefore: gap
5402
- });
5403
- gap = false;
5404
- }
5639
+ let before = -1;
5640
+ shown.forEach((row, i) => {
5641
+ if (!has(row)) gap = vertices.length > 0;
5642
+ else {
5643
+ if (curve && before >= 0) for (const b of curve.between(before, i)) vertices.push({
5644
+ at: b.x,
5645
+ value: b.value,
5646
+ datum: rows[before].datum,
5647
+ gapBefore: false
5648
+ });
5649
+ vertices.push({
5650
+ at: row.x,
5651
+ value: row.values[name] ?? 0,
5652
+ datum: row.datum,
5653
+ gapBefore: gap
5654
+ });
5655
+ gap = false;
5656
+ before = i;
5657
+ }
5658
+ });
5405
5659
  if (share !== void 0 && has(end) && has(next)) {
5660
+ if (curve) for (const b of curve.between(last, last + 1, through)) vertices.push({
5661
+ at: b.x,
5662
+ value: b.value,
5663
+ datum: end.datum,
5664
+ gapBefore: false
5665
+ });
5406
5666
  const from = end.values[name] ?? 0;
5667
+ const value = curve ? curve.valueAt(last, last + 1, through) : from + share * ((next.values[name] ?? 0) - from);
5407
5668
  vertices.push({
5408
5669
  at: through,
5409
- value: from + share * ((next.values[name] ?? 0) - from),
5670
+ value,
5410
5671
  datum: end.datum,
5411
5672
  gapBefore: false
5412
5673
  });
@@ -5428,15 +5689,19 @@ function placeLines(frame, rows, series, through, time = false, labels) {
5428
5689
  ...points[points.length - 1],
5429
5690
  text: labels.text(name, vertices[vertices.length - 1].value)
5430
5691
  }))) : [];
5692
+ const boxes = labels ? placed.map((label) => label.text !== "" ? textBox(label, labels.measure, "ec-value", VALUE_SIZE) : void 0) : [];
5431
5693
  return traced.map(({ name, vertices, points }) => {
5432
5694
  const tip = points[points.length - 1];
5433
- const label = labels ? placed[named.findIndex((line) => line.name === name)] ?? {
5695
+ const index = named.findIndex((line) => line.name === name);
5696
+ const label = labels ? placed[index] ?? {
5434
5697
  x: tip.x + LABEL_GAP,
5435
5698
  y: tip.y + VALUE_SIZE * CENTRE$1,
5436
5699
  anchor: "start",
5437
5700
  text: ""
5438
5701
  } : void 0;
5439
- const labelBounds = labels ? label && label.text !== "" ? [textBox(label, labels.measure, "ec-value", VALUE_SIZE)] : [] : void 0;
5702
+ const own = boxes[index];
5703
+ const labelBounds = labels ? own ? [own] : [] : void 0;
5704
+ const nearbyLabels = labels ? boxes.filter((box, i) => box !== void 0 && i !== index) : void 0;
5440
5705
  const breaks = vertices.flatMap((v, j) => v.gapBefore ? [j] : []);
5441
5706
  const geometry = describeLine({
5442
5707
  key: name,
@@ -5444,7 +5709,8 @@ function placeLines(frame, rows, series, through, time = false, labels) {
5444
5709
  points,
5445
5710
  width: LINE_WIDTH,
5446
5711
  ...breaks.length > 0 ? { breaks } : {},
5447
- ...labelBounds ? { labelBounds } : {}
5712
+ ...labelBounds ? { labelBounds } : {},
5713
+ ...nearbyLabels ? { nearbyLabels } : {}
5448
5714
  });
5449
5715
  let distance = 0;
5450
5716
  const samples = vertices.map((v, j) => {
@@ -5755,6 +6021,7 @@ const VISIBLE = .5;
5755
6021
  function lineChart$1(target, options, env) {
5756
6022
  const container = resolveTarget$2(target, "lineChart");
5757
6023
  checkChartOptions(options, "lineChart");
6024
+ let hoverKind = hoverOf(options);
5758
6025
  let current = options;
5759
6026
  const motion = chartMotion(options.motion, env.motion);
5760
6027
  let effects = resolveEffects(options.on, env.presets);
@@ -5812,10 +6079,12 @@ function lineChart$1(target, options, env) {
5812
6079
  let laidOut;
5813
6080
  let firstTable;
5814
6081
  let names;
6082
+ let pointNames;
5815
6083
  try {
5816
6084
  laidOut = layout(current);
5817
6085
  firstTable = tableFor(current, laidOut);
5818
6086
  names = namesFor(current, laidOut);
6087
+ pointNames = hoverKind === "point" ? pointNamesFor(current, laidOut) : void 0;
5819
6088
  } catch (error) {
5820
6089
  svg.remove();
5821
6090
  throw error;
@@ -5864,6 +6133,11 @@ function lineChart$1(target, options, env) {
5864
6133
  motion,
5865
6134
  onChange: changed
5866
6135
  });
6136
+ const curved = animated(bendOf(laidOut.curve), interpolateNumber, {
6137
+ clock,
6138
+ motion,
6139
+ onChange: changed
6140
+ });
5867
6141
  const yTicks = /* @__PURE__ */ new Map();
5868
6142
  const xTicks = /* @__PURE__ */ new Map();
5869
6143
  let counting = laidOut.decimals;
@@ -5931,7 +6205,7 @@ function lineChart$1(target, options, env) {
5931
6205
  function placedFor(next) {
5932
6206
  const states = next.rows.map(restState);
5933
6207
  return {
5934
- lines: new Map(placeLines(next.frame, states, next.series, drawnThrough(next), next.time, endLabels(next.decimals)).map((line) => [line.series, line])),
6208
+ lines: new Map(placeLines(next.frame, states, next.series, drawnThrough(next), next.time, endLabels(next.decimals), bendOf(next.curve)).map((line) => [line.series, line])),
5935
6209
  points: new Map(states.flatMap((state) => placePoints(next.frame, state, next.series, next.time)).map((point) => [point.key, point]))
5936
6210
  };
5937
6211
  }
@@ -6066,6 +6340,7 @@ function lineChart$1(target, options, env) {
6066
6340
  };
6067
6341
  return [...rowOrder, ...[...leavingRows.values()].filter((record) => record.presence.value > 0 && record.anchor)].map((record) => {
6068
6342
  const { x, values } = stateOf(record);
6343
+ const presence = record.anchor && record.presence.value < 1 ? { presence: record.presence.value } : {};
6069
6344
  return {
6070
6345
  record,
6071
6346
  state: {
@@ -6073,7 +6348,8 @@ function lineChart$1(target, options, env) {
6073
6348
  datum: record.row.datum,
6074
6349
  x,
6075
6350
  values,
6076
- missing: record.row.missing
6351
+ missing: record.row.missing,
6352
+ ...presence
6077
6353
  }
6078
6354
  };
6079
6355
  }).sort((a, b) => a.state.x - b.state.x);
@@ -6188,7 +6464,7 @@ function lineChart$1(target, options, env) {
6188
6464
  function paintLines(frame, states) {
6189
6465
  const drawnLines = [...lineOrder, ...leavingLines()];
6190
6466
  if (states.length === 0 || drawnLines.length === 0) return;
6191
- const placed = placeLines(frame, states, drawnLines.map((line) => line.series), drawnThrough(laidOut), laidOut.time, endLabels(counting));
6467
+ const placed = placeLines(frame, states, drawnLines.map((line) => line.series), drawnThrough(laidOut), laidOut.time, endLabels(counting), curved.value);
6192
6468
  showAll(drawnLines.map((line, i) => ({
6193
6469
  record: line,
6194
6470
  placed: placed[i]
@@ -6279,8 +6555,16 @@ function lineChart$1(target, options, env) {
6279
6555
  surface.hide(point.key, hidden);
6280
6556
  }
6281
6557
  }
6558
+ if (stopsLayer) paintStops(frame);
6282
6559
  }
6283
6560
  function showHover(key) {
6561
+ const point = points.get(key);
6562
+ if (point) {
6563
+ if (!revealed(point.row)) return;
6564
+ const { row } = point.row;
6565
+ tooltip.show(point.shown.geometry, about(row, point.series), () => pointSummary(row, point.series, current), point.handle.style.transform);
6566
+ return;
6567
+ }
6284
6568
  const record = rows.get(key);
6285
6569
  if (!record || !revealed(record)) return;
6286
6570
  const marks = livePoints(record);
@@ -6313,9 +6597,10 @@ function lineChart$1(target, options, env) {
6313
6597
  }
6314
6598
  let ringLine;
6315
6599
  function drawRing(key) {
6316
- const record = key === void 0 ? void 0 : rows.get(key);
6600
+ const point = key === void 0 ? void 0 : points.get(key);
6601
+ const record = key === void 0 ? void 0 : point?.row ?? rows.get(key);
6317
6602
  const live = record !== void 0 && revealed(record);
6318
- const marks = live ? livePoints(record) : [];
6603
+ const marks = live ? point ? [point] : livePoints(record) : [];
6319
6604
  if (live && marks.length === 0) {
6320
6605
  ringLine ?? (ringLine = svgElement("line", {
6321
6606
  class: "ec-focus-ring",
@@ -6365,34 +6650,243 @@ function lineChart$1(target, options, env) {
6365
6650
  const record = column ? byColumn.get(column) : void 0;
6366
6651
  return record && rows.get(record.key) === record && revealed(record) ? record : void 0;
6367
6652
  }
6653
+ let stopsLayer;
6654
+ let plotHit;
6655
+ const stops = /* @__PURE__ */ new Map();
6656
+ let stopOrder = [];
6657
+ const byStop = /* @__PURE__ */ new WeakMap();
6658
+ function pointOrder() {
6659
+ const bySeries = new Map(laidOut.series.map((series) => [series, []]));
6660
+ for (const record of rowOrder) for (const point of livePoints(record)) bySeries.get(point.series)?.push(point);
6661
+ return [...bySeries.values()].flat();
6662
+ }
6663
+ const along = (series) => rowOrder.filter(revealed).flatMap((record) => livePoints(record).filter((point) => point.series === series));
6664
+ function nearestPoint(at) {
6665
+ let best;
6666
+ let far = Infinity;
6667
+ let rank = Infinity;
6668
+ for (const record of rowOrder) {
6669
+ if (!revealed(record)) continue;
6670
+ for (const point of livePoints(record)) {
6671
+ const { x, y } = point.shown.geometry.center;
6672
+ const d = (x - at.x) ** 2 + (y - at.y) ** 2;
6673
+ const r = laidOut.series.indexOf(point.series);
6674
+ if (d < far || d === far && r < rank) [best, far, rank] = [
6675
+ point,
6676
+ d,
6677
+ r
6678
+ ];
6679
+ }
6680
+ }
6681
+ return best;
6682
+ }
6683
+ function heldPoint(at) {
6684
+ const point = hover.key === void 0 || !tooltip.element() ? void 0 : points.get(hover.key);
6685
+ if (!point || !revealed(point.row)) return void 0;
6686
+ const { transform } = point.handle.style;
6687
+ let on = at;
6688
+ if (transform) try {
6689
+ on = matrix.apply(invert(transform), at);
6690
+ } catch {
6691
+ return;
6692
+ }
6693
+ const { center } = point.shown.geometry;
6694
+ return (on.x - center.x) ** 2 + (on.y - center.y) ** 2 <= 4.5 ** 2 ? point : void 0;
6695
+ }
6696
+ function pointAt(clientX, clientY) {
6697
+ const at = fromClient(clientX, clientY);
6698
+ return heldPoint(at) ?? nearestPoint(at);
6699
+ }
6700
+ function fromClient(x, y) {
6701
+ const box = svg.getBoundingClientRect();
6702
+ const k = box.width > 0 && drawnFrame.box.width > 0 ? box.width / drawnFrame.box.width : 1;
6703
+ return {
6704
+ x: (x - box.left) / k,
6705
+ y: (y - box.top) / k
6706
+ };
6707
+ }
6708
+ const abouts = /* @__PURE__ */ new WeakMap();
6709
+ function about(row, series) {
6710
+ let bySeries = abouts.get(row);
6711
+ if (!bySeries) abouts.set(row, bySeries = /* @__PURE__ */ new Map());
6712
+ let known = bySeries.get(series);
6713
+ if (!known) bySeries.set(series, known = {
6714
+ datum: row.datum,
6715
+ series
6716
+ });
6717
+ return known;
6718
+ }
6719
+ function syncStops() {
6720
+ if (hoverKind !== "point") return;
6721
+ if (!stopsLayer) {
6722
+ stopsLayer = svgElement("g", { class: "ec-stops" }, svg);
6723
+ svg.insertBefore(stopsLayer, overlay);
6724
+ plotHit = svgElement("rect", { class: "ec-hit" }, stopsLayer);
6725
+ stopsLayer.addEventListener("click", (event) => {
6726
+ const point = pointAt(event.clientX, event.clientY);
6727
+ if (point) stops.get(point.key)?.element.focus();
6728
+ });
6729
+ }
6730
+ const live = pointOrder();
6731
+ const keep = new Set(live.map((point) => point.key));
6732
+ for (const [key, stop] of stops) {
6733
+ if (keep.has(key)) continue;
6734
+ stop.element.remove();
6735
+ stops.delete(key);
6736
+ }
6737
+ const order = live.map((point) => {
6738
+ let stop = stops.get(point.key);
6739
+ if (!stop) {
6740
+ const element = svgElement("g", {
6741
+ class: "ec-stop",
6742
+ "data-key": point.key,
6743
+ role: "img"
6744
+ }, stopsLayer);
6745
+ stop = {
6746
+ element,
6747
+ bounds: svgElement("circle", {
6748
+ r: 8.5,
6749
+ fill: "none"
6750
+ }, element),
6751
+ x: NaN,
6752
+ y: NaN,
6753
+ hidden: void 0
6754
+ };
6755
+ stops.set(point.key, stop);
6756
+ byStop.set(element, point.key);
6757
+ }
6758
+ const name = pointNames?.get(point.key) ?? point.key;
6759
+ if (stop.element.getAttribute("aria-label") !== name) stop.element.setAttribute("aria-label", name);
6760
+ tooltip.describe(stop.element, about(point.row.row, point.series));
6761
+ return stop.element;
6762
+ });
6763
+ orderElements(stopsLayer, stopOrder, order, hover.active);
6764
+ stopOrder = order;
6765
+ }
6766
+ function paintStops(frame) {
6767
+ const { left, right, top, bottom } = frame.box;
6768
+ setAttributes(plotHit, {
6769
+ x: left - DOT_RADIUS,
6770
+ y: top - DOT_RADIUS,
6771
+ width: right - left + 2 * DOT_RADIUS,
6772
+ height: bottom - top + 2 * DOT_RADIUS
6773
+ });
6774
+ for (const [key, stop] of stops) {
6775
+ const point = points.get(key);
6776
+ if (!point) continue;
6777
+ const hidden = !revealed(point.row);
6778
+ if (stop.hidden !== hidden) {
6779
+ stop.hidden = hidden;
6780
+ setAttributes(stop.element, { visibility: hidden ? "hidden" : void 0 });
6781
+ }
6782
+ const { x, y } = point.shown.geometry.center;
6783
+ if (stop.x === x && stop.y === y) continue;
6784
+ stop.x = x;
6785
+ stop.y = y;
6786
+ setAttributes(stop.bounds, {
6787
+ cx: x,
6788
+ cy: y
6789
+ });
6790
+ }
6791
+ }
6792
+ function counterpart(key) {
6793
+ const point = points.get(key);
6794
+ if (point) return point.row.key;
6795
+ const shown = rowOrder.filter(revealed);
6796
+ const i = shown.findIndex((record) => record.key === key);
6797
+ for (let step = 0; i >= 0 && step < shown.length; step++) for (const at of [i + step, i - step]) {
6798
+ const first = shown[at] && livePoints(shown[at])[0];
6799
+ if (first) return first.key;
6800
+ }
6801
+ }
6802
+ function rehover(kind) {
6803
+ if (kind === hoverKind) return;
6804
+ hover.leave();
6805
+ hoverKind = kind;
6806
+ if (kind === "point") {
6807
+ syncStops();
6808
+ paintStops(drawnFrame);
6809
+ } else columnsLayer.removeAttribute("display");
6810
+ hover.retarget(counterpart);
6811
+ if (kind === "point") columnsLayer.setAttribute("display", "none");
6812
+ else {
6813
+ stopsLayer?.remove();
6814
+ stopsLayer = plotHit = void 0;
6815
+ stops.clear();
6816
+ stopOrder = [];
6817
+ }
6818
+ }
6819
+ const hotLines = /* @__PURE__ */ new Map();
6820
+ function heat(key, on) {
6821
+ const series = on ? hoverKind === "point" ? findMark(key)?.series : void 0 : hotLines.get(key);
6822
+ if (series === void 0) return;
6823
+ if (on) hotLines.set(key, series);
6824
+ else hotLines.delete(key);
6825
+ surface.hot(key, on);
6826
+ if (!on && [...hotLines.values()].includes(series)) return;
6827
+ findMark(series)?.group.classList.toggle("ec-hot-line", on);
6828
+ surface.hot(series, on);
6829
+ }
6830
+ function live(key) {
6831
+ const point = hoverKind === "point" ? points.get(key) : void 0;
6832
+ const record = hoverKind === "point" ? point?.row : rows.get(key);
6833
+ return record !== void 0 && revealed(record);
6834
+ }
6368
6835
  const hover = chartHover({
6369
6836
  svg,
6370
6837
  runner,
6371
6838
  events,
6372
- dim: () => false,
6373
- find(eventTarget) {
6374
- const record = liveRowOf(eventTarget);
6375
- return record && { key: record.key };
6376
- },
6377
- live(key) {
6378
- const record = rows.get(key);
6379
- return record !== void 0 && revealed(record);
6839
+ dim: () => hoverKind === "point" && current.dim !== false && hover.key !== void 0,
6840
+ hot: heat,
6841
+ find(eventTarget, pointer) {
6842
+ if (hoverKind === "x") {
6843
+ const record = liveRowOf(eventTarget);
6844
+ return record && { key: record.key };
6845
+ }
6846
+ const element = eventTarget;
6847
+ if (!stopsLayer || typeof element?.closest !== "function" || !stopsLayer.contains(element)) return void 0;
6848
+ if (pointer) {
6849
+ const point = pointAt(pointer.x, pointer.y);
6850
+ return point && { key: point.key };
6851
+ }
6852
+ const stop = element.closest(".ec-stop");
6853
+ const key = stop ? byStop.get(stop) : void 0;
6854
+ return key !== void 0 && live(key) ? { key } : void 0;
6380
6855
  },
6381
- order: () => rowOrder.filter(revealed).map((record) => record.key),
6856
+ moves: () => hoverKind === "point",
6857
+ live,
6858
+ order: () => (hoverKind === "point" ? pointOrder().filter((point) => revealed(point.row)) : rowOrder.filter(revealed)).map((record) => record.key),
6382
6859
  page(key, by) {
6383
- const from = rows.get(key);
6384
- if (!laidOut.time || !from) return void 0;
6385
- const stops = rowOrder.filter(revealed);
6386
- const to = monthsOn(from.row.x, by, lineEncoding(current).timeZone);
6387
- if (by > 0) return (stops.find((record) => record.row.x >= to) ?? stops[stops.length - 1])?.key;
6388
- for (let i = stops.length - 1; i >= 0; i--) if (stops[i].row.x <= to) return stops[i].key;
6860
+ const point = hoverKind === "point" ? points.get(key) : void 0;
6861
+ const stops = point ? along(point.series).map((p) => ({
6862
+ key: p.key,
6863
+ x: p.row.row.x
6864
+ })) : rowOrder.filter(revealed).map((record) => ({
6865
+ key: record.key,
6866
+ x: record.row.x
6867
+ }));
6868
+ const i = stops.findIndex((stop) => stop.key === key);
6869
+ if (i < 0) return void 0;
6870
+ if (!laidOut.time) return point ? stops[Math.min(stops.length - 1, Math.max(0, i + by * Math.ceil(stops.length / 10)))].key : void 0;
6871
+ const to = monthsOn(stops[i].x, by, lineEncoding(current).timeZone);
6872
+ if (by > 0) return (stops.find((stop) => stop.x >= to) ?? stops[stops.length - 1])?.key;
6873
+ for (let j = stops.length - 1; j >= 0; j--) if (stops[j].x <= to) return stops[j].key;
6389
6874
  return stops[0]?.key;
6390
6875
  },
6876
+ move(key, press) {
6877
+ const point = hoverKind === "point" ? points.get(key) : void 0;
6878
+ if (!point) return void 0;
6879
+ const stops = press === "ArrowUp" || press === "ArrowDown" ? livePoints(point.row).sort((a, b) => a.shown.geometry.center.y - b.shown.geometry.center.y) : along(point.series);
6880
+ const i = stops.indexOf(point);
6881
+ const to = press === "Home" ? 0 : press === "End" ? stops.length - 1 : i + (press === "ArrowDown" || press === "ArrowRight" ? 1 : -1);
6882
+ return stops[Math.max(0, Math.min(stops.length - 1, to))]?.key;
6883
+ },
6391
6884
  marks: (key) => {
6392
6885
  const record = rows.get(key);
6393
- return record ? livePoints(record).map((point) => point.key) : [];
6886
+ if (record) return livePoints(record).map((point) => point.key);
6887
+ return points.has(key) ? [key] : [];
6394
6888
  },
6395
- element: (key) => (rows.get(key) ?? leavingRows.get(key))?.column,
6889
+ element: (key) => (rows.get(key) ?? leavingRows.get(key))?.column ?? stops.get(key)?.element,
6396
6890
  markElement: (key) => findMark(key)?.group,
6397
6891
  onScreen(key) {
6398
6892
  const record = findMark(key);
@@ -6431,7 +6925,7 @@ function lineChart$1(target, options, env) {
6431
6925
  }
6432
6926
  function labelColumn(record) {
6433
6927
  record.column.setAttribute("aria-label", names.get(record.key));
6434
- tooltip.describe(record.column, record.row);
6928
+ if (hoverKind === "x") tooltip.describe(record.column, record.row);
6435
6929
  }
6436
6930
  function announceChange(previous, before) {
6437
6931
  const option = current.announce;
@@ -6567,6 +7061,7 @@ function lineChart$1(target, options, env) {
6567
7061
  record.points = [...live, ...record.points.filter((point) => !kept.has(point) && drawn(point))];
6568
7062
  }
6569
7063
  for (const record of rowOrder) labelColumn(record);
7064
+ syncStops();
6570
7065
  orderElements(columnsLayer, before.filter((record) => !record.leaving).map((record) => record.column), rowOrder.map((record) => record.column), hover.active);
6571
7066
  orderElements(linesLayer, previousLines.map((line) => line.group), lineOrder.map((line) => line.group), () => null);
6572
7067
  rowChanges = changes;
@@ -6596,7 +7091,7 @@ function lineChart$1(target, options, env) {
6596
7091
  for (const tick of next.xTicks) xTicks.get(tick.value).text = tick.label.text;
6597
7092
  const goingLines = leavingLines();
6598
7093
  const folding = [...leavingRows.values()];
6599
- const values = busy(scale, frame.scale, sameFields) || [...yTicks.values()].some((tick) => busy(tick.opacity, tick.wanted ? 1 : 0, same)) || rowOrder.some((record) => busy(record.values, record.row.levels, sameFields)) || lineOrder.some((line) => busy(line.presence, 1, same)) || goingLines.some((line) => busy(line.presence, 0, same));
7094
+ const values = busy(scale, frame.scale, sameFields) || [...yTicks.values()].some((tick) => busy(tick.opacity, tick.wanted ? 1 : 0, same)) || rowOrder.some((record) => busy(record.values, record.row.levels, sameFields)) || lineOrder.some((line) => busy(line.presence, 1, same)) || goingLines.some((line) => busy(line.presence, 0, same)) || busy(curved, bendOf(next.curve), same);
6600
7095
  const positions = busy(box, frame.box, sameFields) || [...xTicks.values()].some((tick) => busy(tick.opacity, tick.wanted ? 1 : 0, same)) || rowOrder.some((record) => busy(record.x, record.row.x, same) || record.anchor !== void 0 && busy(record.presence, 1, same)) || folding.some((record) => record.anchor !== void 0 && busy(record.presence, 0, same));
6601
7096
  let first;
6602
7097
  let second;
@@ -6614,6 +7109,7 @@ function lineChart$1(target, options, env) {
6614
7109
  else value.set(to);
6615
7110
  };
6616
7111
  move(scale, frame.scale, sameFields, first);
7112
+ move(curved, bendOf(next.curve), same, first);
6617
7113
  move(box, frame.box, sameFields, second);
6618
7114
  for (const tick of yTicks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, first);
6619
7115
  for (const tick of xTicks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, second);
@@ -6690,6 +7186,8 @@ function lineChart$1(target, options, env) {
6690
7186
  });
6691
7187
  lineOrder = laidOut.rows.length > 0 ? laidOut.series.map((name) => createLine(name, placed.lines.get(name), false)) : [];
6692
7188
  for (const line of lineOrder) lines.set(line.series, line);
7189
+ syncStops();
7190
+ if (hoverKind === "point") columnsLayer.setAttribute("display", "none");
6693
7191
  land();
6694
7192
  }
6695
7193
  const liveMarks = () => [...lineOrder, ...rowOrder.flatMap(livePoints)];
@@ -6705,15 +7203,18 @@ function lineChart$1(target, options, env) {
6705
7203
  ...next
6706
7204
  };
6707
7205
  checkChartOptions(merged, "lineChart");
7206
+ const kind = hoverOf(merged);
6708
7207
  const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
6709
7208
  const nextLayout = layout(merged, swapped);
6710
7209
  const nextTable = tableFor(merged, nextLayout);
6711
7210
  const nextNames = namesFor(merged, nextLayout);
7211
+ const nextPointNames = kind === "point" ? pointNamesFor(merged, nextLayout) : void 0;
6712
7212
  if ("colors" in next) colors = toColorAssignment(merged.colors);
6713
7213
  const previous = current;
6714
7214
  const seriesBefore = laidOut.series;
6715
7215
  current = merged;
6716
7216
  names = nextNames;
7217
+ pointNames = nextPointNames;
6717
7218
  describeChart(svg, current);
6718
7219
  table.render(nextTable);
6719
7220
  const announcing = announcer !== void 0;
@@ -6722,6 +7223,8 @@ function lineChart$1(target, options, env) {
6722
7223
  announcer.destroy();
6723
7224
  announcer = void 0;
6724
7225
  }
7226
+ rehover(kind);
7227
+ hover.syncDim();
6725
7228
  transitions.supersede();
6726
7229
  const swapping = swapped !== effects;
6727
7230
  effects = swapped;
@@ -6760,8 +7263,14 @@ function lineChart$1(target, options, env) {
6760
7263
  marks: () => [...lineOrder.map((line) => line.shown.geometry), ...rowOrder.filter(revealed).flatMap((record) => livePoints(record).map((point) => point.shown.geometry))],
6761
7264
  focus(key) {
6762
7265
  if (destroyed) return;
6763
- const record = rows.get(key) ?? points.get(key)?.row;
6764
- if (record) hover.focus(record.key);
7266
+ const row = rows.get(key);
7267
+ if (hoverKind === "x") {
7268
+ const record = row ?? points.get(key)?.row;
7269
+ if (record) hover.focus(record.key);
7270
+ return;
7271
+ }
7272
+ const point = points.get(key) ?? (row && livePoints(row)[0]);
7273
+ if (point) hover.focus(point.key);
6765
7274
  },
6766
7275
  leave() {
6767
7276
  if (!destroyed) hover.leave();
@@ -6789,6 +7298,7 @@ function lineChart$1(target, options, env) {
6789
7298
  for (const record of leaving.values()) record.leave?.resolve();
6790
7299
  scale.stop();
6791
7300
  box.stop();
7301
+ curved.stop();
6792
7302
  for (const tick of [...yTicks.values(), ...xTicks.values()]) tick.opacity.stop();
6793
7303
  events.clear();
6794
7304
  rows.clear();
@@ -6861,28 +7371,53 @@ function summary(row, options) {
6861
7371
  lines: [said(row.values, options).join(" · ")]
6862
7372
  };
6863
7373
  }
7374
+ function pointSummary(row, series, options) {
7375
+ return summaryContent(row.label, labelled(row.values, options).filter((v) => v.series === series), format(options), { total: false });
7376
+ }
7377
+ function worded(options, datum, mark) {
7378
+ if (!options.markLabel) return mark.text;
7379
+ try {
7380
+ const named = options.markLabel(datum, mark);
7381
+ if (named !== void 0 && named !== null && String(named).trim() !== "") return String(named);
7382
+ } catch (error) {
7383
+ report(error);
7384
+ }
7385
+ return mark.text;
7386
+ }
6864
7387
  function namesFor(options, layout) {
6865
7388
  const formatted = format(options);
6866
7389
  return new Map(layout.rows.map((row) => {
6867
- const values = labelled(row.values, options);
6868
7390
  const text = `${row.label}: ${said(row.values, options).join(", ")}`;
6869
- if (!options.markLabel) return [row.key, text];
6870
- try {
6871
- const named = options.markLabel(row.datum, {
6872
- key: row.key,
6873
- category: row.label,
6874
- values,
6875
- total: total(row.values),
6876
- format: formatted,
6877
- text
6878
- });
6879
- if (named !== void 0 && named !== null && String(named).trim() !== "") return [row.key, String(named)];
6880
- } catch (error) {
6881
- report(error);
6882
- }
6883
- return [row.key, text];
7391
+ return [row.key, worded(options, row.datum, {
7392
+ key: row.key,
7393
+ category: row.label,
7394
+ values: labelled(row.values, options),
7395
+ total: total(row.values),
7396
+ format: formatted,
7397
+ text
7398
+ })];
6884
7399
  }));
6885
7400
  }
7401
+ function pointNamesFor(options, layout) {
7402
+ const formatted = format(options);
7403
+ return new Map(layout.rows.flatMap((row) => labelled(row.values, options).map((value) => {
7404
+ const key = pointKey(value.series, row.key);
7405
+ const text = `${row.label}: ${formatted(value.value)} ${value.label}`;
7406
+ return [key, worded(options, row.datum, {
7407
+ key,
7408
+ category: row.label,
7409
+ values: [value],
7410
+ total: value.value,
7411
+ format: formatted,
7412
+ text
7413
+ })];
7414
+ })));
7415
+ }
7416
+ function hoverOf(options) {
7417
+ const { hover = "x" } = options;
7418
+ if (hover !== "x" && hover !== "point") throw new TypeError(`lineChart: hover must be "x" or "point", got ${typeof hover === "string" ? JSON.stringify(hover) : String(hover)}.`);
7419
+ return hover;
7420
+ }
6886
7421
  // src/core/geometry/ring.ts
6887
7422
  const ROUND = .5;
6888
7423
  function goesRound(mark) {
@@ -8788,10 +9323,12 @@ function namesIn(root) {
8788
9323
  }
8789
9324
  const lineItems = (first) => first.mark?.items ?? [first];
8790
9325
  const drawsLine = (first) => lineItems(first).some((item) => item.defined !== false);
9326
+ const straight = (first) => {
9327
+ const interpolate = lineItems(first)[0]?.interpolate;
9328
+ return interpolate === void 0 || interpolate === "linear";
9329
+ };
8791
9330
  function pointsOf(first) {
8792
9331
  const items = lineItems(first);
8793
- const interpolate = items[0]?.interpolate;
8794
- if (interpolate !== void 0 && interpolate !== "linear") throw new TypeError(`fromVegaView: a line is drawn with interpolate "${interpolate}", but only straight lines can be read. Use interpolate "linear" (the default), or describe the curve with expressive()'s geometry option.`);
8795
9332
  const points = [];
8796
9333
  let gap = false;
8797
9334
  for (const item of items) {
@@ -8813,6 +9350,16 @@ function pointsOf(first) {
8813
9350
  }
8814
9351
  function lineOf(key, element, first, m) {
8815
9352
  const width = first.strokeWidth ?? Number.parseFloat(element.getAttribute("stroke-width") ?? "1");
9353
+ if (!straight(first)) {
9354
+ const scaled = width * scaleOf(m);
9355
+ return describeShape({
9356
+ key,
9357
+ series: key,
9358
+ d: element.getAttribute("d") ?? "",
9359
+ matrix: m,
9360
+ width: scaled > 0 && Number.isFinite(scaled) ? scaled : 1
9361
+ });
9362
+ }
8816
9363
  const points = pointsOf(first);
8817
9364
  const breaks = points.flatMap((p, i) => p.gapBefore ? [i] : []);
8818
9365
  return describeLine({
@@ -9573,7 +10120,7 @@ function checkOptions$8(options) {
9573
10120
  for (const [key, text] of Object.entries(labels)) if (typeof text !== "string" || text.trim() === "") throw new TypeError(`playButton: labels.${key} must be a string with some text, got ${JSON.stringify(text) ?? String(text)}.`);
9574
10121
  }
9575
10122
  // src/effects/gaits.ts
9576
- const STILL = Object.freeze({
10123
+ const STILL = /* @__PURE__ */ Object.freeze({
9577
10124
  lift: 0,
9578
10125
  spin: 0,
9579
10126
  tilt: 0
@@ -10036,22 +10583,23 @@ const PAST_LABEL = 6;
10036
10583
  const TEXT = 12.5;
10037
10584
  const CENTRE = .36;
10038
10585
  function captionPlace(mark) {
10039
- const boxes = mark.labelBounds ?? [];
10586
+ const own = mark.labelBounds ?? [];
10587
+ const nearby = mark.nearbyLabels ?? [];
10040
10588
  const heading = mark.angle(1);
10041
- const along = farthest(mark.end, heading, boxes);
10042
- if (along === void 0 && boxes.length > 0) {
10589
+ const along = farthest(mark.end, heading, own);
10590
+ if (along === void 0 && own.length > 0) {
10043
10591
  const up = mark.angle(.5) - Math.PI / 2;
10044
- const out = farthest(mark.center, up, boxes);
10045
- if (out !== void 0) return placed(mark.center, up, out);
10592
+ const out = farthest(mark.center, up, own);
10593
+ if (out !== void 0) return placed(mark.center, up, Math.max(out, farthest(mark.center, up, nearby) ?? -Infinity));
10046
10594
  }
10047
- return placed(mark.end, heading, Math.max(PAST_END, along ?? -Infinity));
10595
+ return placed(mark.end, heading, Math.max(PAST_END, along ?? -Infinity, farthest(mark.end, heading, nearby) ?? -Infinity));
10048
10596
  }
10049
10597
  function placed(from, toward, distance) {
10050
10598
  const cos = Math.cos(toward);
10051
10599
  const sin = Math.sin(toward);
10052
10600
  const point = offset(from, toward, distance);
10053
10601
  const drop = TEXT * (sin < 0 ? CENTRE * (1 + sin) : CENTRE + .44000000000000006 * sin);
10054
- const anchor = Math.abs(cos) <= Math.SQRT1_2 + 1e-9 ? "middle" : cos > 0 ? "start" : "end";
10602
+ const anchor = centred(cos) ? "middle" : cos > 0 ? "start" : "end";
10055
10603
  return {
10056
10604
  at: {
10057
10605
  x: point.x,
@@ -10061,17 +10609,23 @@ function placed(from, toward, distance) {
10061
10609
  toward
10062
10610
  };
10063
10611
  }
10612
+ function centred(cos) {
10613
+ return Math.abs(cos) <= Math.SQRT1_2 + 1e-9;
10614
+ }
10064
10615
  function farthest(from, toward, boxes) {
10065
10616
  const cos = Math.cos(toward);
10066
10617
  const sin = Math.sin(toward);
10618
+ const across = centred(cos);
10067
10619
  let exit;
10068
10620
  for (const { x, y, width, height } of boxes) {
10069
- const leaving = leaves(from, cos, sin, {
10621
+ const grown = {
10070
10622
  x: x - PAST_LABEL,
10071
10623
  y: y - PAST_LABEL,
10072
10624
  width: width + 12,
10073
10625
  height: height + 12
10074
- });
10626
+ };
10627
+ let leaving = leaves(from, cos, sin, grown);
10628
+ if (leaving !== void 0 && across) leaving = Math.max(leaving, ((sin > 0 ? grown.y + grown.height : grown.y) - from.y) / sin);
10075
10629
  if (leaving !== void 0) exit = Math.max(exit ?? leaving, leaving);
10076
10630
  }
10077
10631
  return exit;
@@ -11018,7 +11572,7 @@ function configure(options) {
11018
11572
  }
11019
11573
  }
11020
11574
  // src/index.ts
11021
- const VERSION = "0.4.0";
11575
+ const VERSION = "0.5.0";
11022
11576
  const env = {
11023
11577
  presets: presetRegistry,
11024
11578
  icons: iconRegistry,