Copyright | (C) 2016 Christopher Chalmers |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Christopher Chalmers |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
A pie plot is a circular statistical graphic, which is divided into slices to illustrate numerical proportion.
(see piePlot
example for code to make this plot)
- data PieState b n a
- piePlot :: (MonadState (Axis b Polar n) m, Plotable (Wedge n) b, Foldable f) => f a -> (a -> n) -> State (PieState b n a) () -> m ()
- piePlot' :: (MonadState (Axis b Polar n) m, Plotable (Wedge n) b, Foldable f) => f n -> m ()
- onWedges :: (a -> State (Plot (Wedge n) b) ()) -> State (PieState b n a) ()
- wedgeKeys :: Num n => (a -> String) -> State (PieState b n a) ()
- data Wedge n
- mkWedge :: Num n => Direction V2 n -> Angle n -> Wedge n
- class HasWedge f a where
- wedgePlot :: (v ~ BaseSpace c, v ~ V2, PointLike v n (Polar n), MonadState (Axis b c n) m, Plotable (Wedge n) b) => Direction V2 n -> Angle n -> State (Plot (Wedge n) b) () -> m ()
Pie plot
The state used to draw a part chart made of multiple pie wedges.
:: (MonadState (Axis b Polar n) m, Plotable (Wedge n) b, Foldable f) | |
=> f a | data for each wedge |
-> (a -> n) | extract weight of each wedge |
-> State (PieState b n a) () | |
-> m () |
Make a pie plot from a list of data by making a series of wedge plots.
Example
import Plots pieData = [("red", 3), ("blue", 4), ("green", 2), ("purple", 5)] piePlotAxis :: Axis B Polar Double piePlotAxis = polarAxis &~ do piePlot pieData snd $ wedgeKeys fst hide (axes . traversed)
piePlotExample = renderAxis piePlotAxis
:: (MonadState (Axis b Polar n) m, Plotable (Wedge n) b, Foldable f) | |
=> f n | weight of each wedge |
-> m () |
Make a pie plot from list of values without any changes.
Example
import Plots piePlotAxis' :: Axis B Polar Double piePlotAxis' = polarAxis &~ do piePlot' [1,3,5,2] wedgeInnerRadius .= 0.5 hide (axes . traversed)
pieExample' = renderAxis piePlotAxis'
onWedges :: (a -> State (Plot (Wedge n) b) ()) -> State (PieState b n a) () Source #
Modify the state for each wedge given the data entry.
Some common lenses to use on the Wedge
:
plotColour
- change the colour of the barsareaStyle
- modify the style of the barskey
- add a legend entry for that group of barswedgeOffset
- the offset of the wedge from the center
wedgeKeys :: Num n => (a -> String) -> State (PieState b n a) () Source #
Add a legend entry for each item given a function that extracts the item's name.
Wedges
Contains information to draw a single wedge of a pie. It is not
intended to be drawn directly. Instead use piePlot
.
Create a pie wedge with unit radius, starting at direction d
with
width theta
.
class HasWedge f a where Source #
pieWedge :: LensLike' f a (Wedge (N a)) Source #
Description on how to draw a wedge.
wedgeOuterRadius :: Functor f => LensLike' f a (N a) Source #
The outside radius of the wedge. Default is 1
.
wedgeInnerRadius :: Functor f => LensLike' f a (N a) Source #
The inside radius of the wedge. Default is $0$.
wedgeOffset :: Functor f => LensLike' f a (N a) Source #
The offset of the wedge from the center.
wedgeWidth :: Functor f => LensLike' f a (Angle (N a)) Source #
The width of the wedge, starting from the wedgeDirection
.
wedgeDirection :: Functor f => LensLike' f a (Direction V2 (N a)) Source #
The inititial direction of the wedge.
HasWedge f (Wedge n) Source # | |
(Functor f, HasWedge f a) => HasWedge f (Plot a b) Source # | |
((~) (* -> *) (BaseSpace c) V2, Settable f, Typeable * n) => HasWedge f (Axis b c n) Source # | |
((~) (* -> *) v V2, Applicative f, Typeable * n) => HasWedge f (StyledPlot b v n) Source # | |
(Applicative f, Typeable * b, (~) (* -> *) v V2, Typeable * n) => HasWedge f (DynamicPlot b v n) Source # | |
Applicative f => HasWedge f (PieState b n a) Source # | |
wedgePlot :: (v ~ BaseSpace c, v ~ V2, PointLike v n (Polar n), MonadState (Axis b c n) m, Plotable (Wedge n) b) => Direction V2 n -> Angle n -> State (Plot (Wedge n) b) () -> m () Source #
Add a single PiePlot
to the AxisState
from a data set.
Example
import Plots wedgePlotAxis :: Axis B Polar Double wedgePlotAxis = polarAxis &~ do wedgePlot xDir (38@@deg) $ key "wedge"
wedgeExample = renderAxis wedgePlotAxis