diagrams-svg-0.8.0.2: SVG backend for diagrams drawing EDSL.

Maintainer | diagrams-discuss@googlegroups.com
Safe Haskell | None

Diagrams.Backend.SVG

Description

A full-featured rendering backend for diagrams producing SVG files, implemented natively in Haskell (making it easy to use on any platform).

To invoke the SVG backend, you have three options.

- You can use the Diagrams.Backend.SVG.CmdLine module to create standalone executables which output SVG images when invoked.
- You can use the `renderSVG` function provided by this module, which gives you more flexible programmatic control over when and how images are output (making it easy to, for example, write a single program that outputs multiple images, or one that outputs images dynamically based on user input, and so on).
- For the most flexibility (e.g. if you want access to the resulting SVG value directly in memory without writing it to disk), you can manually invoke the `renderDia` method from the `Backend` instance for `SVG`. In particular, `renderDia` has the generic type

     renderDia :: b -> Options b v -> QDiagram b v m -> Result b v

(omitting a few type class constraints). `b` represents the backend type, `v` the vector space, and `m` the type of monoidal query annotations on the diagram. `Options` and `Result` are associated data and type families, respectively, which yield the type of option records and rendering results specific to any particular backend. For `b ~ SVG` and `v ~ R2`, we have

     data Options SVG R2 = SVGOptions
                           { size :: SizeSpec2D   -- ^ The requested size.
                           , svgDefinitions :: Maybe S.Svg
                           -- ^ Custom definitions that will be added to the @defs@
                           --  section of the output.
                           }

     data family Render SVG R2 = R SvgRenderM

     type family Result SVG R2 = Svg

So the type of `renderDia` resolves to

     renderDia :: SVG -> Options SVG R2 -> QDiagram SVG R2 m -> Svg

which you could call like `renderDia SVG (SVGOptions (Width 250)) myDiagram`. (In some situations GHC may not be able to infer the type `m`, in which case you can use a type annotation to specify it; it may be useful to simply use the type synonym `Diagram SVG R2 = QDiagram SVG R2 Any`.) This returns an `Svg` value, which you can, e.g. render to a `ByteString` using `renderSvg`.

Synopsis

- data SVG = SVG
- data family Options b1 v1
- renderSVG :: FilePath -> SizeSpec2D -> Diagram SVG R2 -> IO ()

# Documentation

data SVG Source

`SVG` is simply a token used to identify this rendering backend (to aid type inference).

Constructors

SVG |

Instances

Show SVG |
Typeable SVG |
Backend SVG R2 |
Renderable Text SVG |
Renderable (Path R2) SVG |
Renderable (Trail R2) SVG |
Show (Options SVG R2) |
Monoid (Render SVG R2) |
Renderable (Segment Closed R2) SVG |

data family Options b1 v1

Backend-specific rendering options.

renderSVG :: FilePath -> SizeSpec2D -> Diagram SVG R2 -> IO ()Source

Render a diagram as an SVG, writing to the specified output file and using the requested size.