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.

527 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 b = asc + ds;
  230. var stepYear = (1000 * 60 * 60 * 24 * 30 * 12);
  231. var stepMonth = (1000 * 60 * 60 * 24 * 30);
  232. var stepDay = (1000 * 60 * 60 * 24);
  233. var stepHour = (1000 * 60 * 60);
  234. var stepMinute = (1000 * 60);
  235. var stepSecond = (1000);
  236. var stepMillisecond= (1);
  237. // find the smallest step that is larger than the provided minimumStep
  238. if (stepYear*1000 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 1000;}
  239. if (stepYear*500 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 500;}
  240. if (stepYear*100 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 100;}
  241. if (stepYear*50 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 50;}
  242. if (stepYear*10 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 10;}
  243. if (stepYear*5 > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 5;}
  244. if (stepYear > minimumStep) {this.scale = TimeStep.SCALE.YEAR; this.step = 1;}
  245. if (stepMonth*3 > minimumStep) {this.scale = TimeStep.SCALE.MONTH; this.step = 3;}
  246. if (stepMonth > minimumStep) {this.scale = TimeStep.SCALE.MONTH; this.step = 1;}
  247. if (stepDay*5 > minimumStep) {this.scale = TimeStep.SCALE.DAY; this.step = 5;}
  248. if (stepDay*2 > minimumStep) {this.scale = TimeStep.SCALE.DAY; this.step = 2;}
  249. if (stepDay > minimumStep) {this.scale = TimeStep.SCALE.DAY; this.step = 1;}
  250. if (stepDay/2 > minimumStep) {this.scale = TimeStep.SCALE.WEEKDAY; this.step = 1;}
  251. if (stepHour*4 > minimumStep) {this.scale = TimeStep.SCALE.HOUR; this.step = 4;}
  252. if (stepHour > minimumStep) {this.scale = TimeStep.SCALE.HOUR; this.step = 1;}
  253. if (stepMinute*15 > minimumStep) {this.scale = TimeStep.SCALE.MINUTE; this.step = 15;}
  254. if (stepMinute*10 > minimumStep) {this.scale = TimeStep.SCALE.MINUTE; this.step = 10;}
  255. if (stepMinute*5 > minimumStep) {this.scale = TimeStep.SCALE.MINUTE; this.step = 5;}
  256. if (stepMinute > minimumStep) {this.scale = TimeStep.SCALE.MINUTE; this.step = 1;}
  257. if (stepSecond*15 > minimumStep) {this.scale = TimeStep.SCALE.SECOND; this.step = 15;}
  258. if (stepSecond*10 > minimumStep) {this.scale = TimeStep.SCALE.SECOND; this.step = 10;}
  259. if (stepSecond*5 > minimumStep) {this.scale = TimeStep.SCALE.SECOND; this.step = 5;}
  260. if (stepSecond > minimumStep) {this.scale = TimeStep.SCALE.SECOND; this.step = 1;}
  261. if (stepMillisecond*200 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 200;}
  262. if (stepMillisecond*100 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 100;}
  263. if (stepMillisecond*50 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 50;}
  264. if (stepMillisecond*10 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 10;}
  265. if (stepMillisecond*5 > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 5;}
  266. if (stepMillisecond > minimumStep) {this.scale = TimeStep.SCALE.MILLISECOND; this.step = 1;}
  267. };
  268. /**
  269. * Snap a date to a rounded value.
  270. * The snap intervals are dependent on the current scale and step.
  271. * @param {Date} date the date to be snapped.
  272. * @return {Date} snappedDate
  273. */
  274. TimeStep.prototype.snap = function(date) {
  275. var clone = new Date(date.valueOf());
  276. if (this.scale == TimeStep.SCALE.YEAR) {
  277. var year = clone.getFullYear() + Math.round(clone.getMonth() / 12);
  278. clone.setFullYear(Math.round(year / this.step) * this.step);
  279. clone.setMonth(0);
  280. clone.setDate(0);
  281. clone.setHours(0);
  282. clone.setMinutes(0);
  283. clone.setSeconds(0);
  284. clone.setMilliseconds(0);
  285. }
  286. else if (this.scale == TimeStep.SCALE.MONTH) {
  287. if (clone.getDate() > 15) {
  288. clone.setDate(1);
  289. clone.setMonth(clone.getMonth() + 1);
  290. // important: first set Date to 1, after that change the month.
  291. }
  292. else {
  293. clone.setDate(1);
  294. }
  295. clone.setHours(0);
  296. clone.setMinutes(0);
  297. clone.setSeconds(0);
  298. clone.setMilliseconds(0);
  299. }
  300. else if (this.scale == TimeStep.SCALE.DAY) {
  301. //noinspection FallthroughInSwitchStatementJS
  302. switch (this.step) {
  303. case 5:
  304. case 2:
  305. clone.setHours(Math.round(clone.getHours() / 24) * 24); break;
  306. default:
  307. clone.setHours(Math.round(clone.getHours() / 12) * 12); break;
  308. }
  309. clone.setMinutes(0);
  310. clone.setSeconds(0);
  311. clone.setMilliseconds(0);
  312. }
  313. else if (this.scale == TimeStep.SCALE.WEEKDAY) {
  314. //noinspection FallthroughInSwitchStatementJS
  315. switch (this.step) {
  316. case 5:
  317. case 2:
  318. clone.setHours(Math.round(clone.getHours() / 12) * 12); break;
  319. default:
  320. clone.setHours(Math.round(clone.getHours() / 6) * 6); break;
  321. }
  322. clone.setMinutes(0);
  323. clone.setSeconds(0);
  324. clone.setMilliseconds(0);
  325. }
  326. else if (this.scale == TimeStep.SCALE.HOUR) {
  327. switch (this.step) {
  328. case 4:
  329. clone.setMinutes(Math.round(clone.getMinutes() / 60) * 60); break;
  330. default:
  331. clone.setMinutes(Math.round(clone.getMinutes() / 30) * 30); break;
  332. }
  333. clone.setSeconds(0);
  334. clone.setMilliseconds(0);
  335. } else if (this.scale == TimeStep.SCALE.MINUTE) {
  336. //noinspection FallthroughInSwitchStatementJS
  337. switch (this.step) {
  338. case 15:
  339. case 10:
  340. clone.setMinutes(Math.round(clone.getMinutes() / 5) * 5);
  341. clone.setSeconds(0);
  342. break;
  343. case 5:
  344. clone.setSeconds(Math.round(clone.getSeconds() / 60) * 60); break;
  345. default:
  346. clone.setSeconds(Math.round(clone.getSeconds() / 30) * 30); break;
  347. }
  348. clone.setMilliseconds(0);
  349. }
  350. else if (this.scale == TimeStep.SCALE.SECOND) {
  351. //noinspection FallthroughInSwitchStatementJS
  352. switch (this.step) {
  353. case 15:
  354. case 10:
  355. clone.setSeconds(Math.round(clone.getSeconds() / 5) * 5);
  356. clone.setMilliseconds(0);
  357. break;
  358. case 5:
  359. clone.setMilliseconds(Math.round(clone.getMilliseconds() / 1000) * 1000); break;
  360. default:
  361. clone.setMilliseconds(Math.round(clone.getMilliseconds() / 500) * 500); break;
  362. }
  363. }
  364. else if (this.scale == TimeStep.SCALE.MILLISECOND) {
  365. var step = this.step > 5 ? this.step / 2 : 1;
  366. clone.setMilliseconds(Math.round(clone.getMilliseconds() / step) * step);
  367. }
  368. return clone;
  369. };
  370. /**
  371. * Check if the current value is a major value (for example when the step
  372. * is DAY, a major value is each first day of the MONTH)
  373. * @return {boolean} true if current date is major, else false.
  374. */
  375. TimeStep.prototype.isMajor = function() {
  376. if (this.switchedYear == true) {
  377. this.switchedYear = false;
  378. switch (this.scale) {
  379. case TimeStep.SCALE.YEAR:
  380. case TimeStep.SCALE.MONTH:
  381. case TimeStep.SCALE.WEEKDAY:
  382. case TimeStep.SCALE.DAY:
  383. case TimeStep.SCALE.HOUR:
  384. case TimeStep.SCALE.MINUTE:
  385. case TimeStep.SCALE.SECOND:
  386. case TimeStep.SCALE.MILLISECOND:
  387. return true;
  388. default:
  389. return false;
  390. }
  391. }
  392. else if (this.switchedMonth == true) {
  393. this.switchedMonth = false;
  394. switch (this.scale) {
  395. case TimeStep.SCALE.WEEKDAY:
  396. case TimeStep.SCALE.DAY:
  397. case TimeStep.SCALE.HOUR:
  398. case TimeStep.SCALE.MINUTE:
  399. case TimeStep.SCALE.SECOND:
  400. case TimeStep.SCALE.MILLISECOND:
  401. return true;
  402. default:
  403. return false;
  404. }
  405. }
  406. else if (this.switchedDay == true) {
  407. this.switchedDay = false;
  408. switch (this.scale) {
  409. case TimeStep.SCALE.MILLISECOND:
  410. case TimeStep.SCALE.SECOND:
  411. case TimeStep.SCALE.MINUTE:
  412. case TimeStep.SCALE.HOUR:
  413. return true;
  414. default:
  415. return false;
  416. }
  417. }
  418. switch (this.scale) {
  419. case TimeStep.SCALE.MILLISECOND:
  420. return (this.current.getMilliseconds() == 0);
  421. case TimeStep.SCALE.SECOND:
  422. return (this.current.getSeconds() == 0);
  423. case TimeStep.SCALE.MINUTE:
  424. return (this.current.getHours() == 0) && (this.current.getMinutes() == 0);
  425. case TimeStep.SCALE.HOUR:
  426. return (this.current.getHours() == 0);
  427. case TimeStep.SCALE.WEEKDAY: // intentional fall through
  428. case TimeStep.SCALE.DAY:
  429. return (this.current.getDate() == 1);
  430. case TimeStep.SCALE.MONTH:
  431. return (this.current.getMonth() == 0);
  432. case TimeStep.SCALE.YEAR:
  433. return false;
  434. default:
  435. return false;
  436. }
  437. };
  438. /**
  439. * Returns formatted text for the minor axislabel, depending on the current
  440. * date and the scale. For example when scale is MINUTE, the current time is
  441. * formatted as "hh:mm".
  442. * @param {Date} [date] custom date. if not provided, current date is taken
  443. */
  444. TimeStep.prototype.getLabelMinor = function(date) {
  445. if (date == undefined) {
  446. date = this.current;
  447. }
  448. switch (this.scale) {
  449. case TimeStep.SCALE.MILLISECOND: return moment(date).format('SSS');
  450. case TimeStep.SCALE.SECOND: return moment(date).format('s');
  451. case TimeStep.SCALE.MINUTE: return moment(date).format('HH:mm');
  452. case TimeStep.SCALE.HOUR: return moment(date).format('HH:mm');
  453. case TimeStep.SCALE.WEEKDAY: return moment(date).format('ddd D');
  454. case TimeStep.SCALE.DAY: return moment(date).format('D');
  455. case TimeStep.SCALE.MONTH: return moment(date).format('MMM');
  456. case TimeStep.SCALE.YEAR: return moment(date).format('YYYY');
  457. default: return '';
  458. }
  459. };
  460. /**
  461. * Returns formatted text for the major axis label, depending on the current
  462. * date and the scale. For example when scale is MINUTE, the major scale is
  463. * hours, and the hour will be formatted as "hh".
  464. * @param {Date} [date] custom date. if not provided, current date is taken
  465. */
  466. TimeStep.prototype.getLabelMajor = function(date) {
  467. if (date == undefined) {
  468. date = this.current;
  469. }
  470. //noinspection FallthroughInSwitchStatementJS
  471. switch (this.scale) {
  472. case TimeStep.SCALE.MILLISECOND:return moment(date).format('HH:mm:ss');
  473. case TimeStep.SCALE.SECOND: return moment(date).format('D MMMM HH:mm');
  474. case TimeStep.SCALE.MINUTE:
  475. case TimeStep.SCALE.HOUR: return moment(date).format('ddd D MMMM');
  476. case TimeStep.SCALE.WEEKDAY:
  477. case TimeStep.SCALE.DAY: return moment(date).format('MMMM YYYY');
  478. case TimeStep.SCALE.MONTH: return moment(date).format('YYYY');
  479. case TimeStep.SCALE.YEAR: return '';
  480. default: return '';
  481. }
  482. };
  483. module.exports = TimeStep;