|
29 | 29 |
|
30 | 30 | - **`ChartGPU` component (recommended)**: async create/dispose lifecycle + debounced `ResizeObserver` sizing |
31 | 31 | - **Event props**: `onClick`, `onCrosshairMove`, `onZoomChange`, `onDataAppend`, `onDeviceLost`, etc. |
32 | | -- **Imperative `ref` API**: `ChartGPUHandle` (`getChart`, `getContainer`, `appendData`, `setOption`, `setZoomRange`, `setInteractionX`, `getInteractionX`, `hitTest`, `needsRender`, `renderFrame`, `getRenderMode`, `setRenderMode`) |
| 32 | +- **Imperative `ref` API**: `ChartGPUHandle` (`getChart`, `getContainer`, `appendData` with optional `{ maxPoints }` FIFO, `setOption`, `setZoomRange`, `setInteractionX`, `getInteractionX`, `hitTest`, `needsRender`, `renderFrame`, `getRenderMode`, `setRenderMode`) |
33 | 33 | - **Hooks**: `useChartGPU(...)`, `useGPUContext()`, `useConnectCharts(..., syncOptions?)` |
| 34 | +- **Multi-chart + streaming**: share a `GPUDevice` via `gpuContext` / `useGPUContext`, sync with `useConnectCharts`, stream with `appendData(..., { maxPoints })` |
34 | 35 | - **Helper re-exports (from `@chartgpu/chartgpu`)**: `createChart`, `connectCharts`, `createPipelineCache`, `getPipelineCacheStats`, `destroyPipelineCache`, `createAnnotationAuthoring` |
35 | 36 |
|
36 | 37 | ## Quick start |
@@ -70,13 +71,16 @@ function MyChart() { |
70 | 71 | npm install chartgpu-react @chartgpu/chartgpu react react-dom |
71 | 72 | ``` |
72 | 73 |
|
| 74 | +Peer dependency: **`@chartgpu/chartgpu` ^0.3.6** (aligned with this package’s 0.3.x line). |
| 75 | + |
73 | 76 | ### Requirements |
74 | 77 |
|
75 | | -- React 18.0.0 or higher |
| 78 | +- **React 18 or 19** (`react` / `react-dom` ≥ 18) |
| 79 | +- **TypeScript 5+** for consumers (this package is built and typechecked with **TypeScript 7**) |
76 | 80 | - Browser with WebGPU support: |
77 | 81 | - Chrome/Edge 113+ |
78 | 82 | - Safari 18+ |
79 | | - - Firefox (not yet supported) |
| 83 | + - Firefox: Windows 114+, Mac 145+, Linux nightly |
80 | 84 |
|
81 | 85 | Check browser compatibility at [caniuse.com/webgpu](https://caniuse.com/webgpu). |
82 | 86 |
|
@@ -135,6 +139,40 @@ disconnect(); |
135 | 139 |
|
136 | 140 | If you prefer a hook-driven approach, you can use `onReady` (or `useChartGPU`) to capture instances, then call `useConnectCharts(...)` once both are available. |
137 | 141 |
|
| 142 | +### Streaming append with FIFO window (`maxPoints`) |
| 143 | + |
| 144 | +```tsx |
| 145 | +import { useEffect, useRef } from 'react'; |
| 146 | +import { ChartGPU } from 'chartgpu-react'; |
| 147 | +import type { ChartGPUHandle } from 'chartgpu-react'; |
| 148 | + |
| 149 | +function StreamingChart() { |
| 150 | + const ref = useRef<ChartGPUHandle>(null); |
| 151 | + const xRef = useRef(0); |
| 152 | + |
| 153 | + useEffect(() => { |
| 154 | + const id = window.setInterval(() => { |
| 155 | + const x = xRef.current++; |
| 156 | + ref.current?.appendData(0, [{ x, y: Math.sin(x * 0.05) }], { maxPoints: 50_000 }); |
| 157 | + }, 16); |
| 158 | + return () => window.clearInterval(id); |
| 159 | + }, []); |
| 160 | + |
| 161 | + return ( |
| 162 | + <ChartGPU |
| 163 | + ref={ref} |
| 164 | + options={{ |
| 165 | + autoScroll: true, |
| 166 | + series: [{ type: 'line', data: [], lineStyle: { width: 2, color: '#4facfe' } }], |
| 167 | + xAxis: { type: 'value' }, |
| 168 | + yAxis: { type: 'value' }, |
| 169 | + }} |
| 170 | + style={{ width: '100%', height: 320 }} |
| 171 | + /> |
| 172 | + ); |
| 173 | +} |
| 174 | +``` |
| 175 | + |
138 | 176 | ### External render mode (app-owned render loop) |
139 | 177 |
|
140 | 178 | ```tsx |
|
0 commit comments