module Graphics.Rendering.Chart.Plot.Points(
PlotPoints(..),
defaultPlotPoints,
plot_points_title,
plot_points_style,
plot_points_values,
) where
import Control.Lens
import Graphics.Rendering.Chart.Geometry
import Graphics.Rendering.Chart.Drawing
import Graphics.Rendering.Chart.Renderable
import Graphics.Rendering.Chart.Plot.Types
import Data.Colour (opaque)
import Data.Colour.Names (black, blue)
import Data.Default.Class
data PlotPoints x y = PlotPoints {
_plot_points_title :: String,
_plot_points_style :: PointStyle,
_plot_points_values :: [(x,y)]
}
instance ToPlot PlotPoints where
toPlot p = Plot {
_plot_render = renderPlotPoints p,
_plot_legend = [(_plot_points_title p, renderPlotLegendPoints p)],
_plot_all_points = (map fst pts, map snd pts)
}
where
pts = _plot_points_values p
renderPlotPoints :: PlotPoints x y -> PointMapFn x y -> ChartBackend ()
renderPlotPoints p pmap = do
mapM_ (drawPoint ps . pmap') (_plot_points_values p)
where
pmap' = mapXY pmap
ps = (_plot_points_style p)
renderPlotLegendPoints :: PlotPoints x y -> Rect -> ChartBackend ()
renderPlotLegendPoints p r@(Rect p1 p2) = do
drawPoint ps (Point (p_x p1) ((p_y p1 + p_y p2)/2))
drawPoint ps (Point ((p_x p1 + p_x p2)/2) ((p_y p1 + p_y p2)/2))
drawPoint ps (Point (p_x p2) ((p_y p1 + p_y p2)/2))
where
ps = (_plot_points_style p)
defaultPlotPoints :: PlotPoints x y
defaultPlotPoints = def
instance Default (PlotPoints x y) where
def = PlotPoints
{ _plot_points_title = ""
, _plot_points_style = def
, _plot_points_values = []
}
$( makeLenses ''PlotPoints )