-
Notifications
You must be signed in to change notification settings - Fork 85
API Changes for version 1.0
Whilst previous versions of the library have had minor API, version 1.0 brings several significant changes.
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
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.
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.