Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zorder attribute to control stacking order of SVG traces drawn into cartesian subplots #6918

Merged
merged 49 commits into from
Apr 9, 2024

Conversation

emilykl
Copy link
Contributor

@emilykl emilykl commented Mar 9, 2024

What's new

  • Adds a new attribute zindex to SVG Cartesian traces
  • Behaves like CSS z-index: Traces with higher zindex values are drawn in front of traces with lower zindex values

Codepen

Screenshots:

Screenshot 2024-03-12 at 09 31 41

Screenshot 2024-03-12 at 09 31 16

TO DO:

  • Evaluate performance

dist/plotly-cartesian.js Outdated Show resolved Hide resolved
@ayjayt
Copy link
Contributor

ayjayt commented Mar 11, 2024

plotly/plotly.py#2345

@Farkites Farkites marked this pull request as ready for review March 12, 2024 09:58
@Farkites Farkites changed the title [DRAFT] Add z-index stacking attribute to traces Add z-index stacking attribute to traces Mar 12, 2024
@Farkites Farkites requested a review from archmoj March 12, 2024 10:03
@archmoj
Copy link
Contributor

archmoj commented Mar 25, 2024

@emilykl @Farkites
Right now on the master branch no traces are drawn inside overlayed subplot.
Instead those overlayed traces are drawn inside a layer called overplot

plotinfo.overplot = ensureSingle(plotgroup, 'g', 'overplot');

So it looks like handling the case of overlayed axes in this PR is possible with some minor changes 🤞

@Farkites
Copy link
Contributor

@emilykl @Farkites Right now on the master branch no traces are drawn inside overlayed subplot. Instead those overlayed traces are drawn inside a layer called overplot

plotinfo.overplot = ensureSingle(plotgroup, 'g', 'overplot');

So it looks like handling the case of overlayed axes in this PR is possible with some minor changes 🤞

The issue is that the overplot layer is drawn after the plot layer which contains the main plot. So the trace with the main axis has always have the lowest zindex for the plot to be correct.

@archmoj
Copy link
Contributor

archmoj commented Mar 25, 2024

@emilykl @Farkites Right now on the master branch no traces are drawn inside overlayed subplot. Instead those overlayed traces are drawn inside a layer called overplot

plotinfo.overplot = ensureSingle(plotgroup, 'g', 'overplot');

So it looks like handling the case of overlayed axes in this PR is possible with some minor changes 🤞

The issue is that the overplot layer is drawn after the plot layer which contains the main plot. So the trace with the main axis has always have the lowest zindex for the plot to be correct.

It looks like for traces in overlayed subplots we could default zindex to be greater than the maximum of all zindex values in the overlaying subplot.
Then we should be able to draw them in the main subplot instead of overplot one. No?

@archmoj
Copy link
Contributor

archmoj commented Apr 1, 2024

What is the desirable behavior when hovering over overlapping points?
For example in the following case if I hover over the first point at position y: 0 I get the info for the orange trace not the blue one which is placed on top.

Plotly.newPlot(gd, [{
    zindex: 100,
    marker: {size: 20},
    y: [0, 1]
}, {
    marker: {size: 20},
    y: [0, 2]
}]);

@archmoj archmoj changed the title Add z-index stacking attribute to traces Add z-index stacking attribute to cartesian SVG traces Apr 5, 2024
@archmoj
Copy link
Contributor

archmoj commented Apr 9, 2024

💃
Excellent PR.
Thanks @emilykl @Farkites 🏅

@archmoj archmoj merged commit 067ee11 into master Apr 9, 2024
1 check passed
@archmoj archmoj deleted the trace-zindex branch April 9, 2024 23:13
@archmoj archmoj changed the title Add z-index stacking attribute to cartesian SVG traces Add zorder attribute to control stacking order of SVG traces drawn into cartesian subplots Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants