diff --git a/geom/src/duration.rs b/geom/src/duration.rs index 5b916f9cbc..406aa42db8 100644 --- a/geom/src/duration.rs +++ b/geom/src/duration.rs @@ -163,8 +163,8 @@ impl Duration { // TODO Do something fancier? http://vis.stanford.edu/papers/tick-labels // TODO Unit test me - /// Returns (rounded max, the boundaries in number of minutes) - pub fn make_intervals_for_max(self, num_labels: usize) -> (Duration, Vec) { + /// Returns (rounded max, the boundaries) + pub fn make_intervals_for_max(self, num_labels: usize) -> (Duration, Vec) { // Example 1: 43 minutes, max 5 labels... raw_mins_per_interval is 8.6 let raw_mins_per_interval = (self.num_minutes_rounded_up() as f64) / (num_labels as f64); // So then this rounded up to 10 minutes @@ -185,7 +185,7 @@ impl Duration { } let max = (num_labels as f64) * Duration::minutes(mins_per_interval); - let labels = (0..=num_labels).map(|i| i * mins_per_interval).collect(); + let labels = (0..=num_labels).map(|i| Duration::minutes(i * mins_per_interval)).collect(); if max < self { panic!( diff --git a/widgetry/src/widgets/compare_times.rs b/widgetry/src/widgets/compare_times.rs index 72183d3e0b..a916b7be5e 100644 --- a/widgetry/src/widgets/compare_times.rs +++ b/widgetry/src/widgets/compare_times.rs @@ -94,7 +94,11 @@ impl CompareTimes { labels .iter() .rev() - .map(|x| Line(x.to_string()).small().into_widget(ctx)) + .map(|x| { + Line(x.num_minutes_rounded_up().to_string()) + .small() + .into_widget(ctx) + }) .collect(), ) .evenly_spaced(); @@ -111,7 +115,11 @@ impl CompareTimes { let x_axis = Widget::custom_row( labels .iter() - .map(|x| Line(x.to_string()).small().into_widget(ctx)) + .map(|x| { + Line(x.num_minutes_rounded_up().to_string()) + .small() + .into_widget(ctx) + }) .collect(), ) .evenly_spaced();