starting a plugin to visualize a scenario, by just displaying

neighborhood polygons
This commit is contained in:
Dustin Carlino 2019-04-03 14:39:09 +09:00
parent d0a3b5c383
commit 35d6995a7b
4 changed files with 59 additions and 3 deletions

View File

@ -2,3 +2,16 @@
- https://data.seattle.gov/Transportation/2016-Traffic-Flow-Counts/f22b-ywut
- counts per aterial
## Depicting
Axes:
- time
- source/destination neighborhood or border
- mode choice
- number of trips
Fix a time, then show a bunch of directed arrows between neighborhood polygons.
Line thickness relative to number of trips. Color coding... if you're
interested in a particular neighborhood, vary all the line colors based on
src/dst.

View File

@ -4,7 +4,7 @@ use crate::plugins::{
input_weighted_usize, load_scenario, BlockingPlugin, PluginCtx,
};
use abstutil::Timer;
use ezgui::{GfxCtx, LogScroller, Wizard, WrappedWizard};
use ezgui::{Color, Drawable, GfxCtx, LogScroller, Wizard, WrappedWizard};
use map_model::{Map, Neighborhood};
use sim::{BorderSpawnOverTime, Scenario, SeedParkedCars, SpawnOverTime};
@ -12,6 +12,7 @@ pub enum ScenarioManager {
PickScenario(Wizard),
ManageScenario(Scenario, LogScroller),
EditScenario(Scenario, Wizard),
VisualizeScenario(Scenario, Drawable),
}
impl ScenarioManager {
@ -54,6 +55,19 @@ impl BlockingPlugin for ScenarioManager {
&mut Timer::new("instantiate scenario"),
);
return false;
} else if ctx.input.modal_action("visualize") {
let neighborhoods = Neighborhood::load_all(
ctx.primary.map.get_name(),
&ctx.primary.map.get_gps_bounds(),
);
let draw_all = ctx.prerender.upload(
neighborhoods
.into_iter()
.enumerate()
.map(|(idx, (_, n))| (COLORS[idx % COLORS.len()], n.polygon))
.collect::<Vec<_>>(),
);
*self = ScenarioManager::VisualizeScenario(scenario.clone(), draw_all);
} else if scroller.event(&mut ctx.input) {
return false;
}
@ -72,6 +86,16 @@ impl BlockingPlugin for ScenarioManager {
*self = ScenarioManager::ManageScenario(scenario.clone(), scroller);
}
}
ScenarioManager::VisualizeScenario(ref scenario, _) => {
ctx.input.set_mode_with_prompt(
"Scenario Editor",
format!("Scenario Editor for {}", scenario.scenario_name),
&ctx.canvas,
);
if ctx.input.modal_action("quit") {
return false;
}
}
}
true
}
@ -90,6 +114,9 @@ impl BlockingPlugin for ScenarioManager {
}
wizard.draw(g);
}
ScenarioManager::VisualizeScenario(_, ref draw_all) => {
g.redraw(draw_all);
}
}
}
}
@ -176,3 +203,10 @@ fn edit_scenario(map: &Map, scenario: &mut Scenario, mut wizard: WrappedWizard)
};
Some(())
}
const COLORS: [Color; 3] = [
// TODO these are awful choices
Color::RED.alpha(0.8),
Color::GREEN.alpha(0.8),
Color::BLUE.alpha(0.8),
];

View File

@ -107,7 +107,13 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
),
ModalMenu::new(
"Scenario Editor",
vec![(Key::S, "save"), (Key::E, "edit"), (Key::I, "instantiate")],
vec![
(Key::S, "save"),
(Key::E, "edit"),
(Key::I, "instantiate"),
(Key::V, "visualize"),
(Key::Enter, "quit"),
],
),
ModalMenu::new("Road Editor", vec![(Key::Enter, "quit")]),
ModalMenu::new(

View File

@ -123,6 +123,7 @@ pub enum Key {
Dot,
Comma,
Semicolon,
Colon,
Equals,
// Stuff without a straightforward single-character display
Escape,
@ -197,7 +198,8 @@ impl Key {
Key::Slash => Some(if shift_pressed { '?' } else { '/' }),
Key::Dot => Some(if shift_pressed { '>' } else { '.' }),
Key::Comma => Some(if shift_pressed { '<' } else { ',' }),
Key::Semicolon => Some(if shift_pressed { ':' } else { ';' }),
Key::Semicolon => Some(';'),
Key::Colon => Some(':'),
Key::Equals => Some(if shift_pressed { '+' } else { '=' }),
Key::Escape
| Key::Enter
@ -306,6 +308,7 @@ impl Key {
glutin::VirtualKeyCode::Period => Key::Dot,
glutin::VirtualKeyCode::Comma => Key::Comma,
glutin::VirtualKeyCode::Semicolon => Key::Semicolon,
glutin::VirtualKeyCode::Colon => Key::Colon,
glutin::VirtualKeyCode::Equals => Key::Equals,
glutin::VirtualKeyCode::Escape => Key::Escape,
glutin::VirtualKeyCode::Return => Key::Enter,