Skip to content

Commit

Permalink
Merge pull request #132 from opentripplanner/dev
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
landonreed authored Feb 18, 2020
2 parents a16abb4 + 381c3f5 commit 7c175ee
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 29 deletions.
4 changes: 2 additions & 2 deletions __tests__/util/__mocks__/itinerary.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
},
"route3": {
"longName": "Around another town",
"mode": "BUS",
"shortName": "3",
"sortOrder": -999
"sortOrder": -999,
"type": 3
},
"route4": {
"longName": "Loop route",
Expand Down
6 changes: 3 additions & 3 deletions __tests__/util/__snapshots__/itinerary.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ Array [
},
Object {
"longName": "Around another town",
"mode": "BUS",
"shortName": "3",
"sortOrder": -999,
"type": 3,
},
]
`;
Expand Down Expand Up @@ -77,9 +77,9 @@ Array [
},
Object {
"longName": "Around another town",
"mode": "BUS",
"shortName": "3",
"sortOrder": -999,
"type": 3,
},
]
`;
Expand Down Expand Up @@ -217,9 +217,9 @@ Array [
},
Object {
"longName": "Around another town",
"mode": "BUS",
"shortName": "3",
"sortOrder": -999,
"type": 3,
},
Object {
"longName": "A meandering route",
Expand Down
4 changes: 2 additions & 2 deletions lib/components/viewers/route-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class RouteViewer extends Component {
<RouteRow
findRoute={findRoute}
isActive={viewedRoute && viewedRoute.routeId === route.id}
key={route.id
/* operator={operator */}
key={route.id}
// operator={operator}
route={route}
setViewedRoute={setViewedRoute}
/>
Expand Down
70 changes: 48 additions & 22 deletions lib/util/itinerary.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,29 +262,55 @@ function getSortValues (getterFn, a, b) {
return { aVal, bVal }
}

/**
* Gets a comparator value for a given route's type (OTP mode).
*/
// Lookup for the sort values associated with various OTP modes.
// Note: JSDoc format not used to avoid bug in documentationjs.
// https://github.com/documentationjs/documentation/issues/372
const modeComparatorValue = {
SUBWAY: 1,
TRAM: 2,
RAIL: 3,
GONDOLA: 4,
FERRY: 5,
CABLE_CAR: 6,
FUNICULAR: 7,
BUS: 8
}

// Lookup that maps route types to the OTP mode sort values.
// Note: JSDoc format not used to avoid bug in documentationjs.
// https://github.com/documentationjs/documentation/issues/372
const routeTypeComparatorValue = {
0: modeComparatorValue.TRAM, // - Tram, Streetcar, Light rail.
1: modeComparatorValue.SUBWAY, // - Subway, Metro.
2: modeComparatorValue.RAIL, // - Rail. Used for intercity or long-distance travel.
3: modeComparatorValue.BUS, // - Bus.
4: modeComparatorValue.FERRY, // - Ferry.
5: modeComparatorValue.CABLE_CAR, // - Cable tram.
6: modeComparatorValue.GONDOLA, // - Gondola, etc.
7: modeComparatorValue.FUNICULAR, // - Funicular.
// TODO: 11 and 12 are not a part of OTP as of 2019-02-14, but for now just
// associate them with bus/rail.
11: modeComparatorValue.BUS, // - Trolleybus.
12: modeComparatorValue.RAIL // - Monorail.
}

// Gets a comparator value for a given route's type (OTP mode).
// Note: JSDoc format not used to avoid bug in documentationjs.
// ttps://github.com/documentationjs/documentation/issues/372
function getRouteTypeComparatorValue (route) {
switch (route.mode) {
case 'SUBWAY':
return 1
case 'TRAM':
return 2
case 'RAIL':
return 3
case 'GONDOLA':
return 4
case 'FERRY':
return 5
case 'CABLE_CAR':
return 6
case 'FUNICULAR':
return 7
case 'BUS':
return 8
default:
return 9999
// For some strange reason, the short route response in OTP returns the
// string-based modes, but the long route response returns the
// integer route type. This attempts to account for both of those cases.
if (!route) throw new Error('Route is undefined.', route)
if (typeof modeComparatorValue[route.mode] !== 'undefined') {
return modeComparatorValue[route.mode]
} else if (typeof routeTypeComparatorValue[route.type] !== 'undefined') {
return routeTypeComparatorValue[route.type]
} else {
// Default the comparator value to a large number (placing the route at the
// end of the list).
console.warn('no mode/route type found for route', route)
return 9999
}
}

Expand Down

0 comments on commit 7c175ee

Please sign in to comment.