From 9c11dc478781e216098b1d42e217839f391353af Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Fri, 17 Apr 2020 10:39:36 -0700 Subject: [PATCH] try heatmap for commute viz --- game/src/devtools/blocks.rs | 53 ++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/game/src/devtools/blocks.rs b/game/src/devtools/blocks.rs index cca7fc8d53..9decd2ffa1 100644 --- a/game/src/devtools/blocks.rs +++ b/game/src/devtools/blocks.rs @@ -25,7 +25,6 @@ struct Block { id: usize, bldgs: HashSet, shape: Polygon, - proper: bool, } impl BlockMap { @@ -57,21 +56,12 @@ impl BlockMap { id: block_id, bldgs, shape: Polygon::convex_hull(polygons), - proper, }); } let mut all_blocks = GeomBatch::new(); for block in &blocks { - all_blocks.push( - if block.proper { - Color::YELLOW - } else { - Color::ORANGE - } - .alpha(0.5), - block.shape.clone(), - ); + all_blocks.push(Color::YELLOW.alpha(0.5), block.shape.clone()); } BlockMap { @@ -83,12 +73,16 @@ impl BlockMap { composite: Composite::new( Widget::col(vec![ Widget::row(vec![ - Line("Commute map by block").small_heading().draw(ctx), + Line("Commute map by block") + .small_heading() + .draw(ctx) + .margin_right(10), Btn::text_fg("X") .build_def(ctx, hotkey(Key::Escape)) .align_right(), ]), - Checkbox::text(ctx, "trips from this block", hotkey(Key::Space), true), + Checkbox::text(ctx, "from / to this block", hotkey(Key::Space), true), + Checkbox::text(ctx, "arrows / heatmap", hotkey(Key::H), true), ]) .padding(10) .bg(app.cs.panel_bg), @@ -146,6 +140,7 @@ impl State for BlockMap { fn draw(&self, g: &mut GfxCtx, app: &App) { g.redraw(&self.draw_all_blocks); + self.composite.draw(g); // TODO Expensive! if let Some(pt) = g.get_cursor_in_map_space() { @@ -156,32 +151,36 @@ impl State for BlockMap { batch.push(Color::PURPLE, app.primary.map.get_b(*b).polygon.clone()); } - let from = self.composite.is_checked("trips from this block"); + let from = self.composite.is_checked("from / to this block"); + let arrows = self.composite.is_checked("arrows / heatmap"); let others = self.count_per_block(block, from); if !others.is_empty() { let max_cnt = others.iter().map(|(_, cnt)| *cnt).max().unwrap() as f64; for (other, cnt) in others { - batch.push( - Color::hex("#A32015").alpha(0.7), - PolyLine::new(if from { - vec![block.shape.center(), other.shape.center()] - } else { - vec![other.shape.center(), block.shape.center()] - }) - .make_arrow(Distance::meters(15.0) * (cnt as f64) / max_cnt) - .unwrap(), - ); + let pct = (cnt as f64) / max_cnt; + if arrows { + batch.push( + Color::hex("#A32015").alpha(0.7), + PolyLine::new(if from { + vec![block.shape.center(), other.shape.center()] + } else { + vec![other.shape.center(), block.shape.center()] + }) + .make_arrow(Distance::meters(15.0) * pct) + .unwrap(), + ); + } else { + batch.push(Color::RED.alpha(pct as f32), other.shape.clone()); + } } } let draw = g.upload(batch); g.redraw(&draw); - break; + return; } } } - - self.composite.draw(g); } }