stackedProgressBars component improvements to handle bad inputs

This commit is contained in:
Alfredo Cardigliano 2018-12-12 18:36:16 +01:00
parent 8f6d29d7bc
commit 5c2f560b84

View file

@ -161,6 +161,12 @@ function stackedProgressBars(total, bars, other_label, formatter)
-- The bars
res[#res + 1] = [[<div class="progress">]]
local sum = 0
for _, bar in ipairs(bars) do
sum = sum + bar.value
end
if total > sum then total = sum end
for _, bar in ipairs(bars) do
local percentage = round(bar.value * 100 / total, 2)
cumulative = cumulative + bar.value