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

Maintainer | diagrams-discuss@googlegroups.com
Safe Haskell | None

Diagrams.Attributes

Contents

- Color
  - Line color
  - Fill color
  - Opacity
  - Converting colors
- Lines
  - Width
  - Cap style
  - Join style
  - Miter limit
  - Dashing

Description

Diagrams may have attributes which affect the way they are rendered. This module defines some common attributes; particular backends may also define more backend-specific attributes.

Every attribute type must have a semigroup structure, that is, an associative binary operation for combining two attributes into one. Unless otherwise noted, all the attributes defined here use the `Last` structure, that is, combining two attributes simply keeps the second one and throws away the first. This means that child attributes always override parent attributes.

Synopsis

- class Color c where
  - toAlphaColour :: c -> AlphaColour Double
- data SomeColor = forall c . Color c => SomeColor c
- data LineColor
- getLineColor :: LineColor -> SomeColor
- lineColor :: (Color c, HasStyle a) => c -> a -> a
- lineColorA :: HasStyle a => LineColor -> a -> a
- lc :: HasStyle a => Colour Double -> a -> a
- lcA :: HasStyle a => AlphaColour Double -> a -> a
- data FillColor
- getFillColor :: FillColor -> SomeColor
- recommendFillColor :: (Color c, HasStyle a) => c -> a -> a
- fillColor :: (Color c, HasStyle a) => c -> a -> a
- fc :: HasStyle a => Colour Double -> a -> a
- fcA :: HasStyle a => AlphaColour Double -> a -> a
- data Opacity
- getOpacity :: Opacity -> Double
- opacity :: HasStyle a => Double -> a -> a
- toRGBAUsingSpace :: Color c => RGBSpace Double -> c -> (Double, Double, Double, Double)
- colorToSRGBA :: Color c => c -> (Double, Double, Double, Double)
- colorToRGBA :: Color c => c -> (Double, Double, Double, Double)
- data LineWidth
- getLineWidth :: LineWidth -> Double
- lineWidth :: HasStyle a => Double -> a -> a
- lineWidthA :: HasStyle a => LineWidth -> a -> a
- lw :: HasStyle a => Double -> a -> a
- data LineCap
  - = LineCapButt
  - | LineCapRound
  - | LineCapSquare
- data LineCapA
- getLineCap :: LineCapA -> LineCap
- lineCap :: HasStyle a => LineCap -> a -> a
- data LineJoin
  - = LineJoinMiter
  - | LineJoinRound
  - | LineJoinBevel
- data LineJoinA
- getLineJoin :: LineJoinA -> LineJoin
- lineJoin :: HasStyle a => LineJoin -> a -> a
- newtype LineMiterLimit = LineMiterLimit (Last Double)
- getLineMiterLimit :: LineMiterLimit -> Double
- lineMiterLimit :: HasStyle a => Double -> a -> a
- lineMiterLimitA :: HasStyle a => LineMiterLimit -> a -> a
- data Dashing = Dashing [Double] Double
- data DashingA
- getDashing :: DashingA -> Dashing
- dashing :: HasStyle a => [Double] -> Double -> a -> a

# Color

Diagrams outsources all things color-related to Russell O'Connor's very nice colour package (http://hackage.haskell.org/package/colour). For starters, it provides a large collection of standard color names. However, it also provides a rich set of combinators for combining and manipulating colors; see its documentation for more information.

class Color c where Source

The `Color` type class encompasses color representations which can be used by the Diagrams library. Instances are provided for both the `Colour` and `AlphaColour` types from the Data.Colour library.

Methods

toAlphaColour :: c -> AlphaColour Double Source

Convert a color to its standard representation, AlphaColour

Instances

Color FillColor |
Color LineColor |
Color SomeColor |
(Floating a, Real a) => Color (Colour a) |
(Floating a, Real a) => Color (AlphaColour a) |

data SomeColor Source

An existential wrapper for instances of the `Color` class.

Constructors

forall c . Color c => SomeColor c |

Instances

Typeable SomeColor |
Color SomeColor |

## Line color

data LineColor Source

The color with which lines (strokes) are drawn. Note that child colors always override parent colors; that is, ``lineColor` c1 . `lineColor` c2 $ d` is equivalent to ``lineColor` c2 $ d`. More precisely, the semigroup structure on line color attributes is that of `Last`.

Instances

Typeable LineColor |
Semigroup LineColor |
Default LineColor |
AttributeClass LineColor |
Color LineColor |

getLineColor :: LineColor -> SomeColor Source

lineColor :: (Color c, HasStyle a) => c -> a -> aSource

Set the line (stroke) color. This function is polymorphic in the color type (so it can be used with either `Colour` or `AlphaColour`), but this can sometimes create problems for type inference, so the `lc` and `lcA` variants are provided with more concrete types.

lineColorA :: HasStyle a => LineColor -> a -> aSource

Apply a `lineColor` attribute.

lc :: HasStyle a => Colour Double -> a -> aSource

A synonym for `lineColor`, specialized to ``Colour` Double` (i.e. opaque colors).

lcA :: HasStyle a => AlphaColour Double -> a -> aSource

A synonym for `lineColor`, specialized to ``AlphaColour` Double` (i.e. colors with transparency).

## Fill color

data FillColor Source

The color with which shapes are filled. Note that child colors always override parent colors; that is, ``fillColor` c1 . `fillColor` c2 $ d` is equivalent to ``lineColor` c2 $ d`. More precisely, the semigroup structure on fill color attributes is that of `Last`.

Instances

Typeable FillColor |
Semigroup FillColor |
AttributeClass FillColor |
Color FillColor |

getFillColor :: FillColor -> SomeColor Source

recommendFillColor :: (Color c, HasStyle a) => c -> a -> aSource

Set a "recommended" fill color, to be used only if no explicit calls to `fillColor` (or `fc`, or `fcA`) are used.

fillColor :: (Color c, HasStyle a) => c -> a -> aSource

Set the fill color. This function is polymorphic in the color type (so it can be used with either `Colour` or `AlphaColour`), but this can sometimes create problems for type inference, so the `fc` and `fcA` variants are provided with more concrete types.

fc :: HasStyle a => Colour Double -> a -> aSource

A synonym for `fillColor`, specialized to ``Colour` Double` (i.e. opaque colors).

fcA :: HasStyle a => AlphaColour Double -> a -> aSource

A synonym for `fillColor`, specialized to ``AlphaColour` Double` (i.e. colors with transparency).

## Opacity

data Opacity Source

Although the individual colors in a diagram can have transparency, the opacity/transparency of a diagram as a whole can be specified with the `Opacity` attribute. The opacity is a value between 1 (completely opaque, the default) and 0 (completely transparent). Opacity is multiplicative, that is, ``opacity` o1 . `opacity` o2 === `opacity` (o1 * o2)`. In other words, for example, `opacity 0.8` means "decrease this diagram's opacity to 80% of its previous opacity".

Instances

Typeable Opacity |
Semigroup Opacity |
AttributeClass Opacity |

getOpacity :: Opacity -> Double Source

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

Multiply the opacity (see `Opacity`) by the given value. For example, `opacity 0.8` means "decrease this diagram's opacity to 80% of its previous opacity".

## Converting colors

toRGBAUsingSpace :: Color c => RGBSpace Double -> c -> (Double, Double, Double, Double)Source

Convert to an RGB space while preserving the alpha channel.

colorToSRGBA :: Color c => c -> (Double, Double, Double, Double)Source

Convert to sRGBA.

colorToRGBA :: Color c => c -> (Double, Double, Double, Double)Source

Deprecated: Renamed to colorToSRGBA.

Convert to sRGBA.

# Lines

## Width

data LineWidth Source

The width of lines. By default, the line width is measured with respect to the final coordinate system of a rendered diagram, as opposed to the local coordinate systems in effect at the time the line width was set for various subdiagrams. This is so that it is easy to combine a variety of shapes (some created by scaling) and have them all drawn using a consistent line width. However, sometimes it is desirable for scaling to affect line width; the `freeze` operation is provided for this purpose. The line width of frozen diagrams is affected by transformations.

Line widths specified on child nodes always override line widths specified at parent nodes.

Instances

Typeable LineWidth |
Semigroup LineWidth |
Default LineWidth |
AttributeClass LineWidth |

getLineWidth :: LineWidth -> Double Source

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

Set the line (stroke) width.

lineWidthA :: HasStyle a => LineWidth -> a -> aSource

Apply a `LineWidth` attribute.

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

A convenient synonym for `lineWidth`.

## Cap style

data LineCap Source

What sort of shape should be placed at the endpoints of lines?

Constructors

LineCapButt | Lines end precisely at their endpoints.
LineCapRound | Lines are capped with semicircles centered on endpoints.
LineCapSquare | Lines are capped with a squares centered on endpoints.

Instances

Eq LineCap |
Show LineCap |
Typeable LineCap |
Default LineCap |

data LineCapA Source

Instances

Eq LineCapA |
Typeable LineCapA |
Semigroup LineCapA |
AttributeClass LineCapA |

getLineCap :: LineCapA -> LineCap Source

lineCap :: HasStyle a => LineCap -> a -> aSource

Set the line end cap attribute.

## Join style

data LineJoin Source

How should the join points between line segments be drawn?

Constructors

LineJoinMiter | Use a "miter" shape (whatever that is).
LineJoinRound | Use rounded join points.
LineJoinBevel | Use a "bevel" shape (whatever that is). Are these... carpentry terms?

Instances

Eq LineJoin |
Show LineJoin |
Typeable LineJoin |
Default LineJoin |

data LineJoinA Source

Instances

Eq LineJoinA |
Typeable LineJoinA |
Semigroup LineJoinA |
AttributeClass LineJoinA |

getLineJoin :: LineJoinA -> LineJoin Source

lineJoin :: HasStyle a => LineJoin -> a -> aSource

Set the segment join style.

## Miter limit

newtype LineMiterLimit Source

Miter limit attribute affecting the `LineJoinMiter` joins. For some backends this value may have additional effects.

Constructors

LineMiterLimit (Last Double) |

Instances

Typeable LineMiterLimit |
Semigroup LineMiterLimit |
Default LineMiterLimit |
AttributeClass LineMiterLimit |

getLineMiterLimit :: LineMiterLimit -> Double Source

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

Set the miter limit for joins with `LineJoinMiter`.

lineMiterLimitA :: HasStyle a => LineMiterLimit -> a -> aSource

Apply a `LineMiterLimit` attribute.

## Dashing

data Dashing Source

Create lines that are dashing... er, dashed.

Constructors

Dashing [Double] Double |

Instances

Eq Dashing |
Typeable Dashing |

data DashingA Source

Instances

Eq DashingA |
Typeable DashingA |
Semigroup DashingA |
AttributeClass DashingA |

getDashing :: DashingA -> Dashing Source

dashing Source

Arguments

:: HasStyle a |
=> [Double] | A list specifying alternate lengths of on and off portions of the stroke. The empty list indicates no dashing.
-> Double | An offset into the dash pattern at which the stroke should start.
-> a |
-> a |

Set the line dashing style.