@wick-charts/react 0.1.1 → 0.2.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/README.md ADDED
@@ -0,0 +1,217 @@
1
+ <!-- Generated from README.tmpl.md — edit the template, not this file. -->
2
+
3
+ # Wick Charts
4
+
5
+ High-performance timeseries charts for **React**, **Vue**, and **Svelte**. Canvas-rendered, tree-shakeable, ~25KB gzipped.
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
+ > `TooltipLegend` is the former name of `InfoBar` and is still exported as a deprecated alias.
74
+
75
+ ## Custom render (slots / render-props)
76
+
77
+ ```tsx
78
+ // React — filter two of five series with your own layout
79
+ <Tooltip>
80
+ {({ snapshots, time }) =>
81
+ snapshots
82
+ .filter((s) => s.seriesId === 'btc' || s.seriesId === 'eth')
83
+ .map((s) => (
84
+ <div key={s.id} style={{ color: s.color }}>
85
+ {s.label}: {s.data.close ?? s.data.value}
86
+ </div>
87
+ ))
88
+ }
89
+ </Tooltip>
90
+ ```
91
+
92
+ Each overlay has its own slot context (see the Slot ctx column above); the shape is consistent across frameworks for the same overlay.
93
+
94
+ ### Public helpers (re-exported from each framework package)
95
+
96
+ - `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.
97
+ - `computeTooltipPosition({ x, y, chartWidth, chartHeight, tooltipWidth, tooltipHeight, offsetX?, offsetY? })` — flip + clamp positioning for a tooltip container you own.
98
+ - Types: `SeriesSnapshot`, `LegendItem`, `SliceInfo`, `HoverInfo`.
99
+
100
+ ## Custom number formatting
101
+
102
+ 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`):
103
+
104
+ - `formatCompact(v)` — K/M/B/T suffixes with adaptive precision. Default for `YAxis` (at ranges ≥ 1e6), `PieLegend`, `PieTooltip`, `Sparkline`.
105
+ - `formatPriceAdaptive(v)` — full-precision display that scales decimals to the value's magnitude. Default for `Tooltip` / `TooltipLegend` OHLC and line-value cells. Handles sub-cent prices (`0.00001234` → `"0.00001234"`, not `"0.00"`).
106
+
107
+ ```tsx
108
+ import { Tooltip, YAxis, formatCompact } from '@wick-charts/react';
109
+
110
+ <YAxis format={(v) => `$${formatCompact(v)}`} />
111
+ <Tooltip format={(v, field) => field === 'volume' ? formatCompact(v) : v.toFixed(4)} />
112
+ ```
113
+
114
+ Tooltip / TooltipLegend 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`.
115
+
116
+ ## Themes
117
+
118
+ 22 built-in themes. Import only the ones you need (tree-shakable) and pass them to `ChartContainer` or `ThemeProvider` for global theming.
119
+
120
+ ```tsx
121
+ import { catppuccin } from '@wick-charts/react';
122
+
123
+ // Dark: andromeda, ayuMirage, catppuccin, dracula, gruvbox, highContrast,
124
+ // materialPalenight, monokaiPro, nightOwl, oneDarkPro, panda
125
+ // Light: githubLight, handwritten, lavenderMist, lightPink, minimalLight, mintBreeze,
126
+ // peachCream, quietLight, rosePineDawn, sandDune, solarizedLight
127
+
128
+ <ChartContainer theme={catppuccin.theme}>
129
+ ```
130
+
131
+ Create custom themes with `createTheme()`:
132
+
133
+ ```tsx
134
+ import { createTheme } from '@wick-charts/react';
135
+
136
+ const myTheme = createTheme({
137
+ background: '#1a1b2e',
138
+ upColor: '#00d4aa',
139
+ downColor: '#ff5577',
140
+ 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` | 181 KB | 45.6 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 | 98 KB | 28.5 KB |
208
+ | Line only | 98 KB | 28.6 KB |
209
+ | Full React (all overlays) | 115 KB | 32.8 KB |
210
+
211
+ ## Migration
212
+
213
+ 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.
214
+
215
+ ## License
216
+
217
+ MIT