1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
pub use commuter::CommuterPatterns;
pub use traffic_signals::TrafficSignalDemand;
pub use trip_table::FinishedTripTable;

use widgetry::{Btn, Choice, EventCtx, Line, Panel, TextExt, Widget};

use crate::app::App;
use crate::app::Transition;

mod commuter;
mod generic_trip_table;
mod misc;
mod parking_overhead;
mod summaries;
mod traffic_signals;
mod trip_table;

// Oh the dashboards melted, but we still had the radio
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum DashTab {
    FinishedTripTable,
    CancelledTripTable,
    UnfinishedTripTable,
    TripSummaries,
    ParkingOverhead,
    ActiveTraffic,
    TransitRoutes,
    CommuterPatterns,
    TrafficSignals,
}

impl DashTab {
    pub fn picker(self, ctx: &EventCtx, app: &App) -> Widget {
        let mut choices = vec![
            Choice::new("Trip Table", DashTab::FinishedTripTable),
            Choice::new("Trip Summaries", DashTab::TripSummaries),
            Choice::new("Parking Overhead", DashTab::ParkingOverhead),
            Choice::new("Active Traffic", DashTab::ActiveTraffic),
            Choice::new("Transit Routes", DashTab::TransitRoutes),
            Choice::new("Commuter Patterns", DashTab::CommuterPatterns),
            Choice::new("Traffic Signal Demand", DashTab::TrafficSignals),
        ];
        if app.has_prebaked().is_none() {
            choices.remove(1);
        }
        Widget::row(vec![
            Widget::draw_svg(ctx, "system/assets/meters/trip_histogram.svg"),
            Line("Data").big_heading_plain().draw(ctx),
            Widget::dropdown(ctx, "tab", self, choices),
            format!("By {}", app.primary.sim.time().ampm_tostring())
                .draw_text(ctx)
                .centered_vert(),
            Btn::close(ctx),
        ])
    }

    pub fn transition(
        self,
        ctx: &mut EventCtx,
        app: &mut App,
        panel: &Panel,
    ) -> Option<Transition> {
        let tab = panel.dropdown_value("tab");
        if tab == self {
            return None;
        }
        // Hold on, a few tabs are "sub-tabs" -- don't change
        if tab == DashTab::FinishedTripTable {
            if self == DashTab::CancelledTripTable || self == DashTab::UnfinishedTripTable {
                return None;
            }
        }

        Some(Transition::Replace(match tab {
            DashTab::FinishedTripTable => FinishedTripTable::new(ctx, app),
            DashTab::TripSummaries => {
                summaries::TripSummaries::new(ctx, app, summaries::Filter::new())
            }
            DashTab::ParkingOverhead => parking_overhead::ParkingOverhead::new(ctx, app),
            DashTab::ActiveTraffic => misc::ActiveTraffic::new(ctx, app),
            DashTab::TransitRoutes => misc::TransitRoutes::new(ctx, app),
            DashTab::CommuterPatterns => CommuterPatterns::new(ctx, app),
            DashTab::TrafficSignals => TrafficSignalDemand::new(ctx, app),
            DashTab::CancelledTripTable | DashTab::UnfinishedTripTable => unreachable!(),
        }))
    }
}