Skip to content

Commit 6c17b8d

Browse files
authored
Merge pull request #56 from conveyal/fix-getname-npe
fix(label): handle missing getName function
2 parents e5cfc4e + 988c9e6 commit 6c17b8d

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

lib/labeler/label.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ export default class Label {
1414
}
1515

1616
initText () {
17-
return this.parent.getName()
17+
// TODO: determine why getName is missing for patterns running on routes
18+
// without short names
19+
return typeof this.parent.getName === 'function'
20+
? this.parent.getName()
21+
: null
1822
}
1923

2024
render (display) {}

lib/labeler/segmentlabel.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ export default class SegmentLabel extends Label {
1111
}
1212

1313
render (display) {
14+
const text = this.getText()
15+
// Do not attempt to render label if there is no label text.
16+
if (!text) return null
1417
const x = this.labelAnchor.x - this.containerWidth / 2
1518
const y = this.labelAnchor.y - this.containerHeight / 2
1619
// Draw rounded rectangle for label.
@@ -26,7 +29,7 @@ export default class SegmentLabel extends Label {
2629
ry: this.containerHeight / 2
2730
})
2831
// Offset text location by padding
29-
display.drawText(this.getText(), {
32+
display.drawText(text, {
3033
x: x + this.getPadding(),
3134
// Offset y by a couple of pixels to account for off-centeredness.
3235
y: y + this.getPadding() + 2

lib/renderer/renderedsegment.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ export default class RenderedSegment {
118118
getLabelTextArray () {
119119
var textArray = []
120120
forEach(this.patterns, pattern => {
121+
// TODO: Should we attempt to extract part of the long name if short name
122+
// is missing?
121123
var shortName = pattern.route.route_short_name
122124
if (textArray.indexOf(shortName) === -1) textArray.push(shortName)
123125
})

0 commit comments

Comments
 (0)