Skip to content

Commit

Permalink
Revert "Merge pull request #33 from merlinj1/feature/allow_empty_base…
Browse files Browse the repository at this point in the history
…_values"

This reverts commit 7f8a801, reversing
changes made to 3aae493.
  • Loading branch information
nikos committed Jan 25, 2024
1 parent 6045868 commit 6b69234
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
4 changes: 0 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 5 additions & 5 deletions src/PercentPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,22 @@ export const PercentPanel: React.FC<Props> = ({ options, data, width, height })
serie.fields.find((field) => field.name === options.baseValueField)
);

if (!percentageValueSerie) {
if (!percentageValueSerie || !baseValueSerie) {
return <p>Selected series are not available</p>;
}

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 <p>Selected fields are not available</p>;
}
if (percentageValueField.values.length === 0) {
if (percentageValueField.values.length === 0 || baseValueField.values.length === 0) {
return <p>Selected fields are empty</p>;
}

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);

Expand Down

0 comments on commit 6b69234

Please sign in to comment.