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

Aperta
#21,780 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@adityamukesh ci sta già lavorando.

Dal 7/10/2026.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
70/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

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.

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

Descrizione

en pending
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:

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.

Lingua principale
TypeScript
Stelle
67.7k
Fork
19.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

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 apache/echarts

Tutte le issue di apache/echarts

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.