Skip to content

Commit

Permalink
Merge pull request #51 from conveyal/route-short-name-fix
Browse files Browse the repository at this point in the history
Fix npe on missing route_short_name
  • Loading branch information
evansiroky authored May 23, 2020
2 parents 06c5750 + e9fee8b commit 50d9e79
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions lib/styler/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@ const segments = {
if (!segment.focused) return notFocusedColor
if (segment.type === 'TRANSIT') {
if (segment.patterns) {
if (segment.patterns[0].route.route_short_name.toLowerCase().substring(
0,
2) === 'dc') return '#f00'
if (patternIsDcCirculatorBusRoute(segment.patterns[0])) return '#f00'
return segment.patterns[0].route.getColor()
}
} else if (segment.type === 'CAR') {
Expand Down Expand Up @@ -299,10 +297,7 @@ const segmentsFront = {
display: [
'none',
function (display, data, index, utils) {
if (data.pattern && data.pattern.route && data.pattern.route.route_type ===
3 &&
data.pattern.route.route_short_name.toLowerCase().substring(0, 2) ===
'dc') {
if (patternIsDcCirculatorBusRoute(data.pattern)) {
return 'inline'
}
}
Expand Down Expand Up @@ -331,14 +326,28 @@ const segmentLabelContainers = {
if (!data.isFocused()) return notFocusedColor
},
'stroke-width': function (display, data) {
if (data.parent.pattern && data.parent.pattern.route.route_short_name.toLowerCase()
.substring(0, 2) === 'dc') return 1
if (patternIsDcCirculatorBusRoute(data.parent.pattern)) return 1
return 0
},
rx: 3,
ry: 3
}

/**
* Checks that a pattern runs a DC Bus Circulator route. This check dates back
* to https://github.com/conveyal/transitive.js/commit/b1561dcb6d864fbe6b01de11aa13d06761e1cefd
* and was likely added to support CarFreeAtoZ (Arlington, VA). However, this may
* need to be removed because Arlington no longer runs this service. Also, it
* appears to be hyper-specific to this one implementation.
*/
function patternIsDcCirculatorBusRoute (pattern) {
if (!pattern) return false
const {route} = pattern
const hasShortName = route && route.route_short_name
const isBus = route && route.route_type === 3
return hasShortName && isBus && route.route_short_name.toLowerCase().substring(0, 2) === 'dc'
}

export default {
utils,
wireframe_edges: wireframeEdges,
Expand Down

0 comments on commit 50d9e79

Please sign in to comment.