Skip to content

Commit

Permalink
fix(label): handle missing getName function
Browse files Browse the repository at this point in the history
fix #55
  • Loading branch information
landonreed committed Nov 4, 2020
1 parent e5cfc4e commit 988c9e6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/labeler/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export default class Label {
}

initText () {
return this.parent.getName()
// TODO: determine why getName is missing for patterns running on routes
// without short names
return typeof this.parent.getName === 'function'
? this.parent.getName()
: null
}

render (display) {}
Expand Down
5 changes: 4 additions & 1 deletion lib/labeler/segmentlabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default class SegmentLabel extends Label {
}

render (display) {
const text = this.getText()
// Do not attempt to render label if there is no label text.
if (!text) return null
const x = this.labelAnchor.x - this.containerWidth / 2
const y = this.labelAnchor.y - this.containerHeight / 2
// Draw rounded rectangle for label.
Expand All @@ -26,7 +29,7 @@ export default class SegmentLabel extends Label {
ry: this.containerHeight / 2
})
// Offset text location by padding
display.drawText(this.getText(), {
display.drawText(text, {
x: x + this.getPadding(),
// Offset y by a couple of pixels to account for off-centeredness.
y: y + this.getPadding() + 2
Expand Down
2 changes: 2 additions & 0 deletions lib/renderer/renderedsegment.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export default class RenderedSegment {
getLabelTextArray () {
var textArray = []
forEach(this.patterns, pattern => {
// TODO: Should we attempt to extract part of the long name if short name
// is missing?
var shortName = pattern.route.route_short_name
if (textArray.indexOf(shortName) === -1) textArray.push(shortName)
})
Expand Down

0 comments on commit 988c9e6

Please sign in to comment.