Copyright | (c) 2011-2012 diagrams-svg team (see LICENSE) |
---|---|

License | BSD-style (see LICENSE) |

Maintainer | diagrams-discuss@googlegroups.com |

Safe Haskell | None |

Language | Haskell2010 |

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`

.

# Documentation

`SVG`

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

Show SVG | |

Typeable * SVG | |

Renderable Text SVG | |

Backend SVG R2 | |

Mainable [(String, Diagram SVG R2)] | |

Renderable (DImage Embedded) SVG | |

Renderable (Path R2) SVG | |

Monoid (Render SVG R2) | |

Hashable (Options SVG R2) | |

Mainable (Diagram SVG R2) | |

type Result SVG R2 = Svg | |

data Render SVG R2 = R SvgRenderM | |

data Options SVG R2 = SVGOptions {- _size :: SizeSpec2D
- _svgDefinitions :: Maybe Svg
| |

type MainOpts [(String, Diagram SVG R2)] = (MainOpts (Diagram SVG R2), DiagramMultiOpts) | |

type MainOpts (Diagram SVG R2) = (DiagramOpts, DiagramLoopOpts) |