expressive-charts 0.7.0 → 0.8.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
@@ -656,8 +656,10 @@ function layoutBars(input) {
656
656
  const domain = niceDomain(rows.map((row) => row.total));
657
657
  const texts = rows.map((row) => input.format(row.total));
658
658
  const ticks = domain.ticks.map(input.format);
659
- const frame = (input.encoding.orientation === "horizontal" ? horizontalFrame : verticalFrame)(input, rows, domain, texts, ticks);
660
- const labels = thinLabels(frame, rows, texts, input.measure);
659
+ const make = (values) => (input.encoding.orientation === "horizontal" ? horizontalFrame : verticalFrame)(input, rows, domain, values, ticks);
660
+ let frame = make(texts);
661
+ let labels = thinLabels(frame, rows, texts, input.measure);
662
+ if (!labels.values) labels = thinLabels(frame = make(), rows, texts, input.measure, false);
661
663
  return {
662
664
  width: frame.bands.width,
663
665
  height: frame.bands.height,
@@ -676,10 +678,10 @@ function layoutBars(input) {
676
678
  labels
677
679
  };
678
680
  }
679
- function thinLabels(frame, rows, texts, measure) {
681
+ function thinLabels(frame, rows, texts, measure, values = true) {
680
682
  const placed = rows.map((row, slot) => placeLabels$1(frame, slot, row.total, row.category, texts[slot]));
681
683
  const horizontal = frame.orientation === "horizontal";
682
- const values = !overlaps$1(boxesOf(placed.map(({ value }) => value), measure, "ec-value", VALUE_SIZE$2), horizontal);
684
+ values && (values = !overlaps$1(boxesOf(placed.map(({ value }) => value), measure, "ec-value", VALUE_SIZE$2), horizontal));
683
685
  const categories = (every) => boxesOf(placed.filter((_, slot) => slot % every === 0).map(({ label }) => label), measure, "ec-label", LABEL_SIZE$1);
684
686
  let k = 0;
685
687
  while (thinStep(k) < rows.length && overlaps$1(categories(thinStep(k)), horizontal)) k++;
@@ -924,12 +926,12 @@ function horizontalFrame(input, rows, domain, values, ticks) {
924
926
  const { width, measure } = input;
925
927
  const n = rows.length;
926
928
  const labelWidth = widest$1(rows.map((row) => row.category), "ec-label", LABEL_SIZE$1, measure);
927
- const valueWidth = widest$1(values, "ec-value", VALUE_SIZE$2, measure);
929
+ const valueRoom = values ? widest$1(values, "ec-value", VALUE_SIZE$2, measure) + PAD$1 : 0;
928
930
  const tickWidth = widest$1(ticks, "ec-tick", TICK_SIZE$1, measure);
929
931
  const { positive, negative } = reach(input, rows);
930
- const negativeRoom = domain.lo < 0 ? valueWidth + PAD$1 : 0;
932
+ const negativeRoom = domain.lo < 0 ? valueRoom : 0;
931
933
  const left = Math.max(labelWidth + 10 + negativeRoom + negative, tickWidth / 2 + 2);
932
- const right = Math.max(valueWidth + PAD$1 + 4 + positive, tickWidth / 2 + 2);
934
+ const right = Math.max(valueRoom + 4 + positive, tickWidth / 2 + 2);
933
935
  const rowSize = input.height === void 0 || n === 0 ? ROW : Math.max(0, input.height - TOP$1 - AXIS$1) / n;
934
936
  return {
935
937
  orientation: "horizontal",
@@ -950,15 +952,15 @@ function horizontalFrame(input, rows, domain, values, ticks) {
950
952
  }
951
953
  };
952
954
  }
953
- function verticalFrame(input, rows, domain, _values, ticks) {
955
+ function verticalFrame(input, rows, domain, values, ticks) {
954
956
  const { width, measure } = input;
955
957
  const n = rows.length;
956
958
  const height = input.height ?? VERTICAL_HEIGHT;
957
959
  const tickWidth = widest$1(ticks, "ec-tick", TICK_SIZE$1, measure);
958
960
  const { positive, negative } = reach(input, rows);
959
- const top = (domain.hi > 0 ? 20.5 : TOP$1) + positive;
960
- const values = domain.lo < 0 ? 18.5 : 0;
961
- const bottom = AXIS$1 + values + negative;
961
+ const top = (values && domain.hi > 0 ? 20.5 : TOP$1) + positive;
962
+ const under = values && domain.lo < 0 ? 18.5 : 0;
963
+ const bottom = AXIS$1 + under + negative;
962
964
  const left = tickWidth + 8 + 2;
963
965
  const plot = {
964
966
  x: left,
@@ -975,7 +977,7 @@ function verticalFrame(input, rows, domain, _values, ticks) {
975
977
  hi: domain.hi,
976
978
  from: base,
977
979
  extent: -plot.height,
978
- label: base + values + 18
980
+ label: base + under + 18
979
981
  },
980
982
  bands: {
981
983
  start: plot.x,
@@ -2321,6 +2323,11 @@ function chartHover(options) {
2321
2323
  }] : [];
2322
2324
  });
2323
2325
  const marksFor = (keys) => keys.length === 1 ? marksOf(keys[0]) : [...new Set(keys.flatMap(marksOf))];
2326
+ const standIns = (keys) => keys.flatMap((key) => {
2327
+ const input = options.standIn?.(key);
2328
+ return input ? [input] : [];
2329
+ });
2330
+ const standingFor = (keys, source, marks) => source === "linked" && marks.length === 0 ? keys.find((key) => options.standIn?.(key) !== void 0) : void 0;
2324
2331
  function hoverMarks(marks, source, effects, segment) {
2325
2332
  if (marks.length === 0) return;
2326
2333
  if (effects) runner.hover(marks.map(({ input }) => input));
@@ -2351,11 +2358,13 @@ function chartHover(options) {
2351
2358
  }
2352
2359
  function startHover(keys, source, segment, effects = true) {
2353
2360
  const marks = onScreen(marksFor(keys));
2361
+ const standing = standingFor(keys, source, marks);
2354
2362
  const started = {
2355
2363
  keys,
2356
2364
  source,
2357
2365
  marks: marks.map((mark) => mark.key),
2358
- effects
2366
+ effects,
2367
+ standing
2359
2368
  };
2360
2369
  hovered = started;
2361
2370
  for (const { key: mark } of marks) heat(mark, true);
@@ -2364,8 +2373,9 @@ function chartHover(options) {
2364
2373
  options.tooltip.show(keys[0]);
2365
2374
  listenForEscape(true);
2366
2375
  }
2376
+ if (standing !== void 0) options.stand?.(standing);
2367
2377
  hoverMarks(marks, source, effects, segment);
2368
- if (source !== "linked" && hovered === started) linked?.hover(marks.map(({ input }) => input));
2378
+ if (source !== "linked" && hovered === started) linked?.hover(marks.length > 0 ? marks.map(({ input }) => input) : standIns(keys));
2369
2379
  }
2370
2380
  function endHover() {
2371
2381
  const ended = hovered;
@@ -2373,6 +2383,7 @@ function chartHover(options) {
2373
2383
  listenForEscape(false);
2374
2384
  svg.classList.remove("ec-hovering");
2375
2385
  options.tooltip.hide();
2386
+ if (ended?.standing !== void 0) options.stand?.(void 0);
2376
2387
  leaveMarks(ended?.marks ?? []);
2377
2388
  if (own(ended)) linked?.leave();
2378
2389
  }
@@ -2451,14 +2462,20 @@ function chartHover(options) {
2451
2462
  get key() {
2452
2463
  return own(hovered) ? hovered.keys[0] : void 0;
2453
2464
  },
2465
+ get standing() {
2466
+ return hovered?.standing;
2467
+ },
2454
2468
  get ringKey() {
2455
2469
  return ringKey;
2456
2470
  },
2457
2471
  link: {
2458
- targets: () => options.order().map((key) => ({
2459
- key,
2460
- marks: onScreen(marksOf(key)).map(({ input }) => input)
2461
- })),
2472
+ targets: () => options.order().map((key) => {
2473
+ const marks = onScreen(marksOf(key)).map(({ input }) => input);
2474
+ return {
2475
+ key,
2476
+ marks: marks.length > 0 ? marks : standIns([key])
2477
+ };
2478
+ }),
2462
2479
  hover(keys, effects) {
2463
2480
  if (hovered !== void 0) endHover();
2464
2481
  const live = keys.filter(options.live);
@@ -2494,9 +2511,12 @@ function chartHover(options) {
2494
2511
  }
2495
2512
  const { source, marks: before, effects } = hovered;
2496
2513
  const now = onScreen(marksFor(keys));
2514
+ const standing = standingFor(keys, source, now);
2515
+ if (standing !== hovered.standing) options.stand?.(standing);
2497
2516
  hovered = {
2498
2517
  ...hovered,
2499
- keys
2518
+ keys,
2519
+ standing
2500
2520
  };
2501
2521
  if (now.length === before.length && now.every((mark, i) => mark.key === before[i])) return;
2502
2522
  const had = new Set(before);
@@ -2678,6 +2698,10 @@ function tableModel(input) {
2678
2698
  text: "",
2679
2699
  numeric: false
2680
2700
  });
2701
+ const missing = {
2702
+ text: input.missing ?? "missing",
2703
+ numeric: true
2704
+ };
2681
2705
  const headers = [
2682
2706
  {
2683
2707
  text: options.category ?? input.category ?? "Category",
@@ -2708,10 +2732,7 @@ function tableModel(input) {
2708
2732
  numeric: false
2709
2733
  },
2710
2734
  ...first.map((column) => columnCell(column, row, format)),
2711
- ...input.series.map((series) => row.missing?.has(series) ? {
2712
- text: MISSING,
2713
- numeric: true
2714
- } : number(values.get(series) ?? 0)),
2735
+ ...input.series.map((series) => row.missing?.has(series) ? missing : number(values.get(series) ?? 0)),
2715
2736
  ...totals ? [number(row.total)] : [],
2716
2737
  ...share(row.total),
2717
2738
  ...last.map((column) => columnCell(column, row, format))
@@ -3080,6 +3101,41 @@ function watchFonts(doc, loaded) {
3080
3101
  fonts?.addEventListener?.("loadingdone", loaded);
3081
3102
  return () => fonts?.removeEventListener?.("loadingdone", loaded);
3082
3103
  }
3104
+ const PROBE_TEXT = "Hamburgefonstiv 0123456789";
3105
+ function watchText(svg, clock, changed) {
3106
+ if (typeof ResizeObserver !== "function") return () => {};
3107
+ const probe = svgElement("text", {
3108
+ "font-size": 11,
3109
+ visibility: "hidden",
3110
+ "pointer-events": "none",
3111
+ "aria-hidden": "true"
3112
+ }, svg);
3113
+ probe.textContent = PROBE_TEXT;
3114
+ let measured = 0;
3115
+ let pending = 0;
3116
+ let stopFrame;
3117
+ const observer = new ResizeObserver((entries) => {
3118
+ const next = entries.find((entry) => entry.target === probe)?.contentRect.width ?? 0;
3119
+ if (!(next > 0) || Math.abs(next - pending) < .5) return;
3120
+ pending = next;
3121
+ if (!measured) {
3122
+ measured = next;
3123
+ return;
3124
+ }
3125
+ stopFrame ?? (stopFrame = clock.onFrame(() => {
3126
+ stopFrame?.();
3127
+ stopFrame = void 0;
3128
+ if (Math.abs(pending - measured) < .5) return;
3129
+ measured = pending;
3130
+ changed();
3131
+ }));
3132
+ });
3133
+ observer.observe(probe);
3134
+ return () => {
3135
+ observer.disconnect();
3136
+ stopFrame?.();
3137
+ };
3138
+ }
3083
3139
  function watchHoverDuration(svg, motion) {
3084
3140
  const sync = () => svg.style.setProperty("--ec-hover-duration", `${motion.duration(100, "feedback")}ms`);
3085
3141
  sync();
@@ -3560,6 +3616,10 @@ function barChart$1(target, options, env) {
3560
3616
  series: row.values.map((v) => v.series),
3561
3617
  slot: animated(row.slot, interpolateNumber, env),
3562
3618
  presence: animated(entering ? 0 : 1, interpolateNumber, env),
3619
+ drawn: {
3620
+ label: animated(Number(row.drawn.label), interpolateNumber, env),
3621
+ value: animated(Number(row.drawn.value), interpolateNumber, env)
3622
+ },
3563
3623
  count: void 0,
3564
3624
  leave: void 0
3565
3625
  };
@@ -3568,15 +3628,17 @@ function barChart$1(target, options, env) {
3568
3628
  return record;
3569
3629
  }
3570
3630
  function drawMark(record, row) {
3571
- const before = record.parts[0]?.colors.color;
3631
+ const before = record.parts;
3572
3632
  record.shown = row;
3573
3633
  setAttributes(record.hit, { ...row.hit });
3574
3634
  placeText(record.label, row.label);
3575
3635
  placeText(record.value, row.value);
3576
- const presence = record.presence.value;
3577
- const opacity = presence < 1 ? presence : void 0;
3578
- setAttributes(record.label, { opacity });
3579
- setAttributes(record.value, { opacity });
3636
+ const opacity = (drawn, fade) => {
3637
+ const shown = record.presence.value * (drawn ? fade.value : 1);
3638
+ return shown < 1 ? shown : void 0;
3639
+ };
3640
+ setAttributes(record.label, { opacity: opacity(row.drawn.label, record.drawn.label) });
3641
+ setAttributes(record.value, { opacity: opacity(row.drawn.value, record.drawn.value) });
3580
3642
  const segments = row.geometry.segments ?? [];
3581
3643
  const keep = /* @__PURE__ */ new Set();
3582
3644
  const ownColors = byCategory(current) ? seriesColors(colors.slot(record.key)) : void 0;
@@ -3609,7 +3671,7 @@ function barChart$1(target, options, env) {
3609
3671
  const drawn = Array.from(record.body.children).filter((child) => child.classList.contains("ec-segment"));
3610
3672
  if (record.parts.some((part, i) => drawn[i] !== part.element)) for (const part of record.parts) record.body.appendChild(part.element);
3611
3673
  record.handle.repaint();
3612
- if (record.parts[0]?.colors.color !== before) surface.recolor(record.key);
3674
+ if (record.parts.length !== before.length || record.parts.some((part, i) => part.colors.color !== before[i].colors.color)) surface.recolor(record.key);
3613
3675
  if (record.key === hover.ringKey) drawRing(record.key);
3614
3676
  }
3615
3677
  function drawRing(key) {
@@ -3716,6 +3778,10 @@ function barChart$1(target, options, env) {
3716
3778
  }));
3717
3779
  const total = values.reduce((sum, v) => sum + v.value, 0);
3718
3780
  const text = record.count === void 0 ? row.value.text : format(current)(round$5(total, record.count));
3781
+ const drawn = {
3782
+ label: record.drawn.label.value > 0,
3783
+ value: record.drawn.value.value > 0
3784
+ };
3719
3785
  return placeRow(frame, {
3720
3786
  key: row.key,
3721
3787
  datum: row.datum,
@@ -3724,7 +3790,7 @@ function barChart$1(target, options, env) {
3724
3790
  values,
3725
3791
  slot: record.slot.value,
3726
3792
  text,
3727
- drawn: row.drawn
3793
+ drawn
3728
3794
  }, measure);
3729
3795
  }
3730
3796
  function addTick(value, opacity) {
@@ -3846,8 +3912,11 @@ function barChart$1(target, options, env) {
3846
3912
  let first;
3847
3913
  let second;
3848
3914
  let grow;
3915
+ let out;
3916
+ let into;
3849
3917
  if (!jump && motion.staged) {
3850
3918
  const wait = values ? STAGE$2 : 0;
3919
+ const half = values && positions ? STAGE$2 : STAGE$2 / 2;
3851
3920
  first = { duration: STAGE$2 };
3852
3921
  second = {
3853
3922
  duration: STAGE$2,
@@ -3857,6 +3926,11 @@ function barChart$1(target, options, env) {
3857
3926
  duration: STAGE$2 / 2,
3858
3927
  delay: wait + STAGE$2 / 2
3859
3928
  };
3929
+ out = { duration: half };
3930
+ into = {
3931
+ duration: half,
3932
+ delay: half
3933
+ };
3860
3934
  } else if (!jump) first = second = grow = { duration: (values && positions ? 2 : 1) * STAGE$2 };
3861
3935
  const running = [];
3862
3936
  const move = (value, to, equal, timing) => {
@@ -3867,6 +3941,13 @@ function barChart$1(target, options, env) {
3867
3941
  move(scale, frame.scale, sameFields, first);
3868
3942
  move(bands, frame.bands, sameFields, second);
3869
3943
  for (const tick of ticks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, first);
3944
+ for (const record of order) {
3945
+ const fades = !arriving.has(record);
3946
+ for (const part of ["label", "value"]) {
3947
+ const to = Number(record.row.drawn[part]);
3948
+ move(record.drawn[part], to, same, fades ? to ? into : out : void 0);
3949
+ }
3950
+ }
3870
3951
  for (const record of staying) {
3871
3952
  move(record.values, valuesOf(record.row), sameFields, first);
3872
3953
  move(record.presence, 1, same, first);
@@ -3941,14 +4022,16 @@ function barChart$1(target, options, env) {
3941
4022
  for (const record of order) record.row = rows.get(record.key) ?? record.row;
3942
4023
  transitionTo(next, true);
3943
4024
  }
4025
+ const remeasure = () => {
4026
+ measure.clear();
4027
+ relayout();
4028
+ };
4029
+ const unwatchText = watchText(svg, clock, remeasure);
3944
4030
  const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
3945
4031
  measuredWidth = width;
3946
4032
  if (current.width === void 0) relayout();
3947
4033
  });
3948
- const unwatchFonts = watchFonts(doc, () => {
3949
- measure.clear();
3950
- relayout();
3951
- });
4034
+ const unwatchFonts = watchFonts(doc, remeasure);
3952
4035
  describeChart(svg, current);
3953
4036
  syncLegend(laidOut);
3954
4037
  table.render(firstTable);
@@ -4007,7 +4090,7 @@ function barChart$1(target, options, env) {
4007
4090
  }, () => arrange(nextLayout), (diff) => {
4008
4091
  if (announcing) announceChange(previous, diff);
4009
4092
  });
4010
- if (byCategory(current) !== byCategory(previous)) for (const record of [...order, ...leaving.values()]) dirty.add(record);
4093
+ if ("colors" in next || byCategory(current) !== byCategory(previous)) for (const record of [...order, ...leaving.values()]) dirty.add(record);
4011
4094
  const settled = transitionTo(nextLayout, motion.mode === "off" || nextLayout.orientation !== orientation);
4012
4095
  await transitions.wait(settled, leaves);
4013
4096
  },
@@ -4040,13 +4123,16 @@ function barChart$1(target, options, env) {
4040
4123
  table.destroy();
4041
4124
  announcer?.destroy();
4042
4125
  unwatchHoverDuration();
4126
+ unwatchText();
4043
4127
  unwatchWidth();
4044
4128
  unwatchFonts();
4045
4129
  for (const record of [...order, ...leaving.values()]) {
4046
4130
  for (const value of [
4047
4131
  record.values,
4048
4132
  record.slot,
4049
- record.presence
4133
+ record.presence,
4134
+ record.drawn.label,
4135
+ record.drawn.value
4050
4136
  ]) value.stop();
4051
4137
  record.leave?.resolve();
4052
4138
  }
@@ -4905,14 +4991,16 @@ function donutChart$1(target, options, env) {
4905
4991
  for (const record of order) record.row = slices.get(record.key) ?? record.row;
4906
4992
  transitionTo(next, true);
4907
4993
  }
4994
+ const remeasure = () => {
4995
+ measure.clear();
4996
+ relayout();
4997
+ };
4998
+ const unwatchText = watchText(svg, clock, remeasure);
4908
4999
  const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
4909
5000
  measuredWidth = width;
4910
5001
  if (current.width === void 0) relayout();
4911
5002
  });
4912
- const unwatchFonts = watchFonts(doc, () => {
4913
- measure.clear();
4914
- relayout();
4915
- });
5003
+ const unwatchFonts = watchFonts(doc, remeasure);
4916
5004
  describeDonut();
4917
5005
  syncLegend();
4918
5006
  table.render(firstTable);
@@ -5005,6 +5093,7 @@ function donutChart$1(target, options, env) {
5005
5093
  table.destroy();
5006
5094
  announcer?.destroy();
5007
5095
  unwatchHoverDuration();
5096
+ unwatchText();
5008
5097
  unwatchWidth();
5009
5098
  unwatchFonts();
5010
5099
  for (const record of [...order, ...leaving.values()]) {
@@ -5261,7 +5350,6 @@ function cubic(v0, c1, c2, v1, u) {
5261
5350
  return s * s * s * v0 + 3 * s * s * u * c1 + 3 * s * u * u * c2 + u * u * u * v1;
5262
5351
  }
5263
5352
  // src/charts/time.ts
5264
- const TIME_ZONES = ["UTC", "local"];
5265
5353
  const SECOND = 1e3;
5266
5354
  const MINUTE = 60 * SECOND;
5267
5355
  const HOUR = 60 * MINUTE;
@@ -5369,6 +5457,16 @@ const FIELDS = {
5369
5457
  fractionalSecondDigits: 3
5370
5458
  }
5371
5459
  };
5460
+ function isTimeZone(zone) {
5461
+ if (zone === "UTC" || zone === "local") return true;
5462
+ if (typeof zone !== "string") return false;
5463
+ try {
5464
+ clockOf(zone);
5465
+ return true;
5466
+ } catch {
5467
+ return false;
5468
+ }
5469
+ }
5372
5470
  function timeStep(span) {
5373
5471
  for (const step of STEPS) if (LONGEST$1[step.unit] * step.count >= span) return step;
5374
5472
  return {
@@ -5438,15 +5536,7 @@ function monthsOn(t, months, zone) {
5438
5536
  const last = /* @__PURE__ */ new Date(0);
5439
5537
  last.setUTCFullYear(year, month + months + 1, 0);
5440
5538
  const day = Math.min(date, last.getUTCDate());
5441
- const d = /* @__PURE__ */ new Date(0);
5442
- if (zone === "UTC") {
5443
- d.setUTCFullYear(year, month + months, day);
5444
- d.setUTCHours(hours, minutes, seconds, ms);
5445
- } else {
5446
- d.setFullYear(year, month + months, day);
5447
- d.setHours(hours, minutes, seconds, ms);
5448
- }
5449
- return d.getTime();
5539
+ return timeAt(zone, year, month + months, day, hours, minutes, seconds, ms);
5450
5540
  }
5451
5541
  function timeLevel(t, zone) {
5452
5542
  const { ms, seconds, minutes, hours, date, month } = partsOf(t, zone);
@@ -5458,7 +5548,8 @@ function timeLevel(t, zone) {
5458
5548
  return month !== 0 ? "month" : "year";
5459
5549
  }
5460
5550
  function timeName(times, zone) {
5461
- const finest = times.reduce((max, t) => Math.max(max, LEVELS.indexOf(timeLevel(t, zone))), 0);
5551
+ const shown = clockReader(zone);
5552
+ const finest = times.reduce((max, t) => Math.max(max, LEVELS.indexOf(timeLevel(shown(t), "UTC"))), 0);
5462
5553
  const timeZone = zoneOption(zone);
5463
5554
  const timeStyle = finest >= LEVELS.indexOf("second") ? "medium" : finest >= LEVELS.indexOf("hour") ? "short" : void 0;
5464
5555
  const options = finest === LEVELS.indexOf("millisecond") ? {
@@ -5472,7 +5563,17 @@ function timeName(times, zone) {
5472
5563
  timeZone
5473
5564
  };
5474
5565
  const format = new Intl.DateTimeFormat(void 0, options);
5475
- return (t) => format.format(t);
5566
+ if (zone === "UTC" || !timeStyle) return (t) => format.format(t);
5567
+ const named = new Intl.DateTimeFormat(void 0, {
5568
+ timeZone,
5569
+ timeZoneName: "short"
5570
+ });
5571
+ return (t) => {
5572
+ const text = format.format(t);
5573
+ if (twinOf(t, shown) === void 0) return text;
5574
+ const name = named.formatToParts(t).find((part) => part.type === "timeZoneName")?.value;
5575
+ return name ? `${text} ${name}` : text;
5576
+ };
5476
5577
  }
5477
5578
  function tickWording(zone) {
5478
5579
  const formats = /* @__PURE__ */ new Map();
@@ -5489,19 +5590,10 @@ function tickWording(zone) {
5489
5590
  return format.format(t);
5490
5591
  };
5491
5592
  }
5492
- const zoneOption = (zone) => zone === "UTC" ? "UTC" : void 0;
5593
+ const zoneOption = (zone) => zone === "local" ? void 0 : zone;
5493
5594
  function partsOf(t, zone) {
5494
- const d = new Date(t);
5495
- return zone === "UTC" ? {
5496
- year: d.getUTCFullYear(),
5497
- month: d.getUTCMonth(),
5498
- date: d.getUTCDate(),
5499
- weekday: d.getUTCDay(),
5500
- hours: d.getUTCHours(),
5501
- minutes: d.getUTCMinutes(),
5502
- seconds: d.getUTCSeconds(),
5503
- ms: d.getUTCMilliseconds()
5504
- } : {
5595
+ const d = new Date(zone === "UTC" || zone === "local" ? t : shownAt(t, zone));
5596
+ return zone === "local" ? {
5505
5597
  year: d.getFullYear(),
5506
5598
  month: d.getMonth(),
5507
5599
  date: d.getDate(),
@@ -5510,19 +5602,88 @@ function partsOf(t, zone) {
5510
5602
  minutes: d.getMinutes(),
5511
5603
  seconds: d.getSeconds(),
5512
5604
  ms: d.getMilliseconds()
5605
+ } : {
5606
+ year: d.getUTCFullYear(),
5607
+ month: d.getUTCMonth(),
5608
+ date: d.getUTCDate(),
5609
+ weekday: d.getUTCDay(),
5610
+ hours: d.getUTCHours(),
5611
+ minutes: d.getUTCMinutes(),
5612
+ seconds: d.getUTCSeconds(),
5613
+ ms: d.getUTCMilliseconds()
5513
5614
  };
5514
5615
  }
5515
5616
  function midnight(zone, year, month, date) {
5516
- const d = /* @__PURE__ */ new Date(0);
5517
- if (zone === "UTC") {
5518
- d.setUTCFullYear(year, month, date);
5519
- d.setUTCHours(0, 0, 0, 0);
5520
- } else {
5617
+ return timeAt(zone, year, month, date);
5618
+ }
5619
+ function timeAt(zone, year, month, date, hours = 0, minutes = 0, seconds = 0, ms = 0) {
5620
+ if (zone === "local") {
5621
+ const d = /* @__PURE__ */ new Date(0);
5521
5622
  d.setFullYear(year, month, date);
5522
- d.setHours(0, 0, 0, 0);
5623
+ d.setHours(hours, minutes, seconds, ms);
5624
+ return d.getTime();
5523
5625
  }
5626
+ const shown = utc(year, month, date, hours, minutes, seconds, ms);
5627
+ if (zone === "UTC") return shown;
5628
+ const before = shown - (shownAt(shown - DAY, zone) - (shown - DAY));
5629
+ const after = shown - (shownAt(shown + DAY, zone) - (shown + DAY));
5630
+ if (before === after) return before;
5631
+ const fits = [before, after].filter((t) => shownAt(t, zone) === shown);
5632
+ return fits.length > 0 ? Math.min(...fits) : before;
5633
+ }
5634
+ function utc(year, month, date, hours = 0, minutes = 0, seconds = 0, ms = 0) {
5635
+ const d = /* @__PURE__ */ new Date(0);
5636
+ d.setUTCFullYear(year, month, date);
5637
+ d.setUTCHours(hours, minutes, seconds, ms);
5524
5638
  return d.getTime();
5525
5639
  }
5640
+ function shownAt(t, zone) {
5641
+ if (zone === "UTC") return t;
5642
+ if (zone === "local") {
5643
+ const d = new Date(t);
5644
+ return utc(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
5645
+ }
5646
+ const ms = (t % SECOND + SECOND) % SECOND;
5647
+ const fields = {};
5648
+ for (const part of clockOf(zone).formatToParts(t - ms)) fields[part.type] = part.value;
5649
+ const year = Number(fields["year"]);
5650
+ return utc(fields["era"] === "BC" ? 1 - year : year, Number(fields["month"]) - 1, Number(fields["day"]), Number(fields["hour"]) % 24, Number(fields["minute"]), Number(fields["second"]), ms);
5651
+ }
5652
+ function clockReader(zone) {
5653
+ if (zone === "UTC" || zone === "local") return (t) => shownAt(t, zone);
5654
+ const kept = /* @__PURE__ */ new Map();
5655
+ return (t) => {
5656
+ let shown = kept.get(t);
5657
+ if (shown === void 0) kept.set(t, shown = shownAt(t, zone));
5658
+ return shown;
5659
+ };
5660
+ }
5661
+ function twinOf(t, shown) {
5662
+ const at = shown(t);
5663
+ for (const near of [t - DAY, t + DAY]) {
5664
+ const other = at - (shown(near) - near);
5665
+ if (other !== t && shown(other) === at) return other;
5666
+ }
5667
+ }
5668
+ const clocks = /* @__PURE__ */ new Map();
5669
+ function clockOf(zone) {
5670
+ let clock = clocks.get(zone);
5671
+ if (!clock) {
5672
+ clock = new Intl.DateTimeFormat("en-US", {
5673
+ timeZone: zone,
5674
+ hourCycle: "h23",
5675
+ era: "short",
5676
+ year: "numeric",
5677
+ month: "numeric",
5678
+ day: "numeric",
5679
+ hour: "numeric",
5680
+ minute: "numeric",
5681
+ second: "numeric"
5682
+ });
5683
+ clocks.set(zone, clock);
5684
+ }
5685
+ return clock;
5686
+ }
5526
5687
  // src/charts/line-layout.ts
5527
5688
  const LINE_WIDTH = 2.25;
5528
5689
  const DOT_RADIUS = 4.5;
@@ -5550,7 +5711,7 @@ function lineEncoding(options) {
5550
5711
  const labels = options.labels;
5551
5712
  if (labels !== void 0 && labels !== false && typeof labels !== "function") throw new TypeError("lineChart: labels must be false or a function that returns a line's end label.");
5552
5713
  const timeZone = options.timeZone ?? "UTC";
5553
- if (!TIME_ZONES.includes(timeZone)) throw new TypeError(`lineChart: timeZone must be "UTC" or "local", got ${show$1(timeZone)}.`);
5714
+ if (!isTimeZone(timeZone)) throw new TypeError(`lineChart: timeZone must be "UTC", "local" or the name of a zone Intl knows, such as "Europe/London", got ${show$1(timeZone)}.`);
5554
5715
  const xFormat = options.xFormat;
5555
5716
  if (xFormat !== void 0 && typeof xFormat !== "function") throw new TypeError("lineChart: xFormat must be a function that turns an x into text.");
5556
5717
  const curve = options.curve ?? "linear";
@@ -6047,6 +6208,7 @@ function lineChart$1(target, options, env) {
6047
6208
  const container = resolveTarget$2(target, "lineChart");
6048
6209
  checkChartOptions(options, "lineChart");
6049
6210
  let hoverKind = hoverOf(options);
6211
+ missingOf(options);
6050
6212
  let current = options;
6051
6213
  const motion = chartMotion(options.motion, env.motion);
6052
6214
  let effects = resolveEffects(options.on, env.presets);
@@ -6076,17 +6238,19 @@ function lineChart$1(target, options, env) {
6076
6238
  "aria-hidden": "true",
6077
6239
  visibility: "hidden"
6078
6240
  }, svg);
6079
- const marksLayer = svgElement("g", {
6241
+ const linesLayer = svgElement("g", { class: "ec-lines" }, svgElement("g", {
6080
6242
  class: "ec-marks",
6081
6243
  "aria-hidden": "true"
6082
- }, svg);
6083
- const linesLayer = svgElement("g", { class: "ec-lines" }, marksLayer);
6084
- const pointsLayer = svgElement("g", { class: "ec-points" }, marksLayer);
6085
- const columnsLayer = svgElement("g", { class: "ec-columns" }, svg);
6244
+ }, svg));
6086
6245
  const overlay = svgElement("g", {
6087
6246
  class: "ec-overlay",
6088
6247
  "aria-hidden": "true"
6089
6248
  }, svg);
6249
+ const pointsLayer = svgElement("g", { class: "ec-points" }, svgElement("g", {
6250
+ class: "ec-marks",
6251
+ "aria-hidden": "true"
6252
+ }, svg));
6253
+ const columnsLayer = svgElement("g", { class: "ec-columns" }, svg);
6090
6254
  const measure = textMeasure(svg);
6091
6255
  let rowOrder = [];
6092
6256
  const rows = /* @__PURE__ */ new Map();
@@ -6624,6 +6788,14 @@ function lineChart$1(target, options, env) {
6624
6788
  crosshair.setAttribute("visibility", "hidden");
6625
6789
  tooltip.hide();
6626
6790
  }
6791
+ function stand(key) {
6792
+ const record = key === void 0 ? void 0 : rows.get(key);
6793
+ if (!record || !revealed(record)) crosshair.setAttribute("visibility", "hidden");
6794
+ else setAttributes(crosshair, {
6795
+ ...placeCrosshair(drawnFrame, record.px),
6796
+ visibility: void 0
6797
+ });
6798
+ }
6627
6799
  let ringLine;
6628
6800
  function drawRing(key) {
6629
6801
  const point = key === void 0 ? void 0 : points.get(key);
@@ -6663,6 +6835,7 @@ function lineChart$1(target, options, env) {
6663
6835
  }
6664
6836
  function followHover() {
6665
6837
  if (hover.key !== void 0) showHover(hover.key);
6838
+ if (hover.standing !== void 0) stand(hover.standing);
6666
6839
  if (hover.ringKey !== void 0) drawRing(hover.ringKey);
6667
6840
  }
6668
6841
  const input = (record) => ({
@@ -6673,6 +6846,28 @@ function lineChart$1(target, options, env) {
6673
6846
  mark: record.shown.geometry,
6674
6847
  data: record.shown.data
6675
6848
  });
6849
+ function standIn(key) {
6850
+ const record = rows.get(key);
6851
+ if (!record || !revealed(record)) return void 0;
6852
+ const { row } = record;
6853
+ return {
6854
+ mark: describePoint({
6855
+ key,
6856
+ x: record.px,
6857
+ y: drawnFrame.box.top,
6858
+ r: DOT_RADIUS
6859
+ }),
6860
+ data: {
6861
+ datum: row.datum,
6862
+ samples: [{
6863
+ t: 0,
6864
+ value: NaN,
6865
+ at: laidOut.time ? new Date(row.x) : row.x
6866
+ }],
6867
+ related: () => void 0
6868
+ }
6869
+ };
6870
+ }
6676
6871
  function liveRowOf(eventTarget) {
6677
6872
  const element = eventTarget;
6678
6873
  const column = typeof element?.closest === "function" ? element.closest(".ec-column") : null;
@@ -6768,7 +6963,7 @@ function lineChart$1(target, options, env) {
6768
6963
  if (hoverKind !== "point") return;
6769
6964
  if (!stopsLayer) {
6770
6965
  stopsLayer = svgElement("g", { class: "ec-stops" }, svg);
6771
- svg.insertBefore(stopsLayer, overlay);
6966
+ svg.insertBefore(stopsLayer, columnsLayer.nextSibling);
6772
6967
  plotHit = svgElement("rect", { class: "ec-hit" }, stopsLayer);
6773
6968
  stopsLayer.addEventListener("click", (event) => {
6774
6969
  const point = pointAt(event.clientX, event.clientY);
@@ -6940,6 +7135,8 @@ function lineChart$1(target, options, env) {
6940
7135
  const record = findMark(key);
6941
7136
  return record && onScreen(record);
6942
7137
  },
7138
+ standIn,
7139
+ stand,
6943
7140
  ring: drawRing,
6944
7141
  tooltip: {
6945
7142
  show: showHover,
@@ -6968,7 +7165,8 @@ function lineChart$1(target, options, env) {
6968
7165
  total: total(row.values)
6969
7166
  })),
6970
7167
  format: format(opts),
6971
- total: false
7168
+ total: false,
7169
+ missing: missingOf(opts)
6972
7170
  });
6973
7171
  }
6974
7172
  function labelColumn(record) {
@@ -7207,14 +7405,16 @@ function lineChart$1(target, options, env) {
7207
7405
  for (const point of points.values()) point.target = placed.points.get(point.key) ?? point.target;
7208
7406
  transitionTo(next, true);
7209
7407
  }
7408
+ const remeasure = () => {
7409
+ measure.clear();
7410
+ relayout();
7411
+ };
7412
+ const unwatchText = watchText(svg, clock, remeasure);
7210
7413
  const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
7211
7414
  measuredWidth = width;
7212
7415
  if (current.width === void 0) relayout();
7213
7416
  });
7214
- const unwatchFonts = watchFonts(doc, () => {
7215
- measure.clear();
7216
- relayout();
7217
- });
7417
+ const unwatchFonts = watchFonts(doc, remeasure);
7218
7418
  describeChart(svg, current);
7219
7419
  syncLegend();
7220
7420
  table.render(firstTable);
@@ -7258,6 +7458,7 @@ function lineChart$1(target, options, env) {
7258
7458
  };
7259
7459
  checkChartOptions(merged, "lineChart");
7260
7460
  const kind = hoverOf(merged);
7461
+ missingOf(merged);
7261
7462
  const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
7262
7463
  const nextLayout = layout(merged, swapped);
7263
7464
  const nextTable = tableFor(merged, nextLayout);
@@ -7361,6 +7562,7 @@ function lineChart$1(target, options, env) {
7361
7562
  table.destroy();
7362
7563
  announcer?.destroy();
7363
7564
  unwatchHoverDuration();
7565
+ unwatchText();
7364
7566
  unwatchWidth();
7365
7567
  unwatchFonts();
7366
7568
  for (const record of [...rowOrder, ...leavingRows.values()]) for (const value of [
@@ -7463,9 +7665,10 @@ function labelled(values, options) {
7463
7665
  }
7464
7666
  function said(values, options) {
7465
7667
  const formatted = format(options);
7668
+ const missing = missingOf(options);
7466
7669
  return values.map((v) => {
7467
7670
  const label = seriesLabel(options.seriesLabels, v.series);
7468
- return v.value === void 0 ? `${label} missing` : `${formatted(v.value)} ${label}`;
7671
+ return v.value === void 0 ? `${label} ${missing}` : `${formatted(v.value)} ${label}`;
7469
7672
  });
7470
7673
  }
7471
7674
  function summary(row, options) {
@@ -7522,6 +7725,11 @@ function hoverOf(options) {
7522
7725
  if (hover !== "x" && hover !== "point") throw new TypeError(`lineChart: hover must be "x" or "point", got ${typeof hover === "string" ? JSON.stringify(hover) : String(hover)}.`);
7523
7726
  return hover;
7524
7727
  }
7728
+ function missingOf(options) {
7729
+ const { missing = MISSING } = options;
7730
+ if (typeof missing !== "string" || missing.trim() === "") throw new TypeError(`lineChart: missing must be a word for a missing value, such as "no data", got ${typeof missing === "string" ? JSON.stringify(missing) : String(missing)}.`);
7731
+ return missing;
7732
+ }
7525
7733
  // src/core/geometry/ring.ts
7526
7734
  const ROUND = .5;
7527
7735
  function goesRound(mark) {
@@ -8728,7 +8936,7 @@ function expressive$1(target, options, env) {
8728
8936
  from: from.geometry
8729
8937
  });
8730
8938
  else if (newRow || geometryChanged(from.geometry, mark.geometry) || samplesChanged(from.data.samples, mark.data.samples)) diff.moved.push(record);
8731
- if (from.parts[0]?.colors?.color !== mark.parts[0]?.colors?.color) recolor.push(mark.key);
8939
+ if (from.parts.length !== mark.parts.length || mark.parts.some((part, i) => part.colors?.color !== from.parts[i].colors?.color)) recolor.push(mark.key);
8732
8940
  record.mark = mark;
8733
8941
  } else {
8734
8942
  record = leaving.get(mark.key);
@@ -12505,7 +12713,7 @@ function configure(options) {
12505
12713
  }
12506
12714
  }
12507
12715
  // src/index.ts
12508
- const VERSION = "0.7.0";
12716
+ const VERSION = "0.8.0";
12509
12717
  const env = {
12510
12718
  presets: presetRegistry,
12511
12719
  icons: iconRegistry,