linear_time.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. var string_utils = require('utils/string_utils');
  19. /**
  20. * @class
  21. *
  22. * This is a view which GETs data from a URL and shows it as a time based line
  23. * graph. Time is shown on the X axis with data series shown on Y axis. It
  24. * optionally also has the ability to auto refresh itself over a given time
  25. * interval.
  26. *
  27. * This is an abstract class which is meant to be extended.
  28. *
  29. * Extending classes should override the following:
  30. * <ul>
  31. * <li>url - from where the data can be retrieved
  32. * <li>title - Title to be displayed when showing the chart
  33. * <li>id - which uniquely identifies this chart in any page
  34. * <li>#transformToSeries(jsonData) - function to map server data into graph
  35. * series
  36. * </ul>
  37. *
  38. * Extending classes could optionally override the following:
  39. * <ul>
  40. * <li>#colorForSeries(series) - function to get custom colors per series
  41. * </ul>
  42. *
  43. * @extends Ember.Object
  44. * @extends Ember.View
  45. */
  46. App.ChartLinearTimeView = Ember.View.extend({
  47. templateName: require('templates/main/charts/linear_time'),
  48. /**
  49. * The URL from which data can be retrieved.
  50. *
  51. * This property must be provided for the graph to show properly.
  52. *
  53. * @type String
  54. * @default null
  55. */
  56. url: null,
  57. /**
  58. * A unique ID for this chart.
  59. *
  60. * @type String
  61. * @default null
  62. */
  63. id: null,
  64. /**
  65. * Title to be shown under the chart.
  66. *
  67. * @type String
  68. * @default null
  69. */
  70. title: null,
  71. /**
  72. * @private
  73. *
  74. * @type Rickshaw.Graph
  75. * @default null
  76. */
  77. _graph: null,
  78. _popupGraph: null,
  79. _seriesProperties: null,
  80. renderer: 'area',
  81. popupSuffix: '-popup',
  82. isPopup: false,
  83. isReady: false,
  84. isPopupReady: false,
  85. hasData: true,
  86. /**
  87. * Color palette used for this chart
  88. *
  89. * @private
  90. * @type String[]
  91. */
  92. /*
  93. _paletteScheme: [ 'rgba(181,182,169,0.4)', 'rgba(133,135,114,0.4)',
  94. 'rgba(120,95,67,0.4)', 'rgba(150,85,126,0.4)',
  95. 'rgba(70,130,180,0.4)', 'rgba(0,255,204,0.4)',
  96. 'rgba(255,105,180,0.4)', 'rgba(101,185,172,0.4)',
  97. 'rgba(115,192,58,0.4)', 'rgba(203,81,58,0.4)' ].reverse(),
  98. */
  99. selector: function () {
  100. return '#' + this.get('elementId');
  101. }.property('elementId'),
  102. didInsertElement: function () {
  103. this.loadData();
  104. this.registerGraph();
  105. },
  106. registerGraph: function(){
  107. var graph = {
  108. name: this.get('title'),
  109. id: this.get('elementId'),
  110. popupId: this.get('id')
  111. };
  112. App.router.get('updateController.graphs').push(graph);
  113. },
  114. loadData: function() {
  115. var validUrl = this.get('url');
  116. if (validUrl) {
  117. var hash = {};
  118. hash.url = validUrl;
  119. hash.type = 'GET';
  120. hash.dataType = 'json';
  121. hash.contentType = 'application/json; charset=utf-8';
  122. hash.context = this;
  123. hash.success = this._refreshGraph,
  124. hash.error = function (xhr, textStatus, errorThrown) {
  125. this._showMessage('warn', 'Error', 'There was a problem getting data for the chart (' + textStatus + ': ' + errorThrown + ')');
  126. }
  127. jQuery.ajax(hash);
  128. }
  129. },
  130. /**
  131. * Shows a yellow warning message in place of the chart.
  132. *
  133. * @param type Can be any of 'warn', 'error', 'info', 'success'
  134. * @param title Bolded title for the message
  135. * @param message String representing the message
  136. * @type: Function
  137. */
  138. _showMessage: function(type, title, message){
  139. var chartOverlayId = '#' + this.id + '-chart';
  140. if (this.get('isPopup')) {
  141. chartOverlayId += this.get('popupSuffix');
  142. }
  143. var typeClass;
  144. switch (type) {
  145. case 'error':
  146. typeClass = 'alert-error';
  147. break;
  148. case 'success':
  149. typeClass = 'alert-success';
  150. break;
  151. case 'info':
  152. typeClass = 'alert-info';
  153. break;
  154. default:
  155. typeClass = '';
  156. break;
  157. }
  158. $(chartOverlayId).html('');
  159. $(chartOverlayId).append('<div class=\"alert '+typeClass+'\"><strong>'+title+'</strong> '+message+'</div>');
  160. },
  161. /**
  162. * Transforms the JSON data retrieved from the server into the series
  163. * format that Rickshaw.Graph understands.
  164. *
  165. * The series object is generally in the following format: [ { name :
  166. * "Series 1", data : [ { x : 0, y : 0 }, { x : 1, y : 1 } ] } ]
  167. *
  168. * Extending classes should override this method.
  169. *
  170. * @param jsonData
  171. * Data retrieved from the server
  172. * @type: Function
  173. *
  174. */
  175. transformToSeries: function (jsonData) {
  176. return [ {
  177. name: "Series 1",
  178. data: [ {
  179. x: 0,
  180. y: 0
  181. }, {
  182. x: 1,
  183. y: 1
  184. } ]
  185. } ]
  186. },
  187. /**
  188. * Provides the formatter to use in displaying Y axis.
  189. *
  190. * The default is Rickshaw.Fixtures.Number.formatKMBT which shows 10K,
  191. * 300M etc.
  192. *
  193. * @type Function
  194. */
  195. yAxisFormatter: function(y) {
  196. var value = Rickshaw.Fixtures.Number.formatKMBT(y);
  197. if (value == '') return '0';
  198. value = String(value);
  199. var c = value[value.length - 1];
  200. if (!isNaN(parseInt(c))) {
  201. // c is digit
  202. value = parseFloat(value).toFixed(3).replace(/0+$/, '').replace(/\.$/, '');
  203. }
  204. else {
  205. // c in not digit
  206. value = parseFloat(value.substr(0, value.length - 1)).toFixed(3).replace(/0+$/, '').replace(/\.$/, '') + c;
  207. }
  208. return value;
  209. },
  210. /**
  211. * Provides the color (in any HTML color format) to use for a particular
  212. * series.
  213. *
  214. * @param series
  215. * Series for which color is being requested
  216. * @return color String. Returning null allows this chart to pick a color
  217. * from palette.
  218. * @default null
  219. * @type Function
  220. */
  221. colorForSeries: function (series) {
  222. return null;
  223. },
  224. /**
  225. * Check whether seriesData is correct data for chart drawing
  226. * @param seriesData
  227. * @return {Boolean}
  228. */
  229. checkSeries : function(seriesData){
  230. if(!seriesData || !seriesData.length){
  231. return false;
  232. }
  233. var result = true;
  234. seriesData.forEach(function(item){
  235. if(!item.data.length || !item.data[0] || typeof item.data[0].x === 'undefined'){
  236. result = false;
  237. }
  238. });
  239. return result;
  240. },
  241. /**
  242. * @private
  243. *
  244. * Refreshes the graph with the latest JSON data.
  245. *
  246. * @type Function
  247. */
  248. _refreshGraph: function (jsonData) {
  249. var seriesData = this.transformToSeries(jsonData);
  250. if (this.checkSeries(seriesData)) {
  251. //if graph opened as modal popup
  252. var popup_path = $("#" + this.id + "-container" + this.get('popupSuffix'));
  253. if(popup_path.length) {
  254. popup_path.children().each(function () {
  255. $(this).children().remove();
  256. });
  257. this.set('isPopup', true);
  258. }
  259. else {
  260. $("#" + this.id + "-container").children().each(function (index, value) {
  261. $(value).children().remove();
  262. });
  263. }
  264. this.draw(seriesData);
  265. this.set('hasData', true);
  266. }
  267. else {
  268. this.set('isReady', true);
  269. this._showMessage('info', 'No Data', 'There was no data available.');
  270. this.set('isPopup', false);
  271. this.set('hasData', false);
  272. }
  273. },
  274. /**
  275. * Returns a custom time unit for the graph's X axis. This is needed
  276. * as Rickshaw's default time X axis uses UTC time, which can be confusing
  277. * for users expecting locale specific time. This value defaults to
  278. * App.ChartLinearTimeView.FifteenMinuteTimeUnit.
  279. *
  280. * If <code>null</code> is returned, Rickshaw's default time unit is used.
  281. *
  282. * @type Function
  283. * @return Rickshaw.Fixtures.Time
  284. * @default App.ChartLinearTimeView.FifteenMinuteTimeUnit
  285. */
  286. localeTimeUnit: function(){
  287. return App.ChartLinearTimeView.FifteenMinuteTimeUnit;
  288. },
  289. /**
  290. * @private
  291. *
  292. * When a graph is given a particular width and height,the lines are drawn
  293. * in a slightly bigger area thereby chopping off some of the UI. Hence
  294. * after the rendering, we adjust the SVGs size in the DOM to compensate.
  295. *
  296. * Opened https://github.com/shutterstock/rickshaw/issues/141
  297. *
  298. * @type Function
  299. */
  300. _adjustSVGHeight: function () {
  301. if (this._graph && this._graph.element
  302. && this._graph.element.firstChild) {
  303. var svgElement = this._graph.element.firstChild;
  304. svgElement.setAttribute('height', $(this._graph.element).height()
  305. + "px");
  306. svgElement.setAttribute('width', $(this._graph.element).width()
  307. + "px");
  308. }
  309. },
  310. draw: function(seriesData) {
  311. var isPopup = this.get('isPopup');
  312. var p = '';
  313. if (isPopup) {
  314. p = this.get('popupSuffix');
  315. }
  316. var palette = new Rickshaw.Color.Palette({ scheme: 'munin'});
  317. // var palette = new Rickshaw.Color.Palette({
  318. // scheme: this._paletteScheme
  319. // });
  320. var self = this;
  321. var series_min_length = 100000000;
  322. seriesData.forEach(function (series, index) {
  323. var seriesColor = self.colorForSeries(series);
  324. if (seriesColor == null) {
  325. seriesColor = palette.color();
  326. }
  327. series.color = seriesColor;
  328. series.stroke = 'rgba(0,0,0,0.3)';
  329. if (isPopup) {
  330. // calculate statistic data for popup legend
  331. var avg = 0;
  332. var min = Number.MAX_VALUE;
  333. var max = Number.MIN_VALUE;
  334. for (var i = 0; i < series.data.length; i++) {
  335. avg += series.data[i]['y'];
  336. if (series.data[i]['y'] < min) {
  337. min = series.data[i]['y'];
  338. }
  339. else {
  340. if (series.data[i]['y'] > max) {
  341. max = series.data[i]['y'];
  342. }
  343. }
  344. }
  345. series.name = string_utils.pad(series.name, 30, '&nbsp;', 2) + string_utils.pad('min', 5, '&nbsp;', 3) + string_utils.pad(this.get('yAxisFormatter')(min), 12, '&nbsp;', 3) + string_utils.pad('avg', 5, '&nbsp;', 3) + string_utils.pad(this.get('yAxisFormatter')(avg/series.data.length), 12, '&nbsp;', 3) + string_utils.pad('max', 12, '&nbsp;', 3) + string_utils.pad(this.get('yAxisFormatter')(max), 5, '&nbsp;', 3);
  346. }
  347. if (series.data.length < series_min_length) {
  348. series_min_length = series.data.length;
  349. }
  350. }.bind(this));
  351. seriesData.forEach(function(series, index) {
  352. if (series.data.length > series_min_length) {
  353. series.data.length = series_min_length;
  354. }
  355. });
  356. var chartId = "#" + this.id + "-chart" + p;
  357. var chartOverlayId = "#" + this.id + "-container" + p;
  358. var xaxisElementId = "#" + this.id + "-xaxis" + p;
  359. var yaxisElementId = "#" + this.id + "-yaxis" + p;
  360. var legendElementId = "#" + this.id + "-legend" + p;
  361. var chartElement = document.querySelector(chartId);
  362. var overlayElement = document.querySelector(chartOverlayId);
  363. var xaxisElement = document.querySelector(xaxisElementId);
  364. var yaxisElement = document.querySelector(yaxisElementId);
  365. var legendElement = document.querySelector(legendElementId);
  366. var strokeWidth = 1;
  367. if (this.get('renderer') != 'area') {
  368. strokeWidth = 2;
  369. }
  370. var height = 150;
  371. var width = 400;
  372. if (isPopup) {
  373. height = 180;
  374. width = 670;
  375. } else {
  376. // If not in popup, the width could vary.
  377. // We determine width based on div's size.
  378. var thisElement = this.get('element');
  379. if (thisElement!=null) {
  380. var calculatedWidth = $(thisElement).width();
  381. if (calculatedWidth > 10) {
  382. width = calculatedWidth;
  383. }
  384. }
  385. }
  386. var _graph = new Rickshaw.Graph({
  387. height: height,
  388. width: width,
  389. element: chartElement,
  390. series: seriesData,
  391. interpolation: 'step-after',
  392. stroke: true,
  393. renderer: this.get('renderer'),
  394. strokeWidth: strokeWidth
  395. });
  396. if (this.get('renderer') === 'area') {
  397. _graph.renderer.unstack = false;
  398. }
  399. xAxis = new Rickshaw.Graph.Axis.Time({
  400. graph: _graph,
  401. timeUnit: this.localeTimeUnit()
  402. });
  403. var orientation = 'right';
  404. if (isPopup) {
  405. orientation = 'left';
  406. }
  407. yAxis = new Rickshaw.Graph.Axis.Y({
  408. tickFormat: this.yAxisFormatter,
  409. element: yaxisElement,
  410. orientation: orientation,
  411. graph: _graph
  412. });
  413. var legend = new Rickshaw.Graph.Legend({
  414. graph: _graph,
  415. element: legendElement
  416. });
  417. if (!isPopup) {
  418. overlayElement.addEventListener('mousemove', function () {
  419. $(xaxisElement).removeClass('hide');
  420. $(legendElement).removeClass('hide');
  421. $(chartElement).children("div").removeClass('hide');
  422. });
  423. overlayElement.addEventListener('mouseout', function () {
  424. $(legendElement).addClass('hide');
  425. });
  426. _graph.onUpdate(function () {
  427. $(legendElement).addClass('hide');
  428. });
  429. }
  430. var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({
  431. graph: _graph,
  432. legend: legend
  433. });
  434. var order = new Rickshaw.Graph.Behavior.Series.Order({
  435. graph: _graph,
  436. legend: legend
  437. });
  438. //show the graph when it's loaded
  439. _graph.onUpdate(function(){
  440. self.set('isReady', true);
  441. });
  442. _graph.render();
  443. if (isPopup) {
  444. var self = this;
  445. var hoverDetail = new Rickshaw.Graph.HoverDetail({
  446. graph: _graph,
  447. yFormatter:function (y) {
  448. return self.yAxisFormatter(y);
  449. },
  450. xFormatter:function (x) {
  451. return (new Date(x)).toLocaleTimeString();
  452. },
  453. formatter:function (series, x, y, formattedX, formattedY, d) {
  454. return formattedY + '<br />' + formattedX;
  455. }
  456. });
  457. }
  458. if (isPopup) {
  459. var self = this;
  460. // In popup save selected metrics and show only them after data update
  461. _graph.series.forEach(function(series, index) {
  462. if (self.get('_seriesProperties') !== null && self.get('_seriesProperties')[index] !== null) {
  463. if(self.get('_seriesProperties')[self.get('_seriesProperties').length - index - 1].length > 1) {
  464. $('#'+self.get('id')+'-container'+self.get('popupSuffix')+' a.action:eq('+(self.get('_seriesProperties').length - index - 1)+')').parent('li').addClass('disabled');
  465. series.disable();
  466. }
  467. }
  468. });
  469. //show the graph when it's loaded
  470. _graph.onUpdate(function(){
  471. self.set('isPopupReady', true);
  472. });
  473. _graph.update();
  474. $('li.line').click(function() {
  475. var series = [];
  476. $('#'+self.get('id')+'-container'+self.get('popupSuffix')+' a.action').each(function(index, v) {
  477. series[index] = v.parentNode.classList;
  478. });
  479. self.set('_seriesProperties', series);
  480. });
  481. this.set('_popupGraph', _graph);
  482. }
  483. else {
  484. this.set('_graph', _graph);
  485. }
  486. this.set('isPopup', false);
  487. },
  488. showGraphInPopup: function() {
  489. if(!this.get('hasData')){
  490. return;
  491. }
  492. this.set('isPopup', true);
  493. var self = this;
  494. App.ModalPopup.show({
  495. template: Ember.Handlebars.compile([
  496. '<div class="modal-backdrop"></div><div class="modal modal-graph-line" id="modal" tabindex="-1" role="dialog" aria-labelledby="modal-label" aria-hidden="true">',
  497. '<div class="modal-header">',
  498. '<a class="close" {{action onClose target="view"}}>x</a>',
  499. '<h3 id="modal-label">',
  500. '{{#if headerClass}}{{view headerClass}}',
  501. '{{else}}{{header}}{{/if}}',
  502. '</h3>',
  503. '</div>',
  504. '<div class="modal-body">',
  505. '{{#if bodyClass}}{{view bodyClass}}',
  506. '{{else}}',
  507. '<div class="screensaver no-borders chart-container" {{bindAttr class="view.isReady:hide"}} ></div>',
  508. '<div id="'+this.get('id')+'-container'+this.get('popupSuffix')+'" class="chart-container chart-container'+this.get('popupSuffix')+' hide" {{bindAttr class="view.isReady:show"}} >',
  509. '<div id="'+this.get('id')+'-yaxis'+this.get('popupSuffix')+'" class="'+this.get('id')+'-yaxis chart-y-axis"></div>',
  510. '<div id="'+this.get('id')+'-xaxis'+this.get('popupSuffix')+'" class="'+this.get('id')+'-xaxis chart-x-axis"></div>',
  511. '<div id="'+this.get('id')+'-legend'+this.get('popupSuffix')+'" class="'+this.get('id')+'-legend chart-legend"></div>',
  512. '<div id="'+this.get('id')+'-chart'+this.get('popupSuffix')+'" class="'+this.get('id')+'-chart chart"></div>',
  513. '<div id="'+this.get('id')+'-title'+this.get('popupSuffix')+'" class="'+this.get('id')+'-title chart-title">{{view.title}}</div>'+
  514. '</div>',
  515. '{{/if}}',
  516. '</div>',
  517. '<div class="modal-footer">',
  518. '{{#if view.primary}}<a class="btn btn-success" {{action onPrimary target="view"}}>{{view.primary}}</a>{{/if}}',
  519. '</div>',
  520. '</div>'
  521. ].join('\n')),
  522. header: this.get('title'),
  523. self: self,
  524. isReady: function(){
  525. return this.get('self.isPopupReady');
  526. }.property('self.isPopupReady'),
  527. primary: 'OK',
  528. onPrimary: function() {
  529. this.hide();
  530. self.set('isPopup', false);
  531. }
  532. });
  533. Ember.run.next(function() {
  534. self.loadData();
  535. self.set('isPopupReady', false);
  536. });
  537. }
  538. });
  539. /**
  540. * A formatter which will turn a number into computer storage sizes of the
  541. * format '23 GB' etc.
  542. *
  543. * @type Function
  544. */
  545. App.ChartLinearTimeView.BytesFormatter = function (y) {
  546. if (y == 0) return '0 B';
  547. var value = Rickshaw.Fixtures.Number.formatBase1024KMGTP(y);
  548. if (!y || y.length < 1) {
  549. value = '0 B';
  550. }
  551. else {
  552. if ("number" == typeof value) {
  553. value = String(value);
  554. }
  555. if ("string" == typeof value) {
  556. value = value.replace(/\.\d+/, ''); // Remove decimal part
  557. // Either it ends with digit or ends with character
  558. value = value.replace(/(\d$)/, '$1 '); // Ends with digit like '120'
  559. value = value.replace(/([a-zA-Z]$)/, ' $1'); // Ends with character like
  560. // '120M'
  561. value = value + 'B'; // Append B to make B, MB, GB etc.
  562. }
  563. }
  564. return value;
  565. };
  566. /**
  567. * A formatter which will turn a number into percentage display like '42%'
  568. *
  569. * @type Function
  570. */
  571. App.ChartLinearTimeView.PercentageFormatter = function (percentage) {
  572. var value = percentage;
  573. if (!value || value.length < 1) {
  574. value = '0 %';
  575. } else {
  576. value = value.toFixed(3).replace(/0+$/, '').replace(/\.$/, '') + '%';
  577. }
  578. return value;
  579. };
  580. /**
  581. * A formatter which will turn elapsed time into display time like '50 ms',
  582. * '5s', '10 m', '3 hr' etc. Time is expected to be provided in milliseconds.
  583. *
  584. * @type Function
  585. */
  586. App.ChartLinearTimeView.TimeElapsedFormatter = function (millis) {
  587. var value = millis;
  588. if (!value || value.length < 1) {
  589. value = '0 ms';
  590. } else if ("number" == typeof millis) {
  591. var seconds = millis > 1000 ? Math.round(millis / 1000) : 0;
  592. var minutes = seconds > 60 ? Math.round(seconds / 60) : 0;
  593. var hours = minutes > 60 ? Math.round(minutes / 60) : 0;
  594. var days = hours > 24 ? Math.round(hours / 24) : 0;
  595. if (days > 0) {
  596. value = days + ' d';
  597. } else if (hours > 0) {
  598. value = hours + ' hr';
  599. } else if (minutes > 0) {
  600. value = minutes + ' m';
  601. } else if (seconds > 0) {
  602. value = seconds + ' s';
  603. } else if (millis > 0) {
  604. value = millis.toFixed(3).replace(/0+$/, '').replace(/\.$/, '') + ' ms';
  605. } else {
  606. value = millis.toFixed(3).replace(/0+$/, '').replace(/\.$/, '') + ' ms';
  607. }
  608. }
  609. return value;
  610. };
  611. /**
  612. * A time unit which can be used for showing 15 minute intervals on X axis.
  613. *
  614. * @type Rickshaw.Fixtures.Time
  615. */
  616. App.ChartLinearTimeView.FifteenMinuteTimeUnit = {
  617. name: '15 minute',
  618. seconds: 60 * 15,
  619. formatter: function (d) {
  620. return d.toLocaleString().match(/(\d+:\d+):/)[1];
  621. }
  622. };