packages feed

wyvern-diagrams-0.3.1.1 / src / lib / HelperDiagrams.hs

module HelperDiagrams whereimport Constants (defaultBoundingBoxHeight, defaultBoundingBoxWidth, defaultFontSize, fillColour, fontColour, heightRatio, lineColour, widthRatio, wyvernStyle)import Diagrams.Backend.SVG (B)import Diagrams.Prelude  ( Diagram,    Point (..),    V2 (..),    closeLine,    fc,    font,    fontSize,    fromOffsets,    fromVertices,    lc,    light,    local,    lw,    p2,    position,    r2,    rect,    regPoly,    rotateBy,    roundedRect,    scaleY,    strokeLoop,    text,    translate,    triangle,    veryThin,    (#),  )rect' :: Double -> Double -> Diagram Brect' x y =  fromOffsets [V2 x 0.0, V2 0.0 (y * (-1.0)), V2 (x * (-1.0)) 0.0, V2 0.0 y] # closeLine # strokeLoop # wyvernStyleheadlineShape :: Double -> Double -> Diagram BheadlineShape x y =  fromOffsets [V2 x 0.0, V2 0.0 (y * (-1.0)), V2 (x * (-0.5)) (-0.1), V2 (x * (-0.5)) 0.1, V2 0.0 y]    # closeLine    # strokeLoop    # wyvernStyleaddressShape :: Double -> Double -> Diagram BaddressShape x y =  fromOffsets [V2 (x * 0.5) 0.1, V2 (x * 0.5) (-0.1), V2 0.0 (y * (-1.0)), V2 (x * (-1.0)) 0.0]    # closeLine    # strokeLoop    # wyvernStylerenderText :: String -> Diagram BrenderText x =  text x    # fontSize (local defaultFontSize)    # light    # font "helvetica"    # fc fontColourwyvernRoundedRect :: String -> Diagram BwyvernRoundedRect x =  renderText x    <> roundedRect (defaultBoundingBoxWidth * widthRatio) (defaultBoundingBoxHeight * heightRatio) 0.5 # lw veryThin # lc lineColour # fc fillColourwyvernRect :: String -> Diagram BwyvernRect x =  renderText x    <> rect (defaultBoundingBoxWidth * widthRatio) (defaultBoundingBoxHeight * heightRatio) # lw veryThin # lc lineColour # fc fillColourwyvernHeadline :: String -> Diagram BwyvernHeadline x =  renderText x    <> fromOffsets      [ V2 0.0 (defaultBoundingBoxHeight * heightRatio),        V2 (defaultBoundingBoxWidth * widthRatio) 0.0,        V2 0.0 (defaultBoundingBoxHeight * heightRatio * (-1.0)),        V2 (defaultBoundingBoxWidth * widthRatio * (-0.5)) (-0.1),        V2 (defaultBoundingBoxWidth * widthRatio * (-0.5)) 0.1      ]      # closeLine      # strokeLoop      # wyvernStyle      # translate (r2 (defaultBoundingBoxWidth * widthRatio * (-0.5), defaultBoundingBoxHeight * heightRatio * (-0.5)))wyvernAddress :: String -> Diagram BwyvernAddress x =  renderText x    <> fromOffsets      [ V2 0.0 (defaultBoundingBoxHeight * heightRatio),        V2 (defaultBoundingBoxWidth * widthRatio * 0.5) 0.1,        V2 (defaultBoundingBoxWidth * widthRatio * 0.5) (-0.1),        V2 0.0 (defaultBoundingBoxHeight * heightRatio * (-1.0)),        V2 (defaultBoundingBoxWidth * widthRatio * (-1.0)) 0.0      ]      # closeLine      # strokeLoop      # wyvernStyle      # translate (r2 (defaultBoundingBoxWidth * widthRatio * (-0.5), defaultBoundingBoxHeight * heightRatio * (-0.5)))wyvernQuestion :: String -> Diagram BwyvernQuestion x =  renderText x    <> fromOffsets      [ V2 (-0.1) (defaultBoundingBoxHeight * heightRatio * 0.5),        V2 0.1 (defaultBoundingBoxHeight * heightRatio * 0.5),        V2 (defaultBoundingBoxWidth * widthRatio - 0.2) 0.0,        V2 0.1 (defaultBoundingBoxHeight * heightRatio * (-0.5)),        V2 (-0.1) (defaultBoundingBoxHeight * heightRatio * (-0.5)),        V2 (defaultBoundingBoxWidth * widthRatio * (-1.0) + 0.2) 0.0      ]      # closeLine      # strokeLoop      # wyvernStyle      # translate (r2 (defaultBoundingBoxWidth * widthRatio * (-0.5) + 0.1, defaultBoundingBoxHeight * heightRatio * (-0.5)))    <> renderText "yes" # translate (r2 (-0.2, defaultBoundingBoxHeight * (-0.4)))    <> renderText "no" # translate (r2 (defaultBoundingBoxWidth * 0.45, 0.1))wyvernHex :: String -> Diagram BwyvernHex x =  renderText x    <> regPoly 6 ((defaultBoundingBoxWidth * widthRatio) / 2)      # scaleY ((defaultBoundingBoxHeight * heightRatio) / (defaultBoundingBoxWidth * widthRatio))      # wyvernStyle    <> renderText "yes" # translate (r2 (-0.2, defaultBoundingBoxHeight * (-0.35)))    <> renderText "no" # translate (r2 (defaultBoundingBoxWidth * 0.45, 0.1))renderConnection :: [Point V2 Double] -> Diagram BrenderConnection coordinates = fromVertices coordinates # wyvernStylerenderGammaConnection :: Point V2 Double -> Point V2 Double -> Double -> Double -> Diagram BrenderGammaConnection gO@(P (V2 gOX gOY)) gD@(P (V2 gDX gDY)) maxX minY =  let gD'@(P (V2 gDX' gDY')) = p2 (gDX + (0.1 * sqrt 3.0 / 2.0) + 0.012, gDY + defaultBoundingBoxHeight * 0.5)      gammaMidpoint1 = p2 (gOX, minY)      gammaMidpoint2 = p2 (maxX - defaultBoundingBoxWidth * 0.5, minY)      gammaMidpoint3 = p2 (maxX - defaultBoundingBoxWidth * 0.5, gDY')      coordinates = [gO, gammaMidpoint1, gammaMidpoint2, gammaMidpoint3, gD']   in renderConnection coordinates <> position [(p2 (gDX' - 0.025, gDY'), rotateBy (1 / 4) $ triangle 0.1 # wyvernStyle)]renderUpperBetaConnections :: [(Double, Double)] -> Double -> Diagram BrenderUpperBetaConnections [] maxD = memptyrenderUpperBetaConnections [uBC@(uBCa, uBCb)] maxD =  renderConnection    [ p2 (uBCa, maxD + defaultBoundingBoxHeight * 0.5),      p2 (uBCb, maxD + defaultBoundingBoxHeight * 0.5),      p2 (uBCb, maxD + defaultBoundingBoxHeight * heightRatio * 0.5)    ]renderUpperBetaConnections (uBC@(uBCa, uBCb) : uBCs) maxD =  renderConnection    [ p2 (uBCa, maxD + defaultBoundingBoxHeight * 0.5),      p2 (uBCb, maxD + defaultBoundingBoxHeight * 0.5),      p2 (uBCb, maxD + defaultBoundingBoxHeight * heightRatio * 0.5)    ]    <> renderUpperBetaConnections uBCs maxDrenderSideBetaConnection :: Point V2 Double -> Point V2 Double -> Diagram BrenderSideBetaConnection a@(P (V2 aX aY)) b@(P (V2 bX bY)) =  renderConnection    [ a,      p2 (aX - defaultBoundingBoxWidth * 0.5, aY),      p2 (aX - defaultBoundingBoxWidth * 0.5, bY),      p2 (bX - (0.1 * sqrt 3.0 / 2.0), bY)    ]    <> position [(p2 (bX - 0.06, bY), rotateBy (3 / 4) $ triangle 0.1 # wyvernStyle)]renderLowerBetaConnections' :: [(Double, Double, Double)] -> Double -> Diagram BrenderLowerBetaConnections' [] _ = memptyrenderLowerBetaConnections' (lBC@(lBCa, lBCb, lBCc) : lBCs) minD =  renderConnection [p2 (lBCa, lBCc + defaultBoundingBoxHeight), p2 (lBCa, minD), p2 (lBCb, minD)]    <> renderLowerBetaConnections' lBCs minDrenderLowerBetaConnections :: [(Double, Double, Double)] -> Double -> Diagram BrenderLowerBetaConnections [] _ = memptyrenderLowerBetaConnections (lBC@(lBCa, lBCb, lBCc) : lBCs) minD =  renderConnection [p2 (lBCa, lBCc + defaultBoundingBoxHeight), p2 (lBCa, minD)]    <> renderLowerBetaConnections' lBCs minD