jakesgordon / javascript-state-machine

A javascript finite state machine library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Where is the .dot file generated?

9enki opened this issue · comments

commented

I tried using the visualize function, but I can not find the .dot file. Perhaps .dot files may not have been created.

My code (a.js) is below same as sample of visualization.md

var StateMachine = require('javascript-state-machine');                                                                                                                                                                                                                                       
var visualize = require('javascript-state-machine/lib/visualize');                                                                                                                                                                                                                            
var fsm = new StateMachine({                                                                                                                                                                                                                                                                  
  init: 'open',                                                                                                                                                                                                                                                                               
  transitions: [                                                                                                                                                                                                                                                                              
    { name: 'close', from: 'open',   to: 'closed' },                                                                                                                                                                                                                                          
    { name: 'open',  from: 'closed', to: 'open'   }                                                                                                                                                                                                                                           
  ]                                                                                                                                                                                                                                                                                           
});                                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                              
visualize(fsm) 

And I ran the following command.

node a.js

I was expecting a.dot to be output in the same directory as a.js. However, the file was not output to the same directory, and I searched for other directories, but the dot file was not found. Am I misunderstanding how to use it?

You need to dump the result of visualize to a dot file explicitly.

// a.js
...
const result = visualize(fsm)
console.log(result)

Then you can run node a.js > out.dot.

commented

@xavierchow Thank you for your reply! I was able to get a dot file.