|
|
@ -1,5 +1,6 @@ |
|
|
|
var moment = require('../module/moment'); |
|
|
|
var DateUtil = require('./DateUtil'); |
|
|
|
var util = require('../util'); |
|
|
|
|
|
|
|
/** |
|
|
|
* @constructor TimeStep |
|
|
@ -48,32 +49,45 @@ function TimeStep(start, end, minimumStep, hiddenDates) { |
|
|
|
if (hiddenDates === undefined) { |
|
|
|
this.hiddenDates = []; |
|
|
|
} |
|
|
|
|
|
|
|
this.format = TimeStep.FORMAT; // default formatting
|
|
|
|
} |
|
|
|
|
|
|
|
// Time formatting
|
|
|
|
TimeStep.FORMAT = { |
|
|
|
minorLabels: { |
|
|
|
'millisecond':'SSS', |
|
|
|
'second': 's', |
|
|
|
'minute': 'HH:mm', |
|
|
|
'hour': 'HH:mm', |
|
|
|
'weekday': 'ddd D', |
|
|
|
'day': 'D', |
|
|
|
'month': 'MMM', |
|
|
|
'year': 'YYYY' |
|
|
|
millisecond:'SSS', |
|
|
|
second: 's', |
|
|
|
minute: 'HH:mm', |
|
|
|
hour: 'HH:mm', |
|
|
|
weekday: 'ddd D', |
|
|
|
day: 'D', |
|
|
|
month: 'MMM', |
|
|
|
year: 'YYYY' |
|
|
|
}, |
|
|
|
majorLabels: { |
|
|
|
'millisecond':'HH:mm:ss', |
|
|
|
'second': 'D MMMM HH:mm', |
|
|
|
'minute': 'ddd D MMMM', |
|
|
|
'hour': 'ddd D MMMM', |
|
|
|
'weekday': 'MMMM YYYY', |
|
|
|
'day': 'MMMM YYYY', |
|
|
|
'month': 'YYYY', |
|
|
|
'year': '' |
|
|
|
millisecond:'HH:mm:ss', |
|
|
|
second: 'D MMMM HH:mm', |
|
|
|
minute: 'ddd D MMMM', |
|
|
|
hour: 'ddd D MMMM', |
|
|
|
weekday: 'MMMM YYYY', |
|
|
|
day: 'MMMM YYYY', |
|
|
|
month: 'YYYY', |
|
|
|
year: '' |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Set custom formatting for the minor an major labels of the TimeStep. |
|
|
|
* Both `minorLabels` and `majorLabels` are an Object with properties: |
|
|
|
* 'millisecond, 'second, 'minute', 'hour', 'weekday, 'day, 'month, 'year'. |
|
|
|
* @param {{minorLabels: Object, majorLabels: Object}} format |
|
|
|
*/ |
|
|
|
TimeStep.prototype.setFormat = function (format) { |
|
|
|
var defaultFormat = util.deepExtend({}, TimeStep.FORMAT); |
|
|
|
this.format = util.deepExtend(defaultFormat, format); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Set a new range |
|
|
|
* If minimumStep is provided, the step size is chosen as close as possible |
|
|
@ -493,7 +507,7 @@ TimeStep.prototype.getLabelMinor = function(date) { |
|
|
|
date = this.current; |
|
|
|
} |
|
|
|
|
|
|
|
var format = TimeStep.FORMAT.minorLabels[this.scale]; |
|
|
|
var format = this.format.minorLabels[this.scale]; |
|
|
|
return (format && format.length > 0) ? moment(date).format(format) : ''; |
|
|
|
}; |
|
|
|
|
|
|
@ -508,7 +522,7 @@ TimeStep.prototype.getLabelMajor = function(date) { |
|
|
|
date = this.current; |
|
|
|
} |
|
|
|
|
|
|
|
var format = TimeStep.FORMAT.majorLabels[this.scale]; |
|
|
|
var format = this.format.majorLabels[this.scale]; |
|
|
|
return (format && format.length > 0) ? moment(date).format(format) : ''; |
|
|
|
}; |
|
|
|
|
|
|
|