@opendata-ai/openchart-engine 9.0.0-rc.1 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/compiler/mark-options.ts
2
2
  import { jsonPointer } from "@opendata-ai/openchart-core";
3
3
  var APPLIES_TO = {
4
+ ticks: ["errorbar"],
4
5
  point: ["line", "area", "density"],
5
6
  interpolate: ["line", "area", "density"],
6
7
  orient: ["bar", "histogram"],
@@ -236,6 +237,90 @@ function formatLabelValue(value, ctx) {
236
237
  return (ctx ? defaultNumberFormatter2(ctx) : defaultFmt)(value);
237
238
  }
238
239
 
240
+ // src/charts/_shared/temporal-bands.ts
241
+ import { scaleBand } from "d3-scale";
242
+
243
+ // src/layout/temporal-interval.ts
244
+ import { timeDay, timeMonth, timeWeek, utcDay, utcMonth, utcWeek } from "d3-time";
245
+ var MONTHS = { month: 1, quarter: 3, year: 12 };
246
+ var INFERABLE_UNITS = ["year", "quarter", "month", "week", "day"];
247
+ var MIN_CALENDAR_DAY = 23 * 36e5;
248
+ function temporalDate(value) {
249
+ return value instanceof Date ? value : new Date(String(value));
250
+ }
251
+ function calendarFor(mode) {
252
+ const day = mode === "utc" ? utcDay : timeDay;
253
+ const week = mode === "utc" ? utcWeek : timeWeek;
254
+ const month = mode === "utc" ? utcMonth : timeMonth;
255
+ const addMonths = (date, months) => {
256
+ const start = month.floor(date);
257
+ const target = month.offset(start, months);
258
+ const dayStart = day.floor(date);
259
+ const lastDay = day.count(target, month.offset(target, 1)) - 1;
260
+ const dayIndex = Math.min(day.count(start, dayStart), lastDay);
261
+ return new Date(+day.offset(target, dayIndex) + (+date - +dayStart));
262
+ };
263
+ const isMonthEnd = (date) => +month.floor(day.offset(day.floor(date), 1)) !== +month.floor(date);
264
+ const offset = (unit, date, count2) => {
265
+ const months = MONTHS[unit];
266
+ if (months) return addMonths(date, months * count2);
267
+ return (unit === "week" ? week : day).offset(date, count2);
268
+ };
269
+ const count = (unit, from, to) => {
270
+ const months = MONTHS[unit];
271
+ if (months) return month.count(from, to) / months;
272
+ return (unit === "week" ? week : day).count(from, to);
273
+ };
274
+ const aligned = (unit, anchor, time) => {
275
+ const units = count(unit, anchor, time);
276
+ if (!Number.isInteger(units)) return false;
277
+ if (+offset(unit, anchor, units) === +time) return true;
278
+ return MONTHS[unit] !== void 0 && isMonthEnd(anchor) && isMonthEnd(time) && +anchor - +day.floor(anchor) === +time - +day.floor(time);
279
+ };
280
+ return { offset, count, aligned };
281
+ }
282
+ function inferCalendarUnit(times, calendar) {
283
+ return INFERABLE_UNITS.find((unit) => {
284
+ let smallest = Infinity;
285
+ for (let i = 1; i < times.length; i++) {
286
+ const previous = new Date(times[i - 1]);
287
+ const time = new Date(times[i]);
288
+ const units = calendar.count(unit, previous, time);
289
+ if (units < 1 || !calendar.aligned(unit, previous, time)) return false;
290
+ smallest = Math.min(smallest, units);
291
+ }
292
+ return smallest === 1;
293
+ });
294
+ }
295
+ function resolveTemporalInterval(channel, data, mode) {
296
+ const times = [
297
+ ...new Set(data.map((row) => +temporalDate(row[channel.field])).filter(Number.isFinite))
298
+ ].sort((a, b) => a - b);
299
+ const differences = times.slice(1).map((time, i) => time - times[i]);
300
+ const smallestDifference = differences.length ? differences.reduce((smallest, difference) => Math.min(smallest, difference), Infinity) : 864e5;
301
+ const calendar = calendarFor(mode);
302
+ const value = channel.interval ?? (differences.length && smallestDifference >= MIN_CALENDAR_DAY ? inferCalendarUnit(times, calendar) : void 0) ?? smallestDifference;
303
+ const warnings = [];
304
+ const offset = (date) => typeof value === "number" ? new Date(+date + value) : calendar.offset(value, date, 1);
305
+ const aligned = times.slice(1).every((time, i) => {
306
+ const previous = times[i];
307
+ if (typeof value === "number") {
308
+ const ratio = (time - previous) / value;
309
+ return Math.abs(ratio - Math.round(ratio)) < 1e-7;
310
+ }
311
+ return calendar.aligned(value, new Date(previous), new Date(time));
312
+ });
313
+ if (!aligned)
314
+ warnings.push(
315
+ `[openchart] encoding.${channel.field}.interval ${channel.interval === void 0 ? "was inferred as" : "is"} ${value}; temporal observations are not all multiples of this interval.`
316
+ );
317
+ if (!differences.length && channel.interval === void 0)
318
+ warnings.push(
319
+ `[openchart] Cannot infer a temporal interval for "${channel.field}" from fewer than two distinct dates; using one day.`
320
+ );
321
+ return { value, offset, warnings };
322
+ }
323
+
239
324
  // src/charts/utils.ts
240
325
  import {
241
326
  adaptForLightLineStroke,
@@ -348,6 +433,27 @@ function getSequentialColor(scales, value, fallback = DEFAULT_COLOR) {
348
433
  return scales.defaultColor ?? fallback;
349
434
  }
350
435
 
436
+ // src/charts/_shared/temporal-bands.ts
437
+ function temporalBands(position, channel, data) {
438
+ const scale = position.scale;
439
+ const interval = position.temporalInterval ?? resolveTemporalInterval(channel, data, position.type);
440
+ const padding = channel.scale?.padding ?? 0.2;
441
+ return [...groupByField(data, channel.field)].flatMap(([category, rows]) => {
442
+ const date = temporalDate(rows[0][channel.field]);
443
+ const center = scale(date);
444
+ const width = Math.abs(scale(interval.offset(date)) - center) * (1 - padding);
445
+ if (!Number.isFinite(center) || !Number.isFinite(width) || width <= 0) return [];
446
+ const band = scaleBand().domain([category]).range([center - width / 2, center + width / 2]);
447
+ return [{ data: rows, position: { ...position, type: "band", scale: band } }];
448
+ });
449
+ }
450
+ function temporalGrouping(data, categoryField, colorField) {
451
+ return {
452
+ multipleRows: [...groupByField(data, categoryField).values()].some((rows) => rows.length > 1),
453
+ order: colorField ? [...new Set(data.map((row) => String(row[colorField] ?? "")))] : []
454
+ };
455
+ }
456
+
351
457
  // src/charts/bar/compute.ts
352
458
  function applyStackSeams(marks, theme) {
353
459
  const seam = stackSeamStroke(theme);
@@ -366,13 +472,28 @@ function orientGradientForHorizontalBar(grad) {
366
472
  }
367
473
  var MIN_BAR_WIDTH = 1;
368
474
  var MIN_GROUPED_BAR_THICKNESS = 8;
369
- function computeBarMarks(spec, scales, _chartArea, _strategy, containerWidth, theme) {
475
+ function computeBarMarks(spec, scales, _chartArea, _strategy, containerWidth, theme, grouping) {
370
476
  const encoding = spec.encoding;
371
477
  const xChannel = encoding.x;
372
478
  const yChannel = encoding.y;
373
479
  if (!xChannel || !yChannel || !scales.x || !scales.y) {
374
480
  return [];
375
481
  }
482
+ if (scales.y.type === "utc" || scales.y.type === "time") {
483
+ const colorField2 = encoding.color && "field" in encoding.color ? encoding.color.field : void 0;
484
+ const membership = temporalGrouping(spec.data, yChannel.field, colorField2);
485
+ return temporalBands(scales.y, yChannel, spec.data).flatMap(
486
+ (slot) => computeBarMarks(
487
+ { ...spec, data: slot.data },
488
+ { ...scales, y: slot.position },
489
+ _chartArea,
490
+ _strategy,
491
+ containerWidth,
492
+ theme,
493
+ membership
494
+ )
495
+ );
496
+ }
376
497
  const yScale = scales.y.scale;
377
498
  const xScale = scales.x.scale;
378
499
  if (typeof yScale.bandwidth !== "function") {
@@ -403,7 +524,7 @@ function computeBarMarks(spec, scales, _chartArea, _strategy, containerWidth, th
403
524
  );
404
525
  } else {
405
526
  const categoryGroups = groupByField(spec.data, yChannel.field);
406
- const needsStacking = xChannel.stack === "normalize" || xChannel.stack === "center" || Array.from(categoryGroups.values()).some((rows) => rows.length > 1);
527
+ const needsStacking = grouping?.multipleRows || xChannel.stack === "normalize" || xChannel.stack === "center" || Array.from(categoryGroups.values()).some((rows) => rows.length > 1);
407
528
  if (needsStacking) {
408
529
  const stackEnabled = xChannel.stack !== null && xChannel.stack !== false;
409
530
  if (!stackEnabled) {
@@ -417,7 +538,8 @@ function computeBarMarks(spec, scales, _chartArea, _strategy, containerWidth, th
417
538
  bandwidth,
418
539
  baseline,
419
540
  scales,
420
- containerWidth
541
+ containerWidth,
542
+ grouping?.order
421
543
  );
422
544
  } else {
423
545
  const stackMode = xChannel.stack === "normalize" ? "normalize" : xChannel.stack === "center" ? "center" : "zero";
@@ -507,15 +629,12 @@ function computeStackedBars(data, valueField, categoryField, colorField, xScale,
507
629
  }
508
630
  return marks;
509
631
  }
510
- function computeGroupedBars(data, valueField, categoryField, colorField, xScale, yScale, bandwidth, baseline, scales, containerWidth) {
632
+ function computeGroupedBars(data, valueField, categoryField, colorField, xScale, yScale, bandwidth, baseline, scales, containerWidth, groupOrder) {
511
633
  const marks = [];
512
634
  const categoryGroups = groupByField(data, categoryField);
513
635
  const groupIndexMap = /* @__PURE__ */ new Map();
514
- for (const row of data) {
515
- const key = String(row[colorField] ?? "");
516
- if (!groupIndexMap.has(key)) {
517
- groupIndexMap.set(key, groupIndexMap.size);
518
- }
636
+ for (const key of groupOrder ?? data.map((row) => String(row[colorField] ?? ""))) {
637
+ if (!groupIndexMap.has(key)) groupIndexMap.set(key, groupIndexMap.size);
519
638
  }
520
639
  const groupCount = groupIndexMap.size;
521
640
  if (groupCount === 0) return marks;
@@ -685,6 +804,15 @@ import {
685
804
  pickLabelColor,
686
805
  resolveCollisions
687
806
  } from "@opendata-ai/openchart-core";
807
+ function stackTotals(marks, valueField) {
808
+ const totals = /* @__PURE__ */ new Map();
809
+ for (const mark of marks) {
810
+ if (mark.stackGroup === void 0) continue;
811
+ const value = Math.max(0, Number(mark.data[valueField]) || 0);
812
+ totals.set(mark.stackGroup, (totals.get(mark.stackGroup) ?? 0) + value);
813
+ }
814
+ return totals;
815
+ }
688
816
  var SUFFIX_MULTIPLIERS = {
689
817
  K: 1e3,
690
818
  M: 1e6,
@@ -722,7 +850,11 @@ function computeBarLabels(marks, chartArea, density = "auto", labelFormatter, la
722
850
  const formatter = labelFormatter ?? null;
723
851
  for (const mark of targetMarks) {
724
852
  let valuePart;
725
- const rawNum = valueField != null ? Number(mark.data[valueField]) : NaN;
853
+ let rawNum = valueField != null ? Number(mark.data[valueField]) : NaN;
854
+ if (options.stackTotals && mark.stackGroup !== void 0) {
855
+ const total = options.stackTotals.get(mark.stackGroup) ?? 0;
856
+ rawNum = total > 0 ? rawNum / total : 0;
857
+ }
726
858
  if (formatter && Number.isFinite(rawNum)) {
727
859
  valuePart = formatter(rawNum);
728
860
  } else if (Number.isFinite(rawNum)) {
@@ -742,6 +874,10 @@ function computeBarLabels(marks, chartArea, density = "auto", labelFormatter, la
742
874
  }
743
875
  if (labelPrefix) valuePart = labelPrefix + valuePart;
744
876
  if (labelSuffix) valuePart = valuePart + labelSuffix;
877
+ if (options.content && options.content !== "value") {
878
+ const label = mark.seriesKey ?? String(mark.data[options.labelField ?? ""] ?? "");
879
+ valuePart = options.content === "label" ? label : `${label} ${valuePart}`;
880
+ }
745
881
  const measured = options.measureText?.(valuePart, FONT_SIZE, LABEL_FONT_WEIGHT);
746
882
  const textWidth = measured?.width ?? estimateTextWidth(valuePart, FONT_SIZE, LABEL_FONT_WEIGHT);
747
883
  const textHeight = Math.max(FONT_SIZE * 1.2, measured?.height ?? 0);
@@ -867,10 +1003,14 @@ function computeBarLabels(marks, chartArea, density = "auto", labelFormatter, la
867
1003
  var barRenderer = (spec, scales, chartArea, strategy, theme, containerWidth, labelPlan, measureText) => {
868
1004
  const marks = computeBarMarks(spec, scales, chartArea, strategy, containerWidth, theme);
869
1005
  const valueField = spec.encoding?.x && "field" in spec.encoding.x ? spec.encoding.x.field : void 0;
1006
+ const totals = valueField && spec.encoding.x?.stack === "normalize" ? stackTotals(marks, valueField) : void 0;
870
1007
  const labelFormatter = resolveFieldFormatter({
871
- surfaceFormat: spec.labels.format,
1008
+ surfaceFormat: spec.labels.format || spec.encoding.x?.format || (totals ? ".0%" : void 0),
872
1009
  channelFormat: spec.encoding?.x && "format" in spec.encoding.x ? spec.encoding.x.format : void 0,
873
- values: valueField ? spec.data.map((r) => r[valueField]) : []
1010
+ values: valueField && totals ? marks.map((mark) => {
1011
+ const total = totals.get(mark.stackGroup ?? "") ?? 0;
1012
+ return total > 0 ? Number(mark.data[valueField]) / total : 0;
1013
+ }) : valueField ? spec.data.map((r) => r[valueField]) : []
874
1014
  });
875
1015
  const labels = computeBarLabels(
876
1016
  marks,
@@ -885,6 +1025,9 @@ var barRenderer = (spec, scales, chartArea, strategy, theme, containerWidth, lab
885
1025
  spec.labels.suffix,
886
1026
  theme.fonts.family,
887
1027
  {
1028
+ content: spec.labels.content,
1029
+ labelField: spec.encoding.y?.field,
1030
+ stackTotals: totals,
888
1031
  placement: labelPlan?.placement ?? spec.labels.placement,
889
1032
  columnWidth: labelPlan?.columnWidth,
890
1033
  measureText: spec.labels.placement ? measureText : void 0
@@ -1243,7 +1386,7 @@ var binnedBarRenderer = (spec, scales, chartArea, strategy, theme) => computeBin
1243
1386
 
1244
1387
  // src/charts/calendar/compute.ts
1245
1388
  import { defaultNumberFormatter as defaultNumberFormatter3, formatDate } from "@opendata-ai/openchart-core";
1246
- import { utcDay, utcMonday, utcSunday } from "d3-time";
1389
+ import { utcDay as utcDay2, utcMonday, utcSunday } from "d3-time";
1247
1390
  var MIN_CELL_SIZE = 7;
1248
1391
  var MAX_STEP = 20;
1249
1392
  var MIN_CELL_GAP = 2;
@@ -1274,7 +1417,7 @@ function parseUtcDay(value) {
1274
1417
  if (value == null) return null;
1275
1418
  const date = value instanceof Date ? value : new Date(value);
1276
1419
  if (Number.isNaN(date.getTime())) return null;
1277
- return utcDay.floor(date);
1420
+ return utcDay2.floor(date);
1278
1421
  }
1279
1422
  function isoDayKey(day) {
1280
1423
  return day.toISOString().slice(0, 10);
@@ -1392,7 +1535,7 @@ function computeCalendarMarks(spec, scales, chartArea, theme) {
1392
1535
  aria: labelAria
1393
1536
  });
1394
1537
  }
1395
- for (const day of utcDay.range(yearStart, yearEnd)) {
1538
+ for (const day of utcDay2.range(yearStart, yearEnd)) {
1396
1539
  const col = week.count(firstWeek, day);
1397
1540
  const row = weekdayRow(day, weekStart);
1398
1541
  const key = isoDayKey(day);
@@ -1450,13 +1593,27 @@ function applyStackSeams2(marks, theme) {
1450
1593
  }
1451
1594
  }
1452
1595
  var MIN_COLUMN_HEIGHT = 1;
1453
- function computeColumnMarks(spec, scales, _chartArea, _strategy, theme) {
1596
+ function computeColumnMarks(spec, scales, _chartArea, _strategy, theme, grouping) {
1454
1597
  const encoding = spec.encoding;
1455
1598
  const xChannel = encoding.x;
1456
1599
  const yChannel = encoding.y;
1457
1600
  if (!xChannel || !yChannel || !scales.x || !scales.y) {
1458
1601
  return [];
1459
1602
  }
1603
+ if (scales.x.type === "utc" || scales.x.type === "time") {
1604
+ const colorField2 = encoding.color && "field" in encoding.color ? encoding.color.field : void 0;
1605
+ const membership = temporalGrouping(spec.data, xChannel.field, colorField2);
1606
+ return temporalBands(scales.x, xChannel, spec.data).flatMap(
1607
+ (slot) => computeColumnMarks(
1608
+ { ...spec, data: slot.data },
1609
+ { ...scales, x: slot.position },
1610
+ _chartArea,
1611
+ _strategy,
1612
+ theme,
1613
+ membership
1614
+ )
1615
+ );
1616
+ }
1460
1617
  const xScale = scales.x.scale;
1461
1618
  const yScale = scales.y.scale;
1462
1619
  if (typeof xScale.bandwidth !== "function") {
@@ -1474,7 +1631,7 @@ function computeColumnMarks(spec, scales, _chartArea, _strategy, theme) {
1474
1631
  let marks;
1475
1632
  if (colorField && !isSequentialColor) {
1476
1633
  const categoryGroups = groupByField(spec.data, xChannel.field);
1477
- const needsStacking = yChannel.stack === "normalize" || yChannel.stack === "center" || Array.from(categoryGroups.values()).some((rows) => rows.length > 1);
1634
+ const needsStacking = grouping?.multipleRows || yChannel.stack === "normalize" || yChannel.stack === "center" || Array.from(categoryGroups.values()).some((rows) => rows.length > 1);
1478
1635
  if (needsStacking) {
1479
1636
  const stackEnabled = yChannel.stack !== null && yChannel.stack !== false;
1480
1637
  if (!stackEnabled) {
@@ -1487,7 +1644,8 @@ function computeColumnMarks(spec, scales, _chartArea, _strategy, theme) {
1487
1644
  yScale,
1488
1645
  bandwidth,
1489
1646
  baseline,
1490
- scales
1647
+ scales,
1648
+ grouping?.order
1491
1649
  );
1492
1650
  } else {
1493
1651
  const stackMode = yChannel.stack === "normalize" ? "normalize" : yChannel.stack === "center" ? "center" : "zero";
@@ -1623,15 +1781,12 @@ function computeColoredColumns(data, categoryField, valueField, colorField, xSca
1623
1781
  }
1624
1782
  return marks;
1625
1783
  }
1626
- function computeGroupedColumns(data, categoryField, valueField, colorField, xScale, yScale, bandwidth, baseline, scales) {
1784
+ function computeGroupedColumns(data, categoryField, valueField, colorField, xScale, yScale, bandwidth, baseline, scales, groupOrder) {
1627
1785
  const marks = [];
1628
1786
  const categoryGroups = groupByField(data, categoryField);
1629
1787
  const groupIndexMap = /* @__PURE__ */ new Map();
1630
- for (const row of data) {
1631
- const key = String(row[colorField] ?? "");
1632
- if (!groupIndexMap.has(key)) {
1633
- groupIndexMap.set(key, groupIndexMap.size);
1634
- }
1788
+ for (const key of groupOrder ?? data.map((row) => String(row[colorField] ?? ""))) {
1789
+ if (!groupIndexMap.has(key)) groupIndexMap.set(key, groupIndexMap.size);
1635
1790
  }
1636
1791
  const groupCount = groupIndexMap.size;
1637
1792
  if (groupCount === 0) return marks;
@@ -1780,7 +1935,11 @@ function computeColumnLabels(marks, _chartArea, density = "auto", labelFormatter
1780
1935
  const fitsInSegment = [];
1781
1936
  for (const mark of targetMarks) {
1782
1937
  let valuePart;
1783
- const rawNum = valueField != null ? Number(mark.data[valueField]) : NaN;
1938
+ let rawNum = valueField != null ? Number(mark.data[valueField]) : NaN;
1939
+ if (options.stackTotals && mark.stackGroup !== void 0) {
1940
+ const total = options.stackTotals.get(mark.stackGroup) ?? 0;
1941
+ rawNum = total > 0 ? rawNum / total : 0;
1942
+ }
1784
1943
  if (formatter && Number.isFinite(rawNum)) {
1785
1944
  valuePart = formatter(rawNum);
1786
1945
  } else if (Number.isFinite(rawNum)) {
@@ -1802,6 +1961,10 @@ function computeColumnLabels(marks, _chartArea, density = "auto", labelFormatter
1802
1961
  const isNegative = Number.isFinite(rawNum) ? rawNum < 0 : Number.isFinite(numericValue) && numericValue < 0;
1803
1962
  if (labelPrefix) valuePart = labelPrefix + valuePart;
1804
1963
  if (labelSuffix) valuePart = valuePart + labelSuffix;
1964
+ if (options.content && options.content !== "value") {
1965
+ const label = mark.seriesKey ?? String(mark.data[options.labelField ?? ""] ?? "");
1966
+ valuePart = options.content === "label" ? label : `${label} ${valuePart}`;
1967
+ }
1805
1968
  const measured = options.measureText?.(valuePart, FONT_SIZE, LABEL_FONT_WEIGHT2);
1806
1969
  const textWidth = measured?.width ?? estimateTextWidth2(valuePart, FONT_SIZE, LABEL_FONT_WEIGHT2);
1807
1970
  const textHeight = Math.max(FONT_SIZE * 1.2, measured?.height ?? 0);
@@ -1897,10 +2060,14 @@ function computeColumnLabels(marks, _chartArea, density = "auto", labelFormatter
1897
2060
  var columnRenderer = (spec, scales, chartArea, strategy, theme, _containerWidth, labelPlan, measureText) => {
1898
2061
  const marks = computeColumnMarks(spec, scales, chartArea, strategy, theme);
1899
2062
  const valueField = spec.encoding?.y && "field" in spec.encoding.y ? spec.encoding.y.field : void 0;
2063
+ const totals = valueField && spec.encoding.y?.stack === "normalize" ? stackTotals(marks, valueField) : void 0;
1900
2064
  const labelFormatter = resolveFieldFormatter({
1901
- surfaceFormat: spec.labels.format,
2065
+ surfaceFormat: spec.labels.format || spec.encoding.y?.format || (totals ? ".0%" : void 0),
1902
2066
  channelFormat: spec.encoding?.y && "format" in spec.encoding.y ? spec.encoding.y.format : void 0,
1903
- values: valueField ? spec.data.map((r) => r[valueField]) : []
2067
+ values: valueField && totals ? marks.map((mark) => {
2068
+ const total = totals.get(mark.stackGroup ?? "") ?? 0;
2069
+ return total > 0 ? Number(mark.data[valueField]) / total : 0;
2070
+ }) : valueField ? spec.data.map((r) => r[valueField]) : []
1904
2071
  });
1905
2072
  const labels = computeColumnLabels(
1906
2073
  marks,
@@ -1915,6 +2082,9 @@ var columnRenderer = (spec, scales, chartArea, strategy, theme, _containerWidth,
1915
2082
  spec.labels.suffix,
1916
2083
  theme.fonts.family,
1917
2084
  {
2085
+ content: spec.labels.content,
2086
+ labelField: spec.encoding.x?.field,
2087
+ stackTotals: totals,
1918
2088
  placement: labelPlan?.placement ?? spec.labels.placement,
1919
2089
  columnWidth: labelPlan?.columnWidth,
1920
2090
  measureText: spec.labels.placement ? measureText : void 0
@@ -2188,11 +2358,85 @@ var dotRenderer = (spec, scales, chartArea, strategy, theme) => {
2188
2358
  return marks;
2189
2359
  };
2190
2360
 
2361
+ // src/charts/errorbar/compute.ts
2362
+ import { getRepresentativeColor as getRepresentativeColor5 } from "@opendata-ai/openchart-core";
2363
+
2364
+ // src/charts/errorbar/constants.ts
2365
+ var ERRORBAR_STROKE_WIDTH = 2;
2366
+ var ERRORBAR_CAP_LENGTH = 6;
2367
+ var ERRORBAR_OPACITY = 0.35;
2368
+
2369
+ // src/charts/errorbar/compute.ts
2370
+ function computeErrorbarMarks(spec, scales, _chartArea) {
2371
+ const { x, y, x2, y2 } = spec.encoding;
2372
+ if (!x || !y || !scales.x || !scales.y) return [];
2373
+ const horizontal = !!x2;
2374
+ const bound = horizontal ? x2 : y2;
2375
+ if (!bound) return [];
2376
+ const axis = horizontal ? scales.x : scales.y;
2377
+ const category = horizontal ? scales.y : scales.x;
2378
+ const valueField = horizontal ? x.field : y.field;
2379
+ const categoryField = horizontal ? y.field : x.field;
2380
+ const color = spec.encoding.color;
2381
+ const marks = [];
2382
+ const keys = dedupeKeys(
2383
+ spec.data.map((row) => serializeKeyValue(row[spec.encoding.key?.field ?? categoryField]))
2384
+ );
2385
+ for (const [index, row] of spec.data.entries()) {
2386
+ const lower = scaleValue(axis.scale, axis.type, row[valueField]);
2387
+ const upper = scaleValue(axis.scale, axis.type, row[bound.field]);
2388
+ let center = scaleValue(category.scale, category.type, row[categoryField]);
2389
+ if (lower === null || upper === null || center === null) continue;
2390
+ if (category.type === "band")
2391
+ center += category.scale.bandwidth() / 2;
2392
+ const stroke = spec.markDef.stroke ?? getRepresentativeColor5(
2393
+ getColor(scales, color && "field" in color ? String(row[color.field]) : "__default__")
2394
+ );
2395
+ const suppliedOpacity = spec.encoding.opacity && "field" in spec.encoding.opacity ? finiteNumber(row[spec.encoding.opacity.field]) : finiteNumber(spec.markDef.opacity);
2396
+ const opacity = Math.max(0, Math.min(1, suppliedOpacity ?? ERRORBAR_OPACITY));
2397
+ const common = {
2398
+ stroke,
2399
+ strokeWidth: spec.markDef.strokeWidth ?? ERRORBAR_STROKE_WIDTH,
2400
+ opacity,
2401
+ data: row
2402
+ };
2403
+ const whisker = {
2404
+ ...common,
2405
+ type: "rule",
2406
+ key: keys[index],
2407
+ x1: horizontal ? lower : center,
2408
+ x2: horizontal ? upper : center,
2409
+ y1: horizontal ? center : lower,
2410
+ y2: horizontal ? center : upper,
2411
+ aria: { label: `${row[categoryField]}: ${row[valueField]} to ${row[bound.field]}` }
2412
+ };
2413
+ marks.push(whisker);
2414
+ if (spec.markDef.ticks)
2415
+ for (const [end, position] of [lower, upper].entries()) {
2416
+ const cap = {
2417
+ ...common,
2418
+ type: "tick",
2419
+ key: `${keys[index]}|cap:${end}`,
2420
+ x: horizontal ? position : center,
2421
+ y: horizontal ? center : position,
2422
+ orient: horizontal ? "vertical" : "horizontal",
2423
+ length: ERRORBAR_CAP_LENGTH,
2424
+ aria: { decorative: true }
2425
+ };
2426
+ marks.push(cap);
2427
+ }
2428
+ }
2429
+ return marks;
2430
+ }
2431
+
2432
+ // src/charts/errorbar/index.ts
2433
+ var errorbarRenderer = (spec, scales, area3) => computeErrorbarMarks(spec, scales, area3);
2434
+
2191
2435
  // src/charts/line/index.ts
2192
- import { getRepresentativeColor as getRepresentativeColor7 } from "@opendata-ai/openchart-core";
2436
+ import { getRepresentativeColor as getRepresentativeColor8 } from "@opendata-ai/openchart-core";
2193
2437
 
2194
2438
  // src/charts/line/area.ts
2195
- import { getRepresentativeColor as getRepresentativeColor6, isGradientDef as isGradientDef3 } from "@opendata-ai/openchart-core";
2439
+ import { getRepresentativeColor as getRepresentativeColor7, isGradientDef as isGradientDef3 } from "@opendata-ai/openchart-core";
2196
2440
  import { area as area2, line as line3 } from "d3-shape";
2197
2441
 
2198
2442
  // src/data/area-stack.ts
@@ -2266,7 +2510,7 @@ function computeAreaStack(data, xField, yField, colorField, xType, offset, cache
2266
2510
  }
2267
2511
 
2268
2512
  // src/charts/line/compute.ts
2269
- import { getRepresentativeColor as getRepresentativeColor5 } from "@opendata-ai/openchart-core";
2513
+ import { getRepresentativeColor as getRepresentativeColor6 } from "@opendata-ai/openchart-core";
2270
2514
  import { line as line2 } from "d3-shape";
2271
2515
 
2272
2516
  // src/charts/line/curves.ts
@@ -2369,9 +2613,9 @@ function computeLineMarks(spec, scales, _chartArea, _strategy, theme) {
2369
2613
  }
2370
2614
  continue;
2371
2615
  }
2372
- const point = { x: xVal, y: yVal };
2616
+ const point = { x: xVal, y: yVal, row };
2373
2617
  currentSegment.push(point);
2374
- pointsWithData.push({ ...point, row });
2618
+ pointsWithData.push(point);
2375
2619
  }
2376
2620
  if (currentSegment.length > 0) {
2377
2621
  segments2.push(currentSegment);
@@ -2380,15 +2624,19 @@ function computeLineMarks(spec, scales, _chartArea, _strategy, theme) {
2380
2624
  const lineGenerator = line2().x((d) => d.x).y((d) => d.y).curve(curve);
2381
2625
  const allPoints = [];
2382
2626
  const pathParts = [];
2627
+ const isolatedRows = new Set(
2628
+ segments2.filter((segment) => segment.length === 1).map((segment) => segment[0].row)
2629
+ );
2630
+ const linePointsWithData = pointsWithData.filter((point) => !isolatedRows.has(point.row));
2383
2631
  for (const segment of segments2) {
2384
- if (segment.length === 0) continue;
2632
+ if (segment.length < 2) continue;
2385
2633
  const pathStr = lineGenerator(segment);
2386
2634
  if (pathStr) {
2387
2635
  pathParts.push(pathStr);
2388
2636
  }
2389
2637
  allPoints.push(...segment);
2390
2638
  }
2391
- if (allPoints.length === 0) continue;
2639
+ if (pointsWithData.length === 0) continue;
2392
2640
  const ariaLabel = seriesKey === "__default__" ? `Line with ${allPoints.length} data points` : `${seriesKey}: line with ${allPoints.length} data points`;
2393
2641
  const aria = {
2394
2642
  label: ariaLabel
@@ -2410,7 +2658,7 @@ function computeLineMarks(spec, scales, _chartArea, _strategy, theme) {
2410
2658
  if (pattern) strokeDasharray = pattern;
2411
2659
  }
2412
2660
  const keyField = encoding.key && "field" in encoding.key ? encoding.key.field : void 0;
2413
- const rawPointKeys = pointsWithData.map(
2661
+ const rawPointKeys = linePointsWithData.map(
2414
2662
  (p) => keyField ? serializeKeyValue(p.row[keyField]) : serializeKeyValue(p.row[xChannel.field])
2415
2663
  );
2416
2664
  const lineMark = {
@@ -2425,39 +2673,47 @@ function computeLineMarks(spec, scales, _chartArea, _strategy, theme) {
2425
2673
  strokeDasharray,
2426
2674
  opacity: styleOverride?.opacity,
2427
2675
  seriesKey: seriesStyleKey,
2428
- data: pointsWithData.map((p) => p.row),
2429
- dataPoints: pointsWithData.map((p) => ({ x: p.x, y: p.y, datum: p.row })),
2676
+ data: linePointsWithData.map((p) => p.row),
2677
+ dataPoints: linePointsWithData.map((p) => ({ x: p.x, y: p.y, datum: p.row })),
2430
2678
  aria
2431
2679
  };
2432
2680
  const bucket = isMuted ? mutedMarks : highlightedMarks;
2433
- bucket.push(lineMark);
2681
+ if (allPoints.length > 1) bucket.push(lineMark);
2434
2682
  const markPoint = spec.markDef.point;
2435
2683
  const isSingleEndpoint = markPoint === "last" || markPoint === "first";
2436
2684
  const showPoints = markPoint === true || markPoint === "transparent" || markPoint === "endpoints" || isSingleEndpoint || isSequentialColor;
2437
- if (showPoints) {
2685
+ if (showPoints || isolatedRows.size > 0) {
2438
2686
  const isTransparent = markPoint === "transparent";
2439
2687
  const isEndpoints = markPoint === "endpoints";
2440
2688
  const seriesShowPoints = styleOverride?.showPoints !== false;
2441
2689
  const lastIdx = pointsWithData.length - 1;
2442
2690
  for (let i = 0; i < pointsWithData.length; i++) {
2443
2691
  const p = pointsWithData[i];
2692
+ const isolated = isolatedRows.has(p.row);
2693
+ if (isolated && markPoint === false) {
2694
+ spec.markWarnings?.push(
2695
+ `[openchart] Isolated point in series "${seriesKey}" at index ${i} is hidden by point: false.`
2696
+ );
2697
+ continue;
2698
+ }
2699
+ if (!isolated && !showPoints) continue;
2444
2700
  const isEndpoint = i === 0 || i === lastIdx;
2445
2701
  const isLast = i === lastIdx;
2446
2702
  const isFirst = i === 0;
2447
- if (isSingleEndpoint) {
2703
+ if (isSingleEndpoint && !isolated) {
2448
2704
  if (markPoint === "last" && !isLast) continue;
2449
2705
  if (markPoint === "first" && !isFirst) continue;
2450
2706
  }
2451
- const visible = seriesShowPoints && !isTransparent && (!isEndpoints || isEndpoint);
2707
+ const visible = isolated || seriesShowPoints && !isTransparent && (!isEndpoints || isEndpoint);
2452
2708
  let pointColor = color;
2453
2709
  if (isSequentialColor) {
2454
2710
  const value = finiteNumber(p.row[sequentialColorField]);
2455
2711
  pointColor = value !== void 0 ? getSequentialColor(scales, value) : color;
2456
2712
  }
2457
- const hollow = isEndpoints && visible;
2458
- const pointColorStr = getRepresentativeColor5(pointColor);
2713
+ const hollow = !isolated && isEndpoints && visible;
2714
+ const pointColorStr = getRepresentativeColor6(pointColor);
2459
2715
  const pointKey = keyField ? serializeKeyValue(p.row[keyField]) : seriesStyleKey ? `${seriesStyleKey}|${serializeKeyValue(p.row[xChannel.field])}` : serializeKeyValue(p.row[xChannel.field]);
2460
- if (isSingleEndpoint) {
2716
+ if (isSingleEndpoint && !isolated) {
2461
2717
  bucket.push({
2462
2718
  type: "point",
2463
2719
  key: pointKey,
@@ -2475,6 +2731,7 @@ function computeLineMarks(spec, scales, _chartArea, _strategy, theme) {
2475
2731
  }
2476
2732
  const pointMark = {
2477
2733
  type: "point",
2734
+ ...isolated && seriesStyleKey !== void 0 ? { seriesKey: seriesStyleKey } : {},
2478
2735
  key: pointKey,
2479
2736
  cx: p.x,
2480
2737
  cy: p.y,
@@ -2482,7 +2739,7 @@ function computeLineMarks(spec, scales, _chartArea, _strategy, theme) {
2482
2739
  fill: hollow ? "transparent" : pointColorStr,
2483
2740
  stroke: hollow ? pointColorStr : visible ? pointSeparator : "transparent",
2484
2741
  strokeWidth: visible ? 1.5 : 0,
2485
- fillOpacity: isTransparent ? 0 : 1,
2742
+ fillOpacity: isTransparent && !isolated ? 0 : 1,
2486
2743
  data: p.row,
2487
2744
  aria: {
2488
2745
  label: `Data point: ${xChannel.field}=${String(p.row[xChannel.field])}, ${yChannel.field}=${String(p.row[yChannel.field])}`
@@ -2581,16 +2838,17 @@ function computeSingleArea(spec, scales, _chartArea, theme) {
2581
2838
  if (segments2[segments2.length - 1].length > 0) segments2.push([]);
2582
2839
  continue;
2583
2840
  }
2584
- const point = { x: xVal, yTop: yVal, yBottom: yBottomVal, row };
2841
+ const point = { x: xVal, yTop: yVal, yBottom: yBottomVal, row, segment: segments2.length - 1 };
2585
2842
  validPoints.push(point);
2586
2843
  segments2[segments2.length - 1].push(point);
2587
2844
  }
2588
2845
  if (validPoints.length === 0) continue;
2589
2846
  const curve = resolveCurve(spec.markDef.interpolate);
2590
2847
  const areaGenerator = area2().x((d) => d.x).y0((d) => d.yBottom).y1((d) => d.yTop).curve(curve);
2591
- const pathStr = segments2.map((segment) => areaGenerator(segment) ?? "").join(" ");
2848
+ const bandSegments = segments2.filter((segment) => segment.length > 1);
2849
+ const pathStr = bandSegments.map((segment) => areaGenerator(segment) ?? "").join(" ");
2592
2850
  const topLineGenerator = line3().x((d) => d.x).y((d) => d.yTop).curve(curve);
2593
- const topPathStr = segments2.map((segment) => topLineGenerator(segment) ?? "").join(" ");
2851
+ const topPathStr = bandSegments.map((segment) => topLineGenerator(segment) ?? "").join(" ");
2594
2852
  const topPoints = validPoints.map((p) => ({ x: p.x, y: p.yTop }));
2595
2853
  const bottomPoints = validPoints.map((p) => ({ x: p.x, y: p.yBottom }));
2596
2854
  const ariaLabel = seriesKey === "__default__" ? `Area with ${validPoints.length} data points` : `${seriesKey}: area with ${validPoints.length} data points`;
@@ -2602,10 +2860,10 @@ function computeSingleArea(spec, scales, _chartArea, theme) {
2602
2860
  fillValue = markFill;
2603
2861
  fillOpacity = isGradientDef3(markFill) ? 1 : spec.markDef.fillOpacity ?? spec.markDef.opacity ?? (y2Channel ? 0.25 : DEFAULT_FILL_OPACITY);
2604
2862
  } else if (spec.markDef.fillOpacity != null) {
2605
- fillValue = getRepresentativeColor6(color);
2863
+ fillValue = getRepresentativeColor7(color);
2606
2864
  fillOpacity = spec.markDef.fillOpacity;
2607
2865
  } else {
2608
- const colorStr = getRepresentativeColor6(color);
2866
+ const colorStr = getRepresentativeColor7(color);
2609
2867
  fillValue = buildGradientFill(colorStr, defaultGradientStops);
2610
2868
  fillOpacity = 1;
2611
2869
  }
@@ -2632,7 +2890,7 @@ function computeSingleArea(spec, scales, _chartArea, theme) {
2632
2890
  strokeWidth: spec.markDef.strokeWidth ?? LINE_STROKE_WIDTH,
2633
2891
  seriesKey: seriesKey === "__default__" ? void 0 : seriesKey,
2634
2892
  data: validPoints.map((p) => p.row),
2635
- dataPoints: validPoints.map((p) => ({ x: p.x, y: p.yTop, datum: p.row })),
2893
+ dataPoints: validPoints.map((p) => ({ x: p.x, y: p.yTop, datum: p.row, segment: p.segment })),
2636
2894
  aria
2637
2895
  });
2638
2896
  }
@@ -2688,9 +2946,10 @@ function computeStackedArea(spec, scales, chartArea, theme) {
2688
2946
  if (validPoints.length === 0) continue;
2689
2947
  const stackCurve = resolveCurve(spec.markDef.interpolate);
2690
2948
  const areaGenerator = area2().x((p) => p.x).y0((p) => p.yBottom).y1((p) => p.yTop).curve(stackCurve);
2691
- const pathStr = segments2.map((segment) => areaGenerator(segment) ?? "").join(" ");
2949
+ const bandSegments = segments2.filter((segment) => segment.length > 1);
2950
+ const pathStr = bandSegments.map((segment) => areaGenerator(segment) ?? "").join(" ");
2692
2951
  const topLineGenerator = line3().x((p) => p.x).y((p) => p.yTop).curve(stackCurve);
2693
- const topPathStr = segments2.map((segment) => topLineGenerator(segment) ?? "").join(" ");
2952
+ const topPathStr = bandSegments.map((segment) => topLineGenerator(segment) ?? "").join(" ");
2694
2953
  const topPoints = validPoints.map((p) => ({ x: p.x, y: p.yTop }));
2695
2954
  const bottomPoints = validPoints.map((p) => ({ x: p.x, y: p.yBottom }));
2696
2955
  const aria = {
@@ -2703,7 +2962,7 @@ function computeStackedArea(spec, scales, chartArea, theme) {
2703
2962
  fillValue = markFill;
2704
2963
  fillOpacity = isGradientDef3(markFill) ? 1 : spec.markDef.fillOpacity ?? spec.markDef.opacity ?? 0.7;
2705
2964
  } else {
2706
- fillValue = getRepresentativeColor6(color);
2965
+ fillValue = getRepresentativeColor7(color);
2707
2966
  fillOpacity = spec.markDef.fillOpacity ?? STACKED_FILL_OPACITY;
2708
2967
  }
2709
2968
  const rawPointKeys = validPoints.map((point) => serializeKeyValue(point.xKey));
@@ -2737,7 +2996,7 @@ function computeStackedArea(spec, scales, chartArea, theme) {
2737
2996
  }
2738
2997
  return marks;
2739
2998
  }
2740
- function computeAreaMarks(spec, scales, chartArea, theme) {
2999
+ function computeAreaGeometry(spec, scales, chartArea, theme) {
2741
3000
  const encoding = spec.encoding;
2742
3001
  const yChannel = encoding.y;
2743
3002
  let marks;
@@ -2770,12 +3029,75 @@ var lineRenderer = (spec, scales, chartArea, strategy, theme) => {
2770
3029
  return marks;
2771
3030
  };
2772
3031
  var areaRenderer = (spec, scales, chartArea, strategy, theme) => {
2773
- const areas = computeAreaMarks(spec, scales, chartArea, theme);
3032
+ const geometry2 = computeAreaGeometry(spec, scales, chartArea, theme);
3033
+ const areas = geometry2.filter((mark) => !!mark.path?.trim());
2774
3034
  const encoding = spec.encoding;
2775
3035
  const hasColor = !!(encoding.color && "field" in encoding.color);
2776
3036
  const lines = hasColor ? linesFromAreas(areas) : computeLineMarks(spec, scales, chartArea, strategy, theme);
2777
3037
  const points = hasColor && spec.markDef.point ? pointsFromAreas(areas, spec.markDef.point, resolveKnockoutColor(theme)) : [];
2778
- return [...areas, ...lines, ...points];
3038
+ const isolatedPoints = [];
3039
+ if (hasColor)
3040
+ for (const area3 of geometry2) {
3041
+ const counts = /* @__PURE__ */ new Map();
3042
+ for (const point of area3.dataPoints ?? [])
3043
+ counts.set(point.segment ?? 0, (counts.get(point.segment ?? 0) ?? 0) + 1);
3044
+ for (const [index, point] of (area3.dataPoints ?? []).entries()) {
3045
+ if (counts.get(point.segment ?? 0) !== 1 || point.observed === false) continue;
3046
+ if (spec.markDef.point === false) {
3047
+ spec.markWarnings?.push(
3048
+ `[openchart] Isolated point in series "${area3.seriesKey ?? "series"}" at index ${index} is hidden by point: false.`
3049
+ );
3050
+ continue;
3051
+ }
3052
+ isolatedPoints.push({
3053
+ type: "point",
3054
+ ...area3.seriesKey !== void 0 ? { seriesKey: area3.seriesKey } : {},
3055
+ key: area3.pointKeys?.[index],
3056
+ cx: point.x,
3057
+ cy: point.y,
3058
+ r: AREA_POINT_RADIUS,
3059
+ fill: area3.stroke ?? getRepresentativeColor8(area3.fill),
3060
+ stroke: resolveKnockoutColor(theme),
3061
+ strokeWidth: 1.5,
3062
+ data: point.datum,
3063
+ aria: {
3064
+ label: `${area3.seriesKey ?? "Series"}: ${point.datum[spec.encoding.y?.field ?? ""]}`
3065
+ }
3066
+ });
3067
+ }
3068
+ }
3069
+ const isolatedIntervals = [];
3070
+ if (!hasColor && encoding.y2 && "field" in encoding.y2)
3071
+ for (const area3 of geometry2) {
3072
+ const counts = /* @__PURE__ */ new Map();
3073
+ for (const point of area3.dataPoints ?? [])
3074
+ counts.set(point.segment ?? 0, (counts.get(point.segment ?? 0) ?? 0) + 1);
3075
+ for (const [index, point] of (area3.dataPoints ?? []).entries()) {
3076
+ if (counts.get(point.segment ?? 0) !== 1) continue;
3077
+ isolatedIntervals.push({
3078
+ type: "rule",
3079
+ key: area3.pointKeys?.[index],
3080
+ x1: point.x,
3081
+ y1: point.y,
3082
+ x2: point.x,
3083
+ y2: area3.bottomPoints[index]?.y ?? point.y,
3084
+ stroke: area3.stroke ?? getRepresentativeColor8(area3.fill),
3085
+ strokeWidth: area3.strokeWidth ?? 1,
3086
+ data: point.datum,
3087
+ aria: {
3088
+ label: `Interval: ${point.datum[encoding.y?.field ?? ""]} to ${point.datum[encoding.y2.field]}`
3089
+ }
3090
+ });
3091
+ }
3092
+ }
3093
+ const intervalRows = new Set(isolatedIntervals.map((rule) => rule.data));
3094
+ return [
3095
+ ...areas,
3096
+ ...intervalRows.size ? lines.filter((mark) => mark.type !== "point" || !intervalRows.has(mark.data)) : lines,
3097
+ ...isolatedIntervals,
3098
+ ...points.filter((point) => !isolatedPoints.some((isolated) => isolated.data === point.data)),
3099
+ ...isolatedPoints
3100
+ ];
2779
3101
  };
2780
3102
  function linesFromAreas(areas) {
2781
3103
  return areas.map((a) => ({
@@ -2785,7 +3107,7 @@ function linesFromAreas(areas) {
2785
3107
  // The area already resolved its top-edge stroke (palette color, adapted
2786
3108
  // for a light canvas, or the author's markDef.stroke). Re-deriving it from
2787
3109
  // the fill here would paint an unadapted line over the adapted top path.
2788
- stroke: a.stroke ?? getRepresentativeColor7(a.fill),
3110
+ stroke: a.stroke ?? getRepresentativeColor8(a.fill),
2789
3111
  strokeWidth: a.strokeWidth ?? 1,
2790
3112
  seriesKey: a.seriesKey,
2791
3113
  data: a.data,
@@ -2798,7 +3120,7 @@ function pointsFromAreas(areas, pointMode, separator) {
2798
3120
  const isEndpoints = pointMode === "endpoints";
2799
3121
  const points = [];
2800
3122
  for (const a of areas) {
2801
- const stroke = a.stroke ?? getRepresentativeColor7(a.fill);
3123
+ const stroke = a.stroke ?? getRepresentativeColor8(a.fill);
2802
3124
  const lastIdx = a.topPoints.length - 1;
2803
3125
  for (let i = 0; i < a.topPoints.length; i++) {
2804
3126
  const pt = a.topPoints[i];
@@ -3341,7 +3663,7 @@ var donutRenderer = (spec, scales, chartArea, strategy, theme) => {
3341
3663
  };
3342
3664
 
3343
3665
  // src/charts/range/compute.ts
3344
- import { getRepresentativeColor as getRepresentativeColor8 } from "@opendata-ai/openchart-core";
3666
+ import { getRepresentativeColor as getRepresentativeColor9 } from "@opendata-ai/openchart-core";
3345
3667
 
3346
3668
  // src/annotations/geometry.ts
3347
3669
  import { estimateTextWidth as estimateTextWidth5 } from "@opendata-ai/openchart-core";
@@ -3763,7 +4085,7 @@ function computeRangeMarks(spec, scales, _chartArea, _strategy, theme) {
3763
4085
  const delta = endVal - startVal;
3764
4086
  const catKey = catKeys[i];
3765
4087
  const accent = colorEnc ? getColor(scales, String(row[colorEnc.field] ?? "")) : colorByDirection ? delta > 0 ? theme.colors.positive : delta < 0 ? theme.colors.negative : theme.colors.axis : getColor(scales, "__default__");
3766
- const accentStroke = getRepresentativeColor8(accent);
4088
+ const accentStroke = getRepresentativeColor9(accent);
3767
4089
  const spanAria = {
3768
4090
  label: `${category}: ${startVal} to ${endVal}`
3769
4091
  };
@@ -3888,29 +4210,36 @@ function computeRangeMarks(spec, scales, _chartArea, _strategy, theme) {
3888
4210
  // src/charts/range/labels.ts
3889
4211
  import {
3890
4212
  estimateTextWidth as estimateTextWidth6,
3891
- getRepresentativeColor as getRepresentativeColor9,
4213
+ getRepresentativeColor as getRepresentativeColor10,
3892
4214
  resolveCollisions as resolveCollisions5
3893
4215
  } from "@opendata-ai/openchart-core";
3894
- var LABEL_FONT_SIZE5 = 11;
3895
- var LABEL_FONT_WEIGHT5 = 600;
3896
- var LABEL_OFFSET = 10;
4216
+ var RANGE_LABEL_FONT_SIZE = 11;
4217
+ var RANGE_LABEL_FONT_WEIGHT = 600;
4218
+ var RANGE_LABEL_OFFSET = 10;
3897
4219
  function formatEndpoint(value, formatter, prefix) {
3898
4220
  const num = Number(value);
3899
4221
  if (!Number.isFinite(num)) return null;
3900
4222
  const text = formatter ? formatter(num) : formatLabelValue(num);
3901
4223
  return prefix ? prefix + text : text;
3902
4224
  }
3903
- function buildCandidate(mark, text, horizontal, outerSide, index, fontFamily) {
3904
- const textWidth = estimateTextWidth6(text, LABEL_FONT_SIZE5, LABEL_FONT_WEIGHT5);
3905
- const textHeight = LABEL_FONT_SIZE5 * 1.2;
4225
+ function rangeEndpointText(value, formatter, prefix, content, title, suffix) {
4226
+ const formatted = formatEndpoint(value, formatter, prefix);
4227
+ if (formatted === null) return null;
4228
+ const number = content === void 0 ? formatted : `${formatted}${suffix ?? ""}`;
4229
+ return content === "label" ? title : content === "label value" ? `${title} ${number}` : number;
4230
+ }
4231
+ function buildCandidate(mark, text, horizontal, outerSide, index, fontFamily, measureText) {
4232
+ const measured = measureText?.(text, RANGE_LABEL_FONT_SIZE, RANGE_LABEL_FONT_WEIGHT);
4233
+ const textWidth = measured?.width ?? estimateTextWidth6(text, RANGE_LABEL_FONT_SIZE, RANGE_LABEL_FONT_WEIGHT);
4234
+ const textHeight = Math.max(RANGE_LABEL_FONT_SIZE * 1.2, measured?.height ?? 0);
3906
4235
  let anchorX;
3907
4236
  let anchorY;
3908
4237
  if (horizontal) {
3909
- anchorX = outerSide === "min" ? mark.cx - mark.r - LABEL_OFFSET - textWidth : mark.cx + mark.r + LABEL_OFFSET;
4238
+ anchorX = outerSide === "min" ? mark.cx - mark.r - RANGE_LABEL_OFFSET - textWidth : mark.cx + mark.r + RANGE_LABEL_OFFSET;
3910
4239
  anchorY = mark.cy - textHeight / 2;
3911
4240
  } else {
3912
4241
  anchorX = mark.cx - textWidth / 2;
3913
- anchorY = outerSide === "min" ? mark.cy + mark.r + LABEL_OFFSET - textHeight / 2 : mark.cy - mark.r - LABEL_OFFSET - textHeight / 2;
4242
+ anchorY = outerSide === "min" ? mark.cy + mark.r + RANGE_LABEL_OFFSET - textHeight / 2 : mark.cy - mark.r - RANGE_LABEL_OFFSET - textHeight / 2;
3914
4243
  }
3915
4244
  return {
3916
4245
  text,
@@ -3922,9 +4251,9 @@ function buildCandidate(mark, text, horizontal, outerSide, index, fontFamily) {
3922
4251
  index,
3923
4252
  style: {
3924
4253
  fontFamily,
3925
- fontSize: LABEL_FONT_SIZE5,
3926
- fontWeight: LABEL_FONT_WEIGHT5,
3927
- fill: getRepresentativeColor9(mark.fill),
4254
+ fontSize: RANGE_LABEL_FONT_SIZE,
4255
+ fontWeight: RANGE_LABEL_FONT_WEIGHT,
4256
+ fill: getRepresentativeColor10(mark.fill),
3928
4257
  lineHeight: 1.2,
3929
4258
  textAnchor: "start",
3930
4259
  dominantBaseline: "central",
@@ -3932,16 +4261,30 @@ function buildCandidate(mark, text, horizontal, outerSide, index, fontFamily) {
3932
4261
  }
3933
4262
  };
3934
4263
  }
3935
- function computeRangeLabels(pairs, horizontal, density = "auto", labelPrefix, labelFormatter, startField, endField, fontFamily = "system-ui, -apple-system, sans-serif") {
4264
+ function computeRangeLabels(pairs, horizontal, density = "auto", labelPrefix, labelFormatter, startField, endField, fontFamily = "system-ui, -apple-system, sans-serif", options = {}) {
3936
4265
  if (density === "none" || !startField || !endField) return [];
3937
4266
  const indexed = pairs.map((pair, pairIndex) => ({ pair, pairIndex }));
3938
4267
  const targetPairs = filterByDensity(indexed, density);
3939
4268
  const formatter = labelFormatter ?? null;
3940
4269
  const candidates = [];
3941
4270
  for (const { pair, pairIndex } of targetPairs) {
3942
- const startText = formatEndpoint(pair.start.data[startField], formatter, labelPrefix);
3943
- const endText = formatEndpoint(pair.end.data[endField], formatter, labelPrefix);
3944
- if (startText == null || endText == null) continue;
4271
+ const startText = rangeEndpointText(
4272
+ pair.start.data[startField],
4273
+ formatter,
4274
+ labelPrefix,
4275
+ options.content,
4276
+ options.startTitle ?? startField,
4277
+ options.suffix
4278
+ );
4279
+ const endText = rangeEndpointText(
4280
+ pair.end.data[endField],
4281
+ formatter,
4282
+ labelPrefix,
4283
+ options.content,
4284
+ options.endTitle ?? endField,
4285
+ options.suffix
4286
+ );
4287
+ if (startText === null || endText === null) continue;
3945
4288
  const startIsMin = horizontal ? pair.start.cx <= pair.end.cx : pair.start.cy >= pair.end.cy;
3946
4289
  candidates.push(
3947
4290
  buildCandidate(
@@ -3950,7 +4293,8 @@ function computeRangeLabels(pairs, horizontal, density = "auto", labelPrefix, la
3950
4293
  horizontal,
3951
4294
  startIsMin ? "min" : "max",
3952
4295
  pairIndex * 2,
3953
- fontFamily
4296
+ fontFamily,
4297
+ options.measureText
3954
4298
  ),
3955
4299
  buildCandidate(
3956
4300
  pair.end,
@@ -3958,7 +4302,8 @@ function computeRangeLabels(pairs, horizontal, density = "auto", labelPrefix, la
3958
4302
  horizontal,
3959
4303
  startIsMin ? "max" : "min",
3960
4304
  pairIndex * 2 + 1,
3961
- fontFamily
4305
+ fontFamily,
4306
+ options.measureText
3962
4307
  )
3963
4308
  );
3964
4309
  }
@@ -3977,15 +4322,52 @@ function computeRangeLabels(pairs, horizontal, density = "auto", labelPrefix, la
3977
4322
  }
3978
4323
 
3979
4324
  // src/charts/range/index.ts
3980
- var rangeRenderer = (spec, scales, chartArea, strategy, theme) => {
4325
+ var rangeRenderer = (spec, scales, chartArea, strategy, theme, _width, _plan, measureText) => {
3981
4326
  const marks = computeRangeMarks(spec, scales, chartArea, strategy, theme);
3982
4327
  const style = spec.markDef.style ?? "dumbbell";
3983
- if (style !== "dumbbell") return marks;
4328
+ if (style !== "dumbbell" && spec.labels.content === void 0) return marks;
3984
4329
  const dots = marks.filter((m) => m.type === "point");
3985
4330
  const pairs = [];
3986
4331
  for (let i = 0; i + 1 < dots.length; i += 2) {
3987
4332
  pairs.push({ start: dots[i], end: dots[i + 1] });
3988
4333
  }
4334
+ if (style !== "dumbbell") {
4335
+ for (const mark of marks) {
4336
+ if (mark.aria.decorative) continue;
4337
+ let start, end;
4338
+ if (mark.type === "rect") {
4339
+ const horizontal2 = mark.orient !== "vertical";
4340
+ start = {
4341
+ cx: horizontal2 ? mark.x : mark.x + mark.width / 2,
4342
+ cy: horizontal2 ? mark.y + mark.height / 2 : mark.y + mark.height
4343
+ };
4344
+ end = {
4345
+ cx: horizontal2 ? mark.x + mark.width : mark.x + mark.width / 2,
4346
+ cy: horizontal2 ? mark.y + mark.height / 2 : mark.y
4347
+ };
4348
+ } else if (mark.type === "rule") {
4349
+ start = { cx: mark.x1, cy: mark.y1 };
4350
+ end = { cx: mark.x2, cy: mark.y2 };
4351
+ } else continue;
4352
+ if (mark.type === "rect") {
4353
+ const horizontal2 = mark.orient !== "vertical";
4354
+ const first = horizontal2 ? spec.encoding.x : spec.encoding.y;
4355
+ const second = horizontal2 ? spec.encoding.x2 : spec.encoding.y2;
4356
+ if (first && second && Number(mark.data[first.field]) > Number(mark.data[second.field]))
4357
+ [start, end] = [end, start];
4358
+ }
4359
+ const base = {
4360
+ type: "point",
4361
+ r: 0,
4362
+ fill: theme.colors.text,
4363
+ stroke: "none",
4364
+ strokeWidth: 0,
4365
+ data: mark.data,
4366
+ aria: { decorative: true }
4367
+ };
4368
+ pairs.push({ start: { ...base, ...start }, end: { ...base, ...end } });
4369
+ }
4370
+ }
3989
4371
  const orientation = resolveRangeOrientation(scales);
3990
4372
  const horizontal = orientation !== "vertical";
3991
4373
  const encoding = spec.encoding;
@@ -4008,7 +4390,14 @@ var rangeRenderer = (spec, scales, chartArea, strategy, theme) => {
4008
4390
  labelFormatter,
4009
4391
  startField,
4010
4392
  endField,
4011
- theme.fonts.family
4393
+ theme.fonts.family,
4394
+ {
4395
+ content: spec.labels.content,
4396
+ suffix: spec.labels.suffix,
4397
+ startTitle: startChannel?.title,
4398
+ endTitle: endChannel?.title,
4399
+ measureText
4400
+ }
4012
4401
  );
4013
4402
  for (const label of labels) {
4014
4403
  if (label.index === void 0) continue;
@@ -4017,6 +4406,23 @@ var rangeRenderer = (spec, scales, chartArea, strategy, theme) => {
4017
4406
  const dot = label.index % 2 === 0 ? pair.start : pair.end;
4018
4407
  dot.label = label;
4019
4408
  }
4409
+ if (spec.labels.content !== void 0) {
4410
+ const textMarks = labels.filter((label) => label.visible).map((label) => ({
4411
+ type: "textMark",
4412
+ x: label.x,
4413
+ y: label.y,
4414
+ text: label.text,
4415
+ fill: label.style.fill,
4416
+ fontSize: label.style.fontSize,
4417
+ fontWeight: label.style.fontWeight,
4418
+ fontFamily: label.style.fontFamily,
4419
+ textAnchor: label.style.textAnchor ?? "start",
4420
+ dominantBaseline: "central",
4421
+ data: {},
4422
+ aria: { decorative: true }
4423
+ }));
4424
+ return [...marks, ...textMarks];
4425
+ }
4020
4426
  return marks;
4021
4427
  };
4022
4428
 
@@ -4093,7 +4499,7 @@ function clearRenderers() {
4093
4499
  }
4094
4500
 
4095
4501
  // src/charts/rule/index.ts
4096
- import { getRepresentativeColor as getRepresentativeColor10 } from "@opendata-ai/openchart-core";
4502
+ import { getRepresentativeColor as getRepresentativeColor11 } from "@opendata-ai/openchart-core";
4097
4503
  function computeRuleMarks(spec, scales, chartArea) {
4098
4504
  const encoding = spec.encoding;
4099
4505
  const xChannel = encoding.x;
@@ -4136,7 +4542,7 @@ function computeRuleMarks(spec, scales, chartArea) {
4136
4542
  const y2Val = scaleValue(scales.y.scale, scales.y.type, row[y2Channel.field]);
4137
4543
  if (y2Val != null) y2 = y2Val;
4138
4544
  }
4139
- const color = getRepresentativeColor10(
4545
+ const color = getRepresentativeColor11(
4140
4546
  colorField ? getColor(scales, String(row[colorField] ?? "__default__")) : getColor(scales, "__default__")
4141
4547
  );
4142
4548
  const strokeDashEncoding = encoding.strokeDash && "field" in encoding.strokeDash ? encoding.strokeDash : void 0;
@@ -4158,7 +4564,7 @@ function computeRuleMarks(spec, scales, chartArea) {
4158
4564
  aria
4159
4565
  });
4160
4566
  }
4161
- const posField = xChannel?.field ?? yChannel?.field;
4567
+ const posField = (encoding.key && "field" in encoding.key ? encoding.key.field : void 0) ?? xChannel?.field ?? yChannel?.field;
4162
4568
  const rawKeys = marks.map((m, i) => posField ? serializeKeyValue(m.data[posField]) : String(i));
4163
4569
  const keys = dedupeKeys(rawKeys);
4164
4570
  for (let i = 0; i < marks.length; i++) {
@@ -4358,7 +4764,7 @@ var scatterRenderer = (spec, scales, chartArea, strategy, theme) => {
4358
4764
  };
4359
4765
 
4360
4766
  // src/charts/text/index.ts
4361
- import { getRepresentativeColor as getRepresentativeColor11 } from "@opendata-ai/openchart-core";
4767
+ import { getRepresentativeColor as getRepresentativeColor12 } from "@opendata-ai/openchart-core";
4362
4768
  var DEFAULT_FONT_SIZE = 12;
4363
4769
  var ALIGN_TO_ANCHOR = {
4364
4770
  left: "start",
@@ -4402,7 +4808,7 @@ function computeTextMarks(spec, scales) {
4402
4808
  }
4403
4809
  const text = String(row[textChannel.field] ?? "");
4404
4810
  if (!text) continue;
4405
- const color = getRepresentativeColor11(
4811
+ const color = getRepresentativeColor12(
4406
4812
  colorField ? getColor(scales, String(row[colorField] ?? "__default__")) : getColor(scales, "__default__")
4407
4813
  );
4408
4814
  const fallbackFontSize = markDef.fontSize ?? DEFAULT_FONT_SIZE;
@@ -4439,7 +4845,7 @@ var textRenderer = (spec, scales, _chartArea, _strategy, _theme) => {
4439
4845
  };
4440
4846
 
4441
4847
  // src/charts/tick/index.ts
4442
- import { getRepresentativeColor as getRepresentativeColor12 } from "@opendata-ai/openchart-core";
4848
+ import { getRepresentativeColor as getRepresentativeColor13 } from "@opendata-ai/openchart-core";
4443
4849
  var DEFAULT_TICK_LENGTH = 18;
4444
4850
  function computeTickMarks(spec, scales, _chartArea) {
4445
4851
  const encoding = spec.encoding;
@@ -4455,7 +4861,7 @@ function computeTickMarks(spec, scales, _chartArea) {
4455
4861
  const xVal = scaleValue(scales.x.scale, scales.x.type, row[xChannel.field]);
4456
4862
  const yVal = scaleValue(scales.y.scale, scales.y.type, row[yChannel.field]);
4457
4863
  if (xVal == null || yVal == null) continue;
4458
- const color = getRepresentativeColor12(
4864
+ const color = getRepresentativeColor13(
4459
4865
  colorField ? getColor(scales, String(row[colorField] ?? "__default__")) : getColor(scales, "__default__")
4460
4866
  );
4461
4867
  const aria = {
@@ -4586,6 +4992,7 @@ var waffleRenderer = (spec, scales, chartArea, strategy, _theme) => {
4586
4992
 
4587
4993
  // src/charts/builtin.ts
4588
4994
  var builtinRenderers = {
4995
+ errorbar: errorbarRenderer,
4589
4996
  line: lineRenderer,
4590
4997
  area: areaRenderer,
4591
4998
  bar: barRenderer,
@@ -4642,6 +5049,85 @@ import {
4642
5049
  resolveTheme
4643
5050
  } from "@opendata-ai/openchart-core";
4644
5051
 
5052
+ // src/charts/_shared/mark-metadata.ts
5053
+ import { buildTemporalFormatter, formatDate as formatDate2 } from "@opendata-ai/openchart-core";
5054
+ var RESERVED_SUFFIXES = /* @__PURE__ */ new Set([
5055
+ "mark",
5056
+ "mark-id",
5057
+ "series",
5058
+ "key",
5059
+ "theme",
5060
+ "display",
5061
+ "animation-index",
5062
+ "row-index",
5063
+ "navigation-key",
5064
+ "note-marker-index",
5065
+ "note-spec-index"
5066
+ ]);
5067
+ function identityForRows(encoding, rows) {
5068
+ const identity = {};
5069
+ const fields = /* @__PURE__ */ new Set();
5070
+ for (const name of ["x", "y", "color", "detail", "key"]) {
5071
+ const channel = encoding[name];
5072
+ if (!channel || !("field" in channel)) continue;
5073
+ if ((name === "x" || name === "y") && channel.type === "quantitative") continue;
5074
+ fields.add(channel.field);
5075
+ }
5076
+ for (const field of fields) {
5077
+ const value = rows[0]?.[field];
5078
+ if (value == null || !rows.every((row) => row[field] != null && String(row[field]) === String(value)))
5079
+ continue;
5080
+ let suffix = field.toLowerCase().replace(/[^a-z0-9-]/g, "-");
5081
+ if (RESERVED_SUFFIXES.has(suffix)) suffix = `field-${suffix}`;
5082
+ identity[suffix] = String(value);
5083
+ }
5084
+ return identity;
5085
+ }
5086
+ function descriptionForRows(encoding, rows, warnings, series) {
5087
+ const channel = encoding.description;
5088
+ if (!channel) return void 0;
5089
+ if ("value" in channel) return channel.value;
5090
+ const value = rows[0]?.[channel.field];
5091
+ if (!rows.every((row) => Object.is(row[channel.field], value))) {
5092
+ warnings.push(
5093
+ `[openchart] encoding.description has mixed values in series "${series ?? "series"}"; no series description was emitted.`
5094
+ );
5095
+ return void 0;
5096
+ }
5097
+ if (value == null) return void 0;
5098
+ if (channel.type === "temporal" || value instanceof Date) {
5099
+ const format = buildTemporalFormatter(channel.format);
5100
+ return format ? format(value) : formatDate2(value);
5101
+ }
5102
+ if (typeof value === "number")
5103
+ return resolveFieldFormatter({
5104
+ channelFormat: channel.format,
5105
+ values: rows.map((row) => row[channel.field])
5106
+ })(value);
5107
+ return String(value);
5108
+ }
5109
+ function attachMarkMetadata(marks, encoding, sourceMarkType, warnings) {
5110
+ for (const mark of marks) {
5111
+ if (mark.aria.decorative) continue;
5112
+ const rows = mark.type === "line" || mark.type === "area" ? mark.data : [mark.data];
5113
+ if (!rows.length) continue;
5114
+ const description = descriptionForRows(
5115
+ encoding,
5116
+ rows,
5117
+ warnings,
5118
+ "seriesKey" in mark ? mark.seriesKey : void 0
5119
+ );
5120
+ if (description !== void 0) {
5121
+ mark.authoredDescription = description;
5122
+ mark.aria = { ...mark.aria, label: description };
5123
+ }
5124
+ if (sourceMarkType === "range" && mark.type === "point" || (sourceMarkType === "lollipop" || sourceMarkType === "circle") && mark.type === "rect")
5125
+ continue;
5126
+ mark.markType = (sourceMarkType === "line" || sourceMarkType === "area") && mark.type === "point" ? "point" : sourceMarkType;
5127
+ mark.identity = identityForRows(encoding, rows);
5128
+ }
5129
+ }
5130
+
4645
5131
  // src/compiler/removed-spec-fields.ts
4646
5132
  import { encodePointerToken } from "@opendata-ai/openchart-core";
4647
5133
  var node = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
@@ -4703,6 +5189,9 @@ function collectRemovedSpecErrors(value, prefix = "") {
4703
5189
  return errors;
4704
5190
  }
4705
5191
 
5192
+ // src/compile/source-mark.ts
5193
+ var SOURCE_MARK_TYPE = /* @__PURE__ */ Symbol("openchart.sourceMarkType");
5194
+
4706
5195
  // src/compile/spec-sugar.ts
4707
5196
  import { inferFieldType, resolveSchemeName } from "@opendata-ai/openchart-core";
4708
5197
 
@@ -5277,6 +5766,10 @@ function applyHistogramNormalize(spec) {
5277
5766
  }
5278
5767
  function expandChartSugar(spec, warnings, inheritedData) {
5279
5768
  let out = unwrapDataValues(spec);
5769
+ out = {
5770
+ ...out,
5771
+ [SOURCE_MARK_TYPE]: spec[SOURCE_MARK_TYPE] ?? markTypeOf(spec)
5772
+ };
5280
5773
  out = expandTopLevelTitle(out);
5281
5774
  out = expandDescriptionSugar(out);
5282
5775
  out = stripIgnoredKeys(out, warnings);
@@ -5292,6 +5785,10 @@ function expandChartSugar(spec, warnings, inheritedData) {
5292
5785
  }
5293
5786
  function expandLayerSugar(spec, warnings, inheritedData, parentEncoding) {
5294
5787
  let out = unwrapDataValues(spec);
5788
+ out = {
5789
+ ...out,
5790
+ [SOURCE_MARK_TYPE]: spec[SOURCE_MARK_TYPE] ?? markTypeOf(spec)
5791
+ };
5295
5792
  out = expandTopLevelTitle(out);
5296
5793
  out = stripIgnoredKeys(out, warnings);
5297
5794
  out = expandChannelSugar(out, warnings);
@@ -5697,6 +6194,7 @@ function normalizeLabels(labels) {
5697
6194
  format: labels.format ?? "",
5698
6195
  prefix: labels.prefix ?? "",
5699
6196
  suffix: labels.suffix,
6197
+ content: labels.content,
5700
6198
  color: labels.color,
5701
6199
  fontSize: labels.fontSize,
5702
6200
  ...labels.placement ? { placement: labels.placement } : {}
@@ -5826,7 +6324,7 @@ function normalizeChartSpec(spec, warnings) {
5826
6324
  const encoding = markType === "calendar" ? withCalendarColorScale(inferred) : inferred;
5827
6325
  const data = markType === "waffle" ? applyWaffleOther(spec, encoding, markDef, warnings) : spec.data;
5828
6326
  const display = spec.display ?? "full";
5829
- if (display === "sparkline" && markType !== "line" && markType !== "area" && markType !== "bar" && markType !== "point") {
6327
+ if (display === "sparkline" && markType !== "line" && markType !== "area" && markType !== "bar" && markType !== "point" && markType !== "errorbar") {
5830
6328
  warnings.push(
5831
6329
  `[openchart] display: 'sparkline' works best with mark: 'line' | 'area' | 'bar' | 'point'. Got mark: '${markType}' \u2014 rendering may degrade.`
5832
6330
  );
@@ -5841,6 +6339,7 @@ function normalizeChartSpec(spec, warnings) {
5841
6339
  }
5842
6340
  return {
5843
6341
  markType,
6342
+ sourceMarkType: spec[SOURCE_MARK_TYPE] ?? markType,
5844
6343
  markDef,
5845
6344
  data,
5846
6345
  encoding,
@@ -5862,6 +6361,7 @@ function normalizeChartSpec(spec, warnings) {
5862
6361
  watermark: spec.watermark ?? true,
5863
6362
  highlight: normalizeHighlight(encoding, spec.data, warnings),
5864
6363
  a11y: spec.a11y,
6364
+ frame: spec.frame,
5865
6365
  display,
5866
6366
  resolve: spec.resolve,
5867
6367
  // Default empty userExplicit; compileChart overwrites this with the real
@@ -6038,6 +6538,11 @@ function normalizeBarListSpec(spec, _warnings) {
6038
6538
  type: "barlist",
6039
6539
  data: spec.data,
6040
6540
  encoding: spec.encoding,
6541
+ sort: spec.sort === void 0 ? "descending" : spec.sort,
6542
+ height: spec.height,
6543
+ annotations: spec.annotations,
6544
+ labels: spec.labels,
6545
+ a11y: spec.a11y,
6041
6546
  barHeight: spec.barHeight ?? 6,
6042
6547
  cornerRadius: spec.cornerRadius ?? "pill",
6043
6548
  maxItems: spec.maxItems ?? 20,
@@ -6090,12 +6595,18 @@ function normalizeSpec(spec, warnings = []) {
6090
6595
  `Unknown spec shape. Expected mark (chart), layer, type: 'table', type: 'graph', type: 'sankey', type: 'tilemap', type: 'map', or type: 'barlist'.`
6091
6596
  );
6092
6597
  }
6093
- function flattenLayers(spec, parentData, parentEncoding, parentTransforms, parentWatermark, parentEndpointLabels) {
6598
+ function flattenLayers(spec, parentData, parentEncoding, parentTransforms, parentWatermark, parentEndpointLabels, parentFigure) {
6094
6599
  const resolvedData = spec.data ?? parentData;
6095
6600
  const resolvedEncoding = parentEncoding && spec.encoding ? { ...parentEncoding, ...spec.encoding } : spec.encoding ?? parentEncoding;
6096
6601
  const resolvedTransforms = [...parentTransforms ?? [], ...spec.transform ?? []];
6097
6602
  const resolvedWatermark = spec.watermark ?? parentWatermark;
6098
6603
  const resolvedEndpointLabels = spec.endpointLabels ?? parentEndpointLabels;
6604
+ const figure = {
6605
+ display: spec.display ?? parentFigure?.display,
6606
+ a11y: spec.a11y ?? parentFigure?.a11y,
6607
+ frame: spec.frame ?? parentFigure?.frame,
6608
+ labels: spec.labels ?? parentFigure?.labels
6609
+ };
6099
6610
  const leaves = [];
6100
6611
  for (const child of spec.layer) {
6101
6612
  if (isLayerSpec(child)) {
@@ -6106,7 +6617,8 @@ function flattenLayers(spec, parentData, parentEncoding, parentTransforms, paren
6106
6617
  resolvedEncoding,
6107
6618
  resolvedTransforms,
6108
6619
  resolvedWatermark,
6109
- resolvedEndpointLabels
6620
+ resolvedEndpointLabels,
6621
+ figure
6110
6622
  )
6111
6623
  );
6112
6624
  } else {
@@ -6115,6 +6627,12 @@ function flattenLayers(spec, parentData, parentEncoding, parentTransforms, paren
6115
6627
  const mergedTransforms = [...resolvedTransforms, ...child.transform ?? []];
6116
6628
  leaves.push({
6117
6629
  ...child,
6630
+ display: child.display ?? figure.display,
6631
+ a11y: child.a11y ?? figure.a11y,
6632
+ frame: child.frame ?? figure.frame,
6633
+ // Composed labels belong to bar/range leaves; interval peers such as
6634
+ // ticks must not inherit an inapplicable placement/content option.
6635
+ labels: child.labels ?? (typeof figure.labels === "object" && figure.labels.content !== void 0 && ["bar", "range"].includes(typeof child.mark === "string" ? child.mark : child.mark.type) ? figure.labels : void 0),
6118
6636
  data: mergedData,
6119
6637
  encoding: mergedEncoding,
6120
6638
  transform: mergedTransforms.length > 0 ? mergedTransforms : void 0,
@@ -6324,7 +6842,7 @@ function validateBarListSpec(spec, errors) {
6324
6842
  });
6325
6843
  }
6326
6844
  }
6327
- for (const channel of ["subtitle", "color", "tooltip"]) {
6845
+ for (const channel of ["subtitle", "color", "tooltip", "group", "description"]) {
6328
6846
  const ch = encoding[channel];
6329
6847
  if (!ch) continue;
6330
6848
  const field = ch.field;
@@ -6337,6 +6855,56 @@ function validateBarListSpec(spec, errors) {
6337
6855
  });
6338
6856
  }
6339
6857
  }
6858
+ if (spec.sort !== void 0 && spec.sort !== null && spec.sort !== "ascending" && spec.sort !== "descending")
6859
+ errors.push({
6860
+ code: "INVALID_TYPE",
6861
+ path: "/sort",
6862
+ message: "Bar list sort must be ascending, descending, or null.",
6863
+ suggestion: "Set sort to ascending, descending, or null."
6864
+ });
6865
+ if (spec.height !== void 0 && spec.height !== "auto" && (typeof spec.height !== "number" || !Number.isFinite(spec.height) || spec.height <= 0))
6866
+ errors.push({
6867
+ code: "INVALID_TYPE",
6868
+ path: "/height",
6869
+ message: "Bar list height must be a positive number or auto.",
6870
+ suggestion: "Use height: auto to fit every row, or a positive pixel height."
6871
+ });
6872
+ const group = encoding.group;
6873
+ if (group && (!group.field || typeof group.field !== "string" || group.type !== void 0 && group.type !== "nominal" && group.type !== "ordinal"))
6874
+ errors.push({
6875
+ code: "INVALID_TYPE",
6876
+ path: "/encoding/group",
6877
+ message: "Bar list group must name a nominal or ordinal field.",
6878
+ suggestion: "Set encoding.group to a field with type nominal or ordinal."
6879
+ });
6880
+ const domain = encoding.value?.scale?.domain;
6881
+ if (domain !== void 0 && (!Array.isArray(domain) || domain.length !== 2 || !domain.every((value) => typeof value === "number" && Number.isFinite(value)) || domain[1] <= domain[0]))
6882
+ errors.push({
6883
+ code: "INVALID_TYPE",
6884
+ path: "/encoding/value/scale/domain",
6885
+ message: "Bar list value domain must be two finite numbers in increasing order.",
6886
+ suggestion: "Use a numeric domain such as [0, 1] with lower bound below upper bound."
6887
+ });
6888
+ if (spec.annotations !== void 0) {
6889
+ if (!Array.isArray(spec.annotations))
6890
+ errors.push({
6891
+ code: "INVALID_TYPE",
6892
+ path: "/annotations",
6893
+ message: "Bar list annotations must be an array of vertical reference lines.",
6894
+ suggestion: "Use annotations: [{ type: refline, x: 1 }]."
6895
+ });
6896
+ else
6897
+ spec.annotations.forEach((annotation, index) => {
6898
+ const item = annotation;
6899
+ if (!item || item.type !== "refline" || typeof item.x !== "number" || !Number.isFinite(item.x) || item.y !== void 0)
6900
+ errors.push({
6901
+ code: "INVALID_TYPE",
6902
+ path: `/annotations/${index}`,
6903
+ message: "Bar list annotations require type refline and a finite numeric x; y is not supported.",
6904
+ suggestion: "Use { type: refline, x: 1 } and remove y."
6905
+ });
6906
+ });
6907
+ }
6340
6908
  checkSchemeUnused(
6341
6909
  encoding,
6342
6910
  errors,
@@ -6352,6 +6920,31 @@ import {
6352
6920
  MARK_ENCODING_RULES
6353
6921
  } from "@opendata-ai/openchart-core";
6354
6922
 
6923
+ // src/compiler/validation/frame.ts
6924
+ function validateFrame(spec, errors, prefix = "") {
6925
+ if (spec.frame === void 0) return;
6926
+ const frame = spec.frame;
6927
+ if (!frame || typeof frame !== "object" || Array.isArray(frame)) {
6928
+ errors.push({
6929
+ code: "INVALID_VALUE",
6930
+ path: `${prefix}/frame`,
6931
+ message: "frame must contain finite nonnegative left/right gutters.",
6932
+ suggestion: "Use frame: { left: 48, right: 96 }."
6933
+ });
6934
+ return;
6935
+ }
6936
+ for (const [key, value] of Object.entries(frame)) {
6937
+ if (["left", "right"].includes(key) && value === void 0) continue;
6938
+ if (!["left", "right"].includes(key) || typeof value !== "number" || !Number.isFinite(value) || value < 0)
6939
+ errors.push({
6940
+ code: "INVALID_VALUE",
6941
+ path: `${prefix}/frame/${key}`,
6942
+ message: "Frame gutters must be finite nonnegative left/right values.",
6943
+ suggestion: "Use CSS pixel values of zero or greater for left and right."
6944
+ });
6945
+ }
6946
+ }
6947
+
6355
6948
  // src/compiler/validation/label-placement.ts
6356
6949
  import { inferFieldType as inferFieldType3 } from "@opendata-ai/openchart-core";
6357
6950
  function validateLabelPlacement(spec, errors) {
@@ -6672,11 +7265,79 @@ function validatePointSize(spec, errors) {
6672
7265
  }
6673
7266
  }
6674
7267
  }
7268
+ function validateErrorbarSpec(spec, errors) {
7269
+ const encoding = spec.encoding;
7270
+ const data = spec.data;
7271
+ const horizontal = !!encoding.x2;
7272
+ if (horizontal === !!encoding.y2) {
7273
+ errors.push({
7274
+ message: "Spec error: errorbar requires exactly one of encoding.x2 or encoding.y2",
7275
+ path: "/encoding",
7276
+ code: "ENCODING_MISMATCH",
7277
+ suggestion: "Supply x/x2 for horizontal bounds or y/y2 for vertical bounds."
7278
+ });
7279
+ return;
7280
+ }
7281
+ const value = horizontal ? encoding.x : encoding.y;
7282
+ const category = horizontal ? encoding.y : encoding.x;
7283
+ const end = horizontal ? encoding.x2 : encoding.y2;
7284
+ for (const [channel, name] of [
7285
+ [value, horizontal ? "x" : "y"],
7286
+ [end, horizontal ? "x2" : "y2"]
7287
+ ]) {
7288
+ if (typeof channel?.field !== "string") continue;
7289
+ const type = channel.type ?? (data.some((row) => row[channel.field] != null) ? inferFieldType4(data, channel.field) : "quantitative");
7290
+ if (type !== "quantitative")
7291
+ errors.push({
7292
+ message: `Spec error: errorbar encoding.${name} must be quantitative`,
7293
+ path: `/encoding/${name}`,
7294
+ code: "ENCODING_MISMATCH",
7295
+ suggestion: "Map the interval bound to a quantitative field."
7296
+ });
7297
+ }
7298
+ if (typeof category?.field === "string") {
7299
+ const type = category.type ?? inferFieldType4(data, category.field);
7300
+ if (!["nominal", "ordinal", "temporal"].includes(String(type)))
7301
+ errors.push({
7302
+ message: "Spec error: errorbar requires a nominal, ordinal or temporal category axis",
7303
+ path: horizontal ? "/encoding/y" : "/encoding/x",
7304
+ code: "ENCODING_MISMATCH",
7305
+ suggestion: "Place each interval on a category or date."
7306
+ });
7307
+ }
7308
+ const mark = spec.mark;
7309
+ if (mark && typeof mark === "object" && "ticks" in mark && typeof mark.ticks !== "boolean")
7310
+ errors.push({
7311
+ message: "Spec error: mark.ticks must be boolean",
7312
+ path: "/mark/ticks",
7313
+ code: "INVALID_VALUE",
7314
+ suggestion: "Use ticks: true or false."
7315
+ });
7316
+ }
6675
7317
 
6676
7318
  // src/compiler/validation/chart.ts
6677
7319
  function validateChartSpec(spec, errors) {
6678
7320
  validateLabelPlacement(spec, errors);
7321
+ validateFrame(spec, errors);
6679
7322
  const markType = typeof spec.mark === "string" ? spec.mark : spec.mark?.type;
7323
+ if (spec.encoding && typeof spec.encoding === "object") {
7324
+ for (const [name, raw] of Object.entries(spec.encoding)) {
7325
+ if (!raw || typeof raw !== "object" || !("interval" in raw)) continue;
7326
+ const channel = raw;
7327
+ const interval = channel.interval;
7328
+ if (interval === void 0) continue;
7329
+ const validValue = typeof interval === "number" ? Number.isFinite(interval) && interval > 0 : typeof interval === "string" && ["day", "week", "month", "quarter", "year"].includes(interval);
7330
+ if (!validValue || // Only bar marks size columns from the interval; rect cells and
7331
+ // errorbar whiskers ignore it, so accepting it there would be a no-op.
7332
+ markType !== "bar" || !["x", "y", "x2", "y2"].includes(name) || channel.type !== "temporal")
7333
+ errors.push({
7334
+ code: "INVALID_VALUE",
7335
+ path: jsonPointer5("encoding", name, "interval"),
7336
+ message: "interval requires a temporal position channel of a bar mark and a calendar unit or finite positive milliseconds.",
7337
+ suggestion: "Use day, week, month, quarter, year, or a positive millisecond interval on a temporal position channel of a bar mark."
7338
+ });
7339
+ }
7340
+ }
6680
7341
  if (!Array.isArray(spec.data)) {
6681
7342
  if (spec.data && typeof spec.data === "object" && "url" in spec.data) {
6682
7343
  errors.push({
@@ -6775,6 +7436,7 @@ function validateChartSpec(spec, errors) {
6775
7436
  }
6776
7437
  }
6777
7438
  validateCenterLabel(spec, markType, errors);
7439
+ if (markType === "errorbar") validateErrorbarSpec(spec, errors);
6778
7440
  if (markType === "range") {
6779
7441
  validateRangeSpec(spec, errors);
6780
7442
  }
@@ -6858,6 +7520,16 @@ function validateChartSpec(spec, errors) {
6858
7520
  }
6859
7521
  const channelObj = channelSpec;
6860
7522
  const channelRule = rules[channel];
7523
+ if (channel === "description" && "value" in channelObj) {
7524
+ if (typeof channelObj.value !== "string" || "field" in channelObj)
7525
+ errors.push({
7526
+ message: "Spec error: encoding.description must be a field reference or a string value",
7527
+ path: "/encoding/description",
7528
+ code: "INVALID_VALUE",
7529
+ suggestion: 'Use description: { field: "text" } or { value: "Description" }'
7530
+ });
7531
+ continue;
7532
+ }
6861
7533
  if ("condition" in channelObj) continue;
6862
7534
  if (!channelObj.field || typeof channelObj.field !== "string") {
6863
7535
  errors.push({
@@ -8033,6 +8705,7 @@ function rootLeafPath(path, parentPrefix, leafPrefix, leaf, inheritsData) {
8033
8705
  return `${inherited ? parentPrefix : leafPrefix}${path}`;
8034
8706
  }
8035
8707
  function validateLayerSpec(spec, errors, prefix = "") {
8708
+ validateFrame(spec, errors, prefix);
8036
8709
  const layer = spec.layer;
8037
8710
  if (layer.length === 0) {
8038
8711
  errors.push({
@@ -8629,8 +9302,8 @@ var DEFAULT_ROW_GAP = 8;
8629
9302
  var LABEL_BAR_GAP = 12;
8630
9303
  var BAR_VALUE_GAP = 12;
8631
9304
  var VALUE_WIDTH = 56;
8632
- var LABEL_FONT_SIZE6 = 13;
8633
- var LABEL_FONT_WEIGHT6 = 500;
9305
+ var LABEL_FONT_SIZE5 = 13;
9306
+ var LABEL_FONT_WEIGHT5 = 500;
8634
9307
  var SUBTITLE_FONT_SIZE = 12;
8635
9308
  var SUBTITLE_FONT_WEIGHT2 = 400;
8636
9309
  var VALUE_FONT_SIZE = 12;
@@ -8665,32 +9338,78 @@ function compileBarList(spec, options) {
8665
9338
  watermark
8666
9339
  );
8667
9340
  const padding = theme.spacing.padding;
8668
- const chromeLayout = resolveChromeLayout(
8669
- spec,
8670
- options
8671
- );
8672
- const grownHeight = chromeLayout === "grow" ? options.height + chrome.topHeight + chrome.bottomHeight : options.height;
8673
- const fullArea = {
8674
- x: padding,
8675
- y: padding + chrome.topHeight,
8676
- width: options.width - padding * 2,
8677
- height: chromeLayout === "grow" ? options.height - padding * 2 : options.height - chrome.topHeight - chrome.bottomHeight - padding * 2
8678
- };
8679
- if (fullArea.width <= 0 || fullArea.height <= 0) {
8680
- return emptyLayout(chrome, theme, { ...options, height: grownHeight }, watermark);
8681
- }
8682
9341
  const labelField = barlistSpec.encoding.label.field;
8683
9342
  const valueField = barlistSpec.encoding.value.field;
8684
9343
  const subtitleField = barlistSpec.encoding.subtitle?.field;
8685
9344
  const colorField = barlistSpec.encoding.color?.field;
9345
+ const groupField = barlistSpec.encoding.group?.field;
8686
9346
  const barHeight = barlistSpec.barHeight;
8687
9347
  const cornerRadius = barlistSpec.cornerRadius === "pill" ? barHeight / 2 : barlistSpec.cornerRadius;
8688
- const rowContentHeight = Math.max(barHeight, LABEL_FONT_SIZE6 * 1.4);
9348
+ const rowContentHeight = Math.max(barHeight, LABEL_FONT_SIZE5 * 1.4);
8689
9349
  const rowHeight = rowContentHeight + DEFAULT_ROW_GAP;
8690
- const maxFittingRows = Math.max(1, Math.floor(fullArea.height / rowHeight));
8691
- const validRows = barlistSpec.data.filter((row) => finiteNumber(row[valueField]) !== void 0).sort((a, b) => Number(b[valueField]) - Number(a[valueField])).slice(0, Math.min(barlistSpec.maxItems, maxFittingRows));
8692
- if (validRows.length === 0) {
8693
- return emptyLayout(chrome, theme, options, watermark);
9350
+ const groupHeight = groupField ? LABEL_FONT_SIZE5 * 1.4 + DEFAULT_ROW_GAP : 0;
9351
+ const annotationLane = barlistSpec.annotations?.some((annotation) => annotation.label) ? theme.fonts.sizes.small * 1.5 : 0;
9352
+ const buckets = /* @__PURE__ */ new Map();
9353
+ for (const row of barlistSpec.data) {
9354
+ if (finiteNumber(row[valueField]) === void 0) continue;
9355
+ const group = groupField ? String(row[groupField] ?? "") : "";
9356
+ if (!buckets.has(group)) buckets.set(group, []);
9357
+ buckets.get(group).push(row);
9358
+ }
9359
+ const candidates = [...buckets.values()].flatMap(
9360
+ (rows2) => barlistSpec.sort === null ? rows2 : rows2.slice().sort(
9361
+ (a, b) => (barlistSpec.sort === "ascending" ? 1 : -1) * (Number(a[valueField]) - Number(b[valueField]))
9362
+ )
9363
+ ).slice(0, barlistSpec.maxItems);
9364
+ const groupsCount = groupField ? new Set(candidates.map((row) => String(row[groupField] ?? ""))).size : 0;
9365
+ const chromeLayout = resolveChromeLayout(spec, options);
9366
+ const auto = barlistSpec.height === "auto";
9367
+ const baseHeight = auto ? candidates.length * rowHeight + groupsCount * groupHeight + annotationLane + padding * 2 + (chromeLayout === "grow" ? 0 : chrome.topHeight + chrome.bottomHeight) : typeof barlistSpec.height === "number" ? barlistSpec.height : options.height;
9368
+ const grownHeight = chromeLayout === "grow" ? baseHeight + chrome.topHeight + chrome.bottomHeight : baseHeight;
9369
+ const fullArea = {
9370
+ x: padding,
9371
+ y: padding + chrome.topHeight + annotationLane,
9372
+ width: options.width - padding * 2,
9373
+ height: baseHeight - padding * 2 - annotationLane - (chromeLayout === "grow" ? 0 : chrome.topHeight + chrome.bottomHeight)
9374
+ };
9375
+ const validRows = [];
9376
+ const rowPositions = [];
9377
+ const groupPositions = [];
9378
+ let cursorY = fullArea.y;
9379
+ let previousGroup;
9380
+ for (const row of candidates) {
9381
+ const group = groupField ? String(row[groupField] ?? "") : "";
9382
+ const newGroup = groupField !== void 0 && group !== previousGroup;
9383
+ const header = newGroup ? groupHeight : 0;
9384
+ const fits = cursorY + header + rowHeight <= fullArea.y + fullArea.height + 1e-9;
9385
+ if (!fits && (validRows.length > 0 || fullArea.height <= 0)) break;
9386
+ if (newGroup) {
9387
+ groupPositions.push({ key: group, y: cursorY });
9388
+ cursorY += groupHeight;
9389
+ }
9390
+ validRows.push(row);
9391
+ rowPositions.push(cursorY);
9392
+ cursorY += rowHeight;
9393
+ previousGroup = group;
9394
+ }
9395
+ const compileWarnings = [];
9396
+ const droppedCount = candidates.length - validRows.length;
9397
+ if (droppedCount > 0 && typeof barlistSpec.height === "number") {
9398
+ const message = `Bar list height drops ${droppedCount} rows; use height: 'auto' to fit every row.`;
9399
+ compileWarnings.push({ code: "BARLIST_ROWS_DROPPED", message, context: { droppedCount } });
9400
+ emitSpecWarnings([message], options.onWarn);
9401
+ }
9402
+ if (fullArea.width <= 0 || validRows.length === 0) {
9403
+ const empty = emptyLayout(chrome, theme, { ...options, height: grownHeight }, watermark);
9404
+ return {
9405
+ ...empty,
9406
+ warnings: compileWarnings,
9407
+ a11y: {
9408
+ ...empty.a11y,
9409
+ altText: barlistSpec.a11y?.description ?? "Empty bar list",
9410
+ hidden: barlistSpec.a11y?.hidden
9411
+ }
9412
+ };
8694
9413
  }
8695
9414
  const maxValue = Math.max(...validRows.map((r) => Math.abs(Number(r[valueField]))));
8696
9415
  const colorMap = /* @__PURE__ */ new Map();
@@ -8708,9 +9427,10 @@ function compileBarList(spec, options) {
8708
9427
  return palette[idx % palette.length];
8709
9428
  }
8710
9429
  const formatter = resolveFieldFormatter({
8711
- surfaceFormat: barlistSpec.encoding.value.format,
9430
+ surfaceFormat: barlistSpec.labels?.format ?? barlistSpec.encoding.value.format,
8712
9431
  values: validRows.map((r) => r[valueField])
8713
9432
  });
9433
+ const formatValue3 = (value) => `${barlistSpec.labels?.prefix ?? ""}${formatter(value)}${barlistSpec.labels?.suffix ?? ""}`;
8714
9434
  const measureText = options.measureText ?? ((text, fontSize) => ({
8715
9435
  width: estimateTextWidth7(text, fontSize),
8716
9436
  height: fontSize
@@ -8720,7 +9440,7 @@ function compileBarList(spec, options) {
8720
9440
  for (let i = 0; i < validRows.length; i++) {
8721
9441
  const row = validRows[i];
8722
9442
  const label = String(row[labelField] ?? "");
8723
- const labelW = measureText(label, LABEL_FONT_SIZE6, LABEL_FONT_WEIGHT6).width;
9443
+ const labelW = measureText(label, LABEL_FONT_SIZE5, LABEL_FONT_WEIGHT5).width;
8724
9444
  perRowLabelWidths.set(i, labelW);
8725
9445
  let combined = labelW + 4;
8726
9446
  if (subtitleField && row[subtitleField] != null) {
@@ -8732,7 +9452,13 @@ function compileBarList(spec, options) {
8732
9452
  const isNarrow = fullArea.width < 400;
8733
9453
  const labelBarGap = isNarrow ? 8 : LABEL_BAR_GAP;
8734
9454
  const barValueGap = isNarrow ? 6 : BAR_VALUE_GAP;
8735
- const valueWidth = isNarrow ? 44 : VALUE_WIDTH;
9455
+ const defaultValueWidth = isNarrow ? 44 : VALUE_WIDTH;
9456
+ const valueWidth = barlistSpec.labels ? Math.max(
9457
+ defaultValueWidth,
9458
+ ...validRows.map(
9459
+ (row) => measureText(formatValue3(Number(row[valueField])), VALUE_FONT_SIZE, VALUE_FONT_WEIGHT).width + 4
9460
+ )
9461
+ ) : defaultValueWidth;
8736
9462
  const maxLabelPct = isNarrow ? 0.35 : 0.4;
8737
9463
  const labelWidth = Math.max(50, Math.min(maxCombinedWidth, fullArea.width * maxLabelPct));
8738
9464
  const barAreaWidth = fullArea.width - labelWidth - labelBarGap - barValueGap - valueWidth;
@@ -8753,10 +9479,11 @@ function compileBarList(spec, options) {
8753
9479
  const row = validRows[i];
8754
9480
  const value = Number(row[valueField]);
8755
9481
  const labelText = String(row[labelField] ?? "");
8756
- const formattedValue = formatter(value);
9482
+ const formattedValue = formatValue3(value);
8757
9483
  const barColor = getColor2(row, i);
8758
- const pct = maxValue > 0 ? Math.abs(value) / maxValue : 0;
8759
- const rowY = fullArea.y + i * rowHeight;
9484
+ const domain2 = barlistSpec.encoding.value.scale?.domain;
9485
+ const pct = domain2 ? Math.max(0, Math.min(1, (value - domain2[0]) / (domain2[1] - domain2[0]))) : maxValue > 0 ? Math.abs(value) / maxValue : 0;
9486
+ const rowY = rowPositions[i];
8760
9487
  const centerY = rowY + rowContentHeight / 2;
8761
9488
  const labelX = fullArea.x;
8762
9489
  let displayLabel = labelText;
@@ -8766,14 +9493,14 @@ function compileBarList(spec, options) {
8766
9493
  labelText,
8767
9494
  displayLabelW,
8768
9495
  labelWidth,
8769
- LABEL_FONT_SIZE6,
8770
- LABEL_FONT_WEIGHT6
9496
+ LABEL_FONT_SIZE5,
9497
+ LABEL_FONT_WEIGHT5
8771
9498
  ));
8772
9499
  }
8773
9500
  const labelStyle = {
8774
9501
  fontFamily: theme.fonts.family,
8775
- fontSize: LABEL_FONT_SIZE6,
8776
- fontWeight: LABEL_FONT_WEIGHT6,
9502
+ fontSize: LABEL_FONT_SIZE5,
9503
+ fontWeight: LABEL_FONT_WEIGHT5,
8777
9504
  fill: labelColor,
8778
9505
  lineHeight: 1.4
8779
9506
  };
@@ -8828,6 +9555,21 @@ function compileBarList(spec, options) {
8828
9555
  };
8829
9556
  const rowMark = {
8830
9557
  type: "barlist-row",
9558
+ markType: "bar",
9559
+ fullLabel: labelText,
9560
+ identity: identityForRows(
9561
+ {
9562
+ y: { ...barlistSpec.encoding.label, type: "nominal" },
9563
+ color: barlistSpec.encoding.color,
9564
+ detail: barlistSpec.encoding.group
9565
+ },
9566
+ [row]
9567
+ ),
9568
+ authoredDescription: descriptionForRows(
9569
+ { description: barlistSpec.encoding.description },
9570
+ [row],
9571
+ []
9572
+ ),
8831
9573
  index: i,
8832
9574
  y: rowY,
8833
9575
  height: rowHeight,
@@ -8865,7 +9607,7 @@ function compileBarList(spec, options) {
8865
9607
  formattedValue,
8866
9608
  aria: {
8867
9609
  role: "listitem",
8868
- label: `${labelText}: ${formattedValue}`
9610
+ label: descriptionForRows({ description: barlistSpec.encoding.description }, [row], []) ?? `${labelText}: ${formattedValue}`
8869
9611
  },
8870
9612
  animationIndex: i,
8871
9613
  data: row
@@ -8883,16 +9625,67 @@ function compileBarList(spec, options) {
8883
9625
  });
8884
9626
  }
8885
9627
  const a11y = {
8886
- altText: `Bar list showing ${rows.length} items ranked by ${valueField}`,
9628
+ altText: barlistSpec.a11y?.description ?? `Bar list showing ${rows.length} items ranked by ${valueField}`,
9629
+ hidden: barlistSpec.a11y?.hidden,
8887
9630
  dataTableFallback: rows.map((r) => [r.label.text, r.formattedValue]),
8888
9631
  role: "list",
8889
- keyboardNavigable: rows.length > 0
9632
+ keyboardNavigable: !barlistSpec.a11y?.hidden && rows.length > 0
8890
9633
  };
9634
+ const groups = groupPositions.map(({ key, y }, index) => ({
9635
+ key,
9636
+ label: {
9637
+ text: key,
9638
+ x: fullArea.x,
9639
+ y: y + groupHeight / 2,
9640
+ visible: true,
9641
+ style: {
9642
+ fontFamily: theme.fonts.family,
9643
+ fontSize: LABEL_FONT_SIZE5,
9644
+ fontWeight: LABEL_FONT_WEIGHT5,
9645
+ fill: theme.colors.neutral.secondary,
9646
+ lineHeight: 1.4
9647
+ }
9648
+ },
9649
+ ...index ? { separator: { x1: fullArea.x, x2: fullArea.x + fullArea.width, y } } : {}
9650
+ }));
9651
+ const firstTrack = rows[0].track;
9652
+ const domain = barlistSpec.encoding.value.scale?.domain;
9653
+ const [lower, upper] = domain ?? [0, maxValue];
9654
+ const referenceLines = (barlistSpec.annotations ?? []).flatMap((annotation) => {
9655
+ if (annotation.x < Math.min(lower, upper) || annotation.x > Math.max(lower, upper)) return [];
9656
+ const x = firstTrack.x + (annotation.x - lower) / (upper - lower || 1) * firstTrack.width;
9657
+ return {
9658
+ x,
9659
+ y1: fullArea.y,
9660
+ y2: cursorY,
9661
+ stroke: annotation.stroke ?? theme.colors.axis,
9662
+ strokeWidth: annotation.strokeWidth ?? 1,
9663
+ strokeDasharray: annotation.strokeDash?.join(",") ?? (annotation.style === "dashed" ? "4,4" : annotation.style === "dotted" ? "1,3" : void 0),
9664
+ ...annotation.label ? {
9665
+ label: {
9666
+ text: annotation.label,
9667
+ x,
9668
+ y: fullArea.y - 6,
9669
+ visible: true,
9670
+ style: {
9671
+ fontFamily: theme.fonts.family,
9672
+ fontSize: annotation.fontSize ?? theme.fonts.sizes.small,
9673
+ fontWeight: annotation.fontWeight ?? 400,
9674
+ fill: annotation.fill ?? theme.colors.axis,
9675
+ lineHeight: 1.4
9676
+ }
9677
+ }
9678
+ } : {}
9679
+ };
9680
+ });
8891
9681
  const resolvedAnimation = resolveAnimation(barlistSpec.animation);
8892
9682
  return {
8893
9683
  area: fullArea,
8894
9684
  chrome,
8895
9685
  rows,
9686
+ groups,
9687
+ referenceLines,
9688
+ warnings: compileWarnings,
8896
9689
  tooltipDescriptors,
8897
9690
  a11y,
8898
9691
  theme,
@@ -8924,9 +9717,35 @@ function emptyLayout(chrome, theme, options, watermark) {
8924
9717
  };
8925
9718
  }
8926
9719
 
9720
+ // src/layout/axes/fit-labels.ts
9721
+ function fitAxisLabels(ticks, width, measure) {
9722
+ let shortened = false;
9723
+ const fitted = ticks.map((tick) => {
9724
+ const fullLabel = tick.fullLabel ?? (tick.subtitle ? `${tick.label} ${tick.subtitle}` : tick.label);
9725
+ if (measure(fullLabel) <= width) return tick;
9726
+ shortened = true;
9727
+ let left = 0, right = [...fullLabel].length;
9728
+ const characters = [...fullLabel];
9729
+ if (measure("\u2026") > width) return { ...tick, label: "", subtitle: void 0, fullLabel };
9730
+ while (left < right) {
9731
+ const middle = Math.ceil((left + right) / 2);
9732
+ if (measure(`${characters.slice(0, middle).join("")}\u2026`) <= width) left = middle;
9733
+ else right = middle - 1;
9734
+ }
9735
+ return {
9736
+ ...tick,
9737
+ label: `${characters.slice(0, left).join("")}\u2026`,
9738
+ subtitle: void 0,
9739
+ fullLabel
9740
+ };
9741
+ });
9742
+ return { ticks: fitted, shortened };
9743
+ }
9744
+
8927
9745
  // src/compile/chart.ts
8928
9746
  import {
8929
9747
  adaptTheme as adaptTheme2,
9748
+ estimateTextWidth as estimateTextWidth23,
8930
9749
  isAxislessMark as isAxislessMark4,
8931
9750
  mergeThemeConfig as mergeThemeConfig2,
8932
9751
  resolveTheme as resolveTheme2
@@ -11552,8 +12371,12 @@ function getMaxSeries(spec) {
11552
12371
  if (typeof ep === "object" && ep != null && ep.maxSeries != null) return ep.maxSeries;
11553
12372
  return DEFAULT_MAX_SERIES;
11554
12373
  }
12374
+ function isStackedColumn(spec) {
12375
+ const x = spec.encoding.x, y = spec.encoding.y;
12376
+ return spec.markType === "bar" && !!x && ["nominal", "ordinal", "temporal"].includes(x.type) && y?.type === "quantitative" && y.stack !== null && y.stack !== false && seriesField(spec) !== void 0;
12377
+ }
11555
12378
  function resolveSuppression(spec, ctx) {
11556
- const isLineOrArea2 = spec.markType === "line" || spec.markType === "area";
12379
+ const isLineOrArea2 = spec.markType === "line" || spec.markType === "area" || isStackedColumn(spec) && endpointLabelsExplicitlyOn(spec);
11557
12380
  const isMultiSeries = isLineOrArea2 && seriesField(spec) != null && ctx.seriesCount >= 2;
11558
12381
  const strategyHidesEndpoint = ctx.labelsHiddenByStrategy && !endpointLabelsExplicitlyOn(spec);
11559
12382
  if (!isMultiSeries || strategyHidesEndpoint) {
@@ -11572,11 +12395,11 @@ function resolveSuppression(spec, ctx) {
11572
12395
  const explicitOn = endpointLabelsExplicitlyOn(spec);
11573
12396
  return {
11574
12397
  showTraditionalLegend: !legendHiddenExplicitly(spec),
11575
- showEndpointLabels: explicitOn
12398
+ showEndpointLabels: explicitOn && !((spec.frame?.right !== void 0 || spec.frame?.left !== void 0) && ctx.endpointLabelsDemoted)
11576
12399
  };
11577
12400
  }
11578
12401
  const exceedsCutoff = !endpointLabelsExplicitlyOn(spec) && ctx.seriesCount > getMaxSeries(spec);
11579
- const demoted = !endpointLabelsExplicitlyOn(spec) && !!ctx.endpointLabelsDemoted;
12402
+ const demoted = !!ctx.endpointLabelsDemoted && (spec.frame?.right !== void 0 || spec.frame?.left !== void 0 || !endpointLabelsExplicitlyOn(spec));
11580
12403
  const epExplicitOff = endpointLabelsExplicitlyOff(spec) || exceedsCutoff || demoted;
11581
12404
  const legShown = legendShownExplicitly(spec);
11582
12405
  const legHidden = legendHiddenExplicitly(spec);
@@ -11712,6 +12535,40 @@ function describeRefusal(markType, display, faceted, layered) {
11712
12535
  // src/design/diagnostics.ts
11713
12536
  import { computeLabelBounds, contrastRatio as contrastRatio2, isOpaqueColor as isOpaqueColor2 } from "@opendata-ai/openchart-core";
11714
12537
 
12538
+ // src/charts/range/label-plan.ts
12539
+ import { estimateTextWidth as estimateTextWidth10 } from "@opendata-ai/openchart-core";
12540
+ function rangeLabelReserve(spec, measureText) {
12541
+ if (spec.markType !== "range" || spec.labels.content === void 0 || spec.labels.density === "none" || spec.encoding.y?.type === "quantitative")
12542
+ return 0;
12543
+ const start = spec.encoding.x, end = spec.encoding.x2;
12544
+ if (!start || !end) return 0;
12545
+ const format = resolveFieldFormatter({
12546
+ surfaceFormat: spec.labels.format,
12547
+ channelFormat: start.format,
12548
+ values: spec.data.flatMap((row) => [row[start.field], row[end.field]])
12549
+ });
12550
+ let width = 0;
12551
+ for (const row of spec.data)
12552
+ for (const channel of [start, end]) {
12553
+ const value = Number(row[channel.field]);
12554
+ if (!Number.isFinite(value)) continue;
12555
+ const text = rangeEndpointText(
12556
+ value,
12557
+ format,
12558
+ spec.labels.prefix,
12559
+ spec.labels.content,
12560
+ channel.title ?? channel.field,
12561
+ spec.labels.suffix
12562
+ );
12563
+ if (text === null) continue;
12564
+ width = Math.max(
12565
+ width,
12566
+ measureText?.(text, RANGE_LABEL_FONT_SIZE, RANGE_LABEL_FONT_WEIGHT).width ?? estimateTextWidth10(text, RANGE_LABEL_FONT_SIZE, RANGE_LABEL_FONT_WEIGHT)
12567
+ );
12568
+ }
12569
+ return width + RANGE_LABEL_OFFSET + ((spec.markDef.style ?? "dumbbell") === "dumbbell" ? 6 : 0) + 2;
12570
+ }
12571
+
11715
12572
  // src/layout/frame.ts
11716
12573
  import {
11717
12574
  BREAKPOINT_COMPACT_MAX,
@@ -11723,13 +12580,13 @@ import {
11723
12580
  } from "@opendata-ai/openchart-core";
11724
12581
 
11725
12582
  // src/endpoint-labels/predict.ts
11726
- import { estimateTextWidth as estimateTextWidth11, formatDate as formatDate2, wrapText } from "@opendata-ai/openchart-core";
12583
+ import { estimateTextWidth as estimateTextWidth12, formatDate as formatDate3, wrapText } from "@opendata-ai/openchart-core";
11727
12584
 
11728
12585
  // src/layout/scales.ts
11729
12586
  import { computeFieldFormatContext as computeFieldFormatContext3 } from "@opendata-ai/openchart-core";
11730
12587
  import { extent as extent2, max as max2, min as min2 } from "d3-array";
11731
12588
  import {
11732
- scaleBand,
12589
+ scaleBand as scaleBand2,
11733
12590
  scaleLinear as scaleLinear2,
11734
12591
  scaleLog,
11735
12592
  scaleOrdinal,
@@ -11748,7 +12605,7 @@ import {
11748
12605
  import {
11749
12606
  computeFieldFormatContext as computeFieldFormatContext2,
11750
12607
  defaultNumberFormatter as defaultNumberFormatter4,
11751
- estimateTextWidth as estimateTextWidth10,
12608
+ estimateTextWidth as estimateTextWidth11,
11752
12609
  resolveNumberFormatter as resolveNumberFormatter2,
11753
12610
  resolveSchemeName as resolveSchemeName3
11754
12611
  } from "@opendata-ai/openchart-core";
@@ -11941,7 +12798,7 @@ function computeContinuousLegendContentForChannel(values, channel, theme, availa
11941
12798
  const rowEnds = [];
11942
12799
  const rowHeight = Math.ceil(theme.fonts.sizes.small * 1.3);
11943
12800
  for (const tick of ticks2) {
11944
- const width = estimateTextWidth10(
12801
+ const width = estimateTextWidth11(
11945
12802
  tick.label,
11946
12803
  theme.fonts.sizes.small,
11947
12804
  theme.fonts.weights.normal
@@ -12303,7 +13160,7 @@ var HEATMAP_BAND_PADDING = 0.04;
12303
13160
  function buildBandScale(channel, data, rangeStart, rangeEnd, defaultPadding = DEFAULT_BAND_PADDING) {
12304
13161
  const values = channel.scale?.domain ? channel.scale.domain : applyCategoricalSort(uniqueFieldStrings2(data, channel.field), channel.sort);
12305
13162
  const padding = channel.scale?.padding ?? defaultPadding;
12306
- const scale = scaleBand().domain(values).range([rangeStart, rangeEnd]).padding(padding);
13163
+ const scale = scaleBand2().domain(values).range([rangeStart, rangeEnd]).padding(padding);
12307
13164
  if (channel.scale?.paddingInner !== void 0) {
12308
13165
  scale.paddingInner(channel.scale.paddingInner);
12309
13166
  }
@@ -12423,6 +13280,18 @@ function buildCategoricalScale(channel, data, rangeStart, rangeEnd, chartType, a
12423
13280
  const isTrendMark = chartType === "line" || chartType === "area";
12424
13281
  return buildPointScale(channel, data, rangeStart, rangeEnd, isTrendMark ? 0 : 0.5);
12425
13282
  }
13283
+ function applyTemporalBarInterval(scale, spec, data) {
13284
+ if (spec.markType !== "bar" || !scale || scale.type !== "utc" && scale.type !== "time") return;
13285
+ const interval = resolveTemporalInterval(scale.channel, data, scale.type);
13286
+ scale.temporalInterval = interval;
13287
+ if (scale.channel.scale?.domain) return;
13288
+ const continuous = scale.scale;
13289
+ const [start, end] = continuous.domain();
13290
+ continuous.domain([
13291
+ new Date(+start - (+interval.offset(start) - +start) / 2),
13292
+ new Date(+end + (+interval.offset(end) - +end) / 2)
13293
+ ]);
13294
+ }
12426
13295
  function computeScales(spec, chartArea, data) {
12427
13296
  const result = {};
12428
13297
  const encoding = spec.encoding;
@@ -12460,12 +13329,12 @@ function computeScales(spec, chartArea, data) {
12460
13329
  if (encoding.x) {
12461
13330
  let xData = data;
12462
13331
  let xChannel = encoding.x;
12463
- if ((spec.markType === "range" || spec.markType === "bar") && encoding.x2 && encoding.x.type === "quantitative") {
13332
+ if ((spec.markType === "range" || spec.markType === "bar" || spec.markType === "errorbar") && encoding.x2 && encoding.x.type === "quantitative") {
12464
13333
  const xField = encoding.x.field;
12465
13334
  const x2Field = encoding.x2.field;
12466
13335
  xData = [...data, ...data.map((row) => ({ [xField]: row[x2Field] }))];
12467
13336
  }
12468
- const xStackEnabled = encoding.x.stack === true || encoding.x.stack === "zero" || encoding.x.stack === "normalize" || encoding.x.stack === "center";
13337
+ const xStackEnabled = encoding.y?.type === "temporal" && encoding.x.stack === void 0 || encoding.x.stack === true || encoding.x.stack === "zero" || encoding.x.stack === "normalize" || encoding.x.stack === "center";
12469
13338
  if (spec.markType === "bar" && encoding.color && encoding.x.type === "quantitative" && xStackEnabled) {
12470
13339
  if (encoding.x.stack === "normalize") {
12471
13340
  const existingAxis = encoding.x.axis;
@@ -12525,6 +13394,7 @@ function computeScales(spec, chartArea, data) {
12525
13394
  spec.markType,
12526
13395
  "x"
12527
13396
  );
13397
+ applyTemporalBarInterval(result.x, spec, data);
12528
13398
  if (result.x && encoding.x.type === "quantitative" && encoding.x.field) {
12529
13399
  result.x.formatContext = computeFieldFormatContext3(fieldIterable(data, encoding.x.field));
12530
13400
  }
@@ -12532,16 +13402,16 @@ function computeScales(spec, chartArea, data) {
12532
13402
  if (encoding.y) {
12533
13403
  let yData = data;
12534
13404
  let yChannel = encoding.y;
12535
- if ((spec.markType === "range" || spec.markType === "bar") && encoding.y2 && encoding.y.type === "quantitative") {
13405
+ if ((spec.markType === "range" || spec.markType === "bar" || spec.markType === "errorbar" || spec.markType === "area") && encoding.y2 && encoding.y.type === "quantitative") {
12536
13406
  const yField = encoding.y.field;
12537
13407
  const y2Field = encoding.y2.field;
12538
13408
  yData = [...data, ...data.map((row) => ({ [yField]: row[y2Field] }))];
12539
13409
  }
12540
- const isVerticalBar = spec.markType === "bar" && (encoding.x?.type === "nominal" || encoding.x?.type === "ordinal") && encoding.y.type === "quantitative";
13410
+ const isVerticalBar = spec.markType === "bar" && (encoding.x?.type === "nominal" || encoding.x?.type === "ordinal" || encoding.x?.type === "temporal") && encoding.y.type === "quantitative";
12541
13411
  const stackProp = encoding.y.stack;
12542
13412
  const isExplicitlyStacked = stackProp === true || stackProp === "zero" || stackProp === "normalize" || stackProp === "center";
12543
13413
  const isAreaStacked = spec.markType === "area" && !!encoding.color && "field" in encoding.color && stackProp !== null && stackProp !== false;
12544
- const isBarStacked = isVerticalBar && isExplicitlyStacked;
13414
+ const isBarStacked = isVerticalBar && (isExplicitlyStacked || encoding.x?.type === "temporal" && stackProp === void 0 && !!encoding.color);
12545
13415
  const hasStackingGroup = isBarStacked && encoding.color !== void 0;
12546
13416
  const userRequestedStack = isExplicitlyStacked;
12547
13417
  const isLineOrArea2 = spec.markType === "line" || spec.markType === "area";
@@ -12640,6 +13510,7 @@ function computeScales(spec, chartArea, data) {
12640
13510
  spec.markType,
12641
13511
  "y"
12642
13512
  );
13513
+ applyTemporalBarInterval(result.y, spec, data);
12643
13514
  if (result.y && encoding.y.type === "quantitative" && encoding.y.field) {
12644
13515
  result.y.formatContext = computeFieldFormatContext3(fieldIterable(data, encoding.y.field));
12645
13516
  }
@@ -12683,6 +13554,9 @@ var ENDPOINT_LINE_HEIGHT = 1.25;
12683
13554
  var ENDPOINT_MARKER_RADIUS = 4;
12684
13555
  var ENDPOINT_MARKER_STROKE_WIDTH = 2;
12685
13556
  var ENDPOINT_LEADER_THRESHOLD = 8;
13557
+ function endpointTrailingPadding(fixedLane) {
13558
+ return fixedLane === void 0 ? 4 : 0;
13559
+ }
12686
13560
 
12687
13561
  // src/endpoint-labels/format.ts
12688
13562
  import { defaultNumberFormatter as defaultNumberFormatter5 } from "@opendata-ai/openchart-core";
@@ -12791,7 +13665,8 @@ function predictEndpointLabelsWidth(spec, theme, measureText, xScaleType) {
12791
13665
  if (spec.endpointLabels === false) return 0;
12792
13666
  if (xScaleType === void 0 && spec.encoding.x?.type === "temporal")
12793
13667
  xScaleType = spec.encoding.x.scale?.type ?? resolveTemporalScaleType(spec.encoding.x, spec.data);
12794
- if (spec.markType !== "line" && spec.markType !== "area") return 0;
13668
+ if (spec.markType !== "line" && spec.markType !== "area" && !(isStackedColumn(spec) && endpointLabelsExplicitlyOn(spec)))
13669
+ return 0;
12795
13670
  const field = seriesField(spec);
12796
13671
  if (!field) return 0;
12797
13672
  const seriesNames = /* @__PURE__ */ new Set();
@@ -12816,7 +13691,7 @@ function predictEndpointLabelsWidth(spec, theme, measureText, xScaleType) {
12816
13691
  spec,
12817
13692
  displayed.map(({ row }) => row[valueField ?? ""])
12818
13693
  );
12819
- const measure = (text, size, weight) => measureText?.(text, size, weight).width ?? estimateTextWidth11(text, size, weight);
13694
+ const measure = (text, size, weight) => measureText?.(text, size, weight).width ?? estimateTextWidth12(text, size, weight);
12820
13695
  const sideTextWidth = (side) => {
12821
13696
  const content = resolveEndpointContent(config?.content, side);
12822
13697
  const rows = sideRows(side);
@@ -12848,7 +13723,7 @@ function predictEndpointLabelsWidth(spec, theme, measureText, xScaleType) {
12848
13723
  measure(formatted, theme.fonts.sizes.endpointValue, ENDPOINT_VALUE_FONT_WEIGHT)
12849
13724
  );
12850
13725
  if (qualify && (spec.encoding.x?.type !== "temporal" || xScaleType)) {
12851
- const date = spec.encoding.x?.type === "temporal" ? formatDate2(
13726
+ const date = spec.encoding.x?.type === "temporal" ? formatDate3(
12852
13727
  row[xField],
12853
13728
  void 0,
12854
13729
  void 0,
@@ -12866,7 +13741,10 @@ function predictEndpointLabelsWidth(spec, theme, measureText, xScaleType) {
12866
13741
  if (config?.ends === "both") {
12867
13742
  textColumn = Math.max(textColumn, sideTextWidth("leading"));
12868
13743
  }
12869
- return Math.max(ENDPOINT_SWATCH_SIZE + ENDPOINT_GAP + textColumn + 4, 32);
13744
+ return Math.max(
13745
+ ENDPOINT_SWATCH_SIZE + ENDPOINT_GAP + textColumn + endpointTrailingPadding(spec.frame?.right),
13746
+ 32
13747
+ );
12870
13748
  }
12871
13749
  function isEndsBoth(spec) {
12872
13750
  const ep = spec.endpointLabels;
@@ -12874,7 +13752,7 @@ function isEndsBoth(spec) {
12874
13752
  }
12875
13753
 
12876
13754
  // src/legend/compute.ts
12877
- import { BRAND_RESERVE_WIDTH, COMPACT_WIDTH as COMPACT_WIDTH2, estimateTextWidth as estimateTextWidth13 } from "@opendata-ai/openchart-core";
13755
+ import { BRAND_RESERVE_WIDTH, COMPACT_WIDTH as COMPACT_WIDTH2, estimateTextWidth as estimateTextWidth14 } from "@opendata-ai/openchart-core";
12878
13756
 
12879
13757
  // src/compile/color-scale-range.ts
12880
13758
  import {
@@ -12952,7 +13830,7 @@ function applyColorScaleRange(scales, encoding, theme, highlight, markType) {
12952
13830
  }
12953
13831
 
12954
13832
  // src/legend/wrap.ts
12955
- import { COMPACT_WIDTH, estimateTextWidth as estimateTextWidth12 } from "@opendata-ai/openchart-core";
13833
+ import { COMPACT_WIDTH, estimateTextWidth as estimateTextWidth13 } from "@opendata-ai/openchart-core";
12956
13834
  var SWATCH_SIZE = 12;
12957
13835
  var SWATCH_GAP = 6;
12958
13836
  var ENTRY_GAP = 16;
@@ -12966,7 +13844,7 @@ function measureLegendWrap(entries, maxWidth, labelStyle, maxRows, entryGap = EN
12966
13844
  if (entries.length === 0) {
12967
13845
  return { rowCount: 0, fittingCount: 0, rowWidths: [], placements: [] };
12968
13846
  }
12969
- const measureWidth = measure ?? estimateTextWidth12;
13847
+ const measureWidth = measure ?? estimateTextWidth13;
12970
13848
  let rowCount = 1;
12971
13849
  let rowWidth = 0;
12972
13850
  const rowWidths = [];
@@ -13127,7 +14005,7 @@ function emptyContent(position, theme) {
13127
14005
  };
13128
14006
  }
13129
14007
  function computeLegendContent(spec, strategy, theme, availableWidth, availableHeight, watermark = true, measure, endpointLabelsDemoted) {
13130
- const measureWidth = measure ?? estimateTextWidth13;
14008
+ const measureWidth = measure ?? estimateTextWidth14;
13131
14009
  const sparklineHidden = spec.display === "sparkline" && !spec.userExplicit.legend;
13132
14010
  if (sparklineHidden || spec.legend?.show === false || strategy.legendMaxHeight === 0) {
13133
14011
  return emptyContent("top", theme);
@@ -13202,7 +14080,7 @@ function computeLegendContent(spec, strategy, theme, availableWidth, availableHe
13202
14080
  measureWidth
13203
14081
  );
13204
14082
  }
13205
- function measureCategoricalLegendContent(entries, legend, strategy, theme, availableWidth, availableHeight, watermark = true, measureWidth = estimateTextWidth13) {
14083
+ function measureCategoricalLegendContent(entries, legend, strategy, theme, availableWidth, availableHeight, watermark = true, measureWidth = estimateTextWidth14) {
13206
14084
  const labelStyle = {
13207
14085
  fontFamily: theme.fonts.family,
13208
14086
  fontSize: theme.fonts.sizes.small,
@@ -13417,7 +14295,7 @@ function placeLegend(content, chartArea, containerWidth, _theme, xAxisHeight, ax
13417
14295
  import {
13418
14296
  abbreviateNumber,
13419
14297
  buildD3Formatter,
13420
- estimateTextWidth as estimateTextWidth14,
14298
+ estimateTextWidth as estimateTextWidth15,
13421
14299
  formatNumber as formatNumber3
13422
14300
  } from "@opendata-ai/openchart-core";
13423
14301
  import { scaleLinear as scaleLinear3, scaleSqrt as scaleSqrt3 } from "d3-scale";
@@ -13533,11 +14411,11 @@ function computeSizeLegendContent(sizeEncoding, data, theme, options) {
13533
14411
  };
13534
14412
  });
13535
14413
  const widestLabel = Math.max(
13536
- ...circles.map((c) => estimateTextWidth14(c.label, fontSize, theme.fonts.weights.normal))
14414
+ ...circles.map((c) => estimateTextWidth15(c.label, fontSize, theme.fonts.weights.normal))
13537
14415
  );
13538
14416
  const lastLabelBottom = (circles[circles.length - 1]?.labelY ?? 0) + fontSize * 0.5;
13539
14417
  const circleBlockWidth = maxRadius * 2 + LABEL_GAP + widestLabel;
13540
- const titleWidth = title ? estimateTextWidth14(title, fontSize, theme.fonts.weights.medium) : 0;
14418
+ const titleWidth = title ? estimateTextWidth15(title, fontSize, theme.fonts.weights.medium) : 0;
13541
14419
  return {
13542
14420
  circles,
13543
14421
  width: Math.max(circleBlockWidth, titleWidth),
@@ -13581,7 +14459,7 @@ function placeSizeLegend(content, chartArea, theme, colorLegend) {
13581
14459
  import {
13582
14460
  axisTitleOffset,
13583
14461
  computeXAxisExtentFromLabels,
13584
- estimateTextWidth as estimateTextWidth17,
14462
+ estimateTextWidth as estimateTextWidth18,
13585
14463
  truncateRotatedLabel,
13586
14464
  X_AXIS_TITLE_BAND,
13587
14465
  X_AXIS_TITLE_BAND_ROTATED
@@ -13626,11 +14504,11 @@ function bandLabelStride(maxLabelWidth, angleDeg, fontSize, spacing) {
13626
14504
  }
13627
14505
 
13628
14506
  // src/layout/axes/thinning.ts
13629
- import { estimateTextWidth as estimateTextWidth15 } from "@opendata-ai/openchart-core";
14507
+ import { estimateTextWidth as estimateTextWidth16 } from "@opendata-ai/openchart-core";
13630
14508
  var MIN_TICK_GAP_FACTOR = 0.5;
13631
14509
  var MIN_TICK_COUNT = 2;
13632
14510
  function measureLabel(text, fontSize, fontWeight, measureText) {
13633
- return measureText ? measureText(text, fontSize, fontWeight).width : estimateTextWidth15(text, fontSize, fontWeight);
14511
+ return measureText ? measureText(text, fontSize, fontWeight).width : estimateTextWidth16(text, fontSize, fontWeight);
13634
14512
  }
13635
14513
  function ticksOverlap(ticks, fontSize, fontWeight, measureText, orientation = "horizontal") {
13636
14514
  if (ticks.length < 2) return false;
@@ -13671,8 +14549,8 @@ function thinTicksUntilFit(ticks, fontSize, fontWeight, measureText, orientation
13671
14549
 
13672
14550
  // src/layout/axes/ticks.ts
13673
14551
  import {
13674
- buildTemporalFormatter,
13675
- formatDate as formatDate3,
14552
+ buildTemporalFormatter as buildTemporalFormatter2,
14553
+ formatDate as formatDate4,
13676
14554
  resolveNumberFormatter as resolveNumberFormatter3
13677
14555
  } from "@opendata-ai/openchart-core";
13678
14556
  var Y_PX_PER_TICK = {
@@ -13722,10 +14600,10 @@ function formatTickLabel(value, resolvedScale, compact = false, tickContext) {
13722
14600
  const formatStr = axisConfig?.format;
13723
14601
  const suffix = axisConfig?.labelSuffix ?? "";
13724
14602
  if (TEMPORAL_SCALE_TYPES.has(resolvedScale.type)) {
13725
- const temporalFmt = buildTemporalFormatter(formatStr);
14603
+ const temporalFmt = buildTemporalFormatter2(formatStr);
13726
14604
  if (temporalFmt) return temporalFmt(value) + suffix;
13727
14605
  const useUtc = resolvedScale.type === "utc";
13728
- return formatDate3(value, void 0, void 0, useUtc, compact) + suffix;
14606
+ return formatDate4(value, void 0, void 0, useUtc, compact) + suffix;
13729
14607
  }
13730
14608
  if (NUMERIC_SCALE_TYPES.has(resolvedScale.type)) {
13731
14609
  const num = value;
@@ -13907,7 +14785,7 @@ function resolveExplicitTicks(values, resolvedScale) {
13907
14785
  }
13908
14786
 
13909
14787
  // src/layout/axis-title-plan.ts
13910
- import { estimateTextWidth as estimateTextWidth16, wrapText as wrapText2 } from "@opendata-ai/openchart-core";
14788
+ import { estimateTextWidth as estimateTextWidth17, wrapText as wrapText2 } from "@opendata-ai/openchart-core";
13911
14789
  function isYAxisHeader(channel) {
13912
14790
  const axis = channel?.axis;
13913
14791
  return !!axis && axis.titleAngle === 0 && axis.titleAnchor === "end" && !!axis.title;
@@ -13939,7 +14817,7 @@ function authoredTitleFootprint(channel, theme, measureText) {
13939
14817
  if (!axis || !axis.title || axis.titleAngle === void 0 || isYAxisHeader(channel))
13940
14818
  return void 0;
13941
14819
  const size = theme.fonts.sizes.body;
13942
- const width = measureText?.(axis.title, size, theme.fonts.weights.medium).width ?? estimateTextWidth16(axis.title, size, theme.fonts.weights.medium);
14820
+ const width = measureText?.(axis.title, size, theme.fonts.weights.medium).width ?? estimateTextWidth17(axis.title, size, theme.fonts.weights.medium);
13943
14821
  const angle = axis.titleAngle * Math.PI / 180;
13944
14822
  return {
13945
14823
  width: Math.abs(Math.cos(angle)) * width + Math.abs(Math.sin(angle)) * size,
@@ -14386,7 +15264,7 @@ function computeAxes(scales, chartArea, strategy, theme, measureText, dataContex
14386
15264
  const isRight = result.y.orient === "right";
14387
15265
  if (isRight) {
14388
15266
  const maxTickLabelWidth = result.y.ticks.reduce((max4, t) => {
14389
- const w = estimateTextWidth17(
15267
+ const w = estimateTextWidth18(
14390
15268
  t.label,
14391
15269
  result.y.tickLabelStyle.fontSize,
14392
15270
  result.y.tickLabelStyle.fontWeight ?? 400
@@ -14401,7 +15279,7 @@ function computeAxes(scales, chartArea, strategy, theme, measureText, dataContex
14401
15279
  };
14402
15280
  } else {
14403
15281
  const maxTickLabelWidth = result.y.ticks.reduce((max4, t) => {
14404
- const w = estimateTextWidth17(
15282
+ const w = estimateTextWidth18(
14405
15283
  t.label,
14406
15284
  result.y.tickLabelStyle.fontSize,
14407
15285
  result.y.tickLabelStyle.fontWeight ?? 400
@@ -14461,7 +15339,7 @@ function computeAxes(scales, chartArea, strategy, theme, measureText, dataContex
14461
15339
  if (yConfig.titleAnchor) {
14462
15340
  const anchor = yConfig.titleAnchor;
14463
15341
  result.y.titlePosition.y = chartArea.y + chartArea.height * (anchor === "start" ? 1 : anchor === "end" ? 0 : 0.5);
14464
- const half = (footprint?.height ?? estimateTextWidth17(
15342
+ const half = (footprint?.height ?? estimateTextWidth18(
14465
15343
  result.y.label ?? "",
14466
15344
  theme.fonts.sizes.body,
14467
15345
  theme.fonts.weights.medium
@@ -14484,7 +15362,7 @@ function computeAxes(scales, chartArea, strategy, theme, measureText, dataContex
14484
15362
  }
14485
15363
 
14486
15364
  // src/layout/metrics.ts
14487
- import { estimateTextWidth as estimateTextWidth18 } from "@opendata-ai/openchart-core";
15365
+ import { estimateTextWidth as estimateTextWidth19 } from "@opendata-ai/openchart-core";
14488
15366
  var DEFAULT_LABEL_FONT_SIZE = 10;
14489
15367
  var DEFAULT_VALUE_FONT_SIZE = 22;
14490
15368
  var LABEL_LINE_HEIGHT_RATIO = 1.4;
@@ -14517,7 +15395,7 @@ function computeMetricBar(metrics, metricsTopY, metricsArea, remainingChartHeigh
14517
15395
  const cellWidth = metricsArea.width / metrics.length;
14518
15396
  for (const metric of metrics) {
14519
15397
  const text = valueRunText(metric);
14520
- const measured = measureText ? measureText(text, fonts.value, 510).width : estimateTextWidth18(text, fonts.value, 510);
15398
+ const measured = measureText ? measureText(text, fonts.value, 510).width : estimateTextWidth19(text, fonts.value, 510);
14521
15399
  if (measured > cellWidth - CELL_INNER_PAD) return void 0;
14522
15400
  }
14523
15401
  const labelLine = fonts.label * LABEL_LINE_HEIGHT_RATIO;
@@ -14632,7 +15510,7 @@ function frameSpacing(ctx) {
14632
15510
  };
14633
15511
  }
14634
15512
  function frameReference(ctx, spacing) {
14635
- return chromeInsetReference(
15513
+ const reference = chromeInsetReference(
14636
15514
  ctx.reserves.reference,
14637
15515
  ctx.spec.annotations,
14638
15516
  ctx.options.width,
@@ -14640,6 +15518,16 @@ function frameReference(ctx, spacing) {
14640
15518
  ctx.theme,
14641
15519
  spacing.padding
14642
15520
  );
15521
+ const fixedRight = ctx.spec.frame?.right;
15522
+ if (fixedRight === void 0) return reference;
15523
+ const suppression = resolveSuppression(ctx.spec, {
15524
+ seriesCount: countColorSeries(ctx.spec),
15525
+ labelsHiddenByStrategy: ctx.strategy?.labelMode === "none"
15526
+ });
15527
+ const endpointWidth = predictEndpointLabelsWidth(ctx.spec, ctx.theme, ctx.options.measureText);
15528
+ const endpointReserve = endpointWidth + ctx.theme.spacing.endpointColumnGap;
15529
+ const available = suppression.showEndpointLabels && endpointWidth > 0 && endpointReserve <= fixedRight ? fixedRight - endpointReserve : fixedRight;
15530
+ return reference.right > available ? { ...reference, right: 0 } : reference;
14643
15531
  }
14644
15532
  function frameMargins(ctx, spacing, reference, measures) {
14645
15533
  const { spec, options, theme, strategy } = ctx;
@@ -14661,6 +15549,9 @@ function frameMargins(ctx, spacing, reference, measures) {
14661
15549
  }
14662
15550
  left = Math.max(left, measures.leftGutter) + (measures.valueLabelPlan?.reserveLeft ?? 0);
14663
15551
  right += measures.valueLabelPlan?.reserveRight ?? 0;
15552
+ const rangeReserve = rangeLabelReserve(spec, options.measureText);
15553
+ left = Math.max(left, rangeReserve);
15554
+ right = Math.max(right, rangeReserve);
14664
15555
  if (options.rightAxisReserve && options.rightAxisReserve > 0) {
14665
15556
  right = Math.max(right, hPad + options.rightAxisReserve);
14666
15557
  }
@@ -14669,7 +15560,7 @@ function frameMargins(ctx, spacing, reference, measures) {
14669
15560
  const colorReserve = colorLegendInGutter ? legend.legendWidth + 8 : 0;
14670
15561
  const sizeReserve = measures.sizeLegendContent ? measures.sizeLegendContent.width + SIZE_LEGEND_GAP : 0;
14671
15562
  right += Math.max(colorReserve, sizeReserve) + reference.right;
14672
- return { left, right };
15563
+ return { left: spec.frame?.left ?? left, right: spec.frame?.right ?? right };
14673
15564
  }
14674
15565
  function createFrame(ctx, measures, chrome) {
14675
15566
  const { spec, options, theme } = ctx;
@@ -14993,21 +15884,22 @@ function diagnoseChart(spec, layout) {
14993
15884
 
14994
15885
  // src/endpoint-labels/compute.ts
14995
15886
  import {
14996
- estimateTextWidth as estimateTextWidth20,
14997
- formatDate as formatDate4,
15887
+ estimateTextWidth as estimateTextWidth21,
15888
+ formatDate as formatDate5,
15889
+ getRepresentativeColor as getRepresentativeColor14,
14998
15890
  pickLabelColor as pickLabelColor3,
14999
15891
  wrapText as wrapText3
15000
15892
  } from "@opendata-ai/openchart-core";
15001
15893
 
15002
15894
  // src/endpoint-labels/interior.ts
15003
- import { estimateTextWidth as estimateTextWidth19 } from "@opendata-ai/openchart-core";
15895
+ import { estimateTextWidth as estimateTextWidth20 } from "@opendata-ai/openchart-core";
15004
15896
  function fitInteriorLabel(mark, style, color, measureText) {
15005
15897
  if (!mark.stacked || !mark.seriesKey || !mark.dataPoints?.length) return null;
15006
15898
  if (mark.interpolate && !["linear", "monotone", "step", "step-before", "step-after"].includes(mark.interpolate))
15007
15899
  return null;
15008
15900
  const size = style.fontSize ?? 11;
15009
15901
  const measured = measureText?.(mark.seriesKey, size, style.fontWeight);
15010
- const width = measured?.width ?? estimateTextWidth19(mark.seriesKey, size, style.fontWeight);
15902
+ const width = measured?.width ?? estimateTextWidth20(mark.seriesKey, size, style.fontWeight);
15011
15903
  const height = Math.max(measured?.height ?? size, size * (style.lineHeight ?? 1.25));
15012
15904
  const padding = 4;
15013
15905
  let best = null;
@@ -15136,6 +16028,8 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
15136
16028
  if (strategy?.labelMode === "none" && !endpointLabelsExplicitlyOn(spec)) {
15137
16029
  return emptyLayout2(theme);
15138
16030
  }
16031
+ if ((spec.frame?.right !== void 0 || spec.frame?.left !== void 0) && endpointLabelsDemoted)
16032
+ return emptyLayout2(theme);
15139
16033
  const highlight = spec.highlight ?? [];
15140
16034
  const highlightActive = highlight.length > 0;
15141
16035
  const seriesCount = countColorSeries(spec);
@@ -15149,7 +16043,35 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
15149
16043
  const epExplicitlyOff = spec.endpointLabels === false || typeof spec.endpointLabels === "object" && spec.endpointLabels?.show === false;
15150
16044
  if (!sup.showEndpointLabels && !(highlightActive && !epExplicitlyOff)) return emptyLayout2(theme);
15151
16045
  const bySeriesKey = /* @__PURE__ */ new Map();
15152
- for (const mark of marks) {
16046
+ const endpointMarks = [...marks];
16047
+ if (isStackedColumn(spec) && endpointLabelsExplicitlyOn(spec)) {
16048
+ const columns = /* @__PURE__ */ new Map();
16049
+ for (const mark of marks) {
16050
+ if (mark.type !== "rect" || !mark.seriesKey) continue;
16051
+ const group = columns.get(mark.seriesKey) ?? [];
16052
+ group.push(mark);
16053
+ columns.set(mark.seriesKey, group);
16054
+ }
16055
+ for (const [seriesKey, segments2] of columns) {
16056
+ segments2.sort((a, b) => a.x - b.x);
16057
+ const dataPoints = segments2.map((segment) => ({
16058
+ x: segment.x + segment.width / 2,
16059
+ y: segment.y + segment.height / 2,
16060
+ datum: segment.data
16061
+ }));
16062
+ endpointMarks.push({
16063
+ type: "line",
16064
+ seriesKey,
16065
+ points: dataPoints,
16066
+ dataPoints,
16067
+ data: segments2.map((segment) => segment.data),
16068
+ stroke: getRepresentativeColor14(segments2[segments2.length - 1].fill),
16069
+ strokeWidth: 0,
16070
+ aria: { decorative: true }
16071
+ });
16072
+ }
16073
+ }
16074
+ for (const mark of endpointMarks) {
15153
16075
  if (!isLineOrArea(mark) || !mark.seriesKey) continue;
15154
16076
  const existing = bySeriesKey.get(mark.seriesKey);
15155
16077
  if (!existing || existing.type === "area" && !existing.stacked && mark.type === "line" || mark.type === "area" && mark.stacked) {
@@ -15169,11 +16091,11 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
15169
16091
  return config?.ends === "both" ? [trailing, endpointObservation(mark, "leading", anchor)?.datum[valueField ?? ""]] : [trailing];
15170
16092
  });
15171
16093
  const endpointFormatter2 = endpointFormatter(spec, endpointValues);
15172
- const measure = (text, size, weight) => measureText?.(text, size, weight).width ?? estimateTextWidth20(text, size, weight);
16094
+ const measure = (text, size, weight) => measureText?.(text, size, weight).width ?? estimateTextWidth21(text, size, weight);
15173
16095
  const dateFor = (value) => {
15174
16096
  if (spec.encoding.x?.type !== "temporal") return value == null ? void 0 : String(value);
15175
16097
  if (!xScaleType) return void 0;
15176
- return formatDate4(value, void 0, void 0, xScaleType === "utc");
16098
+ return formatDate5(value, void 0, void 0, xScaleType === "utc");
15177
16099
  };
15178
16100
  const endpointDates = (side) => new Set(
15179
16101
  lineOrAreaMarks.map(
@@ -15182,7 +16104,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
15182
16104
  );
15183
16105
  const qualifyTrailing = config?.placement === "interior" || endpointDates("trailing").size > 1;
15184
16106
  const qualifyLeading = config?.placement === "interior" || endpointDates("leading").size > 1;
15185
- const showMarker = config?.showMarker !== false;
16107
+ const showMarker = !isStackedColumn(spec) && config?.showMarker !== false;
15186
16108
  const markerRadius = config?.markerStyle?.radius ?? ENDPOINT_MARKER_RADIUS;
15187
16109
  const markerStrokeWidth = config?.markerStyle?.strokeWidth ?? ENDPOINT_MARKER_STROKE_WIDTH;
15188
16110
  const markerFill = config?.markerStyle?.fill ?? resolveKnockoutColor(theme);
@@ -15288,7 +16210,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
15288
16210
  }));
15289
16211
  const sweptTops = bidirectionalSweep(sweepInput, chartArea.y, chartArea.y + chartArea.height);
15290
16212
  const columnWidth = Math.max(
15291
- ENDPOINT_SWATCH_SIZE + ENDPOINT_GAP + Math.max(...provisional.map((p) => p.width), 0) + 4,
16213
+ ENDPOINT_SWATCH_SIZE + ENDPOINT_GAP + Math.max(...provisional.map((p) => p.width), 0) + endpointTrailingPadding(spec.frame?.right),
15292
16214
  32
15293
16215
  );
15294
16216
  const columnX = chartArea.x + chartArea.width + theme.spacing.endpointColumnGap;
@@ -15397,7 +16319,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
15397
16319
  chartArea.y + chartArea.height
15398
16320
  );
15399
16321
  const leadingColumnWidth = Math.max(
15400
- ENDPOINT_SWATCH_SIZE + ENDPOINT_GAP + Math.max(...leadingProvisional.map((p) => p.width), 0) + 4,
16322
+ ENDPOINT_SWATCH_SIZE + ENDPOINT_GAP + Math.max(...leadingProvisional.map((p) => p.width), 0) + endpointTrailingPadding(spec.frame?.left),
15401
16323
  32
15402
16324
  );
15403
16325
  const leadingColumnX = chartArea.x - theme.spacing.endpointColumnGap - leadingColumnWidth;
@@ -15472,7 +16394,7 @@ import {
15472
16394
  computeFieldFormatContext as computeFieldFormatContext5,
15473
16395
  computeXAxisExtentFromLabels as computeXAxisExtentFromLabels2,
15474
16396
  defaultNumberFormatter as defaultNumberFormatter6,
15475
- estimateTextWidth as estimateTextWidth21,
16397
+ estimateTextWidth as estimateTextWidth22,
15476
16398
  getHeightClass as getHeightClass2,
15477
16399
  HPAD_COMPACT_FRACTION as HPAD_COMPACT_FRACTION2,
15478
16400
  HPAD_COMPACT_MIN as HPAD_COMPACT_MIN2,
@@ -15490,7 +16412,7 @@ function createMeasureFn(measureText) {
15490
16412
  if (measureText) {
15491
16413
  return (text, fontSize, fontWeight) => measureText(text, fontSize, fontWeight).width;
15492
16414
  }
15493
- return estimateTextWidth21;
16415
+ return estimateTextWidth22;
15494
16416
  }
15495
16417
  function sampleLabelFromContext(maxAbsVal, yAxisFormat, ctx) {
15496
16418
  if (yAxisFormat) {
@@ -15501,6 +16423,12 @@ function sampleLabelFromContext(maxAbsVal, yAxisFormat, ctx) {
15501
16423
  }
15502
16424
  var MAX_ENDPOINT_FRACTION = 0.3;
15503
16425
  function endpointLabelsDemotedAt(chartSpec, theme, width, measureText) {
16426
+ const fixedRight = chartSpec.frame?.right;
16427
+ const fixedLeft = isEndsBoth(chartSpec) ? chartSpec.frame?.left : void 0;
16428
+ const measuredWidth = predictEndpointLabelsWidth(chartSpec, theme, measureText);
16429
+ const required = measuredWidth + theme.spacing.endpointColumnGap;
16430
+ if (measuredWidth > 0 && (fixedRight !== void 0 && required > fixedRight || fixedLeft !== void 0 && required > fixedLeft))
16431
+ return true;
15504
16432
  if (!chartSpec.autoThin || chartSpec.legend?.show === false || endpointLabelsExplicitlyOn(chartSpec))
15505
16433
  return false;
15506
16434
  const epWidth = predictEndpointLabelsWidth(chartSpec, theme, measureText);
@@ -15864,7 +16792,7 @@ function resolveLayoutPlan(chartSpec, renderSpec, options, theme, strategy, wate
15864
16792
  }
15865
16793
  }
15866
16794
  let inlineYLabelInset = 0;
15867
- if (yIsInline && encoding.y && yIsContinuous && encoding.y.axis !== false) {
16795
+ if (chartSpec.frame?.left === void 0 && yIsInline && encoding.y && yIsContinuous && encoding.y.axis !== false) {
15868
16796
  if (yTickValues.length > 0) {
15869
16797
  const scales = computeScales(renderSpec, finalArea, renderSpec.data);
15870
16798
  if (scales.y && scaleSupportsTickCount(scales.y)) {
@@ -16100,15 +17028,18 @@ function getSparklinePad(spec) {
16100
17028
  const strokeWidth = spec.markDef.strokeWidth ?? 2;
16101
17029
  const point = spec.markDef.point;
16102
17030
  const strokePad = Math.max(strokeWidth / 2 + 1, 2);
17031
+ const radius = spec.markType === "point" ? spec.markDef.size ?? 4 : 0;
17032
+ const cap = spec.markType === "errorbar" && spec.markDef.ticks ? ERRORBAR_CAP_LENGTH / 2 + strokeWidth / 2 : 0;
17033
+ const shapePad = Math.max(strokePad, radius > 3.5 ? radius + 0.5 : 0, cap);
16103
17034
  const dotPad = 4;
16104
17035
  const dotRight = point === "last" || point === true || point === "endpoints" || point === "transparent";
16105
17036
  const dotLeft = point === "first" || point === true || point === "endpoints" || point === "transparent";
16106
17037
  const hasDots = dotRight || dotLeft;
16107
17038
  return {
16108
- left: dotLeft ? Math.max(strokePad, dotPad) : strokePad,
16109
- right: dotRight ? Math.max(strokePad, dotPad) : strokePad,
16110
- top: hasDots ? Math.max(strokePad, dotPad) : strokePad,
16111
- bottom: hasDots ? Math.max(strokePad, dotPad) : strokePad
17039
+ left: dotLeft ? Math.max(shapePad, dotPad) : shapePad,
17040
+ right: dotRight ? Math.max(shapePad, dotPad) : shapePad,
17041
+ top: hasDots ? Math.max(shapePad, dotPad) : shapePad,
17042
+ bottom: hasDots ? Math.max(shapePad, dotPad) : shapePad
16112
17043
  };
16113
17044
  }
16114
17045
  function resolveFigureBudget(spec, options, legendLayout, theme, strategy, watermark, plan, reserves = { noteBand: 0, reference: NO_REFERENCE_RESERVE }) {
@@ -16139,7 +17070,7 @@ function resolveFigureBudget(spec, options, legendLayout, theme, strategy, water
16139
17070
  const total = { x: 0, y: 0, width, height: effectiveHeight };
16140
17071
  const degraded = [];
16141
17072
  if (spec.display === "sparkline") {
16142
- const sparkPad = getSparklinePad(spec);
17073
+ const sparkPad = options.sparklinePad ?? getSparklinePad(spec);
16143
17074
  const xAxisSpace = userExplicit.xAxis ? 26 : 0;
16144
17075
  const yAxisSpace = userExplicit.yAxis ? 30 : 0;
16145
17076
  const legend = userExplicit.legend && hasLegendContent(plan.legendContent);
@@ -16163,6 +17094,8 @@ function resolveFigureBudget(spec, options, legendLayout, theme, strategy, water
16163
17094
  };
16164
17095
  if (legend && (legendLayout.position === "right" || legendLayout.position === "bottom-right"))
16165
17096
  margins.right += legendLayout.bounds.width + 8;
17097
+ margins.left = spec.frame?.left ?? margins.left;
17098
+ margins.right = spec.frame?.right ?? margins.right;
16166
17099
  const chartArea = {
16167
17100
  x: margins.left,
16168
17101
  y: margins.top,
@@ -16299,18 +17232,18 @@ function computeGridlines(axes, chartArea, showVertical = false) {
16299
17232
 
16300
17233
  // src/tooltips/compute.ts
16301
17234
  import {
16302
- buildTemporalFormatter as buildTemporalFormatter2,
17235
+ buildTemporalFormatter as buildTemporalFormatter3,
16303
17236
  defaultNumberFormatter as defaultNumberFormatter7,
16304
- formatDate as formatDate5,
17237
+ formatDate as formatDate6,
16305
17238
  formatPercent as formatPercent4,
16306
- getRepresentativeColor as getRepresentativeColor13
17239
+ getRepresentativeColor as getRepresentativeColor15
16307
17240
  } from "@opendata-ai/openchart-core";
16308
17241
  function formatValue2(value, fieldType, formatter) {
16309
17242
  if (value == null) return "";
16310
17243
  if (fieldType === "temporal" || value instanceof Date) {
16311
17244
  if (formatter)
16312
17245
  return formatter(value);
16313
- return formatDate5(value);
17246
+ return formatDate6(value);
16314
17247
  }
16315
17248
  if (typeof value === "number") {
16316
17249
  if (formatter) return formatter(value);
@@ -16339,7 +17272,7 @@ function buildFormatterCache(data, channels) {
16339
17272
  if (cache.has(key)) continue;
16340
17273
  const fmt2 = resolveFormat(ch);
16341
17274
  if (ch.type === "temporal") {
16342
- const temporalFmt = buildTemporalFormatter2(fmt2);
17275
+ const temporalFmt = buildTemporalFormatter3(fmt2);
16343
17276
  cache.set(key, temporalFmt ?? null);
16344
17277
  } else if (ch.type === "quantitative") {
16345
17278
  cache.set(
@@ -16483,13 +17416,13 @@ function getTooltipTitle(row, encoding, encodedFields) {
16483
17416
  }
16484
17417
  return {};
16485
17418
  }
16486
- function tooltipsForLine(mark, encoding, formatters, _markIndex, encodedFields, stackTotals) {
17419
+ function tooltipsForLine(mark, encoding, formatters, _markIndex, encodedFields, stackTotals2) {
16487
17420
  if (mark.dataPoints) {
16488
17421
  for (const dp of mark.dataPoints) {
16489
17422
  const { title, channel } = getTooltipTitle(dp.datum, encoding, encodedFields);
16490
17423
  const fields = buildFields(dp.datum, encoding, formatters, mark.stroke, channel);
16491
- if (stackTotals && encoding.x) {
16492
- const total = stackTotals.get(stackKeyOf(dp.datum[encoding.x.field]));
17424
+ if (stackTotals2 && encoding.x) {
17425
+ const total = stackTotals2.get(stackKeyOf(dp.datum[encoding.x.field]));
16493
17426
  if (total) fields.push(total);
16494
17427
  }
16495
17428
  dp.tooltip = { title, fields };
@@ -16503,21 +17436,21 @@ function tooltipsForPoint(mark, encoding, formatters, markIndex, encodedFields)
16503
17436
  mark.data,
16504
17437
  encoding,
16505
17438
  formatters,
16506
- getRepresentativeColor13(mark.fill),
17439
+ getRepresentativeColor15(mark.fill),
16507
17440
  channel
16508
17441
  );
16509
17442
  return [[`point-${markIndex}`, { title, fields }]];
16510
17443
  }
16511
- function tooltipsForRect(mark, encoding, formatters, markIndex, encodedFields, stackTotals) {
17444
+ function tooltipsForRect(mark, encoding, formatters, markIndex, encodedFields, stackTotals2) {
16512
17445
  const { title, channel } = getTooltipTitle(mark.data, encoding, encodedFields);
16513
17446
  const fields = buildFields(
16514
17447
  mark.data,
16515
17448
  encoding,
16516
17449
  formatters,
16517
- getRepresentativeColor13(mark.fill),
17450
+ getRepresentativeColor15(mark.fill),
16518
17451
  channel
16519
17452
  );
16520
- const total = mark.stackGroup !== void 0 ? stackTotals?.get(mark.stackGroup) : void 0;
17453
+ const total = mark.stackGroup !== void 0 ? stackTotals2?.get(mark.stackGroup) : void 0;
16521
17454
  if (total) fields.push(total);
16522
17455
  return [[`rect-${markIndex}`, { title, fields }]];
16523
17456
  }
@@ -16536,7 +17469,7 @@ function tooltipsForArc(mark, encoding, formatters, markIndex) {
16536
17469
  encoding.y.type,
16537
17470
  getFormatter(formatters, encoding.y)
16538
17471
  ),
16539
- color: getRepresentativeColor13(mark.fill)
17472
+ color: getRepresentativeColor15(mark.fill)
16540
17473
  });
16541
17474
  }
16542
17475
  } else if (encoding.y) {
@@ -16548,13 +17481,13 @@ function tooltipsForArc(mark, encoding, formatters, markIndex) {
16548
17481
  encoding.y.type,
16549
17482
  getFormatter(formatters, encoding.y)
16550
17483
  ),
16551
- color: getRepresentativeColor13(mark.fill)
17484
+ color: getRepresentativeColor15(mark.fill)
16552
17485
  });
16553
17486
  }
16554
17487
  const title = colorEnc ? String(row[colorEnc.field] ?? "") : void 0;
16555
17488
  return [[`arc-${markIndex}`, { title, fields }]];
16556
17489
  }
16557
- function tooltipsForArea(mark, encoding, formatters, _markIndex, encodedFields, stackTotals) {
17490
+ function tooltipsForArea(mark, encoding, formatters, _markIndex, encodedFields, stackTotals2) {
16558
17491
  if (mark.dataPoints) {
16559
17492
  const wantsTotal = mark.stacked === true && mark.stackNormalized !== true;
16560
17493
  for (const dp of mark.dataPoints) {
@@ -16563,11 +17496,11 @@ function tooltipsForArea(mark, encoding, formatters, _markIndex, encodedFields,
16563
17496
  dp.datum,
16564
17497
  encoding,
16565
17498
  formatters,
16566
- getRepresentativeColor13(mark.fill),
17499
+ getRepresentativeColor15(mark.fill),
16567
17500
  channel
16568
17501
  );
16569
17502
  if (wantsTotal && encoding.x) {
16570
- const total = stackTotals?.get(stackKeyOf(dp.datum[encoding.x.field]));
17503
+ const total = stackTotals2?.get(stackKeyOf(dp.datum[encoding.x.field]));
16571
17504
  if (total) fields.push(total);
16572
17505
  }
16573
17506
  dp.tooltip = { title, fields };
@@ -16719,7 +17652,7 @@ function computeCalendarTooltips(spec, marks) {
16719
17652
  ...semanticField(colorEnc, encoding),
16720
17653
  label: resolveLabel(colorEnc),
16721
17654
  value: formatValue2(row[colorEnc.field], colorEnc.type, getFormatter(fmtCache, colorEnc)),
16722
- color: getRepresentativeColor13(mark.fill)
17655
+ color: getRepresentativeColor15(mark.fill)
16723
17656
  }
16724
17657
  ]
16725
17658
  });
@@ -16767,7 +17700,7 @@ function computeWaffleTooltips(spec, marks) {
16767
17700
  ...semanticField(valueCh, encoding),
16768
17701
  label: resolveLabel(valueCh),
16769
17702
  value: formatValue2(row[valueCh.field], valueCh.type, getFormatter(fmtCache, valueCh)),
16770
- color: getRepresentativeColor13(mark.fill)
17703
+ color: getRepresentativeColor15(mark.fill)
16771
17704
  },
16772
17705
  { label: "Share", value: `${cellCounts.get(category) ?? 0} of ${units} units` }
16773
17706
  ]
@@ -16798,7 +17731,7 @@ function computeBinnedBarTooltips(spec, marks) {
16798
17731
  ].filter((ch) => !!ch && "field" in ch);
16799
17732
  const fmtCache = buildFormatterCache(spec.data, allChannels);
16800
17733
  const xFormatter = getFormatter(fmtCache, xCh);
16801
- const stackTotals = computeRectStackTotals(marks, encoding, fmtCache);
17734
+ const stackTotals2 = computeRectStackTotals(marks, encoding, fmtCache);
16802
17735
  for (let i = 0; i < marks.length; i++) {
16803
17736
  const mark = marks[i];
16804
17737
  if (mark.type !== "rect") continue;
@@ -16820,16 +17753,16 @@ function computeBinnedBarTooltips(spec, marks) {
16820
17753
  ...semanticField(colorEnc, encoding),
16821
17754
  label: resolveLabel(colorEnc),
16822
17755
  value: String(row[colorEnc.field] ?? ""),
16823
- color: getRepresentativeColor13(mark.fill)
17756
+ color: getRepresentativeColor15(mark.fill)
16824
17757
  });
16825
17758
  }
16826
17759
  fields.push({
16827
17760
  ...semanticField(yCh, encoding),
16828
17761
  label: resolveLabel(yCh),
16829
17762
  value: formatValue2(row[yCh.field], yCh.type, getFormatter(fmtCache, yCh)),
16830
- ...colorEnc ? {} : { color: getRepresentativeColor13(mark.fill) }
17763
+ ...colorEnc ? {} : { color: getRepresentativeColor15(mark.fill) }
16831
17764
  });
16832
- const total = mark.stackGroup !== void 0 ? stackTotals?.get(mark.stackGroup) : void 0;
17765
+ const total = mark.stackGroup !== void 0 ? stackTotals2?.get(mark.stackGroup) : void 0;
16833
17766
  if (total) fields.push(total);
16834
17767
  descriptors.set(`rect-${i}`, { title, fields });
16835
17768
  }
@@ -16878,7 +17811,7 @@ function computeParliamentTooltips(spec, marks) {
16878
17811
  ...semanticField(valueCh, encoding),
16879
17812
  label: resolveLabel(valueCh),
16880
17813
  value: formatValue2(row[valueCh.field], valueCh.type, getFormatter(fmtCache, valueCh)),
16881
- color: getRepresentativeColor13(mark.fill)
17814
+ color: getRepresentativeColor15(mark.fill)
16882
17815
  },
16883
17816
  { label: "Share", value: share }
16884
17817
  ]
@@ -16908,9 +17841,11 @@ function computeTooltipDescriptors(spec, marks) {
16908
17841
  }
16909
17842
  const encoding = spec.encoding;
16910
17843
  const descriptors = /* @__PURE__ */ new Map();
17844
+ const intervalEnd = spec.markType === "area" && encoding.y && encoding.y2 && "field" in encoding.y2 ? { ...encoding.y, ...encoding.y2 } : void 0;
16911
17845
  const allChannels = [
16912
17846
  encoding.x,
16913
17847
  encoding.y,
17848
+ intervalEnd,
16914
17849
  encoding.color && "field" in encoding.color ? encoding.color : void 0,
16915
17850
  encoding.size && "field" in encoding.size ? encoding.size : void 0,
16916
17851
  ...encoding.tooltip ? Array.isArray(encoding.tooltip) ? encoding.tooltip : [encoding.tooltip] : []
@@ -16929,6 +17864,23 @@ function computeTooltipDescriptors(spec, marks) {
16929
17864
  case "area":
16930
17865
  entries = tooltipsForArea(mark, encoding, formatters, i, encodedFields, areaStackTotals);
16931
17866
  break;
17867
+ case "rule":
17868
+ if (mark.markType === "area" && intervalEnd && !mark.aria.decorative) {
17869
+ const { title, channel } = getTooltipTitle(mark.data, encoding, encodedFields);
17870
+ const fields = buildFields(mark.data, encoding, formatters, mark.stroke, channel);
17871
+ if (!encoding.tooltip)
17872
+ fields.push({
17873
+ ...semanticField(intervalEnd, encoding, "y2", void 0, formatters),
17874
+ label: resolveLabel(intervalEnd),
17875
+ value: formatValue2(
17876
+ mark.data[intervalEnd.field],
17877
+ intervalEnd.type,
17878
+ getFormatter(formatters, intervalEnd)
17879
+ )
17880
+ });
17881
+ entries = [[`rule-${i}`, { title, fields }]];
17882
+ }
17883
+ break;
16932
17884
  case "point":
16933
17885
  entries = tooltipsForPoint(mark, encoding, formatters, i, encodedFields);
16934
17886
  break;
@@ -17050,6 +18002,8 @@ function computeChartScales(spec, area3, theme, chartSpec) {
17050
18002
  spec.highlight,
17051
18003
  chartSpec.markType
17052
18004
  );
18005
+ for (const scale of [scales.x, scales.y])
18006
+ warnings.push(...scale?.temporalInterval?.warnings ?? []);
17053
18007
  scales.defaultColor = chartSpec.markDef.fill ?? chartSpec.markDef.stroke ?? defaultSeriesColor(theme, chartSpec.markType);
17054
18008
  return { scales, warnings };
17055
18009
  }
@@ -17335,14 +18289,14 @@ function scopeTooltipContent(content, scope) {
17335
18289
  }
17336
18290
 
17337
18291
  // src/compile/fill-patterns.ts
17338
- import { getRepresentativeColor as getRepresentativeColor14, pickLabelColor as pickLabelColor4 } from "@opendata-ai/openchart-core";
18292
+ import { getRepresentativeColor as getRepresentativeColor16, pickLabelColor as pickLabelColor4 } from "@opendata-ai/openchart-core";
17339
18293
  var PATTERN_SEQUENCE = ["diagonal", "dot", "crosshatch", "vertical"];
17340
18294
  var MIN_PATTERN_EXTENT = 12;
17341
18295
  function applyFillPatterns(marks, markDef, theme) {
17342
18296
  if (markDef.fillPattern !== "auto") return;
17343
18297
  const assignment = /* @__PURE__ */ new Map();
17344
18298
  const resolve = (fill) => {
17345
- const base = getRepresentativeColor14(fill);
18299
+ const base = getRepresentativeColor16(fill);
17346
18300
  let resolved = assignment.get(base);
17347
18301
  if (!resolved) {
17348
18302
  const type = PATTERN_SEQUENCE[assignment.size % PATTERN_SEQUENCE.length];
@@ -17606,6 +18560,12 @@ function compileFaceted(chartSpec, renderSpec, facetChannel, facetDirection, the
17606
18560
  grid.valueLabelPlan,
17607
18561
  options.measureText
17608
18562
  ) : [];
18563
+ attachMarkMetadata(
18564
+ panelMarks,
18565
+ panelSpecWithDomains.encoding,
18566
+ panelSpecWithDomains.sourceMarkType ?? panelSpecWithDomains.markType,
18567
+ seriesWarnings
18568
+ );
17609
18569
  const annotationMeasure = annotationMeasureFn(options.measureText);
17610
18570
  let panelAnnotations = computeAnnotations(panelSpecWithDomains, {
17611
18571
  scales: panelScales,
@@ -18445,19 +19405,18 @@ function mergeEncoding(base, bpEnc) {
18445
19405
  for (const channel of Object.keys(bpEnc)) {
18446
19406
  const baseCh = mergedEncoding[channel];
18447
19407
  const bpCh = bpEnc[channel];
18448
- if (bpCh && baseCh) {
18449
- const merged = { ...baseCh, ...bpCh };
18450
- for (const key of NESTED_CHANNEL_KEYS) {
18451
- const baseNested = baseCh[key];
18452
- const bpNested = bpCh[key];
18453
- if (baseNested && bpNested && typeof baseNested === "object" && typeof bpNested === "object" && !Array.isArray(baseNested) && !Array.isArray(bpNested)) {
18454
- merged[key] = { ...baseNested, ...bpNested };
18455
- }
19408
+ if (!baseCh || typeof baseCh !== "object" || Array.isArray(baseCh) || !bpCh || typeof bpCh !== "object" || Array.isArray(bpCh)) {
19409
+ continue;
19410
+ }
19411
+ const merged = { ...baseCh, ...bpCh };
19412
+ for (const key of NESTED_CHANNEL_KEYS) {
19413
+ const baseNested = baseCh[key];
19414
+ const bpNested = bpCh[key];
19415
+ if (baseNested && bpNested && typeof baseNested === "object" && typeof bpNested === "object" && !Array.isArray(baseNested) && !Array.isArray(bpNested)) {
19416
+ merged[key] = { ...baseNested, ...bpNested };
18456
19417
  }
18457
- mergedEncoding[channel] = merged;
18458
- } else if (bpCh) {
18459
- mergedEncoding[channel] = bpCh;
18460
19418
  }
19419
+ mergedEncoding[channel] = merged;
18461
19420
  }
18462
19421
  return mergedEncoding;
18463
19422
  }
@@ -18942,7 +19901,10 @@ function layoutSingleChart(input) {
18942
19901
  options.leafContext.plan = plan;
18943
19902
  }
18944
19903
  const chartArea = options.frozenBudget?.chartArea ?? dims.chartArea;
18945
- const scaleArea = scaleAreaFor(chartArea, plan.inlineYLabelInset);
19904
+ const scaleArea = scaleAreaFor(
19905
+ chartArea,
19906
+ options.frozenBudget?.inlineYLabelInset ?? plan.inlineYLabelInset
19907
+ );
18946
19908
  let referenceReserve = dims.reference;
18947
19909
  if (options.frozenBudget && referenceReserve.labels.length > 0) {
18948
19910
  const lane = referenceLaneFor(
@@ -18992,6 +19954,21 @@ function layoutSingleChart(input) {
18992
19954
  // regenerates against the final (taller) chartArea.
18993
19955
  precomputedYTicks: !dims.chromeStripped && plan.yTickValues.length > 0 ? plan.yTickValues : void 0
18994
19956
  });
19957
+ if (chartSpec.frame?.left !== void 0 && axes.y && axes.y.tickPosition !== "inline") {
19958
+ const style = axes.y.tickLabelStyle;
19959
+ const available = Math.max(0, chartSpec.frame.left - (axes.y.labelPadding ?? 6) - 4);
19960
+ const fitted = fitAxisLabels(
19961
+ axes.y.ticks,
19962
+ available,
19963
+ (text) => options.measureText ? options.measureText(text, style.fontSize, style.fontWeight).width : estimateTextWidth23(text, style.fontSize, style.fontWeight)
19964
+ );
19965
+ axes.y.ticks = fitted.ticks;
19966
+ if (fitted.shortened)
19967
+ emitSpecWarnings(
19968
+ ["[openchart] Y-axis labels were shortened to fit frame.left."],
19969
+ options.onWarn
19970
+ );
19971
+ }
18995
19972
  offsetValueLabelAxes(axes, plan.valueLabelPlan);
18996
19973
  emitValueLabelDiagnostic(plan.valueLabelPlan, options);
18997
19974
  const xAxisExtent = axes.x?.extent ?? 0;
@@ -19193,8 +20170,9 @@ function computeChartMarks(chartSpec, renderSpec, scales, chartArea, strategy, t
19193
20170
  renderSpec.markDef
19194
20171
  );
19195
20172
  const renderer = getChartRenderer(rendererKey);
20173
+ const markWarnings = [];
19196
20174
  const marks = renderer ? renderer(
19197
- renderSpec,
20175
+ { ...renderSpec, markWarnings },
19198
20176
  scales,
19199
20177
  chartArea,
19200
20178
  strategy,
@@ -19203,6 +20181,14 @@ function computeChartMarks(chartSpec, renderSpec, scales, chartArea, strategy, t
19203
20181
  valueLabelPlan,
19204
20182
  options.measureText
19205
20183
  ) : [];
20184
+ const metadataWarnings = [];
20185
+ attachMarkMetadata(
20186
+ marks,
20187
+ renderSpec.encoding,
20188
+ renderSpec.sourceMarkType ?? renderSpec.markType,
20189
+ metadataWarnings
20190
+ );
20191
+ emitSpecWarnings([...markWarnings, ...metadataWarnings], options.onWarn);
19206
20192
  applyFillPatterns(marks, chartSpec.markDef, theme);
19207
20193
  const markRenderModeWarnings = [];
19208
20194
  const markRenderMode = resolveMarkRenderMode(
@@ -19228,8 +20214,9 @@ import {
19228
20214
  computeFieldFormatContext as computeFieldFormatContext6,
19229
20215
  computeNoteBandHeight as computeNoteBandHeight2,
19230
20216
  defaultNumberFormatter as defaultNumberFormatter8,
19231
- estimateTextWidth as estimateTextWidth22,
20217
+ estimateTextWidth as estimateTextWidth24,
19232
20218
  mergeThemeConfig as mergeThemeConfig3,
20219
+ resolveMarkDef as resolveMarkDef2,
19233
20220
  resolveNumberFormatter as resolveNumberFormatter5,
19234
20221
  resolveTheme as resolveTheme3,
19235
20222
  TICK_LABEL_OFFSET
@@ -19273,6 +20260,18 @@ function appendLayerMarks(layout, leafIndex, marks, tooltips, sourceMarks = layo
19273
20260
  }
19274
20261
  }
19275
20262
  function compileLayer(spec, options, compileChart2) {
20263
+ const onWarn = options.onWarn;
20264
+ let frameLabelWarning = false;
20265
+ options = {
20266
+ ...options,
20267
+ onWarn: (message) => {
20268
+ if (message.includes("Y-axis labels were shortened to fit frame.left")) {
20269
+ if (frameLabelWarning) return;
20270
+ frameLabelWarning = true;
20271
+ }
20272
+ emitSpecWarnings([message], onWarn);
20273
+ }
20274
+ };
19276
20275
  const leaves = flattenLayers(spec);
19277
20276
  if (leaves.length === 0) {
19278
20277
  throw new Error("LayerSpec has no leaf chart specs after flattening");
@@ -19285,12 +20284,33 @@ function compileLayer(spec, options, compileChart2) {
19285
20284
  appendLayerMarks(layout, 0, marks, tooltipDescriptors2);
19286
20285
  return { ...layout, marks, tooltipDescriptors: tooltipDescriptors2 };
19287
20286
  }
19288
- const layerOptions = { ...options, layered: true };
20287
+ const sparklinePad = spec.display === "sparkline" ? leaves.reduce(
20288
+ (pad2, leaf) => {
20289
+ const markDef = resolveMarkDef2(leaf.mark);
20290
+ const isTrend = markDef.type === "line" || markDef.type === "area";
20291
+ const defaults = isTrend && !leaf.encoding.color && !("point" in markDef) ? { ...markDef, point: "last" } : markDef;
20292
+ const reserve = getSparklinePad({ markDef: defaults, markType: markDef.type });
20293
+ return {
20294
+ left: Math.max(pad2.left, reserve.left),
20295
+ right: Math.max(pad2.right, reserve.right),
20296
+ top: Math.max(pad2.top, reserve.top),
20297
+ bottom: Math.max(pad2.bottom, reserve.bottom)
20298
+ };
20299
+ },
20300
+ { left: 0, right: 0, top: 0, bottom: 0 }
20301
+ ) : void 0;
20302
+ const layerOptions = {
20303
+ ...options,
20304
+ layered: true,
20305
+ ...sparklinePad ? { sparklinePad } : {}
20306
+ };
19289
20307
  if (spec.resolve?.scale?.y === "independent") {
19290
20308
  return compileLayerIndependent(leaves, spec, layerOptions, compileChart2);
19291
20309
  }
19292
- const primarySpec = buildPrimarySpec(leaves, spec);
19293
- const primaryLayout = compileChart2(primarySpec, layerOptions);
20310
+ const sharedDomains = computeSharedDomains(leaves, layerOptions);
20311
+ const primarySpec = withSharedDomains(buildPrimarySpec(leaves, spec), sharedDomains);
20312
+ const primaryContext = {};
20313
+ const primaryLayout = compileChart2(primarySpec, { ...layerOptions, leafContext: primaryContext });
19294
20314
  const allMarks = [];
19295
20315
  const tooltipDescriptors = /* @__PURE__ */ new Map();
19296
20316
  const seenLabels = /* @__PURE__ */ new Set();
@@ -19307,9 +20327,11 @@ function compileLayer(spec, options, compileChart2) {
19307
20327
  indexedLeaves.sort((a, b) => a.zIndex - b.zIndex);
19308
20328
  const leafOptions = {
19309
20329
  ...layerOptions,
19310
- frozenBudget: { chartArea: primaryLayout.area }
20330
+ frozenBudget: {
20331
+ chartArea: primaryLayout.area,
20332
+ inlineYLabelInset: primaryContext.plan?.inlineYLabelInset
20333
+ }
19311
20334
  };
19312
- const sharedDomains = computeSharedDomains(leaves);
19313
20335
  for (const { leaf, leafIndex } of indexedLeaves) {
19314
20336
  const themedLeaf = {
19315
20337
  ...withSharedDomains(leaf, sharedDomains),
@@ -19348,7 +20370,7 @@ function estimateYAxisLabelWidth(data, encoding, baseFontSize, measure) {
19348
20370
  const yEnc = encoding.y;
19349
20371
  const yField = yEnc.field;
19350
20372
  if (!yField) return 40;
19351
- const m = measure ?? estimateTextWidth22;
20373
+ const m = measure ?? estimateTextWidth24;
19352
20374
  const yType = yEnc.type;
19353
20375
  if (yType === "nominal" || yType === "ordinal") {
19354
20376
  let maxWidth = 0;
@@ -19496,6 +20518,7 @@ function compileLayerIndependent(leaves, layerSpec, options, compileChart2) {
19496
20518
  leafContext: leaf0Budget
19497
20519
  });
19498
20520
  }
20521
+ const primaryInlineInset = leaf0Budget.plan?.inlineYLabelInset ?? 0;
19499
20522
  const columns = [layout0.endpointLabels, layout1.endpointLabels].filter(
19500
20523
  (column) => !!column
19501
20524
  );
@@ -19525,7 +20548,10 @@ function compileLayerIndependent(leaves, layerSpec, options, compileChart2) {
19525
20548
  noteReserve: noteReserve(layout0)
19526
20549
  };
19527
20550
  layout0 = compileChart2(primary0, { ...primaryOptions, frozenBudget });
19528
- layout1 = compileChart2(primary1, { ...optionsWithReserve, frozenBudget });
20551
+ layout1 = compileChart2(primary1, {
20552
+ ...optionsWithReserve,
20553
+ frozenBudget: { ...frozenBudget, inlineYLabelInset: primaryInlineInset }
20554
+ });
19529
20555
  const legendShift = rightReserve + layout0.theme.spacing.endpointColumnGap + endpointWidth;
19530
20556
  const localColumnReserve = (layout) => layout.endpointLabels?.entries.length ? layout0.theme.spacing.endpointColumnGap + layout.endpointLabels.bounds.width : 0;
19531
20557
  layout0 = moveRightLegends(layout0, legendShift - localColumnReserve(layout0));
@@ -19542,17 +20568,22 @@ function compileLayerIndependent(leaves, layerSpec, options, compileChart2) {
19542
20568
  noteReserve: noteReserve(layout0)
19543
20569
  };
19544
20570
  layout0 = compileChart2(primary0, { ...primaryOptions, frozenBudget });
19545
- layout1 = compileChart2(primary1, { ...optionsWithReserve, frozenBudget });
20571
+ layout1 = compileChart2(primary1, {
20572
+ ...optionsWithReserve,
20573
+ frozenBudget: { ...frozenBudget, inlineYLabelInset: primaryInlineInset }
20574
+ });
19546
20575
  layout0 = moveRightLegends(layout0, rightReserve);
19547
20576
  layout1 = moveRightLegends(layout1, rightReserve);
19548
20577
  } else if (!columns.length) {
19549
20578
  measure0.release();
19550
- if (noteReserve(layout0) > 0) {
19551
- layout1 = compileChart2(primary1, {
19552
- ...optionsWithReserve,
19553
- frozenBudget: { chartArea: layout0.area, noteReserve: noteReserve(layout0) }
19554
- });
19555
- } else measure1.release();
20579
+ layout1 = compileChart2(primary1, {
20580
+ ...optionsWithReserve,
20581
+ frozenBudget: {
20582
+ chartArea: layout0.area,
20583
+ noteReserve: noteReserve(layout0),
20584
+ inlineYLabelInset: primaryInlineInset
20585
+ }
20586
+ });
19556
20587
  }
19557
20588
  if (layerSpec.theme && leaf0.theme) {
19558
20589
  const leafView = compileChart2(
@@ -19868,6 +20899,20 @@ function withUnionXDomain(leaf0, leaf1) {
19868
20899
  if (ms > maxMs) maxMs = ms;
19869
20900
  }
19870
20901
  if (minMs <= maxMs) {
20902
+ const start = new Date(minMs);
20903
+ const end = new Date(maxMs);
20904
+ for (const leaf of [leaf0, leaf1]) {
20905
+ const mark = typeof leaf.mark === "string" ? leaf.mark : leaf.mark.type;
20906
+ const channel = leaf.encoding?.x;
20907
+ if (mark !== "bar" || channel?.type !== "temporal" || channel.scale?.domain) continue;
20908
+ const interval = resolveTemporalInterval(
20909
+ channel,
20910
+ leaf.data,
20911
+ resolveTemporalScaleType(channel, leaf.data)
20912
+ );
20913
+ minMs = Math.min(minMs, +start - (+interval.offset(start) - +start) / 2);
20914
+ maxMs = Math.max(maxMs, +end + (+interval.offset(end) - +end) / 2);
20915
+ }
19871
20916
  domain = [new Date(minMs).toISOString(), new Date(maxMs).toISOString()];
19872
20917
  }
19873
20918
  } else if (xType === "quantitative") {
@@ -19971,33 +21016,42 @@ function withYDomain(leaf, domain) {
19971
21016
  }
19972
21017
  };
19973
21018
  }
19974
- function computeSharedDomains(leaves) {
21019
+ function computeSharedDomains(leaves, options) {
19975
21020
  const shared = {};
21021
+ const prepared = leaves.map(
21022
+ (leaf) => buildRenderSpec(prepareChartSpec(leaf, { ...options, onWarn: () => {
21023
+ } }).chartSpec)
21024
+ );
21025
+ const domains = prepared.map((spec) => {
21026
+ const encoding = { ...spec.encoding };
21027
+ for (const axis of ["x", "y"]) {
21028
+ const channel = encoding[axis];
21029
+ if (channel)
21030
+ encoding[axis] = { ...channel, ...channel.scale ? { scale: { ...channel.scale } } : {} };
21031
+ }
21032
+ return computeScales({ ...spec, encoding }, { x: 0, y: 0, width: 1, height: 1 }, spec.data);
21033
+ });
19976
21034
  for (const channel of ["x", "y"]) {
19977
- let lo = Number.POSITIVE_INFINITY;
19978
- let hi = Number.NEGATIVE_INFINITY;
19979
- let sawAny = false;
19980
- let usable = true;
19981
- for (const leaf of leaves) {
19982
- const enc = leaf.encoding?.[channel];
19983
- if (!enc || !("field" in enc) || enc.type !== "quantitative" || enc.scale?.domain) {
19984
- usable = false;
19985
- break;
19986
- }
19987
- for (const row of leaf.data ?? []) {
19988
- const v = finiteNumber(row[enc.field]);
19989
- if (v === void 0) continue;
19990
- if (v < lo) lo = v;
19991
- if (v > hi) hi = v;
19992
- sawAny = true;
19993
- }
21035
+ const explicitIndex = leaves.findIndex((leaf) => leaf.encoding?.[channel]?.scale?.domain);
21036
+ const explicit = leaves[explicitIndex]?.encoding?.[channel];
21037
+ if (explicit?.scale?.domain && prepared.every(
21038
+ (spec) => spec.encoding[channel]?.type === prepared[explicitIndex].encoding[channel]?.type
21039
+ )) {
21040
+ shared[channel] = explicit.scale.domain;
21041
+ continue;
19994
21042
  }
19995
- if (!usable || !sawAny || lo > hi) continue;
19996
- const wantsZero = leaves.every((leaf) => {
19997
- const enc = leaf.encoding?.[channel];
19998
- return enc && "scale" in enc ? enc.scale?.zero !== false : true;
19999
- });
20000
- shared[channel] = wantsZero ? [Math.min(0, lo), Math.max(0, hi)] : [lo, hi];
21043
+ if (domains.some((scales) => scales[channel]?.temporalInterval) && prepared.every((spec) => spec.encoding[channel]?.type === "temporal")) {
21044
+ const times = domains.flatMap((scales) => (scales[channel]?.scale.domain() ?? []).map(Number)).filter(Number.isFinite);
21045
+ if (times.length)
21046
+ shared[channel] = [
21047
+ new Date(Math.min(...times)).toISOString(),
21048
+ new Date(Math.max(...times)).toISOString()
21049
+ ];
21050
+ continue;
21051
+ }
21052
+ if (!prepared.every((spec) => spec.encoding[channel]?.type === "quantitative")) continue;
21053
+ const values = domains.flatMap((scales) => (scales[channel]?.scale.domain() ?? []).map(Number)).filter(Number.isFinite);
21054
+ if (values.length) shared[channel] = [Math.min(...values), Math.max(...values)];
20001
21055
  }
20002
21056
  return shared;
20003
21057
  }
@@ -20007,7 +21061,7 @@ function withSharedDomains(leaf, shared) {
20007
21061
  for (const channel of ["x", "y"]) {
20008
21062
  const domain = shared[channel];
20009
21063
  const ch = encoding[channel];
20010
- if (!domain || !ch) continue;
21064
+ if (!domain || !ch || ch.scale?.domain) continue;
20011
21065
  encoding[channel] = {
20012
21066
  ...ch,
20013
21067
  scale: { ...ch.scale ?? {}, domain }
@@ -20024,6 +21078,10 @@ function buildPrimarySpec(leaves, layerSpec) {
20024
21078
  ...leaves[0],
20025
21079
  data: allData,
20026
21080
  chrome: layerSpec.chrome ?? leaves[0].chrome,
21081
+ display: layerSpec.display ?? leaves[0].display,
21082
+ a11y: layerSpec.a11y ?? leaves[0].a11y,
21083
+ frame: layerSpec.frame ?? leaves[0].frame,
21084
+ animation: layerSpec.animation ?? leaves[0].animation,
20027
21085
  // Annotations come from the parent LayerSpec when present, otherwise
20028
21086
  // the first flattened leaf's. Later leaves' annotations are silently
20029
21087
  // dropped. The dual-axis path (compileLayerIndependent) explicitly
@@ -20044,9 +21102,8 @@ function buildPrimarySpec(leaves, layerSpec) {
20044
21102
  import {
20045
21103
  adaptTheme as adaptTheme3,
20046
21104
  buildD3Formatter as buildD3Formatter2,
20047
- CATEGORICAL_PALETTE as CATEGORICAL_PALETTE2,
20048
21105
  computeChrome as computeChrome4,
20049
- estimateTextWidth as estimateTextWidth23,
21106
+ estimateTextWidth as estimateTextWidth25,
20050
21107
  formatNumber as formatNumber4,
20051
21108
  getBreakpoint as getBreakpoint2,
20052
21109
  HPAD_COMPACT_FRACTION as HPAD_COMPACT_FRACTION3,
@@ -20315,16 +21372,16 @@ function joinDataToFeatures(features, data, dataKeyField, featureIdField) {
20315
21372
  }
20316
21373
 
20317
21374
  // src/geo/labels.ts
20318
- import { formatDate as formatDate6 } from "@opendata-ai/openchart-core";
21375
+ import { formatDate as formatDate7 } from "@opendata-ai/openchart-core";
20319
21376
 
20320
21377
  // ../../node_modules/d3-time-format/src/locale.js
20321
21378
  import {
20322
- timeDay,
21379
+ timeDay as timeDay2,
20323
21380
  timeSunday,
20324
21381
  timeMonday,
20325
21382
  timeThursday,
20326
21383
  timeYear,
20327
- utcDay as utcDay2,
21384
+ utcDay as utcDay3,
20328
21385
  utcSunday as utcSunday2,
20329
21386
  utcMonday as utcMonday2,
20330
21387
  utcThursday,
@@ -20493,14 +21550,14 @@ function formatLocale(locale2) {
20493
21550
  if ("Z" in d) {
20494
21551
  week = utcDate(newDate(d.y, 0, 1)), day = week.getUTCDay();
20495
21552
  week = day > 4 || day === 0 ? utcMonday2.ceil(week) : utcMonday2(week);
20496
- week = utcDay2.offset(week, (d.V - 1) * 7);
21553
+ week = utcDay3.offset(week, (d.V - 1) * 7);
20497
21554
  d.y = week.getUTCFullYear();
20498
21555
  d.m = week.getUTCMonth();
20499
21556
  d.d = week.getUTCDate() + (d.w + 6) % 7;
20500
21557
  } else {
20501
21558
  week = localDate(newDate(d.y, 0, 1)), day = week.getDay();
20502
21559
  week = day > 4 || day === 0 ? timeMonday.ceil(week) : timeMonday(week);
20503
- week = timeDay.offset(week, (d.V - 1) * 7);
21560
+ week = timeDay2.offset(week, (d.V - 1) * 7);
20504
21561
  d.y = week.getFullYear();
20505
21562
  d.m = week.getMonth();
20506
21563
  d.d = week.getDate() + (d.w + 6) % 7;
@@ -20737,7 +21794,7 @@ function formatHour12(d, p) {
20737
21794
  return pad(d.getHours() % 12 || 12, p, 2);
20738
21795
  }
20739
21796
  function formatDayOfYear(d, p) {
20740
- return pad(1 + timeDay.count(timeYear(d), d), p, 3);
21797
+ return pad(1 + timeDay2.count(timeYear(d), d), p, 3);
20741
21798
  }
20742
21799
  function formatMilliseconds(d, p) {
20743
21800
  return pad(d.getMilliseconds(), p, 3);
@@ -20804,7 +21861,7 @@ function formatUTCHour12(d, p) {
20804
21861
  return pad(d.getUTCHours() % 12 || 12, p, 2);
20805
21862
  }
20806
21863
  function formatUTCDayOfYear(d, p) {
20807
- return pad(1 + utcDay2.count(utcYear(d), d), p, 3);
21864
+ return pad(1 + utcDay3.count(utcYear(d), d), p, 3);
20808
21865
  }
20809
21866
  function formatUTCMilliseconds(d, p) {
20810
21867
  return pad(d.getUTCMilliseconds(), p, 3);
@@ -22045,7 +23102,7 @@ function fieldText(channel, rows) {
22045
23102
  if (channel.type === "temporal") {
22046
23103
  const date = value instanceof Date ? value : new Date(value);
22047
23104
  if (!Number.isFinite(date.getTime())) return void 0;
22048
- return channel.format ? utcFormat(channel.format)(date) : formatDate6(date);
23105
+ return channel.format ? utcFormat(channel.format)(date) : formatDate7(date);
22049
23106
  }
22050
23107
  const text = String(value);
22051
23108
  return text.trim() ? text : void 0;
@@ -22546,10 +23603,10 @@ function categoricalLegendLabelStyle(theme) {
22546
23603
  };
22547
23604
  }
22548
23605
  function categoricalEntryWidth(label, labelStyle) {
22549
- return CATEGORICAL_SWATCH_SIZE + CATEGORICAL_SWATCH_GAP + estimateTextWidth23(label, labelStyle.fontSize, labelStyle.fontWeight) + CATEGORICAL_ENTRY_GAP;
23606
+ return CATEGORICAL_SWATCH_SIZE + CATEGORICAL_SWATCH_GAP + estimateTextWidth25(label, labelStyle.fontSize, labelStyle.fontWeight) + CATEGORICAL_ENTRY_GAP;
22550
23607
  }
22551
23608
  function noDataBlockWidth(labelStyle) {
22552
- return CATEGORICAL_SWATCH_SIZE + NO_DATA_LABEL_GAP + estimateTextWidth23("No data", labelStyle.fontSize, labelStyle.fontWeight);
23609
+ return CATEGORICAL_SWATCH_SIZE + NO_DATA_LABEL_GAP + estimateTextWidth25("No data", labelStyle.fontSize, labelStyle.fontWeight);
22553
23610
  }
22554
23611
  function wrapCategoricalEntries(widths, legendWidth) {
22555
23612
  const placed = [];
@@ -22704,7 +23761,7 @@ function compileGeoMapImpl(spec, options) {
22704
23761
  }
22705
23762
  const mapFields = mapSpec.fields;
22706
23763
  const measureKeyText = options.measureText ?? ((text, size, weight) => ({
22707
- width: estimateTextWidth23(text, size, weight),
23764
+ width: estimateTextWidth25(text, size, weight),
22708
23765
  height: size
22709
23766
  }));
22710
23767
  const preparedLabels = prepareGeoLabels(
@@ -22941,7 +23998,7 @@ function compileGeoMapImpl(spec, options) {
22941
23998
  Math.ceil(theme.fonts.sizes.small * 1.2)
22942
23999
  );
22943
24000
  const pointCategoryWidths = pointColor && pointColor.type !== "quantitative" ? collectCategories(mapSpec.points.data, pointColor.field, pointColor.scale?.domain).map(
22944
- (label) => CATEGORICAL_SWATCH_SIZE + CATEGORICAL_SWATCH_GAP + estimateTextWidth23(label, theme.fonts.sizes.small, theme.fonts.weights.normal) + CATEGORICAL_ENTRY_GAP
24001
+ (label) => CATEGORICAL_SWATCH_SIZE + CATEGORICAL_SWATCH_GAP + estimateTextWidth25(label, theme.fonts.sizes.small, theme.fonts.weights.normal) + CATEGORICAL_ENTRY_GAP
22945
24002
  ) : [];
22946
24003
  const pointCategoryRows = wrapCategoricalEntries(pointCategoryWidths, fullArea.width);
22947
24004
  const pointCategoryRowCount = pointCategoryRows.length ? pointCategoryRows[pointCategoryRows.length - 1].row + 1 : 1;
@@ -22989,7 +24046,7 @@ function compileGeoMapImpl(spec, options) {
22989
24046
  lineHeight: 1.3
22990
24047
  };
22991
24048
  const measureSideText = options.measureText ?? ((text, size, weight) => ({
22992
- width: estimateTextWidth23(text, size, weight),
24049
+ width: estimateTextWidth25(text, size, weight),
22993
24050
  height: size
22994
24051
  }));
22995
24052
  const measuredSizeContent = sizeContent ? measureGeoSizeKey(
@@ -23059,7 +24116,7 @@ function compileGeoMapImpl(spec, options) {
23059
24116
  legendTitleFor(channel) ?? "",
23060
24117
  theme.fonts.sizes.small,
23061
24118
  theme.fonts.weights.medium
23062
- ).width ?? estimateTextWidth23(legendTitleFor(channel) ?? "", theme.fonts.sizes.small),
24119
+ ).width ?? estimateTextWidth25(legendTitleFor(channel) ?? "", theme.fonts.sizes.small),
23063
24120
  ...collectCategories(
23064
24121
  channel.type === "quantitative" ? [] : channel === colorEncoding ? mapSpec.data : mapSpec.points.data,
23065
24122
  channel.field,
@@ -23069,7 +24126,7 @@ function compileGeoMapImpl(spec, options) {
23069
24126
  label,
23070
24127
  theme.fonts.sizes.small,
23071
24128
  theme.fonts.weights.normal
23072
- ).width ?? estimateTextWidth23(label, theme.fonts.sizes.small))
24129
+ ).width ?? estimateTextWidth25(label, theme.fonts.sizes.small))
23073
24130
  )
23074
24131
  ] : []
23075
24132
  )
@@ -23345,6 +24402,7 @@ function compileGeoMapImpl(spec, options) {
23345
24402
  neutralFill,
23346
24403
  noDataPattern,
23347
24404
  theme,
24405
+ palette: lightTheme.colors.categorical,
23348
24406
  fullArea,
23349
24407
  mapAreaHeight,
23350
24408
  legendReserveGap,
@@ -23457,7 +24515,7 @@ function compileGeoMapImpl(spec, options) {
23457
24515
  }
23458
24516
  }
23459
24517
  }
23460
- const colorSource = explicitRange && Array.isArray(explicitRange) ? explicitRange : CATEGORICAL_PALETTE2;
24518
+ const colorSource = explicitRange && Array.isArray(explicitRange) ? explicitRange : lightTheme.colors.categorical;
23461
24519
  for (let i = 0; i < pointCategories.length; i++) {
23462
24520
  pointCategoryColors.set(pointCategories[i], colorSource[i % colorSource.length]);
23463
24521
  }
@@ -23467,7 +24525,7 @@ function compileGeoMapImpl(spec, options) {
23467
24525
  };
23468
24526
  }
23469
24527
  }
23470
- const defaultFill = CATEGORICAL_PALETTE2[0];
24528
+ const defaultFill = lightTheme.colors.categorical[0];
23471
24529
  const pointOpacity = pts.opacity ?? 0.85;
23472
24530
  const droppedPoints = [];
23473
24531
  for (let i = 0; i < pts.data.length; i++) {
@@ -24005,6 +25063,7 @@ function compileGeoMapImpl(spec, options) {
24005
25063
  neutralFill,
24006
25064
  noDataPattern,
24007
25065
  theme,
25066
+ palette: lightTheme.colors.categorical,
24008
25067
  fullArea,
24009
25068
  mapAreaHeight,
24010
25069
  legendReserveGap,
@@ -24221,7 +25280,7 @@ function compileGeoMapImpl(spec, options) {
24221
25280
  height: contentHeight,
24222
25281
  animation: resolvedAnimation,
24223
25282
  watermark,
24224
- measureText: options.measureText ?? ((text, fontSize) => ({ width: estimateTextWidth23(text, fontSize), height: fontSize })),
25283
+ measureText: options.measureText ?? ((text, fontSize) => ({ width: estimateTextWidth25(text, fontSize), height: fontSize })),
24225
25284
  warnings: compileWarnings,
24226
25285
  mapSize: views ? views[0].mapSize : { width: frame.area.width, height: mapAreaHeight },
24227
25286
  focus: views ? views[0].focus : resolvedFocus
@@ -24353,7 +25412,7 @@ function buildCategoricalMarks(opts) {
24353
25412
  } = opts;
24354
25413
  const categories = collectCategories(joined.values(), colorField, scaleConfig?.domain);
24355
25414
  const explicitRange = scaleConfig?.range;
24356
- const colorSource = explicitRange && Array.isArray(explicitRange) ? explicitRange : CATEGORICAL_PALETTE2;
25415
+ const colorSource = explicitRange && Array.isArray(explicitRange) ? explicitRange : opts.palette;
24357
25416
  const categoryColors = /* @__PURE__ */ new Map();
24358
25417
  for (let i = 0; i < categories.length; i++) {
24359
25418
  categoryColors.set(categories[i], colorSource[i % colorSource.length]);
@@ -24597,7 +25656,7 @@ function emptyLayout3(chrome, theme, options, watermark) {
24597
25656
  height: options.height,
24598
25657
  animation: void 0,
24599
25658
  watermark,
24600
- measureText: options.measureText ?? ((text, fontSize) => ({ width: estimateTextWidth23(text, fontSize), height: fontSize })),
25659
+ measureText: options.measureText ?? ((text, fontSize) => ({ width: estimateTextWidth25(text, fontSize), height: fontSize })),
24601
25660
  warnings: [],
24602
25661
  mapSize: { width: 0, height: 0 },
24603
25662
  focus: null
@@ -25342,7 +26401,7 @@ import {
25342
26401
  buildD3Formatter as buildD3Formatter3,
25343
26402
  computeChrome as computeChrome6,
25344
26403
  defaultNumberFormatter as defaultNumberFormatter10,
25345
- estimateTextWidth as estimateTextWidth24,
26404
+ estimateTextWidth as estimateTextWidth26,
25346
26405
  resolveTheme as resolveTheme6
25347
26406
  } from "@opendata-ai/openchart-core";
25348
26407
 
@@ -25722,8 +26781,8 @@ function compileSankey(spec, options) {
25722
26781
  const nodeFmt = resolveNodeValueFormatter(nodes, resolvedValueFormat, flowFmt);
25723
26782
  const labelBlockWidth = (node3) => {
25724
26783
  const name = node3.label ?? node3.id;
25725
- const nameWidth = estimateTextWidth24(name, labelFontSize, labelFontWeight);
25726
- const valueWidth = estimateTextWidth24(
26784
+ const nameWidth = estimateTextWidth26(name, labelFontSize, labelFontWeight);
26785
+ const valueWidth = estimateTextWidth26(
25727
26786
  formatFlowValue(node3.value ?? 0, nodeFmt),
25728
26787
  labelFontSize,
25729
26788
  valueFontWeight
@@ -25797,7 +26856,7 @@ function compileSankey(spec, options) {
25797
26856
  const nextColumn = columnX0.get(depth + 1);
25798
26857
  if (nextColumn === void 0) return { text, style: valueStyle };
25799
26858
  const available = nextColumn - LABEL_GAP3 - ((node3.x1 ?? 0) + LABEL_GAP3);
25800
- const needed = estimateTextWidth24(node3.label ?? node3.id, labelFontSize, labelFontWeight) + VALUE_GAP + estimateTextWidth24(text, labelFontSize, valueFontWeight);
26859
+ const needed = estimateTextWidth26(node3.label ?? node3.id, labelFontSize, labelFontWeight) + VALUE_GAP + estimateTextWidth26(text, labelFontSize, valueFontWeight);
25801
26860
  return needed <= available ? { text, style: valueStyle } : void 0;
25802
26861
  };
25803
26862
  const nodeMarks = nodes.map((node3) => {
@@ -26055,7 +27114,7 @@ function emptyLayout4(area3, chrome, theme, options, watermark) {
26055
27114
  }
26056
27115
 
26057
27116
  // src/tables/compile-table.ts
26058
- import { computeChrome as computeChrome7, estimateTextWidth as estimateTextWidth25 } from "@opendata-ai/openchart-core";
27117
+ import { computeChrome as computeChrome7, estimateTextWidth as estimateTextWidth27 } from "@opendata-ai/openchart-core";
26059
27118
 
26060
27119
  // src/tables/bar-column.ts
26061
27120
  var NEGATIVE_BAR_COLOR = "#c44e52";
@@ -26180,7 +27239,7 @@ function computeCategoryColors(data, column, theme, darkMode) {
26180
27239
  import {
26181
27240
  buildD3Formatter as buildD3Formatter4,
26182
27241
  defaultNumberFormatter as defaultNumberFormatter11,
26183
- formatDate as formatDate7,
27242
+ formatDate as formatDate8,
26184
27243
  resolveNumberFormatter as resolveNumberFormatter6
26185
27244
  } from "@opendata-ai/openchart-core";
26186
27245
  function isNumericValue(value) {
@@ -26220,7 +27279,7 @@ function formatCell(value, column) {
26220
27279
  if (isDateValue(value)) {
26221
27280
  return {
26222
27281
  value,
26223
- formattedValue: formatDate7(value),
27282
+ formattedValue: formatDate8(value),
26224
27283
  style
26225
27284
  };
26226
27285
  }
@@ -26528,13 +27587,13 @@ function estimateColumnWidth(col, data, fontSize, paddingX) {
26528
27587
  if (col.image) return (col.image.width ?? 24) + paddingX;
26529
27588
  if (col.flag) return 60;
26530
27589
  const label = col.label ?? col.key;
26531
- const headerWidth = estimateTextWidth25(label, fontSize, 600) + paddingX;
27590
+ const headerWidth = estimateTextWidth27(label, fontSize, 600) + paddingX;
26532
27591
  const sampleSize = Math.min(100, data.length);
26533
27592
  let maxDataWidth = 0;
26534
27593
  for (let i = 0; i < sampleSize; i++) {
26535
27594
  const val = data[i][col.key];
26536
27595
  const text = val == null ? "" : String(val);
26537
- const width = estimateTextWidth25(text, fontSize, 400) + paddingX;
27596
+ const width = estimateTextWidth27(text, fontSize, 400) + paddingX;
26538
27597
  if (width > maxDataWidth) maxDataWidth = width;
26539
27598
  }
26540
27599
  return Math.max(MIN_WIDTH, headerWidth, maxDataWidth);
@@ -26895,9 +27954,9 @@ function compileTableLayout(spec, options, theme) {
26895
27954
  import { mergeThemeConfig as mergeThemeConfig7 } from "@opendata-ai/openchart-core";
26896
27955
  import {
26897
27956
  adaptTheme as adaptTheme6,
26898
- CATEGORICAL_PALETTE as CATEGORICAL_PALETTE3,
27957
+ CATEGORICAL_PALETTE as CATEGORICAL_PALETTE2,
26899
27958
  computeChrome as computeChrome8,
26900
- estimateTextWidth as estimateTextWidth26,
27959
+ estimateTextWidth as estimateTextWidth28,
26901
27960
  getBreakpoint as getBreakpoint3,
26902
27961
  HPAD_COMPACT_FRACTION as HPAD_COMPACT_FRACTION4,
26903
27962
  HPAD_COMPACT_MIN as HPAD_COMPACT_MIN4,
@@ -27073,7 +28132,7 @@ function compileQuantitative(tilemapSpec, options, theme, chrome, fullArea, isDa
27073
28132
  });
27074
28133
  const hasEmptyTiles = tiles.some((t) => !t.hasData);
27075
28134
  const noDataLabel = "No data";
27076
- const noDataLabelWidth = estimateTextWidth26(noDataLabel, 11);
28135
+ const noDataLabelWidth = estimateTextWidth28(noDataLabel, 11);
27077
28136
  const noDataBlockWidth2 = hasEmptyTiles ? NO_DATA_BAR_GAP + legendBarHeight + NO_DATA_LABEL_GAP2 + noDataLabelWidth : 0;
27078
28137
  const barWidth = Math.max(0, legendWidth - noDataBlockWidth2);
27079
28138
  const noDataX = legendX + barWidth + NO_DATA_BAR_GAP;
@@ -27133,7 +28192,7 @@ function compileQuantitative(tilemapSpec, options, theme, chrome, fullArea, isDa
27133
28192
  height: contentHeight,
27134
28193
  animation: resolvedAnimation,
27135
28194
  watermark,
27136
- measureText: options.measureText ?? ((text, fontSize) => ({ width: estimateTextWidth26(text, fontSize), height: fontSize }))
28195
+ measureText: options.measureText ?? ((text, fontSize) => ({ width: estimateTextWidth28(text, fontSize), height: fontSize }))
27137
28196
  };
27138
28197
  }
27139
28198
  function compileCategorical(tilemapSpec, options, theme, chrome, fullArea, isDarkMode, watermark, chromeLayout) {
@@ -27164,12 +28223,12 @@ function compileCategorical(tilemapSpec, options, theme, chrome, fullArea, isDar
27164
28223
  for (const cat of categories) {
27165
28224
  categoryColors.set(
27166
28225
  cat,
27167
- tilemapSpec.colors[cat] ?? CATEGORICAL_PALETTE3[categoryColors.size % CATEGORICAL_PALETTE3.length]
28226
+ tilemapSpec.colors[cat] ?? CATEGORICAL_PALETTE2[categoryColors.size % CATEGORICAL_PALETTE2.length]
27168
28227
  );
27169
28228
  }
27170
28229
  } else {
27171
28230
  for (let i = 0; i < categories.length; i++) {
27172
- categoryColors.set(categories[i], CATEGORICAL_PALETTE3[i % CATEGORICAL_PALETTE3.length]);
28231
+ categoryColors.set(categories[i], CATEGORICAL_PALETTE2[i % CATEGORICAL_PALETTE2.length]);
27173
28232
  }
27174
28233
  }
27175
28234
  const showLegend = tilemapSpec.legend?.show !== false;
@@ -27277,7 +28336,7 @@ function compileCategorical(tilemapSpec, options, theme, chrome, fullArea, isDar
27277
28336
  height: contentHeight,
27278
28337
  animation: resolvedAnimation,
27279
28338
  watermark,
27280
- measureText: options.measureText ?? ((text, fontSize) => ({ width: estimateTextWidth26(text, fontSize), height: fontSize }))
28339
+ measureText: options.measureText ?? ((text, fontSize) => ({ width: estimateTextWidth28(text, fontSize), height: fontSize }))
27281
28340
  };
27282
28341
  }
27283
28342
  function buildTileMark(opts) {
@@ -27403,7 +28462,7 @@ function countLegendRows(labels, availableWidth, fontSize) {
27403
28462
  let rows = 1;
27404
28463
  let offsetX = 0;
27405
28464
  for (let i = 0; i < labels.length; i++) {
27406
- const labelWidth = estimateTextWidth26(labels[i], fontSize);
28465
+ const labelWidth = estimateTextWidth28(labels[i], fontSize);
27407
28466
  const entryWidth = LEGEND_SWATCH_SIZE + LEGEND_SWATCH_GAP + labelWidth + LEGEND_ENTRY_GAP;
27408
28467
  if (i > 0 && offsetX + entryWidth > availableWidth) {
27409
28468
  rows++;
@@ -27447,7 +28506,7 @@ function emptyLayout5(chrome, theme, options, watermark) {
27447
28506
  height: options.height,
27448
28507
  watermark,
27449
28508
  animation: void 0,
27450
- measureText: options.measureText ?? ((text, fontSize) => ({ width: estimateTextWidth26(text, fontSize), height: fontSize }))
28509
+ measureText: options.measureText ?? ((text, fontSize) => ({ width: estimateTextWidth28(text, fontSize), height: fontSize }))
27451
28510
  };
27452
28511
  }
27453
28512
 
@@ -28287,7 +29346,15 @@ function queryGeoReaderRecords(index, query, rank, kind) {
28287
29346
  }
28288
29347
 
28289
29348
  // src/migration/v8.ts
28290
- import { encodePointerToken as encodePointerToken3, legacyEditorial, resolveTheme as resolveTheme8 } from "@opendata-ai/openchart-core";
29349
+ import {
29350
+ CATEGORICAL_FILL_PALETTE_DARK,
29351
+ CATEGORICAL_PALETTE_DARK,
29352
+ encodePointerToken as encodePointerToken3,
29353
+ legacyEditorial,
29354
+ resolveTheme as resolveTheme8
29355
+ } from "@opendata-ai/openchart-core";
29356
+ var V8_CATEGORICAL = ["#06b6d4", "#e29e47", "#4170cb", "#b2417f", "#3ca368", "#a584dc"];
29357
+ var V8_CATEGORICAL_FILL = ["#51bccc", "#dda96b", "#587fc8", "#bf6291", "#62ab7d", "#ae96da"];
28291
29358
  function hasCorrectedValueLabels(current) {
28292
29359
  const mark = typeof current.mark === "string" ? current.mark : current.mark?.type;
28293
29360
  const labels = current.labels;
@@ -28520,6 +29587,14 @@ function migrateSpecV8(input, options = {}) {
28520
29587
  const materialized = {
28521
29588
  ...oldTheme,
28522
29589
  colors: {
29590
+ categorical: V8_CATEGORICAL.map((light, index) => ({
29591
+ light,
29592
+ dark: CATEGORICAL_PALETTE_DARK[index]
29593
+ })),
29594
+ categoricalFill: authoredColors.categorical ?? V8_CATEGORICAL_FILL.map((light, index) => ({
29595
+ light,
29596
+ dark: CATEGORICAL_FILL_PALETTE_DARK[index]
29597
+ })),
28523
29598
  annotationRule: { light: "#666666", dark: "#666666" },
28524
29599
  annotationRangeFill: { light: "#000000", dark: "#000000" },
28525
29600
  annotationMarkerFill: { light: legacySurface, dark: "#0a0a0a" },
@@ -28553,7 +29628,7 @@ function migrateSpecV8(input, options = {}) {
28553
29628
  rewrite(
28554
29629
  "theme",
28555
29630
  materialized,
28556
- "Preserve v8 typography and scaffolding ink without overriding authored chrome sizes. Shared measured attribution replaces the fixed brand reserve; footer wrapping, default watermark size and resulting automatic geometry have no legacy opt-out." + (current.type === "map" ? " Updated static map captions, neutral-class context geometry and occupied size-key placement have no legacy opt-out; their layout cannot be preserved." : "") + (hasCorrectedValueLabels(current) && resolveTheme8(oldTheme).fonts.family !== "system-ui, -apple-system, sans-serif" ? " Corrected value labels now follow the resolved theme font; their former system-font mismatch cannot be preserved independently." : "")
29631
+ "Preserve v8 palettes, typography and scaffolding ink without overriding authored chrome sizes. Shared measured attribution replaces the fixed brand reserve; footer wrapping, default watermark size and resulting automatic geometry have no legacy opt-out." + (current.type === "map" ? " Updated static map captions, neutral-class context geometry and occupied size-key placement have no legacy opt-out; their layout cannot be preserved." : "") + (hasCorrectedValueLabels(current) && resolveTheme8(oldTheme).fonts.family !== "system-ui, -apple-system, sans-serif" ? " Corrected value labels now follow the resolved theme font; their former system-font mismatch cannot be preserved independently." : "")
28557
29632
  );
28558
29633
  }
28559
29634
  }
@@ -28685,6 +29760,7 @@ export {
28685
29760
  diagnoseChart,
28686
29761
  evaluatePredicate,
28687
29762
  facetMinHeight,
29763
+ flattenLayers,
28688
29764
  geoColorKeyPosition,
28689
29765
  getChartRenderer,
28690
29766
  heuristicMeasure,