livegauge 0.0.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.
- package/LICENSE +21 -0
- package/README.md +160 -0
- package/dist/index.cjs +1080 -0
- package/dist/index.d.cts +51 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +1053 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Breno Polanski
|
|
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,160 @@
|
|
|
1
|
+
# Livegauge
|
|
2
|
+
|
|
3
|
+
Real-time animated gauge chart for React. Canvas-rendered, 60fps, zero CSS imports.
|
|
4
|
+
|
|
5
|
+
> _Inspired by the [Liveline](https://github.com/benjitaylor/liveline) project by [@benjitaylor](https://github.com/benjitaylor)._
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add livegauge
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Peer dependency: `react >=18`.
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { Gauge } from 'livegauge';
|
|
19
|
+
|
|
20
|
+
function Dashboard() {
|
|
21
|
+
const [speed, setSpeed] = useState(42);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div style={{ width: 300, height: 200 }}>
|
|
25
|
+
<Gauge value={speed} min={0} max={100} color="#3b82f6" theme="dark" />
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The component fills its parent container. Set a width and height on the parent.
|
|
32
|
+
|
|
33
|
+
## Props
|
|
34
|
+
|
|
35
|
+
**Data**
|
|
36
|
+
|
|
37
|
+
| Prop | Type | Default | Description |
|
|
38
|
+
| ------- | -------- | -------- | ------------------- |
|
|
39
|
+
| `value` | `number` | required | Current gauge value |
|
|
40
|
+
| `min` | `number` | `0` | Minimum value |
|
|
41
|
+
| `max` | `number` | `100` | Maximum value |
|
|
42
|
+
|
|
43
|
+
**Appearance**
|
|
44
|
+
|
|
45
|
+
| Prop | Type | Default | Description |
|
|
46
|
+
| ------------ | ---------------------- | ----------- | ------------------------------------------------------- |
|
|
47
|
+
| `theme` | `'light' \| 'dark'` | `'dark'` | Color scheme |
|
|
48
|
+
| `color` | `string` | `'#3b82f6'` | Accent color — arc fill, dot, glow derived from this |
|
|
49
|
+
| `pointer` | `'needle' \| 'circle'` | `'needle'` | Pointer style |
|
|
50
|
+
| `zones` | `GaugeZone[]` | — | Color segments `{ from, to, color }` on the arc |
|
|
51
|
+
| `ticks` | `boolean \| number` | `true` | Tick marks. `true` = auto count, `number` = exact count |
|
|
52
|
+
| `tickLabels` | `boolean` | `false` | Value labels next to tick marks |
|
|
53
|
+
| `arcWidth` | `number` | `12` | Stroke width of the arc in pixels |
|
|
54
|
+
| `showValue` | `boolean` | `true` | Large centered value display |
|
|
55
|
+
| `label` | `string` | — | Text below the value (e.g. "km/h", "RPM") |
|
|
56
|
+
|
|
57
|
+
**Animation**
|
|
58
|
+
|
|
59
|
+
| Prop | Type | Default | Description |
|
|
60
|
+
| ----------- | ------------------------- | ------- | ------------------------------------------------------------------- |
|
|
61
|
+
| `momentum` | `boolean \| Momentum` | `true` | Dot/glow by direction. `true` = auto, or `'up' \| 'down' \| 'flat'` |
|
|
62
|
+
| `degen` | `boolean \| DegenOptions` | `false` | Burst particles + shake on momentum swings |
|
|
63
|
+
| `loading` | `boolean` | `false` | Sweeping arc animation while waiting for data |
|
|
64
|
+
| `lerpSpeed` | `number` | `0.08` | Interpolation speed (0–1) |
|
|
65
|
+
| `dot` | `boolean` | `false` | Show dot at needle tip |
|
|
66
|
+
| `pulse` | `boolean` | `false` | Pulsing ring on needle tip dot |
|
|
67
|
+
| `tooltip` | `boolean` | `false` | Show value tooltip on hover |
|
|
68
|
+
|
|
69
|
+
**Formatting**
|
|
70
|
+
|
|
71
|
+
| Prop | Type | Default | Description |
|
|
72
|
+
| ------------- | ----------------------- | -------------- | --------------------- |
|
|
73
|
+
| `formatValue` | `(v: number) => string` | `v.toFixed(0)` | Value label formatter |
|
|
74
|
+
|
|
75
|
+
**Advanced**
|
|
76
|
+
|
|
77
|
+
| Prop | Type | Default | Description |
|
|
78
|
+
| ------------ | --------------- | ------------- | --------------------------------- |
|
|
79
|
+
| `startAngle` | `number` | `Math.PI` | Arc start angle in radians (left) |
|
|
80
|
+
| `endAngle` | `number` | `Math.PI * 2` | Arc end angle in radians (right) |
|
|
81
|
+
| `className` | `string` | — | Container class |
|
|
82
|
+
| `style` | `CSSProperties` | — | Container styles |
|
|
83
|
+
|
|
84
|
+
## Examples
|
|
85
|
+
|
|
86
|
+
### Basic gauge
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
<Gauge value={72} color="#3b82f6" theme="dark" />
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### With color zones
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
<Gauge
|
|
96
|
+
value={speed}
|
|
97
|
+
min={0}
|
|
98
|
+
max={200}
|
|
99
|
+
color="#22c55e"
|
|
100
|
+
zones={[
|
|
101
|
+
{ from: 0, to: 80, color: '#22c55e' },
|
|
102
|
+
{ from: 80, to: 140, color: '#f59e0b' },
|
|
103
|
+
{ from: 140, to: 200, color: '#ef4444' },
|
|
104
|
+
]}
|
|
105
|
+
label="km/h"
|
|
106
|
+
formatValue={(v) => v.toFixed(0)}
|
|
107
|
+
/>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Degen mode (particles + shake)
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
<Gauge
|
|
114
|
+
value={price}
|
|
115
|
+
min={0}
|
|
116
|
+
max={1000}
|
|
117
|
+
color="#f7931a"
|
|
118
|
+
formatValue={(v) => `$${v.toFixed(2)}`}
|
|
119
|
+
degen
|
|
120
|
+
/>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Tick labels
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
<Gauge
|
|
127
|
+
value={temperature}
|
|
128
|
+
min={-20}
|
|
129
|
+
max={50}
|
|
130
|
+
color="#ef4444"
|
|
131
|
+
ticks={8}
|
|
132
|
+
label="°C"
|
|
133
|
+
theme="light"
|
|
134
|
+
tickLabels
|
|
135
|
+
/>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Loading state
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
<Gauge value={0} loading={isConnecting} color="#8b5cf6" />
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## How It Works
|
|
147
|
+
|
|
148
|
+
- **Canvas rendering** — single `<canvas>` element, no DOM nodes per data point
|
|
149
|
+
- **requestAnimationFrame** loop pauses when the tab is hidden
|
|
150
|
+
- **Frame-rate-independent lerp** on value, range, and glow animations
|
|
151
|
+
- **ResizeObserver** tracks container size — no per-frame layout reads
|
|
152
|
+
- **Theme derivation** — full palette from one accent color + light/dark mode
|
|
153
|
+
|
|
154
|
+
No CSS imports. No external dependencies beyond React.
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
© 2026 Breno Polanski
|
|
159
|
+
|
|
160
|
+
Licensed under MIT
|