module.ts 20 KB

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