getTranslation()

in src/lib/components/molecules/canvas-map/lib/styles/Text.js [165:206]


  getTranslation(elementWidth, elementHeight) {
    const translate = this._getRelativeTranslation()
    let x = (translate.x / 100) * elementWidth
    let y = (translate.y / 100) * elementHeight

    const radialOffsetInPixels =
      this.radialOffset * parseInt(this.fontSize.replace("px", ""))

    switch (this.anchor) {
      case TextAnchor.TOP:
        y += radialOffsetInPixels
        break
      case TextAnchor.BOTTOM:
        y -= radialOffsetInPixels
        break
      case TextAnchor.LEFT:
        x += radialOffsetInPixels
        break
      case TextAnchor.RIGHT:
        x -= radialOffsetInPixels
        break
      case TextAnchor.CENTER:
        break
      case TextAnchor.TOP_LEFT:
        x += radialOffsetInPixels
        y += radialOffsetInPixels
        break
      case TextAnchor.TOP_RIGHT:
        x -= radialOffsetInPixels
        y += radialOffsetInPixels
        break
      case TextAnchor.BOTTOM_LEFT:
        x += radialOffsetInPixels
        y -= radialOffsetInPixels
        break
      case TextAnchor.BOTTOM_RIGHT:
        x -= radialOffsetInPixels
        y -= radialOffsetInPixels
        break
    }
    return { x, y }
  }