graph.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import 'vendor/flot/jquery.flot';
  3. import 'vendor/flot/jquery.flot.selection';
  4. import 'vendor/flot/jquery.flot.time';
  5. import 'vendor/flot/jquery.flot.stack';
  6. import 'vendor/flot/jquery.flot.stackpercent';
  7. import 'vendor/flot/jquery.flot.fillbelow';
  8. import 'vendor/flot/jquery.flot.crosshair';
  9. import 'vendor/flot/jquery.flot.dashes';
  10. import './jquery.flot.events';
  11. import $ from 'jquery';
  12. import _ from 'lodash';
  13. import moment from 'moment';
  14. import kbn from 'app/core/utils/kbn';
  15. import {tickStep} from 'app/core/utils/ticks';
  16. import {appEvents, coreModule} from 'app/core/core';
  17. import GraphTooltip from './graph_tooltip';
  18. import {ThresholdManager} from './threshold_manager';
  19. import {EventManager} from 'app/features/annotations/all';
  20. import {convertValuesToHistogram, getSeriesValues} from './histogram';
  21. /** @ngInject **/
  22. function graphDirective($rootScope, timeSrv, popoverSrv, contextSrv) {
  23. return {
  24. restrict: 'A',
  25. template: '',
  26. link: function(scope, elem) {
  27. var ctrl = scope.ctrl;
  28. var dashboard = ctrl.dashboard;
  29. var panel = ctrl.panel;
  30. var annotations = [];
  31. var data;
  32. var plot;
  33. var sortedSeries;
  34. var legendSideLastValue = null;
  35. var rootScope = scope.$root;
  36. var panelWidth = 0;
  37. var eventManager = new EventManager(ctrl);
  38. var thresholdManager = new ThresholdManager(ctrl);
  39. var tooltip = new GraphTooltip(elem, dashboard, scope, function() {
  40. return sortedSeries;
  41. });
  42. // panel events
  43. ctrl.events.on('panel-teardown', () => {
  44. thresholdManager = null;
  45. if (plot) {
  46. plot.destroy();
  47. plot = null;
  48. }
  49. });
  50. ctrl.events.on('render', function(renderData) {
  51. data = renderData || data;
  52. if (!data) {
  53. return;
  54. }
  55. annotations = ctrl.annotations || [];
  56. render_panel();
  57. });
  58. // global events
  59. appEvents.on('graph-hover', function(evt) {
  60. // ignore other graph hover events if shared tooltip is disabled
  61. if (!dashboard.sharedTooltipModeEnabled()) {
  62. return;
  63. }
  64. // ignore if we are the emitter
  65. if (!plot || evt.panel.id === panel.id || ctrl.otherPanelInFullscreenMode()) {
  66. return;
  67. }
  68. tooltip.show(evt.pos);
  69. }, scope);
  70. appEvents.on('graph-hover-clear', function(event, info) {
  71. if (plot) {
  72. tooltip.clear(plot);
  73. }
  74. }, scope);
  75. function getLegendHeight(panelHeight) {
  76. if (!panel.legend.show || panel.legend.rightSide) {
  77. return 0;
  78. }
  79. if (panel.legend.alignAsTable) {
  80. var legendSeries = _.filter(data, function(series) {
  81. return series.hideFromLegend(panel.legend) === false;
  82. });
  83. var total = 23 + (21 * legendSeries.length);
  84. return Math.min(total, Math.floor(panelHeight/2));
  85. } else {
  86. return 26;
  87. }
  88. }
  89. function setElementHeight() {
  90. try {
  91. var height = ctrl.height - getLegendHeight(ctrl.height);
  92. elem.css('height', height + 'px');
  93. return true;
  94. } catch (e) { // IE throws errors sometimes
  95. console.log(e);
  96. return false;
  97. }
  98. }
  99. function shouldAbortRender() {
  100. if (!data) {
  101. return true;
  102. }
  103. if (!setElementHeight()) { return true; }
  104. if (panelWidth === 0) {
  105. return true;
  106. }
  107. return false;
  108. }
  109. function drawHook(plot) {
  110. // Update legend values
  111. var yaxis = plot.getYAxes();
  112. for (var i = 0; i < data.length; i++) {
  113. var series = data[i];
  114. var axis = yaxis[series.yaxis - 1];
  115. var formater = kbn.valueFormats[panel.yaxes[series.yaxis - 1].format];
  116. // decimal override
  117. if (_.isNumber(panel.decimals)) {
  118. series.updateLegendValues(formater, panel.decimals, null);
  119. } else {
  120. // auto decimals
  121. // legend and tooltip gets one more decimal precision
  122. // than graph legend ticks
  123. var tickDecimals = (axis.tickDecimals || -1) + 1;
  124. series.updateLegendValues(formater, tickDecimals, axis.scaledDecimals + 2);
  125. }
  126. if (!rootScope.$$phase) { scope.$digest(); }
  127. }
  128. // add left axis labels
  129. if (panel.yaxes[0].label && panel.yaxes[0].show) {
  130. $("<div class='axisLabel left-yaxis-label flot-temp-elem'></div>").text(panel.yaxes[0].label).appendTo(elem);
  131. }
  132. // add right axis labels
  133. if (panel.yaxes[1].label && panel.yaxes[1].show) {
  134. $("<div class='axisLabel right-yaxis-label flot-temp-elem'></div>").text(panel.yaxes[1].label).appendTo(elem);
  135. }
  136. thresholdManager.draw(plot);
  137. }
  138. function processOffsetHook(plot, gridMargin) {
  139. var left = panel.yaxes[0];
  140. var right = panel.yaxes[1];
  141. if (left.show && left.label) { gridMargin.left = 20; }
  142. if (right.show && right.label) { gridMargin.right = 20; }
  143. // apply y-axis min/max options
  144. var yaxis = plot.getYAxes();
  145. for (var i = 0; i < yaxis.length; i++) {
  146. var axis = yaxis[i];
  147. var panelOptions = panel.yaxes[i];
  148. axis.options.max = axis.options.max !== null ? axis.options.max : panelOptions.max;
  149. axis.options.min = axis.options.min !== null ? axis.options.min : panelOptions.min;
  150. }
  151. }
  152. // Series could have different timeSteps,
  153. // let's find the smallest one so that bars are correctly rendered.
  154. // In addition, only take series which are rendered as bars for this.
  155. function getMinTimeStepOfSeries(data) {
  156. var min = Number.MAX_VALUE;
  157. for (let i = 0; i < data.length; i++) {
  158. if (!data[i].stats.timeStep) {
  159. continue;
  160. }
  161. if (panel.bars) {
  162. if (data[i].bars && data[i].bars.show === false) {
  163. continue;
  164. }
  165. } else {
  166. if (typeof data[i].bars === 'undefined' || typeof data[i].bars.show === 'undefined' || !data[i].bars.show) {
  167. continue;
  168. }
  169. }
  170. if (data[i].stats.timeStep < min) {
  171. min = data[i].stats.timeStep;
  172. }
  173. }
  174. return min;
  175. }
  176. // Function for rendering panel
  177. function render_panel() {
  178. panelWidth = elem.width();
  179. if (shouldAbortRender()) {
  180. return;
  181. }
  182. // give space to alert editing
  183. thresholdManager.prepare(elem, data);
  184. // un-check dashes if lines are unchecked
  185. panel.dashes = panel.lines ? panel.dashes : false;
  186. var stack = panel.stack ? true : null;
  187. // Populate element
  188. var options: any = {
  189. hooks: {
  190. draw: [drawHook],
  191. processOffset: [processOffsetHook],
  192. },
  193. legend: { show: false },
  194. series: {
  195. stackpercent: panel.stack ? panel.percentage : false,
  196. stack: panel.percentage ? null : stack,
  197. lines: {
  198. show: panel.lines,
  199. zero: false,
  200. fill: translateFillOption(panel.fill),
  201. lineWidth: panel.dashes ? 0 : panel.linewidth,
  202. steps: panel.steppedLine
  203. },
  204. dashes: {
  205. show: panel.dashes,
  206. lineWidth: panel.linewidth,
  207. dashLength: [panel.dashLength, panel.spaceLength]
  208. },
  209. bars: {
  210. show: panel.bars,
  211. fill: 1,
  212. barWidth: 1,
  213. zero: false,
  214. lineWidth: 0
  215. },
  216. points: {
  217. show: panel.points,
  218. fill: 1,
  219. fillColor: false,
  220. radius: panel.points ? panel.pointradius : 2
  221. },
  222. shadowSize: 0
  223. },
  224. yaxes: [],
  225. xaxis: {},
  226. grid: {
  227. minBorderMargin: 0,
  228. markings: [],
  229. backgroundColor: null,
  230. borderWidth: 0,
  231. hoverable: true,
  232. clickable: true,
  233. color: '#c8c8c8',
  234. margin: { left: 0, right: 0 },
  235. labelMarginX: 0,
  236. },
  237. selection: {
  238. mode: "x",
  239. color: '#666'
  240. },
  241. crosshair: {
  242. mode: 'x'
  243. }
  244. };
  245. for (let i = 0; i < data.length; i++) {
  246. let series = data[i];
  247. series.data = series.getFlotPairs(series.nullPointMode || panel.nullPointMode);
  248. // if hidden remove points and disable stack
  249. if (ctrl.hiddenSeries[series.alias]) {
  250. series.data = [];
  251. series.stack = false;
  252. }
  253. }
  254. switch (panel.xaxis.mode) {
  255. case 'series': {
  256. options.series.bars.barWidth = 0.7;
  257. options.series.bars.align = 'center';
  258. for (let i = 0; i < data.length; i++) {
  259. let series = data[i];
  260. series.data = [[i + 1, series.stats[panel.xaxis.values[0]]]];
  261. }
  262. addXSeriesAxis(options);
  263. break;
  264. }
  265. case 'histogram': {
  266. let bucketSize: number;
  267. let values = getSeriesValues(data);
  268. if (data.length && values.length) {
  269. let histMin = _.min(_.map(data, s => s.stats.min));
  270. let histMax = _.max(_.map(data, s => s.stats.max));
  271. let ticks = panel.xaxis.buckets || panelWidth / 50;
  272. bucketSize = tickStep(histMin, histMax, ticks);
  273. let histogram = convertValuesToHistogram(values, bucketSize);
  274. data[0].data = histogram;
  275. options.series.bars.barWidth = bucketSize * 0.8;
  276. } else {
  277. bucketSize = 0;
  278. }
  279. addXHistogramAxis(options, bucketSize);
  280. break;
  281. }
  282. case 'table': {
  283. options.series.bars.barWidth = 0.7;
  284. options.series.bars.align = 'center';
  285. addXTableAxis(options);
  286. break;
  287. }
  288. default: {
  289. options.series.bars.barWidth = getMinTimeStepOfSeries(data) / 1.5;
  290. addTimeAxis(options);
  291. break;
  292. }
  293. }
  294. thresholdManager.addFlotOptions(options, panel);
  295. eventManager.addFlotEvents(annotations, options);
  296. configureAxisOptions(data, options);
  297. sortedSeries = sortSeries(data, ctrl.panel);
  298. function callPlot(incrementRenderCounter) {
  299. try {
  300. plot = $.plot(elem, sortedSeries, options);
  301. if (ctrl.renderError) {
  302. delete ctrl.error;
  303. delete ctrl.inspector;
  304. }
  305. } catch (e) {
  306. console.log('flotcharts error', e);
  307. ctrl.error = e.message || "Render Error";
  308. ctrl.renderError = true;
  309. ctrl.inspector = {error: e};
  310. }
  311. if (incrementRenderCounter) {
  312. ctrl.renderingCompleted();
  313. }
  314. }
  315. if (shouldDelayDraw(panel)) {
  316. // temp fix for legends on the side, need to render twice to get dimensions right
  317. callPlot(false);
  318. setTimeout(function() { callPlot(true); }, 50);
  319. legendSideLastValue = panel.legend.rightSide;
  320. } else {
  321. callPlot(true);
  322. }
  323. }
  324. function sortSeries(series, panel) {
  325. var sortBy = panel.legend.sort;
  326. var sortOrder = panel.legend.sortDesc;
  327. var haveSortBy = sortBy !== null || sortBy !== undefined;
  328. var haveSortOrder = sortOrder !== null || sortOrder !== undefined;
  329. var shouldSortBy = panel.stack && haveSortBy && haveSortOrder;
  330. var sortDesc = panel.legend.sortDesc === true ? -1 : 1;
  331. series.sort((x, y) => {
  332. if (x.zindex > y.zindex) {
  333. return 1;
  334. }
  335. if (x.zindex < y.zindex) {
  336. return -1;
  337. }
  338. if (shouldSortBy) {
  339. if (x.stats[sortBy] > y.stats[sortBy]) {
  340. return 1 * sortDesc;
  341. }
  342. if (x.stats[sortBy] < y.stats[sortBy]) {
  343. return -1 * sortDesc;
  344. }
  345. }
  346. return 0;
  347. });
  348. return series;
  349. }
  350. function translateFillOption(fill) {
  351. if (panel.percentage && panel.stack) {
  352. return fill === 0 ? 0.001 : fill/10;
  353. } else {
  354. return fill/10;
  355. }
  356. }
  357. function shouldDelayDraw(panel) {
  358. if (panel.legend.rightSide) {
  359. return true;
  360. }
  361. if (legendSideLastValue !== null && panel.legend.rightSide !== legendSideLastValue) {
  362. return true;
  363. }
  364. return false;
  365. }
  366. function addTimeAxis(options) {
  367. var ticks = panelWidth / 100;
  368. var min = _.isUndefined(ctrl.range.from) ? null : ctrl.range.from.valueOf();
  369. var max = _.isUndefined(ctrl.range.to) ? null : ctrl.range.to.valueOf();
  370. options.xaxis = {
  371. timezone: dashboard.getTimezone(),
  372. show: panel.xaxis.show,
  373. mode: "time",
  374. min: min,
  375. max: max,
  376. label: "Datetime",
  377. ticks: ticks,
  378. timeformat: time_format(ticks, min, max),
  379. };
  380. }
  381. function addXSeriesAxis(options) {
  382. var ticks = _.map(data, function(series, index) {
  383. return [index + 1, series.alias];
  384. });
  385. options.xaxis = {
  386. timezone: dashboard.getTimezone(),
  387. show: panel.xaxis.show,
  388. mode: null,
  389. min: 0,
  390. max: ticks.length + 1,
  391. label: "Datetime",
  392. ticks: ticks
  393. };
  394. }
  395. function addXHistogramAxis(options, bucketSize) {
  396. let ticks, min, max;
  397. let defaultTicks = panelWidth / 50;
  398. if (data.length && bucketSize) {
  399. ticks = _.map(data[0].data, point => point[0]);
  400. min = _.min(ticks);
  401. max = _.max(ticks);
  402. // Adjust tick step
  403. let tickStep = bucketSize;
  404. let ticks_num = Math.floor((max - min) / tickStep);
  405. while (ticks_num > defaultTicks) {
  406. tickStep = tickStep * 2;
  407. ticks_num = Math.ceil((max - min) / tickStep);
  408. }
  409. // Expand ticks for pretty view
  410. min = Math.floor(min / tickStep) * tickStep;
  411. max = Math.ceil(max / tickStep) * tickStep;
  412. ticks = [];
  413. for (let i = min; i <= max; i += tickStep) {
  414. ticks.push(i);
  415. }
  416. } else {
  417. // Set defaults if no data
  418. ticks = defaultTicks / 2;
  419. min = 0;
  420. max = 1;
  421. }
  422. options.xaxis = {
  423. timezone: dashboard.getTimezone(),
  424. show: panel.xaxis.show,
  425. mode: null,
  426. min: min,
  427. max: max,
  428. label: "Histogram",
  429. ticks: ticks
  430. };
  431. // Use 'short' format for histogram values
  432. configureAxisMode(options.xaxis, 'short');
  433. }
  434. function addXTableAxis(options) {
  435. var ticks = _.map(data, function(series, seriesIndex) {
  436. return _.map(series.datapoints, function(point, pointIndex) {
  437. var tickIndex = seriesIndex * series.datapoints.length + pointIndex;
  438. return [tickIndex + 1, point[1]];
  439. });
  440. });
  441. ticks = _.flatten(ticks, true);
  442. options.xaxis = {
  443. timezone: dashboard.getTimezone(),
  444. show: panel.xaxis.show,
  445. mode: null,
  446. min: 0,
  447. max: ticks.length + 1,
  448. label: "Datetime",
  449. ticks: ticks
  450. };
  451. }
  452. function configureAxisOptions(data, options) {
  453. var defaults = {
  454. position: 'left',
  455. show: panel.yaxes[0].show,
  456. index: 1,
  457. logBase: panel.yaxes[0].logBase || 1,
  458. min: parseNumber(panel.yaxes[0].min),
  459. max: parseNumber(panel.yaxes[0].max),
  460. tickDecimals: panel.yaxes[0].decimals
  461. };
  462. options.yaxes.push(defaults);
  463. if (_.find(data, {yaxis: 2})) {
  464. var secondY = _.clone(defaults);
  465. secondY.index = 2;
  466. secondY.show = panel.yaxes[1].show;
  467. secondY.logBase = panel.yaxes[1].logBase || 1;
  468. secondY.position = 'right';
  469. secondY.min = parseNumber(panel.yaxes[1].min);
  470. secondY.max = parseNumber(panel.yaxes[1].max);
  471. secondY.tickDecimals = panel.yaxes[1].decimals;
  472. options.yaxes.push(secondY);
  473. applyLogScale(options.yaxes[1], data);
  474. configureAxisMode(options.yaxes[1], panel.percentage && panel.stack ? "percent" : panel.yaxes[1].format);
  475. }
  476. applyLogScale(options.yaxes[0], data);
  477. configureAxisMode(options.yaxes[0], panel.percentage && panel.stack ? "percent" : panel.yaxes[0].format);
  478. }
  479. function parseNumber(value: any) {
  480. if (value === null || typeof value === 'undefined') {
  481. return null;
  482. }
  483. return _.toNumber(value);
  484. }
  485. function applyLogScale(axis, data) {
  486. if (axis.logBase === 1) {
  487. return;
  488. }
  489. const minSetToZero = axis.min === 0;
  490. if (axis.min < Number.MIN_VALUE) {
  491. axis.min = null;
  492. }
  493. if (axis.max < Number.MIN_VALUE) {
  494. axis.max = null;
  495. }
  496. var series, i;
  497. var max = axis.max, min = axis.min;
  498. for (i = 0; i < data.length; i++) {
  499. series = data[i];
  500. if (series.yaxis === axis.index) {
  501. if (!max || max < series.stats.max) {
  502. max = series.stats.max;
  503. }
  504. if (!min || min > series.stats.logmin) {
  505. min = series.stats.logmin;
  506. }
  507. }
  508. }
  509. axis.transform = function(v) { return (v < Number.MIN_VALUE) ? null : Math.log(v) / Math.log(axis.logBase); };
  510. axis.inverseTransform = function (v) { return Math.pow(axis.logBase,v); };
  511. if (!max && !min) {
  512. max = axis.inverseTransform(+2);
  513. min = axis.inverseTransform(-2);
  514. } else if (!max) {
  515. max = min*axis.inverseTransform(+4);
  516. } else if (!min) {
  517. min = max*axis.inverseTransform(-4);
  518. }
  519. if (axis.min) {
  520. min = axis.inverseTransform(Math.ceil(axis.transform(axis.min)));
  521. } else {
  522. min = axis.min = axis.inverseTransform(Math.floor(axis.transform(min)));
  523. }
  524. if (axis.max) {
  525. max = axis.inverseTransform(Math.floor(axis.transform(axis.max)));
  526. } else {
  527. max = axis.max = axis.inverseTransform(Math.ceil(axis.transform(max)));
  528. }
  529. if (!min || min < Number.MIN_VALUE || !max || max < Number.MIN_VALUE) {
  530. return;
  531. }
  532. if (Number.isFinite(min) && Number.isFinite(max)) {
  533. if (minSetToZero) {
  534. axis.min = 0.1;
  535. min = 1;
  536. }
  537. axis.ticks = generateTicksForLogScaleYAxis(min, max, axis.logBase);
  538. if (minSetToZero) {
  539. axis.ticks.unshift(0.1);
  540. }
  541. if (axis.ticks[axis.ticks.length - 1] > axis.max) {
  542. axis.max = axis.ticks[axis.ticks.length - 1];
  543. }
  544. } else {
  545. axis.ticks = [1, 2];
  546. delete axis.min;
  547. delete axis.max;
  548. }
  549. }
  550. function generateTicksForLogScaleYAxis(min, max, logBase) {
  551. let ticks = [];
  552. var nextTick;
  553. for (nextTick = min; nextTick <= max; nextTick *= logBase) {
  554. ticks.push(nextTick);
  555. }
  556. const maxNumTicks = Math.ceil(ctrl.height/25);
  557. const numTicks = ticks.length;
  558. if (numTicks > maxNumTicks) {
  559. const factor = Math.ceil(numTicks/maxNumTicks) * logBase;
  560. ticks = [];
  561. for (nextTick = min; nextTick <= (max * factor); nextTick *= factor) {
  562. ticks.push(nextTick);
  563. }
  564. }
  565. return ticks;
  566. }
  567. function configureAxisMode(axis, format) {
  568. axis.tickFormatter = function(val, axis) {
  569. return kbn.valueFormats[format](val, axis.tickDecimals, axis.scaledDecimals);
  570. };
  571. }
  572. function time_format(ticks, min, max) {
  573. if (min && max && ticks) {
  574. var range = max - min;
  575. var secPerTick = (range/ticks) / 1000;
  576. var oneDay = 86400000;
  577. var oneYear = 31536000000;
  578. if (secPerTick <= 45) {
  579. return "%H:%M:%S";
  580. }
  581. if (secPerTick <= 7200 || range <= oneDay) {
  582. return "%H:%M";
  583. }
  584. if (secPerTick <= 80000) {
  585. return "%m/%d %H:%M";
  586. }
  587. if (secPerTick <= 2419200 || range <= oneYear) {
  588. return "%m/%d";
  589. }
  590. return "%Y-%m";
  591. }
  592. return "%H:%M";
  593. }
  594. elem.bind("plotselected", function (event, ranges) {
  595. if (panel.xaxis.mode !== 'time') {
  596. // Skip if panel in histogram or series mode
  597. plot.clearSelection();
  598. return;
  599. }
  600. if ((ranges.ctrlKey || ranges.metaKey) && contextSrv.isEditor) {
  601. // Add annotation
  602. setTimeout(() => {
  603. eventManager.updateTime(ranges.xaxis);
  604. }, 100);
  605. } else {
  606. scope.$apply(function() {
  607. timeSrv.setTime({
  608. from : moment.utc(ranges.xaxis.from),
  609. to : moment.utc(ranges.xaxis.to),
  610. });
  611. });
  612. }
  613. });
  614. elem.bind("plotclick", function (event, pos, item) {
  615. if (panel.xaxis.mode !== 'time') {
  616. // Skip if panel in histogram or series mode
  617. return;
  618. }
  619. if ((pos.ctrlKey || pos.metaKey) && contextSrv.isEditor) {
  620. // Skip if range selected (added in "plotselected" event handler)
  621. let isRangeSelection = pos.x !== pos.x1;
  622. if (!isRangeSelection) {
  623. setTimeout(() => {
  624. eventManager.updateTime({from: pos.x, to: null});
  625. }, 100);
  626. }
  627. }
  628. });
  629. scope.$on('$destroy', function() {
  630. tooltip.destroy();
  631. elem.off();
  632. elem.remove();
  633. });
  634. }
  635. };
  636. }
  637. coreModule.directive('grafanaGraph', graphDirective);