Avoid overlap of point and axis hover labels - #6442
Conversation
|
Before I fix the tests, @archmoj could you have a look if this is a possible solution? 😄 |
|
Thanks for the PR. |
|
Sorry about that. I fixed it. |
|
Thanks and here is a codepen showing the proposed behavior. |
|
That sacrifice is fine IMO - a common label as short as |
|
Unfortunately I cannot reproduce the failing test locally. |
|
@archmoj Could you help me with the one failing test? Locally the test passes fine and I don't see an overlap of labels or why there would be one. Other than this test, this PR is ready from my side. |
The timezone test is to ensure we produce correct hover in different timezones: plotly.js/.circleci/config.yml Lines 52 to 68 in 70c49ce Could you switch the timezone or a use docker to debug? |
I can try. The same test also fails in |
You are right. It's also it('@noCI centered-aligned, should stack nicely upon each other', function(done) { |
|
Ok. I'll give docker a try on Monday. If it also passes there I'll add the |
|
I got a docker container up based on CI config. The test also failed there. I had to dig a bit but ultimately the positions and sizes on CI had minor differences to the local run. In one case this led to an overlap of less than 1 pixel between one hover label and axis label while the other labels didn't overlap. Thus the algorithm produced different layouts on CI and local runs. I changed the code to ignore overlaps of less than 1 pixel. So the approach is not perfect and we can still have some overlap in edge cases, e.g. when not all hover labels are stacked on top of each other, but I assume that is an edge case that we can live with. |
|
Thanks @dagroe. Now it looks very good to my eyes. |
|
@alexcjohnson would appreciate your review to hopefully see this in a release soon 😄 |
|
@dagroe nice touch continuing to allow the labels to show when the common label is very short ✨ I do notice a problem though, that doesn't seem to be present before this PR: sometimes labels in the middle now overlap each other: Here's the graph in that screenshot: Plotly.react(
gd,
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20].map(v=>({x:[100,200,300],y:[v,v+1,v+2]})),
{width:500,height:400,hovermode:'x'}
)If all the y values are the same (as in your screenshots above) this problem doesn't occur. Plotly.react(
gd,
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20].map(v=>({x:[100,200,300],y:[1,2,3]})),
{width:500,height:400,hovermode:'x'}
) |
|
looks like in that particular case, the 2-digit labels slide behind the 1-digit labels 🤔 |
|
Good catch @alexcjohnson. Seems I was actually using the wrong I fixed it and added a test for the example you provided. No idea what is happening with CI. @archmoj can you help with that? |
|
hmph that's a weird CI error, but I get a similar failure when I try to pull your changes locally, looks like something went wrong at the git level 🙄 Usually we don't like to do this because it makes re-reviews harder, but maybe you could try to rebase locally, then force push? Just so git goes through the motions again and hopefully avoids whatever it broke here? |
c925d9d to
9e75c94
Compare
|
That worked, thanks. One test I added fails. Seems the intersection takes the entire axis-label width into account instead only the actual |
alexcjohnson
left a comment
There was a problem hiding this comment.
Behavior looks good to me now - I tried a few more cases like several separated groups that get pushed together:
Plotly.react(
gd,
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20].map(v0=>{
const v = v0 > 9 ? v0 + 100 : v0; return {x:[100,200,300],y:[v,v+1,v+2]}
}),
{width:500,height:400,hovermode:'x',margin:{t:0}}
)Seems like the logic is solid now. Once the tests are passing I think this is good to go! 💃
|
I implemented the changes mentioned above. The test that failed passes now as expected but one test marked as |
All passed. |
👍 Done |
|
@alexcjohnson @archmoj Is this ready to be merged? |





This is an attempt at resolving issue #3973
When hover info extends below the lower edge of the plot it may overlap the hover axis info, as illustrated in this codepen: https://codepen.io/dagroe/pen/BaPmNXr
The goal of this MR is to move the hover info up to always be above the lower edge and thus above the axis hover info.