Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions auto_tests/tests/date_ticker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 37 additions & 23 deletions src/dygraph-tickers.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,29 +220,36 @@ export var dateTicker = function(a, b, pixels, opts, dygraph, vals) {

// Time granularity enumeration
export var Granularity = {
SECONDLY: 0,
TWO_SECONDLY: 1,
FIVE_SECONDLY: 2,
TEN_SECONDLY: 3,
THIRTY_SECONDLY : 4,
MINUTELY: 5,
TWO_MINUTELY: 6,
FIVE_MINUTELY: 7,
TEN_MINUTELY: 8,
THIRTY_MINUTELY: 9,
HOURLY: 10,
TWO_HOURLY: 11,
SIX_HOURLY: 12,
DAILY: 13,
TWO_DAILY: 14,
WEEKLY: 15,
MONTHLY: 16,
QUARTERLY: 17,
BIANNUAL: 18,
ANNUAL: 19,
DECADAL: 20,
CENTENNIAL: 21,
NUM_GRANULARITIES: 22
MSLY: 0,
TWO_MSLY: 1,
FIVE_MSLY: 2,
TEN_MSLY: 3,
FIFTY_MSLY: 4,
HTH_MSLY: 5,
FHTH_MSLY: 6,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What does HTH mean? At first I though "hundred thousand", but that doesn't make sense here; this is just 100/500.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My bad, you're right :)
Would HUNDRED_MSLY and FIVE_HUNDRED_MSLY be ok for you ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Personally, I think there's no harm in spelling out "millisecond" instead of just using "ms". But, it's not my code 😉 (Also, as I mentioned in #776 I think it'd be interesting to explore alternative approaches that make this more customizable.)

SECONDLY: 7,
TWO_SECONDLY: 8,
FIVE_SECONDLY: 9,
TEN_SECONDLY: 10,
THIRTY_SECONDLY: 11,
MINUTELY: 12,
TWO_MINUTELY: 13,
FIVE_MINUTELY: 14,
TEN_MINUTELY: 15,
THIRTY_MINUTELY: 16,
HOURLY: 17,
TWO_HOURLY: 18,
SIX_HOURLY: 19,
DAILY: 20,
TWO_DAILY: 21,
WEEKLY: 22,
MONTHLY: 23,
QUARTERLY: 24,
BIANNUAL: 25,
ANNUAL: 26,
DECADAL: 27,
CENTENNIAL: 28,
NUM_GRANULARITIES: 29,
}

// Date components enumeration (in the order of the arguments in Date)
Expand Down Expand Up @@ -273,6 +280,13 @@ var DateField = {
* @type {Array.<{datefield:number, step:number, spacing:number}>}
*/
var TICK_PLACEMENT = [];
TICK_PLACEMENT[Granularity.MSLY] = {datefield: DateField.DATEFIELD_MS, step: 1, spacing: 1};
TICK_PLACEMENT[Granularity.TWO_MSLY] = {datefield: DateField.DATEFIELD_MS, step: 2, spacing: 2};
TICK_PLACEMENT[Granularity.FIVE_MSLY] = {datefield: DateField.DATEFIELD_MS, step: 5, spacing: 5};
TICK_PLACEMENT[Granularity.TEN_MSLY] = {datefield: DateField.DATEFIELD_MS, step: 10, spacing: 10};
TICK_PLACEMENT[Granularity.FIFTY_MSLY] = {datefield: DateField.DATEFIELD_MS, step: 50, spacing: 50};
TICK_PLACEMENT[Granularity.HTH_MSLY] = {datefield: DateField.DATEFIELD_MS, step: 100, spacing: 100};
TICK_PLACEMENT[Granularity.FHTH_MSLY] = {datefield: DateField.DATEFIELD_MS, step: 500, spacing: 500};
TICK_PLACEMENT[Granularity.SECONDLY] = {datefield: DateField.DATEFIELD_SS, step: 1, spacing: 1000 * 1};
TICK_PLACEMENT[Granularity.TWO_SECONDLY] = {datefield: DateField.DATEFIELD_SS, step: 2, spacing: 1000 * 2};
TICK_PLACEMENT[Granularity.FIVE_SECONDLY] = {datefield: DateField.DATEFIELD_SS, step: 5, spacing: 1000 * 5};
Expand Down
5 changes: 5 additions & 0 deletions src/dygraph-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,11 @@ export function dateAxisLabelFormatter(date, granularity, opts) {
if (frac === 0 || granularity >= DygraphTickers.Granularity.DAILY) {
// e.g. '21 Jan' (%d%b)
return zeropad(day) + '&#160;' + SHORT_MONTH_NAMES_[month];
} else if (granularity < DygraphTickers.Granularity.SECONDLY) {
var str = "" + millis;
return zeropad(secs) + "." + ('000'+str).substring(str.length);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Add an example of what this looks like.

} else if (granularity > DygraphTickers.Granularity.MINUTELY) {
return hmsString_(hours, mins, secs, 0);
} else {
return hmsString_(hours, mins, secs, millis);
}
Expand Down