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

Copyright | (c) Tim Docker 2014
License | BSD-style (see chart/COPYRIGHT)
Safe Haskell | Safe-Inferred
Language | Haskell98

Graphics.Rendering.Chart.Backend

Contents

- The backend Monad
- Backend Operations
- Backend Helpers
- Text Metrics
- Line Types
- Fill Types
- Font and Text Types

Description

This module provides the API for drawing operations abstracted to drive arbitrary Backend.

Synopsis

- type BackendProgram a = Program ChartBackendInstr a
- fillPath :: Path -> BackendProgram ()
- strokePath :: Path -> BackendProgram ()
- drawText :: Point -> String -> BackendProgram ()
- textSize :: String -> BackendProgram TextSize
- withTransform :: Matrix -> BackendProgram a -> BackendProgram a
- withClipRegion :: Rect -> BackendProgram a -> BackendProgram a
- withFontStyle :: FontStyle -> BackendProgram a -> BackendProgram a
- withFillStyle :: FillStyle -> BackendProgram a -> BackendProgram a
- withLineStyle :: LineStyle -> BackendProgram a -> BackendProgram a
- getPointAlignFn :: BackendProgram (Point -> Point)
- getCoordAlignFn :: BackendProgram (Point -> Point)
- data TextSize = TextSize {
  - textSizeWidth :: Double
  - textSizeAscent :: Double
  - textSizeDescent :: Double
  - textSizeYBearing :: Double
  - textSizeHeight :: Double
  }
- data LineCap
  - = LineCapButt
  - | LineCapRound
  - | LineCapSquare
- data LineJoin
  - = LineJoinMiter
  - | LineJoinRound
  - | LineJoinBevel
- data LineStyle = LineStyle {
  - _line_width :: Double
  - _line_color :: AlphaColour Double
  - _line_dashes :: [Double]
  - _line_cap :: LineCap
  - _line_join :: LineJoin
  }
- line_width :: Lens' LineStyle Double
- line_color :: Lens' LineStyle (AlphaColour Double)
- line_dashes :: Lens' LineStyle [Double]
- line_cap :: Lens' LineStyle LineCap
- line_join :: Lens' LineStyle LineJoin
- newtype FillStyle = FillStyleSolid {
  - _fill_color :: AlphaColour Double
  }
- data FontWeight
  - = FontWeightNormal
  - | FontWeightBold
- data FontSlant
  - = FontSlantNormal
  - | FontSlantItalic
  - | FontSlantOblique
- data FontStyle = FontStyle {
  - _font_name :: String
  - _font_size :: Double
  - _font_slant :: FontSlant
  - _font_weight :: FontWeight
  - _font_color :: AlphaColour Double
  }
- data HTextAnchor
  - = HTA_Left
  - | HTA_Centre
  - | HTA_Right
- data VTextAnchor
  - = VTA_Top
  - | VTA_Centre
  - | VTA_Bottom
  - | VTA_BaseLine
- font_name :: Lens' FontStyle String
- font_size :: Lens' FontStyle Double
- font_slant :: Lens' FontStyle FontSlant
- font_weight :: Lens' FontStyle FontWeight
- font_color :: Lens' FontStyle (AlphaColour Double)
- type AlignmentFn = Point -> Point
- data AlignmentFns
- vectorAlignmentFns :: AlignmentFns
- bitmapAlignmentFns :: AlignmentFns

# The backend Monad

type BackendProgram a = Program ChartBackendInstr a Source #

A `BackendProgram` provides the capability to render a chart somewhere.

The coordinate system of the backend has its initial origin (0,0) in the top left corner of the drawing plane. The x-axis points towards the top right corner and the y-axis points towards the bottom left corner. The unit used by coordinates, the font size, and lengths is the always the same, but depends on the backend. All angles are measured in radians.

The line, fill and font style are set to their default values initially.

Information about the semantics of the instructions can be found in the documentation of `ChartBackendInstr`.

# Backend Operations

fillPath :: Path -> BackendProgram () Source #

Fill the given path using the current `FillStyle`. The given path will be closed prior to filling. This function does not perform alignment operations on the path. See `Path` for the exact semantic of paths.

strokePath :: Path -> BackendProgram () Source #

Stroke the outline of the given path using the current `LineStyle`. This function does not perform alignment operations on the path. See `Path` for the exact semantic of paths.

drawText :: Point -> String -> BackendProgram () Source #

Draw a single-line textual label anchored by the baseline (vertical) left (horizontal) point. Uses the current `FontStyle` for drawing.

textSize :: String -> BackendProgram TextSize Source #

Calculate a `TextSize` object with rendering information about the given string without actually rendering it.

withTransform :: Matrix -> BackendProgram a -> BackendProgram a Source #

Apply the given transformation in this local environment when drawing. The given transformation is applied after the current transformation. This means both are combined.

withClipRegion :: Rect -> BackendProgram a -> BackendProgram a Source #

Use the given clipping rectangle when drawing in this local environment. The new clipping region is intersected with the given clip region. You cannot escape the clip!

withFontStyle :: FontStyle -> BackendProgram a -> BackendProgram a Source #

Use the given font style in this local environment when drawing text.

An implementing backend is expected to guarentee to support the following font families: `serif`, `sans-serif` and `monospace`;

If the backend is not able to find or load a given font it is required to fall back to a custom fail-safe font and use it instead.

withFillStyle :: FillStyle -> BackendProgram a -> BackendProgram a Source #

Use the given fill style in this local environment when filling paths.

withLineStyle :: LineStyle -> BackendProgram a -> BackendProgram a Source #

Use the given line style in this local environment when stroking paths.

# Backend Helpers

getPointAlignFn :: BackendProgram (Point -> Point) Source #

Get the point alignment function

getCoordAlignFn :: BackendProgram (Point -> Point) Source #

Get the coordinate alignment function

# Text Metrics

data TextSize Source #

Text metrics returned by `textSize`.

Constructors

TextSize |

Fields

- textSizeWidth :: Double

  The total width of the text.

- textSizeAscent :: Double

  The ascent or space above the baseline.

- textSizeDescent :: Double

  The decent or space below the baseline.

- textSizeYBearing :: Double

  The Y bearing.

- textSizeHeight :: Double

  The total height of the text.

#### Instances

Instances details

Show TextSize Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods showsPrec :: Int -> TextSize -> ShowS Source # show :: TextSize -> String Source # showList :: [TextSize] -> ShowS Source #
Eq TextSize Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods (==) :: TextSize -> TextSize -> Bool Source # (/=) :: TextSize -> TextSize -> Bool Source #

# Line Types

data LineCap Source #

The different supported line ends.

Constructors

LineCapButt | Just cut the line straight.
LineCapRound | Make a rounded line end.
LineCapSquare | Make a square that ends the line.

#### Instances

Instances details

Show LineCap Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods showsPrec :: Int -> LineCap -> ShowS Source # show :: LineCap -> String Source # showList :: [LineCap] -> ShowS Source #
Eq LineCap Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods (==) :: LineCap -> LineCap -> Bool Source # (/=) :: LineCap -> LineCap -> Bool Source #
Ord LineCap Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods compare :: LineCap -> LineCap -> Ordering Source # (<) :: LineCap -> LineCap -> Bool Source # (<=) :: LineCap -> LineCap -> Bool Source # (>) :: LineCap -> LineCap -> Bool Source # (>=) :: LineCap -> LineCap -> Bool Source # max :: LineCap -> LineCap -> LineCap Source # min :: LineCap -> LineCap -> LineCap Source #

data LineJoin Source #

The different supported ways to join line ends.

Constructors

LineJoinMiter | Extends the outline until they meet each other.
LineJoinRound | Draw a circle fragment to connet line end.
LineJoinBevel | Like miter, but cuts it off if a certain threshold is exceeded.

#### Instances

Instances details

Show LineJoin Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods showsPrec :: Int -> LineJoin -> ShowS Source # show :: LineJoin -> String Source # showList :: [LineJoin] -> ShowS Source #
Eq LineJoin Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods (==) :: LineJoin -> LineJoin -> Bool Source # (/=) :: LineJoin -> LineJoin -> Bool Source #
Ord LineJoin Source # |

Instance details

Defined in Graphics.Rendering.Chart.Backend.Types

Methods

compare :: LineJoin -> LineJoin -> Ordering Source #

(<) :: LineJoin -> LineJoin -> Bool Source #

(<=) :: LineJoin -> LineJoin -> Bool Source #

(>) :: LineJoin -> LineJoin -> Bool Source #

(>=) :: LineJoin -> LineJoin -> Bool Source #

max :: LineJoin -> LineJoin -> LineJoin Source #

min :: LineJoin -> LineJoin -> LineJoin Source #

data LineStyle Source #

Data type for the style of a line.

Constructors

LineStyle |

Fields

- _line_width :: Double

  The thickness of a line in device units.

- _line_color :: AlphaColour Double

  The color of a line.

- _line_dashes :: [Double]

  The dash pattern. Every value at a even index gives a dash width and every value at a odd index gives a gap width in device units.

- _line_cap :: LineCap

  How to end a line.

- _line_join :: LineJoin

  How to connect two lines.

#### Instances

Instances details

Show LineStyle Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods showsPrec :: Int -> LineStyle -> ShowS Source # show :: LineStyle -> String Source # showList :: [LineStyle] -> ShowS Source #
Default LineStyle Source # | The default line style.
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods def :: LineStyle Source #
Eq LineStyle Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods (==) :: LineStyle -> LineStyle -> Bool Source # (/=) :: LineStyle -> LineStyle -> Bool Source #

line_width :: Lens' LineStyle Double Source #

line_color :: Lens' LineStyle (AlphaColour Double) Source #

line_dashes :: Lens' LineStyle [Double] Source #

line_cap :: Lens' LineStyle LineCap Source #

line_join :: Lens' LineStyle LineJoin Source #

# Fill Types

newtype FillStyle Source #

Abstract data type for a fill style.

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

Constructors

FillStyleSolid |

Fields

- _fill_color :: AlphaColour Double

#### Instances

Instances details

Show FillStyle Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods showsPrec :: Int -> FillStyle -> ShowS Source # show :: FillStyle -> String Source # showList :: [FillStyle] -> ShowS Source #
Default FillStyle Source # | The default fill style.
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods def :: FillStyle Source #
Eq FillStyle Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods (==) :: FillStyle -> FillStyle -> Bool Source # (/=) :: FillStyle -> FillStyle -> Bool Source #

# Font and Text Types

data FontWeight Source #

The possible weights of a font.

Constructors

FontWeightNormal | Normal font style without weight.
FontWeightBold | Bold font.

#### Instances

Instances details

Show FontWeight Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods showsPrec :: Int -> FontWeight -> ShowS Source # show :: FontWeight -> String Source # showList :: [FontWeight] -> ShowS Source #
Default FontWeight Source # | The default font weight.
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods def :: FontWeight Source #
Eq FontWeight Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods (==) :: FontWeight -> FontWeight -> Bool Source # (/=) :: FontWeight -> FontWeight -> Bool Source #
Ord FontWeight Source # |

Instance details

Defined in Graphics.Rendering.Chart.Backend.Types

Methods

compare :: FontWeight -> FontWeight -> Ordering Source #

(<) :: FontWeight -> FontWeight -> Bool Source #

(<=) :: FontWeight -> FontWeight -> Bool Source #

(>) :: FontWeight -> FontWeight -> Bool Source #

(>=) :: FontWeight -> FontWeight -> Bool Source #

max :: FontWeight -> FontWeight -> FontWeight Source #

min :: FontWeight -> FontWeight -> FontWeight Source #

data FontSlant Source #

The possible slants of a font.

Constructors

FontSlantNormal | Normal font style without slant.
FontSlantItalic | With a slight slant.
FontSlantOblique | With a greater slant.

#### Instances

Instances details

Show FontSlant Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods showsPrec :: Int -> FontSlant -> ShowS Source # show :: FontSlant -> String Source # showList :: [FontSlant] -> ShowS Source #
Default FontSlant Source # | The default font slant.
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods def :: FontSlant Source #
Eq FontSlant Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods (==) :: FontSlant -> FontSlant -> Bool Source # (/=) :: FontSlant -> FontSlant -> Bool Source #
Ord FontSlant Source # |

Instance details

Defined in Graphics.Rendering.Chart.Backend.Types

Methods

compare :: FontSlant -> FontSlant -> Ordering Source #

(<) :: FontSlant -> FontSlant -> Bool Source #

(<=) :: FontSlant -> FontSlant -> Bool Source #

(>) :: FontSlant -> FontSlant -> Bool Source #

(>=) :: FontSlant -> FontSlant -> Bool Source #

max :: FontSlant -> FontSlant -> FontSlant Source #

min :: FontSlant -> FontSlant -> FontSlant Source #

data FontStyle Source #

Data type for a font.

Constructors

FontStyle |

Fields

- _font_name :: String

  The font family or font face to use.

- _font_size :: Double

  The height of the rendered font in device coordinates.

- _font_slant :: FontSlant

  The slant to render with.

- _font_weight :: FontWeight

  The weight to render with.

- _font_color :: AlphaColour Double

  The color to render text with.

#### Instances

Instances details

Show FontStyle Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods showsPrec :: Int -> FontStyle -> ShowS Source # show :: FontStyle -> String Source # showList :: [FontStyle] -> ShowS Source #
Default FontStyle Source # | The default font style.
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods def :: FontStyle Source #
Eq FontStyle Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods (==) :: FontStyle -> FontStyle -> Bool Source # (/=) :: FontStyle -> FontStyle -> Bool Source #

data HTextAnchor Source #

Possible horizontal anchor points for text.

Constructors

HTA_Left |
HTA_Centre |
HTA_Right |

#### Instances

Instances details

Show HTextAnchor Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods showsPrec :: Int -> HTextAnchor -> ShowS Source # show :: HTextAnchor -> String Source # showList :: [HTextAnchor] -> ShowS Source #
Eq HTextAnchor Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods (==) :: HTextAnchor -> HTextAnchor -> Bool Source # (/=) :: HTextAnchor -> HTextAnchor -> Bool Source #
Ord HTextAnchor Source # |

Instance details

Defined in Graphics.Rendering.Chart.Backend.Types

Methods

compare :: HTextAnchor -> HTextAnchor -> Ordering Source #

(<) :: HTextAnchor -> HTextAnchor -> Bool Source #

(<=) :: HTextAnchor -> HTextAnchor -> Bool Source #

(>) :: HTextAnchor -> HTextAnchor -> Bool Source #

(>=) :: HTextAnchor -> HTextAnchor -> Bool Source #

max :: HTextAnchor -> HTextAnchor -> HTextAnchor Source #

min :: HTextAnchor -> HTextAnchor -> HTextAnchor Source #

data VTextAnchor Source #

Possible vertical anchor points for text.

Constructors

VTA_Top |
VTA_Centre |
VTA_Bottom |
VTA_BaseLine |

#### Instances

Instances details

Show VTextAnchor Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods showsPrec :: Int -> VTextAnchor -> ShowS Source # show :: VTextAnchor -> String Source # showList :: [VTextAnchor] -> ShowS Source #
Eq VTextAnchor Source # |
Instance details Defined in Graphics.Rendering.Chart.Backend.Types Methods (==) :: VTextAnchor -> VTextAnchor -> Bool Source # (/=) :: VTextAnchor -> VTextAnchor -> Bool Source #
Ord VTextAnchor Source # |

Instance details

Defined in Graphics.Rendering.Chart.Backend.Types

Methods

compare :: VTextAnchor -> VTextAnchor -> Ordering Source #

(<) :: VTextAnchor -> VTextAnchor -> Bool Source #

(<=) :: VTextAnchor -> VTextAnchor -> Bool Source #

(>) :: VTextAnchor -> VTextAnchor -> Bool Source #

(>=) :: VTextAnchor -> VTextAnchor -> Bool Source #

max :: VTextAnchor -> VTextAnchor -> VTextAnchor Source #

min :: VTextAnchor -> VTextAnchor -> VTextAnchor Source #

font_name :: Lens' FontStyle String Source #

font_size :: Lens' FontStyle Double Source #

font_slant :: Lens' FontStyle FontSlant Source #

font_weight :: Lens' FontStyle FontWeight Source #

font_color :: Lens' FontStyle (AlphaColour Double) Source #

type AlignmentFn = Point -> Point Source #

A function to align points for a certain rendering device.

data AlignmentFns Source #

Holds the point and coordinate alignment function.

vectorAlignmentFns :: AlignmentFns Source #

Alignment to render on vector based graphics.

bitmapAlignmentFns :: AlignmentFns Source #

Alignment to render on raster based graphics.