1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
-----------------------------------------------------------------------------
-- |
-- Module : Graphics.Rendering.Chart.Plot.Types
-- Copyright : (c) Tim Docker 2006, 2014
-- License : BSD-style (see chart/COPYRIGHT)
--
-- Datatypes and functions common to the implementation of the various
-- plot types.
--
{-# LANGUAGE TemplateHaskell #-}
module Graphics.Rendering.Chart.Plot.Types(
Plot(..),
joinPlot,
ToPlot(..),
mapXY,
plot_render,
plot_legend,
plot_all_points,
) where
import Graphics.Rendering.Chart.Geometry
import Graphics.Rendering.Chart.Drawing
import Control.Lens
-- | Interface to control plotting on a 2D area.
data Plot x y = Plot {
-- | Given the mapping between model space coordinates and device
-- coordinates, render this plot into a chart.
_plot_render :: PointMapFn x y -> BackendProgram (),
-- | Details for how to show this plot in a legend. For each item
-- the string is the text to show, and the function renders a
-- graphical sample of the plot.
_plot_legend :: [ (String, Rect -> BackendProgram ()) ],
-- | All of the model space coordinates to be plotted. These are
-- used to autoscale the axes where necessary.
_plot_all_points :: ([x],[y])
}
-- | A type class abstracting the conversion of a value to a Plot.
class ToPlot a where
toPlot :: a x y -> Plot x y
instance ToPlot Plot where
toPlot p = p
-- | Join any two plots together (they will share a legend).
joinPlot :: Plot x y -> Plot x y -> Plot x y
joinPlot Plot{ _plot_render = renderP
, _plot_legend = legendP
, _plot_all_points = (xsP,ysP) }
Plot{ _plot_render = renderQ
, _plot_legend = legendQ
, _plot_all_points = (xsQ,ysQ) }
= Plot{ _plot_render = \a-> renderP a >> renderQ a
, _plot_legend = legendP ++ legendQ
, _plot_all_points = ( xsP++xsQ, ysP++ysQ )
}
----------------------------------------------------------------------
mapXY :: PointMapFn x y -> (x,y) -> Point
mapXY f (x,y) = f (LValue x, LValue y)
----------------------------------------------------------------------
----------------------------------------------------------------------
$( makeLenses ''Plot )
|