You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[<imgsrc="https://hackerbadge.now.sh/api?id=46706528"alt="Featured on Hacker News"height="30" />](https://news.ycombinator.com/item?id=46706528)
20
+
21
+
[<imgsrc="https://awesome.re/mentioned-badge.svg"alt="Featured in Awesome WebGPU"style="height: 30px;" />](https://github.com/mikbry/awesome-webgpu)
22
+
23
+
17
24
</div>
18
25
19
-
`chartgpu-react` is a **thin React + TypeScript wrapper** around the [`chartgpu`](https://www.npmjs.com/package/chartgpu) core library.
26
+
`chartgpu-react` is a **thin React + TypeScript wrapper** around the [`@chartgpu/chartgpu`](https://www.npmjs.com/package/@chartgpu/chartgpu) core library.
If you prefer a hook-driven approach, you can use `onReady` (or `useChartGPU`) to capture instances, then call `connectCharts(...)` once both are available.
134
+
If you prefer a hook-driven approach, you can use `onReady` (or `useChartGPU`) to capture instances, then call `useConnectCharts(...)` once both are available.
@@ -232,28 +242,28 @@ The dev server will start at `http://localhost:3000` and open the examples page
232
242
233
243
### Local development with linked ChartGPU
234
244
235
-
To develop `chartgpu-react` against a local version of the `chartgpu` package (useful for testing changes across both repositories):
245
+
To develop `chartgpu-react` against a local version of the `@chartgpu/chartgpu` package (useful for testing changes across both repositories):
236
246
237
247
```bash
238
-
# 1. Link the chartgpu package from the sibling repo
248
+
# 1. Link the @chartgpu/chartgpu package from the sibling repo
239
249
cd ../chart-gpu
240
250
npm link
241
251
242
-
# 2. Link chartgpu into this project
252
+
# 2. Link @chartgpu/chartgpu into this project
243
253
cd ../chartgpu-react
244
-
npm link chartgpu
254
+
npm link @chartgpu/chartgpu
245
255
246
256
# 3. Build and run - will use the linked local package
247
257
npm run build
248
258
npm run dev
249
259
```
250
260
251
-
**Note:** After linking, `npm run build` and `npm run dev` will resolve imports to your local `chartgpu` package instead of the published version. This allows you to test changes in both repos simultaneously.
261
+
**Note:** After linking, `npm run build` and `npm run dev` will resolve imports to your local `@chartgpu/chartgpu` package instead of the published version. This allows you to test changes in both repos simultaneously.
Copy file name to clipboardExpand all lines: docs/API.md
+19-13Lines changed: 19 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# API reference (chartgpu-react)
2
2
3
-
This package is a **React wrapper** around the `chartgpu` core library. Most runtime behavior lives in `chartgpu`; this repo primarily provides:
3
+
This package is a **React wrapper** around the `@chartgpu/chartgpu` core library. Most runtime behavior lives in `@chartgpu/chartgpu`; this repo primarily provides:
4
4
5
5
- A React component (`ChartGPU`) with lifecycle + resize management
6
6
- A small imperative ref API (`ChartGPUHandle`)
@@ -19,20 +19,20 @@ For an LLM-oriented navigation entrypoint, see [`docs/api/llm-context.md`](./api
19
19
### Hooks
20
20
21
21
-**`useChartGPU(containerRef, options)`** — create/manage an instance imperatively
22
-
-**`useConnectCharts([chartA, chartB, ...])`** — keep crosshair/interaction-x in sync
`chartgpu-react` exposes these helpers so you can often import everything from one package:
29
29
30
30
-`createChart`
31
31
-`connectCharts`
32
32
-`createAnnotationAuthoring`
33
33
34
-
-`createChart` / `connectCharts` are re-exported directly from `chartgpu`.
35
-
-`createAnnotationAuthoring` is a thin wrapper around `chartgpu`’s helper that includes a small fix for `chartgpu@0.2.3`: the upstream authoring context menu hit-testing does not recognize `type: "text"` annotations, so **Edit** may not appear for text notes.
34
+
-`createChart` / `connectCharts` are re-exported directly from `@chartgpu/chartgpu`.
35
+
-`createAnnotationAuthoring` is a thin wrapper around `@chartgpu/chartgpu`'s helper that patches text-annotation context-menu hit-testing (broken in `chartgpu@0.2.3`). Upstream v0.2.5 fixes this natively; the wrapper is kept for API stability — the patch is harmless when running against v0.2.5+.
@@ -80,10 +84,9 @@ Resize calls are debounced (100ms).
80
84
81
85
### Zoom change events
82
86
83
-
If you provide `onZoomChange`, the component polls `chart.getZoomRange()` every 100ms and fires the callback when:
87
+
If you provide `onZoomChange`, the component subscribes to the upstream `zoomRangeChange` event and fires the callback whenever the zoom range changes.
84
88
85
-
- the zoom range transitions from `null` → non-null, or
86
-
-`start`/`end` values change.
89
+
On subscribe, the component also reads the current zoom range via `getZoomRange()` and fires `onZoomChange` once if the range is non-null. This ensures consumers can hydrate UI state without waiting for user interaction.
87
90
88
91
If zoom is disabled (`null`), no callback is fired.
Performs hit-testing on a pointer or mouse event. Returns coordinates and any matched chart element.
83
+
84
+
-**`e`**: a native `PointerEvent` or `MouseEvent` from the chart container.
85
+
-**Returns**: `ChartGPUHitTestResult` with pixel coordinates, domain-space coordinates, and an optional match object.
86
+
- If the chart is not initialized or disposed, returns a sentinel with `isInGrid: false` and `NaN` coordinates.
87
+
88
+
**React ergonomics note**: React synthetic events (`React.PointerEvent`, `React.MouseEvent`) are not the same as native DOM events. Pass `e.nativeEvent` instead:
89
+
90
+
```tsx
91
+
<divonPointerDown={(e) => {
92
+
const result =chartRef.current?.hitTest(e.nativeEvent);
0 commit comments