diff --git a/devenv/dev-dashboards/panel-singlestat/singlestat_test.json b/devenv/dev-dashboards/panel-singlestat/singlestat_test.json index 773c36b1303..424d09308ef 100644 --- a/devenv/dev-dashboards/panel-singlestat/singlestat_test.json +++ b/devenv/dev-dashboards/panel-singlestat/singlestat_test.json @@ -501,6 +501,237 @@ } ], "valueName": "current" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorPrefix": false, + "colorValue": false, + "colors": ["#299c46", "rgba(237, 129, 40, 0.89)", "#d44a3a"], + "datasource": "gdev-testdata", + "decimals": null, + "description": "", + "format": "none", + "gauge": { + "maxValue": 150, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 4, + "w": 8, + "x": 0, + "y": 14 + }, + "id": 8, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "options": {}, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": true, + "lineColor": "rgb(31, 120, 193)", + "show": false + }, + "tableColumn": "Info", + "targets": [ + { + "alias": "", + "expr": "", + "format": "time_series", + "intervalFactor": 1, + "refId": "A", + "scenarioId": "random_walk_table", + "stringInput": "" + } + ], + "thresholds": "81,90", + "title": "TableData 'Info' string Column", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [], + "valueName": "current" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorPrefix": false, + "colorValue": false, + "colors": ["#299c46", "rgba(237, 129, 40, 0.89)", "#d44a3a"], + "datasource": "gdev-testdata", + "decimals": 2, + "description": "", + "format": "celsius", + "gauge": { + "maxValue": 150, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 4, + "w": 8, + "x": 8, + "y": 14 + }, + "id": 9, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "options": {}, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": true, + "lineColor": "rgb(31, 120, 193)", + "show": false + }, + "tableColumn": "Min", + "targets": [ + { + "alias": "", + "expr": "", + "format": "time_series", + "intervalFactor": 1, + "refId": "A", + "scenarioId": "random_walk_table", + "stringInput": "" + } + ], + "thresholds": "81,90", + "title": "TableData 'Value' as temp Column", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [], + "valueName": "current" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorPrefix": false, + "colorValue": false, + "colors": ["#299c46", "rgba(237, 129, 40, 0.89)", "#d44a3a"], + "datasource": "gdev-testdata", + "decimals": null, + "description": "", + "format": "dateTimeFromNow", + "gauge": { + "maxValue": 150, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 4, + "w": 8, + "x": 16, + "y": 14 + }, + "id": 10, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "options": {}, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": true, + "lineColor": "rgb(31, 120, 193)", + "show": false + }, + "tableColumn": "time", + "targets": [ + { + "alias": "", + "expr": "", + "format": "time_series", + "intervalFactor": 1, + "refId": "A", + "scenarioId": "random_walk", + "stringInput": "" + } + ], + "thresholds": "81,90", + "title": "last_time display (a few seconds ago)", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [], + "valueName": "last_time" } ], "refresh": false, diff --git a/packages/grafana-ui/src/components/SingleStatShared/SingleStatBaseOptions.ts b/packages/grafana-ui/src/components/SingleStatShared/SingleStatBaseOptions.ts index ae104fccbf1..87dff8fc9cf 100644 --- a/packages/grafana-ui/src/components/SingleStatShared/SingleStatBaseOptions.ts +++ b/packages/grafana-ui/src/components/SingleStatShared/SingleStatBaseOptions.ts @@ -192,7 +192,7 @@ export function migrateOldThresholds(thresholds?: any[]): Threshold[] | undefine /** * Convert the angular single stat mapping to new react style */ -function convertOldAngulrValueMapping(panel: any): ValueMapping[] { +export function convertOldAngulrValueMapping(panel: any): ValueMapping[] { const mappings: ValueMapping[] = []; // Guess the right type based on options diff --git a/packages/grafana-ui/src/components/SingleStatShared/index.ts b/packages/grafana-ui/src/components/SingleStatShared/index.ts index f6fcffd3fd2..41b23573e22 100644 --- a/packages/grafana-ui/src/components/SingleStatShared/index.ts +++ b/packages/grafana-ui/src/components/SingleStatShared/index.ts @@ -5,4 +5,5 @@ export { SingleStatBaseOptions, sharedSingleStatPanelChangedHandler, sharedSingleStatMigrationHandler, + convertOldAngulrValueMapping, } from './SingleStatBaseOptions'; diff --git a/packages/grafana-ui/src/utils/displayProcessor.ts b/packages/grafana-ui/src/utils/displayProcessor.ts index 78e7298e30f..a9f143835af 100644 --- a/packages/grafana-ui/src/utils/displayProcessor.ts +++ b/packages/grafana-ui/src/utils/displayProcessor.ts @@ -58,6 +58,14 @@ export function getDisplayProcessor(options?: DisplayProcessorOptions): DisplayP if (shouldFormat && !_.isBoolean(value)) { const { decimals, scaledDecimals } = getDecimalsForValue(value, field.decimals); text = formatFunc(numeric, decimals, scaledDecimals, options.isUtc); + + // Check if the formatted text mapped to a different value + if (mappings && mappings.length > 0) { + const mappedValue = getMappedValue(mappings, text); + if (mappedValue) { + text = mappedValue.text; + } + } } if (thresholds && thresholds.length) { color = getColorFromThreshold(numeric, thresholds, theme); diff --git a/public/app/plugins/panel/singlestat/editor.html b/public/app/plugins/panel/singlestat/editor.html index b2f30c80575..269bfafff02 100644 --- a/public/app/plugins/panel/singlestat/editor.html +++ b/public/app/plugins/panel/singlestat/editor.html @@ -40,16 +40,18 @@