Skip to main content

StateDiagram

The following classes can be useful when creating sequence diagrams:

  • siren
  • stateDiagram
  • stateConfig

Simple

let Still, Moving, Crash = "Still", "Moving", "Crash"
siren.stateV2 [
stateDiagram.transitionStart(Still)
stateDiagram.transitionEnd(Still)
stateDiagram.transition(Still, Moving)
stateDiagram.transition(Moving, Still)
stateDiagram.transition(Moving, Crash)
stateDiagram.transitionEnd(Crash)
]
|> siren.withTitle("Simple sample")
|> siren.write

Composite

let First, Second, second, Third, third = "First", "Second", "second", "Third", "third"
siren.stateV2 [
stateDiagram.transition (stateDiagram.startEnd,First)
stateDiagram.stateComposite(First, [
stateDiagram.transition(stateDiagram.startEnd, Second)

stateDiagram.stateComposite(Second, [
stateDiagram.transition(stateDiagram.startEnd, second)
stateDiagram.transition(second, Third)

stateDiagram.stateComposite(Third, [
stateDiagram.transition(stateDiagram.startEnd, third)
stateDiagram.transition(third, stateDiagram.startEnd)
])
])
])
]
|> siren.write

Choice

let if_state, isPositive = "if_state", "IsPositive"
siren.stateV2 [
stateDiagram.stateChoice if_state
stateDiagram.transition(stateDiagram.startEnd, isPositive)
stateDiagram.transition(isPositive, if_state)
stateDiagram.transition(if_state, "False", "if n < 0")
stateDiagram.transition(if_state, "True", "if n >= 0")
]
|> siren.write

Fork

let fork_state, join_state, State2, State3, State4 = "fork_state", "join_state", "State2", "State3", "State4"
siren.stateV2 [
stateDiagram.stateFork fork_state
stateDiagram.transition(stateDiagram.startEnd, fork_state)
stateDiagram.transition(fork_state, State2)
stateDiagram.transition(fork_state, State3)
stateDiagram.stateJoin join_state
stateDiagram.transition(State2, join_state)
stateDiagram.transition(State3, join_state)
stateDiagram.transition(join_state, State4)
stateDiagram.transition(State4, stateDiagram.startEnd)
]
|> siren.write

Concurrency

let Active, NumLockOff, NumLockOn, CapsLockOff, CapsLockOn, ScrollLockOff, ScrollLockOn = 
"Active", "NumLockOff", "NumLockOn", "CapsLockOff", "CapsLockOn", "ScrollLockOff", "ScrollLockOn"
let EvNumLockPressed = "EvNumLockPressed"
let EvCapsLockPressed = "EvCapsLockPressed"
siren.state [
stateDiagram.transitionStart(Active)
stateDiagram.stateComposite(Active, [
stateDiagram.transitionStart(NumLockOff)
stateDiagram.transition(NumLockOff, NumLockOn, EvNumLockPressed)
stateDiagram.transition(NumLockOn, NumLockOff, EvNumLockPressed)
stateDiagram.concurrency
stateDiagram.transitionStart(CapsLockOff)
stateDiagram.transition(CapsLockOff, CapsLockOn, EvCapsLockPressed)
stateDiagram.transition(CapsLockOn, CapsLockOff, EvCapsLockPressed)
stateDiagram.concurrency
stateDiagram.transitionStart(ScrollLockOff)
stateDiagram.transition(ScrollLockOff, ScrollLockOn, "EvScrollLockPressed")
stateDiagram.transition(ScrollLockOn, ScrollLockOff, "EvScrollLockPressed")
])
]
|> siren.write

Direction

let A, B, C, D, a, b = "A", "B", "C", "D", "a", "b"
siren.state [
stateDiagram.direction direction.tb
stateDiagram.transitionStart(A)
stateDiagram.transition(A,B)
stateDiagram.transition(B,C)
stateDiagram.stateComposite(B, [
stateDiagram.direction direction.lr
stateDiagram.transition(a,b)
])
stateDiagram.transition(B,D)
]
|> siren.write

Comment

let A, B, C, D, a, b = "A", "B", "C", "D", "a", "b"
siren.state [
stateDiagram.direction direction.tb
stateDiagram.transitionStart(A)
stateDiagram.comment "This is a comment"
stateDiagram.transition(A,B)
stateDiagram.transition(B,C)
stateDiagram.stateComposite(B, [
stateDiagram.direction direction.lr
stateDiagram.transition(a,b + " " + formatting.comment "This is still a comment")
])
stateDiagram.transition(B,D)
]
|> siren.write