@cascivo/charts 0.2.1 → 0.3.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +152 -68
  2. package/dist/index.js +694 -561
  3. package/package.json +4 -2
package/dist/index.d.ts CHANGED
@@ -43,6 +43,126 @@ declare function linePath(points: readonly Point[], curve?: 'linear' | 'monotone
43
43
  declare function areaPath(points: readonly Point[], baseline: number, curve?: 'linear' | 'monotone'): string;
44
44
  declare function arcPath(cx: number, cy: number, outerRadius: number, innerRadius: number, startAngle: number, endAngle: number): string;
45
45
  declare function stackSeries(series: readonly (readonly number[])[]): [number, number][][];
46
+ /** A single focusable data point for the chart tooltip system.
47
+ * cx/cy are absolute SVG coordinates (already include margin offsets). */
48
+ interface ChartPoint {
49
+ id: string;
50
+ /** Absolute SVG x coordinate */
51
+ cx: number;
52
+ /** Absolute SVG y coordinate */
53
+ cy: number;
54
+ /** Category label or x-axis label */
55
+ label: string;
56
+ /** Datum value (y or measure) */
57
+ value: number | string;
58
+ seriesId?: string;
59
+ /** Share of the whole, 0–100 (pie/donut). Available to a custom formatter. */
60
+ percent?: number;
61
+ /** Mark color for this point — used to tint the tooltip text. */
62
+ color?: string;
63
+ /** Per-segment breakdown for a stacked category, in layer order. */
64
+ segments?: readonly {
65
+ label: string;
66
+ value: number;
67
+ color?: string;
68
+ }[];
69
+ }
70
+ interface TooltipModel {
71
+ /** All focusable points in traversal order */
72
+ points: ChartPoint[];
73
+ /** Custom formatter — defaults to "label: value" */
74
+ format?: (p: ChartPoint) => string;
75
+ }
76
+ interface BarChartSeries<Datum> {
77
+ id: string;
78
+ label: string;
79
+ data: readonly Datum[];
80
+ color?: string;
81
+ }
82
+ interface BarChartProps<Datum = {
83
+ x: string;
84
+ y: number;
85
+ }> {
86
+ series: readonly BarChartSeries<Datum>[];
87
+ x: (d: Datum) => string;
88
+ y: (d: Datum) => number;
89
+ title: string;
90
+ description?: string;
91
+ orientation?: 'vertical' | 'horizontal';
92
+ mode?: 'grouped' | 'stacked';
93
+ width?: number;
94
+ height?: number;
95
+ xTicks?: number;
96
+ yTicks?: number;
97
+ /** Show every Nth category label (and always the last) to thin a crowded x-axis. */
98
+ xLabelEvery?: number;
99
+ legend?: boolean;
100
+ tooltip?: boolean;
101
+ /** Custom tooltip formatter. Stacked default lists "label · total" + per-layer values. */
102
+ tooltipFormat?: (p: ChartPoint) => string;
103
+ className?: string;
104
+ /** Render only the marks — no axes, grid lines, or legend. For micro/inline charts. */
105
+ plain?: boolean;
106
+ }
107
+ declare function BarChart<Datum = {
108
+ x: string;
109
+ y: number;
110
+ }>({
111
+ series,
112
+ x,
113
+ y,
114
+ title,
115
+ description,
116
+ orientation,
117
+ mode,
118
+ width: fixedWidth,
119
+ height,
120
+ xTicks,
121
+ yTicks,
122
+ xLabelEvery,
123
+ legend,
124
+ tooltip,
125
+ tooltipFormat,
126
+ className,
127
+ plain
128
+ }: BarChartProps<Datum>): import("react").JSX.Element;
129
+ /** One layer of a stacked bar at a category. */
130
+ interface StackedSegment {
131
+ /** Layer key — becomes the series id/label (e.g. "Done", "In progress"). */
132
+ key: string;
133
+ value: number;
134
+ /** Optional CSS color for this layer; the first non-undefined per key wins. */
135
+ color?: string;
136
+ }
137
+ /** A single category (bar) with its per-layer segments. */
138
+ interface StackedRow {
139
+ label: string;
140
+ segments: readonly StackedSegment[];
141
+ }
142
+ type StackedDatum = {
143
+ x: string;
144
+ y: number;
145
+ };
146
+ /**
147
+ * Pivot row-oriented `{ label, segments[] }` data into the column-oriented
148
+ * `BarChartSeries[]` + `x`/`y` accessors that `BarChart` consumes. Spread the
149
+ * result straight into the component:
150
+ *
151
+ * ```tsx
152
+ * <BarChart mode="stacked" {...toStackedSeries(rows)} title="…" />
153
+ * ```
154
+ *
155
+ * - Layer keys are collected in first-seen order across all rows (stable column order).
156
+ * - A key missing from a row contributes 0 so stacks stay aligned.
157
+ * - Each layer's color is the first non-undefined color seen for that key.
158
+ *
159
+ * Pure and dependency-free.
160
+ */
161
+ declare function toStackedSeries(rows: readonly StackedRow[]): {
162
+ series: BarChartSeries<StackedDatum>[];
163
+ x: (d: StackedDatum) => string;
164
+ y: (d: StackedDatum) => number;
165
+ };
46
166
  /** Binary search for the index of the nearest value in a sorted array. */
47
167
  declare function nearestIndex(values: readonly number[], target: number): number;
48
168
  /** Statistical helpers for histogram and boxplot charts. */
@@ -85,26 +205,6 @@ interface TreemapRect {
85
205
  * Returns rectangles positioned within [0, width] × [0, height].
86
206
  */
87
207
  declare function squarify(nodes: TreemapNode[], width: number, height: number): TreemapRect[];
88
- /** A single focusable data point for the chart tooltip system.
89
- * cx/cy are absolute SVG coordinates (already include margin offsets). */
90
- interface ChartPoint {
91
- id: string;
92
- /** Absolute SVG x coordinate */
93
- cx: number;
94
- /** Absolute SVG y coordinate */
95
- cy: number;
96
- /** Category label or x-axis label */
97
- label: string;
98
- /** Datum value (y or measure) */
99
- value: number | string;
100
- seriesId?: string;
101
- }
102
- interface TooltipModel {
103
- /** All focusable points in traversal order */
104
- points: ChartPoint[];
105
- /** Custom formatter — defaults to "label: value" */
106
- format?: (p: ChartPoint) => string;
107
- }
108
208
  interface ChartFrameProps {
109
209
  title: string;
110
210
  description?: string | undefined;
@@ -117,6 +217,8 @@ interface ChartFrameProps {
117
217
  }) => ReactNode;
118
218
  className?: string | undefined;
119
219
  'data-state'?: string | undefined;
220
+ /** Visible placeholder text shown when data-state is "empty". Defaults to the i18n built-in. */
221
+ emptyLabel?: string | undefined;
120
222
  plain?: boolean | undefined;
121
223
  /**
122
224
  * Tooltip model. Pass a TooltipModel directly, or a factory function that
@@ -136,6 +238,7 @@ declare function ChartFrame({
136
238
  children,
137
239
  className,
138
240
  'data-state': dataState,
241
+ emptyLabel,
139
242
  plain,
140
243
  tooltip
141
244
  }: ChartFrameProps): import("react").JSX.Element;
@@ -168,6 +271,8 @@ interface AxisProps {
168
271
  length: number;
169
272
  format?: (value: number | string | Date) => string;
170
273
  tickCount?: number;
274
+ /** For band scales: render every Nth category label (and always the last) to avoid crowding. */
275
+ labelEvery?: number | undefined;
171
276
  transform?: string;
172
277
  }
173
278
  declare function Axis({
@@ -176,6 +281,7 @@ declare function Axis({
176
281
  length,
177
282
  format,
178
283
  tickCount,
284
+ labelEvery,
179
285
  transform
180
286
  }: AxisProps): import("react").JSX.Element;
181
287
  interface GridLinesProps {
@@ -299,57 +405,11 @@ declare function AreaChart<Datum = {
299
405
  className,
300
406
  plain
301
407
  }: AreaChartProps<Datum>): import("react").JSX.Element;
302
- interface BarChartSeries<Datum> {
303
- id: string;
304
- label: string;
305
- data: readonly Datum[];
306
- color?: string;
307
- }
308
- interface BarChartProps<Datum = {
309
- x: string;
310
- y: number;
311
- }> {
312
- series: readonly BarChartSeries<Datum>[];
313
- x: (d: Datum) => string;
314
- y: (d: Datum) => number;
315
- title: string;
316
- description?: string;
317
- orientation?: 'vertical' | 'horizontal';
318
- mode?: 'grouped' | 'stacked';
319
- width?: number;
320
- height?: number;
321
- xTicks?: number;
322
- yTicks?: number;
323
- legend?: boolean;
324
- tooltip?: boolean;
325
- className?: string;
326
- /** Render only the marks — no axes, grid lines, or legend. For micro/inline charts. */
327
- plain?: boolean;
328
- }
329
- declare function BarChart<Datum = {
330
- x: string;
331
- y: number;
332
- }>({
333
- series,
334
- x,
335
- y,
336
- title,
337
- description,
338
- orientation,
339
- mode,
340
- width: fixedWidth,
341
- height,
342
- xTicks,
343
- yTicks,
344
- legend,
345
- tooltip,
346
- className,
347
- plain
348
- }: BarChartProps<Datum>): import("react").JSX.Element;
349
408
  interface PieChartDatum {
350
409
  id: string;
351
410
  label: string;
352
411
  value: number;
412
+ /** CSS color overriding the positional palette for this slice. */
353
413
  color?: string;
354
414
  }
355
415
  interface PieChartProps {
@@ -359,6 +419,22 @@ interface PieChartProps {
359
419
  donut?: boolean;
360
420
  width?: number;
361
421
  height?: number;
422
+ /** Square shorthand: sets width === height. Explicit width/height win. */
423
+ size?: number;
424
+ /** Donut ring width in px. Defaults to 0.4 × radius (innerRadius = 0.6 × radius). */
425
+ thickness?: number;
426
+ /** Donut inner radius in px. Takes precedence over `thickness`. Clamped to [0, outerRadius). */
427
+ innerRadius?: number;
428
+ /** Center value text rendered in the donut hole (donut only). */
429
+ centerValue?: string;
430
+ /** Center label text rendered below the value in the donut hole (donut only). */
431
+ centerLabel?: string;
432
+ /** Arbitrary content rendered in the donut hole; takes precedence over centerValue/centerLabel. */
433
+ centerSlot?: ReactNode;
434
+ /** Visible placeholder text when data is empty. Defaults to the i18n built-in ("No data"). */
435
+ emptyLabel?: string;
436
+ /** Custom tooltip formatter. Defaults to "value (pct%)". Receives ChartPoint.percent. */
437
+ tooltipFormat?: (p: ChartPoint) => string;
362
438
  legend?: boolean;
363
439
  className?: string;
364
440
  /** Render only the marks — no legend. For micro/inline charts. */
@@ -371,6 +447,14 @@ declare function PieChart({
371
447
  donut,
372
448
  width: fixedWidth,
373
449
  height,
450
+ size,
451
+ thickness,
452
+ innerRadius,
453
+ centerValue,
454
+ centerLabel,
455
+ centerSlot,
456
+ emptyLabel,
457
+ tooltipFormat,
374
458
  legend,
375
459
  className,
376
460
  plain
@@ -681,4 +765,4 @@ declare function Bullet({
681
765
  height,
682
766
  className
683
767
  }: BulletProps): import("react").JSX.Element;
684
- export { AreaChart, AreaChartProps, AreaChartSeries, Axis, AxisProps, BandScale, BarChart, BarChartProps, BarChartSeries, Bin, BoxStats, Boxplot, BoxplotProps, BoxplotSeries, BubbleChart, BubbleChartProps, BubbleDatum, BubbleSeries, Bullet, BulletProps, ChartFrame, ChartFrameProps, ChartSize, ComboChart, ComboChartBar, ComboChartPoint, ComboChartProps, DEFAULT_MARGINS, GridLines, GridLinesProps, Heatmap, HeatmapDatum, HeatmapProps, Histogram, HistogramProps, Kpi, KpiProps, Legend, LegendProps, LegendSeries, LineChart, LineChartProps, LineChartSeries, LinearScale, LogScale, Meter, MeterProps, MeterThresholds, PLAIN_MARGINS, PieChart, PieChartDatum, PieChartProps, Point, Radar, RadarProps, RadarSeries, ScatterChart, ScatterChartProps, ScatterChartSeries, ScatterDatum, Sparkline, SparklineProps, TimeScale, Treemap, TreemapDatum, TreemapNode, TreemapProps, TreemapRect, arcPath, areaPath, bandScale, binValues, boxStats, extent, linePath, linearScale, logScale, nearestIndex, niceTicks, sqrtScale, squarify, stackSeries, timeScale, useChartSize };
768
+ export { AreaChart, AreaChartProps, AreaChartSeries, Axis, AxisProps, BandScale, BarChart, BarChartProps, BarChartSeries, Bin, BoxStats, Boxplot, BoxplotProps, BoxplotSeries, BubbleChart, BubbleChartProps, BubbleDatum, BubbleSeries, Bullet, BulletProps, ChartFrame, ChartFrameProps, ChartSize, ComboChart, ComboChartBar, ComboChartPoint, ComboChartProps, DEFAULT_MARGINS, GridLines, GridLinesProps, Heatmap, HeatmapDatum, HeatmapProps, Histogram, HistogramProps, Kpi, KpiProps, Legend, LegendProps, LegendSeries, LineChart, LineChartProps, LineChartSeries, LinearScale, LogScale, Meter, MeterProps, MeterThresholds, PLAIN_MARGINS, PieChart, PieChartDatum, PieChartProps, Point, Radar, RadarProps, RadarSeries, ScatterChart, ScatterChartProps, ScatterChartSeries, ScatterDatum, Sparkline, SparklineProps, StackedRow, StackedSegment, TimeScale, Treemap, TreemapDatum, TreemapNode, TreemapProps, TreemapRect, arcPath, areaPath, bandScale, binValues, boxStats, extent, linePath, linearScale, logScale, nearestIndex, niceTicks, sqrtScale, squarify, stackSeries, timeScale, toStackedSeries, useChartSize };