@opendata-ai/openchart-core 9.6.1 → 9.7.1
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 +147 -18
- package/dist/index.js +1029 -120
- package/dist/index.js.map +1 -1
- package/dist/styles.css.map +1 -1
- package/package.json +1 -1
- package/schema/chart.schema.json +87 -2
- package/schema/table.schema.json +87 -2
- package/schema/vizspec.schema.json +199 -2
package/dist/index.js
CHANGED
|
@@ -1436,8 +1436,11 @@ var VL_SCHEME_ALIASES = {
|
|
|
1436
1436
|
category10: "categorical",
|
|
1437
1437
|
tableau10: "categorical"
|
|
1438
1438
|
};
|
|
1439
|
+
function canonicalSchemeName(name) {
|
|
1440
|
+
return SEQUENTIAL_PALETTES[name] || DIVERGING_PALETTES[name] ? name : VL_SCHEME_ALIASES[name.toLowerCase()] ?? name.toLowerCase();
|
|
1441
|
+
}
|
|
1439
1442
|
function resolveSchemeName(name) {
|
|
1440
|
-
const canonical =
|
|
1443
|
+
const canonical = canonicalSchemeName(name);
|
|
1441
1444
|
if (canonical === "categorical") return [...CATEGORICAL_PALETTE];
|
|
1442
1445
|
return SEQUENTIAL_PALETTES[canonical] ?? DIVERGING_PALETTES[canonical];
|
|
1443
1446
|
}
|
|
@@ -1958,6 +1961,8 @@ var FONT_SIZES = {
|
|
|
1958
1961
|
endpointValue: 12
|
|
1959
1962
|
};
|
|
1960
1963
|
var DEFAULT_THEME = /* @__PURE__ */ (() => ({
|
|
1964
|
+
locale: "en-US",
|
|
1965
|
+
logo: null,
|
|
1961
1966
|
colors: {
|
|
1962
1967
|
categorical: [...CATEGORICAL_PALETTE],
|
|
1963
1968
|
categoricalFill: [...CATEGORICAL_FILL_PALETTE],
|
|
@@ -2134,6 +2139,12 @@ function adaptTheme(theme) {
|
|
|
2134
2139
|
};
|
|
2135
2140
|
const categorical = paletteForDark("categorical", CATEGORICAL_PALETTE_DARK);
|
|
2136
2141
|
const categoricalFill = paletteForDark("categoricalFill", CATEGORICAL_FILL_PALETTE_DARK);
|
|
2142
|
+
const rampsForDark = (kind) => Object.fromEntries(
|
|
2143
|
+
Object.entries(theme.colors[kind]).map(([name, stops]) => [
|
|
2144
|
+
name,
|
|
2145
|
+
stops.map((color, index) => theme._rampPairs?.[kind]?.[name]?.[index]?.dark ?? color)
|
|
2146
|
+
])
|
|
2147
|
+
);
|
|
2137
2148
|
const neutral = deriveNeutralRamp(darkText, darkBg, true);
|
|
2138
2149
|
const authoredColors = theme._authored?.colors && !Array.isArray(theme._authored.colors) ? theme._authored.colors : {};
|
|
2139
2150
|
const authoredColor = (key, fallback) => pairs?.[`colors.${key}`]?.dark ?? (authoredColors[key] !== void 0 ? theme.colors[key] ?? fallback : fallback);
|
|
@@ -2163,6 +2174,8 @@ function adaptTheme(theme) {
|
|
|
2163
2174
|
mapOutlineBorder: authoredColor("mapOutlineBorder", "rgba(255,255,255,0.38)"),
|
|
2164
2175
|
categorical,
|
|
2165
2176
|
categoricalFill,
|
|
2177
|
+
sequential: rampsForDark("sequential"),
|
|
2178
|
+
diverging: rampsForDark("diverging"),
|
|
2166
2179
|
hairline: darkHairline,
|
|
2167
2180
|
positive: pairs?.["colors.positive"] ? pairs["colors.positive"].dark : overridden(theme.colors.positive, light.positive, "#4ade80"),
|
|
2168
2181
|
negative: pairs?.["colors.negative"] ? pairs["colors.negative"].dark : overridden(theme.colors.negative, light.negative, "#f87171"),
|
|
@@ -2375,12 +2388,67 @@ var legacyEditorial = {
|
|
|
2375
2388
|
spacing: { padding: 20, chromeGap: 6, chromeToChart: 8, chartToFooter: 8 }
|
|
2376
2389
|
};
|
|
2377
2390
|
|
|
2391
|
+
// src/locale/supported.ts
|
|
2392
|
+
var SUPPORTED_LOCALES = [
|
|
2393
|
+
"en-US",
|
|
2394
|
+
"en-GB",
|
|
2395
|
+
"de-DE",
|
|
2396
|
+
"fr-FR",
|
|
2397
|
+
"es-ES",
|
|
2398
|
+
"pt-BR",
|
|
2399
|
+
"pt-PT",
|
|
2400
|
+
"it-IT",
|
|
2401
|
+
"nl-NL"
|
|
2402
|
+
];
|
|
2403
|
+
function isSupportedLocale(tag) {
|
|
2404
|
+
return SUPPORTED_LOCALES.some((locale) => locale === tag);
|
|
2405
|
+
}
|
|
2406
|
+
function matchLocale(tag) {
|
|
2407
|
+
if (typeof tag !== "string") return null;
|
|
2408
|
+
const lower = tag.toLowerCase();
|
|
2409
|
+
const exact = SUPPORTED_LOCALES.find((locale) => locale.toLowerCase() === lower);
|
|
2410
|
+
if (exact) return exact;
|
|
2411
|
+
const aliases = {
|
|
2412
|
+
de: "de-DE",
|
|
2413
|
+
en: "en-US",
|
|
2414
|
+
fr: "fr-FR",
|
|
2415
|
+
es: "es-ES",
|
|
2416
|
+
it: "it-IT",
|
|
2417
|
+
nl: "nl-NL",
|
|
2418
|
+
pt: "pt-BR"
|
|
2419
|
+
};
|
|
2420
|
+
return Object.hasOwn(aliases, lower) ? aliases[lower] : null;
|
|
2421
|
+
}
|
|
2422
|
+
|
|
2423
|
+
// src/theme/ramps.ts
|
|
2424
|
+
function isRampStop(stop) {
|
|
2425
|
+
if (typeof stop === "string") return true;
|
|
2426
|
+
if (!stop || typeof stop !== "object") return false;
|
|
2427
|
+
const pair = stop;
|
|
2428
|
+
return typeof pair.light === "string" && typeof pair.dark === "string";
|
|
2429
|
+
}
|
|
2430
|
+
function sanitizeRamps(kind, ramps, warn) {
|
|
2431
|
+
const clean2 = {};
|
|
2432
|
+
for (const [name, stops] of Object.entries(ramps)) {
|
|
2433
|
+
const usable = Array.isArray(stops) ? stops.filter(isRampStop) : [];
|
|
2434
|
+
if (warn && (!Array.isArray(stops) || usable.length !== stops.length)) {
|
|
2435
|
+
console.warn(
|
|
2436
|
+
`[openchart] colors.${kind}.${name}: ramps must be arrays of color strings or { light, dark } pairs; ignoring invalid ${Array.isArray(stops) ? "stops" : "ramp"}.`
|
|
2437
|
+
);
|
|
2438
|
+
}
|
|
2439
|
+
if (usable.length > 0) clean2[name] = usable;
|
|
2440
|
+
}
|
|
2441
|
+
return clean2;
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2378
2444
|
// src/theme/resolve.ts
|
|
2379
2445
|
function resolveTokenLight(v) {
|
|
2380
2446
|
return typeof v === "string" ? v : v.light;
|
|
2381
2447
|
}
|
|
2382
2448
|
function themeConfigToPartial(config, base2) {
|
|
2383
2449
|
const partial = {};
|
|
2450
|
+
if (config.locale !== void 0) partial.locale = matchLocale(config.locale) ?? "en-US";
|
|
2451
|
+
if (config.logo !== void 0) partial.logo = config.logo;
|
|
2384
2452
|
if (config.colors) {
|
|
2385
2453
|
const colors = {};
|
|
2386
2454
|
if (Array.isArray(config.colors)) {
|
|
@@ -2390,8 +2458,17 @@ function themeConfigToPartial(config, base2) {
|
|
|
2390
2458
|
colors.categorical = config.colors.categorical.map(resolveTokenLight);
|
|
2391
2459
|
if (config.colors.categoricalFill)
|
|
2392
2460
|
colors.categoricalFill = config.colors.categoricalFill.map(resolveTokenLight);
|
|
2393
|
-
|
|
2394
|
-
|
|
2461
|
+
for (const kind of ["sequential", "diverging"]) {
|
|
2462
|
+
const authored = config.colors[kind];
|
|
2463
|
+
if (authored && typeof authored === "object") {
|
|
2464
|
+
colors[kind] = Object.fromEntries(
|
|
2465
|
+
Object.entries(sanitizeRamps(kind, authored, true)).map(([name, stops]) => [
|
|
2466
|
+
name,
|
|
2467
|
+
stops.map(resolveTokenLight)
|
|
2468
|
+
])
|
|
2469
|
+
);
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2395
2472
|
if (config.colors.background) colors.background = resolveTokenLight(config.colors.background);
|
|
2396
2473
|
if (config.colors.text) colors.text = resolveTokenLight(config.colors.text);
|
|
2397
2474
|
if (config.colors.gridline) colors.gridline = resolveTokenLight(config.colors.gridline);
|
|
@@ -2475,6 +2552,9 @@ function themeConfigToPartial(config, base2) {
|
|
|
2475
2552
|
if (obj.fontSize !== void 0) override.fontSize = obj.fontSize;
|
|
2476
2553
|
if (obj.fontWeight !== void 0) override.fontWeight = obj.fontWeight;
|
|
2477
2554
|
if (obj.lineHeight !== void 0) override.lineHeight = obj.lineHeight;
|
|
2555
|
+
if (obj.fontFamily !== void 0) override.fontFamily = obj.fontFamily;
|
|
2556
|
+
if (obj.align !== void 0) override.align = obj.align;
|
|
2557
|
+
if (obj.prefix !== void 0) override.prefix = obj.prefix;
|
|
2478
2558
|
chrome[element] = override;
|
|
2479
2559
|
}
|
|
2480
2560
|
}
|
|
@@ -2547,6 +2627,22 @@ function collectTokenPairs(config) {
|
|
|
2547
2627
|
}
|
|
2548
2628
|
return Object.keys(pairs).length > 0 ? pairs : void 0;
|
|
2549
2629
|
}
|
|
2630
|
+
function collectRampPairs(config) {
|
|
2631
|
+
if (!config.colors || Array.isArray(config.colors)) return void 0;
|
|
2632
|
+
const result = {};
|
|
2633
|
+
for (const kind of ["sequential", "diverging"]) {
|
|
2634
|
+
const ramps = config.colors[kind];
|
|
2635
|
+
if (ramps && typeof ramps === "object") {
|
|
2636
|
+
result[kind] = Object.fromEntries(
|
|
2637
|
+
Object.entries(sanitizeRamps(kind, ramps, false)).map(([name, stops]) => [
|
|
2638
|
+
name,
|
|
2639
|
+
stops.map((stop) => typeof stop === "string" ? void 0 : stop)
|
|
2640
|
+
])
|
|
2641
|
+
);
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
return Object.keys(result).length ? result : void 0;
|
|
2645
|
+
}
|
|
2550
2646
|
function relativeLuminance2(hex) {
|
|
2551
2647
|
const m = /^#?([0-9a-f]{6})$/i.exec(hex.trim());
|
|
2552
2648
|
if (!m) return 0;
|
|
@@ -2645,6 +2741,7 @@ function resolveTheme(userTheme, base2 = DEFAULT_THEME) {
|
|
|
2645
2741
|
}
|
|
2646
2742
|
const neutral = deriveNeutralRamp(merged.colors.text, merged.colors.background, dark);
|
|
2647
2743
|
const authoredColors = userTheme?.colors && !Array.isArray(userTheme.colors) ? userTheme.colors : {};
|
|
2744
|
+
const rampPairs = userTheme ? collectRampPairs(userTheme) : void 0;
|
|
2648
2745
|
return {
|
|
2649
2746
|
...merged,
|
|
2650
2747
|
_authored: userTheme,
|
|
@@ -2655,10 +2752,108 @@ function resolveTheme(userTheme, base2 = DEFAULT_THEME) {
|
|
|
2655
2752
|
annotationPlate: authoredColors.annotationPlate === void 0 ? neutral.surface : merged.colors.annotationPlate
|
|
2656
2753
|
},
|
|
2657
2754
|
isDark: dark,
|
|
2658
|
-
_tokenPairs: userTheme ? collectTokenPairs(userTheme) : void 0
|
|
2755
|
+
_tokenPairs: userTheme ? collectTokenPairs(userTheme) : void 0,
|
|
2756
|
+
...rampPairs ? { _rampPairs: rampPairs } : {}
|
|
2659
2757
|
};
|
|
2660
2758
|
}
|
|
2661
2759
|
|
|
2760
|
+
// src/layout/chrome-align.ts
|
|
2761
|
+
function alignChromeText(align, width, padding, dx = 0) {
|
|
2762
|
+
if (align === "center") return { x: width / 2 + dx, textAnchor: "middle" };
|
|
2763
|
+
if (align === "right") return { x: width - padding + dx, textAnchor: "end" };
|
|
2764
|
+
return { x: padding + dx, textAnchor: "start" };
|
|
2765
|
+
}
|
|
2766
|
+
function chromePrefix(text, prefix) {
|
|
2767
|
+
return typeof prefix === "string" && prefix && !text.trimStart().toLowerCase().startsWith(prefix.trim().toLowerCase()) ? { prefix } : {};
|
|
2768
|
+
}
|
|
2769
|
+
|
|
2770
|
+
// src/layout/logo-source.ts
|
|
2771
|
+
function isSafeLogoSource(src) {
|
|
2772
|
+
return /^data:image\/png;base64,[A-Za-z0-9+/]+={0,2}$/.test(src) || /^data:image\/svg\+xml(;[cC][hH][aA][rR][sS][eE][tT]=[uU][tT][fF]-8)?(;base64)?,/.test(src);
|
|
2773
|
+
}
|
|
2774
|
+
function positiveSize(width, height) {
|
|
2775
|
+
return Number.isFinite(width) && width > 0 && Number.isFinite(height) && height > 0 ? { width, height } : null;
|
|
2776
|
+
}
|
|
2777
|
+
function readLogoSize(src) {
|
|
2778
|
+
if (!isSafeLogoSource(src)) return null;
|
|
2779
|
+
const comma = src.indexOf(",");
|
|
2780
|
+
const header = src.slice(0, comma);
|
|
2781
|
+
const payload = src.slice(comma + 1);
|
|
2782
|
+
let decoded;
|
|
2783
|
+
try {
|
|
2784
|
+
decoded = header.endsWith(";base64") ? atob(payload) : decodeURIComponent(payload);
|
|
2785
|
+
} catch (error) {
|
|
2786
|
+
if (error instanceof URIError || error instanceof Error && error.name === "InvalidCharacterError")
|
|
2787
|
+
return null;
|
|
2788
|
+
throw error;
|
|
2789
|
+
}
|
|
2790
|
+
if (header === "data:image/png;base64") {
|
|
2791
|
+
if (decoded.length < 24 || decoded.slice(0, 8) !== "\x89PNG\r\n\n" || decoded.slice(12, 16) !== "IHDR")
|
|
2792
|
+
return null;
|
|
2793
|
+
const bytes = Uint8Array.from(decoded.slice(16, 24), (char) => char.charCodeAt(0));
|
|
2794
|
+
const view = new DataView(bytes.buffer);
|
|
2795
|
+
return positiveSize(view.getUint32(0), view.getUint32(4));
|
|
2796
|
+
}
|
|
2797
|
+
const root = /<svg\b([^>]*)>/i.exec(decoded.replace(/<!--[\s\S]*?-->/g, ""))?.[1];
|
|
2798
|
+
if (root === void 0) return null;
|
|
2799
|
+
const attr = (name) => new RegExp(`\\s${name}\\s*=\\s*(["'])(.*?)\\1`, "i").exec(root)?.[2];
|
|
2800
|
+
const dimension = (value) => value && /^\s*\d*\.?\d+(?:e[+-]?\d+)?(?:px)?\s*$/i.test(value) ? Number.parseFloat(value) : 0;
|
|
2801
|
+
const explicit = positiveSize(dimension(attr("width")) || 0, dimension(attr("height")) || 0);
|
|
2802
|
+
if (explicit) return explicit;
|
|
2803
|
+
const viewBox = attr("viewBox")?.trim().split(/[\s,]+/).map(Number);
|
|
2804
|
+
return viewBox?.length === 4 && viewBox.every(Number.isFinite) ? positiveSize(viewBox[2], viewBox[3]) : null;
|
|
2805
|
+
}
|
|
2806
|
+
|
|
2807
|
+
// src/layout/chrome-logo.ts
|
|
2808
|
+
var MIN_CHROME_TEXT_WIDTH = 120;
|
|
2809
|
+
function resolveChromeLogo(logo, width, padding) {
|
|
2810
|
+
if (!logo || typeof logo !== "object" || Array.isArray(logo) || typeof logo.src !== "string" || !isSafeLogoSource(logo.src) || !Number.isFinite(logo.height) || logo.height <= 0 || logo.width !== void 0 && (!Number.isFinite(logo.width) || logo.width <= 0))
|
|
2811
|
+
return void 0;
|
|
2812
|
+
const intrinsic = readLogoSize(logo.src);
|
|
2813
|
+
const logoWidth = logo.width ?? (intrinsic ? logo.height * intrinsic.width / intrinsic.height : logo.height);
|
|
2814
|
+
const availableWidth = width - padding * 2;
|
|
2815
|
+
if (!Number.isFinite(logoWidth) || logoWidth <= 0 || availableWidth <= 0) return void 0;
|
|
2816
|
+
const scale2 = Math.min(1, availableWidth / logoWidth);
|
|
2817
|
+
const resolvedWidth = Math.min(logoWidth, availableWidth);
|
|
2818
|
+
const position = logo.position === "top-left" || logo.position === "top-right" || logo.position === "bottom-left" ? logo.position : "bottom-right";
|
|
2819
|
+
return {
|
|
2820
|
+
href: logo.src,
|
|
2821
|
+
x: position.endsWith("left") ? padding : width - padding - resolvedWidth,
|
|
2822
|
+
y: 0,
|
|
2823
|
+
width: resolvedWidth,
|
|
2824
|
+
height: logo.height * scale2,
|
|
2825
|
+
position,
|
|
2826
|
+
...typeof logo.alt === "string" ? { alt: logo.alt } : {}
|
|
2827
|
+
};
|
|
2828
|
+
}
|
|
2829
|
+
function planTopLogo(logo, padding, gap, textWidth) {
|
|
2830
|
+
if (!logo?.position.startsWith("top")) return { before: 0, beside: 0, height: 0 };
|
|
2831
|
+
const ownRow = logo.position === "top-left" || textWidth - logo.width - gap < MIN_CHROME_TEXT_WIDTH;
|
|
2832
|
+
return {
|
|
2833
|
+
logo: { ...logo, y: padding },
|
|
2834
|
+
before: ownRow ? logo.height + gap : 0,
|
|
2835
|
+
beside: ownRow ? 0 : logo.width + gap,
|
|
2836
|
+
height: logo.height
|
|
2837
|
+
};
|
|
2838
|
+
}
|
|
2839
|
+
function planBottomRightLogo(logo, brandWidth, brandHeight, contentWidth, gap, y) {
|
|
2840
|
+
if (logo?.position !== "bottom-right")
|
|
2841
|
+
return { reservedWidth: 0, height: brandHeight, ownRow: false, brandShift: 0 };
|
|
2842
|
+
const ownRow = brandWidth > 0 && brandWidth + gap + logo.width > contentWidth;
|
|
2843
|
+
return {
|
|
2844
|
+
logo: { ...logo, y: y + (ownRow ? brandHeight + gap : 0) },
|
|
2845
|
+
reservedWidth: ownRow ? 0 : logo.width + gap,
|
|
2846
|
+
height: ownRow ? brandHeight + gap + logo.height : Math.max(brandHeight, logo.height),
|
|
2847
|
+
ownRow,
|
|
2848
|
+
brandShift: ownRow || brandWidth === 0 ? 0 : logo.width + gap
|
|
2849
|
+
};
|
|
2850
|
+
}
|
|
2851
|
+
function planBottomLeftLogo(logo, contentBottom, gap, hasFooter) {
|
|
2852
|
+
if (logo?.position !== "bottom-left") return { height: 0 };
|
|
2853
|
+
const before = hasFooter ? gap : 0;
|
|
2854
|
+
return { logo: { ...logo, y: contentBottom + before }, height: before + logo.height };
|
|
2855
|
+
}
|
|
2856
|
+
|
|
2662
2857
|
// src/layout/chrome.ts
|
|
2663
2858
|
function isSafeLink(href) {
|
|
2664
2859
|
try {
|
|
@@ -2691,12 +2886,12 @@ function buildTextStyle(defaults, fontFamily, textColor, width, overrides, extra
|
|
|
2691
2886
|
const baseFontSize = overrides?.fontSize ?? defaults.fontSize;
|
|
2692
2887
|
const fontSize = hasExplicitSize ? baseFontSize : Math.max(Math.round(scaleFontSize(baseFontSize, width) * extraScale), 10);
|
|
2693
2888
|
return {
|
|
2694
|
-
fontFamily: overrides?.fontFamily
|
|
2889
|
+
fontFamily: typeof overrides?.fontFamily === "string" ? overrides.fontFamily : typeof defaults.fontFamily === "string" ? defaults.fontFamily : fontFamily,
|
|
2695
2890
|
fontSize,
|
|
2696
2891
|
fontWeight: overrides?.fontWeight ?? defaults.fontWeight,
|
|
2697
2892
|
fill: overrides?.color ?? textColor ?? defaults.color,
|
|
2698
2893
|
lineHeight: defaults.lineHeight,
|
|
2699
|
-
textAnchor: "start"
|
|
2894
|
+
textAnchor: defaults.align === "center" ? "middle" : defaults.align === "right" ? "end" : "start"
|
|
2700
2895
|
};
|
|
2701
2896
|
}
|
|
2702
2897
|
function estimateLineCount(text, style, maxWidth, measureText, maxLines) {
|
|
@@ -2709,14 +2904,19 @@ function estimateLineCount(text, style, maxWidth, measureText, maxLines) {
|
|
|
2709
2904
|
return maxLines != null ? Math.min(count, maxLines) : count;
|
|
2710
2905
|
}
|
|
2711
2906
|
if (measureText) {
|
|
2712
|
-
const textWidth = measureText(text, style.fontSize, style.fontWeight).width;
|
|
2907
|
+
const textWidth = measureText(text, style.fontSize, style.fontWeight, style.fontFamily).width;
|
|
2713
2908
|
if (textWidth <= maxWidth) return 1;
|
|
2714
2909
|
const words2 = text.split(" ");
|
|
2715
2910
|
let lines2 = 1;
|
|
2716
2911
|
let current2 = "";
|
|
2717
2912
|
for (const word of words2) {
|
|
2718
2913
|
const candidate = current2 ? `${current2} ${word}` : word;
|
|
2719
|
-
const candidateWidth = measureText(
|
|
2914
|
+
const candidateWidth = measureText(
|
|
2915
|
+
candidate,
|
|
2916
|
+
style.fontSize,
|
|
2917
|
+
style.fontWeight,
|
|
2918
|
+
style.fontFamily
|
|
2919
|
+
).width;
|
|
2720
2920
|
if (candidateWidth > maxWidth && current2) {
|
|
2721
2921
|
lines2++;
|
|
2722
2922
|
current2 = word;
|
|
@@ -2764,12 +2964,17 @@ function measuredWatermark(theme, width, pad, y, measureText) {
|
|
|
2764
2964
|
text: "OpenChart",
|
|
2765
2965
|
x: width - pad,
|
|
2766
2966
|
y,
|
|
2767
|
-
maxWidth: measureText?.("OpenChart", BRAND_FONT_SIZE, 600).width ?? "OpenChart".length * estimateCharWidth(BRAND_FONT_SIZE, 600),
|
|
2967
|
+
maxWidth: measureText?.("OpenChart", BRAND_FONT_SIZE, 600, style.fontFamily).width ?? "OpenChart".length * estimateCharWidth(BRAND_FONT_SIZE, 600),
|
|
2768
2968
|
style
|
|
2769
2969
|
};
|
|
2770
2970
|
}
|
|
2771
|
-
function
|
|
2772
|
-
|
|
2971
|
+
function inheritBodyFamily(measureText, bodyFamily) {
|
|
2972
|
+
return measureText ? (text, fontSize, fontWeight, fontFamily) => measureText(text, fontSize, fontWeight, fontFamily === bodyFamily ? void 0 : fontFamily) : void 0;
|
|
2973
|
+
}
|
|
2974
|
+
function computeChrome(chrome, theme, width, measureTextFn, chromeMode = "full", padding, watermark = true, bottomLegendHeight = 0, crampedTitle = false) {
|
|
2975
|
+
const measureText = inheritBodyFamily(measureTextFn, theme.fonts.family);
|
|
2976
|
+
const logo = chromeMode === "full" && width >= BRAND_MIN_WIDTH && (chrome?.logo === void 0 || chrome.logo === true) ? resolveChromeLogo(theme.logo, width, padding ?? theme.spacing.padding) : void 0;
|
|
2977
|
+
if (!chrome && !logo || chromeMode === "hidden") {
|
|
2773
2978
|
if (watermark && width >= BRAND_MIN_WIDTH) {
|
|
2774
2979
|
const hiddenPad = padding ?? theme.spacing.padding;
|
|
2775
2980
|
const brandHeight2 = estimateTextHeight(BRAND_FONT_SIZE, 1);
|
|
@@ -2790,20 +2995,30 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
|
|
|
2790
2995
|
}
|
|
2791
2996
|
return { topHeight: 0, bottomHeight: 0 };
|
|
2792
2997
|
}
|
|
2998
|
+
chrome ??= {};
|
|
2793
2999
|
const pad = padding ?? theme.spacing.padding;
|
|
2794
3000
|
const chromeGap = theme.spacing.chromeGap;
|
|
2795
3001
|
const WRAP_SAFETY_BUFFER = 5;
|
|
2796
3002
|
const maxWidth = width - pad * 2 - WRAP_SAFETY_BUFFER;
|
|
3003
|
+
const topLogo = planTopLogo(logo, pad, chromeGap, maxWidth);
|
|
3004
|
+
const topWidth = width - topLogo.beside;
|
|
3005
|
+
const topMaxWidth = topLogo.beside > 0 ? topWidth - pad * 2 - WRAP_SAFETY_BUFFER : maxWidth;
|
|
2797
3006
|
const fontFamily = theme.fonts.family;
|
|
2798
|
-
let topY = pad;
|
|
3007
|
+
let topY = pad + topLogo.before;
|
|
2799
3008
|
const topElements = {};
|
|
2800
3009
|
const eyebrowNorm = chromeMode === "compact" ? null : normalizeChromeText(chrome.eyebrow);
|
|
2801
3010
|
const titleNormPeek = normalizeChromeText(chrome.title);
|
|
2802
3011
|
const subtitleNormPeek = chromeMode === "compact" ? null : normalizeChromeText(chrome.subtitle);
|
|
2803
3012
|
let ruleElement;
|
|
2804
3013
|
if (theme.rule && (eyebrowNorm || titleNormPeek || subtitleNormPeek)) {
|
|
3014
|
+
const { x, textAnchor } = alignChromeText(
|
|
3015
|
+
theme.chrome.title.align,
|
|
3016
|
+
topWidth,
|
|
3017
|
+
pad,
|
|
3018
|
+
theme.chrome.title.align ? titleNormPeek?.offset?.dx : 0
|
|
3019
|
+
);
|
|
2805
3020
|
ruleElement = {
|
|
2806
|
-
x:
|
|
3021
|
+
x: x - (textAnchor === "middle" ? theme.rule.width / 2 : textAnchor === "end" ? theme.rule.width : 0),
|
|
2807
3022
|
y: topY,
|
|
2808
3023
|
width: theme.rule.width,
|
|
2809
3024
|
thickness: theme.rule.thickness,
|
|
@@ -2820,13 +3035,21 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
|
|
|
2820
3035
|
eyebrowNorm.style
|
|
2821
3036
|
);
|
|
2822
3037
|
const maxLines = eyebrowNorm.style?.maxLines;
|
|
2823
|
-
const
|
|
3038
|
+
const prefix = chromePrefix(eyebrowNorm.text, theme.chrome.eyebrow.prefix);
|
|
3039
|
+
const lineCount = estimateLineCount(
|
|
3040
|
+
(prefix.prefix ?? "") + eyebrowNorm.text,
|
|
3041
|
+
style,
|
|
3042
|
+
topMaxWidth,
|
|
3043
|
+
measureText,
|
|
3044
|
+
maxLines
|
|
3045
|
+
);
|
|
2824
3046
|
const element = {
|
|
2825
3047
|
text: eyebrowNorm.text,
|
|
3048
|
+
...prefix,
|
|
2826
3049
|
...eyebrowNorm.href ? { href: eyebrowNorm.href } : {},
|
|
2827
|
-
x: pad
|
|
3050
|
+
x: alignChromeText(theme.chrome.eyebrow.align, topWidth, pad, eyebrowNorm.offset?.dx).x,
|
|
2828
3051
|
y: topY + (eyebrowNorm.offset?.dy ?? 0),
|
|
2829
|
-
maxWidth,
|
|
3052
|
+
maxWidth: topMaxWidth,
|
|
2830
3053
|
...maxLines != null ? { maxLines } : {},
|
|
2831
3054
|
style
|
|
2832
3055
|
};
|
|
@@ -2844,13 +3067,21 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
|
|
|
2844
3067
|
crampedTitle ? CRAMPED_TITLE_SCALE : 1
|
|
2845
3068
|
);
|
|
2846
3069
|
const maxLines = titleNorm.style?.maxLines;
|
|
2847
|
-
const
|
|
3070
|
+
const prefix = chromePrefix(titleNorm.text, theme.chrome.title.prefix);
|
|
3071
|
+
const lineCount = estimateLineCount(
|
|
3072
|
+
(prefix.prefix ?? "") + titleNorm.text,
|
|
3073
|
+
style,
|
|
3074
|
+
topMaxWidth,
|
|
3075
|
+
measureText,
|
|
3076
|
+
maxLines
|
|
3077
|
+
);
|
|
2848
3078
|
const element = {
|
|
2849
3079
|
text: titleNorm.text,
|
|
3080
|
+
...prefix,
|
|
2850
3081
|
...titleNorm.href ? { href: titleNorm.href } : {},
|
|
2851
|
-
x: pad
|
|
3082
|
+
x: alignChromeText(theme.chrome.title.align, topWidth, pad, titleNorm.offset?.dx).x,
|
|
2852
3083
|
y: topY + (titleNorm.offset?.dy ?? 0),
|
|
2853
|
-
maxWidth,
|
|
3084
|
+
maxWidth: topMaxWidth,
|
|
2854
3085
|
...maxLines != null ? { maxLines } : {},
|
|
2855
3086
|
style
|
|
2856
3087
|
};
|
|
@@ -2867,13 +3098,21 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
|
|
|
2867
3098
|
subtitleNorm.style
|
|
2868
3099
|
);
|
|
2869
3100
|
const maxLines = subtitleNorm.style?.maxLines;
|
|
2870
|
-
const
|
|
3101
|
+
const prefix = chromePrefix(subtitleNorm.text, theme.chrome.subtitle.prefix);
|
|
3102
|
+
const lineCount = estimateLineCount(
|
|
3103
|
+
(prefix.prefix ?? "") + subtitleNorm.text,
|
|
3104
|
+
style,
|
|
3105
|
+
topMaxWidth,
|
|
3106
|
+
measureText,
|
|
3107
|
+
maxLines
|
|
3108
|
+
);
|
|
2871
3109
|
const element = {
|
|
2872
3110
|
text: subtitleNorm.text,
|
|
3111
|
+
...prefix,
|
|
2873
3112
|
...subtitleNorm.href ? { href: subtitleNorm.href } : {},
|
|
2874
|
-
x: pad
|
|
3113
|
+
x: alignChromeText(theme.chrome.subtitle.align, topWidth, pad, subtitleNorm.offset?.dx).x,
|
|
2875
3114
|
y: topY + (subtitleNorm.offset?.dy ?? 0),
|
|
2876
|
-
maxWidth,
|
|
3115
|
+
maxWidth: topMaxWidth,
|
|
2877
3116
|
...maxLines != null ? { maxLines } : {},
|
|
2878
3117
|
style
|
|
2879
3118
|
};
|
|
@@ -2882,7 +3121,8 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
|
|
|
2882
3121
|
}
|
|
2883
3122
|
const hasTopChrome = eyebrowNorm || titleNorm || subtitleNorm;
|
|
2884
3123
|
const chromeToChart = width < COMPACT_WIDTH ? Math.min(theme.spacing.chromeToChart, 2) : theme.spacing.chromeToChart;
|
|
2885
|
-
const
|
|
3124
|
+
const textTopHeight = hasTopChrome ? topY - pad + chromeToChart - chromeGap : 0;
|
|
3125
|
+
const topHeight = topLogo.logo ? Math.max(textTopHeight, topLogo.height + chromeToChart) : textTopHeight;
|
|
2886
3126
|
if (chromeMode === "compact") {
|
|
2887
3127
|
let compactBottom = 0;
|
|
2888
3128
|
if (watermark && width >= BRAND_MIN_WIDTH) {
|
|
@@ -2922,7 +3162,7 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
|
|
|
2922
3162
|
style.textAnchor = "end";
|
|
2923
3163
|
const naturalWidth = Math.max(
|
|
2924
3164
|
...brandNorm.text.split("\n").map(
|
|
2925
|
-
(line) => measureText?.(line, style.fontSize, style.fontWeight).width ?? line.length * estimateCharWidth(style.fontSize, style.fontWeight)
|
|
3165
|
+
(line) => measureText?.(line, style.fontSize, style.fontWeight, style.fontFamily).width ?? line.length * estimateCharWidth(style.fontSize, style.fontWeight)
|
|
2926
3166
|
)
|
|
2927
3167
|
);
|
|
2928
3168
|
brandElement = {
|
|
@@ -2936,11 +3176,21 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
|
|
|
2936
3176
|
};
|
|
2937
3177
|
}
|
|
2938
3178
|
const brand = brandElement ?? watermarkElement;
|
|
3179
|
+
const gap = Math.max(12, chromeGap);
|
|
2939
3180
|
const brandHeight = brand ? estimateTextHeight(
|
|
2940
3181
|
brand.style.fontSize,
|
|
2941
3182
|
estimateLineCount(brand.text, brand.style, brand.maxWidth, measureText, brand.maxLines),
|
|
2942
3183
|
brand.style.lineHeight
|
|
2943
3184
|
) : 0;
|
|
3185
|
+
const rightLogo = planBottomRightLogo(
|
|
3186
|
+
logo,
|
|
3187
|
+
brand?.maxWidth ?? 0,
|
|
3188
|
+
brandHeight,
|
|
3189
|
+
width - pad * 2,
|
|
3190
|
+
gap,
|
|
3191
|
+
startY
|
|
3192
|
+
);
|
|
3193
|
+
if (brand) brand.x -= rightLogo.brandShift;
|
|
2944
3194
|
const items = ["source", "byline", "footer"].flatMap((key) => {
|
|
2945
3195
|
const norm = normalizeChromeText(chrome[key]);
|
|
2946
3196
|
return norm ? [
|
|
@@ -2957,16 +3207,16 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
|
|
|
2957
3207
|
}
|
|
2958
3208
|
] : [];
|
|
2959
3209
|
});
|
|
2960
|
-
const
|
|
2961
|
-
const inlineWidth = brand ? Math.max(0, brand.x - brand.maxWidth - gap - pad) : maxWidth;
|
|
3210
|
+
const inlineWidth = brand ? Math.max(0, brand.x - brand.maxWidth - gap - pad) : rightLogo.reservedWidth > 0 ? Math.max(0, width - pad * 2 - rightLogo.reservedWidth) : maxWidth;
|
|
2962
3211
|
function resolveItems(availableWidth) {
|
|
2963
3212
|
const elements = {};
|
|
2964
3213
|
let y = startY;
|
|
2965
3214
|
let extent = startY;
|
|
2966
3215
|
for (const { key, norm, style } of items) {
|
|
2967
3216
|
const available = Math.max(1, availableWidth - Math.max(0, norm.offset?.dx ?? 0));
|
|
3217
|
+
const prefix = chromePrefix(norm.text, theme.chrome[key].prefix);
|
|
2968
3218
|
const count = estimateLineCount(
|
|
2969
|
-
norm.text,
|
|
3219
|
+
(prefix.prefix ?? "") + norm.text,
|
|
2970
3220
|
style,
|
|
2971
3221
|
available,
|
|
2972
3222
|
measureText,
|
|
@@ -2976,8 +3226,9 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
|
|
|
2976
3226
|
const itemY = y + (norm.offset?.dy ?? 0);
|
|
2977
3227
|
elements[key] = {
|
|
2978
3228
|
text: norm.text,
|
|
3229
|
+
...prefix,
|
|
2979
3230
|
...norm.href ? { href: norm.href } : {},
|
|
2980
|
-
x: pad
|
|
3231
|
+
x: alignChromeText(theme.chrome[key].align, width, pad, norm.offset?.dx).x,
|
|
2981
3232
|
y: itemY,
|
|
2982
3233
|
maxWidth: available,
|
|
2983
3234
|
...norm.style?.maxLines != null ? { maxLines: norm.style.maxLines } : {},
|
|
@@ -2994,13 +3245,34 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
|
|
|
2994
3245
|
}
|
|
2995
3246
|
const full = resolveItems(maxWidth);
|
|
2996
3247
|
const inline = resolveItems(inlineWidth);
|
|
2997
|
-
const
|
|
2998
|
-
const
|
|
2999
|
-
const
|
|
3248
|
+
const rowHeight = rightLogo.height;
|
|
3249
|
+
const inlineHeight = Math.max(inline.height, (brand?.y ?? startY) - startY + rowHeight);
|
|
3250
|
+
const stackedHeight = full.height + (items.length ? chromeGap : 0) + rowHeight + Math.max(0, brandNorm?.offset?.dy ?? 0);
|
|
3251
|
+
const allLeft = items.every(
|
|
3252
|
+
({ key }) => !theme.chrome[key].align || theme.chrome[key].align === "left"
|
|
3253
|
+
);
|
|
3254
|
+
const hasAttribution = !!brand || !!rightLogo.logo;
|
|
3255
|
+
const stacked = items.length > 0 && (!allLeft || rightLogo.ownRow || hasAttribution && (inlineWidth < 40 || stackedHeight < inlineHeight));
|
|
3000
3256
|
const bottomElements = stacked ? full.elements : inline.elements;
|
|
3001
3257
|
if (stacked && brand) brand.y += full.height + chromeGap;
|
|
3002
|
-
|
|
3003
|
-
const
|
|
3258
|
+
let contentHeight = stacked ? hasAttribution ? stackedHeight : full.height : inlineHeight;
|
|
3259
|
+
const bottomLeftLogo = planBottomLeftLogo(
|
|
3260
|
+
logo,
|
|
3261
|
+
startY + contentHeight,
|
|
3262
|
+
chromeGap,
|
|
3263
|
+
!!(items.length || brand)
|
|
3264
|
+
);
|
|
3265
|
+
contentHeight += bottomLeftLogo.height;
|
|
3266
|
+
const positionedLogo = topLogo.logo ?? planBottomRightLogo(
|
|
3267
|
+
logo,
|
|
3268
|
+
brand?.maxWidth ?? 0,
|
|
3269
|
+
brandHeight,
|
|
3270
|
+
width - pad * 2,
|
|
3271
|
+
gap,
|
|
3272
|
+
startY + (stacked ? full.height + chromeGap : 0)
|
|
3273
|
+
).logo ?? bottomLeftLogo.logo;
|
|
3274
|
+
const hasBottom = items.length || brand || logo?.position.startsWith("bottom");
|
|
3275
|
+
const bottomHeight = hasBottom ? startY + contentHeight + pad : bottomLegendHeight;
|
|
3004
3276
|
return {
|
|
3005
3277
|
topHeight,
|
|
3006
3278
|
bottomHeight,
|
|
@@ -3009,28 +3281,29 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
|
|
|
3009
3281
|
...bottomElements,
|
|
3010
3282
|
...brandElement ? { brand: brandElement } : {},
|
|
3011
3283
|
...watermarkElement ? { watermark: watermarkElement } : {},
|
|
3012
|
-
...
|
|
3284
|
+
...hasBottom ? { attributionLayout: stacked ? "stacked" : "inline" } : {},
|
|
3285
|
+
...positionedLogo ? { logo: positionedLogo } : {}
|
|
3013
3286
|
};
|
|
3014
3287
|
}
|
|
3015
3288
|
|
|
3016
3289
|
// src/layout/text-wrap.ts
|
|
3017
|
-
function wrapText(text, fontSize, fontWeight, maxWidth, measureText) {
|
|
3290
|
+
function wrapText(text, fontSize, fontWeight, maxWidth, measureText, fontFamily) {
|
|
3018
3291
|
if (maxWidth <= 0) return [text];
|
|
3019
3292
|
const segments = text.split("\n");
|
|
3020
3293
|
if (segments.length > 1) {
|
|
3021
3294
|
return segments.flatMap(
|
|
3022
|
-
(segment) => segment.length === 0 ? [""] : wrapText(segment, fontSize, fontWeight, maxWidth, measureText)
|
|
3295
|
+
(segment) => segment.length === 0 ? [""] : wrapText(segment, fontSize, fontWeight, maxWidth, measureText, fontFamily)
|
|
3023
3296
|
);
|
|
3024
3297
|
}
|
|
3025
3298
|
if (measureText) {
|
|
3026
|
-
const textWidth = measureText(text, fontSize, fontWeight).width;
|
|
3299
|
+
const textWidth = measureText(text, fontSize, fontWeight, fontFamily).width;
|
|
3027
3300
|
if (textWidth <= maxWidth) return [text];
|
|
3028
3301
|
const words2 = text.split(" ");
|
|
3029
3302
|
const lines2 = [];
|
|
3030
3303
|
let current2 = "";
|
|
3031
3304
|
for (const word of words2) {
|
|
3032
3305
|
const candidate = current2 ? `${current2} ${word}` : word;
|
|
3033
|
-
const candidateWidth = measureText(candidate, fontSize, fontWeight).width;
|
|
3306
|
+
const candidateWidth = measureText(candidate, fontSize, fontWeight, fontFamily).width;
|
|
3034
3307
|
if (candidateWidth > maxWidth && current2) {
|
|
3035
3308
|
lines2.push(current2);
|
|
3036
3309
|
current2 = word;
|
|
@@ -3194,7 +3467,584 @@ function computeLabelBounds(label) {
|
|
|
3194
3467
|
|
|
3195
3468
|
// src/locale/format.ts
|
|
3196
3469
|
import { format as d3Format } from "d3-format";
|
|
3197
|
-
|
|
3470
|
+
|
|
3471
|
+
// src/locale/definitions.ts
|
|
3472
|
+
var GRANULARITY_FORMATS = /* @__PURE__ */ Object.freeze({
|
|
3473
|
+
year: "%Y",
|
|
3474
|
+
quarter: "",
|
|
3475
|
+
// Quarter is handled by formatDate().
|
|
3476
|
+
month: "%b %Y",
|
|
3477
|
+
week: "%b %d",
|
|
3478
|
+
day: "%b %d, %Y",
|
|
3479
|
+
hour: "%b %d %H:%M",
|
|
3480
|
+
minute: "%H:%M"
|
|
3481
|
+
});
|
|
3482
|
+
var GRANULARITY_FORMATS_COMPACT = /* @__PURE__ */ Object.freeze({
|
|
3483
|
+
year: "%Y",
|
|
3484
|
+
quarter: "",
|
|
3485
|
+
// special-cased below, like GRANULARITY_FORMATS
|
|
3486
|
+
month: "%b",
|
|
3487
|
+
week: "%b %d",
|
|
3488
|
+
day: "%b %d",
|
|
3489
|
+
hour: "%H:%M",
|
|
3490
|
+
minute: "%H:%M"
|
|
3491
|
+
});
|
|
3492
|
+
function definition(number, time, day, week, quarter) {
|
|
3493
|
+
Object.freeze(number.grouping);
|
|
3494
|
+
Object.freeze(number.currency);
|
|
3495
|
+
Object.freeze(number);
|
|
3496
|
+
for (const names of [time.periods, time.days, time.shortDays, time.months, time.shortMonths])
|
|
3497
|
+
Object.freeze(names);
|
|
3498
|
+
Object.freeze(time);
|
|
3499
|
+
return Object.freeze({
|
|
3500
|
+
number,
|
|
3501
|
+
time,
|
|
3502
|
+
formats: Object.freeze({
|
|
3503
|
+
year: "%Y",
|
|
3504
|
+
quarter: "",
|
|
3505
|
+
month: "%b %Y",
|
|
3506
|
+
week,
|
|
3507
|
+
day,
|
|
3508
|
+
hour: `${week} %H:%M`,
|
|
3509
|
+
minute: "%H:%M"
|
|
3510
|
+
}),
|
|
3511
|
+
compactFormats: Object.freeze({
|
|
3512
|
+
year: "%Y",
|
|
3513
|
+
quarter: "",
|
|
3514
|
+
month: "%b",
|
|
3515
|
+
week,
|
|
3516
|
+
day: week,
|
|
3517
|
+
hour: "%H:%M",
|
|
3518
|
+
minute: "%H:%M"
|
|
3519
|
+
}),
|
|
3520
|
+
quarter: `${quarter} %Y`,
|
|
3521
|
+
compactQuarter: `${quarter} '%y`
|
|
3522
|
+
});
|
|
3523
|
+
}
|
|
3524
|
+
var LOCALE_DEFINITIONS = /* @__PURE__ */ Object.freeze({
|
|
3525
|
+
"en-US": /* @__PURE__ */ (() => Object.freeze({
|
|
3526
|
+
.../* @__PURE__ */ definition(
|
|
3527
|
+
{
|
|
3528
|
+
decimal: ".",
|
|
3529
|
+
thousands: ",",
|
|
3530
|
+
grouping: [3],
|
|
3531
|
+
currency: ["$", ""],
|
|
3532
|
+
minus: "\u2212",
|
|
3533
|
+
percent: "%"
|
|
3534
|
+
},
|
|
3535
|
+
{
|
|
3536
|
+
dateTime: "%x, %X",
|
|
3537
|
+
date: "%-m/%-d/%Y",
|
|
3538
|
+
time: "%-I:%M:%S %p",
|
|
3539
|
+
periods: ["AM", "PM"],
|
|
3540
|
+
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
|
3541
|
+
shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
|
3542
|
+
months: [
|
|
3543
|
+
"January",
|
|
3544
|
+
"February",
|
|
3545
|
+
"March",
|
|
3546
|
+
"April",
|
|
3547
|
+
"May",
|
|
3548
|
+
"June",
|
|
3549
|
+
"July",
|
|
3550
|
+
"August",
|
|
3551
|
+
"September",
|
|
3552
|
+
"October",
|
|
3553
|
+
"November",
|
|
3554
|
+
"December"
|
|
3555
|
+
],
|
|
3556
|
+
shortMonths: [
|
|
3557
|
+
"Jan",
|
|
3558
|
+
"Feb",
|
|
3559
|
+
"Mar",
|
|
3560
|
+
"Apr",
|
|
3561
|
+
"May",
|
|
3562
|
+
"Jun",
|
|
3563
|
+
"Jul",
|
|
3564
|
+
"Aug",
|
|
3565
|
+
"Sep",
|
|
3566
|
+
"Oct",
|
|
3567
|
+
"Nov",
|
|
3568
|
+
"Dec"
|
|
3569
|
+
]
|
|
3570
|
+
},
|
|
3571
|
+
GRANULARITY_FORMATS.day,
|
|
3572
|
+
GRANULARITY_FORMATS.week,
|
|
3573
|
+
"Q{q}"
|
|
3574
|
+
),
|
|
3575
|
+
formats: GRANULARITY_FORMATS,
|
|
3576
|
+
compactFormats: GRANULARITY_FORMATS_COMPACT
|
|
3577
|
+
}))(),
|
|
3578
|
+
"en-GB": /* @__PURE__ */ definition(
|
|
3579
|
+
{
|
|
3580
|
+
decimal: ".",
|
|
3581
|
+
thousands: ",",
|
|
3582
|
+
grouping: [3],
|
|
3583
|
+
currency: ["$", ""],
|
|
3584
|
+
minus: "\u2212",
|
|
3585
|
+
percent: "%"
|
|
3586
|
+
},
|
|
3587
|
+
{
|
|
3588
|
+
dateTime: "%x, %X",
|
|
3589
|
+
date: "%d/%m/%Y",
|
|
3590
|
+
time: "%H:%M:%S",
|
|
3591
|
+
periods: ["am", "pm"],
|
|
3592
|
+
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
|
3593
|
+
shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
|
3594
|
+
months: [
|
|
3595
|
+
"January",
|
|
3596
|
+
"February",
|
|
3597
|
+
"March",
|
|
3598
|
+
"April",
|
|
3599
|
+
"May",
|
|
3600
|
+
"June",
|
|
3601
|
+
"July",
|
|
3602
|
+
"August",
|
|
3603
|
+
"September",
|
|
3604
|
+
"October",
|
|
3605
|
+
"November",
|
|
3606
|
+
"December"
|
|
3607
|
+
],
|
|
3608
|
+
shortMonths: [
|
|
3609
|
+
"Jan",
|
|
3610
|
+
"Feb",
|
|
3611
|
+
"Mar",
|
|
3612
|
+
"Apr",
|
|
3613
|
+
"May",
|
|
3614
|
+
"Jun",
|
|
3615
|
+
"Jul",
|
|
3616
|
+
"Aug",
|
|
3617
|
+
"Sept",
|
|
3618
|
+
"Oct",
|
|
3619
|
+
"Nov",
|
|
3620
|
+
"Dec"
|
|
3621
|
+
]
|
|
3622
|
+
},
|
|
3623
|
+
"%-d %b %Y",
|
|
3624
|
+
"%-d %b",
|
|
3625
|
+
"Q{q}"
|
|
3626
|
+
),
|
|
3627
|
+
"de-DE": /* @__PURE__ */ definition(
|
|
3628
|
+
{
|
|
3629
|
+
decimal: ",",
|
|
3630
|
+
thousands: ".",
|
|
3631
|
+
grouping: [3],
|
|
3632
|
+
currency: ["$", ""],
|
|
3633
|
+
minus: "\u2212",
|
|
3634
|
+
percent: "\xA0%"
|
|
3635
|
+
},
|
|
3636
|
+
{
|
|
3637
|
+
dateTime: "%x, %X",
|
|
3638
|
+
date: "%d.%m.%y",
|
|
3639
|
+
time: "%H:%M:%S",
|
|
3640
|
+
periods: ["AM", "PM"],
|
|
3641
|
+
days: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
|
|
3642
|
+
shortDays: ["So.", "Mo.", "Di.", "Mi.", "Do.", "Fr.", "Sa."],
|
|
3643
|
+
months: [
|
|
3644
|
+
"Januar",
|
|
3645
|
+
"Februar",
|
|
3646
|
+
"M\xE4rz",
|
|
3647
|
+
"April",
|
|
3648
|
+
"Mai",
|
|
3649
|
+
"Juni",
|
|
3650
|
+
"Juli",
|
|
3651
|
+
"August",
|
|
3652
|
+
"September",
|
|
3653
|
+
"Oktober",
|
|
3654
|
+
"November",
|
|
3655
|
+
"Dezember"
|
|
3656
|
+
],
|
|
3657
|
+
shortMonths: [
|
|
3658
|
+
"Jan.",
|
|
3659
|
+
"Feb.",
|
|
3660
|
+
"M\xE4rz",
|
|
3661
|
+
"Apr.",
|
|
3662
|
+
"Mai",
|
|
3663
|
+
"Juni",
|
|
3664
|
+
"Juli",
|
|
3665
|
+
"Aug.",
|
|
3666
|
+
"Sept.",
|
|
3667
|
+
"Okt.",
|
|
3668
|
+
"Nov.",
|
|
3669
|
+
"Dez."
|
|
3670
|
+
]
|
|
3671
|
+
},
|
|
3672
|
+
"%-d. %b %Y",
|
|
3673
|
+
"%-d. %b",
|
|
3674
|
+
"Q{q}"
|
|
3675
|
+
),
|
|
3676
|
+
"fr-FR": /* @__PURE__ */ definition(
|
|
3677
|
+
{
|
|
3678
|
+
decimal: ",",
|
|
3679
|
+
thousands: "\u202F",
|
|
3680
|
+
grouping: [3],
|
|
3681
|
+
currency: ["$", ""],
|
|
3682
|
+
minus: "\u2212",
|
|
3683
|
+
percent: "\u202F%"
|
|
3684
|
+
},
|
|
3685
|
+
{
|
|
3686
|
+
dateTime: "%x, %X",
|
|
3687
|
+
date: "%d/%m/%Y",
|
|
3688
|
+
time: "%H:%M:%S",
|
|
3689
|
+
periods: ["AM", "PM"],
|
|
3690
|
+
days: ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
|
|
3691
|
+
shortDays: ["dim.", "lun.", "mar.", "mer.", "jeu.", "ven.", "sam."],
|
|
3692
|
+
months: [
|
|
3693
|
+
"janvier",
|
|
3694
|
+
"f\xE9vrier",
|
|
3695
|
+
"mars",
|
|
3696
|
+
"avril",
|
|
3697
|
+
"mai",
|
|
3698
|
+
"juin",
|
|
3699
|
+
"juillet",
|
|
3700
|
+
"ao\xFBt",
|
|
3701
|
+
"septembre",
|
|
3702
|
+
"octobre",
|
|
3703
|
+
"novembre",
|
|
3704
|
+
"d\xE9cembre"
|
|
3705
|
+
],
|
|
3706
|
+
shortMonths: [
|
|
3707
|
+
"janv.",
|
|
3708
|
+
"f\xE9vr.",
|
|
3709
|
+
"mars",
|
|
3710
|
+
"avr.",
|
|
3711
|
+
"mai",
|
|
3712
|
+
"juin",
|
|
3713
|
+
"juil.",
|
|
3714
|
+
"ao\xFBt",
|
|
3715
|
+
"sept.",
|
|
3716
|
+
"oct.",
|
|
3717
|
+
"nov.",
|
|
3718
|
+
"d\xE9c."
|
|
3719
|
+
]
|
|
3720
|
+
},
|
|
3721
|
+
"%-d %b %Y",
|
|
3722
|
+
"%-d %b",
|
|
3723
|
+
"T{q}"
|
|
3724
|
+
),
|
|
3725
|
+
"es-ES": /* @__PURE__ */ definition(
|
|
3726
|
+
{
|
|
3727
|
+
decimal: ",",
|
|
3728
|
+
thousands: ".",
|
|
3729
|
+
grouping: [3],
|
|
3730
|
+
currency: ["$", ""],
|
|
3731
|
+
minus: "\u2212",
|
|
3732
|
+
percent: "\xA0%"
|
|
3733
|
+
},
|
|
3734
|
+
{
|
|
3735
|
+
dateTime: "%x, %X",
|
|
3736
|
+
date: "%-d/%-m/%y",
|
|
3737
|
+
time: "%H:%M:%S",
|
|
3738
|
+
periods: ["a.\xA0m.", "p.\xA0m."],
|
|
3739
|
+
days: ["domingo", "lunes", "martes", "mi\xE9rcoles", "jueves", "viernes", "s\xE1bado"],
|
|
3740
|
+
shortDays: ["dom", "lun", "mar", "mi\xE9", "jue", "vie", "s\xE1b"],
|
|
3741
|
+
months: [
|
|
3742
|
+
"enero",
|
|
3743
|
+
"febrero",
|
|
3744
|
+
"marzo",
|
|
3745
|
+
"abril",
|
|
3746
|
+
"mayo",
|
|
3747
|
+
"junio",
|
|
3748
|
+
"julio",
|
|
3749
|
+
"agosto",
|
|
3750
|
+
"septiembre",
|
|
3751
|
+
"octubre",
|
|
3752
|
+
"noviembre",
|
|
3753
|
+
"diciembre"
|
|
3754
|
+
],
|
|
3755
|
+
shortMonths: [
|
|
3756
|
+
"ene",
|
|
3757
|
+
"feb",
|
|
3758
|
+
"mar",
|
|
3759
|
+
"abr",
|
|
3760
|
+
"may",
|
|
3761
|
+
"jun",
|
|
3762
|
+
"jul",
|
|
3763
|
+
"ago",
|
|
3764
|
+
"sept",
|
|
3765
|
+
"oct",
|
|
3766
|
+
"nov",
|
|
3767
|
+
"dic"
|
|
3768
|
+
]
|
|
3769
|
+
},
|
|
3770
|
+
"%-d %b %Y",
|
|
3771
|
+
"%-d %b",
|
|
3772
|
+
"T{q}"
|
|
3773
|
+
),
|
|
3774
|
+
"pt-BR": /* @__PURE__ */ definition(
|
|
3775
|
+
{
|
|
3776
|
+
decimal: ",",
|
|
3777
|
+
thousands: ".",
|
|
3778
|
+
grouping: [3],
|
|
3779
|
+
currency: ["$", ""],
|
|
3780
|
+
minus: "\u2212",
|
|
3781
|
+
percent: "%"
|
|
3782
|
+
},
|
|
3783
|
+
{
|
|
3784
|
+
dateTime: "%x, %X",
|
|
3785
|
+
date: "%d/%m/%Y",
|
|
3786
|
+
time: "%H:%M:%S",
|
|
3787
|
+
periods: ["AM", "PM"],
|
|
3788
|
+
days: [
|
|
3789
|
+
"domingo",
|
|
3790
|
+
"segunda-feira",
|
|
3791
|
+
"ter\xE7a-feira",
|
|
3792
|
+
"quarta-feira",
|
|
3793
|
+
"quinta-feira",
|
|
3794
|
+
"sexta-feira",
|
|
3795
|
+
"s\xE1bado"
|
|
3796
|
+
],
|
|
3797
|
+
shortDays: ["dom.", "seg.", "ter.", "qua.", "qui.", "sex.", "s\xE1b."],
|
|
3798
|
+
months: [
|
|
3799
|
+
"janeiro",
|
|
3800
|
+
"fevereiro",
|
|
3801
|
+
"mar\xE7o",
|
|
3802
|
+
"abril",
|
|
3803
|
+
"maio",
|
|
3804
|
+
"junho",
|
|
3805
|
+
"julho",
|
|
3806
|
+
"agosto",
|
|
3807
|
+
"setembro",
|
|
3808
|
+
"outubro",
|
|
3809
|
+
"novembro",
|
|
3810
|
+
"dezembro"
|
|
3811
|
+
],
|
|
3812
|
+
shortMonths: [
|
|
3813
|
+
"jan.",
|
|
3814
|
+
"fev.",
|
|
3815
|
+
"mar.",
|
|
3816
|
+
"abr.",
|
|
3817
|
+
"mai.",
|
|
3818
|
+
"jun.",
|
|
3819
|
+
"jul.",
|
|
3820
|
+
"ago.",
|
|
3821
|
+
"set.",
|
|
3822
|
+
"out.",
|
|
3823
|
+
"nov.",
|
|
3824
|
+
"dez."
|
|
3825
|
+
]
|
|
3826
|
+
},
|
|
3827
|
+
"%-d %b %Y",
|
|
3828
|
+
"%-d %b",
|
|
3829
|
+
"T{q}"
|
|
3830
|
+
),
|
|
3831
|
+
"pt-PT": /* @__PURE__ */ definition(
|
|
3832
|
+
{
|
|
3833
|
+
decimal: ",",
|
|
3834
|
+
thousands: "\xA0",
|
|
3835
|
+
grouping: [3],
|
|
3836
|
+
currency: ["$", ""],
|
|
3837
|
+
minus: "\u2212",
|
|
3838
|
+
percent: "%"
|
|
3839
|
+
},
|
|
3840
|
+
{
|
|
3841
|
+
dateTime: "%x, %X",
|
|
3842
|
+
date: "%d/%m/%y",
|
|
3843
|
+
time: "%H:%M:%S",
|
|
3844
|
+
periods: ["a.m.", "p.m."],
|
|
3845
|
+
days: [
|
|
3846
|
+
"domingo",
|
|
3847
|
+
"segunda-feira",
|
|
3848
|
+
"ter\xE7a-feira",
|
|
3849
|
+
"quarta-feira",
|
|
3850
|
+
"quinta-feira",
|
|
3851
|
+
"sexta-feira",
|
|
3852
|
+
"s\xE1bado"
|
|
3853
|
+
],
|
|
3854
|
+
shortDays: ["domingo", "segunda", "ter\xE7a", "quarta", "quinta", "sexta", "s\xE1bado"],
|
|
3855
|
+
months: [
|
|
3856
|
+
"janeiro",
|
|
3857
|
+
"fevereiro",
|
|
3858
|
+
"mar\xE7o",
|
|
3859
|
+
"abril",
|
|
3860
|
+
"maio",
|
|
3861
|
+
"junho",
|
|
3862
|
+
"julho",
|
|
3863
|
+
"agosto",
|
|
3864
|
+
"setembro",
|
|
3865
|
+
"outubro",
|
|
3866
|
+
"novembro",
|
|
3867
|
+
"dezembro"
|
|
3868
|
+
],
|
|
3869
|
+
shortMonths: [
|
|
3870
|
+
"jan.",
|
|
3871
|
+
"fev.",
|
|
3872
|
+
"mar.",
|
|
3873
|
+
"abr.",
|
|
3874
|
+
"mai.",
|
|
3875
|
+
"jun.",
|
|
3876
|
+
"jul.",
|
|
3877
|
+
"ago.",
|
|
3878
|
+
"set.",
|
|
3879
|
+
"out.",
|
|
3880
|
+
"nov.",
|
|
3881
|
+
"dez."
|
|
3882
|
+
]
|
|
3883
|
+
},
|
|
3884
|
+
"%-d %b %Y",
|
|
3885
|
+
"%-d %b",
|
|
3886
|
+
"T{q}"
|
|
3887
|
+
),
|
|
3888
|
+
"it-IT": /* @__PURE__ */ definition(
|
|
3889
|
+
{
|
|
3890
|
+
decimal: ",",
|
|
3891
|
+
thousands: ".",
|
|
3892
|
+
grouping: [3],
|
|
3893
|
+
currency: ["$", ""],
|
|
3894
|
+
minus: "\u2212",
|
|
3895
|
+
percent: "%"
|
|
3896
|
+
},
|
|
3897
|
+
{
|
|
3898
|
+
dateTime: "%x, %X",
|
|
3899
|
+
date: "%d/%m/%y",
|
|
3900
|
+
time: "%H:%M:%S",
|
|
3901
|
+
periods: ["AM", "PM"],
|
|
3902
|
+
days: ["domenica", "luned\xEC", "marted\xEC", "mercoled\xEC", "gioved\xEC", "venerd\xEC", "sabato"],
|
|
3903
|
+
shortDays: ["dom", "lun", "mar", "mer", "gio", "ven", "sab"],
|
|
3904
|
+
months: [
|
|
3905
|
+
"gennaio",
|
|
3906
|
+
"febbraio",
|
|
3907
|
+
"marzo",
|
|
3908
|
+
"aprile",
|
|
3909
|
+
"maggio",
|
|
3910
|
+
"giugno",
|
|
3911
|
+
"luglio",
|
|
3912
|
+
"agosto",
|
|
3913
|
+
"settembre",
|
|
3914
|
+
"ottobre",
|
|
3915
|
+
"novembre",
|
|
3916
|
+
"dicembre"
|
|
3917
|
+
],
|
|
3918
|
+
shortMonths: [
|
|
3919
|
+
"gen",
|
|
3920
|
+
"feb",
|
|
3921
|
+
"mar",
|
|
3922
|
+
"apr",
|
|
3923
|
+
"mag",
|
|
3924
|
+
"giu",
|
|
3925
|
+
"lug",
|
|
3926
|
+
"ago",
|
|
3927
|
+
"set",
|
|
3928
|
+
"ott",
|
|
3929
|
+
"nov",
|
|
3930
|
+
"dic"
|
|
3931
|
+
]
|
|
3932
|
+
},
|
|
3933
|
+
"%-d %b %Y",
|
|
3934
|
+
"%-d %b",
|
|
3935
|
+
"T{q}"
|
|
3936
|
+
),
|
|
3937
|
+
"nl-NL": /* @__PURE__ */ definition(
|
|
3938
|
+
{
|
|
3939
|
+
decimal: ",",
|
|
3940
|
+
thousands: ".",
|
|
3941
|
+
grouping: [3],
|
|
3942
|
+
currency: ["$", ""],
|
|
3943
|
+
minus: "\u2212",
|
|
3944
|
+
percent: "%"
|
|
3945
|
+
},
|
|
3946
|
+
{
|
|
3947
|
+
dateTime: "%x, %X",
|
|
3948
|
+
date: "%-d-%-m-%Y",
|
|
3949
|
+
time: "%H:%M:%S",
|
|
3950
|
+
periods: ["a.m.", "p.m."],
|
|
3951
|
+
days: ["zondag", "maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag"],
|
|
3952
|
+
shortDays: ["zo", "ma", "di", "wo", "do", "vr", "za"],
|
|
3953
|
+
months: [
|
|
3954
|
+
"januari",
|
|
3955
|
+
"februari",
|
|
3956
|
+
"maart",
|
|
3957
|
+
"april",
|
|
3958
|
+
"mei",
|
|
3959
|
+
"juni",
|
|
3960
|
+
"juli",
|
|
3961
|
+
"augustus",
|
|
3962
|
+
"september",
|
|
3963
|
+
"oktober",
|
|
3964
|
+
"november",
|
|
3965
|
+
"december"
|
|
3966
|
+
],
|
|
3967
|
+
shortMonths: [
|
|
3968
|
+
"jan",
|
|
3969
|
+
"feb",
|
|
3970
|
+
"mrt",
|
|
3971
|
+
"apr",
|
|
3972
|
+
"mei",
|
|
3973
|
+
"jun",
|
|
3974
|
+
"jul",
|
|
3975
|
+
"aug",
|
|
3976
|
+
"sep",
|
|
3977
|
+
"okt",
|
|
3978
|
+
"nov",
|
|
3979
|
+
"dec"
|
|
3980
|
+
]
|
|
3981
|
+
},
|
|
3982
|
+
"%-d %b %Y",
|
|
3983
|
+
"%-d %b",
|
|
3984
|
+
"K{q}"
|
|
3985
|
+
)
|
|
3986
|
+
});
|
|
3987
|
+
|
|
3988
|
+
// src/locale/format-locale.ts
|
|
3989
|
+
import { format, formatLocale, formatPrefix } from "d3-format";
|
|
3990
|
+
import { timeFormat, timeFormatLocale, timeParse, utcFormat, utcParse } from "d3-time-format";
|
|
3991
|
+
var DEFAULT_NUMBER_LOCALE = { format, formatPrefix };
|
|
3992
|
+
var DEFAULT_TIME_LOCALE = { format: timeFormat, parse: timeParse, utcFormat, utcParse };
|
|
3993
|
+
var LOCALE_TAGS = /* @__PURE__ */ new Map();
|
|
3994
|
+
var NUMBER_LOCALES = /* @__PURE__ */ new Map();
|
|
3995
|
+
var TIME_LOCALES = /* @__PURE__ */ new Map();
|
|
3996
|
+
var NUMBER_FORMATTERS = /* @__PURE__ */ new Map();
|
|
3997
|
+
function localeTag(locale) {
|
|
3998
|
+
if (locale === void 0 || locale === "en-US" || typeof locale !== "string") return "en-US";
|
|
3999
|
+
const cached = LOCALE_TAGS.get(locale);
|
|
4000
|
+
if (cached) return cached;
|
|
4001
|
+
const matched = matchLocale(locale);
|
|
4002
|
+
if (!matched) return "en-US";
|
|
4003
|
+
LOCALE_TAGS.set(locale, matched);
|
|
4004
|
+
return matched;
|
|
4005
|
+
}
|
|
4006
|
+
function getNumberLocale(locale) {
|
|
4007
|
+
if (locale === void 0 || locale === "en-US") return DEFAULT_NUMBER_LOCALE;
|
|
4008
|
+
const tag = localeTag(locale);
|
|
4009
|
+
if (tag === "en-US") return DEFAULT_NUMBER_LOCALE;
|
|
4010
|
+
let result = NUMBER_LOCALES.get(tag);
|
|
4011
|
+
if (!result) {
|
|
4012
|
+
result = formatLocale(LOCALE_DEFINITIONS[tag].number);
|
|
4013
|
+
NUMBER_LOCALES.set(tag, result);
|
|
4014
|
+
}
|
|
4015
|
+
return result;
|
|
4016
|
+
}
|
|
4017
|
+
function getTimeLocale(locale) {
|
|
4018
|
+
if (locale === void 0 || locale === "en-US") return DEFAULT_TIME_LOCALE;
|
|
4019
|
+
return getTimeLocaleForTag(localeTag(locale));
|
|
4020
|
+
}
|
|
4021
|
+
function getTimeLocaleForTag(tag) {
|
|
4022
|
+
if (tag === "en-US") return DEFAULT_TIME_LOCALE;
|
|
4023
|
+
let result = TIME_LOCALES.get(tag);
|
|
4024
|
+
if (!result) {
|
|
4025
|
+
result = timeFormatLocale(LOCALE_DEFINITIONS[tag].time);
|
|
4026
|
+
TIME_LOCALES.set(tag, result);
|
|
4027
|
+
}
|
|
4028
|
+
return result;
|
|
4029
|
+
}
|
|
4030
|
+
function numberFormatter(fallback, pattern, locale) {
|
|
4031
|
+
if (locale === void 0 || locale === "en-US") return fallback;
|
|
4032
|
+
const tag = localeTag(locale);
|
|
4033
|
+
if (tag === "en-US") return fallback;
|
|
4034
|
+
let cache = NUMBER_FORMATTERS.get(tag);
|
|
4035
|
+
if (!cache) {
|
|
4036
|
+
cache = /* @__PURE__ */ new Map();
|
|
4037
|
+
NUMBER_FORMATTERS.set(tag, cache);
|
|
4038
|
+
}
|
|
4039
|
+
let formatter = cache.get(pattern);
|
|
4040
|
+
if (!formatter) {
|
|
4041
|
+
formatter = getNumberLocale(tag).format(pattern);
|
|
4042
|
+
cache.set(pattern, formatter);
|
|
4043
|
+
}
|
|
4044
|
+
return formatter;
|
|
4045
|
+
}
|
|
4046
|
+
|
|
4047
|
+
// src/locale/format.ts
|
|
3198
4048
|
var FORMAT_INTEGER = /* @__PURE__ */ d3Format(",");
|
|
3199
4049
|
var FORMAT_TINY = /* @__PURE__ */ d3Format(".2~r");
|
|
3200
4050
|
var FORMAT_DECIMAL = /* @__PURE__ */ d3Format(",.2f");
|
|
@@ -3214,15 +4064,21 @@ var FORMAT_STEP_PRECISION = [
|
|
|
3214
4064
|
/* @__PURE__ */ d3Format(",.2~f"),
|
|
3215
4065
|
/* @__PURE__ */ d3Format(",.3~f")
|
|
3216
4066
|
];
|
|
3217
|
-
function formatNumber(value,
|
|
4067
|
+
function formatNumber(value, locale) {
|
|
3218
4068
|
if (!Number.isFinite(value)) return String(value);
|
|
3219
4069
|
if (Number.isInteger(value)) {
|
|
3220
|
-
return FORMAT_INTEGER(value);
|
|
4070
|
+
return numberFormatter(FORMAT_INTEGER, ",", locale)(value);
|
|
3221
4071
|
}
|
|
3222
4072
|
if (Math.abs(value) < 5e-3) {
|
|
3223
|
-
return FORMAT_TINY(value);
|
|
4073
|
+
return numberFormatter(FORMAT_TINY, ".2~r", locale)(value);
|
|
3224
4074
|
}
|
|
3225
|
-
return FORMAT_DECIMAL(value);
|
|
4075
|
+
return numberFormatter(FORMAT_DECIMAL, ",.2f", locale)(value);
|
|
4076
|
+
}
|
|
4077
|
+
function formatRawNumber(value, locale) {
|
|
4078
|
+
const tag = localeTag(locale);
|
|
4079
|
+
const { decimal, minus } = LOCALE_DEFINITIONS[tag].number;
|
|
4080
|
+
const text = String(value).replace(".", decimal);
|
|
4081
|
+
return tag !== "en-US" && text.startsWith("-") ? minus + text.slice(1) : text;
|
|
3226
4082
|
}
|
|
3227
4083
|
var UNIT_TABLE = [
|
|
3228
4084
|
{ threshold: 1e12, suffix: "T", divisor: 1e12 },
|
|
@@ -3244,21 +4100,21 @@ function fractionDigits(x) {
|
|
|
3244
4100
|
}
|
|
3245
4101
|
return 4;
|
|
3246
4102
|
}
|
|
3247
|
-
function abbreviateNumber(value) {
|
|
4103
|
+
function abbreviateNumber(value, locale) {
|
|
3248
4104
|
if (!Number.isFinite(value)) return String(value);
|
|
3249
4105
|
const absValue = Math.abs(value);
|
|
3250
4106
|
const sign = value < 0 ? "-" : "";
|
|
3251
4107
|
for (let i = 0; i < UNIT_TABLE.length; i++) {
|
|
3252
4108
|
const { threshold, suffix, divisor } = UNIT_TABLE[i];
|
|
3253
4109
|
if (absValue >= threshold) {
|
|
3254
|
-
const mantissa = FORMAT_ABBREV_MANTISSA(absValue / divisor);
|
|
4110
|
+
const mantissa = numberFormatter(FORMAT_ABBREV_MANTISSA, ".1~f", locale)(absValue / divisor);
|
|
3255
4111
|
if (mantissa === "1000" && i > 0) {
|
|
3256
4112
|
return `${sign}1${UNIT_TABLE[i - 1].suffix}`;
|
|
3257
4113
|
}
|
|
3258
4114
|
return `${sign}${mantissa}${suffix}`;
|
|
3259
4115
|
}
|
|
3260
4116
|
}
|
|
3261
|
-
return formatNumber(value);
|
|
4117
|
+
return formatNumber(value, locale);
|
|
3262
4118
|
}
|
|
3263
4119
|
function formatOrdinal(value) {
|
|
3264
4120
|
if (!Number.isFinite(value)) return String(value);
|
|
@@ -3275,17 +4131,17 @@ function formatOrdinal(value) {
|
|
|
3275
4131
|
return `${n}${suffix}`;
|
|
3276
4132
|
}
|
|
3277
4133
|
var D3_FORMAT_SUFFIX_RE = /^(.*~?[efgsrdxXobcnp%])(.+)$/;
|
|
3278
|
-
function buildD3Formatter(formatStr) {
|
|
4134
|
+
function buildD3Formatter(formatStr, locale) {
|
|
3279
4135
|
if (!formatStr) return null;
|
|
3280
4136
|
if (formatStr === "ordinal") return formatOrdinal;
|
|
3281
4137
|
if (formatStr === "compact") {
|
|
3282
4138
|
return (v) => {
|
|
3283
4139
|
if (!Number.isFinite(v)) return String(v);
|
|
3284
|
-
return Math.abs(v) >= 1e3 ? abbreviateNumber(v) : formatNumber(v);
|
|
4140
|
+
return Math.abs(v) >= 1e3 ? abbreviateNumber(v, locale) : formatNumber(v, locale);
|
|
3285
4141
|
};
|
|
3286
4142
|
}
|
|
3287
4143
|
try {
|
|
3288
|
-
const fmt = /* @__PURE__ */
|
|
4144
|
+
const fmt = /* @__PURE__ */ getNumberLocale(locale).format(formatStr);
|
|
3289
4145
|
if (formatStr.includes("s")) {
|
|
3290
4146
|
return (v) => fmt(v).replace(/G$/, "B");
|
|
3291
4147
|
}
|
|
@@ -3294,7 +4150,7 @@ function buildD3Formatter(formatStr) {
|
|
|
3294
4150
|
const m = formatStr.match(D3_FORMAT_SUFFIX_RE);
|
|
3295
4151
|
if (m) {
|
|
3296
4152
|
try {
|
|
3297
|
-
const fmt = /* @__PURE__ */
|
|
4153
|
+
const fmt = /* @__PURE__ */ getNumberLocale(locale).format(m[1]);
|
|
3298
4154
|
const suffix = m[2];
|
|
3299
4155
|
return (v) => fmt(v) + suffix;
|
|
3300
4156
|
} catch {
|
|
@@ -3305,29 +4161,32 @@ function buildD3Formatter(formatStr) {
|
|
|
3305
4161
|
}
|
|
3306
4162
|
function formatPercent2(value, options) {
|
|
3307
4163
|
const fraction = options?.fraction ?? true;
|
|
4164
|
+
const locale = options?.locale;
|
|
4165
|
+
const suffix = LOCALE_DEFINITIONS[localeTag(locale)].number.percent;
|
|
3308
4166
|
const percent = fraction ? value * 100 : value;
|
|
3309
4167
|
if (Number.isFinite(percent) && percent !== 0 && Math.abs(percent) < 0.1) {
|
|
3310
|
-
return percent < 0 ? `>${FORMAT_PERCENT_RAW(-0.1)}
|
|
4168
|
+
return percent < 0 ? `>${numberFormatter(FORMAT_PERCENT_RAW, ",.1~f", locale)(-0.1)}${suffix}` : `<${numberFormatter(FORMAT_PERCENT_RAW, ",.1~f", locale)(0.1)}${suffix}`;
|
|
3311
4169
|
}
|
|
3312
4170
|
if (fraction) {
|
|
3313
|
-
return FORMAT_PERCENT_FRACTION(value);
|
|
4171
|
+
return numberFormatter(FORMAT_PERCENT_FRACTION, ".1~%", locale)(value);
|
|
3314
4172
|
}
|
|
3315
|
-
return `${FORMAT_PERCENT_RAW(value)}
|
|
4173
|
+
return `${numberFormatter(FORMAT_PERCENT_RAW, ",.1~f", locale)(value)}${suffix}`;
|
|
3316
4174
|
}
|
|
3317
4175
|
function formatCurrency(value, options) {
|
|
3318
4176
|
const compact = options?.compact ?? false;
|
|
4177
|
+
const locale = options?.locale;
|
|
3319
4178
|
const abs = Math.abs(value);
|
|
3320
4179
|
const sign = value < 0 ? "-" : "";
|
|
3321
4180
|
if (compact) {
|
|
3322
4181
|
if (abs >= 1e3) {
|
|
3323
|
-
return `${sign}$${abbreviateNumber(abs)}`;
|
|
4182
|
+
return `${sign}$${abbreviateNumber(abs, locale)}`;
|
|
3324
4183
|
}
|
|
3325
|
-
return `${sign}$${formatNumber(abs)}`;
|
|
4184
|
+
return `${sign}$${formatNumber(abs, locale)}`;
|
|
3326
4185
|
}
|
|
3327
4186
|
if (Number.isInteger(value)) {
|
|
3328
|
-
return sign + FORMAT_CURRENCY_INTEGER(abs);
|
|
4187
|
+
return sign + numberFormatter(FORMAT_CURRENCY_INTEGER, "$,", locale)(abs);
|
|
3329
4188
|
}
|
|
3330
|
-
return sign + FORMAT_CURRENCY_DECIMAL(abs);
|
|
4189
|
+
return sign + numberFormatter(FORMAT_CURRENCY_DECIMAL, "$,.2f", locale)(abs);
|
|
3331
4190
|
}
|
|
3332
4191
|
function computeFieldFormatContext(values, surface) {
|
|
3333
4192
|
let min = Infinity;
|
|
@@ -3357,44 +4216,46 @@ function isYearContext(ctx) {
|
|
|
3357
4216
|
}
|
|
3358
4217
|
function resolveNumberFormatter(formatStr, ctx) {
|
|
3359
4218
|
if (!formatStr) return null;
|
|
4219
|
+
const locale = ctx?.locale;
|
|
3360
4220
|
if (formatStr === "ordinal") return formatOrdinal;
|
|
3361
4221
|
if (formatStr === "compact") {
|
|
3362
4222
|
return (v) => {
|
|
3363
4223
|
if (!Number.isFinite(v)) return String(v);
|
|
3364
|
-
return Math.abs(v) >= 1e3 ? abbreviateNumber(v) : formatNumber(v);
|
|
4224
|
+
return Math.abs(v) >= 1e3 ? abbreviateNumber(v, locale) : formatNumber(v, locale);
|
|
3365
4225
|
};
|
|
3366
4226
|
}
|
|
3367
4227
|
if (formatStr === "percent") {
|
|
3368
4228
|
const fraction = ctx?.extent ? Math.max(Math.abs(ctx.extent[0]), Math.abs(ctx.extent[1])) <= 1 : true;
|
|
3369
|
-
return (v) => formatPercent2(v, { fraction });
|
|
4229
|
+
return (v) => formatPercent2(v, { fraction, locale });
|
|
3370
4230
|
}
|
|
3371
4231
|
if (formatStr === "currency") {
|
|
3372
4232
|
const isTable = ctx?.surface === "table";
|
|
3373
4233
|
if (!isTable && ctx?.step != null && (ctx.stepReference ?? 0) >= 1e3) {
|
|
3374
|
-
const stepFmt = buildCompactStepFormatter(ctx.step);
|
|
4234
|
+
const stepFmt = buildCompactStepFormatter(ctx.step, locale);
|
|
3375
4235
|
return (v) => {
|
|
3376
4236
|
const sign = v < 0 ? "-" : "";
|
|
3377
4237
|
return `${sign}$${stepFmt(Math.abs(v))}`;
|
|
3378
4238
|
};
|
|
3379
4239
|
}
|
|
3380
|
-
return (v) => formatCurrency(v, { compact: !isTable });
|
|
4240
|
+
return (v) => formatCurrency(v, { compact: !isTable, locale });
|
|
3381
4241
|
}
|
|
3382
|
-
return buildD3Formatter(formatStr);
|
|
4242
|
+
return buildD3Formatter(formatStr, locale);
|
|
3383
4243
|
}
|
|
3384
4244
|
function defaultNumberFormatter(ctx) {
|
|
4245
|
+
const locale = ctx?.locale;
|
|
3385
4246
|
if (isYearContext(ctx)) {
|
|
3386
4247
|
return (v) => String(Math.round(v));
|
|
3387
4248
|
}
|
|
3388
4249
|
if (ctx?.surface === "table") {
|
|
3389
|
-
return formatNumber;
|
|
4250
|
+
return (v) => formatNumber(v, locale);
|
|
3390
4251
|
}
|
|
3391
4252
|
if (ctx?.step != null && (ctx.stepReference ?? maxAbs(ctx.extent)) >= 1e3) {
|
|
3392
|
-
return buildCompactStepFormatter(ctx.step);
|
|
4253
|
+
return buildCompactStepFormatter(ctx.step, locale);
|
|
3393
4254
|
}
|
|
3394
4255
|
if (ctx?.step != null && ctx.step > 0) {
|
|
3395
4256
|
const p = fractionDigits(ctx.step);
|
|
3396
4257
|
if (p <= 3) {
|
|
3397
|
-
const fmt = FORMAT_STEP_PRECISION[p];
|
|
4258
|
+
const fmt = numberFormatter(FORMAT_STEP_PRECISION[p], `,.${p}~f`, locale);
|
|
3398
4259
|
return (v) => Number.isFinite(v) ? fmt(v) : String(v);
|
|
3399
4260
|
}
|
|
3400
4261
|
}
|
|
@@ -3403,87 +4264,77 @@ function defaultNumberFormatter(ctx) {
|
|
|
3403
4264
|
if (ctx?.extent === void 0 && ctx?.allIntegers === void 0) {
|
|
3404
4265
|
if (Number.isInteger(v) && v >= 1500 && v <= 2500) return String(v);
|
|
3405
4266
|
}
|
|
3406
|
-
return Math.abs(v) >= 1e3 ? abbreviateNumber(v) : formatNumber(v);
|
|
4267
|
+
return Math.abs(v) >= 1e3 ? abbreviateNumber(v, locale) : formatNumber(v, locale);
|
|
3407
4268
|
};
|
|
3408
4269
|
}
|
|
3409
4270
|
function maxAbs(extent) {
|
|
3410
4271
|
if (!extent) return 0;
|
|
3411
4272
|
return Math.max(Math.abs(extent[0]), Math.abs(extent[1]));
|
|
3412
4273
|
}
|
|
3413
|
-
function buildCompactStepFormatter(step) {
|
|
4274
|
+
function buildCompactStepFormatter(step, locale) {
|
|
3414
4275
|
return (v) => {
|
|
3415
4276
|
if (v === 0) return "0";
|
|
3416
4277
|
if (!Number.isFinite(v)) return String(v);
|
|
3417
4278
|
const abs = Math.abs(v);
|
|
3418
|
-
if (abs < 1e3) return formatNumber(v);
|
|
4279
|
+
if (abs < 1e3) return formatNumber(v, locale);
|
|
3419
4280
|
const { suffix, divisor } = unitFor(abs);
|
|
3420
4281
|
const p = fractionDigits(step / divisor);
|
|
3421
4282
|
if (p > 2) {
|
|
3422
|
-
return Number.isInteger(v) ? FORMAT_INTEGER(v) : FORMAT_DECIMAL(v);
|
|
4283
|
+
return Number.isInteger(v) ? numberFormatter(FORMAT_INTEGER, ",", locale)(v) : numberFormatter(FORMAT_DECIMAL, ",.2f", locale)(v);
|
|
3423
4284
|
}
|
|
3424
4285
|
const sign = v < 0 ? "-" : "";
|
|
3425
|
-
return sign + FORMAT_STEP_FRACTION[p](abs / divisor) + suffix;
|
|
4286
|
+
return sign + numberFormatter(FORMAT_STEP_FRACTION[p], `.${p}~f`, locale)(abs / divisor) + suffix;
|
|
3426
4287
|
};
|
|
3427
4288
|
}
|
|
3428
|
-
|
|
3429
|
-
year: "%Y",
|
|
3430
|
-
quarter: "",
|
|
3431
|
-
// Quarter is always special-cased in formatDate() below
|
|
3432
|
-
month: "%b %Y",
|
|
3433
|
-
week: "%b %d",
|
|
3434
|
-
day: "%b %d, %Y",
|
|
3435
|
-
hour: "%b %d %H:%M",
|
|
3436
|
-
minute: "%H:%M"
|
|
3437
|
-
};
|
|
3438
|
-
var GRANULARITY_FORMATS_COMPACT = {
|
|
3439
|
-
year: "%Y",
|
|
3440
|
-
quarter: "",
|
|
3441
|
-
// special-cased below, like GRANULARITY_FORMATS
|
|
3442
|
-
month: "%b",
|
|
3443
|
-
week: "%b %d",
|
|
3444
|
-
day: "%b %d",
|
|
3445
|
-
hour: "%H:%M",
|
|
3446
|
-
minute: "%H:%M"
|
|
3447
|
-
};
|
|
3448
|
-
function formatDate(value, _locale, granularity, useUtc = true, compact = false) {
|
|
4289
|
+
function formatDate(value, locale, granularity, useUtc = true, compact = false) {
|
|
3449
4290
|
const date = value instanceof Date ? value : new Date(value);
|
|
3450
4291
|
if (Number.isNaN(date.getTime())) return String(value);
|
|
3451
4292
|
const gran = granularity ?? inferGranularity(date, useUtc);
|
|
4293
|
+
const tag = localeTag(locale);
|
|
4294
|
+
const definition2 = LOCALE_DEFINITIONS[tag];
|
|
3452
4295
|
if (gran === "quarter") {
|
|
3453
4296
|
const q = useUtc ? Math.ceil((date.getUTCMonth() + 1) / 3) : Math.ceil((date.getMonth() + 1) / 3);
|
|
3454
4297
|
const year = useUtc ? date.getUTCFullYear() : date.getFullYear();
|
|
4298
|
+
if (tag !== "en-US") {
|
|
4299
|
+
const template = compact ? definition2.compactQuarter : definition2.quarter;
|
|
4300
|
+
const pattern = template.replace("{q}", String(q));
|
|
4301
|
+
return (useUtc ? getUtcFormatter(pattern, tag) : getTimeFormatter(pattern, tag))(date);
|
|
4302
|
+
}
|
|
3455
4303
|
if (compact) {
|
|
3456
4304
|
return `Q${q} '${String(year).slice(-2)}`;
|
|
3457
4305
|
}
|
|
3458
4306
|
return `Q${q} ${year}`;
|
|
3459
4307
|
}
|
|
3460
|
-
const
|
|
4308
|
+
const formats = compact ? definition2.compactFormats : definition2.formats;
|
|
4309
|
+
const formatStr = formats[gran];
|
|
3461
4310
|
if (useUtc) {
|
|
3462
|
-
return getUtcFormatter(formatStr)(date);
|
|
4311
|
+
return getUtcFormatter(formatStr, tag)(date);
|
|
3463
4312
|
}
|
|
3464
|
-
return getTimeFormatter(formatStr)(date);
|
|
4313
|
+
return getTimeFormatter(formatStr, tag)(date);
|
|
3465
4314
|
}
|
|
3466
4315
|
var TIME_FORMAT_CACHE = /* @__PURE__ */ new Map();
|
|
3467
4316
|
var UTC_FORMAT_CACHE = /* @__PURE__ */ new Map();
|
|
3468
|
-
function getTimeFormatter(formatStr) {
|
|
3469
|
-
|
|
4317
|
+
function getTimeFormatter(formatStr, tag) {
|
|
4318
|
+
const key = `${tag}:${formatStr}`;
|
|
4319
|
+
let fmt = TIME_FORMAT_CACHE.get(key);
|
|
3470
4320
|
if (!fmt) {
|
|
3471
|
-
fmt =
|
|
3472
|
-
TIME_FORMAT_CACHE.set(
|
|
4321
|
+
fmt = getTimeLocaleForTag(tag).format(formatStr);
|
|
4322
|
+
TIME_FORMAT_CACHE.set(key, fmt);
|
|
3473
4323
|
}
|
|
3474
4324
|
return fmt;
|
|
3475
4325
|
}
|
|
3476
|
-
function getUtcFormatter(formatStr) {
|
|
3477
|
-
|
|
4326
|
+
function getUtcFormatter(formatStr, tag) {
|
|
4327
|
+
const key = `${tag}:${formatStr}`;
|
|
4328
|
+
let fmt = UTC_FORMAT_CACHE.get(key);
|
|
3478
4329
|
if (!fmt) {
|
|
3479
|
-
fmt = utcFormat(formatStr);
|
|
3480
|
-
UTC_FORMAT_CACHE.set(
|
|
4330
|
+
fmt = getTimeLocaleForTag(tag).utcFormat(formatStr);
|
|
4331
|
+
UTC_FORMAT_CACHE.set(key, fmt);
|
|
3481
4332
|
}
|
|
3482
4333
|
return fmt;
|
|
3483
4334
|
}
|
|
3484
|
-
function buildTemporalFormatter(formatStr) {
|
|
4335
|
+
function buildTemporalFormatter(formatStr, locale) {
|
|
3485
4336
|
if (!formatStr) return null;
|
|
3486
|
-
const fmt = utcFormat(formatStr);
|
|
4337
|
+
const fmt = getTimeLocale(locale).utcFormat(formatStr);
|
|
3487
4338
|
return (value) => {
|
|
3488
4339
|
const date = value instanceof Date ? value : new Date(value);
|
|
3489
4340
|
if (Number.isNaN(date.getTime())) return String(value);
|
|
@@ -3504,7 +4355,8 @@ function inferGranularity(date, useUtc = true) {
|
|
|
3504
4355
|
}
|
|
3505
4356
|
|
|
3506
4357
|
// src/accessibility/alt-text.ts
|
|
3507
|
-
function generateAltText(spec, data) {
|
|
4358
|
+
function generateAltText(spec, data, locale) {
|
|
4359
|
+
const number = getNumberLocale(locale).format("d");
|
|
3508
4360
|
const markType = resolveMarkType(spec.mark);
|
|
3509
4361
|
const markDef = resolveMarkDef(spec.mark);
|
|
3510
4362
|
let chartName = MARK_DISPLAY_NAMES[markType] ?? `${markType} chart`;
|
|
@@ -3523,7 +4375,7 @@ function generateAltText(spec, data) {
|
|
|
3523
4375
|
}
|
|
3524
4376
|
if (markDef.type === "waffle") {
|
|
3525
4377
|
const units = markDef.units ?? 100;
|
|
3526
|
-
parts.push(`dividing ${units} units`);
|
|
4378
|
+
parts.push(`dividing ${number(units)} units`);
|
|
3527
4379
|
}
|
|
3528
4380
|
if (markType === "parliament") {
|
|
3529
4381
|
const valueField = spec.encoding.theta?.field ?? spec.encoding.y?.field;
|
|
@@ -3534,7 +4386,7 @@ function generateAltText(spec, data) {
|
|
|
3534
4386
|
}, 0);
|
|
3535
4387
|
if (totalSeats > 0) {
|
|
3536
4388
|
const majority = Math.floor(totalSeats / 2) + 1;
|
|
3537
|
-
parts.push(`with ${totalSeats} seats, ${majority} needed for a majority`);
|
|
4389
|
+
parts.push(`with ${number(totalSeats)} seats, ${number(majority)} needed for a majority`);
|
|
3538
4390
|
}
|
|
3539
4391
|
}
|
|
3540
4392
|
}
|
|
@@ -3571,7 +4423,7 @@ function generateAltText(spec, data) {
|
|
|
3571
4423
|
}
|
|
3572
4424
|
} else if (spec.encoding.x.type === "nominal" || spec.encoding.x.type === "ordinal") {
|
|
3573
4425
|
const uniqueValues = [...new Set(values.map(String))];
|
|
3574
|
-
parts.push(`across ${uniqueValues.length} categories`);
|
|
4426
|
+
parts.push(`across ${number(uniqueValues.length)} categories`);
|
|
3575
4427
|
}
|
|
3576
4428
|
}
|
|
3577
4429
|
}
|
|
@@ -3579,14 +4431,17 @@ function generateAltText(spec, data) {
|
|
|
3579
4431
|
const colorField = spec.encoding.color.field;
|
|
3580
4432
|
const uniqueSeries = [...new Set(data.map((d) => String(d[colorField])).filter(Boolean))];
|
|
3581
4433
|
if (uniqueSeries.length > 0) {
|
|
3582
|
-
parts.push(`with ${uniqueSeries.length} series (${uniqueSeries.join(", ")})`);
|
|
4434
|
+
parts.push(`with ${number(uniqueSeries.length)} series (${uniqueSeries.join(", ")})`);
|
|
3583
4435
|
}
|
|
3584
4436
|
}
|
|
3585
|
-
parts.push(`(${data.length} data points)`);
|
|
4437
|
+
parts.push(`(${number(data.length)} data points)`);
|
|
3586
4438
|
return parts.join(" ");
|
|
3587
4439
|
}
|
|
3588
4440
|
var MAX_SR_TABLE_ROWS = 1e3;
|
|
3589
|
-
function generateDataTable(spec, data) {
|
|
4441
|
+
function generateDataTable(spec, data, locale) {
|
|
4442
|
+
const tag = localeTag(locale);
|
|
4443
|
+
const localized = tag !== "en-US";
|
|
4444
|
+
const symbols = LOCALE_DEFINITIONS[tag].number;
|
|
3590
4445
|
const fields = [];
|
|
3591
4446
|
const encoding = spec.encoding;
|
|
3592
4447
|
if (encoding.x) fields.push(encoding.x.field);
|
|
@@ -3596,12 +4451,53 @@ function generateDataTable(spec, data) {
|
|
|
3596
4451
|
const uniqueFields = [...new Set(fields)];
|
|
3597
4452
|
if (uniqueFields.length === 0) return [];
|
|
3598
4453
|
const headers = uniqueFields;
|
|
3599
|
-
const
|
|
4454
|
+
const granularities = /* @__PURE__ */ new Map();
|
|
4455
|
+
if (localized) {
|
|
4456
|
+
const precision = [
|
|
4457
|
+
"year",
|
|
4458
|
+
"quarter",
|
|
4459
|
+
"month",
|
|
4460
|
+
"week",
|
|
4461
|
+
"day",
|
|
4462
|
+
"hour",
|
|
4463
|
+
"minute"
|
|
4464
|
+
];
|
|
4465
|
+
for (const field of uniqueFields) {
|
|
4466
|
+
const temporal = [encoding.x, encoding.y, encoding.color, encoding.size].some(
|
|
4467
|
+
(channel) => channel && "field" in channel && channel.field === field && channel.type === "temporal"
|
|
4468
|
+
);
|
|
4469
|
+
for (const row of data) {
|
|
4470
|
+
const value = row[field];
|
|
4471
|
+
if (value == null || !temporal && !(value instanceof Date)) continue;
|
|
4472
|
+
const date = value instanceof Date ? value : new Date(String(value));
|
|
4473
|
+
if (Number.isNaN(date.getTime())) continue;
|
|
4474
|
+
const granularity = inferGranularity(date);
|
|
4475
|
+
const current = granularities.get(field);
|
|
4476
|
+
if (!current || precision.indexOf(granularity) > precision.indexOf(current))
|
|
4477
|
+
granularities.set(field, granularity);
|
|
4478
|
+
}
|
|
4479
|
+
}
|
|
4480
|
+
}
|
|
4481
|
+
const rows = data.slice(0, MAX_SR_TABLE_ROWS).map(
|
|
4482
|
+
(row) => uniqueFields.map((field) => {
|
|
4483
|
+
const value = row[field];
|
|
4484
|
+
if (!localized || value == null) return value ?? "";
|
|
4485
|
+
const granularity = granularities.get(field);
|
|
4486
|
+
if (granularity) {
|
|
4487
|
+
const date = value instanceof Date ? value : new Date(String(value));
|
|
4488
|
+
return Number.isNaN(date.getTime()) ? String(value) : formatDate(date, tag, granularity);
|
|
4489
|
+
}
|
|
4490
|
+
return typeof value === "number" ? String(value).replace(".", symbols.decimal).replace(/^-/, symbols.minus ?? "\u2212") : value;
|
|
4491
|
+
})
|
|
4492
|
+
);
|
|
3600
4493
|
return [headers, ...rows];
|
|
3601
4494
|
}
|
|
3602
4495
|
|
|
3603
4496
|
// src/accessibility/aria.ts
|
|
3604
|
-
function generateAriaLabels(marks) {
|
|
4497
|
+
function generateAriaLabels(marks, locale) {
|
|
4498
|
+
const localized = localeTag(locale) !== "en-US";
|
|
4499
|
+
const numberFormatter2 = localized ? defaultNumberFormatter({ locale }) : ariaNumberFormatter;
|
|
4500
|
+
const countFormatter = getNumberLocale(locale).format("d");
|
|
3605
4501
|
const labels = /* @__PURE__ */ new Map();
|
|
3606
4502
|
for (let i = 0; i < marks.length; i++) {
|
|
3607
4503
|
const mark = marks[i];
|
|
@@ -3610,7 +4506,7 @@ function generateAriaLabels(marks) {
|
|
|
3610
4506
|
case "line": {
|
|
3611
4507
|
const series = mark.seriesKey ?? "Series";
|
|
3612
4508
|
const pointCount = mark.points.length;
|
|
3613
|
-
labels.set(key, `Line series: ${series} with ${pointCount} points`);
|
|
4509
|
+
labels.set(key, `Line series: ${series} with ${countFormatter(pointCount)} points`);
|
|
3614
4510
|
break;
|
|
3615
4511
|
}
|
|
3616
4512
|
case "area": {
|
|
@@ -3620,19 +4516,25 @@ function generateAriaLabels(marks) {
|
|
|
3620
4516
|
}
|
|
3621
4517
|
case "rect": {
|
|
3622
4518
|
const dataEntries = Object.entries(mark.data).filter(([k]) => !k.startsWith("_"));
|
|
3623
|
-
const description = dataEntries.map(
|
|
4519
|
+
const description = dataEntries.map(
|
|
4520
|
+
([k, v]) => `${k}: ${formatValue(v, numberFormatter2, localized ? locale : void 0)}`
|
|
4521
|
+
).join(", ");
|
|
3624
4522
|
labels.set(key, `Data point: ${description}`);
|
|
3625
4523
|
break;
|
|
3626
4524
|
}
|
|
3627
4525
|
case "arc": {
|
|
3628
4526
|
const dataEntries = Object.entries(mark.data).filter(([k]) => !k.startsWith("_"));
|
|
3629
|
-
const description = dataEntries.map(
|
|
4527
|
+
const description = dataEntries.map(
|
|
4528
|
+
([k, v]) => `${k}: ${formatValue(v, numberFormatter2, localized ? locale : void 0)}`
|
|
4529
|
+
).join(", ");
|
|
3630
4530
|
labels.set(key, `Slice: ${description}`);
|
|
3631
4531
|
break;
|
|
3632
4532
|
}
|
|
3633
4533
|
case "point": {
|
|
3634
4534
|
const dataEntries = Object.entries(mark.data).filter(([k]) => !k.startsWith("_"));
|
|
3635
|
-
const description = dataEntries.map(
|
|
4535
|
+
const description = dataEntries.map(
|
|
4536
|
+
([k, v]) => `${k}: ${formatValue(v, numberFormatter2, localized ? locale : void 0)}`
|
|
4537
|
+
).join(", ");
|
|
3636
4538
|
labels.set(key, `Data point: ${description}`);
|
|
3637
4539
|
break;
|
|
3638
4540
|
}
|
|
@@ -3641,11 +4543,12 @@ function generateAriaLabels(marks) {
|
|
|
3641
4543
|
return labels;
|
|
3642
4544
|
}
|
|
3643
4545
|
var ariaNumberFormatter = /* @__PURE__ */ defaultNumberFormatter();
|
|
3644
|
-
function formatValue(value) {
|
|
4546
|
+
function formatValue(value, numberFormatter2, locale) {
|
|
3645
4547
|
if (value == null) return "N/A";
|
|
3646
|
-
if (value instanceof Date)
|
|
4548
|
+
if (value instanceof Date)
|
|
4549
|
+
return locale ? formatDate(value, locale, "day") : value.toISOString().slice(0, 10);
|
|
3647
4550
|
if (typeof value === "number") {
|
|
3648
|
-
return
|
|
4551
|
+
return numberFormatter2(value);
|
|
3649
4552
|
}
|
|
3650
4553
|
return String(value);
|
|
3651
4554
|
}
|
|
@@ -4918,6 +5821,7 @@ export {
|
|
|
4918
5821
|
NARROW_VIEWPORT_MAX,
|
|
4919
5822
|
OFFSET_STRATEGIES,
|
|
4920
5823
|
SEQUENTIAL_PALETTES,
|
|
5824
|
+
SUPPORTED_LOCALES,
|
|
4921
5825
|
SUPPORTED_SCHEME_NAMES,
|
|
4922
5826
|
TICK_LABEL_OFFSET,
|
|
4923
5827
|
TICK_LINE_HEIGHT_FACTOR,
|
|
@@ -4941,6 +5845,7 @@ export {
|
|
|
4941
5845
|
buildCompactStepFormatter,
|
|
4942
5846
|
buildD3Formatter,
|
|
4943
5847
|
buildTemporalFormatter,
|
|
5848
|
+
canonicalSchemeName,
|
|
4944
5849
|
checkPaletteDistinguishability,
|
|
4945
5850
|
clampStaggerDelay,
|
|
4946
5851
|
clarity,
|
|
@@ -4980,6 +5885,7 @@ export {
|
|
|
4980
5885
|
formatNumber,
|
|
4981
5886
|
formatOrdinal,
|
|
4982
5887
|
formatPercent2 as formatPercent,
|
|
5888
|
+
formatRawNumber,
|
|
4983
5889
|
generateAltText,
|
|
4984
5890
|
generateAriaLabels,
|
|
4985
5891
|
generateDataTable,
|
|
@@ -5007,7 +5913,9 @@ export {
|
|
|
5007
5913
|
isRangeAnnotation,
|
|
5008
5914
|
isRefLineAnnotation,
|
|
5009
5915
|
isSafeLink,
|
|
5916
|
+
isSafeLogoSource,
|
|
5010
5917
|
isSankeySpec,
|
|
5918
|
+
isSupportedLocale,
|
|
5011
5919
|
isTableSpec,
|
|
5012
5920
|
isTextAnnotation,
|
|
5013
5921
|
isTileMapSpec,
|
|
@@ -5020,6 +5928,7 @@ export {
|
|
|
5020
5928
|
lineChart,
|
|
5021
5929
|
mapFeatureDuration,
|
|
5022
5930
|
mapSweepTiming,
|
|
5931
|
+
matchLocale,
|
|
5023
5932
|
maxRotatedLabelWidth,
|
|
5024
5933
|
meetsAA,
|
|
5025
5934
|
mergeThemeConfig,
|