diff --git a/CHANGELOG.md b/CHANGELOG.md index 42da121..9bae3ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,5 @@ # Changelog -## 1.0.8 (2024-01-23) - -* Show percentage value if base value (ie. from previous time range) is not available. - ## 1.0.7 (2022-11-06) * Fixed prefix in case of negative percentage trend diff --git a/package.json b/package.json index 91bca62..1b8b1b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "grafana-percent-trend-panel", - "version": "1.0.8", + "version": "1.0.7", "description": "Grafana percent trend panel", "scripts": { "build": "grafana-toolkit plugin:build", diff --git a/src/PercentPanel.tsx b/src/PercentPanel.tsx index 95bb30d..58d305b 100644 --- a/src/PercentPanel.tsx +++ b/src/PercentPanel.tsx @@ -107,22 +107,22 @@ export const PercentPanel: React.FC = ({ options, data, width, height }) serie.fields.find((field) => field.name === options.baseValueField) ); - if (!percentageValueSerie) { + if (!percentageValueSerie || !baseValueSerie) { return

Selected series are not available

; } const percentageValueField = percentageValueSerie.fields.find((field) => field.name === options.percentageValueField); - const baseValueField = baseValueSerie?.fields.find((field) => field.name === options.baseValueField); + const baseValueField = baseValueSerie.fields.find((field) => field.name === options.baseValueField); - if (!percentageValueField) { + if (!percentageValueField || !baseValueField) { return

Selected fields are not available

; } - if (percentageValueField.values.length === 0) { + if (percentageValueField.values.length === 0 || baseValueField.values.length === 0) { return

Selected fields are empty

; } const percentageValueSum = percentageValueField.values.toArray().reduce((sum, current) => sum + current, 0); - const baseValueSum = baseValueField ? baseValueField.values.toArray().reduce((sum, current) => sum + current, 0) : 0; + const baseValueSum = baseValueField.values.toArray().reduce((sum, current) => sum + current, 0); const display = prepareTrendDisplay(options, theme.visualization, baseValueSum, percentageValueSum);