Skip to content

feat: create the WebGL context of the focus layer only for selections - #1

Draft
katosh wants to merge 1 commit into
mainfrom
pr/gl2d-focus-context-v3
Draft

katosh wants to merge 1 commit into
mainfrom
pr/gl2d-focus-context-v3

Conversation

@katosh

@katosh katosh commented Dec 4, 2026

Copy link
Copy Markdown

Description

A graph with scattergl or splom traces now creates one WebGL context instead of two. The second context appears when a selection starts: a selection drag mode, or selected points. The change is not opt-in, and the pixels stay the same.

Closes #

Related: plotly#6365 and plotly#2333, where pages with many graphs reach the context limit of the browser.

Bar chart: main holds 2 WebGL contexts at each step, this branch holds 1 after newPlot and 2 after a selection
Live WebGL contexts of one graph with two scattergl traces, main against this branch, in headless Chromium.

Each graph with a regl trace creates a context for the context layer and a context for the focus layer. In these graphs, the focus layer shows only the selected points. Most graphs never select, but the browser counts the second context. Chrome permits about 16 live contexts for each page.

Now prepareRegl creates the context of the focus layer only on request, or if the graph has parcoords. scattergl sends the request when a selection drag mode starts or a selection draw comes. The selected points appear on the focus layer as before.

AnnZarro shows many plotly.js panels on one page and needs this. Related: [umbrella issue link]. Overview: [combined draft PR link].

Changes

  • src/lib/prepare_regl.js: new argument needsFocusLayer
  • src/traces/scattergl/plot.js: request the focus layer for a selection drag mode or a selection draw
  • test/jasmine/tests/gl2d_plot_interact_test.js: 3 updated specs, 1 new spec

Testing

  • gl2d_plot_interact: 17 specs pass, and main has 16
  • scattergl_select, parcoords, splom, scattergl and scatterpolargl pass
  • 61 scenes render the same pixels as main, with drawn selections

Notes

  • Before the first selection, gd._fullLayout._glcanvas.data()[1] holds no regl property
  • plotly.min.js grows by 143 bytes

I can reshape or withdraw this pull request. Thank you for your time.

Checklist

  • The linked issue has the ready-for-pr label, and it has no assignee or lists me as an assignee
  • I opened the pull request from a branch other than main in my fork
  • I selected "Allow edits from maintainers"
  • I did not edit files in dist/
  • I committed package-lock.json only for a dependency change
  • I added a file to draftlogs/ as draftlogs/README.md describes, or I will add one after the pull request opens

Each graph with a regl trace created two WebGL contexts. In scattergl and splom graphs, the focus layer shows only the selected points. Most graphs never select, but the browser counts the second context against its limit of about 16 for each page.

prepareRegl now creates the context of the focus layer on request, or if the graph has parcoords. scattergl sends the request when a selection drag mode starts, or when the first selection draw comes. The selected points appear on the focus layer as before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant