Avoid divide by 0 on pie chart
Division of f64 by 0 yields NaN.
Special case when total is 0 to not divide.
@@ -7,8 +7,12 @@ use std::f64::consts::PI;
/// Create a pie chart to display used / total as percentages
pub fn pie_chart<T>(used: f64, total: f64, total_color: &str, used_color: &str) -> El<T> {
+ let (percent, radians) = if total == 0.0 {
+ (0.0, 0.0)
+ } else {
let percent = used / total;
- let radians = 2.0 * PI * percent;
+ (percent, 2.0 * PI * percent)
+ };
let end_x = radians.cos();
let end_y = radians.sin();
