@sproutsocial/seeds-react-data-viz 0.16.1 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/annotations-CjFoRPXf.d.mts +20 -0
  2. package/dist/annotations-CjFoRPXf.d.ts +20 -0
  3. package/dist/axis-WOeYkTO1.d.mts +44 -0
  4. package/dist/axis-WOeYkTO1.d.ts +44 -0
  5. package/dist/bar/index.d.mts +3 -1
  6. package/dist/bar/index.d.ts +3 -1
  7. package/dist/bar/index.js +15 -8
  8. package/dist/bar/index.js.map +1 -1
  9. package/dist/{axis-BVPkC6iF.d.ts → chartBase-C-l7yYGx.d.ts} +5 -59
  10. package/dist/{axis-BjucJt39.d.mts → chartBase-Cn_5CUJi.d.mts} +5 -59
  11. package/dist/chunk-6D7P3IOT.js +150 -0
  12. package/dist/chunk-6D7P3IOT.js.map +1 -0
  13. package/dist/chunk-CYQXUAJC.js +169 -0
  14. package/dist/chunk-CYQXUAJC.js.map +1 -0
  15. package/dist/{chunk-EJYDQYLE.js → chunk-HDEKK4W4.js} +101 -248
  16. package/dist/chunk-HDEKK4W4.js.map +1 -0
  17. package/dist/chunk-QKH2ZO2D.js +68 -0
  18. package/dist/chunk-QKH2ZO2D.js.map +1 -0
  19. package/dist/donut/index.d.mts +48 -0
  20. package/dist/donut/index.d.ts +48 -0
  21. package/dist/donut/index.js +125 -0
  22. package/dist/donut/index.js.map +1 -0
  23. package/dist/esm/bar/index.js +13 -6
  24. package/dist/esm/bar/index.js.map +1 -1
  25. package/dist/esm/chunk-NAKJY5PA.js +150 -0
  26. package/dist/esm/chunk-NAKJY5PA.js.map +1 -0
  27. package/dist/esm/chunk-O5VJGGZY.js +68 -0
  28. package/dist/esm/chunk-O5VJGGZY.js.map +1 -0
  29. package/dist/esm/{chunk-DKTW56NJ.js → chunk-TKNWM7L3.js} +102 -249
  30. package/dist/esm/chunk-TKNWM7L3.js.map +1 -0
  31. package/dist/esm/chunk-XMYGML25.js +169 -0
  32. package/dist/esm/chunk-XMYGML25.js.map +1 -0
  33. package/dist/esm/donut/index.js +125 -0
  34. package/dist/esm/donut/index.js.map +1 -0
  35. package/dist/esm/index.js +13 -157
  36. package/dist/esm/index.js.map +1 -1
  37. package/dist/esm/line-area/index.js +14 -6
  38. package/dist/esm/line-area/index.js.map +1 -1
  39. package/dist/esm/sparkline/index.js +123 -0
  40. package/dist/esm/sparkline/index.js.map +1 -0
  41. package/dist/index.d.mts +3 -0
  42. package/dist/index.d.ts +3 -0
  43. package/dist/index.js +55 -199
  44. package/dist/index.js.map +1 -1
  45. package/dist/line-area/index.d.mts +6 -3
  46. package/dist/line-area/index.d.ts +6 -3
  47. package/dist/line-area/index.js +16 -8
  48. package/dist/line-area/index.js.map +1 -1
  49. package/dist/sparkline/index.d.mts +75 -0
  50. package/dist/sparkline/index.d.ts +75 -0
  51. package/dist/sparkline/index.js +123 -0
  52. package/dist/sparkline/index.js.map +1 -0
  53. package/dist/sparkline.css +76 -0
  54. package/package.json +22 -11
  55. package/dist/chunk-EJYDQYLE.js.map +0 -1
  56. 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;AA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AM,UAAU,IAAI,KAAK,eAAe,YAAY;AAAA,IAClD,GAAG;AAAA,IACH,UAAU;AAAA,EACZ,CAAC,EAAE,OAAO,SAAS;AAEnB,MAAI,OAAO,KAAK,iBAAiB,EAAE,SAAS,GAAG;AAC7C,UAAM,YAAY,IAAI,KAAK,eAAe,YAAY;AAAA,MACpD,GAAG;AAAA,MACH,UAAU;AAAA,IACZ,CAAC,EAAE,OAAO,SAAS;AACnB,WAAO,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,68 @@
1
+ import {
2
+ valueFormatter
3
+ } from "./chunk-TKNWM7L3.js";
4
+
5
+ // src/charts/shared/annotations.ts
6
+ function buildAnnotationConfig(annotations) {
7
+ if (!annotations?.length) {
8
+ return { annotations: void 0, lookup: void 0 };
9
+ }
10
+ const labels = [];
11
+ const lookup = /* @__PURE__ */ new Map();
12
+ for (const annotation of annotations) {
13
+ const { position } = annotation;
14
+ labels.push({
15
+ // Highcharts anchor — always uses `x` regardless of chart orientation.
16
+ point: { x: position, y: 0, xAxis: 0, yAxis: 0 },
17
+ // Space (not empty) — Highcharts reverts to its built-in label text on empty string.
18
+ text: " "
19
+ });
20
+ lookup.set(position, annotation);
21
+ }
22
+ if (labels.length === 0) {
23
+ return { annotations: void 0, lookup: void 0 };
24
+ }
25
+ return {
26
+ // `useHTML: true` makes Highcharts attach an HTML `graphic.div` to each
27
+ // label, which the marker portal needs as its render target. `padding: 0`
28
+ // removes Highcharts' default left padding so markers stay centered.
29
+ annotations: [{ labels, labelOptions: { useHTML: true, padding: 0 } }],
30
+ lookup
31
+ };
32
+ }
33
+
34
+ // src/charts/shared/valueAxisLabelFormatter.ts
35
+ import { formatNumeral } from "@sproutsocial/seeds-react-numeral";
36
+ var FIXED_LOCALE = "en-US";
37
+ function deriveAbbreviateFromTicks(context) {
38
+ const tickPositions = context.axis.tickPositions;
39
+ const maxValue = tickPositions && tickPositions.length > 0 ? tickPositions[tickPositions.length - 1] : void 0;
40
+ return typeof maxValue === "number" && maxValue > 9999 ? 1e3 : true;
41
+ }
42
+ function defaultValueAxisLabelFormatter() {
43
+ const numberValue = Number(this.value);
44
+ if (numberValue === 0) {
45
+ return formatNumeral({ locale: FIXED_LOCALE, number: 0 });
46
+ }
47
+ const abbreviate = deriveAbbreviateFromTicks(this);
48
+ return formatNumeral({
49
+ abbreviate,
50
+ format: "decimal",
51
+ locale: FIXED_LOCALE,
52
+ number: numberValue
53
+ });
54
+ }
55
+ function makeValueAxisLabelFormatter(format) {
56
+ return function() {
57
+ const numberValue = Number(this.value);
58
+ const abbreviate = format.abbreviate === false ? false : deriveAbbreviateFromTicks(this);
59
+ return valueFormatter({ ...format, value: numberValue, abbreviate });
60
+ };
61
+ }
62
+
63
+ export {
64
+ buildAnnotationConfig,
65
+ defaultValueAxisLabelFormatter,
66
+ makeValueAxisLabelFormatter
67
+ };
68
+ //# sourceMappingURL=chunk-O5VJGGZY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/charts/shared/annotations.ts","../../src/charts/shared/valueAxisLabelFormatter.ts"],"sourcesContent":["// Shared annotation plumbing across v2 chart families. Currently consumed by\n// BarChart; v2 Line/Area will share the same `annotations` shape and reuse\n// `buildAnnotationConfig` directly. Annotation data is purely numeric —\n// the module has no knowledge of `categories`; resolving a numeric position to\n// a display name is the tooltip's job (see chartBase `renderContent`).\n\nimport type { TypeIconName } from \"@sproutsocial/seeds-react-icon\";\nimport type { SeedsChartAnnotationsOptions } from \"./chartBase\";\n\n/**\n * Annotations keyed by the numeric Highcharts index. Both consumers resolve\n * numerically: the marker portal reads `label.point.x` and the tooltip reads\n * `context.point.x` (numeric on both category and datetime axes).\n */\nexport type ChartAnnotationLookup = Map<number, ChartAnnotation>;\n\n/**\n * Declarative annotation shape — the DS renders the marker and tooltip header\n * internally; consumers don't supply render functions. See CE-7.\n */\nexport interface ChartAnnotation {\n /** Numeric x-axis coordinate — a category index (category axes) or the raw coordinate (datetime/linear axes). */\n position: number;\n /** Icon shown above the chart at `position` and inline with `title` in the tooltip header. */\n icon?: TypeIconName;\n /** Color applied to the marker's vertical line. */\n color?: string;\n /** Tooltip header line 1. */\n title?: string;\n /** Tooltip header line 2. */\n description?: string;\n}\n\n/**\n * Build the Highcharts `annotations` config and a parallel lookup keyed by the\n * numeric `position`. Both consumers (chart adapter for Highcharts, ChartRenderer\n * for the portal + tooltip) read from the same numeric lookup to stay aligned.\n */\nexport function buildAnnotationConfig(\n annotations: ChartAnnotation[] | undefined\n): {\n annotations: SeedsChartAnnotationsOptions[] | undefined;\n lookup: ChartAnnotationLookup | undefined;\n} {\n if (!annotations?.length) {\n return { annotations: undefined, lookup: undefined };\n }\n const labels: {\n point: { x: number; y: number; xAxis: 0; yAxis: 0 };\n text: string;\n }[] = [];\n const lookup: ChartAnnotationLookup = new Map();\n for (const annotation of annotations) {\n const { position } = annotation;\n labels.push({\n // Highcharts anchor — always uses `x` regardless of chart orientation.\n point: { x: position, y: 0, xAxis: 0, yAxis: 0 },\n // Space (not empty) — Highcharts reverts to its built-in label text on empty string.\n text: \" \",\n });\n // Keyed by the numeric position only. The marker portal reads\n // `label.point.x` and the tooltip reads `context.point.x` — both numeric on\n // every axis type, so no category-name keying is needed.\n lookup.set(position, annotation);\n }\n if (labels.length === 0) {\n return { annotations: undefined, lookup: undefined };\n }\n return {\n // `useHTML: true` makes Highcharts attach an HTML `graphic.div` to each\n // label, which the marker portal needs as its render target. `padding: 0`\n // removes Highcharts' default left padding so markers stay centered.\n annotations: [{ labels, labelOptions: { useHTML: true, padding: 0 } }],\n lookup,\n };\n}\n","import { formatNumeral } from \"@sproutsocial/seeds-react-numeral\";\n\nimport type { SeedsAxisLabelFormatterContext } from \"./chartBase\";\nimport { valueFormatter, type ValueFormat } from \"./formatters/valueFormatter\";\n\n/**\n * Fixed internal locale for the default value-axis formatter. Pins the en-US\n * compact symbols (2K / 1.2M / 1.2B) so output is deterministic regardless of\n * the environment's locale resolution.\n * TODO: consumer-facing locale and an override surface may be added later.\n */\nconst FIXED_LOCALE = \"en-US\";\n\n/**\n * Derive formatNumeral's `abbreviate` threshold from the axis tick scan.\n *\n * formatNumeral abbreviates above 10,000 by default; passing a numeric\n * `abbreviate` lowers that threshold to that value. When the top tick exceeds\n * 9,999 we lower it to 1,000 so the whole axis reads \"2K 4K 6K 8K 10K\" rather\n * than a mixed \"2,000 4,000 6,000 8,000 10K\". Otherwise `true` keeps the default\n * 10,000 threshold. Centralizes the 9,999 rule for both formatters below.\n */\nfunction deriveAbbreviateFromTicks(\n context: SeedsAxisLabelFormatterContext\n): boolean | number {\n const tickPositions = context.axis.tickPositions;\n const maxValue =\n tickPositions && tickPositions.length > 0\n ? tickPositions[tickPositions.length - 1]\n : undefined;\n return typeof maxValue === \"number\" && maxValue > 9999 ? 1000 : true;\n}\n\n/**\n * Internal, zero-config default value-axis label formatter for v2 chart\n * families. Abbreviates value-axis ticks (1.20K / 1.20M / 1.20B); decimal mode\n * only. Zero renders \"0\". Decimal compact precision is fixed at two fraction\n * digits, so abbreviated ticks always carry two decimals.\n *\n * Wired as a Highcharts `yAxis.labels.formatter`, invoked `this`-bound with the\n * Seeds-local context.\n */\nexport function defaultValueAxisLabelFormatter(\n this: SeedsAxisLabelFormatterContext\n): string {\n const numberValue = Number(this.value);\n\n if (numberValue === 0) {\n return formatNumeral({ locale: FIXED_LOCALE, number: 0 });\n }\n\n const abbreviate = deriveAbbreviateFromTicks(this);\n\n return formatNumeral({\n abbreviate,\n format: \"decimal\",\n locale: FIXED_LOCALE,\n number: numberValue,\n });\n}\n\n/**\n * Build a `format`-driven value-axis label formatter that runs a declarative\n * {@link ValueFormat} through the shared {@link valueFormatter}. Reuses the same\n * `tickPositions` scan as {@link defaultValueAxisLabelFormatter} so the\n * axis-wide \"smart 1k/10k\" abbreviation is preserved for decimal/currency ticks.\n *\n * Wired as a Highcharts `yAxis.labels.formatter`; invoked `this`-bound with the\n * Seeds-local context. The returned formatter never carries chart-engine types,\n * keeping the engine boundary intact.\n */\nexport function makeValueAxisLabelFormatter(format: ValueFormat) {\n return function (this: SeedsAxisLabelFormatterContext): string {\n const numberValue = Number(this.value);\n\n // Honor an explicit `abbreviate: false` opt-out; otherwise derive the\n // threshold from the same tick scan as the default formatter (abbreviation\n // only affects decimal/currency — percent and duration ignore it inside\n // valueFormatter).\n const abbreviate =\n format.abbreviate === false ? false : deriveAbbreviateFromTicks(this);\n\n return valueFormatter({ ...format, value: numberValue, abbreviate });\n };\n}\n"],"mappings":";;;;;AAsCO,SAAS,sBACd,aAIA;AACA,MAAI,CAAC,aAAa,QAAQ;AACxB,WAAO,EAAE,aAAa,QAAW,QAAQ,OAAU;AAAA,EACrD;AACA,QAAM,SAGA,CAAC;AACP,QAAM,SAAgC,oBAAI,IAAI;AAC9C,aAAW,cAAc,aAAa;AACpC,UAAM,EAAE,SAAS,IAAI;AACrB,WA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