Closed davidje13 closed 6 years ago
Once SVG generation is supported, https://github.com/aheckmann/gm may be useful for SVG to PNG. This would be useful for server-side applications and allow automatic generation of screenshots via an npm
command
Text measurement can be achieved using https://github.com/nodebox/opentype.js
This will require having sans-serif & monospace fonts available at runtime, and might be able to work with the existing woff2-formatted Handlee font (claims support for woff, which might include woff2…) — possible source: https://pagure.io/liberation-fonts
Specifically, getAdvanceWidth
should serve this purpose.
There is now a proof-of-concept executable included with the project which is able to generate SVGs from the commandline. Usage:
node bin/sequence-diagram-svg > file.svg
(Enter code to stdin then press Ctrl+D to close the stream)
This is built around the newly added VirtualSequenceDiagram
, which wraps the necessary setup for a browserless render (using VirtualDocument
and VirtualTextSizer
).
In some situations it is desirable to be able to render SVG code without a DOM (e.g. server-side rendering).
Most areas should convert easily by providing a mocked DOM (with e.g.
appendChild
andsetAttribute
defined), but the difficulty is measuring text (which is necessary for deciding positions of agents, size of boxes, etc.)