@wick-charts/vue 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.
Files changed (4) hide show
  1. package/README.md +198 -0
  2. package/dist/index.d.ts +1216 -109
  3. package/dist/index.js +4283 -1897
  4. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,198 @@
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/vue
24
+ ```
25
+
26
+ ## Quick Start
27
+
28
+ ```vue
29
+ <script setup>
30
+ import {
31
+ ChartContainer, CandlestickSeries, Tooltip,
32
+ Crosshair, YAxis, TimeAxis
33
+ } from '@wick-charts/vue';
34
+
35
+ const props = defineProps(['data']);
36
+ </script>
37
+
38
+ <template>
39
+ <ChartContainer>
40
+ <CandlestickSeries :data="props.data" />
41
+ <Tooltip />
42
+ <Crosshair />
43
+ <YAxis />
44
+ <TimeAxis />
45
+ </ChartContainer>
46
+ </template>
47
+ ```
48
+
49
+ ## Series Types
50
+
51
+ | Component | Data Format | Description |
52
+ |---|---|---|
53
+ | `CandlestickSeries` | `{ time, open, high, low, close, volume? }[]` | OHLC candlesticks with volume bars |
54
+ | `LineSeries` | `{ time, value }[][]` | Line/area charts, multi-layer, stacking |
55
+ | `BarSeries` | `{ time, value }[][]` | Histogram/bar charts, stacking |
56
+ | `PieSeries` | `{ label, value, color? }[]` | Pie and donut charts |
57
+
58
+ ## UI Overlays
59
+
60
+ 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.
61
+
62
+ | Component | Description | Slot ctx |
63
+ |---|---|---|
64
+ | `Tooltip` | Floating glass tooltip near cursor on hover | `{ snapshots, time }` |
65
+ | `InfoBar` | Compact OHLC / values info bar hoisted above the canvas | `{ snapshots, time, isHover }` |
66
+ | `Title` | Chart title / subtitle bar hoisted above the canvas | — |
67
+ | `Crosshair` | Axis labels at cursor position | — |
68
+ | `YAxis` | Vertical price/value axis with animated ticks | — |
69
+ | `TimeAxis` | Horizontal time axis with animated ticks | — |
70
+ | `YLabel` | Floating price badge with dashed line | `{ value, y, bgColor, isLive, direction, format }` |
71
+ | `Legend` | Clickable legend with toggle/isolate modes | `{ items: LegendItem[] }` |
72
+ | `PieTooltip` | Tooltip for pie/donut hover | `{ info, format }` |
73
+ | `PieLegend` | Slice labels with values or percentages | `{ slices, mode, format }` |
74
+
75
+ ## Custom render (slots / render-props)
76
+
77
+ ```vue
78
+ <!-- Vue — same context, different syntax -->
79
+ <Tooltip v-slot="{ snapshots, time }">
80
+ <div
81
+ v-for="s in snapshots.filter((x) => x.seriesId === 'btc' || x.seriesId === 'eth')"
82
+ :key="s.id"
83
+ :style="{ color: s.color }"
84
+ >
85
+ {{ s.label }}: {{ s.data.close ?? s.data.value }}
86
+ </div>
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
+ ```vue
106
+ <script setup>
107
+ import { Tooltip, YAxis, formatCompact } from '@wick-charts/vue';
108
+
109
+ const yFormat = (v) => `$${formatCompact(v)}`;
110
+ const tipFormat = (v, field) => (field === 'volume' ? formatCompact(v) : v.toFixed(4));
111
+ </script>
112
+
113
+ <template>
114
+ <YAxis :format="yFormat" />
115
+ <Tooltip :format="tipFormat" />
116
+ </template>
117
+ ```
118
+
119
+ 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`.
120
+
121
+ ## Themes
122
+
123
+ 22 built-in themes. Import only the ones you need (tree-shakable) and pass them to `ChartContainer` or `ThemeProvider` for global theming.
124
+
125
+ ```vue
126
+ <script setup>
127
+ import { catppuccin } from '@wick-charts/vue';
128
+ // Dark: andromeda, ayuMirage, catppuccin, dracula, gruvbox, highContrast,
129
+ // materialPalenight, monokaiPro, nightOwl, oneDarkPro, panda
130
+ // Light: githubLight, handwritten, lavenderMist, lightPink, minimalLight, mintBreeze,
131
+ // peachCream, quietLight, rosePineDawn, sandDune, solarizedLight
132
+ </script>
133
+
134
+ <template>
135
+ <ChartContainer :theme="catppuccin.theme" />
136
+ </template>
137
+ ```
138
+
139
+ Create custom themes with `createTheme()`:
140
+
141
+ ```ts
142
+ import { createTheme } from '@wick-charts/vue';
143
+
144
+ const myTheme = createTheme({
145
+ background: '#1a1b2e',
146
+ upColor: '#00d4aa',
147
+ downColor: '#ff5577',
148
+ textColor: '#8888aa',
149
+ });
150
+ ```
151
+
152
+ ## Real-Time Data
153
+
154
+ ```vue
155
+ <template>
156
+ <!-- Full replace (initial load) -->
157
+ <CandlestickSeries :data="allCandles" />
158
+ </template>
159
+
160
+ <!--
161
+ The component auto-detects changes:
162
+ - data.length grew by 1-5 → append
163
+ - data.length same → update last point
164
+ - data.length shrunk or grew by >5 → full replace
165
+ -->
166
+ ```
167
+
168
+ ## Configuration
169
+
170
+ ```vue
171
+ <template>
172
+ <ChartContainer
173
+ :theme="theme"
174
+ :axis="{
175
+ y: { visible: true, width: 55, min: 0, max: 'auto' },
176
+ x: { visible: true, height: 30 },
177
+ }"
178
+ />
179
+ </template>
180
+
181
+ <!-- Vue ChartContainer currently accepts theme + axis; padding/gradient/grid/interactive are React-only. -->
182
+ ```
183
+
184
+ ## Bundle Size
185
+
186
+ Full `dist/index.js` (minified + gzipped):
187
+
188
+ | Package | Raw | Gzip |
189
+ |---|---|---|
190
+ | `@wick-charts/vue` | 219 KB | 57.3 KB |
191
+
192
+ ## Migration
193
+
194
+ 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.
195
+
196
+ ## License
197
+
198
+ MIT