Skip to content

State Diagram Example

Sebi1006 edited this page Jun 8, 2021 · 1 revision

This is an example project of a state diagram.

Shape DSL

node startNode for StateMachine {
    edges {
        startToState
        startToRegion
    }
    style: startStyle
    sizeMin(width: 40, height: 40)
    sizeMax(width: 40, height: 40)
    resizing(horizontal: false, vertical: false, proportional: false)
    ellipse {
        size(width: 40, height: 40)
        position(x: 0, y: 0)
    }
}

node stateNode for State {
    edges {
        stateToState
        stateToRegion
        stateToFinal
    }
    style: stateStyle
    sizeMin(width: 100, height: 50)
    sizeMax(width: 300, height: 150)
    resizing(horizontal: true, vertical: true, proportional: true)
    roundedRectangle {
        size(width: 150, height: 75)
        position(x: 0, y: 0)
        curve(width: 1, height: 1)
        textfield {
            style: stateNameStyle
            identifier: StateName
            position(x: -30, y: 0)
            size(width: 100, height: 20)
            editable: true
            align(horizontal: middle, vertical: top)
        }
        textfield {
            style: stateMethodStyle
            identifier: entry
            position(x: 10, y: -15)
            size(width: 125, height: 15)
            editable: true
            align(horizontal: left, vertical: middle)
        }
        textfield {
            style: stateMethodStyle
            identifier: do
            position(x: 10, y: 0)
            size(width: 125, height: 15)
            editable: true
            align(horizontal: left, vertical: middle)
        }
        textfield {
            style: stateMethodStyle
            identifier: exit
            position(x: 10, y: 15)
            size(width: 125, height: 15)
            editable: true
            align(horizontal: left, vertical: middle)
        }
    }
}

node regionNode for Region {
    edges {
        regionToRegion
        regionToState
        regionToFinal
    }
    style: regionStyle
    sizeMin(width: 300, height: 150)
    sizeMax(width: 1000, height: 500)
    resizing(horizontal: true, vertical: true, proportional: false)
    roundedRectangle {
        size(width: 500, height: 250)
        position(x: 0, y: 0)
        curve(width: 1, height: 1)
        textfield {
            style: regionNameStyle
            identifier: RegionName
            position(x: -40, y: 0)
            size(width: 100, height: 20)
            editable: true
            align(horizontal: middle, vertical: top)
        }
    }
}

node finalNode for FinalState {
    edges {}
    style: finalStyle
    sizeMin(width: 40, height: 40)
    sizeMax(width: 40, height: 40)
    resizing(horizontal: false, vertical: false, proportional: false)
    ellipse {
        size(width: 40, height: 40)
        position(x: 0, y: 0)
    }
}

edge startToState for StateMachine.startToState {
    target: State
    style: defaultEdgeStyle
    placing {
        offset: 20.0
        polygon {
            style: arrowStyle
            point(x: 0, y: 0)
            point(x: 10, y: 5)
            point(x: 7, y: 0)
            point(x: 10, y: -5)
        }
    }
    placing {
        offset: 0.5
        textfield {
            style: edgeLabelStyle
            identifier: triggerActivity
            position(x: 0, y: 5)
            size(width: 150, height: 15)
            editable: true
            align(horizontal: middle, vertical: middle)
        }
    }
    placing {
        offset: 0.5
        textfield {
            style: edgeLabelStyle
            identifier: guard
            position(x: 0, y: -5)
            size(width: 150, height: 15)
            editable: true
            align(horizontal: middle, vertical: middle)
        }
    }
}

edge startToRegion for StateMachine.startToRegion {
    target: Region
    style: defaultEdgeStyle
    placing {
        offset: 20.0
        polygon {
            style: arrowStyle
            point(x: 0, y: 0)
            point(x: 10, y: 5)
            point(x: 7, y: 0)
            point(x: 10, y: -5)
        }
    }
    placing {
        offset: 0.5
        textfield {
            style: edgeLabelStyle
            identifier: triggerActivity
            position(x: 0, y: 5)
            size(width: 150, height: 15)
            editable: true
            align(horizontal: middle, vertical: middle)
        }
    }
    placing {
        offset: 0.5
        textfield {
            style: edgeLabelStyle
            identifier: guard
            position(x: 0, y: -5)
            size(width: 150, height: 15)
            editable: true
            align(horizontal: middle, vertical: middle)
        }
    }
}

edge regionToRegion for Region.regionToRegion {
    target: Region
    style: defaultEdgeStyle
    placing {
        offset: 20.0
        polygon {
            style: arrowStyle
            point(x: 0, y: 0)
            point(x: 10, y: 5)
            point(x: 7, y: 0)
            point(x: 10, y: -5)
        }
    }
    placing {
        offset: 0.5
        textfield {
            style: edgeLabelStyle
            identifier: triggerActivity
            position(x: 0, y: 5)
            size(width: 150, height: 15)
            editable: true
            align(horizontal: middle, vertical: middle)
        }
    }
    placing {
        offset: 0.5
        textfield {
            style: edgeLabelStyle
            identifier: guard
            position(x: 0, y: -5)
            size(width: 150, height: 15)
            editable: true
            align(horizontal: middle, vertical: middle)
        }
    }
}

edge regionToState for Region.regionToState {
    target: State
    style: defaultEdgeStyle
    placing {
        offset: 20.0
        polygon {
            style: arrowStyle
            point(x: 0, y: 0)
            point(x: 10, y: 5)
            point(x: 7, y: 0)
            point(x: 10, y: -5)
        }
    }
    placing {
        offset: 0.5
        textfield {
            style: edgeLabelStyle
            identifier: triggerActivity
            position(x: 0, y: 5)
            size(width: 150, height: 15)
            editable: true
            align(horizontal: middle, vertical: middle)
        }
    }
    placing {
        offset: 0.5
        textfield {
            style: edgeLabelStyle
            identifier: guard
            position(x: 0, y: -5)
            size(width: 150, height: 15)
            editable: true
            align(horizontal: middle, vertical: middle)
        }
    }
}

edge stateToState for State.stateToState {
    target: State
    style: defaultEdgeStyle
    placing {
        offset: 20.0
        polygon {
            style: arrowStyle
            point(x: 0, y: 0)
            point(x: 10, y: 5)
            point(x: 7, y: 0)
            point(x: 10, y: -5)
        }
    }
    placing {
        offset: 0.5
        textfield {
            style: edgeLabelStyle
            identifier: triggerActivity
            position(x: 0, y: 5)
            size(width: 150, height: 15)
            editable: true
            align(horizontal: middle, vertical: middle)
        }
    }
    placing {
        offset: 0.5
        textfield {
            style: edgeLabelStyle
            identifier: guard
            position(x: 0, y: -5)
            size(width: 150, height: 15)
            editable: true
            align(horizontal: middle, vertical: middle)
        }
    }
}

edge stateToRegion for State.stateToRegion {
    target: Region
    style: defaultEdgeStyle
    placing {
        offset: 20.0
        polygon {
            style: arrowStyle
            point(x: 0, y: 0)
            point(x: 10, y: 5)
            point(x: 7, y: 0)
            point(x: 10, y: -5)
        }
    }
    placing {
        offset: 0.5
        textfield {
            style: edgeLabelStyle
            identifier: triggerActivity
            position(x: 0, y: 5)
            size(width: 150, height: 15)
            editable: true
            align(horizontal: middle, vertical: middle)
        }
    }
    placing {
        offset: 0.5
        textfield {
            style: edgeLabelStyle
            identifier: guard
            position(x: 0, y: -5)
            size(width: 150, height: 15)
            editable: true
            align(horizontal: middle, vertical: middle)
        }
    }
}

edge stateToFinal for State.stateToFinal {
    target: FinalState
    style: defaultEdgeStyle
    placing {
        offset: 20.0
        polygon {
            style: arrowStyle
            point(x: 0, y: 0)
            point(x: 10, y: 5)
            point(x: 7, y: 0)
            point(x: 10, y: -5)
        }
    }
    placing {
        offset: 0.5
        textfield {
            style: edgeLabelStyle
            identifier: triggerActivity
            position(x: 0, y: 5)
            size(width: 150, height: 15)
            editable: true
            align(horizontal: middle, vertical: middle)
        }
    }
    placing {
        offset: 0.5
        textfield {
            style: edgeLabelStyle
            identifier: guard
            position(x: 0, y: -5)
            size(width: 150, height: 15)
            editable: true
            align(horizontal: middle, vertical: middle)
        }
    }
}

edge regionToFinal for Region.regionToFinal {
    target: FinalState
    style: defaultEdgeStyle
    placing {
        offset: 20.0
        polygon {
            style: arrowStyle
            point(x: 0, y: 0)
            point(x: 10, y: 5)
            point(x: 7, y: 0)
            point(x: 10, y: -5)
        }
    }
    placing {
        offset: 0.5
        textfield {
            style: edgeLabelStyle
            identifier: triggerActivity
            position(x: 0, y: 5)
            size(width: 150, height: 15)
            editable: true
            align(horizontal: middle, vertical: middle)
        }
    }
    placing {
        offset: 0.5
        textfield {
            style: edgeLabelStyle
            identifier: guard
            position(x: 0, y: -5)
            size(width: 150, height: 15)
            editable: true
            align(horizontal: middle, vertical: middle)
        }
    }
}

Style DSL

style startStyle {
    description = "Style for start node"
    line-color = black
    line-style = dashed
    line-width = 3
    background-color = black
}

style finalStyle {
    description = "Style for final node"
    line-color = black
    line-style = dashed
    line-width = 3
    background-color = white
}

style stateStyle {
    description = "Style for state"
    line-color = black
    line-style = dashed
    line-width = 3
    background-color = yellow
}

style regionStyle {
    description = "Style for region"
    line-color = black
    line-style = dashed
    line-width = 3
    background-color = lightblue
}

style stateNameStyle {
    description = "Style for state name"
    font-size = 12
    font-bold = true
    background-color = yellow
}

style regionNameStyle {
    description = "Style for region name"
    font-size = 12
    font-bold = true
    background-color = lightblue
}

style stateMethodStyle {
    description = "Style for state methods"
    font-size = 11
    font-italic = true
    background-color = yellow
}

style edgeLabelStyle {
    description = "Style for edge labels"
    font-size = 10
    background-color = white
}

style defaultEdgeStyle {
    description = "Style for default edge"
    line-width = 1
    line-color = black
}

style arrowStyle {
    description = "Style for arrow"
    line-width = 3
    background-color = black
}

Diagram DSL

diagram stateDiagram {
    palette node {
        startNode
        regionNode
        stateNode
        finalNode
    }
}

Model Instance Editor Examples

Example 1

State Diagram Model Instance Editor Example 1

Example 2

State Diagram Model Instance Editor Example 2