mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-26 07:52:05 +03:00
return Duration not mins
This commit is contained in:
parent
a1a97877a5
commit
78a840edfa
@ -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<usize>) {
|
||||
/// Returns (rounded max, the boundaries)
|
||||
pub fn make_intervals_for_max(self, num_labels: usize) -> (Duration, Vec<Duration>) {
|
||||
// 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!(
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user