项目作者: lucmartens

项目描述 :
Visualize a xstate or react-automata statechart as a plantuml state diagram
高级语言: JavaScript
项目地址: git://github.com/lucmartens/xstate-plantuml.git
创建时间: 2018-08-25T12:17:47Z
项目社区:https://github.com/lucmartens/xstate-plantuml

开源协议:MIT License

下载


xstate-plantuml

npm
Travis

Visualize a xstate or react-automata statechart as a plantuml state diagram.

Try online

Installation

  1. npm install xstate-plantuml

Usage

import xstate-plantuml and call it’s default export using a xstate config or machine

  1. import visualize from 'xstate-plantuml';
  2. const config = {
  3. key: 'light',
  4. initial: 'green',
  5. states: {
  6. green: {
  7. on: {
  8. TIMER: 'red'
  9. }
  10. },
  11. red: {
  12. on: {
  13. TIMER: 'green'
  14. }
  15. }
  16. }
  17. };
  18. visualize(config);

Which returns a string containing the following plantuml source

  1. @startuml
  2. left to right direction
  3. state "light" as light {
  4. [*] --> light.green
  5. state "green" as light.green {
  6. light.green --> light.red : TIMER
  7. }
  8. state "red" as light.red {
  9. light.red --> light.green : TIMER
  10. }
  11. }
  12. @enduml

Which you can render to the following image

usage

Options

In addition to a state machine, visualize accepts an options map

option default description
leftToRight true whether to render left to right or top to bottom
skinParams [] Additional skinparams to include

Our previous example with different options

  1. visualize(config, {
  2. leftToRight: false,
  3. skinParams: ['monochrome true']
  4. });
  1. @startuml
  2. skinparam monochrome true
  3. state "light" as light {
  4. [*] --> light.green
  5. state "green" as light.green {
  6. light.green --> light.red : TIMER
  7. }
  8. state "red" as light.red {
  9. light.red --> light.green : TIMER
  10. }
  11. }
  12. @enduml

compiles to

options

Examples

Hierarchical state

alarm

Parallel state

text-editor

History state

payment

Internal transitions

word

Guards, actions and activities

download