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

Copyright | (c) 2011-2015 diagrams-svg team (see LICENSE)
License | BSD-style (see LICENSE)
Maintainer | diagrams-discuss@googlegroups.com
Safe Haskell | None
Language | Haskell2010

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` or `renderPretty` functions provided by this module, which give 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). The only difference between the two functions is that `renderPretty`, pretty prints the SVG output.
- 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 n -> QDiagram b v n m -> Result b v n

(omitting a few type class constraints). `b` represents the backend type, `v` the vector space, `n` the numerical field, 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`, `v ~ V2`, we have

    data    Options SVG V2 n = SVGOptions
        { _size            :: SizeSpec V2 n   -- ^ The requested size.
        , _svgDefinitions  :: Maybe Element
                              -- ^ Custom definitions that will be added to the @defs@
                              --   section of the output.
        , _idPrefix        :: T.Text
        , _svgAttributes   :: [Attribute]
                              -- ^ Attriubtes to apply to the entire svg element.
        , _generateDoctype :: Bool
        }

    data family Render SVG V2 n = R 'SvgRenderM n'

    type family Result SVG V2 n = Element

So the type of `renderDia` resolves to

    renderDia :: SVG -> Options SVG V2 n -> QDiagram SVG V2 n m -> Element

which you could call like `renderDia SVG (SVGOptions (mkWidth 250) Nothing "" [] True) myDiagram` (if you have the `OverloadedStrings` extension enabled; otherwise you can use 'Text.pack ""'). (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 = QDiagram SVG V2 Double Any`.) This returns an `Element` value, which you can, e.g. render to a `ByteString` using `renderBS` from the 'svg-builder' package.

Synopsis

- data SVG = SVG
- type B = SVG
- data family Options b (v :: Type -> Type) n :: Type
- sizeSpec :: Lens' (Options SVG V2 n) (SizeSpec V2 n)
- svgDefinitions :: Lens' (Options SVG V2 n) (Maybe Element)
- idPrefix :: Lens' (Options SVG V2 n) Text
- svgAttributes :: Lens' (Options SVG V2 n) [Attribute]
- generateDoctype :: Lens' (Options SVG V2 n) Bool
- type SVGFloat n = (Show n, TypeableFloat n)
- renderSVG :: SVGFloat n => FilePath -> SizeSpec V2 n -> QDiagram SVG V2 n Any -> IO ()
- renderSVG' :: SVGFloat n => FilePath -> Options SVG V2 n -> QDiagram SVG V2 n Any -> IO ()
- renderPretty :: SVGFloat n => FilePath -> SizeSpec V2 n -> QDiagram SVG V2 n Any -> IO ()
- renderPretty' :: SVGFloat n => FilePath -> Options SVG V2 n -> QDiagram SVG V2 n Any -> IO ()
- loadImageSVG :: SVGFloat n => FilePath -> IO (QDiagram SVG V2 n Any)

# Documentation

data SVG Source #

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

Constructors

SVG |

Instances

Show SVG Source # |
Instance details Defined in Diagrams.Backend.SVG Methods showsPrec :: Int -> SVG -> ShowS Source # show :: SVG -> String Source # showList :: [SVG] -> ShowS Source #
SVGFloat n => Backend SVG V2 n Source # |

Instance details

Defined in Diagrams.Backend.SVG

Associated Types

data Render SVG V2 n :: Type Source #

type Result SVG V2 n :: Type Source #

data Options SVG V2 n :: Type Source #

Methods

adjustDia :: (Additive V2, Monoid' m, Num n) => SVG -> Options SVG V2 n -> QDiagram SVG V2 n m -> (Options SVG V2 n, Transformation V2 n, QDiagram SVG V2 n m) Source #

renderRTree :: SVG -> Options SVG V2 n -> RTree SVG V2 n Annotation -> Result SVG V2 n Source #

SVGFloat n => Mainable [(String, QDiagram SVG V2 n Any)] Source # |

Instance details

Defined in Diagrams.Backend.SVG.CmdLine

Associated Types

type MainOpts [(String, QDiagram SVG V2 n Any)] :: Type Source #

Methods

mainArgs :: [(String, QDiagram SVG V2 n Any)] -> IO (MainOpts [(String, QDiagram SVG V2 n Any)]) Source #

mainRender :: MainOpts [(String, QDiagram SVG V2 n Any)] -> [(String, QDiagram SVG V2 n Any)] -> IO () Source #

mainWith :: [(String, QDiagram SVG V2 n Any)] -> IO () Source #

SVGFloat n => Renderable (Text n) SVG Source # |
Instance details Defined in Diagrams.Backend.SVG Methods render :: SVG -> Text n -> Render SVG (V (Text n)) (N (Text n)) Source #
SVGFloat n => Renderable (DImage n Embedded) SVG Source # |
Instance details Defined in Diagrams.Backend.SVG Methods render :: SVG -> DImage n Embedded -> Render SVG (V (DImage n Embedded)) (N (DImage n Embedded)) Source #
SVGFloat n => Renderable (Path V2 n) SVG Source # |
Instance details Defined in Diagrams.Backend.SVG Methods render :: SVG -> Path V2 n -> Render SVG (V (Path V2 n)) (N (Path V2 n)) Source #
Semigroup (Render SVG V2 n) Source # |
Instance details Defined in Diagrams.Backend.SVG Methods (<>) :: Render SVG V2 n -> Render SVG V2 n -> Render SVG V2 n Source # sconcat :: NonEmpty (Render SVG V2 n) -> Render SVG V2 n Source # stimes :: Integral b => b -> Render SVG V2 n -> Render SVG V2 n Source #
Monoid (Render SVG V2 n) Source # |
Instance details Defined in Diagrams.Backend.SVG Methods mempty :: Render SVG V2 n Source # mappend :: Render SVG V2 n -> Render SVG V2 n -> Render SVG V2 n Source # mconcat :: [Render SVG V2 n] -> Render SVG V2 n Source #
Hashable n => Hashable (Options SVG V2 n) Source # |
Instance details Defined in Diagrams.Backend.SVG Methods hashWithSalt :: Int -> Options SVG V2 n -> Int Source # hash :: Options SVG V2 n -> Int Source #
SVGFloat n => Mainable (QDiagram SVG V2 n Any) Source # |
Instance details Defined in Diagrams.Backend.SVG.CmdLine Associated Types type MainOpts (QDiagram SVG V2 n Any) :: Type Source # Methods mainArgs :: QDiagram SVG V2 n Any -> IO (MainOpts (QDiagram SVG V2 n Any)) Source # mainRender :: MainOpts (QDiagram SVG V2 n Any) -> QDiagram SVG V2 n Any -> IO () Source # mainWith :: QDiagram SVG V2 n Any -> IO () Source #
type V SVG Source # |
Instance details Defined in Diagrams.Backend.SVG type V SVG = V2
type N SVG Source # |
Instance details Defined in Diagrams.Backend.SVG type N SVG = Double
data Options SVG V2 n Source # |

Instance details

Defined in Diagrams.Backend.SVG

data Options SVG V2 n = SVGOptions {

- _size :: SizeSpec V2 n
- _svgDefinitions :: Maybe Element
- _idPrefix :: Text
- _svgAttributes :: [Attribute]
- _generateDoctype :: Bool

}

newtype Render SVG V2 n Source # |
Instance details Defined in Diagrams.Backend.SVG newtype Render SVG V2 n = R (SvgRenderM n)
type Result SVG V2 n Source # |
Instance details Defined in Diagrams.Backend.SVG type Result SVG V2 n = Element
type MainOpts [(String, QDiagram SVG V2 n Any)] Source # |
Instance details Defined in Diagrams.Backend.SVG.CmdLine type MainOpts [(String, QDiagram SVG V2 n Any)] = (MainOpts (QDiagram SVG V2 n Any), DiagramMultiOpts)
type MainOpts (QDiagram SVG V2 n Any) Source # |
Instance details Defined in Diagrams.Backend.SVG.CmdLine type MainOpts (QDiagram SVG V2 n Any)

type B = SVG Source #

data family Options b (v :: Type -> Type) n :: Type Source #

Backend-specific rendering options.

Instances

Hashable n => Hashable (Options SVG V2 n) Source # |
Instance details Defined in Diagrams.Backend.SVG Methods hashWithSalt :: Int -> Options SVG V2 n -> Int Source # hash :: Options SVG V2 n -> Int Source #
data Options NullBackend v n |
Instance details Defined in Diagrams.Core.Types data Options NullBackend v n
data Options SVG V2 n Source # |

Instance details

Defined in Diagrams.Backend.SVG

data Options SVG V2 n = SVGOptions {

- _size :: SizeSpec V2 n
- _svgDefinitions :: Maybe Element
- _idPrefix :: Text
- _svgAttributes :: [Attribute]
- _generateDoctype :: Bool

}

sizeSpec :: Lens' (Options SVG V2 n) (SizeSpec V2 n) Source #

Lens onto the size of the svg options.

svgDefinitions :: Lens' (Options SVG V2 n) (Maybe Element) Source #

Lens onto the svg definitions of the svg options.

idPrefix :: Lens' (Options SVG V2 n) Text Source #

Lens onto the idPrefix of the svg options. This is the prefix given to clipping paths to distinguish them from other svg files in the same web page.

svgAttributes :: Lens' (Options SVG V2 n) [Attribute] Source #

Lens onto the svgAttributes field of the svg options. This field is provided to supply SVG attributes to the entire diagram.

generateDoctype :: Lens' (Options SVG V2 n) Bool Source #

Lens onto the generateDoctype field of the svg options. Set to False if you don't want a doctype tag included in the output.

type SVGFloat n = (Show n, TypeableFloat n) Source #

Constaint on number type that diagrams-svg can use to render an SVG. This includes the common number types: Double, Float

renderSVG :: SVGFloat n => FilePath -> SizeSpec V2 n -> QDiagram SVG V2 n Any -> IO () Source #

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

renderSVG' :: SVGFloat n => FilePath -> Options SVG V2 n -> QDiagram SVG V2 n Any -> IO () Source #

Render a diagram as an SVG, writing to the specified output file and using the backend options. The id prefix is derived from the basename of the output file.

renderPretty :: SVGFloat n => FilePath -> SizeSpec V2 n -> QDiagram SVG V2 n Any -> IO () Source #

Render a diagram as a pretty printed SVG.

renderPretty' :: SVGFloat n => FilePath -> Options SVG V2 n -> QDiagram SVG V2 n Any -> IO () Source #

Render a diagram as a pretty printed SVG to the specified output file and using the backend options. The id prefix is derived from the basename of the output file.

loadImageSVG :: SVGFloat n => FilePath -> IO (QDiagram SVG V2 n Any) Source #

Load images (JPGPNG...) in a SVG specific way.