expressive-charts 0.7.0 → 0.9.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,42 @@ 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
+ probe.remove();
5234
+ };
5235
+ }
5179
5236
  function watchHoverDuration(svg, motion) {
5180
5237
  const sync = () => svg.style.setProperty("--ec-hover-duration", `${motion.duration(100, "feedback")}ms`);
5181
5238
  sync();
@@ -5656,6 +5713,10 @@ function barChart$1(target, options, env) {
5656
5713
  series: row.values.map((v) => v.series),
5657
5714
  slot: animated(row.slot, interpolateNumber, env),
5658
5715
  presence: animated(entering ? 0 : 1, interpolateNumber, env),
5716
+ drawn: {
5717
+ label: animated(Number(row.drawn.label), interpolateNumber, env),
5718
+ value: animated(Number(row.drawn.value), interpolateNumber, env)
5719
+ },
5659
5720
  count: void 0,
5660
5721
  leave: void 0
5661
5722
  };
@@ -5664,15 +5725,17 @@ function barChart$1(target, options, env) {
5664
5725
  return record;
5665
5726
  }
5666
5727
  function drawMark(record, row) {
5667
- const before = record.parts[0]?.colors.color;
5728
+ const before = record.parts;
5668
5729
  record.shown = row;
5669
5730
  setAttributes(record.hit, { ...row.hit });
5670
5731
  placeText(record.label, row.label);
5671
5732
  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 });
5733
+ const opacity = (drawn, fade) => {
5734
+ const shown = record.presence.value * (drawn ? fade.value : 1);
5735
+ return shown < 1 ? shown : void 0;
5736
+ };
5737
+ setAttributes(record.label, { opacity: opacity(row.drawn.label, record.drawn.label) });
5738
+ setAttributes(record.value, { opacity: opacity(row.drawn.value, record.drawn.value) });
5676
5739
  const segments = row.geometry.segments ?? [];
5677
5740
  const keep = /* @__PURE__ */ new Set();
5678
5741
  const ownColors = byCategory(current) ? seriesColors(colors.slot(record.key)) : void 0;
@@ -5705,7 +5768,7 @@ function barChart$1(target, options, env) {
5705
5768
  const drawn = Array.from(record.body.children).filter((child) => child.classList.contains("ec-segment"));
5706
5769
  if (record.parts.some((part, i) => drawn[i] !== part.element)) for (const part of record.parts) record.body.appendChild(part.element);
5707
5770
  record.handle.repaint();
5708
- if (record.parts[0]?.colors.color !== before) surface.recolor(record.key);
5771
+ if (record.parts.length !== before.length || record.parts.some((part, i) => part.colors.color !== before[i].colors.color)) surface.recolor(record.key);
5709
5772
  if (record.key === hover.ringKey) drawRing(record.key);
5710
5773
  }
5711
5774
  function drawRing(key) {
@@ -5812,6 +5875,10 @@ function barChart$1(target, options, env) {
5812
5875
  }));
5813
5876
  const total = values.reduce((sum, v) => sum + v.value, 0);
5814
5877
  const text = record.count === void 0 ? row.value.text : format(current)(round$5(total, record.count));
5878
+ const drawn = {
5879
+ label: record.drawn.label.value > 0,
5880
+ value: record.drawn.value.value > 0
5881
+ };
5815
5882
  return placeRow(frame, {
5816
5883
  key: row.key,
5817
5884
  datum: row.datum,
@@ -5820,7 +5887,7 @@ function barChart$1(target, options, env) {
5820
5887
  values,
5821
5888
  slot: record.slot.value,
5822
5889
  text,
5823
- drawn: row.drawn
5890
+ drawn
5824
5891
  }, measure);
5825
5892
  }
5826
5893
  function addTick(value, opacity) {
@@ -5942,8 +6009,11 @@ function barChart$1(target, options, env) {
5942
6009
  let first;
5943
6010
  let second;
5944
6011
  let grow;
6012
+ let out;
6013
+ let into;
5945
6014
  if (!jump && motion.staged) {
5946
6015
  const wait = values ? STAGE$2 : 0;
6016
+ const half = values && positions ? STAGE$2 : STAGE$2 / 2;
5947
6017
  first = { duration: STAGE$2 };
5948
6018
  second = {
5949
6019
  duration: STAGE$2,
@@ -5953,6 +6023,11 @@ function barChart$1(target, options, env) {
5953
6023
  duration: STAGE$2 / 2,
5954
6024
  delay: wait + STAGE$2 / 2
5955
6025
  };
6026
+ out = { duration: half };
6027
+ into = {
6028
+ duration: half,
6029
+ delay: half
6030
+ };
5956
6031
  } else if (!jump) first = second = grow = { duration: (values && positions ? 2 : 1) * STAGE$2 };
5957
6032
  const running = [];
5958
6033
  const move = (value, to, equal, timing) => {
@@ -5963,6 +6038,13 @@ function barChart$1(target, options, env) {
5963
6038
  move(scale, frame.scale, sameFields, first);
5964
6039
  move(bands, frame.bands, sameFields, second);
5965
6040
  for (const tick of ticks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, first);
6041
+ for (const record of order) {
6042
+ const fades = !arriving.has(record);
6043
+ for (const part of ["label", "value"]) {
6044
+ const to = Number(record.row.drawn[part]);
6045
+ move(record.drawn[part], to, same, fades ? to ? into : out : void 0);
6046
+ }
6047
+ }
5966
6048
  for (const record of staying) {
5967
6049
  move(record.values, valuesOf(record.row), sameFields, first);
5968
6050
  move(record.presence, 1, same, first);
@@ -6037,14 +6119,16 @@ function barChart$1(target, options, env) {
6037
6119
  for (const record of order) record.row = rows.get(record.key) ?? record.row;
6038
6120
  transitionTo(next, true);
6039
6121
  }
6122
+ const remeasure = () => {
6123
+ measure.clear();
6124
+ relayout();
6125
+ };
6126
+ const unwatchText = watchText(svg, clock, remeasure);
6040
6127
  const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
6041
6128
  measuredWidth = width;
6042
6129
  if (current.width === void 0) relayout();
6043
6130
  });
6044
- const unwatchFonts = watchFonts(doc, () => {
6045
- measure.clear();
6046
- relayout();
6047
- });
6131
+ const unwatchFonts = watchFonts(doc, remeasure);
6048
6132
  describeChart(svg, current);
6049
6133
  syncLegend(laidOut);
6050
6134
  table.render(firstTable);
@@ -6103,7 +6187,7 @@ function barChart$1(target, options, env) {
6103
6187
  }, () => arrange(nextLayout), (diff) => {
6104
6188
  if (announcing) announceChange(previous, diff);
6105
6189
  });
6106
- if (byCategory(current) !== byCategory(previous)) for (const record of [...order, ...leaving.values()]) dirty.add(record);
6190
+ if ("colors" in next || byCategory(current) !== byCategory(previous)) for (const record of [...order, ...leaving.values()]) dirty.add(record);
6107
6191
  const settled = transitionTo(nextLayout, motion.mode === "off" || nextLayout.orientation !== orientation);
6108
6192
  await transitions.wait(settled, leaves);
6109
6193
  },
@@ -6136,13 +6220,16 @@ function barChart$1(target, options, env) {
6136
6220
  table.destroy();
6137
6221
  announcer?.destroy();
6138
6222
  unwatchHoverDuration();
6223
+ unwatchText();
6139
6224
  unwatchWidth();
6140
6225
  unwatchFonts();
6141
6226
  for (const record of [...order, ...leaving.values()]) {
6142
6227
  for (const value of [
6143
6228
  record.values,
6144
6229
  record.slot,
6145
- record.presence
6230
+ record.presence,
6231
+ record.drawn.label,
6232
+ record.drawn.value
6146
6233
  ]) value.stop();
6147
6234
  record.leave?.resolve();
6148
6235
  }
@@ -7001,14 +7088,16 @@ function donutChart$1(target, options, env) {
7001
7088
  for (const record of order) record.row = slices.get(record.key) ?? record.row;
7002
7089
  transitionTo(next, true);
7003
7090
  }
7091
+ const remeasure = () => {
7092
+ measure.clear();
7093
+ relayout();
7094
+ };
7095
+ const unwatchText = watchText(svg, clock, remeasure);
7004
7096
  const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
7005
7097
  measuredWidth = width;
7006
7098
  if (current.width === void 0) relayout();
7007
7099
  });
7008
- const unwatchFonts = watchFonts(doc, () => {
7009
- measure.clear();
7010
- relayout();
7011
- });
7100
+ const unwatchFonts = watchFonts(doc, remeasure);
7012
7101
  describeDonut();
7013
7102
  syncLegend();
7014
7103
  table.render(firstTable);
@@ -7101,6 +7190,7 @@ function donutChart$1(target, options, env) {
7101
7190
  table.destroy();
7102
7191
  announcer?.destroy();
7103
7192
  unwatchHoverDuration();
7193
+ unwatchText();
7104
7194
  unwatchWidth();
7105
7195
  unwatchFonts();
7106
7196
  for (const record of [...order, ...leaving.values()]) {
@@ -7357,7 +7447,6 @@ function cubic(v0, c1, c2, v1, u) {
7357
7447
  return s * s * s * v0 + 3 * s * s * u * c1 + 3 * s * u * u * c2 + u * u * u * v1;
7358
7448
  }
7359
7449
  // src/charts/time.ts
7360
- const TIME_ZONES = ["UTC", "local"];
7361
7450
  const SECOND = 1e3;
7362
7451
  const MINUTE = 60 * SECOND;
7363
7452
  const HOUR = 60 * MINUTE;
@@ -7465,6 +7554,16 @@ const FIELDS = {
7465
7554
  fractionalSecondDigits: 3
7466
7555
  }
7467
7556
  };
7557
+ function isTimeZone(zone) {
7558
+ if (zone === "UTC" || zone === "local") return true;
7559
+ if (typeof zone !== "string") return false;
7560
+ try {
7561
+ clockOf(zone);
7562
+ return true;
7563
+ } catch {
7564
+ return false;
7565
+ }
7566
+ }
7468
7567
  function timeStep(span) {
7469
7568
  for (const step of STEPS) if (LONGEST$1[step.unit] * step.count >= span) return step;
7470
7569
  return {
@@ -7534,15 +7633,7 @@ function monthsOn(t, months, zone) {
7534
7633
  const last = /* @__PURE__ */ new Date(0);
7535
7634
  last.setUTCFullYear(year, month + months + 1, 0);
7536
7635
  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();
7636
+ return timeAt(zone, year, month + months, day, hours, minutes, seconds, ms);
7546
7637
  }
7547
7638
  function timeLevel(t, zone) {
7548
7639
  const { ms, seconds, minutes, hours, date, month } = partsOf(t, zone);
@@ -7554,7 +7645,8 @@ function timeLevel(t, zone) {
7554
7645
  return month !== 0 ? "month" : "year";
7555
7646
  }
7556
7647
  function timeName(times, zone) {
7557
- const finest = times.reduce((max, t) => Math.max(max, LEVELS.indexOf(timeLevel(t, zone))), 0);
7648
+ const shown = clockReader(zone);
7649
+ const finest = times.reduce((max, t) => Math.max(max, LEVELS.indexOf(timeLevel(shown(t), "UTC"))), 0);
7558
7650
  const timeZone = zoneOption(zone);
7559
7651
  const timeStyle = finest >= LEVELS.indexOf("second") ? "medium" : finest >= LEVELS.indexOf("hour") ? "short" : void 0;
7560
7652
  const options = finest === LEVELS.indexOf("millisecond") ? {
@@ -7568,7 +7660,17 @@ function timeName(times, zone) {
7568
7660
  timeZone
7569
7661
  };
7570
7662
  const format = new Intl.DateTimeFormat(void 0, options);
7571
- return (t) => format.format(t);
7663
+ if (zone === "UTC" || !timeStyle) return (t) => format.format(t);
7664
+ const named = new Intl.DateTimeFormat(void 0, {
7665
+ timeZone,
7666
+ timeZoneName: "short"
7667
+ });
7668
+ return (t) => {
7669
+ const text = format.format(t);
7670
+ if (twinOf(t, shown) === void 0) return text;
7671
+ const name = named.formatToParts(t).find((part) => part.type === "timeZoneName")?.value;
7672
+ return name ? `${text} ${name}` : text;
7673
+ };
7572
7674
  }
7573
7675
  function tickWording(zone) {
7574
7676
  const formats = /* @__PURE__ */ new Map();
@@ -7585,19 +7687,10 @@ function tickWording(zone) {
7585
7687
  return format.format(t);
7586
7688
  };
7587
7689
  }
7588
- const zoneOption = (zone) => zone === "UTC" ? "UTC" : void 0;
7690
+ const zoneOption = (zone) => zone === "local" ? void 0 : zone;
7589
7691
  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
- } : {
7692
+ const d = new Date(zone === "UTC" || zone === "local" ? t : shownAt(t, zone));
7693
+ return zone === "local" ? {
7601
7694
  year: d.getFullYear(),
7602
7695
  month: d.getMonth(),
7603
7696
  date: d.getDate(),
@@ -7606,19 +7699,88 @@ function partsOf(t, zone) {
7606
7699
  minutes: d.getMinutes(),
7607
7700
  seconds: d.getSeconds(),
7608
7701
  ms: d.getMilliseconds()
7702
+ } : {
7703
+ year: d.getUTCFullYear(),
7704
+ month: d.getUTCMonth(),
7705
+ date: d.getUTCDate(),
7706
+ weekday: d.getUTCDay(),
7707
+ hours: d.getUTCHours(),
7708
+ minutes: d.getUTCMinutes(),
7709
+ seconds: d.getUTCSeconds(),
7710
+ ms: d.getUTCMilliseconds()
7609
7711
  };
7610
7712
  }
7611
7713
  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 {
7714
+ return timeAt(zone, year, month, date);
7715
+ }
7716
+ function timeAt(zone, year, month, date, hours = 0, minutes = 0, seconds = 0, ms = 0) {
7717
+ if (zone === "local") {
7718
+ const d = /* @__PURE__ */ new Date(0);
7617
7719
  d.setFullYear(year, month, date);
7618
- d.setHours(0, 0, 0, 0);
7720
+ d.setHours(hours, minutes, seconds, ms);
7721
+ return d.getTime();
7619
7722
  }
7723
+ const shown = utc(year, month, date, hours, minutes, seconds, ms);
7724
+ if (zone === "UTC") return shown;
7725
+ const before = shown - (shownAt(shown - DAY, zone) - (shown - DAY));
7726
+ const after = shown - (shownAt(shown + DAY, zone) - (shown + DAY));
7727
+ if (before === after) return before;
7728
+ const fits = [before, after].filter((t) => shownAt(t, zone) === shown);
7729
+ return fits.length > 0 ? Math.min(...fits) : before;
7730
+ }
7731
+ function utc(year, month, date, hours = 0, minutes = 0, seconds = 0, ms = 0) {
7732
+ const d = /* @__PURE__ */ new Date(0);
7733
+ d.setUTCFullYear(year, month, date);
7734
+ d.setUTCHours(hours, minutes, seconds, ms);
7620
7735
  return d.getTime();
7621
7736
  }
7737
+ function shownAt(t, zone) {
7738
+ if (zone === "UTC") return t;
7739
+ if (zone === "local") {
7740
+ const d = new Date(t);
7741
+ return utc(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
7742
+ }
7743
+ const ms = (t % SECOND + SECOND) % SECOND;
7744
+ const fields = {};
7745
+ for (const part of clockOf(zone).formatToParts(t - ms)) fields[part.type] = part.value;
7746
+ const year = Number(fields["year"]);
7747
+ 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);
7748
+ }
7749
+ function clockReader(zone) {
7750
+ if (zone === "UTC" || zone === "local") return (t) => shownAt(t, zone);
7751
+ const kept = /* @__PURE__ */ new Map();
7752
+ return (t) => {
7753
+ let shown = kept.get(t);
7754
+ if (shown === void 0) kept.set(t, shown = shownAt(t, zone));
7755
+ return shown;
7756
+ };
7757
+ }
7758
+ function twinOf(t, shown) {
7759
+ const at = shown(t);
7760
+ for (const near of [t - DAY, t + DAY]) {
7761
+ const other = at - (shown(near) - near);
7762
+ if (other !== t && shown(other) === at) return other;
7763
+ }
7764
+ }
7765
+ const clocks = /* @__PURE__ */ new Map();
7766
+ function clockOf(zone) {
7767
+ let clock = clocks.get(zone);
7768
+ if (!clock) {
7769
+ clock = new Intl.DateTimeFormat("en-US", {
7770
+ timeZone: zone,
7771
+ hourCycle: "h23",
7772
+ era: "short",
7773
+ year: "numeric",
7774
+ month: "numeric",
7775
+ day: "numeric",
7776
+ hour: "numeric",
7777
+ minute: "numeric",
7778
+ second: "numeric"
7779
+ });
7780
+ clocks.set(zone, clock);
7781
+ }
7782
+ return clock;
7783
+ }
7622
7784
  // src/charts/line-layout.ts
7623
7785
  const LINE_WIDTH = 2.25;
7624
7786
  const DOT_RADIUS = 4.5;
@@ -7646,7 +7808,7 @@ function lineEncoding(options) {
7646
7808
  const labels = options.labels;
7647
7809
  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
7810
  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)}.`);
7811
+ 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
7812
  const xFormat = options.xFormat;
7651
7813
  if (xFormat !== void 0 && typeof xFormat !== "function") throw new TypeError("lineChart: xFormat must be a function that turns an x into text.");
7652
7814
  const curve = options.curve ?? "linear";
@@ -8143,6 +8305,7 @@ function lineChart$1(target, options, env) {
8143
8305
  const container = resolveTarget$2(target, "lineChart");
8144
8306
  checkChartOptions(options, "lineChart");
8145
8307
  let hoverKind = hoverOf(options);
8308
+ missingOf(options);
8146
8309
  let current = options;
8147
8310
  const motion = chartMotion(options.motion, env.motion);
8148
8311
  let effects = resolveEffects(options.on, env.presets);
@@ -8172,17 +8335,19 @@ function lineChart$1(target, options, env) {
8172
8335
  "aria-hidden": "true",
8173
8336
  visibility: "hidden"
8174
8337
  }, svg);
8175
- const marksLayer = svgElement("g", {
8338
+ const linesLayer = svgElement("g", { class: "ec-lines" }, svgElement("g", {
8176
8339
  class: "ec-marks",
8177
8340
  "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);
8341
+ }, svg));
8182
8342
  const overlay = svgElement("g", {
8183
8343
  class: "ec-overlay",
8184
8344
  "aria-hidden": "true"
8185
8345
  }, svg);
8346
+ const pointsLayer = svgElement("g", { class: "ec-points" }, svgElement("g", {
8347
+ class: "ec-marks",
8348
+ "aria-hidden": "true"
8349
+ }, svg));
8350
+ const columnsLayer = svgElement("g", { class: "ec-columns" }, svg);
8186
8351
  const measure = textMeasure(svg);
8187
8352
  let rowOrder = [];
8188
8353
  const rows = /* @__PURE__ */ new Map();
@@ -8720,6 +8885,14 @@ function lineChart$1(target, options, env) {
8720
8885
  crosshair.setAttribute("visibility", "hidden");
8721
8886
  tooltip.hide();
8722
8887
  }
8888
+ function stand(key) {
8889
+ const record = key === void 0 ? void 0 : rows.get(key);
8890
+ if (!record || !revealed(record)) crosshair.setAttribute("visibility", "hidden");
8891
+ else setAttributes(crosshair, {
8892
+ ...placeCrosshair(drawnFrame, record.px),
8893
+ visibility: void 0
8894
+ });
8895
+ }
8723
8896
  let ringLine;
8724
8897
  function drawRing(key) {
8725
8898
  const point = key === void 0 ? void 0 : points.get(key);
@@ -8759,6 +8932,7 @@ function lineChart$1(target, options, env) {
8759
8932
  }
8760
8933
  function followHover() {
8761
8934
  if (hover.key !== void 0) showHover(hover.key);
8935
+ if (hover.standing !== void 0) stand(hover.standing);
8762
8936
  if (hover.ringKey !== void 0) drawRing(hover.ringKey);
8763
8937
  }
8764
8938
  const input = (record) => ({
@@ -8769,6 +8943,28 @@ function lineChart$1(target, options, env) {
8769
8943
  mark: record.shown.geometry,
8770
8944
  data: record.shown.data
8771
8945
  });
8946
+ function standIn(key) {
8947
+ const record = rows.get(key);
8948
+ if (!record || !revealed(record)) return void 0;
8949
+ const { row } = record;
8950
+ return {
8951
+ mark: describePoint({
8952
+ key,
8953
+ x: record.px,
8954
+ y: drawnFrame.box.top,
8955
+ r: DOT_RADIUS
8956
+ }),
8957
+ data: {
8958
+ datum: row.datum,
8959
+ samples: [{
8960
+ t: 0,
8961
+ value: NaN,
8962
+ at: laidOut.time ? new Date(row.x) : row.x
8963
+ }],
8964
+ related: () => void 0
8965
+ }
8966
+ };
8967
+ }
8772
8968
  function liveRowOf(eventTarget) {
8773
8969
  const element = eventTarget;
8774
8970
  const column = typeof element?.closest === "function" ? element.closest(".ec-column") : null;
@@ -8864,7 +9060,7 @@ function lineChart$1(target, options, env) {
8864
9060
  if (hoverKind !== "point") return;
8865
9061
  if (!stopsLayer) {
8866
9062
  stopsLayer = svgElement("g", { class: "ec-stops" }, svg);
8867
- svg.insertBefore(stopsLayer, overlay);
9063
+ svg.insertBefore(stopsLayer, columnsLayer.nextSibling);
8868
9064
  plotHit = svgElement("rect", { class: "ec-hit" }, stopsLayer);
8869
9065
  stopsLayer.addEventListener("click", (event) => {
8870
9066
  const point = pointAt(event.clientX, event.clientY);
@@ -9036,6 +9232,8 @@ function lineChart$1(target, options, env) {
9036
9232
  const record = findMark(key);
9037
9233
  return record && onScreen(record);
9038
9234
  },
9235
+ standIn,
9236
+ stand,
9039
9237
  ring: drawRing,
9040
9238
  tooltip: {
9041
9239
  show: showHover,
@@ -9064,7 +9262,8 @@ function lineChart$1(target, options, env) {
9064
9262
  total: total(row.values)
9065
9263
  })),
9066
9264
  format: format(opts),
9067
- total: false
9265
+ total: false,
9266
+ missing: missingOf(opts)
9068
9267
  });
9069
9268
  }
9070
9269
  function labelColumn(record) {
@@ -9303,14 +9502,16 @@ function lineChart$1(target, options, env) {
9303
9502
  for (const point of points.values()) point.target = placed.points.get(point.key) ?? point.target;
9304
9503
  transitionTo(next, true);
9305
9504
  }
9505
+ const remeasure = () => {
9506
+ measure.clear();
9507
+ relayout();
9508
+ };
9509
+ const unwatchText = watchText(svg, clock, remeasure);
9306
9510
  const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
9307
9511
  measuredWidth = width;
9308
9512
  if (current.width === void 0) relayout();
9309
9513
  });
9310
- const unwatchFonts = watchFonts(doc, () => {
9311
- measure.clear();
9312
- relayout();
9313
- });
9514
+ const unwatchFonts = watchFonts(doc, remeasure);
9314
9515
  describeChart(svg, current);
9315
9516
  syncLegend();
9316
9517
  table.render(firstTable);
@@ -9354,6 +9555,7 @@ function lineChart$1(target, options, env) {
9354
9555
  };
9355
9556
  checkChartOptions(merged, "lineChart");
9356
9557
  const kind = hoverOf(merged);
9558
+ missingOf(merged);
9357
9559
  const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
9358
9560
  const nextLayout = layout(merged, swapped);
9359
9561
  const nextTable = tableFor(merged, nextLayout);
@@ -9457,6 +9659,7 @@ function lineChart$1(target, options, env) {
9457
9659
  table.destroy();
9458
9660
  announcer?.destroy();
9459
9661
  unwatchHoverDuration();
9662
+ unwatchText();
9460
9663
  unwatchWidth();
9461
9664
  unwatchFonts();
9462
9665
  for (const record of [...rowOrder, ...leavingRows.values()]) for (const value of [
@@ -9559,9 +9762,10 @@ function labelled(values, options) {
9559
9762
  }
9560
9763
  function said(values, options) {
9561
9764
  const formatted = format(options);
9765
+ const missing = missingOf(options);
9562
9766
  return values.map((v) => {
9563
9767
  const label = seriesLabel(options.seriesLabels, v.series);
9564
- return v.value === void 0 ? `${label} missing` : `${formatted(v.value)} ${label}`;
9768
+ return v.value === void 0 ? `${label} ${missing}` : `${formatted(v.value)} ${label}`;
9565
9769
  });
9566
9770
  }
9567
9771
  function summary(row, options) {
@@ -9618,6 +9822,11 @@ function hoverOf(options) {
9618
9822
  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
9823
  return hover;
9620
9824
  }
9825
+ function missingOf(options) {
9826
+ const { missing = MISSING } = options;
9827
+ 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)}.`);
9828
+ return missing;
9829
+ }
9621
9830
  // src/core/geometry/ring.ts
9622
9831
  const ROUND = .5;
9623
9832
  function goesRound(mark) {
@@ -10021,11 +10230,25 @@ function hostColors(element, root) {
10021
10230
  const color = paint === "fill" ? fill : paintOf$1(element, root, "stroke");
10022
10231
  if (color === void 0 || color === NONE) return void 0;
10023
10232
  return {
10024
- color,
10025
- strong: `color-mix(in oklab, ${color}, ${cssColor("text")} ${STRONG})`,
10233
+ ...strongColors(color),
10026
10234
  paint
10027
10235
  };
10028
10236
  }
10237
+ function strongColors(color) {
10238
+ return {
10239
+ color,
10240
+ strong: `color-mix(in oklab, ${color}, ${cssColor("text")} ${STRONG})`
10241
+ };
10242
+ }
10243
+ function drawnStyle(element, root, property) {
10244
+ const computed = element.ownerDocument.defaultView?.getComputedStyle?.(element).getPropertyValue(property).trim() ?? "";
10245
+ if (attributesComputed(root)) return computed;
10246
+ for (let node = element; node; node = node === root ? null : node.parentElement) {
10247
+ const value = node.style?.getPropertyValue(property) || node.getAttribute(property);
10248
+ if (value) return value.trim();
10249
+ }
10250
+ return computed;
10251
+ }
10029
10252
  const STRONG = "25%";
10030
10253
  const NONE = "none";
10031
10254
  const SVG_NS$1 = "http://www.w3.org/2000/svg";
@@ -10436,6 +10659,8 @@ const WRAPPING_ROLES = /* @__PURE__ */ new Set([
10436
10659
  "graphics-symbol",
10437
10660
  "graphics-object"
10438
10661
  ]);
10662
+ const insides = /* @__PURE__ */ new WeakMap();
10663
+ const insidesOf = (port) => port ? insides.get(port) : void 0;
10439
10664
  function expressive$1(target, options, env) {
10440
10665
  checkOptions$12(options);
10441
10666
  const motion = chartMotion(options.motion, env.motion);
@@ -10764,8 +10989,10 @@ function expressive$1(target, options, env) {
10764
10989
  const runs = make("g", { class: "ec-runs" }, overlay);
10765
10990
  const ring = maskedRing(overlay);
10766
10991
  const find = (key) => records.get(key) ?? leaving.get(key);
10992
+ const measure = textMeasure(runs);
10767
10993
  const surface = svgSurface({
10768
10994
  overlay: runs,
10995
+ measure,
10769
10996
  mark: (key) => ({
10770
10997
  set: (style) => find(key)?.handle.set(style),
10771
10998
  reset: () => find(key)?.handle.reset()
@@ -10783,6 +11010,12 @@ function expressive$1(target, options, env) {
10783
11010
  mark: record.mark.geometry,
10784
11011
  data: record.mark.data
10785
11012
  });
11013
+ function remeasure() {
11014
+ measure.clear();
11015
+ for (const record of order) runner.change(record.mark.geometry, record.mark.data);
11016
+ }
11017
+ let unwatchText = () => {};
11018
+ const unwatchFonts = watchFonts(doc, remeasure);
10786
11019
  function createRecord(mark) {
10787
11020
  const record = {
10788
11021
  key: mark.key,
@@ -10823,7 +11056,7 @@ function expressive$1(target, options, env) {
10823
11056
  from: from.geometry
10824
11057
  });
10825
11058
  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);
11059
+ 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
11060
  record.mark = mark;
10828
11061
  } else {
10829
11062
  record = leaving.get(mark.key);
@@ -10893,6 +11126,7 @@ function expressive$1(target, options, env) {
10893
11126
  function moveTo(next) {
10894
11127
  detach();
10895
11128
  root = next;
11129
+ unwatchText = watchText(root, clock, remeasure);
10896
11130
  root.appendChild(overlay);
10897
11131
  if ((options.keyboard === true || options.markLabel) && root.getAttribute("role") === "img" && !warnedImage) {
10898
11132
  warnedImage = true;
@@ -10924,6 +11158,7 @@ function expressive$1(target, options, env) {
10924
11158
  endHover();
10925
11159
  interaction?.destroy();
10926
11160
  interaction = void 0;
11161
+ unwatchText();
10927
11162
  }
10928
11163
  function ownerOf(eventTarget) {
10929
11164
  for (let node = eventTarget; node && node !== root; node = node.parentElement) {
@@ -11223,6 +11458,15 @@ function expressive$1(target, options, env) {
11223
11458
  return true;
11224
11459
  }
11225
11460
  };
11461
+ insides.set(link, {
11462
+ root: () => root,
11463
+ ancestor: () => ancestor,
11464
+ elements: () => order.flatMap((record) => record.mark.parts.map((part) => part.element)),
11465
+ keyOf: (element) => ownerOf(element)?.record.key,
11466
+ colorOf: (key) => records.get(key)?.mark.parts[0]?.colors?.color,
11467
+ moveTabStop: (key) => keyboard?.moveTabStop(key) ?? false,
11468
+ edits
11469
+ });
11226
11470
  return linkable(link, {
11227
11471
  refresh(next) {
11228
11472
  if (destroyed) return;
@@ -11301,6 +11545,7 @@ function expressive$1(target, options, env) {
11301
11545
  watching?.destroy();
11302
11546
  runner.destroy();
11303
11547
  unsubscribeMotion?.();
11548
+ unwatchFonts();
11304
11549
  keyboard?.destroy();
11305
11550
  detach();
11306
11551
  overlay.remove();
@@ -11451,6 +11696,119 @@ function geometryChanged(from, to) {
11451
11696
  const b = to.segments ?? [];
11452
11697
  return a.length !== b.length || a.some((segment, i) => segment.key !== b[i].key || segment.outline.d !== b[i].outline.d);
11453
11698
  }
11699
+ // src/charts/adapter/host-view.ts
11700
+ const FONT = [
11701
+ "font-family",
11702
+ "font-size",
11703
+ "font-style",
11704
+ "font-weight",
11705
+ "font-variant-numeric",
11706
+ "letter-spacing",
11707
+ "word-spacing",
11708
+ "dominant-baseline",
11709
+ "fill"
11710
+ ];
11711
+ const LENGTHS = /* @__PURE__ */ new Set([
11712
+ "font-size",
11713
+ "letter-spacing",
11714
+ "word-spacing"
11715
+ ]);
11716
+ function first(element, name) {
11717
+ const list = element[name]?.baseVal;
11718
+ if (list && list.numberOfItems > 0) return list.getItem(0).value;
11719
+ return Number.parseFloat(element.getAttribute(name) ?? "") || 0;
11720
+ }
11721
+ function scaled(value, scale) {
11722
+ if (scale === 1) return value;
11723
+ return value.replace(/(-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(px)?(?![\w.%])/gi, (_, n, px) => `${Math.round(Number(n) * scale * 1e3) / 1e3}${px ?? ""}`);
11724
+ }
11725
+ function hostView(attachment, options = {}) {
11726
+ const port = typeof attachment === "object" && attachment !== null ? portOf(attachment) : void 0;
11727
+ const inside = insidesOf(port);
11728
+ if (!port || !inside?.root()) throw new TypeError("hostView needs an attachment that expressive() or fromVegaView() returned, with marks in an <svg>.");
11729
+ if (typeof options !== "object" || options === null || options.labels !== void 0 && typeof options.labels !== "function") throw new TypeError("hostView: labels must be a function that returns the host's labels, such as () => names.map((element) => ({ element, key: element.textContent, role: \"category\" })).");
11730
+ const { edits } = inside;
11731
+ const svg = () => inside.root();
11732
+ let given;
11733
+ let hidden = [];
11734
+ function read() {
11735
+ if (!options.labels) return [];
11736
+ const keys = new Set(attachment.marks().map((mark) => mark.key));
11737
+ try {
11738
+ return Array.from(options.labels()).filter((label) => label?.element?.localName === "text" && svg().contains(label.element) && keys.has(label.key) && (label.role === "category" || label.role === "value"));
11739
+ } catch (error) {
11740
+ report(error);
11741
+ return [];
11742
+ }
11743
+ }
11744
+ function chartLabel({ element, key, role }) {
11745
+ const root = svg();
11746
+ const m = between$1(view.space, element, root);
11747
+ const at = matrix.apply(m, {
11748
+ x: first(element, "x"),
11749
+ y: first(element, "y")
11750
+ });
11751
+ const scale = scaleOf$2(m);
11752
+ const text = element.ownerDocument.createElementNS(SVG_NS$2, "text");
11753
+ text.textContent = element.textContent;
11754
+ for (const name of ["dx", "dy"]) {
11755
+ const value = element.getAttribute(name);
11756
+ if (value !== null) text.setAttribute(name, scaled(value, scale));
11757
+ }
11758
+ setStyles(text, Object.fromEntries(FONT.map((property) => {
11759
+ const value = drawnStyle(element, root, property);
11760
+ return [property, (LENGTHS.has(property) ? scaled(value, scale) : value) || void 0];
11761
+ })));
11762
+ const anchor = drawnStyle(element, root, "text-anchor");
11763
+ return {
11764
+ key,
11765
+ role,
11766
+ text: element.textContent ?? "",
11767
+ x: at.x,
11768
+ y: at.y,
11769
+ anchor: anchor === "middle" || anchor === "end" ? anchor : "start",
11770
+ element: text
11771
+ };
11772
+ }
11773
+ const view = {
11774
+ get element() {
11775
+ return svg();
11776
+ },
11777
+ get space() {
11778
+ return inside.ancestor() ?? svg();
11779
+ },
11780
+ refresh: (source) => attachment.refresh(source),
11781
+ update: (next) => attachment.update(next),
11782
+ on: (type, listener) => attachment.on(type, listener),
11783
+ marks: () => attachment.marks(),
11784
+ focus: (key) => attachment.focus(key),
11785
+ leave: () => attachment.leave(),
11786
+ destroy() {
11787
+ given = void 0;
11788
+ hidden = [];
11789
+ attachment.destroy();
11790
+ },
11791
+ labels: () => (given ?? read()).map(chartLabel),
11792
+ paintOf(key) {
11793
+ const color = inside.colorOf(key);
11794
+ return color === void 0 ? void 0 : {
11795
+ color: key,
11796
+ drawn: true,
11797
+ cssColor: color
11798
+ };
11799
+ },
11800
+ keyOf: (element) => inside.keyOf(element),
11801
+ moveTabStop: (key) => inside.moveTabStop(key),
11802
+ morphing(on) {
11803
+ for (const element of hidden) edits.style(element, "visibility", void 0);
11804
+ given = on ? read() : void 0;
11805
+ hidden = given ? [...inside.elements(), ...given.map((label) => label.element)] : [];
11806
+ for (const element of hidden) edits.style(element, "visibility", "hidden");
11807
+ edits.toggleClass(svg(), "ec-morphing", on);
11808
+ }
11809
+ };
11810
+ return linkable(port, view);
11811
+ }
11454
11812
  // src/charts/adapter/vega.ts
11455
11813
  const MARK_TYPES = [
11456
11814
  "line",
@@ -12032,13 +12390,14 @@ function chartSwitch$1(target, options, env) {
12032
12390
  const runsLayer = svgElement("g", { class: "ec-switch-runs" }, overlay);
12033
12391
  const labelsLayer = svgElement("g", { class: "ec-switch-labels" }, overlay);
12034
12392
  const announcer = options.announce ? chartAnnouncer(overlay) : void 0;
12393
+ const tokensOf = (paint) => markColorStyles(paint.cssColor === void 0 ? seriesColors(colors.slot(paint.color)) : strongColors(paint.cssColor));
12035
12394
  const orders = /* @__PURE__ */ new WeakMap();
12036
12395
  const surfaceFor = (paints, extras) => ({ group(key, order) {
12037
12396
  const group = svgElement("g", {
12038
12397
  class: "ec-run",
12039
12398
  "data-key": key
12040
12399
  }, runsLayer);
12041
- setStyles(group, markColorStyles(seriesColors(colors.slot(paints[order] ?? key))));
12400
+ setStyles(group, tokensOf(paints[order] ?? { color: key }));
12042
12401
  orders.set(group, order);
12043
12402
  const above = Array.from(runsLayer.children).find((child) => (orders.get(child) ?? -Infinity) > order);
12044
12403
  runsLayer.insertBefore(group, above ?? null);
@@ -12078,7 +12437,7 @@ function chartSwitch$1(target, options, env) {
12078
12437
  ]].forEach(([end, opacity, color]) => {
12079
12438
  if (!end) return;
12080
12439
  const element = endDot();
12081
- setStyles(element, markColorStyles(seriesColors(colors.slot(color))));
12440
+ setStyles(element, tokensOf(color));
12082
12441
  placeDot(element, end);
12083
12442
  dots.push({
12084
12443
  element,
@@ -12153,8 +12512,9 @@ function chartSwitch$1(target, options, env) {
12153
12512
  function readFocus(from) {
12154
12513
  const element = focused();
12155
12514
  const inside = element !== null && from.container.contains(element);
12156
- const keyed = (inside ? element : from.chart.element.querySelector("[tabindex=\"0\"]"))?.closest("[data-key]");
12157
- const key = keyed && from.chart.element.contains(keyed) ? keyed.getAttribute("data-key") : null;
12515
+ const stop = inside ? element : from.chart.element.querySelector("[tabindex=\"0\"]");
12516
+ const keyed = stop?.closest("[data-key]");
12517
+ const key = (stop && from.chart.keyOf?.(stop)) ?? (keyed && from.chart.element.contains(keyed) ? keyed.getAttribute("data-key") : null);
12158
12518
  if (!inside && key === null) return void 0;
12159
12519
  return {
12160
12520
  keys: key === null ? [] : from.chart.standsFor?.(key) ?? [key],
@@ -12207,6 +12567,7 @@ function chartSwitch$1(target, options, env) {
12207
12567
  each.container.classList.remove("ec-switch-inactive");
12208
12568
  each.container.classList.add("ec-switching");
12209
12569
  each.container.setAttribute("inert", "");
12570
+ each.chart.morphing?.(true);
12210
12571
  each.chart.element.classList.add("ec-morphing");
12211
12572
  }
12212
12573
  const { pairs, surface, scene } = prepare(from, to);
@@ -12282,6 +12643,7 @@ function chartSwitch$1(target, options, env) {
12282
12643
  const to = session.forward ? session.b : session.a;
12283
12644
  for (const each of [session.a, session.b]) {
12284
12645
  each.chart.element.classList.remove("ec-morphing");
12646
+ each.chart.morphing?.(false);
12285
12647
  each.container.classList.remove("ec-switching");
12286
12648
  each.container.style.removeProperty("opacity");
12287
12649
  }
@@ -12294,8 +12656,8 @@ function chartSwitch$1(target, options, env) {
12294
12656
  session.settle();
12295
12657
  }
12296
12658
  function prepare(a, b) {
12297
- const toA = between$1(overlay, a.chart.element, wrapper);
12298
- const toB = between$1(overlay, b.chart.element, wrapper);
12659
+ const toA = between$1(overlay, a.chart.space ?? a.chart.element, wrapper);
12660
+ const toB = between$1(overlay, b.chart.space ?? b.chart.element, wrapper);
12299
12661
  const scaleA = scaleOf(toA);
12300
12662
  const scaleB = scaleOf(toB);
12301
12663
  const from = a.chart.marks().map((mark) => mapMark(mark, toA));
@@ -12315,8 +12677,8 @@ function chartSwitch$1(target, options, env) {
12315
12677
  from: was.drawn ? partner : dot$1(partner),
12316
12678
  to: will.drawn ? mark : dot$1(mark)
12317
12679
  });
12318
- paints.push(will.color);
12319
- extras.push(extrasFor([ringOf(was, scaleA), ringOf(will, scaleB)], [endOf(was, partner, scaleA), endOf(will, mark, scaleB)], [was.color, will.color]));
12680
+ paints.push(will);
12681
+ extras.push(extrasFor([ringOf(was, scaleA), ringOf(will, scaleB)], [endOf(was, partner, scaleA), endOf(will, mark, scaleB)], [was, will]));
12320
12682
  }
12321
12683
  const drawings = [];
12322
12684
  if (extras.some((each) => each !== void 0)) drawings.push((s) => {
@@ -12331,16 +12693,18 @@ function chartSwitch$1(target, options, env) {
12331
12693
  const id = (label) => `${label.role}\n${label.key}`;
12332
12694
  const labelsA = a.chart.labels();
12333
12695
  const labelsB = b.chart.labels();
12696
+ const sizeA = a.chart.space ? scaleA : 1;
12697
+ const sizeB = b.chart.space ? scaleB : 1;
12334
12698
  const byId = new Map(labelsA.map((label) => [id(label), label]));
12335
12699
  const matched = /* @__PURE__ */ new Set();
12336
12700
  for (const label of labelsB) {
12337
12701
  const partner = byId.get(id(label));
12338
12702
  if (!partner) continue;
12339
12703
  matched.add(id(label));
12340
- drawings.push(moveLabel(copyLabel(partner, toA), copyLabel(label, toB)));
12704
+ drawings.push(moveLabel(copyLabel(partner, toA, sizeA), copyLabel(label, toB, sizeB)));
12341
12705
  }
12342
- for (const label of labelsA) if (!matched.has(id(label))) drawings.push(fadeLabel(copyLabel(label, toA), fadeOut));
12343
- for (const label of labelsB) if (!byId.has(id(label))) drawings.push(fadeLabel(copyLabel(label, toB), fadeIn));
12706
+ for (const label of labelsA) if (!matched.has(id(label))) drawings.push(fadeLabel(copyLabel(label, toA, sizeA), fadeOut));
12707
+ for (const label of labelsB) if (!byId.has(id(label))) drawings.push(fadeLabel(copyLabel(label, toB, sizeB), fadeIn));
12344
12708
  drawings.push((s) => {
12345
12709
  setOpacity(a.container, 1 - clamp$1(s / OUT_BY));
12346
12710
  setOpacity(b.container, clamp$1((s - HALF) / .5));
@@ -12365,7 +12729,7 @@ function chartSwitch$1(target, options, env) {
12365
12729
  class: "ec-switch-fade",
12366
12730
  "data-key": mark.key
12367
12731
  }, fadesLayer);
12368
- setStyles(group, markColorStyles(seriesColors(colors.slot(paint.color))));
12732
+ setStyles(group, tokensOf(paint));
12369
12733
  const ring = ringOf(paint, scale);
12370
12734
  svgLayer(group).path(mark.outline.d, mark.outline.closed ? {
12371
12735
  fill: "mark",
@@ -12390,7 +12754,7 @@ function chartSwitch$1(target, options, env) {
12390
12754
  });
12391
12755
  return element;
12392
12756
  }
12393
- function copyLabel(label, m) {
12757
+ function copyLabel(label, m, scale) {
12394
12758
  const text = label.element.cloneNode(true);
12395
12759
  for (const name of [
12396
12760
  "id",
@@ -12399,17 +12763,19 @@ function chartSwitch$1(target, options, env) {
12399
12763
  "aria-hidden"
12400
12764
  ]) text.removeAttribute(name);
12401
12765
  text.textContent = label.text;
12402
- const at = matrix.apply(m, label);
12766
+ const copy = {
12767
+ text,
12768
+ at: matrix.apply(m, label),
12769
+ scale
12770
+ };
12403
12771
  setAttributes(text, {
12404
- x: at.x,
12405
- y: at.y,
12406
- "text-anchor": label.anchor
12772
+ x: copy.at.x,
12773
+ y: copy.at.y,
12774
+ "text-anchor": label.anchor,
12775
+ ...scaledAt(copy, copy.at.x, copy.at.y)
12407
12776
  });
12408
12777
  labelsLayer.appendChild(text);
12409
- return {
12410
- text,
12411
- at
12412
- };
12778
+ return copy;
12413
12779
  }
12414
12780
  const api = {
12415
12781
  get current() {
@@ -12461,6 +12827,7 @@ function chartSwitch$1(target, options, env) {
12461
12827
  session.driver?.cancel();
12462
12828
  session.transition?.clear();
12463
12829
  session.scene.clear();
12830
+ for (const each of [session.a, session.b]) each.chart.morphing?.(false);
12464
12831
  session.settle();
12465
12832
  }
12466
12833
  stopMotion();
@@ -12560,15 +12927,25 @@ function moveLabel(a, b) {
12560
12927
  setAttributes(a.text, {
12561
12928
  x,
12562
12929
  y,
12563
- visibility: second ? "hidden" : void 0
12930
+ visibility: second ? "hidden" : void 0,
12931
+ ...scaledAt(a, x, y)
12564
12932
  });
12565
12933
  setAttributes(b.text, {
12566
12934
  x,
12567
12935
  y,
12568
- visibility: second ? void 0 : "hidden"
12936
+ visibility: second ? void 0 : "hidden",
12937
+ ...scaledAt(b, x, y)
12569
12938
  });
12570
12939
  };
12571
12940
  }
12941
+ const scaledAt = (copy, x, y) => copy.scale === 1 ? {} : { transform: transformAttribute([
12942
+ copy.scale,
12943
+ 0,
12944
+ 0,
12945
+ copy.scale,
12946
+ x * (1 - copy.scale),
12947
+ y * (1 - copy.scale)
12948
+ ]) };
12572
12949
  function fadeLabel(label, opacity) {
12573
12950
  return (s) => setAttributes(label.text, { opacity: opacity(s) });
12574
12951
  }
@@ -14836,7 +15213,7 @@ function configure(options) {
14836
15213
  }
14837
15214
  }
14838
15215
  // src/index.ts
14839
- const VERSION = "0.7.0";
15216
+ const VERSION = "0.9.0";
14840
15217
  const env = {
14841
15218
  presets: presetRegistry,
14842
15219
  icons: iconRegistry,
@@ -14889,6 +15266,7 @@ exports.expressive = expressive;
14889
15266
  exports.flash = flash;
14890
15267
  exports.fromVegaView = fromVegaView;
14891
15268
  exports.gaits = gaits;
15269
+ exports.hostView = hostView;
14892
15270
  exports.iconFromSvg = iconFromSvg;
14893
15271
  exports.icons = icons;
14894
15272
  exports.interpolateNumber = interpolateNumber;