@opendata-ai/openchart-core 8.9.1 → 9.0.0-rc.2
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/README.md +3 -2
- package/dist/index.d.ts +704 -348
- package/dist/index.js +353 -247
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.css.map +1 -1
- package/package.json +1 -1
- package/schema/chart.schema.json +1475 -5266
- package/schema/table.schema.json +64 -89
- package/schema/vizspec.schema.json +2040 -9798
package/dist/index.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
// src/helpers/json-pointer.ts
|
|
2
|
+
function encodePointerToken(token) {
|
|
3
|
+
return String(token).replace(/~/g, "~0").replace(/\//g, "~1");
|
|
4
|
+
}
|
|
5
|
+
function jsonPointer(...tokens2) {
|
|
6
|
+
return tokens2.map((token) => `/${encodePointerToken(token)}`).join("");
|
|
7
|
+
}
|
|
8
|
+
|
|
1
9
|
// src/helpers/edit-transactions.ts
|
|
2
10
|
function isContainer(value) {
|
|
3
11
|
return Array.isArray(value) || value !== null && typeof value === "object" && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
@@ -18,9 +26,6 @@ function tokens(path) {
|
|
|
18
26
|
return decoded;
|
|
19
27
|
});
|
|
20
28
|
}
|
|
21
|
-
function pointer(parts) {
|
|
22
|
-
return `/${parts.map((part) => part.replace(/~/g, "~0").replace(/\//g, "~1")).join("/")}`;
|
|
23
|
-
}
|
|
24
29
|
function keyAt(parent, token, insert = false) {
|
|
25
30
|
if (!Array.isArray(parent)) return token;
|
|
26
31
|
if (insert && token === "-") return parent.length;
|
|
@@ -51,7 +56,8 @@ function checkExpectation(root, parts, expected) {
|
|
|
51
56
|
if (!isContainer(target) || Array.isArray(target))
|
|
52
57
|
throw new Error("Annotation target is invalid.");
|
|
53
58
|
for (const field of ["id", "type", "text"]) {
|
|
54
|
-
|
|
59
|
+
const actual = field === "text" && target.type !== "text" ? target.label : target[field];
|
|
60
|
+
if (Object.hasOwn(expected, field) && actual !== expected[field]) {
|
|
55
61
|
throw new Error(`Annotation ${field} changed; discard the stale edit.`);
|
|
56
62
|
}
|
|
57
63
|
}
|
|
@@ -75,7 +81,7 @@ function applyEditTransaction(spec, tx) {
|
|
|
75
81
|
if (op.op !== "add" || Array.isArray(parent))
|
|
76
82
|
throw new Error("Intermediate container is missing.");
|
|
77
83
|
parent[key2] = /^(0|[1-9]\d*|-)$/.test(parts[i + 1]) ? [] : {};
|
|
78
|
-
created.push(
|
|
84
|
+
created.push(jsonPointer(...parts.slice(0, i + 1)));
|
|
79
85
|
}
|
|
80
86
|
parent = read(parent, key2);
|
|
81
87
|
}
|
|
@@ -83,7 +89,7 @@ function applyEditTransaction(spec, tx) {
|
|
|
83
89
|
const key = keyAt(parent, parts.at(-1), op.op === "add");
|
|
84
90
|
const exists = Object.hasOwn(parent, key);
|
|
85
91
|
const old = read(parent, key);
|
|
86
|
-
const path =
|
|
92
|
+
const path = jsonPointer(...parts.slice(0, -1), key);
|
|
87
93
|
let undo;
|
|
88
94
|
if (op.op === "remove") {
|
|
89
95
|
if (!exists) throw new Error("Edit target no longer exists.");
|
|
@@ -343,11 +349,6 @@ var elementRef = {
|
|
|
343
349
|
key,
|
|
344
350
|
...path !== void 0 ? { path } : {}
|
|
345
351
|
}),
|
|
346
|
-
seriesLabel: (series, path) => ({
|
|
347
|
-
type: "series-label",
|
|
348
|
-
series,
|
|
349
|
-
...path !== void 0 ? { path } : {}
|
|
350
|
-
}),
|
|
351
352
|
legend: (path) => ({
|
|
352
353
|
type: "legend",
|
|
353
354
|
...path !== void 0 ? { path } : {}
|
|
@@ -441,8 +442,7 @@ function isRangeAnnotation(annotation) {
|
|
|
441
442
|
return annotation.type === "range";
|
|
442
443
|
}
|
|
443
444
|
function isRefLineAnnotation(annotation) {
|
|
444
|
-
|
|
445
|
-
return type === "refline" || type === "rule";
|
|
445
|
+
return annotation.type === "refline";
|
|
446
446
|
}
|
|
447
447
|
var MARK_DISPLAY_NAMES = {
|
|
448
448
|
bar: "Bar chart",
|
|
@@ -636,16 +636,61 @@ var CSS_TOKENS = [
|
|
|
636
636
|
{ name: "--oc-title-tracking", light: "-0.022em" },
|
|
637
637
|
{ name: "--oc-subtitle-size", light: "14px" },
|
|
638
638
|
{ name: "--oc-subtitle-weight", light: "400" },
|
|
639
|
-
{ name: "--oc-source-size", light: "
|
|
639
|
+
{ name: "--oc-source-size", light: "12px" },
|
|
640
640
|
{ name: "--oc-source-weight", light: "400" },
|
|
641
641
|
{ name: "--oc-body-size", light: "13px" },
|
|
642
|
+
{
|
|
643
|
+
name: "--oc-gridline-zero",
|
|
644
|
+
light: "rgba(0, 0, 0, 0.22)",
|
|
645
|
+
dark: "rgba(255, 255, 255, 0.24)",
|
|
646
|
+
comment: "Emphasis for existing zero rules; does not change the domain"
|
|
647
|
+
},
|
|
648
|
+
{
|
|
649
|
+
name: "--oc-endpoint-label-size",
|
|
650
|
+
light: "13px",
|
|
651
|
+
consumers: "Endpoint geometry and authored theme stamp"
|
|
652
|
+
},
|
|
653
|
+
{
|
|
654
|
+
name: "--oc-endpoint-value-size",
|
|
655
|
+
light: "12px",
|
|
656
|
+
consumers: "Endpoint geometry and authored theme stamp"
|
|
657
|
+
},
|
|
658
|
+
{ name: "--oc-endpoint-entry-gap", light: "6px", consumers: "Endpoint collision spacing" },
|
|
659
|
+
{ name: "--oc-endpoint-value-gap", light: "4px", consumers: "Endpoint internal spacing" },
|
|
660
|
+
{
|
|
661
|
+
name: "--oc-endpoint-column-gap",
|
|
662
|
+
light: "18px",
|
|
663
|
+
consumers: "Endpoint frame reservation and placement"
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
name: "--oc-map-no-data-fill",
|
|
667
|
+
light: "#f0f0f0",
|
|
668
|
+
dark: "#171719",
|
|
669
|
+
comment: "Engine omission derives neutral[100] from the active theme"
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
name: "--oc-map-no-data-hatch",
|
|
673
|
+
light: "#c9c9c9",
|
|
674
|
+
dark: "#3d3e3f",
|
|
675
|
+
comment: "Engine omission derives neutral[300] from the active theme"
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
name: "--oc-map-interior-border",
|
|
679
|
+
light: "rgba(0, 0, 0, 0.14)",
|
|
680
|
+
dark: "rgba(255, 255, 255, 0.18)"
|
|
681
|
+
},
|
|
682
|
+
{
|
|
683
|
+
name: "--oc-map-outline-border",
|
|
684
|
+
light: "rgba(0, 0, 0, 0.4)",
|
|
685
|
+
dark: "rgba(255, 255, 255, 0.38)"
|
|
686
|
+
},
|
|
642
687
|
{ name: "--oc-annotation-label", light: "#333333", dark: "#d1d5db" },
|
|
643
688
|
{ name: "--oc-annotation-muted", light: "#6b7280", dark: "#9ca3af" },
|
|
644
689
|
{ name: "--oc-annotation-leader", light: "#8f8f8f", dark: "#9aa0a6" },
|
|
645
|
-
{ name: "--oc-annotation-rule", light: "#
|
|
646
|
-
{ name: "--oc-annotation-range-fill", light: "#
|
|
647
|
-
{ name: "--oc-annotation-marker-fill", light: "#ffffff", dark: "#
|
|
648
|
-
{ name: "--oc-annotation-plate", light: "#ffffff", dark: "#
|
|
690
|
+
{ name: "--oc-annotation-rule", light: "#888888", dark: "#9ca3af" },
|
|
691
|
+
{ name: "--oc-annotation-range-fill", light: "#f0c040", dark: "#f0c040" },
|
|
692
|
+
{ name: "--oc-annotation-marker-fill", light: "#ffffff", dark: "#09090b" },
|
|
693
|
+
{ name: "--oc-annotation-plate", light: "#ffffff", dark: "#09090b" },
|
|
649
694
|
{ name: "--oc-eyebrow-size", light: "11px" },
|
|
650
695
|
{ name: "--oc-eyebrow-weight", light: "500" },
|
|
651
696
|
{ name: "--oc-eyebrow-tracking", light: "0.08em" },
|
|
@@ -693,7 +738,7 @@ var CSS_TOKENS = [
|
|
|
693
738
|
{
|
|
694
739
|
section: "Lines",
|
|
695
740
|
name: "--oc-gridline",
|
|
696
|
-
light: "rgba(0, 0, 0, 0.
|
|
741
|
+
light: "rgba(0, 0, 0, 0.05)",
|
|
697
742
|
dark: "rgba(255, 255, 255, 0.06)"
|
|
698
743
|
},
|
|
699
744
|
{
|
|
@@ -1480,10 +1525,8 @@ function axisTitleOffset(maxTickLabelWidth, titleFontSize, width, inline = false
|
|
|
1480
1525
|
}
|
|
1481
1526
|
var NARROW_VIEWPORT_MAX = 500;
|
|
1482
1527
|
var TOP_PAD_EXTRA_NARROW = 10;
|
|
1483
|
-
var TOP_PAD_NARROW_MAX = NARROW_VIEWPORT_MAX;
|
|
1484
1528
|
var LABEL_GAP_COMPACT = 8;
|
|
1485
1529
|
var LABEL_GAP_DEFAULT = 12;
|
|
1486
|
-
var LABEL_GAP_NARROW_MAX = NARROW_VIEWPORT_MAX;
|
|
1487
1530
|
var MAX_LEFT_LABEL_FRACTION_MEDIUM_MAX = 600;
|
|
1488
1531
|
var MAX_LEFT_LABEL_FRACTION_COMPACT = 0.45;
|
|
1489
1532
|
var MAX_LEFT_LABEL_FRACTION_MEDIUM = 0.55;
|
|
@@ -1546,6 +1589,17 @@ function truncateRotatedLabel(label, tickAngle, tickFontSize, tickFontWeight, me
|
|
|
1546
1589
|
}
|
|
1547
1590
|
|
|
1548
1591
|
// src/theme/defaults.ts
|
|
1592
|
+
var FONT_SIZES = {
|
|
1593
|
+
title: 26,
|
|
1594
|
+
subtitle: 14,
|
|
1595
|
+
body: 13,
|
|
1596
|
+
small: 12,
|
|
1597
|
+
axisTick: 12,
|
|
1598
|
+
metricLabel: 11,
|
|
1599
|
+
metricValue: 22,
|
|
1600
|
+
endpointLabel: 13,
|
|
1601
|
+
endpointValue: 12
|
|
1602
|
+
};
|
|
1549
1603
|
var DEFAULT_THEME = {
|
|
1550
1604
|
colors: {
|
|
1551
1605
|
categorical: [...CATEGORICAL_PALETTE],
|
|
@@ -1554,7 +1608,10 @@ var DEFAULT_THEME = {
|
|
|
1554
1608
|
diverging: DIVERGING_PALETTES,
|
|
1555
1609
|
background: "transparent",
|
|
1556
1610
|
text: "#09090b",
|
|
1557
|
-
gridline: "rgba(0,0,0,0.
|
|
1611
|
+
gridline: "rgba(0,0,0,0.05)",
|
|
1612
|
+
gridlineZero: "rgba(0,0,0,0.22)",
|
|
1613
|
+
mapInteriorBorder: "rgba(0,0,0,0.14)",
|
|
1614
|
+
mapOutlineBorder: "rgba(0,0,0,0.40)",
|
|
1558
1615
|
// Structural hairline: axis lines, separators. Deliberately heavier than
|
|
1559
1616
|
// the gridline and lighter than any ink, so structure reads as structure.
|
|
1560
1617
|
hairline: "rgba(0,0,0,0.14)",
|
|
@@ -1567,8 +1624,8 @@ var DEFAULT_THEME = {
|
|
|
1567
1624
|
annotationLabel: "#333333",
|
|
1568
1625
|
annotationMuted: "#6b7280",
|
|
1569
1626
|
annotationLeader: "#8f8f8f",
|
|
1570
|
-
annotationRule: "#
|
|
1571
|
-
annotationRangeFill: "#
|
|
1627
|
+
annotationRule: "#888888",
|
|
1628
|
+
annotationRangeFill: "#f0c040",
|
|
1572
1629
|
annotationMarkerFill: "#ffffff",
|
|
1573
1630
|
annotationPlate: "#ffffff",
|
|
1574
1631
|
positive: "#15803d",
|
|
@@ -1577,15 +1634,7 @@ var DEFAULT_THEME = {
|
|
|
1577
1634
|
fonts: {
|
|
1578
1635
|
family: '"Inter Variable", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
1579
1636
|
mono: '"JetBrains Mono", "Fira Code", "Cascadia Code", monospace',
|
|
1580
|
-
sizes:
|
|
1581
|
-
title: 26,
|
|
1582
|
-
subtitle: 14,
|
|
1583
|
-
body: 13,
|
|
1584
|
-
small: 11,
|
|
1585
|
-
axisTick: 11,
|
|
1586
|
-
metricLabel: 11,
|
|
1587
|
-
metricValue: 22
|
|
1588
|
-
},
|
|
1637
|
+
sizes: FONT_SIZES,
|
|
1589
1638
|
// One ladder everywhere: 400 regular / 500 medium (eyebrow, labels, UI,
|
|
1590
1639
|
// values) / 600 semibold (title, series names, annotation lede) / 700 bold.
|
|
1591
1640
|
weights: {
|
|
@@ -1598,8 +1647,8 @@ var DEFAULT_THEME = {
|
|
|
1598
1647
|
spacing: {
|
|
1599
1648
|
padding: 20,
|
|
1600
1649
|
chromeGap: 6,
|
|
1601
|
-
chromeToChart:
|
|
1602
|
-
chartToFooter:
|
|
1650
|
+
chromeToChart: 16,
|
|
1651
|
+
chartToFooter: 12,
|
|
1603
1652
|
axisMargin: 6,
|
|
1604
1653
|
xAxisHeight: X_AXIS_BAND_HEIGHT,
|
|
1605
1654
|
// Gap (px) between the x-axis line and the TOP of the tick labels. The
|
|
@@ -1607,7 +1656,10 @@ var DEFAULT_THEME = {
|
|
|
1607
1656
|
// by textAscent() to land it on the alphabetic baseline (rather than
|
|
1608
1657
|
// dominant-baseline:hanging, which WebKit positions from different metrics),
|
|
1609
1658
|
// so the gap holds regardless of font size.
|
|
1610
|
-
xAxisLabelPadding: 4
|
|
1659
|
+
xAxisLabelPadding: 4,
|
|
1660
|
+
endpointEntryGap: 6,
|
|
1661
|
+
endpointValueGap: 4,
|
|
1662
|
+
endpointColumnGap: 18
|
|
1611
1663
|
},
|
|
1612
1664
|
/** Containers and tooltips. Marks carry their own 2px radius constant. */
|
|
1613
1665
|
borderRadius: 8,
|
|
@@ -1619,31 +1671,31 @@ var DEFAULT_THEME = {
|
|
|
1619
1671
|
lineHeight: 1.4
|
|
1620
1672
|
},
|
|
1621
1673
|
title: {
|
|
1622
|
-
fontSize:
|
|
1674
|
+
fontSize: FONT_SIZES.title,
|
|
1623
1675
|
fontWeight: 600,
|
|
1624
1676
|
color: "#09090b",
|
|
1625
1677
|
lineHeight: 1.15
|
|
1626
1678
|
},
|
|
1627
1679
|
subtitle: {
|
|
1628
|
-
fontSize:
|
|
1680
|
+
fontSize: FONT_SIZES.subtitle,
|
|
1629
1681
|
fontWeight: 400,
|
|
1630
1682
|
color: "#71717a",
|
|
1631
1683
|
lineHeight: 1.45
|
|
1632
1684
|
},
|
|
1633
1685
|
source: {
|
|
1634
|
-
fontSize:
|
|
1686
|
+
fontSize: FONT_SIZES.small,
|
|
1635
1687
|
fontWeight: 400,
|
|
1636
1688
|
color: "#71717a",
|
|
1637
1689
|
lineHeight: 1.4
|
|
1638
1690
|
},
|
|
1639
1691
|
byline: {
|
|
1640
|
-
fontSize:
|
|
1692
|
+
fontSize: FONT_SIZES.small,
|
|
1641
1693
|
fontWeight: 400,
|
|
1642
1694
|
color: "#71717a",
|
|
1643
1695
|
lineHeight: 1.4
|
|
1644
1696
|
},
|
|
1645
1697
|
footer: {
|
|
1646
|
-
fontSize:
|
|
1698
|
+
fontSize: FONT_SIZES.small,
|
|
1647
1699
|
fontWeight: 400,
|
|
1648
1700
|
color: "#71717a",
|
|
1649
1701
|
lineHeight: 1.4
|
|
@@ -1726,6 +1778,9 @@ function adaptTheme(theme) {
|
|
|
1726
1778
|
const categoricalFill = overridden(theme.colors.categoricalFill, light.categoricalFill, [
|
|
1727
1779
|
...CATEGORICAL_FILL_PALETTE_DARK
|
|
1728
1780
|
]);
|
|
1781
|
+
const neutral = deriveNeutralRamp(darkText, darkBg, true);
|
|
1782
|
+
const authoredColors = theme._authored?.colors && !Array.isArray(theme._authored.colors) ? theme._authored.colors : {};
|
|
1783
|
+
const authoredColor = (key, fallback) => pairs?.[`colors.${key}`]?.dark ?? (authoredColors[key] !== void 0 ? theme.colors[key] ?? fallback : fallback);
|
|
1729
1784
|
return {
|
|
1730
1785
|
...theme,
|
|
1731
1786
|
isDark: true,
|
|
@@ -1734,22 +1789,27 @@ function adaptTheme(theme) {
|
|
|
1734
1789
|
background: darkBg,
|
|
1735
1790
|
text: darkText,
|
|
1736
1791
|
gridline: darkGridline,
|
|
1792
|
+
gridlineZero: authoredColor("gridlineZero", "rgba(255,255,255,0.24)"),
|
|
1737
1793
|
axis: darkAxis,
|
|
1738
1794
|
annotationFill: pairs?.["colors.annotationFill"] ? pairs["colors.annotationFill"].dark : overridden(theme.colors.annotationFill, light.annotationFill, "rgba(255,255,255,0.06)"),
|
|
1739
1795
|
annotationText: pairs?.["colors.annotationText"] ? pairs["colors.annotationText"].dark : overridden(theme.colors.annotationText, light.annotationText, darkMuted),
|
|
1740
|
-
annotationLabel:
|
|
1741
|
-
annotationMuted:
|
|
1742
|
-
annotationLeader:
|
|
1743
|
-
annotationRule:
|
|
1744
|
-
annotationRangeFill:
|
|
1745
|
-
annotationMarkerFill: pairs?.["colors.annotationMarkerFill"]?.dark ??
|
|
1746
|
-
annotationPlate: pairs?.["colors.annotationPlate"]?.dark ??
|
|
1796
|
+
annotationLabel: authoredColor("annotationLabel", "#d1d5db"),
|
|
1797
|
+
annotationMuted: authoredColor("annotationMuted", "#9ca3af"),
|
|
1798
|
+
annotationLeader: authoredColor("annotationLeader", "#9aa0a6"),
|
|
1799
|
+
annotationRule: authoredColor("annotationRule", "#9ca3af"),
|
|
1800
|
+
annotationRangeFill: authoredColor("annotationRangeFill", "#f0c040"),
|
|
1801
|
+
annotationMarkerFill: pairs?.["colors.annotationMarkerFill"]?.dark ?? (authoredColors.annotationMarkerFill !== void 0 ? theme.colors.annotationMarkerFill : neutral.surface),
|
|
1802
|
+
annotationPlate: pairs?.["colors.annotationPlate"]?.dark ?? (authoredColors.annotationPlate !== void 0 ? theme.colors.annotationPlate : neutral.surface),
|
|
1803
|
+
mapNoDataFill: pairs?.["colors.mapNoDataFill"]?.dark ?? theme.colors.mapNoDataFill,
|
|
1804
|
+
mapNoDataHatch: pairs?.["colors.mapNoDataHatch"]?.dark ?? theme.colors.mapNoDataHatch,
|
|
1805
|
+
mapInteriorBorder: authoredColor("mapInteriorBorder", "rgba(255,255,255,0.18)"),
|
|
1806
|
+
mapOutlineBorder: authoredColor("mapOutlineBorder", "rgba(255,255,255,0.38)"),
|
|
1747
1807
|
categorical,
|
|
1748
1808
|
categoricalFill,
|
|
1749
1809
|
hairline: darkHairline,
|
|
1750
1810
|
positive: pairs?.["colors.positive"] ? pairs["colors.positive"].dark : overridden(theme.colors.positive, light.positive, "#4ade80"),
|
|
1751
1811
|
negative: pairs?.["colors.negative"] ? pairs["colors.negative"].dark : overridden(theme.colors.negative, light.negative, "#f87171"),
|
|
1752
|
-
neutral
|
|
1812
|
+
neutral
|
|
1753
1813
|
},
|
|
1754
1814
|
chrome: {
|
|
1755
1815
|
// Eyebrow keeps its accent tint (cyan in both modes) unless the user
|
|
@@ -1781,8 +1841,9 @@ function adaptTheme(theme) {
|
|
|
1781
1841
|
}
|
|
1782
1842
|
},
|
|
1783
1843
|
// The editorial rule is a brand device: it keeps its authored color unless
|
|
1784
|
-
// the theme gave an explicit dark half of the pair.
|
|
1785
|
-
|
|
1844
|
+
// the theme gave an explicit dark half of the pair. A partial rule with no
|
|
1845
|
+
// color derives from text ink, so it follows the dark text.
|
|
1846
|
+
rule: theme.rule && pairs?.["rule.color"] ? { ...theme.rule, color: pairs["rule.color"].dark } : theme.rule && theme._authored?.rule?.color === void 0 && theme.rule.color === theme.colors.text ? { ...theme.rule, color: darkText } : theme.rule
|
|
1786
1847
|
};
|
|
1787
1848
|
}
|
|
1788
1849
|
function adaptForLightLineStroke(color) {
|
|
@@ -1796,12 +1857,26 @@ function adaptForLightLineStroke(color) {
|
|
|
1796
1857
|
}
|
|
1797
1858
|
|
|
1798
1859
|
// src/theme/merge.ts
|
|
1860
|
+
function isRecord(value) {
|
|
1861
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1862
|
+
}
|
|
1863
|
+
function mergeThemeObjects(base, override) {
|
|
1864
|
+
if (!isRecord(override) || "light" in override || "dark" in override) return override;
|
|
1865
|
+
const result = isRecord(base) ? { ...base } : {};
|
|
1866
|
+
for (const [key, value] of Object.entries(override)) {
|
|
1867
|
+
if (value !== void 0) result[key] = mergeThemeObjects(result[key], value);
|
|
1868
|
+
}
|
|
1869
|
+
return result;
|
|
1870
|
+
}
|
|
1871
|
+
function normalize(config) {
|
|
1872
|
+
return Array.isArray(config.colors) ? { ...config, colors: { categorical: config.colors } } : config;
|
|
1873
|
+
}
|
|
1799
1874
|
function mergeThemeConfig(base, override) {
|
|
1800
|
-
|
|
1875
|
+
if (!override) return base;
|
|
1876
|
+
return mergeThemeObjects(base ? normalize(base) : {}, normalize(override));
|
|
1801
1877
|
}
|
|
1802
1878
|
|
|
1803
1879
|
// src/theme/presets.ts
|
|
1804
|
-
var editorial = {};
|
|
1805
1880
|
var essay = {
|
|
1806
1881
|
colors: {
|
|
1807
1882
|
background: { light: "#faf8f5", dark: "#1a1816" },
|
|
@@ -1874,7 +1949,7 @@ var broadsheet = {
|
|
|
1874
1949
|
},
|
|
1875
1950
|
chrome: {
|
|
1876
1951
|
eyebrow: { color: { light: "#e3120b", dark: "#f4463f" }, fontSize: 11, fontWeight: 700 },
|
|
1877
|
-
title: {
|
|
1952
|
+
title: { fontWeight: 700, lineHeight: 1.18 },
|
|
1878
1953
|
subtitle: { fontWeight: 400, lineHeight: 1.45 }
|
|
1879
1954
|
},
|
|
1880
1955
|
/** The masthead device: a short red bar above the eyebrow. */
|
|
@@ -1909,7 +1984,7 @@ var terminal = {
|
|
|
1909
1984
|
},
|
|
1910
1985
|
chrome: {
|
|
1911
1986
|
eyebrow: { color: { light: "#22d3ee", dark: "#22d3ee" }, fontSize: 10, fontWeight: 500 },
|
|
1912
|
-
title: {
|
|
1987
|
+
title: { fontWeight: 600, lineHeight: 1.3 },
|
|
1913
1988
|
subtitle: { fontWeight: 400, lineHeight: 1.4 }
|
|
1914
1989
|
},
|
|
1915
1990
|
borderRadius: 4,
|
|
@@ -1920,13 +1995,9 @@ var clarity = {
|
|
|
1920
1995
|
background: { light: "#ffffff", dark: "#09090b" },
|
|
1921
1996
|
axis: { light: "#52525b", dark: "#a1a1aa" }
|
|
1922
1997
|
},
|
|
1923
|
-
fonts: { sizes: { title: 26, subtitle: 14, body: 13, small: 12, axisTick: 12 } },
|
|
1924
1998
|
chrome: {
|
|
1925
|
-
eyebrow: { color: { light: "#0f766e", dark: "#5eead4" } }
|
|
1926
|
-
|
|
1927
|
-
footer: { fontSize: 12 }
|
|
1928
|
-
},
|
|
1929
|
-
spacing: { chromeToChart: 16, chartToFooter: 12 }
|
|
1999
|
+
eyebrow: { color: { light: "#0f766e", dark: "#5eead4" } }
|
|
2000
|
+
}
|
|
1930
2001
|
};
|
|
1931
2002
|
var legacyEditorial = {
|
|
1932
2003
|
fonts: { sizes: { title: 26, subtitle: 14, body: 13, small: 11, axisTick: 11 } },
|
|
@@ -1934,23 +2005,10 @@ var legacyEditorial = {
|
|
|
1934
2005
|
};
|
|
1935
2006
|
|
|
1936
2007
|
// src/theme/resolve.ts
|
|
1937
|
-
function deepMerge(target, source) {
|
|
1938
|
-
const result = { ...target };
|
|
1939
|
-
for (const key of Object.keys(source)) {
|
|
1940
|
-
const sourceVal = source[key];
|
|
1941
|
-
const targetVal = target[key];
|
|
1942
|
-
if (sourceVal !== void 0 && sourceVal !== null && typeof sourceVal === "object" && !Array.isArray(sourceVal) && typeof targetVal === "object" && targetVal !== null && !Array.isArray(targetVal)) {
|
|
1943
|
-
result[key] = deepMerge(targetVal, sourceVal);
|
|
1944
|
-
} else if (sourceVal !== void 0) {
|
|
1945
|
-
result[key] = sourceVal;
|
|
1946
|
-
}
|
|
1947
|
-
}
|
|
1948
|
-
return result;
|
|
1949
|
-
}
|
|
1950
2008
|
function resolveTokenLight(v) {
|
|
1951
2009
|
return typeof v === "string" ? v : v.light;
|
|
1952
2010
|
}
|
|
1953
|
-
function themeConfigToPartial(config) {
|
|
2011
|
+
function themeConfigToPartial(config, base) {
|
|
1954
2012
|
const partial = {};
|
|
1955
2013
|
if (config.colors) {
|
|
1956
2014
|
const colors = {};
|
|
@@ -1984,6 +2042,16 @@ function themeConfigToPartial(config) {
|
|
|
1984
2042
|
colors.annotationMarkerFill = resolveTokenLight(config.colors.annotationMarkerFill);
|
|
1985
2043
|
if (config.colors.annotationPlate)
|
|
1986
2044
|
colors.annotationPlate = resolveTokenLight(config.colors.annotationPlate);
|
|
2045
|
+
for (const key of [
|
|
2046
|
+
"gridlineZero",
|
|
2047
|
+
"mapNoDataFill",
|
|
2048
|
+
"mapNoDataHatch",
|
|
2049
|
+
"mapInteriorBorder",
|
|
2050
|
+
"mapOutlineBorder"
|
|
2051
|
+
]) {
|
|
2052
|
+
const value = config.colors[key];
|
|
2053
|
+
if (value !== void 0) colors[key] = resolveTokenLight(value);
|
|
2054
|
+
}
|
|
1987
2055
|
if (config.colors.positive) colors.positive = resolveTokenLight(config.colors.positive);
|
|
1988
2056
|
if (config.colors.negative) colors.negative = resolveTokenLight(config.colors.negative);
|
|
1989
2057
|
}
|
|
@@ -2012,6 +2080,9 @@ function themeConfigToPartial(config) {
|
|
|
2012
2080
|
if (config.spacing.xAxisHeight !== void 0) spacing.xAxisHeight = config.spacing.xAxisHeight;
|
|
2013
2081
|
if (config.spacing.xAxisLabelPadding !== void 0)
|
|
2014
2082
|
spacing.xAxisLabelPadding = config.spacing.xAxisLabelPadding;
|
|
2083
|
+
for (const key of ["endpointEntryGap", "endpointValueGap", "endpointColumnGap"]) {
|
|
2084
|
+
if (config.spacing[key] !== void 0) spacing[key] = config.spacing[key];
|
|
2085
|
+
}
|
|
2015
2086
|
partial.spacing = spacing;
|
|
2016
2087
|
}
|
|
2017
2088
|
if (config.borderRadius !== void 0) {
|
|
@@ -2021,9 +2092,9 @@ function themeConfigToPartial(config) {
|
|
|
2021
2092
|
const chrome = {};
|
|
2022
2093
|
for (const [element, value] of Object.entries(config.chrome)) {
|
|
2023
2094
|
if (value === void 0) continue;
|
|
2024
|
-
if (typeof value === "string")
|
|
2025
|
-
chrome
|
|
2026
|
-
|
|
2095
|
+
if (typeof value === "string")
|
|
2096
|
+
throw new Error("theme.chrome string colors were removed in v9; use { color }.");
|
|
2097
|
+
{
|
|
2027
2098
|
const override = {};
|
|
2028
2099
|
const obj = value;
|
|
2029
2100
|
if (obj.color !== void 0) override.color = resolveTokenLight(obj.color);
|
|
@@ -2037,11 +2108,14 @@ function themeConfigToPartial(config) {
|
|
|
2037
2108
|
}
|
|
2038
2109
|
if (config.rule) {
|
|
2039
2110
|
partial.rule = {
|
|
2040
|
-
color: resolveTokenLight(
|
|
2041
|
-
|
|
2042
|
-
|
|
2111
|
+
color: resolveTokenLight(
|
|
2112
|
+
config.rule.color ?? base.rule?.color ?? (config.colors && !Array.isArray(config.colors) ? config.colors.text : void 0) ?? DEFAULT_THEME.colors.text
|
|
2113
|
+
),
|
|
2114
|
+
width: config.rule.width ?? base.rule?.width ?? 40,
|
|
2115
|
+
thickness: config.rule.thickness ?? base.rule?.thickness ?? 3
|
|
2043
2116
|
};
|
|
2044
2117
|
}
|
|
2118
|
+
if (config.rule === null) partial.rule = null;
|
|
2045
2119
|
if (config.seriesStrategy) {
|
|
2046
2120
|
partial.seriesStrategy = config.seriesStrategy;
|
|
2047
2121
|
}
|
|
@@ -2054,6 +2128,7 @@ function collectTokenPairs(config) {
|
|
|
2054
2128
|
"background",
|
|
2055
2129
|
"text",
|
|
2056
2130
|
"gridline",
|
|
2131
|
+
"gridlineZero",
|
|
2057
2132
|
"hairline",
|
|
2058
2133
|
"axis",
|
|
2059
2134
|
"annotationFill",
|
|
@@ -2065,6 +2140,10 @@ function collectTokenPairs(config) {
|
|
|
2065
2140
|
"annotationRangeFill",
|
|
2066
2141
|
"annotationMarkerFill",
|
|
2067
2142
|
"annotationPlate",
|
|
2143
|
+
"mapNoDataFill",
|
|
2144
|
+
"mapNoDataHatch",
|
|
2145
|
+
"mapInteriorBorder",
|
|
2146
|
+
"mapOutlineBorder",
|
|
2068
2147
|
"positive",
|
|
2069
2148
|
"negative"
|
|
2070
2149
|
];
|
|
@@ -2141,31 +2220,28 @@ function adjustOpacity(hex, opacity) {
|
|
|
2141
2220
|
return `#${toHex(mix2(r))}${toHex(mix2(g))}${toHex(mix2(b))}`;
|
|
2142
2221
|
}
|
|
2143
2222
|
function resolveTheme(userTheme, base = DEFAULT_THEME) {
|
|
2144
|
-
let merged = userTheme ?
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
...
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
source: { ...merged.chrome.source, fontSize: s.small },
|
|
2159
|
-
byline: { ...merged.chrome.byline, fontSize: s.small },
|
|
2160
|
-
footer: { ...merged.chrome.footer, fontSize: s.small }
|
|
2223
|
+
let merged = userTheme ? mergeThemeObjects(base, themeConfigToPartial(userTheme, base)) : { ...base };
|
|
2224
|
+
for (const [element, size] of Object.entries({
|
|
2225
|
+
title: "title",
|
|
2226
|
+
subtitle: "subtitle",
|
|
2227
|
+
source: "small",
|
|
2228
|
+
byline: "small",
|
|
2229
|
+
footer: "small"
|
|
2230
|
+
})) {
|
|
2231
|
+
if (userTheme?.chrome?.[element]?.fontSize === void 0) {
|
|
2232
|
+
merged = {
|
|
2233
|
+
...merged,
|
|
2234
|
+
chrome: {
|
|
2235
|
+
...merged.chrome,
|
|
2236
|
+
[element]: { ...merged.chrome[element], fontSize: merged.fonts.sizes[size] }
|
|
2161
2237
|
}
|
|
2162
|
-
}
|
|
2163
|
-
}
|
|
2238
|
+
};
|
|
2239
|
+
}
|
|
2164
2240
|
}
|
|
2165
2241
|
const dark = isDarkBackground(merged.colors.background);
|
|
2166
2242
|
if (dark) {
|
|
2167
|
-
merged = adaptChromeForDarkBg(merged, merged.colors.text);
|
|
2168
|
-
const
|
|
2243
|
+
merged = adaptChromeForDarkBg({ ...merged, colors: { ...merged.colors } }, merged.colors.text);
|
|
2244
|
+
const authoredColors2 = userTheme?.colors && !Array.isArray(userTheme.colors) ? userTheme.colors : {};
|
|
2169
2245
|
for (const key of [
|
|
2170
2246
|
"annotationLabel",
|
|
2171
2247
|
"annotationMuted",
|
|
@@ -2173,20 +2249,28 @@ function resolveTheme(userTheme, base = DEFAULT_THEME) {
|
|
|
2173
2249
|
"annotationRule",
|
|
2174
2250
|
"annotationRangeFill",
|
|
2175
2251
|
"annotationMarkerFill",
|
|
2176
|
-
"annotationPlate"
|
|
2252
|
+
"annotationPlate",
|
|
2253
|
+
"gridlineZero",
|
|
2254
|
+
"mapInteriorBorder",
|
|
2255
|
+
"mapOutlineBorder"
|
|
2177
2256
|
]) {
|
|
2178
|
-
if (
|
|
2257
|
+
if (authoredColors2[key] === void 0)
|
|
2179
2258
|
merged.colors[key] = cssTokenDefault(
|
|
2180
2259
|
`--oc-${key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}`,
|
|
2181
2260
|
"dark"
|
|
2182
2261
|
);
|
|
2183
2262
|
}
|
|
2184
2263
|
}
|
|
2264
|
+
const neutral = deriveNeutralRamp(merged.colors.text, merged.colors.background, dark);
|
|
2265
|
+
const authoredColors = userTheme?.colors && !Array.isArray(userTheme.colors) ? userTheme.colors : {};
|
|
2185
2266
|
return {
|
|
2186
2267
|
...merged,
|
|
2268
|
+
_authored: userTheme,
|
|
2187
2269
|
colors: {
|
|
2188
2270
|
...merged.colors,
|
|
2189
|
-
neutral
|
|
2271
|
+
neutral,
|
|
2272
|
+
annotationMarkerFill: authoredColors.annotationMarkerFill === void 0 ? neutral.surface : merged.colors.annotationMarkerFill,
|
|
2273
|
+
annotationPlate: authoredColors.annotationPlate === void 0 ? neutral.surface : merged.colors.annotationPlate
|
|
2190
2274
|
},
|
|
2191
2275
|
isDark: dark,
|
|
2192
2276
|
_tokenPairs: userTheme ? collectTokenPairs(userTheme) : void 0
|
|
@@ -2270,24 +2354,39 @@ function computeNoteBandHeight(input, theme) {
|
|
|
2270
2354
|
const count = typeof input === "number" ? input : (input.footnotes?.reduce((sum, note) => sum + (note.lines?.length ?? 1), 0) ?? 0) + (input.seriesSummary?.reduce((sum, entry) => sum + entry.lines.length, 0) ?? 0);
|
|
2271
2355
|
return count <= 0 ? 0 : count * theme.fonts.sizes.small * FOOTNOTE_LINE_HEIGHT + FOOTNOTE_BAND_GAP;
|
|
2272
2356
|
}
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2357
|
+
function measuredWatermark(theme, width, pad, y, measureText) {
|
|
2358
|
+
if (width < BRAND_MIN_WIDTH) return void 0;
|
|
2359
|
+
const style = {
|
|
2360
|
+
fontFamily: theme.fonts.family,
|
|
2361
|
+
fontSize: BRAND_FONT_SIZE,
|
|
2362
|
+
fontWeight: 600,
|
|
2363
|
+
fill: theme.colors.axis,
|
|
2364
|
+
textAnchor: "end",
|
|
2365
|
+
lineHeight: 1.3
|
|
2366
|
+
};
|
|
2367
|
+
return {
|
|
2368
|
+
text: "OpenData",
|
|
2369
|
+
x: width - pad,
|
|
2370
|
+
y,
|
|
2371
|
+
maxWidth: measureText?.("OpenData", BRAND_FONT_SIZE, 600).width ?? "OpenData".length * estimateCharWidth(BRAND_FONT_SIZE, 600),
|
|
2372
|
+
style
|
|
2373
|
+
};
|
|
2282
2374
|
}
|
|
2283
2375
|
function computeChrome(chrome, theme, width, measureText, chromeMode = "full", padding, watermark = true, bottomLegendHeight = 0, crampedTitle = false) {
|
|
2284
2376
|
if (!chrome || chromeMode === "hidden") {
|
|
2285
2377
|
if (watermark && width >= BRAND_MIN_WIDTH) {
|
|
2286
2378
|
const hiddenPad = padding ?? theme.spacing.padding;
|
|
2287
|
-
const
|
|
2379
|
+
const brandHeight2 = estimateTextHeight(BRAND_FONT_SIZE, 1);
|
|
2288
2380
|
return {
|
|
2289
2381
|
topHeight: 0,
|
|
2290
|
-
bottomHeight: theme.spacing.chartToFooter +
|
|
2382
|
+
bottomHeight: theme.spacing.chartToFooter + brandHeight2 + hiddenPad + bottomLegendHeight,
|
|
2383
|
+
watermark: measuredWatermark(
|
|
2384
|
+
theme,
|
|
2385
|
+
width,
|
|
2386
|
+
hiddenPad,
|
|
2387
|
+
theme.spacing.chartToFooter + bottomLegendHeight,
|
|
2388
|
+
measureText
|
|
2389
|
+
)
|
|
2291
2390
|
};
|
|
2292
2391
|
}
|
|
2293
2392
|
if (bottomLegendHeight > 0) {
|
|
@@ -2388,125 +2487,128 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
|
|
|
2388
2487
|
if (chromeMode === "compact") {
|
|
2389
2488
|
let compactBottom = 0;
|
|
2390
2489
|
if (watermark && width >= BRAND_MIN_WIDTH) {
|
|
2391
|
-
const
|
|
2392
|
-
compactBottom = theme.spacing.chartToFooter +
|
|
2490
|
+
const brandHeight2 = estimateTextHeight(BRAND_FONT_SIZE, 1);
|
|
2491
|
+
compactBottom = theme.spacing.chartToFooter + brandHeight2 + pad + bottomLegendHeight;
|
|
2393
2492
|
} else if (bottomLegendHeight > 0) {
|
|
2394
2493
|
compactBottom = bottomLegendHeight;
|
|
2395
2494
|
}
|
|
2396
2495
|
return {
|
|
2397
2496
|
topHeight,
|
|
2398
2497
|
bottomHeight: compactBottom,
|
|
2498
|
+
...watermark ? {
|
|
2499
|
+
watermark: measuredWatermark(
|
|
2500
|
+
theme,
|
|
2501
|
+
width,
|
|
2502
|
+
pad,
|
|
2503
|
+
theme.spacing.chartToFooter + bottomLegendHeight,
|
|
2504
|
+
measureText
|
|
2505
|
+
)
|
|
2506
|
+
} : {},
|
|
2399
2507
|
...ruleElement ? { rule: ruleElement } : {},
|
|
2400
2508
|
...topElements
|
|
2401
2509
|
};
|
|
2402
2510
|
}
|
|
2511
|
+
const startY = theme.spacing.chartToFooter + bottomLegendHeight;
|
|
2403
2512
|
const brandNorm = normalizeChromeText(chrome.brand);
|
|
2404
|
-
const
|
|
2405
|
-
const shouldReserveBrandWidth = (showWatermark || !!brandNorm) && width >= BRAND_MIN_WIDTH;
|
|
2406
|
-
const bottomMaxWidth = maxWidth - (shouldReserveBrandWidth ? BRAND_RESERVE_WIDTH : 0);
|
|
2407
|
-
const bottomElements = {};
|
|
2408
|
-
let bottomHeight = 0;
|
|
2409
|
-
const bottomItems = [];
|
|
2410
|
-
const sourceNorm = normalizeChromeText(chrome.source);
|
|
2411
|
-
if (sourceNorm) {
|
|
2412
|
-
bottomItems.push({
|
|
2413
|
-
key: "source",
|
|
2414
|
-
norm: sourceNorm,
|
|
2415
|
-
defaults: theme.chrome.source
|
|
2416
|
-
});
|
|
2417
|
-
}
|
|
2418
|
-
const bylineNorm = normalizeChromeText(chrome.byline);
|
|
2419
|
-
if (bylineNorm) {
|
|
2420
|
-
bottomItems.push({
|
|
2421
|
-
key: "byline",
|
|
2422
|
-
norm: bylineNorm,
|
|
2423
|
-
defaults: theme.chrome.byline
|
|
2424
|
-
});
|
|
2425
|
-
}
|
|
2426
|
-
const footerNorm = normalizeChromeText(chrome.footer);
|
|
2427
|
-
if (footerNorm) {
|
|
2428
|
-
bottomItems.push({
|
|
2429
|
-
key: "footer",
|
|
2430
|
-
norm: footerNorm,
|
|
2431
|
-
defaults: theme.chrome.footer
|
|
2432
|
-
});
|
|
2433
|
-
}
|
|
2434
|
-
if (bottomItems.length > 0) {
|
|
2435
|
-
bottomHeight += theme.spacing.chartToFooter;
|
|
2436
|
-
bottomHeight += bottomLegendHeight;
|
|
2437
|
-
for (const item of bottomItems) {
|
|
2438
|
-
const style = buildTextStyle(
|
|
2439
|
-
item.defaults,
|
|
2440
|
-
fontFamily,
|
|
2441
|
-
item.defaults.color,
|
|
2442
|
-
width,
|
|
2443
|
-
item.norm.style
|
|
2444
|
-
);
|
|
2445
|
-
const maxLines = item.norm.style?.maxLines;
|
|
2446
|
-
const lineCount = estimateLineCount(
|
|
2447
|
-
item.norm.text,
|
|
2448
|
-
style,
|
|
2449
|
-
bottomMaxWidth,
|
|
2450
|
-
measureText,
|
|
2451
|
-
maxLines
|
|
2452
|
-
);
|
|
2453
|
-
const height = estimateTextHeight(style.fontSize, lineCount, style.lineHeight);
|
|
2454
|
-
bottomElements[item.key] = {
|
|
2455
|
-
text: item.norm.text,
|
|
2456
|
-
x: pad + (item.norm.offset?.dx ?? 0),
|
|
2457
|
-
y: bottomHeight + (item.norm.offset?.dy ?? 0),
|
|
2458
|
-
// offset from where bottom chrome starts
|
|
2459
|
-
maxWidth: bottomMaxWidth,
|
|
2460
|
-
...maxLines != null ? { maxLines } : {},
|
|
2461
|
-
style
|
|
2462
|
-
};
|
|
2463
|
-
bottomHeight += height + chromeGap;
|
|
2464
|
-
}
|
|
2465
|
-
bottomHeight -= chromeGap;
|
|
2466
|
-
if (showWatermark && width >= BRAND_MIN_WIDTH) {
|
|
2467
|
-
const brandHeight = estimateTextHeight(BRAND_FONT_SIZE, 1);
|
|
2468
|
-
const contentBelowFirstItem = bottomHeight - theme.spacing.chartToFooter;
|
|
2469
|
-
if (brandHeight > contentBelowFirstItem) {
|
|
2470
|
-
bottomHeight += brandHeight - contentBelowFirstItem;
|
|
2471
|
-
}
|
|
2472
|
-
}
|
|
2473
|
-
bottomHeight += pad;
|
|
2474
|
-
} else if (showWatermark && width >= BRAND_MIN_WIDTH) {
|
|
2475
|
-
const brandHeight = estimateTextHeight(BRAND_FONT_SIZE, 1);
|
|
2476
|
-
bottomHeight = theme.spacing.chartToFooter + brandHeight + pad + bottomLegendHeight;
|
|
2477
|
-
} else if (bottomLegendHeight > 0) {
|
|
2478
|
-
bottomHeight = bottomLegendHeight;
|
|
2479
|
-
}
|
|
2513
|
+
const watermarkElement = watermark && !brandNorm ? measuredWatermark(theme, width, pad, startY, measureText) : void 0;
|
|
2480
2514
|
let brandElement;
|
|
2481
2515
|
if (brandNorm && width >= BRAND_MIN_WIDTH) {
|
|
2482
|
-
const
|
|
2516
|
+
const style = buildTextStyle(
|
|
2483
2517
|
theme.chrome.footer,
|
|
2484
2518
|
fontFamily,
|
|
2485
2519
|
theme.chrome.footer.color,
|
|
2486
2520
|
width,
|
|
2487
2521
|
brandNorm.style
|
|
2488
2522
|
);
|
|
2489
|
-
|
|
2490
|
-
const
|
|
2523
|
+
style.textAnchor = "end";
|
|
2524
|
+
const naturalWidth = Math.max(
|
|
2525
|
+
...brandNorm.text.split("\n").map(
|
|
2526
|
+
(line) => measureText?.(line, style.fontSize, style.fontWeight).width ?? line.length * estimateCharWidth(style.fontSize, style.fontWeight)
|
|
2527
|
+
)
|
|
2528
|
+
);
|
|
2491
2529
|
brandElement = {
|
|
2492
2530
|
text: brandNorm.text,
|
|
2493
2531
|
x: width - pad + (brandNorm.offset?.dx ?? 0),
|
|
2494
|
-
y:
|
|
2495
|
-
maxWidth:
|
|
2496
|
-
style:
|
|
2532
|
+
y: startY + (brandNorm.offset?.dy ?? 0),
|
|
2533
|
+
maxWidth: Math.max(1, Math.min(maxWidth, naturalWidth)),
|
|
2534
|
+
...brandNorm.style?.maxLines != null ? { maxLines: brandNorm.style.maxLines } : {},
|
|
2535
|
+
style
|
|
2497
2536
|
};
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2537
|
+
}
|
|
2538
|
+
const brand = brandElement ?? watermarkElement;
|
|
2539
|
+
const brandHeight = brand ? estimateTextHeight(
|
|
2540
|
+
brand.style.fontSize,
|
|
2541
|
+
estimateLineCount(brand.text, brand.style, brand.maxWidth, measureText, brand.maxLines),
|
|
2542
|
+
brand.style.lineHeight
|
|
2543
|
+
) : 0;
|
|
2544
|
+
const items = ["source", "byline", "footer"].flatMap((key) => {
|
|
2545
|
+
const norm = normalizeChromeText(chrome[key]);
|
|
2546
|
+
return norm ? [
|
|
2547
|
+
{
|
|
2548
|
+
key,
|
|
2549
|
+
norm,
|
|
2550
|
+
style: buildTextStyle(
|
|
2551
|
+
theme.chrome[key],
|
|
2552
|
+
fontFamily,
|
|
2553
|
+
theme.chrome[key].color,
|
|
2554
|
+
width,
|
|
2555
|
+
norm.style
|
|
2556
|
+
)
|
|
2557
|
+
}
|
|
2558
|
+
] : [];
|
|
2559
|
+
});
|
|
2560
|
+
const gap = Math.max(12, chromeGap);
|
|
2561
|
+
const inlineWidth = brand ? Math.max(0, brand.x - brand.maxWidth - gap - pad) : maxWidth;
|
|
2562
|
+
function resolveItems(availableWidth) {
|
|
2563
|
+
const elements = {};
|
|
2564
|
+
let y = startY;
|
|
2565
|
+
let extent = startY;
|
|
2566
|
+
for (const { key, norm, style } of items) {
|
|
2567
|
+
const available = Math.max(1, availableWidth - Math.max(0, norm.offset?.dx ?? 0));
|
|
2568
|
+
const count = estimateLineCount(
|
|
2569
|
+
norm.text,
|
|
2570
|
+
style,
|
|
2571
|
+
available,
|
|
2572
|
+
measureText,
|
|
2573
|
+
norm.style?.maxLines
|
|
2574
|
+
);
|
|
2575
|
+
const height = estimateTextHeight(style.fontSize, count, style.lineHeight);
|
|
2576
|
+
const itemY = y + (norm.offset?.dy ?? 0);
|
|
2577
|
+
elements[key] = {
|
|
2578
|
+
text: norm.text,
|
|
2579
|
+
x: pad + (norm.offset?.dx ?? 0),
|
|
2580
|
+
y: itemY,
|
|
2581
|
+
maxWidth: available,
|
|
2582
|
+
...norm.style?.maxLines != null ? { maxLines: norm.style.maxLines } : {},
|
|
2583
|
+
style
|
|
2584
|
+
};
|
|
2585
|
+
extent = Math.max(extent, itemY + height);
|
|
2586
|
+
y += height + chromeGap;
|
|
2501
2587
|
}
|
|
2588
|
+
return {
|
|
2589
|
+
elements,
|
|
2590
|
+
extent,
|
|
2591
|
+
height: items.length ? Math.max(y - chromeGap, extent) - startY : 0
|
|
2592
|
+
};
|
|
2502
2593
|
}
|
|
2594
|
+
const full = resolveItems(maxWidth);
|
|
2595
|
+
const inline = resolveItems(inlineWidth);
|
|
2596
|
+
const inlineHeight = Math.max(inline.height, (brand?.y ?? startY) - startY + brandHeight);
|
|
2597
|
+
const stackedHeight = full.height + (items.length ? chromeGap : 0) + brandHeight + Math.max(0, brandNorm?.offset?.dy ?? 0);
|
|
2598
|
+
const stacked = !!brand && items.length > 0 && (inlineWidth < 40 || stackedHeight < inlineHeight);
|
|
2599
|
+
const bottomElements = stacked ? full.elements : inline.elements;
|
|
2600
|
+
if (stacked && brand) brand.y += full.height + chromeGap;
|
|
2601
|
+
const contentHeight = stacked ? stackedHeight : inlineHeight;
|
|
2602
|
+
const bottomHeight = items.length || brand ? startY + contentHeight + pad : bottomLegendHeight;
|
|
2503
2603
|
return {
|
|
2504
2604
|
topHeight,
|
|
2505
2605
|
bottomHeight,
|
|
2506
2606
|
...ruleElement ? { rule: ruleElement } : {},
|
|
2507
2607
|
...topElements,
|
|
2508
2608
|
...bottomElements,
|
|
2509
|
-
...brandElement ? { brand: brandElement } : {}
|
|
2609
|
+
...brandElement ? { brand: brandElement } : {},
|
|
2610
|
+
...watermarkElement ? { watermark: watermarkElement } : {},
|
|
2611
|
+
...items.length || brand ? { attributionLayout: stacked ? "stacked" : "inline" } : {}
|
|
2510
2612
|
};
|
|
2511
2613
|
}
|
|
2512
2614
|
|
|
@@ -2701,6 +2803,12 @@ var FORMAT_PERCENT_RAW = d3Format(",.1~f");
|
|
|
2701
2803
|
var FORMAT_CURRENCY_INTEGER = d3Format("$,");
|
|
2702
2804
|
var FORMAT_CURRENCY_DECIMAL = d3Format("$,.2f");
|
|
2703
2805
|
var FORMAT_STEP_FRACTION = [d3Format(".0~f"), d3Format(".1~f"), d3Format(".2~f")];
|
|
2806
|
+
var FORMAT_STEP_PRECISION = [
|
|
2807
|
+
d3Format(",.0~f"),
|
|
2808
|
+
d3Format(",.1~f"),
|
|
2809
|
+
d3Format(",.2~f"),
|
|
2810
|
+
d3Format(",.3~f")
|
|
2811
|
+
];
|
|
2704
2812
|
function formatNumber(value, _locale) {
|
|
2705
2813
|
if (!Number.isFinite(value)) return String(value);
|
|
2706
2814
|
if (Number.isInteger(value)) {
|
|
@@ -2878,6 +2986,13 @@ function defaultNumberFormatter(ctx) {
|
|
|
2878
2986
|
if (ctx?.step != null && (ctx.stepReference ?? maxAbs(ctx.extent)) >= 1e3) {
|
|
2879
2987
|
return buildCompactStepFormatter(ctx.step);
|
|
2880
2988
|
}
|
|
2989
|
+
if (ctx?.step != null && ctx.step > 0) {
|
|
2990
|
+
const p = fractionDigits(ctx.step);
|
|
2991
|
+
if (p <= 3) {
|
|
2992
|
+
const fmt = FORMAT_STEP_PRECISION[p];
|
|
2993
|
+
return (v) => Number.isFinite(v) ? fmt(v) : String(v);
|
|
2994
|
+
}
|
|
2995
|
+
}
|
|
2881
2996
|
return (v) => {
|
|
2882
2997
|
if (!Number.isFinite(v)) return String(v);
|
|
2883
2998
|
if (ctx?.extent === void 0 && ctx?.allIntegers === void 0) {
|
|
@@ -2988,7 +3103,7 @@ function generateAltText(spec, data) {
|
|
|
2988
3103
|
const markType = resolveMarkType(spec.mark);
|
|
2989
3104
|
const markDef = resolveMarkDef(spec.mark);
|
|
2990
3105
|
let chartName = MARK_DISPLAY_NAMES[markType] ?? `${markType} chart`;
|
|
2991
|
-
if (
|
|
3106
|
+
if (markDef.type === "arc" && markDef.innerRadius && markDef.innerRadius > 0) {
|
|
2992
3107
|
chartName = "Donut chart";
|
|
2993
3108
|
}
|
|
2994
3109
|
const isBinnedBar = markType === "bar" && !!spec.encoding.x2 && spec.encoding.x?.type === "quantitative" && spec.encoding.y?.type === "quantitative";
|
|
@@ -3001,7 +3116,7 @@ function generateAltText(spec, data) {
|
|
|
3001
3116
|
const titleText = typeof title === "string" ? title : title.text;
|
|
3002
3117
|
parts.push(`showing ${titleText}`);
|
|
3003
3118
|
}
|
|
3004
|
-
if (
|
|
3119
|
+
if (markDef.type === "waffle") {
|
|
3005
3120
|
const units = markDef.units ?? 100;
|
|
3006
3121
|
parts.push(`dividing ${units} units`);
|
|
3007
3122
|
}
|
|
@@ -3131,44 +3246,43 @@ function formatValue(value) {
|
|
|
3131
3246
|
}
|
|
3132
3247
|
|
|
3133
3248
|
// src/helpers/spec-builders.ts
|
|
3134
|
-
var
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
}
|
|
3140
|
-
function warnDarkMode(options) {
|
|
3141
|
-
if (options?.darkMode !== void 0)
|
|
3142
|
-
warnBuilderOption(
|
|
3143
|
-
"darkMode",
|
|
3144
|
-
"Builder darkMode is deprecated and has no effect; use the mount option."
|
|
3145
|
-
);
|
|
3146
|
-
}
|
|
3147
|
-
var ISO_DATE_RE = /^\d{4}(-\d{2}(-\d{2}(T\d{2}(:\d{2}(:\d{2})?)?)?)?)?$/;
|
|
3249
|
+
var DATE_STRING_RES = [
|
|
3250
|
+
/^\d{4}-\d{2}(-\d{2}([T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?)?$/,
|
|
3251
|
+
/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\.?( \d{1,2},?)? \d{4}$/i,
|
|
3252
|
+
/^(\d{1,2}\/\d{1,2}\/\d{4}|\d{4}\/\d{1,2}\/\d{1,2})$/
|
|
3253
|
+
];
|
|
3148
3254
|
function inferFieldType(data, field) {
|
|
3149
|
-
const sampleSize = Math.min(data.length
|
|
3150
|
-
let
|
|
3151
|
-
let
|
|
3152
|
-
let
|
|
3255
|
+
const sampleSize = Math.min(50, data.length);
|
|
3256
|
+
let numericCount = 0;
|
|
3257
|
+
let dateCount = 0;
|
|
3258
|
+
let totalNonNull = 0;
|
|
3153
3259
|
for (let i = 0; i < sampleSize; i++) {
|
|
3154
3260
|
const value = data[i][field];
|
|
3155
3261
|
if (value == null) continue;
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3262
|
+
totalNonNull++;
|
|
3263
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
3264
|
+
numericCount++;
|
|
3265
|
+
continue;
|
|
3266
|
+
}
|
|
3267
|
+
if (typeof value === "string") {
|
|
3268
|
+
const num = Number(value);
|
|
3269
|
+
if (!Number.isNaN(num) && Number.isFinite(num) && value.trim() !== "") {
|
|
3270
|
+
numericCount++;
|
|
3271
|
+
continue;
|
|
3163
3272
|
}
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3273
|
+
const date = new Date(value);
|
|
3274
|
+
if (DATE_STRING_RES.some((re) => re.test(value)) && !Number.isNaN(date.getTime())) {
|
|
3275
|
+
dateCount++;
|
|
3276
|
+
continue;
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
3279
|
+
if (value instanceof Date && !Number.isNaN(value.getTime())) {
|
|
3280
|
+
dateCount++;
|
|
3168
3281
|
}
|
|
3169
3282
|
}
|
|
3170
|
-
if (
|
|
3171
|
-
if (
|
|
3283
|
+
if (totalNonNull === 0) return "nominal";
|
|
3284
|
+
if (dateCount / totalNonNull > 0.8) return "temporal";
|
|
3285
|
+
if (numericCount / totalNonNull > 0.8) return "quantitative";
|
|
3172
3286
|
return "nominal";
|
|
3173
3287
|
}
|
|
3174
3288
|
function resolveField(ref, data) {
|
|
@@ -3188,7 +3302,6 @@ function buildEncoding(channels, options, data) {
|
|
|
3188
3302
|
return encoding;
|
|
3189
3303
|
}
|
|
3190
3304
|
function buildChartSpec(mark, data, encoding, options) {
|
|
3191
|
-
warnDarkMode(options);
|
|
3192
3305
|
const spec = { mark, data, encoding };
|
|
3193
3306
|
if (options?.chrome) spec.chrome = options.chrome;
|
|
3194
3307
|
if (options?.annotations) spec.annotations = options.annotations;
|
|
@@ -3257,9 +3370,6 @@ function scatterChart(data, x, y, options) {
|
|
|
3257
3370
|
return buildChartSpec("point", data, encoding, options);
|
|
3258
3371
|
}
|
|
3259
3372
|
function dataTable(data, options) {
|
|
3260
|
-
warnDarkMode(options);
|
|
3261
|
-
if (options?.compact !== void 0)
|
|
3262
|
-
warnBuilderOption("compact", "dataTable compact is deprecated; use density.");
|
|
3263
3373
|
let columns = options?.columns;
|
|
3264
3374
|
if (!columns && data.length > 0) {
|
|
3265
3375
|
columns = Object.keys(data[0]).map((key) => {
|
|
@@ -3284,12 +3394,10 @@ function dataTable(data, options) {
|
|
|
3284
3394
|
if (options?.pagination !== void 0) spec.pagination = options.pagination;
|
|
3285
3395
|
if (options?.stickyFirstColumn !== void 0) spec.stickyFirstColumn = options.stickyFirstColumn;
|
|
3286
3396
|
if (options?.density !== void 0) spec.density = options.density;
|
|
3287
|
-
else if (options?.compact !== void 0) spec.density = options.compact ? "condensed" : "regular";
|
|
3288
3397
|
if (options?.responsive !== void 0) spec.responsive = options.responsive;
|
|
3289
3398
|
return spec;
|
|
3290
3399
|
}
|
|
3291
3400
|
function tileMap(data, options) {
|
|
3292
|
-
warnDarkMode(options);
|
|
3293
3401
|
return {
|
|
3294
3402
|
type: "tilemap",
|
|
3295
3403
|
data,
|
|
@@ -3450,7 +3558,6 @@ export {
|
|
|
3450
3558
|
HPAD_COMPACT_MIN,
|
|
3451
3559
|
LABEL_GAP_COMPACT,
|
|
3452
3560
|
LABEL_GAP_DEFAULT,
|
|
3453
|
-
LABEL_GAP_NARROW_MAX,
|
|
3454
3561
|
MARK_DISPLAY_NAMES,
|
|
3455
3562
|
MARK_ENCODING_RULES,
|
|
3456
3563
|
MARK_TYPES,
|
|
@@ -3468,7 +3575,6 @@ export {
|
|
|
3468
3575
|
TICK_LABEL_OFFSET,
|
|
3469
3576
|
TICK_LINE_HEIGHT_FACTOR,
|
|
3470
3577
|
TOP_PAD_EXTRA_NARROW,
|
|
3471
|
-
TOP_PAD_NARROW_MAX,
|
|
3472
3578
|
X_AXIS_BAND_HEIGHT,
|
|
3473
3579
|
X_AXIS_ROTATED_EXTENT_CAP,
|
|
3474
3580
|
X_AXIS_TITLE_BAND,
|
|
@@ -3503,12 +3609,11 @@ export {
|
|
|
3503
3609
|
detectCollision,
|
|
3504
3610
|
donutChart,
|
|
3505
3611
|
dotChart,
|
|
3506
|
-
editorial,
|
|
3507
3612
|
elementRef,
|
|
3613
|
+
encodePointerToken,
|
|
3508
3614
|
essay,
|
|
3509
3615
|
estimateTextWidth,
|
|
3510
3616
|
findAccessibleColor,
|
|
3511
|
-
footnoteBandHeight,
|
|
3512
3617
|
formatCurrency,
|
|
3513
3618
|
formatDate,
|
|
3514
3619
|
formatNumber,
|
|
@@ -3542,6 +3647,7 @@ export {
|
|
|
3542
3647
|
isTileMapSpec,
|
|
3543
3648
|
isValueDef,
|
|
3544
3649
|
isYearContext,
|
|
3650
|
+
jsonPointer,
|
|
3545
3651
|
legacyEditorial,
|
|
3546
3652
|
lineChart,
|
|
3547
3653
|
maxRotatedLabelWidth,
|