module.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. import _ from 'lodash';
  2. import $ from 'jquery';
  3. import 'vendor/flot/jquery.flot';
  4. import 'vendor/flot/jquery.flot.gauge';
  5. import 'app/features/panel/panellinks/link_srv';
  6. import { getDecimalsForValue } from '@grafana/ui';
  7. import kbn from 'app/core/utils/kbn';
  8. import config from 'app/core/config';
  9. import TimeSeries from 'app/core/time_series2';
  10. import { MetricsPanelCtrl } from 'app/plugins/sdk';
  11. import { isTableData } from '@grafana/data';
  12. import { GrafanaThemeType, getValueFormat, getColorFromHexRgbOrName } from '@grafana/ui';
  13. import { auto } from 'angular';
  14. import { LinkSrv, LinkModel } from 'app/features/panel/panellinks/link_srv';
  15. import TableModel from 'app/core/table_model';
  16. const BASE_FONT_SIZE = 38;
  17. interface DataFormat {
  18. value: string | number;
  19. valueFormatted: string;
  20. valueRounded: number;
  21. }
  22. class SingleStatCtrl extends MetricsPanelCtrl {
  23. static templateUrl = 'module.html';
  24. dataType = 'timeseries';
  25. series: any[];
  26. data: any;
  27. fontSizes: any[];
  28. unitFormats: any[];
  29. invalidGaugeRange: boolean;
  30. panel: any;
  31. events: any;
  32. valueNameOptions: any[] = [
  33. { value: 'min', text: 'Min' },
  34. { value: 'max', text: 'Max' },
  35. { value: 'avg', text: 'Average' },
  36. { value: 'current', text: 'Current' },
  37. { value: 'total', text: 'Total' },
  38. { value: 'name', text: 'Name' },
  39. { value: 'first', text: 'First' },
  40. { value: 'delta', text: 'Delta' },
  41. { value: 'diff', text: 'Difference' },
  42. { value: 'range', text: 'Range' },
  43. { value: 'last_time', text: 'Time of last point' },
  44. ];
  45. tableColumnOptions: any;
  46. // Set and populate defaults
  47. panelDefaults: any = {
  48. links: [],
  49. datasource: null,
  50. maxDataPoints: 100,
  51. interval: null,
  52. targets: [{}],
  53. cacheTimeout: null,
  54. format: 'none',
  55. prefix: '',
  56. postfix: '',
  57. nullText: null,
  58. valueMaps: [{ value: 'null', op: '=', text: 'N/A' }],
  59. mappingTypes: [{ name: 'value to text', value: 1 }, { name: 'range to text', value: 2 }],
  60. rangeMaps: [{ from: 'null', to: 'null', text: 'N/A' }],
  61. mappingType: 1,
  62. nullPointMode: 'connected',
  63. valueName: 'avg',
  64. prefixFontSize: '50%',
  65. valueFontSize: '80%',
  66. postfixFontSize: '50%',
  67. thresholds: '',
  68. colorBackground: false,
  69. colorValue: false,
  70. colors: ['#299c46', 'rgba(237, 129, 40, 0.89)', '#d44a3a'],
  71. sparkline: {
  72. show: false,
  73. full: false,
  74. ymin: null,
  75. ymax: null,
  76. lineColor: 'rgb(31, 120, 193)',
  77. fillColor: 'rgba(31, 118, 189, 0.18)',
  78. },
  79. gauge: {
  80. show: false,
  81. minValue: 0,
  82. maxValue: 100,
  83. thresholdMarkers: true,
  84. thresholdLabels: false,
  85. },
  86. tableColumn: '',
  87. };
  88. /** @ngInject */
  89. constructor($scope: any, $injector: auto.IInjectorService, private linkSrv: LinkSrv, private $sanitize: any) {
  90. super($scope, $injector);
  91. _.defaults(this.panel, this.panelDefaults);
  92. this.events.on('data-received', this.onDataReceived.bind(this));
  93. this.events.on('data-error', this.onDataError.bind(this));
  94. this.events.on('data-snapshot-load', this.onDataReceived.bind(this));
  95. this.events.on('init-edit-mode', this.onInitEditMode.bind(this));
  96. this.onSparklineColorChange = this.onSparklineColorChange.bind(this);
  97. this.onSparklineFillChange = this.onSparklineFillChange.bind(this);
  98. }
  99. onInitEditMode() {
  100. this.fontSizes = ['20%', '30%', '50%', '70%', '80%', '100%', '110%', '120%', '150%', '170%', '200%'];
  101. this.addEditorTab('Options', 'public/app/plugins/panel/singlestat/editor.html', 2);
  102. this.addEditorTab('Value Mappings', 'public/app/plugins/panel/singlestat/mappings.html', 3);
  103. this.unitFormats = kbn.getUnitFormats();
  104. }
  105. setUnitFormat(subItem: { value: any }) {
  106. this.panel.format = subItem.value;
  107. this.refresh();
  108. }
  109. onDataError(err: any) {
  110. this.onDataReceived([]);
  111. }
  112. onDataReceived(dataList: any[]) {
  113. const data: any = {
  114. scopedVars: _.extend({}, this.panel.scopedVars),
  115. };
  116. if (dataList.length > 0 && isTableData(dataList[0])) {
  117. this.dataType = 'table';
  118. const tableData = dataList.map(this.tableHandler.bind(this));
  119. this.setTableValues(tableData, data);
  120. } else {
  121. this.dataType = 'timeseries';
  122. this.series = dataList.map(this.seriesHandler.bind(this));
  123. this.setValues(data);
  124. }
  125. this.data = data;
  126. this.render();
  127. }
  128. seriesHandler(dataFrame: any) {
  129. const series = new TimeSeries({
  130. datapoints: dataFrame.datapoints || [],
  131. alias: dataFrame.target,
  132. });
  133. series.flotpairs = series.getFlotPairs(this.panel.nullPointMode);
  134. return series;
  135. }
  136. tableHandler(tableData: TableModel) {
  137. const datapoints: any[] = [];
  138. const columnNames: string[] = [];
  139. tableData.columns.forEach((column, columnIndex) => {
  140. columnNames[columnIndex] = column.text;
  141. });
  142. this.tableColumnOptions = columnNames;
  143. if (!_.find(tableData.columns, ['text', this.panel.tableColumn])) {
  144. this.setTableColumnToSensibleDefault(tableData);
  145. }
  146. tableData.rows.forEach(row => {
  147. const datapoint: any = {};
  148. row.forEach((value: any, columnIndex: number) => {
  149. const key = columnNames[columnIndex];
  150. datapoint[key] = value;
  151. });
  152. datapoints.push(datapoint);
  153. });
  154. return datapoints;
  155. }
  156. setTableColumnToSensibleDefault(tableData: TableModel) {
  157. if (tableData.columns.length === 1) {
  158. this.panel.tableColumn = tableData.columns[0].text;
  159. } else {
  160. this.panel.tableColumn = _.find(tableData.columns, col => {
  161. return col.type !== 'time';
  162. }).text;
  163. }
  164. }
  165. setTableValues(tableData: any[], data: DataFormat) {
  166. if (!tableData || tableData.length === 0) {
  167. return;
  168. }
  169. if (tableData[0].length === 0 || tableData[0][0][this.panel.tableColumn] === undefined) {
  170. return;
  171. }
  172. const datapoint = tableData[0][0];
  173. data.value = datapoint[this.panel.tableColumn];
  174. if (_.isString(data.value)) {
  175. data.valueFormatted = _.escape(data.value);
  176. data.value = 0;
  177. data.valueRounded = 0;
  178. } else {
  179. const decimalInfo = getDecimalsForValue(data.value, this.panel.decimals);
  180. const formatFunc = getValueFormat(this.panel.format);
  181. data.valueFormatted = formatFunc(
  182. datapoint[this.panel.tableColumn],
  183. decimalInfo.decimals,
  184. decimalInfo.scaledDecimals
  185. );
  186. data.valueRounded = kbn.roundValue(data.value, decimalInfo.decimals);
  187. }
  188. this.setValueMapping(data);
  189. }
  190. canModifyText() {
  191. return !this.panel.gauge.show;
  192. }
  193. setColoring(options: { background: any }) {
  194. if (options.background) {
  195. this.panel.colorValue = false;
  196. this.panel.colors = ['rgba(71, 212, 59, 0.4)', 'rgba(245, 150, 40, 0.73)', 'rgba(225, 40, 40, 0.59)'];
  197. } else {
  198. this.panel.colorBackground = false;
  199. this.panel.colors = ['rgba(50, 172, 45, 0.97)', 'rgba(237, 129, 40, 0.89)', 'rgba(245, 54, 54, 0.9)'];
  200. }
  201. this.render();
  202. }
  203. invertColorOrder() {
  204. const tmp = this.panel.colors[0];
  205. this.panel.colors[0] = this.panel.colors[2];
  206. this.panel.colors[2] = tmp;
  207. this.render();
  208. }
  209. onColorChange(panelColorIndex: number) {
  210. return (color: string) => {
  211. this.panel.colors[panelColorIndex] = color;
  212. this.render();
  213. };
  214. }
  215. onSparklineColorChange(newColor: string) {
  216. this.panel.sparkline.lineColor = newColor;
  217. this.render();
  218. }
  219. onSparklineFillChange(newColor: string) {
  220. this.panel.sparkline.fillColor = newColor;
  221. this.render();
  222. }
  223. setValues(data: any) {
  224. data.flotpairs = [];
  225. if (this.series.length > 1) {
  226. const error: any = new Error();
  227. error.message = 'Multiple Series Error';
  228. error.data =
  229. 'Metric query returns ' +
  230. this.series.length +
  231. ' series. Single Stat Panel expects a single series.\n\nResponse:\n' +
  232. JSON.stringify(this.series);
  233. throw error;
  234. }
  235. if (this.series && this.series.length > 0) {
  236. const lastPoint: any = _.last(this.series[0].datapoints);
  237. const lastValue = _.isArray(lastPoint) ? lastPoint[0] : null;
  238. const formatFunc = getValueFormat(this.panel.format);
  239. if (this.panel.valueName === 'name') {
  240. data.value = 0;
  241. data.valueRounded = 0;
  242. data.valueFormatted = this.series[0].alias;
  243. } else if (_.isString(lastValue)) {
  244. data.value = 0;
  245. data.valueFormatted = _.escape(lastValue);
  246. data.valueRounded = 0;
  247. } else if (this.panel.valueName === 'last_time') {
  248. data.value = lastPoint[1];
  249. data.valueRounded = data.value;
  250. data.valueFormatted = formatFunc(data.value, 0, 0, this.dashboard.isTimezoneUtc());
  251. } else {
  252. data.value = this.series[0].stats[this.panel.valueName];
  253. data.flotpairs = this.series[0].flotpairs;
  254. const decimalInfo = getDecimalsForValue(data.value, this.panel.decimals);
  255. data.valueFormatted = formatFunc(
  256. data.value,
  257. decimalInfo.decimals,
  258. decimalInfo.scaledDecimals,
  259. this.dashboard.isTimezoneUtc()
  260. );
  261. data.valueRounded = kbn.roundValue(data.value, decimalInfo.decimals);
  262. }
  263. // Add $__name variable for using in prefix or postfix
  264. data.scopedVars['__name'] = { value: this.series[0].label };
  265. }
  266. this.setValueMapping(data);
  267. }
  268. setValueMapping(data: DataFormat) {
  269. // check value to text mappings if its enabled
  270. if (this.panel.mappingType === 1) {
  271. for (let i = 0; i < this.panel.valueMaps.length; i++) {
  272. const map = this.panel.valueMaps[i];
  273. // special null case
  274. if (map.value === 'null') {
  275. if (data.value === null || data.value === void 0) {
  276. data.valueFormatted = map.text;
  277. return;
  278. }
  279. continue;
  280. }
  281. // value/number to text mapping
  282. const value = parseFloat(map.value);
  283. if (value === data.valueRounded) {
  284. data.valueFormatted = map.text;
  285. return;
  286. }
  287. }
  288. } else if (this.panel.mappingType === 2) {
  289. for (let i = 0; i < this.panel.rangeMaps.length; i++) {
  290. const map = this.panel.rangeMaps[i];
  291. // special null case
  292. if (map.from === 'null' && map.to === 'null') {
  293. if (data.value === null || data.value === void 0) {
  294. data.valueFormatted = map.text;
  295. return;
  296. }
  297. continue;
  298. }
  299. // value/number to range mapping
  300. const from = parseFloat(map.from);
  301. const to = parseFloat(map.to);
  302. if (to >= data.valueRounded && from <= data.valueRounded) {
  303. data.valueFormatted = map.text;
  304. return;
  305. }
  306. }
  307. }
  308. if (data.value === null || data.value === void 0) {
  309. data.valueFormatted = 'no value';
  310. }
  311. }
  312. removeValueMap(map: any) {
  313. const index = _.indexOf(this.panel.valueMaps, map);
  314. this.panel.valueMaps.splice(index, 1);
  315. this.render();
  316. }
  317. addValueMap() {
  318. this.panel.valueMaps.push({ value: '', op: '=', text: '' });
  319. }
  320. removeRangeMap(rangeMap: any) {
  321. const index = _.indexOf(this.panel.rangeMaps, rangeMap);
  322. this.panel.rangeMaps.splice(index, 1);
  323. this.render();
  324. }
  325. addRangeMap() {
  326. this.panel.rangeMaps.push({ from: '', to: '', text: '' });
  327. }
  328. link(scope: any, elem: JQuery, attrs: any, ctrl: any) {
  329. const $location = this.$location;
  330. const linkSrv = this.linkSrv;
  331. const $timeout = this.$timeout;
  332. const $sanitize = this.$sanitize;
  333. const panel = ctrl.panel;
  334. const templateSrv = this.templateSrv;
  335. let data: any;
  336. let linkInfo: LinkModel | null = null;
  337. const $panelContainer = elem.find('.panel-container');
  338. elem = elem.find('.singlestat-panel');
  339. function applyColoringThresholds(valueString: string) {
  340. const color = getColorForValue(data, data.value);
  341. if (color) {
  342. return '<span style="color:' + color + '">' + valueString + '</span>';
  343. }
  344. return valueString;
  345. }
  346. function getSpan(className: string, fontSizePercent: string, applyColoring: any, value: string) {
  347. value = $sanitize(templateSrv.replace(value, data.scopedVars));
  348. value = applyColoring ? applyColoringThresholds(value) : value;
  349. const pixelSize = (parseInt(fontSizePercent, 10) / 100) * BASE_FONT_SIZE;
  350. return '<span class="' + className + '" style="font-size:' + pixelSize + 'px">' + value + '</span>';
  351. }
  352. function getBigValueHtml() {
  353. let body = '<div class="singlestat-panel-value-container">';
  354. if (panel.prefix) {
  355. body += getSpan('singlestat-panel-prefix', panel.prefixFontSize, panel.colorPrefix, panel.prefix);
  356. }
  357. body += getSpan('singlestat-panel-value', panel.valueFontSize, panel.colorValue, data.valueFormatted);
  358. if (panel.postfix) {
  359. body += getSpan('singlestat-panel-postfix', panel.postfixFontSize, panel.colorPostfix, panel.postfix);
  360. }
  361. body += '</div>';
  362. return body;
  363. }
  364. function getValueText() {
  365. let result = panel.prefix ? templateSrv.replace(panel.prefix, data.scopedVars) : '';
  366. result += data.valueFormatted;
  367. result += panel.postfix ? templateSrv.replace(panel.postfix, data.scopedVars) : '';
  368. return result;
  369. }
  370. function addGauge() {
  371. const width = elem.width();
  372. const height = elem.height();
  373. // Allow to use a bit more space for wide gauges
  374. const dimension = Math.min(width, height * 1.3);
  375. ctrl.invalidGaugeRange = false;
  376. if (panel.gauge.minValue > panel.gauge.maxValue) {
  377. ctrl.invalidGaugeRange = true;
  378. return;
  379. }
  380. const plotCanvas = $('<div></div>');
  381. const plotCss = {
  382. top: '5px',
  383. margin: 'auto',
  384. position: 'relative',
  385. height: height * 0.9 + 'px',
  386. width: dimension + 'px',
  387. };
  388. plotCanvas.css(plotCss);
  389. const thresholds = [];
  390. for (let i = 0; i < data.thresholds.length; i++) {
  391. thresholds.push({
  392. value: data.thresholds[i],
  393. color: data.colorMap[i],
  394. });
  395. }
  396. thresholds.push({
  397. value: panel.gauge.maxValue,
  398. color: data.colorMap[data.colorMap.length - 1],
  399. });
  400. const bgColor = config.bootData.user.lightTheme ? 'rgb(230,230,230)' : 'rgb(38,38,38)';
  401. const fontScale = parseInt(panel.valueFontSize, 10) / 100;
  402. const fontSize = Math.min(dimension / 5, 100) * fontScale;
  403. // Reduce gauge width if threshold labels enabled
  404. const gaugeWidthReduceRatio = panel.gauge.thresholdLabels ? 1.5 : 1;
  405. const gaugeWidth = Math.min(dimension / 6, 60) / gaugeWidthReduceRatio;
  406. const thresholdMarkersWidth = gaugeWidth / 5;
  407. const thresholdLabelFontSize = fontSize / 2.5;
  408. const options: any = {
  409. series: {
  410. gauges: {
  411. gauge: {
  412. min: panel.gauge.minValue,
  413. max: panel.gauge.maxValue,
  414. background: { color: bgColor },
  415. border: { color: null },
  416. shadow: { show: false },
  417. width: gaugeWidth,
  418. },
  419. frame: { show: false },
  420. label: { show: false },
  421. layout: { margin: 0, thresholdWidth: 0 },
  422. cell: { border: { width: 0 } },
  423. threshold: {
  424. values: thresholds,
  425. label: {
  426. show: panel.gauge.thresholdLabels,
  427. margin: thresholdMarkersWidth + 1,
  428. font: { size: thresholdLabelFontSize },
  429. },
  430. show: panel.gauge.thresholdMarkers,
  431. width: thresholdMarkersWidth,
  432. },
  433. value: {
  434. color: panel.colorValue ? getColorForValue(data, data.valueRounded) : null,
  435. formatter: () => {
  436. return getValueText();
  437. },
  438. font: {
  439. size: fontSize,
  440. family: config.theme.typography.fontFamily.sansSerif,
  441. },
  442. },
  443. show: true,
  444. },
  445. },
  446. };
  447. elem.append(plotCanvas);
  448. const plotSeries = {
  449. data: [[0, data.value]],
  450. };
  451. $.plot(plotCanvas, [plotSeries], options);
  452. }
  453. function addSparkline() {
  454. const width = elem.width();
  455. if (width < 30) {
  456. // element has not gotten it's width yet
  457. // delay sparkline render
  458. setTimeout(addSparkline, 30);
  459. return;
  460. }
  461. const height = ctrl.height;
  462. const plotCanvas = $('<div></div>');
  463. const plotCss: any = {};
  464. plotCss.position = 'absolute';
  465. plotCss.bottom = '0px';
  466. if (panel.sparkline.full) {
  467. plotCss.left = '0px';
  468. plotCss.width = width + 'px';
  469. const dynamicHeightMargin = height <= 100 ? 5 : Math.round(height / 100) * 15 + 5;
  470. plotCss.height = height - dynamicHeightMargin + 'px';
  471. } else {
  472. plotCss.left = '0px';
  473. plotCss.width = width + 'px';
  474. plotCss.height = Math.floor(height * 0.25) + 'px';
  475. }
  476. plotCanvas.css(plotCss);
  477. const options = {
  478. legend: { show: false },
  479. series: {
  480. lines: {
  481. show: true,
  482. fill: 1,
  483. lineWidth: 1,
  484. fillColor: getColorFromHexRgbOrName(panel.sparkline.fillColor, config.theme.type),
  485. zero: false,
  486. },
  487. },
  488. yaxis: {
  489. show: false,
  490. min: panel.sparkline.ymin,
  491. max: panel.sparkline.ymax,
  492. },
  493. xaxis: {
  494. show: false,
  495. mode: 'time',
  496. min: ctrl.range.from.valueOf(),
  497. max: ctrl.range.to.valueOf(),
  498. },
  499. grid: { hoverable: false, show: false },
  500. };
  501. elem.append(plotCanvas);
  502. const plotSeries = {
  503. data: data.flotpairs,
  504. color: getColorFromHexRgbOrName(panel.sparkline.lineColor, config.theme.type),
  505. };
  506. $.plot(plotCanvas, [plotSeries], options);
  507. }
  508. function render() {
  509. if (!ctrl.data) {
  510. return;
  511. }
  512. data = ctrl.data;
  513. // get thresholds
  514. data.thresholds = panel.thresholds.split(',').map((strVale: string) => {
  515. return Number(strVale.trim());
  516. });
  517. // Map panel colors to hex or rgb/a values
  518. data.colorMap = panel.colors.map((color: string) =>
  519. getColorFromHexRgbOrName(
  520. color,
  521. config.bootData.user.lightTheme ? GrafanaThemeType.Light : GrafanaThemeType.Dark
  522. )
  523. );
  524. const body = panel.gauge.show ? '' : getBigValueHtml();
  525. if (panel.colorBackground) {
  526. const color = getColorForValue(data, data.value);
  527. console.log(color);
  528. if (color) {
  529. $panelContainer.css('background-color', color);
  530. if (scope.fullscreen) {
  531. elem.css('background-color', color);
  532. } else {
  533. elem.css('background-color', '');
  534. }
  535. } else {
  536. $panelContainer.css('background-color', '');
  537. elem.css('background-color', '');
  538. }
  539. } else {
  540. $panelContainer.css('background-color', '');
  541. elem.css('background-color', '');
  542. }
  543. elem.html(body);
  544. if (panel.sparkline.show) {
  545. addSparkline();
  546. }
  547. if (panel.gauge.show) {
  548. addGauge();
  549. }
  550. elem.toggleClass('pointer', panel.links.length > 0);
  551. if (panel.links.length > 0) {
  552. linkInfo = linkSrv.getDataLinkUIModel(panel.links[0], data.scopedVars);
  553. } else {
  554. linkInfo = null;
  555. }
  556. }
  557. function hookupDrilldownLinkTooltip() {
  558. // drilldown link tooltip
  559. const drilldownTooltip = $('<div id="tooltip" class="">hello</div>"');
  560. elem.mouseleave(() => {
  561. if (panel.links.length === 0) {
  562. return;
  563. }
  564. $timeout(() => {
  565. drilldownTooltip.detach();
  566. });
  567. });
  568. elem.click(evt => {
  569. if (!linkInfo) {
  570. return;
  571. }
  572. // ignore title clicks in title
  573. if ($(evt).parents('.panel-header').length > 0) {
  574. return;
  575. }
  576. if (linkInfo.target === '_blank') {
  577. window.open(linkInfo.href, '_blank');
  578. return;
  579. }
  580. if (linkInfo.href.indexOf('http') === 0) {
  581. window.location.href = linkInfo.href;
  582. } else {
  583. $timeout(() => {
  584. $location.url(linkInfo.href);
  585. });
  586. }
  587. drilldownTooltip.detach();
  588. });
  589. elem.mousemove(e => {
  590. if (!linkInfo) {
  591. return;
  592. }
  593. drilldownTooltip.text('click to go to: ' + linkInfo.title);
  594. drilldownTooltip.place_tt(e.pageX, e.pageY - 50);
  595. });
  596. }
  597. hookupDrilldownLinkTooltip();
  598. this.events.on('render', () => {
  599. render();
  600. ctrl.renderingCompleted();
  601. });
  602. }
  603. }
  604. function getColorForValue(data: any, value: number) {
  605. if (!_.isFinite(value)) {
  606. return null;
  607. }
  608. for (let i = data.thresholds.length; i > 0; i--) {
  609. if (value >= data.thresholds[i - 1]) {
  610. return data.colorMap[i];
  611. }
  612. }
  613. return _.first(data.colorMap);
  614. }
  615. export { SingleStatCtrl, SingleStatCtrl as PanelCtrl, getColorForValue };