From 11e9d7781f16fcee48970ba4ec6485a786263307 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 9 Dec 2019 13:42:28 -0800 Subject: [PATCH] adjust the histogram, hide some text stats now --- game/src/common/plot.rs | 42 ++++++++++++++----- game/src/sandbox/gameplay/faster_trips.rs | 28 +++++++++++++ .../sandbox/gameplay/fix_traffic_signals.rs | 4 +- game/src/sandbox/overlays.rs | 1 - 4 files changed, 61 insertions(+), 14 deletions(-) diff --git a/game/src/common/plot.rs b/game/src/common/plot.rs index 4a36923eeb..c7c75cffcd 100644 --- a/game/src/common/plot.rs +++ b/game/src/common/plot.rs @@ -204,14 +204,14 @@ pub struct Histogram { } impl Histogram { - pub fn new(title: &str, unsorted_dts: Vec, ctx: &EventCtx) -> Histogram { + pub fn new(unsorted_dts: Vec, 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 { diff --git a/game/src/sandbox/gameplay/faster_trips.rs b/game/src/sandbox/gameplay/faster_trips.rs index 0ea276873d..27800cc77b 100644 --- a/game/src/sandbox/gameplay/faster_trips.rs +++ b/game/src/sandbox/gameplay/faster_trips.rs @@ -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 +} diff --git a/game/src/sandbox/gameplay/fix_traffic_signals.rs b/game/src/sandbox/gameplay/fix_traffic_signals.rs index 1594ca2bc6..8d553014c0 100644 --- a/game/src/sandbox/gameplay/fix_traffic_signals.rs +++ b/game/src/sandbox/gameplay/fix_traffic_signals.rs @@ -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") { diff --git a/game/src/sandbox/overlays.rs b/game/src/sandbox/overlays.rs index 7a2b8fe316..021ffee11e 100644 --- a/game/src/sandbox/overlays.rs +++ b/game/src/sandbox/overlays.rs @@ -582,7 +582,6 @@ impl Overlays { Overlays::FinishedTripsHistogram( now, Histogram::new( - "Finished trip time deltas", ui.primary .sim .get_analytics()