Skip to content

Add cliponaxis to scattergl - #8222

Open
benjibunbun wants to merge 2 commits into
plotly:mainfrom
benjibunbun:scattergl-cliponaxis
Open

benjibunbun wants to merge 2 commits into
plotly:mainfrom
benjibunbun:scattergl-cliponaxis

Conversation

@benjibunbun

Copy link
Copy Markdown

Closes #8074.

This adds cliponaxis to scattergl so markers on the edge of the plot area can show in full like they already can for scatter. The default is still true. So nothing changes unless a trace sets cliponaxis: false.

regl-scatter2d uses the viewport as its scissor box, which means the only way to let markers draw past the axes is to give them a bigger viewport. For a cliponaxis: false trace the marker layers (scatter2d and select2d) get a viewport that is larger by the biggest marker radius on each side. I round that up to whole device pixels because regl truncates the viewport to whole pixels anyway. The range grows by the same amount in data units so the markers stay in the same place on screen.

convertMarkerStyle already loops over the sizes and line widths so now it also keeps the largest of each. calc uses those and the selected / unselected sizes to work out the pad once per trace. No extra pass over the data. I also changed plot to call scene.update instead of updating each layer by itself. That way the first draw and pan/zoom go through the same code and can't end up with different padding.

Lines, fills and error bars stay clipped like they do for scatter. Text stays clipped too, and that part is different from scatter. scattergl draws text with gl-text, which has its own viewport, and how far a label reaches depends on its text. So I kept this to markers, which is what the issue is about.

There are two more differences from scatter that I didn't try to fix here:

  • A point just outside the axis range can now show partly. That happens when its center is closer to the edge than the largest marker radius in the trace. It gets cut off at the edge of the bigger viewport, while scatter hides those points. Fixing it needs either a filter over the points on every pan frame or a change to the regl-scatter2d shader.
  • The WebGL canvas sits above the axes. So these markers draw over axis lines and tick labels whatever xaxis.layer is. That's the same thing as [BUG]: axis.layer / axis.zerolinelayer: 'above traces' do not render above scattergl traces #8075.

I didn't add it to scatterpolargl. Its attributes.js leaves cliponaxis out on purpose and I kept it that way.

Tests:

  • scattergl_test.js
    • supplyDefaults only coerces cliponaxis for traces with markers.
    • A pixel test where a marker draws past the corner of the plot area. The line and error bar of the same trace stay inside, and so does the marker of a default trace.
    • A test for how much the marker viewport grows in scatter2d and select2d. It covers a circle with a border, a square, array sizes and line widths, and a selected size. A restyle back to cliponaxis: true puts the viewport back on the plot area.
  • gl2d_plot_interact_test.js: the marker range stays padded during and after a pan. The line range doesn't change.
  • New mock gl2d_cliponaxis_false. The left subplot uses cliponaxis: false and the right one uses the default, which is how scattergl looks today. It has no baseline yet. I'll add the one from the CI artifact.

On my machine (macOS, Chrome 158) scattergl, scattergl_select, gl2d_plot_interact, gl2d_click, scatterpolargl and splom pass. The one exception is hover with (x|y)period positioning and that one fails on main here too. The existing scattergl, scatterpolargl and splom mocks render the same as on main so no existing baseline changes. npm run regl-codegen gives no changes either.

Assisted by Claude Code.

`scatter` has `cliponaxis`, but `scattergl` always clips markers at the
plot area, so a marker on an axis shows only in part. If `cliponaxis` is
`false`, the marker layers now get a larger viewport and range, so these
markers show in full. Lines, fills, error bars and text stay clipped.

This branch has not been deployed

No deployments
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.

[FEATURE]: Support cliponaxis for scattergl (and other WebGL-based traces that reuse it)

1 participant