@wick-charts/react 0.1.2 → 0.2.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/README.md ADDED
@@ -0,0 +1,215 @@
1
+ # Wick Charts
2
+
3
+ <!-- Generated from README.tmpl.md — edit the template, not this file. -->
4
+
5
+ High-performance timeseries charts for **React**, **Vue**, and **Svelte**. Canvas-rendered, tree-shakeable, ~36KB gzipped when tree-shaken.
6
+
7
+ [Live Demo](https://mo4islona.github.io/wick-charts/)
8
+
9
+ ## Features
10
+
11
+ - **Candlestick, Line, Bar, Pie** — all from one package
12
+ - **Real-time streaming** — append/update data at 60fps
13
+ - **22 built-in themes** — dark, light, and custom
14
+ - **Interactive** — zoom, pan, crosshair, tooltips
15
+ - **Stacking** — normal and percent modes for line/bar
16
+ - **Custom-render helpers** — `buildHoverSnapshots` / `buildLastSnapshots` / `computeTooltipPosition` for overlays that need to escape the built-in UI (structural-equality cache included)
17
+ - **Tree-shakeable** — import only what you use
18
+ - **Zero dependencies** — just your framework
19
+
20
+ ## Install
21
+
22
+ ```bash
23
+ npm install @wick-charts/react
24
+ ```
25
+
26
+ ## Quick Start
27
+
28
+ ```tsx
29
+ import {
30
+ ChartContainer, CandlestickSeries, Tooltip,
31
+ Crosshair, YAxis, TimeAxis
32
+ } from '@wick-charts/react';
33
+
34
+ function Chart({ data }) {
35
+ return (
36
+ <ChartContainer>
37
+ <CandlestickSeries data={data} />
38
+ <Tooltip />
39
+ <Crosshair />
40
+ <YAxis />
41
+ <TimeAxis />
42
+ </ChartContainer>
43
+ );
44
+ }
45
+ ```
46
+
47
+ ## Series Types
48
+
49
+ | Component | Data Format | Description |
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 |
55
+
56
+ ## UI Overlays
57
+
58
+ Every DOM overlay ships a default UI **and** a scoped slot / render-prop so you can replace the contents with your own layout. Positioning, crosshair wiring, and data computation stay in the library — the slot just hands you the already-computed data.
59
+
60
+ | Component | Description | Slot ctx |
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 }` |
72
+
73
+ ## Custom render (slots / render-props)
74
+
75
+ ```tsx
76
+ // React — filter two of five series with your own layout
77
+ <Tooltip>
78
+ {({ snapshots, time }) =>
79
+ snapshots
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
+ upColor: '#00d4aa',
137
+ downColor: '#ff5577',
138
+ textColor: '#8888aa',
139
+ });
140
+ ```
141
+
142
+ ## Real-Time Data
143
+
144
+ ```tsx
145
+ // Full replace (initial load)
146
+ <CandlestickSeries data={allCandles} />
147
+
148
+ // The component auto-detects changes:
149
+ // - data.length grew by 1-5 → append
150
+ // - data.length same → update last point
151
+ // - data.length shrunk or grew by >5 → full replace
152
+ ```
153
+
154
+ ## Batch Updates
155
+
156
+ ```tsx
157
+ const chart = useChartInstance();
158
+
159
+ chart.batch(() => {
160
+ chart.setSeriesData(id, layer0, 0);
161
+ chart.setSeriesData(id, layer1, 1);
162
+ // Y-range and render happen once after batch
163
+ });
164
+ ```
165
+
166
+ ## Configuration
167
+
168
+ ```tsx
169
+ <ChartContainer
170
+ theme={theme}
171
+ axis={{
172
+ y: { visible: true, width: 55, min: 0, max: 'auto' },
173
+ x: { visible: true, height: 30 },
174
+ }}
175
+ padding={{ top: 20, bottom: 20, right: { intervals: 3 }, left: { intervals: 0 } }}
176
+ gradient={true}
177
+ interactive={true}
178
+ grid={true}
179
+ >
180
+ ```
181
+
182
+ ## Hooks
183
+
184
+ | Hook | Description |
185
+ |---|---|
186
+ | `useChartInstance()` | Access the `ChartInstance` from context |
187
+ | `useVisibleRange(chart)` | Current visible time range |
188
+ | `useYRange(chart)` | Current Y-axis min/max |
189
+ | `useLastYValue(chart, id)` | Last value + live status for a series |
190
+ | `usePreviousClose(chart, id)` | Previous close price |
191
+ | `useCrosshairPosition(chart)` | Crosshair coordinates and snapped time |
192
+
193
+ ## Bundle Size
194
+
195
+ Full `dist/index.js` (minified + gzipped):
196
+
197
+ | Package | Raw | Gzip |
198
+ |---|---|---|
199
+ | `@wick-charts/react` | 224 KB | 59.3 KB |
200
+
201
+ Tree-shaking on the consumer side cuts this down further — `pnpm size` builds representative React scenarios through esbuild with production settings:
202
+
203
+ | Scenario | Raw | Gzip |
204
+ |---|---|---|
205
+ | Candlestick only | 122.1 KB | 36.3 KB |
206
+ | Line only | 122.4 KB | 36.4 KB |
207
+ | Full React (all overlays) | 140.6 KB | 41.3 KB |
208
+
209
+ ## Migration
210
+
211
+ Upgrading across versions? See [MIGRATION.md](https://github.com/mo4islona/wick-charts/blob/main/MIGRATION.md) for per-version breaking-change notes and code snippets.
212
+
213
+ ## License
214
+
215
+ MIT