Fix wrong histogram for special case scale=0

This commit is contained in:
Wuzzy 2022-04-17 00:51:19 +02:00
parent 3e9435f260
commit ae15300c66

View File

@ -731,7 +731,14 @@ local show_histogram_formspec = function(player, stats)
local maxh = 6.0
local boxes = ""
boxes = boxes .. "label[0,7.0;"..F(S("Max.")).."\n"..F(S("Min.")).."]"
for h=1, HISTOGRAM_BUCKETS do
local hstart = 1
-- Special case: If bucket sizes are equal, only show the last bucket
-- (can happen if scale=0)
if HISTOGRAM_BUCKETS > 1 and stats.histogram_points[1] == stats.histogram_points[2] then
hstart = HISTOGRAM_BUCKETS
end
-- Drawn histogram bars, tooltips and labels
for h=hstart, HISTOGRAM_BUCKETS do
local count = stats.histogram[h]
local ratio = (stats.histogram[h] / stats.value_count)
local perc = ratio * 100