xstate-plantuml

0.5.0 • Public • Published

xstate-plantuml

npm Travis

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

Try online

Installation

npm install xstate-plantuml

Usage

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

import visualize from 'xstate-plantuml';
 
const config = {
  key: 'light',
  initial: 'green',
  states: {
    green: {
      on: {
        TIMER: 'red'
      }
    },
    red: {
      on: {
        TIMER: 'green'
      }
    }
  }
};
 
visualize(config);

Which returns a string containing the following plantuml source

@startuml
left to right direction
state "light" as light {
  [*] --> light.green
 
  state "green" as light.green {
    light.green --> light.red : TIMER
  }
 
  state "red" as light.red {
    light.red --> light.green : TIMER
  }
}
@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

visualize(config, {
  leftToRight: false,
  skinParams: ['monochrome true']
});
@startuml
skinparam monochrome true
 
state "light" as light {
  [*] --> light.green
 
  state "green" as light.green {
    light.green --> light.red : TIMER
  }
 
  state "red" as light.red {
    light.red --> light.green : TIMER
  }
}
@enduml

compiles to

options

Examples

Hierarchical state

alarm

Parallel state

text-editor

History state

payment

Internal transitions

word

Guards, actions and activities

download

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.5.0600latest

Version History

VersionDownloads (Last 7 Days)Published
0.5.0600
0.4.5135
0.4.42
0.4.315
0.4.23
0.4.11
0.4.01
0.3.11
0.3.01
0.2.01
0.1.11
0.1.01

Package Sidebar

Install

npm i xstate-plantuml

Weekly Downloads

762

Version

0.5.0

License

MIT

Unpacked Size

81.2 kB

Total Files

29

Last publish

Collaborators

  • lucmartens