graph.ts 22 KB

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