@opendata-ai/openchart-engine 9.3.0 → 9.5.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.d.ts +5 -2
- package/dist/index.js +951 -322
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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
|
|
1617
|
+
highlight,
|
|
1618
1618
|
a11y: spec.a11y,
|
|
1619
1619
|
frame: spec.frame,
|
|
1620
1620
|
display,
|
|
@@ -1642,6 +1642,7 @@ function normalizeTableSpec(spec, _warnings) {
|
|
|
1642
1642
|
data: spec.data,
|
|
1643
1643
|
columns: spec.columns,
|
|
1644
1644
|
rowKey: spec.rowKey,
|
|
1645
|
+
a11y: spec.a11y,
|
|
1645
1646
|
chrome: normalizeChrome2(spec.chrome),
|
|
1646
1647
|
theme: spec.theme ?? {},
|
|
1647
1648
|
search: spec.search ?? false,
|
|
@@ -1914,7 +1915,7 @@ function flattenLayers(spec, parentData, parentEncoding, parentTransforms, paren
|
|
|
1914
1915
|
}
|
|
1915
1916
|
|
|
1916
1917
|
// src/compiler/validate.ts
|
|
1917
|
-
import { isRaceSpec as isRaceSpec2, jsonPointer as
|
|
1918
|
+
import { isRaceSpec as isRaceSpec2, jsonPointer as jsonPointer19, MARK_TYPES as MARK_TYPES2 } from "@opendata-ai/openchart-core";
|
|
1918
1919
|
|
|
1919
1920
|
// src/compiler/validation/barlist.ts
|
|
1920
1921
|
import { jsonPointer as jsonPointer3 } from "@opendata-ai/openchart-core";
|
|
@@ -2185,6 +2186,117 @@ import {
|
|
|
2185
2186
|
MARK_ENCODING_RULES
|
|
2186
2187
|
} from "@opendata-ai/openchart-core";
|
|
2187
2188
|
|
|
2189
|
+
// src/compiler/validation/axis-scale.ts
|
|
2190
|
+
var QUANTITATIVE_SCALES = /* @__PURE__ */ new Set(["linear", "log", "pow", "sqrt", "symlog"]);
|
|
2191
|
+
var TIME_INTERVALS = ["year", "quarter", "month", "week", "day", "hour", "minute"];
|
|
2192
|
+
function isRecord(value) {
|
|
2193
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2194
|
+
}
|
|
2195
|
+
function invalid(errors, path, message, suggestion) {
|
|
2196
|
+
errors.push({ code: "INVALID_VALUE", path, message, suggestion });
|
|
2197
|
+
}
|
|
2198
|
+
function validateEnds(scale, quantitative, name, errors) {
|
|
2199
|
+
const label = `encoding.${name}.scale`;
|
|
2200
|
+
const path = `/encoding/${name}/scale`;
|
|
2201
|
+
const { domainMin, domainMax } = scale;
|
|
2202
|
+
if (domainMin === void 0 && domainMax === void 0) return;
|
|
2203
|
+
if (!quantitative) {
|
|
2204
|
+
invalid(
|
|
2205
|
+
errors,
|
|
2206
|
+
path,
|
|
2207
|
+
`${label}.domainMin and domainMax apply to quantitative scales only. Use scale.domain for other scales.`,
|
|
2208
|
+
"Use scale.domain for this channel."
|
|
2209
|
+
);
|
|
2210
|
+
return;
|
|
2211
|
+
}
|
|
2212
|
+
for (const end of ["domainMin", "domainMax"]) {
|
|
2213
|
+
const value = scale[end];
|
|
2214
|
+
if (value !== void 0 && (typeof value !== "number" || !Number.isFinite(value)))
|
|
2215
|
+
invalid(
|
|
2216
|
+
errors,
|
|
2217
|
+
`${path}/${end}`,
|
|
2218
|
+
`${label}.${end} must be a finite number.`,
|
|
2219
|
+
"Use a finite numeric endpoint."
|
|
2220
|
+
);
|
|
2221
|
+
}
|
|
2222
|
+
if (scale.domain !== void 0)
|
|
2223
|
+
invalid(
|
|
2224
|
+
errors,
|
|
2225
|
+
path,
|
|
2226
|
+
`Use either ${label}.domain or domainMin/domainMax, not both.`,
|
|
2227
|
+
"Remove domain or the individual endpoints."
|
|
2228
|
+
);
|
|
2229
|
+
if (typeof domainMin === "number" && typeof domainMax === "number" && domainMin >= domainMax)
|
|
2230
|
+
invalid(
|
|
2231
|
+
errors,
|
|
2232
|
+
path,
|
|
2233
|
+
`${label}.domainMin must be less than domainMax.`,
|
|
2234
|
+
"Set the lower endpoint below the upper endpoint."
|
|
2235
|
+
);
|
|
2236
|
+
}
|
|
2237
|
+
function validateStep(step, quantitative, temporal, name, errors) {
|
|
2238
|
+
if (step === void 0) return;
|
|
2239
|
+
const label = `encoding.${name}.axis.tickStep`;
|
|
2240
|
+
const path = `/encoding/${name}/axis/tickStep`;
|
|
2241
|
+
if (!quantitative && !temporal) {
|
|
2242
|
+
invalid(
|
|
2243
|
+
errors,
|
|
2244
|
+
path,
|
|
2245
|
+
`${label} applies to quantitative and temporal axes only.`,
|
|
2246
|
+
"Remove tickStep from this channel."
|
|
2247
|
+
);
|
|
2248
|
+
} else if (quantitative) {
|
|
2249
|
+
if (typeof step !== "number")
|
|
2250
|
+
invalid(
|
|
2251
|
+
errors,
|
|
2252
|
+
path,
|
|
2253
|
+
`${label} on a quantitative axis takes a number.`,
|
|
2254
|
+
"Use a numeric distance between ticks."
|
|
2255
|
+
);
|
|
2256
|
+
else if (!Number.isFinite(step) || step <= 0)
|
|
2257
|
+
invalid(
|
|
2258
|
+
errors,
|
|
2259
|
+
path,
|
|
2260
|
+
`${label} must be a positive number.`,
|
|
2261
|
+
"Use a finite number greater than zero."
|
|
2262
|
+
);
|
|
2263
|
+
} else if (!isRecord(step)) {
|
|
2264
|
+
invalid(
|
|
2265
|
+
errors,
|
|
2266
|
+
path,
|
|
2267
|
+
`${label} on a temporal axis takes { interval, step }, such as { interval: 'month', step: 3 }.`,
|
|
2268
|
+
"Use an interval object for temporal ticks."
|
|
2269
|
+
);
|
|
2270
|
+
} else {
|
|
2271
|
+
if (typeof step.interval !== "string" || !TIME_INTERVALS.includes(step.interval))
|
|
2272
|
+
invalid(
|
|
2273
|
+
errors,
|
|
2274
|
+
`${path}/interval`,
|
|
2275
|
+
`${label}.interval must be one of ${TIME_INTERVALS.join(", ")}.`,
|
|
2276
|
+
"Choose a supported calendar interval."
|
|
2277
|
+
);
|
|
2278
|
+
if (step.step !== void 0 && (typeof step.step !== "number" || !Number.isInteger(step.step) || step.step <= 0))
|
|
2279
|
+
invalid(
|
|
2280
|
+
errors,
|
|
2281
|
+
`${path}/step`,
|
|
2282
|
+
`${label}.step must be a positive whole number.`,
|
|
2283
|
+
"Use a positive integer interval count."
|
|
2284
|
+
);
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
function validateAxisScaleOptions(spec, errors) {
|
|
2288
|
+
if (!isRecord(spec.encoding)) return;
|
|
2289
|
+
for (const name of ["x", "y"]) {
|
|
2290
|
+
const channel = spec.encoding[name];
|
|
2291
|
+
if (!isRecord(channel)) continue;
|
|
2292
|
+
const scale = isRecord(channel.scale) ? channel.scale : {};
|
|
2293
|
+
const quantitative = channel.type === "quantitative" && (scale.type === void 0 || typeof scale.type === "string" && QUANTITATIVE_SCALES.has(scale.type));
|
|
2294
|
+
validateEnds(scale, quantitative, name, errors);
|
|
2295
|
+
if (isRecord(channel.axis))
|
|
2296
|
+
validateStep(channel.axis.tickStep, quantitative, channel.type === "temporal", name, errors);
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2188
2300
|
// src/compiler/validation/frame.ts
|
|
2189
2301
|
function validateFrame(spec, errors, prefix = "") {
|
|
2190
2302
|
if (spec.frame === void 0) return;
|
|
@@ -2384,6 +2496,19 @@ function validateRangeSpec(spec, errors) {
|
|
|
2384
2496
|
}
|
|
2385
2497
|
}
|
|
2386
2498
|
}
|
|
2499
|
+
function validateArcRadius(spec, errors) {
|
|
2500
|
+
if (!spec.mark || typeof spec.mark !== "object" || !("innerRadius" in spec.mark)) return;
|
|
2501
|
+
const radius = spec.mark.innerRadius;
|
|
2502
|
+
if (radius === void 0) return;
|
|
2503
|
+
if (typeof radius !== "number" || !Number.isFinite(radius) || radius < 0) {
|
|
2504
|
+
errors.push({
|
|
2505
|
+
code: "INVALID_VALUE",
|
|
2506
|
+
path: "/mark/innerRadius",
|
|
2507
|
+
message: "mark.innerRadius must be 0 or more: a fraction of the radius below 1, or pixels from 1 up.",
|
|
2508
|
+
suggestion: "Use 0 for a pie, a fraction such as 0.6 for a donut, or a pixel radius such as 20."
|
|
2509
|
+
});
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2387
2512
|
function validateCenterLabel(spec, markType, errors) {
|
|
2388
2513
|
if (!spec.mark || typeof spec.mark !== "object" || Array.isArray(spec.mark)) return;
|
|
2389
2514
|
const centerLabel = spec.mark.centerLabel;
|
|
@@ -2740,7 +2865,7 @@ var PLAYBACK_OPTIONS = [
|
|
|
2740
2865
|
];
|
|
2741
2866
|
var TIMING_EXAMPLES = { duration: 12e3, step: 700, holdEnd: 0 };
|
|
2742
2867
|
var PERIOD_POSITIONS = ["auto", "center", "top-right", "bottom-left"];
|
|
2743
|
-
function
|
|
2868
|
+
function isRecord2(value) {
|
|
2744
2869
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2745
2870
|
}
|
|
2746
2871
|
function isFiniteNumber(value) {
|
|
@@ -2749,7 +2874,7 @@ function isFiniteNumber(value) {
|
|
|
2749
2874
|
function isStringArray(value) {
|
|
2750
2875
|
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
2751
2876
|
}
|
|
2752
|
-
function
|
|
2877
|
+
function invalid2(path, message, suggestion) {
|
|
2753
2878
|
return { code: "INVALID_VALUE", path, message: `Spec error: ${message}`, suggestion };
|
|
2754
2879
|
}
|
|
2755
2880
|
function checkUnknownPlaybackKeys(block, errors) {
|
|
@@ -2757,7 +2882,7 @@ function checkUnknownPlaybackKeys(block, errors) {
|
|
|
2757
2882
|
if (PLAYBACK_OPTIONS.some((known) => known === option)) continue;
|
|
2758
2883
|
const hint = didYouMean(option, PLAYBACK_OPTIONS);
|
|
2759
2884
|
errors.push(
|
|
2760
|
-
|
|
2885
|
+
invalid2(
|
|
2761
2886
|
jsonPointer5("playback", option),
|
|
2762
2887
|
`Unknown playback option "${option}"`,
|
|
2763
2888
|
hint ? `Check the option name and keep its value.${hint}` : `Remove "${option}". Supported playback options are ${PLAYBACK_OPTIONS.join(", ")}.`
|
|
@@ -2768,7 +2893,7 @@ function checkUnknownPlaybackKeys(block, errors) {
|
|
|
2768
2893
|
function checkTiming(name, block, errors) {
|
|
2769
2894
|
if (block.duration !== void 0 && block.step !== void 0) {
|
|
2770
2895
|
errors.push(
|
|
2771
|
-
|
|
2896
|
+
invalid2(
|
|
2772
2897
|
`/${name}`,
|
|
2773
2898
|
`${name}.duration and ${name}.step are mutually exclusive`,
|
|
2774
2899
|
`Keep duration for the whole ${name} or step for each period. Remove the other option.`
|
|
@@ -2781,7 +2906,7 @@ function checkTiming(name, block, errors) {
|
|
|
2781
2906
|
const allowZero = option === "holdEnd";
|
|
2782
2907
|
if (isFiniteNumber(value) && value >= 0 && (value > 0 || allowZero)) continue;
|
|
2783
2908
|
errors.push(
|
|
2784
|
-
|
|
2909
|
+
invalid2(
|
|
2785
2910
|
jsonPointer5(name, option),
|
|
2786
2911
|
`${name}.${option} must be a finite number ${allowZero ? "of zero or more" : "greater than zero"}`,
|
|
2787
2912
|
`Use ${option}: ${example} or omit the option. Times are in milliseconds.`
|
|
@@ -2792,7 +2917,7 @@ function checkTiming(name, block, errors) {
|
|
|
2792
2917
|
function checkGaps(name, gaps, errors) {
|
|
2793
2918
|
if (gaps === void 0 || gaps === "interpolate" || gaps === "hold" || gaps === "drop") return;
|
|
2794
2919
|
errors.push(
|
|
2795
|
-
|
|
2920
|
+
invalid2(
|
|
2796
2921
|
`/${name}/gaps`,
|
|
2797
2922
|
`${name}.gaps must be "interpolate", "hold", or "drop"`,
|
|
2798
2923
|
'Use "interpolate" to fill gaps between observed periods, "hold" to carry the last value, or "drop" to leave values absent.'
|
|
@@ -2803,7 +2928,7 @@ function checkSwitches(name, block, errors) {
|
|
|
2803
2928
|
for (const option of ["loop", "controls"]) {
|
|
2804
2929
|
if (block[option] === void 0 || typeof block[option] === "boolean") continue;
|
|
2805
2930
|
errors.push(
|
|
2806
|
-
|
|
2931
|
+
invalid2(
|
|
2807
2932
|
jsonPointer5(name, option),
|
|
2808
2933
|
`${name}.${option} must be true or false`,
|
|
2809
2934
|
`Use ${option}: false to disable it or ${option}: true to enable it.`
|
|
@@ -2813,7 +2938,7 @@ function checkSwitches(name, block, errors) {
|
|
|
2813
2938
|
const { autoplay } = block;
|
|
2814
2939
|
if (autoplay === void 0 || autoplay === "visible" || typeof autoplay === "boolean") return;
|
|
2815
2940
|
errors.push(
|
|
2816
|
-
|
|
2941
|
+
invalid2(
|
|
2817
2942
|
`/${name}/autoplay`,
|
|
2818
2943
|
`${name}.autoplay must be "visible", true, or false`,
|
|
2819
2944
|
'Use "visible" to start when the chart is in view, true to start immediately, or false to wait for play.'
|
|
@@ -2822,9 +2947,9 @@ function checkSwitches(name, block, errors) {
|
|
|
2822
2947
|
}
|
|
2823
2948
|
function checkPeriod(name, period, errors) {
|
|
2824
2949
|
if (period === void 0 || period === false) return;
|
|
2825
|
-
if (!
|
|
2950
|
+
if (!isRecord2(period)) {
|
|
2826
2951
|
errors.push(
|
|
2827
|
-
|
|
2952
|
+
invalid2(
|
|
2828
2953
|
`/${name}/period`,
|
|
2829
2954
|
`${name}.period must be false or an object`,
|
|
2830
2955
|
'Use period: false to hide the label, period: { format: "%Y" } to format it, or omit period to use the default label.'
|
|
@@ -2834,7 +2959,7 @@ function checkPeriod(name, period, errors) {
|
|
|
2834
2959
|
}
|
|
2835
2960
|
if (period.format !== void 0 && typeof period.format !== "string") {
|
|
2836
2961
|
errors.push(
|
|
2837
|
-
|
|
2962
|
+
invalid2(
|
|
2838
2963
|
`/${name}/period/format`,
|
|
2839
2964
|
`${name}.period.format must be a string`,
|
|
2840
2965
|
'Use a format string such as format: "%Y" for temporal years or omit format.'
|
|
@@ -2844,7 +2969,7 @@ function checkPeriod(name, period, errors) {
|
|
|
2844
2969
|
if (name !== "playback" || period.position === void 0) return;
|
|
2845
2970
|
if (PERIOD_POSITIONS.some((position) => position === period.position)) return;
|
|
2846
2971
|
errors.push(
|
|
2847
|
-
|
|
2972
|
+
invalid2(
|
|
2848
2973
|
"/playback/period/position",
|
|
2849
2974
|
`playback.period.position must be ${PERIOD_POSITIONS.map((p) => `"${p}"`).join(", ")}`,
|
|
2850
2975
|
'Use "auto" to place the label for the chart type, or omit position.'
|
|
@@ -2855,7 +2980,7 @@ function checkHighlights(block, errors) {
|
|
|
2855
2980
|
const { labels, trails } = block;
|
|
2856
2981
|
if (labels !== void 0 && !isStringArray(labels)) {
|
|
2857
2982
|
errors.push(
|
|
2858
|
-
|
|
2983
|
+
invalid2(
|
|
2859
2984
|
"/playback/labels",
|
|
2860
2985
|
"playback.labels must be an array of key names",
|
|
2861
2986
|
'Use labels: ["China", "India"] with values from the key field, or omit labels.'
|
|
@@ -2864,7 +2989,7 @@ function checkHighlights(block, errors) {
|
|
|
2864
2989
|
}
|
|
2865
2990
|
if (trails !== void 0 && typeof trails !== "boolean" && !isStringArray(trails)) {
|
|
2866
2991
|
errors.push(
|
|
2867
|
-
|
|
2992
|
+
invalid2(
|
|
2868
2993
|
"/playback/trails",
|
|
2869
2994
|
"playback.trails must be true, false, or an array of key names",
|
|
2870
2995
|
'Use trails: true for every key, trails: ["China"] for named keys, or omit trails.'
|
|
@@ -2874,7 +2999,7 @@ function checkHighlights(block, errors) {
|
|
|
2874
2999
|
}
|
|
2875
3000
|
function validatePlaybackBlock(blockName, value, errors) {
|
|
2876
3001
|
if (value === void 0) return;
|
|
2877
|
-
if (!
|
|
3002
|
+
if (!isRecord2(value)) {
|
|
2878
3003
|
if (blockName === "race") return;
|
|
2879
3004
|
errors.push({
|
|
2880
3005
|
code: "INVALID_TYPE",
|
|
@@ -2896,16 +3021,16 @@ function validatePlaybackBlock(blockName, value, errors) {
|
|
|
2896
3021
|
var SUPPORTED_MARKS = ["point", "circle", "bar"];
|
|
2897
3022
|
var KEYED_MARKS = ["point", "circle"];
|
|
2898
3023
|
var TIME_PATH = "/encoding/time";
|
|
2899
|
-
function
|
|
3024
|
+
function isRecord3(value) {
|
|
2900
3025
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2901
3026
|
}
|
|
2902
3027
|
function fieldOf(channel) {
|
|
2903
|
-
if (!
|
|
3028
|
+
if (!isRecord3(channel)) return void 0;
|
|
2904
3029
|
return typeof channel.field === "string" ? channel.field : void 0;
|
|
2905
3030
|
}
|
|
2906
3031
|
function markTypeOf2(spec) {
|
|
2907
3032
|
if (typeof spec.mark === "string") return spec.mark;
|
|
2908
|
-
return
|
|
3033
|
+
return isRecord3(spec.mark) && typeof spec.mark.type === "string" ? spec.mark.type : void 0;
|
|
2909
3034
|
}
|
|
2910
3035
|
function mismatch(path, message, suggestion) {
|
|
2911
3036
|
return { code: "ENCODING_MISMATCH", path, message: `Spec error: ${message}`, suggestion };
|
|
@@ -2958,7 +3083,7 @@ function checkUnsupportedFeatures(spec, encoding, context, errors) {
|
|
|
2958
3083
|
)
|
|
2959
3084
|
);
|
|
2960
3085
|
}
|
|
2961
|
-
if (
|
|
3086
|
+
if (isRecord3(spec.mark) && spec.mark.trendline) {
|
|
2962
3087
|
errors.push(
|
|
2963
3088
|
mismatch(
|
|
2964
3089
|
"/mark/trendline",
|
|
@@ -2970,7 +3095,7 @@ function checkUnsupportedFeatures(spec, encoding, context, errors) {
|
|
|
2970
3095
|
}
|
|
2971
3096
|
function checkPointOnlyOptions(spec, errors) {
|
|
2972
3097
|
const mark = markTypeOf2(spec);
|
|
2973
|
-
if (!mark || mark === "point" || !
|
|
3098
|
+
if (!mark || mark === "point" || !isRecord3(spec.playback)) return;
|
|
2974
3099
|
for (const option of ["trails", "labels"]) {
|
|
2975
3100
|
const value = spec.playback[option];
|
|
2976
3101
|
if (value === void 0 || value === false) continue;
|
|
@@ -2984,12 +3109,12 @@ function checkPointOnlyOptions(spec, errors) {
|
|
|
2984
3109
|
}
|
|
2985
3110
|
}
|
|
2986
3111
|
function checkTrailAxes(spec, encoding, errors) {
|
|
2987
|
-
if (markTypeOf2(spec) !== "point" || !
|
|
3112
|
+
if (markTypeOf2(spec) !== "point" || !isRecord3(spec.playback)) return;
|
|
2988
3113
|
const trails = spec.playback.trails;
|
|
2989
3114
|
if (trails === void 0 || trails === false) return;
|
|
2990
3115
|
for (const channel of ["x", "y"]) {
|
|
2991
3116
|
const authored = encoding[channel];
|
|
2992
|
-
const type =
|
|
3117
|
+
const type = isRecord3(authored) ? authored.type : void 0;
|
|
2993
3118
|
if (type === void 0 || type === "quantitative") continue;
|
|
2994
3119
|
errors.push(
|
|
2995
3120
|
mismatch(
|
|
@@ -3004,7 +3129,7 @@ function checkTrailAxes(spec, encoding, errors) {
|
|
|
3004
3129
|
function checkAggregateKeepsTime(spec, timeField, errors) {
|
|
3005
3130
|
if (!Array.isArray(spec.transform)) return;
|
|
3006
3131
|
spec.transform.forEach((step, index) => {
|
|
3007
|
-
if (!(
|
|
3132
|
+
if (!(isRecord3(step) && "aggregate" in step)) return;
|
|
3008
3133
|
const groupby = Array.isArray(step.groupby) ? step.groupby : [];
|
|
3009
3134
|
if (groupby.includes(timeField)) return;
|
|
3010
3135
|
errors.push(
|
|
@@ -3017,7 +3142,7 @@ function checkAggregateKeepsTime(spec, timeField, errors) {
|
|
|
3017
3142
|
});
|
|
3018
3143
|
}
|
|
3019
3144
|
function barIdentity(encoding) {
|
|
3020
|
-
const xQuantitative =
|
|
3145
|
+
const xQuantitative = isRecord3(encoding.x) && encoding.x.type === "quantitative";
|
|
3021
3146
|
const categoryField = fieldOf(xQuantitative ? encoding.y : encoding.x);
|
|
3022
3147
|
if (!categoryField) return null;
|
|
3023
3148
|
const colorField = fieldOf(encoding.color);
|
|
@@ -3046,7 +3171,7 @@ function identityFor(spec, encoding, errors) {
|
|
|
3046
3171
|
};
|
|
3047
3172
|
}
|
|
3048
3173
|
function timeTypeOf(time) {
|
|
3049
|
-
const type =
|
|
3174
|
+
const type = isRecord3(time) ? time.type : void 0;
|
|
3050
3175
|
return type === "temporal" || type === "quantitative" ? type : "ordinal";
|
|
3051
3176
|
}
|
|
3052
3177
|
function checkUniqueRows(spec, identity, time, errors) {
|
|
@@ -3061,7 +3186,7 @@ function checkUniqueRows(spec, identity, time, errors) {
|
|
|
3061
3186
|
});
|
|
3062
3187
|
}
|
|
3063
3188
|
function validateTimeEncoding(spec, errors, context = {}) {
|
|
3064
|
-
const encoding =
|
|
3189
|
+
const encoding = isRecord3(spec.encoding) ? spec.encoding : {};
|
|
3065
3190
|
checkUnsupportedFeatures(spec, encoding, context, errors);
|
|
3066
3191
|
checkPointOnlyOptions(spec, errors);
|
|
3067
3192
|
checkTrailAxes(spec, encoding, errors);
|
|
@@ -3201,6 +3326,8 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
3201
3326
|
}
|
|
3202
3327
|
}
|
|
3203
3328
|
validateCenterLabel(spec, markType, errors);
|
|
3329
|
+
validateAxisScaleOptions(spec, errors);
|
|
3330
|
+
validateArcRadius(spec, errors);
|
|
3204
3331
|
if (markType === "errorbar") validateErrorbarSpec(spec, errors);
|
|
3205
3332
|
if (markType === "range") {
|
|
3206
3333
|
validateRangeSpec(spec, errors);
|
|
@@ -3285,6 +3412,16 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
3285
3412
|
}
|
|
3286
3413
|
const channelObj = channelSpec;
|
|
3287
3414
|
const channelRule = rules[channel];
|
|
3415
|
+
if (channel === "color" && "value" in channelObj && !("field" in channelObj)) {
|
|
3416
|
+
if (typeof channelObj.value !== "string")
|
|
3417
|
+
errors.push({
|
|
3418
|
+
message: "encoding.color.value must be a color string.",
|
|
3419
|
+
path: "/encoding/color/value",
|
|
3420
|
+
code: "INVALID_VALUE",
|
|
3421
|
+
suggestion: 'Use a color string such as "#ff0000".'
|
|
3422
|
+
});
|
|
3423
|
+
continue;
|
|
3424
|
+
}
|
|
3288
3425
|
if (channel === "description" && "value" in channelObj) {
|
|
3289
3426
|
if (typeof channelObj.value !== "string" || "field" in channelObj)
|
|
3290
3427
|
errors.push({
|
|
@@ -3526,8 +3663,33 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
3526
3663
|
}
|
|
3527
3664
|
}
|
|
3528
3665
|
|
|
3666
|
+
// src/compiler/validation/chrome-links.ts
|
|
3667
|
+
import { isSafeLink, jsonPointer as jsonPointer8 } from "@opendata-ai/openchart-core";
|
|
3668
|
+
function validateChromeLinks(spec, errors, prefix = "") {
|
|
3669
|
+
const chrome = spec.chrome;
|
|
3670
|
+
if (chrome && typeof chrome === "object" && !Array.isArray(chrome)) {
|
|
3671
|
+
for (const [key, value] of Object.entries(chrome)) {
|
|
3672
|
+
if (!value || typeof value !== "object" || !("href" in value)) continue;
|
|
3673
|
+
if (value.href === void 0) continue;
|
|
3674
|
+
if (typeof value.href === "string" && isSafeLink(value.href)) continue;
|
|
3675
|
+
errors.push({
|
|
3676
|
+
code: "INVALID_VALUE",
|
|
3677
|
+
path: `${prefix}${jsonPointer8("chrome", key, "href")}`,
|
|
3678
|
+
message: `chrome.${key}.href must be an http, https or mailto link.`,
|
|
3679
|
+
suggestion: "Use an absolute http, https or mailto URL, or omit href."
|
|
3680
|
+
});
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
if (Array.isArray(spec.layer)) {
|
|
3684
|
+
for (const [index, child] of spec.layer.entries()) {
|
|
3685
|
+
if (child && typeof child === "object" && !Array.isArray(child))
|
|
3686
|
+
validateChromeLinks(child, errors, `${prefix}${jsonPointer8("layer", index)}`);
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
3690
|
+
|
|
3529
3691
|
// src/compiler/validation/common-fields.ts
|
|
3530
|
-
import { encodePointerToken as encodePointerToken2, jsonPointer as
|
|
3692
|
+
import { encodePointerToken as encodePointerToken2, jsonPointer as jsonPointer9 } from "@opendata-ai/openchart-core";
|
|
3531
3693
|
function validateAnimation(spec, errors) {
|
|
3532
3694
|
const animation = spec.animation;
|
|
3533
3695
|
if (typeof animation === "string" && !["fluid", "subtle"].includes(animation)) {
|
|
@@ -3586,7 +3748,7 @@ function validatePhaseTiming(settings, path, errors) {
|
|
|
3586
3748
|
errors.push({
|
|
3587
3749
|
code: "INVALID_VALUE",
|
|
3588
3750
|
suggestion: TIMING_SUGGESTION,
|
|
3589
|
-
path:
|
|
3751
|
+
path: jsonPointer9(...path),
|
|
3590
3752
|
message: "A phase cannot combine spring with duration or ease."
|
|
3591
3753
|
});
|
|
3592
3754
|
}
|
|
@@ -3594,7 +3756,7 @@ function validatePhaseTiming(settings, path, errors) {
|
|
|
3594
3756
|
errors.push({
|
|
3595
3757
|
code: "INVALID_VALUE",
|
|
3596
3758
|
suggestion: TIMING_SUGGESTION,
|
|
3597
|
-
path:
|
|
3759
|
+
path: jsonPointer9(...path, "spring"),
|
|
3598
3760
|
message: "Spring must be a configuration object."
|
|
3599
3761
|
});
|
|
3600
3762
|
} else {
|
|
@@ -3605,7 +3767,7 @@ function validatePhaseTiming(settings, path, errors) {
|
|
|
3605
3767
|
errors.push({
|
|
3606
3768
|
code: "INVALID_VALUE",
|
|
3607
3769
|
suggestion: TIMING_SUGGESTION,
|
|
3608
|
-
path:
|
|
3770
|
+
path: jsonPointer9(...path, "spring", key),
|
|
3609
3771
|
message: "Spring parameters must be finite positive stiffness, damping, or mass."
|
|
3610
3772
|
});
|
|
3611
3773
|
}
|
|
@@ -3620,7 +3782,7 @@ function validateDuration(duration, path, errors) {
|
|
|
3620
3782
|
errors.push({
|
|
3621
3783
|
code: "INVALID_VALUE",
|
|
3622
3784
|
suggestion: TIMING_SUGGESTION,
|
|
3623
|
-
path:
|
|
3785
|
+
path: jsonPointer9(...path, "duration"),
|
|
3624
3786
|
message: "Animation duration must be finite and nonnegative."
|
|
3625
3787
|
});
|
|
3626
3788
|
}
|
|
@@ -3630,7 +3792,7 @@ function validateEase(ease, path, errors) {
|
|
|
3630
3792
|
errors.push({
|
|
3631
3793
|
code: "INVALID_VALUE",
|
|
3632
3794
|
suggestion: "Use ease: 'smooth', 'snappy', or 'gentle'.",
|
|
3633
|
-
path:
|
|
3795
|
+
path: jsonPointer9(...path, "ease"),
|
|
3634
3796
|
message: `Animation ease must be 'smooth', 'snappy', or 'gentle', got ${JSON.stringify(ease)}.`
|
|
3635
3797
|
});
|
|
3636
3798
|
}
|
|
@@ -3696,7 +3858,7 @@ function validateFieldMetadata(obj, errors) {
|
|
|
3696
3858
|
return;
|
|
3697
3859
|
}
|
|
3698
3860
|
for (const [field, value] of Object.entries(obj.fields)) {
|
|
3699
|
-
const path =
|
|
3861
|
+
const path = jsonPointer9("fields", field);
|
|
3700
3862
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
3701
3863
|
fail2(path, "Field metadata must be an object.");
|
|
3702
3864
|
continue;
|
|
@@ -3739,7 +3901,7 @@ function validateFieldMetadata(obj, errors) {
|
|
|
3739
3901
|
}
|
|
3740
3902
|
|
|
3741
3903
|
// src/compiler/validation/geo-map.ts
|
|
3742
|
-
import { jsonPointer as
|
|
3904
|
+
import { jsonPointer as jsonPointer11 } from "@opendata-ai/openchart-core";
|
|
3743
3905
|
|
|
3744
3906
|
// src/geo/projections.ts
|
|
3745
3907
|
import { geoAlbersUsa, geoBounds, geoEqualEarth, geoIdentity, geoMercator } from "d3-geo";
|
|
@@ -3843,20 +4005,20 @@ function topologyBBox(topology) {
|
|
|
3843
4005
|
}
|
|
3844
4006
|
|
|
3845
4007
|
// src/compiler/validation/geo-time.ts
|
|
3846
|
-
import { jsonPointer as
|
|
4008
|
+
import { jsonPointer as jsonPointer10 } from "@opendata-ai/openchart-core";
|
|
3847
4009
|
var TIME_TYPES = ["temporal", "ordinal", "quantitative"];
|
|
3848
4010
|
var POINT_ONLY_OPTIONS = ["labels", "trails"];
|
|
3849
|
-
function
|
|
4011
|
+
function isRecord4(value) {
|
|
3850
4012
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3851
4013
|
}
|
|
3852
4014
|
function fieldOf2(channel) {
|
|
3853
|
-
return
|
|
4015
|
+
return isRecord4(channel) && typeof channel.field === "string" ? channel.field : void 0;
|
|
3854
4016
|
}
|
|
3855
4017
|
function timeTypeOf2(channel) {
|
|
3856
|
-
const type =
|
|
4018
|
+
const type = isRecord4(channel) ? channel.type : void 0;
|
|
3857
4019
|
return typeof type === "string" && TIME_TYPES.includes(type) ? type : void 0;
|
|
3858
4020
|
}
|
|
3859
|
-
function
|
|
4021
|
+
function invalid3(path, message, suggestion) {
|
|
3860
4022
|
return { code: "INVALID_VALUE", path, message: `Spec error: ${message}`, suggestion };
|
|
3861
4023
|
}
|
|
3862
4024
|
function checkTimeChannel(channel, path, errors) {
|
|
@@ -3871,7 +4033,7 @@ function checkTimeChannel(channel, path, errors) {
|
|
|
3871
4033
|
}
|
|
3872
4034
|
if (timeTypeOf2(channel)) return;
|
|
3873
4035
|
errors.push(
|
|
3874
|
-
|
|
4036
|
+
invalid3(
|
|
3875
4037
|
`${path}/type`,
|
|
3876
4038
|
`time type must be one of ${TIME_TYPES.join(", ")}, received ${JSON.stringify(channel.type)}`,
|
|
3877
4039
|
"Use temporal for dates and years, quantitative for numbers, ordinal for labels in order."
|
|
@@ -3886,7 +4048,7 @@ function checkUniqueRows2(rows, identityField, time, path, errors) {
|
|
|
3886
4048
|
const collision = firstDuplicateCell(rows, identityOf, { field: timeField, type: timeType });
|
|
3887
4049
|
if (!collision) return;
|
|
3888
4050
|
errors.push(
|
|
3889
|
-
|
|
4051
|
+
invalid3(
|
|
3890
4052
|
path,
|
|
3891
4053
|
`${collision.count} rows have ${identityField} = '${collision.identity}' and ${timeField} = '${String(collision.period)}'. Aggregate them first.`,
|
|
3892
4054
|
`Aggregate the data so each ${identityField} has one row per ${timeField}.`
|
|
@@ -3895,13 +4057,13 @@ function checkUniqueRows2(rows, identityField, time, path, errors) {
|
|
|
3895
4057
|
}
|
|
3896
4058
|
function checkPlaybackBlock(spec, errors) {
|
|
3897
4059
|
validatePlaybackBlock("playback", spec.playback, errors);
|
|
3898
|
-
if (!
|
|
4060
|
+
if (!isRecord4(spec.playback)) return;
|
|
3899
4061
|
for (const option of POINT_ONLY_OPTIONS) {
|
|
3900
4062
|
const value = spec.playback[option];
|
|
3901
4063
|
if (value === void 0 || value === false) continue;
|
|
3902
4064
|
errors.push(
|
|
3903
|
-
|
|
3904
|
-
|
|
4065
|
+
invalid3(
|
|
4066
|
+
jsonPointer10("playback", option),
|
|
3905
4067
|
`playback.${option} is only supported on point charts, not maps`,
|
|
3906
4068
|
`Remove playback.${option}.`
|
|
3907
4069
|
)
|
|
@@ -3920,9 +4082,9 @@ function checkChoroplethTime(spec, encoding, errors) {
|
|
|
3920
4082
|
});
|
|
3921
4083
|
}
|
|
3922
4084
|
const color = encoding.color;
|
|
3923
|
-
if (!
|
|
4085
|
+
if (!isRecord4(color) || color.type !== "quantitative") {
|
|
3924
4086
|
errors.push(
|
|
3925
|
-
|
|
4087
|
+
invalid3(
|
|
3926
4088
|
"/encoding/color",
|
|
3927
4089
|
"a map with encoding.time needs a quantitative encoding.color to recolor each period",
|
|
3928
4090
|
'Set encoding.color to a numeric field with type: "quantitative", or remove encoding.time.'
|
|
@@ -3949,7 +4111,7 @@ function checkLayersShareTimeType(encoding, points, errors) {
|
|
|
3949
4111
|
const pointType = timeTypeOf2(points.time);
|
|
3950
4112
|
if (!featureType || !pointType || featureType === pointType) return;
|
|
3951
4113
|
errors.push(
|
|
3952
|
-
|
|
4114
|
+
invalid3(
|
|
3953
4115
|
"/points/time/type",
|
|
3954
4116
|
`encoding.time is ${featureType} but points.time is ${pointType}; both layers play on one timeline`,
|
|
3955
4117
|
`Give encoding.time and points.time the same type, e.g. both "${featureType}".`
|
|
@@ -3957,8 +4119,8 @@ function checkLayersShareTimeType(encoding, points, errors) {
|
|
|
3957
4119
|
);
|
|
3958
4120
|
}
|
|
3959
4121
|
function validateGeoMapTime(spec, errors) {
|
|
3960
|
-
const encoding =
|
|
3961
|
-
const points =
|
|
4122
|
+
const encoding = isRecord4(spec.encoding) ? spec.encoding : {};
|
|
4123
|
+
const points = isRecord4(spec.points) ? spec.points : void 0;
|
|
3962
4124
|
const choroplethTime = encoding.time != null;
|
|
3963
4125
|
const pointsTime = points?.time != null;
|
|
3964
4126
|
if (!choroplethTime && !pointsTime) return;
|
|
@@ -3969,9 +4131,9 @@ function validateGeoMapTime(spec, errors) {
|
|
|
3969
4131
|
}
|
|
3970
4132
|
function checkTileColoring(spec, encoding, errors) {
|
|
3971
4133
|
const value = encoding.value;
|
|
3972
|
-
if (
|
|
4134
|
+
if (isRecord4(value) && value.type !== void 0 && value.type !== "quantitative") {
|
|
3973
4135
|
errors.push(
|
|
3974
|
-
|
|
4136
|
+
invalid3(
|
|
3975
4137
|
"/encoding/value",
|
|
3976
4138
|
`a tile map with encoding.time needs a quantitative encoding.value, received type ${JSON.stringify(value.type)}`,
|
|
3977
4139
|
'Set encoding.value to a numeric field with type: "quantitative".'
|
|
@@ -3980,7 +4142,7 @@ function checkTileColoring(spec, encoding, errors) {
|
|
|
3980
4142
|
}
|
|
3981
4143
|
if (encoding.color !== void 0) {
|
|
3982
4144
|
errors.push(
|
|
3983
|
-
|
|
4145
|
+
invalid3(
|
|
3984
4146
|
"/encoding/color",
|
|
3985
4147
|
"a tile map with encoding.time shades encoding.value, so it cannot use categorical encoding.color",
|
|
3986
4148
|
"Remove encoding.color, or remove encoding.time for a categorical tile map."
|
|
@@ -3989,7 +4151,7 @@ function checkTileColoring(spec, encoding, errors) {
|
|
|
3989
4151
|
}
|
|
3990
4152
|
if (spec.colors !== void 0) {
|
|
3991
4153
|
errors.push(
|
|
3992
|
-
|
|
4154
|
+
invalid3(
|
|
3993
4155
|
"/colors",
|
|
3994
4156
|
"a tile map with encoding.time shades encoding.value, so it cannot use categorical colors",
|
|
3995
4157
|
"Remove colors, or remove encoding.time for a categorical tile map."
|
|
@@ -3998,7 +4160,7 @@ function checkTileColoring(spec, encoding, errors) {
|
|
|
3998
4160
|
}
|
|
3999
4161
|
}
|
|
4000
4162
|
function validateTileMapTime(spec, errors) {
|
|
4001
|
-
const encoding =
|
|
4163
|
+
const encoding = isRecord4(spec.encoding) ? spec.encoding : {};
|
|
4002
4164
|
if (encoding.time == null) return;
|
|
4003
4165
|
checkTimeChannel(encoding.time, "/encoding/time", errors);
|
|
4004
4166
|
if (!Array.isArray(spec.data)) {
|
|
@@ -4063,7 +4225,7 @@ function validateGeoMapSpec(spec, errors) {
|
|
|
4063
4225
|
if (!["activeValue", "distribution"].includes(name) || typeof value !== "boolean")
|
|
4064
4226
|
errors.push({
|
|
4065
4227
|
code: "INVALID_VALUE",
|
|
4066
|
-
path:
|
|
4228
|
+
path: jsonPointer11("colorKey", name),
|
|
4067
4229
|
message: "colorKey accepts only boolean activeValue and distribution.",
|
|
4068
4230
|
suggestion: "Omit either option or set it to true or false."
|
|
4069
4231
|
});
|
|
@@ -4114,7 +4276,7 @@ function validateGeoMapSpec(spec, errors) {
|
|
|
4114
4276
|
if (typeof focus[i] !== "string" && typeof focus[i] !== "number") {
|
|
4115
4277
|
errors.push({
|
|
4116
4278
|
message: `Spec error: geo.focus array element [${i}] must be a string or number`,
|
|
4117
|
-
path:
|
|
4279
|
+
path: jsonPointer11("geo", "focus", i),
|
|
4118
4280
|
code: "INVALID_TYPE",
|
|
4119
4281
|
suggestion: "Each element in the focus array should be a feature id (string or number)"
|
|
4120
4282
|
});
|
|
@@ -4162,7 +4324,7 @@ function validateGeoMapSpec(spec, errors) {
|
|
|
4162
4324
|
if (typeof feats[i] !== "string" && typeof feats[i] !== "number") {
|
|
4163
4325
|
errors.push({
|
|
4164
4326
|
message: `Spec error: geo.focus.features[${i}] must be a string or number`,
|
|
4165
|
-
path:
|
|
4327
|
+
path: jsonPointer11("geo", "focus", "features", i),
|
|
4166
4328
|
code: "INVALID_TYPE",
|
|
4167
4329
|
suggestion: "Each element should be a feature id (string or number)"
|
|
4168
4330
|
});
|
|
@@ -4250,14 +4412,14 @@ function validateGeoMapSpec(spec, errors) {
|
|
|
4250
4412
|
if (!enc || typeof enc !== "object") {
|
|
4251
4413
|
errors.push({
|
|
4252
4414
|
message: `Spec error: points requires "${ch}" encoding channel`,
|
|
4253
|
-
path:
|
|
4415
|
+
path: jsonPointer11("points", ch),
|
|
4254
4416
|
code: "MISSING_FIELD",
|
|
4255
4417
|
suggestion: `Add points.${ch}, e.g. ${ch}: { field: "${ch === "longitude" ? "lon" : "lat"}", type: "quantitative" }`
|
|
4256
4418
|
});
|
|
4257
4419
|
} else if (!enc.field || typeof enc.field !== "string") {
|
|
4258
4420
|
errors.push({
|
|
4259
4421
|
message: `Spec error: points.${ch} must have a "field" string`,
|
|
4260
|
-
path:
|
|
4422
|
+
path: jsonPointer11("points", ch, "field"),
|
|
4261
4423
|
code: "MISSING_FIELD",
|
|
4262
4424
|
suggestion: `Add a field name, e.g. ${ch}: { field: "${ch === "longitude" ? "lon" : "lat"}" }`
|
|
4263
4425
|
});
|
|
@@ -4268,7 +4430,7 @@ function validateGeoMapSpec(spec, errors) {
|
|
|
4268
4430
|
if (enc && typeof enc === "object" && (!enc.field || typeof enc.field !== "string")) {
|
|
4269
4431
|
errors.push({
|
|
4270
4432
|
message: `Spec error: points.${ch} must have a "field" string when provided`,
|
|
4271
|
-
path:
|
|
4433
|
+
path: jsonPointer11("points", ch, "field"),
|
|
4272
4434
|
code: "MISSING_FIELD",
|
|
4273
4435
|
suggestion: `Add a field name, e.g. ${ch}: { field: "myField" }`
|
|
4274
4436
|
});
|
|
@@ -4524,7 +4686,7 @@ function validateGeoMapViews(spec, errors) {
|
|
|
4524
4686
|
}
|
|
4525
4687
|
|
|
4526
4688
|
// src/compiler/validation/graph.ts
|
|
4527
|
-
import { jsonPointer as
|
|
4689
|
+
import { jsonPointer as jsonPointer12 } from "@opendata-ai/openchart-core";
|
|
4528
4690
|
function validateGraphSpec(spec, errors) {
|
|
4529
4691
|
if (!Array.isArray(spec.nodes)) {
|
|
4530
4692
|
errors.push({
|
|
@@ -4551,7 +4713,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
4551
4713
|
if (!node3 || typeof node3 !== "object") {
|
|
4552
4714
|
errors.push({
|
|
4553
4715
|
message: `Spec error: nodes[${i}] must be an object`,
|
|
4554
|
-
path:
|
|
4716
|
+
path: jsonPointer12("nodes", i),
|
|
4555
4717
|
code: "INVALID_TYPE",
|
|
4556
4718
|
suggestion: 'Each node must be an object with at least an "id" field, e.g. { id: "a" }'
|
|
4557
4719
|
});
|
|
@@ -4560,7 +4722,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
4560
4722
|
if (typeof node3.id !== "string" || node3.id === "") {
|
|
4561
4723
|
errors.push({
|
|
4562
4724
|
message: `Spec error: nodes[${i}] must have a non-empty string "id" field`,
|
|
4563
|
-
path:
|
|
4725
|
+
path: jsonPointer12("nodes", i, "id"),
|
|
4564
4726
|
code: "MISSING_FIELD",
|
|
4565
4727
|
suggestion: 'Add a string id to the node, e.g. { id: "node1" }'
|
|
4566
4728
|
});
|
|
@@ -4612,7 +4774,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
4612
4774
|
if (!edge || typeof edge !== "object") {
|
|
4613
4775
|
errors.push({
|
|
4614
4776
|
message: `Spec error: edges[${i}] must be an object`,
|
|
4615
|
-
path:
|
|
4777
|
+
path: jsonPointer12("edges", i),
|
|
4616
4778
|
code: "INVALID_TYPE",
|
|
4617
4779
|
suggestion: 'Each edge must be an object with "source" and "target" fields, e.g. { source: "a", target: "b" }'
|
|
4618
4780
|
});
|
|
@@ -4621,14 +4783,14 @@ function validateGraphSpec(spec, errors) {
|
|
|
4621
4783
|
if (typeof edge.source !== "string" || edge.source === "") {
|
|
4622
4784
|
errors.push({
|
|
4623
4785
|
message: `Spec error: edges[${i}] must have a non-empty string "source" field`,
|
|
4624
|
-
path:
|
|
4786
|
+
path: jsonPointer12("edges", i, "source"),
|
|
4625
4787
|
code: "MISSING_FIELD",
|
|
4626
4788
|
suggestion: 'Add a source node id, e.g. { source: "a", target: "b" }'
|
|
4627
4789
|
});
|
|
4628
4790
|
} else if (nodeIds.size > 0 && !nodeIds.has(edge.source)) {
|
|
4629
4791
|
errors.push({
|
|
4630
4792
|
message: `Spec error: edges[${i}].source "${edge.source}" does not reference an existing node id`,
|
|
4631
|
-
path:
|
|
4793
|
+
path: jsonPointer12("edges", i, "source"),
|
|
4632
4794
|
code: "DATA_FIELD_MISSING",
|
|
4633
4795
|
suggestion: `Use one of the existing node ids: ${[...nodeIds].slice(0, 5).join(", ")}${nodeIds.size > 5 ? "..." : ""}.${didYouMean(edge.source, [...nodeIds])}`
|
|
4634
4796
|
});
|
|
@@ -4636,14 +4798,14 @@ function validateGraphSpec(spec, errors) {
|
|
|
4636
4798
|
if (typeof edge.target !== "string" || edge.target === "") {
|
|
4637
4799
|
errors.push({
|
|
4638
4800
|
message: `Spec error: edges[${i}] must have a non-empty string "target" field`,
|
|
4639
|
-
path:
|
|
4801
|
+
path: jsonPointer12("edges", i, "target"),
|
|
4640
4802
|
code: "MISSING_FIELD",
|
|
4641
4803
|
suggestion: 'Add a target node id, e.g. { source: "a", target: "b" }'
|
|
4642
4804
|
});
|
|
4643
4805
|
} else if (nodeIds.size > 0 && !nodeIds.has(edge.target)) {
|
|
4644
4806
|
errors.push({
|
|
4645
4807
|
message: `Spec error: edges[${i}].target "${edge.target}" does not reference an existing node id`,
|
|
4646
|
-
path:
|
|
4808
|
+
path: jsonPointer12("edges", i, "target"),
|
|
4647
4809
|
code: "DATA_FIELD_MISSING",
|
|
4648
4810
|
suggestion: `Use one of the existing node ids: ${[...nodeIds].slice(0, 5).join(", ")}${nodeIds.size > 5 ? "..." : ""}.${didYouMean(edge.target, [...nodeIds])}`
|
|
4649
4811
|
});
|
|
@@ -4675,7 +4837,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
4675
4837
|
if (ch?.field && typeof ch.field === "string" && nodes.length > 0 && !nodeFields.has(ch.field)) {
|
|
4676
4838
|
errors.push({
|
|
4677
4839
|
message: `Spec error: encoding.${channel}.field "${ch.field}" does not exist on nodes. Available fields: ${[...nodeFields].join(", ")}`,
|
|
4678
|
-
path:
|
|
4840
|
+
path: jsonPointer12("encoding", channel, "field"),
|
|
4679
4841
|
code: "DATA_FIELD_MISSING",
|
|
4680
4842
|
suggestion: `Use one of the node fields: ${[...nodeFields].join(", ")}.${didYouMean(ch.field, [...nodeFields])}`
|
|
4681
4843
|
});
|
|
@@ -4687,7 +4849,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
4687
4849
|
if (ch?.field && typeof ch.field === "string" && edges.length > 0 && !edgeFields.has(ch.field)) {
|
|
4688
4850
|
errors.push({
|
|
4689
4851
|
message: `Spec error: encoding.${channel}.field "${ch.field}" does not exist on edges. Available fields: ${[...edgeFields].join(", ")}`,
|
|
4690
|
-
path:
|
|
4852
|
+
path: jsonPointer12("encoding", channel, "field"),
|
|
4691
4853
|
code: "DATA_FIELD_MISSING",
|
|
4692
4854
|
suggestion: `Use one of the edge fields: ${[...edgeFields].join(", ")}.${didYouMean(ch.field, [...edgeFields])}`
|
|
4693
4855
|
});
|
|
@@ -4714,7 +4876,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
4714
4876
|
}
|
|
4715
4877
|
|
|
4716
4878
|
// src/compiler/validation/layer.ts
|
|
4717
|
-
import { jsonPointer as
|
|
4879
|
+
import { jsonPointer as jsonPointer13, MARK_TYPES } from "@opendata-ai/openchart-core";
|
|
4718
4880
|
function rootLeafPath(path, parentPrefix, leafPrefix, leaf, inheritsData) {
|
|
4719
4881
|
const [, first, second] = path.split("/");
|
|
4720
4882
|
const leafEncoding = leaf.encoding;
|
|
@@ -4738,7 +4900,7 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
4738
4900
|
if (!child || typeof child !== "object" || Array.isArray(child)) {
|
|
4739
4901
|
errors.push({
|
|
4740
4902
|
message: `Spec error: layer[${i}] must be an object`,
|
|
4741
|
-
path: `${prefix}${
|
|
4903
|
+
path: `${prefix}${jsonPointer13("layer", i)}`,
|
|
4742
4904
|
code: "INVALID_TYPE",
|
|
4743
4905
|
suggestion: "Each layer must be a chart spec (with mark) or a nested layer spec (with layer)"
|
|
4744
4906
|
});
|
|
@@ -4748,7 +4910,7 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
4748
4910
|
if (childObj.type === "race") {
|
|
4749
4911
|
errors.push({
|
|
4750
4912
|
code: "INVALID_VALUE",
|
|
4751
|
-
path: `${prefix}${
|
|
4913
|
+
path: `${prefix}${jsonPointer13("layer", i, "type")}`,
|
|
4752
4914
|
message: "Race specs cannot be layered.",
|
|
4753
4915
|
suggestion: "Render the race in its own container."
|
|
4754
4916
|
});
|
|
@@ -4759,14 +4921,14 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
4759
4921
|
if (!isNestedLayer && !isChildChart) {
|
|
4760
4922
|
errors.push({
|
|
4761
4923
|
message: `Spec error: layer[${i}] must have a "mark" field or a "layer" array`,
|
|
4762
|
-
path: `${prefix}${
|
|
4924
|
+
path: `${prefix}${jsonPointer13("layer", i)}`,
|
|
4763
4925
|
code: "MISSING_FIELD",
|
|
4764
4926
|
suggestion: "Each layer must be a chart spec (with mark + encoding) or a nested layer spec (with layer array)"
|
|
4765
4927
|
});
|
|
4766
4928
|
continue;
|
|
4767
4929
|
}
|
|
4768
4930
|
if (isNestedLayer) {
|
|
4769
|
-
validateLayerSpec(childObj, errors, `${prefix}${
|
|
4931
|
+
validateLayerSpec(childObj, errors, `${prefix}${jsonPointer13("layer", i)}`);
|
|
4770
4932
|
} else if (isChildChart) {
|
|
4771
4933
|
const mark = childObj.mark;
|
|
4772
4934
|
let markValue;
|
|
@@ -4778,7 +4940,7 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
4778
4940
|
if (!markValue || !MARK_TYPES.has(markValue)) {
|
|
4779
4941
|
errors.push({
|
|
4780
4942
|
message: `Spec error: layer[${i}].mark "${markValue ?? String(mark)}" is not a valid mark type`,
|
|
4781
|
-
path: `${prefix}${
|
|
4943
|
+
path: `${prefix}${jsonPointer13("layer", i, "mark")}`,
|
|
4782
4944
|
code: "INVALID_VALUE",
|
|
4783
4945
|
suggestion: `Change mark to one of: ${[...MARK_TYPES].join(", ")}`
|
|
4784
4946
|
});
|
|
@@ -4800,7 +4962,7 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
4800
4962
|
if (mergedForValidation.data && mergedForValidation.encoding) {
|
|
4801
4963
|
const leafErrors = [];
|
|
4802
4964
|
validateChartSpec(mergedForValidation, leafErrors, { inLayer: true });
|
|
4803
|
-
const leafPrefix = `${prefix}${
|
|
4965
|
+
const leafPrefix = `${prefix}${jsonPointer13("layer", i)}`;
|
|
4804
4966
|
for (const error of leafErrors)
|
|
4805
4967
|
errors.push({
|
|
4806
4968
|
...error,
|
|
@@ -4813,10 +4975,10 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
4813
4975
|
}
|
|
4814
4976
|
|
|
4815
4977
|
// src/compiler/validation/race.ts
|
|
4816
|
-
import { jsonPointer as
|
|
4978
|
+
import { jsonPointer as jsonPointer15 } from "@opendata-ai/openchart-core";
|
|
4817
4979
|
|
|
4818
4980
|
// src/compiler/validation/race-options.ts
|
|
4819
|
-
import { jsonPointer as
|
|
4981
|
+
import { jsonPointer as jsonPointer14 } from "@opendata-ai/openchart-core";
|
|
4820
4982
|
var RACE_OPTIONS = [
|
|
4821
4983
|
"top",
|
|
4822
4984
|
"duration",
|
|
@@ -4847,7 +5009,7 @@ var RACE_ERROR_ORDER = [
|
|
|
4847
5009
|
"period"
|
|
4848
5010
|
];
|
|
4849
5011
|
var CHART_ONLY_PLAYBACK_OPTIONS = ["labels", "trails"];
|
|
4850
|
-
function
|
|
5012
|
+
function isRecord5(value) {
|
|
4851
5013
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4852
5014
|
}
|
|
4853
5015
|
function isFiniteNumber2(value) {
|
|
@@ -4859,7 +5021,7 @@ function checkUnknownRaceKeys(race, errors) {
|
|
|
4859
5021
|
const hint = didYouMean(option, RACE_OPTIONS);
|
|
4860
5022
|
errors.push({
|
|
4861
5023
|
code: "INVALID_VALUE",
|
|
4862
|
-
path:
|
|
5024
|
+
path: jsonPointer14("race", option),
|
|
4863
5025
|
message: `Spec error: Unknown race option "${option}"`,
|
|
4864
5026
|
suggestion: hint ? `Check the option name and keep its value.${hint}` : `Remove "${option}". Supported race options are ${RACE_OPTIONS.join(", ")}.`
|
|
4865
5027
|
});
|
|
@@ -4884,7 +5046,7 @@ function checkScale(race, errors) {
|
|
|
4884
5046
|
suggestion: "Set race.top to the desired number of visible ranks, e.g. top: 10."
|
|
4885
5047
|
});
|
|
4886
5048
|
}
|
|
4887
|
-
if (rescale !== void 0 && rescale !== "frame" && rescale !== "fixed" && !(
|
|
5049
|
+
if (rescale !== void 0 && rescale !== "frame" && rescale !== "fixed" && !(isRecord5(rescale) && isFiniteNumber2(rescale.min))) {
|
|
4888
5050
|
errors.push({
|
|
4889
5051
|
code: "INVALID_VALUE",
|
|
4890
5052
|
path: "/race/rescale",
|
|
@@ -4922,26 +5084,26 @@ function checkTimingAcrossBlocks(race, playback, errors) {
|
|
|
4922
5084
|
if (race[raceField2] === void 0 || playback[playbackField] === void 0) continue;
|
|
4923
5085
|
errors.push({
|
|
4924
5086
|
code: "INVALID_VALUE",
|
|
4925
|
-
path:
|
|
5087
|
+
path: jsonPointer14("playback", playbackField),
|
|
4926
5088
|
message: `Spec error: duration and step are mutually exclusive across race and playback (race.${raceField2}, playback.${playbackField})`,
|
|
4927
5089
|
suggestion: "Keep duration for the whole race or step for each period, in one block. Remove the other option."
|
|
4928
5090
|
});
|
|
4929
5091
|
}
|
|
4930
5092
|
}
|
|
4931
5093
|
function checkPlaybackAgainstRace(race, playback, errors) {
|
|
4932
|
-
if (
|
|
5094
|
+
if (isRecord5(race)) checkTimingAcrossBlocks(race, playback, errors);
|
|
4933
5095
|
for (const field of Object.keys(playback)) {
|
|
4934
5096
|
if (CHART_ONLY_PLAYBACK_OPTIONS.includes(field)) {
|
|
4935
5097
|
errors.push({
|
|
4936
5098
|
code: "INVALID_VALUE",
|
|
4937
|
-
path:
|
|
5099
|
+
path: jsonPointer14("playback", field),
|
|
4938
5100
|
message: `Spec error: playback.${field} applies to point and circle charts only`,
|
|
4939
5101
|
suggestion: `Remove playback.${field} from the race spec.`
|
|
4940
5102
|
});
|
|
4941
|
-
} else if (
|
|
5103
|
+
} else if (isRecord5(race) && race[field] !== void 0 && playback[field] !== void 0) {
|
|
4942
5104
|
errors.push({
|
|
4943
5105
|
code: "INVALID_VALUE",
|
|
4944
|
-
path:
|
|
5106
|
+
path: jsonPointer14("playback", field),
|
|
4945
5107
|
message: `Spec error: ${field} is set in both race and playback`,
|
|
4946
5108
|
suggestion: `Keep ${field} in one block. Remove it from race or from playback.`
|
|
4947
5109
|
});
|
|
@@ -4950,7 +5112,7 @@ function checkPlaybackAgainstRace(race, playback, errors) {
|
|
|
4950
5112
|
}
|
|
4951
5113
|
function validateOptions(race, errors) {
|
|
4952
5114
|
if (race === void 0) return;
|
|
4953
|
-
if (!
|
|
5115
|
+
if (!isRecord5(race)) {
|
|
4954
5116
|
errors.push({
|
|
4955
5117
|
code: "INVALID_TYPE",
|
|
4956
5118
|
path: "/race",
|
|
@@ -4965,7 +5127,7 @@ function validateOptions(race, errors) {
|
|
|
4965
5127
|
function validateRacePlayback(race, playback, errors) {
|
|
4966
5128
|
if (playback === void 0) return;
|
|
4967
5129
|
validatePlaybackBlock("playback", playback, errors);
|
|
4968
|
-
if (
|
|
5130
|
+
if (isRecord5(playback)) checkPlaybackAgainstRace(race, playback, errors);
|
|
4969
5131
|
}
|
|
4970
5132
|
|
|
4971
5133
|
// src/compiler/validation/race.ts
|
|
@@ -4982,7 +5144,7 @@ var TABLE_COLUMNS = [
|
|
|
4982
5144
|
"value",
|
|
4983
5145
|
"share"
|
|
4984
5146
|
];
|
|
4985
|
-
function
|
|
5147
|
+
function isRecord6(value) {
|
|
4986
5148
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4987
5149
|
}
|
|
4988
5150
|
function validateEncodingType(channel, type, errors) {
|
|
@@ -5005,7 +5167,7 @@ function validateEncodingType(channel, type, errors) {
|
|
|
5005
5167
|
}
|
|
5006
5168
|
}
|
|
5007
5169
|
function validateEncoding(encoding, errors) {
|
|
5008
|
-
if (!
|
|
5170
|
+
if (!isRecord6(encoding)) {
|
|
5009
5171
|
errors.push({
|
|
5010
5172
|
code: encoding === void 0 ? "MISSING_FIELD" : "INVALID_TYPE",
|
|
5011
5173
|
path: "/encoding",
|
|
@@ -5016,10 +5178,10 @@ function validateEncoding(encoding, errors) {
|
|
|
5016
5178
|
}
|
|
5017
5179
|
for (const [channel, example] of Object.entries({ time: "year", key: "country", value: "gdp" })) {
|
|
5018
5180
|
const definition = encoding[channel];
|
|
5019
|
-
if (!
|
|
5181
|
+
if (!isRecord6(definition)) {
|
|
5020
5182
|
errors.push({
|
|
5021
5183
|
code: definition === void 0 ? "MISSING_FIELD" : "INVALID_TYPE",
|
|
5022
|
-
path:
|
|
5184
|
+
path: jsonPointer15("encoding", channel),
|
|
5023
5185
|
message: definition === void 0 ? `Spec error: race encoding requires a "${channel}" channel` : `Spec error: encoding.${channel} must be an object`,
|
|
5024
5186
|
suggestion: `Add encoding.${channel} with a field from your data, e.g. { field: "${example}" }.`
|
|
5025
5187
|
});
|
|
@@ -5029,7 +5191,7 @@ function validateEncoding(encoding, errors) {
|
|
|
5029
5191
|
if (typeof field !== "string" || field.trim() === "") {
|
|
5030
5192
|
errors.push({
|
|
5031
5193
|
code: field === void 0 ? "MISSING_FIELD" : "INVALID_TYPE",
|
|
5032
|
-
path:
|
|
5194
|
+
path: jsonPointer15("encoding", channel, "field"),
|
|
5033
5195
|
message: `Spec error: encoding.${channel} requires a non-empty "field" string`,
|
|
5034
5196
|
suggestion: `Set encoding.${channel}.field to the name of a column in your data, e.g. "${example}".`
|
|
5035
5197
|
});
|
|
@@ -5038,17 +5200,17 @@ function validateEncoding(encoding, errors) {
|
|
|
5038
5200
|
}
|
|
5039
5201
|
for (const channel of ["label", "color"]) {
|
|
5040
5202
|
const definition = encoding[channel];
|
|
5041
|
-
if (definition === void 0 ||
|
|
5203
|
+
if (definition === void 0 || isRecord6(definition)) continue;
|
|
5042
5204
|
errors.push({
|
|
5043
5205
|
code: "INVALID_TYPE",
|
|
5044
|
-
path:
|
|
5206
|
+
path: jsonPointer15("encoding", channel),
|
|
5045
5207
|
message: `Spec error: encoding.${channel} must be an object`,
|
|
5046
5208
|
suggestion: `Use a channel definition or omit encoding.${channel}.`
|
|
5047
5209
|
});
|
|
5048
5210
|
}
|
|
5049
5211
|
}
|
|
5050
5212
|
function validateEncodingFields(encoding, data, errors) {
|
|
5051
|
-
if (!
|
|
5213
|
+
if (!isRecord6(encoding) || data.length === 0) return;
|
|
5052
5214
|
const dataColumns = /* @__PURE__ */ new Set();
|
|
5053
5215
|
for (const row of data) {
|
|
5054
5216
|
for (const column of Object.keys(row)) dataColumns.add(column);
|
|
@@ -5057,12 +5219,12 @@ function validateEncodingFields(encoding, data, errors) {
|
|
|
5057
5219
|
const availableColumns = columnList.join(", ");
|
|
5058
5220
|
for (const channel of ["time", "key", "value", "label", "color"]) {
|
|
5059
5221
|
const definition = encoding[channel];
|
|
5060
|
-
if (!
|
|
5222
|
+
if (!isRecord6(definition)) continue;
|
|
5061
5223
|
const { field } = definition;
|
|
5062
5224
|
if (typeof field !== "string" || field.trim() === "" || dataColumns.has(field)) continue;
|
|
5063
5225
|
errors.push({
|
|
5064
5226
|
message: `Spec error: encoding.${channel}.field "${field}" does not exist in data. Available columns: ${availableColumns}`,
|
|
5065
|
-
path:
|
|
5227
|
+
path: jsonPointer15("encoding", channel, "field"),
|
|
5066
5228
|
code: "DATA_FIELD_MISSING",
|
|
5067
5229
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(field, columnList)}`
|
|
5068
5230
|
});
|
|
@@ -5100,7 +5262,7 @@ function validateMarkOptions(type, definition, errors) {
|
|
|
5100
5262
|
if (type === "table") validateTableColumns(columns, errors);
|
|
5101
5263
|
}
|
|
5102
5264
|
function validateMark(mark, errors) {
|
|
5103
|
-
const definition =
|
|
5265
|
+
const definition = isRecord6(mark) ? mark : void 0;
|
|
5104
5266
|
const type = definition ? definition.type : mark;
|
|
5105
5267
|
if (type !== "bar" && type !== "line" && type !== "table") {
|
|
5106
5268
|
errors.push({
|
|
@@ -5117,7 +5279,7 @@ function validateMark(mark, errors) {
|
|
|
5117
5279
|
if (option === "type" || option === supported) continue;
|
|
5118
5280
|
errors.push({
|
|
5119
5281
|
code: "INVALID_VALUE",
|
|
5120
|
-
path:
|
|
5282
|
+
path: jsonPointer15("mark", option),
|
|
5121
5283
|
message: `Spec error: unknown option "${option}" on the race "${type}" mark`,
|
|
5122
5284
|
suggestion: `Remove "${option}". The "${type}" mark supports "${supported}".${didYouMean(option, [supported])}`
|
|
5123
5285
|
});
|
|
@@ -5137,7 +5299,7 @@ function validateData(data, errors) {
|
|
|
5137
5299
|
let firstInvalidRow = -1;
|
|
5138
5300
|
let invalidCount = 0;
|
|
5139
5301
|
for (let index = 0; index < data.length; index++) {
|
|
5140
|
-
if (
|
|
5302
|
+
if (isRecord6(data[index])) continue;
|
|
5141
5303
|
if (firstInvalidRow === -1) firstInvalidRow = index;
|
|
5142
5304
|
invalidCount++;
|
|
5143
5305
|
}
|
|
@@ -5146,7 +5308,7 @@ function validateData(data, errors) {
|
|
|
5146
5308
|
const otherRows = invalidCount > 1 ? " and the other non-object rows" : "";
|
|
5147
5309
|
errors.push({
|
|
5148
5310
|
code: "INVALID_TYPE",
|
|
5149
|
-
path:
|
|
5311
|
+
path: jsonPointer15("data", firstInvalidRow),
|
|
5150
5312
|
message: `Spec error: each race data row must be an object. ${invalidCount} of ${data.length} rows ${invalidRows}.`,
|
|
5151
5313
|
suggestion: `Replace or remove row ${firstInvalidRow + 1}${otherRows}. Each row should name the fields used by time, key, and value.`
|
|
5152
5314
|
});
|
|
@@ -5171,7 +5333,7 @@ function validateRaceSpec(spec, errors) {
|
|
|
5171
5333
|
}
|
|
5172
5334
|
|
|
5173
5335
|
// src/compiler/validation/sankey.ts
|
|
5174
|
-
import { jsonPointer as
|
|
5336
|
+
import { jsonPointer as jsonPointer16 } from "@opendata-ai/openchart-core";
|
|
5175
5337
|
|
|
5176
5338
|
// src/sankey/overrides.ts
|
|
5177
5339
|
import { getBreakpoint } from "@opendata-ai/openchart-core";
|
|
@@ -5246,7 +5408,7 @@ function validateSankeySpec(spec, errors) {
|
|
|
5246
5408
|
if (!ch || typeof ch !== "object") {
|
|
5247
5409
|
errors.push({
|
|
5248
5410
|
message: `Spec error: sankey encoding requires "${channel}" channel`,
|
|
5249
|
-
path:
|
|
5411
|
+
path: jsonPointer16("encoding", channel),
|
|
5250
5412
|
code: "MISSING_FIELD",
|
|
5251
5413
|
suggestion: `Add encoding.${channel} with a field from your data (${availableColumns}). Example: ${channel}: { field: "${columnList[0] ?? "myField"}", type: "${channel === "value" ? "quantitative" : "nominal"}" }`
|
|
5252
5414
|
});
|
|
@@ -5255,7 +5417,7 @@ function validateSankeySpec(spec, errors) {
|
|
|
5255
5417
|
if (!ch.field || typeof ch.field !== "string") {
|
|
5256
5418
|
errors.push({
|
|
5257
5419
|
message: `Spec error: encoding.${channel} must have a "field" string`,
|
|
5258
|
-
path:
|
|
5420
|
+
path: jsonPointer16("encoding", channel, "field"),
|
|
5259
5421
|
code: "MISSING_FIELD",
|
|
5260
5422
|
suggestion: `Add a field name from your data columns: ${availableColumns}`
|
|
5261
5423
|
});
|
|
@@ -5264,7 +5426,7 @@ function validateSankeySpec(spec, errors) {
|
|
|
5264
5426
|
if (!dataColumns.has(ch.field)) {
|
|
5265
5427
|
errors.push({
|
|
5266
5428
|
message: `Spec error: encoding.${channel}.field "${ch.field}" does not exist in data. Available columns: ${availableColumns}`,
|
|
5267
|
-
path:
|
|
5429
|
+
path: jsonPointer16("encoding", channel, "field"),
|
|
5268
5430
|
code: "DATA_FIELD_MISSING",
|
|
5269
5431
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(ch.field, columnList)}`
|
|
5270
5432
|
});
|
|
@@ -5294,7 +5456,7 @@ function validateSankeyOverrides(overrides, errors) {
|
|
|
5294
5456
|
if (!breakpoints.includes(breakpoint)) {
|
|
5295
5457
|
errors.push({
|
|
5296
5458
|
message: `Spec error: sankey overrides has unknown breakpoint "${breakpoint}"`,
|
|
5297
|
-
path:
|
|
5459
|
+
path: jsonPointer16("overrides", breakpoint),
|
|
5298
5460
|
code: "INVALID_VALUE",
|
|
5299
5461
|
suggestion: `Valid breakpoints: compact (under 400px), medium (400 to 700px).${didYouMean(breakpoint, [...breakpoints])}`
|
|
5300
5462
|
});
|
|
@@ -5303,7 +5465,7 @@ function validateSankeyOverrides(overrides, errors) {
|
|
|
5303
5465
|
if (!isPlainObject2(block)) {
|
|
5304
5466
|
errors.push({
|
|
5305
5467
|
message: `Spec error: overrides.${breakpoint} must be an object`,
|
|
5306
|
-
path:
|
|
5468
|
+
path: jsonPointer16("overrides", breakpoint),
|
|
5307
5469
|
code: "INVALID_TYPE",
|
|
5308
5470
|
suggestion: `Use overrides.${breakpoint}: { other: 0.05 }`
|
|
5309
5471
|
});
|
|
@@ -5333,7 +5495,7 @@ var OVERRIDE_FIELD_CHECKS = {
|
|
|
5333
5495
|
function validateOverrideBlock(breakpoint, block, errors) {
|
|
5334
5496
|
const fields = SANKEY_OVERRIDE_FIELDS;
|
|
5335
5497
|
for (const [field, value] of Object.entries(block)) {
|
|
5336
|
-
const path =
|
|
5498
|
+
const path = jsonPointer16("overrides", breakpoint, field);
|
|
5337
5499
|
if (!fields.includes(field)) {
|
|
5338
5500
|
errors.push({
|
|
5339
5501
|
message: `Spec error: overrides.${breakpoint} cannot set "${field}"`,
|
|
@@ -5356,7 +5518,7 @@ function validateOverrideBlock(breakpoint, block, errors) {
|
|
|
5356
5518
|
}
|
|
5357
5519
|
|
|
5358
5520
|
// src/compiler/validation/table.ts
|
|
5359
|
-
import { jsonPointer as
|
|
5521
|
+
import { jsonPointer as jsonPointer17 } from "@opendata-ai/openchart-core";
|
|
5360
5522
|
function validateTableSpec(spec, errors) {
|
|
5361
5523
|
if (!Array.isArray(spec.data)) {
|
|
5362
5524
|
errors.push({
|
|
@@ -5405,7 +5567,7 @@ function validateTableSpec(spec, errors) {
|
|
|
5405
5567
|
if (!col || typeof col !== "object") {
|
|
5406
5568
|
errors.push({
|
|
5407
5569
|
message: `Spec error: columns[${i}] must be an object`,
|
|
5408
|
-
path:
|
|
5570
|
+
path: jsonPointer17("columns", i),
|
|
5409
5571
|
code: "INVALID_TYPE",
|
|
5410
5572
|
suggestion: 'Each column entry should be an object, e.g. { key: "fieldName" }'
|
|
5411
5573
|
});
|
|
@@ -5414,7 +5576,7 @@ function validateTableSpec(spec, errors) {
|
|
|
5414
5576
|
if (!col.key || typeof col.key !== "string") {
|
|
5415
5577
|
errors.push({
|
|
5416
5578
|
message: `Spec error: columns[${i}] must have a "key" string`,
|
|
5417
|
-
path:
|
|
5579
|
+
path: jsonPointer17("columns", i, "key"),
|
|
5418
5580
|
code: "MISSING_FIELD",
|
|
5419
5581
|
suggestion: `Add a key referencing a data field. Available columns: ${availableColumns}`
|
|
5420
5582
|
});
|
|
@@ -5423,7 +5585,7 @@ function validateTableSpec(spec, errors) {
|
|
|
5423
5585
|
if (!dataColumns.has(col.key)) {
|
|
5424
5586
|
errors.push({
|
|
5425
5587
|
message: `Spec error: columns[${i}].key "${col.key}" does not exist in data. Available columns: ${availableColumns}`,
|
|
5426
|
-
path:
|
|
5588
|
+
path: jsonPointer17("columns", i, "key"),
|
|
5427
5589
|
code: "DATA_FIELD_MISSING",
|
|
5428
5590
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(col.key, columnList)}`
|
|
5429
5591
|
});
|
|
@@ -5434,7 +5596,7 @@ function validateTableSpec(spec, errors) {
|
|
|
5434
5596
|
if (visuals.length > 1) {
|
|
5435
5597
|
errors.push({
|
|
5436
5598
|
message: `Spec error: columns[${i}] has multiple visual features (${visuals.join(", ")}). Only one is allowed per column.`,
|
|
5437
|
-
path:
|
|
5599
|
+
path: jsonPointer17("columns", i),
|
|
5438
5600
|
code: "INVALID_VALUE",
|
|
5439
5601
|
suggestion: `Keep only one visual feature per column. Remove all but one of: ${visuals.join(", ")}`
|
|
5440
5602
|
});
|
|
@@ -5443,7 +5605,7 @@ function validateTableSpec(spec, errors) {
|
|
|
5443
5605
|
}
|
|
5444
5606
|
|
|
5445
5607
|
// src/compiler/validation/tilemap.ts
|
|
5446
|
-
import { jsonPointer as
|
|
5608
|
+
import { jsonPointer as jsonPointer18 } from "@opendata-ai/openchart-core";
|
|
5447
5609
|
function validateTileMapSpec(spec, errors) {
|
|
5448
5610
|
validateTileMapTime(spec, errors);
|
|
5449
5611
|
if (!spec.data || typeof spec.data !== "object") {
|
|
@@ -5502,7 +5664,7 @@ function validateTileMapSpec(spec, errors) {
|
|
|
5502
5664
|
if (!ch || typeof ch !== "object") {
|
|
5503
5665
|
errors.push({
|
|
5504
5666
|
message: `Spec error: tilemap encoding requires "${channel}" channel`,
|
|
5505
|
-
path:
|
|
5667
|
+
path: jsonPointer18("encoding", channel),
|
|
5506
5668
|
code: "MISSING_FIELD",
|
|
5507
5669
|
suggestion: `Add encoding.${channel} with a field from your data (${availableColumns}). Example: ${channel}: { field: "${columnList[0] ?? "myField"}", type: "${channel === "value" ? "quantitative" : "nominal"}" }`
|
|
5508
5670
|
});
|
|
@@ -5511,7 +5673,7 @@ function validateTileMapSpec(spec, errors) {
|
|
|
5511
5673
|
if (!ch.field || typeof ch.field !== "string") {
|
|
5512
5674
|
errors.push({
|
|
5513
5675
|
message: `Spec error: encoding.${channel} must have a "field" string`,
|
|
5514
|
-
path:
|
|
5676
|
+
path: jsonPointer18("encoding", channel, "field"),
|
|
5515
5677
|
code: "MISSING_FIELD",
|
|
5516
5678
|
suggestion: `Add a field name from your data columns: ${availableColumns}`
|
|
5517
5679
|
});
|
|
@@ -5520,7 +5682,7 @@ function validateTileMapSpec(spec, errors) {
|
|
|
5520
5682
|
if (!dataColumns.has(ch.field)) {
|
|
5521
5683
|
errors.push({
|
|
5522
5684
|
message: `Spec error: encoding.${channel}.field "${ch.field}" does not exist in data. Available columns: ${availableColumns}`,
|
|
5523
|
-
path:
|
|
5685
|
+
path: jsonPointer18("encoding", channel, "field"),
|
|
5524
5686
|
code: "DATA_FIELD_MISSING",
|
|
5525
5687
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(ch.field, columnList)}`
|
|
5526
5688
|
});
|
|
@@ -5557,7 +5719,7 @@ function validateAnnotationLayout(spec, errors, prefix = "") {
|
|
|
5557
5719
|
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
|
|
5558
5720
|
errors.push({
|
|
5559
5721
|
code: "INVALID_VALUE",
|
|
5560
|
-
path: `${prefix}${
|
|
5722
|
+
path: `${prefix}${jsonPointer19("annotations", index, field)}`,
|
|
5561
5723
|
message: `${field} must be a positive finite number`,
|
|
5562
5724
|
suggestion: field === "maxWidth" ? "Use null for unlimited width." : "Omit subtitleFontSize to use the default ratio."
|
|
5563
5725
|
});
|
|
@@ -5565,7 +5727,7 @@ function validateAnnotationLayout(spec, errors, prefix = "") {
|
|
|
5565
5727
|
if (annotation?.labelPlacement !== void 0 && !["auto", "start", "end", "outside"].includes(annotation.labelPlacement))
|
|
5566
5728
|
errors.push({
|
|
5567
5729
|
code: "INVALID_VALUE",
|
|
5568
|
-
path: `${prefix}${
|
|
5730
|
+
path: `${prefix}${jsonPointer19("annotations", index, "labelPlacement")}`,
|
|
5569
5731
|
message: "Unknown reference label placement",
|
|
5570
5732
|
suggestion: "Use auto, start, end or outside."
|
|
5571
5733
|
});
|
|
@@ -5573,7 +5735,7 @@ function validateAnnotationLayout(spec, errors, prefix = "") {
|
|
|
5573
5735
|
if (bend !== void 0 && (typeof bend !== "number" || !Number.isFinite(bend) || bend < -1 || bend > 1)) {
|
|
5574
5736
|
errors.push({
|
|
5575
5737
|
code: "INVALID_VALUE",
|
|
5576
|
-
path: `${prefix}${
|
|
5738
|
+
path: `${prefix}${jsonPointer19("annotations", index, "connector", "bend")}`,
|
|
5577
5739
|
message: "Connector bend must be a finite number between -1 and 1",
|
|
5578
5740
|
suggestion: "Omit bend for the automatic curve, or use a number in [-1, 1]."
|
|
5579
5741
|
});
|
|
@@ -5605,6 +5767,7 @@ ${details}`);
|
|
|
5605
5767
|
function validateCommonSpecFields(obj, errors) {
|
|
5606
5768
|
errors.push(...collectRemovedSpecErrors(obj));
|
|
5607
5769
|
validateAnnotationLayout(obj, errors);
|
|
5770
|
+
validateChromeLinks(obj, errors);
|
|
5608
5771
|
validateFieldMetadata(obj, errors);
|
|
5609
5772
|
if (obj.chrome !== void 0) {
|
|
5610
5773
|
const chrome = obj.chrome;
|
|
@@ -5621,7 +5784,7 @@ function validateCommonSpecFields(obj, errors) {
|
|
|
5621
5784
|
if (value === void 0) continue;
|
|
5622
5785
|
if (typeof value !== "string" && (!value || typeof value !== "object" || Array.isArray(value) || typeof value.text !== "string")) {
|
|
5623
5786
|
errors.push({
|
|
5624
|
-
path:
|
|
5787
|
+
path: jsonPointer19("chrome", key),
|
|
5625
5788
|
code: "INVALID_TYPE",
|
|
5626
5789
|
message: `${key} must be text or an object with a string text property.`,
|
|
5627
5790
|
suggestion: "Preserve authored styling in the object and provide text as a string."
|
|
@@ -5664,7 +5827,7 @@ function validateSpecShape(spec) {
|
|
|
5664
5827
|
errors: [
|
|
5665
5828
|
{
|
|
5666
5829
|
message: `Spec error: "${key}" composition is not supported`,
|
|
5667
|
-
path:
|
|
5830
|
+
path: jsonPointer19(key),
|
|
5668
5831
|
code: "INVALID_VALUE",
|
|
5669
5832
|
suggestion: "Render each chart in its own container instead. For small multiples of the same chart, use the facet encoding channel: encoding.facet = { field, type }"
|
|
5670
5833
|
}
|
|
@@ -8438,11 +8601,16 @@ function resolveRangeAnnotation(annotation, scales, chartArea, isDark, fontFamil
|
|
|
8438
8601
|
width = Math.abs(x2px - x1px);
|
|
8439
8602
|
}
|
|
8440
8603
|
if (annotation.y1 !== void 0 && annotation.y2 !== void 0) {
|
|
8441
|
-
const
|
|
8442
|
-
|
|
8443
|
-
|
|
8444
|
-
|
|
8445
|
-
|
|
8604
|
+
const edges = [
|
|
8605
|
+
resolveEdge(annotation.y1, scales.y, "start"),
|
|
8606
|
+
resolveEdge(annotation.y1, scales.y, "end"),
|
|
8607
|
+
resolveEdge(annotation.y2, scales.y, "start"),
|
|
8608
|
+
resolveEdge(annotation.y2, scales.y, "end")
|
|
8609
|
+
];
|
|
8610
|
+
if (edges.some((edge) => edge === null)) return null;
|
|
8611
|
+
const positions = edges.filter((edge) => edge !== null);
|
|
8612
|
+
y = Math.min(...positions);
|
|
8613
|
+
height = Math.max(...positions) - y;
|
|
8446
8614
|
}
|
|
8447
8615
|
const rect = { x, y, width, height };
|
|
8448
8616
|
let label;
|
|
@@ -8636,6 +8804,9 @@ function computeAnnotations(spec, ctx) {
|
|
|
8636
8804
|
...sourceAnnotation,
|
|
8637
8805
|
maxWidth: sourceAnnotation.maxWidth === void 0 ? defaultCalloutMaxWidth(sourceAnnotation, ctx) : sourceAnnotation.maxWidth
|
|
8638
8806
|
} : { ...sourceAnnotation, fontSize: sourceAnnotation.fontSize ?? ctx.smallFontSize ?? 12 };
|
|
8807
|
+
if (annotation.responsive === "hide" && ctx.strategy.annotationPosition === "tooltip-only") {
|
|
8808
|
+
continue;
|
|
8809
|
+
}
|
|
8639
8810
|
if (isCompact && annotation.responsive !== false) {
|
|
8640
8811
|
continue;
|
|
8641
8812
|
}
|
|
@@ -8726,6 +8897,8 @@ function computeAnnotations(spec, ctx) {
|
|
|
8726
8897
|
nudgeRefLineLabel(resolved, annotation, ctx.obstacles, ctx.chartArea, ctx.measure);
|
|
8727
8898
|
}
|
|
8728
8899
|
annotations.push(resolved);
|
|
8900
|
+
} else {
|
|
8901
|
+
ctx.onUnplaced?.(specIndex);
|
|
8729
8902
|
}
|
|
8730
8903
|
}
|
|
8731
8904
|
if (autoQueue.length > 0 && ctx.svg.width > 0 && ctx.svg.height > 0) {
|
|
@@ -9151,6 +9324,17 @@ function filterByDensity(marks, density) {
|
|
|
9151
9324
|
return marks;
|
|
9152
9325
|
}
|
|
9153
9326
|
|
|
9327
|
+
// src/charts/_shared/highlight-filter.ts
|
|
9328
|
+
function filterHighlighted(marks, highlight, colorField) {
|
|
9329
|
+
if (!highlight?.length) return marks;
|
|
9330
|
+
const selected = new Set(highlight);
|
|
9331
|
+
return marks.filter((mark) => {
|
|
9332
|
+
const series = "seriesKey" in mark ? mark.seriesKey : void 0;
|
|
9333
|
+
const value = colorField && !Array.isArray(mark.data) ? mark.data?.[colorField] : void 0;
|
|
9334
|
+
return selected.has(series ?? String(value));
|
|
9335
|
+
});
|
|
9336
|
+
}
|
|
9337
|
+
|
|
9154
9338
|
// src/charts/bar/mirror-labels.ts
|
|
9155
9339
|
var GUTTER_PADDING = 8;
|
|
9156
9340
|
var HALF_LABEL_GAP = 8;
|
|
@@ -9173,7 +9357,9 @@ function attachValueLabels(rects, spec, xField, leftSeries, theme) {
|
|
|
9173
9357
|
values: spec.data.map((row) => row[xField])
|
|
9174
9358
|
});
|
|
9175
9359
|
const fontSize = spec.labels.fontSize ?? VALUE_LABEL_FONT_SIZE;
|
|
9176
|
-
|
|
9360
|
+
const color = spec.encoding.color;
|
|
9361
|
+
const candidates = spec.labels.highlightedOnly ? filterHighlighted(rects, spec.highlight, color && "field" in color ? color.field : void 0) : rects;
|
|
9362
|
+
for (const mark of filterByDensity(candidates, spec.labels.density)) {
|
|
9177
9363
|
const onLeft = mark.seriesKey === leftSeries;
|
|
9178
9364
|
const text = `${spec.labels.prefix ?? ""}${format2(Number(mark.data[xField]))}${spec.labels.suffix ?? ""}`;
|
|
9179
9365
|
const label = {
|
|
@@ -9265,11 +9451,14 @@ function planBarLabels(spec, theme, options) {
|
|
|
9265
9451
|
const channel = horizontal ? spec.encoding.x : spec.encoding.y;
|
|
9266
9452
|
if (!channel || !("field" in channel)) return empty;
|
|
9267
9453
|
const field = channel.field;
|
|
9268
|
-
const
|
|
9454
|
+
const color = spec.encoding.color;
|
|
9455
|
+
const highlight = spec.labels.highlightedOnly ? spec.highlight : void 0;
|
|
9456
|
+
const rows = highlight?.length && color && "field" in color ? spec.data.filter((row) => highlight.includes(String(row[color.field]))) : spec.data;
|
|
9457
|
+
const values = rows.map((row) => finiteNumber(row[field])).filter((value) => value !== void 0);
|
|
9269
9458
|
const format2 = resolveFieldFormatter({
|
|
9270
9459
|
surfaceFormat: spec.labels.format,
|
|
9271
9460
|
channelFormat: "format" in channel ? channel.format : void 0,
|
|
9272
|
-
values
|
|
9461
|
+
values: spec.data.map((row) => row[field])
|
|
9273
9462
|
});
|
|
9274
9463
|
const fontSize = spec.labels.fontSize ?? (horizontal ? 11 : 10);
|
|
9275
9464
|
let maxWidth = 0;
|
|
@@ -9354,6 +9543,68 @@ import {
|
|
|
9354
9543
|
formatDate as formatDate2,
|
|
9355
9544
|
resolveNumberFormatter as resolveNumberFormatter2
|
|
9356
9545
|
} from "@opendata-ai/openchart-core";
|
|
9546
|
+
|
|
9547
|
+
// src/layout/axes/tick-step.ts
|
|
9548
|
+
import {
|
|
9549
|
+
timeDay,
|
|
9550
|
+
timeHour,
|
|
9551
|
+
timeMinute,
|
|
9552
|
+
timeMonth,
|
|
9553
|
+
timeWeek,
|
|
9554
|
+
timeYear,
|
|
9555
|
+
utcDay,
|
|
9556
|
+
utcHour,
|
|
9557
|
+
utcMinute,
|
|
9558
|
+
utcMonth,
|
|
9559
|
+
utcWeek,
|
|
9560
|
+
utcYear
|
|
9561
|
+
} from "d3-time";
|
|
9562
|
+
function stepTicks(scale, step, scaleType) {
|
|
9563
|
+
const domain = scale.domain();
|
|
9564
|
+
const d0 = Number(domain[0]);
|
|
9565
|
+
const d1 = Number(domain[domain.length - 1]);
|
|
9566
|
+
if (!Number.isFinite(d0) || !Number.isFinite(d1)) return null;
|
|
9567
|
+
if (typeof step === "number") {
|
|
9568
|
+
if (!Number.isFinite(step) || step <= 0) return null;
|
|
9569
|
+
const start = Math.ceil(d0 / step - 1e-9) * step;
|
|
9570
|
+
const count = Math.floor((d1 + step * 1e-9 - start) / step) + 1;
|
|
9571
|
+
if (!Number.isFinite(start) || count > 100) return null;
|
|
9572
|
+
return Array.from(
|
|
9573
|
+
{ length: Math.max(0, count) },
|
|
9574
|
+
(_, k) => Number((start + k * step).toPrecision(12))
|
|
9575
|
+
);
|
|
9576
|
+
}
|
|
9577
|
+
const utc = scaleType === "utc";
|
|
9578
|
+
const intervals = {
|
|
9579
|
+
year: utc ? utcYear : timeYear,
|
|
9580
|
+
quarter: utc ? utcMonth : timeMonth,
|
|
9581
|
+
month: utc ? utcMonth : timeMonth,
|
|
9582
|
+
week: utc ? utcWeek : timeWeek,
|
|
9583
|
+
day: utc ? utcDay : timeDay,
|
|
9584
|
+
hour: utc ? utcHour : timeHour,
|
|
9585
|
+
minute: utc ? utcMinute : timeMinute
|
|
9586
|
+
};
|
|
9587
|
+
const interval = intervals[step.interval]?.every(
|
|
9588
|
+
(step.step ?? 1) * (step.interval === "quarter" ? 3 : 1)
|
|
9589
|
+
);
|
|
9590
|
+
if (!interval) return null;
|
|
9591
|
+
const values = [];
|
|
9592
|
+
for (let date = interval.ceil(new Date(d0)); +date <= d1; date = interval.offset(date, 1)) {
|
|
9593
|
+
values.push(date);
|
|
9594
|
+
if (values.length > 100) return null;
|
|
9595
|
+
}
|
|
9596
|
+
return values;
|
|
9597
|
+
}
|
|
9598
|
+
|
|
9599
|
+
// src/layout/axes/ticks.ts
|
|
9600
|
+
function resolveStepTicks(resolvedScale) {
|
|
9601
|
+
const config = resolvedScale.channel.axis;
|
|
9602
|
+
if (!config || config.tickStep === void 0 || resolvedScale.type === "sequential") return null;
|
|
9603
|
+
const scale = resolvedScale.scale;
|
|
9604
|
+
if (!("ticks" in scale) || !("invert" in scale)) return null;
|
|
9605
|
+
const values = stepTicks(scale, config.tickStep, resolvedScale.type);
|
|
9606
|
+
return values === null ? null : resolveExplicitTicks(values, resolvedScale);
|
|
9607
|
+
}
|
|
9357
9608
|
var Y_PX_PER_TICK = {
|
|
9358
9609
|
full: 40,
|
|
9359
9610
|
reduced: 70,
|
|
@@ -9399,12 +9650,13 @@ var TEMPORAL_SCALE_TYPES = /* @__PURE__ */ new Set(["time", "utc"]);
|
|
|
9399
9650
|
function formatTickLabel(value, resolvedScale, compact = false, tickContext) {
|
|
9400
9651
|
const axisConfig = resolvedScale.channel.axis || void 0;
|
|
9401
9652
|
const formatStr = axisConfig?.format;
|
|
9653
|
+
const prefix = axisConfig?.labelPrefix ?? "";
|
|
9402
9654
|
const suffix = axisConfig?.labelSuffix ?? "";
|
|
9403
9655
|
if (TEMPORAL_SCALE_TYPES.has(resolvedScale.type)) {
|
|
9404
9656
|
const temporalFmt = buildTemporalFormatter2(formatStr);
|
|
9405
|
-
if (temporalFmt) return temporalFmt(value) + suffix;
|
|
9657
|
+
if (temporalFmt) return prefix + temporalFmt(value) + suffix;
|
|
9406
9658
|
const useUtc = resolvedScale.type === "utc";
|
|
9407
|
-
return formatDate2(value, void 0, void 0, useUtc, compact) + suffix;
|
|
9659
|
+
return prefix + formatDate2(value, void 0, void 0, useUtc, compact) + suffix;
|
|
9408
9660
|
}
|
|
9409
9661
|
if (NUMERIC_SCALE_TYPES.has(resolvedScale.type)) {
|
|
9410
9662
|
const num = value;
|
|
@@ -9415,7 +9667,7 @@ function formatTickLabel(value, resolvedScale, compact = false, tickContext) {
|
|
|
9415
9667
|
stepReference: tickContext?.maxAbsTick
|
|
9416
9668
|
};
|
|
9417
9669
|
const fmt3 = resolveNumberFormatter2(formatStr, ctx);
|
|
9418
|
-
if (fmt3) return fmt3(num) + suffix;
|
|
9670
|
+
if (fmt3) return prefix + fmt3(num) + suffix;
|
|
9419
9671
|
}
|
|
9420
9672
|
const fmt2 = resolveFieldFormatter({
|
|
9421
9673
|
channelFormat: resolvedScale.channel.format,
|
|
@@ -9425,9 +9677,9 @@ function formatTickLabel(value, resolvedScale, compact = false, tickContext) {
|
|
|
9425
9677
|
stepReference: tickContext?.maxAbsTick
|
|
9426
9678
|
}
|
|
9427
9679
|
});
|
|
9428
|
-
return fmt2(num) + suffix;
|
|
9680
|
+
return prefix + fmt2(num) + suffix;
|
|
9429
9681
|
}
|
|
9430
|
-
return String(value) + suffix;
|
|
9682
|
+
return prefix + String(value) + suffix;
|
|
9431
9683
|
}
|
|
9432
9684
|
function computeTickContext(ticks) {
|
|
9433
9685
|
if (ticks.length < 2) return void 0;
|
|
@@ -9550,7 +9802,7 @@ function categoricalTicks(resolvedScale, density, orientation = "horizontal", su
|
|
|
9550
9802
|
const tick = {
|
|
9551
9803
|
value,
|
|
9552
9804
|
position: pos,
|
|
9553
|
-
label: value
|
|
9805
|
+
label: formatTickLabel(value, resolvedScale)
|
|
9554
9806
|
};
|
|
9555
9807
|
if (subtitleMap) {
|
|
9556
9808
|
const subtitle = subtitleMap.get(value);
|
|
@@ -9926,7 +10178,7 @@ function isConditionalValueDef(def) {
|
|
|
9926
10178
|
import { scaleBand } from "d3-scale";
|
|
9927
10179
|
|
|
9928
10180
|
// src/layout/temporal-interval.ts
|
|
9929
|
-
import { timeDay, timeMonth, timeWeek, utcDay, utcMonth, utcWeek } from "d3-time";
|
|
10181
|
+
import { timeDay as timeDay2, timeMonth as timeMonth2, timeWeek as timeWeek2, utcDay as utcDay2, utcMonth as utcMonth2, utcWeek as utcWeek2 } from "d3-time";
|
|
9930
10182
|
var MONTHS = { month: 1, quarter: 3, year: 12 };
|
|
9931
10183
|
var INFERABLE_UNITS = ["year", "quarter", "month", "week", "day"];
|
|
9932
10184
|
var MIN_CALENDAR_DAY = 23 * 36e5;
|
|
@@ -9934,9 +10186,9 @@ function temporalDate(value) {
|
|
|
9934
10186
|
return value instanceof Date ? value : new Date(String(value));
|
|
9935
10187
|
}
|
|
9936
10188
|
function calendarFor(mode) {
|
|
9937
|
-
const day = mode === "utc" ?
|
|
9938
|
-
const week = mode === "utc" ?
|
|
9939
|
-
const month = mode === "utc" ?
|
|
10189
|
+
const day = mode === "utc" ? utcDay2 : timeDay2;
|
|
10190
|
+
const week = mode === "utc" ? utcWeek2 : timeWeek2;
|
|
10191
|
+
const month = mode === "utc" ? utcMonth2 : timeMonth2;
|
|
9940
10192
|
const addMonths = (date, months) => {
|
|
9941
10193
|
const start = month.floor(date);
|
|
9942
10194
|
const target = month.offset(start, months);
|
|
@@ -10581,8 +10833,10 @@ var barRenderer = (spec, scales, chartArea, strategy, theme, containerWidth, lab
|
|
|
10581
10833
|
return total > 0 ? Number(mark.data[valueField]) / total : 0;
|
|
10582
10834
|
}) : valueField ? spec.data.map((r) => r[valueField]) : []
|
|
10583
10835
|
});
|
|
10836
|
+
const color = spec.encoding.color;
|
|
10837
|
+
const targetMarks = spec.labels.highlightedOnly ? filterHighlighted(marks, spec.highlight, color && "field" in color ? color.field : void 0) : marks;
|
|
10584
10838
|
const labels = computeBarLabels(
|
|
10585
|
-
|
|
10839
|
+
targetMarks,
|
|
10586
10840
|
chartArea,
|
|
10587
10841
|
spec.labels.density,
|
|
10588
10842
|
labelFormatter,
|
|
@@ -10602,7 +10856,7 @@ var barRenderer = (spec, scales, chartArea, strategy, theme, containerWidth, lab
|
|
|
10602
10856
|
measureText: spec.labels.placement ? measureText : void 0
|
|
10603
10857
|
}
|
|
10604
10858
|
);
|
|
10605
|
-
const labelMarks =
|
|
10859
|
+
const labelMarks = filterByDensity(targetMarks, spec.labels.density);
|
|
10606
10860
|
for (let i = 0; i < labelMarks.length && i < labels.length; i++) {
|
|
10607
10861
|
labelMarks[i].label = labels[i];
|
|
10608
10862
|
}
|
|
@@ -10955,7 +11209,7 @@ var binnedBarRenderer = (spec, scales, chartArea, strategy, theme) => computeBin
|
|
|
10955
11209
|
|
|
10956
11210
|
// src/charts/calendar/compute.ts
|
|
10957
11211
|
import { defaultNumberFormatter as defaultNumberFormatter3, formatDate as formatDate3 } from "@opendata-ai/openchart-core";
|
|
10958
|
-
import { utcDay as
|
|
11212
|
+
import { utcDay as utcDay3, utcMonday, utcSunday } from "d3-time";
|
|
10959
11213
|
var MIN_CELL_SIZE = 7;
|
|
10960
11214
|
var MAX_STEP = 20;
|
|
10961
11215
|
var MIN_CELL_GAP = 2;
|
|
@@ -10986,7 +11240,7 @@ function parseUtcDay(value) {
|
|
|
10986
11240
|
if (value == null) return null;
|
|
10987
11241
|
const date = value instanceof Date ? value : new Date(value);
|
|
10988
11242
|
if (Number.isNaN(date.getTime())) return null;
|
|
10989
|
-
return
|
|
11243
|
+
return utcDay3.floor(date);
|
|
10990
11244
|
}
|
|
10991
11245
|
function isoDayKey(day) {
|
|
10992
11246
|
return day.toISOString().slice(0, 10);
|
|
@@ -11104,7 +11358,7 @@ function computeCalendarMarks(spec, scales, chartArea, theme) {
|
|
|
11104
11358
|
aria: labelAria
|
|
11105
11359
|
});
|
|
11106
11360
|
}
|
|
11107
|
-
for (const day of
|
|
11361
|
+
for (const day of utcDay3.range(yearStart, yearEnd)) {
|
|
11108
11362
|
const col = week.count(firstWeek, day);
|
|
11109
11363
|
const row = weekdayRow(day, weekStart);
|
|
11110
11364
|
const key = isoDayKey(day);
|
|
@@ -11164,6 +11418,10 @@ function applyStackSeams2(marks, theme) {
|
|
|
11164
11418
|
}
|
|
11165
11419
|
}
|
|
11166
11420
|
var MIN_COLUMN_HEIGHT = 1;
|
|
11421
|
+
function columnStackMode(stack2) {
|
|
11422
|
+
if (stack2 === null || stack2 === false) return null;
|
|
11423
|
+
return stack2 === "normalize" || stack2 === "center" ? stack2 : "zero";
|
|
11424
|
+
}
|
|
11167
11425
|
function computeColumnMarks(spec, scales, _chartArea, _strategy, theme, grouping) {
|
|
11168
11426
|
const encoding = spec.encoding;
|
|
11169
11427
|
const xChannel = encoding.x;
|
|
@@ -11204,8 +11462,8 @@ function computeColumnMarks(spec, scales, _chartArea, _strategy, theme, grouping
|
|
|
11204
11462
|
const categoryGroups = groupByField(spec.data, xChannel.field);
|
|
11205
11463
|
const needsStacking = grouping?.multipleRows || yChannel.stack === "normalize" || yChannel.stack === "center" || Array.from(categoryGroups.values()).some((rows) => rows.length > 1);
|
|
11206
11464
|
if (needsStacking) {
|
|
11207
|
-
const
|
|
11208
|
-
if (
|
|
11465
|
+
const stackMode = columnStackMode(yChannel.stack);
|
|
11466
|
+
if (stackMode === null) {
|
|
11209
11467
|
marks = computeGroupedColumns(
|
|
11210
11468
|
measuredData,
|
|
11211
11469
|
xChannel.field,
|
|
@@ -11219,7 +11477,6 @@ function computeColumnMarks(spec, scales, _chartArea, _strategy, theme, grouping
|
|
|
11219
11477
|
grouping?.order
|
|
11220
11478
|
);
|
|
11221
11479
|
} else {
|
|
11222
|
-
const stackMode = yChannel.stack === "normalize" ? "normalize" : yChannel.stack === "center" ? "center" : "zero";
|
|
11223
11480
|
marks = computeStackedColumns(
|
|
11224
11481
|
measuredData,
|
|
11225
11482
|
xChannel.field,
|
|
@@ -11641,8 +11898,10 @@ var columnRenderer = (spec, scales, chartArea, strategy, theme, _containerWidth,
|
|
|
11641
11898
|
return total > 0 ? Number(mark.data[valueField]) / total : 0;
|
|
11642
11899
|
}) : valueField ? spec.data.map((r) => r[valueField]) : []
|
|
11643
11900
|
});
|
|
11901
|
+
const color = spec.encoding.color;
|
|
11902
|
+
const targetMarks = spec.labels.highlightedOnly ? filterHighlighted(marks, spec.highlight, color && "field" in color ? color.field : void 0) : marks;
|
|
11644
11903
|
const labels = computeColumnLabels(
|
|
11645
|
-
|
|
11904
|
+
targetMarks,
|
|
11646
11905
|
chartArea,
|
|
11647
11906
|
spec.labels.density,
|
|
11648
11907
|
labelFormatter,
|
|
@@ -11662,7 +11921,7 @@ var columnRenderer = (spec, scales, chartArea, strategy, theme, _containerWidth,
|
|
|
11662
11921
|
measureText: spec.labels.placement ? measureText : void 0
|
|
11663
11922
|
}
|
|
11664
11923
|
);
|
|
11665
|
-
const labelMarks =
|
|
11924
|
+
const labelMarks = filterByDensity(targetMarks, spec.labels.density);
|
|
11666
11925
|
for (let i = 0; i < labelMarks.length && i < labels.length; i++) {
|
|
11667
11926
|
labelMarks[i].label = labels[i];
|
|
11668
11927
|
}
|
|
@@ -12889,6 +13148,9 @@ var parliamentRenderer = (spec, scales, chartArea, strategy, theme) => {
|
|
|
12889
13148
|
return computeParliamentMarks(spec, scales, chartArea, strategy, theme);
|
|
12890
13149
|
};
|
|
12891
13150
|
|
|
13151
|
+
// src/charts/pie/index.ts
|
|
13152
|
+
import { resolveMeasurer } from "@opendata-ai/openchart-core";
|
|
13153
|
+
|
|
12892
13154
|
// src/charts/pie/compute.ts
|
|
12893
13155
|
import {
|
|
12894
13156
|
CATEGORICAL_FILL_PALETTE,
|
|
@@ -12953,7 +13215,7 @@ function computeSweepBounds(startAngle, endAngle) {
|
|
|
12953
13215
|
maxY: Math.max(...ys)
|
|
12954
13216
|
};
|
|
12955
13217
|
}
|
|
12956
|
-
function computePieMarks(spec, scales, chartArea, _strategy,
|
|
13218
|
+
function computePieMarks(spec, scales, chartArea, _strategy, innerRadiusSpec = 0, theme, leftLabelReserve = 0, rightLabelReserve = leftLabelReserve) {
|
|
12957
13219
|
const palette = theme?.colors.categoricalFill ?? DEFAULT_PALETTE;
|
|
12958
13220
|
const sliceStroke = resolveKnockoutColor(theme);
|
|
12959
13221
|
const encoding = spec.encoding;
|
|
@@ -13003,9 +13265,20 @@ function computePieMarks(spec, scales, chartArea, _strategy, isDonut = false, th
|
|
|
13003
13265
|
const sweepBounds = computeSweepBounds(startAngle, endAngle);
|
|
13004
13266
|
const sweepWidth = sweepBounds.maxX - sweepBounds.minX;
|
|
13005
13267
|
const sweepHeight = sweepBounds.maxY - sweepBounds.minY;
|
|
13006
|
-
const
|
|
13007
|
-
const
|
|
13008
|
-
const
|
|
13268
|
+
const partialSweep = Math.abs(endAngle - startAngle) < Math.PI * 2;
|
|
13269
|
+
const maxReserve = chartArea.width * (partialSweep ? 0.25 : 0.5);
|
|
13270
|
+
const leftReserve = spec.labels.density === "none" ? 0 : Math.min(leftLabelReserve, maxReserve);
|
|
13271
|
+
const rightReserve = spec.labels.density === "none" ? 0 : Math.min(rightLabelReserve, maxReserve);
|
|
13272
|
+
const availableWidth = chartArea.width - leftReserve - rightReserve;
|
|
13273
|
+
const unreservedOuter = Math.min(chartArea.width / sweepWidth, chartArea.height / sweepHeight) * 0.85;
|
|
13274
|
+
const outerRadius = Math.min(availableWidth / sweepWidth, chartArea.height / sweepHeight) * 0.85;
|
|
13275
|
+
const innerRadius = innerRadiusSpec <= 0 ? 0 : innerRadiusSpec < 1 ? outerRadius * innerRadiusSpec : Math.min(innerRadiusSpec * (outerRadius / unreservedOuter), outerRadius * 0.95);
|
|
13276
|
+
const centeredX2 = chartArea.x + chartArea.width / 2 - (sweepBounds.minX + sweepBounds.maxX) / 2 * outerRadius;
|
|
13277
|
+
const columnLeft = centeredX2 + sweepBounds.minX * outerRadius - leftReserve;
|
|
13278
|
+
const columnRight = centeredX2 + sweepBounds.maxX * outerRadius + rightReserve;
|
|
13279
|
+
const minShift = chartArea.x - columnLeft;
|
|
13280
|
+
const maxShift = chartArea.x + chartArea.width - columnRight;
|
|
13281
|
+
const centerX = centeredX2 + Math.max(minShift, Math.min(0, maxShift));
|
|
13009
13282
|
const centerY = chartArea.y + chartArea.height / 2 - (sweepBounds.minY + sweepBounds.maxY) / 2 * outerRadius;
|
|
13010
13283
|
const arcGenerator = d3Arc().innerRadius(innerRadius).outerRadius(outerRadius);
|
|
13011
13284
|
const marks = [];
|
|
@@ -13076,6 +13349,10 @@ import { estimateTextWidth as estimateTextWidth9, resolveCollisions as resolveCo
|
|
|
13076
13349
|
var LABEL_FONT_SIZE5 = 11;
|
|
13077
13350
|
var LABEL_FONT_WEIGHT5 = 500;
|
|
13078
13351
|
var LEADER_LINE_OFFSET = 12;
|
|
13352
|
+
function pieLabelReserve(texts, fontSize) {
|
|
13353
|
+
if (texts.length === 0) return 0;
|
|
13354
|
+
return Math.max(...texts.map((text) => estimateTextWidth9(text, fontSize))) + LEADER_LINE_OFFSET + 8;
|
|
13355
|
+
}
|
|
13079
13356
|
function computePieLabels(marks, _chartArea, density = "auto", _textFill = "#333333", options = {}) {
|
|
13080
13357
|
const fontFamily = options.fontFamily ?? "system-ui, -apple-system, sans-serif";
|
|
13081
13358
|
const formatValue3 = options.formatValue;
|
|
@@ -13099,7 +13376,7 @@ function computePieLabels(marks, _chartArea, density = "auto", _textFill = "#333
|
|
|
13099
13376
|
const rawValueText = openParen > firstColon ? ariaLabel.slice(firstColon + 1, openParen).trim() : "";
|
|
13100
13377
|
const rawValue = Number(rawValueText);
|
|
13101
13378
|
const valueText = formatValue3 && Number.isFinite(rawValue) ? formatValue3(rawValue) : percentText;
|
|
13102
|
-
const labelText = valueText ? `${sliceName} ${valueText}` : sliceName;
|
|
13379
|
+
const labelText = valueText ? `${sliceName} ${options.prefix ?? ""}${valueText}${options.suffix ?? ""}` : sliceName;
|
|
13103
13380
|
const textWidth2 = estimateTextWidth9(labelText, LABEL_FONT_SIZE5, LABEL_FONT_WEIGHT5);
|
|
13104
13381
|
const textHeight = LABEL_FONT_SIZE5 * 1.2;
|
|
13105
13382
|
const midAngle = (mark.startAngle + mark.endAngle) / 2;
|
|
@@ -13109,7 +13386,7 @@ function computePieLabels(marks, _chartArea, density = "auto", _textFill = "#333
|
|
|
13109
13386
|
const isRight = Math.sin(midAngle) > 0;
|
|
13110
13387
|
candidates.push({
|
|
13111
13388
|
text: labelText,
|
|
13112
|
-
anchorX:
|
|
13389
|
+
anchorX: labelX,
|
|
13113
13390
|
anchorY: labelY - textHeight / 2,
|
|
13114
13391
|
width: textWidth2,
|
|
13115
13392
|
height: textHeight,
|
|
@@ -13144,7 +13421,16 @@ function computePieLabels(marks, _chartArea, density = "auto", _textFill = "#333
|
|
|
13144
13421
|
...c.index !== void 0 ? { index: c.index } : {}
|
|
13145
13422
|
}));
|
|
13146
13423
|
} else {
|
|
13147
|
-
|
|
13424
|
+
const boxes2 = candidates.map((candidate) => {
|
|
13425
|
+
const boxLeft = candidate.style.textAnchor === "end" ? candidate.anchorX - candidate.width : candidate.anchorX;
|
|
13426
|
+
return { ...candidate, anchorX: boxLeft };
|
|
13427
|
+
});
|
|
13428
|
+
resolved = resolveCollisions4(boxes2);
|
|
13429
|
+
for (const label of resolved) {
|
|
13430
|
+
if (label.style.textAnchor === "end") {
|
|
13431
|
+
label.x += estimateTextWidth9(label.text, LABEL_FONT_SIZE5, LABEL_FONT_WEIGHT5);
|
|
13432
|
+
}
|
|
13433
|
+
}
|
|
13148
13434
|
}
|
|
13149
13435
|
for (let i = 0; i < resolved.length; i++) {
|
|
13150
13436
|
const label = resolved[i];
|
|
@@ -13164,25 +13450,82 @@ function computePieLabels(marks, _chartArea, density = "auto", _textFill = "#333
|
|
|
13164
13450
|
}
|
|
13165
13451
|
|
|
13166
13452
|
// src/charts/pie/index.ts
|
|
13453
|
+
function pieMarksWithLabels(spec, scales, chartArea, strategy, theme) {
|
|
13454
|
+
const options = pieLabelOptions(spec, theme);
|
|
13455
|
+
const innerRadius = spec.markDef.innerRadius ?? 0;
|
|
13456
|
+
let marks = computePieMarks(spec, scales, chartArea, strategy, innerRadius, theme);
|
|
13457
|
+
if (spec.labels.density !== "none") {
|
|
13458
|
+
const leftTexts = [];
|
|
13459
|
+
const rightTexts = [];
|
|
13460
|
+
for (const label of computePieLabels(marks, chartArea, "all", theme.colors.text, options)) {
|
|
13461
|
+
const mark = label.index !== void 0 ? marks[label.index] : void 0;
|
|
13462
|
+
if (!mark) continue;
|
|
13463
|
+
const isRight = Math.sin((mark.startAngle + mark.endAngle) / 2) > 0;
|
|
13464
|
+
(isRight ? rightTexts : leftTexts).push(label.text);
|
|
13465
|
+
}
|
|
13466
|
+
const fitted = computePieMarks(
|
|
13467
|
+
spec,
|
|
13468
|
+
scales,
|
|
13469
|
+
chartArea,
|
|
13470
|
+
strategy,
|
|
13471
|
+
innerRadius,
|
|
13472
|
+
theme,
|
|
13473
|
+
pieLabelReserve(leftTexts, 11),
|
|
13474
|
+
pieLabelReserve(rightTexts, 11)
|
|
13475
|
+
);
|
|
13476
|
+
if (fitted[0] && fitted[0].outerRadius < 0.15 * Math.min(chartArea.width, chartArea.height)) {
|
|
13477
|
+
return marks;
|
|
13478
|
+
}
|
|
13479
|
+
marks = fitted;
|
|
13480
|
+
}
|
|
13481
|
+
const labels = computePieLabels(
|
|
13482
|
+
marks,
|
|
13483
|
+
chartArea,
|
|
13484
|
+
spec.labels.density,
|
|
13485
|
+
theme.colors.text,
|
|
13486
|
+
options
|
|
13487
|
+
);
|
|
13488
|
+
for (const label of labels) {
|
|
13489
|
+
if (label.index !== void 0 && marks[label.index]) marks[label.index].label = label;
|
|
13490
|
+
}
|
|
13491
|
+
return marks;
|
|
13492
|
+
}
|
|
13167
13493
|
function pieLabelOptions(spec, theme) {
|
|
13494
|
+
const options = {
|
|
13495
|
+
fontFamily: theme.fonts.family,
|
|
13496
|
+
prefix: spec.labels.prefix,
|
|
13497
|
+
suffix: spec.labels.suffix
|
|
13498
|
+
};
|
|
13168
13499
|
const valueChannel = spec.encoding.y ?? spec.encoding.x;
|
|
13169
13500
|
const valueField = valueChannel && "field" in valueChannel ? valueChannel.field : void 0;
|
|
13170
|
-
if (!spec.labels.format) return
|
|
13501
|
+
if (!spec.labels.format) return options;
|
|
13171
13502
|
const formatter = resolveFieldFormatter({
|
|
13172
13503
|
surfaceFormat: spec.labels.format,
|
|
13173
13504
|
values: valueField ? spec.data.map((r) => r[valueField]) : []
|
|
13174
13505
|
});
|
|
13175
|
-
return {
|
|
13506
|
+
return { ...options, formatValue: formatter };
|
|
13176
13507
|
}
|
|
13177
|
-
function centerLabelMarks(spec, marks, theme) {
|
|
13508
|
+
function centerLabelMarks(spec, marks, theme, measureText) {
|
|
13178
13509
|
const config = spec.markDef.centerLabel;
|
|
13179
13510
|
if (!config || marks.length === 0) return [];
|
|
13180
13511
|
const text = typeof config === "string" ? config : config.text;
|
|
13181
13512
|
if (!text) return [];
|
|
13182
|
-
|
|
13513
|
+
let subtitle = typeof config === "string" ? void 0 : config.subtitle;
|
|
13183
13514
|
const { center } = marks[0];
|
|
13184
|
-
const
|
|
13515
|
+
const measure = resolveMeasurer(measureText);
|
|
13516
|
+
const availableWidth = 2 * marks[0].innerRadius * 0.8;
|
|
13517
|
+
let valueSize = theme.fonts.sizes.metricValue;
|
|
13185
13518
|
const captionSize = theme.fonts.sizes.small;
|
|
13519
|
+
const valueWidth = measure(text, valueSize, theme.fonts.weights.semibold).width;
|
|
13520
|
+
if (valueWidth > availableWidth) {
|
|
13521
|
+
if (measure(text, 11, theme.fonts.weights.semibold).width > availableWidth) return [];
|
|
13522
|
+
valueSize = Math.max(11, Math.floor(valueSize * availableWidth / valueWidth));
|
|
13523
|
+
if (measure(text, valueSize, theme.fonts.weights.semibold).width > availableWidth)
|
|
13524
|
+
valueSize = 11;
|
|
13525
|
+
}
|
|
13526
|
+
if (subtitle && measure(subtitle, captionSize, theme.fonts.weights.normal).width > availableWidth) {
|
|
13527
|
+
subtitle = void 0;
|
|
13528
|
+
}
|
|
13186
13529
|
const valueY = subtitle ? center.y - captionSize * 0.6 : center.y;
|
|
13187
13530
|
const out = [
|
|
13188
13531
|
{
|
|
@@ -13221,32 +13564,11 @@ function centerLabelMarks(spec, marks, theme) {
|
|
|
13221
13564
|
return out;
|
|
13222
13565
|
}
|
|
13223
13566
|
var pieRenderer = (spec, scales, chartArea, strategy, theme) => {
|
|
13224
|
-
|
|
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;
|
|
13567
|
+
return pieMarksWithLabels(spec, scales, chartArea, strategy, theme);
|
|
13236
13568
|
};
|
|
13237
|
-
var donutRenderer = (spec, scales, chartArea, strategy, theme) => {
|
|
13238
|
-
const marks =
|
|
13239
|
-
|
|
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)];
|
|
13569
|
+
var donutRenderer = (spec, scales, chartArea, strategy, theme, _containerWidth, _labelPlan, measureText) => {
|
|
13570
|
+
const marks = pieMarksWithLabels(spec, scales, chartArea, strategy, theme);
|
|
13571
|
+
return [...marks, ...centerLabelMarks(spec, marks, theme, measureText)];
|
|
13250
13572
|
};
|
|
13251
13573
|
|
|
13252
13574
|
// src/charts/range/compute.ts
|
|
@@ -14845,6 +15167,23 @@ function computeContinuousLegendContent(spec, theme, availableWidth) {
|
|
|
14845
15167
|
return computeContinuousLegendContentForChannel(values, colorEnc, theme, availableWidth);
|
|
14846
15168
|
}
|
|
14847
15169
|
|
|
15170
|
+
// src/layout/color-domain.ts
|
|
15171
|
+
function completeColorDomain(authored, observed) {
|
|
15172
|
+
return [...new Set([...authored, ...observed].map(String))];
|
|
15173
|
+
}
|
|
15174
|
+
|
|
15175
|
+
// src/layout/domain-ends.ts
|
|
15176
|
+
function applyDomainEnds(fitted, scale) {
|
|
15177
|
+
if (scale?.domain || scale?.domainMin === void 0 && scale?.domainMax === void 0)
|
|
15178
|
+
return fitted;
|
|
15179
|
+
const min4 = scale.domainMin ?? fitted[0];
|
|
15180
|
+
const max4 = scale.domainMax ?? fitted[1];
|
|
15181
|
+
if (min4 < max4) return [min4, max4];
|
|
15182
|
+
if (scale.domainMin === void 0) return [max4 - Math.max(Math.abs(max4) * 0.1, 1), max4];
|
|
15183
|
+
if (scale.domainMax === void 0) return [min4, min4 + Math.max(Math.abs(min4) * 0.1, 1)];
|
|
15184
|
+
return [min4, max4];
|
|
15185
|
+
}
|
|
15186
|
+
|
|
14848
15187
|
// src/layout/scales.ts
|
|
14849
15188
|
function numericFieldValues2(data, field) {
|
|
14850
15189
|
const result = [];
|
|
@@ -14928,6 +15267,18 @@ function buildUtcScale(channel, data, rangeStart, rangeEnd) {
|
|
|
14928
15267
|
applyContinuousConfig(scale, channel);
|
|
14929
15268
|
return { scale, type: "utc", channel };
|
|
14930
15269
|
}
|
|
15270
|
+
function applyQuantitativeEnds(scale, channel) {
|
|
15271
|
+
const config = channel.scale;
|
|
15272
|
+
if (config?.domain || config?.domainMin === void 0 && config?.domainMax === void 0)
|
|
15273
|
+
return;
|
|
15274
|
+
const [lo, hi] = scale.domain();
|
|
15275
|
+
scale.domain(applyDomainEnds([lo, hi], config));
|
|
15276
|
+
if (config.nice !== false) {
|
|
15277
|
+
scale.nice();
|
|
15278
|
+
const [niceLo, niceHi] = scale.domain();
|
|
15279
|
+
scale.domain(applyDomainEnds([niceLo, niceHi], config));
|
|
15280
|
+
}
|
|
15281
|
+
}
|
|
14931
15282
|
function buildLinearScale(channel, data, rangeStart, rangeEnd) {
|
|
14932
15283
|
const values = numericFieldValues2(data, channel.field);
|
|
14933
15284
|
let domainMin;
|
|
@@ -14955,6 +15306,7 @@ function buildLinearScale(channel, data, rangeStart, rangeEnd) {
|
|
|
14955
15306
|
}
|
|
14956
15307
|
}
|
|
14957
15308
|
}
|
|
15309
|
+
applyQuantitativeEnds(scale, channel);
|
|
14958
15310
|
applyContinuousConfig(scale, channel);
|
|
14959
15311
|
return { scale, type: "linear", channel };
|
|
14960
15312
|
}
|
|
@@ -14969,6 +15321,7 @@ function buildLogScale(channel, data, rangeStart, rangeEnd) {
|
|
|
14969
15321
|
if (!channel.scale?.domain && channel.scale?.nice !== false) {
|
|
14970
15322
|
scale.nice();
|
|
14971
15323
|
}
|
|
15324
|
+
applyQuantitativeEnds(scale, channel);
|
|
14972
15325
|
applyContinuousConfig(scale, channel);
|
|
14973
15326
|
return { scale, type: "log", channel };
|
|
14974
15327
|
}
|
|
@@ -14993,6 +15346,7 @@ function buildPowScale(channel, data, rangeStart, rangeEnd) {
|
|
|
14993
15346
|
if (!channel.scale?.domain && channel.scale?.nice !== false) {
|
|
14994
15347
|
scale.nice();
|
|
14995
15348
|
}
|
|
15349
|
+
applyQuantitativeEnds(scale, channel);
|
|
14996
15350
|
applyContinuousConfig(scale, channel);
|
|
14997
15351
|
return { scale, type: "pow", channel };
|
|
14998
15352
|
}
|
|
@@ -15014,6 +15368,7 @@ function buildSqrtScale(channel, data, rangeStart, rangeEnd) {
|
|
|
15014
15368
|
if (!channel.scale?.domain && channel.scale?.nice !== false) {
|
|
15015
15369
|
scale.nice();
|
|
15016
15370
|
}
|
|
15371
|
+
applyQuantitativeEnds(scale, channel);
|
|
15017
15372
|
applyContinuousConfig(scale, channel);
|
|
15018
15373
|
return { scale, type: "sqrt", channel };
|
|
15019
15374
|
}
|
|
@@ -15038,6 +15393,7 @@ function buildSymlogScale(channel, data, rangeStart, rangeEnd) {
|
|
|
15038
15393
|
if (!channel.scale?.domain && channel.scale?.nice !== false) {
|
|
15039
15394
|
scale.nice();
|
|
15040
15395
|
}
|
|
15396
|
+
applyQuantitativeEnds(scale, channel);
|
|
15041
15397
|
applyContinuousConfig(scale, channel);
|
|
15042
15398
|
return { scale, type: "symlog", channel };
|
|
15043
15399
|
}
|
|
@@ -15114,7 +15470,7 @@ function buildPointScale(channel, data, rangeStart, rangeEnd, defaultPadding = 0
|
|
|
15114
15470
|
}
|
|
15115
15471
|
function buildOrdinalColorScale(channel, data, palette) {
|
|
15116
15472
|
const explicitDomain = channel.scale?.domain;
|
|
15117
|
-
const values = explicitDomain ? explicitDomain.
|
|
15473
|
+
const values = explicitDomain ? completeColorDomain(explicitDomain, uniqueFieldStrings2(data, channel.field)) : applyCategoricalSort(uniqueFieldStrings2(data, channel.field), channel.sort);
|
|
15118
15474
|
const explicitRange = channel.scale?.range;
|
|
15119
15475
|
const colors = explicitRange ?? palette;
|
|
15120
15476
|
const scale = scaleOrdinal().domain(values).range(colors);
|
|
@@ -15255,7 +15611,11 @@ function computeScales(spec, chartArea, data) {
|
|
|
15255
15611
|
const axis = existingAxis === false || existingAxis?.format ? existingAxis : { ...typeof existingAxis === "object" ? existingAxis : {}, format: ".0%" };
|
|
15256
15612
|
xChannel = {
|
|
15257
15613
|
...encoding.x,
|
|
15258
|
-
scale: {
|
|
15614
|
+
scale: {
|
|
15615
|
+
...encoding.x.scale,
|
|
15616
|
+
domain: applyDomainEnds([0, 1], encoding.x.scale),
|
|
15617
|
+
nice: false
|
|
15618
|
+
},
|
|
15259
15619
|
axis
|
|
15260
15620
|
};
|
|
15261
15621
|
} else if (encoding.x.stack === "center") {
|
|
@@ -15277,7 +15637,11 @@ function computeScales(spec, chartArea, data) {
|
|
|
15277
15637
|
const half = maxSum / 2;
|
|
15278
15638
|
xChannel = {
|
|
15279
15639
|
...encoding.x,
|
|
15280
|
-
scale: {
|
|
15640
|
+
scale: {
|
|
15641
|
+
...encoding.x.scale,
|
|
15642
|
+
domain: applyDomainEnds([-half, half], encoding.x.scale),
|
|
15643
|
+
zero: true
|
|
15644
|
+
}
|
|
15281
15645
|
};
|
|
15282
15646
|
}
|
|
15283
15647
|
} else {
|
|
@@ -15357,7 +15721,7 @@ function computeScales(spec, chartArea, data) {
|
|
|
15357
15721
|
...encoding.y,
|
|
15358
15722
|
scale: {
|
|
15359
15723
|
...encoding.y.scale,
|
|
15360
|
-
domain: encoding.y.scale?.domain ?? [lower, upper],
|
|
15724
|
+
domain: encoding.y.scale?.domain ?? applyDomainEnds([lower, upper], encoding.y.scale),
|
|
15361
15725
|
...stackProp === "normalize" ? { nice: false } : {}
|
|
15362
15726
|
},
|
|
15363
15727
|
...stackProp === "normalize" ? {
|
|
@@ -15371,7 +15735,11 @@ function computeScales(spec, chartArea, data) {
|
|
|
15371
15735
|
const axis = existingAxis === false || existingAxis?.format ? existingAxis : { ...typeof existingAxis === "object" ? existingAxis : {}, format: ".0%" };
|
|
15372
15736
|
yChannel = {
|
|
15373
15737
|
...encoding.y,
|
|
15374
|
-
scale: {
|
|
15738
|
+
scale: {
|
|
15739
|
+
...encoding.y.scale,
|
|
15740
|
+
domain: applyDomainEnds([0, 1], encoding.y.scale),
|
|
15741
|
+
nice: false
|
|
15742
|
+
},
|
|
15375
15743
|
axis
|
|
15376
15744
|
};
|
|
15377
15745
|
} else if (encoding.y.stack === "center") {
|
|
@@ -15393,7 +15761,11 @@ function computeScales(spec, chartArea, data) {
|
|
|
15393
15761
|
const half = maxSum / 2;
|
|
15394
15762
|
yChannel = {
|
|
15395
15763
|
...encoding.y,
|
|
15396
|
-
scale: {
|
|
15764
|
+
scale: {
|
|
15765
|
+
...encoding.y.scale,
|
|
15766
|
+
domain: applyDomainEnds([-half, half], encoding.y.scale),
|
|
15767
|
+
zero: true
|
|
15768
|
+
}
|
|
15397
15769
|
};
|
|
15398
15770
|
}
|
|
15399
15771
|
} else {
|
|
@@ -15424,6 +15796,11 @@ function computeScales(spec, chartArea, data) {
|
|
|
15424
15796
|
spec.markType,
|
|
15425
15797
|
"y"
|
|
15426
15798
|
);
|
|
15799
|
+
if (result.y.type === "band" || result.y.type === "point") {
|
|
15800
|
+
const scale = result.y.scale;
|
|
15801
|
+
const [r0, r1] = scale.range();
|
|
15802
|
+
scale.range([r1, r0]);
|
|
15803
|
+
}
|
|
15427
15804
|
applyTemporalBarInterval(result.y, spec, data);
|
|
15428
15805
|
if (result.y && encoding.y.type === "quantitative" && encoding.y.field) {
|
|
15429
15806
|
result.y.formatContext = computeFieldFormatContext3(fieldIterable(data, encoding.y.field));
|
|
@@ -15531,13 +15908,37 @@ function endpointFormatter(spec, displayedValues) {
|
|
|
15531
15908
|
const axisFormat = axis && typeof axis === "object" ? axis.format : void 0;
|
|
15532
15909
|
const explicit = config?.format || axisFormat || spec.encoding.y?.format;
|
|
15533
15910
|
const fallbackFormat = !explicit && maxAbs < 1e3 && !isYearContext(context) ? `,.${Math.round(-Math.log10(step))}f` : void 0;
|
|
15534
|
-
|
|
15911
|
+
const formatter = resolveFieldFormatter({
|
|
15535
15912
|
surfaceFormat: config?.format || axisFormat || fallbackFormat,
|
|
15536
15913
|
channelFormat: spec.encoding.y?.format,
|
|
15537
15914
|
values: valueField ? spec.data.map((row) => row[valueField]) : [],
|
|
15538
15915
|
// Raw-unit precision must not turn compact magnitudes into full integers.
|
|
15539
15916
|
step: maxAbs < 1e3 ? step : void 0
|
|
15540
15917
|
});
|
|
15918
|
+
return (value) => `${config?.prefix ?? ""}${formatter(value)}${config?.suffix ?? ""}`;
|
|
15919
|
+
}
|
|
15920
|
+
|
|
15921
|
+
// src/compile/data-clip.ts
|
|
15922
|
+
function filterClippedDomains(data, encoding) {
|
|
15923
|
+
let result = data;
|
|
15924
|
+
for (const channel of ["x", "y"]) {
|
|
15925
|
+
const enc = encoding[channel];
|
|
15926
|
+
if (!enc?.scale?.clip || !enc.scale.domain) continue;
|
|
15927
|
+
const domain = enc.scale.domain;
|
|
15928
|
+
const field = enc.field;
|
|
15929
|
+
if (!Array.isArray(domain)) continue;
|
|
15930
|
+
if (domain.length === 2 && typeof domain[0] === "number") {
|
|
15931
|
+
const [lo, hi] = domain;
|
|
15932
|
+
result = result.filter((row) => {
|
|
15933
|
+
const v = Number(row[field]);
|
|
15934
|
+
return Number.isFinite(v) && v >= lo && v <= hi;
|
|
15935
|
+
});
|
|
15936
|
+
} else if (typeof domain[0] === "string") {
|
|
15937
|
+
const allowed = new Set(domain);
|
|
15938
|
+
result = result.filter((row) => allowed.has(String(row[field])));
|
|
15939
|
+
}
|
|
15940
|
+
}
|
|
15941
|
+
return result;
|
|
15541
15942
|
}
|
|
15542
15943
|
|
|
15543
15944
|
// src/endpoint-labels/source.ts
|
|
@@ -15547,14 +15948,15 @@ function endpointSourceRows(spec) {
|
|
|
15547
15948
|
const y = spec.encoding.y;
|
|
15548
15949
|
const groups = /* @__PURE__ */ new Map();
|
|
15549
15950
|
if (!field || !x || !y) return groups;
|
|
15951
|
+
const data = filterClippedDomains(spec.data, spec.encoding);
|
|
15550
15952
|
const stacked = spec.markType === "area" && y.stack !== null && y.stack !== false;
|
|
15551
15953
|
const gaps = /* @__PURE__ */ new Set();
|
|
15552
15954
|
if (stacked) {
|
|
15553
|
-
for (const row of
|
|
15955
|
+
for (const row of data) {
|
|
15554
15956
|
if (finiteNumber(row[y.field]) === void 0) gaps.add(String(row[x.field]));
|
|
15555
15957
|
}
|
|
15556
15958
|
}
|
|
15557
|
-
const rows = x.type === "nominal" || x.type === "ordinal" ?
|
|
15959
|
+
const rows = x.type === "nominal" || x.type === "ordinal" ? data : sortByField(data, x.field);
|
|
15558
15960
|
for (const row of rows) {
|
|
15559
15961
|
const xValue = row[x.field];
|
|
15560
15962
|
const positionalType = x.scale?.type;
|
|
@@ -15564,7 +15966,8 @@ function endpointSourceRows(spec) {
|
|
|
15564
15966
|
continue;
|
|
15565
15967
|
if (numeric && finiteNumber(xValue) === void 0) continue;
|
|
15566
15968
|
const name = String(row[field]);
|
|
15567
|
-
if (spec.highlight?.length && !spec.highlight.includes(name))
|
|
15969
|
+
if (spec.labels?.highlightedOnly && spec.highlight?.length && !spec.highlight.includes(name))
|
|
15970
|
+
continue;
|
|
15568
15971
|
if (row[x.field] == null || finiteNumber(row[y.field]) === void 0 || gaps.has(String(row[x.field])))
|
|
15569
15972
|
continue;
|
|
15570
15973
|
const group = groups.get(name);
|
|
@@ -15682,7 +16085,7 @@ var FILL_MARKS = /* @__PURE__ */ new Set([
|
|
|
15682
16085
|
"rect"
|
|
15683
16086
|
]);
|
|
15684
16087
|
function mutedSeriesColor(theme) {
|
|
15685
|
-
return theme.
|
|
16088
|
+
return theme.colors.muted;
|
|
15686
16089
|
}
|
|
15687
16090
|
function paletteFor(theme, markType) {
|
|
15688
16091
|
return markType && FILL_MARKS.has(markType) ? theme.colors.categoricalFill : theme.colors.categorical;
|
|
@@ -15705,13 +16108,14 @@ function paletteOverflowWarnings(domainLength, theme, markType) {
|
|
|
15705
16108
|
`[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
16109
|
];
|
|
15707
16110
|
}
|
|
15708
|
-
function categoricalColorsForDomain(domain, theme, highlight, markType) {
|
|
15709
|
-
const palette = extendPalette(paletteFor(theme, markType), domain.length);
|
|
16111
|
+
function categoricalColorsForDomain(domain, theme, highlight, markType, explicitPalette) {
|
|
16112
|
+
const palette = explicitPalette?.length ? explicitPalette : extendPalette(paletteFor(theme, markType), domain.length);
|
|
15710
16113
|
if (highlight && highlight.length > 0) {
|
|
15711
16114
|
const highlightSet = new Set(highlight);
|
|
15712
16115
|
const muted = mutedSeriesColor(theme);
|
|
15713
16116
|
return domain.map((v, i) => highlightSet.has(v) ? palette[i % palette.length] : muted);
|
|
15714
16117
|
}
|
|
16118
|
+
if (explicitPalette?.length) return explicitPalette;
|
|
15715
16119
|
const strategy = theme.seriesStrategy ?? "palette";
|
|
15716
16120
|
if (strategy !== "accent-neutral") return palette;
|
|
15717
16121
|
const count = domain.length;
|
|
@@ -15722,8 +16126,22 @@ function categoricalColorsForDomain(domain, theme, highlight, markType) {
|
|
|
15722
16126
|
}
|
|
15723
16127
|
function applyColorScaleRange(scales, encoding, theme, highlight, markType) {
|
|
15724
16128
|
if (!scales.color) return [];
|
|
15725
|
-
const
|
|
15726
|
-
if (
|
|
16129
|
+
const explicitRange = encoding.color && "field" in encoding.color ? encoding.color.scale?.range : void 0;
|
|
16130
|
+
if (explicitRange?.length) {
|
|
16131
|
+
if (highlight?.length && scales.color.type === "ordinal") {
|
|
16132
|
+
const scale = scales.color.scale;
|
|
16133
|
+
scale.range(
|
|
16134
|
+
categoricalColorsForDomain(
|
|
16135
|
+
scale.domain(),
|
|
16136
|
+
theme,
|
|
16137
|
+
highlight,
|
|
16138
|
+
markType,
|
|
16139
|
+
explicitRange.map(String)
|
|
16140
|
+
)
|
|
16141
|
+
);
|
|
16142
|
+
}
|
|
16143
|
+
return [];
|
|
16144
|
+
}
|
|
15727
16145
|
if (scales.color.type === "sequential") {
|
|
15728
16146
|
const seqStops = Object.values(theme.colors.sequential)[0] ?? theme.colors.categorical;
|
|
15729
16147
|
scales.color.scale.range([
|
|
@@ -15867,8 +16285,14 @@ function extractColorEntries(spec, theme) {
|
|
|
15867
16285
|
const explicitDomain = colorEnc.scale?.domain;
|
|
15868
16286
|
const explicitRange = colorEnc.scale?.range;
|
|
15869
16287
|
const shape = swatchShapeForType(spec.markType);
|
|
15870
|
-
const scaleDomain = explicitDomain ? explicitDomain
|
|
15871
|
-
const rawDomainColors =
|
|
16288
|
+
const scaleDomain = explicitDomain ? completeColorDomain(explicitDomain, dataValues) : applyCategoricalSort(dataValues, colorEnc.sort);
|
|
16289
|
+
const rawDomainColors = categoricalColorsForDomain(
|
|
16290
|
+
scaleDomain,
|
|
16291
|
+
theme,
|
|
16292
|
+
spec.highlight,
|
|
16293
|
+
spec.markType,
|
|
16294
|
+
explicitRange
|
|
16295
|
+
);
|
|
15872
16296
|
const domainColors = isStrokeSeriesMark(spec.markType) ? rawDomainColors.map((c) => resolveSeriesStroke(spec, c, theme)) : rawDomainColors;
|
|
15873
16297
|
const uniqueValues = explicitDomain ? [
|
|
15874
16298
|
...explicitDomain.filter((v) => dataValues.includes(v)),
|
|
@@ -16674,11 +17098,14 @@ function computeAxes(scales, chartArea, strategy, theme, measureText, dataContex
|
|
|
16674
17098
|
const isContinuousX = scales.x.type !== "band" && scales.x.type !== "point" && scales.x.type !== "ordinal";
|
|
16675
17099
|
const xTargetCount = isContinuousX ? targetTickCount(chartArea.width, xDensity, "x") : void 0;
|
|
16676
17100
|
const mirrorTicks = dataContext?.mirrorXTicks;
|
|
17101
|
+
const steppedTicks = resolveStepTicks(scales.x);
|
|
16677
17102
|
let allTicks;
|
|
16678
17103
|
if (mirrorTicks) {
|
|
16679
17104
|
allTicks = mirrorTicks;
|
|
16680
17105
|
} else if (axisConfig?.values) {
|
|
16681
17106
|
allTicks = resolveExplicitTicks(axisConfig.values, scales.x);
|
|
17107
|
+
} else if (steppedTicks !== null) {
|
|
17108
|
+
allTicks = steppedTicks;
|
|
16682
17109
|
} else if (!isContinuousX) {
|
|
16683
17110
|
allTicks = categoricalTicks(scales.x, xDensity, "horizontal");
|
|
16684
17111
|
} else {
|
|
@@ -16715,7 +17142,7 @@ function computeAxes(scales, chartArea, strategy, theme, measureText, dataContex
|
|
|
16715
17142
|
);
|
|
16716
17143
|
bandStride = bandLabelStride(maxLabelWidth, tickAngle, fontSize, anchorSpacing);
|
|
16717
17144
|
}
|
|
16718
|
-
const hasExplicitValues = !!axisConfig?.values || !!mirrorTicks;
|
|
17145
|
+
const hasExplicitValues = !!axisConfig?.values || !!mirrorTicks || steppedTicks !== null;
|
|
16719
17146
|
let ticks;
|
|
16720
17147
|
if (hasExplicitValues) {
|
|
16721
17148
|
ticks = allTicks;
|
|
@@ -16811,9 +17238,12 @@ function computeAxes(scales, chartArea, strategy, theme, measureText, dataContex
|
|
|
16811
17238
|
const axisConfig = scales.y.channel.axis;
|
|
16812
17239
|
const isContinuousY = scales.y.type !== "band" && scales.y.type !== "point" && scales.y.type !== "ordinal";
|
|
16813
17240
|
const yTargetCount = isContinuousY ? targetTickCount(chartArea.height, yDensity, "y") : void 0;
|
|
17241
|
+
const steppedTicks = resolveStepTicks(scales.y);
|
|
16814
17242
|
let allTicks;
|
|
16815
17243
|
if (axisConfig?.values) {
|
|
16816
17244
|
allTicks = resolveExplicitTicks(axisConfig.values, scales.y);
|
|
17245
|
+
} else if (steppedTicks !== null) {
|
|
17246
|
+
allTicks = steppedTicks;
|
|
16817
17247
|
} else if (dataContext?.precomputedYTicks && dataContext.precomputedYTicks.length > 0 && isContinuousY) {
|
|
16818
17248
|
allTicks = resolveExplicitTicks(dataContext.precomputedYTicks, scales.y);
|
|
16819
17249
|
} else if (!isContinuousY) {
|
|
@@ -16828,7 +17258,7 @@ function computeAxes(scales, chartArea, strategy, theme, measureText, dataContex
|
|
|
16828
17258
|
} else {
|
|
16829
17259
|
allTicks = continuousTicks(scales.y, yDensity, yTargetCount);
|
|
16830
17260
|
}
|
|
16831
|
-
const shouldThinY = scales.y.type !== "band" && !axisConfig?.values && !dataContext?.precomputedYTicks?.length;
|
|
17261
|
+
const shouldThinY = scales.y.type !== "band" && !axisConfig?.values && steppedTicks === null && !dataContext?.precomputedYTicks?.length;
|
|
16832
17262
|
let ticks;
|
|
16833
17263
|
if (!shouldThinY) {
|
|
16834
17264
|
ticks = allTicks;
|
|
@@ -17345,6 +17775,102 @@ function createFrame(ctx, measures, chrome) {
|
|
|
17345
17775
|
return { spacing, effectiveHeight, reference, lane, place };
|
|
17346
17776
|
}
|
|
17347
17777
|
|
|
17778
|
+
// src/design/annotation-diagnostic.ts
|
|
17779
|
+
function unplacedAnnotationDiagnostics(spec, layout) {
|
|
17780
|
+
return layout.unplacedAnnotations.map((index) => {
|
|
17781
|
+
const annotation = spec.annotations?.[index];
|
|
17782
|
+
const text = annotation?.type === "text" ? annotation.text : annotation?.label;
|
|
17783
|
+
const quote = text ? ` ("${text.slice(0, 40)}${text.length > 40 ? "\u2026" : ""}")` : "";
|
|
17784
|
+
return {
|
|
17785
|
+
code: "annotations.unplaced",
|
|
17786
|
+
path: `/annotations/${index}`,
|
|
17787
|
+
severity: "warning",
|
|
17788
|
+
status: "failed",
|
|
17789
|
+
origin: "author",
|
|
17790
|
+
viewport: layout.dimensions,
|
|
17791
|
+
message: `Annotation ${index + 1}${quote} is not drawn: its position is not on the chart's axes.`
|
|
17792
|
+
};
|
|
17793
|
+
});
|
|
17794
|
+
}
|
|
17795
|
+
|
|
17796
|
+
// src/design/domain-diagnostic.ts
|
|
17797
|
+
function zeroStack(spec, channel) {
|
|
17798
|
+
const mark = typeof spec.mark === "string" ? spec.mark : spec.mark.type;
|
|
17799
|
+
const stack2 = channel.stack;
|
|
17800
|
+
const color = spec.encoding.color;
|
|
17801
|
+
if (!color || !("field" in color) || color.type === "quantitative") return false;
|
|
17802
|
+
if (mark === "area") return stack2 !== false && stack2 !== null;
|
|
17803
|
+
const vertical = mark === "bar" && ["nominal", "ordinal", "temporal"].includes(spec.encoding.x?.type ?? "");
|
|
17804
|
+
return vertical && columnStackMode(stack2) === "zero";
|
|
17805
|
+
}
|
|
17806
|
+
function stackedValues(spec, channel) {
|
|
17807
|
+
const groups = /* @__PURE__ */ new Map();
|
|
17808
|
+
for (const row of spec.data) {
|
|
17809
|
+
const value = finiteNumber(row[channel.field]);
|
|
17810
|
+
if (value === void 0) continue;
|
|
17811
|
+
const key = String(row[spec.encoding.x?.field ?? ""]);
|
|
17812
|
+
const sums = groups.get(key) ?? [0, 0];
|
|
17813
|
+
sums[value < 0 ? 0 : 1] += value;
|
|
17814
|
+
groups.set(key, sums);
|
|
17815
|
+
}
|
|
17816
|
+
return [...groups.values()].flat();
|
|
17817
|
+
}
|
|
17818
|
+
function areaValues(spec, channel) {
|
|
17819
|
+
const x = spec.encoding.x;
|
|
17820
|
+
const color = spec.encoding.color;
|
|
17821
|
+
if (!x || !color || !("field" in color)) return [];
|
|
17822
|
+
const geometry2 = computeAreaStack(
|
|
17823
|
+
spec.data,
|
|
17824
|
+
x.field,
|
|
17825
|
+
channel.field,
|
|
17826
|
+
color.field,
|
|
17827
|
+
x.type,
|
|
17828
|
+
channel.stack
|
|
17829
|
+
);
|
|
17830
|
+
const groups = /* @__PURE__ */ new Map();
|
|
17831
|
+
for (const layer of geometry2.stackedData) {
|
|
17832
|
+
for (const point of layer) {
|
|
17833
|
+
const key = String(point.data.__x__);
|
|
17834
|
+
if (geometry2.missingBoundaries.has(key)) continue;
|
|
17835
|
+
const bounds2 = groups.get(key) ?? [0, 0];
|
|
17836
|
+
bounds2[0] = Math.min(bounds2[0], point[0], point[1]);
|
|
17837
|
+
bounds2[1] = Math.max(bounds2[1], point[0], point[1]);
|
|
17838
|
+
groups.set(key, bounds2);
|
|
17839
|
+
}
|
|
17840
|
+
}
|
|
17841
|
+
return [...groups.values()].flat();
|
|
17842
|
+
}
|
|
17843
|
+
function outsideDomainDiagnostics(spec, layout) {
|
|
17844
|
+
const diagnostics = [];
|
|
17845
|
+
for (const axis of ["x", "y"]) {
|
|
17846
|
+
const channel = spec.encoding[axis];
|
|
17847
|
+
const scale = channel?.scale;
|
|
17848
|
+
if (!channel || !scale || scale.clip || !["quantitative", "temporal"].includes(channel.type) || channel.stack === "normalize" || channel.stack === "center")
|
|
17849
|
+
continue;
|
|
17850
|
+
if (!scale.domain && scale.domainMin === void 0 && scale.domainMax === void 0) continue;
|
|
17851
|
+
const bounds2 = scale.domain ?? [scale.domainMin, scale.domainMax];
|
|
17852
|
+
const parse = channel.type === "temporal" ? (v) => Date.parse(String(v)) : finiteNumber;
|
|
17853
|
+
const lower = bounds2[0] === void 0 ? -Infinity : parse(bounds2[0]);
|
|
17854
|
+
const upper = bounds2[1] === void 0 ? Infinity : parse(bounds2[1]);
|
|
17855
|
+
if (lower === void 0 || upper === void 0) continue;
|
|
17856
|
+
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]));
|
|
17857
|
+
const count = values.filter(
|
|
17858
|
+
(value) => value !== void 0 && Number.isFinite(value) && (value < lower || value > upper)
|
|
17859
|
+
).length;
|
|
17860
|
+
if (!count) continue;
|
|
17861
|
+
diagnostics.push({
|
|
17862
|
+
code: "data.outside-domain",
|
|
17863
|
+
path: `/encoding/${axis}/scale`,
|
|
17864
|
+
severity: "warning",
|
|
17865
|
+
status: "failed",
|
|
17866
|
+
origin: "author",
|
|
17867
|
+
viewport: layout.dimensions,
|
|
17868
|
+
message: `${count} ${count === 1 ? "observation falls" : "observations fall"} outside the ${axis} axis domain (${bounds2[0] ?? "auto"} to ${bounds2[1] ?? "auto"}).`
|
|
17869
|
+
});
|
|
17870
|
+
}
|
|
17871
|
+
return diagnostics;
|
|
17872
|
+
}
|
|
17873
|
+
|
|
17348
17874
|
// src/design/identity.ts
|
|
17349
17875
|
function observationKey(value) {
|
|
17350
17876
|
if (typeof value === "string") return `string:${value}`;
|
|
@@ -17569,6 +18095,10 @@ function diagnoseChart(spec, layout) {
|
|
|
17569
18095
|
]
|
|
17570
18096
|
};
|
|
17571
18097
|
}
|
|
18098
|
+
diagnostics.push(
|
|
18099
|
+
...outsideDomainDiagnostics(spec, layout),
|
|
18100
|
+
...unplacedAnnotationDiagnostics(spec, layout)
|
|
18101
|
+
);
|
|
17572
18102
|
return diagnostics;
|
|
17573
18103
|
}
|
|
17574
18104
|
|
|
@@ -17657,6 +18187,74 @@ function endpointObservation(mark, side, anchor = "boundary") {
|
|
|
17657
18187
|
return { ...point, datum: mark.data[index] ?? {}, band: false };
|
|
17658
18188
|
}
|
|
17659
18189
|
|
|
18190
|
+
// src/endpoint-labels/placement.ts
|
|
18191
|
+
function bidirectionalSweep(entries, areaTop, areaBottom) {
|
|
18192
|
+
const n = entries.length;
|
|
18193
|
+
if (n === 0) return [];
|
|
18194
|
+
const sorted = [...entries].sort((a, b) => a.naturalTop - b.naturalTop);
|
|
18195
|
+
const tops = sorted.map((e) => Math.max(areaTop, e.naturalTop));
|
|
18196
|
+
for (let i = 0; i < n; i++) {
|
|
18197
|
+
if (i > 0) {
|
|
18198
|
+
const minTop = tops[i - 1] + sorted[i - 1].height;
|
|
18199
|
+
if (tops[i] < minTop) tops[i] = minTop;
|
|
18200
|
+
}
|
|
18201
|
+
const maxTop = areaBottom - sorted[i].height;
|
|
18202
|
+
if (tops[i] > maxTop) tops[i] = maxTop;
|
|
18203
|
+
}
|
|
18204
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
18205
|
+
if (i < n - 1) {
|
|
18206
|
+
const maxTop = tops[i + 1] - sorted[i].height;
|
|
18207
|
+
if (tops[i] > maxTop) tops[i] = maxTop;
|
|
18208
|
+
}
|
|
18209
|
+
if (tops[i] < areaTop) tops[i] = areaTop;
|
|
18210
|
+
}
|
|
18211
|
+
const result = new Array(n);
|
|
18212
|
+
for (let i = 0; i < n; i++) {
|
|
18213
|
+
result[sorted[i].index] = tops[i];
|
|
18214
|
+
}
|
|
18215
|
+
return result;
|
|
18216
|
+
}
|
|
18217
|
+
function placeEndpointEntries(entries, areaTop, areaBottom) {
|
|
18218
|
+
const primary = entries.flatMap((entry, index) => entry.muted ? [] : [{ ...entry, index }]);
|
|
18219
|
+
const primaryTops = bidirectionalSweep(
|
|
18220
|
+
primary.map((entry, index) => ({ ...entry, index })),
|
|
18221
|
+
areaTop,
|
|
18222
|
+
areaBottom
|
|
18223
|
+
);
|
|
18224
|
+
const result = entries.map(() => null);
|
|
18225
|
+
const occupied = primary.map((entry, index) => {
|
|
18226
|
+
const top = primaryTops[index];
|
|
18227
|
+
result[entry.index] = top;
|
|
18228
|
+
return { top, bottom: top + entry.height };
|
|
18229
|
+
});
|
|
18230
|
+
const muted = entries.map((entry, index) => ({ ...entry, index })).filter((entry) => entry.muted).sort((a, b) => a.naturalTop - b.naturalTop || a.index - b.index);
|
|
18231
|
+
for (const entry of muted) {
|
|
18232
|
+
const top = nearestFreeTop(entry, occupied, areaTop, areaBottom);
|
|
18233
|
+
result[entry.index] = top;
|
|
18234
|
+
if (top !== null) occupied.push({ top, bottom: top + entry.height });
|
|
18235
|
+
}
|
|
18236
|
+
return result;
|
|
18237
|
+
}
|
|
18238
|
+
function nearestFreeTop(entry, occupied, areaTop, areaBottom) {
|
|
18239
|
+
const natural = Math.max(areaTop, Math.min(entry.naturalTop, areaBottom - entry.height));
|
|
18240
|
+
let best = null;
|
|
18241
|
+
let distance = Infinity;
|
|
18242
|
+
let gapStart = areaTop;
|
|
18243
|
+
const boxes2 = [...occupied].sort((a, b) => a.top - b.top);
|
|
18244
|
+
for (const box of [...boxes2, { top: areaBottom, bottom: areaBottom }]) {
|
|
18245
|
+
if (box.top - gapStart >= entry.height) {
|
|
18246
|
+
const top = Math.max(gapStart, Math.min(natural, box.top - entry.height));
|
|
18247
|
+
const delta = Math.abs(top - natural);
|
|
18248
|
+
if (delta < distance && delta <= entry.height) {
|
|
18249
|
+
best = top;
|
|
18250
|
+
distance = delta;
|
|
18251
|
+
}
|
|
18252
|
+
}
|
|
18253
|
+
gapStart = Math.max(gapStart, box.bottom);
|
|
18254
|
+
}
|
|
18255
|
+
return best;
|
|
18256
|
+
}
|
|
18257
|
+
|
|
17660
18258
|
// src/endpoint-labels/compute.ts
|
|
17661
18259
|
function emptyLayout2(theme) {
|
|
17662
18260
|
const labelStyle = {
|
|
@@ -17682,38 +18280,13 @@ function emptyLayout2(theme) {
|
|
|
17682
18280
|
swatchSize: ENDPOINT_SWATCH_SIZE,
|
|
17683
18281
|
gap: ENDPOINT_GAP,
|
|
17684
18282
|
valueGap: theme.spacing.endpointValueGap,
|
|
18283
|
+
mutedTextColor: theme.colors.axis,
|
|
17685
18284
|
swatchChipFill: theme.colors.annotationFill ?? theme.colors.background
|
|
17686
18285
|
};
|
|
17687
18286
|
}
|
|
17688
18287
|
function isLineOrArea(mark) {
|
|
17689
18288
|
return mark.type === "line" || mark.type === "area";
|
|
17690
18289
|
}
|
|
17691
|
-
function bidirectionalSweep(entries, areaTop, areaBottom) {
|
|
17692
|
-
const n = entries.length;
|
|
17693
|
-
if (n === 0) return [];
|
|
17694
|
-
const sorted = [...entries].sort((a, b) => a.naturalTop - b.naturalTop);
|
|
17695
|
-
const tops = sorted.map((e) => Math.max(areaTop, e.naturalTop));
|
|
17696
|
-
for (let i = 0; i < n; i++) {
|
|
17697
|
-
if (i > 0) {
|
|
17698
|
-
const minTop = tops[i - 1] + sorted[i - 1].height;
|
|
17699
|
-
if (tops[i] < minTop) tops[i] = minTop;
|
|
17700
|
-
}
|
|
17701
|
-
const maxTop = areaBottom - sorted[i].height;
|
|
17702
|
-
if (tops[i] > maxTop) tops[i] = maxTop;
|
|
17703
|
-
}
|
|
17704
|
-
for (let i = n - 1; i >= 0; i--) {
|
|
17705
|
-
if (i < n - 1) {
|
|
17706
|
-
const maxTop = tops[i + 1] - sorted[i].height;
|
|
17707
|
-
if (tops[i] > maxTop) tops[i] = maxTop;
|
|
17708
|
-
}
|
|
17709
|
-
if (tops[i] < areaTop) tops[i] = areaTop;
|
|
17710
|
-
}
|
|
17711
|
-
const result = new Array(n);
|
|
17712
|
-
for (let i = 0; i < n; i++) {
|
|
17713
|
-
result[sorted[i].index] = tops[i];
|
|
17714
|
-
}
|
|
17715
|
-
return result;
|
|
17716
|
-
}
|
|
17717
18290
|
function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpointLabelsDemoted, measureText, xScaleType) {
|
|
17718
18291
|
if (strategy?.labelMode === "none" && !endpointLabelsExplicitlyOn(spec)) {
|
|
17719
18292
|
return emptyLayout2(theme);
|
|
@@ -17730,6 +18303,8 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
17730
18303
|
labelsHiddenByStrategy: false,
|
|
17731
18304
|
endpointLabelsDemoted
|
|
17732
18305
|
});
|
|
18306
|
+
const nameMuted = highlightActive && sup.showEndpointLabels && !spec.labels.highlightedOnly;
|
|
18307
|
+
const isMuted = (key) => highlightActive && !highlight.includes(key);
|
|
17733
18308
|
const epExplicitlyOff = spec.endpointLabels === false || typeof spec.endpointLabels === "object" && spec.endpointLabels?.show === false;
|
|
17734
18309
|
if (!sup.showEndpointLabels && !(highlightActive && !epExplicitlyOff)) return emptyLayout2(theme);
|
|
17735
18310
|
const bySeriesKey = /* @__PURE__ */ new Map();
|
|
@@ -17769,7 +18344,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
17769
18344
|
}
|
|
17770
18345
|
}
|
|
17771
18346
|
const lineOrAreaMarks = Array.from(bySeriesKey.values()).filter(
|
|
17772
|
-
(mark) => !
|
|
18347
|
+
(mark) => !isMuted(mark.seriesKey) || nameMuted
|
|
17773
18348
|
);
|
|
17774
18349
|
if (lineOrAreaMarks.length < 2 && !highlightActive) return emptyLayout2(theme);
|
|
17775
18350
|
const config = typeof spec.endpointLabels === "object" ? spec.endpointLabels : void 0;
|
|
@@ -17816,7 +18391,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
17816
18391
|
fontVariant: "tabular-nums"
|
|
17817
18392
|
};
|
|
17818
18393
|
const interior = config?.placement === "interior" ? lineOrAreaMarks.flatMap((mark) => {
|
|
17819
|
-
if (mark.type !== "area" || !mark.stacked) return [];
|
|
18394
|
+
if (mark.type !== "area" || !mark.stacked || isMuted(mark.seriesKey)) return [];
|
|
17820
18395
|
const color = mark.stroke ?? (typeof mark.fill === "string" ? mark.fill : theme.colors.text);
|
|
17821
18396
|
const label = fitInteriorLabel(
|
|
17822
18397
|
mark,
|
|
@@ -17841,7 +18416,6 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
17841
18416
|
for (const mark of lineOrAreaMarks) {
|
|
17842
18417
|
const seriesKey = mark.seriesKey;
|
|
17843
18418
|
if (!seriesKey) continue;
|
|
17844
|
-
if (highlightActive && !highlight.includes(seriesKey)) continue;
|
|
17845
18419
|
const last = endpointObservation(mark, "trailing", anchor);
|
|
17846
18420
|
if (!last) continue;
|
|
17847
18421
|
const rawValue = last.datum[valueField ?? ""];
|
|
@@ -17877,6 +18451,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
17877
18451
|
const entryHeight = labelHeight + (value ? theme.spacing.endpointValueGap : 0) + valueHeight + (date ? valueLineHeight + theme.spacing.endpointValueGap : 0);
|
|
17878
18452
|
const color = mark.type === "line" ? mark.stroke : mark.stroke ?? (typeof mark.fill === "string" ? mark.fill : theme.colors.categorical[0]);
|
|
17879
18453
|
provisional.push({
|
|
18454
|
+
muted: isMuted(seriesKey),
|
|
17880
18455
|
seriesKey,
|
|
17881
18456
|
labelLines,
|
|
17882
18457
|
value,
|
|
@@ -17893,20 +18468,21 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
17893
18468
|
}
|
|
17894
18469
|
if (provisional.length === 0) return emptyLayout2(theme);
|
|
17895
18470
|
if (provisional.length < 2 && !highlightActive) return emptyLayout2(theme);
|
|
17896
|
-
const sweepInput = provisional.map((p
|
|
18471
|
+
const sweepInput = provisional.map((p) => ({
|
|
17897
18472
|
naturalTop: p.dataY - theme.fonts.sizes.endpointLabel / 2,
|
|
17898
18473
|
height: p.height + theme.spacing.endpointEntryGap,
|
|
17899
|
-
|
|
18474
|
+
muted: p.muted
|
|
17900
18475
|
}));
|
|
17901
|
-
const sweptTops =
|
|
18476
|
+
const sweptTops = placeEndpointEntries(sweepInput, chartArea.y, chartArea.y + chartArea.height);
|
|
17902
18477
|
const columnWidth = Math.max(
|
|
17903
18478
|
ENDPOINT_SWATCH_SIZE + ENDPOINT_GAP + Math.max(...provisional.map((p) => p.width), 0) + endpointTrailingPadding(spec.frame?.right),
|
|
17904
18479
|
32
|
|
17905
18480
|
);
|
|
17906
18481
|
const columnX = chartArea.x + chartArea.width + theme.spacing.endpointColumnGap;
|
|
17907
18482
|
const showLeader = config?.showLeader === true;
|
|
17908
|
-
const entries = provisional.
|
|
18483
|
+
const entries = provisional.flatMap((p, i) => {
|
|
17909
18484
|
const labelY = sweptTops[i];
|
|
18485
|
+
if (labelY === null) return [];
|
|
17910
18486
|
const swatchRowY = labelY + theme.fonts.sizes.endpointLabel / 2;
|
|
17911
18487
|
const displaced = Math.abs(swatchRowY - p.dataY) > ENDPOINT_LEADER_THRESHOLD;
|
|
17912
18488
|
const entry = {
|
|
@@ -17921,6 +18497,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
17921
18497
|
labelY,
|
|
17922
18498
|
showLeader: p.band || showLeader && displaced
|
|
17923
18499
|
};
|
|
18500
|
+
if (p.muted) entry.muted = true;
|
|
17924
18501
|
if (p.strokeDasharray) entry.strokeDasharray = p.strokeDasharray;
|
|
17925
18502
|
if (showMarker && !p.band) {
|
|
17926
18503
|
entry.marker = {
|
|
@@ -17933,7 +18510,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
17933
18510
|
radius: markerRadius
|
|
17934
18511
|
};
|
|
17935
18512
|
}
|
|
17936
|
-
return entry;
|
|
18513
|
+
return [entry];
|
|
17937
18514
|
});
|
|
17938
18515
|
const endsBoth = config?.ends === "both";
|
|
17939
18516
|
let leading;
|
|
@@ -17943,7 +18520,6 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
17943
18520
|
for (const mark of lineOrAreaMarks) {
|
|
17944
18521
|
const seriesKey = mark.seriesKey;
|
|
17945
18522
|
if (!seriesKey) continue;
|
|
17946
|
-
if (highlightActive && !highlight.includes(seriesKey)) continue;
|
|
17947
18523
|
const first = endpointObservation(mark, "leading", anchor);
|
|
17948
18524
|
if (!first) continue;
|
|
17949
18525
|
const rawValue = first.datum[valueField ?? ""];
|
|
@@ -17979,6 +18555,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
17979
18555
|
const entryHeight = labelHeight + (value ? theme.spacing.endpointValueGap : 0) + valueHeight + (date ? valueLineHeight + theme.spacing.endpointValueGap : 0);
|
|
17980
18556
|
const color = mark.type === "line" ? mark.stroke : mark.stroke ?? (typeof mark.fill === "string" ? mark.fill : theme.colors.categorical[0]);
|
|
17981
18557
|
leadingProvisional.push({
|
|
18558
|
+
muted: isMuted(seriesKey),
|
|
17982
18559
|
seriesKey,
|
|
17983
18560
|
labelLines,
|
|
17984
18561
|
value,
|
|
@@ -17998,12 +18575,12 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
17998
18575
|
});
|
|
17999
18576
|
}
|
|
18000
18577
|
if (leadingProvisional.length >= 2 || leadingProvisional.length === 1 && highlightActive) {
|
|
18001
|
-
const leadingSweepInput = leadingProvisional.map((p
|
|
18578
|
+
const leadingSweepInput = leadingProvisional.map((p) => ({
|
|
18002
18579
|
naturalTop: p.dataY - theme.fonts.sizes.endpointLabel / 2,
|
|
18003
18580
|
height: p.height + theme.spacing.endpointEntryGap,
|
|
18004
|
-
|
|
18581
|
+
muted: p.muted
|
|
18005
18582
|
}));
|
|
18006
|
-
const leadingSweptTops =
|
|
18583
|
+
const leadingSweptTops = placeEndpointEntries(
|
|
18007
18584
|
leadingSweepInput,
|
|
18008
18585
|
chartArea.y,
|
|
18009
18586
|
chartArea.y + chartArea.height
|
|
@@ -18013,8 +18590,9 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18013
18590
|
32
|
|
18014
18591
|
);
|
|
18015
18592
|
const leadingColumnX = chartArea.x - theme.spacing.endpointColumnGap - leadingColumnWidth;
|
|
18016
|
-
leading = leadingProvisional.
|
|
18593
|
+
leading = leadingProvisional.flatMap((p, i) => {
|
|
18017
18594
|
const labelY = leadingSweptTops[i];
|
|
18595
|
+
if (labelY === null) return [];
|
|
18018
18596
|
const swatchRowY = labelY + theme.fonts.sizes.endpointLabel / 2;
|
|
18019
18597
|
const displaced = Math.abs(swatchRowY - p.dataY) > ENDPOINT_LEADER_THRESHOLD;
|
|
18020
18598
|
const entry = {
|
|
@@ -18029,6 +18607,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18029
18607
|
labelY,
|
|
18030
18608
|
showLeader: p.band || showLeader && displaced
|
|
18031
18609
|
};
|
|
18610
|
+
if (p.muted) entry.muted = true;
|
|
18032
18611
|
if (p.strokeDasharray) entry.strokeDasharray = p.strokeDasharray;
|
|
18033
18612
|
if (showMarker && !p.band) {
|
|
18034
18613
|
entry.marker = {
|
|
@@ -18041,7 +18620,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18041
18620
|
radius: markerRadius
|
|
18042
18621
|
};
|
|
18043
18622
|
}
|
|
18044
|
-
return entry;
|
|
18623
|
+
return [entry];
|
|
18045
18624
|
});
|
|
18046
18625
|
leadingBounds = {
|
|
18047
18626
|
x: leadingColumnX,
|
|
@@ -18065,6 +18644,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18065
18644
|
swatchSize: ENDPOINT_SWATCH_SIZE,
|
|
18066
18645
|
gap: ENDPOINT_GAP,
|
|
18067
18646
|
valueGap: theme.spacing.endpointValueGap,
|
|
18647
|
+
mutedTextColor: theme.colors.axis,
|
|
18068
18648
|
swatchChipFill: theme.colors.annotationFill ?? theme.colors.background,
|
|
18069
18649
|
leading,
|
|
18070
18650
|
leadingBounds
|
|
@@ -18220,7 +18800,7 @@ function resolveLayoutPlan(chartSpec, renderSpec, options, theme, strategy, wate
|
|
|
18220
18800
|
const yLabelField = yAxisCfg?.labelField;
|
|
18221
18801
|
let maxLabelWidth = 0;
|
|
18222
18802
|
for (const row of renderSpec.data) {
|
|
18223
|
-
const label = String(row[yField] ?? "")
|
|
18803
|
+
const label = `${yAxisCfg?.labelPrefix ?? ""}${String(row[yField] ?? "")}${yAxisCfg?.labelSuffix ?? ""}`;
|
|
18224
18804
|
let w = measure(label, theme.fonts.sizes.axisTick, theme.fonts.weights.normal);
|
|
18225
18805
|
if (yLabelField) {
|
|
18226
18806
|
const subtitle = String(row[yLabelField] ?? "");
|
|
@@ -18320,6 +18900,10 @@ function resolveLayoutPlan(chartSpec, renderSpec, options, theme, strategy, wate
|
|
|
18320
18900
|
const yTicksFor = (area3) => {
|
|
18321
18901
|
const scales = computeScales(renderSpec, area3, renderSpec.data);
|
|
18322
18902
|
if (!scales.y || !scaleSupportsTickCount(scales.y)) return null;
|
|
18903
|
+
const config = scales.y.channel.axis || void 0;
|
|
18904
|
+
if (config?.values) return resolveExplicitTicks(config.values, scales.y);
|
|
18905
|
+
const stepped = resolveStepTicks(scales.y);
|
|
18906
|
+
if (stepped !== null) return stepped;
|
|
18323
18907
|
const axisTickCount = yAxisCfg?.tickCount;
|
|
18324
18908
|
const effectiveCount = axisTickCount ?? targetTickCount(area3.height, "full", "y");
|
|
18325
18909
|
return axisTickCount != null ? buildContinuousTicks(scales.y, effectiveCount) : buildDefaultYTicks(scales.y, effectiveCount);
|
|
@@ -18488,7 +19072,7 @@ function resolveLayoutPlan(chartSpec, renderSpec, options, theme, strategy, wate
|
|
|
18488
19072
|
if (yTickValues.length > 0) {
|
|
18489
19073
|
const scales = computeScales(renderSpec, finalArea, renderSpec.data);
|
|
18490
19074
|
if (scales.y && scaleSupportsTickCount(scales.y)) {
|
|
18491
|
-
const ticks =
|
|
19075
|
+
const ticks = resolveExplicitTicks(yTickValues, scales.y);
|
|
18492
19076
|
let maxLabelWidth = 0;
|
|
18493
19077
|
for (const t of ticks) {
|
|
18494
19078
|
const w = measure(t.label, theme.fonts.sizes.axisTick, theme.fonts.weights.normal);
|
|
@@ -18527,7 +19111,7 @@ function resolveLayoutPlan(chartSpec, renderSpec, options, theme, strategy, wate
|
|
|
18527
19111
|
if (yTickValues.length > 0) {
|
|
18528
19112
|
const scales = computeScales(renderSpec, finalArea, renderSpec.data);
|
|
18529
19113
|
if (scales.y && scaleSupportsTickCount(scales.y)) {
|
|
18530
|
-
const ticks =
|
|
19114
|
+
const ticks = resolveExplicitTicks(yTickValues, scales.y);
|
|
18531
19115
|
for (const t of ticks) {
|
|
18532
19116
|
const w = measure(t.label, theme.fonts.sizes.axisTick, theme.fonts.weights.normal);
|
|
18533
19117
|
if (w > estTickLabelWidth) estTickLabelWidth = w;
|
|
@@ -18951,6 +19535,11 @@ function resolveFormat(ch) {
|
|
|
18951
19535
|
const ax = ch.axis || void 0;
|
|
18952
19536
|
return ch.format ?? ax?.format;
|
|
18953
19537
|
}
|
|
19538
|
+
function formatAxisValue(row, ch, formatters) {
|
|
19539
|
+
const axis = ch.axis && typeof ch.axis === "object" ? ch.axis : void 0;
|
|
19540
|
+
const text = formatValue2(row[ch.field], ch.type, getFormatter(formatters, ch));
|
|
19541
|
+
return `${axis?.labelPrefix ?? ""}${text}${axis?.labelSuffix ?? ""}`;
|
|
19542
|
+
}
|
|
18954
19543
|
function cacheKey(ch) {
|
|
18955
19544
|
const fmt2 = resolveFormat(ch);
|
|
18956
19545
|
return fmt2 ? `${ch.field}::${ch.type}::${fmt2}` : `${ch.field}::${ch.type}`;
|
|
@@ -19039,11 +19628,7 @@ function buildFields(row, encoding, formatters, color, titleChannel) {
|
|
|
19039
19628
|
(titleChannel === "y" ? skipped : fields).push({
|
|
19040
19629
|
...semanticField(encoding.y, encoding, "y", void 0, formatters),
|
|
19041
19630
|
label: resolveLabel(encoding.y),
|
|
19042
|
-
value:
|
|
19043
|
-
row[encoding.y.field],
|
|
19044
|
-
encoding.y.type,
|
|
19045
|
-
getFormatter(formatters, encoding.y)
|
|
19046
|
-
),
|
|
19631
|
+
value: formatAxisValue(row, encoding.y, formatters),
|
|
19047
19632
|
color: encoding.color ? void 0 : color
|
|
19048
19633
|
});
|
|
19049
19634
|
}
|
|
@@ -19051,11 +19636,7 @@ function buildFields(row, encoding, formatters, color, titleChannel) {
|
|
|
19051
19636
|
(titleChannel === "x" ? skipped : fields).push({
|
|
19052
19637
|
...semanticField(encoding.x, encoding, "x", void 0, formatters),
|
|
19053
19638
|
label: resolveLabel(encoding.x),
|
|
19054
|
-
value:
|
|
19055
|
-
row[encoding.x.field],
|
|
19056
|
-
encoding.x.type,
|
|
19057
|
-
getFormatter(formatters, encoding.x)
|
|
19058
|
-
)
|
|
19639
|
+
value: formatAxisValue(row, encoding.x, formatters)
|
|
19059
19640
|
});
|
|
19060
19641
|
}
|
|
19061
19642
|
if (encoding.size && "field" in encoding.size) {
|
|
@@ -20174,8 +20755,14 @@ function compileFaceted(chartSpec, renderSpec, facetChannel, facetDirection, the
|
|
|
20174
20755
|
const yResolve = resolveConfig?.scale?.y ?? yDefault;
|
|
20175
20756
|
const xResolve = resolveConfig?.scale?.x ?? xDefault;
|
|
20176
20757
|
const fullScales = computeScales(panelSpec, chartArea, renderSpec.data);
|
|
20177
|
-
const sharedXDomain = xResolve === "shared" && fullScales.x ?
|
|
20178
|
-
|
|
20758
|
+
const sharedXDomain = xResolve === "shared" && fullScales.x ? panelEncoding.x?.type === "quantitative" ? applyDomainEnds(
|
|
20759
|
+
[Number(fullScales.x.scale.domain()[0]), Number(fullScales.x.scale.domain()[1])],
|
|
20760
|
+
panelEncoding.x.scale
|
|
20761
|
+
) : fullScales.x.scale.domain() : void 0;
|
|
20762
|
+
const sharedYDomain = yResolve === "shared" && fullScales.y ? panelEncoding.y?.type === "quantitative" ? applyDomainEnds(
|
|
20763
|
+
[Number(fullScales.y.scale.domain()[0]), Number(fullScales.y.scale.domain()[1])],
|
|
20764
|
+
panelEncoding.y.scale
|
|
20765
|
+
) : fullScales.y.scale.domain() : void 0;
|
|
20179
20766
|
const sharedColorScale = (resolveConfig?.scale?.color ?? "shared") === "shared" ? computeChartScales({ ...panelSpec, data: renderSpec.data }, chartArea, theme, chartSpec).scales.color : void 0;
|
|
20180
20767
|
const sizeDefaults = sizeScaleDefaultsFor(chartSpec.markType);
|
|
20181
20768
|
const sizeChannel = panelEncoding.size;
|
|
@@ -20189,6 +20776,7 @@ function compileFaceted(chartSpec, renderSpec, facetChannel, facetDirection, the
|
|
|
20189
20776
|
const renderer = getChartRenderer(rendererKey);
|
|
20190
20777
|
const allMarks = [];
|
|
20191
20778
|
const panelLayouts = [];
|
|
20779
|
+
const unplacedByPanel = [];
|
|
20192
20780
|
const allFootnotes = [];
|
|
20193
20781
|
const footnoteNumberBySpecIndex = /* @__PURE__ */ new Map();
|
|
20194
20782
|
for (const gridPanel of grid.panels) {
|
|
@@ -20199,14 +20787,30 @@ function compileFaceted(chartSpec, renderSpec, facetChannel, facetDirection, the
|
|
|
20199
20787
|
const xCh = panelEnc.x;
|
|
20200
20788
|
panelEnc = {
|
|
20201
20789
|
...panelEnc,
|
|
20202
|
-
x: {
|
|
20790
|
+
x: {
|
|
20791
|
+
...xCh,
|
|
20792
|
+
scale: {
|
|
20793
|
+
...xCh.scale ?? {},
|
|
20794
|
+
domainMin: void 0,
|
|
20795
|
+
domainMax: void 0,
|
|
20796
|
+
domain: sharedXDomain
|
|
20797
|
+
}
|
|
20798
|
+
}
|
|
20203
20799
|
};
|
|
20204
20800
|
}
|
|
20205
20801
|
if (sharedYDomain && panelEnc.y) {
|
|
20206
20802
|
const yCh = panelEnc.y;
|
|
20207
20803
|
panelEnc = {
|
|
20208
20804
|
...panelEnc,
|
|
20209
|
-
y: {
|
|
20805
|
+
y: {
|
|
20806
|
+
...yCh,
|
|
20807
|
+
scale: {
|
|
20808
|
+
...yCh.scale ?? {},
|
|
20809
|
+
domainMin: void 0,
|
|
20810
|
+
domainMax: void 0,
|
|
20811
|
+
domain: sharedYDomain
|
|
20812
|
+
}
|
|
20813
|
+
}
|
|
20210
20814
|
};
|
|
20211
20815
|
}
|
|
20212
20816
|
if (sharedSizeDomain && sizeChannel) {
|
|
@@ -20282,7 +20886,10 @@ function compileFaceted(chartSpec, renderSpec, facetChannel, facetDirection, the
|
|
|
20282
20886
|
seriesWarnings
|
|
20283
20887
|
);
|
|
20284
20888
|
const annotationMeasure = annotationMeasureFn(options.measureText);
|
|
20889
|
+
const panelUnplaced = /* @__PURE__ */ new Set();
|
|
20890
|
+
unplacedByPanel.push(panelUnplaced);
|
|
20285
20891
|
let panelAnnotations = computeAnnotations(panelSpecWithDomains, {
|
|
20892
|
+
onUnplaced: (i) => panelUnplaced.add(i),
|
|
20286
20893
|
scales: panelScales,
|
|
20287
20894
|
chartArea: gridPanel.area,
|
|
20288
20895
|
referenceContainer: gridPanel.referenceContainer,
|
|
@@ -20398,6 +21005,9 @@ function compileFaceted(chartSpec, renderSpec, facetChannel, facetDirection, the
|
|
|
20398
21005
|
axes: { x: void 0, y: void 0 },
|
|
20399
21006
|
marks: allMarks,
|
|
20400
21007
|
annotations: [],
|
|
21008
|
+
unplacedAnnotations: [...unplacedByPanel[0] ?? []].filter(
|
|
21009
|
+
(i) => unplacedByPanel.every((panel) => panel.has(i))
|
|
21010
|
+
),
|
|
20401
21011
|
legend: finalLegend,
|
|
20402
21012
|
// Facets share one color legend across the grid; the size channel isn't
|
|
20403
21013
|
// supported in facet specs, so there is no second legend to carry.
|
|
@@ -21234,29 +21844,6 @@ ${placementErrors.map((error) => `${error.path}: ${error.message}`).join("\n")}`
|
|
|
21234
21844
|
};
|
|
21235
21845
|
}
|
|
21236
21846
|
|
|
21237
|
-
// src/compile/data-clip.ts
|
|
21238
|
-
function filterClippedDomains(data, encoding) {
|
|
21239
|
-
let result = data;
|
|
21240
|
-
for (const channel of ["x", "y"]) {
|
|
21241
|
-
const enc = encoding[channel];
|
|
21242
|
-
if (!enc?.scale?.clip || !enc.scale.domain) continue;
|
|
21243
|
-
const domain = enc.scale.domain;
|
|
21244
|
-
const field = enc.field;
|
|
21245
|
-
if (!Array.isArray(domain)) continue;
|
|
21246
|
-
if (domain.length === 2 && typeof domain[0] === "number") {
|
|
21247
|
-
const [lo, hi] = domain;
|
|
21248
|
-
result = result.filter((row) => {
|
|
21249
|
-
const v = Number(row[field]);
|
|
21250
|
-
return Number.isFinite(v) && v >= lo && v <= hi;
|
|
21251
|
-
});
|
|
21252
|
-
} else if (typeof domain[0] === "string") {
|
|
21253
|
-
const allowed = new Set(domain);
|
|
21254
|
-
result = result.filter((row) => allowed.has(String(row[field])));
|
|
21255
|
-
}
|
|
21256
|
-
}
|
|
21257
|
-
return result;
|
|
21258
|
-
}
|
|
21259
|
-
|
|
21260
21847
|
// src/compile/render-spec.ts
|
|
21261
21848
|
function buildRenderSpec(chartSpec) {
|
|
21262
21849
|
let renderData = chartSpec.data;
|
|
@@ -21490,10 +22077,13 @@ function resolveCompileTheme(specTheme, options) {
|
|
|
21490
22077
|
const theme = resolveTheme2(mergeThemeConfig2(specTheme, options.theme));
|
|
21491
22078
|
return options.darkMode ? adaptTheme2(theme) : theme;
|
|
21492
22079
|
}
|
|
21493
|
-
function compileChartInternal(spec, optionsInput) {
|
|
22080
|
+
function compileChartInternal(spec, optionsInput, hideArcLabels = false) {
|
|
21494
22081
|
const prepared = prepareChartSpec(spec, optionsInput);
|
|
21495
22082
|
const { options } = prepared;
|
|
21496
22083
|
let { chartSpec } = prepared;
|
|
22084
|
+
if (hideArcLabels && chartSpec.markType === "arc") {
|
|
22085
|
+
chartSpec = { ...chartSpec, labels: { ...chartSpec.labels, density: "none" } };
|
|
22086
|
+
}
|
|
21497
22087
|
const theme = resolveCompileTheme(chartSpec.theme, options);
|
|
21498
22088
|
const seriesWarnings = seriesIdentificationWarnings(chartSpec);
|
|
21499
22089
|
const heightContext = heightContextResolver({
|
|
@@ -21542,6 +22132,9 @@ function compileChartInternal(spec, optionsInput) {
|
|
|
21542
22132
|
theme,
|
|
21543
22133
|
sizing
|
|
21544
22134
|
});
|
|
22135
|
+
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)) {
|
|
22136
|
+
return compileChartInternal(spec, optionsInput, true);
|
|
22137
|
+
}
|
|
21545
22138
|
emitSpecWarnings(seriesWarnings, options.onWarn);
|
|
21546
22139
|
if (options.onDiagnostic) {
|
|
21547
22140
|
const diagnosticSpec = {
|
|
@@ -21788,7 +22381,9 @@ function layoutSingleChart(input) {
|
|
|
21788
22381
|
measureText: options.measureText
|
|
21789
22382
|
});
|
|
21790
22383
|
const annotationMeasure = annotationMeasureFn(options.measureText);
|
|
22384
|
+
const unplaced = [];
|
|
21791
22385
|
let annotations = computeAnnotations(chartSpec, {
|
|
22386
|
+
onUnplaced: (i) => unplaced.push(i),
|
|
21792
22387
|
scales,
|
|
21793
22388
|
chartArea,
|
|
21794
22389
|
strategy,
|
|
@@ -21893,6 +22488,7 @@ function layoutSingleChart(input) {
|
|
|
21893
22488
|
marks,
|
|
21894
22489
|
annotations,
|
|
21895
22490
|
legend: finalLegend,
|
|
22491
|
+
unplacedAnnotations: unplaced,
|
|
21896
22492
|
legends: allLegends,
|
|
21897
22493
|
...endpointLabels.entries.length > 0 ? { endpointLabels } : {},
|
|
21898
22494
|
tooltipDescriptors,
|
|
@@ -22123,11 +22719,14 @@ function estimateYAxisLabelWidth(data, encoding, baseFontSize, measure) {
|
|
|
22123
22719
|
const yField = yEnc.field;
|
|
22124
22720
|
if (!yField) return 40;
|
|
22125
22721
|
const m = measure ?? estimateTextWidth25;
|
|
22722
|
+
const axis = yEnc.axis || void 0;
|
|
22723
|
+
const prefix = axis?.labelPrefix ?? "";
|
|
22724
|
+
const suffix = axis?.labelSuffix ?? "";
|
|
22126
22725
|
const yType = yEnc.type;
|
|
22127
22726
|
if (yType === "nominal" || yType === "ordinal") {
|
|
22128
22727
|
let maxWidth = 0;
|
|
22129
22728
|
for (const row of data) {
|
|
22130
|
-
const label = String(row[yField] ?? "");
|
|
22729
|
+
const label = prefix + String(row[yField] ?? "") + suffix;
|
|
22131
22730
|
const w = m(label, baseFontSize, 400);
|
|
22132
22731
|
if (w > maxWidth) maxWidth = w;
|
|
22133
22732
|
}
|
|
@@ -22154,7 +22753,7 @@ function estimateYAxisLabelWidth(data, encoding, baseFontSize, measure) {
|
|
|
22154
22753
|
);
|
|
22155
22754
|
}
|
|
22156
22755
|
const hasNeg = data.some((r) => Number(r[yField]) < 0);
|
|
22157
|
-
const labelEst = (hasNeg ? "-" : "") + sampleLabel;
|
|
22756
|
+
const labelEst = prefix + (hasNeg ? "-" : "") + sampleLabel + suffix;
|
|
22158
22757
|
return m(labelEst, baseFontSize, 400) + 10;
|
|
22159
22758
|
}
|
|
22160
22759
|
function compileLayerIndependent(leaves, layerSpec, options, compileChart2) {
|
|
@@ -22557,20 +23156,26 @@ function mergeEndpointColumns(columns, area3, rightReserve, leadingColumnX, colu
|
|
|
22557
23156
|
const { leadersEnabled: _leadersEnabled, bandSeries: _bandSeries, ...first } = columns[0];
|
|
22558
23157
|
const sweep = (entries) => {
|
|
22559
23158
|
const size = first.labelStyle.fontSize;
|
|
22560
|
-
const tops =
|
|
22561
|
-
entries.map((entry
|
|
23159
|
+
const tops = placeEndpointEntries(
|
|
23160
|
+
entries.map((entry) => ({
|
|
22562
23161
|
naturalTop: entry.dataY - size / 2,
|
|
22563
23162
|
height: entry.labelLines.length * size * (first.labelStyle.lineHeight ?? 1.25) + (entry.value ? first.valueGap + first.valueStyle.fontSize * (first.valueStyle.lineHeight ?? 1.25) : 0) + (entry.date ? first.valueStyle.fontSize * (first.valueStyle.lineHeight ?? 1.25) + first.valueGap : 0) + entryGap,
|
|
22564
|
-
|
|
23163
|
+
muted: entry.muted === true
|
|
22565
23164
|
})),
|
|
22566
23165
|
area3.y,
|
|
22567
23166
|
area3.y + area3.height
|
|
22568
23167
|
);
|
|
22569
|
-
return entries.
|
|
22570
|
-
|
|
22571
|
-
|
|
22572
|
-
|
|
22573
|
-
|
|
23168
|
+
return entries.flatMap(({ leadersEnabled, bandLeader, ...entry }, index) => {
|
|
23169
|
+
const top = tops[index];
|
|
23170
|
+
if (top === null) return [];
|
|
23171
|
+
return [
|
|
23172
|
+
{
|
|
23173
|
+
...entry,
|
|
23174
|
+
labelY: top,
|
|
23175
|
+
showLeader: bandLeader || leadersEnabled && Math.abs(top + size / 2 - entry.dataY) > ENDPOINT_LEADER_THRESHOLD
|
|
23176
|
+
}
|
|
23177
|
+
];
|
|
23178
|
+
});
|
|
22574
23179
|
};
|
|
22575
23180
|
const leadingColumns = columns.filter((column) => column.leadingBounds);
|
|
22576
23181
|
const leadingWidth = Math.max(0, ...leadingColumns.map((column) => column.leadingBounds.width));
|
|
@@ -22612,6 +23217,8 @@ function mergeEndpointColumns(columns, area3, rightReserve, leadingColumnX, colu
|
|
|
22612
23217
|
}
|
|
22613
23218
|
function withXDomain(leaf, domain) {
|
|
22614
23219
|
if (!leaf.encoding?.x) return leaf;
|
|
23220
|
+
const scale = leaf.encoding.x.scale;
|
|
23221
|
+
const resolvedDomain = leaf.encoding.x.type === "quantitative" ? applyDomainEnds([Number(domain[0]), Number(domain[1])], scale) : domain;
|
|
22615
23222
|
return {
|
|
22616
23223
|
...leaf,
|
|
22617
23224
|
encoding: {
|
|
@@ -22620,7 +23227,9 @@ function withXDomain(leaf, domain) {
|
|
|
22620
23227
|
...leaf.encoding.x,
|
|
22621
23228
|
scale: {
|
|
22622
23229
|
...leaf.encoding.x.scale,
|
|
22623
|
-
|
|
23230
|
+
domainMin: void 0,
|
|
23231
|
+
domainMax: void 0,
|
|
23232
|
+
domain: resolvedDomain
|
|
22624
23233
|
}
|
|
22625
23234
|
}
|
|
22626
23235
|
}
|
|
@@ -22676,7 +23285,12 @@ function withUnionXDomain(leaf0, leaf1) {
|
|
|
22676
23285
|
if (n < min4) min4 = n;
|
|
22677
23286
|
if (n > max4) max4 = n;
|
|
22678
23287
|
}
|
|
22679
|
-
if (min4 <= max4)
|
|
23288
|
+
if (min4 <= max4) {
|
|
23289
|
+
const authored = [xEnc0?.scale, xEnc1?.scale].find(
|
|
23290
|
+
(scale) => scale?.domainMin !== void 0 || scale?.domainMax !== void 0
|
|
23291
|
+
);
|
|
23292
|
+
domain = applyDomainEnds([min4, max4], authored);
|
|
23293
|
+
}
|
|
22680
23294
|
} else {
|
|
22681
23295
|
const seen = /* @__PURE__ */ new Set();
|
|
22682
23296
|
const categories = [];
|
|
@@ -22700,7 +23314,10 @@ function alignYDomains(leaf0, leaf1) {
|
|
|
22700
23314
|
const yEnc1 = leaf1.encoding?.y;
|
|
22701
23315
|
if (!yEnc0 || !yEnc1) return void 0;
|
|
22702
23316
|
if (yEnc0.type !== "quantitative" || yEnc1.type !== "quantitative") return void 0;
|
|
22703
|
-
if (yEnc0.scale
|
|
23317
|
+
if ([yEnc0.scale, yEnc1.scale].some(
|
|
23318
|
+
(scale) => scale?.domain || scale?.domainMin !== void 0 || scale?.domainMax !== void 0
|
|
23319
|
+
))
|
|
23320
|
+
return void 0;
|
|
22704
23321
|
const hasStackedY = (leaf) => {
|
|
22705
23322
|
if (!leaf.encoding?.color) return false;
|
|
22706
23323
|
const mark = typeof leaf.mark === "string" ? leaf.mark : leaf.mark.type;
|
|
@@ -22797,7 +23414,13 @@ function computeSharedDomains(leaves, options) {
|
|
|
22797
23414
|
}
|
|
22798
23415
|
if (!prepared.every((spec) => spec.encoding[channel]?.type === "quantitative")) continue;
|
|
22799
23416
|
const values = domains.flatMap((scales) => (scales[channel]?.scale.domain() ?? []).map(Number)).filter(Number.isFinite);
|
|
22800
|
-
if (values.length)
|
|
23417
|
+
if (values.length) {
|
|
23418
|
+
const authored = leaves.find((leaf) => {
|
|
23419
|
+
const scale = leaf.encoding[channel]?.scale;
|
|
23420
|
+
return scale?.domainMin !== void 0 || scale?.domainMax !== void 0;
|
|
23421
|
+
})?.encoding[channel]?.scale;
|
|
23422
|
+
shared[channel] = applyDomainEnds([Math.min(...values), Math.max(...values)], authored);
|
|
23423
|
+
}
|
|
22801
23424
|
}
|
|
22802
23425
|
return shared;
|
|
22803
23426
|
}
|
|
@@ -22808,9 +23431,16 @@ function withSharedDomains(leaf, shared) {
|
|
|
22808
23431
|
const domain = shared[channel];
|
|
22809
23432
|
const ch = encoding[channel];
|
|
22810
23433
|
if (!domain || !ch || ch.scale?.domain) continue;
|
|
23434
|
+
const authored = leaf.encoding[channel];
|
|
23435
|
+
const resolvedDomain = authored?.type === "quantitative" ? applyDomainEnds([Number(domain[0]), Number(domain[1])], authored.scale) : domain;
|
|
22811
23436
|
encoding[channel] = {
|
|
22812
23437
|
...ch,
|
|
22813
|
-
scale: {
|
|
23438
|
+
scale: {
|
|
23439
|
+
...ch.scale ?? {},
|
|
23440
|
+
domainMin: void 0,
|
|
23441
|
+
domainMax: void 0,
|
|
23442
|
+
domain: resolvedDomain
|
|
23443
|
+
}
|
|
22814
23444
|
};
|
|
22815
23445
|
}
|
|
22816
23446
|
return { ...leaf, encoding };
|
|
@@ -26353,7 +26983,7 @@ function streamingCanonicalAnchor(feature, projection, bounds2) {
|
|
|
26353
26983
|
area: 0,
|
|
26354
26984
|
winding: 0
|
|
26355
26985
|
}));
|
|
26356
|
-
let first, last, area3 = 0,
|
|
26986
|
+
let first, last, area3 = 0, invalid4 = false;
|
|
26357
26987
|
const segment = (a, b) => {
|
|
26358
26988
|
area3 += a.x * b.y - b.x * a.y;
|
|
26359
26989
|
const dx = b.x - a.x, dy = b.y - a.y;
|
|
@@ -26391,7 +27021,7 @@ function streamingCanonicalAnchor(feature, projection, bounds2) {
|
|
|
26391
27021
|
},
|
|
26392
27022
|
point(x, y) {
|
|
26393
27023
|
if (!Number.isFinite(x) || !Number.isFinite(y)) {
|
|
26394
|
-
|
|
27024
|
+
invalid4 = true;
|
|
26395
27025
|
return;
|
|
26396
27026
|
}
|
|
26397
27027
|
const p = { x, y };
|
|
@@ -26403,7 +27033,7 @@ function streamingCanonicalAnchor(feature, projection, bounds2) {
|
|
|
26403
27033
|
}
|
|
26404
27034
|
})
|
|
26405
27035
|
);
|
|
26406
|
-
if (
|
|
27036
|
+
if (invalid4) return void 0;
|
|
26407
27037
|
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
27038
|
}
|
|
26409
27039
|
function captureGeoLabelGeometry(featureId, feature, projection, limits = {}) {
|
|
@@ -27717,11 +28347,9 @@ function compileGeoMapImpl(spec, options, scope) {
|
|
|
27717
28347
|
const geoCollection = viewSources?.primary.collection ?? topoFeature2(topology, topology.objects[objectKey]);
|
|
27718
28348
|
const insetSelection = viewSources ? selectGeoInsetFeatures(geoCollection.features, mapSpec.geo.insets ?? []) : void 0;
|
|
27719
28349
|
const geoFeatures = geoCollection.features;
|
|
27720
|
-
const
|
|
27721
|
-
|
|
27722
|
-
|
|
27723
|
-
mapSpec.points?.data.length ?? 0
|
|
27724
|
-
);
|
|
28350
|
+
const description = spec.a11y && typeof spec.a11y === "object" && "description" in spec.a11y && typeof spec.a11y.description === "string" ? spec.a11y.description : void 0;
|
|
28351
|
+
const authoredDescription = description?.trim() ? description : void 0;
|
|
28352
|
+
const emptyAltText = authoredDescription ?? describeGeoMap(geoFeatures.length, mapSpec.encoding.color, mapSpec.points?.data.length ?? 0);
|
|
27725
28353
|
if ((fullArea.width <= 0 || fullArea.height <= 0) && !hasGeoLabels(mapSpec)) {
|
|
27726
28354
|
return emptyLayout4(chrome, theme, options, watermark, emptyAltText);
|
|
27727
28355
|
}
|
|
@@ -28855,7 +29483,7 @@ function compileGeoMapImpl(spec, options, scope) {
|
|
|
28855
29483
|
}
|
|
28856
29484
|
const a11yDataField = colorEncoding?.field;
|
|
28857
29485
|
const a11y = {
|
|
28858
|
-
altText: describeGeoMap(geoFeatures.length, colorEncoding, pointMarks.length),
|
|
29486
|
+
altText: authoredDescription ?? describeGeoMap(geoFeatures.length, colorEncoding, pointMarks.length),
|
|
28859
29487
|
dataTableFallback: [
|
|
28860
29488
|
...featureMarks.filter((m) => m.data).map((m) => [
|
|
28861
29489
|
m.name ?? String(m.id),
|
|
@@ -28869,7 +29497,7 @@ function compileGeoMapImpl(spec, options, scope) {
|
|
|
28869
29497
|
role: "img",
|
|
28870
29498
|
keyboardNavigable: featureMarks.length > 0 || pointMarks.length > 0
|
|
28871
29499
|
};
|
|
28872
|
-
if (showChoroplethLegend && classScale) {
|
|
29500
|
+
if (!authoredDescription && showChoroplethLegend && classScale) {
|
|
28873
29501
|
a11y.altText += `. Color ranges: ${classScale.colors.map((_, index) => classIntervalText(classScale, index, formatter)).join("; ")}.`;
|
|
28874
29502
|
}
|
|
28875
29503
|
const resolvedFocus = resolveFocus(mapSpec.geo.focus, featureMarks, pointMarks, compileWarnings);
|
|
@@ -32201,7 +32829,8 @@ function compileTableLayout(spec, options, theme) {
|
|
|
32201
32829
|
totalRow: spec.totalRow ? buildTotalRow(spec.totalRow.label, spec.columns, resolvedColumns, filteredData) : void 0,
|
|
32202
32830
|
a11y: {
|
|
32203
32831
|
caption,
|
|
32204
|
-
summary: `${resolvedColumns.length} columns, ${totalFiltered} rows
|
|
32832
|
+
summary: `${resolvedColumns.length} columns, ${totalFiltered} rows`,
|
|
32833
|
+
description: spec.a11y?.description?.trim() || null
|
|
32205
32834
|
},
|
|
32206
32835
|
theme,
|
|
32207
32836
|
animation: resolveAnimation(spec.animation),
|