sverweij / state-machine-cat

write beautiful state charts :scream_cat:
https://state-machine-cat.js.org
MIT License
793 stars 45 forks source link

Export to png and pdf option #165

Closed ambagasdowa closed 1 year ago

ambagasdowa commented 1 year ago

There is posible to have this feature ?

Context

there will be nice to export directly from smcat im doing it with pipe to rsvg-convert
smcat file.smcat | rsvg-convert | img-viewer

pipe

Proposed Behavior

add png and pdf export option with -o switch in smcat cli

Considered alternatives

im using this rsvg-convert

i found a lib in node rsvg

sverweij commented 1 year ago

hi @ambagasdowa - thanks for raising this issue. It's possible to emit png (and maybe even pdf) with the options already available in the underlying render engine (GraphViz). In state-machine-cat it means a bit of code shuffling to support a binary output format - I'll put it on the backlog.

You can already emulate exactly what the output will be with:

smcat yourdiagram.smcat --output-type dot --output-to - | dot -T png > yourdiagram.png
sverweij commented 1 year ago

Hi @ambagasdowa I've published a beta on npm (state-machine-cat@10.1.0-beta-1 - shasum ba8f7e03e0d45ea65bc8ae88e2fc3891585aa081) that outputs png and pdf - provided you use the command line version, and the command line version has the native GraphViz dot at its disposal.

What that version this should work:

smcat yourdiagram.smcat --output-type png --output-to yourdiagram.png

It still needs additional unit tests and error handling for when the fallback engine (viz.js) needs to be used because graphviz dot isn't available, but it's functional.

Could you let me know how it works for you?

ambagasdowa commented 1 year ago

It's just great, I have been testing it and it works great. I will keep testing to inform you of any eventuality.

test

sverweij commented 1 year ago

Hi @ambagasdowa thanks for confirming :-). I've added non-regression tests & handling for the fall back for GraphViz - so I'm going to merge the PR and release a new version.

sverweij commented 1 year ago

published as part of state-machine-cat@10.1.0