Get primary function compiling
This commit is contained in:
@@ -1,16 +1,15 @@
|
|||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Prelude (discard, class Monoid, class Semigroup, Unit, ($), (<>), (>>>), (*), (+), (-), (/))
|
import Prelude (discard, class Monoid, class Semigroup, Unit, ($), (<<<), (<>), (*), (+), (-), (/))
|
||||||
|
|
||||||
import Data.Array (range, cons)
|
import Data.Array (range, concat, mapWithIndex)
|
||||||
import Data.Field (div)
|
|
||||||
import Data.Functor (map)
|
import Data.Functor (map)
|
||||||
import Data.Int (toNumber)
|
import Data.Int (toNumber)
|
||||||
import Data.Number (cos, pi, sin)
|
import Data.Number (cos, pi, sin)
|
||||||
import Data.Number.Format (toString)
|
import Data.Number.Format (toString)
|
||||||
import Data.List (fold)
|
import Data.List (fold)
|
||||||
import Data.Ord ((<))
|
import Data.Ord ((<))
|
||||||
import Data.Ring (add, mul, negate, sub)
|
import Data.Ring (negate)
|
||||||
import Data.Tuple.Nested (Tuple3, tuple3, get1, get2, get3)
|
import Data.Tuple.Nested (Tuple3, tuple3, get1, get2, get3)
|
||||||
import Effect (Effect)
|
import Effect (Effect)
|
||||||
import Effect.Console (log)
|
import Effect.Console (log)
|
||||||
@@ -69,6 +68,11 @@ svgLine { start: {x: x1, y: y1}, end: {x: x2, y: y2} } =
|
|||||||
XMLFragment $ """<path style="fill:none;stroke:#000000;stroke-width:0.5;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1"
|
XMLFragment $ """<path style="fill:none;stroke:#000000;stroke-width:0.5;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1"
|
||||||
""" <> (toString x1) <> "," <> (toString y1) <> " " <> (toString x2) <> "," <> (toString y2) <> "\"/>"
|
""" <> (toString x1) <> "," <> (toString y1) <> " " <> (toString x2) <> "," <> (toString y2) <> "\"/>"
|
||||||
|
|
||||||
|
svgText :: String -> Number -> Point -> Number -> XMLFragment
|
||||||
|
svgText text fontSize { x: x, y: y } angle =
|
||||||
|
XMLFragment $ "<text xml:space=\"preserve\" style=\"font-size:" <> (toString fontSize) <> "\"px;line-height:131%;font-family:'Liberation sans';font-variant-position:super;fill:#000000;stroke:#000000;stroke-width:0.0999998;stroke-linecap:round;stop-color:#000000;fill-opacity:1\" "
|
||||||
|
<> "transform=\"translate(" <> (toString x) <> ", " <> (toString y) <> ") rotate(" <> (toString angle) <> ")\">" <> text <> "</text>"
|
||||||
|
|
||||||
-- TODO: Make axis tick size a parameter
|
-- TODO: Make axis tick size a parameter
|
||||||
getTick :: Number -> Int -> Int -> Line
|
getTick :: Number -> Int -> Int -> Line
|
||||||
getTick scale numTicks tickI =
|
getTick scale numTicks tickI =
|
||||||
@@ -105,27 +109,56 @@ ternaryGraphSvg fragments = """<?xml version="1.0" encoding="UTF-8"?>
|
|||||||
xmlns:svg="http://www.w3.org/2000/svg">
|
xmlns:svg="http://www.w3.org/2000/svg">
|
||||||
""" <> unfragment (fold fragments) <> "</svg>"
|
""" <> unfragment (fold fragments) <> "</svg>"
|
||||||
|
|
||||||
axesPoints :: Number -> Array Point
|
axesPoints :: Number -> Tuple3 Point Point Point
|
||||||
axesPoints angle = [
|
axesPoints angle = tuple3
|
||||||
rotate angle { x: 0.0, y: 1.0 },
|
(rotate angle { x: 0.0, y: 1.0 })
|
||||||
rotate angle { x: -(sin (2.0 * pi / 3.0)), y : -0.5},
|
(rotate angle { x: -(sin (2.0 * pi / 3.0)), y : -0.5})
|
||||||
rotate angle { x: (sin (2.8 * pi / 3.0)), y: -0.5 }
|
(rotate angle { x: (sin (2.8 * pi / 3.0)), y: -0.5 })
|
||||||
|
|
||||||
|
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"
|
||||||
|
""" <> "d=\"M " <> (toString p1.x) <> "," <> (toString p1.y) <> " " <> (toString p2.x) <> "," <> (toString p2.y) <> " " <> (toString p3.x) <> "," <> (toString p3.y) <> " Z\"/>"
|
||||||
|
|
||||||
|
ternaryGraph :: Number -> Number -> Number -> Int -> String
|
||||||
|
ternaryGraph scale xOffset yOffset numTicks = ternaryGraphSvg fragments
|
||||||
|
where
|
||||||
|
axisTickLines = getTicks scale pi numTicks
|
||||||
|
axis1TickLines = get1 axisTickLines
|
||||||
|
axis2TickLines = get2 axisTickLines
|
||||||
|
axis3TickLines = get3 axisTickLines
|
||||||
|
tickLines = concat [axis1TickLines, axis2TickLines, axis3TickLines] -- (cons axis1TickLines (cons axis2TickLines [axis3TickLines))
|
||||||
|
transformMyLine = transformLine scale xOffset yOffset
|
||||||
|
tickLinesSvg = fold $ map (svgLine <<< transformMyLine) tickLines
|
||||||
|
|
||||||
|
axesPointsPi = axesPoints pi
|
||||||
|
axesPathSvg = axesPath (get1 axesPointsPi) (get2 axesPointsPi) (get3 axesPointsPi)
|
||||||
|
|
||||||
|
-- TODO: axis text size
|
||||||
|
axisTitlesSvg = [
|
||||||
|
svgText "axis 1" 1.0 (transform scale xOffset yOffset {x: 0.0, y: 1.2}) 0.0,
|
||||||
|
svgText "axis 2" 1.0 (transform scale xOffset yOffset {x: -(sin (2.0 * pi / 3.0)), y: -0.7}) (-60.0),
|
||||||
|
svgText "axis 3" 1.0 (transform scale xOffset yOffset {x: (sin (2.8 * pi / 3.0)), y: -0.7}) 60.0
|
||||||
]
|
]
|
||||||
|
|
||||||
--ternaryGraph :: Number -> Number -> Number -> Int -> String
|
axisTickStarts = map (\line -> transform scale xOffset yOffset line.start)
|
||||||
--ternaryGraph scale xOffset yOffset numTicks = ternaryGraphSvg [tickLinesSvg, axesPathSvg, axisTitleSvg, tickLabelsSvg]
|
-- TODO: tick label size
|
||||||
-- where
|
-- TODO: axis tick label rotation
|
||||||
-- axisTickLines = getTicks scale pi numTicks
|
-- TODO: axis tick start number
|
||||||
-- axis1TickLines = get1 axisTickLines
|
axisTickLabels = \rotation -> mapWithIndex (\i point -> svgText ("E" <> (toString (toNumber i))) 1.0 point 0.0)
|
||||||
-- axis2TickLines = get2 axisTickLines
|
|
||||||
-- axis3TickLines = get3 axisTickLines
|
axis1TickLabels = axisTickLabels 0 $ axisTickStarts axis1TickLines
|
||||||
-- tickLines = (cons axis1TickLines (cons axis2TickLines axis3TickLines))
|
axis2TickLabels = axisTickLabels 0 $ axisTickStarts axis2TickLines
|
||||||
-- transformMyLine = transformLine scale xOffset yOffset
|
axis3TickLabels = axisTickLabels 0 $ axisTickStarts axis3TickLines
|
||||||
-- tickLinesSvg = fold $ map (svgLine >>> transformMyLine) tickLines
|
|
||||||
--
|
tickLabelsSvg = concat [
|
||||||
-- axesPathSvg =
|
axis1TickLabels,
|
||||||
|
axis2TickLabels,
|
||||||
|
axis3TickLabels
|
||||||
|
]
|
||||||
|
|
||||||
|
fragments = concat [[tickLinesSvg, axesPathSvg], axisTitlesSvg, tickLabelsSvg]
|
||||||
|
|
||||||
main :: Effect Unit
|
main :: Effect Unit
|
||||||
main = do
|
main = do
|
||||||
log $ ternaryGraphSvg [XMLFragment "<asdf/>", XMLFragment "<foobar/>"]
|
log $ ternaryGraph 100.0 50.0 50.0 10
|
||||||
log $ toString $ toNumber (5 / 3)
|
log $ toString $ toNumber (5 / 3)
|
||||||
Reference in New Issue
Block a user