siren-hs is a Haskell library and CLI for building directed flowchart-style graphs and rendering them to SVG.
The project includes:
- A typed graph model in
src/Siren/Types.hs - A composable EDSL for graph construction in
src/Siren/EDSL.hs - Two layered layout engines:
- Sugiyama-like (
src/Siren/Layout/Sugiyama.hs) - Dagre-style (
src/Siren/Layout/Dagre.hs)
- Sugiyama-like (
- An SVG renderer based on
diagrams-svginsrc/Siren/Render/SVG.hs - A CLI application with sample graphs in
app/Main.hsandapp/Samples.hs
- Node shapes: rectangle, rounded rectangle, diamond
- Directed edges with optional labels
- Two layout strategies for hierarchical diagrams
- Layout direction support (
TopDown,LeftRight) in the library APIs - Batch rendering of all built-in sample graphs
This project uses Stack.
stack buildRun tests:
stack testThe executable expects a graph name and optionally a layout engine.
stack run -- GRAPH_NAME [--layout ENGINE]Short option for layout:
stack run -- GRAPH_NAME -l ENGINEWhere:
ENGINEissugiyama(default) ordagre- Output is written to
output/<graph>-<engine>.svg
samplebuggedchaindiamond-mergefan-incrossing-bipartitelong-labelmulti-source-sinkcycledense-layereddisconnectedladder
stack run -- sample
stack run -- long-label --layout dagrestack run -- allThis generates 24 SVG files (12 samples x 2 engines) in output/.
Import the top-level Siren module:
import SirenCommon convenience functions:
writeGraphSvg :: FilePath -> Direction -> Graph -> IO ()writeGraphSvgDagre :: FilePath -> Direction -> Graph -> IO ()writeGraphWith :: (LayoutEngine engine, RenderEngine renderer LaidOutGraph) => engine -> renderer -> FilePath -> Graph -> IO ()
Minimal example:
import Siren
main :: IO ()
main =
case buildGraph (node "start" "Start" <> node "end" "End" <> edge "start" "end") of
Left err -> putStrLn err
Right g -> writeGraphSvg "output/example.svg" TopDown gsrc/Siren.hs: top-level public APIsrc/Siren/Types.hs: core graph typessrc/Siren/EDSL.hs: graph construction DSLsrc/Siren/Layout/*.hs: layout engines and shared layout types/utilitiessrc/Siren/Render/SVG.hs: SVG rendering backendapp/Main.hs: CLI entry pointapp/Samples.hs: sample graphs used by the CLItest/: test suite (tasty,tasty-hunit,tasty-quickcheck)
This repository uses package.yaml (hpack) as the source of truth.
- Edit package metadata and dependencies in
package.yaml - Let Stack/hpack regenerate
siren-hs.cabal - Avoid manual edits to generated Cabal fields