Module

Hylograph.Components.Treemap

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

Treemap component.

Packs rectangular cells into the chart's inner area, each cell sized proportionally to a numeric value. One row per cell — flat data only in v1; hierarchy is a future concern.

Uses the squarify algorithm (Bruls, Huijsen, van Wijk 2000), which greedily adds cells to alternating rows/columns, picking the axis that keeps the aspect ratio closest to 1. D3's default. Implemented inline here rather than in Hylograph.Shape so this component ships without a workspace retarget of hylograph-selection (see report at PR time); promoting squarify upstream is a clean follow-up once there's a second consumer.

series drives colour in the multi-series case (palette lookup by distinct series name). Single-series (the default) cycles the palette by cell index so individual cells are distinguishable without requiring the caller to supply a fake series projection.

Labels are centred in cells whose area meets labelMinArea; smaller cells rely on the tooltip alone to avoid text overflow.

#Encoding Source

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

#Config Source

type Config :: Row Type -> Typetype Config r = { borderColor :: String, borderWidth :: Number, cellPadding :: Number, encoding :: Encoding r, highlightGroup :: Maybe String, labelMinArea :: Number, layout :: Layout, showLabels :: Boolean }

#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. { label :: Record r -> String, value :: Record r -> Number } -> Config r

Smart-constructor with reasonable defaults.

Caller provides the two essential projections (value, label). key defaults to label; tooltip to "<label>: <value>"; series to \_ -> "" so the default is a single-series treemap where each cell gets its own palette colour by index.

#treemap Source

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

Build a HATS Tree for this treemap.

#frame Source

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