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 }}