graph.ts 21 KB

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