diff --git a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/PublicTransitDashboard.java b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/PublicTransitDashboard.java index 6903902d098..b40db6b8b05 100644 --- a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/PublicTransitDashboard.java +++ b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/PublicTransitDashboard.java @@ -5,11 +5,24 @@ import org.matsim.simwrapper.Layout; import org.matsim.simwrapper.viz.TransitViewer; +import java.util.ArrayList; +import java.util.List; + /** * Standard dashboard for public transit. */ public class PublicTransitDashboard implements Dashboard { + private List customRouteTypes = new ArrayList<>(); + + /** + * Add custom route types to the transit viewer. + */ + public PublicTransitDashboard withCustomRouteTypes(TransitViewer.CustomRouteType... custom) { + customRouteTypes.addAll(List.of(custom)); + return this; + } + @Override public void configure(Header header, Layout layout) { @@ -23,6 +36,9 @@ public void configure(Header header, Layout layout) { viz.description = "Visualize the transit schedule."; viz.network = "*output_network.xml.gz"; viz.transitSchedule = data.output("*output_transitSchedule.xml.gz"); + + if (!customRouteTypes.isEmpty()) + viz.customRouteTypes = customRouteTypes; }); } } diff --git a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/viz/TransitViewer.java b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/viz/TransitViewer.java index ff9e8176b60..4f6622d2b11 100644 --- a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/viz/TransitViewer.java +++ b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/viz/TransitViewer.java @@ -2,6 +2,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; + /** * Transit viewer for pt schedules. */ @@ -13,7 +15,55 @@ public class TransitViewer extends Viz { @JsonProperty(required = true) public String transitSchedule; + public List customRouteTypes; + public TransitViewer() { super("transit"); } + + public CustomRouteType addCustomRouteType(String label, String color, boolean hide) { + CustomRouteType crt = new CustomRouteType(); + crt.label = label; + crt.color = color; + crt.hide = hide; + customRouteTypes.add(crt); + return crt; + } + + public static class CustomRouteType { + public String label; + public String color; + public Boolean hide; + Match match; + + public CustomRouteType addMatchTransportMode(String... transportMode) { + if (match == null) + match = new Match(); + + match.transportMode = transportMode; + return this; + } + + public CustomRouteType addMatchId(String... id) { + if (match == null) + match = new Match(); + + match.id = id; + return this; + } + + public CustomRouteType addMatchGtfsRouteType(Integer... gtfsRouteType) { + if (match == null) + match = new Match(); + + match.gtfsRouteType = gtfsRouteType; + return this; + } + } + + private static class Match { + Object transportMode; + Object id; + Object gtfsRouteType; + } } diff --git a/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/DashboardTests.java b/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/DashboardTests.java index baf1b5b2b8d..dca4a209df1 100644 --- a/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/DashboardTests.java +++ b/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/DashboardTests.java @@ -13,6 +13,7 @@ import org.matsim.simwrapper.SimWrapper; import org.matsim.simwrapper.SimWrapperConfigGroup; import org.matsim.simwrapper.TestScenario; +import org.matsim.simwrapper.viz.TransitViewer; import org.matsim.testcases.MatsimTestUtils; import tech.tablesaw.api.Table; import tech.tablesaw.io.csv.CsvReadOptions; @@ -157,4 +158,24 @@ void odTrips() { } + @Test + void ptCustom() { + PublicTransitDashboard pt = new PublicTransitDashboard(); + + // bus + TransitViewer.CustomRouteType crt = new TransitViewer.CustomRouteType(); + crt.label = "Bus"; + crt.color = "#109192"; + crt.addMatchGtfsRouteType(3); + + // rail + TransitViewer.CustomRouteType crtRail = new TransitViewer.CustomRouteType(); + crtRail.label = "Rail"; + crtRail.color = "#EC0016"; + crtRail.addMatchGtfsRouteType(2); + + pt.withCustomRouteTypes(crt, crtRail); + + run(pt); + } }