Skip to content

Commit

Permalink
Transit Viewer Dashboard - Custom Route Types (#3507)
Browse files Browse the repository at this point in the history
* update yaml structure for transit viewer

* added custom route types to transit viewer

* added test

---------

Co-authored-by: rakow <[email protected]>
  • Loading branch information
frievoe97 and rakow authored Oct 9, 2024
1 parent 1957734 commit 5f085ef
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransitViewer.CustomRouteType> 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) {

Expand All @@ -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;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

/**
* Transit viewer for pt schedules.
*/
Expand All @@ -13,7 +15,55 @@ public class TransitViewer extends Viz {
@JsonProperty(required = true)
public String transitSchedule;

public List<CustomRouteType> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 5f085ef

Please sign in to comment.