@cascivo/charts 0.2.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,684 @@
1
+ import { ReactNode } from "react";
2
+ import { Signal } from "@preact/signals-react";
3
+
4
+ interface LinearScale {
5
+ domain: [number, number];
6
+ range: [number, number];
7
+ map(value: number): number;
8
+ invert(position: number): number;
9
+ ticks(count?: number): number[];
10
+ }
11
+ declare function linearScale(domain: [number, number], range: [number, number]): LinearScale;
12
+ /** Extended nice-numbers: steps are 1, 2, 2.5 or 5 × 10^k covering [min, max]. */
13
+ declare function niceTicks(min: number, max: number, count?: number): number[];
14
+ interface BandScale<T extends string = string> {
15
+ domain: readonly T[];
16
+ range: [number, number];
17
+ bandwidth: number;
18
+ map(value: T): number | undefined;
19
+ }
20
+ declare function bandScale<T extends string>(domain: readonly T[], range: [number, number], padding?: number): BandScale<T>;
21
+ /** Square-root scale for area-proportional bubble sizes. Maps values in sqrt space. */
22
+ declare function sqrtScale(domain: [number, number], range: [number, number]): (value: number) => number;
23
+ interface LogScale {
24
+ domain: [number, number];
25
+ range: [number, number];
26
+ map(value: number): number;
27
+ invert(position: number): number;
28
+ ticks(): number[];
29
+ }
30
+ declare function logScale(domain: [number, number], range: [number, number]): LogScale;
31
+ interface TimeScale {
32
+ domain: [Date, Date];
33
+ range: [number, number];
34
+ map(value: Date): number;
35
+ invert(position: number): Date;
36
+ ticks(count?: number): Date[];
37
+ tickInterval(): 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year';
38
+ tickFormat(): Intl.DateTimeFormatOptions;
39
+ }
40
+ declare function timeScale(domain: [Date, Date], range: [number, number]): TimeScale;
41
+ type Point = readonly [x: number, y: number];
42
+ declare function linePath(points: readonly Point[], curve?: 'linear' | 'monotone'): string;
43
+ declare function areaPath(points: readonly Point[], baseline: number, curve?: 'linear' | 'monotone'): string;
44
+ declare function arcPath(cx: number, cy: number, outerRadius: number, innerRadius: number, startAngle: number, endAngle: number): string;
45
+ declare function stackSeries(series: readonly (readonly number[])[]): [number, number][][];
46
+ /** Binary search for the index of the nearest value in a sorted array. */
47
+ declare function nearestIndex(values: readonly number[], target: number): number;
48
+ /** Statistical helpers for histogram and boxplot charts. */
49
+ interface Bin {
50
+ x0: number;
51
+ x1: number;
52
+ count: number;
53
+ }
54
+ /**
55
+ * Freedman–Diaconis bin width with sane fallbacks.
56
+ * Returns inclusive-exclusive bins covering [min, max].
57
+ */
58
+ declare function binValues(values: readonly number[], binCount?: number): Bin[];
59
+ interface BoxStats {
60
+ min: number;
61
+ q1: number;
62
+ median: number;
63
+ q3: number;
64
+ max: number;
65
+ outliers: number[];
66
+ }
67
+ /** Five-number summary with outlier detection via 1.5×IQR fences. */
68
+ declare function boxStats(values: readonly number[]): BoxStats;
69
+ /** [min, max] extent of an array of numbers. */
70
+ declare function extent(values: readonly number[]): [number, number];
71
+ /** Squarified treemap layout algorithm. */
72
+ interface TreemapNode {
73
+ id: string;
74
+ value: number;
75
+ }
76
+ interface TreemapRect {
77
+ id: string;
78
+ x: number;
79
+ y: number;
80
+ w: number;
81
+ h: number;
82
+ }
83
+ /**
84
+ * Squarified treemap algorithm (~60 lines).
85
+ * Returns rectangles positioned within [0, width] × [0, height].
86
+ */
87
+ 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
+ interface ChartFrameProps {
109
+ title: string;
110
+ description?: string | undefined;
111
+ width?: number | undefined;
112
+ height?: number | undefined;
113
+ fallback?: ReactNode;
114
+ children: (size: {
115
+ width: number;
116
+ height: number;
117
+ }) => ReactNode;
118
+ className?: string | undefined;
119
+ 'data-state'?: string | undefined;
120
+ plain?: boolean | undefined;
121
+ /**
122
+ * Tooltip model. Pass a TooltipModel directly, or a factory function that
123
+ * receives the resolved chart size so cx/cy can be computed from scales.
124
+ */
125
+ tooltip?: TooltipModel | ((size: {
126
+ width: number;
127
+ height: number;
128
+ }) => TooltipModel | undefined) | undefined;
129
+ }
130
+ declare function ChartFrame({
131
+ title,
132
+ description,
133
+ width: fixedWidth,
134
+ height: fixedHeight,
135
+ fallback,
136
+ children,
137
+ className,
138
+ 'data-state': dataState,
139
+ plain,
140
+ tooltip
141
+ }: ChartFrameProps): import("react").JSX.Element;
142
+ interface ChartSize {
143
+ width: number;
144
+ height: number;
145
+ }
146
+ declare function useChartSize(defaultWidth?: number, defaultHeight?: number): {
147
+ ref: React.RefObject<HTMLDivElement | null>;
148
+ width: import('@preact/signals-react').Signal<number>;
149
+ height: import('@preact/signals-react').Signal<number>;
150
+ };
151
+ declare const DEFAULT_MARGINS: {
152
+ readonly top: 8;
153
+ readonly right: 8;
154
+ readonly bottom: 24;
155
+ readonly left: 36;
156
+ };
157
+ /** Margins for plain (chrome-less) charts — just enough to keep strokes unclipped. */
158
+ declare const PLAIN_MARGINS: {
159
+ readonly top: 2;
160
+ readonly right: 2;
161
+ readonly bottom: 2;
162
+ readonly left: 2;
163
+ };
164
+ type AnyScale = LinearScale | BandScale | LogScale | TimeScale;
165
+ interface AxisProps {
166
+ scale: AnyScale;
167
+ orientation: 'x' | 'y';
168
+ length: number;
169
+ format?: (value: number | string | Date) => string;
170
+ tickCount?: number;
171
+ transform?: string;
172
+ }
173
+ declare function Axis({
174
+ scale,
175
+ orientation,
176
+ length,
177
+ format,
178
+ tickCount,
179
+ transform
180
+ }: AxisProps): import("react").JSX.Element;
181
+ interface GridLinesProps {
182
+ scale: LinearScale;
183
+ orientation: 'x' | 'y';
184
+ length: number;
185
+ tickCount?: number;
186
+ transform?: string;
187
+ }
188
+ declare function GridLines({
189
+ scale,
190
+ orientation,
191
+ length,
192
+ tickCount,
193
+ transform
194
+ }: GridLinesProps): import("react").JSX.Element;
195
+ interface LegendSeries {
196
+ id: string;
197
+ label: string;
198
+ color: string;
199
+ }
200
+ interface LegendProps {
201
+ series: readonly LegendSeries[];
202
+ hidden: Signal<Set<string>>;
203
+ }
204
+ declare function Legend({
205
+ series,
206
+ hidden
207
+ }: LegendProps): import("react").JSX.Element;
208
+ interface LineChartSeries<Datum> {
209
+ id: string;
210
+ label: string;
211
+ data: readonly Datum[];
212
+ color?: string;
213
+ }
214
+ interface LineChartProps<Datum = {
215
+ x: number;
216
+ y: number;
217
+ }> {
218
+ series: readonly LineChartSeries<Datum>[];
219
+ x: (d: Datum) => number | Date;
220
+ y: (d: Datum) => number;
221
+ title: string;
222
+ description?: string;
223
+ curve?: 'linear' | 'monotone';
224
+ width?: number;
225
+ height?: number;
226
+ xTicks?: number;
227
+ yTicks?: number;
228
+ legend?: boolean;
229
+ tooltip?: boolean;
230
+ formatTooltip?: (datum: Datum, series: LineChartSeries<Datum>) => string;
231
+ className?: string;
232
+ /** Render only the marks — no axes, grid lines, or legend. For micro/inline charts. */
233
+ plain?: boolean;
234
+ }
235
+ declare function LineChart<Datum = {
236
+ x: number;
237
+ y: number;
238
+ }>({
239
+ series,
240
+ x,
241
+ y,
242
+ title,
243
+ description,
244
+ curve,
245
+ width: fixedWidth,
246
+ height,
247
+ xTicks,
248
+ yTicks,
249
+ legend,
250
+ tooltip,
251
+ formatTooltip,
252
+ className,
253
+ plain
254
+ }: LineChartProps<Datum>): import("react").JSX.Element;
255
+ interface AreaChartSeries<Datum> {
256
+ id: string;
257
+ label: string;
258
+ data: readonly Datum[];
259
+ color?: string;
260
+ }
261
+ interface AreaChartProps<Datum = {
262
+ x: number;
263
+ y: number;
264
+ }> {
265
+ series: readonly AreaChartSeries<Datum>[];
266
+ x: (d: Datum) => number;
267
+ y: (d: Datum) => number;
268
+ title: string;
269
+ description?: string;
270
+ stacked?: boolean;
271
+ curve?: 'linear' | 'monotone';
272
+ width?: number;
273
+ height?: number;
274
+ xTicks?: number;
275
+ yTicks?: number;
276
+ legend?: boolean;
277
+ tooltip?: boolean;
278
+ className?: string;
279
+ /** Render only the marks — no axes, grid lines, or legend. For micro/inline charts. */
280
+ plain?: boolean;
281
+ }
282
+ declare function AreaChart<Datum = {
283
+ x: number;
284
+ y: number;
285
+ }>({
286
+ series,
287
+ x,
288
+ y,
289
+ title,
290
+ description,
291
+ stacked,
292
+ curve,
293
+ width: fixedWidth,
294
+ height,
295
+ xTicks,
296
+ yTicks,
297
+ legend,
298
+ tooltip,
299
+ className,
300
+ plain
301
+ }: 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
+ interface PieChartDatum {
350
+ id: string;
351
+ label: string;
352
+ value: number;
353
+ color?: string;
354
+ }
355
+ interface PieChartProps {
356
+ data: readonly PieChartDatum[];
357
+ title: string;
358
+ description?: string;
359
+ donut?: boolean;
360
+ width?: number;
361
+ height?: number;
362
+ legend?: boolean;
363
+ className?: string;
364
+ /** Render only the marks — no legend. For micro/inline charts. */
365
+ plain?: boolean;
366
+ }
367
+ declare function PieChart({
368
+ data,
369
+ title,
370
+ description,
371
+ donut,
372
+ width: fixedWidth,
373
+ height,
374
+ legend,
375
+ className,
376
+ plain
377
+ }: PieChartProps): import("react").JSX.Element;
378
+ interface ScatterDatum {
379
+ x: number;
380
+ y: number;
381
+ r?: number;
382
+ }
383
+ interface ScatterChartSeries {
384
+ id: string;
385
+ label: string;
386
+ data: readonly ScatterDatum[];
387
+ color?: string;
388
+ }
389
+ interface ScatterChartProps {
390
+ series: readonly ScatterChartSeries[];
391
+ title: string;
392
+ description?: string;
393
+ r?: number | ((d: ScatterDatum) => number);
394
+ width?: number;
395
+ height?: number;
396
+ xTicks?: number;
397
+ yTicks?: number;
398
+ legend?: boolean;
399
+ tooltip?: boolean;
400
+ className?: string;
401
+ /** Render only the marks — no axes, grid lines, or legend. For micro/inline charts. */
402
+ plain?: boolean;
403
+ }
404
+ declare function ScatterChart({
405
+ series,
406
+ title,
407
+ description,
408
+ r: rProp,
409
+ width: fixedWidth,
410
+ height,
411
+ xTicks,
412
+ yTicks,
413
+ legend,
414
+ tooltip,
415
+ className,
416
+ plain
417
+ }: ScatterChartProps): import("react").JSX.Element;
418
+ interface SparklineProps {
419
+ data: readonly number[];
420
+ width?: number;
421
+ height?: number;
422
+ label: string;
423
+ color?: string;
424
+ endDot?: boolean;
425
+ }
426
+ declare function Sparkline({
427
+ data,
428
+ width,
429
+ height,
430
+ label,
431
+ color,
432
+ endDot
433
+ }: SparklineProps): import("react").JSX.Element;
434
+ interface MeterThresholds {
435
+ warning?: number;
436
+ critical?: number;
437
+ }
438
+ interface MeterProps {
439
+ value: number;
440
+ min?: number;
441
+ max?: number;
442
+ label: string;
443
+ variant?: 'bar' | 'gauge';
444
+ thresholds?: MeterThresholds;
445
+ width?: number;
446
+ height?: number;
447
+ }
448
+ declare function Meter({
449
+ value,
450
+ min,
451
+ max,
452
+ label,
453
+ variant,
454
+ thresholds,
455
+ width,
456
+ height
457
+ }: MeterProps): import("react").JSX.Element;
458
+ interface KpiProps {
459
+ value: string | number;
460
+ label: string;
461
+ delta?: number;
462
+ deltaLabel?: string;
463
+ icon?: ReactNode;
464
+ sparkline?: readonly number[];
465
+ className?: string;
466
+ }
467
+ declare function Kpi({
468
+ value,
469
+ label,
470
+ delta,
471
+ deltaLabel,
472
+ icon,
473
+ sparkline,
474
+ className
475
+ }: KpiProps): import("react").JSX.Element;
476
+ interface HistogramProps {
477
+ data: number[];
478
+ bins?: number;
479
+ title: string;
480
+ label: string;
481
+ description?: string;
482
+ width?: number;
483
+ height?: number;
484
+ className?: string;
485
+ /** Render only the marks — no axes or grid lines. For micro/inline charts. */
486
+ plain?: boolean;
487
+ }
488
+ declare function Histogram({
489
+ data,
490
+ bins,
491
+ title,
492
+ label: _label,
493
+ description,
494
+ width: fixedWidth,
495
+ height,
496
+ className,
497
+ plain
498
+ }: HistogramProps): import("react").JSX.Element;
499
+ interface BoxplotSeries {
500
+ id: string;
501
+ label: string;
502
+ values: number[];
503
+ }
504
+ interface BoxplotProps {
505
+ series: BoxplotSeries[];
506
+ title: string;
507
+ description?: string;
508
+ width?: number;
509
+ height?: number;
510
+ className?: string;
511
+ /** Render only the marks — no axes. For micro/inline charts. */
512
+ plain?: boolean;
513
+ }
514
+ declare function Boxplot({
515
+ series,
516
+ title,
517
+ description,
518
+ width: fixedWidth,
519
+ height,
520
+ className,
521
+ plain
522
+ }: BoxplotProps): import("react").JSX.Element;
523
+ interface BubbleDatum {
524
+ x: number;
525
+ y: number;
526
+ size: number;
527
+ }
528
+ interface BubbleSeries {
529
+ name: string;
530
+ data: BubbleDatum[];
531
+ }
532
+ interface BubbleChartProps {
533
+ series: BubbleSeries[];
534
+ title: string;
535
+ description?: string;
536
+ width?: number;
537
+ height?: number;
538
+ tooltip?: boolean;
539
+ className?: string;
540
+ /** Render only the marks — no axes or grid lines. For micro/inline charts. */
541
+ plain?: boolean;
542
+ }
543
+ declare function BubbleChart({
544
+ series,
545
+ title,
546
+ description,
547
+ width: fixedWidth,
548
+ height,
549
+ tooltip,
550
+ className,
551
+ plain
552
+ }: BubbleChartProps): import("react").JSX.Element;
553
+ interface ComboChartBar {
554
+ label: string;
555
+ value: number;
556
+ }
557
+ interface ComboChartPoint {
558
+ x: number;
559
+ y: number;
560
+ }
561
+ interface ComboChartProps {
562
+ bars: ComboChartBar[];
563
+ line: ComboChartPoint[];
564
+ title: string;
565
+ description?: string;
566
+ secondAxis?: boolean;
567
+ width?: number;
568
+ height?: number;
569
+ tooltip?: boolean;
570
+ className?: string;
571
+ /** Render only the marks — no axes or grid lines. For micro/inline charts. */
572
+ plain?: boolean;
573
+ }
574
+ declare function ComboChart({
575
+ bars,
576
+ line,
577
+ title,
578
+ description,
579
+ secondAxis,
580
+ width: fixedWidth,
581
+ height,
582
+ tooltip,
583
+ className,
584
+ plain
585
+ }: ComboChartProps): import("react").JSX.Element;
586
+ interface HeatmapDatum {
587
+ x: string;
588
+ y: string;
589
+ value: number;
590
+ }
591
+ interface HeatmapProps {
592
+ data: HeatmapDatum[];
593
+ title: string;
594
+ description?: string;
595
+ width?: number;
596
+ height?: number;
597
+ className?: string;
598
+ /** Render only the marks — no axes. For micro/inline charts. */
599
+ plain?: boolean;
600
+ }
601
+ declare function Heatmap({
602
+ data,
603
+ title,
604
+ description,
605
+ width: fixedWidth,
606
+ height,
607
+ className,
608
+ plain
609
+ }: HeatmapProps): import("react").JSX.Element;
610
+ interface TreemapDatum {
611
+ id: string;
612
+ label: string;
613
+ value: number;
614
+ }
615
+ interface TreemapProps {
616
+ data: TreemapDatum[];
617
+ title: string;
618
+ description?: string;
619
+ width?: number;
620
+ height?: number;
621
+ className?: string;
622
+ /** Render only the colored rects — no text labels. For micro/inline charts. */
623
+ plain?: boolean;
624
+ }
625
+ declare function Treemap({
626
+ data,
627
+ title,
628
+ description,
629
+ width: fixedWidth,
630
+ height,
631
+ className,
632
+ plain
633
+ }: TreemapProps): import("react").JSX.Element;
634
+ interface RadarSeries {
635
+ id: string;
636
+ label: string;
637
+ values: number[];
638
+ }
639
+ interface RadarProps {
640
+ axes: string[];
641
+ series: RadarSeries[];
642
+ max?: number;
643
+ title: string;
644
+ description?: string;
645
+ width?: number;
646
+ height?: number;
647
+ className?: string;
648
+ /** Render only the data polygons — no rings, spokes, or axis labels. For micro/inline charts. */
649
+ plain?: boolean;
650
+ }
651
+ declare function Radar({
652
+ axes,
653
+ series,
654
+ max,
655
+ title,
656
+ description,
657
+ width: fixedWidth,
658
+ height,
659
+ className,
660
+ plain
661
+ }: RadarProps): import("react").JSX.Element;
662
+ interface BulletProps {
663
+ value: number;
664
+ target: number;
665
+ ranges: number[];
666
+ label: string;
667
+ min?: number;
668
+ max?: number;
669
+ width?: number;
670
+ height?: number;
671
+ className?: string;
672
+ }
673
+ declare function Bullet({
674
+ value,
675
+ target,
676
+ ranges,
677
+ label,
678
+ min,
679
+ max,
680
+ width,
681
+ height,
682
+ className
683
+ }: 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 };