davidje13 / SequenceDiagram

Javascript tool for generating sequence diagrams from code
https://sequence.davidje13.com/
GNU Lesser General Public License v3.0
123 stars 39 forks source link

support rendering without a DOM #32

Closed davidje13 closed 6 years ago

davidje13 commented 6 years ago

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 and setAttribute defined), but the difficulty is measuring text (which is necessary for deciding positions of agents, size of boxes, etc.)

davidje13 commented 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

davidje13 commented 6 years ago

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.

davidje13 commented 6 years ago

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).