Add tickLabelStrings

To be able to get string dimensions from DOM
This commit is contained in:
Nathan McRae
2025-08-07 22:01:14 -07:00
parent 4f4acfe6b2
commit 392200f82e

View File

@@ -11,6 +11,7 @@ import Data.Number.Format (toString)
import Data.List (fold) import Data.List (fold)
import Data.Ord ((<)) import Data.Ord ((<))
import Data.Ring (negate) import Data.Ring (negate)
import Data.Set as Set
import Data.Tuple.Nested (Tuple3, tuple3, get1, get2, get3) import Data.Tuple.Nested (Tuple3, tuple3, get1, get2, get3)
type Point = type Point =
@@ -111,6 +112,15 @@ axesPath :: Point -> Point -> Point -> XMLFragment
axesPath p1 p2 p3 = XMLFragment $ """<path style="fill:none;stroke:#000000;stroke-width:1;stroke-linecap:bevel;stroke-linejoin:bevel;stroke-dasharray:none;stroke-opacity:1" axesPath p1 p2 p3 = XMLFragment $ """<path style="fill:none;stroke:#000000;stroke-width:1;stroke-linecap:bevel;stroke-linejoin:bevel;stroke-dasharray:none;stroke-opacity:1"
""" <> "d=\"M " <> (toString p1.x) <> "," <> (toString p1.y) <> " " <> (toString p2.x) <> "," <> (toString p2.y) <> " " <> (toString p3.x) <> "," <> (toString p3.y) <> " Z\"/>" """ <> "d=\"M " <> (toString p1.x) <> "," <> (toString p1.y) <> " " <> (toString p2.x) <> "," <> (toString p2.y) <> " " <> (toString p3.x) <> "," <> (toString p3.y) <> " Z\"/>"
tickLabelStrings :: Int -> Int -> Int -> Int -> Set.Set String
tickLabelStrings numTicks axis1Start axis2Start axis3Start =
Set.map (\x -> "E" <> (toString (Int.toNumber x))) axisTicks
where
axis1Ticks = Set.fromFoldable (range axis1Start (axis1Start + numTicks - 1))
axis2Ticks = Set.fromFoldable (range axis2Start (axis2Start + numTicks - 1))
axis3Ticks = Set.fromFoldable (range axis3Start (axis3Start + numTicks - 1))
axisTicks = Set.union (Set.union axis1Ticks axis2Ticks) axis3Ticks
ternaryGraph :: Number -> Number -> Number -> Int -> String ternaryGraph :: Number -> Number -> Number -> Int -> String
ternaryGraph scale xOffset yOffset numTicks = ternaryGraphSvg fragments ternaryGraph scale xOffset yOffset numTicks = ternaryGraphSvg fragments
where where