@wick-charts/react 0.3.2 → 0.3.4
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/README.md +18 -164
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +248 -67
- package/dist/index.js +2945 -2631
- package/package.json +2 -2
- package/src/ChartContainer.tsx +49 -1
- package/src/index.ts +1 -0
- package/src/ui/TimeAxis.tsx +6 -3
- package/src/ui/YAxis.tsx +4 -2
- package/src/ui/axisFade.ts +23 -0
package/README.md
CHANGED
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- Generated from README.tmpl.md — edit the template, not this file. -->
|
|
4
4
|
|
|
5
|
-
High-performance timeseries charts for **React**, **Vue**, and **Svelte**. Canvas-rendered, tree-shakeable,
|
|
5
|
+
High-performance timeseries charts for **React**, **Vue**, and **Svelte**. Canvas-rendered, tree-shakeable, zero runtime dependencies.
|
|
6
6
|
|
|
7
|
-
[Live Demo](https://mo4islona.github.io/wick-charts/)
|
|
7
|
+
[Live Demo](https://mo4islona.github.io/wick-charts/) · [Docs](https://mo4islona.github.io/wick-charts/#/api/chart-container)
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
|
-
- **Candlestick, Line, Bar, Pie** — all from one package
|
|
12
|
-
- **Real-time streaming** — append/update
|
|
13
|
-
- **22 built-in themes**
|
|
11
|
+
- **Candlestick, Line, Bar, Pie, Sparkline** — all from one package
|
|
12
|
+
- **Real-time streaming** — append/update at 60fps with coordinated animations
|
|
13
|
+
- **22 built-in themes** plus `createTheme()` for custom palettes
|
|
14
14
|
- **Interactive** — zoom, pan, crosshair, tooltips
|
|
15
15
|
- **Stacking** — normal and percent modes for line/bar
|
|
16
|
-
- **Custom-render
|
|
16
|
+
- **Custom-render slots** — keep the built-in positioning, replace the contents
|
|
17
17
|
- **Tree-shakeable** — import only what you use
|
|
18
|
-
- **Zero dependencies** — just your framework
|
|
18
|
+
- **Zero runtime dependencies** — just your framework
|
|
19
19
|
|
|
20
20
|
## Install
|
|
21
21
|
|
|
@@ -44,169 +44,23 @@ function Chart({ data }) {
|
|
|
44
44
|
}
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
##
|
|
47
|
+
## API
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|---|---|---|
|
|
51
|
-
| `CandlestickSeries` | `{ time, open, high, low, close, volume? }[]` | OHLC candlesticks with volume bars |
|
|
52
|
-
| `LineSeries` | `{ time, value }[][]` | Line/area charts, multi-layer, stacking |
|
|
53
|
-
| `BarSeries` | `{ time, value }[][]` | Histogram/bar charts, stacking |
|
|
54
|
-
| `PieSeries` | `{ label, value, color? }[]` | Pie and donut charts |
|
|
49
|
+
Every component, prop, type, and slot context lives in the docs site:
|
|
55
50
|
|
|
56
|
-
|
|
51
|
+
[mo4islona.github.io/wick-charts/#/api/chart-container](https://mo4islona.github.io/wick-charts/#/api/chart-container)
|
|
57
52
|
|
|
58
|
-
|
|
53
|
+
Start there for [ChartContainer](https://mo4islona.github.io/wick-charts/#/api/chart-container), then drill into the series ([Candlestick](https://mo4islona.github.io/wick-charts/#/api/candlestick-series), [Line](https://mo4islona.github.io/wick-charts/#/api/line-series), [Bar](https://mo4islona.github.io/wick-charts/#/api/bar-series), [Pie](https://mo4islona.github.io/wick-charts/#/api/pie-series), [Sparkline](https://mo4islona.github.io/wick-charts/#/api/sparkline)) and overlays ([Tooltip](https://mo4islona.github.io/wick-charts/#/api/tooltip), [InfoBar](https://mo4islona.github.io/wick-charts/#/api/info-bar), [Crosshair](https://mo4islona.github.io/wick-charts/#/api/crosshair), [Legend](https://mo4islona.github.io/wick-charts/#/api/legend), [YAxis](https://mo4islona.github.io/wick-charts/#/api/y-axis), [XAxis](https://mo4islona.github.io/wick-charts/#/api/x-axis), [Navigator](https://mo4islona.github.io/wick-charts/#/api/navigator), …).
|
|
59
54
|
|
|
60
|
-
|
|
61
|
-
|---|---|---|
|
|
62
|
-
| `Tooltip` | Floating glass tooltip near cursor on hover | `{ snapshots, time }` |
|
|
63
|
-
| `InfoBar` | Compact OHLC / values info bar hoisted above the canvas | `{ snapshots, time, isHover }` |
|
|
64
|
-
| `Title` | Chart title / subtitle bar hoisted above the canvas | — |
|
|
65
|
-
| `Crosshair` | Axis labels at cursor position | — |
|
|
66
|
-
| `YAxis` | Vertical price/value axis with animated ticks | — |
|
|
67
|
-
| `TimeAxis` | Horizontal time axis with animated ticks | — |
|
|
68
|
-
| `YLabel` | Floating price badge with dashed line | `{ value, y, bgColor, isLive, direction, format }` |
|
|
69
|
-
| `Legend` | Clickable legend with toggle/isolate modes | `{ items: LegendItem[] }` |
|
|
70
|
-
| `PieTooltip` | Tooltip for pie/donut hover | `{ info, format }` |
|
|
71
|
-
| `PieLegend` | Slice labels with values or percentages | `{ slices, mode, format }` |
|
|
55
|
+
## Bundle size
|
|
72
56
|
|
|
73
|
-
|
|
57
|
+
Tree-shaken React scenarios via `pnpm size` (esbuild, minified, browser target, React/ReactDOM external):
|
|
74
58
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
.filter((s) => s.seriesId === 'btc' || s.seriesId === 'eth')
|
|
81
|
-
.map((s) => (
|
|
82
|
-
<div key={s.id} style={{ color: s.color }}>
|
|
83
|
-
{s.label}: {s.data.close ?? s.data.value}
|
|
84
|
-
</div>
|
|
85
|
-
))
|
|
86
|
-
}
|
|
87
|
-
</Tooltip>
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
Each overlay has its own slot context (see the Slot ctx column above); the shape is consistent across frameworks for the same overlay.
|
|
91
|
-
|
|
92
|
-
### Public helpers (re-exported from each framework package)
|
|
93
|
-
|
|
94
|
-
- `buildHoverSnapshots(chart, { time, sort?, cacheKey })` / `buildLastSnapshots(chart, { sort?, cacheKey })` — structural-equality-cached snapshot arrays for building your own floating widgets. Calls with the same args return the **same reference** while the chart's overlay version is unchanged, so `React.memo` / Vue `computed` / Svelte `$:` skip renders on no-op mousemoves.
|
|
95
|
-
- `computeTooltipPosition({ x, y, chartWidth, chartHeight, tooltipWidth, tooltipHeight, offsetX?, offsetY? })` — flip + clamp positioning for a tooltip container you own.
|
|
96
|
-
- Types: `SeriesSnapshot`, `LegendItem`, `SliceInfo`, `HoverInfo`.
|
|
97
|
-
|
|
98
|
-
## Custom number formatting
|
|
99
|
-
|
|
100
|
-
Every numeric overlay accepts a `format` prop so you can override the default label rendering. Two shared helpers ship in each framework package (`@wick-charts/react`, `@wick-charts/vue`, `@wick-charts/svelte`):
|
|
101
|
-
|
|
102
|
-
- `formatCompact(v)` — K/M/B/T suffixes with adaptive precision. Default for `YAxis` (at ranges ≥ 1e6), `PieLegend`, `PieTooltip`, `Sparkline`.
|
|
103
|
-
- `formatPriceAdaptive(v)` — full-precision display that scales decimals to the value's magnitude. Default for `Tooltip` / `InfoBar` OHLC and line-value cells. Handles sub-cent prices (`0.00001234` → `"0.00001234"`, not `"0.00"`).
|
|
104
|
-
|
|
105
|
-
```tsx
|
|
106
|
-
import { Tooltip, YAxis, formatCompact } from '@wick-charts/react';
|
|
107
|
-
|
|
108
|
-
<YAxis format={(v) => `$${formatCompact(v)}`} />
|
|
109
|
-
<Tooltip format={(v, field) => field === 'volume' ? formatCompact(v) : v.toFixed(4)} />
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
Tooltip / InfoBar pass a `field` arg (`'open' | 'high' | 'low' | 'close' | 'volume' | 'value'`) so you can branch on which cell you're formatting. All other overlays receive a single `value: number`.
|
|
113
|
-
|
|
114
|
-
## Themes
|
|
115
|
-
|
|
116
|
-
22 built-in themes. Import only the ones you need (tree-shakable) and pass them to `ChartContainer` or `ThemeProvider` for global theming.
|
|
117
|
-
|
|
118
|
-
```tsx
|
|
119
|
-
import { catppuccin } from '@wick-charts/react';
|
|
120
|
-
|
|
121
|
-
// Dark: andromeda, ayuMirage, catppuccin, dracula, gruvbox, highContrast,
|
|
122
|
-
// materialPalenight, monokaiPro, nightOwl, oneDarkPro, panda
|
|
123
|
-
// Light: githubLight, handwritten, lavenderMist, lightPink, minimalLight, mintBreeze,
|
|
124
|
-
// peachCream, quietLight, rosePineDawn, sandDune, solarizedLight
|
|
125
|
-
|
|
126
|
-
<ChartContainer theme={catppuccin.theme}>
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
Create custom themes with `createTheme()`:
|
|
130
|
-
|
|
131
|
-
```tsx
|
|
132
|
-
import { createTheme } from '@wick-charts/react';
|
|
133
|
-
|
|
134
|
-
const myTheme = createTheme({
|
|
135
|
-
background: '#1a1b2e',
|
|
136
|
-
candlestick: {
|
|
137
|
-
up: { body: '#00d4aa' },
|
|
138
|
-
down: { body: '#ff5577' },
|
|
139
|
-
},
|
|
140
|
-
axis: { textColor: '#8888aa' },
|
|
141
|
-
});
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
## Real-Time Data
|
|
145
|
-
|
|
146
|
-
```tsx
|
|
147
|
-
// Full replace (initial load)
|
|
148
|
-
<CandlestickSeries data={allCandles} />
|
|
149
|
-
|
|
150
|
-
// The component auto-detects changes:
|
|
151
|
-
// - data.length grew by 1-5 → append
|
|
152
|
-
// - data.length same → update last point
|
|
153
|
-
// - data.length shrunk or grew by >5 → full replace
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
## Batch Updates
|
|
157
|
-
|
|
158
|
-
```tsx
|
|
159
|
-
const chart = useChartInstance();
|
|
160
|
-
|
|
161
|
-
chart.batch(() => {
|
|
162
|
-
chart.setSeriesData(id, layer0, 0);
|
|
163
|
-
chart.setSeriesData(id, layer1, 1);
|
|
164
|
-
// Y-range and render happen once after batch
|
|
165
|
-
});
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
## Configuration
|
|
169
|
-
|
|
170
|
-
```tsx
|
|
171
|
-
<ChartContainer
|
|
172
|
-
theme={theme}
|
|
173
|
-
axis={{
|
|
174
|
-
y: { visible: true, width: 55, min: 0, max: 'auto' },
|
|
175
|
-
x: { visible: true, height: 30 },
|
|
176
|
-
}}
|
|
177
|
-
padding={{ top: 20, bottom: 20, right: { intervals: 3 }, left: { intervals: 0 } }}
|
|
178
|
-
gradient={true}
|
|
179
|
-
interactive={true}
|
|
180
|
-
grid={true}
|
|
181
|
-
>
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
## Hooks
|
|
185
|
-
|
|
186
|
-
| Hook | Description |
|
|
187
|
-
|---|---|
|
|
188
|
-
| `useChartInstance()` | Access the `ChartInstance` from context |
|
|
189
|
-
| `useVisibleRange(chart)` | Current visible time range |
|
|
190
|
-
| `useYRange(chart)` | Current Y-axis min/max |
|
|
191
|
-
| `useLastYValue(chart, id)` | Last value + live status for a series |
|
|
192
|
-
| `usePreviousClose(chart, id)` | Previous close price |
|
|
193
|
-
| `useCrosshairPosition(chart)` | Crosshair coordinates and snapped time |
|
|
194
|
-
|
|
195
|
-
## Bundle Size
|
|
196
|
-
|
|
197
|
-
Full `dist/index.js` (minified + gzipped):
|
|
198
|
-
|
|
199
|
-
| Package | Raw | Gzip |
|
|
200
|
-
|---|---|---|
|
|
201
|
-
| `@wick-charts/react` | 224 KB | 59.3 KB |
|
|
202
|
-
|
|
203
|
-
Tree-shaking on the consumer side cuts this down further — `pnpm size` builds representative React scenarios through esbuild with production settings:
|
|
204
|
-
|
|
205
|
-
| Scenario | Raw | Gzip |
|
|
206
|
-
|---|---|---|
|
|
207
|
-
| Candlestick only | 122.1 KB | 36.3 KB |
|
|
208
|
-
| Line only | 122.4 KB | 36.4 KB |
|
|
209
|
-
| Full React (all overlays) | 140.6 KB | 41.3 KB |
|
|
59
|
+
| Scenario | Raw | Gzip | Brotli |
|
|
60
|
+
|---|---:|---:|---:|
|
|
61
|
+
| Candlestick only | 147 KB | 44 KB | 38 KB |
|
|
62
|
+
| Line only | 147 KB | 44 KB | 38 KB |
|
|
63
|
+
| Full React | 164 KB | 49 KB | 41 KB |
|
|
210
64
|
|
|
211
65
|
## Migration
|
|
212
66
|
|