module.ts 20 KB

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