module.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. /** @scratch /panels/5
  2. * include::panels/histogram.asciidoc[]
  3. */
  4. /** @scratch /panels/histogram/0
  5. * == Histogram
  6. * Status: *Stable*
  7. *
  8. * The histogram panel allow for the display of time charts. It includes several modes and tranformations
  9. * to display event counts, mean, min, max and total of numeric fields, and derivatives of counter
  10. * fields.
  11. *
  12. */
  13. define([
  14. 'angular',
  15. 'app',
  16. 'jquery',
  17. 'underscore',
  18. 'kbn',
  19. 'moment',
  20. './timeSeries',
  21. 'jquery.flot',
  22. 'jquery.flot.events',
  23. 'jquery.flot.selection',
  24. 'jquery.flot.time',
  25. 'jquery.flot.byte',
  26. 'jquery.flot.stack',
  27. 'jquery.flot.stackpercent'
  28. ],
  29. function (angular, app, $, _, kbn, moment, timeSeries) {
  30. 'use strict';
  31. var module = angular.module('kibana.panels.graphite', []);
  32. app.useModule(module);
  33. module.controller('graphite', function($scope, $rootScope, filterSrv, graphiteSrv, $timeout) {
  34. $scope.panelMeta = {
  35. modals : [],
  36. editorTabs: [],
  37. fullEditorTabs : [
  38. {
  39. title:'Targets',
  40. src:'app/panels/graphite/editor.html'
  41. },
  42. {
  43. title:'Axis labels',
  44. src:'app/panels/graphite/axisEditor.html'
  45. },
  46. {
  47. title:'Style',
  48. src:'app/panels/graphite/styleEditor.html'
  49. }
  50. ],
  51. menuItems: [
  52. { text: 'View fullscreen', click: 'toggleFullscreen()' },
  53. { text: 'Edit', click: 'openConfigureModal()' },
  54. { text: 'Duplicate', click: 'duplicate()' },
  55. { text: 'Span', submenu: [
  56. { text: '1', click: 'updateColumnSpan(1)' },
  57. { text: '2', click: 'updateColumnSpan(2)' },
  58. { text: '3', click: 'updateColumnSpan(3)' },
  59. { text: '4', click: 'updateColumnSpan(4)' },
  60. { text: '5', click: 'updateColumnSpan(5)' },
  61. { text: '6', click: 'updateColumnSpan(6)' },
  62. { text: '7', click: 'updateColumnSpan(7)' },
  63. { text: '8', click: 'updateColumnSpan(8)' },
  64. { text: '9', click: 'updateColumnSpan(9)' },
  65. { text: '10', click: 'updateColumnSpan(10)' },
  66. { text: '11', click: 'updateColumnSpan(11)' },
  67. { text: '12', click: 'updateColumnSpan(12)' },
  68. ]},
  69. { text: 'Remove', click: 'remove_panel_from_row(row, panel)' }
  70. ],
  71. status : "Unstable",
  72. description : "Graphite graphing panel <br /><br />"
  73. };
  74. // Set and populate defaults
  75. var _d = {
  76. /** @scratch /panels/histogram/3
  77. * x-axis:: Show the x-axis
  78. */
  79. 'x-axis' : true,
  80. /** @scratch /panels/histogram/3
  81. * y-axis:: Show the y-axis
  82. */
  83. 'y-axis' : true,
  84. /** @scratch /panels/histogram/3
  85. * scale:: Scale the y-axis by this factor
  86. */
  87. scale : 1,
  88. /** @scratch /panels/histogram/3
  89. * y_format:: 'none','bytes','short '
  90. */
  91. y_format : 'none',
  92. y2_format : 'none',
  93. /** @scratch /panels/histogram/5
  94. * grid object:: Min and max y-axis values
  95. * grid.min::: Minimum y-axis value
  96. * grid.max::: Maximum y-axis value
  97. */
  98. grid : {
  99. max: null,
  100. min: 0
  101. },
  102. /** @scratch /panels/histogram/3
  103. * ==== Annotations
  104. * annotate object:: A query can be specified, the results of which will be displayed as markers on
  105. * the chart. For example, for noting code deploys.
  106. * annotate.enable::: Should annotations, aka markers, be shown?
  107. * annotate.query::: Lucene query_string syntax query to use for markers.
  108. * annotate.size::: Max number of markers to show
  109. * annotate.field::: Field from documents to show
  110. * annotate.sort::: Sort array in format [field,order], For example [`@timestamp',`desc']
  111. */
  112. annotate : {
  113. enable : false,
  114. query : "*",
  115. size : 20,
  116. field : '_type',
  117. sort : ['_score','desc']
  118. },
  119. /** @scratch /panels/histogram/3
  120. * ==== Interval options
  121. * auto_int:: Automatically scale intervals?
  122. */
  123. auto_int : true,
  124. /** @scratch /panels/histogram/3
  125. * resolution:: If auto_int is true, shoot for this many bars.
  126. */
  127. resolution : 100,
  128. /** @scratch /panels/histogram/3
  129. * interval:: If auto_int is set to false, use this as the interval.
  130. */
  131. interval : '5m',
  132. /** @scratch /panels/histogram/3
  133. * interval:: Array of possible intervals in the *View* selector. Example [`auto',`1s',`5m',`3h']
  134. */
  135. intervals : ['auto','1s','1m','5m','10m','30m','1h','3h','12h','1d','1w','1y'],
  136. /** @scratch /panels/histogram/3
  137. * ==== Drawing options
  138. * lines:: Show line chart
  139. */
  140. lines : true,
  141. /** @scratch /panels/histogram/3
  142. * fill:: Area fill factor for line charts, 1-10
  143. */
  144. fill : 0,
  145. /** @scratch /panels/histogram/3
  146. * linewidth:: Weight of lines in pixels
  147. */
  148. linewidth : 1,
  149. /** @scratch /panels/histogram/3
  150. * points:: Show points on chart
  151. */
  152. points : false,
  153. /** @scratch /panels/histogram/3
  154. * pointradius:: Size of points in pixels
  155. */
  156. pointradius : 5,
  157. /** @scratch /panels/histogram/3
  158. * bars:: Show bars on chart
  159. */
  160. bars : false,
  161. /** @scratch /panels/histogram/3
  162. * stack:: Stack multiple series
  163. */
  164. stack : true,
  165. /** @scratch /panels/histogram/3
  166. * spyable:: Show inspect icon
  167. */
  168. spyable : true,
  169. /** @scratch /panels/histogram/3
  170. * zoomlinks:: Show `Zoom Out' link
  171. */
  172. zoomlinks : false,
  173. /** @scratch /panels/histogram/3
  174. * options:: Show quick view options section
  175. */
  176. options : false,
  177. /** @scratch /panels/histogram/3
  178. * legend:: Display the legond
  179. */
  180. legend : true,
  181. /** @scratch /panels/histogram/3
  182. * interactive:: Enable click-and-drag to zoom functionality
  183. */
  184. interactive : true,
  185. /** @scratch /panels/histogram/3
  186. * legend_counts:: Show counts in legend
  187. */
  188. legend_counts : true,
  189. /** @scratch /panels/histogram/3
  190. * ==== Transformations
  191. * timezone:: Correct for browser timezone?. Valid values: browser, utc
  192. */
  193. timezone : 'browser', // browser or utc
  194. /** @scratch /panels/histogram/3
  195. * percentage:: Show the y-axis as a percentage of the axis total. Only makes sense for multiple
  196. * queries
  197. */
  198. percentage : false,
  199. /** @scratch /panels/histogram/3
  200. * zerofill:: Improves the accuracy of line charts at a small performance cost.
  201. */
  202. zerofill : true,
  203. nullPointMode : 'connected',
  204. steppedLine: false,
  205. tooltip : {
  206. value_type: 'cumulative',
  207. query_as_alias: true
  208. },
  209. targets: [],
  210. aliasColors: {},
  211. aliasYAxis: {},
  212. };
  213. _.defaults($scope.panel,_d);
  214. _.defaults($scope.panel.tooltip,_d.tooltip);
  215. _.defaults($scope.panel.annotate,_d.annotate);
  216. _.defaults($scope.panel.grid,_d.grid);
  217. $scope.init = function() {
  218. // Hide view options by default
  219. $scope.fullscreen = false;
  220. $scope.options = false;
  221. $scope.editor = {index: 1};
  222. $scope.editorTabs = _.union(['General'],_.pluck($scope.panelMeta.fullEditorTabs,'title'));
  223. $scope.hiddenSeries = {};
  224. // Always show the query if an alias isn't set. Users can set an alias if the query is too
  225. // long
  226. $scope.panel.tooltip.query_as_alias = true;
  227. $scope.get_data();
  228. };
  229. $scope.set_interval = function(interval) {
  230. if(interval !== 'auto') {
  231. $scope.panel.auto_int = false;
  232. $scope.panel.interval = interval;
  233. } else {
  234. $scope.panel.auto_int = true;
  235. }
  236. };
  237. $scope.typeAheadSource = function () {
  238. return ["test", "asd", "testing2"];
  239. };
  240. $scope.remove_panel_from_row = function(row, panel) {
  241. if ($scope.fullscreen) {
  242. $rootScope.$emit('panel-fullscreen-exit');
  243. }
  244. else {
  245. $scope.$parent.remove_panel_from_row(row, panel);
  246. }
  247. };
  248. $scope.removeTarget = function (target) {
  249. $scope.panel.targets = _.without($scope.panel.targets, target);
  250. $scope.get_data();
  251. };
  252. $scope.interval_label = function(interval) {
  253. return $scope.panel.auto_int && interval === $scope.panel.interval ? interval+" (auto)" : interval;
  254. };
  255. $scope.updateTimeRange = function () {
  256. var range = filterSrv.timeRange();
  257. var interval = filterSrv.timeRange();
  258. if ($scope.panel.auto_int) {
  259. if (range) {
  260. interval = kbn.secondsToHms(
  261. kbn.calculate_interval(range.from, range.to, $scope.panel.resolution, 0) / 1000
  262. );
  263. }
  264. }
  265. $scope.interval = $scope.panel.interval = interval || '10m';
  266. $scope.range = range;
  267. };
  268. $scope.colors = [
  269. "#7EB26D","#EAB839","#6ED0E0","#EF843C","#E24D42","#1F78C1","#BA43A9","#705DA0", //1
  270. "#508642","#CCA300","#447EBC","#C15C17","#890F02","#0A437C","#6D1F62","#584477", //2
  271. "#B7DBAB","#F4D598","#70DBED","#F9BA8F","#F29191","#82B5D8","#E5A8E2","#AEA2E0", //3
  272. "#629E51","#E5AC0E","#64B0C8","#E0752D","#BF1B00","#0A50A1","#962D82","#614D93", //4
  273. "#9AC48A","#F2C96D","#65C5DB","#F9934E","#EA6460","#5195CE","#D683CE","#806EB7", //5
  274. "#3F6833","#967302","#2F575E","#99440A","#58140C","#052B51","#511749","#3F2B5B", //6
  275. "#E0F9D7","#FCEACA","#CFFAFF","#F9E2D2","#FCE2DE","#BADFF4","#F9D9F9","#DEDAF7" //7
  276. ];
  277. /**
  278. * Fetch the data for a chunk of a queries results. Multiple segments occur when several indicies
  279. * need to be consulted (like timestamped logstash indicies)
  280. *
  281. * The results of this function are stored on the scope's data property. This property will be an
  282. * array of objects with the properties info, time_series, and hits. These objects are used in the
  283. * render_panel function to create the historgram.
  284. *
  285. */
  286. $scope.get_data = function() {
  287. delete $scope.panel.error;
  288. $scope.panelMeta.loading = true;
  289. $scope.updateTimeRange();
  290. var graphiteQuery = {
  291. range: $scope.range,
  292. targets: $scope.panel.targets,
  293. maxDataPoints: $scope.panel.span * 50
  294. };
  295. return graphiteSrv.query(graphiteQuery)
  296. .then($scope.receiveGraphiteData)
  297. .then(null, function(err) {
  298. $scope.panel.error = err.message || "Graphite HTTP Request Error";
  299. });
  300. };
  301. $scope.receiveGraphiteData = function(results) {
  302. $scope.panelMeta.loading = false;
  303. results = results.data;
  304. $scope.legend = [];
  305. var data = [];
  306. _.each(results, function(targetData) {
  307. var alias = targetData.target;
  308. var color = $scope.panel.aliasColors[alias] || $scope.colors[data.length];
  309. var yaxis = $scope.panel.aliasYAxis[alias] || 1;
  310. var tsOpts = {
  311. interval: $scope.interval,
  312. start_date: $scope.range && $scope.range.from,
  313. end_date: $scope.range && $scope.range.to,
  314. };
  315. var time_series = new timeSeries.ZeroFilled(tsOpts);
  316. _.each(targetData.datapoints, function(valueArray) {
  317. if (valueArray[0]) {
  318. time_series.addValue(valueArray[1] * 1000, valueArray[0]);
  319. }
  320. });
  321. var seriesInfo = {
  322. alias: alias,
  323. color: color,
  324. enable: true,
  325. yaxis: yaxis,
  326. };
  327. $scope.legend.push(seriesInfo);
  328. data.push({
  329. info: seriesInfo,
  330. time_series: time_series,
  331. });
  332. });
  333. $scope.render(data);
  334. };
  335. $scope.add_target = function() {
  336. $scope.panel.targets.push({target: ''});
  337. };
  338. $scope.enterFullscreenMode = function(options) {
  339. var docHeight = $(window).height();
  340. var editHeight = Math.floor(docHeight * 0.3);
  341. var fullscreenHeight = Math.floor(docHeight * 0.7);
  342. var oldTimeRange = $scope.range;
  343. $scope.height = options.edit ? editHeight : fullscreenHeight;
  344. $scope.editMode = options.edit;
  345. if (!$scope.fullscreen) {
  346. var closeEditMode = $rootScope.$on('panel-fullscreen-exit', function() {
  347. $scope.editMode = false;
  348. $scope.fullscreen = false;
  349. delete $scope.height;
  350. closeEditMode();
  351. $timeout(function() {
  352. $scope.$emit('render');
  353. if (oldTimeRange !== $scope.range) {
  354. $scope.dashboard.refresh();
  355. }
  356. });
  357. });
  358. }
  359. $(window).scrollTop(0);
  360. $scope.fullscreen = true;
  361. $rootScope.$emit('panel-fullscreen-enter');
  362. $timeout($scope.render);
  363. };
  364. $scope.openConfigureModal = function() {
  365. if ($scope.editMode) {
  366. $rootScope.$emit('panel-fullscreen-exit');
  367. return;
  368. }
  369. $scope.enterFullscreenMode({edit: true});
  370. };
  371. $scope.render = function(data) {
  372. $scope.$emit('render', data);
  373. };
  374. $scope.changeSeriesColor = function(series, color) {
  375. series.color = color;
  376. $scope.panel.aliasColors[series.alias] = series.color;
  377. $scope.render();
  378. };
  379. $scope.duplicate = function(addToRow) {
  380. addToRow = addToRow || $scope.row;
  381. var currentRowSpan = $scope.rowSpan(addToRow);
  382. if (currentRowSpan <= 8) {
  383. addToRow.panels.push(angular.copy($scope.panel));
  384. }
  385. else {
  386. var rowsList = $scope.dashboard.current.rows;
  387. var rowIndex = _.indexOf(rowsList, addToRow);
  388. if (rowIndex === rowsList.length - 1) {
  389. var newRow = angular.copy($scope.row);
  390. newRow.panels = [];
  391. $scope.dashboard.current.rows.push(newRow);
  392. $scope.duplicate(newRow);
  393. }
  394. else {
  395. $scope.duplicate(rowsList[rowIndex+1]);
  396. }
  397. }
  398. };
  399. $scope.toggleFullscreen = function() {
  400. if ($scope.fullscreen && !$scope.editMode) {
  401. $rootScope.$emit('panel-fullscreen-exit');
  402. return;
  403. }
  404. $scope.enterFullscreenMode({edit: false});
  405. };
  406. $scope.toggleSeries = function(info) {
  407. if ($scope.hiddenSeries[info.alias]) {
  408. delete $scope.hiddenSeries[info.alias];
  409. }
  410. else {
  411. $scope.hiddenSeries[info.alias] = true;
  412. }
  413. $scope.$emit('toggleLegend', info.alias);
  414. };
  415. $scope.toggleYAxis = function(info) {
  416. info.yaxis = info.yaxis === 2 ? 1 : 2;
  417. $scope.panel.aliasYAxis[info.alias] = info.yaxis;
  418. $scope.render();
  419. };
  420. $scope.updateColumnSpan = function(span) {
  421. $scope.panel.span = span;
  422. $timeout($scope.render);
  423. };
  424. });
  425. module.directive('histogramChart', function(filterSrv, $rootScope) {
  426. return {
  427. restrict: 'A',
  428. template: '<div> </div>',
  429. link: function(scope, elem) {
  430. var data, plot;
  431. var hiddenData = {};
  432. scope.$on('refresh',function() {
  433. if ($rootScope.fullscreen && !scope.fullscreen) {
  434. return;
  435. }
  436. scope.get_data();
  437. });
  438. scope.$on('toggleLegend', function(e, alias) {
  439. if (hiddenData[alias]) {
  440. data.push(hiddenData[alias]);
  441. delete hiddenData[alias];
  442. }
  443. render_panel();
  444. });
  445. // Receive render events
  446. scope.$on('render',function(event, d) {
  447. data = d || data;
  448. render_panel();
  449. });
  450. // Re-render if the window is resized
  451. angular.element(window).bind('resize', function() {
  452. render_panel();
  453. });
  454. // Function for rendering panel
  455. function render_panel() {
  456. if (!data) {
  457. return;
  458. }
  459. // IE doesn't work without this
  460. elem.css({height:scope.height || scope.row.height});
  461. _.each(data, function(series) {
  462. series.label = series.info.alias;
  463. series.color = series.info.color;
  464. });
  465. _.each(_.keys(scope.hiddenSeries), function(seriesAlias) {
  466. var dataSeries = _.find(data, function(series) {
  467. return series.info.alias === seriesAlias;
  468. });
  469. if (dataSeries) {
  470. hiddenData[dataSeries.info.alias] = dataSeries;
  471. data = _.without(data, dataSeries);
  472. }
  473. });
  474. // Set barwidth based on specified interval
  475. var barwidth = kbn.interval_to_ms(scope.panel.interval);
  476. var stack = scope.panel.stack ? true : null;
  477. // Populate element
  478. var options = {
  479. legend: { show: false },
  480. series: {
  481. stackpercent: scope.panel.stack ? scope.panel.percentage : false,
  482. stack: scope.panel.percentage ? null : stack,
  483. lines: {
  484. show: scope.panel.lines,
  485. // Silly, but fixes bug in stacked percentages
  486. fill: scope.panel.fill === 0 ? 0.001 : scope.panel.fill/10,
  487. lineWidth: scope.panel.linewidth,
  488. steps: scope.panel.steppedLine
  489. },
  490. bars: {
  491. show: scope.panel.bars,
  492. fill: 1,
  493. barWidth: barwidth/1.5,
  494. zero: false,
  495. lineWidth: 0
  496. },
  497. points: {
  498. show: scope.panel.points,
  499. fill: 1,
  500. fillColor: false,
  501. radius: scope.panel.pointradius
  502. },
  503. shadowSize: 1
  504. },
  505. yaxes: [],
  506. xaxis: {
  507. timezone: scope.panel.timezone,
  508. show: scope.panel['x-axis'],
  509. mode: "time",
  510. min: _.isUndefined(scope.range.from) ? null : scope.range.from.getTime(),
  511. max: _.isUndefined(scope.range.to) ? null : scope.range.to.getTime(),
  512. timeformat: time_format(scope.panel.interval),
  513. label: "Datetime",
  514. ticks: elem.width()/100
  515. },
  516. grid: {
  517. backgroundColor: null,
  518. borderWidth: 0,
  519. hoverable: true,
  520. color: '#c8c8c8'
  521. }
  522. };
  523. if(scope.panel.annotate.enable) {
  524. options.events = {
  525. levels: 1,
  526. data: scope.annotations,
  527. types: {
  528. 'annotation': {
  529. level: 1,
  530. icon: {
  531. icon: "icon-tag icon-flip-vertical",
  532. size: 20,
  533. color: "#222",
  534. outline: "#bbb"
  535. }
  536. }
  537. }
  538. //xaxis: int // the x axis to attach events to
  539. };
  540. }
  541. if(scope.panel.interactive) {
  542. options.selection = { mode: "x", color: '#666' };
  543. }
  544. // when rendering stacked bars, we need to ensure each point that has data is zero-filled
  545. // so that the stacking happens in the proper order
  546. var required_times = [];
  547. if (data.length > 1) {
  548. required_times = Array.prototype.concat.apply([], _.map(data, function (query) {
  549. return query.time_series.getOrderedTimes();
  550. }));
  551. required_times = _.uniq(required_times.sort(function (a, b) {
  552. // decending numeric sort
  553. return a-b;
  554. }), true);
  555. }
  556. for (var i = 0; i < data.length; i++) {
  557. var _d = data[i].time_series.getFlotPairs(required_times, scope.panel.nullPointMode);
  558. data[i].yaxis = data[i].info.yaxis;
  559. data[i].data = _d;
  560. data[i].info.y_format = data[i].yaxis === 1 ? scope.panel.y_format : scope.panel.y2_format;
  561. }
  562. configureAxisOptions(data, options);
  563. plot = $.plot(elem, data, options);
  564. if (scope.panel.leftYAxisLabel) {
  565. elem.css('margin-left', '10px');
  566. var yaxisLabel = $("<div class='axisLabel yaxisLabel'></div>")
  567. .text(scope.panel.leftYAxisLabel)
  568. .appendTo(elem);
  569. yaxisLabel.css("margin-top", yaxisLabel.width() / 2 - 20);
  570. } else if (elem.css('margin-left')) {
  571. elem.css('margin-left', '');
  572. }
  573. }
  574. function configureAxisOptions(data, options)
  575. {
  576. var defaults = {
  577. position: 'left',
  578. show: scope.panel['y-axis'],
  579. min: scope.panel.grid.min,
  580. max: scope.panel.percentage && scope.panel.stack ? 100 : scope.panel.grid.max
  581. };
  582. options.yaxes.push(defaults);
  583. if (_.findWhere(data, {yaxis: 2})) {
  584. var secondY = _.clone(defaults);
  585. secondY.position = 'right';
  586. options.yaxes.push(secondY);
  587. configureAxisMode(options.yaxes[1], scope.panel.y2_format);
  588. }
  589. configureAxisMode(options.yaxes[0], scope.panel.y_format);
  590. }
  591. function configureAxisMode(axis, format) {
  592. if (format === 'bytes') {
  593. axis.mode = "byte";
  594. }
  595. if (format === 'short') {
  596. axis.tickFormatter = function(val) {
  597. return kbn.shortFormat(val,0);
  598. };
  599. }
  600. }
  601. function time_format(interval) {
  602. var _int = kbn.interval_to_seconds(interval);
  603. if(_int >= 2628000) {
  604. return "%Y-%m";
  605. }
  606. if(_int >= 10000) {
  607. return "%Y-%m-%d";
  608. }
  609. if(_int >= 60) {
  610. return "%H:%M<br>%m-%d";
  611. }
  612. return "%H:%M:%S";
  613. }
  614. var $tooltip = $('<div>');
  615. elem.bind("plothover", function (event, pos, item) {
  616. var group, value, timestamp;
  617. if (item) {
  618. if (item.series.info.alias || scope.panel.tooltip.query_as_alias) {
  619. group = '<small style="font-size:0.9em;">' +
  620. '<i class="icon-circle" style="color:'+item.series.color+';"></i>' + ' ' +
  621. (item.series.info.alias || item.series.info.query)+
  622. '</small><br>';
  623. } else {
  624. group = kbn.query_color_dot(item.series.color, 15) + ' ';
  625. }
  626. value = (scope.panel.stack && scope.panel.tooltip.value_type === 'individual') ?
  627. item.datapoint[1] - item.datapoint[2] :
  628. item.datapoint[1];
  629. if(item.series.info.y_format === 'bytes') {
  630. value = kbn.byteFormat(value,2);
  631. }
  632. if(item.series.info.y_format === 'short') {
  633. value = kbn.shortFormat(value,2);
  634. }
  635. timestamp = scope.panel.timezone === 'browser' ?
  636. moment(item.datapoint[0]).format('YYYY-MM-DD HH:mm:ss') :
  637. moment.utc(item.datapoint[0]).format('YYYY-MM-DD HH:mm:ss');
  638. $tooltip
  639. .html(
  640. group + value + " @ " + timestamp
  641. )
  642. .place_tt(pos.pageX, pos.pageY);
  643. } else {
  644. $tooltip.detach();
  645. }
  646. });
  647. elem.bind("plotselected", function (event, ranges) {
  648. filterSrv.setTime({
  649. from : moment.utc(ranges.xaxis.from).toDate(),
  650. to : moment.utc(ranges.xaxis.to).toDate(),
  651. });
  652. });
  653. }
  654. };
  655. });
  656. });