chart-svg-0.6.0.0: Charting library targetting SVGs.
Safe HaskellSafe-Inferred
LanguageGHC2021

Chart.Bar

Description

Bar charts

Synopsis

Documentation

data BarOptions Source #

Typical bar chart options.

The internal model for a bar chart (across the x-axis for a vertical bar chart) is:

  • half the outerGap at the start and the end.
  • each row collection of bars, including the outerGap and innerGaps has a value of 1.
  • the entire x range of the chart isequal to the number of rows in the bar data.
  • The value of inner and outer gaps are relative to this model.
>>> let barDataExample = BarData [[1, 2, 3, 5, 8, 0, -2, 11, 2, 1], [1 .. 10]] (("row " <>) . pack . show <$> [1 .. 11]) (("column " <>) . pack . show <$> [1 .. 2])
>>> let barExample = barChart defaultBarOptions barDataExample
writeChartOptions "other/bar.svg" barExample

Constructors

BarOptions 

Fields

Instances

Instances details
Generic BarOptions Source # 
Instance details

Defined in Chart.Bar

Associated Types

type Rep BarOptions :: Type -> Type #

Show BarOptions Source # 
Instance details

Defined in Chart.Bar

Eq BarOptions Source # 
Instance details

Defined in Chart.Bar

type Rep BarOptions Source # 
Instance details

Defined in Chart.Bar

type Rep BarOptions = D1 ('MetaData "BarOptions" "Chart.Bar" "chart-svg-0.6.0.0-HjsGv1l8hv76XDZORokPY6" 'False) (C1 ('MetaCons "BarOptions" 'PrefixI 'True) (((S1 ('MetaSel ('Just "barRectStyles") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Style]) :*: (S1 ('MetaSel ('Just "barTextStyles") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Style]) :*: S1 ('MetaSel ('Just "outerGap") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Double))) :*: (S1 ('MetaSel ('Just "innerGap") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Double) :*: (S1 ('MetaSel ('Just "textGap") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Double) :*: S1 ('MetaSel ('Just "textGapNegative") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Double)))) :*: ((S1 ('MetaSel ('Just "textShiftVert") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Double) :*: (S1 ('MetaSel ('Just "displayValues") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "valueFormatN") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FormatN))) :*: (S1 ('MetaSel ('Just "barOrientation") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Orientation) :*: (S1 ('MetaSel ('Just "barStacked") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Stacked) :*: S1 ('MetaSel ('Just "barLegendOptions") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 LegendOptions))))))

defaultBarOptions :: BarOptions Source #

The official bar options.

data BarData Source #

Two dimensional data, maybe with row and column labels.

Constructors

BarData 

Fields

Instances

Instances details
Generic BarData Source # 
Instance details

Defined in Chart.Bar

Associated Types

type Rep BarData :: Type -> Type #

Methods

from :: BarData -> Rep BarData x #

to :: Rep BarData x -> BarData #

Show BarData Source # 
Instance details

Defined in Chart.Bar

Eq BarData Source # 
Instance details

Defined in Chart.Bar

Methods

(==) :: BarData -> BarData -> Bool #

(/=) :: BarData -> BarData -> Bool #

type Rep BarData Source # 
Instance details

Defined in Chart.Bar

type Rep BarData = D1 ('MetaData "BarData" "Chart.Bar" "chart-svg-0.6.0.0-HjsGv1l8hv76XDZORokPY6" 'False) (C1 ('MetaCons "BarData" 'PrefixI 'True) (S1 ('MetaSel ('Just "barData") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [[Double]]) :*: (S1 ('MetaSel ('Just "barRowLabels") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Text]) :*: S1 ('MetaSel ('Just "barColumnLabels") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Text]))))

barRange :: [[Double]] -> Rect Double Source #

Calculate the Rect range of a bar data set.

>>> barRange [[1,2],[2,3]]
Rect 0.0 2.0 0.0 3.0
>>> barRange [[]]
Rect (-0.5) 0.5 (-0.5) 0.5

bars :: BarOptions -> BarData -> [Chart] Source #

A bar chart without hud trimmings.

>>> bars defaultBarOptions (BarData [[1,2],[2,3]] [] [])
[Chart {chartStyle = Style {size = 6.0e-2, borderSize = 5.0e-3, color = Colour 0.02 0.29 0.48 0.70, borderColor = Colour 0.02 0.29 0.48 1.00, scaleP = NoScaleP, anchor = AnchorMiddle, rotation = Nothing, translate = Nothing, escapeText = EscapeText, frame = Nothing, lineCap = Nothing, lineJoin = Nothing, dasharray = Nothing, dashoffset = Nothing, hsize = 0.6, vsize = 1.1, vshift = -0.25, glyphShape = SquareGlyph}, chartData = RectData [Rect (-0.5) (-0.26315789473684215) (-0.5) (-0.16666666666666669),Rect 2.631578947368418e-2 0.26315789473684204 (-0.5) 0.16666666666666663]},Chart {chartStyle = Style {size = 6.0e-2, borderSize = 5.0e-3, color = Colour 0.66 0.07 0.55 0.70, borderColor = Colour 0.66 0.07 0.55 1.00, scaleP = NoScaleP, anchor = AnchorMiddle, rotation = Nothing, translate = Nothing, escapeText = EscapeText, frame = Nothing, lineCap = Nothing, lineJoin = Nothing, dasharray = Nothing, dashoffset = Nothing, hsize = 0.6, vsize = 1.1, vshift = -0.25, glyphShape = SquareGlyph}, chartData = RectData [Rect (-0.26315789473684215) (-2.6315789473684292e-2) (-0.5) 0.16666666666666663,Rect 0.26315789473684204 0.4999999999999999 (-0.5) 0.5]}]
>>> bars defaultBarOptions (BarData [[]] [] [])
[]

barChart :: BarOptions -> BarData -> ChartOptions Source #

A bar chart.

>>> emptyBar = barChart defaultBarOptions (BarData [] [] [])
>>> foldOf (#chartTree % charts') emptyBar
[]

barRects :: BarOptions -> [[Double]] -> [[Rect Double]] Source #

Make bars from the double list values, normalizing to one :: Rect.

>>> barRects defaultBarOptions [[1,2],[2,3]]
[[Rect (-0.5) (-0.26315789473684215) (-0.5) (-0.16666666666666669),Rect 2.631578947368418e-2 0.26315789473684204 (-0.5) 0.16666666666666663],[Rect (-0.26315789473684215) (-2.6315789473684292e-2) (-0.5) 0.16666666666666663,Rect 0.26315789473684204 0.4999999999999999 (-0.5) 0.5]]
>>> barRects defaultBarOptions [[]]
[]

barTextCharts :: BarOptions -> BarData -> [Chart] Source #

Placed text, hold the bars.