diagrams-svg

SVG backend for diagrams drawing EDSL.

http://projects.haskell.org/diagrams/

Version on this page:1.4.3@rev:2
LTS Haskell 22.36:1.4.3.2
Stackage Nightly 2024-10-03:1.4.3.2
Latest on Hackage:1.4.3.2

See all snapshots diagrams-svg appears in

BSD-3-Clause licensed by Felipe Lessa, Deepak Jois
Maintained by [email protected]
This version can be pinned in stack with:diagrams-svg-1.4.3@sha256:36708b0b4cf35507ccf689f1a25f6f81b8f41c2c4c2900793de820f66d4e241c,3181

Module documentation for 1.4.3

diagrams-svg Hackage Build Status

diagrams-svg is a an SVG backend for diagrams. Diagrams is a powerful, flexible, declarative domain-specific language for creating vector graphics, using the Haskell programming language.

diagrams-svg is the default out-of-the box backend that comes with the diagrams framework, and supports most features defined in diagrams-lib.

Installation

cabal update && cabal install diagrams-svg

Usage

A simple example that uses diagrams-svg to draw a square.

import Diagrams.Prelude
import Diagrams.Backend.SVG.CmdLine

b1 :: Diagram B
b1 = square 20 # lw 0.002

main = mainWith (pad 1.1 b1)

Save this to file named Square.hs and compile this program:

ghc --make Square.hs

This will generate an executable which, when run produces an SVG file. Run the executable with the --help option to find out more about how to call it.

$ ./Square --help
./Square

Usage: ./Square [-w|--width WIDTH] [-h|--height HEIGHT] [-o|--output OUTPUT] [--loop] [-s|--src ARG] [-i|--interval INTERVAL]
  Command-line diagram generation.

Available options:
  -?,--help                Show this help text
  -w,--width WIDTH         Desired WIDTH of the output image
  -h,--height HEIGHT       Desired HEIGHT of the output image
  -o,--output OUTPUT       OUTPUT file
  -l,--loop                Run in a self-recompiling loop
  -s,--src ARG             Source file to watch
  -i,--interval INTERVAL   When running in a loop, check for changes every INTERVAL seconds.
  -p,--pretty              Pretty print the SVG output

You must pass an output file name with a .svg extension to generate the SVG file.

$ ./Square -o square.svg

The command above generates the SVG file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
    "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="22.0" height="22.0" viewBox="0 0 22 22">
  <g>
    <g stroke="rgb(0,0,0)" stroke-opacity="1.0" fill="rgb(0,0,0)" fill-opacity="0.0" stroke-width="2.0e-3">
       <path d="M 21.0,21.0 l -2.220446049250313e-15,-20.0 h -20.0 l -2.220446049250313e-15,20.0 Z" />
    </g>
  </g>
</svg>

Changes

v1.4.3 (2019-12-10)

  • Allow base-4.13 (GHC 8.8), lens-4.18, semigroups-0.19, hashable-1.3, optparse-applicative-0.15
  • Stop rounding the coordinates of the viewbox (#109)
  • New svgClass, svgId, and svgTitle functions for setting SVG attributes via annotations

v1.4.2 (2018-05-09)

  • Allow base-4.11 (GHC 8.4) and lens-4.16
  • Add Semigroup (Render SVG V2 n) instance

v1.4.1.1 (2017-08-23)

  • Allow base-4.10 and optparse-applicative-0.14
  • Fix gradients applied to text (#98)

v1.4.1 (2016-10-26)

  • Handle wider range of font weight specifications
  • allow lens-4.15

v1.4.0.4 (2016-08-22)

  • Require optparse-applicative-0.13, and fix compilation error

v1.4.0.3 (2016-08-16)

  • Allow optparse-applicative-0.13

v1.4.0.2 (2016-06-06)

  • allow base-4.9
  • test with GHC 8.0
  • minor documentation updates

v1.4.0.1 (2016-05-01)

  • allow lens-4.14

v1.4 (2016-02-14)

– Changes for svg-builder – Deprecate svgId and svgClass

v1.3.1.8 (2015-11-14)

  • allow lucid-svg-0.6

v1.3.1.7 (2015-11-10)

  • allow semigroups-0.18

Full Changelog

v1.3.1.6 (2015-09-29)

  • allow optparse-applicative-0.12

Full Changelog

v1.3.1.5 (2015-09-19)

  • allow lens-4.13 and semigroups-0.17

Full Changelog

v1.3.1.4 (2015-07-19)

Full Changelog

v1.3.1.3 (2015-07-09)

  • Changes to allow lucid-svg-0.5

v1.3.1.2 (2015-05-26)

Full Changelog

v1.3.1.1 (2015-05-06)

Bug Fix: handle empty dashing array properly (#80)

v1.3.1 (2015-04-30)

API Changes

  • Type of SVGOptions changed. _svgDefinitions :: Maybe SvgM

Internal Changes

  • Use ReaderT for styles

v1.3 (2015-04-19)

Full Changelog

New features

  • User settable ID prefixes

  • Support opacity group

  • Fix clipping bug (Issue #70)

Internal Changes

  • Switch rendering engine from blaze-svg to lucid-svg

  • Use fsnotify for looping

  • Add defs tags for clips and gradients

Implemented enhancements:

  • Put clip path, gradients, etc in defs tag. #73

Fixed bugs:

  • Font size not applied properly in composite diagram #66

  • clipping broken #70

Merged pull requests:

v1.1.0.5 (2015-04-03)

  • allow lens-4.9

  • allow vector-space-0.10

  • allow blaze-markup-0.7

v1.1.0.4 (2015-01-13)

Full Changelog

v1.1.0.3 (2014-12-07)

Full Changelog

v1.1.0.2 (2014-11-17)

Full Changelog

Fixed bugs:

  • Font scaling uses “em” units. #30

Merged pull requests:

v1.1.0.1 (2014-08-22)

Full Changelog

Closed issues:

  • Embedding JPEG images without repacking #57

Merged pull requests:

  • Enable compilation with GHC HEAD (v7.9) #60 (ggreif)

  • Add loadImageSVG to support JPEG-images without repacking via Native DImages #58 (taruti)

  • Allow svg output file to be pretty printed #56 (jeffreyrosenbluth)

v1.1 (2014-06-02)

Full Changelog

New features

  • Support for radial and linear gradients.

  • Support for embedded images in .png format.

New instances

  • Renderable instances for DImage Embedded.

API changes

  • Updates to work with Measure units.

  • Substantial refactoring of Backend instance to support changes in Diagrams.Core.

Dependency/version changes

  • New dependencies: base64-bytestring and JuicyPixels.

  • Allow lens-4.2

  • Allow mtl-2.2

Closed issues:

  • Support hyperlinks #48

  • Line width not handled properly by some browsers #33

  • implement image embedding #11

Merged pull requests:

v1.0.2.1 (2014-03-19)

Full Changelog

v1.0.2 (2014-03-09)

Full Changelog

New features

  • Support for including hyperlinks.

Dependency/version changes

  • Allow diagrams-core-1.1 and diagrams-lib-1.1

  • Allow lens-4.0

Bug fixes

  • Use splitFills to properly render certain diagrams with mixed lines and filled loops. Previously, in certain situations loops that should have been filled were not. (#43)

  • Don’t emit last segment of a loop if it is linear.

    See diagrams-cairo#38. This wasn’t actually causing any observable problems in the SVG backend output, but this seems a better/more robust way to do things in any case.

Closed issues:

  • SVG backend doesn’t fill loops if they occur in the same subtree as a line #43

Merged pull requests:

  • Hyperlinks #49 (tdox)

  • stop using ignoreFill; use splitFills instead. Fixes #43. #47 (byorgey)

v1.0.1.3 (2014-02-06)

Full Changelog

v1.0.1.2 (2014-02-04)

Full Changelog

v1.0.1.1 (2014-01-30)

Full Changelog

v1.0.1 (2014-01-26)

Full Changelog

Merged pull requests:

  • Add Hashable instance for Options SVG R2 #45 (byorgey)

v1.0 (2013-11-25)

According to the PVP, these changes should require a major version bump. However, a major version bump would be quite annoying and I don’t expect these instance changes to affect anyone (the changes were made for internal reasons). Please yell if it does affect you.

Full Changelog

Fixed bugs:

  • SVG backend fills lines again #42

v0.8.0.2 (2013-10-26)

Full Changelog

Closed issues:

  • Text alignment support #17

  • Add a workaround for the Chrome stroke-width 0 bug #3

Merged pull requests:

v0.8.0.1 (2013-09-11)

Full Changelog

v0.8 (2013-09-10)

Full Changelog

New features

  • Extra SVG definitions, to be inserted in the output, may be passed as an argument

  • Support for new miter limit attribute

  • Approximate text alignment

Bug fixes

  • Stacking multiple clip regions now works properly

Merged pull requests:

  • Font embedding changes #38 (jbracker)

  • Added approximation of text alignment. Better then nothing… #36 (jbracker)

v0.7 (2013-08-09)

Full Changelog

New features

  • New renderToSVG convenience function

  • Vastly improved Haddock documentation

New instances

  • Show instance for Options SVG R2

Dependency/version changes

  • allow base-4.7 and unix-2.7

  • Upgrade to monoid-extras-0.3

Implemented enhancements:

  • Improve Haddock documentation #27

Fixed bugs:

  • Lines should not be filled #35

Closed issues:

  • diagrams-svg.cabal out of sync with core and lib #34

  • Add function of type FilePath -> SizeSpec2D -> Diagram -> IO () #28

Merged pull requests:

  • General SVG backend cleanup, additional documentation, and new API function #29 (byorgey)

v0.6.0.1 (2012-12-14)

Full Changelog

v0.6 (2012-12-12)

First “officially supported” release.

Features still not implemented:

  • text alignment

  • inline images

As of this release everything else Should Work (tm).

Closed issues:

  • Line width does not follow specification? #24

  • diagrams-svg doesn’t build under directory-1.2 (and hence GHC-7.6) #20

  • Freezing does not appear to work with the SVG backend #19

  • Font family support #18

  • Fill color needs to be explicitly specified for text nodes #15

  • Implement clipping #14

  • Add README, documentation and generate documentation on Hackage #13

  • implement text attributes #10

  • implement text rendering #9

  • implement line cap #8

  • implement line dashing #7

  • Implement line join attribute #6

  • Implement opacity #5

  • Implement fill rule #4

  • Switch to using blaze-svg combinators #2

  • Create a new branch for using blaze-svg #1

Merged pull requests:

* This Change Log was automatically generated by (and hand edited) github_changelog_generator