1

The quickstart for the diagrams package tells me to compile and run the following program:

{-# LANGUAGE NoMonomorphismRestriction #-}

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

main = mainWith (circle 1 :: Diagram B)

It them claims:

If you now view circle.svg in your favorite web browser, you should see circle

However, it doesn't. What I actually see is this:

crop circle

Notice the cropped edges of the diagram. This is because the line has a width, but the image is being cropped with the assumption of the line having no width.

Here is the SVG output:

<?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" 
    height="200.0000" stroke-opacity="1" 
    viewBox="0 0 200 200" 
    font-size="1" 
    width="200.0000" 
    xmlns:xlink="http://www.w3.org/1999/xlink" 
    stroke="rgb(0,0,0)" 
    version="1.1">
  <defs></defs>
  <g
      stroke-linejoin="miter" 
      stroke-opacity="1.0" 
      fill-opacity="0.0" 
      stroke="rgb(0,0,0)" 
      stroke-width="0.8" 
      fill="rgb(0,0,0)" 
      stroke-linecap="butt" 
      stroke-miterlimit="10.0">
    <path 
      d="M 200.0000,100.0000 c 0.0000,-55.2285 -44.7715,-100.0000 -100.0000 -100.0000c -55.2285,-0.0000 -100.0000,44.7715 -100.0000 100.0000c -0.0000,55.2285 44.7715,100.0000 100.0000 100.0000c 55.2285,0.0000 100.0000,-44.7715 100.0000 -100.0000Z"
    />
  </g>
</svg>

How can I tell diagrams to take the width of the line into account when defining the envelope of the diagram?

jameshfisher
  • 34,029
  • 31
  • 121
  • 167
  • 1
    Can't reproduce. The SVG certainly is _not_ cropped, at worst the browser crops the output it renders from it. And `frame` _does_ add a margin so even this won't happen (at least in recent versions; I tried it with `diagrams-1.3.0.1`). – leftaroundabout Jun 03 '16 at 23:08

1 Answers1

0

Sorry I never saw this before; just in case anyone else runs across it: you're right that the tutorial is pulling a bit of a fast one on you, since it automatically wraps all the example diagrams in a frame. There is no way to tell diagrams to take the width of the line into account when making the envelope (for various reasons that would be very difficult), but you can add some space around the outside of a diagram, e.g. using a function like frame or pad.

Brent Yorgey
  • 2,043
  • 16
  • 17