Add tooltips to the agent meters, and stop showing both buses and passengers. Fixes #239 (#323)

This commit is contained in:
Dustin Carlino 2020-09-11 11:08:26 -07:00 committed by GitHub
parent edbc674970
commit 2895d50a1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 29 deletions

View File

@ -1,3 +0,0 @@
<svg width="22" height="27" viewBox="0 0 22 27" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.9891 22.2227C17.2687 22.2227 17.2687 18.8105 15.9891 18.8105H7.58031C6.60538 18.8105 6.23978 18.0793 6.05698 17.2262L2.64473 5.89265C2.34006 4.61306 -0.280063 5.16146 0.0246025 6.44105L3.43686 19.2979C3.86339 21.0041 5.69139 22.2837 7.51938 22.2837H15.9891V22.2227ZM9.89577 15.0936L10.0176 15.642H15.3798C16.1719 15.642 16.8422 15.1545 17.0859 14.4842H18.3655C19.1576 14.4842 19.8279 15.0936 19.8888 15.8248L21.8996 24.721C22.3261 26.3662 19.2795 26.9755 18.8529 25.3913L17.2687 18.1402C17.2687 17.9574 17.1468 17.8965 17.025 17.8965H9.28644C8.06778 17.8965 6.97098 17.2872 6.60538 16.0076L4.77739 9.67051C4.35086 8.32998 5.14299 6.86759 6.54445 6.44105C7.76311 6.07545 9.28644 6.50199 9.65204 7.84252L10.9316 12.2297C10.9926 12.4125 11.1144 12.4734 11.2972 12.4734H15.4407C16.1719 12.4734 16.7203 13.0828 16.7203 13.753C16.7203 14.4842 16.111 15.0326 15.4407 15.0326H10.0176C10.0176 15.0936 9.95671 15.0936 9.89577 15.0936ZM6.54445 0.104004C4.96019 0.104004 3.68059 1.3836 3.68059 2.96786C3.68059 4.55212 4.96019 5.83172 6.54445 5.83172C8.12871 5.83172 9.40831 4.55212 9.40831 2.96786C9.40831 1.3836 8.12871 0.104004 6.54445 0.104004Z" fill="#F2F2F2"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -303,32 +303,49 @@ impl AgentMeter {
let (finished, unfinished) = app.primary.sim.num_trips();
let by_type = app.primary.sim.num_agents();
let mut row = Vec::new();
for (agent_type, name) in vec![
(AgentType::Pedestrian, "pedestrian"),
(AgentType::Bike, "bike"),
(AgentType::Car, "car"),
] {
let n = prettyprint_usize(by_type.get(agent_type));
row.push(Widget::custom_row(vec![
Widget::draw_svg_with_tooltip(
ctx,
format!("system/assets/meters/{}.svg", name),
Text::from(Line(format!("{} {}", n, agent_type.plural_noun()))),
)
.margin_right(5),
n.draw_text(ctx),
]));
}
row.push(Widget::custom_row(vec![
Widget::draw_svg_with_tooltip(
ctx,
"system/assets/meters/bus.svg",
Text::from_multiline(vec![
Line(format!(
"{} public transit passengers",
prettyprint_usize(by_type.get(AgentType::TransitRider))
)),
Line(format!(
"{} buses",
prettyprint_usize(by_type.get(AgentType::Bus))
)),
Line(format!(
"{} trains",
prettyprint_usize(by_type.get(AgentType::Train))
)),
]),
)
.margin_right(5),
prettyprint_usize(by_type.get(AgentType::TransitRider)).draw_text(ctx),
]));
let rows = vec![
"Active trips".draw_text(ctx),
Widget::custom_row(vec![
Widget::custom_row(vec![
Widget::draw_svg(ctx, "system/assets/meters/pedestrian.svg").margin_right(5),
prettyprint_usize(by_type.get(AgentType::Pedestrian)).draw_text(ctx),
]),
Widget::custom_row(vec![
Widget::draw_svg(ctx, "system/assets/meters/bike.svg").margin_right(5),
prettyprint_usize(by_type.get(AgentType::Bike)).draw_text(ctx),
]),
Widget::custom_row(vec![
Widget::draw_svg(ctx, "system/assets/meters/car.svg").margin_right(5),
prettyprint_usize(by_type.get(AgentType::Car)).draw_text(ctx),
]),
Widget::custom_row(vec![
Widget::draw_svg(ctx, "system/assets/meters/bus.svg").margin_right(5),
prettyprint_usize(by_type.get(AgentType::Bus) + by_type.get(AgentType::Train))
.draw_text(ctx),
]),
Widget::custom_row(vec![
Widget::draw_svg(ctx, "system/assets/meters/passenger.svg").margin_right(5),
prettyprint_usize(by_type.get(AgentType::TransitRider)).draw_text(ctx),
]),
])
.centered(),
Widget::custom_row(row).centered(),
Widget::horiz_separator(ctx, 0.2),
Widget::row(vec![
{

View File

@ -176,6 +176,17 @@ impl AgentType {
}
}
pub fn plural_noun(self) -> &'static str {
match self {
AgentType::Car => "cars",
AgentType::Bike => "bikes",
AgentType::Bus => "buses",
AgentType::Train => "trains",
AgentType::Pedestrian => "pedestrians",
AgentType::TransitRider => "transit riders",
}
}
pub fn ongoing_verb(self) -> &'static str {
match self {
AgentType::Car => "driving",

View File

@ -19,8 +19,8 @@ pub mod text_box;
use crate::widgets::containers::{Container, Nothing};
pub use crate::widgets::panel::Panel;
use crate::{
Button, Choice, Color, DeferDraw, Drawable, Dropdown, EventCtx, GeomBatch, GfxCtx, JustDraw,
Menu, RewriteColor, ScreenDims, ScreenPt, ScreenRectangle, TextBox,
Button, Choice, Color, DeferDraw, DrawWithTooltips, Drawable, Dropdown, EventCtx, GeomBatch,
GfxCtx, JustDraw, Menu, RewriteColor, ScreenDims, ScreenPt, ScreenRectangle, Text, TextBox,
};
use geom::{Distance, Percent, Polygon};
use std::collections::HashSet;
@ -308,6 +308,22 @@ impl Widget {
pub fn draw_svg_transform(ctx: &EventCtx, filename: &str, rewrite: RewriteColor) -> Widget {
JustDraw::svg_transform(ctx, filename, rewrite)
}
pub fn draw_svg_with_tooltip<I: Into<String>>(
ctx: &EventCtx,
filename: I,
tooltip: Text,
) -> Widget {
let (mut batch, bounds) = crate::svg::load_svg(ctx.prerender, &filename.into());
// Preserve the whitespace in the SVG.
// TODO Maybe always do this, add a way to autocrop() to remove it if needed.
batch.push(Color::INVISIBLE, bounds.get_rectangle());
DrawWithTooltips::new(
ctx,
batch,
vec![(bounds.get_rectangle(), tooltip)],
Box::new(|_| GeomBatch::new()),
)
}
// TODO Likewise
pub fn text_entry(ctx: &EventCtx, prefilled: String, exclusive_focus: bool) -> Widget {