Skip to content

Commit

Permalink
get rid of draw prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
robx committed Jan 3, 2020
1 parent e61e07e commit 93fd01e
Show file tree
Hide file tree
Showing 8 changed files with 420 additions and 388 deletions.
14 changes: 7 additions & 7 deletions src/Draw/Code.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{-# LANGUAGE TypeFamilies #-}

module Draw.Code
( drawCode
( code
, arrowRight
, arrowRightL
, arrowDown
Expand All @@ -27,19 +27,19 @@ import Diagrams.Prelude hiding ( place

import qualified Data.Map.Strict as Map

drawCode :: Backend' b => Code -> [TaggedComponent (Drawing b)]
drawCode cs = concat [collect Atop, collect West, collect North]
code :: Backend' b => Code -> [TaggedComponent (Drawing b)]
code cs = concat [collect Atop, collect West, collect North]
where
parts = map drawCodePart cs
parts = map codePart cs
collect p =
let matching = map snd . filter ((==) p . fst) $ parts
in if null matching then [] else [comp p $ mconcat matching]
fakeSize = (0, 0) -- should be the dimensions of the code part
comp p d =
TaggedComponent (Just Code) $ PlacedComponent p $ RawComponent fakeSize $ d

drawCodePart :: Backend' b => CodePart -> (Placement, Drawing b)
drawCodePart cp = case cp of
codePart :: Backend' b => CodePart -> (Placement, Drawing b)
codePart cp = case cp of
Rows' rs -> (West, placeGrid g # centerX')
where g = Map.fromList [ (C 1 r, arrowRight) | r <- rs ]
Cols cs -> (North, placeGrid g # centerY')
Expand All @@ -50,7 +50,7 @@ drawCodePart cp = case cp of
where g = Map.fromList [ (N c 0, arrowDown) | c <- cs ]
LabelsN g -> (Atop, placeGrid . fmap label . clues $ g)
where
label c = drawChar c # scale 0.5 # fc gray # translate (r2 (1 / 3, -1 / 3))
label c = char c # scale 0.5 # fc gray # translate (r2 (1 / 3, -1 / 3))
LRows' rs -> (West, placeGrid g # centerX')
where
g = Map.fromList [ (C 0 r, arrowRightL [l]) | (l, r) <- Map.toList rs ]
Expand Down
43 changes: 22 additions & 21 deletions src/Draw/Component.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import qualified Data.Map.Strict as Map

import Diagrams.Prelude hiding ( dot
, place
, star
)

import Data.Component
Expand All @@ -24,13 +25,13 @@ import Draw.Style
import Draw.Elements
import Draw.Code

drawComponents :: Backend' b => [PlacedComponent (Drawing b)] -> Drawing b
drawComponents cs = snd $ go $ reverse cs
components :: Backend' b => [PlacedComponent (Drawing b)] -> Drawing b
components cs = snd $ go $ reverse cs
where
go [] = ((0 :: Int, 0 :: Int), mempty)
go ((PlacedComponent p c) : pcs)
= let
(tl , dc ) = drawComponent c
(tl , dc ) = component c
(tls, dcs) = go pcs
ntl = (max (fst tl) (fst tls), max (snd tl) (snd tls))
in
Expand All @@ -46,24 +47,24 @@ drawComponents cs = snd $ go $ reverse cs
(=!=) = beside unitY
(|!|) = beside (negated unitX)

drawComponent :: Backend' b => Component (Drawing b) -> (Size, Drawing b)
drawComponent c = case c of
component :: Backend' b => Component (Drawing b) -> (Size, Drawing b)
component c = case c of
RawComponent sz x -> (sz, x)
Grid s g -> (cellSize g, grid (gridStyle s) g)
Regions g -> (cellSize g, drawAreas g)
CellGrid g -> (cellSize g, placeGrid . fmap drawDecoration $ g)
NodeGrid g -> (nodeSize g, placeGrid . fmap drawDecoration $ g)
Regions g -> (cellSize g, areas g)
CellGrid g -> (cellSize g, placeGrid . fmap decoration $ g)
NodeGrid g -> (nodeSize g, placeGrid . fmap decoration $ g)
EdgeGrid g ->
(edgeSize g, placeGrid' . Map.mapKeys midPoint . fmap drawDecoration $ g)
(edgeSize g, placeGrid' . Map.mapKeys midPoint . fmap decoration $ g)
FullGrid ns cs es ->
( nodeSize ns
, mconcat
. map (snd . drawComponent)
. map (snd . component)
$ [NodeGrid ns, CellGrid cs, EdgeGrid es]
)
Note ds -> ((0, 0), note $ hcatSep 0.2 $ map drawDecoration $ ds)
Note ds -> ((0, 0), note $ hcatSep 0.2 $ map decoration $ ds)
Pyramid g -> (shiftSize g, shiftGrid g)
CellPyramid g -> (shiftSize g, placeGrid . fmap drawDecoration $ g)
CellPyramid g -> (shiftSize g, placeGrid . fmap decoration $ g)
where
gridStyle s = case s of
GridDefault -> gDefault
Expand All @@ -73,20 +74,20 @@ drawComponent c = case c of
GridPlain -> gPlain
GridPlainDashed -> gPlainDashed

drawDecoration :: Backend' b => Decoration -> Drawing b
drawDecoration d = case d of
decoration :: Backend' b => Decoration -> Drawing b
decoration d = case d of
Blank -> mempty
Letter c -> drawChar c
Letter c -> char c
Letters s -> text' s
InvertedLetters s -> invert $ text' s
DecKropkiDot k -> kropkiDot k
AfternoonSouth -> afternoonSouth
AfternoonWest -> afternoonWest
LightDiagonal diag -> lc (blend 0.5 gray white) $ drawPrimeDiag diag
DarkDiagonal diag -> lc gray $ drawPrimeDiag diag
LightDiagonal diag -> lc (blend 0.5 gray white) $ primeDiag diag
DarkDiagonal diag -> lc gray $ primeDiag diag
SmallDot -> dot
Dot -> scale 0.5 $ smallPearl MBlack
Star -> drawStar Data.Elements.Star
Star -> star Data.Elements.Star
Shade -> fillBG gray
DarkShade -> fillBG (blend 0.5 gray black)
Black -> fillBG black
Expand All @@ -105,6 +106,6 @@ drawDecoration d = case d of
Ship dir -> shipEnd dir
LabeledArrow dir w -> labeledArrow dir $ text' w
InvertedLabeledArrow dir w -> invert $ labeledArrow dir $ text' w
Tent -> draw tent
Tree -> drawTree Data.Elements.Tree
Myopia dirs -> drawMyopia dirs
Tent -> draw tentDia
Tree -> tree Data.Elements.Tree
Myopia dirs -> myopia dirs
Loading

0 comments on commit 93fd01e

Please sign in to comment.