- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.9k
 
Fix period positioned hover to work in different time zones as well as on grouped bars #5864
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
Changes from 5 commits
01b4836
              585ddbd
              528801a
              b400917
              138707c
              21fa988
              3bdbedb
              3ba7ec7
              3e52b94
              bfed46b
              2c07925
              1b7fba1
              4d2961d
              1890e77
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Fix period positioned hover to work in different time zones [[#5864](https://github.com/plotly/plotly.js/pull/5864)] | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -1993,19 +1993,33 @@ function getCoord(axLetter, winningPoint, fullLayout) { | |
| var ax = winningPoint[axLetter + 'a']; | ||
| var val = winningPoint[axLetter + 'Val']; | ||
| 
     | 
||
| var trace = winningPoint.trace; | ||
| var cd = winningPoint.cd; | ||
| var d = cd[winningPoint.index]; | ||
| 
     | 
||
| if(ax.type === 'category') val = ax._categoriesMap[val]; | ||
| else if(ax.type === 'date') { | ||
| var period = winningPoint[axLetter + 'Period']; | ||
| val = ax.d2c(period !== undefined ? period : val); | ||
| var periodalignment = trace[axLetter + 'periodalignment']; | ||
| if(periodalignment) { | ||
| var start = d[axLetter + 'Start']; | ||
| var end = d[axLetter + 'End']; | ||
| var diff = end - start; | ||
| if(periodalignment === 'end') { | ||
| val += diff; | ||
| } else if(periodalignment === 'middle') { | ||
| val += diff / 2; | ||
| } | ||
| } | ||
| 
     | 
||
| val = ax.d2c(val); | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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  val = ax.d2c(period !== undefined ? period : val);To: val = period !== undefined ? period : ax.d2c(val);There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
                
       | 
||
| if( | ||
| fullLayout.boxmode === 'group' || | ||
| fullLayout.violinmode === 'group' | ||
| ) { | ||
| val += cd0.t.dPos; | ||
| val += d.t.dPos; | ||
| } | ||
| } | ||
| 
     | 
||
| 
          
            
          
           | 
    ||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.