@sproutsocial/seeds-react-data-viz 0.7.32 → 0.14.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.
@@ -0,0 +1,208 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { TypeIconName } from '@sproutsocial/seeds-react-icon';
4
+ import { c as TypeChartNumberFormat, k as TypeChartStyleColor } from '../types-B7ILUQ6_.mjs';
5
+ import { C as ChartExportHandle } from '../chartExport-CKYpuhik.mjs';
6
+ import 'highcharts';
7
+
8
+ type TypeValuePercentInput = "decimal" | "whole";
9
+ type TypeValueFormatterOptions = Readonly<{
10
+ /** The raw numeric value. For duration, milliseconds. */
11
+ value: number;
12
+ /** default "decimal" */
13
+ numberFormat?: TypeChartNumberFormat;
14
+ /** Only used when numberFormat === "currency". default "USD" */
15
+ currency?: string;
16
+ /** true → 10k threshold; number → max(1000, abs(n)); false → never. default true */
17
+ abbreviate?: boolean | number;
18
+ /** "decimal" scales 0.42 → "42%"; "whole" treats 42 → "42%". default "decimal" */
19
+ percentInput?: TypeValuePercentInput;
20
+ /** locale for decimal/currency/percent (formatNumeral) */
21
+ numberLocale?: Intl.LocalesArgument;
22
+ /** locale for duration (formatDuration) */
23
+ textLocale?: Intl.LocalesArgument;
24
+ }>;
25
+ /**
26
+ * Declarative value-format config for axis ticks and the default tooltip — the
27
+ * full {@link TypeValueFormatterOptions} surface minus `value`, which is
28
+ * supplied per-tick / per-row by the caller (the adapter and tooltip).
29
+ */
30
+ type ValueFormat = Omit<TypeValueFormatterOptions, "value">;
31
+
32
+ interface ChartTooltipDataRow {
33
+ color: TypeChartStyleColor;
34
+ name: string;
35
+ value: number | null;
36
+ }
37
+ /** Tooltip render-prop signature for v2 charts. */
38
+ interface ChartTooltipProps {
39
+ data: ChartTooltipDataRow[];
40
+ /** Resolved x-axis position. Category name for category axes, numeric for time/linear. */
41
+ position: number | string;
42
+ /** Resolved chart timezone — pass to date formatters when `position` is a numeric timestamp. Undefined on category axes. */
43
+ timezone?: string;
44
+ /** Declarative annotation anchored at this position, if any. Rendered in the tooltip header. */
45
+ annotation?: {
46
+ icon?: TypeIconName;
47
+ color?: string;
48
+ title?: string;
49
+ description?: string;
50
+ };
51
+ /** True when the chart has an `onClick` handler — used by the default tooltip to render the click-label footer. */
52
+ hasOnClick?: boolean;
53
+ /** Footer content shown in the default tooltip when the chart is clickable. */
54
+ tooltipClickLabel?: ReactNode;
55
+ /** Content shown in place of a row's value when the value is null. Defaults to an em-dash. */
56
+ invalidNumberLabel?: ReactNode;
57
+ /** Declarative value format for the tooltip value cell. Omit for raw rendering. Applied at full precision (abbreviation off). */
58
+ valueFormat?: ValueFormat;
59
+ }
60
+
61
+ /**
62
+ * Declarative annotation shape — the DS renders the marker and tooltip header
63
+ * internally; consumers don't supply render functions. See CE-7.
64
+ */
65
+ interface ChartAnnotation {
66
+ /** Numeric x-axis coordinate — a category index (category axes) or the raw coordinate (datetime/linear axes). */
67
+ position: number;
68
+ /** Icon shown above the chart at `position` and inline with `title` in the tooltip header. */
69
+ icon?: TypeIconName;
70
+ /** Color applied to the marker's vertical line. */
71
+ color?: string;
72
+ /** Tooltip header line 1. */
73
+ title?: string;
74
+ /** Tooltip header line 2. */
75
+ description?: string;
76
+ }
77
+
78
+ /**
79
+ * Pure, Highcharts-free datetime axis label formatter for v2 chart families.
80
+ *
81
+ * Ports v1's `helpers/xAxisLabelFormatter` into a rendering-agnostic shape: it
82
+ * returns a `{ primary, secondary? }` object instead of an HTML string, leaving
83
+ * SVG rendering to the caller. The timezone- and DST-correct boundary detection
84
+ * (calendar parts read in the target timezone) and the per-granularity
85
+ * `Intl.DateTimeFormat` option sets are a near-verbatim port of v1.
86
+ *
87
+ * The one net-new piece versus v1 is granularity derivation: v1 receives
88
+ * `unitName` from Highcharts, but `charts/` may not depend on Highcharts types
89
+ * (see `charts/README.md` invariants), so granularity is derived from the
90
+ * spacing of `tickPositions`.
91
+ */
92
+ type DatetimeTimeFormat = "12" | "24";
93
+
94
+ /** A datetime data point: `[msSinceEpoch, value]` tuple or `{ x, y }` object. */
95
+ type DatetimePoint = [number, number | null] | {
96
+ x: number;
97
+ y: number | null;
98
+ };
99
+ /** A value on a category axis, or a datetime point when the axis is `"datetime"`. */
100
+ type ChartDataPoint = number | null | DatetimePoint;
101
+ /** Category axis — labels indexed parallel to `series.data`. The default axis type. */
102
+ interface CategoryAxis {
103
+ type?: "category";
104
+ /** Category labels, indexed parallel to `series.data`. */
105
+ categories: Array<string>;
106
+ crosshair?: boolean;
107
+ }
108
+ /** Datetime axis — `series.data` carries timestamped points. */
109
+ interface DatetimeAxis {
110
+ type: "datetime";
111
+ crosshair?: boolean;
112
+ /**
113
+ * 12- or 24-hour clock for hour-granularity tick labels (e.g. `9 AM` vs
114
+ * `09:00`). Default `"12"`. Coarser granularities (day/month/year) ignore it.
115
+ */
116
+ timeFormat?: DatetimeTimeFormat;
117
+ }
118
+
119
+ /** A datetime data point: `[msSinceEpoch, value]` tuple or `{ x, y }` object. */
120
+ type BarDatetimePoint = DatetimePoint;
121
+ /** A category y-value, or a datetime point when the dimensional axis is `"datetime"`. */
122
+ type BarDataPoint = ChartDataPoint;
123
+ interface BarSeries {
124
+ name: string;
125
+ /**
126
+ * Y-values indexed parallel to `xAxis.categories` on a category axis, or
127
+ * `[timestamp, value]` / `{ x, y }` points on a datetime axis.
128
+ */
129
+ data: Array<BarDataPoint>;
130
+ color?: string;
131
+ /** Seeds icon or partner-logo name rendered before the series name in the legend. */
132
+ icon?: TypeIconName;
133
+ }
134
+ type BarXAxis = CategoryAxis | DatetimeAxis;
135
+ interface BarYAxis {
136
+ min?: number;
137
+ max?: number;
138
+ /** Default: true. */
139
+ showGridLines?: boolean;
140
+ title?: string;
141
+ /**
142
+ * Declarative value formatting applied to y-axis tick labels and the default
143
+ * tooltip value. Omit for the zero-config decimal default (smart 1k/10k
144
+ * abbreviation on the axis, raw values in the tooltip).
145
+ */
146
+ format?: ValueFormat;
147
+ /**
148
+ * Show y-axis tick labels. Default `true`. `false` hides them (maps to
149
+ * Highcharts' `labels.enabled`, replacing v1's `() => ""` formatter trick).
150
+ */
151
+ showLabels?: boolean;
152
+ }
153
+ /**
154
+ * Direction in which bars are drawn. Single-member union for now; expands to
155
+ * `"vertical" | "horizontal"` when `HorizontalBarChart` ships.
156
+ */
157
+ type BarChartDirection = "vertical";
158
+ interface BarChartProps {
159
+ /** Wired into Highcharts' `accessibility.description`. */
160
+ description: string;
161
+ series: Array<BarSeries>;
162
+ /**
163
+ * Maximum number of series to display. Series beyond the limit are dropped to
164
+ * keep the chart readable and accessible. Default `10`.
165
+ */
166
+ seriesLimit?: number;
167
+ /**
168
+ * Suppress the `console.warn` emitted when the series count exceeds the limit.
169
+ * The cap still applies. Default `false`.
170
+ */
171
+ hideSeriesLimitWarning?: boolean;
172
+ xAxis: BarXAxis;
173
+ yAxis?: BarYAxis;
174
+ /** IANA timezone for datetime-axis ticks and tooltips. Default `"UTC"`. Ignored for category axes. */
175
+ timezone?: string;
176
+ /**
177
+ * Stacking mode for multi-series charts. Defaults to `"normal"` — the
178
+ * canonical design-system spec renders multi-series bar charts as a single
179
+ * stacked column per category. `"percent"` normalizes each column to 100%.
180
+ * `"grouped"` renders series as adjacent bars per category; not part of the
181
+ * canonical spec, but available for non-standard use cases.
182
+ */
183
+ stacking?: "normal" | "percent" | "grouped";
184
+ /** Appended to each tooltip value (e.g., `" MT"`, `"%"`). */
185
+ valueSuffix?: string;
186
+ /** Override for the default tooltip content. */
187
+ tooltip?: (args: ChartTooltipProps) => ReactNode;
188
+ /** Declarative annotations rendered at positions on the chart. */
189
+ annotations?: ChartAnnotation[];
190
+ /** Click handler invoked with the dimensional-axis value of the clicked column — the category name on a category axis, the numeric timestamp on a datetime axis. `position` is direction-agnostic: the x-axis value on `VerticalBarChart`, the y-axis value on `HorizontalBarChart`. */
191
+ onClick?: ({ position }: {
192
+ position: number | string;
193
+ }) => void;
194
+ /** Footer content shown in the default tooltip when `onClick` is set. */
195
+ tooltipClickLabel?: ReactNode;
196
+ /** Override for the value shown when a data point is invalid/missing (null). Defaults to an em-dash. */
197
+ invalidNumberLabel?: ReactNode;
198
+ /**
199
+ * Fired once per chart instance with an opaque {@link ChartExportHandle} for
200
+ * triggering PNG/SVG/PDF/CSV downloads. Re-fires only on a genuine remount,
201
+ * never on data or prop updates.
202
+ */
203
+ onReady?: (handle: ChartExportHandle) => void;
204
+ }
205
+
206
+ declare const VerticalBarChart: react.NamedExoticComponent<BarChartProps>;
207
+
208
+ export { type BarChartDirection, type BarChartProps, type BarDataPoint, type BarDatetimePoint, type BarSeries, type BarXAxis, type BarYAxis, type CategoryAxis, ChartExportHandle, type DatetimeAxis, type ValueFormat, VerticalBarChart };
@@ -0,0 +1,208 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { TypeIconName } from '@sproutsocial/seeds-react-icon';
4
+ import { c as TypeChartNumberFormat, k as TypeChartStyleColor } from '../types-B7ILUQ6_.js';
5
+ import { C as ChartExportHandle } from '../chartExport-CKYpuhik.js';
6
+ import 'highcharts';
7
+
8
+ type TypeValuePercentInput = "decimal" | "whole";
9
+ type TypeValueFormatterOptions = Readonly<{
10
+ /** The raw numeric value. For duration, milliseconds. */
11
+ value: number;
12
+ /** default "decimal" */
13
+ numberFormat?: TypeChartNumberFormat;
14
+ /** Only used when numberFormat === "currency". default "USD" */
15
+ currency?: string;
16
+ /** true → 10k threshold; number → max(1000, abs(n)); false → never. default true */
17
+ abbreviate?: boolean | number;
18
+ /** "decimal" scales 0.42 → "42%"; "whole" treats 42 → "42%". default "decimal" */
19
+ percentInput?: TypeValuePercentInput;
20
+ /** locale for decimal/currency/percent (formatNumeral) */
21
+ numberLocale?: Intl.LocalesArgument;
22
+ /** locale for duration (formatDuration) */
23
+ textLocale?: Intl.LocalesArgument;
24
+ }>;
25
+ /**
26
+ * Declarative value-format config for axis ticks and the default tooltip — the
27
+ * full {@link TypeValueFormatterOptions} surface minus `value`, which is
28
+ * supplied per-tick / per-row by the caller (the adapter and tooltip).
29
+ */
30
+ type ValueFormat = Omit<TypeValueFormatterOptions, "value">;
31
+
32
+ interface ChartTooltipDataRow {
33
+ color: TypeChartStyleColor;
34
+ name: string;
35
+ value: number | null;
36
+ }
37
+ /** Tooltip render-prop signature for v2 charts. */
38
+ interface ChartTooltipProps {
39
+ data: ChartTooltipDataRow[];
40
+ /** Resolved x-axis position. Category name for category axes, numeric for time/linear. */
41
+ position: number | string;
42
+ /** Resolved chart timezone — pass to date formatters when `position` is a numeric timestamp. Undefined on category axes. */
43
+ timezone?: string;
44
+ /** Declarative annotation anchored at this position, if any. Rendered in the tooltip header. */
45
+ annotation?: {
46
+ icon?: TypeIconName;
47
+ color?: string;
48
+ title?: string;
49
+ description?: string;
50
+ };
51
+ /** True when the chart has an `onClick` handler — used by the default tooltip to render the click-label footer. */
52
+ hasOnClick?: boolean;
53
+ /** Footer content shown in the default tooltip when the chart is clickable. */
54
+ tooltipClickLabel?: ReactNode;
55
+ /** Content shown in place of a row's value when the value is null. Defaults to an em-dash. */
56
+ invalidNumberLabel?: ReactNode;
57
+ /** Declarative value format for the tooltip value cell. Omit for raw rendering. Applied at full precision (abbreviation off). */
58
+ valueFormat?: ValueFormat;
59
+ }
60
+
61
+ /**
62
+ * Declarative annotation shape — the DS renders the marker and tooltip header
63
+ * internally; consumers don't supply render functions. See CE-7.
64
+ */
65
+ interface ChartAnnotation {
66
+ /** Numeric x-axis coordinate — a category index (category axes) or the raw coordinate (datetime/linear axes). */
67
+ position: number;
68
+ /** Icon shown above the chart at `position` and inline with `title` in the tooltip header. */
69
+ icon?: TypeIconName;
70
+ /** Color applied to the marker's vertical line. */
71
+ color?: string;
72
+ /** Tooltip header line 1. */
73
+ title?: string;
74
+ /** Tooltip header line 2. */
75
+ description?: string;
76
+ }
77
+
78
+ /**
79
+ * Pure, Highcharts-free datetime axis label formatter for v2 chart families.
80
+ *
81
+ * Ports v1's `helpers/xAxisLabelFormatter` into a rendering-agnostic shape: it
82
+ * returns a `{ primary, secondary? }` object instead of an HTML string, leaving
83
+ * SVG rendering to the caller. The timezone- and DST-correct boundary detection
84
+ * (calendar parts read in the target timezone) and the per-granularity
85
+ * `Intl.DateTimeFormat` option sets are a near-verbatim port of v1.
86
+ *
87
+ * The one net-new piece versus v1 is granularity derivation: v1 receives
88
+ * `unitName` from Highcharts, but `charts/` may not depend on Highcharts types
89
+ * (see `charts/README.md` invariants), so granularity is derived from the
90
+ * spacing of `tickPositions`.
91
+ */
92
+ type DatetimeTimeFormat = "12" | "24";
93
+
94
+ /** A datetime data point: `[msSinceEpoch, value]` tuple or `{ x, y }` object. */
95
+ type DatetimePoint = [number, number | null] | {
96
+ x: number;
97
+ y: number | null;
98
+ };
99
+ /** A value on a category axis, or a datetime point when the axis is `"datetime"`. */
100
+ type ChartDataPoint = number | null | DatetimePoint;
101
+ /** Category axis — labels indexed parallel to `series.data`. The default axis type. */
102
+ interface CategoryAxis {
103
+ type?: "category";
104
+ /** Category labels, indexed parallel to `series.data`. */
105
+ categories: Array<string>;
106
+ crosshair?: boolean;
107
+ }
108
+ /** Datetime axis — `series.data` carries timestamped points. */
109
+ interface DatetimeAxis {
110
+ type: "datetime";
111
+ crosshair?: boolean;
112
+ /**
113
+ * 12- or 24-hour clock for hour-granularity tick labels (e.g. `9 AM` vs
114
+ * `09:00`). Default `"12"`. Coarser granularities (day/month/year) ignore it.
115
+ */
116
+ timeFormat?: DatetimeTimeFormat;
117
+ }
118
+
119
+ /** A datetime data point: `[msSinceEpoch, value]` tuple or `{ x, y }` object. */
120
+ type BarDatetimePoint = DatetimePoint;
121
+ /** A category y-value, or a datetime point when the dimensional axis is `"datetime"`. */
122
+ type BarDataPoint = ChartDataPoint;
123
+ interface BarSeries {
124
+ name: string;
125
+ /**
126
+ * Y-values indexed parallel to `xAxis.categories` on a category axis, or
127
+ * `[timestamp, value]` / `{ x, y }` points on a datetime axis.
128
+ */
129
+ data: Array<BarDataPoint>;
130
+ color?: string;
131
+ /** Seeds icon or partner-logo name rendered before the series name in the legend. */
132
+ icon?: TypeIconName;
133
+ }
134
+ type BarXAxis = CategoryAxis | DatetimeAxis;
135
+ interface BarYAxis {
136
+ min?: number;
137
+ max?: number;
138
+ /** Default: true. */
139
+ showGridLines?: boolean;
140
+ title?: string;
141
+ /**
142
+ * Declarative value formatting applied to y-axis tick labels and the default
143
+ * tooltip value. Omit for the zero-config decimal default (smart 1k/10k
144
+ * abbreviation on the axis, raw values in the tooltip).
145
+ */
146
+ format?: ValueFormat;
147
+ /**
148
+ * Show y-axis tick labels. Default `true`. `false` hides them (maps to
149
+ * Highcharts' `labels.enabled`, replacing v1's `() => ""` formatter trick).
150
+ */
151
+ showLabels?: boolean;
152
+ }
153
+ /**
154
+ * Direction in which bars are drawn. Single-member union for now; expands to
155
+ * `"vertical" | "horizontal"` when `HorizontalBarChart` ships.
156
+ */
157
+ type BarChartDirection = "vertical";
158
+ interface BarChartProps {
159
+ /** Wired into Highcharts' `accessibility.description`. */
160
+ description: string;
161
+ series: Array<BarSeries>;
162
+ /**
163
+ * Maximum number of series to display. Series beyond the limit are dropped to
164
+ * keep the chart readable and accessible. Default `10`.
165
+ */
166
+ seriesLimit?: number;
167
+ /**
168
+ * Suppress the `console.warn` emitted when the series count exceeds the limit.
169
+ * The cap still applies. Default `false`.
170
+ */
171
+ hideSeriesLimitWarning?: boolean;
172
+ xAxis: BarXAxis;
173
+ yAxis?: BarYAxis;
174
+ /** IANA timezone for datetime-axis ticks and tooltips. Default `"UTC"`. Ignored for category axes. */
175
+ timezone?: string;
176
+ /**
177
+ * Stacking mode for multi-series charts. Defaults to `"normal"` — the
178
+ * canonical design-system spec renders multi-series bar charts as a single
179
+ * stacked column per category. `"percent"` normalizes each column to 100%.
180
+ * `"grouped"` renders series as adjacent bars per category; not part of the
181
+ * canonical spec, but available for non-standard use cases.
182
+ */
183
+ stacking?: "normal" | "percent" | "grouped";
184
+ /** Appended to each tooltip value (e.g., `" MT"`, `"%"`). */
185
+ valueSuffix?: string;
186
+ /** Override for the default tooltip content. */
187
+ tooltip?: (args: ChartTooltipProps) => ReactNode;
188
+ /** Declarative annotations rendered at positions on the chart. */
189
+ annotations?: ChartAnnotation[];
190
+ /** Click handler invoked with the dimensional-axis value of the clicked column — the category name on a category axis, the numeric timestamp on a datetime axis. `position` is direction-agnostic: the x-axis value on `VerticalBarChart`, the y-axis value on `HorizontalBarChart`. */
191
+ onClick?: ({ position }: {
192
+ position: number | string;
193
+ }) => void;
194
+ /** Footer content shown in the default tooltip when `onClick` is set. */
195
+ tooltipClickLabel?: ReactNode;
196
+ /** Override for the value shown when a data point is invalid/missing (null). Defaults to an em-dash. */
197
+ invalidNumberLabel?: ReactNode;
198
+ /**
199
+ * Fired once per chart instance with an opaque {@link ChartExportHandle} for
200
+ * triggering PNG/SVG/PDF/CSV downloads. Re-fires only on a genuine remount,
201
+ * never on data or prop updates.
202
+ */
203
+ onReady?: (handle: ChartExportHandle) => void;
204
+ }
205
+
206
+ declare const VerticalBarChart: react.NamedExoticComponent<BarChartProps>;
207
+
208
+ export { type BarChartDirection, type BarChartProps, type BarDataPoint, type BarDatetimePoint, type BarSeries, type BarXAxis, type BarYAxis, type CategoryAxis, ChartExportHandle, type DatetimeAxis, type ValueFormat, VerticalBarChart };