liveline 0.0.0 → 0.0.2
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 +175 -0
- package/dist/index.cjs +1796 -0
- package/dist/index.d.cts +79 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.js +1769 -0
- package/package.json +61 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Benji Taylor
|
|
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,175 @@
|
|
|
1
|
+
# Liveline
|
|
2
|
+
|
|
3
|
+
Real-time animated line chart for React. Canvas-rendered, 60fps, zero CSS imports.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add liveline
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Peer dependency: `react >=18`.
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { Liveline } from 'liveline'
|
|
17
|
+
import type { LivelinePoint } from 'liveline'
|
|
18
|
+
|
|
19
|
+
function Chart() {
|
|
20
|
+
const [data, setData] = useState<LivelinePoint[]>([])
|
|
21
|
+
const [value, setValue] = useState(0)
|
|
22
|
+
|
|
23
|
+
// Feed data from WebSocket, polling, etc.
|
|
24
|
+
// Each point: { time: unixSeconds, value: number }
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div style={{ height: 300 }}>
|
|
28
|
+
<Liveline data={data} value={value} color="#3b82f6" theme="dark" />
|
|
29
|
+
</div>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The component fills its parent container. Set a height on the parent. Pass `data` as a growing array of points and `value` as the latest number — Liveline handles smooth interpolation between updates.
|
|
35
|
+
|
|
36
|
+
## Props
|
|
37
|
+
|
|
38
|
+
**Data**
|
|
39
|
+
|
|
40
|
+
| Prop | Type | Default | Description |
|
|
41
|
+
|------|------|---------|-------------|
|
|
42
|
+
| `data` | `LivelinePoint[]` | required | Array of `{ time, value }` points |
|
|
43
|
+
| `value` | `number` | required | Latest value (smoothly interpolated) |
|
|
44
|
+
|
|
45
|
+
**Appearance**
|
|
46
|
+
|
|
47
|
+
| Prop | Type | Default | Description |
|
|
48
|
+
|------|------|---------|-------------|
|
|
49
|
+
| `theme` | `'light' \| 'dark'` | `'dark'` | Color scheme |
|
|
50
|
+
| `color` | `string` | `'#3b82f6'` | Accent color — all palette colors derived from this |
|
|
51
|
+
| `grid` | `boolean` | `true` | Y-axis grid lines + labels |
|
|
52
|
+
| `badge` | `boolean` | `true` | Value pill tracking chart tip |
|
|
53
|
+
| `badgeVariant` | `'default' \| 'minimal'` | `'default'` | Badge style: accent-colored or white with grey text |
|
|
54
|
+
| `badgeTail` | `boolean` | `true` | Pointed tail on badge pill |
|
|
55
|
+
| `fill` | `boolean` | `true` | Gradient under the curve |
|
|
56
|
+
| `pulse` | `boolean` | `true` | Pulsing ring on live dot |
|
|
57
|
+
|
|
58
|
+
**Features**
|
|
59
|
+
|
|
60
|
+
| Prop | Type | Default | Description |
|
|
61
|
+
|------|------|---------|-------------|
|
|
62
|
+
| `momentum` | `boolean \| Momentum` | `true` | Dot glow + arrows. `true` = auto-detect, or `'up' \| 'down' \| 'flat'` |
|
|
63
|
+
| `scrub` | `boolean` | `true` | Crosshair scrubbing on hover |
|
|
64
|
+
| `exaggerate` | `boolean` | `false` | Tight Y-axis — small moves fill chart height |
|
|
65
|
+
| `showValue` | `boolean` | `false` | Large live value overlay (60fps DOM update, no re-renders) |
|
|
66
|
+
| `valueMomentumColor` | `boolean` | `false` | Color the value text green/red by momentum |
|
|
67
|
+
| `degen` | `boolean \| DegenOptions` | `false` | Burst particles + chart shake on momentum swings |
|
|
68
|
+
|
|
69
|
+
**Time**
|
|
70
|
+
|
|
71
|
+
| Prop | Type | Default | Description |
|
|
72
|
+
|------|------|---------|-------------|
|
|
73
|
+
| `window` | `number` | `30` | Visible time window in seconds |
|
|
74
|
+
| `windows` | `WindowOption[]` | — | Time horizon buttons `[{ label, secs }]` |
|
|
75
|
+
| `onWindowChange` | `(secs) => void` | — | Called when a window button is clicked |
|
|
76
|
+
| `windowStyle` | `'default' \| 'rounded' \| 'text'` | `'default'` | Window button visual style |
|
|
77
|
+
|
|
78
|
+
**Crosshair**
|
|
79
|
+
|
|
80
|
+
| Prop | Type | Default | Description |
|
|
81
|
+
|------|------|---------|-------------|
|
|
82
|
+
| `tooltipY` | `number` | `14` | Vertical offset for crosshair tooltip text |
|
|
83
|
+
| `tooltipOutline` | `boolean` | `true` | Stroke outline on tooltip text for readability |
|
|
84
|
+
|
|
85
|
+
**Orderbook**
|
|
86
|
+
|
|
87
|
+
| Prop | Type | Default | Description |
|
|
88
|
+
|------|------|---------|-------------|
|
|
89
|
+
| `orderbook` | `OrderbookData` | — | Bid/ask depth stream `{ bids, asks }` |
|
|
90
|
+
|
|
91
|
+
**Advanced**
|
|
92
|
+
|
|
93
|
+
| Prop | Type | Default | Description |
|
|
94
|
+
|------|------|---------|-------------|
|
|
95
|
+
| `referenceLine` | `ReferenceLine` | — | Horizontal reference line `{ value, label? }` |
|
|
96
|
+
| `formatValue` | `(v: number) => string` | `v.toFixed(2)` | Value label formatter |
|
|
97
|
+
| `formatTime` | `(t: number) => string` | `HH:MM:SS` | Time axis formatter |
|
|
98
|
+
| `lerpSpeed` | `number` | `0.08` | Interpolation speed (0–1) |
|
|
99
|
+
| `padding` | `Padding` | `{ top: 12, right: 80, bottom: 28, left: 12 }` | Chart padding override |
|
|
100
|
+
| `onHover` | `(point \| null) => void` | — | Hover callback with `{ time, value, x, y }` |
|
|
101
|
+
| `cursor` | `string` | `'crosshair'` | CSS cursor on canvas hover |
|
|
102
|
+
| `className` | `string` | — | Container class |
|
|
103
|
+
| `style` | `CSSProperties` | — | Container styles |
|
|
104
|
+
|
|
105
|
+
## Examples
|
|
106
|
+
|
|
107
|
+
### Basic (line + badge)
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
<Liveline data={data} value={value} color="#3b82f6" theme="dark" />
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Crypto-style (momentum + degen + exaggerate)
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
<Liveline
|
|
117
|
+
data={data}
|
|
118
|
+
value={value}
|
|
119
|
+
color="#f7931a"
|
|
120
|
+
exaggerate
|
|
121
|
+
degen
|
|
122
|
+
showValue
|
|
123
|
+
valueMomentumColor
|
|
124
|
+
formatValue={(v) => `$${v.toLocaleString('en-US', { minimumFractionDigits: 2 })}`}
|
|
125
|
+
/>
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Dashboard (showValue + windows + no badge)
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
<Liveline
|
|
132
|
+
data={data}
|
|
133
|
+
value={value}
|
|
134
|
+
badge={false}
|
|
135
|
+
showValue
|
|
136
|
+
windows={[
|
|
137
|
+
{ label: '15s', secs: 15 },
|
|
138
|
+
{ label: '30s', secs: 30 },
|
|
139
|
+
{ label: '2m', secs: 120 },
|
|
140
|
+
{ label: '5m', secs: 300 },
|
|
141
|
+
]}
|
|
142
|
+
onWindowChange={(secs) => console.log('window:', secs)}
|
|
143
|
+
/>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Orderbook (orderbook data + particles)
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
<Liveline
|
|
150
|
+
data={data}
|
|
151
|
+
value={value}
|
|
152
|
+
color="#f7931a"
|
|
153
|
+
orderbook={{ bids: [[100, 2], [99, 5]], asks: [[101, 3], [102, 4]] }}
|
|
154
|
+
degen
|
|
155
|
+
showValue
|
|
156
|
+
/>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## How It Works
|
|
160
|
+
|
|
161
|
+
- **Canvas rendering** — single `<canvas>` element, no DOM nodes per data point
|
|
162
|
+
- **requestAnimationFrame** loop pauses when the tab is hidden
|
|
163
|
+
- **Catmull-Rom splines** for smooth curves through data points
|
|
164
|
+
- **Frame-rate-independent lerp** on value, Y-axis range, badge color, and scrub opacity
|
|
165
|
+
- **ResizeObserver** tracks container size — no per-frame layout reads
|
|
166
|
+
- **Theme derivation** — full palette from one accent color + light/dark mode
|
|
167
|
+
- **Binary search interpolation** for hover value lookup
|
|
168
|
+
|
|
169
|
+
No CSS imports. No external dependencies beyond React.
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
© 2026 Benji Taylor
|
|
174
|
+
|
|
175
|
+
Licensed under MIT
|