Skip to content

Commit

Permalink
basic decision step rendering done
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrJustyna committed Mar 13, 2024
1 parent 00c5f03 commit 1736484
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
23 changes: 19 additions & 4 deletions HelloWorld.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Diagrams.TwoD.Text
data StepType
= StartType
| RegularStep
| DecisionStep
| EndType

data Step = Step {
Expand All @@ -23,19 +24,32 @@ stepShape :: Double -> Diagram B
stepShape x = rect 0.95 0.4 # showOrigin # named x

startShape :: Double -> Diagram B
startShape x = text "start" # fontSize (local 0.1) # light # font "courier" <> roundedRect 0.95 0.4 0.5 # showOrigin # named x
startShape x = text "start" # fontSize (local 0.1) # light # font "courier" <> roundedRect 1.0 0.4 0.5 # showOrigin # named x

endShape :: Double -> Diagram B
endShape x = text "end" # fontSize (local 0.1) # thinWeight # font "courier" <> roundedRect 0.95 0.4 0.5 # showOrigin # named x
endShape x = text "end" # fontSize (local 0.1) # thinWeight # font "courier" <> roundedRect 1.0 0.4 0.5 # showOrigin # named x

decisionShape :: Double -> Diagram B
decisionShape x = fromOffsets
[V2 (-0.1) 0.2,
V2 0.1 0.2,
V2 0.8 0.0,
V2 0.1 (-0.2),
V2 (-0.1) (-0.2),
V2 (-0.8) (0.0)]
# translate (r2 ((-0.4), (-0.2)))
# showOrigin
# named x

uniqueName :: Double -> Double -> Double
uniqueName x y = x * 10 + (abs y)

steps :: [Step]
steps =
Step { originCoordinates = p2 (0, 0), name = uniqueName 0 0, stepType = StartType }
: [Step { originCoordinates = p2 (x, y), name = uniqueName x y, stepType = RegularStep } | x <- [0], y <- [-1, -2, -3]]
++ [Step { originCoordinates = p2 (0, -4), name = uniqueName 0 4, stepType = EndType }]
: Step { originCoordinates = p2 (0, -1), name = uniqueName 0 (-1), stepType = DecisionStep }
: [Step { originCoordinates = p2 (x, y), name = uniqueName x y, stepType = RegularStep } | x <- [0], y <- [-2, -3, -4]]
++ [Step { originCoordinates = p2 (0, -5), name = uniqueName 0 (-5), stepType = EndType }]

connections :: [Step] -> [QDiagram B V2 Double Any -> QDiagram B V2 Double Any]
connections (x1: x2: xn) = connectOutside' (with & arrowHead .~ noHead) (stepName x1) (stepName x2): connections (x2: xn)
Expand All @@ -45,6 +59,7 @@ connections [] = []
correctShape :: StepType -> Double -> Diagram B
correctShape StartType = startShape
correctShape EndType = endShape
correctShape DecisionStep = decisionShape
correctShape _ = stepShape

main = mainWith $
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@

![hello-world](./hello-world.svg)

## terminology:

* start - first step of a diagram
* end - last step of a diagram
* command - "do X" non-branching action, basic building block of a diagram
* decision - branching step with two possible outcomes:
* yes
* no

**todo:** set diagram here? Depending on how I implement the steps.

## resources

* [drakon](https://drakonhub.com/read/docs)
Expand Down
Loading

0 comments on commit 1736484

Please sign in to comment.