adjust the histogram, hide some text stats now

This commit is contained in:
Dustin Carlino 2019-12-09 13:42:28 -08:00
parent 158f09c3a9
commit 11e9d7781f
4 changed files with 61 additions and 14 deletions

View File

@ -204,14 +204,14 @@ pub struct Histogram {
}
impl Histogram {
pub fn new(title: &str, unsorted_dts: Vec<Duration>, ctx: &EventCtx) -> Histogram {
pub fn new(unsorted_dts: Vec<Duration>, ctx: &EventCtx) -> Histogram {
let mut batch = GeomBatch::new();
let mut labels: Vec<(Text, ScreenPt)> = Vec::new();
let x1 = 0.5 * ctx.canvas.window_width;
let x2 = 0.9 * ctx.canvas.window_width;
let y1 = 0.4 * ctx.canvas.window_height;
let y2 = 0.8 * ctx.canvas.window_height;
let x1 = 0.7 * ctx.canvas.window_width;
let x2 = 0.95 * ctx.canvas.window_width;
let y1 = 0.6 * ctx.canvas.window_height;
let y2 = 0.9 * ctx.canvas.window_height;
batch.push(
Color::grey(0.8),
Polygon::rectangle_topleft(
@ -250,10 +250,11 @@ impl Histogram {
let min_y = 0;
let max_y = bars.iter().map(|(_, _, cnt)| *cnt).max().unwrap();
for (idx, (min, _, cnt)) in bars.into_iter().enumerate() {
// TODO Or maybe the average?
let color = if min < Duration::ZERO {
for (idx, (min, max, cnt)) in bars.into_iter().enumerate() {
let color = if max < Duration::ZERO {
Color::RED
} else if min < Duration::ZERO {
Color::YELLOW
} else {
Color::GREEN
};
@ -270,12 +271,31 @@ impl Histogram {
) {
batch.push(color, rect);
}
}
// TODO These can still get really squished. Draw rotated?
let num_x_labels = 3;
for i in 0..num_x_labels {
let percent_x = (i as f64) / ((num_x_labels - 1) as f64);
let dt = min_x + (max_x - min_x) * percent_x;
labels.push((
Text::from(Line(min.to_string())),
ScreenPt::new(x1 + (x2 - x1) * percent_x_left, y2),
Text::from(Line(dt.to_string())),
ScreenPt::new(x1 + percent_x * (x2 - x1), y2),
));
}
let num_y_labels = 5;
for i in 0..num_y_labels {
let percent_y = (i as f64) / ((num_y_labels - 1) as f64);
// TODO Better alignment...
let left_px = 30.0;
labels.push((
Text::from(Line(abstutil::prettyprint_usize(
((max_y as f64) * percent_y) as usize,
))),
ScreenPt::new(x1 - left_px, y2 - percent_y * (y2 - y1)),
));
}
// TODO Print the max_x label
}
Histogram {

View File

@ -98,3 +98,31 @@ pub fn faster_trips_panel(mode: TripMode, ui: &UI, prebaked: &Analytics) -> Text
}
txt
}
pub fn small_faster_trips_panel(mode: TripMode, ui: &UI, prebaked: &Analytics) -> Text {
let time = ui.primary.sim.time();
let now = ui.primary.sim.get_analytics().finished_trips(time, mode);
let baseline = prebaked.finished_trips(time, mode);
let mut txt = Text::new();
txt.add_appended(vec![
Line(format!(
"{} finished {} trips (",
prettyprint_usize(now.count()),
mode
)),
cmp_count_more(now.count(), baseline.count()),
Line(")"),
]);
if now.count() == 0 || baseline.count() == 0 {
return txt;
}
let stat = Statistic::P50;
txt.add(Line(format!("{}: {} ", stat, now.select(stat))));
txt.append_all(cmp_duration_shorter(
now.select(stat),
baseline.select(stat),
));
txt
}

View File

@ -1,5 +1,5 @@
use crate::game::{msg, Transition};
use crate::sandbox::gameplay::faster_trips::faster_trips_panel;
use crate::sandbox::gameplay::faster_trips::small_faster_trips_panel;
use crate::sandbox::gameplay::{manage_overlays, GameplayState};
use crate::sandbox::overlays::Overlays;
use crate::ui::UI;
@ -75,7 +75,7 @@ impl GameplayState for FixTrafficSignals {
if self.time != ui.primary.sim.time() {
self.time = ui.primary.sim.time();
menu.set_info(ctx, faster_trips_panel(TripMode::Drive, ui, prebaked));
menu.set_info(ctx, small_faster_trips_panel(TripMode::Drive, ui, prebaked));
}
if menu.action("help") {

View File

@ -582,7 +582,6 @@ impl Overlays {
Overlays::FinishedTripsHistogram(
now,
Histogram::new(
"Finished trip time deltas",
ui.primary
.sim
.get_analytics()