-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic state graph rendering support
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Milestone 3 | ||
|
||
## Summary | ||
|
||
Changes: | ||
|
||
* Running in emulated environment by CLB | ||
* Rendering CEMScript state graphs | ||
|
||
## State graph examples | ||
|
||
```graphviz | ||
digraph Creator { | ||
rankdir=LR; | ||
node [shape="dot",fontsize=14,fixedsize=true,width=1.5]; | ||
edge [fontsize=11];"Void In" [color="orange"];"Void Out" [color="orange"];"Void In" -> NotStarted [label="Create (stage Open)"]; | ||
NotStarted -> CurrentBid [label="Start (stage Open)"]; | ||
CurrentBid -> CurrentBid [label="MakeBid (stage Open)"]; | ||
CurrentBid -> Winner [label="Close (stage Closed)"]; | ||
Winner -> "Void Out" [label="Buyout (stage Closed)"]; | ||
} | ||
``` | ||
|
||
```graphviz | ||
digraph Creator { | ||
rankdir=LR; | ||
node [shape="dot",fontsize=14,fixedsize=true,width=1.5]; | ||
edge [fontsize=11];"Void In" [color="orange"];"Void Out" [color="orange"];"Void In" -> Spawning [label="Create (stage Always)"]; | ||
Spawning -> Spawning [label="Spawn (stage Always)"]; | ||
Spawning -> "Void Out" [label="Finalize (stage Always)"]; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module Cardano.CEM.Documentation where | ||
|
||
import Prelude | ||
|
||
import Data.Map qualified as Map | ||
import Data.Proxy | ||
|
||
import Cardano.CEM | ||
import Data.List (stripPrefix) | ||
|
||
dotStyling = | ||
"rankdir=LR;\n" | ||
<> "node [shape=\"dot\",fontsize=14,fixedsize=true,width=1.5];\n" | ||
<> "edge [fontsize=11];" | ||
<> "\"Void In\" [color=\"orange\"];" | ||
<> "\"Void Out\" [color=\"orange\"];" | ||
|
||
cemDotGraphString :: (CEMScript script) => String -> Proxy script -> String | ||
cemDotGraphString name proxy = | ||
"digraph " | ||
<> name | ||
<> " {\n" | ||
<> dotStyling | ||
<> edges | ||
<> "}" | ||
where | ||
showSpine :: (Show s) => s -> String | ||
showSpine = stripSpineSuffix . show | ||
stripSpineSuffix = reverse . drop 5 . reverse | ||
edges = | ||
foldMap id $ | ||
[ ( maybe "\"Void In\"" showSpine from | ||
<> " -> " | ||
<> (maybe "\"Void Out\"" showSpine to) | ||
<> " [label=\"" | ||
<> showSpine transition | ||
<> " (stage " | ||
<> show stage | ||
<> ")" | ||
<> "\"]; \n" | ||
) | ||
| (transition, (stage, from, to)) <- | ||
Map.assocs $ transitionStage proxy | ||
] |