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

未关闭
#207 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
d3, typescript

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
TypeScript
星标
870
派生
57
平均合并
11 小时 58 分钟
30 天内合并 PR
18

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/charts 的其他 Issue

查看 TanStack/charts 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。