-
Notifications
You must be signed in to change notification settings - Fork 121
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(timescale): consider timezone on axis ticks #151
Conversation
The d3-scale function, used to compute axis ticks, compute a discrete and nice rounded number of ticks on a time scale. By the way, this rounding is applied using UTC or local timezone, meaning that we cannot display a nicely rounded tick if we want to display data in a timezone different from the local or utc one. This commit includes a new optional prop to each series `timeZone` that can be used to configure this behaviour (default to utc). fix elastic#130
Codecov Report
@@ Coverage Diff @@
## master #151 +/- ##
==========================================
+ Coverage 94.03% 94.16% +0.13%
==========================================
Files 34 34
Lines 1744 1766 +22
Branches 219 224 +5
==========================================
+ Hits 1640 1663 +23
Misses 90 90
+ Partials 14 13 -1
Continue to review full report at Codecov.
|
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.
one minor naming suggestion, otherwise code LGTM (the tests are super for helping to understand the changes!)
@@ -179,10 +200,10 @@ export function linearStepAfter(invertedValue: number, minInterval: number): num | |||
* @param invertedValue the inverted value | |||
* @param minInterval the data minimum interval grether than 0 | |||
*/ | |||
export function linearStep(invertedValue: number, minInterval: number): number { | |||
const diff = invertedValue / minInterval; | |||
export function linearStep(minDomain: number, invertedValue: number, minInterval: number): number { |
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.
if I'm following correctly, minDomain
represents the domain's minimum value instead of the minimum possible domain. so I wonder if it this parameter could be domainMin
as opposed to minDomain
(which, especially since another parameter is called minInterval
, makes it seem like this is the minimum domain amount instead of the domain mininum). I guess the point I'm trying to get at is changing the name to reflect that in minInterval
we are describing the distance between numbers, while the other parameter currently called minDomain
is representing the minimum bound of a range of numbers.
maybe also we could add this param to the @param
docs on the function to clarify what this value is (and that it comes from the computed domain).
@@ -147,7 +163,12 @@ export function isLogarithmicScale(scale: Scale) { | |||
return scale.type === ScaleType.Log; | |||
} | |||
|
|||
function invertValue(invertedValue: number, minInterval: number, stepType?: StepType) { | |||
function invertValue( | |||
minDomain: number, |
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.
similar to the comment on minDomain
parameter in linearStep
, a suggestion to comment what this parameter represents (and possibly change the name).
🎉 This PR is included in version 3.7.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
## [3.7.2](elastic/elastic-charts@v3.7.1...v3.7.2) (2019-04-08) ### Bug Fixes * **timescale:** consider timezone on axis ticks ([opensearch-project#151](elastic/elastic-charts#151)) ([e4ee93e](elastic/elastic-charts@e4ee93e)), closes [opensearch-project#130](elastic/elastic-charts#130)
Summary
The
d3-scaleTime
andd3-scaleUtc
functions, used to compute axis ticks, compute a discrete and nice rounded number of ticks on a time scale. This rounding (the start of a day, an hour, a month, a year depending on the data interval) is applied to UTC or local timezones, meaning that we cannot display a nicely rounded tick if we want to display data in a timezone different from the local or utc one.This PR includes a new optional prop to each series
timeZone
that can be used to configure this behaviour (default to utc).To enable a nice rounded ticks on d3-scaleUtc on any timezone we followed this approach:
your current status:
the d3
scaleUtc
scale is implemented to display nicely rounded axis ticks, rounded to hours, days, months days, depending on the domain extent.This means that if my domain is
[1388556000000,1514786400000]
scaleUtc
will find the nice time based on UTC timezone, that means:2014-01-01T00:00:00.000-06:00
in milliseconds is1388556000000
1388556000000
in UTC is2014-01-01T06:00:00.000Z
scaleUtc
will compute the ticks and will round that nice value to2014-04-01T00:00:00.000Z
1388556000000
and graphically it will represented as the followingno matter what type of formatting you are applying to the text label, the positioning will be always shifted by -6 hours
To fix this, the idea is to apply a shift only on the axis scale. We want to shift the nice rounded value to the right place:
from
[1388556000000,1514786400000]
to[1388556000000 ,1514786400000]
WIP
fix #130
Display data with UTC-6 using UTC-6 as display timezone (the screenshot local timezone is UTC+1):
Display UTC timezoned data using UTC as display timezone
Display UTC timezoned data using local timezone (UTC+1) as display timezone (data is shifted to +1 but the ticks are nicely kept to UTC+1 rounded days
Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.[ ] This was checked for cross-browser compatibility, including a check against IE11