diagrams-lib-0.6.0.3: Embedded domain-specific language for declarative graphics

Diagrams.TwoD

Description

This module defines the two-dimensional vector space R^2, two-dimensional transformations, and various predefined two-dimensional shapes. This module re-exports useful functionality from a group of more specific modules:

Synopsis

# R^2

data R2 Source

The two-dimensional Euclidean vector space R^2. This type is intentionally abstract.

``` r2 (3,4) :: R2
3 & 4    :: R2
```
• To construct the vector from the origin to a point `p`, use `p .-. origin`.
• To convert a vector `v` into the point obtained by following `v` from the origin, use `origin .+^ v`.
• To convert a vector back into a pair of components, use `unv2` or `coords` (from Diagrams.Coordinates). These are typically used in conjunction with the `ViewPatterns` extension:
``` foo (unr2 -> (x,y)) = ...
foo (coords -> x :& y) = ...
```

Instances

 Eq R2 Fractional R2 Num R2 Ord R2 Read R2 Show R2 Typeable R2 Transformable R2 HasBasis R2 VectorSpace R2 InnerSpace R2 AdditiveGroup R2 Coordinates R2 Newtype R2 (Double, Double) Traced (FixedSegment R2) Traced (Segment R2) Traced (Path R2) Traced (Trail R2) Renderable (Path R2) b => PathLike (QDiagram b R2 Any)

r2 :: (Double, Double) -> R2Source

Construct a 2D vector from a pair of components. See also `&`.

unr2 :: R2 -> (Double, Double)Source

Convert a 2D vector back into a pair of components. See also `coords`.

type P2 = Point R2Source

Points in R^2. This type is intentionally abstract.

``` p2 (3,4)  :: P2
3 & 4     :: P2
```
• To construct a point from a vector `v`, use `origin .+^ v`.
• To convert a point `p` into the vector from the origin to `p`, use `p .-. origin`.
• To convert a point back into a pair of coordinates, use `unp2`, or `coords` (from Diagrams.Coordinates). It's common to use these in conjunction with the `ViewPatterns` extension:
``` foo (unp2 -> (x,y)) = ...
foo (coords -> x :& y) = ...
```

p2 :: (Double, Double) -> P2Source

Construct a 2D point from a pair of coordinates. See also `&`.

unp2 :: P2 -> (Double, Double)Source

Convert a 2D point back into a pair of coordinates. See also `coords`.

Transformations in R^2.

The unit vector in the positive X direction.

The unit vector in the positive Y direction.

The unit vector in the negative X direction.

The unit vector in the negative Y direction.

direction :: Angle a => R2 -> aSource

Compute the direction of a vector, measured counterclockwise from the positive x-axis as a fraction of a full turn. The zero vector is arbitrarily assigned the direction 0.

fromDirection :: Angle a => a -> R2Source

Convert an angle into a unit vector pointing in that direction.

e :: Angle a => a -> R2Source

A convenient synonym for `fromDirection`.

# Angles

tau :: Floating a => aSource

The circle constant, the ratio of a circle's circumference to its radius. Note that `pi = tau/2`.

For more information and a well-reasoned argument why we should all be using tau instead of pi, see The Tau Manifesto, http://tauday.com/.

To hear what it sounds like (and to easily memorize the first 30 digits or so), try http://youtu.be/3174T-3-59Q.

class Num a => Angle a whereSource

Type class for types that measure angles.

Methods

toCircleFrac :: a -> CircleFracSource

Convert to a fraction of a circle.

Convert from a fraction of a circle.

Instances

 Angle Deg 360 degrees = 1 full circle. Angle Rad tau radians = 1 full circle. Angle CircleFrac

newtype CircleFrac Source

Newtype wrapper used to represent angles as fractions of a circle. For example, 1/3 = tau/3 radians = 120 degrees.

Constructors

 CircleFrac FieldsgetCircleFrac :: Double

Newtype wrapper for representing angles in radians.

Constructors

Instances

newtype Deg Source

Newtype wrapper for representing angles in degrees.

Constructors

 Deg FieldsgetDeg :: Double

Instances

 Enum Deg Eq Deg Floating Deg Fractional Deg Num Deg Ord Deg Read Deg Real Deg RealFloat Deg RealFrac Deg Show Deg Angle Deg 360 degrees = 1 full circle.

fullCircle :: Angle a => aSource

An angle representing a full circle.

convertAngle :: (Angle a, Angle b) => a -> bSource

Convert between two angle representations.

# Paths

## Stroking

stroke :: Renderable (Path R2) b => Path R2 -> Diagram b R2Source

Convert a path into a diagram. The resulting diagram has the names 0, 1, ... assigned to each of the path's vertices.

See also `stroke'`, which takes an extra options record allowing its behavior to be customized.

Note that a bug in GHC 7.0.1 causes a context stack overflow when inferring the type of `stroke`. The solution is to give a type signature to expressions involving `stroke`, or (recommended) upgrade GHC (the bug is fixed in 7.0.2 onwards).

stroke' :: (Renderable (Path R2) b, IsName a) => StrokeOpts a -> Path R2 -> Diagram b R2Source

A variant of `stroke` that takes an extra record of options to customize its behavior. In particular:

• Names can be assigned to the path's vertices

`StrokeOpts` is an instance of `Default`, so ```stroke' with { ... }``` syntax may be used.

strokeT :: Renderable (Path R2) b => Trail R2 -> Diagram b R2Source

A composition of `stroke` and `pathFromTrail` for conveniently converting a trail directly into a diagram.

Note that a bug in GHC 7.0.1 causes a context stack overflow when inferring the type of `stroke` and hence of `strokeT` as well. The solution is to give a type signature to expressions involving `strokeT`, or (recommended) upgrade GHC (the bug is fixed in 7.0.2 onwards).

strokeT' :: (Renderable (Path R2) b, IsName a) => StrokeOpts a -> Trail R2 -> Diagram b R2Source

A composition of `stroke'` and `pathFromTrail` for conveniently converting a trail directly into a diagram.

data FillRule Source

Enumeration of algorithms or "rules" for determining which points lie in the interior of a (possibly self-intersecting) closed path.

Constructors

 Winding Interior points are those with a nonzero winding number. See http://en.wikipedia.org/wiki/Nonzero-rule. EvenOdd Interior points are those where a ray extended infinitely in a particular direction crosses the path an odd number of times. See http://en.wikipedia.org/wiki/Even-odd_rule.

Instances

 Eq FillRule

fillRule :: HasStyle a => FillRule -> a -> aSource

Specify the fill rule that should be used for determining which points are inside a path.

data StrokeOpts a Source

A record of options that control how a path is stroked. `StrokeOpts` is an instance of `Default`, so a `StrokeOpts` records can be created using `with { ... }` notation.

Constructors

 StrokeOpts FieldsvertexNames :: [[a]]Atomic names that should be assigned to the vertices of the path so that they can be referenced later. If there are not enough names, the extra vertices are not assigned names; if there are too many, the extra names are ignored. Note that this is a list of lists of names, since paths can consist of multiple trails. The first list of names are assigned to the vertices of the first trail, the second list to the second trail, and so on. The default value is the empty list. queryFillRule :: FillRuleThe fill rule used for determining which points are inside the path. The default is `Winding`. NOTE: for now, this only affects the resulting diagram's `Query`, not how it will be drawn! To set the fill rule determining how it is to be drawn, use the `fillRule` function.

Instances

 Default (StrokeOpts a)

## Clipping

clipBy :: (HasStyle a, V a ~ R2) => Path R2 -> a -> aSource

Clip a diagram by the given path:

• Only the parts of the diagram which lie in the interior of the path will be drawn.
• The envelope of the diagram is unaffected.

# Shapes

## Rules

hrule :: (PathLike p, V p ~ R2) => Double -> pSource

Create a centered horizontal (L-R) line of the given length.

vrule :: (PathLike p, V p ~ R2) => Double -> pSource

Create a centered vertical (T-B) line of the given length.

## Circle-ish things

unitCircle :: (PathLike p, V p ~ R2) => pSource

A circle of radius 1, with center at the origin.

circle :: (PathLike p, V p ~ R2, Transformable p) => Double -> pSource

A circle of the given radius, centered at the origin. As a path, it begins at (r,0).

ellipse :: (PathLike p, V p ~ R2, Transformable p) => Double -> pSource

`ellipse e` constructs an ellipse with eccentricity `e` by scaling the unit circle in the X direction. The eccentricity must be within the interval [0,1).

ellipseXY :: (PathLike p, V p ~ R2, Transformable p) => Double -> Double -> pSource

`ellipseXY x y` creates an axis-aligned ellipse, centered at the origin, with radius `x` along the x-axis and radius `y` along the y-axis.

arc :: (Angle a, PathLike p, V p ~ R2) => a -> a -> pSource

Given a start angle `s` and an end angle `e`, `arc s e` is the path of a radius one arc counterclockwise between the two angles. The origin of the arc is its center.

arc' :: (Angle a, PathLike p, V p ~ R2) => Double -> a -> a -> pSource

Given a radus `r`, a start angle `s` and an end angle `e`, `arc' r s e` is the path of a radius `(abs r)` arc between the two angles. If a negative radius is given, the arc will be clockwise, otherwise it will be counterclockwise. The origin of the arc is its center.

arcCW :: (Angle a, PathLike p, V p ~ R2) => a -> a -> pSource

Like `arc` but clockwise.

wedge :: (Angle a, PathLike p, V p ~ R2) => Double -> a -> a -> pSource

Create a circular wedge of the given radius, beginning at the first angle and extending counterclockwise to the second.

## General polygons

polygon :: (PathLike p, V p ~ R2) => PolygonOpts -> pSource

Generate the vertices of a polygon. See `PolygonOpts` for more information.

Options for specifying a polygon.

Constructors

 PolygonOpts FieldspolyType :: PolyTypeSpecification for the polygon's vertices. polyOrient :: PolyOrientationShould a rotation be applied to the polygon in order to orient it in a particular way? polyCenter :: P2Should a translation be applied to the polygon in order to place the center at a particular location?

Instances

 Default PolygonOpts The default polygon is a regular pentagon of radius 1, centered at the origin, aligned to the x-axis.

data PolyType Source

Method used to determine the vertices of a polygon.

Constructors

 forall a . Angle a => PolyPolar [a] [Double] A "polar" polygon. The first argument is a list of central angles from each vertex to the next. The second argument is a list of radii from the origin to each successive vertex. To construct an n-gon, use a list of n-1 angles and n radii. Extra angles or radii are ignored. Cyclic polygons (with all vertices lying on a circle) can be constructed using a second argument of `(repeat r)`. forall a . Angle a => PolySides [a] [Double] A polygon determined by the distance between successive vertices and the angles formed by each three successive vertices. In other words, a polygon specified by "turtle graphics": go straight ahead x1 units; turn by angle a1; go straght ahead x2 units; turn by angle a2; etc. The polygon will be centered at the centroid of its vertices. The first argument is a list of vertex angles, giving the angle at each vertex from the previous vertex to the next. The first angle in the list is the angle at the second vertex; the first edge always starts out heading in the positive y direction from the first vertex. The second argument is a list of distances between successive vertices. To construct an n-gon, use a list of n-2 angles and n-1 edge lengths. Extra angles or lengths are ignored. PolyRegular Int Double A regular polygon with the given number of sides (first argument) and the given radius (second argument).

Determine how a polygon should be oriented.

Constructors

 NoOrient No special orientation; the first vertex will be at (1,0). This is the default. OrientH Orient horizontally, so the bottommost edge is parallel to the x-axis. OrientV Orient vertically, so the leftmost edge is parallel to the y-axis. OrientTo R2 Orient so some edge is facing in the direction of, that is, perpendicular to, the given vector.

## Star polygons

data StarOpts Source

Options for creating "star" polygons, where the edges connect possibly non-adjacent vertices.

Constructors

 StarFun (Int -> Int) Specify the order in which the vertices should be connected by a function that maps each vertex index to the index of the vertex that should come next. Indexing of vertices begins at 0. StarSkip Int Specify a star polygon by a "skip". A skip of 1 indicates a normal polygon, where edges go between successive vertices. A skip of 2 means that edges will connect every second vertex, skipping one in between. Generally, a skip of n means that edges will connect every nth vertex.

star :: StarOpts -> [P2] -> Path R2Source

Create a generalized star polygon. The `StarOpts` are used to determine in which order the given vertices should be connected. The intention is that the second argument of type `[P2]` could be generated by a call to `polygon`, `regPoly`, or the like, since a list of vertices is `PathLike`. But of course the list can be generated any way you like. A `Path R2` is returned (instead of any `PathLike`) because the resulting path may have more than one component, for example if the vertices are to be connected in several disjoint cycles.

## Regular polygons

regPoly :: (PathLike p, V p ~ R2) => Int -> Double -> pSource

Create a regular polygon. The first argument is the number of sides, and the second is the length of the sides. (Compare to the `polygon` function with a `PolyRegular` option, which produces polygons of a given radius).

The polygon will be oriented with one edge parallel to the x-axis.

eqTriangle :: (PathLike p, V p ~ R2) => Double -> pSource

An equilateral triangle, with sides of the given length and base parallel to the x-axis.

square :: (PathLike p, Transformable p, V p ~ R2) => Double -> pSource

A square with its center at the origin and sides of the given length, oriented parallel to the axes.

pentagon :: (PathLike p, V p ~ R2) => Double -> pSource

A regular pentagon, with sides of the given length and base parallel to the x-axis.

hexagon :: (PathLike p, V p ~ R2) => Double -> pSource

A regular hexagon, with sides of the given length and base parallel to the x-axis.

septagon :: (PathLike p, V p ~ R2) => Double -> pSource

A regular septagon, with sides of the given length and base parallel to the x-axis.

octagon :: (PathLike p, V p ~ R2) => Double -> pSource

A regular octagon, with sides of the given length and base parallel to the x-axis.

nonagon :: (PathLike p, V p ~ R2) => Double -> pSource

A regular nonagon, with sides of the given length and base parallel to the x-axis.

decagon :: (PathLike p, V p ~ R2) => Double -> pSource

A regular decagon, with sides of the given length and base parallel to the x-axis.

hendecagon :: (PathLike p, V p ~ R2) => Double -> pSource

A regular hendecagon, with sides of the given length and base parallel to the x-axis.

dodecagon :: (PathLike p, V p ~ R2) => Double -> pSource

A regular dodecagon, with sides of the given length and base parallel to the x-axis.

## Other special polygons

unitSquare :: (PathLike p, V p ~ R2) => pSource

A square with its center at the origin and sides of length 1, oriented parallel to the axes.

rect :: (PathLike p, Transformable p, V p ~ R2) => Double -> Double -> pSource

`rect w h` is an axis-aligned rectangle of width `w` and height `h`, centered at the origin.

## Other shapes

roundedRect :: (PathLike p, V p ~ R2) => Double -> Double -> Double -> pSource

`roundedRect w h r` generates a closed trail, or closed path centered at the origin, of an axis-aligned rectangle with width `w`, height `h`, and circular rounded corners of radius `r`. If `r` is negative the corner will be cut out in a reverse arc. If the size of `r` is larger than half the smaller dimension of `w` and `h`, then it will be reduced to fit in that range, to prevent the corners from overlapping. The trail or path begins with the right edge and proceeds counterclockwise. If you need to specify a different radius for each corner individually, use `roundedRect'` instead.

roundedRect' :: (PathLike p, V p ~ R2) => Double -> Double -> RoundedRectOpts -> pSource

`roundedRect'` works like `roundedRect` but allows you to set the radius of each corner indivually, using `RoundedRectOpts`. The default corner radius is 0. Each radius can also be negative, which results in the curves being reversed to be inward instead of outward.

Constructors

Instances

 Default RoundedRectOpts

# Text

Create a primitive text diagram from the given string, with center alignment, equivalent to `alignedText 0.5 0.5`.

Note that it takes up no space, as text size information is not available.

Create a primitive text diagram from the given string, origin at the top left corner of the text's bounding box, equivalent to `alignedText 0 1`.

Note that it takes up no space.

Create a primitive text diagram from the given string, with the origin set to a point interpolated within the bounding box. The first parameter varies from 0 (left) to 1 (right), and the second parameter from 0 (bottom) to 1 (top).

The height of this box is determined by the font's potential ascent and descent, rather than the height of the particular string.

Note that it takes up no space.

Create a primitive text diagram from the given string, with the origin set to be on the baseline, at the beginning (although not bounding). This is the reference point of showText in the Cairo graphics library.

Note that it takes up no space.

font :: HasStyle a => String -> a -> aSource

Specify a font family to be used for all text within a diagram.

fontSize :: HasStyle a => Double -> a -> aSource

Set the font size, that is, the size of the font's em-square as measured within the current local vector space. The default size is `1`.

italic :: HasStyle a => a -> aSource

Set all text in italics.

oblique :: HasStyle a => a -> aSource

Set all text using an oblique slant.

bold :: HasStyle a => a -> aSource

Set all text using a bold font weight.

# Images

Take an external image from the specified file and turn it into a diagram with the specified width and height, centered at the origin. Note that the image's aspect ratio will be preserved; if the specified width and height have a different ratio than the image's aspect ratio, there will be extra space in one dimension.

# Transformations

## Rotation

rotation :: Angle a => a -> T2Source

Create a transformation which performs a rotation about the local origin by the given angle. See also `rotate`.

rotate :: (Transformable t, V t ~ R2, Angle a) => a -> t -> tSource

Rotate about the local origin by the given angle. Positive angles correspond to counterclockwise rotation, negative to clockwise. The angle can be expressed using any type which is an instance of `Angle`. For example, ```rotate (1/4 :: CircleFrac)```, `rotate (tau/4 :: Rad)`, and ```rotate (90 :: Deg)``` all represent the same transformation, namely, a counterclockwise rotation by a right angle. To rotate about some point other than the local origin, see `rotateAbout`.

Note that writing `rotate (1/4)`, with no type annotation, will yield an error since GHC cannot figure out which sort of angle you want to use. In this common situation you can use `rotateBy`, which is specialized to take a `CircleFrac` argument.

rotateBy :: (Transformable t, V t ~ R2) => CircleFrac -> t -> tSource

A synonym for `rotate`, specialized to only work with `CircleFrac` arguments; it can be more convenient to write `rotateBy (1/4)` than `rotate (1/4 :: CircleFrac)`.

rotationAbout :: Angle a => P2 -> a -> T2Source

`rotationAbout p` is a rotation about the point `p` (instead of around the local origin).

rotateAbout :: (Transformable t, V t ~ R2, Angle a) => P2 -> a -> t -> tSource

`rotateAbout p` is like `rotate`, except it rotates around the point `p` instead of around the local origin.

## Scaling

Construct a transformation which scales by the given factor in the x (horizontal) direction.

scaleX :: (Transformable t, V t ~ R2) => Double -> t -> tSource

Scale a diagram by the given factor in the x (horizontal) direction. To scale uniformly, use `scale`.

Construct a transformation which scales by the given factor in the y (vertical) direction.

scaleY :: (Transformable t, V t ~ R2) => Double -> t -> tSource

Scale a diagram by the given factor in the y (vertical) direction. To scale uniformly, use `scale`.

scaling :: (HasLinearMap v, Fractional (Scalar v)) => Scalar v -> Transformation v

Create a uniform scaling transformation.

scale :: (Transformable t, Fractional (Scalar (V t)), Eq (Scalar (V t))) => Scalar (V t) -> t -> t

Scale uniformly in every dimension by the given scalar.

scaleToX :: (Enveloped t, Transformable t, V t ~ R2) => Double -> t -> tSource

`scaleToX w` scales a diagram in the x (horizontal) direction by whatever factor required to make its width `w`. `scaleToX` should not be applied to diagrams with a width of 0, such as `vrule`.

scaleToY :: (Enveloped t, Transformable t, V t ~ R2) => Double -> t -> tSource

`scaleToY h` scales a diagram in the y (vertical) direction by whatever factor required to make its height `h`. `scaleToY` should not be applied to diagrams with a height of 0, such as `hrule`.

scaleUToX :: (Enveloped t, Transformable t, V t ~ R2) => Double -> t -> tSource

`scaleUToX w` scales a diagram uniformly by whatever factor required to make its width `w`. `scaleUToX` should not be applied to diagrams with a width of 0, such as `vrule`.

scaleUToY :: (Enveloped t, Transformable t, V t ~ R2) => Double -> t -> tSource

`scaleUToY h` scales a diagram uniformly by whatever factor required to make its height `h`. `scaleUToY` should not be applied to diagrams with a height of 0, such as `hrule`.

## Translation

Construct a transformation which translates by the given distance in the x (horizontal) direction.

translateX :: (Transformable t, V t ~ R2) => Double -> t -> tSource

Translate a diagram by the given distance in the x (horizontal) direction.

Construct a transformation which translates by the given distance in the y (vertical) direction.

translateY :: (Transformable t, V t ~ R2) => Double -> t -> tSource

Translate a diagram by the given distance in the y (vertical) direction.

translation :: HasLinearMap v => v -> Transformation v

Create a translation.

translate :: (Transformable t, HasLinearMap (V t)) => V t -> t -> t

Translate by a vector.

## Reflection

Construct a transformation which flips a diagram from left to right, i.e. sends the point (x,y) to (-x,y).

reflectX :: (Transformable t, V t ~ R2) => t -> tSource

Flip a diagram from left to right, i.e. send the point (x,y) to (-x,y).

Construct a transformation which flips a diagram from top to bottom, i.e. sends the point (x,y) to (x,-y).

reflectY :: (Transformable t, V t ~ R2) => t -> tSource

Flip a diagram from top to bottom, i.e. send the point (x,y) to (x,-y).

`reflectionAbout p v` is a reflection in the line determined by the point `p` and vector `v`.

reflectAbout :: (Transformable t, V t ~ R2) => P2 -> R2 -> t -> tSource

`reflectAbout p v` reflects a diagram in the line determined by the point `p` and the vector `v`.

## Shears

`shearingX d` is the linear transformation which is the identity on y coordinates and sends `(0,1)` to `(d,1)`.

shearX :: (Transformable t, V t ~ R2) => Double -> t -> tSource

`shearX d` performs a shear in the x-direction which sends `(0,1)` to `(d,1)`.

`shearingY d` is the linear transformation which is the identity on x coordinates and sends `(1,0)` to `(1,d)`.

shearY :: (Transformable t, V t ~ R2) => Double -> t -> tSource

`shearY d` performs a shear in the y-direction which sends `(1,0)` to `(1,d)`.

# Combinators

## Combining multiple diagrams

(===) :: (Juxtaposable a, V a ~ R2, Semigroup a) => a -> a -> aSource

Place two diagrams (or other objects) vertically adjacent to one another, with the first diagram above the second. Since Haskell ignores whitespace in expressions, one can thus write

```    c
===
d
```

to place `c` above `d`. The local origin of the resulting combined diagram is the same as the local origin of the first. `(===)` is associative and has `mempty` as a right (but not left) identity. See the documentation of `beside` for more information.

(|||) :: (Juxtaposable a, V a ~ R2, Semigroup a) => a -> a -> aSource

Place two diagrams (or other juxtaposable objects) horizontally adjacent to one another, with the first diagram to the left of the second. The local origin of the resulting combined diagram is the same as the local origin of the first. `(===)` is associative and has `mempty` as a right (but not left) identity. See the documentation of `beside` for more information.

atAngle :: (Juxtaposable a, V a ~ R2, Semigroup a, Angle b) => b -> a -> a -> aSource

Place two diagrams (or other juxtaposable objects) adjacent to one another, with the second diagram placed along a line at angle `th` from the first. The local origin of the resulting combined diagram is the same as the local origin of the first. See the documentation of `beside` for more information.

hcat :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => [a] -> aSource

Lay out a list of juxtaposable objects in a row from left to right, so that their local origins lie along a single horizontal line, with successive envelopes tangent to one another.

• For more control over the spacing, see `hcat'`.
• To align the diagrams vertically (or otherwise), use alignment combinators (such as `alignT` or `alignB`) from Diagrams.TwoD.Align before applying `hcat`.
• For non-axis-aligned layout, see `cat`.

hcat' :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => CatOpts R2 -> [a] -> aSource

A variant of `hcat` taking an extra `CatOpts` record to control the spacing. See the `cat'` documentation for a description of the possibilities.

vcat :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => [a] -> aSource

Lay out a list of juxtaposable objects in a column from top to bottom, so that their local origins lie along a single vertical line, with successive envelopes tangent to one another.

• For more control over the spacing, see `vcat'`.
• To align the diagrams horizontally (or otherwise), use alignment combinators (such as `alignL` or `alignR`) from Diagrams.TwoD.Align before applying `vcat`.
• For non-axis-aligned layout, see `cat`.

vcat' :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => CatOpts R2 -> [a] -> aSource

A variant of `vcat` taking an extra `CatOpts` record to control the spacing. See the `cat'` documentation for a description of the possibilities.

## Spacing and envelopes

strutX :: (Backend b R2, Monoid' m) => Double -> QDiagram b R2 mSource

`strutX d` is an empty diagram with width `d`, height 0, and a centered local origin. Note that `strutX (-w)` behaves the same as `strutX w`.

strutY :: (Backend b R2, Monoid' m) => Double -> QDiagram b R2 mSource

`strutY d` is an empty diagram with height `d`, width 0, and a centered local origin. Note that `strutY (-h)` behaves the same as `strutY h`.

padX :: (Backend b R2, Monoid' m) => Double -> QDiagram b R2 m -> QDiagram b R2 mSource

`padX s` "pads" a diagram in the x-direction, expanding its envelope horizontally by a factor of `s` (factors between 0 and 1 can be used to shrink the envelope). Note that the envelope will expand with respect to the local origin, so if the origin is not centered horizontally the padding may appear "uneven". If this is not desired, the origin can be centered (using `centerX`) before applying `padX`.

padY :: (Backend b R2, Monoid' m) => Double -> QDiagram b R2 m -> QDiagram b R2 mSource

`padY s` "pads" a diagram in the y-direction, expanding its envelope vertically by a factor of `s` (factors between 0 and 1 can be used to shrink the envelope). Note that the envelope will expand with respect to the local origin, so if the origin is not centered vertically the padding may appear "uneven". If this is not desired, the origin can be centered (using `centerY`) before applying `padY`.

extrudeLeft :: (Semigroup m, Monoid m) => Double -> QDiagram b R2 m -> QDiagram b R2 mSource

`extrudeLeft s` "extrudes" a diagram in the negative x-direction, offsetting its envelope by the provided distance. When ` s < 0 `, the envelope is inset instead.

See the documentation for `extrudeEnvelope` for more information.

extrudeRight :: (Semigroup m, Monoid m) => Double -> QDiagram b R2 m -> QDiagram b R2 mSource

`extrudeRight s` "extrudes" a diagram in the positive x-direction, offsetting its envelope by the provided distance. When ` s < 0 `, the envelope is inset instead.

See the documentation for `extrudeEnvelope` for more information.

extrudeBottom :: (Semigroup m, Monoid m) => Double -> QDiagram b R2 m -> QDiagram b R2 mSource

`extrudeBottom s` "extrudes" a diagram in the negative y-direction, offsetting its envelope by the provided distance. When ` s < 0 `, the envelope is inset instead.

See the documentation for `extrudeEnvelope` for more information.

extrudeTop :: (Semigroup m, Monoid m) => Double -> QDiagram b R2 m -> QDiagram b R2 mSource

`extrudeTop s` "extrudes" a diagram in the positive y-direction, offsetting its envelope by the provided distance. When ` s < 0 `, the envelope is inset instead.

See the documentation for `extrudeEnvelope` for more information.

view :: (Backend b R2, Monoid' m) => P2 -> R2 -> QDiagram b R2 m -> QDiagram b R2 mSource

`view p v` sets the envelope of a diagram to a rectangle whose lower-left corner is at `p` and whose upper-right corner is at ```p .+^ v```. Useful for selecting the rectangular portion of a diagram which should actually be "viewed" in the final render, if you don't want to see the entire diagram.

## Background

boundingRect :: (Enveloped p, Transformable p, PathLike p, V p ~ R2, Enveloped a, V a ~ R2) => a -> pSource

Construct a bounding rectangle for an enveloped object, that is, the smallest axis-aligned rectangle which encloses the object.

bg :: Renderable (Path R2) b => Colour Double -> Diagram b R2 -> Diagram b R2Source

"Set the background color" of a diagram. That is, place a diagram atop a bounding rectangle of the given color.

# Alignment

alignL :: (Alignable a, V a ~ R2) => a -> aSource

Align along the left edge, i.e. translate the diagram in a horizontal direction so that the local origin is on the left edge of the envelope.

alignR :: (Alignable a, V a ~ R2) => a -> aSource

Align along the right edge.

alignT :: (Alignable a, V a ~ R2) => a -> aSource

Align along the top edge.

alignB :: (Alignable a, V a ~ R2) => a -> aSource

Align along the bottom edge.

alignTL :: (Alignable a, V a ~ R2) => a -> aSource

alignTR :: (Alignable a, V a ~ R2) => a -> aSource

alignBL :: (Alignable a, V a ~ R2) => a -> aSource

alignBR :: (Alignable a, V a ~ R2) => a -> aSource

alignX :: (Alignable a, V a ~ R2) => Double -> a -> aSource

`alignX` moves the local origin horizontally as follows:

• `alignX (-1)` moves the local origin to the left edge of the envelope;
• `align 1` moves the local origin to the right edge;
• any other argument interpolates linearly between these. For example, `alignX 0` centers, `alignX 2` moves the origin one "radius" to the right of the right edge, and so on.

alignY :: (Alignable a, V a ~ R2) => Double -> a -> aSource

Like `alignX`, but moving the local origin vertically, with an argument of `1` corresponding to the top edge and `(-1)` corresponding to the bottom edge.

centerX :: (Alignable a, V a ~ R2) => a -> aSource

Center the local origin along the X-axis.

centerY :: (Alignable a, V a ~ R2) => a -> aSource

Center the local origin along the Y-axis.

centerXY :: (Alignable a, V a ~ R2) => a -> aSource

Center along both the X- and Y-axes.

# Size

## Computing size

width :: (Enveloped a, V a ~ R2) => a -> DoubleSource

Compute the width of an enveloped object.

height :: (Enveloped a, V a ~ R2) => a -> DoubleSource

Compute the height of an enveloped object.

size2D :: (Enveloped a, V a ~ R2) => a -> (Double, Double)Source

Compute the width and height of an enveloped object.

sizeSpec2D :: (Enveloped a, V a ~ R2) => a -> SizeSpec2DSource

Compute the size of an enveloped object as a `SizeSpec2D` value.

extentX :: (Enveloped a, V a ~ R2) => a -> Maybe (Double, Double)Source

Compute the absolute x-coordinate range of an enveloped object in R2, in the form (lo,hi). Return `Nothing` for objects with an empty envelope.

extentY :: (Enveloped a, V a ~ R2) => a -> Maybe (Double, Double)Source

Compute the absolute y-coordinate range of an enveloped object in R2, in the form (lo,hi).

center2D :: (Enveloped a, V a ~ R2) => a -> P2Source

Compute the point at the center (in the x- and y-directions) of a enveloped object. Return the origin for objects with an empty envelope.

## Specifying size

data SizeSpec2D Source

A specification of a (requested) rectangular size.

Constructors

 Width Double Specify an explicit width. The height should be determined automatically (so as to preserve aspect ratio). Height Double Specify an explicit height. The width should be determined automatically (so as to preserve aspect ratio). Dims Double Double An explicit specification of a width and height. Absolute Absolute size: use whatever size an object already has; do not rescale.

Create a size specification from a possibly-specified width and height.

sized :: (Transformable a, Enveloped a, V a ~ R2) => SizeSpec2D -> a -> aSource

Uniformly scale any enveloped object so that it fits within the given size.

sizedAs :: (Transformable a, Enveloped a, V a ~ R2, Enveloped b, V b ~ R2) => b -> a -> aSource

Uniformly scale an enveloped object so that it "has the same size as" (fits within the width and height of) some other object.

# Visual aids for understanding the internal model

showOrigin :: (Renderable (Path R2) b, Backend b R2, Monoid' m) => QDiagram b R2 m -> QDiagram b R2 mSource

Mark the origin of a diagram by placing a red dot 1/50th its size.

showOrigin' :: (Renderable (Path R2) b, Backend b R2, Monoid' m) => OriginOpts -> QDiagram b R2 m -> QDiagram b R2 mSource

Mark the origin of a diagram, with control over colour and scale of marker dot.

data OriginOpts Source

Constructors

 OriginOpts FieldsoColor :: Colour Double oScale :: Double oMinSize :: Double

Instances

 Default OriginOpts