Reimplement getAllTextDimensions

Create SVG text elements so that the dimensions are representative
This commit is contained in:
Nathan McRae
2025-08-19 19:05:50 -07:00
parent d26f7778ba
commit 99cc71e330
2 changed files with 59 additions and 40 deletions

View File

@@ -87,13 +87,19 @@ svgLine { start: {x: x1, y: y1}, end: {x: x2, y: y2} } =
""" <> "d=\"M " <> (toString x1) <> "," <> (toString y1) <> " " <> (toString x2) <> "," <> (toString y2) <> "\"/>"
svgText :: String -> Point -> Number -> TextStyle -> Dimension -> XMLFragment
svgText text { x: x, y: y } angle style dimension =
XMLFragment $ "<text xml:space=\"preserve\" style=\"font-size:" <> (toString style.sizePx) <> "px;line-height:131%;font-family:'" <> style.typeface <> "';fill:#000000;stroke:#000000;stroke-width:0.0999998;stroke-linecap:round;stop-color:#000000;fill-opacity:1\" "
svgText = svgTextID Maybe.Nothing
svgTextID :: Maybe.Maybe String -> String -> Point -> Number -> TextStyle -> Dimension -> XMLFragment
svgTextID idMaybe text { x: x, y: y } angle style dimension =
XMLFragment $ "<text " <> idText <> " xml:space=\"preserve\" style=\"font-size:" <> (toString style.sizePx) <> "px;line-height:131%;font-family:'" <> style.typeface <> "';fill:#000000;stroke:#000000;stroke-width:0.0999998;stroke-linecap:round;stop-color:#000000;fill-opacity:1\" "
<> "transform=\"translate(" <> (toString centerX) <> ", " <> (toString centerY) <> ") rotate(" <> (toString (angle * 180.0 / pi)) <> ")\">" <> text <> "</text>"
where
offset = rotate angle {x: dimension.widthPx, y: dimension.heightPx}
centerX = x - offset.x / 2.0
centerY = y - offset.y / 2.0
centerX = x - offset.x / 4.0
centerY = y - offset.y / 4.0
idText = case idMaybe of
Maybe.Nothing -> ""
Maybe.Just id -> "id=\"" <> id <> "\""
-- TODO: Make axis tick size a parameter
getTick :: Number -> Int -> Int -> Line
@@ -173,6 +179,7 @@ ternaryGraph scale xOffset yOffset definition textDimensions = result
axis1TitlePos = {x: 0.0, y: 0.9}
axis2TitlePos = rotate (2.0 * pi / 3.0) axis1TitlePos
axis3TitlePos = rotate (-2.0 * pi / 3.0) axis1TitlePos
axisTitleSize = definition.axisTitleTextStyle.sizePx
axisTitlesSvg :: Array (Either.Either String XMLFragment)
axisTitlesSvg = [