Skip to content
Tim Docker edited this page Aug 31, 2014 · 9 revisions

Version 1.3

Added Vector field plots

There is an example plot in the gallery. Thanks to Anton Vorontsov for the contribution.

New State module

A new API for constructing charts, based upon a state monad. This is to replace the existing Graphics.Rendering.Chart.Simple module. The wiki contains an overview of the API. Also, the code behind several of the example charts in the gallery has been updated to use this API.

New Easy Module

This module exports all key chart components (including the new State module) as well as these some key external components required to use the API:

  • Control.Lens
  • Data.Default.Class
  • Data.Colour
  • Data.Colour.Names

It also includes some helper functions to facilitate constructing scatter, line, and bar charts.

The Simple module has been deprecated.

The new Easy module is intended to replace Simple. All functions in the Simple module have been marked as deprecated, and will be removed in a future release.

API changes

Several (minor) changes have been made to improve the consistency and composability of the API.

These previously deprecated functions are removed. The def value from the Data.Default.Class should be used instead:

  • defaultLinearAxis
  • defaultLogAxis
  • defaultAxisStyle
  • defaultFontStyle
  • defaultPointStyle
  • defaultPlotAnnotation
  • defaultAreaSpots
  • defaultAreaSpots4D
  • defaultPlotBars
  • defaultPlotCandle
  • defaultPlotErrBars
  • defaultPlotFillBetween
  • defaultPlotLines
  • defaultPieLayout
  • defaultPieChart
  • defaultPieItem
  • defaultPlotPoints
  • defaultLayoutAxis
  • defaultStackedLayouts
  • defaultLegendStyle

These previously deprecated functions are removed, replaced by the more general renderableToFile:

  • renderableToPNGFile
  • renderableToPDFFile
  • renderableToPSFile
  • renderableToSVGFile
  • sparkLineToPDF
  • sparkLineToPNG

The deprecated CRender type alias has been remoted. Use ChartBackend in its place.

These definitions have been renamed:

  • fill_colour -> fill_color
  • setLayoutForeground -> layout_foreground
  • updateAllAxesStyles -> layout_axes_styles
  • setLayoutLRForeground -> layoutlr_foreground
  • updateAllAxesStylesLR -> layoutlr_axes_styles

The renderableToFile function present in both the Chart and Diagrams backend has had it's parameters reordered, making the function more usefullly composable:

renderableToFile :: FileOptions -> FilePath -> Renderable a -> IO (PickFn a)

Version 1.1

Thanks go to Jan Bracker for his summer of code contributions to this release.

Refactored Layout API

Previously there was a single datatype Layout1 that attempted to function both as a single and dual y axis chart. This has now been split into two different types:

-- | A Layout value is a single plot area, with single x and y
--   axes. The title is at the top and the legend at the bottom. It's
--   parametrized by the types of values to be plotted on the x
--   and y axes.
data Layout x y = ...

-- | A LayoutLR value is a single plot area, with an x axis and
--   independent left and right y axes, with a title at the top;
--   legend at the bottom. It's parametrized by the types of values
--   to be plotted on the x and two y axes.
data LayoutLR x y1 y2 = ...

More efficient SVG generation with Diagrams

V1.0 of the library rendered all text in SVG files by stroking the outlines of the fonts. Whilst simple this resulting in lengthy rendering times and large SVG files. This release has an alternative SVG rendering mode, where the fonts are embedded in the SVG file, text is rendered using the SVG text elements.

Simplified rendering to files

Both the cairo and diagrams backend now have a simple function to produce an output file in different formats. eg from the cairo backend:

data FileFormat = PNG | SVG | PS | PDF

data FileOptions = FileOptions {
  _fo_size :: (Int,Int),
  _fo_format :: FileFormat
}

instance Default FileOptions where
  def =  FileOptions (800,600) PNG

renderableToFile :: FileOptions -> Renderable a -> FilePath -> IO (PickFn a)

The existing functions to produce files of each type have been deprecated. Various low level functions remain to permit more control where required.

Version 1.0

Parts of these notes are based on this page.

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

More information on how to use backends can be found here.

Use of Control.Lens

The Control.Lens package has sufficient community acceptance to be the preffered 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

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.

New Diagrams backend

Since backends are now separated from the core library we have implemented a backend based on the Diagrams library. Details on how to use the new backend can be found here. This backend is the alternative if you don't want to or can't use cairo for rendering.

The backend is fully functional and supports all of charts, but there are some major drawbacks in the current implementation:

  • There are performance issues. Rendering charts with the diagrams backend is notably slower then using the original cairo backend.
  • The size of outputs in formats like SVG, PDF or EPS can be huge (several MB).

These issue come from the use of the SVGFonts library to render and measure text. It is used due to the lack of font metrics in the basic diagrams library. SVGFonts loads paths for each character (or glyph), composes them and renders the result using the diagrams path rendering capabilities. The performance issues are suspected to result from the repeated operations that have to be done on those paths. Outputs are bloated, because the path of each bit of text is written to the output separately and thus the font information is not shared. This also results in the missing support to select text in SVGs or PDFs.

There are efforts to fix some of the performance problem and the huge output sizes in the SVG format by embedding the needed font information and enabling to share it again.