@acronis-platform/ui-react 4.1.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ui/area-chart/area-chart.js +191 -85
- package/dist/components/ui/area-chart/area-chart.js.map +1 -1
- package/dist/components/ui/bar-chart/bar-chart.js +288 -225
- package/dist/components/ui/bar-chart/bar-chart.js.map +1 -1
- package/dist/components/ui/card-widget-carousel/card-widget-carousel.js +85 -0
- package/dist/components/ui/card-widget-carousel/card-widget-carousel.js.map +1 -0
- package/dist/components/ui/card-widget-carousel/card-widget.js +82 -0
- package/dist/components/ui/card-widget-carousel/card-widget.js.map +1 -0
- package/dist/components/ui/category-bar/category-bar.js.map +1 -1
- package/dist/components/ui/chart/chart-format.js +25 -22
- package/dist/components/ui/chart/chart-format.js.map +1 -1
- package/dist/components/ui/chart/chart-palette.js +9 -8
- package/dist/components/ui/chart/chart-palette.js.map +1 -1
- package/dist/components/ui/chart/chart.js +127 -89
- package/dist/components/ui/chart/chart.js.map +1 -1
- package/dist/components/ui/funnel-chart/funnel-chart.js +189 -113
- package/dist/components/ui/funnel-chart/funnel-chart.js.map +1 -1
- package/dist/components/ui/input-select/input-select.js +18 -9
- package/dist/components/ui/input-select/input-select.js.map +1 -1
- package/dist/components/ui/line-chart/line-chart.js +194 -86
- package/dist/components/ui/line-chart/line-chart.js.map +1 -1
- package/dist/components/ui/radar-chart/radar-chart.js +76 -66
- package/dist/components/ui/radar-chart/radar-chart.js.map +1 -1
- package/dist/components/ui/scatter-chart/scatter-chart.js +5 -2
- package/dist/components/ui/scatter-chart/scatter-chart.js.map +1 -1
- package/dist/components/ui/separator/separator.js +52 -10
- package/dist/components/ui/separator/separator.js.map +1 -1
- package/dist/components/ui/sidebar-secondary/sidebar-secondary.js +144 -121
- package/dist/components/ui/sidebar-secondary/sidebar-secondary.js.map +1 -1
- package/dist/components/ui/tree-item/tree-item.js +67 -0
- package/dist/components/ui/tree-item/tree-item.js.map +1 -0
- package/dist/components/ui/treemap/treemap.js +73 -66
- package/dist/components/ui/treemap/treemap.js.map +1 -1
- package/dist/index.js +109 -107
- package/dist/llms/area-chart.md +2 -1
- package/dist/llms/bar-chart.md +132 -33
- package/dist/llms/card-widget-carousel.md +252 -0
- package/dist/llms/category-bar.md +2 -2
- package/dist/llms/funnel-chart.md +269 -101
- package/dist/llms/input-select.md +175 -1
- package/dist/llms/line-chart.md +2 -1
- package/dist/llms/metric.md +10 -5
- package/dist/llms/radar-chart.md +15 -5
- package/dist/llms/scatter-chart.md +2 -1
- package/dist/llms/separator.md +27 -8
- package/dist/llms/sidebar-secondary.md +235 -4
- package/dist/llms/tree-item.md +359 -0
- package/dist/llms/treemap.md +47 -36
- package/dist/llms.txt +5 -4
- package/dist/react.js +109 -107
- package/dist/src/components/ui/area-chart/area-chart.d.ts +10 -0
- package/dist/src/components/ui/bar-chart/bar-chart.d.ts +75 -10
- package/dist/src/components/ui/bar-chart/bar-chart.docs.d.ts +146 -0
- package/dist/src/components/ui/bar-chart/index.d.ts +1 -1
- package/dist/src/components/ui/card-widget-carousel/card-widget-carousel.d.ts +9 -0
- package/dist/src/components/ui/card-widget-carousel/card-widget.d.ts +43 -0
- package/dist/src/components/ui/card-widget-carousel/index.d.ts +2 -0
- package/dist/src/components/ui/chart/chart-format.d.ts +9 -1
- package/dist/src/components/ui/chart/chart-palette.d.ts +38 -10
- package/dist/src/components/ui/chart/chart.d.ts +8 -1
- package/dist/src/components/ui/chart/index.d.ts +2 -2
- package/dist/src/components/ui/funnel-chart/funnel-chart.d.ts +92 -26
- package/dist/src/components/ui/funnel-chart/index.d.ts +1 -1
- package/dist/src/components/ui/input-select/input-select.d.ts +34 -2
- package/dist/src/components/ui/line-chart/line-chart.d.ts +11 -1
- package/dist/src/components/ui/radar-chart/radar-chart.d.ts +42 -9
- package/dist/src/components/ui/separator/separator.d.ts +9 -1
- package/dist/src/components/ui/sidebar-secondary/sidebar-secondary.d.ts +23 -3
- package/dist/src/components/ui/tree-item/index.d.ts +1 -0
- package/dist/src/components/ui/tree-item/tree-item.d.ts +64 -0
- package/dist/src/components/ui/treemap/treemap.d.ts +16 -5
- package/dist/src/index.d.ts +2 -1
- package/dist/ui-react.css +1 -1
- package/package.json +1 -1
- package/dist/components/ui/meter/meter.js +0 -79
- package/dist/components/ui/meter/meter.js.map +0 -1
- package/dist/llms/meter.md +0 -177
- package/dist/src/components/ui/meter/index.d.ts +0 -1
- package/dist/src/components/ui/meter/meter.d.ts +0 -25
|
@@ -46,12 +46,15 @@ function o(e) {
|
|
|
46
46
|
...i === void 0 ? {} : { animationEasing: i }
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
function s(e) {
|
|
50
|
+
return e?.filter((e) => !(typeof e.dataKey == "string" && e.dataKey.startsWith("_proj_")));
|
|
51
|
+
}
|
|
52
|
+
var c = "fill-[var(--ui-text-on-surface-primary)]!", l = "fill-[var(--ui-text-on-status-strong-neutral)]!", u = 12, d = {
|
|
50
53
|
top: 16,
|
|
51
54
|
right: 24,
|
|
52
55
|
bottom: 5,
|
|
53
56
|
left: 12
|
|
54
|
-
},
|
|
57
|
+
}, f = /* @__PURE__ */ new Set([
|
|
55
58
|
"center",
|
|
56
59
|
"centerTop",
|
|
57
60
|
"centerBottom",
|
|
@@ -63,42 +66,42 @@ var s = "fill-[var(--ui-text-on-surface-primary)]!", c = "fill-[var(--ui-text-on
|
|
|
63
66
|
"insideEnd",
|
|
64
67
|
"end"
|
|
65
68
|
]);
|
|
66
|
-
function
|
|
69
|
+
function p(e) {
|
|
67
70
|
let { labelPosition: t, isStacked: n = !1, growingEnd: r = "top" } = e;
|
|
68
71
|
return t === void 0 ? n ? "center" : r : t;
|
|
69
72
|
}
|
|
70
|
-
function
|
|
71
|
-
return t.translucentSeries ?
|
|
73
|
+
function m(e, t = {}) {
|
|
74
|
+
return t.translucentSeries ? c : f.has(e) ? l : c;
|
|
72
75
|
}
|
|
73
|
-
function
|
|
76
|
+
function h(e) {
|
|
74
77
|
if (e) return (t) => t == null ? "" : e(t);
|
|
75
78
|
}
|
|
76
|
-
function
|
|
79
|
+
function g(e) {
|
|
77
80
|
return e ? Array.isArray(e) ? e : [e] : [];
|
|
78
81
|
}
|
|
79
|
-
function
|
|
82
|
+
function _(e, t, n) {
|
|
80
83
|
if (!e) return;
|
|
81
84
|
if (typeof e.value == "number") return e.value;
|
|
82
85
|
if (!e.average) return;
|
|
83
86
|
let r = typeof e.average == "string" ? [e.average] : n, i = t.flatMap((e) => r.map((t) => e[t]).filter((e) => typeof e == "number"));
|
|
84
87
|
if (i.length !== 0) return i.reduce((e, t) => e + t, 0) / i.length;
|
|
85
88
|
}
|
|
86
|
-
var
|
|
87
|
-
function
|
|
89
|
+
var v = "var(--ui-text-on-surface-secondary)";
|
|
90
|
+
function y(e, t = "insideTopRight") {
|
|
88
91
|
return {
|
|
89
|
-
stroke:
|
|
92
|
+
stroke: v,
|
|
90
93
|
strokeDasharray: "4 4",
|
|
91
94
|
ifOverflow: "extendDomain",
|
|
92
95
|
label: e ? {
|
|
93
96
|
value: e,
|
|
94
97
|
position: t,
|
|
95
|
-
fill:
|
|
98
|
+
fill: v,
|
|
96
99
|
fontSize: 12
|
|
97
100
|
} : void 0
|
|
98
101
|
};
|
|
99
102
|
}
|
|
100
|
-
var
|
|
101
|
-
function
|
|
103
|
+
var b = 28, x = "Chart range selector";
|
|
104
|
+
function S({ brushHeight: e, brushAriaLabel: t = x }) {
|
|
102
105
|
return {
|
|
103
106
|
height: e != null && e > 0 ? e : 28,
|
|
104
107
|
fill: "var(--ui-background-surface-secondary)",
|
|
@@ -107,28 +110,28 @@ function x({ brushHeight: e, brushAriaLabel: t = b }) {
|
|
|
107
110
|
ariaLabel: t
|
|
108
111
|
};
|
|
109
112
|
}
|
|
110
|
-
var
|
|
113
|
+
var C = (e) => {
|
|
111
114
|
if (typeof e == "string" && e.trim() === "") return null;
|
|
112
115
|
let t = typeof e == "number" ? e : Number(e);
|
|
113
116
|
return Number.isFinite(t) ? t : null;
|
|
114
|
-
},
|
|
115
|
-
let t =
|
|
117
|
+
}, w = (e) => {
|
|
118
|
+
let t = C(e);
|
|
116
119
|
return t === null ? String(e) : new Intl.NumberFormat("en", {
|
|
117
120
|
notation: "compact",
|
|
118
121
|
maximumFractionDigits: 1
|
|
119
122
|
}).format(t);
|
|
120
|
-
},
|
|
121
|
-
let t =
|
|
123
|
+
}, T = (e) => {
|
|
124
|
+
let t = C(e);
|
|
122
125
|
return t === null ? String(e) : `${t}%`;
|
|
123
126
|
};
|
|
124
|
-
function
|
|
127
|
+
function E(e, t = "en") {
|
|
125
128
|
let n = new Intl.NumberFormat(t, e);
|
|
126
129
|
return (e) => {
|
|
127
|
-
let t =
|
|
130
|
+
let t = C(e);
|
|
128
131
|
return t === null ? String(e) : n.format(t);
|
|
129
132
|
};
|
|
130
133
|
}
|
|
131
134
|
//#endregion
|
|
132
|
-
export {
|
|
135
|
+
export { x as CHART_BRUSH_ARIA_LABEL, b as CHART_BRUSH_HEIGHT, c as CHART_LABEL_FILL_CLASS, l as CHART_LABEL_FILL_ON_SERIES_CLASS, u as CHART_LABEL_FONT_SIZE, d as CHART_LABEL_MARGIN, v as CHART_REFERENCE_LINE_STROKE, E as createTickFormatter, s as dropProjectionPayload, w as formatCompactNumber, T as formatPercent, o as resolveAnimation, e as resolveAxisDomain, S as resolveBrushProps, p as resolveCartesianLabelPosition, a as resolveCategoryRange, _ as resolveChartReferenceValue, m as resolveLabelFillClass, y as resolveReferenceLineProps, t as resolveRotatedTickAnchor, n as resolveXAxisHeight, r as resolveXAxisTitle, i as resolveYAxisTitle, h as toLabelFormatter, g as toReferenceLineList };
|
|
133
136
|
|
|
134
137
|
//# sourceMappingURL=chart-format.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-format.js","names":[],"sources":["../../../../src/components/ui/chart/chart-format.ts"],"sourcesContent":["// Shared axis helpers for the cartesian chart components (BarChart, LineChart,\n// AreaChart, ComposedChart, ScatterChart, ConfidenceCone, Histogram). Three\n// concerns live here so every chart formats + toggles axes the same way rather\n// than each reimplementing it:\n//\n// 1. `CartesianChartProps` — the common axis knobs each cartesian chart mixes\n// into its own props (show/hide either axis, per-axis tick formatting).\n// 2. A small set of tick formatters (+ a factory) callers pass to\n// `xTickFormatter` / `yTickFormatter`.\n// 3. `resolveAxisDomain` — maps the `yAxisDomain` preset to a recharts\n// `domain`, shared so all 7 charts can't drift apart on it.\n//\n// These format only the axis *tick labels*; series colors and tokens are\n// unaffected. Formatters coerce to a number and pass non-numeric values through\n// untouched (a category axis stays readable if a formatter is applied to it).\n\nimport type { AxisDomainItem } from 'recharts';\n\nimport type { ChartTooltipContentType } from './chart';\n\n/** A recharts-compatible tick formatter: `(value, index) => label`. */\nexport type TickFormatter = (value: number | string, index?: number) => string;\n\n/**\n * Props shared by every cartesian chart (Bar, Line, Area, Composed, Scatter,\n * ConfidenceCone, Histogram) — chrome toggles, axis titles/units, tick\n * formatting/visibility, and grid trim. All optional. `showLegend` and `xUnit`\n * are deliberately *not* here: `showLegend` doesn't apply to `Histogram` and\n * `xUnit` only to charts with a numeric X axis, so they stay per-component.\n */\nexport interface CartesianChartProps {\n /** Render the CartesianGrid. Defaults to `true`. */\n showGrid?: boolean;\n /** Render the hover tooltip. Defaults to `true`. */\n showTooltip?: boolean;\n /**\n * Replace the default tooltip. Pass a configured `ChartTooltipContent` (from\n * this library) — e.g. with a `formatter` / `labelFormatter` — to customize it\n * without composing recharts yourself. Ignored when `showTooltip` is false.\n */\n tooltipContent?: ChartTooltipContentType;\n /** Title rendered beneath the X axis. */\n xAxisLabel?: string;\n /** Title rendered beside the Y axis (rotated). */\n yAxisLabel?: string;\n /**\n * Unit suffix appended to the Y axis's tick values (recharts `unit`) — applies\n * when the Y axis is the numeric one. `BarChart` with\n * `orientation=\"horizontal\"` puts the values on X instead; use `xUnit` there.\n */\n yUnit?: string;\n /** Show the X axis (its ticks + title). Defaults to `true`. */\n showXAxis?: boolean;\n /** Show the Y axis (its ticks + title). Defaults to `true`. */\n showYAxis?: boolean;\n /** Format each X-axis tick value — e.g. `formatCompactNumber` or a `createTickFormatter(...)`. */\n xTickFormatter?: TickFormatter;\n /** Format each Y-axis tick value — e.g. `formatCompactNumber` or a `createTickFormatter(...)`. */\n yTickFormatter?: TickFormatter;\n /**\n * Rotate the X-axis tick labels by this many degrees. A negative angle (e.g.\n * `-45`) tilts them up toward the right; the tick anchor + axis height adjust\n * to keep long labels readable.\n */\n xAxisAngle?: number;\n /**\n * X-axis tick density — a recharts placement strategy, or a fixed number of\n * ticks to *skip* between two rendered ones (recharts `interval`: `0` shows\n * every tick, `1` every other one, `2` every third, …).\n */\n xAxisInterval?:\n | number\n | 'preserveStart'\n | 'preserveEnd'\n | 'preserveStartEnd'\n | 'equidistantPreserveStart';\n /**\n * Desired number of ticks on the value axis (recharts `tickCount`; a hint, not\n * exact). Applies to whichever axis holds the values — Y for most charts, X for\n * `BarChart` with `orientation=\"horizontal\"`.\n */\n yAxisTickCount?: number;\n /**\n * Value-axis domain preset. Applies to whichever axis holds the values — Y for\n * most charts, X for `BarChart` with `orientation=\"horizontal\"`.\n *\n * - `auto` — fit the data at both ends; the axis need not include 0.\n * - `zero` — anchor the axis at 0. This is also recharts' behavior when the\n * prop is omitted, so it's the explicit form of the default.\n * - `dataMin-dataMax` — tight to the data, with no padding.\n */\n yAxisDomain?: 'auto' | 'dataMin-dataMax' | 'zero';\n /** Draw grid lines dashed instead of solid. */\n gridDashed?: boolean;\n /** Show horizontal grid lines. Defaults to each chart's own default when unset. */\n gridHorizontal?: boolean;\n /** Show vertical grid lines. Defaults to each chart's own default when unset. */\n gridVertical?: boolean;\n}\n\n/**\n * Map a `yAxisDomain` preset to a recharts `domain`. Shared by all 7 cartesian\n * charts, and applied to whichever axis holds the values (X for horizontal bars).\n *\n * `undefined` (no preset) is left to recharts, whose default is `[0, 'auto']` —\n * i.e. already zero-anchored. That's why `auto` has to be spelled out as\n * `['auto', 'auto']`: passing `undefined` for it would silently anchor at 0 and\n * make the preset indistinguishable from `zero`.\n */\nexport function resolveAxisDomain(\n preset: 'auto' | 'dataMin-dataMax' | 'zero' | undefined\n): Readonly<[AxisDomainItem, AxisDomainItem]> | undefined {\n switch (preset) {\n case 'auto':\n return ['auto', 'auto'];\n case 'zero':\n return [0, 'auto'];\n case 'dataMin-dataMax':\n return ['dataMin', 'dataMax'];\n default:\n return undefined;\n }\n}\n\n/**\n * `text-anchor` for a rotated X tick row, so the tick's text ends (or begins) at\n * the tick it labels instead of straddling it. Shared by all 7 cartesian charts.\n *\n * A tick rotated anti-clockwise trails off to the lower left, so it must be\n * anchored at its end; a clockwise one trails to the lower right and is anchored\n * at its start. Only an *omitted* angle keeps recharts' own default (`middle`):\n * the branch is on `angle < 0`, so `angle={0}` anchors at `start` like any\n * clockwise rotation. A caller that normalises \"upright\" to `0` instead of\n * leaving `xAxisAngle` off therefore gets the rotated-tick treatment — here and\n * in `resolveXAxisHeight`.\n */\nexport function resolveRotatedTickAnchor(\n angle: number | undefined\n): 'start' | 'end' | undefined {\n if (angle == null) return undefined;\n return angle < 0 ? 'end' : 'start';\n}\n\n/**\n * Height to reserve for the X tick row, or `undefined` to keep recharts' own\n * default. Shared by all 7 cartesian charts.\n *\n * recharts' default 30 covers one upright tick row and nothing else, so a\n * rotated row (+20) and an axis title (+18) each need their own allowance. The\n * two are additive rather than exclusive — a chart can rotate its ticks *and*\n * title the axis, which a label-or-angle ternary under-allocates.\n *\n * The +20 keys off the angle being *present*, not non-zero, so `angle={0}`\n * reserves the rotated row's height as well — the same edge case\n * `resolveRotatedTickAnchor` has, kept consistent between the two.\n */\nexport function resolveXAxisHeight(\n label: string | undefined,\n angle: number | undefined\n): number | undefined {\n if (!label && angle == null) return undefined;\n return 30 + (angle != null ? 20 : 0) + (label ? 18 : 0);\n}\n\n/**\n * recharts `label` for an X axis title, placed below the tick row. Shared by all\n * 7 cartesian charts; `insideTop` is for a secondary scale on the top edge.\n */\nexport function resolveXAxisTitle(\n label: string | undefined,\n position: 'insideBottom' | 'insideTop' = 'insideBottom',\n offset = 0\n) {\n if (!label) return undefined;\n return { value: label, position, offset };\n}\n\n/**\n * recharts `label` for a rotated value-axis title, angled so it reads from the\n * outside in — upward on a left axis (the convention), downward on a right one,\n * where -90° would put the text's baseline against the plot. Shared by all 7\n * cartesian charts; only `ComposedChart` currently uses the right-hand side.\n */\nexport function resolveYAxisTitle(\n label: string | undefined,\n orientation: 'left' | 'right' = 'left'\n) {\n if (!label) return undefined;\n return {\n value: label,\n angle: orientation === 'left' ? -90 : 90,\n position:\n orientation === 'left' ? ('insideLeft' as const) : ('insideRight' as const),\n style: { textAnchor: 'middle' as const },\n };\n}\n\n/**\n * A category range on a cartesian chart: `from`/`to` accept either the\n * category's value (an `xKey` cell, e.g. `'Sep'`) or its 0-based row index. Both\n * ends are inclusive, and either can be omitted to run to that end of the data.\n * Shared by the charts that scope something to a slice of the categories — a\n * reference band, a per-series style override.\n */\nexport interface ChartCategoryRange {\n from?: string | number;\n to?: string | number;\n}\n\n/**\n * Resolve a category range to inclusive row indices. A bound is either the\n * category's own value (matched against the `xKey` cell) or a 0-based index;\n * an omitted bound runs to that end of the data. Returns `undefined` when the\n * data is empty or the range resolves to nothing (an unknown value, or a `to`\n * that lands before its `from`).\n *\n * Exported for unit tests; not part of the package's public API.\n */\nexport function resolveCategoryRange(\n range: ChartCategoryRange,\n data: ReadonlyArray<Record<string, unknown>>,\n xKey: string\n): [number, number] | undefined {\n if (data.length === 0) return undefined;\n\n const resolve = (bound: string | number | undefined, fallback: number) => {\n if (bound === undefined) return fallback;\n // A numeric bound is an index unless the categories are numbers themselves,\n // in which case matching a category value is the more useful reading.\n const asValue = data.findIndex((row) => row[xKey] === bound);\n if (asValue !== -1) return asValue;\n if (typeof bound === 'number' && Number.isInteger(bound)) {\n return bound >= 0 && bound < data.length ? bound : -1;\n }\n return -1;\n };\n\n const start = resolve(range.from, 0);\n const end = resolve(range.to, data.length - 1);\n if (start === -1 || end === -1 || start > end) return undefined;\n return [start, end];\n}\n\n/**\n * Which value axis a series is measured against, on a chart that can carry two.\n *\n * `secondary` is the opt-in: the second axis exists only when at least one series\n * asks for it, so a chart whose series all leave this unset keeps the single\n * shared scale — and its recharts output — exactly as before.\n */\nexport type ChartYAxisTarget = 'primary' | 'secondary';\n\n/**\n * Second value-axis props, for a chart whose series can be measured on two\n * independent scales. **Only `ComposedChart` implements these today.** It is the\n * one chart in the suite where two scales are unambiguous: its series already\n * differ in mark type, so a bar read against the left axis and a line against the\n * right can't be mistaken for two marks sharing one. On a single-mark chart (Bar,\n * Area) two scales invite comparing heights that aren't comparable, which is why\n * these props are not mixed into `CartesianChartProps`.\n *\n * The primary axis is configured through `CartesianChartProps` (`yAxisLabel`,\n * `yUnit`, `yTickFormatter`, `yAxisTickCount`, `yAxisDomain`, `showYAxis`); every\n * `secondary*` prop here is its counterpart on the second axis, so the two scales\n * format and bound themselves independently, and each is inert until a series\n * selects that axis.\n *\n * `yAxisOrientation` is the exception on both counts: it places the *primary*\n * axis, and it applies whether or not a second one exists. It lives here because\n * it is only meaningful once a chart can mirror a pair of axes — a single-axis\n * chart has no second side to give up.\n */\nexport interface SecondaryYAxisProps {\n /**\n * Which side the *primary* value axis sits on. Defaults to `left`. The secondary\n * axis always takes the opposite side. Unlike the `secondary*` props below, this\n * one applies to a single-scale chart too.\n *\n * Inert on a chart whose marks grow horizontally: the value axis is X there, so\n * the primary sits along the bottom edge and the secondary along the top, and\n * neither has a left/right side to pick.\n */\n yAxisOrientation?: 'left' | 'right';\n /**\n * Show the secondary axis's ticks + title. Defaults to `true`. Setting it false\n * keeps the second *scale* (series still measure against it) and only drops its\n * chrome — the same meaning `showYAxis` has for the primary axis.\n */\n showSecondaryYAxis?: boolean;\n /** Title rendered beside the secondary axis (rotated). */\n secondaryYAxisLabel?: string;\n /** Unit suffix appended to the secondary axis's tick values (recharts `unit`). */\n secondaryYUnit?: string;\n /** Format each secondary-axis tick value — the counterpart of `yTickFormatter`. */\n secondaryYTickFormatter?: TickFormatter;\n /** Desired number of ticks on the secondary axis (recharts `tickCount`; a hint, not exact). */\n secondaryYAxisTickCount?: number;\n /** Domain preset for the secondary axis — same presets as `yAxisDomain`. */\n secondaryYAxisDomain?: 'auto' | 'dataMin-dataMax' | 'zero';\n}\n\n/**\n * How a series interpolates between its points (recharts `type`), shared by the\n * Line and Area families so both offer the same set:\n *\n * - `linear` — straight segments between points.\n * - `monotone` — smoothed, without overshooting a point's value.\n * - `natural` — a natural cubic spline; smoother than `monotone`, but it may\n * overshoot, so read it as a trend rather than exact values.\n * - `basis` — a B-spline that is *not* required to pass through the points at\n * all; the smoothest option, and the least literal.\n * - `step` — right-angle segments, changing value at the midpoint between two\n * points; `stepBefore` changes at the leading point and `stepAfter` at the\n * trailing one.\n */\nexport type ChartCurveType =\n | 'linear'\n | 'monotone'\n | 'natural'\n | 'basis'\n | 'step'\n | 'stepBefore'\n | 'stepAfter';\n\n/** recharts animation easing curves. */\nexport type ChartAnimationEasing =\n | 'ease'\n | 'ease-in'\n | 'ease-out'\n | 'ease-in-out'\n | 'linear';\n\n/**\n * Entrance-animation props shared by *every* chart type (not just the cartesian\n * ones) — charts hardcode `isAnimationActive={false}` otherwise. All optional and\n * off by default, so an unset chart renders byte-identically to before (and its\n * VR baselines stay stable). Spread `resolveAnimation(props)` onto each series.\n */\nexport interface ChartAnimationProps {\n /** Enable entrance animation. Defaults to `false` (keeps output/baselines stable). */\n animate?: boolean;\n /** Animation duration in ms (recharts `animationDuration`). */\n animationDuration?: number;\n /** Delay before the animation starts, in ms (recharts `animationBegin`). */\n animationBegin?: number;\n /** Easing curve (recharts `animationEasing`). */\n animationEasing?: ChartAnimationEasing;\n}\n\n/** The resolved recharts animation props to spread onto a series/shape. */\nexport interface ResolvedAnimation {\n isAnimationActive: boolean | 'auto';\n animationDuration?: number;\n animationBegin?: number;\n animationEasing?: ChartAnimationEasing;\n}\n\n/**\n * Turn the shared `ChartAnimationProps` into the recharts series props. The\n * timing props only appear when given, so an unset chart spreads exactly\n * `{ isAnimationActive: false }` — the previous hardcoded value.\n *\n * `animate` maps to recharts' `'auto'`, not to a literal `true`: `'auto'` is the\n * only value that honors `prefers-reduced-motion` (and disables the animation in\n * SSR). recharts resolves it as\n * `isActive = isActiveProp === 'auto' ? !isSsr && !prefersReducedMotion : isActiveProp`,\n * so a literal `true` would force motion on users who asked for none — this\n * library has no other reduced-motion escape hatch.\n */\nexport function resolveAnimation(props: ChartAnimationProps): ResolvedAnimation {\n const { animate = false, animationDuration, animationBegin, animationEasing } =\n props;\n return {\n isAnimationActive: animate ? 'auto' : false,\n ...(animationDuration !== undefined ? { animationDuration } : {}),\n ...(animationBegin !== undefined ? { animationBegin } : {}),\n ...(animationEasing !== undefined ? { animationEasing } : {}),\n };\n}\n\n/** Where a data label sits on a cartesian series (recharts `LabelList` position). */\nexport type CartesianLabelPosition =\n | 'top'\n | 'bottom'\n | 'left'\n | 'right'\n | 'center'\n | 'insideTop'\n | 'insideBottom'\n | 'insideLeft'\n | 'insideRight'\n | 'insideStart'\n | 'insideEnd';\n\n/**\n * Where a data label sits on a *polar* series (Pie, RadialBar). Deliberately not\n * `CartesianLabelPosition`: recharts routes a polar label list through\n * `getAttrsOfPolarLabel` / `renderRadialLabel`, which understand only these\n * seven values — every cartesian-only position (`top`, `insideLeft`, …) silently\n * collapses to the same mid-radius placement, so offering them would advertise\n * distinctions that don't exist.\n */\nexport type PolarLabelPosition =\n | 'outside'\n | 'center'\n | 'centerTop'\n | 'centerBottom'\n | 'insideStart'\n | 'insideEnd'\n | 'end';\n\n/** Any position accepted by the suite's data labels. */\nexport type ChartLabelPosition = CartesianLabelPosition | PolarLabelPosition;\n\n/**\n * Data-label props shared by the charts that can annotate each point/segment with\n * its value. `labelPosition` stays per-chart (the valid position set differs by\n * family), but `showLabels` + `labelFormatter` are common. Label formatting reuses\n * the same `TickFormatter` type as the axes, so a label and its axis read the same.\n */\nexport interface ChartDataLabelProps {\n /** Render a value label on each data point/segment. Defaults to `false`. */\n showLabels?: boolean;\n /** Format each label value — pass the same formatter used on the value axis. */\n labelFormatter?: TickFormatter;\n}\n\n/**\n * Fill for a label that sits on the chart *surface* — i.e. an outside position\n * (`top`, `right`, polar `outside`). Inverts with the theme, so it only works\n * against the surface background.\n */\nexport const CHART_LABEL_FILL_CLASS = 'fill-[var(--ui-text-on-surface-primary)]!';\n\n/**\n * Fill for a label that sits on an *opaque series fill* — any `inside*`\n * position, a polar mid-radius/centroid placement, or a stacked bar/arc segment\n * (an area's fill is translucent, so it uses the on-surface token). The on-surface\n * token must not be used there: it resolves near-white in dark mode and drops to\n * ~1.6:1 against the saturated status/brand fills the charts colour series with,\n * failing the `accessibility/contrast` grammar rule (`must`, WCAG 1.4.3). This is\n * the same \"text on a strong colored surface\" token `Treemap` already uses; it is\n * white in both themes, so it holds up over every series colour.\n */\nexport const CHART_LABEL_FILL_ON_SERIES_CLASS =\n 'fill-[var(--ui-text-on-status-strong-neutral)]!';\n\nexport const CHART_LABEL_FONT_SIZE = 12;\n\n/**\n * Plot-area inset to apply when a Line/Area series carries outside data labels.\n * recharts hands those label lists `parentViewBox: undefined` (its own source\n * calls this out as a bug in `cartesian/Line.js`), so `getCartesianPosition`'s\n * `clamp` has nothing to clamp against and the first/last point's value is cut\n * off at the SVG edge. Widening the margin is the only lever a composition over\n * recharts has. `Bar` does pass a `parentViewBox`, so bar series don't need it.\n */\nexport const CHART_LABEL_MARGIN = {\n top: 16,\n right: 24,\n bottom: 5,\n left: 12,\n} as const;\n\n/** Positions that draw the label on top of the series fill rather than the surface. */\nconst ON_SERIES_LABEL_POSITIONS = new Set<ChartLabelPosition>([\n 'center',\n 'centerTop',\n 'centerBottom',\n 'insideTop',\n 'insideBottom',\n 'insideLeft',\n 'insideRight',\n 'insideStart',\n 'insideEnd',\n 'end',\n]);\n\n/**\n * Resolve where a cartesian value label sits, given the caller's override, the\n * layout, and the position of the series' growing end (`top` for a vertical bar\n * or a line/area point, `right` for a horizontal bar).\n *\n * The stacked branch is the reason this isn't inlined: a stacked segment has no\n * free space at its growing end — the next segment is drawn there — so a `top`\n * label lands *inside* its neighbour rather than over its own segment. Centring\n * it in its own segment is the readable placement; `resolveLabelFillClass` then\n * pairs it with the fill that has contrast over that family's series colour.\n */\nexport function resolveCartesianLabelPosition(options: {\n labelPosition?: CartesianLabelPosition;\n isStacked?: boolean;\n growingEnd?: CartesianLabelPosition;\n}): CartesianLabelPosition {\n const { labelPosition, isStacked = false, growingEnd = 'top' } = options;\n if (labelPosition !== undefined) return labelPosition;\n return isStacked ? 'center' : growingEnd;\n}\n\n/**\n * Pick the label fill that actually has contrast at `position`. Callers must pass\n * the *resolved* position (after their own default), never `undefined` for a\n * polar chart — recharts' polar fallback is a mid-radius placement, which is on\n * the fill even though no `inside*` value was given.\n *\n * Returns a `className`, not a `fill` attribute, and the utility is `!`-flagged:\n * the cartesian charts scope `[&_.recharts-label]:fill-foreground` on their\n * container to theme axis titles, and a `LabelList`'s text carries\n * `.recharts-label` too — so a CSS rule would quietly beat an SVG presentation\n * attribute and undo the contrast fix.\n *\n * `translucentSeries` opts a family out of the on-fill token: an area's fill is\n * a gradient (0.8 → 0.1 alpha) or a flat `fillOpacity`, so what sits behind the\n * label is the surface tinted by the series colour, not the series colour. The\n * white on-fill token disappears into it in light mode — the theme-inverting\n * on-surface token is the readable one there, and stays white in dark mode.\n */\nexport function resolveLabelFillClass(\n position: ChartLabelPosition,\n options: { translucentSeries?: boolean } = {}\n): string {\n if (options.translucentSeries) return CHART_LABEL_FILL_CLASS;\n return ON_SERIES_LABEL_POSITIONS.has(position)\n ? CHART_LABEL_FILL_ON_SERIES_CLASS\n : CHART_LABEL_FILL_CLASS;\n}\n\n/**\n * Adapt a `TickFormatter` to recharts' `LabelList` `formatter` prop, whose value\n * type is wider. Returns `undefined` when no formatter is given, so a label\n * renders its raw value. Lets labels reuse the same formatters as the value axis.\n *\n * Null/undefined is filtered out rather than forwarded: recharts builds a label\n * entry for *every* point including the null ones that `connectNulls` is meant to\n * bridge, and the tick formatters coerce (`formatCompactNumber(null)` is `\"0\"`,\n * `formatPercent(undefined)` is `\"undefined\"`) — which would paint a phantom\n * value over an intentional gap.\n */\nexport function toLabelFormatter(\n formatter: TickFormatter | undefined\n): ((value: unknown) => string) | undefined {\n if (!formatter) return undefined;\n return (value: unknown) =>\n value == null ? '' : formatter(value as number | string);\n}\n\n/** Where a reference line's caption sits relative to the rule. */\nexport type ChartReferenceLabelPosition =\n | 'top'\n | 'insideTopLeft'\n | 'insideTopRight'\n | 'insideBottomLeft'\n | 'insideBottomRight';\n\n/**\n * A dashed rule across the value axis — a target, a threshold, or a series\n * average. Shared by the cartesian charts that draw one (`BarChart`,\n * `LineChart`, `AreaChart`) so the config reads the same on all three.\n */\nexport interface ChartReferenceLine {\n /** Fixed position on the value axis. Takes precedence over `average`. */\n value?: number;\n /**\n * Draw the line at the mean of one series (a `dataKeys` entry) or, when\n * `true`, of every plotted series' values.\n */\n average?: boolean | string;\n /** Optional caption rendered alongside the line. */\n label?: string;\n /**\n * Where the caption sits. Defaults to the chart's own placement — move it\n * when the rule lands where the series already is and the two collide.\n */\n labelPosition?: ChartReferenceLabelPosition;\n}\n\n/**\n * Normalize the `referenceLine` prop — a single config or an array — to a list.\n * Every chart accepts both forms, so this keeps the render path uniform.\n */\nexport function toReferenceLineList(\n referenceLine: ChartReferenceLine | ChartReferenceLine[] | undefined\n): ChartReferenceLine[] {\n if (!referenceLine) return [];\n return Array.isArray(referenceLine) ? referenceLine : [referenceLine];\n}\n\n/**\n * Resolve a `referenceLine` config to a position on the value axis: a fixed\n * `value` wins; otherwise the mean of the requested series (a single `dataKeys`\n * entry, or all of them when `average` is `true`). Returns `undefined` when\n * there is nothing to draw (no config, or no numeric values to average) — the\n * caller skips the line rather than drawing it at 0.\n *\n * Rows are `unknown`-valued because `ComposedChart` types its data that way; the\n * body only ever reads cells that are numbers, so a wider row type costs nothing\n * and saves every caller a cast.\n */\nexport function resolveChartReferenceValue(\n referenceLine: ChartReferenceLine | undefined,\n data: ReadonlyArray<Record<string, unknown>>,\n dataKeys: string[]\n): number | undefined {\n if (!referenceLine) return undefined;\n if (typeof referenceLine.value === 'number') return referenceLine.value;\n if (!referenceLine.average) return undefined;\n\n const keys =\n typeof referenceLine.average === 'string'\n ? [referenceLine.average]\n : dataKeys;\n const nums = data.flatMap((row) =>\n keys\n .map((key) => row[key])\n .filter((value): value is number => typeof value === 'number')\n );\n if (nums.length === 0) return undefined;\n return nums.reduce((sum, n) => sum + n, 0) / nums.length;\n}\n\n/**\n * Stroke (and caption fill) of a reference rule. The muted text token, so the\n * rule reads as annotation rather than as another series — and stays legible in\n * both themes without competing with the series colors.\n */\nexport const CHART_REFERENCE_LINE_STROKE =\n 'var(--ui-text-on-surface-secondary)';\n\n/**\n * The recharts props that paint a reference rule: a dashed line in the muted\n * text token with an optional caption. Shared so the three charts that draw one\n * can't drift on the stroke, dash pattern, or caption styling.\n *\n * `labelPosition` is the chart's default placement; a config's own\n * `labelPosition` overrides it at the call site.\n *\n * `ifOverflow: 'extendDomain'` is part of the contract, not a detail: a target\n * above the data maximum is exactly the case a reference line is for, and\n * recharts' default (`discard`) would silently drop it.\n */\nexport function resolveReferenceLineProps(\n label: string | undefined,\n labelPosition: ChartReferenceLabelPosition = 'insideTopRight'\n) {\n return {\n stroke: CHART_REFERENCE_LINE_STROKE,\n strokeDasharray: '4 4',\n ifOverflow: 'extendDomain' as const,\n label: label\n ? {\n value: label,\n position: labelPosition,\n fill: CHART_REFERENCE_LINE_STROKE,\n fontSize: CHART_LABEL_FONT_SIZE,\n }\n : undefined,\n };\n}\n\n/**\n * Range-brush props for the cartesian charts that support one — `BarChart`,\n * `LineChart`, `AreaChart`, `ComposedChart`. Deliberately not folded into\n * `CartesianChartProps`: `ScatterChart` plots a continuous X (the brush indexes\n * rows, not values) and `Histogram` / `ConfidenceCone` render a derived series,\n * so a brush over their row order would slice the wrong thing.\n */\nexport interface ChartBrushProps {\n /**\n * Render a range brush beneath the chart — drag its handles (or the selected\n * window) to zoom the series to a slice of the data. Defaults to `false`.\n */\n showBrush?: boolean;\n /** Height of the brush strip in px. Defaults to 28. */\n brushHeight?: number;\n /**\n * Accessible name for the brush's two range handles. Both are focusable\n * `role=\"slider\"` elements, so they need one. Defaults to\n * `'Chart range selector'`.\n */\n brushAriaLabel?: string;\n}\n\n/**\n * Height of the brush strip. recharts' own default is 40, which eats an eighth\n * of a 320px-tall dashboard widget; 28 still fits the travellers and the\n * range captions.\n */\nexport const CHART_BRUSH_HEIGHT = 28;\n\n/**\n * Accessible name for the brush handles. recharts' own fallback is\n * `\"Min value: \".concat(start, \", Max value: \").concat(end)`, where both halves\n * come from a `name` property on the data row — a field none of our charts\n * require, so it announces \"Min value: undefined, Max value: undefined\". Always\n * pass `ariaLabel` to suppress it.\n */\nexport const CHART_BRUSH_ARIA_LABEL = 'Chart range selector';\n\n/** The resolved recharts brush props to spread onto a `<Brush>`. */\nexport interface ResolvedBrush {\n height: number;\n fill: string;\n stroke: string;\n travellerWidth: number;\n ariaLabel: string;\n}\n\n/**\n * Theme + size a recharts `<Brush>` from the shared `ChartBrushProps`.\n *\n * recharts derives the *whole* brush from two color props, so both have to be\n * chosen for every element they reach (`cartesian/Brush.js`):\n * - `fill` paints only the strip's background rect.\n * - `stroke` paints its border, the traveller handles' **fill**, the selected\n * window at 20% opacity, and the range caption text.\n *\n * Hence the mid-grey text token rather than the border one: the travellers are\n * solid `stroke`-colored rects with two hardcoded `#fff` grip lines drawn on\n * top, so a pale stroke would render the grips invisible in light mode. That\n * token is theme-stable (same grey in light and dark), and white grips read\n * against it either way.\n */\nexport function resolveBrushProps({\n brushHeight,\n brushAriaLabel = CHART_BRUSH_ARIA_LABEL,\n}: Omit<ChartBrushProps, 'showBrush'>): ResolvedBrush {\n return {\n // recharts drops the brush entirely when height <= 0, which would turn\n // `showBrush` into a silent no-op — treat a non-positive height as unset.\n height:\n brushHeight != null && brushHeight > 0 ? brushHeight : CHART_BRUSH_HEIGHT,\n fill: 'var(--ui-background-surface-secondary)',\n stroke: 'var(--ui-text-on-surface-secondary)',\n travellerWidth: 8,\n ariaLabel: brushAriaLabel,\n };\n}\n\nconst toNumber = (value: number | string): number | null => {\n // `Number('')` and `Number(' ')` are 0, not NaN — so blank strings have to be\n // rejected before the finite check, or an empty tick label would render \"0\".\n if (typeof value === 'string' && value.trim() === '') return null;\n const n = typeof value === 'number' ? value : Number(value);\n return Number.isFinite(n) ? n : null;\n};\n\n/**\n * Compact thousands/millions: `1234 → \"1.2K\"`, `1_500_000 → \"1.5M\"`. Non-numeric\n * values (including blank strings) pass through unchanged. Use for large-count\n * axes (revenue, users, …).\n *\n * Formats in `en`. For another locale use\n * `createTickFormatter({ notation: 'compact', maximumFractionDigits: 1 }, locale)`.\n */\nexport const formatCompactNumber: TickFormatter = (value) => {\n const n = toNumber(value);\n if (n === null) return String(value);\n return new Intl.NumberFormat('en', {\n notation: 'compact',\n maximumFractionDigits: 1,\n }).format(n);\n};\n\n/**\n * Append a percent sign to an already-scaled value: `41.8 → \"41.8%\"`. (The value\n * is treated as a percentage, not a 0–1 fraction.) Non-numeric values (including\n * blank strings) pass through.\n *\n * Appends a bare `%`, which is not how every locale writes it. For locale-correct\n * output on values that really are fractions, use\n * `createTickFormatter({ style: 'percent' }, locale)`.\n */\nexport const formatPercent: TickFormatter = (value) => {\n const n = toNumber(value);\n if (n === null) return String(value);\n return `${n}%`;\n};\n\n/**\n * Build a tick formatter from `Intl.NumberFormat` options — the escape hatch for\n * currency, fixed decimals, or a specific locale. E.g.\n * `createTickFormatter({ style: 'currency', currency: 'USD', notation: 'compact' })`\n * → `146500 → \"$147K\"`. Non-numeric values pass through unchanged.\n */\nexport function createTickFormatter(\n options: Intl.NumberFormatOptions,\n locale = 'en'\n): TickFormatter {\n const nf = new Intl.NumberFormat(locale, options);\n return (value) => {\n const n = toNumber(value);\n return n === null ? String(value) : nf.format(n);\n };\n}\n"],"mappings":";AA6G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AI,EAAK;AACpD;AAOA,IAAa,IACX;AAcF,SAAgB,EACd,GACA,IAA6C,kBAC7C;CACA,OAAO;EACL,QAAQ;EACR,iBAAiB;EACjB,YAAY;EACZ,OAAO,IACH;GACE,OAAO;GACP,UAAU;GACV,MAAM;GACN,UAAA;EACF,IACA,KAAA;CACN;AACF;AA8BA,IAAa,IAAqB,IASrB,IAAyB;AA0BtC,SAAgB,EAAkB,EAChC,gBACA,oBAAiB,KACmC;CACpD,OAAO;EAGL,QACE,KAAe,QAAQ,IAAc,IAAI,IAAA;EAC3C,MAAM;EACN,QAAQ;EACR,gBAAgB;EAChB,WAAW;CACb;AACF;AAEA,IAAM,KAAY,MAA0C;CAG1D,IAAI,OAAO,KAAU,YAAY,EAAM,KAAK,MAAM,IAAI,OAAO;CAC7D,IAAM,IAAI,OAAO,KAAU,WAAW,IAAQ,OAAO,CAAK;CAC1D,OAAO,OAAO,SAAS,CAAC,IAAI,IAAI;AAClC,GAUa,KAAsC,MAAU;CAC3D,IAAM,IAAI,EAAS,CAAK;CAExB,OADI,MAAM,OAAa,OAAO,CAAK,IAC5B,IAAI,KAAK,aAAa,MAAM;EACjC,UAAU;EACV,uBAAuB;CACzB,CAAC,CAAC,CAAC,OAAO,CAAC;AACb,GAWa,KAAgC,MAAU;CACrD,IAAM,IAAI,EAAS,CAAK;CAExB,OADI,MAAM,OAAa,OAAO,CAAK,IAC5B,GAAG,EAAE;AACd;AAQA,SAAgB,EACd,GACA,IAAS,MACM;CACf,IAAM,IAAK,IAAI,KAAK,aAAa,GAAQ,CAAO;CAChD,QAAQ,MAAU;EAChB,IAAM,IAAI,EAAS,CAAK;EACxB,OAAO,MAAM,OAAO,OAAO,CAAK,IAAI,EAAG,OAAO,CAAC;CACjD;AACF"}
|
|
1
|
+
{"version":3,"file":"chart-format.js","names":[],"sources":["../../../../src/components/ui/chart/chart-format.ts"],"sourcesContent":["// Shared axis helpers for the cartesian chart components (BarChart, LineChart,\n// AreaChart, ComposedChart, ScatterChart, ConfidenceCone, Histogram). Three\n// concerns live here so every chart formats + toggles axes the same way rather\n// than each reimplementing it:\n//\n// 1. `CartesianChartProps` — the common axis knobs each cartesian chart mixes\n// into its own props (show/hide either axis, per-axis tick formatting).\n// 2. A small set of tick formatters (+ a factory) callers pass to\n// `xTickFormatter` / `yTickFormatter`.\n// 3. `resolveAxisDomain` — maps the `yAxisDomain` preset to a recharts\n// `domain`, shared so all 7 charts can't drift apart on it.\n//\n// These format only the axis *tick labels*; series colors and tokens are\n// unaffected. Formatters coerce to a number and pass non-numeric values through\n// untouched (a category axis stays readable if a formatter is applied to it).\n\nimport type { AxisDomainItem } from 'recharts';\n\nimport type { ChartTooltipContentType } from './chart';\n\n/** A recharts-compatible tick formatter: `(value, index) => label`. */\nexport type TickFormatter = (value: number | string, index?: number) => string;\n\n/**\n * Props shared by every cartesian chart (Bar, Line, Area, Composed, Scatter,\n * ConfidenceCone, Histogram) — chrome toggles, axis titles/units, tick\n * formatting/visibility, and grid trim. All optional. `showLegend` and `xUnit`\n * are deliberately *not* here: `showLegend` doesn't apply to `Histogram` and\n * `xUnit` only to charts with a numeric X axis, so they stay per-component.\n */\nexport interface CartesianChartProps {\n /** Render the CartesianGrid. Defaults to `true`. */\n showGrid?: boolean;\n /** Render the hover tooltip. Defaults to `true`. */\n showTooltip?: boolean;\n /**\n * Replace the default tooltip. Pass a configured `ChartTooltipContent` (from\n * this library) — e.g. with a `formatter` / `labelFormatter` — to customize it\n * without composing recharts yourself. Ignored when `showTooltip` is false.\n */\n tooltipContent?: ChartTooltipContentType;\n /** Title rendered beneath the X axis. */\n xAxisLabel?: string;\n /** Title rendered beside the Y axis (rotated). */\n yAxisLabel?: string;\n /**\n * Unit suffix appended to the Y axis's tick values (recharts `unit`) — applies\n * when the Y axis is the numeric one. `ComposedChart` with\n * `orientation=\"horizontal\"` puts the values on X instead; use `xUnit` there.\n */\n yUnit?: string;\n /** Show the X axis (its ticks + title). Defaults to `true`. */\n showXAxis?: boolean;\n /** Show the Y axis (its ticks + title). Defaults to `true`. */\n showYAxis?: boolean;\n /** Format each X-axis tick value — e.g. `formatCompactNumber` or a `createTickFormatter(...)`. */\n xTickFormatter?: TickFormatter;\n /** Format each Y-axis tick value — e.g. `formatCompactNumber` or a `createTickFormatter(...)`. */\n yTickFormatter?: TickFormatter;\n /**\n * Rotate the X-axis tick labels by this many degrees. A negative angle (e.g.\n * `-45`) tilts them up toward the right; the tick anchor + axis height adjust\n * to keep long labels readable.\n */\n xAxisAngle?: number;\n /**\n * X-axis tick density — a recharts placement strategy, or a fixed number of\n * ticks to *skip* between two rendered ones (recharts `interval`: `0` shows\n * every tick, `1` every other one, `2` every third, …).\n */\n xAxisInterval?:\n | number\n | 'preserveStart'\n | 'preserveEnd'\n | 'preserveStartEnd'\n | 'equidistantPreserveStart';\n /**\n * Desired number of ticks on the value axis (recharts `tickCount`; a hint, not\n * exact). Applies to whichever axis holds the values — Y for most charts, X for\n * `BarChart` with `orientation=\"horizontal\"`.\n */\n yAxisTickCount?: number;\n /**\n * Value-axis domain preset. Applies to whichever axis holds the values — Y for\n * most charts, X for `BarChart` with `orientation=\"horizontal\"`.\n *\n * - `auto` — fit the data at both ends; the axis need not include 0.\n * - `zero` — anchor the axis at 0. This is also recharts' behavior when the\n * prop is omitted, so it's the explicit form of the default.\n * - `dataMin-dataMax` — tight to the data, with no padding.\n */\n yAxisDomain?: 'auto' | 'dataMin-dataMax' | 'zero';\n /** Draw grid lines dashed instead of solid. */\n gridDashed?: boolean;\n /** Show horizontal grid lines. Defaults to each chart's own default when unset. */\n gridHorizontal?: boolean;\n /** Show vertical grid lines. Defaults to each chart's own default when unset. */\n gridVertical?: boolean;\n}\n\n/**\n * Map a `yAxisDomain` preset to a recharts `domain`. Shared by all 7 cartesian\n * charts, and applied to whichever axis holds the values (X for horizontal bars).\n *\n * `undefined` (no preset) is left to recharts, whose default is `[0, 'auto']` —\n * i.e. already zero-anchored. That's why `auto` has to be spelled out as\n * `['auto', 'auto']`: passing `undefined` for it would silently anchor at 0 and\n * make the preset indistinguishable from `zero`.\n */\nexport function resolveAxisDomain(\n preset: 'auto' | 'dataMin-dataMax' | 'zero' | undefined\n): Readonly<[AxisDomainItem, AxisDomainItem]> | undefined {\n switch (preset) {\n case 'auto':\n return ['auto', 'auto'];\n case 'zero':\n return [0, 'auto'];\n case 'dataMin-dataMax':\n return ['dataMin', 'dataMax'];\n default:\n return undefined;\n }\n}\n\n/**\n * `text-anchor` for a rotated X tick row, so the tick's text ends (or begins) at\n * the tick it labels instead of straddling it. Shared by all 7 cartesian charts.\n *\n * A tick rotated anti-clockwise trails off to the lower left, so it must be\n * anchored at its end; a clockwise one trails to the lower right and is anchored\n * at its start. Only an *omitted* angle keeps recharts' own default (`middle`):\n * the branch is on `angle < 0`, so `angle={0}` anchors at `start` like any\n * clockwise rotation. A caller that normalises \"upright\" to `0` instead of\n * leaving `xAxisAngle` off therefore gets the rotated-tick treatment — here and\n * in `resolveXAxisHeight`.\n */\nexport function resolveRotatedTickAnchor(\n angle: number | undefined\n): 'start' | 'end' | undefined {\n if (angle == null) return undefined;\n return angle < 0 ? 'end' : 'start';\n}\n\n/**\n * Height to reserve for the X tick row, or `undefined` to keep recharts' own\n * default. Shared by all 7 cartesian charts.\n *\n * recharts' default 30 covers one upright tick row and nothing else, so a\n * rotated row (+20) and an axis title (+18) each need their own allowance. The\n * two are additive rather than exclusive — a chart can rotate its ticks *and*\n * title the axis, which a label-or-angle ternary under-allocates.\n *\n * The +20 keys off the angle being *present*, not non-zero, so `angle={0}`\n * reserves the rotated row's height as well — the same edge case\n * `resolveRotatedTickAnchor` has, kept consistent between the two.\n */\nexport function resolveXAxisHeight(\n label: string | undefined,\n angle: number | undefined\n): number | undefined {\n if (!label && angle == null) return undefined;\n return 30 + (angle != null ? 20 : 0) + (label ? 18 : 0);\n}\n\n/**\n * recharts `label` for an X axis title, placed below the tick row. Shared by all\n * 7 cartesian charts; `insideTop` is for a secondary scale on the top edge.\n */\nexport function resolveXAxisTitle(\n label: string | undefined,\n position: 'insideBottom' | 'insideTop' = 'insideBottom',\n offset = 0\n) {\n if (!label) return undefined;\n return { value: label, position, offset };\n}\n\n/**\n * recharts `label` for a rotated value-axis title, angled so it reads from the\n * outside in — upward on a left axis (the convention), downward on a right one,\n * where -90° would put the text's baseline against the plot. Shared by all 7\n * cartesian charts; only `ComposedChart` currently uses the right-hand side.\n */\nexport function resolveYAxisTitle(\n label: string | undefined,\n orientation: 'left' | 'right' = 'left'\n) {\n if (!label) return undefined;\n return {\n value: label,\n angle: orientation === 'left' ? -90 : 90,\n position:\n orientation === 'left' ? ('insideLeft' as const) : ('insideRight' as const),\n style: { textAnchor: 'middle' as const },\n };\n}\n\n/**\n * A category range on a cartesian chart: `from`/`to` accept either the\n * category's value (an `xKey` cell, e.g. `'Sep'`) or its 0-based row index. Both\n * ends are inclusive, and either can be omitted to run to that end of the data.\n * Shared by the charts that scope something to a slice of the categories — a\n * reference band, a per-series style override.\n */\nexport interface ChartCategoryRange {\n from?: string | number;\n to?: string | number;\n}\n\n/**\n * Resolve a category range to inclusive row indices. A bound is either the\n * category's own value (matched against the `xKey` cell) or a 0-based index;\n * an omitted bound runs to that end of the data. Returns `undefined` when the\n * data is empty or the range resolves to nothing (an unknown value, or a `to`\n * that lands before its `from`).\n *\n * Exported for unit tests; not part of the package's public API.\n */\nexport function resolveCategoryRange(\n range: ChartCategoryRange,\n data: ReadonlyArray<Record<string, unknown>>,\n xKey: string\n): [number, number] | undefined {\n if (data.length === 0) return undefined;\n\n const resolve = (bound: string | number | undefined, fallback: number) => {\n if (bound === undefined) return fallback;\n // A numeric bound is an index unless the categories are numbers themselves,\n // in which case matching a category value is the more useful reading.\n const asValue = data.findIndex((row) => row[xKey] === bound);\n if (asValue !== -1) return asValue;\n if (typeof bound === 'number' && Number.isInteger(bound)) {\n return bound >= 0 && bound < data.length ? bound : -1;\n }\n return -1;\n };\n\n const start = resolve(range.from, 0);\n const end = resolve(range.to, data.length - 1);\n if (start === -1 || end === -1 || start > end) return undefined;\n return [start, end];\n}\n\n/**\n * Which value axis a series is measured against, on a chart that can carry two.\n *\n * `secondary` is the opt-in: the second axis exists only when at least one series\n * asks for it, so a chart whose series all leave this unset keeps the single\n * shared scale — and its recharts output — exactly as before.\n */\nexport type ChartYAxisTarget = 'primary' | 'secondary';\n\n/**\n * Second value-axis props, for a chart whose series can be measured on two\n * independent scales. **Only `ComposedChart` implements these today.** It is the\n * one chart in the suite where two scales are unambiguous: its series already\n * differ in mark type, so a bar read against the left axis and a line against the\n * right can't be mistaken for two marks sharing one. On a single-mark chart (Bar,\n * Area) two scales invite comparing heights that aren't comparable, which is why\n * these props are not mixed into `CartesianChartProps`.\n *\n * The primary axis is configured through `CartesianChartProps` (`yAxisLabel`,\n * `yUnit`, `yTickFormatter`, `yAxisTickCount`, `yAxisDomain`, `showYAxis`); every\n * `secondary*` prop here is its counterpart on the second axis, so the two scales\n * format and bound themselves independently, and each is inert until a series\n * selects that axis.\n *\n * `yAxisOrientation` is the exception on both counts: it places the *primary*\n * axis, and it applies whether or not a second one exists. It lives here because\n * it is only meaningful once a chart can mirror a pair of axes — a single-axis\n * chart has no second side to give up.\n */\nexport interface SecondaryYAxisProps {\n /**\n * Which side the *primary* value axis sits on. Defaults to `left`. The secondary\n * axis always takes the opposite side. Unlike the `secondary*` props below, this\n * one applies to a single-scale chart too.\n *\n * Inert on a chart whose marks grow horizontally: the value axis is X there, so\n * the primary sits along the bottom edge and the secondary along the top, and\n * neither has a left/right side to pick.\n */\n yAxisOrientation?: 'left' | 'right';\n /**\n * Show the secondary axis's ticks + title. Defaults to `true`. Setting it false\n * keeps the second *scale* (series still measure against it) and only drops its\n * chrome — the same meaning `showYAxis` has for the primary axis.\n */\n showSecondaryYAxis?: boolean;\n /** Title rendered beside the secondary axis (rotated). */\n secondaryYAxisLabel?: string;\n /** Unit suffix appended to the secondary axis's tick values (recharts `unit`). */\n secondaryYUnit?: string;\n /** Format each secondary-axis tick value — the counterpart of `yTickFormatter`. */\n secondaryYTickFormatter?: TickFormatter;\n /** Desired number of ticks on the secondary axis (recharts `tickCount`; a hint, not exact). */\n secondaryYAxisTickCount?: number;\n /** Domain preset for the secondary axis — same presets as `yAxisDomain`. */\n secondaryYAxisDomain?: 'auto' | 'dataMin-dataMax' | 'zero';\n}\n\n/**\n * How a series interpolates between its points (recharts `type`), shared by the\n * Line and Area families so both offer the same set:\n *\n * - `linear` — straight segments between points.\n * - `monotone` — smoothed, without overshooting a point's value.\n * - `natural` — a natural cubic spline; smoother than `monotone`, but it may\n * overshoot, so read it as a trend rather than exact values.\n * - `basis` — a B-spline that is *not* required to pass through the points at\n * all; the smoothest option, and the least literal.\n * - `step` — right-angle segments, changing value at the midpoint between two\n * points; `stepBefore` changes at the leading point and `stepAfter` at the\n * trailing one.\n */\nexport type ChartCurveType =\n | 'linear'\n | 'monotone'\n | 'natural'\n | 'basis'\n | 'step'\n | 'stepBefore'\n | 'stepAfter';\n\n/** recharts animation easing curves. */\nexport type ChartAnimationEasing =\n | 'ease'\n | 'ease-in'\n | 'ease-out'\n | 'ease-in-out'\n | 'linear';\n\n/**\n * Entrance-animation props shared by *every* chart type (not just the cartesian\n * ones) — charts hardcode `isAnimationActive={false}` otherwise. All optional and\n * off by default, so an unset chart renders byte-identically to before (and its\n * VR baselines stay stable). Spread `resolveAnimation(props)` onto each series.\n */\nexport interface ChartAnimationProps {\n /** Enable entrance animation. Defaults to `false` (keeps output/baselines stable). */\n animate?: boolean;\n /** Animation duration in ms (recharts `animationDuration`). */\n animationDuration?: number;\n /** Delay before the animation starts, in ms (recharts `animationBegin`). */\n animationBegin?: number;\n /** Easing curve (recharts `animationEasing`). */\n animationEasing?: ChartAnimationEasing;\n}\n\n/** The resolved recharts animation props to spread onto a series/shape. */\nexport interface ResolvedAnimation {\n isAnimationActive: boolean | 'auto';\n animationDuration?: number;\n animationBegin?: number;\n animationEasing?: ChartAnimationEasing;\n}\n\n/**\n * Turn the shared `ChartAnimationProps` into the recharts series props. The\n * timing props only appear when given, so an unset chart spreads exactly\n * `{ isAnimationActive: false }` — the previous hardcoded value.\n *\n * `animate` maps to recharts' `'auto'`, not to a literal `true`: `'auto'` is the\n * only value that honors `prefers-reduced-motion` (and disables the animation in\n * SSR). recharts resolves it as\n * `isActive = isActiveProp === 'auto' ? !isSsr && !prefersReducedMotion : isActiveProp`,\n * so a literal `true` would force motion on users who asked for none — this\n * library has no other reduced-motion escape hatch.\n */\nexport function resolveAnimation(props: ChartAnimationProps): ResolvedAnimation {\n const { animate = false, animationDuration, animationBegin, animationEasing } =\n props;\n return {\n isAnimationActive: animate ? 'auto' : false,\n ...(animationDuration !== undefined ? { animationDuration } : {}),\n ...(animationBegin !== undefined ? { animationBegin } : {}),\n ...(animationEasing !== undefined ? { animationEasing } : {}),\n };\n}\n\n/**\n * Remove synthetic `_proj_*` series entries from a recharts payload array so\n * they don't appear in custom tooltip or legend content. Safe to call with\n * `undefined` — returns `undefined` unchanged.\n */\nexport function dropProjectionPayload<T extends { dataKey?: unknown }>(\n payload: readonly T[] | undefined\n): T[] | undefined {\n return payload?.filter(\n (item) =>\n !(typeof item.dataKey === 'string' && item.dataKey.startsWith('_proj_'))\n );\n}\n\n/** Where a data label sits on a cartesian series (recharts `LabelList` position). */\nexport type CartesianLabelPosition =\n | 'top'\n | 'bottom'\n | 'left'\n | 'right'\n | 'center'\n | 'insideTop'\n | 'insideBottom'\n | 'insideLeft'\n | 'insideRight'\n | 'insideStart'\n | 'insideEnd';\n\n/**\n * Where a data label sits on a *polar* series (Pie, RadialBar). Deliberately not\n * `CartesianLabelPosition`: recharts routes a polar label list through\n * `getAttrsOfPolarLabel` / `renderRadialLabel`, which understand only these\n * seven values — every cartesian-only position (`top`, `insideLeft`, …) silently\n * collapses to the same mid-radius placement, so offering them would advertise\n * distinctions that don't exist.\n */\nexport type PolarLabelPosition =\n | 'outside'\n | 'center'\n | 'centerTop'\n | 'centerBottom'\n | 'insideStart'\n | 'insideEnd'\n | 'end';\n\n/** Any position accepted by the suite's data labels. */\nexport type ChartLabelPosition = CartesianLabelPosition | PolarLabelPosition;\n\n/**\n * Data-label props shared by the charts that can annotate each point/segment with\n * its value. `labelPosition` stays per-chart (the valid position set differs by\n * family), but `showLabels` + `labelFormatter` are common. Label formatting reuses\n * the same `TickFormatter` type as the axes, so a label and its axis read the same.\n */\nexport interface ChartDataLabelProps {\n /** Render a value label on each data point/segment. Defaults to `false`. */\n showLabels?: boolean;\n /** Format each label value — pass the same formatter used on the value axis. */\n labelFormatter?: TickFormatter;\n}\n\n/**\n * Fill for a label that sits on the chart *surface* — i.e. an outside position\n * (`top`, `right`, polar `outside`). Inverts with the theme, so it only works\n * against the surface background.\n */\nexport const CHART_LABEL_FILL_CLASS = 'fill-[var(--ui-text-on-surface-primary)]!';\n\n/**\n * Fill for a label that sits on an *opaque series fill* — any `inside*`\n * position, a polar mid-radius/centroid placement, or a stacked bar/arc segment\n * (an area's fill is translucent, so it uses the on-surface token). The on-surface\n * token must not be used there: it resolves near-white in dark mode and drops to\n * ~1.6:1 against the saturated status/brand fills the charts colour series with,\n * failing the `accessibility/contrast` grammar rule (`must`, WCAG 1.4.3). This is\n * the same \"text on a strong colored surface\" token `Treemap` already uses; it is\n * white in both themes, so it holds up over every series colour.\n */\nexport const CHART_LABEL_FILL_ON_SERIES_CLASS =\n 'fill-[var(--ui-text-on-status-strong-neutral)]!';\n\nexport const CHART_LABEL_FONT_SIZE = 12;\n\n/**\n * Plot-area inset to apply when a Line/Area series carries outside data labels.\n * recharts hands those label lists `parentViewBox: undefined` (its own source\n * calls this out as a bug in `cartesian/Line.js`), so `getCartesianPosition`'s\n * `clamp` has nothing to clamp against and the first/last point's value is cut\n * off at the SVG edge. Widening the margin is the only lever a composition over\n * recharts has. `Bar` does pass a `parentViewBox`, so bar series don't need it.\n */\nexport const CHART_LABEL_MARGIN = {\n top: 16,\n right: 24,\n bottom: 5,\n left: 12,\n} as const;\n\n/** Positions that draw the label on top of the series fill rather than the surface. */\nconst ON_SERIES_LABEL_POSITIONS = new Set<ChartLabelPosition>([\n 'center',\n 'centerTop',\n 'centerBottom',\n 'insideTop',\n 'insideBottom',\n 'insideLeft',\n 'insideRight',\n 'insideStart',\n 'insideEnd',\n 'end',\n]);\n\n/**\n * Resolve where a cartesian value label sits, given the caller's override, the\n * layout, and the position of the series' growing end (`top` for a vertical bar\n * or a line/area point, `right` for a horizontal bar).\n *\n * The stacked branch is the reason this isn't inlined: a stacked segment has no\n * free space at its growing end — the next segment is drawn there — so a `top`\n * label lands *inside* its neighbour rather than over its own segment. Centring\n * it in its own segment is the readable placement; `resolveLabelFillClass` then\n * pairs it with the fill that has contrast over that family's series colour.\n */\nexport function resolveCartesianLabelPosition(options: {\n labelPosition?: CartesianLabelPosition;\n isStacked?: boolean;\n growingEnd?: CartesianLabelPosition;\n}): CartesianLabelPosition {\n const { labelPosition, isStacked = false, growingEnd = 'top' } = options;\n if (labelPosition !== undefined) return labelPosition;\n return isStacked ? 'center' : growingEnd;\n}\n\n/**\n * Pick the label fill that actually has contrast at `position`. Callers must pass\n * the *resolved* position (after their own default), never `undefined` for a\n * polar chart — recharts' polar fallback is a mid-radius placement, which is on\n * the fill even though no `inside*` value was given.\n *\n * Returns a `className`, not a `fill` attribute, and the utility is `!`-flagged:\n * the cartesian charts scope `[&_.recharts-label]:fill-foreground` on their\n * container to theme axis titles, and a `LabelList`'s text carries\n * `.recharts-label` too — so a CSS rule would quietly beat an SVG presentation\n * attribute and undo the contrast fix.\n *\n * `translucentSeries` opts a family out of the on-fill token: an area's fill is\n * a gradient (0.8 → 0.1 alpha) or a flat `fillOpacity`, so what sits behind the\n * label is the surface tinted by the series colour, not the series colour. The\n * white on-fill token disappears into it in light mode — the theme-inverting\n * on-surface token is the readable one there, and stays white in dark mode.\n */\nexport function resolveLabelFillClass(\n position: ChartLabelPosition,\n options: { translucentSeries?: boolean } = {}\n): string {\n if (options.translucentSeries) return CHART_LABEL_FILL_CLASS;\n return ON_SERIES_LABEL_POSITIONS.has(position)\n ? CHART_LABEL_FILL_ON_SERIES_CLASS\n : CHART_LABEL_FILL_CLASS;\n}\n\n/**\n * Adapt a `TickFormatter` to recharts' `LabelList` `formatter` prop, whose value\n * type is wider. Returns `undefined` when no formatter is given, so a label\n * renders its raw value. Lets labels reuse the same formatters as the value axis.\n *\n * Null/undefined is filtered out rather than forwarded: recharts builds a label\n * entry for *every* point including the null ones that `connectNulls` is meant to\n * bridge, and the tick formatters coerce (`formatCompactNumber(null)` is `\"0\"`,\n * `formatPercent(undefined)` is `\"undefined\"`) — which would paint a phantom\n * value over an intentional gap.\n */\nexport function toLabelFormatter(\n formatter: TickFormatter | undefined\n): ((value: unknown) => string) | undefined {\n if (!formatter) return undefined;\n return (value: unknown) =>\n value == null ? '' : formatter(value as number | string);\n}\n\n/** Where a reference line's caption sits relative to the rule. */\nexport type ChartReferenceLabelPosition =\n | 'top'\n | 'insideTopLeft'\n | 'insideTopRight'\n | 'insideBottomLeft'\n | 'insideBottomRight';\n\n/**\n * A dashed rule across the value axis — a target, a threshold, or a series\n * average. Shared by the cartesian charts that draw one (`BarChart`,\n * `LineChart`, `AreaChart`) so the config reads the same on all three.\n */\nexport interface ChartReferenceLine {\n /** Fixed position on the value axis. Takes precedence over `average`. */\n value?: number;\n /**\n * Draw the line at the mean of one series (a `dataKeys` entry) or, when\n * `true`, of every plotted series' values.\n */\n average?: boolean | string;\n /** Optional caption rendered alongside the line. */\n label?: string;\n /**\n * Where the caption sits. Defaults to the chart's own placement — move it\n * when the rule lands where the series already is and the two collide.\n */\n labelPosition?: ChartReferenceLabelPosition;\n}\n\n/**\n * Normalize the `referenceLine` prop — a single config or an array — to a list.\n * Every chart accepts both forms, so this keeps the render path uniform.\n */\nexport function toReferenceLineList(\n referenceLine: ChartReferenceLine | ChartReferenceLine[] | undefined\n): ChartReferenceLine[] {\n if (!referenceLine) return [];\n return Array.isArray(referenceLine) ? referenceLine : [referenceLine];\n}\n\n/**\n * Resolve a `referenceLine` config to a position on the value axis: a fixed\n * `value` wins; otherwise the mean of the requested series (a single `dataKeys`\n * entry, or all of them when `average` is `true`). Returns `undefined` when\n * there is nothing to draw (no config, or no numeric values to average) — the\n * caller skips the line rather than drawing it at 0.\n *\n * Rows are `unknown`-valued because `ComposedChart` types its data that way; the\n * body only ever reads cells that are numbers, so a wider row type costs nothing\n * and saves every caller a cast.\n */\nexport function resolveChartReferenceValue(\n referenceLine: ChartReferenceLine | undefined,\n data: ReadonlyArray<Record<string, unknown>>,\n dataKeys: string[]\n): number | undefined {\n if (!referenceLine) return undefined;\n if (typeof referenceLine.value === 'number') return referenceLine.value;\n if (!referenceLine.average) return undefined;\n\n const keys =\n typeof referenceLine.average === 'string'\n ? [referenceLine.average]\n : dataKeys;\n const nums = data.flatMap((row) =>\n keys\n .map((key) => row[key])\n .filter((value): value is number => typeof value === 'number')\n );\n if (nums.length === 0) return undefined;\n return nums.reduce((sum, n) => sum + n, 0) / nums.length;\n}\n\n/**\n * Stroke (and caption fill) of a reference rule. The muted text token, so the\n * rule reads as annotation rather than as another series — and stays legible in\n * both themes without competing with the series colors.\n */\nexport const CHART_REFERENCE_LINE_STROKE =\n 'var(--ui-text-on-surface-secondary)';\n\n/**\n * The recharts props that paint a reference rule: a dashed line in the muted\n * text token with an optional caption. Shared so the three charts that draw one\n * can't drift on the stroke, dash pattern, or caption styling.\n *\n * `labelPosition` is the chart's default placement; a config's own\n * `labelPosition` overrides it at the call site.\n *\n * `ifOverflow: 'extendDomain'` is part of the contract, not a detail: a target\n * above the data maximum is exactly the case a reference line is for, and\n * recharts' default (`discard`) would silently drop it.\n */\nexport function resolveReferenceLineProps(\n label: string | undefined,\n labelPosition: ChartReferenceLabelPosition = 'insideTopRight'\n) {\n return {\n stroke: CHART_REFERENCE_LINE_STROKE,\n strokeDasharray: '4 4',\n ifOverflow: 'extendDomain' as const,\n label: label\n ? {\n value: label,\n position: labelPosition,\n fill: CHART_REFERENCE_LINE_STROKE,\n fontSize: CHART_LABEL_FONT_SIZE,\n }\n : undefined,\n };\n}\n\n/**\n * Range-brush props for the cartesian charts that support one — `BarChart`,\n * `LineChart`, `AreaChart`, `ComposedChart`. Deliberately not folded into\n * `CartesianChartProps`: `ScatterChart` plots a continuous X (the brush indexes\n * rows, not values) and `Histogram` / `ConfidenceCone` render a derived series,\n * so a brush over their row order would slice the wrong thing.\n */\nexport interface ChartBrushProps {\n /**\n * Render a range brush beneath the chart — drag its handles (or the selected\n * window) to zoom the series to a slice of the data. Defaults to `false`.\n */\n showBrush?: boolean;\n /** Height of the brush strip in px. Defaults to 28. */\n brushHeight?: number;\n /**\n * Accessible name for the brush's two range handles. Both are focusable\n * `role=\"slider\"` elements, so they need one. Defaults to\n * `'Chart range selector'`.\n */\n brushAriaLabel?: string;\n}\n\n/**\n * Height of the brush strip. recharts' own default is 40, which eats an eighth\n * of a 320px-tall dashboard widget; 28 still fits the travellers and the\n * range captions.\n */\nexport const CHART_BRUSH_HEIGHT = 28;\n\n/**\n * Accessible name for the brush handles. recharts' own fallback is\n * `\"Min value: \".concat(start, \", Max value: \").concat(end)`, where both halves\n * come from a `name` property on the data row — a field none of our charts\n * require, so it announces \"Min value: undefined, Max value: undefined\". Always\n * pass `ariaLabel` to suppress it.\n */\nexport const CHART_BRUSH_ARIA_LABEL = 'Chart range selector';\n\n/** The resolved recharts brush props to spread onto a `<Brush>`. */\nexport interface ResolvedBrush {\n height: number;\n fill: string;\n stroke: string;\n travellerWidth: number;\n ariaLabel: string;\n}\n\n/**\n * Theme + size a recharts `<Brush>` from the shared `ChartBrushProps`.\n *\n * recharts derives the *whole* brush from two color props, so both have to be\n * chosen for every element they reach (`cartesian/Brush.js`):\n * - `fill` paints only the strip's background rect.\n * - `stroke` paints its border, the traveller handles' **fill**, the selected\n * window at 20% opacity, and the range caption text.\n *\n * Hence the mid-grey text token rather than the border one: the travellers are\n * solid `stroke`-colored rects with two hardcoded `#fff` grip lines drawn on\n * top, so a pale stroke would render the grips invisible in light mode. That\n * token is theme-stable (same grey in light and dark), and white grips read\n * against it either way.\n */\nexport function resolveBrushProps({\n brushHeight,\n brushAriaLabel = CHART_BRUSH_ARIA_LABEL,\n}: Omit<ChartBrushProps, 'showBrush'>): ResolvedBrush {\n return {\n // recharts drops the brush entirely when height <= 0, which would turn\n // `showBrush` into a silent no-op — treat a non-positive height as unset.\n height:\n brushHeight != null && brushHeight > 0 ? brushHeight : CHART_BRUSH_HEIGHT,\n fill: 'var(--ui-background-surface-secondary)',\n stroke: 'var(--ui-text-on-surface-secondary)',\n travellerWidth: 8,\n ariaLabel: brushAriaLabel,\n };\n}\n\nconst toNumber = (value: number | string): number | null => {\n // `Number('')` and `Number(' ')` are 0, not NaN — so blank strings have to be\n // rejected before the finite check, or an empty tick label would render \"0\".\n if (typeof value === 'string' && value.trim() === '') return null;\n const n = typeof value === 'number' ? value : Number(value);\n return Number.isFinite(n) ? n : null;\n};\n\n/**\n * Compact thousands/millions: `1234 → \"1.2K\"`, `1_500_000 → \"1.5M\"`. Non-numeric\n * values (including blank strings) pass through unchanged. Use for large-count\n * axes (revenue, users, …).\n *\n * Formats in `en`. For another locale use\n * `createTickFormatter({ notation: 'compact', maximumFractionDigits: 1 }, locale)`.\n */\nexport const formatCompactNumber: TickFormatter = (value) => {\n const n = toNumber(value);\n if (n === null) return String(value);\n return new Intl.NumberFormat('en', {\n notation: 'compact',\n maximumFractionDigits: 1,\n }).format(n);\n};\n\n/**\n * Append a percent sign to an already-scaled value: `41.8 → \"41.8%\"`. (The value\n * is treated as a percentage, not a 0–1 fraction.) Non-numeric values (including\n * blank strings) pass through.\n *\n * Appends a bare `%`, which is not how every locale writes it. For locale-correct\n * output on values that really are fractions, use\n * `createTickFormatter({ style: 'percent' }, locale)`.\n */\nexport const formatPercent: TickFormatter = (value) => {\n const n = toNumber(value);\n if (n === null) return String(value);\n return `${n}%`;\n};\n\n/**\n * Build a tick formatter from `Intl.NumberFormat` options — the escape hatch for\n * currency, fixed decimals, or a specific locale. E.g.\n * `createTickFormatter({ style: 'currency', currency: 'USD', notation: 'compact' })`\n * → `146500 → \"$147K\"`. Non-numeric values pass through unchanged.\n */\nexport function createTickFormatter(\n options: Intl.NumberFormatOptions,\n locale = 'en'\n): TickFormatter {\n const nf = new Intl.NumberFormat(locale, options);\n return (value) => {\n const n = toNumber(value);\n return n === null ? String(value) : nf.format(n);\n };\n}\n"],"mappings":";AA6GA,SAAgB,EACd,GACwD;CACxD,QAAQ,GAAR;EACE,KAAK,QACH,OAAO,CAAC,QAAQ,MAAM;EACxB,KAAK,QACH,OAAO,CAAC,GAAG,MAAM;EACnB,KAAK,mBACH,OAAO,CAAC,WAAW,SAAS;EAC9B,SACE;CACJ;AACF;AAcA,SAAgB,EACd,GAC6B;CACzB,SAAS,MACb,OAAO,IAAQ,IAAI,QAAQ;AAC7B;AAeA,SAAgB,EACd,GACA,GACoB;CAChB,OAAC,KAAS,KAAS,OACvB,OAAO,MAAM,KAAS,OAAY,IAAL,OAAW,IAAQ,KAAK;AACvD;AAMA,SAAgB,EACd,GACA,IAAyC,gBACzC,IAAS,GACT;CACK,OACL,OAAO;EAAE,OAAO;EAAO;EAAU;CAAO;AAC1C;AAQA,SAAgB,EACd,GACA,IAAgC,QAChC;CACK,OACL,OAAO;EACL,OAAO;EACP,OAAO,MAAgB,SAAS,MAAM;EACtC,UACE,MAAgB,SAAU,eAA0B;EACtD,OAAO,EAAE,YAAY,SAAkB;CACzC;AACF;AAuBA,SAAgB,EACd,GACA,GACA,GAC8B;CAC9B,IAAI,EAAK,WAAW,GAAG;CAEvB,IAAM,KAAW,GAAoC,MAAqB;EACxE,IAAI,MAAU,KAAA,GAAW,OAAO;EAGhC,IAAM,IAAU,EAAK,WAAW,MAAQ,EAAI,OAAU,CAAK;EAK3D,OAJI,MAAY,KACZ,OAAO,KAAU,YAAY,OAAO,UAAU,CAAK,KAC9C,KAAS,KAAK,IAAQ,EAAK,SAAS,IAAQ,KAF1B;CAK7B,GAEM,IAAQ,EAAQ,EAAM,MAAM,CAAC,GAC7B,IAAM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A,SAAgB,EACd,GACA,IAAS,MACM;CACf,IAAM,IAAK,IAAI,KAAK,aAAa,GAAQ,CAAO;CAChD,QAAQ,MAAU;EAChB,IAAM,IAAI,EAAS,CAAK;EACxB,OAAO,MAAM,OAAO,OAAO,CAAK,IAAI,EAAG,OAAO,CAAC;CACjD;AACF"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
//#region src/components/ui/chart/chart-palette.ts
|
|
2
2
|
var e = (e) => `var(--ui-dataviz-${e})`, t = Object.freeze(Array.from({ length: 16 }, (t, n) => e(`categorical-${n + 1}`))), n = Object.freeze({
|
|
3
|
-
blue: Object.freeze(Array.from({ length: 8 }, (t, n) => e(`sequential-blue-${
|
|
4
|
-
teal: Object.freeze(Array.from({ length: 8 }, (t, n) => e(`sequential-teal-${
|
|
5
|
-
orange: Object.freeze(Array.from({ length: 8 }, (t, n) => e(`sequential-orange-${
|
|
6
|
-
violet: Object.freeze(Array.from({ length: 8 }, (t, n) => e(`sequential-violet-${
|
|
3
|
+
blue: Object.freeze(Array.from({ length: 8 }, (t, n) => e(`sequential-blue-${8 - n}`))),
|
|
4
|
+
teal: Object.freeze(Array.from({ length: 8 }, (t, n) => e(`sequential-teal-${8 - n}`))),
|
|
5
|
+
orange: Object.freeze(Array.from({ length: 8 }, (t, n) => e(`sequential-orange-${8 - n}`))),
|
|
6
|
+
violet: Object.freeze(Array.from({ length: 8 }, (t, n) => e(`sequential-violet-${8 - n}`)))
|
|
7
7
|
}), r = (t) => Object.freeze([
|
|
8
8
|
e(`diverging-${t}-a3`),
|
|
9
|
+
e(`diverging-${t}-b3`),
|
|
9
10
|
e(`diverging-${t}-a2`),
|
|
10
|
-
e(`diverging-${t}-a1`),
|
|
11
|
-
e(`diverging-${t}-b1`),
|
|
12
11
|
e(`diverging-${t}-b2`),
|
|
13
|
-
e(`diverging-${t}-
|
|
12
|
+
e(`diverging-${t}-a1`),
|
|
13
|
+
e(`diverging-${t}-b1`)
|
|
14
14
|
]), i = Object.freeze({
|
|
15
15
|
"blue-orange": r("blue-orange"),
|
|
16
16
|
"teal-violet": r("teal-violet")
|
|
@@ -34,6 +34,7 @@ function c(e) {
|
|
|
34
34
|
switch (e.type) {
|
|
35
35
|
case "status": return Object.keys(a).map((e) => ({ status: e }));
|
|
36
36
|
case "categorical": return t.map((e, t) => ({ slot: t + 1 }));
|
|
37
|
+
case "diverging": return [{ side: "a" }, { side: "b" }];
|
|
37
38
|
default: return [];
|
|
38
39
|
}
|
|
39
40
|
}
|
|
@@ -51,7 +52,7 @@ function d(e, { index: t, tone: n }) {
|
|
|
51
52
|
else if (typeof n?.slot == "number") {
|
|
52
53
|
if (e.type === "categorical") return r[u(n.slot, r.length, e) - 1];
|
|
53
54
|
l(`A chart series pins slot ${n.slot} under the "${e.type}" palette, whose stops are a ramp and are not individually selectable. Ignoring.`);
|
|
54
|
-
}
|
|
55
|
+
} else n?.side !== void 0 && e.type !== "diverging" && l(`A chart series declares a side ("${n.side}") under the "${e.type}" palette, which is not diverging. Ignoring.`);
|
|
55
56
|
return r[t % r.length];
|
|
56
57
|
}
|
|
57
58
|
function f(e, t) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-palette.js","names":[],"sources":["../../../../src/components/ui/chart/chart-palette.ts"],"sourcesContent":["// The dataviz palettes a chart paints its series from.\n//\n// Every color here resolves to a `--ui-dataviz-*` token from\n// `@acronis-platform/tokens-pd`'s semantic tier (already imported by\n// `styles/index.css`), so light/dark and brand overrides come for free — the\n// tokens are `light-dark()` pairs. There is deliberately no `--ui-chart-*`\n// component tier: these tokens are already semantic and shared across every\n// chart type, and a 1:1 alias layer would be pure indirection (see\n// `context/conventions.md`, \"bridge what's reused\").\n//\n// The four palettes mirror the product's widget editor, which offers exactly\n// this choice — Categorical / Sequential / Diverging / Status — and then, for\n// Categorical and Status only, a per-series color picker. Sequential and\n// Diverging expose the ramp/pair and nothing else, so how N series spread\n// across a ramp's stops is this module's decision, not the user's.\n\n/** A sequential ramp: one hue, eight stops from lightest to darkest. */\nexport type ChartSequentialRamp = 'blue' | 'teal' | 'orange' | 'violet';\n\n/** A diverging pair: two hues meeting at a pale midpoint. */\nexport type ChartDivergingPair = 'blue-orange' | 'teal-violet';\n\n/**\n * A semantic status tone. Ordered by severity in the product's picker:\n * danger (red) · critical (orange) · warning (yellow) · success (green) ·\n * info (blue) · neutral (gray). Note that `critical` is orange and ranks\n * *below* `danger` — that is what the tokens say, across the whole semantic\n * tier, not a typo here.\n */\nexport type ChartStatusTone =\n | 'danger'\n | 'critical'\n | 'warning'\n | 'success'\n | 'info'\n | 'neutral';\n\n/** Which palette a chart's series are painted from. */\nexport type ChartPalette =\n | { type: 'categorical' }\n | { type: 'sequential'; ramp: ChartSequentialRamp }\n | { type: 'diverging'; pair: ChartDivergingPair }\n | { type: 'status' };\n\n/**\n * How one series picks its color out of the active palette.\n *\n * Only the two palettes whose colors are independent of each other accept an\n * override:\n *\n * - `categorical` — `{ slot }` picks one of the 16 hues.\n * - `status` — `{ status }` names a tone.\n *\n * `sequential` and `diverging` accept none. Their stops are a *ramp*: the\n * colors mean something only in relation to each other, so letting one series\n * jump to an arbitrary stop would break the reading order the ramp exists to\n * convey. The product's widget editor agrees — it offers a ramp/pair picker\n * and no per-series control. An override passed under those palettes is\n * ignored, with a dev warning.\n *\n * Neither form can express a color from outside the palette — that is the point.\n */\nexport type ChartSeriesTone =\n | { slot: number; status?: never; sameAs?: never }\n | { slot?: never; status: ChartStatusTone; sameAs?: never }\n /**\n * Paint whatever the series under this key paints, under any palette. For a\n * twin series that is the *same* metric drawn differently — a forecast tail\n * continuing its actuals, a projection band behind its bars — where two hues\n * would read as two metrics. Resolved by `resolveChartColors`, which is the\n * only place the whole config is in view.\n */\n | { slot?: never; status?: never; sameAs: string };\n\nconst token = (name: string) => `var(--ui-dataviz-${name})`;\n\n/** The 16 categorical hues, in the order the product's picker lists them. */\nexport const CHART_CATEGORICAL_TOKENS = Object.freeze(\n Array.from({ length: 16 }, (_, i) => token(`categorical-${i + 1}`))\n);\n\n/** Each sequential ramp's eight stops, lightest (1) to darkest (8). */\nexport const CHART_SEQUENTIAL_TOKENS: Readonly<\n Record<ChartSequentialRamp, readonly string[]>\n> = Object.freeze({\n blue: Object.freeze(\n Array.from({ length: 8 }, (_, i) => token(`sequential-blue-${i + 1}`))\n ),\n teal: Object.freeze(\n Array.from({ length: 8 }, (_, i) => token(`sequential-teal-${i + 1}`))\n ),\n orange: Object.freeze(\n Array.from({ length: 8 }, (_, i) => token(`sequential-orange-${i + 1}`))\n ),\n violet: Object.freeze(\n Array.from({ length: 8 }, (_, i) => token(`sequential-violet-${i + 1}`))\n ),\n});\n\n// Ordered `a3 → a1` then `b1 → b3`: strongest of the first hue, through the two\n// pale midpoints, out to the strongest of the second. That is the order the\n// ChartTreeMap mockup paints its tiles in (Figma node 8999:72012), and it is\n// what makes a diverging palette read as a single gradient rather than two\n// unrelated ramps.\nconst divergingStops = (pair: string) =>\n Object.freeze([\n token(`diverging-${pair}-a3`),\n token(`diverging-${pair}-a2`),\n token(`diverging-${pair}-a1`),\n token(`diverging-${pair}-b1`),\n token(`diverging-${pair}-b2`),\n token(`diverging-${pair}-b3`),\n ]);\n\n/** Each diverging pair's six stops, one hue's strongest through to the other's. */\nexport const CHART_DIVERGING_TOKENS: Readonly<\n Record<ChartDivergingPair, readonly string[]>\n> = Object.freeze({\n 'blue-orange': divergingStops('blue-orange'),\n 'teal-violet': divergingStops('teal-violet'),\n});\n\n/** The six semantic status tones. */\nexport const CHART_STATUS_TOKENS: Readonly<Record<ChartStatusTone, string>> =\n Object.freeze({\n danger: token('meaningful-status-danger'),\n critical: token('meaningful-status-critical'),\n warning: token('meaningful-status-warning'),\n success: token('meaningful-status-success'),\n info: token('meaningful-status-info'),\n neutral: token('meaningful-status-neutral'),\n });\n\n/** The default palette — what a chart paints with when none is chosen. */\nexport const CHART_DEFAULT_PALETTE: ChartPalette = Object.freeze({\n type: 'categorical',\n});\n\n/**\n * The stops a palette offers, in picker order. `status` has named tones rather\n * than positional stops, so it returns an empty list — use\n * `CHART_STATUS_TOKENS` for those.\n */\nexport function listPaletteStops(palette: ChartPalette): readonly string[] {\n switch (palette.type) {\n case 'categorical':\n return CHART_CATEGORICAL_TOKENS;\n case 'sequential':\n return CHART_SEQUENTIAL_TOKENS[palette.ramp];\n case 'diverging':\n return CHART_DIVERGING_TOKENS[palette.pair];\n case 'status':\n return [];\n }\n}\n\n/**\n * Every choice a per-series picker may offer for this palette — what the\n * product's widget editor renders in its dropdown. Pure, so the form can build\n * its UI without re-deriving the palette.\n *\n * Empty for `sequential` and `diverging`: those have no per-series control, so\n * a form driven by this function renders no picker for them, which is exactly\n * the design.\n */\nexport function listPaletteChoices(\n palette: ChartPalette\n): readonly ChartSeriesTone[] {\n switch (palette.type) {\n case 'status':\n return (Object.keys(CHART_STATUS_TOKENS) as ChartStatusTone[]).map(\n (status) => ({ status })\n );\n case 'categorical':\n return CHART_CATEGORICAL_TOKENS.map((_, i) => ({ slot: i + 1 }));\n default:\n return [];\n }\n}\n\nfunction warn(message: string) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`[ui-react] ${message}`);\n }\n}\n\nfunction clampSlot(slot: number, length: number, palette: ChartPalette) {\n const rounded = Math.round(slot);\n\n if (!Number.isFinite(slot) || rounded < 1 || rounded > length) {\n warn(\n `Chart series slot ${slot} is outside the \"${palette.type}\" palette (1–${length}). Clamping.`\n );\n return Math.min(\n Math.max(Number.isFinite(rounded) ? rounded : 1, 1),\n length\n );\n }\n\n return rounded;\n}\n\nexport interface ResolveSeriesColorOptions {\n /** This series' position among the chart's series. */\n index: number;\n /** This series' explicit choice within the palette, if it may make one. */\n tone?: ChartSeriesTone;\n}\n\n/**\n * The color one series paints with.\n *\n * Series walk the palette **in its defined order** — series 1 takes stop 1,\n * series 2 takes stop 2, and so on, wrapping once the stops run out. The order\n * is the design's, not something derived here: no re-ordering, no spreading\n * across a ramp, no skipping stops.\n *\n * On top of that, `categorical` and `status` honour a per-series override\n * (see `ChartSeriesTone`); `sequential` and `diverging` do not.\n *\n * Always returns a token from the active palette. A `slot` out of range is\n * clamped (with a dev warning) rather than passed through, so switching\n * palettes can never leave a series painting off-palette.\n */\nexport function resolveSeriesColor(\n palette: ChartPalette,\n { index, tone }: ResolveSeriesColorOptions\n): string {\n if (palette.type === 'status') {\n if (tone?.status) {\n return CHART_STATUS_TOKENS[tone.status];\n }\n\n // Unlike the ordered palettes there is no meaningful \"next\" tone to fall\n // back to — status colors carry meaning, and inventing one would be worse\n // than reading gray.\n warn(\n 'A chart series has no `status` under the \"status\" palette. Falling back to neutral.'\n );\n return CHART_STATUS_TOKENS.neutral;\n }\n\n const stops = listPaletteStops(palette);\n\n if (tone?.status) {\n warn(\n `A chart series names a status (\"${tone.status}\") under the \"${palette.type}\" palette, which has no status tones. Ignoring.`\n );\n } else if (typeof tone?.slot === 'number') {\n if (palette.type === 'categorical') {\n return stops[clampSlot(tone.slot, stops.length, palette) - 1];\n }\n\n warn(\n `A chart series pins slot ${tone.slot} under the \"${palette.type}\" palette, whose stops are a ramp and are not individually selectable. Ignoring.`\n );\n }\n\n // Wraps rather than clamps once the stops run out: a chart with more series\n // than the palette has colors is unreadable either way, but wrapping keeps\n // each series distinguishable from its immediate neighbours.\n return stops[index % stops.length];\n}\n\n/**\n * Series that would paint the same color — what the widget editor's \"duplicate\n * color\" warning is keyed to. Returns one group per collision, each holding the\n * colliding series' keys in input order.\n *\n * Only series that named a `tone` can collide: automatic assignment is\n * injective by construction (up to `categorical`'s 16-series wrap).\n *\n * Pass the chart's `config` to exclude intentional aliases: a series with\n * `tone: { sameAs }` shares its target's colour on purpose, so it is not a\n * collision. Without the config every alias reads as a duplicate.\n */\nexport function findDuplicateTones(\n colors: Readonly<Record<string, string>>,\n config?: Readonly<Record<string, { tone?: { sameAs?: string } }>>\n): string[][] {\n const byColor = new Map<string, string[]>();\n\n for (const [key, color] of Object.entries(colors)) {\n if (config?.[key]?.tone?.sameAs) {\n continue;\n }\n const group = byColor.get(color);\n if (group) {\n group.push(key);\n } else {\n byColor.set(color, [key]);\n }\n }\n\n return [...byColor.values()].filter((group) => group.length > 1);\n}\n"],"mappings":";AA0EA,IAAM,KAAS,MAAiB,oBAAoB,EAAK,IAG5C,IAA2B,OAAO,OAC7C,MAAM,KAAK,EAAE,QAAQ,GAAG,IAAI,GAAG,MAAM,EAAM,eAAe,IAAI,GAAG,CAAC,CACpE,GAGa,IAET,OAAO,OAAO;CAChB,MAAM,OAAO,OACX,MAAM,KAAK,EAAE,QAAQ,EAAE,IAAI,GAAG,MAAM,EAAM,mBAAmB,IAAI,GAAG,CAAC,CACvE;CACA,MAAM,OAAO,OACX,MAAM,KAAK,EAAE,QAAQ,EAAE,IAAI,GAAG,MAAM,EAAM,mBAAmB,IAAI,GAAG,CAAC,CACvE;CACA,QAAQ,OAAO,OACb,MAAM,KAAK,EAAE,QAAQ,EAAE,IAAI,GAAG,MAAM,EAAM,qBAAqB,IAAI,GAAG,CAAC,CACzE;CACA,QAAQ,OAAO,OACb,MAAM,KAAK,EAAE,QAAQ,EAAE,IAAI,GAAG,MAAM,EAAM,qBAAqB,IAAI,GAAG,CAAC,CACzE;AACF,CAAC,GAOK,KAAkB,MACtB,OAAO,OAAO;CACZ,EAAM,aAAa,EAAK,IAAI;CAC5B,EAAM,aAAa,EAAK,IAAI;CAC5B,EAAM,aAAa,EAAK,IAAI;CAC5B,EAAM,aAAa,EAAK,IAAI;CAC5B,EAAM,aAAa,EAAK,IAAI;CAC5B,EAAM,aAAa,EAAK,IAAI;AAC9B,CAAC,GAGU,IAET,OAAO,OAAO;CAChB,eAAe,EAAe,aAAa;CAC3C,eAAe,EAAe,aAAa;AAC7C,CAAC,GAGY,IACX,OAAO,OAAO;CACZ,QAAQ,EAAM,0BAA0B;CACxC,UAAU,EAAM,4BAA4B;CAC5C,SAAS,EAAM,2BAA2B;CAC1C,SAAS,EAAM,2BAA2B;CAC1C,MAAM,EAAM,wBAAwB;CACpC,SAAS,EA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AU,EAAK,MAAM,EAAM,QAAQ,CAAO,IAAI;EAG7D,EACE,4BAA4B,EAAK,KAAK,cAAc,EAAQ,KAAK,iFACnE;CACF;CAKA,OAAO,EAAM,IAAQ,EAAM;AAC7B;AAcA,SAAgB,EACd,GACA,GACY;CACZ,IAAM,oBAAU,IAAI,IAAsB;CAE1C,KAAK,IAAM,CAAC,GAAK,MAAU,OAAO,QAAQ,CAAM,GAAG;EACjD,IAAI,IAAS,EAAI,EAAE,MAAM,QACvB;EAEF,IAAM,IAAQ,EAAQ,IAAI,CAAK;EAC/B,AAAI,IACF,EAAM,KAAK,CAAG,IAEd,EAAQ,IAAI,GAAO,CAAC,CAAG,CAAC;CAE5B;CAEA,OAAO,CAAC,GAAG,EAAQ,OAAO,CAAC,CAAC,CAAC,QAAQ,MAAU,EAAM,SAAS,CAAC;AACjE"}
|
|
1
|
+
{"version":3,"file":"chart-palette.js","names":[],"sources":["../../../../src/components/ui/chart/chart-palette.ts"],"sourcesContent":["// The dataviz palettes a chart paints its series from.\n//\n// Every color here resolves to a `--ui-dataviz-*` token from\n// `@acronis-platform/tokens-pd`'s semantic tier (already imported by\n// `styles/index.css`), so light/dark and brand overrides come for free — the\n// tokens are `light-dark()` pairs. There is deliberately no `--ui-chart-*`\n// component tier: these tokens are already semantic and shared across every\n// chart type, and a 1:1 alias layer would be pure indirection (see\n// `context/conventions.md`, \"bridge what's reused\").\n//\n// The four palettes mirror the product's widget editor, which offers exactly\n// this choice — Categorical / Sequential / Diverging / Status — and then, for\n// Categorical and Status only, a per-series color picker. Sequential and\n// Diverging expose the ramp/pair and nothing else, so how N series spread\n// across a ramp's stops is this module's decision, not the user's.\n\n/** A sequential ramp: one hue, eight stops from lightest to darkest. */\nexport type ChartSequentialRamp = 'blue' | 'teal' | 'orange' | 'violet';\n\n/** A diverging pair: two hues meeting at a pale midpoint. */\nexport type ChartDivergingPair = 'blue-orange' | 'teal-violet';\n\n/**\n * A semantic status tone. Ordered by severity in the product's picker:\n * danger (red) · critical (orange) · warning (yellow) · success (green) ·\n * info (blue) · neutral (gray). Note that `critical` is orange and ranks\n * *below* `danger` — that is what the tokens say, across the whole semantic\n * tier, not a typo here.\n */\nexport type ChartStatusTone =\n | 'danger'\n | 'critical'\n | 'warning'\n | 'success'\n | 'info'\n | 'neutral';\n\n/** Which hue side of a diverging pair a series belongs to. */\nexport type ChartDivergingSide = 'a' | 'b';\n\n/** Which palette a chart's series are painted from. */\nexport type ChartPalette =\n | { type: 'categorical' }\n | { type: 'sequential'; ramp: ChartSequentialRamp }\n | { type: 'diverging'; pair: ChartDivergingPair }\n | { type: 'status' };\n\n/**\n * How one series picks its color out of the active palette.\n *\n * Three palettes accept a per-series override:\n *\n * - `categorical` — `{ slot }` picks one of the 16 hues.\n * - `status` — `{ status }` names a tone (required; there is no meaningful\n * positional fallback for status colors).\n * - `diverging` — `{ side: 'a' | 'b' }` pins the series to one hue family.\n * All side-`a` series walk the a-hue stops (a3 → a2 → a1, strongest-first,\n * wrapping past three). All side-`b` series walk the b-hue stops likewise.\n * Un-sided series walk the default interleaved ramp (a3-b3-a2-b2-a1-b1),\n * skipping any stop already claimed by a sided series. This assignment\n * requires the full config, so it happens in `resolveChartColors`, not here.\n *\n * `sequential` accepts no override: its stops are a ramp, meaningful only in\n * relation to each other. An override passed under a non-matching palette is\n * ignored, with a dev warning.\n *\n * `{ sameAs: key }` is palette-agnostic: the series mirrors whatever color\n * another series resolves to. Use it for a twin series that is the *same*\n * metric drawn differently (a forecast tail, a projection band), where two\n * distinct hues would read as two separate metrics. An aliased series doesn't\n * consume a stop.\n *\n * No form can express a color from outside the active palette — that is the point.\n */\nexport type ChartSeriesTone =\n | { slot: number; status?: never; sameAs?: never; side?: never }\n | { slot?: never; status: ChartStatusTone; sameAs?: never; side?: never }\n /**\n * Paint whatever the series under this key paints, under any palette. For a\n * twin series that is the *same* metric drawn differently — a forecast tail\n * continuing its actuals, a projection band behind its bars — where two hues\n * would read as two metrics. Resolved by `resolveChartColors`, which is the\n * only place the whole config is in view.\n */\n | { slot?: never; status?: never; sameAs: string; side?: never }\n /**\n * Diverging palette only. Pins this series to one of the two hue sides.\n * `resolveChartColors` groups all series that share a side together and\n * assigns them that side's three stops (strongest first, wrapping). Series\n * that declare no side walk the default interleaved ramp.\n *\n * Under any palette other than `diverging`, this is ignored with a dev warning.\n */\n | { slot?: never; status?: never; sameAs?: never; side: ChartDivergingSide };\n\nconst token = (name: string) => `var(--ui-dataviz-${name})`;\n\n/** The 16 categorical hues, in the order the product's picker lists them. */\nexport const CHART_CATEGORICAL_TOKENS = Object.freeze(\n Array.from({ length: 16 }, (_, i) => token(`categorical-${i + 1}`))\n);\n\n/** Each sequential ramp's eight stops, darkest (8) to lightest (1). */\nexport const CHART_SEQUENTIAL_TOKENS: Readonly<\n Record<ChartSequentialRamp, readonly string[]>\n> = Object.freeze({\n blue: Object.freeze(\n Array.from({ length: 8 }, (_, i) => token(`sequential-blue-${8 - i}`))\n ),\n teal: Object.freeze(\n Array.from({ length: 8 }, (_, i) => token(`sequential-teal-${8 - i}`))\n ),\n orange: Object.freeze(\n Array.from({ length: 8 }, (_, i) => token(`sequential-orange-${8 - i}`))\n ),\n violet: Object.freeze(\n Array.from({ length: 8 }, (_, i) => token(`sequential-violet-${8 - i}`))\n ),\n});\n\n// Interleaved strongest-first: a3-b3-a2-b2-a1-b1 so adjacent series contrast\n// maximally (one \"a\" hue next to one \"b\" hue), and the darkest/most saturated\n// stops are used first.\nconst divergingStops = (pair: string) =>\n Object.freeze([\n token(`diverging-${pair}-a3`),\n token(`diverging-${pair}-b3`),\n token(`diverging-${pair}-a2`),\n token(`diverging-${pair}-b2`),\n token(`diverging-${pair}-a1`),\n token(`diverging-${pair}-b1`),\n ]);\n\n/** Each diverging pair's six stops, one hue's strongest through to the other's. */\nexport const CHART_DIVERGING_TOKENS: Readonly<\n Record<ChartDivergingPair, readonly string[]>\n> = Object.freeze({\n 'blue-orange': divergingStops('blue-orange'),\n 'teal-violet': divergingStops('teal-violet'),\n});\n\n/** The six semantic status tones. */\nexport const CHART_STATUS_TOKENS: Readonly<Record<ChartStatusTone, string>> =\n Object.freeze({\n danger: token('meaningful-status-danger'),\n critical: token('meaningful-status-critical'),\n warning: token('meaningful-status-warning'),\n success: token('meaningful-status-success'),\n info: token('meaningful-status-info'),\n neutral: token('meaningful-status-neutral'),\n });\n\n/** The default palette — what a chart paints with when none is chosen. */\nexport const CHART_DEFAULT_PALETTE: ChartPalette = Object.freeze({\n type: 'categorical',\n});\n\n/**\n * The stops a palette offers, in picker order. `status` has named tones rather\n * than positional stops, so it returns an empty list — use\n * `CHART_STATUS_TOKENS` for those.\n */\nexport function listPaletteStops(palette: ChartPalette): readonly string[] {\n switch (palette.type) {\n case 'categorical':\n return CHART_CATEGORICAL_TOKENS;\n case 'sequential':\n return CHART_SEQUENTIAL_TOKENS[palette.ramp];\n case 'diverging':\n return CHART_DIVERGING_TOKENS[palette.pair];\n case 'status':\n return [];\n }\n}\n\n/**\n * Every choice a per-series picker may offer for this palette — what the\n * product's widget editor renders in its dropdown. Pure, so the form can build\n * its UI without re-deriving the palette.\n *\n * Empty for `sequential` and `diverging`: those have no per-series control, so\n * a form driven by this function renders no picker for them, which is exactly\n * the design.\n */\nexport function listPaletteChoices(\n palette: ChartPalette\n): readonly ChartSeriesTone[] {\n switch (palette.type) {\n case 'status':\n return (Object.keys(CHART_STATUS_TOKENS) as ChartStatusTone[]).map(\n (status) => ({ status })\n );\n case 'categorical':\n return CHART_CATEGORICAL_TOKENS.map((_, i) => ({ slot: i + 1 }));\n case 'diverging':\n return [{ side: 'a' as const }, { side: 'b' as const }];\n default:\n return [];\n }\n}\n\nfunction warn(message: string) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`[ui-react] ${message}`);\n }\n}\n\nfunction clampSlot(slot: number, length: number, palette: ChartPalette) {\n const rounded = Math.round(slot);\n\n if (!Number.isFinite(slot) || rounded < 1 || rounded > length) {\n warn(\n `Chart series slot ${slot} is outside the \"${palette.type}\" palette (1–${length}). Clamping.`\n );\n return Math.min(\n Math.max(Number.isFinite(rounded) ? rounded : 1, 1),\n length\n );\n }\n\n return rounded;\n}\n\nexport interface ResolveSeriesColorOptions {\n /** This series' position among the chart's series. */\n index: number;\n /** This series' explicit choice within the palette, if it may make one. */\n tone?: ChartSeriesTone;\n}\n\n/**\n * The color one series paints with.\n *\n * Series walk the palette **in its defined order** — series 1 takes stop 1,\n * series 2 takes stop 2, and so on, wrapping once the stops run out. The order\n * is the design's, not something derived here: no re-ordering, no spreading\n * across a ramp, no skipping stops.\n *\n * On top of that, `categorical` and `status` honour a per-series override\n * (see `ChartSeriesTone`); `sequential` and `diverging` do not.\n *\n * Always returns a token from the active palette. A `slot` out of range is\n * clamped (with a dev warning) rather than passed through, so switching\n * palettes can never leave a series painting off-palette.\n */\nexport function resolveSeriesColor(\n palette: ChartPalette,\n { index, tone }: ResolveSeriesColorOptions\n): string {\n if (palette.type === 'status') {\n if (tone?.status) {\n return CHART_STATUS_TOKENS[tone.status];\n }\n\n // Unlike the ordered palettes there is no meaningful \"next\" tone to fall\n // back to — status colors carry meaning, and inventing one would be worse\n // than reading gray.\n warn(\n 'A chart series has no `status` under the \"status\" palette. Falling back to neutral.'\n );\n return CHART_STATUS_TOKENS.neutral;\n }\n\n const stops = listPaletteStops(palette);\n\n if (tone?.status) {\n warn(\n `A chart series names a status (\"${tone.status}\") under the \"${palette.type}\" palette, which has no status tones. Ignoring.`\n );\n } else if (typeof tone?.slot === 'number') {\n if (palette.type === 'categorical') {\n return stops[clampSlot(tone.slot, stops.length, palette) - 1];\n }\n\n warn(\n `A chart series pins slot ${tone.slot} under the \"${palette.type}\" palette, whose stops are a ramp and are not individually selectable. Ignoring.`\n );\n } else if (tone?.side !== undefined) {\n if (palette.type !== 'diverging') {\n warn(\n `A chart series declares a side (\"${tone.side}\") under the \"${palette.type}\" palette, which is not diverging. Ignoring.`\n );\n }\n // For diverging: resolveChartColors handles side assignment directly.\n // Fall through to positional as a safe fallback for standalone calls.\n }\n\n // Wraps rather than clamps once the stops run out: a chart with more series\n // than the palette has colors is unreadable either way, but wrapping keeps\n // each series distinguishable from its immediate neighbours.\n return stops[index % stops.length];\n}\n\n/**\n * Series that would paint the same color — what the widget editor's \"duplicate\n * color\" warning is keyed to. Returns one group per collision, each holding the\n * colliding series' keys in input order.\n *\n * Only series that named a `tone` can collide: automatic assignment is\n * injective by construction (up to `categorical`'s 16-series wrap).\n *\n * Pass the chart's `config` to exclude intentional aliases: a series with\n * `tone: { sameAs }` shares its target's colour on purpose, so it is not a\n * collision. Without the config every alias reads as a duplicate.\n */\nexport function findDuplicateTones(\n colors: Readonly<Record<string, string>>,\n config?: Readonly<Record<string, { tone?: { sameAs?: string } }>>\n): string[][] {\n const byColor = new Map<string, string[]>();\n\n for (const [key, color] of Object.entries(colors)) {\n if (config?.[key]?.tone?.sameAs) {\n continue;\n }\n const group = byColor.get(color);\n if (group) {\n group.push(key);\n } else {\n byColor.set(color, [key]);\n }\n }\n\n return [...byColor.values()].filter((group) => group.length > 1);\n}\n"],"mappings":";AA+FA,IAAM,KAAS,MAAiB,oBAAoB,EAAK,IAG5C,IAA2B,OAAO,OAC7C,MAAM,KAAK,EAAE,QAAQ,GAAG,IAAI,GAAG,MAAM,EAAM,eAAe,IAAI,GAAG,CAAC,CACpE,GAGa,IAET,OAAO,OAAO;CAChB,MAAM,OAAO,OACX,MAAM,KAAK,EAAE,QAAQ,EAAE,IAAI,GAAG,MAAM,EAAM,mBAAmB,IAAI,GAAG,CAAC,CACvE;CACA,MAAM,OAAO,OACX,MAAM,KAAK,EAAE,QAAQ,EAAE,IAAI,GAAG,MAAM,EAAM,mBAAmB,IAAI,GAAG,CAAC,CACvE;CACA,QAAQ,OAAO,OACb,MAAM,KAAK,EAAE,QAAQ,EAAE,IAAI,GAAG,MAAM,EAAM,qBAAqB,IAAI,GAAG,CAAC,CACzE;CACA,QAAQ,OAAO,OACb,MAAM,KAAK,EAAE,QAAQ,EAAE,IAAI,GAA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