Skip to content

API Changes for version 1.0

Jan Bracker edited this page Aug 26, 2013 · 3 revisions

Whilst previous versions of the library have had minor API, version 1.0 brings several significant changes.

Separation of backend imports

Now there is a clean package level separation between the chart core and the rendering backend, this is reflected in the imports. Typically two imports are required:

import Graphics.Rendering.Chart
import Graphics.Rendering.Chart.Backend.Cairo

Use of Control.Lens

The Control.Lens package has sufficient community acceptance to be the prefered record access library for haskell. The chart library has hence migrated from Data.Accessor to the lens library. The lens library is large, with a huge number of operations (a short overview is here). However in the context of the chart library, the two main operators required are .~ - which purely updates a value pointed to by a lens, and standard function composition ., which composes lens to "point" at subvalues. A simple example:

setLinesBlue :: PlotLines a b -> PlotLines a b
setLinesBlue = plot_lines_style  . line_color .~ opaque blue

and there are many more examples in the various test and demo charts.

Use of Data.Default

The chart library makes available default values of many types to reduce the code required to draw a chart. In prior versions, defaults have been provided via a constant value, eg:

defaultPlotLines :: PlotLines x y

The library now uses Data.Default.Class to give a consistent API to defaults. Instances of this typeclass

class Default a where
    def :: a

are provided for each value. Hence in user code where one previously wrote defaultXXX, one now just writes def.

The old names are still available, but marked as deprecated, and will be removed in a future release.

Clone this wiki locally