Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- data Chart where
- newtype ChartTree = ChartTree {}
- tree' :: Iso' ChartTree (Tree (Maybe Text, [Chart]))
- chart' :: Traversal' ChartTree Chart
- charts' :: Traversal' ChartTree [Chart]
- named :: Text -> [Chart] -> ChartTree
- unnamed :: [Chart] -> ChartTree
- rename :: Maybe Text -> ChartTree -> ChartTree
- blank :: Rect Double -> ChartTree
- group :: Maybe Text -> [ChartTree] -> ChartTree
- filterChartTree :: (Chart -> Bool) -> ChartTree -> ChartTree
- data Orientation
- data Stacked
- data ChartAspect
- box :: Chart -> Maybe (Rect Double)
- sbox :: Chart -> Maybe (Rect Double)
- projectWith :: Rect Double -> Rect Double -> Chart -> Chart
- maybeProjectWith :: Maybe (Rect Double) -> Maybe (Rect Double) -> Chart -> Chart
- moveChart :: Point Double -> Chart -> Chart
- scaleChart :: Double -> Chart -> Chart
- scaleStyle :: Double -> Chart -> Chart
- colourChart :: (Colour -> Colour) -> Chart -> Chart
- projectChartTree :: Rect Double -> [Chart] -> [Chart]
- boxes :: [Chart] -> Maybe (Rect Double)
- box' :: Lens' ChartTree (Maybe (Rect Double))
- styleBoxes :: [Chart] -> Maybe (Rect Double)
- styleBox' :: Lens' ChartTree (Maybe (Rect Double))
- vert :: Double -> [ChartTree] -> ChartTree
- hori :: Double -> [ChartTree] -> ChartTree
- stack :: Int -> Double -> [ChartTree] -> ChartTree
- frameChart :: RectStyle -> Double -> [Chart] -> Chart
- isEmptyChart :: Chart -> Bool
- padChart :: Double -> [Chart] -> Chart
- rectangularize :: RectStyle -> ChartTree -> ChartTree
- glyphize :: GlyphStyle -> ChartTree -> ChartTree
- overText :: (TextStyle -> TextStyle) -> Chart -> Chart
- renamed :: Text -> ChartTree -> ChartTree
Charts
There are 6 Chart primitives, unified as the Chart type.
RectChart
: a rectangle in the XY-domain. For example, a
is the set of points on the XY Plane bounded by (0,0), (0,1), (1,0) & (1,1). Much of the library is built onRect
0 1 0 1Rect
Double
s but the base types are polymorphic.LineChart
: a list of points which represent connected straight lines. [Point
0 0,Point
1 1,Point
2 2,Point
3 3] is an example; three lines connected up to form a line from (0,0) to (3,3).GlyphChart
: aGlyphShape
which is a predefined shaped centered at aPoint
in XY space.TextChart
: text centered at aPoint
in XY space.PathChart
: specification of curvilinear paths using the SVG standards.BlankChart
: a rectangular space that has no visual representation.
What is a Chart is usually a combination of these primitives into a tree or list of charts.
Each Chart primitive is a product of a style (the syntactic representation of the data) and a list of data.
A simple example is:
>>>
let r = RectChart defaultRectStyle [one]
>>>
r
RectChart (RectStyle {borderSize = 1.0e-2, borderColor = Colour 0.02 0.29 0.48 1.00, color = Colour 0.02 0.73 0.80 0.10}) [Rect -0.5 0.5 -0.5 0.5]
Using the defaults, this chart is rendered as:
writeChartOptions "other/unit.hs" $ mempty & #hudOptions .~ defaultHudOptions & #charts .~ unnamed [r]
RectChart :: RectStyle -> [Rect Double] -> Chart | |
LineChart :: LineStyle -> [[Point Double]] -> Chart | |
GlyphChart :: GlyphStyle -> [Point Double] -> Chart | |
TextChart :: TextStyle -> [(Text, Point Double)] -> Chart | |
PathChart :: PathStyle -> [PathData Double] -> Chart | |
BlankChart :: [Rect Double] -> Chart |
A group of charts represented by a Tree
of chart lists with labelled branches. The labelling is particularly useful downstream, when groupings become grouped SVG elements with classes or ids.
tree' :: Iso' ChartTree (Tree (Maybe Text, [Chart])) Source #
Lens between ChartTree and the underlying Tree representation
named :: Text -> [Chart] -> ChartTree Source #
Convert a chart list to a tree, adding a specific text label.
data Orientation Source #
Verticle or Horizontal
Instances
Generic Orientation Source # | |
Defined in Chart.Primitive type Rep Orientation :: Type -> Type # from :: Orientation -> Rep Orientation x # to :: Rep Orientation x -> Orientation # | |
Show Orientation Source # | |
Defined in Chart.Primitive showsPrec :: Int -> Orientation -> ShowS # show :: Orientation -> String # showList :: [Orientation] -> ShowS # | |
Eq Orientation Source # | |
Defined in Chart.Primitive (==) :: Orientation -> Orientation -> Bool # (/=) :: Orientation -> Orientation -> Bool # | |
type Rep Orientation Source # | |
Whether to stack chart data
data ChartAspect Source #
The basis for the x-y ratio of a chart
Default style features tend towards assuming that the usual height of the overall svg image is around 1, and ChartAspect is based on this assumption, so that a ChartAspect of FixedAspect 1.5
, say, means a height of 1 and a width of 1.5.
FixedAspect Double | Rescale charts to a fixed x-y ratio, inclusive of hud and style features |
CanvasAspect Double | Rescale charts to an overall height of 1, preserving the x-y ratio of the data canvas. |
ChartAspect | Rescale charts to a height of 1, preserving the existing x-y ratio of the underlying charts, inclusive of hud and style. |
Instances
Boxes
Library functionality (rescaling, combining charts, working out axes and generally putting charts together) is driven by a box model. A box is a rectangular space that bounds chart elements.
box :: Chart -> Maybe (Rect Double) Source #
The Rect
which encloses the data elements of the chart. Bounding box is a synonym.
>>>
box r
Just Rect -0.5 0.5 -0.5 0.5
sbox :: Chart -> Maybe (Rect Double) Source #
The bounding box for a chart including both data and style elements.
>>>
sbox r
Just Rect -0.505 0.505 -0.505 0.505
In the above example, the border of the rectangle adds an extra 0.1 to the height and width of the bounding box enclosing the chart.
projectWith :: Rect Double -> Rect Double -> Chart -> Chart Source #
projects a Chart to a new space from an old rectangular space, preserving linear metric structure.
>>>
projectWith (fmap (2*) one) one r
RectChart (RectStyle {borderSize = 1.0e-2, borderColor = Colour 0.02 0.29 0.48 1.00, color = Colour 0.02 0.73 0.80 0.10}) [Rect -1.0 1.0 -1.0 1.0]
maybeProjectWith :: Maybe (Rect Double) -> Maybe (Rect Double) -> Chart -> Chart Source #
Maybe project a Chart to a new rectangular space from an old rectangular space, if both Rects exist.
scaleChart :: Double -> Chart -> Chart Source #
Scale a chart (effecting both the chart data and the style).
colourChart :: (Colour -> Colour) -> Chart -> Chart Source #
Modify chart colors, applying to both border and main colors.
projectChartTree :: Rect Double -> [Chart] -> [Chart] Source #
Project a chart tree to a new bounding box, guarding against singleton bounds.
box' :: Lens' ChartTree (Maybe (Rect Double)) Source #
Lens between a ChartTree and its bounding box.
styleBoxes :: [Chart] -> Maybe (Rect Double) Source #
Compute the bounding box of the data and style elements contained in a list of charts.
styleBox' :: Lens' ChartTree (Maybe (Rect Double)) Source #
Lens between a style bounding box and a ChartTree tree.
Note that a round trip may be only approximately isomorphic ie
forall c r. \c -> view styleBox' . set styleBox r c ~= r
Combinators
vert :: Double -> [ChartTree] -> ChartTree Source #
Vertically stack a list of trees (proceeding upwards), aligning them to the left
hori :: Double -> [ChartTree] -> ChartTree Source #
Horizontally stack a list of trees (proceeding to the right) with a gap between
stack :: Int -> Double -> [ChartTree] -> ChartTree Source #
Stack a list of tree charts horizontally, then vertically
frameChart :: RectStyle -> Double -> [Chart] -> Chart Source #
Create a frame over some charts with (additive) padding.
>>>
frameChart defaultRectStyle 0.1 [BlankChart []]
RectChart (RectStyle {borderSize = 1.0e-2, borderColor = Colour 0.02 0.29 0.48 1.00, color = Colour 0.02 0.73 0.80 0.10}) []
isEmptyChart :: Chart -> Bool Source #
Whether a chart is empty of data to be represented.
padChart :: Double -> [Chart] -> Chart Source #
Additive padding, framing or buffering for a chart list.
rectangularize :: RectStyle -> ChartTree -> ChartTree Source #
Make a new chart tree out of the bounding boxes of a chart tree.