Handle sparse results

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

View File

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