3

I am trying this diagrams example:

funs          = map (flip (^)) [2..6]
visualize f   = stroke' (with & vertexNames .~ [[0 .. 6 :: Int]] )
                    (regPoly 7 1)
                  # lw none
                  # showLabels
                  # fontSize (Local 0.6)
             <> star (StarFun f) (regPoly 7 1)
                  # stroke # lw thick # lc red
example       = center . hcat' (with & sep .~ 0.5) $ map visualize funs

And here is the result:

enter image description here

Everything appears as expected that some of the numbers (or more precisely, the center of these numbers) are place near the edges of the image, so in the end they look like having been cut off.

Is there a way to solve this?

duplode
  • 33,731
  • 7
  • 79
  • 150
qed
  • 22,298
  • 21
  • 125
  • 196

2 Answers2

9

The problem is text doesn't have an envelope so it's size isn't taken into account. You can solve your problem by using the frame function which adds a border to the envelope.

example = frame 2 . center . hcat' (with & sep .~ 5) $ map visualize funs

example

cchalmers
  • 2,896
  • 1
  • 11
  • 11
1

I partly solved the problem by making a new function addMargin:

{-# LANGUAGE NoMonomorphismRestriction #-}

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



funs          = map (flip (^)) [2..6]
visualize f   = stroke' (with & vertexNames .~ [[0 .. 6 :: Int]] )
                    p
                  # lw none
                  # showLabels
                  # fontSize (Local 1.6)
             <> star (StarFun f) p
                  # stroke # lw thick # lc red
             where
               p = (regPoly 7 2)

example       = center . hcat' (with & sep .~ 5) $ map visualize funs

addMargin m a = c where
  c = s === b === s where
    s = strutY m
    b = s' ||| a ||| s' where
      s' = strutX m


main = mainWith (addMargin 33 example :: Diagram B R2)

enter image description here

Everything looks fine except that the 0 on the right side is still covered by something, somehow.

qed
  • 22,298
  • 21
  • 125
  • 196