vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

525 lines
21 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. var moment = require('../module/moment');
  2. var DateUtil = require('./DateUtil');
  3. /**
  4. * @constructor TimeStep
  5. * The class TimeStep is an iterator for dates. You provide a start date and an
  6. * end date. The class itself determines the best scale (step size) based on the
  7. * provided start Date, end Date, and minimumStep.
  8. *
  9. * If minimumStep is provided, the step size is chosen as close as possible
  10. * to the minimumStep but larger than minimumStep. If minimumStep is not
  11. * provided, the scale is set to 1 DAY.
  12. * The minimumStep should correspond with the onscreen size of about 6 characters
  13. *
  14. * Alternatively, you can set a scale by hand.
  15. * After creation, you can initialize the class by executing first(). Then you
  16. * can iterate from the start date to the end date via next(). You can check if
  17. * the end date is reached with the function hasNext(). After each step, you can
  18. * retrieve the current date via getCurrent().
  19. * The TimeStep has scales ranging from milliseconds, seconds, minutes, hours,
  20. * days, to years.
  21. *
  22. * Version: 1.2
  23. *
  24. * @param {Date} [start] The start date, for example new Date(2010, 9, 21)
  25. * or new Date(2010, 9, 21, 23, 45, 00)
  26. * @param {Date} [end] The end date
  27. * @param {Number} [minimumStep] Optional. Minimum step size in milliseconds
  28. */
  29. function TimeStep(start, end, minimumStep, hiddenDates) {
  30. // variables
  31. this.current = new Date();
  32. this._start = new Date();
  33. this._end = new Date();
  34. this.autoScale = true;
  35. this.scale = TimeStep.SCALE.DAY;
  36. this.step = 1;
  37. // initialize the range
  38. this.setRange(start, end, minimumStep);
  39. // hidden Dates options
  40. this.switchedDay = false;
  41. this.switchedMonth = false;
  42. this.switchedYear = false;
  43. this.hiddenDates = hiddenDates;
  44. if (hiddenDates === undefined) {
  45. this.hiddenDates = [];
  46. }
  47. }
  48. /// enum scale
  49. TimeStep.SCALE = {
  50. MILLISECOND: 1,
  51. SECOND: 2,
  52. MINUTE: 3,
  53. HOUR: 4,
  54. DAY: 5,
  55. WEEKDAY: 6,
  56. MONTH: 7,
  57. YEAR: 8
  58. };
  59. /**
  60. * Set a new range
  61. * If minimumStep is provided, the step size is chosen as close as possible
  62. * to the minimumStep but larger than minimumStep. If minimumStep is not
  63. * provided, the scale is set to 1 DAY.
  64. * The minimumStep should correspond with the onscreen size of about 6 characters
  65. * @param {Date} [start] The start date and time.
  66. * @param {Date} [end] The end date and time.
  67. * @param {int} [minimumStep] Optional. Minimum step size in milliseconds
  68. */
  69. TimeStep.prototype.setRange = function(start, end, minimumStep) {
  70. if (!(start instanceof Date) || !(end instanceof Date)) {
  71. throw "No legal start or end date in method setRange";
  72. }
  73. this._start = (start != undefined) ? new Date(start.valueOf()) : new Date();
  74. this._end = (end != undefined) ? new Date(end.valueOf()) : new Date();
  75. if (this.autoScale) {
  76. this.setMinimumStep(minimumStep);
  77. }
  78. };
  79. /**
  80. * Set the range iterator to the start date.
  81. */
  82. TimeStep.prototype.first = function() {
  83. this.current = new Date(this._start.valueOf());
  84. this.roundToMinor();
  85. };
  86. /**
  87. * Round the current date to the first minor date value
  88. * This must be executed once when the current date is set to start Date
  89. */
  90. TimeStep.prototype.roundToMinor = function() {
  91. // round to floor
  92. // IMPORTANT: we have no breaks in this switch! (this is no bug)
  93. //noinspection FallthroughInSwitchStatementJS
  94. switch (this.scale) {
  95. case TimeStep.SCALE.YEAR:
  96. this.current.setFullYear(this.step * Math.floor(this.current.getFullYear() / this.step));
  97. this.current.setMonth(0);
  98. case TimeStep.SCALE.MONTH: this.current.setDate(1);
  99. case TimeStep.SCALE.DAY: // intentional fall through
  100. case TimeStep.SCALE.WEEKDAY: this.current.setHours(0);
  101. case TimeStep.SCALE.HOUR: this.current.setMinutes(0);
  102. case TimeStep.SCALE.MINUTE: this.current.setSeconds(0);
  103. case TimeStep.SCALE.SECOND: this.current.setMilliseconds(0);
  104. //case TimeStep.SCALE.MILLISECOND: // nothing to do for milliseconds
  105. }
  106. if (this.step != 1) {
  107. // round down to the first minor value that is a multiple of the current step size
  108. switch (this.scale) {
  109. case TimeStep.SCALE.MILLISECOND: this.current.setMilliseconds(this.current.getMilliseconds() - this.current.getMilliseconds() % this.step); break;
  110. case TimeStep.SCALE.SECOND: this.current.setSeconds(this.current.getSeconds() - this.current.getSeconds() % this.step); break;
  111. case TimeStep.SCALE.MINUTE: this.current.setMinutes(this.current.getMinutes() - this.current.getMinutes() % this.step); break;
  112. case TimeStep.SCALE.HOUR: this.current.setHours(this.current.getHours() - this.current.getHours() % this.step); break;
  113. case TimeStep.SCALE.WEEKDAY: // intentional fall through
  114. case TimeStep.SCALE.DAY: this.current.setDate((this.current.getDate()-1) - (this.current.getDate()-1) % this.step + 1); break;
  115. case TimeStep.SCALE.MONTH: this.current.setMonth(this.current.getMonth() - this.current.getMonth() % this.step); break;
  116. case TimeStep.SCALE.YEAR: this.current.setFullYear(this.current.getFullYear() - this.current.getFullYear() % this.step); break;
  117. default: break;
  118. }
  119. }
  120. };
  121. /**
  122. * Check if the there is a next step
  123. * @return {boolean} true if the current date has not passed the end date
  124. */
  125. TimeStep.prototype.hasNext = function () {
  126. return (this.current.valueOf() <= this._end.valueOf());
  127. };
  128. /**
  129. * Do the next step
  130. */
  131. TimeStep.prototype.next = function() {
  132. var prev = this.current.valueOf();
  133. // Two cases, needed to prevent issues with switching daylight savings
  134. // (end of March and end of October)
  135. if (this.current.getMonth() < 6) {
  136. switch (this.scale) {
  137. case TimeStep.SCALE.MILLISECOND:
  138. this.current = new Date(this.current.valueOf() + this.step); break;
  139. case TimeStep.SCALE.SECOND: this.current = new Date(this.current.valueOf() + this.step * 1000); break;
  140. case TimeStep.SCALE.MINUTE: this.current = new Date(this.current.valueOf() + this.step * 1000 * 60); break;
  141. case TimeStep.SCALE.HOUR:
  142. this.current = new Date(this.current.valueOf() + this.step * 1000 * 60 * 60);
  143. // in case of skipping an hour for daylight savings, adjust the hour again (else you get: 0h 5h 9h ... instead of 0h 4h 8h ...)
  144. var h = this.current.getHours();
  145. this.current.setHours(h - (h % this.step));
  146. break;
  147. case TimeStep.SCALE.WEEKDAY: // intentional fall through
  148. case TimeStep.SCALE.DAY: this.current.setDate(this.current.getDate() + this.step); break;
  149. case TimeStep.SCALE.MONTH: this.current.setMonth(this.current.getMonth() + this.step); break;
  150. case TimeStep.SCALE.YEAR: this.current.setFullYear(this.current.getFullYear() + this.step); break;
  151. default: break;
  152. }
  153. }
  154. else {
  155. switch (this.scale) {
  156. case TimeStep.SCALE.MILLISECOND: this.current = new Date(this.current.valueOf() + this.step); break;
  157. case TimeStep.SCALE.SECOND: this.current.setSeconds(this.current.getSeconds() + this.step); break;
  158. case TimeStep.SCALE.MINUTE: this.current.setMinutes(this.current.getMinutes() + this.step); break;
  159. case TimeStep.SCALE.HOUR: this.current.setHours(this.current.getHours() + this.step); break;
  160. case TimeStep.SCALE.WEEKDAY: // intentional fall through
  161. case TimeStep.SCALE.DAY: this.current.setDate(this.current.getDate() + this.step); break;
  162. case TimeStep.SCALE.MONTH: this.current.setMonth(this.current.getMonth() + this.step); break;
  163. case TimeStep.SCALE.YEAR: this.current.setFullYear(this.current.getFullYear() + this.step); break;
  164. default: break;
  165. }
  166. }
  167. if (this.step != 1) {
  168. // round down to the correct major value
  169. switch (this.scale) {
  170. case TimeStep.SCALE.MILLISECOND: if(this.current.getMilliseconds() < this.step) this.current.setMilliseconds(0); break;
  171. case TimeStep.SCALE.SECOND: if(this.current.getSeconds() < this.step) this.current.setSeconds(0); break;
  172. case TimeStep.SCALE.MINUTE: if(this.current.getMinutes() < this.step) this.current.setMinutes(0); break;
  173. case TimeStep.SCALE.HOUR: if(this.current.getHours() < this.step) this.current.setHours(0); break;
  174. case TimeStep.SCALE.WEEKDAY: // intentional fall through
  175. case TimeStep.SCALE.DAY: if(this.current.getDate() < this.step+1) this.current.setDate(1); break;
  176. case TimeStep.SCALE.MONTH: if(this.current.getMonth() < this.step) this.current.setMonth(0); break;
  177. case TimeStep.SCALE.YEAR: break; // nothing to do for year
  178. default: break;
  179. }
  180. }
  181. // safety mechanism: if current time is still unchanged, move to the end
  182. if (this.current.valueOf() == prev) {
  183. this.current = new Date(this._end.valueOf());
  184. }
  185. DateUtil.stepOverHiddenDates(this, prev);
  186. };
  187. /**
  188. * Get the current datetime
  189. * @return {Date} current The current date
  190. */
  191. TimeStep.prototype.getCurrent = function() {
  192. return this.current;
  193. };
  194. /**
  195. * Set a custom scale. Autoscaling will be disabled.
  196. * For example setScale(SCALE.MINUTES, 5) will result
  197. * in minor steps of 5 minutes, and major steps of an hour.
  198. *
  199. * @param {TimeStep.SCALE} newScale
  200. * A scale. Choose from SCALE.MILLISECOND,
  201. * SCALE.SECOND, SCALE.MINUTE, SCALE.HOUR,
  202. * SCALE.WEEKDAY, SCALE.DAY, SCALE.MONTH,
  203. * SCALE.YEAR.
  204. * @param {Number} newStep A step size, by default 1. Choose for
  205. * example 1, 2, 5, or 10.
  206. */
  207. TimeStep.prototype.setScale = function(newScale, newStep) {
  208. this.scale = newScale;
  209. if (newStep > 0) {
  210. this.step = newStep;
  211. }
  212. this.autoScale = false;
  213. };
  214. /**
  215. * Enable or disable autoscaling
  216. * @param {boolean} enable If true, autoascaling is set true
  217. */
  218. TimeStep.prototype.setAutoScale = function (enable) {
  219. this.autoScale = enable;
  220. };
  221. /**
  222. * Automatically determine the scale that bests fits the provided minimum step
  223. * @param {Number} [minimumStep] The minimum step size in milliseconds
  224. */
  225. TimeStep.prototype.setMinimumStep = function(minimumStep) {
  226. if (minimumStep == undefined) {
  227. return;
  228. }
  229. var stepYear = (1000 * 60 * 60 * 24 * 30 * 12);
  230. var stepMonth = (1000 * 60 * 60 * 24 * 30);
  231. var stepDay = (1000 * 60 * 60 * 24);
  232. var stepHour = (1000 * 60 * 60);
  233. var stepMinute = (1000 * 60);
  234. var stepSecond = (1000);
  235. var stepMillisecond= (1);
  236. // find the smallest step that is larger than the provided minimumStep
  237. if (stepYear*1000 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 1000;}
  238. if (stepYear*500 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 500;}
  239. if (stepYear*100 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 100;}
  240. if (stepYear*50 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 50;}
  241. if (stepYear*10 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 10;}
  242. if (stepYear*5 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 5;}
  243. if (stepYear > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 1;}
  244. if (stepMonth*3 > minimumStep) {this.scale = TimeStep.SCALE.MONTH; this.step = 3;}
  245. if (stepMonth > minimumStep) {this.scale = TimeStep.SCALE.MONTH; this.step = 1;}
  246. if (stepDay*5 > minimumStep) {this.scale = TimeStep.SCALE.DAY; this.step = 5;}
  247. if (stepDay*2 > minimumStep) {this.scale = TimeStep.SCALE.DAY; this.step = 2;}
  248. if (stepDay > minimumStep) {this.scale = TimeStep.SCALE.DAY; this.step = 1;}
  249. if (stepDay/2 > minimumStep) {this.scale = TimeStep.SCALE.WEEKDAY; this.step = 1;}
  250. if (stepHour*4 > minimumStep) {this.scale = TimeStep.SCALE.HOUR; this.step = 4;}
  251. if (stepHour > minimumStep) {this.scale = TimeStep.SCALE.HOUR; this.step = 1;}
  252. if (stepMinute*15 > minimumStep) {this.scale = TimeStep.SCALE.MINUTE; this.step = 15;}
  253. if (stepMinute*10 > minimumStep) {this.scale = TimeStep.SCALE.MINUTE; this.step = 10;}
  254. if (stepMinute*5 > minimumStep) {this.scale = TimeStep.SCALE.MINUTE; this.step = 5;}
  255. if (stepMinute > minimumStep) {this.scale = TimeStep.SCALE.MINUTE; this.step = 1;}
  256. if (stepSecond*15 > minimumStep) {this.scale = TimeStep.SCALE.SECOND; this.step = 15;}
  257. if (stepSecond*10 > minimumStep) {this.scale = TimeStep.SCALE.SECOND; this.step = 10;}
  258. if (stepSecond*5 > minimumStep) {this.scale = TimeStep.SCALE.SECOND; this.step = 5;}
  259. if (stepSecond > minimumStep) {this.scale = TimeStep.SCALE.SECOND; this.step = 1;}
  260. if (stepMillisecond*200 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 200;}
  261. if (stepMillisecond*100 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 100;}
  262. if (stepMillisecond*50 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 50;}
  263. if (stepMillisecond*10 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 10;}
  264. if (stepMillisecond*5 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 5;}
  265. if (stepMillisecond > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 1;}
  266. };
  267. /**
  268. * Snap a date to a rounded value.
  269. * The snap intervals are dependent on the current scale and step.
  270. * @param {Date} date the date to be snapped.
  271. * @return {Date} snappedDate
  272. */
  273. TimeStep.prototype.snap = function(date) {
  274. var clone = new Date(date.valueOf());
  275. if (this.scale == TimeStep.SCALE.YEAR) {
  276. var year = clone.getFullYear() + Math.round(clone.getMonth() / 12);
  277. clone.setFullYear(Math.round(year / this.step) * this.step);
  278. clone.setMonth(0);
  279. clone.setDate(0);
  280. clone.setHours(0);
  281. clone.setMinutes(0);
  282. clone.setSeconds(0);
  283. clone.setMilliseconds(0);
  284. }
  285. else if (this.scale == TimeStep.SCALE.MONTH) {
  286. if (clone.getDate() > 15) {
  287. clone.setDate(1);
  288. clone.setMonth(clone.getMonth() + 1);
  289. // important: first set Date to 1, after that change the month.
  290. }
  291. else {
  292. clone.setDate(1);
  293. }
  294. clone.setHours(0);
  295. clone.setMinutes(0);
  296. clone.setSeconds(0);
  297. clone.setMilliseconds(0);
  298. }
  299. else if (this.scale == TimeStep.SCALE.DAY) {
  300. //noinspection FallthroughInSwitchStatementJS
  301. switch (this.step) {
  302. case 5:
  303. case 2:
  304. clone.setHours(Math.round(clone.getHours() / 24) * 24); break;
  305. default:
  306. clone.setHours(Math.round(clone.getHours() / 12) * 12); break;
  307. }
  308. clone.setMinutes(0);
  309. clone.setSeconds(0);
  310. clone.setMilliseconds(0);
  311. }
  312. else if (this.scale == TimeStep.SCALE.WEEKDAY) {
  313. //noinspection FallthroughInSwitchStatementJS
  314. switch (this.step) {
  315. case 5:
  316. case 2:
  317. clone.setHours(Math.round(clone.getHours() / 12) * 12); break;
  318. default:
  319. clone.setHours(Math.round(clone.getHours() / 6) * 6); break;
  320. }
  321. clone.setMinutes(0);
  322. clone.setSeconds(0);
  323. clone.setMilliseconds(0);
  324. }
  325. else if (this.scale == TimeStep.SCALE.HOUR) {
  326. switch (this.step) {
  327. case 4:
  328. clone.setMinutes(Math.round(clone.getMinutes() / 60) * 60); break;
  329. default:
  330. clone.setMinutes(Math.round(clone.getMinutes() / 30) * 30); break;
  331. }
  332. clone.setSeconds(0);
  333. clone.setMilliseconds(0);
  334. } else if (this.scale == TimeStep.SCALE.MINUTE) {
  335. //noinspection FallthroughInSwitchStatementJS
  336. switch (this.step) {
  337. case 15:
  338. case 10:
  339. clone.setMinutes(Math.round(clone.getMinutes() / 5) * 5);
  340. clone.setSeconds(0);
  341. break;
  342. case 5:
  343. clone.setSeconds(Math.round(clone.getSeconds() / 60) * 60); break;
  344. default:
  345. clone.setSeconds(Math.round(clone.getSeconds() / 30) * 30); break;
  346. }
  347. clone.setMilliseconds(0);
  348. }
  349. else if (this.scale == TimeStep.SCALE.SECOND) {
  350. //noinspection FallthroughInSwitchStatementJS
  351. switch (this.step) {
  352. case 15:
  353. case 10:
  354. clone.setSeconds(Math.round(clone.getSeconds() / 5) * 5);
  355. clone.setMilliseconds(0);
  356. break;
  357. case 5:
  358. clone.setMilliseconds(Math.round(clone.getMilliseconds() / 1000) * 1000); break;
  359. default:
  360. clone.setMilliseconds(Math.round(clone.getMilliseconds() / 500) * 500); break;
  361. }
  362. }
  363. else if (this.scale == TimeStep.SCALE.MILLISECOND) {
  364. var step = this.step > 5 ? this.step / 2 : 1;
  365. clone.setMilliseconds(Math.round(clone.getMilliseconds() / step) * step);
  366. }
  367. return clone;
  368. };
  369. /**
  370. * Check if the current value is a major value (for example when the step
  371. * is DAY, a major value is each first day of the MONTH)
  372. * @return {boolean} true if current date is major, else false.
  373. */
  374. TimeStep.prototype.isMajor = function() {
  375. if (this.switchedYear == true) {
  376. this.switchedYear = false;
  377. switch (this.scale) {
  378. case TimeStep.SCALE.YEAR:
  379. case TimeStep.SCALE.MONTH:
  380. case TimeStep.SCALE.WEEKDAY:
  381. case TimeStep.SCALE.DAY:
  382. case TimeStep.SCALE.HOUR:
  383. case TimeStep.SCALE.MINUTE:
  384. case TimeStep.SCALE.SECOND:
  385. case TimeStep.SCALE.MILLISECOND:
  386. return true;
  387. default:
  388. return false;
  389. }
  390. }
  391. else if (this.switchedMonth == true) {
  392. this.switchedMonth = false;
  393. switch (this.scale) {
  394. case TimeStep.SCALE.WEEKDAY:
  395. case TimeStep.SCALE.DAY:
  396. case TimeStep.SCALE.HOUR:
  397. case TimeStep.SCALE.MINUTE:
  398. case TimeStep.SCALE.SECOND:
  399. case TimeStep.SCALE.MILLISECOND:
  400. return true;
  401. default:
  402. return false;
  403. }
  404. }
  405. else if (this.switchedDay == true) {
  406. this.switchedDay = false;
  407. switch (this.scale) {
  408. case TimeStep.SCALE.MILLISECOND:
  409. case TimeStep.SCALE.SECOND:
  410. case TimeStep.SCALE.MINUTE:
  411. case TimeStep.SCALE.HOUR:
  412. return true;
  413. default:
  414. return false;
  415. }
  416. }
  417. switch (this.scale) {
  418. case TimeStep.SCALE.MILLISECOND:
  419. return (this.current.getMilliseconds() == 0);
  420. case TimeStep.SCALE.SECOND:
  421. return (this.current.getSeconds() == 0);
  422. case TimeStep.SCALE.MINUTE:
  423. return (this.current.getHours() == 0) && (this.current.getMinutes() == 0);
  424. case TimeStep.SCALE.HOUR:
  425. return (this.current.getHours() == 0);
  426. case TimeStep.SCALE.WEEKDAY: // intentional fall through
  427. case TimeStep.SCALE.DAY:
  428. return (this.current.getDate() == 1);
  429. case TimeStep.SCALE.MONTH:
  430. return (this.current.getMonth() == 0);
  431. case TimeStep.SCALE.YEAR:
  432. return false;
  433. default:
  434. return false;
  435. }
  436. };
  437. /**
  438. * Returns formatted text for the minor axislabel, depending on the current
  439. * date and the scale. For example when scale is MINUTE, the current time is
  440. * formatted as "hh:mm".
  441. * @param {Date} [date] custom date. if not provided, current date is taken
  442. */
  443. TimeStep.prototype.getLabelMinor = function(date) {
  444. if (date == undefined) {
  445. date = this.current;
  446. }
  447. switch (this.scale) {
  448. case TimeStep.SCALE.MILLISECOND: return moment(date).format('SSS');
  449. case TimeStep.SCALE.SECOND: return moment(date).format('s');
  450. case TimeStep.SCALE.MINUTE: return moment(date).format('HH:mm');
  451. case TimeStep.SCALE.HOUR: return moment(date).format('HH:mm');
  452. case TimeStep.SCALE.WEEKDAY: return moment(date).format('ddd D');
  453. case TimeStep.SCALE.DAY: return moment(date).format('D');
  454. case TimeStep.SCALE.MONTH: return moment(date).format('MMM');
  455. case TimeStep.SCALE.YEAR: return moment(date).format('YYYY');
  456. default: return '';
  457. }
  458. };
  459. /**
  460. * Returns formatted text for the major axis label, depending on the current
  461. * date and the scale. For example when scale is MINUTE, the major scale is
  462. * hours, and the hour will be formatted as "hh".
  463. * @param {Date} [date] custom date. if not provided, current date is taken
  464. */
  465. TimeStep.prototype.getLabelMajor = function(date) {
  466. if (date == undefined) {
  467. date = this.current;
  468. }
  469. //noinspection FallthroughInSwitchStatementJS
  470. switch (this.scale) {
  471. case TimeStep.SCALE.MILLISECOND:return moment(date).format('HH:mm:ss');
  472. case TimeStep.SCALE.SECOND: return moment(date).format('D MMMM HH:mm');
  473. case TimeStep.SCALE.MINUTE:
  474. case TimeStep.SCALE.HOUR: return moment(date).format('ddd D MMMM');
  475. case TimeStep.SCALE.WEEKDAY:
  476. case TimeStep.SCALE.DAY: return moment(date).format('MMMM YYYY');
  477. case TimeStep.SCALE.MONTH: return moment(date).format('YYYY');
  478. case TimeStep.SCALE.YEAR: return '';
  479. default: return '';
  480. }
  481. };
  482. module.exports = TimeStep;