Chart-0.16: A library for generating 2D Charts and Plots

Safe Haskell | None

Graphics.Rendering.Chart.Types

Description

This module contains basic types and functions used for drawing.

Note that template haskell is used to derive accessor functions (see `Accessor`) for each field of the following data types:

- `CairoLineStyle`
- `CairoFontStyle`

These accessors are not shown in this API documentation. They have the same name as the field, but with the trailing underscore dropped. Hence for data field f_::F in type D, they have type

       f :: Data.Accessor.Accessor D F

Synopsis

- data Rect = Rect Point Point
- data Point = Point {
  - p_x :: Double
  - p_y :: Double
  }
- data Vector = Vector {
  - v_x :: Double
  - v_y :: Double
  }
- type RectSize = (Double, Double)
- type Range = (Double, Double)
- mkrect :: Point -> Point -> Point -> Point -> Rect
- pvadd :: Point -> Vector -> Point
- pvsub :: Point -> Vector -> Point
- psub :: Point -> Point -> Vector
- vscale :: Double -> Vector -> Vector
- within :: Point -> Rect -> Bool
- data RectEdge
  - = E_Top
  - | E_Bottom
  - | E_Left
  - | E_Right
- data Limit a
  - = LMin
  - | LValue a
  - | LMax
- type PointMapFn x y = (Limit x, Limit y) -> Point
- preserveCState :: CRender a -> CRender a
- setClipRegion :: Point -> Point -> CRender ()
- moveTo :: Point -> CRender ()
- lineTo :: Point -> CRender ()
- rectPath :: Rect -> [Point]
- strokePath :: [Point] -> CRender ()
- fillPath :: [Point] -> CRender ()
- isValidNumber :: RealFloat a => a -> Bool
- maybeM :: Monad m => b -> (a -> m b) -> Maybe a -> m b
- defaultColorSeq :: [AlphaColour Double]
- setSourceColor :: AlphaColour Double -> Render ()
- data CairoLineStyle = CairoLineStyle {
  - line_width_ :: Double
  - line_color_ :: AlphaColour Double
  - line_dashes_ :: [Double]
  - line_cap_ :: LineCap
  - line_join_ :: LineJoin
  }
- solidLine :: Double -> AlphaColour Double -> CairoLineStyle
- dashedLine :: Double -> [Double] -> AlphaColour Double -> CairoLineStyle
- setLineStyle :: CairoLineStyle -> CRender ()
- newtype CairoFillStyle = CairoFillStyle (CRender ())
- defaultPointStyle :: CairoPointStyle
- solidFillStyle :: AlphaColour Double -> CairoFillStyle
- setFillStyle :: CairoFillStyle -> CRender ()
- data CairoFontStyle = CairoFontStyle {
  - font_name_ :: String
  - font_size_ :: Double
  - font_slant_ :: FontSlant
  - font_weight_ :: FontWeight
  - font_color_ :: AlphaColour Double
  }
- defaultFontStyle :: CairoFontStyle
- setFontStyle :: CairoFontStyle -> CRender ()
- newtype CairoPointStyle = CairoPointStyle (Point -> CRender ())
- filledPolygon :: Double -> Int -> Bool -> AlphaColour Double -> CairoPointStyle
- hollowPolygon :: Double -> Double -> Int -> Bool -> AlphaColour Double -> CairoPointStyle
- filledCircles :: Double -> AlphaColour Double -> CairoPointStyle
- hollowCircles :: Double -> Double -> AlphaColour Double -> CairoPointStyle
- plusses :: Double -> Double -> AlphaColour Double -> CairoPointStyle
- exes :: Double -> Double -> AlphaColour Double -> CairoPointStyle
- stars :: Double -> Double -> AlphaColour Double -> CairoPointStyle
- data HTextAnchor
  - = HTA_Left
  - | HTA_Centre
  - | HTA_Right
- data VTextAnchor
  - = VTA_Top
  - | VTA_Centre
  - | VTA_Bottom
  - | VTA_BaseLine
- drawText :: HTextAnchor -> VTextAnchor -> Point -> String -> CRender ()
- drawTextR :: HTextAnchor -> VTextAnchor -> Double -> Point -> String -> CRender ()
- drawTextsR :: HTextAnchor -> VTextAnchor -> Double -> Point -> String -> CRender ()
- textSize :: String -> CRender RectSize
- textDrawRect :: HTextAnchor -> VTextAnchor -> Point -> String -> CRender Rect
- newtype CRender a = DR (ReaderT CEnv Render a)
- data CEnv = CEnv {
  - cenv_point_alignfn :: Point -> Point
  - cenv_coord_alignfn :: Point -> Point
  }
- runCRender :: CRender a -> CEnv -> Render a
- c :: Render a -> CRender a
- alignp :: Point -> CRender Point
- alignc :: Point -> CRender Point
- line_width :: T CairoLineStyle Double
- line_color :: T CairoLineStyle (AlphaColour Double)
- line_dashes :: T CairoLineStyle [Double]
- line_cap :: T CairoLineStyle LineCap
- line_join :: T CairoLineStyle LineJoin
- font_name :: T CairoFontStyle String
- font_size :: T CairoFontStyle Double
- font_slant :: T CairoFontStyle FontSlant
- font_weight :: T CairoFontStyle FontWeight
- font_color :: T CairoFontStyle (AlphaColour Double)

# Documentation

data Rect Source

A rectangle is defined by two points.

Constructors

Rect Point Point |

Instances

Show Rect |

data Point Source

A point in two dimensions.

Constructors

Point |

Fields

p_x :: Double
p_y :: Double

Instances

Show Point |

data Vector Source

Constructors

Vector |

Fields

v_x :: Double
v_y :: Double

Instances

Show Vector |

type RectSize = (Double, Double)Source

type Range = (Double, Double)Source

mkrect :: Point -> Point -> Point -> Point -> Rect Source

Create a rectangle based upon the coordinates of 4 points.

pvadd :: Point -> Vector -> Point Source

Add a point and a vector.

pvsub :: Point -> Vector -> Point Source

Subtract a vector from a point.

psub :: Point -> Point -> Vector Source

Subtract two points.

vscale :: Double -> Vector -> Vector Source

Scale a vector by a constant.

within :: Point -> Rect -> Bool Source

Test if a point is within a rectangle.

data RectEdge Source

Constructors

E_Top |
E_Bottom |
E_Left |
E_Right |

data Limit a Source

Constructors

LMin |
LValue a |
LMax |

Instances

Show a => Show (Limit a) |

type PointMapFn x y = (Limit x, Limit y) -> Point Source

A function mapping between points.

preserveCState :: CRender a -> CRender aSource

Execute a rendering action in a saved context (ie bracketed between C.save and C.restore).

setClipRegion :: Point -> Point -> CRender ()Source

moveTo :: Point -> CRender ()Source

lineTo :: Point -> CRender ()Source

rectPath :: Rect -> [Point]Source

Make a path from a rectangle.

strokePath :: [Point] -> CRender ()Source

Draw lines between the specified points.

The points will be corrected by the cenv_point_alignfn, so that when drawing bitmaps, 1 pixel wide lines will be centred on the pixels.

fillPath :: [Point] -> CRender ()Source

Fill the region with the given corners.

The points will be corrected by the cenv_coord_alignfn, so that when drawing bitmaps, the edges of the region will fall between pixels.

isValidNumber :: RealFloat a => a -> Bool Source

maybeM :: Monad m => b -> (a -> m b) -> Maybe a -> m bSource

defaultColorSeq :: [AlphaColour Double]Source

setSourceColor :: AlphaColour Double -> Render ()Source

data CairoLineStyle Source

Data type for the style of a line.

Constructors

CairoLineStyle |

Fields

line_width_ :: Double
line_color_ :: AlphaColour Double
line_dashes_ :: [Double]
line_cap_ :: LineCap
line_join_ :: LineJoin

solidLine Source

Arguments

:: Double | Width of line.
-> AlphaColour Double |
-> CairoLineStyle |

dashedLine Source

Arguments

:: Double | Width of line.
-> [Double] | The dash pattern in device coordinates.
-> AlphaColour Double |
-> CairoLineStyle |

setLineStyle :: CairoLineStyle -> CRender ()Source

newtype CairoFillStyle Source

Abstract data type for a fill style.

The contained Cairo action sets the required fill style in the Cairo rendering state.

Constructors

CairoFillStyle (CRender ()) |

defaultPointStyle :: CairoPointStyle Source

solidFillStyle :: AlphaColour Double -> CairoFillStyle Source

setFillStyle :: CairoFillStyle -> CRender ()Source

data CairoFontStyle Source

Data type for a font.

Constructors

CairoFontStyle |

Fields

font_name_ :: String
font_size_ :: Double
font_slant_ :: FontSlant
font_weight_ :: FontWeight
font_color_ :: AlphaColour Double

defaultFontStyle :: CairoFontStyle Source

setFontStyle :: CairoFontStyle -> CRender ()Source

newtype CairoPointStyle Source

Abstract data type for the style of a plotted point.

The contained Cairo action draws a point in the desired style, at the supplied device coordinates.

Constructors

CairoPointStyle (Point -> CRender ()) |

filledPolygon Source

Arguments

:: Double | Radius of circle.
-> Int | Number of vertices.
-> Bool | Is right-side-up?
-> AlphaColour Double |
-> CairoPointStyle |

hollowPolygon Source

Arguments

:: Double | Radius of circle.
-> Double | Thickness of line.
-> Int | Number of vertices.
-> Bool | Is right-side-up?
-> AlphaColour Double |
-> CairoPointStyle |

filledCircles Source

Arguments

:: Double | Radius of circle.
-> AlphaColour Double | Colour.
-> CairoPointStyle |

hollowCircles Source

Arguments

:: Double | Radius of circle.
-> Double | Thickness of line.
-> AlphaColour Double |
-> CairoPointStyle |

plusses Source

Arguments

:: Double | Radius of circle.
-> Double | Thickness of line.
-> AlphaColour Double |
-> CairoPointStyle |

exes Source

Arguments

:: Double | Radius of circle.
-> Double | Thickness of line.
-> AlphaColour Double |
-> CairoPointStyle |

stars Source

Arguments

:: Double | Radius of circle.
-> Double | Thickness of line.
-> AlphaColour Double |
-> CairoPointStyle |

data HTextAnchor Source

Constructors

HTA_Left |
HTA_Centre |
HTA_Right |

data VTextAnchor Source

Constructors

VTA_Top |
VTA_Centre |
VTA_Bottom |
VTA_BaseLine |

drawText :: HTextAnchor -> VTextAnchor -> Point -> String -> CRender ()Source

Function to draw a textual label anchored by one of its corners or edges.

drawTextR :: HTextAnchor -> VTextAnchor -> Double -> Point -> String -> CRender ()Source

Function to draw a textual label anchored by one of its corners or edges, with rotation. Rotation angle is given in degrees, rotation is performed around anchor point.

drawTextsR :: HTextAnchor -> VTextAnchor -> Double -> Point -> String -> CRender ()Source

Function to draw a multi-line textual label anchored by one of its corners or edges, with rotation. Rotation angle is given in degrees, rotation is performed around anchor point.

textSize :: String -> CRender RectSize Source

Return the bounding rectangle for a text string rendered in the current context.

textDrawRect :: HTextAnchor -> VTextAnchor -> Point -> String -> CRender Rect Source

Recturn the bounding rectangle for a text string positioned where it would be drawn by drawText

newtype CRender a Source

The reader monad containing context information to control the rendering process.

Constructors

DR (ReaderT CEnv Render a) |

Instances

Monad CRender |
Functor CRender |
MonadReader CEnv CRender |

data CEnv Source

The environment present in the CRender Monad.

Constructors

CEnv |

Fields

cenv_point_alignfn :: Point -> Point

  An adjustment applied immediately prior to points being displayed in device coordinates.

  When device coordinates correspond to pixels, a cleaner image is created if this transform rounds to the nearest pixel. With higher-resolution output, this transform can just be the identity function.

cenv_coord_alignfn :: Point -> Point

  A adjustment applied immediately prior to coordinates being transformed.

Instances

MonadReader CEnv CRender |

runCRender :: CRender a -> CEnv -> Render aSource

c :: Render a -> CRender aSource

alignp :: Point -> CRender Point Source

alignc :: Point -> CRender Point Source

line_width :: T CairoLineStyle Double Source

line_color :: T CairoLineStyle (AlphaColour Double)Source

line_dashes :: T CairoLineStyle [Double]Source

line_cap :: T CairoLineStyle LineCap Source

line_join :: T CairoLineStyle LineJoin Source

font_name :: T CairoFontStyle String Source

font_size :: T CairoFontStyle Double Source

font_slant :: T CairoFontStyle FontSlant Source

font_weight :: T CairoFontStyle FontWeight Source

font_color :: T CairoFontStyle (AlphaColour Double)Source