haskellhaskell-diagrams

Is there a container type in Haskell Diagrams?


I am trying to map out some data in Diagrams. I am completely new to Diagrams, but I essentially want to have a rectangle, that grows when I put other diagrams atop of it. I have scoured the docs, but havn't found anything.

Does there exist such a shape, or a way to know how much to scaleY?


Solution

  • If all you need is a rectangle surrounding some diagram(s), boundingRect might be enough. It could look like this (note the pad is entirely optional):

    -- Arbitrary example, taken from the manual.
    contents :: Diagram B
    contents = c ||| hrule 1 ||| c
        where
        c = circle 1 <> vrule 2
    
    -- Adding a bounding rectangle around it, with a little padding.
    example :: Diagram B
    example = contents <> bounds
        where
        bounds = boundingRect (contents # pad 1.1)
            # lc red