avoid divide by zero

This commit is contained in:
Russ 2019-06-14 00:49:32 -07:00 committed by Florian Dehau
parent 25a0825ae4
commit f0e0b515ad

View File

@ -133,7 +133,7 @@ impl<'a> Widget for BarChart<'a> {
.data
.iter()
.take(max_index)
.map(|&(l, v)| (l, v * u64::from(chart_area.height) * 8 / max))
.map(|&(l, v)| (l, v * u64::from(chart_area.height) * 8 / std::cmp::max(max, 1)))
.collect::<Vec<(&str, u64)>>();
for j in (0..chart_area.height - 1).rev() {
for (i, d) in data.iter_mut().enumerate() {