Skip to content

Commit a7227d1

Browse files
cryptoquicklukevmorris
authored andcommitted
Add milliseconds granularity wtih changes from danvk#777 with suggestions taken into account and mergeable with master.
1 parent 64f1c4d commit a7227d1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/dygraph-tickers.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ export var dateTicker = function(a, b, pixels, opts, dygraph, vals) {
220220

221221
// Time granularity enumeration
222222
export var Granularity = {
223+
MILLISECONDLY: 22,
224+
TWO_MILLISECONDLY: 23,
225+
FIVE_MILLISECONDLY: 24,
226+
TEN_MILLISECONDLY: 25,
227+
FIFTY_MILLISECONDLY: 26,
228+
HUNDRED_MILLISECONDLY: 27,
229+
FIVE_HUNDRED_MILLISECONDLY: 28,
223230
SECONDLY: 0,
224231
TWO_SECONDLY: 1,
225232
FIVE_SECONDLY: 2,
@@ -242,7 +249,7 @@ export var Granularity = {
242249
ANNUAL: 19,
243250
DECADAL: 20,
244251
CENTENNIAL: 21,
245-
NUM_GRANULARITIES: 22
252+
NUM_GRANULARITIES: 29
246253
}
247254

248255
// Date components enumeration (in the order of the arguments in Date)
@@ -273,6 +280,13 @@ var DateField = {
273280
* @type {Array.<{datefield:number, step:number, spacing:number}>}
274281
*/
275282
var TICK_PLACEMENT = [];
283+
TICK_PLACEMENT[Granularity.MILLISECONDLY] = {datefield: DateField.DATEFIELD_MS, step: 1, spacing: 1};
284+
TICK_PLACEMENT[Granularity.TWO_MILLISECONDLY] = {datefield: DateField.DATEFIELD_MS, step: 2, spacing: 2};
285+
TICK_PLACEMENT[Granularity.FIVE_MILLISECONDLY] = {datefield: DateField.DATEFIELD_MS, step: 5, spacing: 5};
286+
TICK_PLACEMENT[Granularity.TEN_MILLISECONDLY] = {datefield: DateField.DATEFIELD_MS, step: 10, spacing: 10};
287+
TICK_PLACEMENT[Granularity.FIFTY_MILLISECONDLY] = {datefield: DateField.DATEFIELD_MS, step: 50, spacing: 50};
288+
TICK_PLACEMENT[Granularity.HUNDRED_MILLISECONDLY] = {datefield: DateField.DATEFIELD_MS, step: 100, spacing: 100};
289+
TICK_PLACEMENT[Granularity.FIVE_HUNDRED_MILLISECONDLY] = {datefield: DateField.DATEFIELD_MS, step: 500, spacing: 500};
276290
TICK_PLACEMENT[Granularity.SECONDLY] = {datefield: DateField.DATEFIELD_SS, step: 1, spacing: 1000 * 1};
277291
TICK_PLACEMENT[Granularity.TWO_SECONDLY] = {datefield: DateField.DATEFIELD_SS, step: 2, spacing: 1000 * 2};
278292
TICK_PLACEMENT[Granularity.FIVE_SECONDLY] = {datefield: DateField.DATEFIELD_SS, step: 5, spacing: 1000 * 5};

src/dygraph-utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,11 @@ export function dateAxisLabelFormatter(date, granularity, opts) {
12141214
if (frac === 0 || granularity >= DygraphTickers.Granularity.DAILY) {
12151215
// e.g. '21 Jan' (%d%b)
12161216
return zeropad(day) + '&#160;' + SHORT_MONTH_NAMES_[month];
1217+
} else if (granularity < DygraphTickers.Granularity.SECONDLY) {
1218+
var str = "" + millis;
1219+
return zeropad(secs) + "." + ('000'+str).substring(str.length);
1220+
} else if (granularity > DygraphTickers.Granularity.MINUTELY) {
1221+
return hmsString_(hours, mins, secs, 0);
12171222
} else {
12181223
return hmsString_(hours, mins, secs, millis);
12191224
}

0 commit comments

Comments
 (0)