module.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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 $location, 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 (this.tableColumnOptions.length === 1) {
  142. this.panel.tableColumn = this.tableColumnOptions[0];
  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. setColoring(options) {
  175. if (options.background) {
  176. this.panel.colorValue = false;
  177. this.panel.colors = ['rgba(71, 212, 59, 0.4)', 'rgba(245, 150, 40, 0.73)', 'rgba(225, 40, 40, 0.59)'];
  178. } else {
  179. this.panel.colorBackground = false;
  180. this.panel.colors = ['rgba(50, 172, 45, 0.97)', 'rgba(237, 129, 40, 0.89)', 'rgba(245, 54, 54, 0.9)'];
  181. }
  182. this.render();
  183. }
  184. invertColorOrder() {
  185. var tmp = this.panel.colors[0];
  186. this.panel.colors[0] = this.panel.colors[2];
  187. this.panel.colors[2] = tmp;
  188. this.render();
  189. }
  190. onColorChange(panelColorIndex) {
  191. return color => {
  192. this.panel.colors[panelColorIndex] = color;
  193. this.render();
  194. };
  195. }
  196. onSparklineColorChange(newColor) {
  197. this.panel.sparkline.lineColor = newColor;
  198. this.render();
  199. }
  200. onSparklineFillChange(newColor) {
  201. this.panel.sparkline.fillColor = newColor;
  202. this.render();
  203. }
  204. getDecimalsForValue(value) {
  205. if (_.isNumber(this.panel.decimals)) {
  206. return { decimals: this.panel.decimals, scaledDecimals: null };
  207. }
  208. var delta = value / 2;
  209. var dec = -Math.floor(Math.log(delta) / Math.LN10);
  210. var magn = Math.pow(10, -dec),
  211. norm = delta / magn, // norm is between 1.0 and 10.0
  212. size;
  213. if (norm < 1.5) {
  214. size = 1;
  215. } else if (norm < 3) {
  216. size = 2;
  217. // special case for 2.5, requires an extra decimal
  218. if (norm > 2.25) {
  219. size = 2.5;
  220. ++dec;
  221. }
  222. } else if (norm < 7.5) {
  223. size = 5;
  224. } else {
  225. size = 10;
  226. }
  227. size *= magn;
  228. // reduce starting decimals if not needed
  229. if (Math.floor(value) === value) {
  230. dec = 0;
  231. }
  232. var result: any = {};
  233. result.decimals = Math.max(0, dec);
  234. result.scaledDecimals = result.decimals - Math.floor(Math.log(size) / Math.LN10) + 2;
  235. return result;
  236. }
  237. setValues(data) {
  238. data.flotpairs = [];
  239. if (this.series.length > 1) {
  240. var error: any = new Error();
  241. error.message = 'Multiple Series Error';
  242. error.data =
  243. 'Metric query returns ' +
  244. this.series.length +
  245. ' series. Single Stat Panel expects a single series.\n\nResponse:\n' +
  246. JSON.stringify(this.series);
  247. throw error;
  248. }
  249. if (this.series && this.series.length > 0) {
  250. let lastPoint = _.last(this.series[0].datapoints);
  251. let lastValue = _.isArray(lastPoint) ? lastPoint[0] : null;
  252. if (this.panel.valueName === 'name') {
  253. data.value = 0;
  254. data.valueRounded = 0;
  255. data.valueFormatted = this.series[0].alias;
  256. } else if (_.isString(lastValue)) {
  257. data.value = 0;
  258. data.valueFormatted = _.escape(lastValue);
  259. data.valueRounded = 0;
  260. } else if (this.panel.valueName === 'last_time') {
  261. let formatFunc = kbn.valueFormats[this.panel.format];
  262. data.value = lastPoint[1];
  263. data.valueRounded = data.value;
  264. data.valueFormatted = formatFunc(data.value, 0, 0);
  265. } else {
  266. data.value = this.series[0].stats[this.panel.valueName];
  267. data.flotpairs = this.series[0].flotpairs;
  268. let decimalInfo = this.getDecimalsForValue(data.value);
  269. let formatFunc = kbn.valueFormats[this.panel.format];
  270. data.valueFormatted = formatFunc(data.value, decimalInfo.decimals, decimalInfo.scaledDecimals);
  271. data.valueRounded = kbn.roundValue(data.value, decimalInfo.decimals);
  272. }
  273. // Add $__name variable for using in prefix or postfix
  274. data.scopedVars = _.extend({}, this.panel.scopedVars);
  275. data.scopedVars['__name'] = { value: this.series[0].label };
  276. }
  277. this.setValueMapping(data);
  278. }
  279. setValueMapping(data) {
  280. // check value to text mappings if its enabled
  281. if (this.panel.mappingType === 1) {
  282. for (let i = 0; i < this.panel.valueMaps.length; i++) {
  283. let map = this.panel.valueMaps[i];
  284. // special null case
  285. if (map.value === 'null') {
  286. if (data.value === null || data.value === void 0) {
  287. data.valueFormatted = map.text;
  288. return;
  289. }
  290. continue;
  291. }
  292. // value/number to text mapping
  293. var value = parseFloat(map.value);
  294. if (value === data.valueRounded) {
  295. data.valueFormatted = map.text;
  296. return;
  297. }
  298. }
  299. } else if (this.panel.mappingType === 2) {
  300. for (let i = 0; i < this.panel.rangeMaps.length; i++) {
  301. let map = this.panel.rangeMaps[i];
  302. // special null case
  303. if (map.from === 'null' && map.to === 'null') {
  304. if (data.value === null || data.value === void 0) {
  305. data.valueFormatted = map.text;
  306. return;
  307. }
  308. continue;
  309. }
  310. // value/number to range mapping
  311. var from = parseFloat(map.from);
  312. var to = parseFloat(map.to);
  313. if (to >= data.valueRounded && from <= data.valueRounded) {
  314. data.valueFormatted = map.text;
  315. return;
  316. }
  317. }
  318. }
  319. if (data.value === null || data.value === void 0) {
  320. data.valueFormatted = 'no value';
  321. }
  322. }
  323. removeValueMap(map) {
  324. var index = _.indexOf(this.panel.valueMaps, map);
  325. this.panel.valueMaps.splice(index, 1);
  326. this.render();
  327. }
  328. addValueMap() {
  329. this.panel.valueMaps.push({ value: '', op: '=', text: '' });
  330. }
  331. removeRangeMap(rangeMap) {
  332. var index = _.indexOf(this.panel.rangeMaps, rangeMap);
  333. this.panel.rangeMaps.splice(index, 1);
  334. this.render();
  335. }
  336. addRangeMap() {
  337. this.panel.rangeMaps.push({ from: '', to: '', text: '' });
  338. }
  339. link(scope, elem, attrs, ctrl) {
  340. var $location = this.$location;
  341. var linkSrv = this.linkSrv;
  342. var $timeout = this.$timeout;
  343. var panel = ctrl.panel;
  344. var templateSrv = this.templateSrv;
  345. var data, linkInfo;
  346. var $panelContainer = elem.find('.panel-container');
  347. elem = elem.find('.singlestat-panel');
  348. function applyColoringThresholds(value, valueString) {
  349. if (!panel.colorValue) {
  350. return valueString;
  351. }
  352. var color = getColorForValue(data, value);
  353. if (color) {
  354. return '<span style="color:' + color + '">' + valueString + '</span>';
  355. }
  356. return valueString;
  357. }
  358. function getSpan(className, fontSize, value) {
  359. value = templateSrv.replace(value, data.scopedVars);
  360. return '<span class="' + className + '" style="font-size:' + fontSize + '">' + value + '</span>';
  361. }
  362. function getBigValueHtml() {
  363. var body = '<div class="singlestat-panel-value-container">';
  364. if (panel.prefix) {
  365. body += getSpan('singlestat-panel-prefix', panel.prefixFontSize, panel.prefix);
  366. }
  367. var value = applyColoringThresholds(data.value, data.valueFormatted);
  368. body += getSpan('singlestat-panel-value', panel.valueFontSize, value);
  369. if (panel.postfix) {
  370. body += getSpan('singlestat-panel-postfix', panel.postfixFontSize, panel.postfix);
  371. }
  372. body += '</div>';
  373. return body;
  374. }
  375. function getValueText() {
  376. var result = panel.prefix ? templateSrv.replace(panel.prefix, data.scopedVars) : '';
  377. result += data.valueFormatted;
  378. result += panel.postfix ? templateSrv.replace(panel.postfix, data.scopedVars) : '';
  379. return result;
  380. }
  381. function addGauge() {
  382. var width = elem.width();
  383. var height = elem.height();
  384. // Allow to use a bit more space for wide gauges
  385. var dimension = Math.min(width, height * 1.3);
  386. ctrl.invalidGaugeRange = false;
  387. if (panel.gauge.minValue > panel.gauge.maxValue) {
  388. ctrl.invalidGaugeRange = true;
  389. return;
  390. }
  391. var plotCanvas = $('<div></div>');
  392. var plotCss = {
  393. top: '10px',
  394. margin: 'auto',
  395. position: 'relative',
  396. height: height * 0.9 + 'px',
  397. width: dimension + 'px',
  398. };
  399. plotCanvas.css(plotCss);
  400. var thresholds = [];
  401. for (var i = 0; i < data.thresholds.length; i++) {
  402. thresholds.push({
  403. value: data.thresholds[i],
  404. color: data.colorMap[i],
  405. });
  406. }
  407. thresholds.push({
  408. value: panel.gauge.maxValue,
  409. color: data.colorMap[data.colorMap.length - 1],
  410. });
  411. var bgColor = config.bootData.user.lightTheme ? 'rgb(230,230,230)' : 'rgb(38,38,38)';
  412. var fontScale = parseInt(panel.valueFontSize) / 100;
  413. var fontSize = Math.min(dimension / 5, 100) * fontScale;
  414. // Reduce gauge width if threshold labels enabled
  415. var gaugeWidthReduceRatio = panel.gauge.thresholdLabels ? 1.5 : 1;
  416. var gaugeWidth = Math.min(dimension / 6, 60) / gaugeWidthReduceRatio;
  417. var thresholdMarkersWidth = gaugeWidth / 5;
  418. var thresholdLabelFontSize = fontSize / 2.5;
  419. var options = {
  420. series: {
  421. gauges: {
  422. gauge: {
  423. min: panel.gauge.minValue,
  424. max: panel.gauge.maxValue,
  425. background: { color: bgColor },
  426. border: { color: null },
  427. shadow: { show: false },
  428. width: gaugeWidth,
  429. },
  430. frame: { show: false },
  431. label: { show: false },
  432. layout: { margin: 0, thresholdWidth: 0 },
  433. cell: { border: { width: 0 } },
  434. threshold: {
  435. values: thresholds,
  436. label: {
  437. show: panel.gauge.thresholdLabels,
  438. margin: thresholdMarkersWidth + 1,
  439. font: { size: thresholdLabelFontSize },
  440. },
  441. show: panel.gauge.thresholdMarkers,
  442. width: thresholdMarkersWidth,
  443. },
  444. value: {
  445. color: panel.colorValue ? getColorForValue(data, data.valueRounded) : null,
  446. formatter: function() {
  447. return getValueText();
  448. },
  449. font: {
  450. size: fontSize,
  451. family: '"Helvetica Neue", Helvetica, Arial, sans-serif',
  452. },
  453. },
  454. show: true,
  455. },
  456. },
  457. };
  458. elem.append(plotCanvas);
  459. var plotSeries = {
  460. data: [[0, data.valueRounded]],
  461. };
  462. $.plot(plotCanvas, [plotSeries], options);
  463. }
  464. function addSparkline() {
  465. var width = elem.width() + 20;
  466. if (width < 30) {
  467. // element has not gotten it's width yet
  468. // delay sparkline render
  469. setTimeout(addSparkline, 30);
  470. return;
  471. }
  472. var height = ctrl.height;
  473. var plotCanvas = $('<div></div>');
  474. var plotCss: any = {};
  475. plotCss.position = 'absolute';
  476. if (panel.sparkline.full) {
  477. plotCss.bottom = '5px';
  478. plotCss.left = '-5px';
  479. plotCss.width = width - 10 + 'px';
  480. var dynamicHeightMargin = height <= 100 ? 5 : Math.round(height / 100) * 15 + 5;
  481. plotCss.height = height - dynamicHeightMargin + 'px';
  482. } else {
  483. plotCss.bottom = '0px';
  484. plotCss.left = '-5px';
  485. plotCss.width = width - 10 + 'px';
  486. plotCss.height = Math.floor(height * 0.25) + 'px';
  487. }
  488. plotCanvas.css(plotCss);
  489. var options = {
  490. legend: { show: false },
  491. series: {
  492. lines: {
  493. show: true,
  494. fill: 1,
  495. lineWidth: 1,
  496. fillColor: panel.sparkline.fillColor,
  497. },
  498. },
  499. yaxes: { show: false },
  500. xaxis: {
  501. show: false,
  502. mode: 'time',
  503. min: ctrl.range.from.valueOf(),
  504. max: ctrl.range.to.valueOf(),
  505. },
  506. grid: { hoverable: false, show: false },
  507. };
  508. elem.append(plotCanvas);
  509. var plotSeries = {
  510. data: data.flotpairs,
  511. color: panel.sparkline.lineColor,
  512. };
  513. $.plot(plotCanvas, [plotSeries], options);
  514. }
  515. function render() {
  516. if (!ctrl.data) {
  517. return;
  518. }
  519. data = ctrl.data;
  520. // get thresholds
  521. data.thresholds = panel.thresholds.split(',').map(function(strVale) {
  522. return Number(strVale.trim());
  523. });
  524. data.colorMap = panel.colors;
  525. var body = panel.gauge.show ? '' : getBigValueHtml();
  526. if (panel.colorBackground) {
  527. var color = getColorForValue(data, data.value);
  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. }
  536. } else {
  537. $panelContainer.css('background-color', '');
  538. elem.css('background-color', '');
  539. }
  540. elem.html(body);
  541. if (panel.sparkline.show) {
  542. addSparkline();
  543. }
  544. if (panel.gauge.show) {
  545. addGauge();
  546. }
  547. elem.toggleClass('pointer', panel.links.length > 0);
  548. if (panel.links.length > 0) {
  549. linkInfo = linkSrv.getPanelLinkAnchorInfo(panel.links[0], data.scopedVars);
  550. } else {
  551. linkInfo = null;
  552. }
  553. }
  554. function hookupDrilldownLinkTooltip() {
  555. // drilldown link tooltip
  556. var drilldownTooltip = $('<div id="tooltip" class="">hello</div>"');
  557. elem.mouseleave(function() {
  558. if (panel.links.length === 0) {
  559. return;
  560. }
  561. $timeout(function() {
  562. drilldownTooltip.detach();
  563. });
  564. });
  565. elem.click(function(evt) {
  566. if (!linkInfo) {
  567. return;
  568. }
  569. // ignore title clicks in title
  570. if ($(evt).parents('.panel-header').length > 0) {
  571. return;
  572. }
  573. if (linkInfo.target === '_blank') {
  574. window.open(linkInfo.href, '_blank');
  575. return;
  576. }
  577. if (linkInfo.href.indexOf('http') === 0) {
  578. window.location.href = linkInfo.href;
  579. } else {
  580. $timeout(function() {
  581. $location.url(linkInfo.href);
  582. });
  583. }
  584. drilldownTooltip.detach();
  585. });
  586. elem.mousemove(function(e) {
  587. if (!linkInfo) {
  588. return;
  589. }
  590. drilldownTooltip.text('click to go to: ' + linkInfo.title);
  591. drilldownTooltip.place_tt(e.pageX, e.pageY - 50);
  592. });
  593. }
  594. hookupDrilldownLinkTooltip();
  595. this.events.on('render', function() {
  596. render();
  597. ctrl.renderingCompleted();
  598. });
  599. }
  600. }
  601. function getColorForValue(data, value) {
  602. if (!_.isFinite(value)) {
  603. return null;
  604. }
  605. for (var i = data.thresholds.length; i > 0; i--) {
  606. if (value >= data.thresholds[i - 1]) {
  607. return data.colorMap[i];
  608. }
  609. }
  610. return _.first(data.colorMap);
  611. }
  612. export { SingleStatCtrl, SingleStatCtrl as PanelCtrl, getColorForValue };