react-scale-break-chart 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Angga Fardana
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # react-scale-break-chart
2
+
3
+ A zero-dependency React SVG bar chart that automatically compresses extreme value ranges behind a zigzag break indicator so both small and large values remain readable side-by-side.
4
+
5
+ [![CI](https://github.com/afardana/react-scale-break-chart/actions/workflows/ci.yml/badge.svg)](https://github.com/afardana/react-scale-break-chart/actions/workflows/ci.yml)
6
+ [![npm](https://img.shields.io/npm/v/react-scale-break-chart)](https://www.npmjs.com/package/react-scale-break-chart)
7
+
8
+ ## Features
9
+
10
+ - **Automatic scale break** — detects when one series dominates others by an order of magnitude and compresses the upper region behind a styled zigzag indicator
11
+ - **Upper-region zoom** — when dominant values are tightly clustered (< 10% variance), the chart zooms into the top of the Y-axis so small differences are still visible
12
+ - **Non-break zoom** — when all values are clustered (e.g. 8.029M – 8.068M), the Y-axis automatically narrows around the data range rather than starting at 0
13
+ - **Transition zone** — series that cross the break but fall below the zoomed region get proportional height above the break band
14
+ - **Responsive** — auto-sizes to container width via `ResizeObserver`; supports `height="auto"` for container-driven height
15
+ - **Tooltips & hover** — built-in hover effects with a clean tooltip; no external charting library needed
16
+ - **Tree-shakeable** — ships ESM + CJS with TypeScript declarations
17
+ - **Minimal footprint** — ~28 KB min (no D3, no Recharts)
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ npm install react-scale-break-chart
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ```tsx
28
+ import { ScaleBreakBarChart } from 'react-scale-break-chart';
29
+
30
+ const data = [
31
+ { name: 'Jan', otc: 158_000, voice: 2_711_000, fbb: 7_286_000 },
32
+ { name: 'Feb', otc: 146_000, voice: 2_673_000, fbb: 7_297_000 },
33
+ { name: 'Mar', otc: 152_000, voice: 2_650_000, fbb: 7_310_000 },
34
+ ];
35
+
36
+ const series = [
37
+ { dataKey: 'otc', label: 'OTC', color: '#F5A623' },
38
+ { dataKey: 'voice', label: 'Voice', color: '#E74C3C' },
39
+ { dataKey: 'fbb', label: 'Fixed Broadband', color: '#5B9BD5' },
40
+ ];
41
+
42
+ function App() {
43
+ return (
44
+ <ScaleBreakBarChart
45
+ data={data}
46
+ series={series}
47
+ height={400}
48
+ breakThreshold={5}
49
+ formatValue={(v) => v.toLocaleString('id-ID')}
50
+ />
51
+ );
52
+ }
53
+ ```
54
+
55
+ ## Props
56
+
57
+ | Prop | Type | Default | Description |
58
+ |------|------|---------|-------------|
59
+ | `data` | `ScaleBreakDataPoint[]` | — | Array of data points; one per bar group |
60
+ | `series` | `SeriesConfig[]` | — | Series definitions (dataKey, label, color) |
61
+ | `height` | `number \| 'auto'` | `350` | Fixed px height or `'auto'` for container-driven |
62
+ | `breakThreshold` | `number` | `5` | Ratio above which the dominant series triggers a scale break |
63
+ | `formatValue` | `(n: number) => string` | `String` | Formatter for value labels & tooltip |
64
+ | `className` | `string` | — | Additional className on root wrapper |
65
+
66
+ ## How the Scale Break Works
67
+
68
+ ```
69
+ ┌────────────────────────────────────┐
70
+ │ Upper region │ ← zoomed scale for dominant series
71
+ │ ╱╲╱╲╱╲╱╲╱╲╱╲╱╲ break indicator │
72
+ │ Lower region │ ← proportional scale for all series
73
+ │──────────────────────────── 0 ─────│
74
+ └────────────────────────────────────┘
75
+ ```
76
+
77
+ 1. **Break detection**: When `max(series₁) / max(series₂) > breakThreshold`, the chart splits the Y-axis
78
+ 2. **Lower region** (40%): Shows small values proportionally
79
+ 3. **Upper region** (60%): Shows large values in a compressed (or zoomed) scale
80
+ 4. **Transition zone**: If the upper region is zoomed, bars between `lowerMax` and `upperMin` get sqrt-scaled height in a reserved 15% transition area
81
+
82
+ ## Development
83
+
84
+ ```bash
85
+ npm install
86
+ npm run build # tsup → dist/
87
+ npm run typecheck # tsc --noEmit
88
+ npm test # vitest
89
+ npm run dev # tsup --watch
90
+ ```
91
+
92
+ ## License
93
+
94
+ [MIT](./LICENSE) © Angga Fardana
@@ -0,0 +1,46 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ /**
4
+ * Scale-Break Bar Chart — Type definitions
5
+ *
6
+ * A custom SVG chart that compresses dominant values with zigzag break
7
+ * indicators so small values remain clearly visible alongside large ones.
8
+ * Supports both stacked and grouped (side-by-side) bar modes.
9
+ */
10
+ /** A single data point on the x-axis (e.g., one month). */
11
+ interface ScaleBreakDataPoint {
12
+ /** Display label for the x-axis (e.g. "January"). */
13
+ name: string;
14
+ /** Dynamic numeric keys matching `SeriesConfig.dataKey`. */
15
+ [key: string]: string | number;
16
+ }
17
+ /** Configuration for one segment / series in the bar chart. */
18
+ interface SeriesConfig {
19
+ /** Property name on the data point to read the value from. */
20
+ dataKey: string;
21
+ /** Human-readable label shown in legend & tooltip. */
22
+ label: string;
23
+ /** Fill colour (hex or CSS). */
24
+ color: string;
25
+ }
26
+ /** Props accepted by the `<ScaleBreakBarChart>` component. */
27
+ interface ScaleBreakBarChartProps {
28
+ /** Array of data points; one per bar group. */
29
+ data: ScaleBreakDataPoint[];
30
+ /** Series definitions. */
31
+ series: SeriesConfig[];
32
+ /** Chart height in px (default 350). Use `'auto'` to fill container height. */
33
+ height?: number | 'auto';
34
+ /** Ratio above which the dominant segment triggers a scale break (default 5). */
35
+ breakThreshold?: number;
36
+ /** Minimum pixel height for non-dominant segments so they remain visible (default 32). */
37
+ minSegmentPx?: number;
38
+ /** Value formatter for labels & tooltip (default `String`). */
39
+ formatValue?: (value: number) => string;
40
+ /** Additional className on the root wrapper. */
41
+ className?: string;
42
+ }
43
+
44
+ declare function ScaleBreakBarChart({ data, series, height, breakThreshold, formatValue, className, }: ScaleBreakBarChartProps): react_jsx_runtime.JSX.Element;
45
+
46
+ export { ScaleBreakBarChart, type ScaleBreakBarChartProps, type ScaleBreakDataPoint, type SeriesConfig };
@@ -0,0 +1,46 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ /**
4
+ * Scale-Break Bar Chart — Type definitions
5
+ *
6
+ * A custom SVG chart that compresses dominant values with zigzag break
7
+ * indicators so small values remain clearly visible alongside large ones.
8
+ * Supports both stacked and grouped (side-by-side) bar modes.
9
+ */
10
+ /** A single data point on the x-axis (e.g., one month). */
11
+ interface ScaleBreakDataPoint {
12
+ /** Display label for the x-axis (e.g. "January"). */
13
+ name: string;
14
+ /** Dynamic numeric keys matching `SeriesConfig.dataKey`. */
15
+ [key: string]: string | number;
16
+ }
17
+ /** Configuration for one segment / series in the bar chart. */
18
+ interface SeriesConfig {
19
+ /** Property name on the data point to read the value from. */
20
+ dataKey: string;
21
+ /** Human-readable label shown in legend & tooltip. */
22
+ label: string;
23
+ /** Fill colour (hex or CSS). */
24
+ color: string;
25
+ }
26
+ /** Props accepted by the `<ScaleBreakBarChart>` component. */
27
+ interface ScaleBreakBarChartProps {
28
+ /** Array of data points; one per bar group. */
29
+ data: ScaleBreakDataPoint[];
30
+ /** Series definitions. */
31
+ series: SeriesConfig[];
32
+ /** Chart height in px (default 350). Use `'auto'` to fill container height. */
33
+ height?: number | 'auto';
34
+ /** Ratio above which the dominant segment triggers a scale break (default 5). */
35
+ breakThreshold?: number;
36
+ /** Minimum pixel height for non-dominant segments so they remain visible (default 32). */
37
+ minSegmentPx?: number;
38
+ /** Value formatter for labels & tooltip (default `String`). */
39
+ formatValue?: (value: number) => string;
40
+ /** Additional className on the root wrapper. */
41
+ className?: string;
42
+ }
43
+
44
+ declare function ScaleBreakBarChart({ data, series, height, breakThreshold, formatValue, className, }: ScaleBreakBarChartProps): react_jsx_runtime.JSX.Element;
45
+
46
+ export { ScaleBreakBarChart, type ScaleBreakBarChartProps, type ScaleBreakDataPoint, type SeriesConfig };