Handle sparse results

This commit is contained in:
Roberto Alsina 2023-06-04 19:34:45 -03:00
parent 6a357fe776
commit 52007a4b5b

View File

@ -101,10 +101,13 @@ class Handler
x = (1922..2015).to_a
y = x.map { |_| 0 }
else # We got results
displayed = true
values = Hash(Int32, Int32).new(default_value: 0)
results.map { |r|
x << r[0].as_i
y << r[1].as_i
values[r[0].as_i] = r[1].as_i
}
(1922..2015).map { |year|
x << year
y << values[year] # Defaults to 0, so we have the whole set
}
end
plot(x, y, title: nombre.titleize, style: :lines, linewidth: 3)