[Feature] Public API to get the laid-out rectangle of a grid
@adityamukesh 已经在做这个了。
开始于 2026年10月7日。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 70/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
调研方向
Start in src/core/echarts.ts at the implementations of containPixel and convertToPixel, which already resolve a finder object like { gridIndex } to a component. Follow that path to the grid coordinate system's getRect() and expose it as a documented public method returning chart pixels or null before layout. Done means the new API is typed, documented alongside convertToPixel/containPixel, and covered by a test in test/ that checks containLabel and outerBoundsMode shrinking the returned rectangle.
由索引模型根据 Issue 内容生成。
描述
What problem does this feature solve?
The pixel rectangle of a grid (the plot, where the axes are drawn) is known only after ECharts has laid the chart out, and there is no public way to read it. Apps that draw HTML or SVG over a chart (hover labels, a crosshair line, markers, annotations) need it to put the overlay exactly on the plot.
This has been asked before (#16898, #16480) and answered with the private chart.getModel().getComponent('grid').coordinateSystem.getRect(); #16479 says getModel is private and may change. Everything public falls short:
chart.getOption().grid[0]holds the configured values (left,right,outerBoundsMode, ...), not the result of the layout, so it is wrong as soon ascontainLabelorouterBoundsMode: 'auto'shrink the plot.chart.convertToPixel({ xAxisIndex: 0 }, extreme)needs the axis extent. After a dataZoom, or withscale/ automatic ranges, only the model knows it (#17919);getOption().xAxis[0].min/maxstill holds the configured values after a zoom.chart.containPixel('grid', [x, y])can find the edges by probing, but that is aboutlog2(size)calls per edge on every layout change.chart.getOption()deep-clones the whole option, data included, on every call, so it cannot be used on every mouse move.
Our case: a pointer drawn in HTML over several synced charts with a few thousand points each (labels at the points nearest to the mouse, a line across the plot and the time under it). It needs the plot's rectangle on every mouse move, so the read has to be cheap, and today it depends on a private method.
What does the proposed API look like?
A getter that mirrors the finders of containPixel and convertToPixel:
chart.getRect({ gridIndex: 0 });
// -> { x: 70, y: 32, width: 460, height: 204 } in chart pixels, or null when the chart has no such grid or is not laid out yet
Or chart.getGridRect(gridIndex?); the name is open. What matters is that it is documented and stable, and that it gives the result of the layout (including outerBoundsMode and containLabel), which is what getRect() of the grid coordinate system holds today.
- 主要语言
- TypeScript
- 星标
- 67.7k
- 派生
- 19.9k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/echarts 的其他 Issue
-
[Bug] String formatter templates only replace the first occurrence of `{a}`/`{b}`/`{c}`可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭en pending
难度 2/5 1-3 小时 新手友好度 80/100
-
[Bug] Inverse axis collapses the grid with outerBoundsContain when a tick is near the axis edge可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭en pending
难度 2/5 1-3 小时 新手友好度 82/100
-
en pending
难度 2/5 1-3 小时 新手友好度 78/100
-
en pending
难度 2/5 1-3 小时 新手友好度 78/100
-
[Bug] The zoom cursor in the toolbox area is incorrect可能已有人在做 @waterWang 于 98 天前认领。 未关闭bug en pending
难度 2/5 1-3 小时 新手友好度 70/100
相似的 Issue
-
Stop retrying permanent GitHub API failures in retry.sh可能已有人在做 @muspi-merol-review 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
promplate/code-review#113 · 1 条评论 ·
维护者通常 1 天内回复
-
triage
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
サムネイルの Storage のバケット(`thumbnails`)に、大きさの上限(1 MiB)と許可する種類(JPEG、PNG、WebP)を設定する可能已有人在做 @ykzts 今天认领。 未关闭tech: supabase
难度 2/5 1-3 小时 新手友好度 78/100
inabagumi/shinju-date#7147 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
elecnix/your-attention#129 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
umami-software/umami#4780 ·
维护者通常 3 天内回复