module.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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/dashboard/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, private $sanitize) {
  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. scopedVars: _.extend({}, this.panel.scopedVars),
  101. };
  102. if (dataList.length > 0 && dataList[0].type === 'table') {
  103. this.dataType = 'table';
  104. const tableData = dataList.map(this.tableHandler.bind(this));
  105. this.setTableValues(tableData, data);
  106. } else {
  107. this.dataType = 'timeseries';
  108. this.series = dataList.map(this.seriesHandler.bind(this));
  109. this.setValues(data);
  110. }
  111. this.data = data;
  112. this.render();
  113. }
  114. seriesHandler(seriesData) {
  115. const series = new TimeSeries({
  116. datapoints: seriesData.datapoints || [],
  117. alias: seriesData.target,
  118. });
  119. series.flotpairs = series.getFlotPairs(this.panel.nullPointMode);
  120. return series;
  121. }
  122. tableHandler(tableData) {
  123. const datapoints = [];
  124. const columnNames = {};
  125. tableData.columns.forEach((column, columnIndex) => {
  126. columnNames[columnIndex] = column.text;
  127. });
  128. this.tableColumnOptions = columnNames;
  129. if (!_.find(tableData.columns, ['text', this.panel.tableColumn])) {
  130. this.setTableColumnToSensibleDefault(tableData);
  131. }
  132. tableData.rows.forEach(row => {
  133. const datapoint = {};
  134. row.forEach((value, columnIndex) => {
  135. const key = columnNames[columnIndex];
  136. datapoint[key] = value;
  137. });
  138. datapoints.push(datapoint);
  139. });
  140. return datapoints;
  141. }
  142. setTableColumnToSensibleDefault(tableData) {
  143. if (tableData.columns.length === 1) {
  144. this.panel.tableColumn = tableData.columns[0].text;
  145. } else {
  146. this.panel.tableColumn = _.find(tableData.columns, col => {
  147. return col.type !== 'time';
  148. }).text;
  149. }
  150. }
  151. setTableValues(tableData, data) {
  152. if (!tableData || tableData.length === 0) {
  153. return;
  154. }
  155. if (tableData[0].length === 0 || tableData[0][0][this.panel.tableColumn] === undefined) {
  156. return;
  157. }
  158. const datapoint = tableData[0][0];
  159. data.value = datapoint[this.panel.tableColumn];
  160. if (_.isString(data.value)) {
  161. data.valueFormatted = _.escape(data.value);
  162. data.value = 0;
  163. data.valueRounded = 0;
  164. } else {
  165. const decimalInfo = this.getDecimalsForValue(data.value);
  166. const formatFunc = kbn.valueFormats[this.panel.format];
  167. data.valueFormatted = formatFunc(
  168. datapoint[this.panel.tableColumn],
  169. decimalInfo.decimals,
  170. decimalInfo.scaledDecimals
  171. );
  172. data.valueRounded = kbn.roundValue(data.value, this.panel.decimals || 0);
  173. }
  174. this.setValueMapping(data);
  175. }
  176. canModifyText() {
  177. return !this.panel.gauge.show;
  178. }
  179. setColoring(options) {
  180. if (options.background) {
  181. this.panel.colorValue = false;
  182. this.panel.colors = ['rgba(71, 212, 59, 0.4)', 'rgba(245, 150, 40, 0.73)', 'rgba(225, 40, 40, 0.59)'];
  183. } else {
  184. this.panel.colorBackground = false;
  185. this.panel.colors = ['rgba(50, 172, 45, 0.97)', 'rgba(237, 129, 40, 0.89)', 'rgba(245, 54, 54, 0.9)'];
  186. }
  187. this.render();
  188. }
  189. invertColorOrder() {
  190. const tmp = this.panel.colors[0];
  191. this.panel.colors[0] = this.panel.colors[2];
  192. this.panel.colors[2] = tmp;
  193. this.render();
  194. }
  195. onColorChange(panelColorIndex) {
  196. return color => {
  197. this.panel.colors[panelColorIndex] = color;
  198. this.render();
  199. };
  200. }
  201. onSparklineColorChange(newColor) {
  202. this.panel.sparkline.lineColor = newColor;
  203. this.render();
  204. }
  205. onSparklineFillChange(newColor) {
  206. this.panel.sparkline.fillColor = newColor;
  207. this.render();
  208. }
  209. getDecimalsForValue(value) {
  210. if (_.isNumber(this.panel.decimals)) {
  211. return { decimals: this.panel.decimals, scaledDecimals: null };
  212. }
  213. const delta = value / 2;
  214. let dec = -Math.floor(Math.log(delta) / Math.LN10);
  215. const magn = Math.pow(10, -dec);
  216. const norm = delta / magn; // norm is between 1.0 and 10.0
  217. let size;
  218. if (norm < 1.5) {
  219. size = 1;
  220. } else if (norm < 3) {
  221. size = 2;
  222. // special case for 2.5, requires an extra decimal
  223. if (norm > 2.25) {
  224. size = 2.5;
  225. ++dec;
  226. }
  227. } else if (norm < 7.5) {
  228. size = 5;
  229. } else {
  230. size = 10;
  231. }
  232. size *= magn;
  233. // reduce starting decimals if not needed
  234. if (Math.floor(value) === value) {
  235. dec = 0;
  236. }
  237. const result: any = {};
  238. result.decimals = Math.max(0, dec);
  239. result.scaledDecimals = result.decimals - Math.floor(Math.log(size) / Math.LN10) + 2;
  240. return result;
  241. }
  242. setValues(data) {
  243. data.flotpairs = [];
  244. if (this.series.length > 1) {
  245. const error: any = new Error();
  246. error.message = 'Multiple Series Error';
  247. error.data =
  248. 'Metric query returns ' +
  249. this.series.length +
  250. ' series. Single Stat Panel expects a single series.\n\nResponse:\n' +
  251. JSON.stringify(this.series);
  252. throw error;
  253. }
  254. if (this.series && this.series.length > 0) {
  255. const lastPoint = _.last(this.series[0].datapoints);
  256. const lastValue = _.isArray(lastPoint) ? lastPoint[0] : null;
  257. if (this.panel.valueName === 'name') {
  258. data.value = 0;
  259. data.valueRounded = 0;
  260. data.valueFormatted = this.series[0].alias;
  261. } else if (_.isString(lastValue)) {
  262. data.value = 0;
  263. data.valueFormatted = _.escape(lastValue);
  264. data.valueRounded = 0;
  265. } else if (this.panel.valueName === 'last_time') {
  266. const formatFunc = kbn.valueFormats[this.panel.format];
  267. data.value = lastPoint[1];
  268. data.valueRounded = data.value;
  269. data.valueFormatted = formatFunc(data.value, this.dashboard.isTimezoneUtc());
  270. } else {
  271. data.value = this.series[0].stats[this.panel.valueName];
  272. data.flotpairs = this.series[0].flotpairs;
  273. const decimalInfo = this.getDecimalsForValue(data.value);
  274. const formatFunc = kbn.valueFormats[this.panel.format];
  275. data.valueFormatted = formatFunc(data.value, decimalInfo.decimals, decimalInfo.scaledDecimals);
  276. data.valueRounded = kbn.roundValue(data.value, decimalInfo.decimals);
  277. }
  278. // Add $__name variable for using in prefix or postfix
  279. data.scopedVars['__name'] = { value: this.series[0].label };
  280. }
  281. this.setValueMapping(data);
  282. }
  283. setValueMapping(data) {
  284. // check value to text mappings if its enabled
  285. if (this.panel.mappingType === 1) {
  286. for (let i = 0; i < this.panel.valueMaps.length; i++) {
  287. const map = this.panel.valueMaps[i];
  288. // special null case
  289. if (map.value === 'null') {
  290. if (data.value === null || data.value === void 0) {
  291. data.valueFormatted = map.text;
  292. return;
  293. }
  294. continue;
  295. }
  296. // value/number to text mapping
  297. const value = parseFloat(map.value);
  298. if (value === data.valueRounded) {
  299. data.valueFormatted = map.text;
  300. return;
  301. }
  302. }
  303. } else if (this.panel.mappingType === 2) {
  304. for (let i = 0; i < this.panel.rangeMaps.length; i++) {
  305. const map = this.panel.rangeMaps[i];
  306. // special null case
  307. if (map.from === 'null' && map.to === 'null') {
  308. if (data.value === null || data.value === void 0) {
  309. data.valueFormatted = map.text;
  310. return;
  311. }
  312. continue;
  313. }
  314. // value/number to range mapping
  315. const from = parseFloat(map.from);
  316. const to = parseFloat(map.to);
  317. if (to >= data.valueRounded && from <= data.valueRounded) {
  318. data.valueFormatted = map.text;
  319. return;
  320. }
  321. }
  322. }
  323. if (data.value === null || data.value === void 0) {
  324. data.valueFormatted = 'no value';
  325. }
  326. }
  327. removeValueMap(map) {
  328. const index = _.indexOf(this.panel.valueMaps, map);
  329. this.panel.valueMaps.splice(index, 1);
  330. this.render();
  331. }
  332. addValueMap() {
  333. this.panel.valueMaps.push({ value: '', op: '=', text: '' });
  334. }
  335. removeRangeMap(rangeMap) {
  336. const index = _.indexOf(this.panel.rangeMaps, rangeMap);
  337. this.panel.rangeMaps.splice(index, 1);
  338. this.render();
  339. }
  340. addRangeMap() {
  341. this.panel.rangeMaps.push({ from: '', to: '', text: '' });
  342. }
  343. link(scope, elem, attrs, ctrl) {
  344. const $location = this.$location;
  345. const linkSrv = this.linkSrv;
  346. const $timeout = this.$timeout;
  347. const $sanitize = this.$sanitize;
  348. const panel = ctrl.panel;
  349. const templateSrv = this.templateSrv;
  350. let data, linkInfo;
  351. const $panelContainer = elem.find('.panel-container');
  352. elem = elem.find('.singlestat-panel');
  353. function applyColoringThresholds(valueString) {
  354. const color = getColorForValue(data, data.value);
  355. if (color) {
  356. return '<span style="color:' + color + '">' + valueString + '</span>';
  357. }
  358. return valueString;
  359. }
  360. function getSpan(className, fontSize, applyColoring, value) {
  361. value = $sanitize(templateSrv.replace(value, data.scopedVars));
  362. value = applyColoring ? applyColoringThresholds(value) : value;
  363. return '<span class="' + className + '" style="font-size:' + fontSize + '">' + value + '</span>';
  364. }
  365. function getBigValueHtml() {
  366. let body = '<div class="singlestat-panel-value-container">';
  367. if (panel.prefix) {
  368. body += getSpan('singlestat-panel-prefix', panel.prefixFontSize, panel.colorPrefix, panel.prefix);
  369. }
  370. body += getSpan('singlestat-panel-value', panel.valueFontSize, panel.colorValue, data.valueFormatted);
  371. if (panel.postfix) {
  372. body += getSpan('singlestat-panel-postfix', panel.postfixFontSize, panel.colorPostfix, panel.postfix);
  373. }
  374. body += '</div>';
  375. return body;
  376. }
  377. function getValueText() {
  378. let result = panel.prefix ? templateSrv.replace(panel.prefix, data.scopedVars) : '';
  379. result += data.valueFormatted;
  380. result += panel.postfix ? templateSrv.replace(panel.postfix, data.scopedVars) : '';
  381. return result;
  382. }
  383. function addGauge() {
  384. const width = elem.width();
  385. const height = elem.height();
  386. // Allow to use a bit more space for wide gauges
  387. const dimension = Math.min(width, height * 1.3);
  388. ctrl.invalidGaugeRange = false;
  389. if (panel.gauge.minValue > panel.gauge.maxValue) {
  390. ctrl.invalidGaugeRange = true;
  391. return;
  392. }
  393. const plotCanvas = $('<div></div>');
  394. const plotCss = {
  395. top: '10px',
  396. margin: 'auto',
  397. position: 'relative',
  398. height: height * 0.9 + 'px',
  399. width: dimension + 'px',
  400. };
  401. plotCanvas.css(plotCss);
  402. const thresholds = [];
  403. for (let i = 0; i < data.thresholds.length; i++) {
  404. thresholds.push({
  405. value: data.thresholds[i],
  406. color: data.colorMap[i],
  407. });
  408. }
  409. thresholds.push({
  410. value: panel.gauge.maxValue,
  411. color: data.colorMap[data.colorMap.length - 1],
  412. });
  413. const bgColor = config.bootData.user.lightTheme ? 'rgb(230,230,230)' : 'rgb(38,38,38)';
  414. const fontScale = parseInt(panel.valueFontSize, 10) / 100;
  415. const fontSize = Math.min(dimension / 5, 100) * fontScale;
  416. // Reduce gauge width if threshold labels enabled
  417. const gaugeWidthReduceRatio = panel.gauge.thresholdLabels ? 1.5 : 1;
  418. const gaugeWidth = Math.min(dimension / 6, 60) / gaugeWidthReduceRatio;
  419. const thresholdMarkersWidth = gaugeWidth / 5;
  420. const thresholdLabelFontSize = fontSize / 2.5;
  421. const options = {
  422. series: {
  423. gauges: {
  424. gauge: {
  425. min: panel.gauge.minValue,
  426. max: panel.gauge.maxValue,
  427. background: { color: bgColor },
  428. border: { color: null },
  429. shadow: { show: false },
  430. width: gaugeWidth,
  431. },
  432. frame: { show: false },
  433. label: { show: false },
  434. layout: { margin: 0, thresholdWidth: 0 },
  435. cell: { border: { width: 0 } },
  436. threshold: {
  437. values: thresholds,
  438. label: {
  439. show: panel.gauge.thresholdLabels,
  440. margin: thresholdMarkersWidth + 1,
  441. font: { size: thresholdLabelFontSize },
  442. },
  443. show: panel.gauge.thresholdMarkers,
  444. width: thresholdMarkersWidth,
  445. },
  446. value: {
  447. color: panel.colorValue ? getColorForValue(data, data.valueRounded) : null,
  448. formatter: () => {
  449. return getValueText();
  450. },
  451. font: {
  452. size: fontSize,
  453. family: '"Helvetica Neue", Helvetica, Arial, sans-serif',
  454. },
  455. },
  456. show: true,
  457. },
  458. },
  459. };
  460. elem.append(plotCanvas);
  461. const plotSeries = {
  462. data: [[0, data.value]],
  463. };
  464. $.plot(plotCanvas, [plotSeries], options);
  465. }
  466. function addSparkline() {
  467. const width = elem.width() + 20;
  468. if (width < 30) {
  469. // element has not gotten it's width yet
  470. // delay sparkline render
  471. setTimeout(addSparkline, 30);
  472. return;
  473. }
  474. const height = ctrl.height;
  475. const plotCanvas = $('<div></div>');
  476. const plotCss: any = {};
  477. plotCss.position = 'absolute';
  478. if (panel.sparkline.full) {
  479. plotCss.bottom = '5px';
  480. plotCss.left = '-5px';
  481. plotCss.width = width - 10 + 'px';
  482. const dynamicHeightMargin = height <= 100 ? 5 : Math.round(height / 100) * 15 + 5;
  483. plotCss.height = height - dynamicHeightMargin + 'px';
  484. } else {
  485. plotCss.bottom = '0px';
  486. plotCss.left = '-5px';
  487. plotCss.width = width - 10 + 'px';
  488. plotCss.height = Math.floor(height * 0.25) + 'px';
  489. }
  490. plotCanvas.css(plotCss);
  491. const options = {
  492. legend: { show: false },
  493. series: {
  494. lines: {
  495. show: true,
  496. fill: 1,
  497. zero: false,
  498. lineWidth: 1,
  499. fillColor: panel.sparkline.fillColor,
  500. },
  501. },
  502. yaxes: { show: false },
  503. xaxis: {
  504. show: false,
  505. mode: 'time',
  506. min: ctrl.range.from.valueOf(),
  507. max: ctrl.range.to.valueOf(),
  508. },
  509. grid: { hoverable: false, show: false },
  510. };
  511. elem.append(plotCanvas);
  512. const plotSeries = {
  513. data: data.flotpairs,
  514. color: panel.sparkline.lineColor,
  515. };
  516. $.plot(plotCanvas, [plotSeries], options);
  517. }
  518. function render() {
  519. if (!ctrl.data) {
  520. return;
  521. }
  522. data = ctrl.data;
  523. // get thresholds
  524. data.thresholds = panel.thresholds.split(',').map(strVale => {
  525. return Number(strVale.trim());
  526. });
  527. data.colorMap = panel.colors;
  528. const body = panel.gauge.show ? '' : getBigValueHtml();
  529. if (panel.colorBackground) {
  530. const color = getColorForValue(data, data.value);
  531. if (color) {
  532. $panelContainer.css('background-color', color);
  533. if (scope.fullscreen) {
  534. elem.css('background-color', color);
  535. } else {
  536. elem.css('background-color', '');
  537. }
  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.getPanelLinkAnchorInfo(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, value) {
  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 };