Skip to content

Commit 7c175ee

Browse files
authored
Merge pull request #132 from opentripplanner/dev
New release
2 parents a16abb4 + 381c3f5 commit 7c175ee

File tree

4 files changed

+55
-29
lines changed

4 files changed

+55
-29
lines changed

Diff for: __tests__/util/__mocks__/itinerary.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
},
1414
"route3": {
1515
"longName": "Around another town",
16-
"mode": "BUS",
1716
"shortName": "3",
18-
"sortOrder": -999
17+
"sortOrder": -999,
18+
"type": 3
1919
},
2020
"route4": {
2121
"longName": "Loop route",

Diff for: __tests__/util/__snapshots__/itinerary.js.snap

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ Array [
4343
},
4444
Object {
4545
"longName": "Around another town",
46-
"mode": "BUS",
4746
"shortName": "3",
4847
"sortOrder": -999,
48+
"type": 3,
4949
},
5050
]
5151
`;
@@ -77,9 +77,9 @@ Array [
7777
},
7878
Object {
7979
"longName": "Around another town",
80-
"mode": "BUS",
8180
"shortName": "3",
8281
"sortOrder": -999,
82+
"type": 3,
8383
},
8484
]
8585
`;
@@ -217,9 +217,9 @@ Array [
217217
},
218218
Object {
219219
"longName": "Around another town",
220-
"mode": "BUS",
221220
"shortName": "3",
222221
"sortOrder": -999,
222+
"type": 3,
223223
},
224224
Object {
225225
"longName": "A meandering route",

Diff for: lib/components/viewers/route-viewer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ class RouteViewer extends Component {
9999
<RouteRow
100100
findRoute={findRoute}
101101
isActive={viewedRoute && viewedRoute.routeId === route.id}
102-
key={route.id
103-
/* operator={operator */}
102+
key={route.id}
103+
// operator={operator}
104104
route={route}
105105
setViewedRoute={setViewedRoute}
106106
/>

Diff for: lib/util/itinerary.js

+48-22
Original file line numberDiff line numberDiff line change
@@ -262,29 +262,55 @@ function getSortValues (getterFn, a, b) {
262262
return { aVal, bVal }
263263
}
264264

265-
/**
266-
* Gets a comparator value for a given route's type (OTP mode).
267-
*/
265+
// Lookup for the sort values associated with various OTP modes.
266+
// Note: JSDoc format not used to avoid bug in documentationjs.
267+
// https://github.com/documentationjs/documentation/issues/372
268+
const modeComparatorValue = {
269+
SUBWAY: 1,
270+
TRAM: 2,
271+
RAIL: 3,
272+
GONDOLA: 4,
273+
FERRY: 5,
274+
CABLE_CAR: 6,
275+
FUNICULAR: 7,
276+
BUS: 8
277+
}
278+
279+
// Lookup that maps route types to the OTP mode sort values.
280+
// Note: JSDoc format not used to avoid bug in documentationjs.
281+
// https://github.com/documentationjs/documentation/issues/372
282+
const routeTypeComparatorValue = {
283+
0: modeComparatorValue.TRAM, // - Tram, Streetcar, Light rail.
284+
1: modeComparatorValue.SUBWAY, // - Subway, Metro.
285+
2: modeComparatorValue.RAIL, // - Rail. Used for intercity or long-distance travel.
286+
3: modeComparatorValue.BUS, // - Bus.
287+
4: modeComparatorValue.FERRY, // - Ferry.
288+
5: modeComparatorValue.CABLE_CAR, // - Cable tram.
289+
6: modeComparatorValue.GONDOLA, // - Gondola, etc.
290+
7: modeComparatorValue.FUNICULAR, // - Funicular.
291+
// TODO: 11 and 12 are not a part of OTP as of 2019-02-14, but for now just
292+
// associate them with bus/rail.
293+
11: modeComparatorValue.BUS, // - Trolleybus.
294+
12: modeComparatorValue.RAIL // - Monorail.
295+
}
296+
297+
// Gets a comparator value for a given route's type (OTP mode).
298+
// Note: JSDoc format not used to avoid bug in documentationjs.
299+
// ttps://github.com/documentationjs/documentation/issues/372
268300
function getRouteTypeComparatorValue (route) {
269-
switch (route.mode) {
270-
case 'SUBWAY':
271-
return 1
272-
case 'TRAM':
273-
return 2
274-
case 'RAIL':
275-
return 3
276-
case 'GONDOLA':
277-
return 4
278-
case 'FERRY':
279-
return 5
280-
case 'CABLE_CAR':
281-
return 6
282-
case 'FUNICULAR':
283-
return 7
284-
case 'BUS':
285-
return 8
286-
default:
287-
return 9999
301+
// For some strange reason, the short route response in OTP returns the
302+
// string-based modes, but the long route response returns the
303+
// integer route type. This attempts to account for both of those cases.
304+
if (!route) throw new Error('Route is undefined.', route)
305+
if (typeof modeComparatorValue[route.mode] !== 'undefined') {
306+
return modeComparatorValue[route.mode]
307+
} else if (typeof routeTypeComparatorValue[route.type] !== 'undefined') {
308+
return routeTypeComparatorValue[route.type]
309+
} else {
310+
// Default the comparator value to a large number (placing the route at the
311+
// end of the list).
312+
console.warn('no mode/route type found for route', route)
313+
return 9999
288314
}
289315
}
290316

0 commit comments

Comments
 (0)