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 period positioned hover to work in different time zones as well as on grouped bars #5864

Merged
merged 14 commits into from
Jul 29, 2021

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Jul 28, 2021

Fixes #5822 (comment) | cc: #5861
Also closes #5841.

@plotly/plotly_js

@archmoj archmoj added bug something broken status: reviewable labels Jul 28, 2021
@archmoj archmoj requested a review from alexcjohnson July 28, 2021 21:46
}
}

val = ax.d2c(val);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@archmoj Can you explain why the previous code was timezone-dependent, and how this fixes it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous logic used start and end of period directly which appears to depend on the time zone.
But now we only use the difference between two which should not be impacted by time zone.
We will keep #5861 open until we could further investigate other time zone problems.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah ok, I think I understand it now. The previous one had the advantage of front-loading more of the calculation, so let's try and get back toward that. I think what's going on is when you pull out the period with:

var period = winningPoint[axLetter + 'Period'];

This is already in calcdata format - ie a number - so when we run ax.d2c on it we get the legacy convert-from-local-to-UTC behavior. But val is in data format - ie a string - so it needs ax.d2c. So the right solution is to just change the one line:

val = ax.d2c(period !== undefined ? period : val);

To:

val = period !== undefined ? period : ax.d2c(val);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the hint. There was actually a problem in new code which is fixed now.
Unfortunately trying val = period !== undefined ? period : ax.d2c(val); didn't pass the tests.
However xStart and xEnd are coming from the calc step so the changes should be fast.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm OK - well, this seems to work so let's go with it. Thanks for investigating!

}

var cd0 = winningPoint.cd[winningPoint.index];
if(cd0 && cd0.t && cd0.t.posLetter === ax._id) {
if(d && d.t && d.t.posLetter === ax._id) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code has been around for ages but I'm just noticing it now and it confused the heck out of me: normally the t object only exists on the first entry in cd (that's why the var we extracted it from was called cd0) because it contains extra calculated info that applies to the whole trace. And at the calc step that's true of box and violin too. But then during the plot step it appears these traces add t to all cd entries so that if you draw points, the one box the points are for will look like a whole trace to the reused scatter code with which we're drawing the points.

So yes, this works... but only due to a quirk of our drawing code and only for box and violin, so it feels fragile. Nonblocking, but when we need t we should really get it from cd[0].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What you suggesting here is renaming d back to cd0? Or I should simply add a comment above cd0.d?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm saying instead of assuming box & violin will have t in every element of cd (d is cd[winningPoint.index] and winningPoint.index need not be zero) we should be using cd[0].t.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 3e52b94

@archmoj archmoj changed the title Fix period hover to work in different time zones Fix period positioned hover to work in different time zones as well as on grouped bars Jul 29, 2021
@archmoj archmoj requested a review from alexcjohnson July 29, 2021 18:49
- run:
name: Run hover_label test in America/Toronto timezone
environment:
TZ: "America/Toronto"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need all these time zones to be tested?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's pretty quick, might as well keep them all for now.

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.

💃 Let's go!

@archmoj archmoj merged commit 129fc2a into master Jul 29, 2021
@archmoj archmoj deleted the period-hover-timezone branch July 29, 2021 20:07
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
Development

Successfully merging this pull request may close these issues.

Bars and unified hover location with half-years periods hover misplaced with period positioning
2 participants