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

Fix hover with period alignment points and improve positioning of spikes and unified hover label #5846

Merged
merged 28 commits into from
Jul 23, 2021

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Jul 21, 2021

Fixes #5822, fixes #5841 and fixes #5721.

@plotly/plotly_js

@archmoj archmoj added bug something broken status: reviewable labels Jul 21, 2021
@archmoj archmoj added this to the v2.3.0 milestone Jul 21, 2021
@nicolaskruchten
Copy link
Contributor

This looks good AFAICT! @alexcjohnson can we get an expedited review plz?

'bar : 1'
]});

_hover(gd, { xpx: 210, ypx: 200 });
assertLabel({title: 'Jan', items: [
'bar : (Jan 1, 2000, 1)',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 5348 has a typo that's making this test confusing (xhoverfrmat)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good eye. Addressed in 7c37e98.

@alexcjohnson
Copy link
Collaborator

Looking specifically at the test I commented on above but having fixed the typo, here's the behavior on master:
pre-5846
It's not perfect, I don't think we should be showing Jan while the cursor is over the first half of Feb, but otherwise I actually think it looks correct: the spikeline shows the point that wins and the hover label shows all traces that match that period and it's positioned at one edge of the period.

Here's the behavior currently with this PR:
with-5846
Now the hoverlabel is positioned at the spikeline regardless of the period, it very often does NOT contain all the traces with points in a matching period, and when you do get multiple traces you mix points representing different periods - with some very weird flipping between two winning points right around the period boundary.

I thought at one point we had the idea that a period-positioned scatter trace should behave like a bar for hover purposes, in that any given point should be included in the hover whenever your cursor is over the period it represents. Did we drop that idea?

@nicolaskruchten
Copy link
Contributor

a period-positioned scatter trace should behave like a bar for hover purposes

Yes, here are the period-positioning invariants: #5553

The behaviour you note above is indeed troubling. Which mock is this?

@nicolaskruchten
Copy link
Contributor

I'm also seeing some odd spikeline/hover mismatches in the all-bar case: https://codepen.io/nicolaskruchten/pen/bGWoVKB?editors=0010

unified

@alexcjohnson
Copy link
Collaborator

It's this, from the test I commented on:

var scatterType = 'scatter';
Plotly.newPlot(gd, {
                data: [
                    {
                        name: 'bar',
                        type: 'bar',
                        x: ['2000-01', '2000-02'],
                        y: [1, 2],
                        xhoverformat: '%b',
                        xperiod: 'M1'
                    },
                    {
                        name: 'start',
                        type: scatterType,
                        x: ['2000-01', '2000-02'],
                        y: [1, 2],
                        xhoverformat: '%b',
                        xperiod: 'M1',
                        xperiodalignment: 'start'
                    },
                    {
                        name: 'end',
                        type: scatterType,
                        x: ['2000-01', '2000-02'],
                        y: [1, 2],
                        xhoverformat: '%b',
                        xperiod: 'M1',
                        xperiodalignment: 'end'
                    },
                ],
                layout: {
                    showlegend: false,
                    width: 600,
                    height: 400,
                    hovermode: 'x unified'
                }
            })

@archmoj archmoj requested a review from alexcjohnson July 21, 2021 20:12
@alexcjohnson
Copy link
Collaborator

Better, it's now consistently showing all the traces I think it should. I still think we need to push the hover label outside the period the winning point represents, and right now it seems the hover label and spike line positions are referenced to different points: the label at the first (?) point in the hover set, but the spike line at the winning point. For example in the period_positioning3 mock, with my cursor near the end of May, I can't see the brown point or most of the red point being hovered on, and the spike line is obscured:
Screen Shot 2021-07-21 at 4 56 21 PM

@nicolaskruchten
Copy link
Contributor

Agreed with Alex's point above: the hoverlabel should always be to the side of the spikeline (as it is on master I believe)

@nicolaskruchten
Copy link
Contributor

nicolaskruchten commented Jul 22, 2021

With this build, I don't seem to be able to hover on the left-most points in the figure from #5822 ... see https://codepen.io/nicolaskruchten/pen/MWmEzeJ?editors=0010

@archmoj
Copy link
Contributor Author

archmoj commented Jul 22, 2021

With this build, I don't seem to be able to hover on the left-most points in the figure from #5822 ... see https://codepen.io/nicolaskruchten/pen/MWmEzeJ?editors=0010

Good catch. Thank you!

@archmoj
Copy link
Contributor Author

archmoj commented Jul 22, 2021

But I can see your argument, I'd be OK with pushing the label back to the spike line at least when it's a scatter point that wins. I think if it's a bar that wins it's still better to push it to the edge of the bar, and in fact to the edge of the bar group when we're labeling the whole group.

@archmoj can we do this please? When the scatter point wins, it's ok for the hovelabel to occlude the bar.

Good idea. Applied in 16f4554.

@alexcjohnson
Copy link
Collaborator

It's still possible to have the hover label occluding the spikeline - hover on the right half of any period in period_positioning3
Screen Shot 2021-07-22 at 5 16 30 PM

@nicolaskruchten
Copy link
Contributor

I think this is a case of the spike line not matching the hover-winning point, which is indeed a bug, and it seems worse with this PR than on master. Can we see if there's a fix for it plz?

@archmoj
Copy link
Contributor Author

archmoj commented Jul 22, 2021

It's still possible to have the hover label occluding the spikeline - hover on the right half of any period in period_positioning3
Screen Shot 2021-07-22 at 5 16 30 PM

That's simply because of "When the scatter point wins, it's ok for the hovelabel to occlude the bar" logic added in 16f4554. Without it there would be no occlusion with spikeline :)

@archmoj
Copy link
Contributor Author

archmoj commented Jul 22, 2021

I think this is a case of the spike line not matching the hover-winning point, which is indeed a bug, and it seems worse with this PR than on master. Can we see if there's a fix for it plz?

This is also true : )

@nicolaskruchten
Copy link
Contributor

Let's try to fix the spike line position too please before merging this. It should not be possible for the spike line to be on a different point that the winning point: there's a specific attribute for that.

@archmoj
Copy link
Contributor Author

archmoj commented Jul 22, 2021

Let's try to fix the spike line position too please before merging this. It should not be possible for the spike line to be on a different point that the winning point: there's a specific attribute for that.

On it.

@archmoj
Copy link
Contributor Author

archmoj commented Jul 22, 2021

Let's try to fix the spike line position too please before merging this. It should not be possible for the spike line to be on a different point that the winning point: there's a specific attribute for that.

Done in dca5b1e.

 - also adjust scattergl and splom hover label position
@nicolaskruchten
Copy link
Contributor

Closer! So in this pen: https://codepen.io/nicolaskruchten/pen/xxdPKwZ?editors=0010 when I hover over the left-most point I get no bar in the hoverlabel, and when I hover on the next point I get the left-most bar in the hoverset. This is even more apparent when hovermode = 'x'.

I should add that the vertical position over the hoverlabels seems too low in this pen: https://codepen.io/nicolaskruchten/pen/QWvOLjJ?editors=0010 ... the hoverlabel is always around the bottom two points for me.

@archmoj
Copy link
Contributor Author

archmoj commented Jul 23, 2021

I should add that the vertical position over the hoverlabels seems too low in this pen: https://codepen.io/nicolaskruchten/pen/QWvOLjJ?editors=0010 ... the hoverlabel is always around the bottom two points for me.

Good catch. Fixed in df6353d

@archmoj
Copy link
Contributor Author

archmoj commented Jul 23, 2021

Closer! So in this pen: https://codepen.io/nicolaskruchten/pen/xxdPKwZ?editors=0010 when I hover over the left-most point I get no bar in the hoverlabel, and when I hover on the next point I get the left-most bar in the hoverset. This is even more apparent when hovermode = 'x'.

That's a bug.

@archmoj
Copy link
Contributor Author

archmoj commented Jul 23, 2021

Closer! So in this pen: https://codepen.io/nicolaskruchten/pen/xxdPKwZ?editors=0010 when I hover over the left-most point I get no bar in the hoverlabel, and when I hover on the next point I get the left-most bar in the hoverset. This is even more apparent when hovermode = 'x'.

That's a bug.

Addressed in 9217db4.

@nicolaskruchten
Copy link
Contributor

OK, this last set of changes nails down everything I care about! There's still some oddity around end-positioned grouped-bars but we can leave that out for now.

@alexcjohnson over to you, again :)

@archmoj archmoj changed the title Fix misplaced hover with period positioning Fix hover with period alignment points and improve positioning of spikes and unified hover label Jul 23, 2021
Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃 I think we have a winner! 🏆

@archmoj archmoj merged commit 87e4e12 into master Jul 23, 2021
@archmoj archmoj deleted the fix5822-hover-with-period branch July 23, 2021 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
3 participants