From 17d19cacffdbfa60ca2fc828b968d62e3779e037 Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Mon, 4 Jan 2021 13:25:05 -0500 Subject: [PATCH] Fix up zero-score issues (#468) * return score of 100 when no checks specified * fix up zero states in frontend * rename variables --- pkg/dashboard/assets/js/charts.js | 15 ++++++++++----- pkg/dashboard/helpers.go | 4 ++-- pkg/dashboard/templates/dashboard.gohtml | 18 +++++++++++++++--- pkg/validator/summary.go | 4 ++-- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/pkg/dashboard/assets/js/charts.js b/pkg/dashboard/assets/js/charts.js index 49532fd4..34333426 100644 --- a/pkg/dashboard/assets/js/charts.js +++ b/pkg/dashboard/assets/js/charts.js @@ -1,14 +1,19 @@ $(function () { + var data = [ + polarisSummary.Successes, + polarisSummary.Warnings, + polarisSummary.Dangers, + ]; + var sum = data.reduce(function(total, cur) { return total + cur }, 0.0) + if (sum === 0.0) { + data = [1, 0, 0]; + } var clusterChart = new Chart("clusterScoreChart", { type: 'doughnut', data: { labels: ["Passing", "Warning", "Error"], datasets: [{ - data: [ - polarisSummary.Successes, - polarisSummary.Warnings, - polarisSummary.Dangers, - ], + data: data, backgroundColor: ['#8BD2DC', '#f26c21', '#a11f4c'], }] }, diff --git a/pkg/dashboard/helpers.go b/pkg/dashboard/helpers.go index 84779010..f5db055d 100644 --- a/pkg/dashboard/helpers.go +++ b/pkg/dashboard/helpers.go @@ -25,7 +25,7 @@ import ( func getWarningWidth(counts validator.CountSummary, fullWidth int) uint { denom := counts.Successes + counts.Warnings + counts.Dangers if denom == 0 { - return uint(0) + return uint(1 * float64(fullWidth)) } res := float64(counts.Successes+counts.Warnings) / float64(denom) * float64(fullWidth) return uint(res) @@ -34,7 +34,7 @@ func getWarningWidth(counts validator.CountSummary, fullWidth int) uint { func getSuccessWidth(counts validator.CountSummary, fullWidth int) uint { denom := counts.Successes + counts.Warnings + counts.Dangers if denom == 0 { - return uint(0) + return uint(1 * float64(fullWidth)) } res := float64(counts.Successes) / float64(denom) * float64(fullWidth) return uint(res) diff --git a/pkg/dashboard/templates/dashboard.gohtml b/pkg/dashboard/templates/dashboard.gohtml index a5eea79b..83963d8e 100644 --- a/pkg/dashboard/templates/dashboard.gohtml +++ b/pkg/dashboard/templates/dashboard.gohtml @@ -153,7 +153,11 @@ {{ .Name }}
-

Controller Spec:

+

Controller Spec: + {{ if eq 0 (len .Results.GetSortedResults) }} + no checks applied + {{ end }} +

-

Pod Spec:

+

Pod Spec: + {{ if eq 0 (len .PodResult.Results.GetSortedResults) }} + no checks applied + {{ end }} +