@opendata-ai/openchart-engine 9.2.3 → 9.4.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
@@ -1425,6 +1425,7 @@ function normalizeLabels(labels) {
1425
1425
  if (labels === true || labels === void 0) return { density: "auto", format: "", prefix: "" };
1426
1426
  return {
1427
1427
  density: labels.density ?? "auto",
1428
+ highlightedOnly: labels.highlightedOnly,
1428
1429
  format: labels.format ?? "",
1429
1430
  prefix: labels.prefix ?? "",
1430
1431
  suffix: labels.suffix,
@@ -1452,11 +1453,6 @@ function normalizeHighlight(encoding, data, warnings) {
1452
1453
  }
1453
1454
  }
1454
1455
  }
1455
- if (highlight.length > 0 && color.scale?.range) {
1456
- warnings.push(
1457
- "[openchart] encoding.color.highlight has no effect on color assignment when encoding.color.scale.range is explicitly provided"
1458
- );
1459
- }
1460
1456
  return highlight;
1461
1457
  }
1462
1458
  function normalizeSeriesSearch(spec, encoding, warnings) {
@@ -1592,6 +1588,10 @@ function normalizeChartSpec(spec, warnings) {
1592
1588
  if (markType === "parliament") {
1593
1589
  warnParliamentMajorityRange(markDef, encoding, spec.data, warnings);
1594
1590
  }
1591
+ const highlight = normalizeHighlight(encoding, spec.data, warnings);
1592
+ if (typeof spec.labels === "object" && spec.labels.highlightedOnly && !highlight.length) {
1593
+ warnings.push("labels.highlightedOnly has no effect without encoding.color.highlight.");
1594
+ }
1595
1595
  return {
1596
1596
  markType,
1597
1597
  sourceMarkType: spec[SOURCE_MARK_TYPE] ?? markType,
@@ -1614,7 +1614,7 @@ function normalizeChartSpec(spec, warnings) {
1614
1614
  hiddenSeries: spec.hiddenSeries ?? [],
1615
1615
  seriesStyles: spec.seriesStyles ?? {},
1616
1616
  watermark: spec.watermark ?? true,
1617
- highlight: normalizeHighlight(encoding, spec.data, warnings),
1617
+ highlight,
1618
1618
  a11y: spec.a11y,
1619
1619
  frame: spec.frame,
1620
1620
  display,
@@ -2185,6 +2185,117 @@ import {
2185
2185
  MARK_ENCODING_RULES
2186
2186
  } from "@opendata-ai/openchart-core";
2187
2187
 
2188
+ // src/compiler/validation/axis-scale.ts
2189
+ var QUANTITATIVE_SCALES = /* @__PURE__ */ new Set(["linear", "log", "pow", "sqrt", "symlog"]);
2190
+ var TIME_INTERVALS = ["year", "quarter", "month", "week", "day", "hour", "minute"];
2191
+ function isRecord(value) {
2192
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2193
+ }
2194
+ function invalid(errors, path, message, suggestion) {
2195
+ errors.push({ code: "INVALID_VALUE", path, message, suggestion });
2196
+ }
2197
+ function validateEnds(scale, quantitative, name, errors) {
2198
+ const label = `encoding.${name}.scale`;
2199
+ const path = `/encoding/${name}/scale`;
2200
+ const { domainMin, domainMax } = scale;
2201
+ if (domainMin === void 0 && domainMax === void 0) return;
2202
+ if (!quantitative) {
2203
+ invalid(
2204
+ errors,
2205
+ path,
2206
+ `${label}.domainMin and domainMax apply to quantitative scales only. Use scale.domain for other scales.`,
2207
+ "Use scale.domain for this channel."
2208
+ );
2209
+ return;
2210
+ }
2211
+ for (const end of ["domainMin", "domainMax"]) {
2212
+ const value = scale[end];
2213
+ if (value !== void 0 && (typeof value !== "number" || !Number.isFinite(value)))
2214
+ invalid(
2215
+ errors,
2216
+ `${path}/${end}`,
2217
+ `${label}.${end} must be a finite number.`,
2218
+ "Use a finite numeric endpoint."
2219
+ );
2220
+ }
2221
+ if (scale.domain !== void 0)
2222
+ invalid(
2223
+ errors,
2224
+ path,
2225
+ `Use either ${label}.domain or domainMin/domainMax, not both.`,
2226
+ "Remove domain or the individual endpoints."
2227
+ );
2228
+ if (typeof domainMin === "number" && typeof domainMax === "number" && domainMin >= domainMax)
2229
+ invalid(
2230
+ errors,
2231
+ path,
2232
+ `${label}.domainMin must be less than domainMax.`,
2233
+ "Set the lower endpoint below the upper endpoint."
2234
+ );
2235
+ }
2236
+ function validateStep(step, quantitative, temporal, name, errors) {
2237
+ if (step === void 0) return;
2238
+ const label = `encoding.${name}.axis.tickStep`;
2239
+ const path = `/encoding/${name}/axis/tickStep`;
2240
+ if (!quantitative && !temporal) {
2241
+ invalid(
2242
+ errors,
2243
+ path,
2244
+ `${label} applies to quantitative and temporal axes only.`,
2245
+ "Remove tickStep from this channel."
2246
+ );
2247
+ } else if (quantitative) {
2248
+ if (typeof step !== "number")
2249
+ invalid(
2250
+ errors,
2251
+ path,
2252
+ `${label} on a quantitative axis takes a number.`,
2253
+ "Use a numeric distance between ticks."
2254
+ );
2255
+ else if (!Number.isFinite(step) || step <= 0)
2256
+ invalid(
2257
+ errors,
2258
+ path,
2259
+ `${label} must be a positive number.`,
2260
+ "Use a finite number greater than zero."
2261
+ );
2262
+ } else if (!isRecord(step)) {
2263
+ invalid(
2264
+ errors,
2265
+ path,
2266
+ `${label} on a temporal axis takes { interval, step }, such as { interval: 'month', step: 3 }.`,
2267
+ "Use an interval object for temporal ticks."
2268
+ );
2269
+ } else {
2270
+ if (typeof step.interval !== "string" || !TIME_INTERVALS.includes(step.interval))
2271
+ invalid(
2272
+ errors,
2273
+ `${path}/interval`,
2274
+ `${label}.interval must be one of ${TIME_INTERVALS.join(", ")}.`,
2275
+ "Choose a supported calendar interval."
2276
+ );
2277
+ if (step.step !== void 0 && (typeof step.step !== "number" || !Number.isInteger(step.step) || step.step <= 0))
2278
+ invalid(
2279
+ errors,
2280
+ `${path}/step`,
2281
+ `${label}.step must be a positive whole number.`,
2282
+ "Use a positive integer interval count."
2283
+ );
2284
+ }
2285
+ }
2286
+ function validateAxisScaleOptions(spec, errors) {
2287
+ if (!isRecord(spec.encoding)) return;
2288
+ for (const name of ["x", "y"]) {
2289
+ const channel = spec.encoding[name];
2290
+ if (!isRecord(channel)) continue;
2291
+ const scale = isRecord(channel.scale) ? channel.scale : {};
2292
+ const quantitative = channel.type === "quantitative" && (scale.type === void 0 || typeof scale.type === "string" && QUANTITATIVE_SCALES.has(scale.type));
2293
+ validateEnds(scale, quantitative, name, errors);
2294
+ if (isRecord(channel.axis))
2295
+ validateStep(channel.axis.tickStep, quantitative, channel.type === "temporal", name, errors);
2296
+ }
2297
+ }
2298
+
2188
2299
  // src/compiler/validation/frame.ts
2189
2300
  function validateFrame(spec, errors, prefix = "") {
2190
2301
  if (spec.frame === void 0) return;
@@ -2384,6 +2495,19 @@ function validateRangeSpec(spec, errors) {
2384
2495
  }
2385
2496
  }
2386
2497
  }
2498
+ function validateArcRadius(spec, errors) {
2499
+ if (!spec.mark || typeof spec.mark !== "object" || !("innerRadius" in spec.mark)) return;
2500
+ const radius = spec.mark.innerRadius;
2501
+ if (radius === void 0) return;
2502
+ if (typeof radius !== "number" || !Number.isFinite(radius) || radius < 0) {
2503
+ errors.push({
2504
+ code: "INVALID_VALUE",
2505
+ path: "/mark/innerRadius",
2506
+ message: "mark.innerRadius must be 0 or more: a fraction of the radius below 1, or pixels from 1 up.",
2507
+ suggestion: "Use 0 for a pie, a fraction such as 0.6 for a donut, or a pixel radius such as 20."
2508
+ });
2509
+ }
2510
+ }
2387
2511
  function validateCenterLabel(spec, markType, errors) {
2388
2512
  if (!spec.mark || typeof spec.mark !== "object" || Array.isArray(spec.mark)) return;
2389
2513
  const centerLabel = spec.mark.centerLabel;
@@ -2740,7 +2864,7 @@ var PLAYBACK_OPTIONS = [
2740
2864
  ];
2741
2865
  var TIMING_EXAMPLES = { duration: 12e3, step: 700, holdEnd: 0 };
2742
2866
  var PERIOD_POSITIONS = ["auto", "center", "top-right", "bottom-left"];
2743
- function isRecord(value) {
2867
+ function isRecord2(value) {
2744
2868
  return typeof value === "object" && value !== null && !Array.isArray(value);
2745
2869
  }
2746
2870
  function isFiniteNumber(value) {
@@ -2749,7 +2873,7 @@ function isFiniteNumber(value) {
2749
2873
  function isStringArray(value) {
2750
2874
  return Array.isArray(value) && value.every((item) => typeof item === "string");
2751
2875
  }
2752
- function invalid(path, message, suggestion) {
2876
+ function invalid2(path, message, suggestion) {
2753
2877
  return { code: "INVALID_VALUE", path, message: `Spec error: ${message}`, suggestion };
2754
2878
  }
2755
2879
  function checkUnknownPlaybackKeys(block, errors) {
@@ -2757,7 +2881,7 @@ function checkUnknownPlaybackKeys(block, errors) {
2757
2881
  if (PLAYBACK_OPTIONS.some((known) => known === option)) continue;
2758
2882
  const hint = didYouMean(option, PLAYBACK_OPTIONS);
2759
2883
  errors.push(
2760
- invalid(
2884
+ invalid2(
2761
2885
  jsonPointer5("playback", option),
2762
2886
  `Unknown playback option "${option}"`,
2763
2887
  hint ? `Check the option name and keep its value.${hint}` : `Remove "${option}". Supported playback options are ${PLAYBACK_OPTIONS.join(", ")}.`
@@ -2768,7 +2892,7 @@ function checkUnknownPlaybackKeys(block, errors) {
2768
2892
  function checkTiming(name, block, errors) {
2769
2893
  if (block.duration !== void 0 && block.step !== void 0) {
2770
2894
  errors.push(
2771
- invalid(
2895
+ invalid2(
2772
2896
  `/${name}`,
2773
2897
  `${name}.duration and ${name}.step are mutually exclusive`,
2774
2898
  `Keep duration for the whole ${name} or step for each period. Remove the other option.`
@@ -2781,7 +2905,7 @@ function checkTiming(name, block, errors) {
2781
2905
  const allowZero = option === "holdEnd";
2782
2906
  if (isFiniteNumber(value) && value >= 0 && (value > 0 || allowZero)) continue;
2783
2907
  errors.push(
2784
- invalid(
2908
+ invalid2(
2785
2909
  jsonPointer5(name, option),
2786
2910
  `${name}.${option} must be a finite number ${allowZero ? "of zero or more" : "greater than zero"}`,
2787
2911
  `Use ${option}: ${example} or omit the option. Times are in milliseconds.`
@@ -2792,7 +2916,7 @@ function checkTiming(name, block, errors) {
2792
2916
  function checkGaps(name, gaps, errors) {
2793
2917
  if (gaps === void 0 || gaps === "interpolate" || gaps === "hold" || gaps === "drop") return;
2794
2918
  errors.push(
2795
- invalid(
2919
+ invalid2(
2796
2920
  `/${name}/gaps`,
2797
2921
  `${name}.gaps must be "interpolate", "hold", or "drop"`,
2798
2922
  'Use "interpolate" to fill gaps between observed periods, "hold" to carry the last value, or "drop" to leave values absent.'
@@ -2803,7 +2927,7 @@ function checkSwitches(name, block, errors) {
2803
2927
  for (const option of ["loop", "controls"]) {
2804
2928
  if (block[option] === void 0 || typeof block[option] === "boolean") continue;
2805
2929
  errors.push(
2806
- invalid(
2930
+ invalid2(
2807
2931
  jsonPointer5(name, option),
2808
2932
  `${name}.${option} must be true or false`,
2809
2933
  `Use ${option}: false to disable it or ${option}: true to enable it.`
@@ -2813,7 +2937,7 @@ function checkSwitches(name, block, errors) {
2813
2937
  const { autoplay } = block;
2814
2938
  if (autoplay === void 0 || autoplay === "visible" || typeof autoplay === "boolean") return;
2815
2939
  errors.push(
2816
- invalid(
2940
+ invalid2(
2817
2941
  `/${name}/autoplay`,
2818
2942
  `${name}.autoplay must be "visible", true, or false`,
2819
2943
  'Use "visible" to start when the chart is in view, true to start immediately, or false to wait for play.'
@@ -2822,9 +2946,9 @@ function checkSwitches(name, block, errors) {
2822
2946
  }
2823
2947
  function checkPeriod(name, period, errors) {
2824
2948
  if (period === void 0 || period === false) return;
2825
- if (!isRecord(period)) {
2949
+ if (!isRecord2(period)) {
2826
2950
  errors.push(
2827
- invalid(
2951
+ invalid2(
2828
2952
  `/${name}/period`,
2829
2953
  `${name}.period must be false or an object`,
2830
2954
  'Use period: false to hide the label, period: { format: "%Y" } to format it, or omit period to use the default label.'
@@ -2834,7 +2958,7 @@ function checkPeriod(name, period, errors) {
2834
2958
  }
2835
2959
  if (period.format !== void 0 && typeof period.format !== "string") {
2836
2960
  errors.push(
2837
- invalid(
2961
+ invalid2(
2838
2962
  `/${name}/period/format`,
2839
2963
  `${name}.period.format must be a string`,
2840
2964
  'Use a format string such as format: "%Y" for temporal years or omit format.'
@@ -2844,7 +2968,7 @@ function checkPeriod(name, period, errors) {
2844
2968
  if (name !== "playback" || period.position === void 0) return;
2845
2969
  if (PERIOD_POSITIONS.some((position) => position === period.position)) return;
2846
2970
  errors.push(
2847
- invalid(
2971
+ invalid2(
2848
2972
  "/playback/period/position",
2849
2973
  `playback.period.position must be ${PERIOD_POSITIONS.map((p) => `"${p}"`).join(", ")}`,
2850
2974
  'Use "auto" to place the label for the chart type, or omit position.'
@@ -2855,7 +2979,7 @@ function checkHighlights(block, errors) {
2855
2979
  const { labels, trails } = block;
2856
2980
  if (labels !== void 0 && !isStringArray(labels)) {
2857
2981
  errors.push(
2858
- invalid(
2982
+ invalid2(
2859
2983
  "/playback/labels",
2860
2984
  "playback.labels must be an array of key names",
2861
2985
  'Use labels: ["China", "India"] with values from the key field, or omit labels.'
@@ -2864,7 +2988,7 @@ function checkHighlights(block, errors) {
2864
2988
  }
2865
2989
  if (trails !== void 0 && typeof trails !== "boolean" && !isStringArray(trails)) {
2866
2990
  errors.push(
2867
- invalid(
2991
+ invalid2(
2868
2992
  "/playback/trails",
2869
2993
  "playback.trails must be true, false, or an array of key names",
2870
2994
  'Use trails: true for every key, trails: ["China"] for named keys, or omit trails.'
@@ -2874,7 +2998,7 @@ function checkHighlights(block, errors) {
2874
2998
  }
2875
2999
  function validatePlaybackBlock(blockName, value, errors) {
2876
3000
  if (value === void 0) return;
2877
- if (!isRecord(value)) {
3001
+ if (!isRecord2(value)) {
2878
3002
  if (blockName === "race") return;
2879
3003
  errors.push({
2880
3004
  code: "INVALID_TYPE",
@@ -2896,16 +3020,16 @@ function validatePlaybackBlock(blockName, value, errors) {
2896
3020
  var SUPPORTED_MARKS = ["point", "circle", "bar"];
2897
3021
  var KEYED_MARKS = ["point", "circle"];
2898
3022
  var TIME_PATH = "/encoding/time";
2899
- function isRecord2(value) {
3023
+ function isRecord3(value) {
2900
3024
  return typeof value === "object" && value !== null && !Array.isArray(value);
2901
3025
  }
2902
3026
  function fieldOf(channel) {
2903
- if (!isRecord2(channel)) return void 0;
3027
+ if (!isRecord3(channel)) return void 0;
2904
3028
  return typeof channel.field === "string" ? channel.field : void 0;
2905
3029
  }
2906
3030
  function markTypeOf2(spec) {
2907
3031
  if (typeof spec.mark === "string") return spec.mark;
2908
- return isRecord2(spec.mark) && typeof spec.mark.type === "string" ? spec.mark.type : void 0;
3032
+ return isRecord3(spec.mark) && typeof spec.mark.type === "string" ? spec.mark.type : void 0;
2909
3033
  }
2910
3034
  function mismatch(path, message, suggestion) {
2911
3035
  return { code: "ENCODING_MISMATCH", path, message: `Spec error: ${message}`, suggestion };
@@ -2958,7 +3082,7 @@ function checkUnsupportedFeatures(spec, encoding, context, errors) {
2958
3082
  )
2959
3083
  );
2960
3084
  }
2961
- if (isRecord2(spec.mark) && spec.mark.trendline) {
3085
+ if (isRecord3(spec.mark) && spec.mark.trendline) {
2962
3086
  errors.push(
2963
3087
  mismatch(
2964
3088
  "/mark/trendline",
@@ -2970,7 +3094,7 @@ function checkUnsupportedFeatures(spec, encoding, context, errors) {
2970
3094
  }
2971
3095
  function checkPointOnlyOptions(spec, errors) {
2972
3096
  const mark = markTypeOf2(spec);
2973
- if (!mark || mark === "point" || !isRecord2(spec.playback)) return;
3097
+ if (!mark || mark === "point" || !isRecord3(spec.playback)) return;
2974
3098
  for (const option of ["trails", "labels"]) {
2975
3099
  const value = spec.playback[option];
2976
3100
  if (value === void 0 || value === false) continue;
@@ -2984,12 +3108,12 @@ function checkPointOnlyOptions(spec, errors) {
2984
3108
  }
2985
3109
  }
2986
3110
  function checkTrailAxes(spec, encoding, errors) {
2987
- if (markTypeOf2(spec) !== "point" || !isRecord2(spec.playback)) return;
3111
+ if (markTypeOf2(spec) !== "point" || !isRecord3(spec.playback)) return;
2988
3112
  const trails = spec.playback.trails;
2989
3113
  if (trails === void 0 || trails === false) return;
2990
3114
  for (const channel of ["x", "y"]) {
2991
3115
  const authored = encoding[channel];
2992
- const type = isRecord2(authored) ? authored.type : void 0;
3116
+ const type = isRecord3(authored) ? authored.type : void 0;
2993
3117
  if (type === void 0 || type === "quantitative") continue;
2994
3118
  errors.push(
2995
3119
  mismatch(
@@ -3004,7 +3128,7 @@ function checkTrailAxes(spec, encoding, errors) {
3004
3128
  function checkAggregateKeepsTime(spec, timeField, errors) {
3005
3129
  if (!Array.isArray(spec.transform)) return;
3006
3130
  spec.transform.forEach((step, index) => {
3007
- if (!(isRecord2(step) && "aggregate" in step)) return;
3131
+ if (!(isRecord3(step) && "aggregate" in step)) return;
3008
3132
  const groupby = Array.isArray(step.groupby) ? step.groupby : [];
3009
3133
  if (groupby.includes(timeField)) return;
3010
3134
  errors.push(
@@ -3017,7 +3141,7 @@ function checkAggregateKeepsTime(spec, timeField, errors) {
3017
3141
  });
3018
3142
  }
3019
3143
  function barIdentity(encoding) {
3020
- const xQuantitative = isRecord2(encoding.x) && encoding.x.type === "quantitative";
3144
+ const xQuantitative = isRecord3(encoding.x) && encoding.x.type === "quantitative";
3021
3145
  const categoryField = fieldOf(xQuantitative ? encoding.y : encoding.x);
3022
3146
  if (!categoryField) return null;
3023
3147
  const colorField = fieldOf(encoding.color);
@@ -3046,7 +3170,7 @@ function identityFor(spec, encoding, errors) {
3046
3170
  };
3047
3171
  }
3048
3172
  function timeTypeOf(time) {
3049
- const type = isRecord2(time) ? time.type : void 0;
3173
+ const type = isRecord3(time) ? time.type : void 0;
3050
3174
  return type === "temporal" || type === "quantitative" ? type : "ordinal";
3051
3175
  }
3052
3176
  function checkUniqueRows(spec, identity, time, errors) {
@@ -3061,7 +3185,7 @@ function checkUniqueRows(spec, identity, time, errors) {
3061
3185
  });
3062
3186
  }
3063
3187
  function validateTimeEncoding(spec, errors, context = {}) {
3064
- const encoding = isRecord2(spec.encoding) ? spec.encoding : {};
3188
+ const encoding = isRecord3(spec.encoding) ? spec.encoding : {};
3065
3189
  checkUnsupportedFeatures(spec, encoding, context, errors);
3066
3190
  checkPointOnlyOptions(spec, errors);
3067
3191
  checkTrailAxes(spec, encoding, errors);
@@ -3201,6 +3325,8 @@ function validateChartSpec(spec, errors, context = {}) {
3201
3325
  }
3202
3326
  }
3203
3327
  validateCenterLabel(spec, markType, errors);
3328
+ validateAxisScaleOptions(spec, errors);
3329
+ validateArcRadius(spec, errors);
3204
3330
  if (markType === "errorbar") validateErrorbarSpec(spec, errors);
3205
3331
  if (markType === "range") {
3206
3332
  validateRangeSpec(spec, errors);
@@ -3285,6 +3411,16 @@ function validateChartSpec(spec, errors, context = {}) {
3285
3411
  }
3286
3412
  const channelObj = channelSpec;
3287
3413
  const channelRule = rules[channel];
3414
+ if (channel === "color" && "value" in channelObj && !("field" in channelObj)) {
3415
+ if (typeof channelObj.value !== "string")
3416
+ errors.push({
3417
+ message: "encoding.color.value must be a color string.",
3418
+ path: "/encoding/color/value",
3419
+ code: "INVALID_VALUE",
3420
+ suggestion: 'Use a color string such as "#ff0000".'
3421
+ });
3422
+ continue;
3423
+ }
3288
3424
  if (channel === "description" && "value" in channelObj) {
3289
3425
  if (typeof channelObj.value !== "string" || "field" in channelObj)
3290
3426
  errors.push({
@@ -3846,17 +3982,17 @@ function topologyBBox(topology) {
3846
3982
  import { jsonPointer as jsonPointer9 } from "@opendata-ai/openchart-core";
3847
3983
  var TIME_TYPES = ["temporal", "ordinal", "quantitative"];
3848
3984
  var POINT_ONLY_OPTIONS = ["labels", "trails"];
3849
- function isRecord3(value) {
3985
+ function isRecord4(value) {
3850
3986
  return typeof value === "object" && value !== null && !Array.isArray(value);
3851
3987
  }
3852
3988
  function fieldOf2(channel) {
3853
- return isRecord3(channel) && typeof channel.field === "string" ? channel.field : void 0;
3989
+ return isRecord4(channel) && typeof channel.field === "string" ? channel.field : void 0;
3854
3990
  }
3855
3991
  function timeTypeOf2(channel) {
3856
- const type = isRecord3(channel) ? channel.type : void 0;
3992
+ const type = isRecord4(channel) ? channel.type : void 0;
3857
3993
  return typeof type === "string" && TIME_TYPES.includes(type) ? type : void 0;
3858
3994
  }
3859
- function invalid2(path, message, suggestion) {
3995
+ function invalid3(path, message, suggestion) {
3860
3996
  return { code: "INVALID_VALUE", path, message: `Spec error: ${message}`, suggestion };
3861
3997
  }
3862
3998
  function checkTimeChannel(channel, path, errors) {
@@ -3871,7 +4007,7 @@ function checkTimeChannel(channel, path, errors) {
3871
4007
  }
3872
4008
  if (timeTypeOf2(channel)) return;
3873
4009
  errors.push(
3874
- invalid2(
4010
+ invalid3(
3875
4011
  `${path}/type`,
3876
4012
  `time type must be one of ${TIME_TYPES.join(", ")}, received ${JSON.stringify(channel.type)}`,
3877
4013
  "Use temporal for dates and years, quantitative for numbers, ordinal for labels in order."
@@ -3886,7 +4022,7 @@ function checkUniqueRows2(rows, identityField, time, path, errors) {
3886
4022
  const collision = firstDuplicateCell(rows, identityOf, { field: timeField, type: timeType });
3887
4023
  if (!collision) return;
3888
4024
  errors.push(
3889
- invalid2(
4025
+ invalid3(
3890
4026
  path,
3891
4027
  `${collision.count} rows have ${identityField} = '${collision.identity}' and ${timeField} = '${String(collision.period)}'. Aggregate them first.`,
3892
4028
  `Aggregate the data so each ${identityField} has one row per ${timeField}.`
@@ -3895,12 +4031,12 @@ function checkUniqueRows2(rows, identityField, time, path, errors) {
3895
4031
  }
3896
4032
  function checkPlaybackBlock(spec, errors) {
3897
4033
  validatePlaybackBlock("playback", spec.playback, errors);
3898
- if (!isRecord3(spec.playback)) return;
4034
+ if (!isRecord4(spec.playback)) return;
3899
4035
  for (const option of POINT_ONLY_OPTIONS) {
3900
4036
  const value = spec.playback[option];
3901
4037
  if (value === void 0 || value === false) continue;
3902
4038
  errors.push(
3903
- invalid2(
4039
+ invalid3(
3904
4040
  jsonPointer9("playback", option),
3905
4041
  `playback.${option} is only supported on point charts, not maps`,
3906
4042
  `Remove playback.${option}.`
@@ -3920,9 +4056,9 @@ function checkChoroplethTime(spec, encoding, errors) {
3920
4056
  });
3921
4057
  }
3922
4058
  const color = encoding.color;
3923
- if (!isRecord3(color) || color.type !== "quantitative") {
4059
+ if (!isRecord4(color) || color.type !== "quantitative") {
3924
4060
  errors.push(
3925
- invalid2(
4061
+ invalid3(
3926
4062
  "/encoding/color",
3927
4063
  "a map with encoding.time needs a quantitative encoding.color to recolor each period",
3928
4064
  'Set encoding.color to a numeric field with type: "quantitative", or remove encoding.time.'
@@ -3949,7 +4085,7 @@ function checkLayersShareTimeType(encoding, points, errors) {
3949
4085
  const pointType = timeTypeOf2(points.time);
3950
4086
  if (!featureType || !pointType || featureType === pointType) return;
3951
4087
  errors.push(
3952
- invalid2(
4088
+ invalid3(
3953
4089
  "/points/time/type",
3954
4090
  `encoding.time is ${featureType} but points.time is ${pointType}; both layers play on one timeline`,
3955
4091
  `Give encoding.time and points.time the same type, e.g. both "${featureType}".`
@@ -3957,8 +4093,8 @@ function checkLayersShareTimeType(encoding, points, errors) {
3957
4093
  );
3958
4094
  }
3959
4095
  function validateGeoMapTime(spec, errors) {
3960
- const encoding = isRecord3(spec.encoding) ? spec.encoding : {};
3961
- const points = isRecord3(spec.points) ? spec.points : void 0;
4096
+ const encoding = isRecord4(spec.encoding) ? spec.encoding : {};
4097
+ const points = isRecord4(spec.points) ? spec.points : void 0;
3962
4098
  const choroplethTime = encoding.time != null;
3963
4099
  const pointsTime = points?.time != null;
3964
4100
  if (!choroplethTime && !pointsTime) return;
@@ -3969,9 +4105,9 @@ function validateGeoMapTime(spec, errors) {
3969
4105
  }
3970
4106
  function checkTileColoring(spec, encoding, errors) {
3971
4107
  const value = encoding.value;
3972
- if (isRecord3(value) && value.type !== void 0 && value.type !== "quantitative") {
4108
+ if (isRecord4(value) && value.type !== void 0 && value.type !== "quantitative") {
3973
4109
  errors.push(
3974
- invalid2(
4110
+ invalid3(
3975
4111
  "/encoding/value",
3976
4112
  `a tile map with encoding.time needs a quantitative encoding.value, received type ${JSON.stringify(value.type)}`,
3977
4113
  'Set encoding.value to a numeric field with type: "quantitative".'
@@ -3980,7 +4116,7 @@ function checkTileColoring(spec, encoding, errors) {
3980
4116
  }
3981
4117
  if (encoding.color !== void 0) {
3982
4118
  errors.push(
3983
- invalid2(
4119
+ invalid3(
3984
4120
  "/encoding/color",
3985
4121
  "a tile map with encoding.time shades encoding.value, so it cannot use categorical encoding.color",
3986
4122
  "Remove encoding.color, or remove encoding.time for a categorical tile map."
@@ -3989,7 +4125,7 @@ function checkTileColoring(spec, encoding, errors) {
3989
4125
  }
3990
4126
  if (spec.colors !== void 0) {
3991
4127
  errors.push(
3992
- invalid2(
4128
+ invalid3(
3993
4129
  "/colors",
3994
4130
  "a tile map with encoding.time shades encoding.value, so it cannot use categorical colors",
3995
4131
  "Remove colors, or remove encoding.time for a categorical tile map."
@@ -3998,7 +4134,7 @@ function checkTileColoring(spec, encoding, errors) {
3998
4134
  }
3999
4135
  }
4000
4136
  function validateTileMapTime(spec, errors) {
4001
- const encoding = isRecord3(spec.encoding) ? spec.encoding : {};
4137
+ const encoding = isRecord4(spec.encoding) ? spec.encoding : {};
4002
4138
  if (encoding.time == null) return;
4003
4139
  checkTimeChannel(encoding.time, "/encoding/time", errors);
4004
4140
  if (!Array.isArray(spec.data)) {
@@ -4847,7 +4983,7 @@ var RACE_ERROR_ORDER = [
4847
4983
  "period"
4848
4984
  ];
4849
4985
  var CHART_ONLY_PLAYBACK_OPTIONS = ["labels", "trails"];
4850
- function isRecord4(value) {
4986
+ function isRecord5(value) {
4851
4987
  return typeof value === "object" && value !== null && !Array.isArray(value);
4852
4988
  }
4853
4989
  function isFiniteNumber2(value) {
@@ -4884,7 +5020,7 @@ function checkScale(race, errors) {
4884
5020
  suggestion: "Set race.top to the desired number of visible ranks, e.g. top: 10."
4885
5021
  });
4886
5022
  }
4887
- if (rescale !== void 0 && rescale !== "frame" && rescale !== "fixed" && !(isRecord4(rescale) && isFiniteNumber2(rescale.min))) {
5023
+ if (rescale !== void 0 && rescale !== "frame" && rescale !== "fixed" && !(isRecord5(rescale) && isFiniteNumber2(rescale.min))) {
4888
5024
  errors.push({
4889
5025
  code: "INVALID_VALUE",
4890
5026
  path: "/race/rescale",
@@ -4929,7 +5065,7 @@ function checkTimingAcrossBlocks(race, playback, errors) {
4929
5065
  }
4930
5066
  }
4931
5067
  function checkPlaybackAgainstRace(race, playback, errors) {
4932
- if (isRecord4(race)) checkTimingAcrossBlocks(race, playback, errors);
5068
+ if (isRecord5(race)) checkTimingAcrossBlocks(race, playback, errors);
4933
5069
  for (const field of Object.keys(playback)) {
4934
5070
  if (CHART_ONLY_PLAYBACK_OPTIONS.includes(field)) {
4935
5071
  errors.push({
@@ -4938,7 +5074,7 @@ function checkPlaybackAgainstRace(race, playback, errors) {
4938
5074
  message: `Spec error: playback.${field} applies to point and circle charts only`,
4939
5075
  suggestion: `Remove playback.${field} from the race spec.`
4940
5076
  });
4941
- } else if (isRecord4(race) && race[field] !== void 0 && playback[field] !== void 0) {
5077
+ } else if (isRecord5(race) && race[field] !== void 0 && playback[field] !== void 0) {
4942
5078
  errors.push({
4943
5079
  code: "INVALID_VALUE",
4944
5080
  path: jsonPointer13("playback", field),
@@ -4950,7 +5086,7 @@ function checkPlaybackAgainstRace(race, playback, errors) {
4950
5086
  }
4951
5087
  function validateOptions(race, errors) {
4952
5088
  if (race === void 0) return;
4953
- if (!isRecord4(race)) {
5089
+ if (!isRecord5(race)) {
4954
5090
  errors.push({
4955
5091
  code: "INVALID_TYPE",
4956
5092
  path: "/race",
@@ -4965,7 +5101,7 @@ function validateOptions(race, errors) {
4965
5101
  function validateRacePlayback(race, playback, errors) {
4966
5102
  if (playback === void 0) return;
4967
5103
  validatePlaybackBlock("playback", playback, errors);
4968
- if (isRecord4(playback)) checkPlaybackAgainstRace(race, playback, errors);
5104
+ if (isRecord5(playback)) checkPlaybackAgainstRace(race, playback, errors);
4969
5105
  }
4970
5106
 
4971
5107
  // src/compiler/validation/race.ts
@@ -4982,7 +5118,7 @@ var TABLE_COLUMNS = [
4982
5118
  "value",
4983
5119
  "share"
4984
5120
  ];
4985
- function isRecord5(value) {
5121
+ function isRecord6(value) {
4986
5122
  return typeof value === "object" && value !== null && !Array.isArray(value);
4987
5123
  }
4988
5124
  function validateEncodingType(channel, type, errors) {
@@ -5005,7 +5141,7 @@ function validateEncodingType(channel, type, errors) {
5005
5141
  }
5006
5142
  }
5007
5143
  function validateEncoding(encoding, errors) {
5008
- if (!isRecord5(encoding)) {
5144
+ if (!isRecord6(encoding)) {
5009
5145
  errors.push({
5010
5146
  code: encoding === void 0 ? "MISSING_FIELD" : "INVALID_TYPE",
5011
5147
  path: "/encoding",
@@ -5016,7 +5152,7 @@ function validateEncoding(encoding, errors) {
5016
5152
  }
5017
5153
  for (const [channel, example] of Object.entries({ time: "year", key: "country", value: "gdp" })) {
5018
5154
  const definition = encoding[channel];
5019
- if (!isRecord5(definition)) {
5155
+ if (!isRecord6(definition)) {
5020
5156
  errors.push({
5021
5157
  code: definition === void 0 ? "MISSING_FIELD" : "INVALID_TYPE",
5022
5158
  path: jsonPointer14("encoding", channel),
@@ -5038,7 +5174,7 @@ function validateEncoding(encoding, errors) {
5038
5174
  }
5039
5175
  for (const channel of ["label", "color"]) {
5040
5176
  const definition = encoding[channel];
5041
- if (definition === void 0 || isRecord5(definition)) continue;
5177
+ if (definition === void 0 || isRecord6(definition)) continue;
5042
5178
  errors.push({
5043
5179
  code: "INVALID_TYPE",
5044
5180
  path: jsonPointer14("encoding", channel),
@@ -5048,7 +5184,7 @@ function validateEncoding(encoding, errors) {
5048
5184
  }
5049
5185
  }
5050
5186
  function validateEncodingFields(encoding, data, errors) {
5051
- if (!isRecord5(encoding) || data.length === 0) return;
5187
+ if (!isRecord6(encoding) || data.length === 0) return;
5052
5188
  const dataColumns = /* @__PURE__ */ new Set();
5053
5189
  for (const row of data) {
5054
5190
  for (const column of Object.keys(row)) dataColumns.add(column);
@@ -5057,7 +5193,7 @@ function validateEncodingFields(encoding, data, errors) {
5057
5193
  const availableColumns = columnList.join(", ");
5058
5194
  for (const channel of ["time", "key", "value", "label", "color"]) {
5059
5195
  const definition = encoding[channel];
5060
- if (!isRecord5(definition)) continue;
5196
+ if (!isRecord6(definition)) continue;
5061
5197
  const { field } = definition;
5062
5198
  if (typeof field !== "string" || field.trim() === "" || dataColumns.has(field)) continue;
5063
5199
  errors.push({
@@ -5100,7 +5236,7 @@ function validateMarkOptions(type, definition, errors) {
5100
5236
  if (type === "table") validateTableColumns(columns, errors);
5101
5237
  }
5102
5238
  function validateMark(mark, errors) {
5103
- const definition = isRecord5(mark) ? mark : void 0;
5239
+ const definition = isRecord6(mark) ? mark : void 0;
5104
5240
  const type = definition ? definition.type : mark;
5105
5241
  if (type !== "bar" && type !== "line" && type !== "table") {
5106
5242
  errors.push({
@@ -5137,7 +5273,7 @@ function validateData(data, errors) {
5137
5273
  let firstInvalidRow = -1;
5138
5274
  let invalidCount = 0;
5139
5275
  for (let index = 0; index < data.length; index++) {
5140
- if (isRecord5(data[index])) continue;
5276
+ if (isRecord6(data[index])) continue;
5141
5277
  if (firstInvalidRow === -1) firstInvalidRow = index;
5142
5278
  invalidCount++;
5143
5279
  }
@@ -8726,6 +8862,8 @@ function computeAnnotations(spec, ctx) {
8726
8862
  nudgeRefLineLabel(resolved, annotation, ctx.obstacles, ctx.chartArea, ctx.measure);
8727
8863
  }
8728
8864
  annotations.push(resolved);
8865
+ } else {
8866
+ ctx.onUnplaced?.(specIndex);
8729
8867
  }
8730
8868
  }
8731
8869
  if (autoQueue.length > 0 && ctx.svg.width > 0 && ctx.svg.height > 0) {
@@ -9151,6 +9289,17 @@ function filterByDensity(marks, density) {
9151
9289
  return marks;
9152
9290
  }
9153
9291
 
9292
+ // src/charts/_shared/highlight-filter.ts
9293
+ function filterHighlighted(marks, highlight, colorField) {
9294
+ if (!highlight?.length) return marks;
9295
+ const selected = new Set(highlight);
9296
+ return marks.filter((mark) => {
9297
+ const series = "seriesKey" in mark ? mark.seriesKey : void 0;
9298
+ const value = colorField && !Array.isArray(mark.data) ? mark.data?.[colorField] : void 0;
9299
+ return selected.has(series ?? String(value));
9300
+ });
9301
+ }
9302
+
9154
9303
  // src/charts/bar/mirror-labels.ts
9155
9304
  var GUTTER_PADDING = 8;
9156
9305
  var HALF_LABEL_GAP = 8;
@@ -9173,7 +9322,9 @@ function attachValueLabels(rects, spec, xField, leftSeries, theme) {
9173
9322
  values: spec.data.map((row) => row[xField])
9174
9323
  });
9175
9324
  const fontSize = spec.labels.fontSize ?? VALUE_LABEL_FONT_SIZE;
9176
- for (const mark of filterByDensity(rects, spec.labels.density)) {
9325
+ const color = spec.encoding.color;
9326
+ const candidates = spec.labels.highlightedOnly ? filterHighlighted(rects, spec.highlight, color && "field" in color ? color.field : void 0) : rects;
9327
+ for (const mark of filterByDensity(candidates, spec.labels.density)) {
9177
9328
  const onLeft = mark.seriesKey === leftSeries;
9178
9329
  const text = `${spec.labels.prefix ?? ""}${format2(Number(mark.data[xField]))}${spec.labels.suffix ?? ""}`;
9179
9330
  const label = {
@@ -9265,11 +9416,14 @@ function planBarLabels(spec, theme, options) {
9265
9416
  const channel = horizontal ? spec.encoding.x : spec.encoding.y;
9266
9417
  if (!channel || !("field" in channel)) return empty;
9267
9418
  const field = channel.field;
9268
- const values = spec.data.map((row) => finiteNumber(row[field])).filter((value) => value !== void 0);
9419
+ const color = spec.encoding.color;
9420
+ const highlight = spec.labels.highlightedOnly ? spec.highlight : void 0;
9421
+ const rows = highlight?.length && color && "field" in color ? spec.data.filter((row) => highlight.includes(String(row[color.field]))) : spec.data;
9422
+ const values = rows.map((row) => finiteNumber(row[field])).filter((value) => value !== void 0);
9269
9423
  const format2 = resolveFieldFormatter({
9270
9424
  surfaceFormat: spec.labels.format,
9271
9425
  channelFormat: "format" in channel ? channel.format : void 0,
9272
- values
9426
+ values: spec.data.map((row) => row[field])
9273
9427
  });
9274
9428
  const fontSize = spec.labels.fontSize ?? (horizontal ? 11 : 10);
9275
9429
  let maxWidth = 0;
@@ -9354,6 +9508,68 @@ import {
9354
9508
  formatDate as formatDate2,
9355
9509
  resolveNumberFormatter as resolveNumberFormatter2
9356
9510
  } from "@opendata-ai/openchart-core";
9511
+
9512
+ // src/layout/axes/tick-step.ts
9513
+ import {
9514
+ timeDay,
9515
+ timeHour,
9516
+ timeMinute,
9517
+ timeMonth,
9518
+ timeWeek,
9519
+ timeYear,
9520
+ utcDay,
9521
+ utcHour,
9522
+ utcMinute,
9523
+ utcMonth,
9524
+ utcWeek,
9525
+ utcYear
9526
+ } from "d3-time";
9527
+ function stepTicks(scale, step, scaleType) {
9528
+ const domain = scale.domain();
9529
+ const d0 = Number(domain[0]);
9530
+ const d1 = Number(domain[domain.length - 1]);
9531
+ if (!Number.isFinite(d0) || !Number.isFinite(d1)) return null;
9532
+ if (typeof step === "number") {
9533
+ if (!Number.isFinite(step) || step <= 0) return null;
9534
+ const start = Math.ceil(d0 / step - 1e-9) * step;
9535
+ const count = Math.floor((d1 + step * 1e-9 - start) / step) + 1;
9536
+ if (!Number.isFinite(start) || count > 100) return null;
9537
+ return Array.from(
9538
+ { length: Math.max(0, count) },
9539
+ (_, k) => Number((start + k * step).toPrecision(12))
9540
+ );
9541
+ }
9542
+ const utc = scaleType === "utc";
9543
+ const intervals = {
9544
+ year: utc ? utcYear : timeYear,
9545
+ quarter: utc ? utcMonth : timeMonth,
9546
+ month: utc ? utcMonth : timeMonth,
9547
+ week: utc ? utcWeek : timeWeek,
9548
+ day: utc ? utcDay : timeDay,
9549
+ hour: utc ? utcHour : timeHour,
9550
+ minute: utc ? utcMinute : timeMinute
9551
+ };
9552
+ const interval = intervals[step.interval]?.every(
9553
+ (step.step ?? 1) * (step.interval === "quarter" ? 3 : 1)
9554
+ );
9555
+ if (!interval) return null;
9556
+ const values = [];
9557
+ for (let date = interval.ceil(new Date(d0)); +date <= d1; date = interval.offset(date, 1)) {
9558
+ values.push(date);
9559
+ if (values.length > 100) return null;
9560
+ }
9561
+ return values;
9562
+ }
9563
+
9564
+ // src/layout/axes/ticks.ts
9565
+ function resolveStepTicks(resolvedScale) {
9566
+ const config = resolvedScale.channel.axis;
9567
+ if (!config || config.tickStep === void 0 || resolvedScale.type === "sequential") return null;
9568
+ const scale = resolvedScale.scale;
9569
+ if (!("ticks" in scale) || !("invert" in scale)) return null;
9570
+ const values = stepTicks(scale, config.tickStep, resolvedScale.type);
9571
+ return values === null ? null : resolveExplicitTicks(values, resolvedScale);
9572
+ }
9357
9573
  var Y_PX_PER_TICK = {
9358
9574
  full: 40,
9359
9575
  reduced: 70,
@@ -9399,12 +9615,13 @@ var TEMPORAL_SCALE_TYPES = /* @__PURE__ */ new Set(["time", "utc"]);
9399
9615
  function formatTickLabel(value, resolvedScale, compact = false, tickContext) {
9400
9616
  const axisConfig = resolvedScale.channel.axis || void 0;
9401
9617
  const formatStr = axisConfig?.format;
9618
+ const prefix = axisConfig?.labelPrefix ?? "";
9402
9619
  const suffix = axisConfig?.labelSuffix ?? "";
9403
9620
  if (TEMPORAL_SCALE_TYPES.has(resolvedScale.type)) {
9404
9621
  const temporalFmt = buildTemporalFormatter2(formatStr);
9405
- if (temporalFmt) return temporalFmt(value) + suffix;
9622
+ if (temporalFmt) return prefix + temporalFmt(value) + suffix;
9406
9623
  const useUtc = resolvedScale.type === "utc";
9407
- return formatDate2(value, void 0, void 0, useUtc, compact) + suffix;
9624
+ return prefix + formatDate2(value, void 0, void 0, useUtc, compact) + suffix;
9408
9625
  }
9409
9626
  if (NUMERIC_SCALE_TYPES.has(resolvedScale.type)) {
9410
9627
  const num = value;
@@ -9415,7 +9632,7 @@ function formatTickLabel(value, resolvedScale, compact = false, tickContext) {
9415
9632
  stepReference: tickContext?.maxAbsTick
9416
9633
  };
9417
9634
  const fmt3 = resolveNumberFormatter2(formatStr, ctx);
9418
- if (fmt3) return fmt3(num) + suffix;
9635
+ if (fmt3) return prefix + fmt3(num) + suffix;
9419
9636
  }
9420
9637
  const fmt2 = resolveFieldFormatter({
9421
9638
  channelFormat: resolvedScale.channel.format,
@@ -9425,9 +9642,9 @@ function formatTickLabel(value, resolvedScale, compact = false, tickContext) {
9425
9642
  stepReference: tickContext?.maxAbsTick
9426
9643
  }
9427
9644
  });
9428
- return fmt2(num) + suffix;
9645
+ return prefix + fmt2(num) + suffix;
9429
9646
  }
9430
- return String(value) + suffix;
9647
+ return prefix + String(value) + suffix;
9431
9648
  }
9432
9649
  function computeTickContext(ticks) {
9433
9650
  if (ticks.length < 2) return void 0;
@@ -9550,7 +9767,7 @@ function categoricalTicks(resolvedScale, density, orientation = "horizontal", su
9550
9767
  const tick = {
9551
9768
  value,
9552
9769
  position: pos,
9553
- label: value
9770
+ label: formatTickLabel(value, resolvedScale)
9554
9771
  };
9555
9772
  if (subtitleMap) {
9556
9773
  const subtitle = subtitleMap.get(value);
@@ -9926,7 +10143,7 @@ function isConditionalValueDef(def) {
9926
10143
  import { scaleBand } from "d3-scale";
9927
10144
 
9928
10145
  // src/layout/temporal-interval.ts
9929
- import { timeDay, timeMonth, timeWeek, utcDay, utcMonth, utcWeek } from "d3-time";
10146
+ import { timeDay as timeDay2, timeMonth as timeMonth2, timeWeek as timeWeek2, utcDay as utcDay2, utcMonth as utcMonth2, utcWeek as utcWeek2 } from "d3-time";
9930
10147
  var MONTHS = { month: 1, quarter: 3, year: 12 };
9931
10148
  var INFERABLE_UNITS = ["year", "quarter", "month", "week", "day"];
9932
10149
  var MIN_CALENDAR_DAY = 23 * 36e5;
@@ -9934,9 +10151,9 @@ function temporalDate(value) {
9934
10151
  return value instanceof Date ? value : new Date(String(value));
9935
10152
  }
9936
10153
  function calendarFor(mode) {
9937
- const day = mode === "utc" ? utcDay : timeDay;
9938
- const week = mode === "utc" ? utcWeek : timeWeek;
9939
- const month = mode === "utc" ? utcMonth : timeMonth;
10154
+ const day = mode === "utc" ? utcDay2 : timeDay2;
10155
+ const week = mode === "utc" ? utcWeek2 : timeWeek2;
10156
+ const month = mode === "utc" ? utcMonth2 : timeMonth2;
9940
10157
  const addMonths = (date, months) => {
9941
10158
  const start = month.floor(date);
9942
10159
  const target = month.offset(start, months);
@@ -10581,8 +10798,10 @@ var barRenderer = (spec, scales, chartArea, strategy, theme, containerWidth, lab
10581
10798
  return total > 0 ? Number(mark.data[valueField]) / total : 0;
10582
10799
  }) : valueField ? spec.data.map((r) => r[valueField]) : []
10583
10800
  });
10801
+ const color = spec.encoding.color;
10802
+ const targetMarks = spec.labels.highlightedOnly ? filterHighlighted(marks, spec.highlight, color && "field" in color ? color.field : void 0) : marks;
10584
10803
  const labels = computeBarLabels(
10585
- marks,
10804
+ targetMarks,
10586
10805
  chartArea,
10587
10806
  spec.labels.density,
10588
10807
  labelFormatter,
@@ -10602,7 +10821,7 @@ var barRenderer = (spec, scales, chartArea, strategy, theme, containerWidth, lab
10602
10821
  measureText: spec.labels.placement ? measureText : void 0
10603
10822
  }
10604
10823
  );
10605
- const labelMarks = spec.labels.placement ? filterByDensity(marks, spec.labels.density) : marks;
10824
+ const labelMarks = filterByDensity(targetMarks, spec.labels.density);
10606
10825
  for (let i = 0; i < labelMarks.length && i < labels.length; i++) {
10607
10826
  labelMarks[i].label = labels[i];
10608
10827
  }
@@ -10955,7 +11174,7 @@ var binnedBarRenderer = (spec, scales, chartArea, strategy, theme) => computeBin
10955
11174
 
10956
11175
  // src/charts/calendar/compute.ts
10957
11176
  import { defaultNumberFormatter as defaultNumberFormatter3, formatDate as formatDate3 } from "@opendata-ai/openchart-core";
10958
- import { utcDay as utcDay2, utcMonday, utcSunday } from "d3-time";
11177
+ import { utcDay as utcDay3, utcMonday, utcSunday } from "d3-time";
10959
11178
  var MIN_CELL_SIZE = 7;
10960
11179
  var MAX_STEP = 20;
10961
11180
  var MIN_CELL_GAP = 2;
@@ -10986,7 +11205,7 @@ function parseUtcDay(value) {
10986
11205
  if (value == null) return null;
10987
11206
  const date = value instanceof Date ? value : new Date(value);
10988
11207
  if (Number.isNaN(date.getTime())) return null;
10989
- return utcDay2.floor(date);
11208
+ return utcDay3.floor(date);
10990
11209
  }
10991
11210
  function isoDayKey(day) {
10992
11211
  return day.toISOString().slice(0, 10);
@@ -11104,7 +11323,7 @@ function computeCalendarMarks(spec, scales, chartArea, theme) {
11104
11323
  aria: labelAria
11105
11324
  });
11106
11325
  }
11107
- for (const day of utcDay2.range(yearStart, yearEnd)) {
11326
+ for (const day of utcDay3.range(yearStart, yearEnd)) {
11108
11327
  const col = week.count(firstWeek, day);
11109
11328
  const row = weekdayRow(day, weekStart);
11110
11329
  const key = isoDayKey(day);
@@ -11164,6 +11383,10 @@ function applyStackSeams2(marks, theme) {
11164
11383
  }
11165
11384
  }
11166
11385
  var MIN_COLUMN_HEIGHT = 1;
11386
+ function columnStackMode(stack2) {
11387
+ if (stack2 === null || stack2 === false) return null;
11388
+ return stack2 === "normalize" || stack2 === "center" ? stack2 : "zero";
11389
+ }
11167
11390
  function computeColumnMarks(spec, scales, _chartArea, _strategy, theme, grouping) {
11168
11391
  const encoding = spec.encoding;
11169
11392
  const xChannel = encoding.x;
@@ -11204,8 +11427,8 @@ function computeColumnMarks(spec, scales, _chartArea, _strategy, theme, grouping
11204
11427
  const categoryGroups = groupByField(spec.data, xChannel.field);
11205
11428
  const needsStacking = grouping?.multipleRows || yChannel.stack === "normalize" || yChannel.stack === "center" || Array.from(categoryGroups.values()).some((rows) => rows.length > 1);
11206
11429
  if (needsStacking) {
11207
- const stackEnabled = yChannel.stack !== null && yChannel.stack !== false;
11208
- if (!stackEnabled) {
11430
+ const stackMode = columnStackMode(yChannel.stack);
11431
+ if (stackMode === null) {
11209
11432
  marks = computeGroupedColumns(
11210
11433
  measuredData,
11211
11434
  xChannel.field,
@@ -11219,7 +11442,6 @@ function computeColumnMarks(spec, scales, _chartArea, _strategy, theme, grouping
11219
11442
  grouping?.order
11220
11443
  );
11221
11444
  } else {
11222
- const stackMode = yChannel.stack === "normalize" ? "normalize" : yChannel.stack === "center" ? "center" : "zero";
11223
11445
  marks = computeStackedColumns(
11224
11446
  measuredData,
11225
11447
  xChannel.field,
@@ -11641,8 +11863,10 @@ var columnRenderer = (spec, scales, chartArea, strategy, theme, _containerWidth,
11641
11863
  return total > 0 ? Number(mark.data[valueField]) / total : 0;
11642
11864
  }) : valueField ? spec.data.map((r) => r[valueField]) : []
11643
11865
  });
11866
+ const color = spec.encoding.color;
11867
+ const targetMarks = spec.labels.highlightedOnly ? filterHighlighted(marks, spec.highlight, color && "field" in color ? color.field : void 0) : marks;
11644
11868
  const labels = computeColumnLabels(
11645
- marks,
11869
+ targetMarks,
11646
11870
  chartArea,
11647
11871
  spec.labels.density,
11648
11872
  labelFormatter,
@@ -11662,7 +11886,7 @@ var columnRenderer = (spec, scales, chartArea, strategy, theme, _containerWidth,
11662
11886
  measureText: spec.labels.placement ? measureText : void 0
11663
11887
  }
11664
11888
  );
11665
- const labelMarks = spec.labels.placement ? filterByDensity(marks, spec.labels.density) : marks;
11889
+ const labelMarks = filterByDensity(targetMarks, spec.labels.density);
11666
11890
  for (let i = 0; i < labelMarks.length && i < labels.length; i++) {
11667
11891
  labelMarks[i].label = labels[i];
11668
11892
  }
@@ -12889,6 +13113,9 @@ var parliamentRenderer = (spec, scales, chartArea, strategy, theme) => {
12889
13113
  return computeParliamentMarks(spec, scales, chartArea, strategy, theme);
12890
13114
  };
12891
13115
 
13116
+ // src/charts/pie/index.ts
13117
+ import { resolveMeasurer } from "@opendata-ai/openchart-core";
13118
+
12892
13119
  // src/charts/pie/compute.ts
12893
13120
  import {
12894
13121
  CATEGORICAL_FILL_PALETTE,
@@ -12953,7 +13180,7 @@ function computeSweepBounds(startAngle, endAngle) {
12953
13180
  maxY: Math.max(...ys)
12954
13181
  };
12955
13182
  }
12956
- function computePieMarks(spec, scales, chartArea, _strategy, isDonut = false, theme) {
13183
+ function computePieMarks(spec, scales, chartArea, _strategy, innerRadiusSpec = 0, theme, leftLabelReserve = 0, rightLabelReserve = leftLabelReserve) {
12957
13184
  const palette = theme?.colors.categoricalFill ?? DEFAULT_PALETTE;
12958
13185
  const sliceStroke = resolveKnockoutColor(theme);
12959
13186
  const encoding = spec.encoding;
@@ -13003,9 +13230,20 @@ function computePieMarks(spec, scales, chartArea, _strategy, isDonut = false, th
13003
13230
  const sweepBounds = computeSweepBounds(startAngle, endAngle);
13004
13231
  const sweepWidth = sweepBounds.maxX - sweepBounds.minX;
13005
13232
  const sweepHeight = sweepBounds.maxY - sweepBounds.minY;
13006
- const outerRadius = Math.min(chartArea.width / sweepWidth, chartArea.height / sweepHeight) * 0.85;
13007
- const innerRadius = isDonut ? outerRadius * 0.6 : 0;
13008
- const centerX = chartArea.x + chartArea.width / 2 - (sweepBounds.minX + sweepBounds.maxX) / 2 * outerRadius;
13233
+ const partialSweep = Math.abs(endAngle - startAngle) < Math.PI * 2;
13234
+ const maxReserve = chartArea.width * (partialSweep ? 0.25 : 0.5);
13235
+ const leftReserve = spec.labels.density === "none" ? 0 : Math.min(leftLabelReserve, maxReserve);
13236
+ const rightReserve = spec.labels.density === "none" ? 0 : Math.min(rightLabelReserve, maxReserve);
13237
+ const availableWidth = chartArea.width - leftReserve - rightReserve;
13238
+ const unreservedOuter = Math.min(chartArea.width / sweepWidth, chartArea.height / sweepHeight) * 0.85;
13239
+ const outerRadius = Math.min(availableWidth / sweepWidth, chartArea.height / sweepHeight) * 0.85;
13240
+ const innerRadius = innerRadiusSpec <= 0 ? 0 : innerRadiusSpec < 1 ? outerRadius * innerRadiusSpec : Math.min(innerRadiusSpec * (outerRadius / unreservedOuter), outerRadius * 0.95);
13241
+ const centeredX2 = chartArea.x + chartArea.width / 2 - (sweepBounds.minX + sweepBounds.maxX) / 2 * outerRadius;
13242
+ const columnLeft = centeredX2 + sweepBounds.minX * outerRadius - leftReserve;
13243
+ const columnRight = centeredX2 + sweepBounds.maxX * outerRadius + rightReserve;
13244
+ const minShift = chartArea.x - columnLeft;
13245
+ const maxShift = chartArea.x + chartArea.width - columnRight;
13246
+ const centerX = centeredX2 + Math.max(minShift, Math.min(0, maxShift));
13009
13247
  const centerY = chartArea.y + chartArea.height / 2 - (sweepBounds.minY + sweepBounds.maxY) / 2 * outerRadius;
13010
13248
  const arcGenerator = d3Arc().innerRadius(innerRadius).outerRadius(outerRadius);
13011
13249
  const marks = [];
@@ -13076,6 +13314,10 @@ import { estimateTextWidth as estimateTextWidth9, resolveCollisions as resolveCo
13076
13314
  var LABEL_FONT_SIZE5 = 11;
13077
13315
  var LABEL_FONT_WEIGHT5 = 500;
13078
13316
  var LEADER_LINE_OFFSET = 12;
13317
+ function pieLabelReserve(texts, fontSize) {
13318
+ if (texts.length === 0) return 0;
13319
+ return Math.max(...texts.map((text) => estimateTextWidth9(text, fontSize))) + LEADER_LINE_OFFSET + 8;
13320
+ }
13079
13321
  function computePieLabels(marks, _chartArea, density = "auto", _textFill = "#333333", options = {}) {
13080
13322
  const fontFamily = options.fontFamily ?? "system-ui, -apple-system, sans-serif";
13081
13323
  const formatValue3 = options.formatValue;
@@ -13099,7 +13341,7 @@ function computePieLabels(marks, _chartArea, density = "auto", _textFill = "#333
13099
13341
  const rawValueText = openParen > firstColon ? ariaLabel.slice(firstColon + 1, openParen).trim() : "";
13100
13342
  const rawValue = Number(rawValueText);
13101
13343
  const valueText = formatValue3 && Number.isFinite(rawValue) ? formatValue3(rawValue) : percentText;
13102
- const labelText = valueText ? `${sliceName} ${valueText}` : sliceName;
13344
+ const labelText = valueText ? `${sliceName} ${options.prefix ?? ""}${valueText}${options.suffix ?? ""}` : sliceName;
13103
13345
  const textWidth2 = estimateTextWidth9(labelText, LABEL_FONT_SIZE5, LABEL_FONT_WEIGHT5);
13104
13346
  const textHeight = LABEL_FONT_SIZE5 * 1.2;
13105
13347
  const midAngle = (mark.startAngle + mark.endAngle) / 2;
@@ -13109,7 +13351,7 @@ function computePieLabels(marks, _chartArea, density = "auto", _textFill = "#333
13109
13351
  const isRight = Math.sin(midAngle) > 0;
13110
13352
  candidates.push({
13111
13353
  text: labelText,
13112
- anchorX: isRight ? labelX : labelX - textWidth2,
13354
+ anchorX: labelX,
13113
13355
  anchorY: labelY - textHeight / 2,
13114
13356
  width: textWidth2,
13115
13357
  height: textHeight,
@@ -13144,7 +13386,16 @@ function computePieLabels(marks, _chartArea, density = "auto", _textFill = "#333
13144
13386
  ...c.index !== void 0 ? { index: c.index } : {}
13145
13387
  }));
13146
13388
  } else {
13147
- resolved = resolveCollisions4(candidates);
13389
+ const boxes2 = candidates.map((candidate) => {
13390
+ const boxLeft = candidate.style.textAnchor === "end" ? candidate.anchorX - candidate.width : candidate.anchorX;
13391
+ return { ...candidate, anchorX: boxLeft };
13392
+ });
13393
+ resolved = resolveCollisions4(boxes2);
13394
+ for (const label of resolved) {
13395
+ if (label.style.textAnchor === "end") {
13396
+ label.x += estimateTextWidth9(label.text, LABEL_FONT_SIZE5, LABEL_FONT_WEIGHT5);
13397
+ }
13398
+ }
13148
13399
  }
13149
13400
  for (let i = 0; i < resolved.length; i++) {
13150
13401
  const label = resolved[i];
@@ -13164,25 +13415,82 @@ function computePieLabels(marks, _chartArea, density = "auto", _textFill = "#333
13164
13415
  }
13165
13416
 
13166
13417
  // src/charts/pie/index.ts
13418
+ function pieMarksWithLabels(spec, scales, chartArea, strategy, theme) {
13419
+ const options = pieLabelOptions(spec, theme);
13420
+ const innerRadius = spec.markDef.innerRadius ?? 0;
13421
+ let marks = computePieMarks(spec, scales, chartArea, strategy, innerRadius, theme);
13422
+ if (spec.labels.density !== "none") {
13423
+ const leftTexts = [];
13424
+ const rightTexts = [];
13425
+ for (const label of computePieLabels(marks, chartArea, "all", theme.colors.text, options)) {
13426
+ const mark = label.index !== void 0 ? marks[label.index] : void 0;
13427
+ if (!mark) continue;
13428
+ const isRight = Math.sin((mark.startAngle + mark.endAngle) / 2) > 0;
13429
+ (isRight ? rightTexts : leftTexts).push(label.text);
13430
+ }
13431
+ const fitted = computePieMarks(
13432
+ spec,
13433
+ scales,
13434
+ chartArea,
13435
+ strategy,
13436
+ innerRadius,
13437
+ theme,
13438
+ pieLabelReserve(leftTexts, 11),
13439
+ pieLabelReserve(rightTexts, 11)
13440
+ );
13441
+ if (fitted[0] && fitted[0].outerRadius < 0.15 * Math.min(chartArea.width, chartArea.height)) {
13442
+ return marks;
13443
+ }
13444
+ marks = fitted;
13445
+ }
13446
+ const labels = computePieLabels(
13447
+ marks,
13448
+ chartArea,
13449
+ spec.labels.density,
13450
+ theme.colors.text,
13451
+ options
13452
+ );
13453
+ for (const label of labels) {
13454
+ if (label.index !== void 0 && marks[label.index]) marks[label.index].label = label;
13455
+ }
13456
+ return marks;
13457
+ }
13167
13458
  function pieLabelOptions(spec, theme) {
13459
+ const options = {
13460
+ fontFamily: theme.fonts.family,
13461
+ prefix: spec.labels.prefix,
13462
+ suffix: spec.labels.suffix
13463
+ };
13168
13464
  const valueChannel = spec.encoding.y ?? spec.encoding.x;
13169
13465
  const valueField = valueChannel && "field" in valueChannel ? valueChannel.field : void 0;
13170
- if (!spec.labels.format) return { fontFamily: theme.fonts.family };
13466
+ if (!spec.labels.format) return options;
13171
13467
  const formatter = resolveFieldFormatter({
13172
13468
  surfaceFormat: spec.labels.format,
13173
13469
  values: valueField ? spec.data.map((r) => r[valueField]) : []
13174
13470
  });
13175
- return { fontFamily: theme.fonts.family, formatValue: formatter };
13471
+ return { ...options, formatValue: formatter };
13176
13472
  }
13177
- function centerLabelMarks(spec, marks, theme) {
13473
+ function centerLabelMarks(spec, marks, theme, measureText) {
13178
13474
  const config = spec.markDef.centerLabel;
13179
13475
  if (!config || marks.length === 0) return [];
13180
13476
  const text = typeof config === "string" ? config : config.text;
13181
13477
  if (!text) return [];
13182
- const subtitle = typeof config === "string" ? void 0 : config.subtitle;
13478
+ let subtitle = typeof config === "string" ? void 0 : config.subtitle;
13183
13479
  const { center } = marks[0];
13184
- const valueSize = theme.fonts.sizes.metricValue;
13480
+ const measure = resolveMeasurer(measureText);
13481
+ const availableWidth = 2 * marks[0].innerRadius * 0.8;
13482
+ let valueSize = theme.fonts.sizes.metricValue;
13185
13483
  const captionSize = theme.fonts.sizes.small;
13484
+ const valueWidth = measure(text, valueSize, theme.fonts.weights.semibold).width;
13485
+ if (valueWidth > availableWidth) {
13486
+ if (measure(text, 11, theme.fonts.weights.semibold).width > availableWidth) return [];
13487
+ valueSize = Math.max(11, Math.floor(valueSize * availableWidth / valueWidth));
13488
+ if (measure(text, valueSize, theme.fonts.weights.semibold).width > availableWidth)
13489
+ valueSize = 11;
13490
+ }
13491
+ if (subtitle && measure(subtitle, captionSize, theme.fonts.weights.normal).width > availableWidth) {
13492
+ subtitle = void 0;
13493
+ }
13186
13494
  const valueY = subtitle ? center.y - captionSize * 0.6 : center.y;
13187
13495
  const out = [
13188
13496
  {
@@ -13221,32 +13529,11 @@ function centerLabelMarks(spec, marks, theme) {
13221
13529
  return out;
13222
13530
  }
13223
13531
  var pieRenderer = (spec, scales, chartArea, strategy, theme) => {
13224
- const marks = computePieMarks(spec, scales, chartArea, strategy, false, theme);
13225
- const labels = computePieLabels(
13226
- marks,
13227
- chartArea,
13228
- spec.labels.density,
13229
- theme.colors.text,
13230
- pieLabelOptions(spec, theme)
13231
- );
13232
- for (const label of labels) {
13233
- if (label.index !== void 0 && marks[label.index]) marks[label.index].label = label;
13234
- }
13235
- return marks;
13532
+ return pieMarksWithLabels(spec, scales, chartArea, strategy, theme);
13236
13533
  };
13237
- var donutRenderer = (spec, scales, chartArea, strategy, theme) => {
13238
- const marks = computePieMarks(spec, scales, chartArea, strategy, true, theme);
13239
- const labels = computePieLabels(
13240
- marks,
13241
- chartArea,
13242
- spec.labels.density,
13243
- theme.colors.text,
13244
- pieLabelOptions(spec, theme)
13245
- );
13246
- for (const label of labels) {
13247
- if (label.index !== void 0 && marks[label.index]) marks[label.index].label = label;
13248
- }
13249
- return [...marks, ...centerLabelMarks(spec, marks, theme)];
13534
+ var donutRenderer = (spec, scales, chartArea, strategy, theme, _containerWidth, _labelPlan, measureText) => {
13535
+ const marks = pieMarksWithLabels(spec, scales, chartArea, strategy, theme);
13536
+ return [...marks, ...centerLabelMarks(spec, marks, theme, measureText)];
13250
13537
  };
13251
13538
 
13252
13539
  // src/charts/range/compute.ts
@@ -14845,6 +15132,23 @@ function computeContinuousLegendContent(spec, theme, availableWidth) {
14845
15132
  return computeContinuousLegendContentForChannel(values, colorEnc, theme, availableWidth);
14846
15133
  }
14847
15134
 
15135
+ // src/layout/color-domain.ts
15136
+ function completeColorDomain(authored, observed) {
15137
+ return [...new Set([...authored, ...observed].map(String))];
15138
+ }
15139
+
15140
+ // src/layout/domain-ends.ts
15141
+ function applyDomainEnds(fitted, scale) {
15142
+ if (scale?.domain || scale?.domainMin === void 0 && scale?.domainMax === void 0)
15143
+ return fitted;
15144
+ const min4 = scale.domainMin ?? fitted[0];
15145
+ const max4 = scale.domainMax ?? fitted[1];
15146
+ if (min4 < max4) return [min4, max4];
15147
+ if (scale.domainMin === void 0) return [max4 - Math.max(Math.abs(max4) * 0.1, 1), max4];
15148
+ if (scale.domainMax === void 0) return [min4, min4 + Math.max(Math.abs(min4) * 0.1, 1)];
15149
+ return [min4, max4];
15150
+ }
15151
+
14848
15152
  // src/layout/scales.ts
14849
15153
  function numericFieldValues2(data, field) {
14850
15154
  const result = [];
@@ -14928,6 +15232,18 @@ function buildUtcScale(channel, data, rangeStart, rangeEnd) {
14928
15232
  applyContinuousConfig(scale, channel);
14929
15233
  return { scale, type: "utc", channel };
14930
15234
  }
15235
+ function applyQuantitativeEnds(scale, channel) {
15236
+ const config = channel.scale;
15237
+ if (config?.domain || config?.domainMin === void 0 && config?.domainMax === void 0)
15238
+ return;
15239
+ const [lo, hi] = scale.domain();
15240
+ scale.domain(applyDomainEnds([lo, hi], config));
15241
+ if (config.nice !== false) {
15242
+ scale.nice();
15243
+ const [niceLo, niceHi] = scale.domain();
15244
+ scale.domain(applyDomainEnds([niceLo, niceHi], config));
15245
+ }
15246
+ }
14931
15247
  function buildLinearScale(channel, data, rangeStart, rangeEnd) {
14932
15248
  const values = numericFieldValues2(data, channel.field);
14933
15249
  let domainMin;
@@ -14955,6 +15271,7 @@ function buildLinearScale(channel, data, rangeStart, rangeEnd) {
14955
15271
  }
14956
15272
  }
14957
15273
  }
15274
+ applyQuantitativeEnds(scale, channel);
14958
15275
  applyContinuousConfig(scale, channel);
14959
15276
  return { scale, type: "linear", channel };
14960
15277
  }
@@ -14969,6 +15286,7 @@ function buildLogScale(channel, data, rangeStart, rangeEnd) {
14969
15286
  if (!channel.scale?.domain && channel.scale?.nice !== false) {
14970
15287
  scale.nice();
14971
15288
  }
15289
+ applyQuantitativeEnds(scale, channel);
14972
15290
  applyContinuousConfig(scale, channel);
14973
15291
  return { scale, type: "log", channel };
14974
15292
  }
@@ -14993,6 +15311,7 @@ function buildPowScale(channel, data, rangeStart, rangeEnd) {
14993
15311
  if (!channel.scale?.domain && channel.scale?.nice !== false) {
14994
15312
  scale.nice();
14995
15313
  }
15314
+ applyQuantitativeEnds(scale, channel);
14996
15315
  applyContinuousConfig(scale, channel);
14997
15316
  return { scale, type: "pow", channel };
14998
15317
  }
@@ -15014,6 +15333,7 @@ function buildSqrtScale(channel, data, rangeStart, rangeEnd) {
15014
15333
  if (!channel.scale?.domain && channel.scale?.nice !== false) {
15015
15334
  scale.nice();
15016
15335
  }
15336
+ applyQuantitativeEnds(scale, channel);
15017
15337
  applyContinuousConfig(scale, channel);
15018
15338
  return { scale, type: "sqrt", channel };
15019
15339
  }
@@ -15038,6 +15358,7 @@ function buildSymlogScale(channel, data, rangeStart, rangeEnd) {
15038
15358
  if (!channel.scale?.domain && channel.scale?.nice !== false) {
15039
15359
  scale.nice();
15040
15360
  }
15361
+ applyQuantitativeEnds(scale, channel);
15041
15362
  applyContinuousConfig(scale, channel);
15042
15363
  return { scale, type: "symlog", channel };
15043
15364
  }
@@ -15114,7 +15435,7 @@ function buildPointScale(channel, data, rangeStart, rangeEnd, defaultPadding = 0
15114
15435
  }
15115
15436
  function buildOrdinalColorScale(channel, data, palette) {
15116
15437
  const explicitDomain = channel.scale?.domain;
15117
- const values = explicitDomain ? explicitDomain.map(String) : applyCategoricalSort(uniqueFieldStrings2(data, channel.field), channel.sort);
15438
+ const values = explicitDomain ? completeColorDomain(explicitDomain, uniqueFieldStrings2(data, channel.field)) : applyCategoricalSort(uniqueFieldStrings2(data, channel.field), channel.sort);
15118
15439
  const explicitRange = channel.scale?.range;
15119
15440
  const colors = explicitRange ?? palette;
15120
15441
  const scale = scaleOrdinal().domain(values).range(colors);
@@ -15255,7 +15576,11 @@ function computeScales(spec, chartArea, data) {
15255
15576
  const axis = existingAxis === false || existingAxis?.format ? existingAxis : { ...typeof existingAxis === "object" ? existingAxis : {}, format: ".0%" };
15256
15577
  xChannel = {
15257
15578
  ...encoding.x,
15258
- scale: { ...encoding.x.scale, domain: [0, 1], nice: false },
15579
+ scale: {
15580
+ ...encoding.x.scale,
15581
+ domain: applyDomainEnds([0, 1], encoding.x.scale),
15582
+ nice: false
15583
+ },
15259
15584
  axis
15260
15585
  };
15261
15586
  } else if (encoding.x.stack === "center") {
@@ -15277,7 +15602,11 @@ function computeScales(spec, chartArea, data) {
15277
15602
  const half = maxSum / 2;
15278
15603
  xChannel = {
15279
15604
  ...encoding.x,
15280
- scale: { ...encoding.x.scale, domain: [-half, half], zero: true }
15605
+ scale: {
15606
+ ...encoding.x.scale,
15607
+ domain: applyDomainEnds([-half, half], encoding.x.scale),
15608
+ zero: true
15609
+ }
15281
15610
  };
15282
15611
  }
15283
15612
  } else {
@@ -15357,7 +15686,7 @@ function computeScales(spec, chartArea, data) {
15357
15686
  ...encoding.y,
15358
15687
  scale: {
15359
15688
  ...encoding.y.scale,
15360
- domain: encoding.y.scale?.domain ?? [lower, upper],
15689
+ domain: encoding.y.scale?.domain ?? applyDomainEnds([lower, upper], encoding.y.scale),
15361
15690
  ...stackProp === "normalize" ? { nice: false } : {}
15362
15691
  },
15363
15692
  ...stackProp === "normalize" ? {
@@ -15371,7 +15700,11 @@ function computeScales(spec, chartArea, data) {
15371
15700
  const axis = existingAxis === false || existingAxis?.format ? existingAxis : { ...typeof existingAxis === "object" ? existingAxis : {}, format: ".0%" };
15372
15701
  yChannel = {
15373
15702
  ...encoding.y,
15374
- scale: { ...encoding.y.scale, domain: [0, 1], nice: false },
15703
+ scale: {
15704
+ ...encoding.y.scale,
15705
+ domain: applyDomainEnds([0, 1], encoding.y.scale),
15706
+ nice: false
15707
+ },
15375
15708
  axis
15376
15709
  };
15377
15710
  } else if (encoding.y.stack === "center") {
@@ -15393,7 +15726,11 @@ function computeScales(spec, chartArea, data) {
15393
15726
  const half = maxSum / 2;
15394
15727
  yChannel = {
15395
15728
  ...encoding.y,
15396
- scale: { ...encoding.y.scale, domain: [-half, half], zero: true }
15729
+ scale: {
15730
+ ...encoding.y.scale,
15731
+ domain: applyDomainEnds([-half, half], encoding.y.scale),
15732
+ zero: true
15733
+ }
15397
15734
  };
15398
15735
  }
15399
15736
  } else {
@@ -15531,13 +15868,14 @@ function endpointFormatter(spec, displayedValues) {
15531
15868
  const axisFormat = axis && typeof axis === "object" ? axis.format : void 0;
15532
15869
  const explicit = config?.format || axisFormat || spec.encoding.y?.format;
15533
15870
  const fallbackFormat = !explicit && maxAbs < 1e3 && !isYearContext(context) ? `,.${Math.round(-Math.log10(step))}f` : void 0;
15534
- return resolveFieldFormatter({
15871
+ const formatter = resolveFieldFormatter({
15535
15872
  surfaceFormat: config?.format || axisFormat || fallbackFormat,
15536
15873
  channelFormat: spec.encoding.y?.format,
15537
15874
  values: valueField ? spec.data.map((row) => row[valueField]) : [],
15538
15875
  // Raw-unit precision must not turn compact magnitudes into full integers.
15539
15876
  step: maxAbs < 1e3 ? step : void 0
15540
15877
  });
15878
+ return (value) => `${config?.prefix ?? ""}${formatter(value)}${config?.suffix ?? ""}`;
15541
15879
  }
15542
15880
 
15543
15881
  // src/endpoint-labels/source.ts
@@ -15682,7 +16020,7 @@ var FILL_MARKS = /* @__PURE__ */ new Set([
15682
16020
  "rect"
15683
16021
  ]);
15684
16022
  function mutedSeriesColor(theme) {
15685
- return theme.isDark ? ACHROMATIC_RAMP.fgFaint : "#d4d4d8";
16023
+ return theme.colors.muted;
15686
16024
  }
15687
16025
  function paletteFor(theme, markType) {
15688
16026
  return markType && FILL_MARKS.has(markType) ? theme.colors.categoricalFill : theme.colors.categorical;
@@ -15705,13 +16043,14 @@ function paletteOverflowWarnings(domainLength, theme, markType) {
15705
16043
  `[openchart] color encoding has ${domainLength} categories but the palette carries ${palette.length}; slots ${palette.length + 1}+ come from the extended ramp and are harder to tell apart. Bucket the tail, facet, or direct-label instead.`
15706
16044
  ];
15707
16045
  }
15708
- function categoricalColorsForDomain(domain, theme, highlight, markType) {
15709
- const palette = extendPalette(paletteFor(theme, markType), domain.length);
16046
+ function categoricalColorsForDomain(domain, theme, highlight, markType, explicitPalette) {
16047
+ const palette = explicitPalette?.length ? explicitPalette : extendPalette(paletteFor(theme, markType), domain.length);
15710
16048
  if (highlight && highlight.length > 0) {
15711
16049
  const highlightSet = new Set(highlight);
15712
16050
  const muted = mutedSeriesColor(theme);
15713
16051
  return domain.map((v, i) => highlightSet.has(v) ? palette[i % palette.length] : muted);
15714
16052
  }
16053
+ if (explicitPalette?.length) return explicitPalette;
15715
16054
  const strategy = theme.seriesStrategy ?? "palette";
15716
16055
  if (strategy !== "accent-neutral") return palette;
15717
16056
  const count = domain.length;
@@ -15722,8 +16061,22 @@ function categoricalColorsForDomain(domain, theme, highlight, markType) {
15722
16061
  }
15723
16062
  function applyColorScaleRange(scales, encoding, theme, highlight, markType) {
15724
16063
  if (!scales.color) return [];
15725
- const hasExplicitRange = !!(encoding.color && "field" in encoding.color && encoding.color.scale?.range?.length);
15726
- if (hasExplicitRange) return [];
16064
+ const explicitRange = encoding.color && "field" in encoding.color ? encoding.color.scale?.range : void 0;
16065
+ if (explicitRange?.length) {
16066
+ if (highlight?.length && scales.color.type === "ordinal") {
16067
+ const scale = scales.color.scale;
16068
+ scale.range(
16069
+ categoricalColorsForDomain(
16070
+ scale.domain(),
16071
+ theme,
16072
+ highlight,
16073
+ markType,
16074
+ explicitRange.map(String)
16075
+ )
16076
+ );
16077
+ }
16078
+ return [];
16079
+ }
15727
16080
  if (scales.color.type === "sequential") {
15728
16081
  const seqStops = Object.values(theme.colors.sequential)[0] ?? theme.colors.categorical;
15729
16082
  scales.color.scale.range([
@@ -15867,8 +16220,14 @@ function extractColorEntries(spec, theme) {
15867
16220
  const explicitDomain = colorEnc.scale?.domain;
15868
16221
  const explicitRange = colorEnc.scale?.range;
15869
16222
  const shape = swatchShapeForType(spec.markType);
15870
- const scaleDomain = explicitDomain ? explicitDomain.map(String) : applyCategoricalSort(dataValues, colorEnc.sort);
15871
- const rawDomainColors = explicitRange ?? categoricalColorsForDomain(scaleDomain, theme, spec.highlight, spec.markType);
16223
+ const scaleDomain = explicitDomain ? completeColorDomain(explicitDomain, dataValues) : applyCategoricalSort(dataValues, colorEnc.sort);
16224
+ const rawDomainColors = categoricalColorsForDomain(
16225
+ scaleDomain,
16226
+ theme,
16227
+ spec.highlight,
16228
+ spec.markType,
16229
+ explicitRange
16230
+ );
15872
16231
  const domainColors = isStrokeSeriesMark(spec.markType) ? rawDomainColors.map((c) => resolveSeriesStroke(spec, c, theme)) : rawDomainColors;
15873
16232
  const uniqueValues = explicitDomain ? [
15874
16233
  ...explicitDomain.filter((v) => dataValues.includes(v)),
@@ -16674,11 +17033,14 @@ function computeAxes(scales, chartArea, strategy, theme, measureText, dataContex
16674
17033
  const isContinuousX = scales.x.type !== "band" && scales.x.type !== "point" && scales.x.type !== "ordinal";
16675
17034
  const xTargetCount = isContinuousX ? targetTickCount(chartArea.width, xDensity, "x") : void 0;
16676
17035
  const mirrorTicks = dataContext?.mirrorXTicks;
17036
+ const steppedTicks = resolveStepTicks(scales.x);
16677
17037
  let allTicks;
16678
17038
  if (mirrorTicks) {
16679
17039
  allTicks = mirrorTicks;
16680
17040
  } else if (axisConfig?.values) {
16681
17041
  allTicks = resolveExplicitTicks(axisConfig.values, scales.x);
17042
+ } else if (steppedTicks !== null) {
17043
+ allTicks = steppedTicks;
16682
17044
  } else if (!isContinuousX) {
16683
17045
  allTicks = categoricalTicks(scales.x, xDensity, "horizontal");
16684
17046
  } else {
@@ -16715,7 +17077,7 @@ function computeAxes(scales, chartArea, strategy, theme, measureText, dataContex
16715
17077
  );
16716
17078
  bandStride = bandLabelStride(maxLabelWidth, tickAngle, fontSize, anchorSpacing);
16717
17079
  }
16718
- const hasExplicitValues = !!axisConfig?.values || !!mirrorTicks;
17080
+ const hasExplicitValues = !!axisConfig?.values || !!mirrorTicks || steppedTicks !== null;
16719
17081
  let ticks;
16720
17082
  if (hasExplicitValues) {
16721
17083
  ticks = allTicks;
@@ -16811,9 +17173,12 @@ function computeAxes(scales, chartArea, strategy, theme, measureText, dataContex
16811
17173
  const axisConfig = scales.y.channel.axis;
16812
17174
  const isContinuousY = scales.y.type !== "band" && scales.y.type !== "point" && scales.y.type !== "ordinal";
16813
17175
  const yTargetCount = isContinuousY ? targetTickCount(chartArea.height, yDensity, "y") : void 0;
17176
+ const steppedTicks = resolveStepTicks(scales.y);
16814
17177
  let allTicks;
16815
17178
  if (axisConfig?.values) {
16816
17179
  allTicks = resolveExplicitTicks(axisConfig.values, scales.y);
17180
+ } else if (steppedTicks !== null) {
17181
+ allTicks = steppedTicks;
16817
17182
  } else if (dataContext?.precomputedYTicks && dataContext.precomputedYTicks.length > 0 && isContinuousY) {
16818
17183
  allTicks = resolveExplicitTicks(dataContext.precomputedYTicks, scales.y);
16819
17184
  } else if (!isContinuousY) {
@@ -16828,7 +17193,7 @@ function computeAxes(scales, chartArea, strategy, theme, measureText, dataContex
16828
17193
  } else {
16829
17194
  allTicks = continuousTicks(scales.y, yDensity, yTargetCount);
16830
17195
  }
16831
- const shouldThinY = scales.y.type !== "band" && !axisConfig?.values && !dataContext?.precomputedYTicks?.length;
17196
+ const shouldThinY = scales.y.type !== "band" && !axisConfig?.values && steppedTicks === null && !dataContext?.precomputedYTicks?.length;
16832
17197
  let ticks;
16833
17198
  if (!shouldThinY) {
16834
17199
  ticks = allTicks;
@@ -17345,6 +17710,102 @@ function createFrame(ctx, measures, chrome) {
17345
17710
  return { spacing, effectiveHeight, reference, lane, place };
17346
17711
  }
17347
17712
 
17713
+ // src/design/annotation-diagnostic.ts
17714
+ function unplacedAnnotationDiagnostics(spec, layout) {
17715
+ return layout.unplacedAnnotations.map((index) => {
17716
+ const annotation = spec.annotations?.[index];
17717
+ const text = annotation?.type === "text" ? annotation.text : annotation?.label;
17718
+ const quote = text ? ` ("${text.slice(0, 40)}${text.length > 40 ? "\u2026" : ""}")` : "";
17719
+ return {
17720
+ code: "annotations.unplaced",
17721
+ path: `/annotations/${index}`,
17722
+ severity: "warning",
17723
+ status: "failed",
17724
+ origin: "author",
17725
+ viewport: layout.dimensions,
17726
+ message: `Annotation ${index + 1}${quote} is not drawn: its position is not on the chart's axes.`
17727
+ };
17728
+ });
17729
+ }
17730
+
17731
+ // src/design/domain-diagnostic.ts
17732
+ function zeroStack(spec, channel) {
17733
+ const mark = typeof spec.mark === "string" ? spec.mark : spec.mark.type;
17734
+ const stack2 = channel.stack;
17735
+ const color = spec.encoding.color;
17736
+ if (!color || !("field" in color) || color.type === "quantitative") return false;
17737
+ if (mark === "area") return stack2 !== false && stack2 !== null;
17738
+ const vertical = mark === "bar" && ["nominal", "ordinal", "temporal"].includes(spec.encoding.x?.type ?? "");
17739
+ return vertical && columnStackMode(stack2) === "zero";
17740
+ }
17741
+ function stackedValues(spec, channel) {
17742
+ const groups = /* @__PURE__ */ new Map();
17743
+ for (const row of spec.data) {
17744
+ const value = finiteNumber(row[channel.field]);
17745
+ if (value === void 0) continue;
17746
+ const key = String(row[spec.encoding.x?.field ?? ""]);
17747
+ const sums = groups.get(key) ?? [0, 0];
17748
+ sums[value < 0 ? 0 : 1] += value;
17749
+ groups.set(key, sums);
17750
+ }
17751
+ return [...groups.values()].flat();
17752
+ }
17753
+ function areaValues(spec, channel) {
17754
+ const x = spec.encoding.x;
17755
+ const color = spec.encoding.color;
17756
+ if (!x || !color || !("field" in color)) return [];
17757
+ const geometry2 = computeAreaStack(
17758
+ spec.data,
17759
+ x.field,
17760
+ channel.field,
17761
+ color.field,
17762
+ x.type,
17763
+ channel.stack
17764
+ );
17765
+ const groups = /* @__PURE__ */ new Map();
17766
+ for (const layer of geometry2.stackedData) {
17767
+ for (const point of layer) {
17768
+ const key = String(point.data.__x__);
17769
+ if (geometry2.missingBoundaries.has(key)) continue;
17770
+ const bounds2 = groups.get(key) ?? [0, 0];
17771
+ bounds2[0] = Math.min(bounds2[0], point[0], point[1]);
17772
+ bounds2[1] = Math.max(bounds2[1], point[0], point[1]);
17773
+ groups.set(key, bounds2);
17774
+ }
17775
+ }
17776
+ return [...groups.values()].flat();
17777
+ }
17778
+ function outsideDomainDiagnostics(spec, layout) {
17779
+ const diagnostics = [];
17780
+ for (const axis of ["x", "y"]) {
17781
+ const channel = spec.encoding[axis];
17782
+ const scale = channel?.scale;
17783
+ if (!channel || !scale || scale.clip || !["quantitative", "temporal"].includes(channel.type) || channel.stack === "normalize" || channel.stack === "center")
17784
+ continue;
17785
+ if (!scale.domain && scale.domainMin === void 0 && scale.domainMax === void 0) continue;
17786
+ const bounds2 = scale.domain ?? [scale.domainMin, scale.domainMax];
17787
+ const parse = channel.type === "temporal" ? (v) => Date.parse(String(v)) : finiteNumber;
17788
+ const lower = bounds2[0] === void 0 ? -Infinity : parse(bounds2[0]);
17789
+ const upper = bounds2[1] === void 0 ? Infinity : parse(bounds2[1]);
17790
+ if (lower === void 0 || upper === void 0) continue;
17791
+ const values = axis === "y" && zeroStack(spec, channel) ? (typeof spec.mark === "string" ? spec.mark : spec.mark.type) === "area" ? areaValues(spec, channel) : stackedValues(spec, channel) : spec.data.map((row) => parse(row[channel.field]));
17792
+ const count = values.filter(
17793
+ (value) => value !== void 0 && Number.isFinite(value) && (value < lower || value > upper)
17794
+ ).length;
17795
+ if (!count) continue;
17796
+ diagnostics.push({
17797
+ code: "data.outside-domain",
17798
+ path: `/encoding/${axis}/scale`,
17799
+ severity: "warning",
17800
+ status: "failed",
17801
+ origin: "author",
17802
+ viewport: layout.dimensions,
17803
+ message: `${count} ${count === 1 ? "observation falls" : "observations fall"} outside the ${axis} axis domain (${bounds2[0] ?? "auto"} to ${bounds2[1] ?? "auto"}).`
17804
+ });
17805
+ }
17806
+ return diagnostics;
17807
+ }
17808
+
17348
17809
  // src/design/identity.ts
17349
17810
  function observationKey(value) {
17350
17811
  if (typeof value === "string") return `string:${value}`;
@@ -17569,6 +18030,10 @@ function diagnoseChart(spec, layout) {
17569
18030
  ]
17570
18031
  };
17571
18032
  }
18033
+ diagnostics.push(
18034
+ ...outsideDomainDiagnostics(spec, layout),
18035
+ ...unplacedAnnotationDiagnostics(spec, layout)
18036
+ );
17572
18037
  return diagnostics;
17573
18038
  }
17574
18039
 
@@ -18220,7 +18685,7 @@ function resolveLayoutPlan(chartSpec, renderSpec, options, theme, strategy, wate
18220
18685
  const yLabelField = yAxisCfg?.labelField;
18221
18686
  let maxLabelWidth = 0;
18222
18687
  for (const row of renderSpec.data) {
18223
- const label = String(row[yField] ?? "");
18688
+ const label = `${yAxisCfg?.labelPrefix ?? ""}${String(row[yField] ?? "")}${yAxisCfg?.labelSuffix ?? ""}`;
18224
18689
  let w = measure(label, theme.fonts.sizes.axisTick, theme.fonts.weights.normal);
18225
18690
  if (yLabelField) {
18226
18691
  const subtitle = String(row[yLabelField] ?? "");
@@ -18320,6 +18785,10 @@ function resolveLayoutPlan(chartSpec, renderSpec, options, theme, strategy, wate
18320
18785
  const yTicksFor = (area3) => {
18321
18786
  const scales = computeScales(renderSpec, area3, renderSpec.data);
18322
18787
  if (!scales.y || !scaleSupportsTickCount(scales.y)) return null;
18788
+ const config = scales.y.channel.axis || void 0;
18789
+ if (config?.values) return resolveExplicitTicks(config.values, scales.y);
18790
+ const stepped = resolveStepTicks(scales.y);
18791
+ if (stepped !== null) return stepped;
18323
18792
  const axisTickCount = yAxisCfg?.tickCount;
18324
18793
  const effectiveCount = axisTickCount ?? targetTickCount(area3.height, "full", "y");
18325
18794
  return axisTickCount != null ? buildContinuousTicks(scales.y, effectiveCount) : buildDefaultYTicks(scales.y, effectiveCount);
@@ -18488,7 +18957,7 @@ function resolveLayoutPlan(chartSpec, renderSpec, options, theme, strategy, wate
18488
18957
  if (yTickValues.length > 0) {
18489
18958
  const scales = computeScales(renderSpec, finalArea, renderSpec.data);
18490
18959
  if (scales.y && scaleSupportsTickCount(scales.y)) {
18491
- const ticks = buildContinuousTicks(scales.y, yTickCount || 5);
18960
+ const ticks = resolveExplicitTicks(yTickValues, scales.y);
18492
18961
  let maxLabelWidth = 0;
18493
18962
  for (const t of ticks) {
18494
18963
  const w = measure(t.label, theme.fonts.sizes.axisTick, theme.fonts.weights.normal);
@@ -18527,7 +18996,7 @@ function resolveLayoutPlan(chartSpec, renderSpec, options, theme, strategy, wate
18527
18996
  if (yTickValues.length > 0) {
18528
18997
  const scales = computeScales(renderSpec, finalArea, renderSpec.data);
18529
18998
  if (scales.y && scaleSupportsTickCount(scales.y)) {
18530
- const ticks = buildContinuousTicks(scales.y, yTickCount || 5);
18999
+ const ticks = resolveExplicitTicks(yTickValues, scales.y);
18531
19000
  for (const t of ticks) {
18532
19001
  const w = measure(t.label, theme.fonts.sizes.axisTick, theme.fonts.weights.normal);
18533
19002
  if (w > estTickLabelWidth) estTickLabelWidth = w;
@@ -18951,6 +19420,11 @@ function resolveFormat(ch) {
18951
19420
  const ax = ch.axis || void 0;
18952
19421
  return ch.format ?? ax?.format;
18953
19422
  }
19423
+ function formatAxisValue(row, ch, formatters) {
19424
+ const axis = ch.axis && typeof ch.axis === "object" ? ch.axis : void 0;
19425
+ const text = formatValue2(row[ch.field], ch.type, getFormatter(formatters, ch));
19426
+ return `${axis?.labelPrefix ?? ""}${text}${axis?.labelSuffix ?? ""}`;
19427
+ }
18954
19428
  function cacheKey(ch) {
18955
19429
  const fmt2 = resolveFormat(ch);
18956
19430
  return fmt2 ? `${ch.field}::${ch.type}::${fmt2}` : `${ch.field}::${ch.type}`;
@@ -19039,11 +19513,7 @@ function buildFields(row, encoding, formatters, color, titleChannel) {
19039
19513
  (titleChannel === "y" ? skipped : fields).push({
19040
19514
  ...semanticField(encoding.y, encoding, "y", void 0, formatters),
19041
19515
  label: resolveLabel(encoding.y),
19042
- value: formatValue2(
19043
- row[encoding.y.field],
19044
- encoding.y.type,
19045
- getFormatter(formatters, encoding.y)
19046
- ),
19516
+ value: formatAxisValue(row, encoding.y, formatters),
19047
19517
  color: encoding.color ? void 0 : color
19048
19518
  });
19049
19519
  }
@@ -19051,11 +19521,7 @@ function buildFields(row, encoding, formatters, color, titleChannel) {
19051
19521
  (titleChannel === "x" ? skipped : fields).push({
19052
19522
  ...semanticField(encoding.x, encoding, "x", void 0, formatters),
19053
19523
  label: resolveLabel(encoding.x),
19054
- value: formatValue2(
19055
- row[encoding.x.field],
19056
- encoding.x.type,
19057
- getFormatter(formatters, encoding.x)
19058
- )
19524
+ value: formatAxisValue(row, encoding.x, formatters)
19059
19525
  });
19060
19526
  }
19061
19527
  if (encoding.size && "field" in encoding.size) {
@@ -20174,8 +20640,14 @@ function compileFaceted(chartSpec, renderSpec, facetChannel, facetDirection, the
20174
20640
  const yResolve = resolveConfig?.scale?.y ?? yDefault;
20175
20641
  const xResolve = resolveConfig?.scale?.x ?? xDefault;
20176
20642
  const fullScales = computeScales(panelSpec, chartArea, renderSpec.data);
20177
- const sharedXDomain = xResolve === "shared" && fullScales.x ? fullScales.x.scale.domain() : void 0;
20178
- const sharedYDomain = yResolve === "shared" && fullScales.y ? fullScales.y.scale.domain() : void 0;
20643
+ const sharedXDomain = xResolve === "shared" && fullScales.x ? panelEncoding.x?.type === "quantitative" ? applyDomainEnds(
20644
+ [Number(fullScales.x.scale.domain()[0]), Number(fullScales.x.scale.domain()[1])],
20645
+ panelEncoding.x.scale
20646
+ ) : fullScales.x.scale.domain() : void 0;
20647
+ const sharedYDomain = yResolve === "shared" && fullScales.y ? panelEncoding.y?.type === "quantitative" ? applyDomainEnds(
20648
+ [Number(fullScales.y.scale.domain()[0]), Number(fullScales.y.scale.domain()[1])],
20649
+ panelEncoding.y.scale
20650
+ ) : fullScales.y.scale.domain() : void 0;
20179
20651
  const sharedColorScale = (resolveConfig?.scale?.color ?? "shared") === "shared" ? computeChartScales({ ...panelSpec, data: renderSpec.data }, chartArea, theme, chartSpec).scales.color : void 0;
20180
20652
  const sizeDefaults = sizeScaleDefaultsFor(chartSpec.markType);
20181
20653
  const sizeChannel = panelEncoding.size;
@@ -20189,6 +20661,7 @@ function compileFaceted(chartSpec, renderSpec, facetChannel, facetDirection, the
20189
20661
  const renderer = getChartRenderer(rendererKey);
20190
20662
  const allMarks = [];
20191
20663
  const panelLayouts = [];
20664
+ const unplacedByPanel = [];
20192
20665
  const allFootnotes = [];
20193
20666
  const footnoteNumberBySpecIndex = /* @__PURE__ */ new Map();
20194
20667
  for (const gridPanel of grid.panels) {
@@ -20199,14 +20672,30 @@ function compileFaceted(chartSpec, renderSpec, facetChannel, facetDirection, the
20199
20672
  const xCh = panelEnc.x;
20200
20673
  panelEnc = {
20201
20674
  ...panelEnc,
20202
- x: { ...xCh, scale: { ...xCh.scale ?? {}, domain: sharedXDomain } }
20675
+ x: {
20676
+ ...xCh,
20677
+ scale: {
20678
+ ...xCh.scale ?? {},
20679
+ domainMin: void 0,
20680
+ domainMax: void 0,
20681
+ domain: sharedXDomain
20682
+ }
20683
+ }
20203
20684
  };
20204
20685
  }
20205
20686
  if (sharedYDomain && panelEnc.y) {
20206
20687
  const yCh = panelEnc.y;
20207
20688
  panelEnc = {
20208
20689
  ...panelEnc,
20209
- y: { ...yCh, scale: { ...yCh.scale ?? {}, domain: sharedYDomain } }
20690
+ y: {
20691
+ ...yCh,
20692
+ scale: {
20693
+ ...yCh.scale ?? {},
20694
+ domainMin: void 0,
20695
+ domainMax: void 0,
20696
+ domain: sharedYDomain
20697
+ }
20698
+ }
20210
20699
  };
20211
20700
  }
20212
20701
  if (sharedSizeDomain && sizeChannel) {
@@ -20282,7 +20771,10 @@ function compileFaceted(chartSpec, renderSpec, facetChannel, facetDirection, the
20282
20771
  seriesWarnings
20283
20772
  );
20284
20773
  const annotationMeasure = annotationMeasureFn(options.measureText);
20774
+ const panelUnplaced = /* @__PURE__ */ new Set();
20775
+ unplacedByPanel.push(panelUnplaced);
20285
20776
  let panelAnnotations = computeAnnotations(panelSpecWithDomains, {
20777
+ onUnplaced: (i) => panelUnplaced.add(i),
20286
20778
  scales: panelScales,
20287
20779
  chartArea: gridPanel.area,
20288
20780
  referenceContainer: gridPanel.referenceContainer,
@@ -20398,6 +20890,9 @@ function compileFaceted(chartSpec, renderSpec, facetChannel, facetDirection, the
20398
20890
  axes: { x: void 0, y: void 0 },
20399
20891
  marks: allMarks,
20400
20892
  annotations: [],
20893
+ unplacedAnnotations: [...unplacedByPanel[0] ?? []].filter(
20894
+ (i) => unplacedByPanel.every((panel) => panel.has(i))
20895
+ ),
20401
20896
  legend: finalLegend,
20402
20897
  // Facets share one color legend across the grid; the size channel isn't
20403
20898
  // supported in facet specs, so there is no second legend to carry.
@@ -21490,10 +21985,13 @@ function resolveCompileTheme(specTheme, options) {
21490
21985
  const theme = resolveTheme2(mergeThemeConfig2(specTheme, options.theme));
21491
21986
  return options.darkMode ? adaptTheme2(theme) : theme;
21492
21987
  }
21493
- function compileChartInternal(spec, optionsInput) {
21988
+ function compileChartInternal(spec, optionsInput, hideArcLabels = false) {
21494
21989
  const prepared = prepareChartSpec(spec, optionsInput);
21495
21990
  const { options } = prepared;
21496
21991
  let { chartSpec } = prepared;
21992
+ if (hideArcLabels && chartSpec.markType === "arc") {
21993
+ chartSpec = { ...chartSpec, labels: { ...chartSpec.labels, density: "none" } };
21994
+ }
21497
21995
  const theme = resolveCompileTheme(chartSpec.theme, options);
21498
21996
  const seriesWarnings = seriesIdentificationWarnings(chartSpec);
21499
21997
  const heightContext = heightContextResolver({
@@ -21542,6 +22040,9 @@ function compileChartInternal(spec, optionsInput) {
21542
22040
  theme,
21543
22041
  sizing
21544
22042
  });
22043
+ if (chartSpec.markType === "arc" && chartSpec.labels.density !== "none" && layout.marks.some((mark) => mark.type === "arc") && layout.marks.every((mark) => mark.type !== "arc" || mark.label === void 0)) {
22044
+ return compileChartInternal(spec, optionsInput, true);
22045
+ }
21545
22046
  emitSpecWarnings(seriesWarnings, options.onWarn);
21546
22047
  if (options.onDiagnostic) {
21547
22048
  const diagnosticSpec = {
@@ -21788,7 +22289,9 @@ function layoutSingleChart(input) {
21788
22289
  measureText: options.measureText
21789
22290
  });
21790
22291
  const annotationMeasure = annotationMeasureFn(options.measureText);
22292
+ const unplaced = [];
21791
22293
  let annotations = computeAnnotations(chartSpec, {
22294
+ onUnplaced: (i) => unplaced.push(i),
21792
22295
  scales,
21793
22296
  chartArea,
21794
22297
  strategy,
@@ -21893,6 +22396,7 @@ function layoutSingleChart(input) {
21893
22396
  marks,
21894
22397
  annotations,
21895
22398
  legend: finalLegend,
22399
+ unplacedAnnotations: unplaced,
21896
22400
  legends: allLegends,
21897
22401
  ...endpointLabels.entries.length > 0 ? { endpointLabels } : {},
21898
22402
  tooltipDescriptors,
@@ -22123,11 +22627,14 @@ function estimateYAxisLabelWidth(data, encoding, baseFontSize, measure) {
22123
22627
  const yField = yEnc.field;
22124
22628
  if (!yField) return 40;
22125
22629
  const m = measure ?? estimateTextWidth25;
22630
+ const axis = yEnc.axis || void 0;
22631
+ const prefix = axis?.labelPrefix ?? "";
22632
+ const suffix = axis?.labelSuffix ?? "";
22126
22633
  const yType = yEnc.type;
22127
22634
  if (yType === "nominal" || yType === "ordinal") {
22128
22635
  let maxWidth = 0;
22129
22636
  for (const row of data) {
22130
- const label = String(row[yField] ?? "");
22637
+ const label = prefix + String(row[yField] ?? "") + suffix;
22131
22638
  const w = m(label, baseFontSize, 400);
22132
22639
  if (w > maxWidth) maxWidth = w;
22133
22640
  }
@@ -22154,7 +22661,7 @@ function estimateYAxisLabelWidth(data, encoding, baseFontSize, measure) {
22154
22661
  );
22155
22662
  }
22156
22663
  const hasNeg = data.some((r) => Number(r[yField]) < 0);
22157
- const labelEst = (hasNeg ? "-" : "") + sampleLabel;
22664
+ const labelEst = prefix + (hasNeg ? "-" : "") + sampleLabel + suffix;
22158
22665
  return m(labelEst, baseFontSize, 400) + 10;
22159
22666
  }
22160
22667
  function compileLayerIndependent(leaves, layerSpec, options, compileChart2) {
@@ -22612,6 +23119,8 @@ function mergeEndpointColumns(columns, area3, rightReserve, leadingColumnX, colu
22612
23119
  }
22613
23120
  function withXDomain(leaf, domain) {
22614
23121
  if (!leaf.encoding?.x) return leaf;
23122
+ const scale = leaf.encoding.x.scale;
23123
+ const resolvedDomain = leaf.encoding.x.type === "quantitative" ? applyDomainEnds([Number(domain[0]), Number(domain[1])], scale) : domain;
22615
23124
  return {
22616
23125
  ...leaf,
22617
23126
  encoding: {
@@ -22620,7 +23129,9 @@ function withXDomain(leaf, domain) {
22620
23129
  ...leaf.encoding.x,
22621
23130
  scale: {
22622
23131
  ...leaf.encoding.x.scale,
22623
- domain
23132
+ domainMin: void 0,
23133
+ domainMax: void 0,
23134
+ domain: resolvedDomain
22624
23135
  }
22625
23136
  }
22626
23137
  }
@@ -22676,7 +23187,12 @@ function withUnionXDomain(leaf0, leaf1) {
22676
23187
  if (n < min4) min4 = n;
22677
23188
  if (n > max4) max4 = n;
22678
23189
  }
22679
- if (min4 <= max4) domain = [min4, max4];
23190
+ if (min4 <= max4) {
23191
+ const authored = [xEnc0?.scale, xEnc1?.scale].find(
23192
+ (scale) => scale?.domainMin !== void 0 || scale?.domainMax !== void 0
23193
+ );
23194
+ domain = applyDomainEnds([min4, max4], authored);
23195
+ }
22680
23196
  } else {
22681
23197
  const seen = /* @__PURE__ */ new Set();
22682
23198
  const categories = [];
@@ -22700,7 +23216,10 @@ function alignYDomains(leaf0, leaf1) {
22700
23216
  const yEnc1 = leaf1.encoding?.y;
22701
23217
  if (!yEnc0 || !yEnc1) return void 0;
22702
23218
  if (yEnc0.type !== "quantitative" || yEnc1.type !== "quantitative") return void 0;
22703
- if (yEnc0.scale?.domain || yEnc1.scale?.domain) return void 0;
23219
+ if ([yEnc0.scale, yEnc1.scale].some(
23220
+ (scale) => scale?.domain || scale?.domainMin !== void 0 || scale?.domainMax !== void 0
23221
+ ))
23222
+ return void 0;
22704
23223
  const hasStackedY = (leaf) => {
22705
23224
  if (!leaf.encoding?.color) return false;
22706
23225
  const mark = typeof leaf.mark === "string" ? leaf.mark : leaf.mark.type;
@@ -22797,7 +23316,13 @@ function computeSharedDomains(leaves, options) {
22797
23316
  }
22798
23317
  if (!prepared.every((spec) => spec.encoding[channel]?.type === "quantitative")) continue;
22799
23318
  const values = domains.flatMap((scales) => (scales[channel]?.scale.domain() ?? []).map(Number)).filter(Number.isFinite);
22800
- if (values.length) shared[channel] = [Math.min(...values), Math.max(...values)];
23319
+ if (values.length) {
23320
+ const authored = leaves.find((leaf) => {
23321
+ const scale = leaf.encoding[channel]?.scale;
23322
+ return scale?.domainMin !== void 0 || scale?.domainMax !== void 0;
23323
+ })?.encoding[channel]?.scale;
23324
+ shared[channel] = applyDomainEnds([Math.min(...values), Math.max(...values)], authored);
23325
+ }
22801
23326
  }
22802
23327
  return shared;
22803
23328
  }
@@ -22808,9 +23333,16 @@ function withSharedDomains(leaf, shared) {
22808
23333
  const domain = shared[channel];
22809
23334
  const ch = encoding[channel];
22810
23335
  if (!domain || !ch || ch.scale?.domain) continue;
23336
+ const authored = leaf.encoding[channel];
23337
+ const resolvedDomain = authored?.type === "quantitative" ? applyDomainEnds([Number(domain[0]), Number(domain[1])], authored.scale) : domain;
22811
23338
  encoding[channel] = {
22812
23339
  ...ch,
22813
- scale: { ...ch.scale ?? {}, domain }
23340
+ scale: {
23341
+ ...ch.scale ?? {},
23342
+ domainMin: void 0,
23343
+ domainMax: void 0,
23344
+ domain: resolvedDomain
23345
+ }
22814
23346
  };
22815
23347
  }
22816
23348
  return { ...leaf, encoding };
@@ -26353,7 +26885,7 @@ function streamingCanonicalAnchor(feature, projection, bounds2) {
26353
26885
  area: 0,
26354
26886
  winding: 0
26355
26887
  }));
26356
- let first, last, area3 = 0, invalid3 = false;
26888
+ let first, last, area3 = 0, invalid4 = false;
26357
26889
  const segment = (a, b) => {
26358
26890
  area3 += a.x * b.y - b.x * a.y;
26359
26891
  const dx = b.x - a.x, dy = b.y - a.y;
@@ -26391,7 +26923,7 @@ function streamingCanonicalAnchor(feature, projection, bounds2) {
26391
26923
  },
26392
26924
  point(x, y) {
26393
26925
  if (!Number.isFinite(x) || !Number.isFinite(y)) {
26394
- invalid3 = true;
26926
+ invalid4 = true;
26395
26927
  return;
26396
26928
  }
26397
26929
  const p = { x, y };
@@ -26403,7 +26935,7 @@ function streamingCanonicalAnchor(feature, projection, bounds2) {
26403
26935
  }
26404
26936
  })
26405
26937
  );
26406
- if (invalid3) return void 0;
26938
+ if (invalid4) return void 0;
26407
26939
  return probes.filter((p) => p.winding !== 0 && p.distance2 > EPS * EPS).sort((a, b) => b.area - a.area || b.distance2 - a.distance2)[0]?.point;
26408
26940
  }
26409
26941
  function captureGeoLabelGeometry(featureId, feature, projection, limits = {}) {
@@ -31472,6 +32004,9 @@ import {
31472
32004
  formatDate as formatDate8,
31473
32005
  resolveNumberFormatter as resolveNumberFormatter6
31474
32006
  } from "@opendata-ai/openchart-core";
32007
+ import { utcFormat as utcFormat3 } from "d3-time-format";
32008
+ var TIME_DIRECTIVE = /%/;
32009
+ var ISO_8601 = /^(\d{4})-(\d{2})-(\d{2})(T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[+-]\d{2}:?\d{2})?$/;
31475
32010
  function isNumericValue(value) {
31476
32011
  if (typeof value === "number") return Number.isFinite(value);
31477
32012
  return false;
@@ -31480,6 +32015,28 @@ function isDateValue(value) {
31480
32015
  if (value instanceof Date) return !Number.isNaN(value.getTime());
31481
32016
  return false;
31482
32017
  }
32018
+ function isRealCalendarDay(year, month, day) {
32019
+ const date = new Date(Date.UTC(year, month - 1, day));
32020
+ return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
32021
+ }
32022
+ function toDate2(value) {
32023
+ if (value instanceof Date) return Number.isNaN(value.getTime()) ? void 0 : value;
32024
+ if (typeof value !== "string") return void 0;
32025
+ const parts = ISO_8601.exec(value);
32026
+ if (!parts) return void 0;
32027
+ const [, year, month, day, time, offset] = parts;
32028
+ if (!isRealCalendarDay(Number(year), Number(month), Number(day))) return void 0;
32029
+ const parsed = new Date(time && !offset ? `${value}Z` : value);
32030
+ return Number.isNaN(parsed.getTime()) ? void 0 : parsed;
32031
+ }
32032
+ function formatTemporalValue(value, column) {
32033
+ if (column.type !== "temporal" || !column.format || !TIME_DIRECTIVE.test(column.format)) {
32034
+ return void 0;
32035
+ }
32036
+ const date = toDate2(value);
32037
+ if (!date) return void 0;
32038
+ return utcFormat3(column.format)(date);
32039
+ }
31483
32040
  function formatCell(value, column) {
31484
32041
  const style = {};
31485
32042
  if (value == null) {
@@ -31499,6 +32056,10 @@ function formatCell(value, column) {
31499
32056
  };
31500
32057
  }
31501
32058
  }
32059
+ const temporal = formatTemporalValue(value, column);
32060
+ if (temporal !== void 0) {
32061
+ return { value, formattedValue: temporal, style };
32062
+ }
31502
32063
  if (isNumericValue(value)) {
31503
32064
  return {
31504
32065
  value,
@@ -31530,7 +32091,7 @@ function formatValueForSearch(value, column) {
31530
32091
  if (isNumericValue(value)) {
31531
32092
  return defaultNumberFormatter11({ surface: "table" })(value);
31532
32093
  }
31533
- return String(value);
32094
+ return formatTemporalValue(value, column) ?? String(value);
31534
32095
  }
31535
32096
 
31536
32097
  // src/tables/heatmap.ts