mirror of
https://github.com/codedownio/haskell-plot.git
synced 2025-04-16 03:16:23 +00:00
add background colours for figure and plot
This commit is contained in:
parent
f1408aa325
commit
3f18228974
@ -75,6 +75,17 @@ defaultGridLine = ColourLine grey
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
defaultFigureBackgroundColour :: Color
|
||||
defaultFigureBackgroundColour = white
|
||||
|
||||
defaultFigureForegroundColour :: Color
|
||||
defaultFigureForegroundColour = black
|
||||
|
||||
defaultPlotBackgroundColour :: Color
|
||||
defaultPlotBackgroundColour = white
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
defaultBarWidth :: Double
|
||||
defaultBarWidth = 5
|
||||
|
||||
@ -197,7 +208,7 @@ defaultSupply = SupplyData defaultColourList defaultGlyphList
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
emptyPlot :: PlotData
|
||||
emptyPlot = Plot False defaultPlotPadding NoText (Ranges (Left (Range Linear (-1) 1)) (Left (Range Linear (-1) 1)))
|
||||
emptyPlot = Plot False defaultPlotBackgroundColour defaultPlotPadding NoText (Ranges (Left (Range Linear (-1) 1)) (Left (Range Linear (-1) 1)))
|
||||
[] BarSpread undefined Nothing []
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
@ -208,7 +219,7 @@ emptyPlots = (A.listArray ((0,0),(0,0)) [])
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
emptyFigure :: FigureData
|
||||
emptyFigure = Figure defaultFigurePadding NoText NoText emptyPlots
|
||||
emptyFigure = Figure defaultFigureBackgroundColour defaultFigurePadding NoText NoText emptyPlots
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
|
@ -35,6 +35,7 @@ module Graphics.Rendering.Plot.Figure (
|
||||
-- * Figures
|
||||
, newFigure
|
||||
-- ** Formatting
|
||||
, setBackgroundColour
|
||||
, setFigurePadding
|
||||
, withTitle
|
||||
, withSubTitle
|
||||
@ -42,6 +43,8 @@ module Graphics.Rendering.Plot.Figure (
|
||||
, withPlot, withPlots
|
||||
-- * Sub-plots
|
||||
, Plot()
|
||||
-- ** Colour
|
||||
, setPlotBackgroundColour
|
||||
-- ** Plot elements
|
||||
, Border
|
||||
, setBorder
|
||||
@ -212,7 +215,7 @@ withBarDefaults m = do
|
||||
|
||||
-- | create a new blank 'Figure'
|
||||
newFigure :: Figure ()
|
||||
newFigure = putFigure $ Figure defaultFigurePadding NoText NoText
|
||||
newFigure = putFigure $ Figure defaultFigureBackgroundColour defaultFigurePadding NoText NoText
|
||||
(A.listArray ((1,1),(1,1)) [Nothing])
|
||||
{-
|
||||
newLineFigure :: DataSeries -- ^ the y series
|
||||
@ -235,6 +238,10 @@ newFigure Line d@(DS_1toN _ _) = putFigure $ newLineFigure d
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
-- | set the background colour of the figure
|
||||
setBackgroundColour :: Color -> Figure ()
|
||||
setBackgroundColour c = modifyFigure $ \s -> s { _back_clr = c }
|
||||
|
||||
-- | set the padding of the figure
|
||||
setFigurePadding :: Double -> Double -> Double -> Double -> Figure ()
|
||||
setFigurePadding l r b t = modifyFigure $ \s -> s { _fig_pads = Padding l r b t }
|
||||
|
@ -17,6 +17,7 @@ module Graphics.Rendering.Plot.Figure.Plot (
|
||||
-- * Plot elements
|
||||
, Border
|
||||
, setBorder
|
||||
, setPlotBackgroundColour
|
||||
, setPlotPadding
|
||||
, withHeading
|
||||
-- * Series data
|
||||
@ -114,6 +115,10 @@ import qualified Graphics.Rendering.Plot.Figure.Plot.Annotation as AN
|
||||
setBorder :: Border -> Plot ()
|
||||
setBorder b = modify $ \s -> s { _border = b }
|
||||
|
||||
-- | set the plot background colour
|
||||
setPlotBackgroundColour :: Color -> Plot ()
|
||||
setPlotBackgroundColour c = modify $ \s -> s { _back_colr = c }
|
||||
|
||||
-- | set the padding of the subplot
|
||||
setPlotPadding :: Double -> Double -> Double -> Double -> Plot ()
|
||||
setPlotPadding l r b t = modify $ \s -> s { _plot_pads = Padding l r b t }
|
||||
|
@ -150,10 +150,10 @@ writeSurfaceFS rw fn (w,h) f = rw fn (fromIntegral w) (fromIntegral h) (flip C.r
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
renderFigure :: FigureData -> Render ()
|
||||
renderFigure (Figure p t s d) = do
|
||||
renderFigure (Figure b p t s d) = do
|
||||
cairo $ do
|
||||
C.save
|
||||
C.setSourceRGBA 1 1 1 1
|
||||
setColour b
|
||||
C.paint
|
||||
C.restore
|
||||
|
||||
|
@ -33,6 +33,8 @@ module Graphics.Rendering.Plot.Render.Plot (
|
||||
|
||||
import qualified Data.Array.IArray as A
|
||||
|
||||
import Data.Colour.Names
|
||||
|
||||
import qualified Graphics.Rendering.Cairo as C
|
||||
--import qualified Graphics.Rendering.Pango as P
|
||||
|
||||
@ -84,34 +86,25 @@ renderPlots d = do
|
||||
put bb) (A.assocs d)
|
||||
|
||||
renderPlot :: PlotData -> Render ()
|
||||
renderPlot (Plot b p hd r a bc d l an) = do
|
||||
renderPlot (Plot b c p hd r a bc d l an) = do
|
||||
tx <- bbCentreWidth
|
||||
ty <- bbTopHeight
|
||||
(_,th) <- renderText hd Centre TTop tx ty
|
||||
if th == 0 then return () else bbLowerTop (th+textPad)
|
||||
{- attempt to have different colour plot area
|
||||
(BoundingBox x y w h) <- get
|
||||
cairo $ do
|
||||
setColour white
|
||||
C.moveTo x y
|
||||
C.lineTo (x+w) y
|
||||
C.lineTo (x+w) (y+h)
|
||||
C.lineTo x (y+h)
|
||||
C.stroke
|
||||
C.clip
|
||||
C.fill
|
||||
C.paint
|
||||
-}
|
||||
when (th /= 0) $ bbLowerTop (th+textPad)
|
||||
legend <- renderLegend l d
|
||||
padding <- renderAxes p r a
|
||||
(axes,padding) <- renderAxes p r a
|
||||
renderBorder b
|
||||
cairo C.save
|
||||
clipBoundary
|
||||
when (c /= white) (do
|
||||
cairo $ do
|
||||
setColour c
|
||||
C.paint)
|
||||
renderData r bc d
|
||||
renderAnnotations r an
|
||||
cairo C.restore
|
||||
legend padding
|
||||
|
||||
axes
|
||||
renderBorder :: Border -> Render ()
|
||||
renderBorder False = return ()
|
||||
renderBorder True = do
|
||||
|
@ -107,15 +107,16 @@ isZeroPadding (Padding l0 r0 b0 t0) (Padding l1 r1 b1 t1) = do
|
||||
else return t1
|
||||
return $ Padding l r b t
|
||||
|
||||
renderAxes :: Padding -> Ranges -> [AxisData] -> Render Padding
|
||||
renderAxes :: Padding -> Ranges -> [AxisData] -> Render (Render (),Padding)
|
||||
renderAxes p r axes = do
|
||||
lp <- foldM shiftForAxisLabel (Padding 0 0 0 0) axes
|
||||
tp <- foldM (shiftForTicks r) (Padding 0 0 0 0) axes
|
||||
let apd = addPadding lp tp
|
||||
p' <- isZeroPadding p apd
|
||||
mapM_ (renderAxisLabel p') axes
|
||||
mapM_ (renderAxis r) axes
|
||||
return p'
|
||||
return ((do
|
||||
mapM_ (renderAxisLabel p') axes
|
||||
mapM_ (renderAxis r) axes
|
||||
),p')
|
||||
|
||||
shiftForAxisLabel :: Padding -> AxisData -> Render Padding
|
||||
shiftForAxisLabel p (Axis _ _ _ _ _ _ _ NoText) = return p
|
||||
|
@ -419,6 +419,7 @@ data BarSetting = BarNone | BarSpread | BarStack
|
||||
-- | a plot
|
||||
data PlotData = Plot {
|
||||
_border :: Border
|
||||
, _back_colr :: Color
|
||||
, _plot_pads :: Padding
|
||||
, _heading :: TextEntry
|
||||
, _ranges :: Ranges
|
||||
@ -474,7 +475,8 @@ annoteInPlot m = FP $ lift $ (mapReaderT annoteInPlot') (runAnnote m)
|
||||
|
||||
-- | a chart has a title and contains one or more plots
|
||||
data FigureData = Figure {
|
||||
_fig_pads :: Padding
|
||||
_back_clr :: Color
|
||||
, _fig_pads :: Padding
|
||||
, _title :: TextEntry
|
||||
, _subtitle :: TextEntry
|
||||
, _plots :: Plots
|
||||
|
Loading…
x
Reference in New Issue
Block a user