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.cjs CHANGED
@@ -2752,8 +2752,10 @@ function layoutBars(input) {
2752
2752
  const domain = niceDomain(rows.map((row) => row.total));
2753
2753
  const texts = rows.map((row) => input.format(row.total));
2754
2754
  const ticks = domain.ticks.map(input.format);
2755
- const frame = (input.encoding.orientation === "horizontal" ? horizontalFrame : verticalFrame)(input, rows, domain, texts, ticks);
2756
- const labels = thinLabels(frame, rows, texts, input.measure);
2755
+ const make = (values) => (input.encoding.orientation === "horizontal" ? horizontalFrame : verticalFrame)(input, rows, domain, values, ticks);
2756
+ let frame = make(texts);
2757
+ let labels = thinLabels(frame, rows, texts, input.measure);
2758
+ if (!labels.values) labels = thinLabels(frame = make(), rows, texts, input.measure, false);
2757
2759
  return {
2758
2760
  width: frame.bands.width,
2759
2761
  height: frame.bands.height,
@@ -2772,10 +2774,10 @@ function layoutBars(input) {
2772
2774
  labels
2773
2775
  };
2774
2776
  }
2775
- function thinLabels(frame, rows, texts, measure) {
2777
+ function thinLabels(frame, rows, texts, measure, values = true) {
2776
2778
  const placed = rows.map((row, slot) => placeLabels$1(frame, slot, row.total, row.category, texts[slot]));
2777
2779
  const horizontal = frame.orientation === "horizontal";
2778
- const values = !overlaps$1(boxesOf(placed.map(({ value }) => value), measure, "ec-value", VALUE_SIZE$2), horizontal);
2780
+ values && (values = !overlaps$1(boxesOf(placed.map(({ value }) => value), measure, "ec-value", VALUE_SIZE$2), horizontal));
2779
2781
  const categories = (every) => boxesOf(placed.filter((_, slot) => slot % every === 0).map(({ label }) => label), measure, "ec-label", LABEL_SIZE$1);
2780
2782
  let k = 0;
2781
2783
  while (thinStep(k) < rows.length && overlaps$1(categories(thinStep(k)), horizontal)) k++;
@@ -3020,12 +3022,12 @@ function horizontalFrame(input, rows, domain, values, ticks) {
3020
3022
  const { width, measure } = input;
3021
3023
  const n = rows.length;
3022
3024
  const labelWidth = widest$1(rows.map((row) => row.category), "ec-label", LABEL_SIZE$1, measure);
3023
- const valueWidth = widest$1(values, "ec-value", VALUE_SIZE$2, measure);
3025
+ const valueRoom = values ? widest$1(values, "ec-value", VALUE_SIZE$2, measure) + PAD$1 : 0;
3024
3026
  const tickWidth = widest$1(ticks, "ec-tick", TICK_SIZE$1, measure);
3025
3027
  const { positive, negative } = reach(input, rows);
3026
- const negativeRoom = domain.lo < 0 ? valueWidth + PAD$1 : 0;
3028
+ const negativeRoom = domain.lo < 0 ? valueRoom : 0;
3027
3029
  const left = Math.max(labelWidth + 10 + negativeRoom + negative, tickWidth / 2 + 2);
3028
- const right = Math.max(valueWidth + PAD$1 + 4 + positive, tickWidth / 2 + 2);
3030
+ const right = Math.max(valueRoom + 4 + positive, tickWidth / 2 + 2);
3029
3031
  const rowSize = input.height === void 0 || n === 0 ? ROW : Math.max(0, input.height - TOP$1 - AXIS$1) / n;
3030
3032
  return {
3031
3033
  orientation: "horizontal",
@@ -3046,15 +3048,15 @@ function horizontalFrame(input, rows, domain, values, ticks) {
3046
3048
  }
3047
3049
  };
3048
3050
  }
3049
- function verticalFrame(input, rows, domain, _values, ticks) {
3051
+ function verticalFrame(input, rows, domain, values, ticks) {
3050
3052
  const { width, measure } = input;
3051
3053
  const n = rows.length;
3052
3054
  const height = input.height ?? VERTICAL_HEIGHT;
3053
3055
  const tickWidth = widest$1(ticks, "ec-tick", TICK_SIZE$1, measure);
3054
3056
  const { positive, negative } = reach(input, rows);
3055
- const top = (domain.hi > 0 ? 20.5 : TOP$1) + positive;
3056
- const values = domain.lo < 0 ? 18.5 : 0;
3057
- const bottom = AXIS$1 + values + negative;
3057
+ const top = (values && domain.hi > 0 ? 20.5 : TOP$1) + positive;
3058
+ const under = values && domain.lo < 0 ? 18.5 : 0;
3059
+ const bottom = AXIS$1 + under + negative;
3058
3060
  const left = tickWidth + 8 + 2;
3059
3061
  const plot = {
3060
3062
  x: left,
@@ -3071,7 +3073,7 @@ function verticalFrame(input, rows, domain, _values, ticks) {
3071
3073
  hi: domain.hi,
3072
3074
  from: base,
3073
3075
  extent: -plot.height,
3074
- label: base + values + 18
3076
+ label: base + under + 18
3075
3077
  },
3076
3078
  bands: {
3077
3079
  start: plot.x,
@@ -4417,6 +4419,11 @@ function chartHover(options) {
4417
4419
  }] : [];
4418
4420
  });
4419
4421
  const marksFor = (keys) => keys.length === 1 ? marksOf(keys[0]) : [...new Set(keys.flatMap(marksOf))];
4422
+ const standIns = (keys) => keys.flatMap((key) => {
4423
+ const input = options.standIn?.(key);
4424
+ return input ? [input] : [];
4425
+ });
4426
+ const standingFor = (keys, source, marks) => source === "linked" && marks.length === 0 ? keys.find((key) => options.standIn?.(key) !== void 0) : void 0;
4420
4427
  function hoverMarks(marks, source, effects, segment) {
4421
4428
  if (marks.length === 0) return;
4422
4429
  if (effects) runner.hover(marks.map(({ input }) => input));
@@ -4447,11 +4454,13 @@ function chartHover(options) {
4447
4454
  }
4448
4455
  function startHover(keys, source, segment, effects = true) {
4449
4456
  const marks = onScreen(marksFor(keys));
4457
+ const standing = standingFor(keys, source, marks);
4450
4458
  const started = {
4451
4459
  keys,
4452
4460
  source,
4453
4461
  marks: marks.map((mark) => mark.key),
4454
- effects
4462
+ effects,
4463
+ standing
4455
4464
  };
4456
4465
  hovered = started;
4457
4466
  for (const { key: mark } of marks) heat(mark, true);
@@ -4460,8 +4469,9 @@ function chartHover(options) {
4460
4469
  options.tooltip.show(keys[0]);
4461
4470
  listenForEscape(true);
4462
4471
  }
4472
+ if (standing !== void 0) options.stand?.(standing);
4463
4473
  hoverMarks(marks, source, effects, segment);
4464
- if (source !== "linked" && hovered === started) linked?.hover(marks.map(({ input }) => input));
4474
+ if (source !== "linked" && hovered === started) linked?.hover(marks.length > 0 ? marks.map(({ input }) => input) : standIns(keys));
4465
4475
  }
4466
4476
  function endHover() {
4467
4477
  const ended = hovered;
@@ -4469,6 +4479,7 @@ function chartHover(options) {
4469
4479
  listenForEscape(false);
4470
4480
  svg.classList.remove("ec-hovering");
4471
4481
  options.tooltip.hide();
4482
+ if (ended?.standing !== void 0) options.stand?.(void 0);
4472
4483
  leaveMarks(ended?.marks ?? []);
4473
4484
  if (own(ended)) linked?.leave();
4474
4485
  }
@@ -4547,14 +4558,20 @@ function chartHover(options) {
4547
4558
  get key() {
4548
4559
  return own(hovered) ? hovered.keys[0] : void 0;
4549
4560
  },
4561
+ get standing() {
4562
+ return hovered?.standing;
4563
+ },
4550
4564
  get ringKey() {
4551
4565
  return ringKey;
4552
4566
  },
4553
4567
  link: {
4554
- targets: () => options.order().map((key) => ({
4555
- key,
4556
- marks: onScreen(marksOf(key)).map(({ input }) => input)
4557
- })),
4568
+ targets: () => options.order().map((key) => {
4569
+ const marks = onScreen(marksOf(key)).map(({ input }) => input);
4570
+ return {
4571
+ key,
4572
+ marks: marks.length > 0 ? marks : standIns([key])
4573
+ };
4574
+ }),
4558
4575
  hover(keys, effects) {
4559
4576
  if (hovered !== void 0) endHover();
4560
4577
  const live = keys.filter(options.live);
@@ -4590,9 +4607,12 @@ function chartHover(options) {
4590
4607
  }
4591
4608
  const { source, marks: before, effects } = hovered;
4592
4609
  const now = onScreen(marksFor(keys));
4610
+ const standing = standingFor(keys, source, now);
4611
+ if (standing !== hovered.standing) options.stand?.(standing);
4593
4612
  hovered = {
4594
4613
  ...hovered,
4595
- keys
4614
+ keys,
4615
+ standing
4596
4616
  };
4597
4617
  if (now.length === before.length && now.every((mark, i) => mark.key === before[i])) return;
4598
4618
  const had = new Set(before);
@@ -4774,6 +4794,10 @@ function tableModel(input) {
4774
4794
  text: "",
4775
4795
  numeric: false
4776
4796
  });
4797
+ const missing = {
4798
+ text: input.missing ?? "missing",
4799
+ numeric: true
4800
+ };
4777
4801
  const headers = [
4778
4802
  {
4779
4803
  text: options.category ?? input.category ?? "Category",
@@ -4804,10 +4828,7 @@ function tableModel(input) {
4804
4828
  numeric: false
4805
4829
  },
4806
4830
  ...first.map((column) => columnCell(column, row, format)),
4807
- ...input.series.map((series) => row.missing?.has(series) ? {
4808
- text: MISSING,
4809
- numeric: true
4810
- } : number(values.get(series) ?? 0)),
4831
+ ...input.series.map((series) => row.missing?.has(series) ? missing : number(values.get(series) ?? 0)),
4811
4832
  ...totals ? [number(row.total)] : [],
4812
4833
  ...share(row.total),
4813
4834
  ...last.map((column) => columnCell(column, row, format))
@@ -5176,6 +5197,41 @@ function watchFonts(doc, loaded) {
5176
5197
  fonts?.addEventListener?.("loadingdone", loaded);
5177
5198
  return () => fonts?.removeEventListener?.("loadingdone", loaded);
5178
5199
  }
5200
+ const PROBE_TEXT = "Hamburgefonstiv 0123456789";
5201
+ function watchText(svg, clock, changed) {
5202
+ if (typeof ResizeObserver !== "function") return () => {};
5203
+ const probe = svgElement("text", {
5204
+ "font-size": 11,
5205
+ visibility: "hidden",
5206
+ "pointer-events": "none",
5207
+ "aria-hidden": "true"
5208
+ }, svg);
5209
+ probe.textContent = PROBE_TEXT;
5210
+ let measured = 0;
5211
+ let pending = 0;
5212
+ let stopFrame;
5213
+ const observer = new ResizeObserver((entries) => {
5214
+ const next = entries.find((entry) => entry.target === probe)?.contentRect.width ?? 0;
5215
+ if (!(next > 0) || Math.abs(next - pending) < .5) return;
5216
+ pending = next;
5217
+ if (!measured) {
5218
+ measured = next;
5219
+ return;
5220
+ }
5221
+ stopFrame ?? (stopFrame = clock.onFrame(() => {
5222
+ stopFrame?.();
5223
+ stopFrame = void 0;
5224
+ if (Math.abs(pending - measured) < .5) return;
5225
+ measured = pending;
5226
+ changed();
5227
+ }));
5228
+ });
5229
+ observer.observe(probe);
5230
+ return () => {
5231
+ observer.disconnect();
5232
+ stopFrame?.();
5233
+ };
5234
+ }
5179
5235
  function watchHoverDuration(svg, motion) {
5180
5236
  const sync = () => svg.style.setProperty("--ec-hover-duration", `${motion.duration(100, "feedback")}ms`);
5181
5237
  sync();
@@ -5656,6 +5712,10 @@ function barChart$1(target, options, env) {
5656
5712
  series: row.values.map((v) => v.series),
5657
5713
  slot: animated(row.slot, interpolateNumber, env),
5658
5714
  presence: animated(entering ? 0 : 1, interpolateNumber, env),
5715
+ drawn: {
5716
+ label: animated(Number(row.drawn.label), interpolateNumber, env),
5717
+ value: animated(Number(row.drawn.value), interpolateNumber, env)
5718
+ },
5659
5719
  count: void 0,
5660
5720
  leave: void 0
5661
5721
  };
@@ -5664,15 +5724,17 @@ function barChart$1(target, options, env) {
5664
5724
  return record;
5665
5725
  }
5666
5726
  function drawMark(record, row) {
5667
- const before = record.parts[0]?.colors.color;
5727
+ const before = record.parts;
5668
5728
  record.shown = row;
5669
5729
  setAttributes(record.hit, { ...row.hit });
5670
5730
  placeText(record.label, row.label);
5671
5731
  placeText(record.value, row.value);
5672
- const presence = record.presence.value;
5673
- const opacity = presence < 1 ? presence : void 0;
5674
- setAttributes(record.label, { opacity });
5675
- setAttributes(record.value, { opacity });
5732
+ const opacity = (drawn, fade) => {
5733
+ const shown = record.presence.value * (drawn ? fade.value : 1);
5734
+ return shown < 1 ? shown : void 0;
5735
+ };
5736
+ setAttributes(record.label, { opacity: opacity(row.drawn.label, record.drawn.label) });
5737
+ setAttributes(record.value, { opacity: opacity(row.drawn.value, record.drawn.value) });
5676
5738
  const segments = row.geometry.segments ?? [];
5677
5739
  const keep = /* @__PURE__ */ new Set();
5678
5740
  const ownColors = byCategory(current) ? seriesColors(colors.slot(record.key)) : void 0;
@@ -5705,7 +5767,7 @@ function barChart$1(target, options, env) {
5705
5767
  const drawn = Array.from(record.body.children).filter((child) => child.classList.contains("ec-segment"));
5706
5768
  if (record.parts.some((part, i) => drawn[i] !== part.element)) for (const part of record.parts) record.body.appendChild(part.element);
5707
5769
  record.handle.repaint();
5708
- if (record.parts[0]?.colors.color !== before) surface.recolor(record.key);
5770
+ if (record.parts.length !== before.length || record.parts.some((part, i) => part.colors.color !== before[i].colors.color)) surface.recolor(record.key);
5709
5771
  if (record.key === hover.ringKey) drawRing(record.key);
5710
5772
  }
5711
5773
  function drawRing(key) {
@@ -5812,6 +5874,10 @@ function barChart$1(target, options, env) {
5812
5874
  }));
5813
5875
  const total = values.reduce((sum, v) => sum + v.value, 0);
5814
5876
  const text = record.count === void 0 ? row.value.text : format(current)(round$5(total, record.count));
5877
+ const drawn = {
5878
+ label: record.drawn.label.value > 0,
5879
+ value: record.drawn.value.value > 0
5880
+ };
5815
5881
  return placeRow(frame, {
5816
5882
  key: row.key,
5817
5883
  datum: row.datum,
@@ -5820,7 +5886,7 @@ function barChart$1(target, options, env) {
5820
5886
  values,
5821
5887
  slot: record.slot.value,
5822
5888
  text,
5823
- drawn: row.drawn
5889
+ drawn
5824
5890
  }, measure);
5825
5891
  }
5826
5892
  function addTick(value, opacity) {
@@ -5942,8 +6008,11 @@ function barChart$1(target, options, env) {
5942
6008
  let first;
5943
6009
  let second;
5944
6010
  let grow;
6011
+ let out;
6012
+ let into;
5945
6013
  if (!jump && motion.staged) {
5946
6014
  const wait = values ? STAGE$2 : 0;
6015
+ const half = values && positions ? STAGE$2 : STAGE$2 / 2;
5947
6016
  first = { duration: STAGE$2 };
5948
6017
  second = {
5949
6018
  duration: STAGE$2,
@@ -5953,6 +6022,11 @@ function barChart$1(target, options, env) {
5953
6022
  duration: STAGE$2 / 2,
5954
6023
  delay: wait + STAGE$2 / 2
5955
6024
  };
6025
+ out = { duration: half };
6026
+ into = {
6027
+ duration: half,
6028
+ delay: half
6029
+ };
5956
6030
  } else if (!jump) first = second = grow = { duration: (values && positions ? 2 : 1) * STAGE$2 };
5957
6031
  const running = [];
5958
6032
  const move = (value, to, equal, timing) => {
@@ -5963,6 +6037,13 @@ function barChart$1(target, options, env) {
5963
6037
  move(scale, frame.scale, sameFields, first);
5964
6038
  move(bands, frame.bands, sameFields, second);
5965
6039
  for (const tick of ticks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, first);
6040
+ for (const record of order) {
6041
+ const fades = !arriving.has(record);
6042
+ for (const part of ["label", "value"]) {
6043
+ const to = Number(record.row.drawn[part]);
6044
+ move(record.drawn[part], to, same, fades ? to ? into : out : void 0);
6045
+ }
6046
+ }
5966
6047
  for (const record of staying) {
5967
6048
  move(record.values, valuesOf(record.row), sameFields, first);
5968
6049
  move(record.presence, 1, same, first);
@@ -6037,14 +6118,16 @@ function barChart$1(target, options, env) {
6037
6118
  for (const record of order) record.row = rows.get(record.key) ?? record.row;
6038
6119
  transitionTo(next, true);
6039
6120
  }
6121
+ const remeasure = () => {
6122
+ measure.clear();
6123
+ relayout();
6124
+ };
6125
+ const unwatchText = watchText(svg, clock, remeasure);
6040
6126
  const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
6041
6127
  measuredWidth = width;
6042
6128
  if (current.width === void 0) relayout();
6043
6129
  });
6044
- const unwatchFonts = watchFonts(doc, () => {
6045
- measure.clear();
6046
- relayout();
6047
- });
6130
+ const unwatchFonts = watchFonts(doc, remeasure);
6048
6131
  describeChart(svg, current);
6049
6132
  syncLegend(laidOut);
6050
6133
  table.render(firstTable);
@@ -6103,7 +6186,7 @@ function barChart$1(target, options, env) {
6103
6186
  }, () => arrange(nextLayout), (diff) => {
6104
6187
  if (announcing) announceChange(previous, diff);
6105
6188
  });
6106
- if (byCategory(current) !== byCategory(previous)) for (const record of [...order, ...leaving.values()]) dirty.add(record);
6189
+ if ("colors" in next || byCategory(current) !== byCategory(previous)) for (const record of [...order, ...leaving.values()]) dirty.add(record);
6107
6190
  const settled = transitionTo(nextLayout, motion.mode === "off" || nextLayout.orientation !== orientation);
6108
6191
  await transitions.wait(settled, leaves);
6109
6192
  },
@@ -6136,13 +6219,16 @@ function barChart$1(target, options, env) {
6136
6219
  table.destroy();
6137
6220
  announcer?.destroy();
6138
6221
  unwatchHoverDuration();
6222
+ unwatchText();
6139
6223
  unwatchWidth();
6140
6224
  unwatchFonts();
6141
6225
  for (const record of [...order, ...leaving.values()]) {
6142
6226
  for (const value of [
6143
6227
  record.values,
6144
6228
  record.slot,
6145
- record.presence
6229
+ record.presence,
6230
+ record.drawn.label,
6231
+ record.drawn.value
6146
6232
  ]) value.stop();
6147
6233
  record.leave?.resolve();
6148
6234
  }
@@ -7001,14 +7087,16 @@ function donutChart$1(target, options, env) {
7001
7087
  for (const record of order) record.row = slices.get(record.key) ?? record.row;
7002
7088
  transitionTo(next, true);
7003
7089
  }
7090
+ const remeasure = () => {
7091
+ measure.clear();
7092
+ relayout();
7093
+ };
7094
+ const unwatchText = watchText(svg, clock, remeasure);
7004
7095
  const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
7005
7096
  measuredWidth = width;
7006
7097
  if (current.width === void 0) relayout();
7007
7098
  });
7008
- const unwatchFonts = watchFonts(doc, () => {
7009
- measure.clear();
7010
- relayout();
7011
- });
7099
+ const unwatchFonts = watchFonts(doc, remeasure);
7012
7100
  describeDonut();
7013
7101
  syncLegend();
7014
7102
  table.render(firstTable);
@@ -7101,6 +7189,7 @@ function donutChart$1(target, options, env) {
7101
7189
  table.destroy();
7102
7190
  announcer?.destroy();
7103
7191
  unwatchHoverDuration();
7192
+ unwatchText();
7104
7193
  unwatchWidth();
7105
7194
  unwatchFonts();
7106
7195
  for (const record of [...order, ...leaving.values()]) {
@@ -7357,7 +7446,6 @@ function cubic(v0, c1, c2, v1, u) {
7357
7446
  return s * s * s * v0 + 3 * s * s * u * c1 + 3 * s * u * u * c2 + u * u * u * v1;
7358
7447
  }
7359
7448
  // src/charts/time.ts
7360
- const TIME_ZONES = ["UTC", "local"];
7361
7449
  const SECOND = 1e3;
7362
7450
  const MINUTE = 60 * SECOND;
7363
7451
  const HOUR = 60 * MINUTE;
@@ -7465,6 +7553,16 @@ const FIELDS = {
7465
7553
  fractionalSecondDigits: 3
7466
7554
  }
7467
7555
  };
7556
+ function isTimeZone(zone) {
7557
+ if (zone === "UTC" || zone === "local") return true;
7558
+ if (typeof zone !== "string") return false;
7559
+ try {
7560
+ clockOf(zone);
7561
+ return true;
7562
+ } catch {
7563
+ return false;
7564
+ }
7565
+ }
7468
7566
  function timeStep(span) {
7469
7567
  for (const step of STEPS) if (LONGEST$1[step.unit] * step.count >= span) return step;
7470
7568
  return {
@@ -7534,15 +7632,7 @@ function monthsOn(t, months, zone) {
7534
7632
  const last = /* @__PURE__ */ new Date(0);
7535
7633
  last.setUTCFullYear(year, month + months + 1, 0);
7536
7634
  const day = Math.min(date, last.getUTCDate());
7537
- const d = /* @__PURE__ */ new Date(0);
7538
- if (zone === "UTC") {
7539
- d.setUTCFullYear(year, month + months, day);
7540
- d.setUTCHours(hours, minutes, seconds, ms);
7541
- } else {
7542
- d.setFullYear(year, month + months, day);
7543
- d.setHours(hours, minutes, seconds, ms);
7544
- }
7545
- return d.getTime();
7635
+ return timeAt(zone, year, month + months, day, hours, minutes, seconds, ms);
7546
7636
  }
7547
7637
  function timeLevel(t, zone) {
7548
7638
  const { ms, seconds, minutes, hours, date, month } = partsOf(t, zone);
@@ -7554,7 +7644,8 @@ function timeLevel(t, zone) {
7554
7644
  return month !== 0 ? "month" : "year";
7555
7645
  }
7556
7646
  function timeName(times, zone) {
7557
- const finest = times.reduce((max, t) => Math.max(max, LEVELS.indexOf(timeLevel(t, zone))), 0);
7647
+ const shown = clockReader(zone);
7648
+ const finest = times.reduce((max, t) => Math.max(max, LEVELS.indexOf(timeLevel(shown(t), "UTC"))), 0);
7558
7649
  const timeZone = zoneOption(zone);
7559
7650
  const timeStyle = finest >= LEVELS.indexOf("second") ? "medium" : finest >= LEVELS.indexOf("hour") ? "short" : void 0;
7560
7651
  const options = finest === LEVELS.indexOf("millisecond") ? {
@@ -7568,7 +7659,17 @@ function timeName(times, zone) {
7568
7659
  timeZone
7569
7660
  };
7570
7661
  const format = new Intl.DateTimeFormat(void 0, options);
7571
- return (t) => format.format(t);
7662
+ if (zone === "UTC" || !timeStyle) return (t) => format.format(t);
7663
+ const named = new Intl.DateTimeFormat(void 0, {
7664
+ timeZone,
7665
+ timeZoneName: "short"
7666
+ });
7667
+ return (t) => {
7668
+ const text = format.format(t);
7669
+ if (twinOf(t, shown) === void 0) return text;
7670
+ const name = named.formatToParts(t).find((part) => part.type === "timeZoneName")?.value;
7671
+ return name ? `${text} ${name}` : text;
7672
+ };
7572
7673
  }
7573
7674
  function tickWording(zone) {
7574
7675
  const formats = /* @__PURE__ */ new Map();
@@ -7585,19 +7686,10 @@ function tickWording(zone) {
7585
7686
  return format.format(t);
7586
7687
  };
7587
7688
  }
7588
- const zoneOption = (zone) => zone === "UTC" ? "UTC" : void 0;
7689
+ const zoneOption = (zone) => zone === "local" ? void 0 : zone;
7589
7690
  function partsOf(t, zone) {
7590
- const d = new Date(t);
7591
- return zone === "UTC" ? {
7592
- year: d.getUTCFullYear(),
7593
- month: d.getUTCMonth(),
7594
- date: d.getUTCDate(),
7595
- weekday: d.getUTCDay(),
7596
- hours: d.getUTCHours(),
7597
- minutes: d.getUTCMinutes(),
7598
- seconds: d.getUTCSeconds(),
7599
- ms: d.getUTCMilliseconds()
7600
- } : {
7691
+ const d = new Date(zone === "UTC" || zone === "local" ? t : shownAt(t, zone));
7692
+ return zone === "local" ? {
7601
7693
  year: d.getFullYear(),
7602
7694
  month: d.getMonth(),
7603
7695
  date: d.getDate(),
@@ -7606,19 +7698,88 @@ function partsOf(t, zone) {
7606
7698
  minutes: d.getMinutes(),
7607
7699
  seconds: d.getSeconds(),
7608
7700
  ms: d.getMilliseconds()
7701
+ } : {
7702
+ year: d.getUTCFullYear(),
7703
+ month: d.getUTCMonth(),
7704
+ date: d.getUTCDate(),
7705
+ weekday: d.getUTCDay(),
7706
+ hours: d.getUTCHours(),
7707
+ minutes: d.getUTCMinutes(),
7708
+ seconds: d.getUTCSeconds(),
7709
+ ms: d.getUTCMilliseconds()
7609
7710
  };
7610
7711
  }
7611
7712
  function midnight(zone, year, month, date) {
7612
- const d = /* @__PURE__ */ new Date(0);
7613
- if (zone === "UTC") {
7614
- d.setUTCFullYear(year, month, date);
7615
- d.setUTCHours(0, 0, 0, 0);
7616
- } else {
7713
+ return timeAt(zone, year, month, date);
7714
+ }
7715
+ function timeAt(zone, year, month, date, hours = 0, minutes = 0, seconds = 0, ms = 0) {
7716
+ if (zone === "local") {
7717
+ const d = /* @__PURE__ */ new Date(0);
7617
7718
  d.setFullYear(year, month, date);
7618
- d.setHours(0, 0, 0, 0);
7719
+ d.setHours(hours, minutes, seconds, ms);
7720
+ return d.getTime();
7619
7721
  }
7722
+ const shown = utc(year, month, date, hours, minutes, seconds, ms);
7723
+ if (zone === "UTC") return shown;
7724
+ const before = shown - (shownAt(shown - DAY, zone) - (shown - DAY));
7725
+ const after = shown - (shownAt(shown + DAY, zone) - (shown + DAY));
7726
+ if (before === after) return before;
7727
+ const fits = [before, after].filter((t) => shownAt(t, zone) === shown);
7728
+ return fits.length > 0 ? Math.min(...fits) : before;
7729
+ }
7730
+ function utc(year, month, date, hours = 0, minutes = 0, seconds = 0, ms = 0) {
7731
+ const d = /* @__PURE__ */ new Date(0);
7732
+ d.setUTCFullYear(year, month, date);
7733
+ d.setUTCHours(hours, minutes, seconds, ms);
7620
7734
  return d.getTime();
7621
7735
  }
7736
+ function shownAt(t, zone) {
7737
+ if (zone === "UTC") return t;
7738
+ if (zone === "local") {
7739
+ const d = new Date(t);
7740
+ return utc(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
7741
+ }
7742
+ const ms = (t % SECOND + SECOND) % SECOND;
7743
+ const fields = {};
7744
+ for (const part of clockOf(zone).formatToParts(t - ms)) fields[part.type] = part.value;
7745
+ const year = Number(fields["year"]);
7746
+ 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);
7747
+ }
7748
+ function clockReader(zone) {
7749
+ if (zone === "UTC" || zone === "local") return (t) => shownAt(t, zone);
7750
+ const kept = /* @__PURE__ */ new Map();
7751
+ return (t) => {
7752
+ let shown = kept.get(t);
7753
+ if (shown === void 0) kept.set(t, shown = shownAt(t, zone));
7754
+ return shown;
7755
+ };
7756
+ }
7757
+ function twinOf(t, shown) {
7758
+ const at = shown(t);
7759
+ for (const near of [t - DAY, t + DAY]) {
7760
+ const other = at - (shown(near) - near);
7761
+ if (other !== t && shown(other) === at) return other;
7762
+ }
7763
+ }
7764
+ const clocks = /* @__PURE__ */ new Map();
7765
+ function clockOf(zone) {
7766
+ let clock = clocks.get(zone);
7767
+ if (!clock) {
7768
+ clock = new Intl.DateTimeFormat("en-US", {
7769
+ timeZone: zone,
7770
+ hourCycle: "h23",
7771
+ era: "short",
7772
+ year: "numeric",
7773
+ month: "numeric",
7774
+ day: "numeric",
7775
+ hour: "numeric",
7776
+ minute: "numeric",
7777
+ second: "numeric"
7778
+ });
7779
+ clocks.set(zone, clock);
7780
+ }
7781
+ return clock;
7782
+ }
7622
7783
  // src/charts/line-layout.ts
7623
7784
  const LINE_WIDTH = 2.25;
7624
7785
  const DOT_RADIUS = 4.5;
@@ -7646,7 +7807,7 @@ function lineEncoding(options) {
7646
7807
  const labels = options.labels;
7647
7808
  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.");
7648
7809
  const timeZone = options.timeZone ?? "UTC";
7649
- if (!TIME_ZONES.includes(timeZone)) throw new TypeError(`lineChart: timeZone must be "UTC" or "local", got ${show$1(timeZone)}.`);
7810
+ 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)}.`);
7650
7811
  const xFormat = options.xFormat;
7651
7812
  if (xFormat !== void 0 && typeof xFormat !== "function") throw new TypeError("lineChart: xFormat must be a function that turns an x into text.");
7652
7813
  const curve = options.curve ?? "linear";
@@ -8143,6 +8304,7 @@ function lineChart$1(target, options, env) {
8143
8304
  const container = resolveTarget$2(target, "lineChart");
8144
8305
  checkChartOptions(options, "lineChart");
8145
8306
  let hoverKind = hoverOf(options);
8307
+ missingOf(options);
8146
8308
  let current = options;
8147
8309
  const motion = chartMotion(options.motion, env.motion);
8148
8310
  let effects = resolveEffects(options.on, env.presets);
@@ -8172,17 +8334,19 @@ function lineChart$1(target, options, env) {
8172
8334
  "aria-hidden": "true",
8173
8335
  visibility: "hidden"
8174
8336
  }, svg);
8175
- const marksLayer = svgElement("g", {
8337
+ const linesLayer = svgElement("g", { class: "ec-lines" }, svgElement("g", {
8176
8338
  class: "ec-marks",
8177
8339
  "aria-hidden": "true"
8178
- }, svg);
8179
- const linesLayer = svgElement("g", { class: "ec-lines" }, marksLayer);
8180
- const pointsLayer = svgElement("g", { class: "ec-points" }, marksLayer);
8181
- const columnsLayer = svgElement("g", { class: "ec-columns" }, svg);
8340
+ }, svg));
8182
8341
  const overlay = svgElement("g", {
8183
8342
  class: "ec-overlay",
8184
8343
  "aria-hidden": "true"
8185
8344
  }, svg);
8345
+ const pointsLayer = svgElement("g", { class: "ec-points" }, svgElement("g", {
8346
+ class: "ec-marks",
8347
+ "aria-hidden": "true"
8348
+ }, svg));
8349
+ const columnsLayer = svgElement("g", { class: "ec-columns" }, svg);
8186
8350
  const measure = textMeasure(svg);
8187
8351
  let rowOrder = [];
8188
8352
  const rows = /* @__PURE__ */ new Map();
@@ -8720,6 +8884,14 @@ function lineChart$1(target, options, env) {
8720
8884
  crosshair.setAttribute("visibility", "hidden");
8721
8885
  tooltip.hide();
8722
8886
  }
8887
+ function stand(key) {
8888
+ const record = key === void 0 ? void 0 : rows.get(key);
8889
+ if (!record || !revealed(record)) crosshair.setAttribute("visibility", "hidden");
8890
+ else setAttributes(crosshair, {
8891
+ ...placeCrosshair(drawnFrame, record.px),
8892
+ visibility: void 0
8893
+ });
8894
+ }
8723
8895
  let ringLine;
8724
8896
  function drawRing(key) {
8725
8897
  const point = key === void 0 ? void 0 : points.get(key);
@@ -8759,6 +8931,7 @@ function lineChart$1(target, options, env) {
8759
8931
  }
8760
8932
  function followHover() {
8761
8933
  if (hover.key !== void 0) showHover(hover.key);
8934
+ if (hover.standing !== void 0) stand(hover.standing);
8762
8935
  if (hover.ringKey !== void 0) drawRing(hover.ringKey);
8763
8936
  }
8764
8937
  const input = (record) => ({
@@ -8769,6 +8942,28 @@ function lineChart$1(target, options, env) {
8769
8942
  mark: record.shown.geometry,
8770
8943
  data: record.shown.data
8771
8944
  });
8945
+ function standIn(key) {
8946
+ const record = rows.get(key);
8947
+ if (!record || !revealed(record)) return void 0;
8948
+ const { row } = record;
8949
+ return {
8950
+ mark: describePoint({
8951
+ key,
8952
+ x: record.px,
8953
+ y: drawnFrame.box.top,
8954
+ r: DOT_RADIUS
8955
+ }),
8956
+ data: {
8957
+ datum: row.datum,
8958
+ samples: [{
8959
+ t: 0,
8960
+ value: NaN,
8961
+ at: laidOut.time ? new Date(row.x) : row.x
8962
+ }],
8963
+ related: () => void 0
8964
+ }
8965
+ };
8966
+ }
8772
8967
  function liveRowOf(eventTarget) {
8773
8968
  const element = eventTarget;
8774
8969
  const column = typeof element?.closest === "function" ? element.closest(".ec-column") : null;
@@ -8864,7 +9059,7 @@ function lineChart$1(target, options, env) {
8864
9059
  if (hoverKind !== "point") return;
8865
9060
  if (!stopsLayer) {
8866
9061
  stopsLayer = svgElement("g", { class: "ec-stops" }, svg);
8867
- svg.insertBefore(stopsLayer, overlay);
9062
+ svg.insertBefore(stopsLayer, columnsLayer.nextSibling);
8868
9063
  plotHit = svgElement("rect", { class: "ec-hit" }, stopsLayer);
8869
9064
  stopsLayer.addEventListener("click", (event) => {
8870
9065
  const point = pointAt(event.clientX, event.clientY);
@@ -9036,6 +9231,8 @@ function lineChart$1(target, options, env) {
9036
9231
  const record = findMark(key);
9037
9232
  return record && onScreen(record);
9038
9233
  },
9234
+ standIn,
9235
+ stand,
9039
9236
  ring: drawRing,
9040
9237
  tooltip: {
9041
9238
  show: showHover,
@@ -9064,7 +9261,8 @@ function lineChart$1(target, options, env) {
9064
9261
  total: total(row.values)
9065
9262
  })),
9066
9263
  format: format(opts),
9067
- total: false
9264
+ total: false,
9265
+ missing: missingOf(opts)
9068
9266
  });
9069
9267
  }
9070
9268
  function labelColumn(record) {
@@ -9303,14 +9501,16 @@ function lineChart$1(target, options, env) {
9303
9501
  for (const point of points.values()) point.target = placed.points.get(point.key) ?? point.target;
9304
9502
  transitionTo(next, true);
9305
9503
  }
9504
+ const remeasure = () => {
9505
+ measure.clear();
9506
+ relayout();
9507
+ };
9508
+ const unwatchText = watchText(svg, clock, remeasure);
9306
9509
  const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
9307
9510
  measuredWidth = width;
9308
9511
  if (current.width === void 0) relayout();
9309
9512
  });
9310
- const unwatchFonts = watchFonts(doc, () => {
9311
- measure.clear();
9312
- relayout();
9313
- });
9513
+ const unwatchFonts = watchFonts(doc, remeasure);
9314
9514
  describeChart(svg, current);
9315
9515
  syncLegend();
9316
9516
  table.render(firstTable);
@@ -9354,6 +9554,7 @@ function lineChart$1(target, options, env) {
9354
9554
  };
9355
9555
  checkChartOptions(merged, "lineChart");
9356
9556
  const kind = hoverOf(merged);
9557
+ missingOf(merged);
9357
9558
  const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
9358
9559
  const nextLayout = layout(merged, swapped);
9359
9560
  const nextTable = tableFor(merged, nextLayout);
@@ -9457,6 +9658,7 @@ function lineChart$1(target, options, env) {
9457
9658
  table.destroy();
9458
9659
  announcer?.destroy();
9459
9660
  unwatchHoverDuration();
9661
+ unwatchText();
9460
9662
  unwatchWidth();
9461
9663
  unwatchFonts();
9462
9664
  for (const record of [...rowOrder, ...leavingRows.values()]) for (const value of [
@@ -9559,9 +9761,10 @@ function labelled(values, options) {
9559
9761
  }
9560
9762
  function said(values, options) {
9561
9763
  const formatted = format(options);
9764
+ const missing = missingOf(options);
9562
9765
  return values.map((v) => {
9563
9766
  const label = seriesLabel(options.seriesLabels, v.series);
9564
- return v.value === void 0 ? `${label} missing` : `${formatted(v.value)} ${label}`;
9767
+ return v.value === void 0 ? `${label} ${missing}` : `${formatted(v.value)} ${label}`;
9565
9768
  });
9566
9769
  }
9567
9770
  function summary(row, options) {
@@ -9618,6 +9821,11 @@ function hoverOf(options) {
9618
9821
  if (hover !== "x" && hover !== "point") throw new TypeError(`lineChart: hover must be "x" or "point", got ${typeof hover === "string" ? JSON.stringify(hover) : String(hover)}.`);
9619
9822
  return hover;
9620
9823
  }
9824
+ function missingOf(options) {
9825
+ const { missing = MISSING } = options;
9826
+ 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)}.`);
9827
+ return missing;
9828
+ }
9621
9829
  // src/core/geometry/ring.ts
9622
9830
  const ROUND = .5;
9623
9831
  function goesRound(mark) {
@@ -10823,7 +11031,7 @@ function expressive$1(target, options, env) {
10823
11031
  from: from.geometry
10824
11032
  });
10825
11033
  else if (newRow || geometryChanged(from.geometry, mark.geometry) || samplesChanged(from.data.samples, mark.data.samples)) diff.moved.push(record);
10826
- if (from.parts[0]?.colors?.color !== mark.parts[0]?.colors?.color) recolor.push(mark.key);
11034
+ if (from.parts.length !== mark.parts.length || mark.parts.some((part, i) => part.colors?.color !== from.parts[i].colors?.color)) recolor.push(mark.key);
10827
11035
  record.mark = mark;
10828
11036
  } else {
10829
11037
  record = leaving.get(mark.key);
@@ -14836,7 +15044,7 @@ function configure(options) {
14836
15044
  }
14837
15045
  }
14838
15046
  // src/index.ts
14839
- const VERSION = "0.7.0";
15047
+ const VERSION = "0.8.0";
14840
15048
  const env = {
14841
15049
  presets: presetRegistry,
14842
15050
  icons: iconRegistry,