HTML5 canvas backend for diagrams drawing EDSL


Version on this page:
LTS Haskell 21.13:
Stackage Nightly 2023-09-27:
Latest on Hackage:

See all snapshots diagrams-canvas appears in

BSD-3-Clause licensed by Jeffrey Rosenbluth, Ryan Yates, Brent Yorgey, Andy Gill, Daniel Bergey
This version can be pinned in stack with:diagrams-canvas-,1802

Module documentation for


diagrams-canvas is a canvas backend for diagrams based on the blank-canvas https://github.com/ku-fpg/blank-canvas package. Diagrams is a powerful, flexible, declarative domain-specific language for creating vector graphics, using the Haskell programming language. It supports most features defined in diagrams-lib.


cabal update && cabal install diagrams-canvas


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

import Diagrams.Prelude
import Diagrams.Backend.Canvas.CmdLine

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 -threaded Square.hs

This will generate an executable which, when run dispays the resulting diagrams to http://localhost:3000/

$ ./Square -w 750

Changes (2 April 2015)

  • allow lens-4.9
  • allow vector-space-0.10 (13 Jan 2015)

  • Allow vector-space-0.9
  • Allow lens-4.7 (17 November 2014)

  • Allow lens-4.6 (8 October 2014)

  • Allow optparse-applicative-0.11
  • Allow NumInstances-1.4

0.3 (20 September 2014)

  • Allow & require blank-canvas-0.5.*
  • Allow text-1.2
  • Allow & require optparse-applicative-0.10.* (22 August 2014)

  • Allow lens-4.4