@sproutsocial/seeds-react-data-viz 0.16.1 → 0.17.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/annotations-CjFoRPXf.d.mts +20 -0
- package/dist/annotations-CjFoRPXf.d.ts +20 -0
- package/dist/axis-WOeYkTO1.d.mts +44 -0
- package/dist/axis-WOeYkTO1.d.ts +44 -0
- package/dist/bar/index.d.mts +3 -1
- package/dist/bar/index.d.ts +3 -1
- package/dist/bar/index.js +12 -8
- package/dist/bar/index.js.map +1 -1
- package/dist/{axis-BVPkC6iF.d.ts → chartBase-C-l7yYGx.d.ts} +5 -59
- package/dist/{axis-BjucJt39.d.mts → chartBase-Cn_5CUJi.d.mts} +5 -59
- package/dist/{chunk-EJYDQYLE.js → chunk-2K7PFHIM.js} +92 -245
- package/dist/chunk-2K7PFHIM.js.map +1 -0
- package/dist/chunk-6D7P3IOT.js +150 -0
- package/dist/chunk-6D7P3IOT.js.map +1 -0
- package/dist/chunk-CYQXUAJC.js +169 -0
- package/dist/chunk-CYQXUAJC.js.map +1 -0
- package/dist/chunk-VVGBJOFH.js +68 -0
- package/dist/chunk-VVGBJOFH.js.map +1 -0
- package/dist/donut/index.d.mts +48 -0
- package/dist/donut/index.d.ts +48 -0
- package/dist/donut/index.js +125 -0
- package/dist/donut/index.js.map +1 -0
- package/dist/esm/bar/index.js +10 -6
- package/dist/esm/bar/index.js.map +1 -1
- package/dist/esm/chunk-AUJ3EWRH.js +68 -0
- package/dist/esm/chunk-AUJ3EWRH.js.map +1 -0
- package/dist/esm/{chunk-DKTW56NJ.js → chunk-LPQXJJNT.js} +93 -246
- package/dist/esm/chunk-LPQXJJNT.js.map +1 -0
- package/dist/esm/chunk-NAKJY5PA.js +150 -0
- package/dist/esm/chunk-NAKJY5PA.js.map +1 -0
- package/dist/esm/chunk-XMYGML25.js +169 -0
- package/dist/esm/chunk-XMYGML25.js.map +1 -0
- package/dist/esm/donut/index.js +125 -0
- package/dist/esm/donut/index.js.map +1 -0
- package/dist/esm/index.js +13 -157
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/line-area/index.js +11 -6
- package/dist/esm/line-area/index.js.map +1 -1
- package/dist/esm/sparkline/index.js +123 -0
- package/dist/esm/sparkline/index.js.map +1 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +55 -199
- package/dist/index.js.map +1 -1
- package/dist/line-area/index.d.mts +6 -3
- package/dist/line-area/index.d.ts +6 -3
- package/dist/line-area/index.js +13 -8
- package/dist/line-area/index.js.map +1 -1
- package/dist/sparkline/index.d.mts +75 -0
- package/dist/sparkline/index.d.ts +75 -0
- package/dist/sparkline/index.js +123 -0
- package/dist/sparkline/index.js.map +1 -0
- package/dist/sparkline.css +76 -0
- package/package.json +13 -2
- package/dist/chunk-EJYDQYLE.js.map +0 -1
- package/dist/esm/chunk-DKTW56NJ.js.map +0 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// src/charts/shared/formatters/datetimeFormatter.ts
|
|
2
|
+
var DAY_MS = 864e5;
|
|
3
|
+
var WEEK_MS = 6048e5;
|
|
4
|
+
var MIN_MONTH_MS = 24192e5;
|
|
5
|
+
var MIN_YEAR_MS = 31536e6;
|
|
6
|
+
var getDatePartsInTimezone = (date, timezone) => {
|
|
7
|
+
const formatter = new Intl.DateTimeFormat("en-US", {
|
|
8
|
+
year: "numeric",
|
|
9
|
+
month: "numeric",
|
|
10
|
+
day: "numeric",
|
|
11
|
+
timeZone: timezone
|
|
12
|
+
});
|
|
13
|
+
const parts = formatter.formatToParts(date);
|
|
14
|
+
return {
|
|
15
|
+
day: parseInt(parts.find((p) => p.type === "day")?.value ?? "0", 10),
|
|
16
|
+
month: parseInt(parts.find((p) => p.type === "month")?.value ?? "0", 10),
|
|
17
|
+
year: parseInt(parts.find((p) => p.type === "year")?.value ?? "0", 10)
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
var deriveGranularity = (tickPositions) => {
|
|
21
|
+
if (tickPositions.length < 2) {
|
|
22
|
+
return "day";
|
|
23
|
+
}
|
|
24
|
+
const deltas = [];
|
|
25
|
+
for (let i = 1; i < tickPositions.length; i++) {
|
|
26
|
+
const curr = tickPositions[i];
|
|
27
|
+
const prev = tickPositions[i - 1];
|
|
28
|
+
if (curr === void 0 || prev === void 0) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
deltas.push(Math.abs(curr - prev));
|
|
32
|
+
}
|
|
33
|
+
deltas.sort((a, b) => a - b);
|
|
34
|
+
const mid = Math.floor(deltas.length / 2);
|
|
35
|
+
const upper = deltas[mid];
|
|
36
|
+
const lower = deltas[mid - 1];
|
|
37
|
+
const median = deltas.length % 2 === 0 && lower !== void 0 ? (lower + upper) / 2 : upper;
|
|
38
|
+
if (median < DAY_MS) {
|
|
39
|
+
return "hour";
|
|
40
|
+
}
|
|
41
|
+
if (median < WEEK_MS) {
|
|
42
|
+
return "day";
|
|
43
|
+
}
|
|
44
|
+
if (median < MIN_MONTH_MS) {
|
|
45
|
+
return "week";
|
|
46
|
+
}
|
|
47
|
+
if (median < MIN_YEAR_MS) {
|
|
48
|
+
return "month";
|
|
49
|
+
}
|
|
50
|
+
return "year";
|
|
51
|
+
};
|
|
52
|
+
function datetimeFormatter({
|
|
53
|
+
value,
|
|
54
|
+
tickPositions = [],
|
|
55
|
+
// optional
|
|
56
|
+
timezone = "UTC",
|
|
57
|
+
timeFormat = "12",
|
|
58
|
+
textLocale = "en-US"
|
|
59
|
+
}) {
|
|
60
|
+
if (typeof value === "string" || !Number.isFinite(value)) {
|
|
61
|
+
return { primary: String(value) };
|
|
62
|
+
}
|
|
63
|
+
const granularity = deriveGranularity(tickPositions);
|
|
64
|
+
const tickIndex = tickPositions.indexOf(value);
|
|
65
|
+
const isFirst = tickIndex === 0;
|
|
66
|
+
const previousValue = tickPositions[tickIndex - 1];
|
|
67
|
+
const valueDate = new Date(value);
|
|
68
|
+
const valueParts = getDatePartsInTimezone(valueDate, timezone);
|
|
69
|
+
const previousValueDate = previousValue ? new Date(previousValue) : void 0;
|
|
70
|
+
const previousValueParts = previousValueDate ? getDatePartsInTimezone(previousValueDate, timezone) : void 0;
|
|
71
|
+
let firstPartOptions = {};
|
|
72
|
+
let secondPartOptions = {};
|
|
73
|
+
switch (granularity) {
|
|
74
|
+
case "hour":
|
|
75
|
+
firstPartOptions = timeFormat === "24" ? { hour: "numeric", minute: "numeric", hour12: false } : { hour: "numeric" };
|
|
76
|
+
if (isFirst || valueParts.day !== previousValueParts?.day) {
|
|
77
|
+
secondPartOptions = { day: "numeric", month: "short" };
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
case "day":
|
|
81
|
+
case "week":
|
|
82
|
+
firstPartOptions = { day: "numeric" };
|
|
83
|
+
if (isFirst || valueParts.month !== previousValueParts?.month) {
|
|
84
|
+
secondPartOptions = { month: "short" };
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
case "month":
|
|
88
|
+
firstPartOptions = { month: "short" };
|
|
89
|
+
if (isFirst || valueParts.year !== previousValueParts?.year) {
|
|
90
|
+
secondPartOptions = { year: "numeric" };
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
case "year":
|
|
94
|
+
firstPartOptions = { year: "numeric" };
|
|
95
|
+
break;
|
|
96
|
+
default:
|
|
97
|
+
firstPartOptions = {};
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
const primary = new Intl.DateTimeFormat(textLocale, {
|
|
101
|
+
...firstPartOptions,
|
|
102
|
+
timeZone: timezone
|
|
103
|
+
}).format(valueDate);
|
|
104
|
+
if (Object.keys(secondPartOptions).length > 0) {
|
|
105
|
+
const secondary = new Intl.DateTimeFormat(textLocale, {
|
|
106
|
+
...secondPartOptions,
|
|
107
|
+
timeZone: timezone
|
|
108
|
+
}).format(valueDate);
|
|
109
|
+
return { primary, secondary };
|
|
110
|
+
}
|
|
111
|
+
return { primary };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/charts/shared/axisOptions.ts
|
|
115
|
+
function makeDatetimeAxisLabelFormatter(timezone, timeFormat) {
|
|
116
|
+
return function() {
|
|
117
|
+
const { primary, secondary } = datetimeFormatter({
|
|
118
|
+
value: this.value,
|
|
119
|
+
tickPositions: this.axis.tickPositions ?? [],
|
|
120
|
+
timezone,
|
|
121
|
+
timeFormat
|
|
122
|
+
});
|
|
123
|
+
return secondary ? `${primary}<br/><span class="hc-axis-label-secondary">${secondary}</span>` : primary;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function buildDimensionalAxis(axis, timezone) {
|
|
127
|
+
if (axis.type === "datetime") {
|
|
128
|
+
return {
|
|
129
|
+
type: "datetime",
|
|
130
|
+
crosshair: axis.crosshair,
|
|
131
|
+
labels: {
|
|
132
|
+
formatter: makeDatetimeAxisLabelFormatter(timezone, axis.timeFormat)
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
type: "category",
|
|
138
|
+
categories: [...axis.categories],
|
|
139
|
+
crosshair: axis.crosshair
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function resolveTooltipTimezone(axis, timezone) {
|
|
143
|
+
return axis.type === "datetime" ? timezone ?? "UTC" : void 0;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export {
|
|
147
|
+
buildDimensionalAxis,
|
|
148
|
+
resolveTooltipTimezone
|
|
149
|
+
};
|
|
150
|
+
//# sourceMappingURL=chunk-NAKJY5PA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/charts/shared/formatters/datetimeFormatter.ts","../../src/charts/shared/axisOptions.ts"],"sourcesContent":["/**\n * Pure, Highcharts-free datetime axis label formatter for v2 chart families.\n *\n * Ports v1's `helpers/xAxisLabelFormatter` into a rendering-agnostic shape: it\n * returns a `{ primary, secondary? }` object instead of an HTML string, leaving\n * SVG rendering to the caller. The timezone- and DST-correct boundary detection\n * (calendar parts read in the target timezone) and the per-granularity\n * `Intl.DateTimeFormat` option sets are a near-verbatim port of v1.\n *\n * The one net-new piece versus v1 is granularity derivation: v1 receives\n * `unitName` from Highcharts, but `charts/` may not depend on Highcharts types\n * (see `charts/README.md` invariants), so granularity is derived from the\n * spacing of `tickPositions`.\n */\n\n// Local types — defined here rather than imported from the Highcharts package\n// or v1's src/types.ts, to keep charts/ self-contained per the README invariant.\nexport type DatetimeTimeFormat = \"12\" | \"24\";\n\nexport type DatetimeLabel = Readonly<{\n primary: string;\n /** Omitted (undefined) when the tick is not on a unit boundary. */\n secondary?: string;\n}>;\n\ntype DatetimeGranularity = \"hour\" | \"day\" | \"week\" | \"month\" | \"year\";\n\ntype DatetimeFormatterInput = Readonly<{\n /** ms-epoch tick value, or a categorical string passed through verbatim. */\n value: number | string;\n /** Full tick array — used for boundary lookup and granularity derivation. */\n tickPositions: readonly number[];\n // optional\n /** IANA timezone. Defaults to \"UTC\". */\n timezone?: string;\n /** \"12\" | \"24\" hour clock for the hour granularity. Defaults to \"12\". */\n timeFormat?: DatetimeTimeFormat;\n /** Locale for Intl formatting. Defaults to \"en-US\". */\n textLocale?: Intl.LocalesArgument;\n}>;\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars -- kept alongside DAY_MS/WEEK_MS for upcoming duration formatting; stable numeric constant unlikely to drift\nconst HOUR_MS = 3_600_000;\nconst DAY_MS = 86_400_000;\nconst WEEK_MS = 604_800_000;\n// Granularity cutoffs use the *minimum* month/year length, not the average, so\n// calendar-aligned axes classify correctly: a real Highcharts month-unit axis\n// sits 28–31d apart and a year-unit axis 365–366d apart. Comparing the median\n// tick delta against the *average* month (30.44d) / year (365.25d) length\n// misclassified a 28-day February month gap as \"week\" and a 365-day non-leap\n// year as \"month\". Bias to the minimum so the shortest real span still reads as\n// \"month\" / \"year\".\nconst MIN_MONTH_MS = 2_419_200_000; // 28 days (shortest month, non-leap Feb)\nconst MIN_YEAR_MS = 31_536_000_000; // 365 days (shortest, non-leap year)\n\n/**\n * Reads the calendar day/month/year of a date *in the target timezone* via\n * `Intl.DateTimeFormat(...).formatToParts`. This is what makes boundary\n * detection timezone- and DST-correct (a 25-hour \"fall back\" day still rolls\n * the day over on the correct local-midnight tick). Ported verbatim from v1.\n */\nconst getDatePartsInTimezone = (date: Date, timezone: string) => {\n const formatter = new Intl.DateTimeFormat(\"en-US\", {\n year: \"numeric\",\n month: \"numeric\",\n day: \"numeric\",\n timeZone: timezone,\n });\n const parts = formatter.formatToParts(date);\n return {\n day: parseInt(parts.find((p) => p.type === \"day\")?.value ?? \"0\", 10),\n month: parseInt(parts.find((p) => p.type === \"month\")?.value ?? \"0\", 10),\n year: parseInt(parts.find((p) => p.type === \"year\")?.value ?? \"0\", 10),\n };\n};\n\n/**\n * Derives the axis granularity from the median delta between consecutive\n * `tickPositions`. Median (not mean) so an irregular first/last gap does not\n * skew the result. With fewer than two ticks there is no spacing to measure, so\n * we default to \"day\".\n *\n * Note: \"day\" and \"week\" produce identical output (same primary/secondary\n * option sets), so the day/week threshold is cosmetic and never changes a label.\n * The week↔month and month↔year cutoffs do change output, so they compare\n * against the *minimum* month/year length (not the average); see MIN_MONTH_MS /\n * MIN_YEAR_MS for why calendar-aligned axes would otherwise be misclassified.\n */\nconst deriveGranularity = (\n tickPositions: readonly number[]\n): DatetimeGranularity => {\n if (tickPositions.length < 2) {\n return \"day\";\n }\n\n const deltas: number[] = [];\n for (let i = 1; i < tickPositions.length; i++) {\n const curr = tickPositions[i];\n const prev = tickPositions[i - 1];\n // Both reads are in range by the loop bounds (1 <= i < length); the guard\n // only satisfies noUncheckedIndexedAccess and is unreachable at runtime.\n if (curr === undefined || prev === undefined) {\n continue;\n }\n deltas.push(Math.abs(curr - prev));\n }\n deltas.sort((a, b) => a - b);\n\n const mid = Math.floor(deltas.length / 2);\n // `length >= 2` is guaranteed by the early return above, so `deltas` has at\n // least one element and `deltas[mid]` is always defined; `deltas[mid - 1]` is\n // only read on the even-length branch, where it is guaranteed in range too.\n const upper = deltas[mid]!;\n const lower = deltas[mid - 1];\n const median =\n deltas.length % 2 === 0 && lower !== undefined\n ? (lower + upper) / 2\n : upper;\n\n if (median < DAY_MS) {\n return \"hour\";\n }\n if (median < WEEK_MS) {\n return \"day\";\n }\n if (median < MIN_MONTH_MS) {\n return \"week\";\n }\n if (median < MIN_YEAR_MS) {\n return \"month\";\n }\n return \"year\";\n};\n\n/**\n * Derives a datetime tick's two-line stacked label as a rendering-agnostic\n * `{ primary, secondary? }` object. `secondary` is emitted only on a unit\n * boundary (the first tick, or when the relevant calendar part changes versus\n * the previous tick), matching v1's two-line semantics.\n *\n * Categorical (string) values and non-finite numbers are passed through as\n * `{ primary: String(value) }` with no secondary, so callers always get a\n * stable, markup-free string rather than \"Invalid Date\".\n */\nexport function datetimeFormatter({\n value,\n tickPositions = [],\n // optional\n timezone = \"UTC\",\n timeFormat = \"12\",\n textLocale = \"en-US\",\n}: DatetimeFormatterInput): DatetimeLabel {\n // Categorical (string) data, and non-finite timestamps, pass through.\n if (typeof value === \"string\" || !Number.isFinite(value)) {\n return { primary: String(value) };\n }\n\n const granularity = deriveGranularity(tickPositions);\n\n const tickIndex = tickPositions.indexOf(value);\n const isFirst = tickIndex === 0;\n const previousValue = tickPositions[tickIndex - 1];\n\n const valueDate = new Date(value);\n const valueParts = getDatePartsInTimezone(valueDate, timezone);\n const previousValueDate = previousValue ? new Date(previousValue) : undefined;\n const previousValueParts = previousValueDate\n ? getDatePartsInTimezone(previousValueDate, timezone)\n : undefined;\n\n let firstPartOptions: Intl.DateTimeFormatOptions = {};\n let secondPartOptions: Intl.DateTimeFormatOptions = {};\n\n switch (granularity) {\n case \"hour\":\n firstPartOptions =\n timeFormat === \"24\"\n ? { hour: \"numeric\", minute: \"numeric\", hour12: false }\n : { hour: \"numeric\" };\n if (isFirst || valueParts.day !== previousValueParts?.day) {\n secondPartOptions = { day: \"numeric\", month: \"short\" };\n }\n break;\n case \"day\":\n case \"week\":\n firstPartOptions = { day: \"numeric\" };\n if (isFirst || valueParts.month !== previousValueParts?.month) {\n secondPartOptions = { month: \"short\" };\n }\n break;\n case \"month\":\n firstPartOptions = { month: \"short\" };\n if (isFirst || valueParts.year !== previousValueParts?.year) {\n secondPartOptions = { year: \"numeric\" };\n }\n break;\n case \"year\":\n firstPartOptions = { year: \"numeric\" };\n break;\n default:\n firstPartOptions = {};\n break;\n }\n\n const primary = new Intl.DateTimeFormat(textLocale, {\n ...firstPartOptions,\n timeZone: timezone,\n }).format(valueDate);\n\n if (Object.keys(secondPartOptions).length > 0) {\n const secondary = new Intl.DateTimeFormat(textLocale, {\n ...secondPartOptions,\n timeZone: timezone,\n }).format(valueDate);\n return { primary, secondary };\n }\n\n return { primary };\n}\n","// Shared adapter helpers for the X/Y chart families (bar, line-area, …). Each\n// family's adapter still owns its `chart.type`, `plotOptions`, `series`, and\n// value (y) axis; these utilities cover the dimensional-axis + timezone wiring\n// that is identical across families, so it lives in one place.\n//\n// Deliberately granular (one concern per function) rather than a single base-\n// options builder, so a non-X/Y family like donut can reuse the subset that\n// applies to it. The broader shared-shell + value-axis sharing is left to the\n// X/Y pattern-sharing spike — the value axis in particular diverges per family\n// today (e.g. bar's declarative `format` from CE-41), so it stays per-family.\n\nimport type { DimensionalAxis } from \"./axis\";\nimport type {\n SeedsAxisLabelFormatterContext,\n SeedsChartXAxisOptions,\n} from \"./chartBase\";\nimport { datetimeFormatter } from \"./formatters/datetimeFormatter\";\nimport type { DatetimeTimeFormat } from \"./formatters/datetimeFormatter\";\n\n// Datetime tick labels: a granularity-aware, timezone/DST-correct two-line\n// stacked label via the shared `datetimeFormatter`, rendered as SVG. `<br/>` is a\n// line break in Highcharts' SVG text (styledMode, useHTML: false); the secondary\n// token is wrapped in a <span> — rendered as a <tspan> — styled by the\n// `.highcharts-xaxis-labels` rule in `styles/chartStyles.ts`.\nfunction makeDatetimeAxisLabelFormatter(\n timezone: string,\n timeFormat: DatetimeTimeFormat | undefined\n) {\n return function (this: SeedsAxisLabelFormatterContext): string {\n const { primary, secondary } = datetimeFormatter({\n value: this.value,\n tickPositions: this.axis.tickPositions ?? [],\n timezone,\n timeFormat,\n });\n return secondary\n ? `${primary}<br/><span class=\"hc-axis-label-secondary\">${secondary}</span>`\n : primary;\n };\n}\n\n/**\n * Builds the dimensional (x) axis options shared by the X/Y chart families.\n * Category axes pass their labels through; datetime axes get the granularity-\n * aware two-line label formatter. `timezone` is only consulted for datetime.\n */\nexport function buildDimensionalAxis(\n axis: DimensionalAxis,\n timezone: string\n): SeedsChartXAxisOptions {\n if (axis.type === \"datetime\") {\n return {\n type: \"datetime\",\n crosshair: axis.crosshair,\n labels: {\n formatter: makeDatetimeAxisLabelFormatter(timezone, axis.timeFormat),\n },\n };\n }\n return {\n type: \"category\",\n categories: [...axis.categories],\n crosshair: axis.crosshair,\n };\n}\n\n/**\n * The timezone shared by datetime-axis ticks (`time.timezone`) and the tooltip\n * date formatter, so they can never disagree about the day. Defaults to `\"UTC\"`\n * on a datetime axis; `undefined` on a category axis (timezone is meaningless).\n */\nexport function resolveTooltipTimezone(\n axis: DimensionalAxis,\n timezone?: string\n): string | undefined {\n return axis.type === \"datetime\" ? timezone ?? \"UTC\" : undefined;\n}\n"],"mappings":";AA2CA,IAAM,SAAS;AACf,IAAM,UAAU;AAQhB,IAAM,eAAe;AACrB,IAAM,cAAc;AAQpB,IAAM,yBAAyB,CAAC,MAAY,aAAqB;AAC/D,QAAM,YAAY,IAAI,KAAK,eAAe,SAAS;AAAA,IACjD,MAAM;AAAA,IACN,OAAO;AAAA,IACP,KAAK;AAAA,IACL,UAAU;AAAA,EACZ,CAAC;AACD,QAAM,QAAQ,UAAU,cAAc,IAAI;AAC1C,SAAO;AAAA,IACL,KAAK,SAAS,MAAM,KAAK,CAAC,MAAM,EAAE,SAAS,KAAK,GAAG,SAAS,KAAK,EAAE;AAAA,IACnE,OAAO,SAAS,MAAM,KAAK,CAAC,MAAM,EAAE,SAAS,OAAO,GAAG,SAA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O,EAAE,SAAS,UAAU;AAAA,EAC9B;AAEA,SAAO,EAAE,QAAQ;AACnB;;;AClMA,SAAS,+BACP,UACA,YACA;AACA,SAAO,WAAwD;AAC7D,UAAM,EAAE,SAAS,UAAU,IAAI,kBAAkB;AAAA,MAC/C,OAAO,KAAK;AAAA,MACZ,eAAe,KAAK,KAAK,iBAAiB,CAAC;AAAA,MAC3C;AAAA,MACA;AAAA,IACF,CAAC;AACD,WAAO,YACH,GAAG,OAAO,8CAA8C,SAAS,YACjE;AAAA,EACN;AACF;AAOO,SAAS,qBACd,MACA,UACwB;AACxB,MAAI,KAAK,SAAS,YAAY;AAC5B,WAAO;AAAA,MACL,MAAM;AAAA,MACN,WAAW,KAAK;AAAA,MAChB,QAAQ;AAAA,QACN,WAAW,+BAA+B,UAAU,KAAK,UAAU;AAAA,MACrE;AAAA,IACF;AAAA,EACF;AACA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY,CAAC,GAAG,KAAK,UAAU;AAAA,IAC/B,WAAW,KAAK;AAAA,EAClB;AACF;AAOO,SAAS,uBACd,MACA,UACoB;AACpB,SAAO,KAAK,SAAS,aAAa,YAAY,QAAQ;AACxD;","names":[]}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// src/constants/chartOptions.ts
|
|
2
|
+
import _ from "lodash";
|
|
3
|
+
var baseChartOptions = {
|
|
4
|
+
chart: {
|
|
5
|
+
animation: false,
|
|
6
|
+
styledMode: true
|
|
7
|
+
},
|
|
8
|
+
credits: {
|
|
9
|
+
enabled: false
|
|
10
|
+
},
|
|
11
|
+
exporting: {
|
|
12
|
+
enabled: false,
|
|
13
|
+
fallbackToExportServer: false
|
|
14
|
+
},
|
|
15
|
+
legend: {
|
|
16
|
+
enabled: false
|
|
17
|
+
},
|
|
18
|
+
title: {
|
|
19
|
+
text: void 0
|
|
20
|
+
},
|
|
21
|
+
tooltip: {
|
|
22
|
+
hideDelay: 0,
|
|
23
|
+
outside: true,
|
|
24
|
+
padding: 0,
|
|
25
|
+
shape: "rect",
|
|
26
|
+
shared: true,
|
|
27
|
+
useHTML: true
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var TIME_SERIES_CHART_HEIGHT = 275;
|
|
31
|
+
var timeSeriesChartOptions = _.merge({}, baseChartOptions, {
|
|
32
|
+
annotations: [
|
|
33
|
+
{
|
|
34
|
+
draggable: "",
|
|
35
|
+
labelOptions: {
|
|
36
|
+
useHTML: true,
|
|
37
|
+
padding: 0
|
|
38
|
+
// removes "left" property padding created by highcharts so that label is centered
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
chart: {
|
|
43
|
+
// events.click is set at the component level because of the optional onClick prop
|
|
44
|
+
height: TIME_SERIES_CHART_HEIGHT,
|
|
45
|
+
spacing: [5, 1, 0, 2]
|
|
46
|
+
},
|
|
47
|
+
plotOptions: {
|
|
48
|
+
series: {
|
|
49
|
+
animation: false,
|
|
50
|
+
clip: false,
|
|
51
|
+
marker: {
|
|
52
|
+
enabled: false,
|
|
53
|
+
states: {
|
|
54
|
+
hover: {
|
|
55
|
+
enabled: false
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
xAxis: {
|
|
62
|
+
crosshair: {
|
|
63
|
+
zIndex: 3
|
|
64
|
+
},
|
|
65
|
+
minPadding: 0,
|
|
66
|
+
// must be handled dynamically instead of css
|
|
67
|
+
maxPadding: 0,
|
|
68
|
+
// must be handled dynamically instead of css
|
|
69
|
+
type: "datetime",
|
|
70
|
+
labels: {
|
|
71
|
+
useHTML: true
|
|
72
|
+
// formatter is set at the component level because of the required text locale prop
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
yAxis: {
|
|
76
|
+
labels: {
|
|
77
|
+
useHTML: true
|
|
78
|
+
// formatter is set at the component level because of the optional yAxisLabelFormatter prop
|
|
79
|
+
},
|
|
80
|
+
softMax: 0,
|
|
81
|
+
softMin: 0,
|
|
82
|
+
title: {
|
|
83
|
+
text: void 0
|
|
84
|
+
},
|
|
85
|
+
plotLines: [
|
|
86
|
+
/* Adds a custom plotLine at y=0 to represent the chart baseline.
|
|
87
|
+
This approach allows full control over the line's appearance (e.g., color, z-index),
|
|
88
|
+
unlike relying on the default xAxis line, which always renders at the bottom of the chart
|
|
89
|
+
even when y=0 appears elsewhere (e.g., with negative values).
|
|
90
|
+
*/
|
|
91
|
+
{
|
|
92
|
+
className: "y-axis-zero-line",
|
|
93
|
+
value: 0,
|
|
94
|
+
zIndex: 3
|
|
95
|
+
// ensures the line appears over the default y=0 line, which we can't seleect as specifically
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
var lineChartOptions = _.merge({}, timeSeriesChartOptions, {
|
|
101
|
+
// plotOptions.spline.events.click is set at the component level because of the optional onClick prop
|
|
102
|
+
});
|
|
103
|
+
var areaChartOptions = _.merge({}, timeSeriesChartOptions, {
|
|
104
|
+
plotOptions: {
|
|
105
|
+
areaspline: {
|
|
106
|
+
// events.click is set at the component level because of the optional onClick prop
|
|
107
|
+
stacking: "normal"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
var columnChartOptions = _.merge({}, timeSeriesChartOptions, {
|
|
112
|
+
plotOptions: {
|
|
113
|
+
column: {
|
|
114
|
+
stacking: "normal",
|
|
115
|
+
pointPadding: 0.25,
|
|
116
|
+
groupPadding: 0.25,
|
|
117
|
+
borderRadius: 4
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
xAxis: {
|
|
121
|
+
crosshair: false
|
|
122
|
+
},
|
|
123
|
+
yAxis: {
|
|
124
|
+
plotLines: [
|
|
125
|
+
{
|
|
126
|
+
// For stacked column charts with visible borders (e.g., white for contrast),
|
|
127
|
+
// we raise the zIndex of the y=0 plotLine to ensure it remains visible
|
|
128
|
+
// and isn't visually covered by overlapping column borders.
|
|
129
|
+
zIndex: 5
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
var VERTICAL_BAR_CHART_DEFAULT_SERIES_LIMIT = 10;
|
|
135
|
+
var DONUT_CHART_HALO_SIZE = 10;
|
|
136
|
+
var DONUT_CHART_HEIGHT = 250 + DONUT_CHART_HALO_SIZE * 2;
|
|
137
|
+
var DONUT_CHART_WIDTH = DONUT_CHART_HEIGHT;
|
|
138
|
+
var donutChartOptions = _.merge({}, baseChartOptions, {
|
|
139
|
+
chart: {
|
|
140
|
+
height: DONUT_CHART_HEIGHT,
|
|
141
|
+
spacing: [0, 0, 0, 0]
|
|
142
|
+
},
|
|
143
|
+
plotOptions: {
|
|
144
|
+
pie: {
|
|
145
|
+
animation: false,
|
|
146
|
+
borderRadius: 0,
|
|
147
|
+
// must be handled here instead of css because of path rendering
|
|
148
|
+
dataLabels: {
|
|
149
|
+
enabled: false
|
|
150
|
+
},
|
|
151
|
+
innerSize: "50%"
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
export {
|
|
157
|
+
baseChartOptions,
|
|
158
|
+
TIME_SERIES_CHART_HEIGHT,
|
|
159
|
+
timeSeriesChartOptions,
|
|
160
|
+
lineChartOptions,
|
|
161
|
+
areaChartOptions,
|
|
162
|
+
columnChartOptions,
|
|
163
|
+
VERTICAL_BAR_CHART_DEFAULT_SERIES_LIMIT,
|
|
164
|
+
DONUT_CHART_HALO_SIZE,
|
|
165
|
+
DONUT_CHART_HEIGHT,
|
|
166
|
+
DONUT_CHART_WIDTH,
|
|
167
|
+
donutChartOptions
|
|
168
|
+
};
|
|
169
|
+
//# sourceMappingURL=chunk-XMYGML25.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/constants/chartOptions.ts"],"sourcesContent":["import type { Options } from \"highcharts\";\nimport _ from \"lodash\";\n\n// options that should apply to all charts\n// this is being exported because it's needed for the listening bubble chart component.\n// when that components gets moved into the data-viz package, we can remove the export here\nexport const baseChartOptions: Options = {\n chart: {\n animation: false,\n styledMode: true,\n },\n credits: {\n enabled: false,\n },\n exporting: {\n enabled: false,\n fallbackToExportServer: false,\n },\n legend: {\n enabled: false,\n },\n title: {\n text: undefined,\n },\n tooltip: {\n hideDelay: 0,\n outside: true,\n padding: 0,\n shape: \"rect\",\n shared: true,\n useHTML: true,\n },\n};\n\n// options that should apply to time series charts\nexport const TIME_SERIES_CHART_HEIGHT = 275;\nexport const timeSeriesChartOptions: Options = _.merge({}, baseChartOptions, {\n annotations: [\n {\n draggable: \"\",\n labelOptions: {\n useHTML: true,\n padding: 0, // removes \"left\" property padding created by highcharts so that label is centered\n },\n },\n ],\n chart: {\n // events.click is set at the component level because of the optional onClick prop\n height: TIME_SERIES_CHART_HEIGHT,\n spacing: [5, 1, 0, 2],\n },\n plotOptions: {\n series: {\n animation: false,\n clip: false,\n marker: {\n enabled: false,\n states: {\n hover: {\n enabled: false,\n },\n },\n },\n },\n },\n xAxis: {\n crosshair: {\n zIndex: 3,\n },\n minPadding: 0, // must be handled dynamically instead of css\n maxPadding: 0, // must be handled dynamically instead of css\n type: \"datetime\",\n labels: {\n useHTML: true,\n // formatter is set at the component level because of the required text locale prop\n },\n },\n yAxis: {\n labels: {\n useHTML: true,\n // formatter is set at the component level because of the optional yAxisLabelFormatter prop\n },\n softMax: 0,\n softMin: 0,\n title: {\n text: undefined,\n },\n plotLines: [\n /* Adds a custom plotLine at y=0 to represent the chart baseline.\n This approach allows full control over the line's appearance (e.g., color, z-index),\n unlike relying on the default xAxis line, which always renders at the bottom of the chart\n even when y=0 appears elsewhere (e.g., with negative values).\n */\n {\n className: \"y-axis-zero-line\",\n value: 0,\n zIndex: 3, // ensures the line appears over the default y=0 line, which we can't seleect as specifically\n },\n ],\n },\n});\n\n// options that should apply to LineChart\nexport const lineChartOptions: Options = _.merge({}, timeSeriesChartOptions, {\n // plotOptions.spline.events.click is set at the component level because of the optional onClick prop\n});\n\n// options that should apply to AreaChart\nexport const areaChartOptions: Options = _.merge({}, timeSeriesChartOptions, {\n plotOptions: {\n areaspline: {\n // events.click is set at the component level because of the optional onClick prop\n stacking: \"normal\",\n },\n },\n});\n\nexport const columnChartOptions: Options = _.merge({}, timeSeriesChartOptions, {\n plotOptions: {\n column: {\n stacking: \"normal\",\n pointPadding: 0.25,\n groupPadding: 0.25,\n borderRadius: 4,\n },\n },\n xAxis: {\n crosshair: false,\n },\n yAxis: {\n plotLines: [\n {\n // For stacked column charts with visible borders (e.g., white for contrast),\n // we raise the zIndex of the y=0 plotLine to ensure it remains visible\n // and isn't visually covered by overlapping column borders.\n zIndex: 5,\n },\n ],\n },\n});\n\n/**\n * The default series limit for VerticalBarChart.\n * This limit is recommended to maintain chart readability and accessibility.\n * @see {VerticalBarChart}\n */\nexport const VERTICAL_BAR_CHART_DEFAULT_SERIES_LIMIT = 10;\n\n// options that should apply to DonutChart\nexport const DONUT_CHART_HALO_SIZE = 10; // 10 is the default from highcharts\nexport const DONUT_CHART_HEIGHT = 250 + DONUT_CHART_HALO_SIZE * 2;\nexport const DONUT_CHART_WIDTH = DONUT_CHART_HEIGHT;\nexport const donutChartOptions: Options = _.merge({}, baseChartOptions, {\n chart: {\n height: DONUT_CHART_HEIGHT,\n spacing: [0, 0, 0, 0],\n },\n plotOptions: {\n pie: {\n animation: false,\n borderRadius: 0, // must be handled here instead of css because of path rendering\n dataLabels: {\n enabled: false,\n },\n innerSize: \"50%\",\n },\n },\n});\n"],"mappings":";AACA,OAAO,OAAO;AAKP,IAAM,mBAA4B;AAAA,EACvC,OAAO;AAAA,IACL,WAAW;AAAA,IACX,YAAY;AAAA,EACd;AAAA,EACA,SAAS;AAAA,IACP,SAAS;AAAA,EACX;AAAA,EACA,WAAW;AAAA,IACT,SAAS;AAAA,IACT,wBAAwB;AAAA,EAC1B;AAAA,EACA,QAAQ;AAAA,IACN,SAAS;AAAA,EACX;AAAA,EACA,OAAO;AAAA,IACL,MAAM;AAAA,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AAGM,IAAM,mBAA4B,EAAE,MAAM,CAAC,GAAG,wBAAwB;AAAA,EAC3E,aAAa;AAAA,IACX,YAAY;AAAA;AAAA,MAEV,UAAU;AAAA,IACZ;AAAA,EACF;AACF,CAAC;AAEM,IAAM,qBAA8B,EAAE,MAAM,CAAC,GAAG,wBAAwB;AAAA,EAC7E,aAAa;AAAA,IACX,QAAQ;AAAA,MACN,UAAU;AAAA,MACV,cAAc;AAAA,MACd,cAAc;AAAA,MACd,cAAc;AAAA,IAChB;AAAA,EACF;AAAA,EACA,OAAO;AAAA,IACL,WAAW;AAAA,EACb;AAAA,EACA,OAAO;AAAA,IACL,WAAW;AAAA,MACT;AAAA;AAAA;AAAA;AAAA,QAIE,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAOM,IAAM,0CAA0C;AAGhD,IAAM,wBAAwB;AAC9B,IAAM,qBAAqB,MAAM,wBAAwB;AACzD,IAAM,oBAAoB;AAC1B,IAAM,oBAA6B,EAAE,MAAM,CAAC,GAAG,kBAAkB;AAAA,EACtE,OAAO;AAAA,IACL,QAAQ;AAAA,IACR,SAAS,CAAC,GAAG,GAAG,GAAG,CAAC;AAAA,EACtB;AAAA,EACA,aAAa;AAAA,IACX,KAAK;AAAA,MACH,WAAW;AAAA,MACX,cAAc;AAAA;AAAA,MACd,YAAY;AAAA,QACV,SAAS;AAAA,MACX;AAAA,MACA,WAAW;AAAA,IACb;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DONUT_CHART_HEIGHT
|
|
3
|
+
} from "../chunk-XMYGML25.js";
|
|
4
|
+
import {
|
|
5
|
+
ChartRenderer,
|
|
6
|
+
buildBaseChartOptions,
|
|
7
|
+
useSeedsChartSetup
|
|
8
|
+
} from "../chunk-LPQXJJNT.js";
|
|
9
|
+
import {
|
|
10
|
+
donutChartStyles
|
|
11
|
+
} from "../chunk-Z4LOM4OZ.js";
|
|
12
|
+
|
|
13
|
+
// src/charts/donut/DonutChart.tsx
|
|
14
|
+
import { memo, useMemo } from "react";
|
|
15
|
+
|
|
16
|
+
// src/charts/donut/adapter.ts
|
|
17
|
+
function buildDonutOptions(props, colors) {
|
|
18
|
+
const base = buildBaseChartOptions({
|
|
19
|
+
type: "pie",
|
|
20
|
+
description: props.description
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
...base,
|
|
24
|
+
chart: {
|
|
25
|
+
type: "pie",
|
|
26
|
+
styledMode: true,
|
|
27
|
+
animation: false,
|
|
28
|
+
// Height only — width is left fluid (v1 parity) so the chart fills its
|
|
29
|
+
// container and the pie auto-centers. The container bounds the width (see
|
|
30
|
+
// styles.ts) so the legend below wraps to the donut and centers with it.
|
|
31
|
+
height: DONUT_CHART_HEIGHT,
|
|
32
|
+
// Drop Highcharts' default spacing so the donut uses the full height.
|
|
33
|
+
spacing: [0, 0, 0, 0]
|
|
34
|
+
},
|
|
35
|
+
plotOptions: {
|
|
36
|
+
pie: {
|
|
37
|
+
animation: false,
|
|
38
|
+
// borderRadius must be set in JS, not CSS, because Highcharts computes
|
|
39
|
+
// the arc path before applying it — CSS border-radius has no effect.
|
|
40
|
+
borderRadius: 0,
|
|
41
|
+
dataLabels: { enabled: false },
|
|
42
|
+
innerSize: "50%",
|
|
43
|
+
...props.onClick ? {
|
|
44
|
+
point: {
|
|
45
|
+
events: {
|
|
46
|
+
click() {
|
|
47
|
+
props.onClick?.({ position: this.name });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} : {}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
series: [
|
|
55
|
+
{
|
|
56
|
+
type: "pie",
|
|
57
|
+
name: "Data",
|
|
58
|
+
data: props.data.map((d, i) => ({
|
|
59
|
+
name: d.name,
|
|
60
|
+
y: d.value,
|
|
61
|
+
color: d.color ?? colors[i] ?? ""
|
|
62
|
+
}))
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/charts/donut/styles.ts
|
|
69
|
+
import styled from "styled-components";
|
|
70
|
+
var DonutChartContainer = styled.div`
|
|
71
|
+
background-color: ${({ theme }) => theme.colors.container.background.base};
|
|
72
|
+
${donutChartStyles}
|
|
73
|
+
|
|
74
|
+
/* Dim non-hovered slices. Highcharts adds .highcharts-point-inactive to
|
|
75
|
+
all pie points except the hovered one. In styledMode, opacity is CSS-only
|
|
76
|
+
(JS plotOptions.states.inactive.opacity is ignored). */
|
|
77
|
+
.highcharts-pie-series .highcharts-point-inactive {
|
|
78
|
+
opacity: 0.3;
|
|
79
|
+
transition: opacity 0s;
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
|
|
83
|
+
// src/charts/donut/DonutChart.tsx
|
|
84
|
+
import { jsx } from "react/jsx-runtime";
|
|
85
|
+
var DonutChart = memo(function DonutChart2(props) {
|
|
86
|
+
const { colors } = useSeedsChartSetup({
|
|
87
|
+
series: props.data.map((d) => ({ color: d.color }))
|
|
88
|
+
});
|
|
89
|
+
const options = useMemo(
|
|
90
|
+
() => buildDonutOptions(props, colors),
|
|
91
|
+
[props, colors]
|
|
92
|
+
);
|
|
93
|
+
const hasOnClick = Boolean(props.onClick);
|
|
94
|
+
const tooltip = props.tooltip ? (args) => props.tooltip(args) : void 0;
|
|
95
|
+
return /* @__PURE__ */ jsx(
|
|
96
|
+
DonutChartContainer,
|
|
97
|
+
{
|
|
98
|
+
$colors: colors,
|
|
99
|
+
$hasOnClick: hasOnClick,
|
|
100
|
+
className: props.className,
|
|
101
|
+
children: /* @__PURE__ */ jsx(
|
|
102
|
+
ChartRenderer,
|
|
103
|
+
{
|
|
104
|
+
options,
|
|
105
|
+
series: props.data.map((d, i) => ({
|
|
106
|
+
name: d.name,
|
|
107
|
+
color: colors[i],
|
|
108
|
+
icon: d.icon
|
|
109
|
+
})),
|
|
110
|
+
colors,
|
|
111
|
+
tooltip,
|
|
112
|
+
hasOnClick,
|
|
113
|
+
tooltipClickLabel: props.tooltipClickLabel,
|
|
114
|
+
invalidNumberLabel: props.invalidNumberLabel,
|
|
115
|
+
valueFormat: props.format,
|
|
116
|
+
onReady: props.onReady
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
export {
|
|
123
|
+
DonutChart
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/charts/donut/DonutChart.tsx","../../../src/charts/donut/adapter.ts","../../../src/charts/donut/styles.ts"],"sourcesContent":["import { memo, useMemo } from \"react\";\nimport {\n useSeedsChartSetup,\n ChartRenderer,\n type ChartTooltipProps,\n} from \"../shared/chartBase\";\nimport { buildDonutOptions } from \"./adapter\";\nimport { DonutChartContainer } from \"./styles\";\nimport type { DonutChartProps, DonutChartTooltipProps } from \"./types\";\n\nexport const DonutChart = memo(function DonutChart(props: DonutChartProps) {\n // Map each data item to { color? } so useSeedsChartSetup resolves the palette.\n const { colors } = useSeedsChartSetup({\n series: props.data.map((d) => ({ color: d.color })),\n });\n\n // Memoize to avoid spurious Highcharts redraws on parent re-renders.\n const options = useMemo(\n () => buildDonutOptions(props, colors),\n [props, colors]\n );\n const hasOnClick = Boolean(props.onClick);\n\n // `ChartRenderer` expects `(ChartTooltipProps) => ReactNode`. The consumer's\n // function expects the narrower `DonutChartTooltipProps` (required `percent`).\n // Wrap rather than cast the function type so the intent is explicit.\n const tooltip = props.tooltip\n ? (args: ChartTooltipProps) =>\n props.tooltip!(args as unknown as DonutChartTooltipProps)\n : undefined;\n\n return (\n <DonutChartContainer\n $colors={colors}\n $hasOnClick={hasOnClick}\n className={props.className}\n >\n <ChartRenderer\n options={options}\n series={props.data.map((d, i) => ({\n name: d.name,\n color: colors[i],\n icon: d.icon,\n }))}\n colors={colors}\n tooltip={tooltip}\n hasOnClick={hasOnClick}\n tooltipClickLabel={props.tooltipClickLabel}\n invalidNumberLabel={props.invalidNumberLabel}\n valueFormat={props.format}\n onReady={props.onReady}\n />\n </DonutChartContainer>\n );\n});\n","import type { SeedsChartOptions } from \"../shared/chartBase\";\nimport { buildBaseChartOptions } from \"../shared/baseChartOptions\";\nimport { DONUT_CHART_HEIGHT } from \"../../constants/chartOptions\";\nimport type { DonutChartProps } from \"./types\";\n\nexport function buildDonutOptions(\n props: DonutChartProps,\n colors: ReadonlyArray<string>\n): SeedsChartOptions {\n const base = buildBaseChartOptions({\n type: \"pie\",\n description: props.description,\n });\n return {\n ...base,\n chart: {\n type: \"pie\" as const,\n styledMode: true,\n animation: false,\n // Height only — width is left fluid (v1 parity) so the chart fills its\n // container and the pie auto-centers. The container bounds the width (see\n // styles.ts) so the legend below wraps to the donut and centers with it.\n height: DONUT_CHART_HEIGHT,\n // Drop Highcharts' default spacing so the donut uses the full height.\n spacing: [0, 0, 0, 0],\n },\n plotOptions: {\n pie: {\n animation: false,\n // borderRadius must be set in JS, not CSS, because Highcharts computes\n // the arc path before applying it — CSS border-radius has no effect.\n borderRadius: 0,\n dataLabels: { enabled: false },\n innerSize: \"50%\",\n ...(props.onClick\n ? {\n point: {\n events: {\n click(this: { name: string }) {\n props.onClick?.({ position: this.name });\n },\n },\n },\n }\n : {}),\n },\n },\n series: [\n {\n type: \"pie\",\n name: \"Data\",\n data: props.data.map((d, i) => ({\n name: d.name,\n y: d.value,\n color: d.color ?? colors[i] ?? \"\",\n })),\n },\n ],\n };\n}\n","import styled from \"styled-components\";\nimport { donutChartStyles } from \"../../styles/chartStyles\";\nimport type {\n TypeChartStyleColor,\n TypeChartStyleHasOnClick,\n} from \"../../types\";\n\ntype StyleProps = Readonly<{\n $colors: ReadonlyArray<TypeChartStyleColor>;\n $hasOnClick: TypeChartStyleHasOnClick;\n}>;\n\n// Plain styled `div` — not `Box`. Per the DS Tailwind direction (established in\n// CE-28/line-area), new components render semantic elements internally.\n//\n// No width constraint (v1 parity): the chart fills the container and the pie\n// auto-centers, while the legend centers in the same width — so the legend\n// stays on one row and centers with the donut instead of wrapping to match it.\nexport const DonutChartContainer = styled.div<StyleProps>`\n background-color: ${({ theme }) => theme.colors.container.background.base};\n ${donutChartStyles}\n\n /* Dim non-hovered slices. Highcharts adds .highcharts-point-inactive to\n all pie points except the hovered one. In styledMode, opacity is CSS-only\n (JS plotOptions.states.inactive.opacity is ignored). */\n .highcharts-pie-series .highcharts-point-inactive {\n opacity: 0.3;\n transition: opacity 0s;\n }\n`;\n"],"mappings":";;;;;;;;;;;;;AAAA,SAAS,MAAM,eAAe;;;ACKvB,SAAS,kBACd,OACA,QACmB;AACnB,QAAM,OAAO,sBAAsB;AAAA,IACjC,MAAM;AAAA,IACN,aAAa,MAAM;AAAA,EACrB,CAAC;AACD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO;AAAA,MACL,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,WAAW;AAAA;AAAA;AAAA;AAAA,MAIX,QAAQ;AAAA;AAAA,MAER,SAAS,CAAC,GAAG,GAAG,GAAG,CAAC;AAAA,IACtB;AAAA,IACA,aAAa;AAAA,MACX,KAAK;AAAA,QACH,WAAW;AAAA;AAAA;AAAA,QAGX,cAAc;AAAA,QACd,YAAY,EAAE,SAAS,MAAM;AAAA,QAC7B,WAAW;AAAA,QACX,GAAI,MAAM,UACN;AAAA,UACE,OAAO;AAAA,YACL,QAAQ;AAAA,cACN,QAA8B;AAC5B,sBAAM,UAAU,EAAE,UAAU,KAAK,KAAK,CAAC;AAAA,cACzC;AAAA,YACF;AAAA,UACF;AAAA,QACF,IACA,CAAC;AAAA,MACP;AAAA,IACF;AAAA,IACA,QAAQ;AAAA,MACN;AAAA,QACE,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM,MAAM,KAAK,IAAI,CAAC,GAAG,OAAO;AAAA,UAC9B,MAAM,EAAE;AAAA,UACR,GAAG,EAAE;AAAA,UACL,OAAO,EAAE,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