Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting segment_label#font-size to 0px causes transitive.js to crash #66

Open
landonreed opened this issue Apr 6, 2021 · 1 comment
Labels

Comments

@landonreed
Copy link
Contributor

@binh-dam-ibigroup, can you document some of the things that you tried/noticed about this when debugging?

@binh-dam-ibigroup
Copy link
Collaborator

Here are two quick things I tried that did not work at first and need further investigation:

At https://github.com/conveyal/transitive.js/blob/master/lib/labeler/labeler.js#L322

    if (label.fontSize) {
      // (Code in this block is unchanged)
      const textDimensions = measureText({
        text: labelText,
        // Append 'px' if a unit was not specified in font-size.
        fontSize: getFontSizeWithUnit(label.fontSize),
        fontFamily: label.fontFamily || 'sans-serif',
        lineHeight: 1.2
      })

      label.textWidth = textDimensions.width.value
      label.textHeight = textDimensions.height.value
      label.computeContainerDimensions()
    } else {
      label.textWidth = 1
      label.textHeight = 1
      label.containerWidth = 1
      label.containerHeight = 1
    }

    return label

At https://github.com/conveyal/transitive.js/blob/master/lib/labeler/segmentlabel.js#L34:

    if (fontSize) {
      // (Code in this block is unchanged)
      // Offset text location by padding
      display.drawText(text, {
        x: x + this.getPadding(),
        // Offset y by a couple of pixels to account for off-centeredness.
        y: y + this.getPadding() + 2
      }, {
        // text color
        fill: display.styler.compute2('segment_labels', 'color', this.parent),
        'font-family': display.styler.compute2('segment_labels', 'font-family', this.parent),
        // Append 'px' if a unit was not specified in font-size.
        'font-size': getFontSizeWithUnit(fontSize)
      })
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants