diagrams-0.2.1.3: An EDSL for creating simple diagramsSource codeContentsIndex
Graphics.Rendering.Diagrams.Types
Portabilityportable
Stabilityexperimental
Maintainerbyorgey@gmail.com
Contents
Primitive types
Shapes, attributes, and layouts
Rendering
Description
Type definitions and convenience functions for Graphics.Rendering.Diagrams, an embedded domain-specific language (EDSL) for creating simple diagrams.
Synopsis
data Diagram
= Empty
| Prim Shape
| Ann Attr Diagram
| Compound Layout
| Union [Diagram]
| Sized Point Diagram
class Color c where
colorToRGBA :: c -> (Double, Double, Double, Double)
data SomeColor = forall c . Color c => SomeColor c
type Point = (Double, Double)
type Vec = Point
(*.) :: Double -> Point -> Point
(.+.) :: Point -> Point -> Point
(.-.) :: Point -> Point -> Point
(.*.) :: Point -> Point -> Point
data Path = Path PathType [Vec]
data PathType
= Open
| Closed
data PathStyle
= Straight
| Bezier Double
class ShapeClass s where
shapeSize :: s -> Point
renderShape :: s -> DiaRenderM ()
data Shape = forall s . ShapeClass s => Shape s
class AttrClass a where
attrSize :: a -> Point -> Point
renderAttr :: a -> DiaRenderM (DiaRenderEnv -> DiaRenderEnv)
data Attr = forall a . AttrClass a => Attr a
class Functor f => LayoutClass l f where
layoutSizeAndPos :: l -> f (Point, Diagram) -> (Point, [Diagram])
data Layout = forall l f . LayoutClass l f => Layout l (f Diagram)
data DiaRenderEnv = DREnv {
envFillColor :: SomeColor
envStrokeColor :: SomeColor
envStrokeWidth :: Double
}
defaultDiaRenderEnv :: DiaRenderEnv
setEnvFillColor :: Color c => c -> DiaRenderEnv -> DiaRenderEnv
setEnvStrokeColor :: Color c => c -> DiaRenderEnv -> DiaRenderEnv
setEnvStrokeWidth :: Double -> DiaRenderEnv -> DiaRenderEnv
newtype DiaRenderM a = DRM (ReaderT DiaRenderEnv Render a)
runDiaRenderM :: DiaRenderM a -> DiaRenderEnv -> Render a
c :: Render a -> DiaRenderM a
data SizeSpec
= Width Double
| Height Double
| Auto
data OutputType
= PNG
| PS
| PDF
| SVG
Primitive types
data Diagram Source
Diagram is the core data type which describes a diagram. Diagrams may be constructed, transformed, combined, and ultimately rendered as an image.
Constructors
EmptyThe empty diagram
Prim ShapeA primitive shape
Ann Attr DiagramAn annotated diagram
Compound LayoutA compound diagram
Union [Diagram]A fully processed compound diagram, ready for rendering
Sized Point DiagramAn explicitly sized diagram whose bounding box takes up a particular amount of space.
class Color c whereSource
The Color type class encompasses color representations which can be used by the Diagrams library; that is, every function in the Diagrams library which expects a color can take any type which is an instance of Color. Instances are provided for both the Colour and AlphaColour types from the Data.Colour library.
Methods
colorToRGBA :: c -> (Double, Double, Double, Double)Source
data SomeColor Source
Existential wrapper for instances of the Color class.
Constructors
forall c . Color c => SomeColor c
type Point = (Double, Double)Source
Basic 2D points/vectors.
type Vec = PointSource
(*.) :: Double -> Point -> PointSource
Scalar multiplication.
(.+.) :: Point -> Point -> PointSource
(.-.) :: Point -> Point -> PointSource
Elementwise addition, subtraction and multiplication for Points.
(.*.) :: Point -> Point -> PointSource
data Path Source
A path is a series of edges which can be stroked, filled, etc. It can be either open (the default) or closed (i.e. the first and last vertices are connected).
Constructors
Path PathType [Vec]
data PathType Source
A path can be open (normal) or closed (first and last vertices connected automatically).
Constructors
Open
Closed
data PathStyle Source
The styles in which a path can be rendered.
Constructors
Straight
Bezier Double
Shapes, attributes, and layouts
class ShapeClass s whereSource

The primitive shapes which can be used to build up a diagram. Every primitive shape must be an instance of ShapeClass.

Given a shape s, if shapeSize s evaluates to (w,h), then the drawing rendered by renderShape s should fit within a w by h rectangle centered at the origin.

You can create your own shape primitives by creating a new data type and making it an instance of ShapeClass. If you do so, you must be sure that your ShapeClass instance satisfies the law described above, on which the rendering engine relies in order to compute the proper positions for objects in a diagram. Otherwise, instances of your object in a diagram may extend outside the boundaries of the rendered image, or inadvertently overlap or be overlapped by other diagram elements. Of course, you are free to ignore this "law" as well; it will cause unexpected output at worst, and at best you may find some clever way to bend the system to your will. =)

Methods
shapeSize :: s -> PointSource
Calculate the size (the dimensions of a bounding box centered at the origin) of a shape.
renderShape :: s -> DiaRenderM ()Source
Calculate a cairo Render action to render a shape.
data Shape Source
Existential wrapper type for shapes.
Constructors
forall s . ShapeClass s => Shape s
class AttrClass a whereSource
Attributes which can be applied as annotations to a Diagram, and change the way the Diagram is interpreted or rendered. Every attribute must be an instance of AttrClass.
Methods
attrSize :: a -> Point -> PointSource
Given an attribute and the size of the diagram to which it is an annotation, return a new size for the diagram. The default implementation is to simply return the size unchanged.
renderAttr :: a -> DiaRenderM (DiaRenderEnv -> DiaRenderEnv)Source
In order to implement this attribute, renderAttr may perform an action in the DiaRenderM monad, and return a function which produces a local modification to the render environment. The change produced by this function will only remain in effect for any sub-diagrams, and the environment will return to its former state afterwards.
data Attr Source
Existential wrapper type for attributes.
Constructors
forall a . AttrClass a => Attr a
class Functor f => LayoutClass l f whereSource
All layouts must be instances of LayoutClass, along with an appropriate container type which must be an instance of Functor.
Methods
layoutSizeAndPos :: l -> f (Point, Diagram) -> (Point, [Diagram])Source
Given a layout and a container of (size, diagram) pairs (which have already had all subdiagrams appropriately positioned), compute the overall bounding box size for this layout, as well as a list of positioned subdiagrams.
data Layout Source
An existential wrapper type for layouts. A layout consists of a (possibly parameterized) layout type, along with a container of Diagrams.
Constructors
forall l f . LayoutClass l f => Layout l (f Diagram)
Rendering
data DiaRenderEnv Source
An environment containing additional parameters to be made available while rendering, which for one reason or another are not or cannot be provided by the cairo Render monad itself. For example, cairo only tracks one current color, so we must track a fill color and stroke color separately.
Constructors
DREnv
envFillColor :: SomeColor
envStrokeColor :: SomeColor
envStrokeWidth :: Double
defaultDiaRenderEnv :: DiaRenderEnvSource
The default rendering environment: transparent fill with 1-pixel black strokes.
setEnvFillColor :: Color c => c -> DiaRenderEnv -> DiaRenderEnvSource
setEnvStrokeColor :: Color c => c -> DiaRenderEnv -> DiaRenderEnvSource
setEnvStrokeWidth :: Double -> DiaRenderEnv -> DiaRenderEnvSource
newtype DiaRenderM a Source
The custom rendering monad: ReaderT DiaRenderEnv on top of cairo's Render monad.
Constructors
DRM (ReaderT DiaRenderEnv Render a)
runDiaRenderM :: DiaRenderM a -> DiaRenderEnv -> Render aSource
Run a DiaRenderM action, given an initial rendering environment, to produce a cairo Render action.
c :: Render a -> DiaRenderM aSource
Lift a cairo Render action into a DiaRenderM action.
data SizeSpec Source
A specification of the size of a rendered Diagram.
Constructors
Width Doublean explicit width; the height is determined automatically
Height Doublean explicit height; the width is determined automatically
Autodetermine the size automatically (do not scale)
data OutputType Source
The supported output file types for rendered diagrams.
Constructors
PNG
PS
PDF
SVG
Produced by Haddock version 2.6.1