[Feature] Expose the focus position to the host: CSS variables on the root, plot-space pointer in `onFocusChange`

Aperta
#207 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
d3, typescript

Direzione di ricerca

Start with packages/charts-core/src/renderer.ts, especially notifyFocus and sameFocusObservation, which the issue identifies as the focus notification and deduplication points. Trace how the renderer resolves pointer positions and how tooltip positions are represented before deciding where to expose them. Done means an opt-in can expose focus index and plot coordinates on the chart root, clear them when focus ends, and report pointer position through the focus callback or a new pointer callback.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Version: @tanstack/charts 1.1.0 (57774e1).

Today the focused point is only available through onFocusChange. Styling something from focus, such as fading axis ticks near the hovered x or dimming the other bars, means writing the value yourself on every focus change from that callback.

We do exactly this in a chart migration: the host sets --hover-x and its siblings on the chart root, and CSS reads them. It works, but each chart has to wire the same callback-to-style plumbing, and the write happens on a separate path from the library's own focus paint.

Ask: an opt-in to have the renderer set the focused datum's index and position on the chart root, for example data-focus-index and --ts-focus-x/--ts-focus-y in plot coordinates, and clear them when focus ends. That would let charts style focus from CSS alone, without a scene rebuild or extra JS per move.

Checked against 57774e14a1a86081eddb3a23523724a40da05640 (v1.1.0).

The pointer position is never reported (moved here from #190's comment)

notifyFocus calls onFocusChange only when the primary point's (key, markId, datumIndex) or Object.is(datum) changes (renderer.ts:561-581, sameFocusObservation at renderer.ts:1404-1416). Moves inside one point's hit region produce no callback, and the callback carries no coordinates.

Example: a live line chart whose crosshair and pill follow the raw pointer x between samples cannot get that x from the focus pipeline. It needs a separate pointermove listener on the container, and it then has to convert client coordinates to plot space itself.

Proposal: pass the resolved pointer position (plot-space x/y, or the ChartTooltipPosition already used for tooltips) as a second argument to onFocusChange, or add an opt-in onPointerMove with scene coordinates. This does not conflict with the dedupe in #178; it only adds data to the call that already happens. The CSS variables above would be filled from the same position.

Lingua principale
TypeScript
Stelle
870
Fork
57
Merge medio
11h 58m
PR unite (30g)
18

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TanStack/charts

Tutte le issue di TanStack/charts

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.