Module

Hylograph.Components.BarChart

Package
purescript-hylograph-components
Repository
afcondon/purescript-hylograph-components

Bar chart component.

Surface style: one preset per Excel-class chart type. Users get a named component (BarChart) with a typed Config record they can edit field-by-field in Atelier or pass as a literal in code. Underneath the preset we reach for the grammar-of-graphics primitives HATS already provides.

Data is Foldable t => t (Record r) — Arrays, Lists, Sets, Maps (by value), all accepted. Encoding projections pull category + value + key + tooltip text out of each row; the defaults use category :: String and value :: Number, override when your row shape differs.

Coordinated hover is built in: each bar registers with HATS' onCoordinatedHighlightWithTooltip under a shared group. Two bar charts sharing a group on the same page will highlight together for matching keys.

#Orientation Source

data Orientation

Bar orientation. Vertical = categories along X, values up Y (default).

Constructors

#StackMode Source

data StackMode

How multiple rows sharing a category are arranged when there is more than one series.

  • Grouped: bars side-by-side within each category's band.
  • Stacked: bars stacked on the value axis; axis shows raw totals.
  • Normalized100: bars stacked and each category normalized to 100%; value axis shows percentages. Assumes one row per (category, series).

Single-series charts render identically under any mode.

Constructors

#Encoding Source

type Encoding :: Row Type -> Typetype Encoding r = { category :: Record r -> String, key :: Record r -> String, series :: Record r -> String, tooltip :: Record r -> String, value :: Record r -> Number }

Projections pulling each channel out of a row. series :: \_ -> "" in the default smart-constructor makes single-series usage a degenerate special case of the multi-series code path.

#AxisLabels Source

type AxisLabels = { x :: Maybe String, y :: Maybe String }

#Config Source

type Config :: Row Type -> Typetype Config r = { barPadding :: Number, encoding :: Encoding r, highlightGroup :: Maybe String, labels :: AxisLabels, layout :: Layout, orientation :: Orientation, stacking :: StackMode }

#Input Source

type Input :: (Type -> Type) -> Row Type -> Typetype Input t r = { config :: Config r, dataset :: t (Record r), theme :: Theme }

#config Source

config :: forall r. { category :: Record r -> String, value :: Record r -> Number } -> Config r

Smart-constructor for a Config with reasonable defaults.

Pass the two projections that can't be inferred (category, value). key defaults to category; tooltip defaults to "<category>: <value>". Everything layout/style-wise has a starter value you can mutate.

#barChart Source

barChart :: forall t r. Foldable t => Input t r -> Tree

Build a HATS Tree for this bar chart. Pure; rendering is the caller's concern (see Hylograph.Components.BarChart.Frame for a Halogen wrapper that calls rerender).

#frame Source

frame :: forall query output t r m. MonadAff m => Foldable t => Component query (FrameInput (Input t r)) output m

Halogen component wrapping barChart. Use with any Foldable container; the container type is carried through the FrameInput alias.