You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by "unitrongroup-ir (via GitHub)" <gi...@apache.org> on 2026/10/06 22:40:30 UTC

[I] [Feature] Public API to get the laid-out rectangle of a grid [echarts]

unitrongroup-ir opened a new issue, #21780:
URL: https://github.com/apache/echarts/issues/21780

   ### 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 as `containLabel` or `outerBoundsMode: 'auto'` shrink the plot.
   - `chart.convertToPixel({ xAxisIndex: 0 }, extreme)` needs the axis extent. After a dataZoom, or with `scale` / automatic ranges, only the model knows it (#17919); `getOption().xAxis[0].min/max` still holds the configured values after a zoom.
   - `chart.containPixel('grid', [x, y])` can find the edges by probing, but that is about `log2(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`:
   
   ```ts
   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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


Re: [I] [Feature] Public API to get the laid-out rectangle of a grid [echarts]

Posted by "adityamukesh (via GitHub)" <gi...@apache.org>.
adityamukesh commented on issue #21780:
URL: https://github.com/apache/echarts/issues/21780#issuecomment-6034669542

   Hi maintainers, I would like to work on this issue.
   
   I can implement the public API method to expose the calculated bounding box / rectangle of a laid-out grid component. Could you please assign this to me? Thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


Re: [I] [Feature] Public API to get the laid-out rectangle of a grid [echarts]

Posted by "unitrongroup-ir (via GitHub)" <gi...@apache.org>.
unitrongroup-ir commented on issue #21780:
URL: https://github.com/apache/echarts/issues/21780#issuecomment-6051387292

   @adityamukesh thanks for offering to take this. A few notes from the requester's side, in case they help the design:
   
   - **The result of the layout.** The value should be what `grid.coordinateSystem.getRect()` holds after the layout, so `containLabel` and `outerBoundsMode` are included. The configured `grid` option (`getOption().grid`) is not enough, which is the whole reason for the request.
   - **Cheap to call.** We read it on every mouse move to place an HTML overlay, so please no deep clone as `getOption()` does. Four numbers are enough.
   - **A plain value, not the internal object.** The private path returns the grid's own `BoundingRect` (with a `margin` field), which a caller can modify. A fresh `{ x, y, width, height }` per call is fine.
   - **Finder like the existing APIs.** `{ gridIndex }` / `{ gridId }` as in `containPixel` and `convertToPixel` looks right to us, and `null` when there is no such grid or it is not laid out yet.
   
   A way to test it without a browser: ECharts renders in Node with `echarts.init(null, null, { renderer: 'svg', ssr: true, width: 800, height: 400 })`. With a fixed axis range, the rectangle can be checked against `convertToPixel` of the axis minimum and maximum (they sit on the left and right edges), also after a `dataZoom` and with `containLabel: true`. We use exactly that to guard our own use of the private path against upgrades (checked with 6.1.0).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org