DataViz.Layout.Pattern
- Package
- purescript-hylograph-layout
- Repository
- afcondon/purescript-hylograph-layout
Geometric Layout Patterns
Simple, deterministic layout functions for positioning N items within a viewport. Each function handles all the tedious calculations (aspect ratio, spacing, centering) and returns an array of points ready to zip with your data.
Usage
import DataViz.Layout.Pattern (grid, phyllotaxis)
import DataViz.Layout.Pattern.Types (viewportWithPadding)
-- Layout 100 items in a grid with 20px padding
let vp = viewportWithPadding 800.0 600.0 20.0
let positions = grid vp 100
-- Zip with your data
let positioned = Array.zipWith (\pos datum -> { x: pos.x, y: pos.y, datum })
positions myData
#phyllotaxis Source
phyllotaxis :: Viewport -> Int -> Array PointPhyllotaxis layout - golden angle spiral like sunflower seeds Produces beautiful, naturally-looking distributions. Items are placed at increasing distances from center using golden angle.
#layered Source
layered :: Viewport -> Array Int -> Array PointLayered layout - multiple horizontal rows with varying item counts. Perfect for neural networks, hierarchies, or any row-based visualization.
Takes an array of item counts per layer. Returns flat array of all positions. Layers are evenly spaced vertically; items within each layer are evenly spaced horizontally across the full width.
-- Neural network: 4 inputs, 8 hidden, 8 hidden, 2 outputs
let positions = layered vp [4, 8, 8, 2]
#masonry Source
masonry :: Int -> Number -> Viewport -> Array Number -> Array RectMasonry (Pinterest-style) layout with fixed column count. Places each item into the shortest column, producing a compact arrangement.
Takes column count, gap between items, viewport, and array of item heights. Returns positioned rectangles in input order.
let rects = masonry 3 10.0 (viewport 800.0 600.0) [100.0, 150.0, 80.0, 200.0, 120.0]
#shelf Source
shelf :: Number -> Viewport -> Array { height :: Number, width :: Number } -> Array RectShelf layout — place items left-to-right, wrapping to the next row on overflow. Horizontal complement to masonry. Each item has its own width and height.
let rects = shelf 8.0 (viewport 800.0 600.0) [{width: 120.0, height: 80.0}, ...]
#waffle Source
waffle :: Int -> Int -> Viewport -> Array Int -> Array WaffleCellWaffle chart — proportional unit grid (alternative to pie charts). A rows×cols grid where cells are colored by category proportional to each category's count. Cells filled left-to-right, top-to-bottom.
let cells = waffle 10 10 (viewport 400.0 400.0) [30, 25, 20, 15, 10]
#stacked Source
stacked :: Number -> Viewport -> Array (Array Number) -> Array (Array Rect)Vertical stacked bar chart — groups of segments stacked bottom-to-top. Each inner array is one bar's segments. All bars scaled to the same maximum.
let rects = stacked 8.0 (viewport 800.0 400.0) [[30.0, 20.0, 10.0], [25.0, 35.0, 5.0]]
#justified Source
justified :: Number -> Number -> Viewport -> Array Number -> Array RectJustified layout — all rows fill exact viewport width, row heights vary. Like Google Images or Flickr galleries. Input is aspect ratios (width/height).
Algorithm: greedily fill rows. Each row's height = availableWidth / sum(aspectRatios). When height drops below threshold, break to next row. Last row left-aligned at target height.
let rects = justified 200.0 8.0 (viewport 800.0 600.0) [1.5, 0.75, 1.33, 2.0, 0.8]
#binPack Source
binPack :: Viewport -> Array { height :: Number, width :: Number } -> Array Rect2D rectangle bin packing using Skyline Bottom-Left algorithm. Packs rectangles into the viewport like a texture atlas / sprite sheet. Items are sorted tallest-first for better packing.
let rects = binPack (viewport 800.0 600.0) [{width: 100.0, height: 80.0}, ...]
#calendarGrid Source
calendarGrid :: Int -> Int -> Number -> Viewport -> Array RectCalendar grid — 7-column weekly layout with weekday offset. Pure geometry: caller converts dates to day-of-week offset and day count.
-- March 2026 starts on Sunday (offset 0), has 31 days
let rects = calendarGrid 0 31 4.0 (viewport 700.0 500.0)
#swimlane Source
swimlane :: Int -> Number -> Viewport -> Array { end :: Number, lane :: Int, start :: Number } -> Array RectSwimlane layout — horizontal lanes with items positioned by start/end. For timelines, Gantt charts, kanban boards. Start and end values are normalized 0.0-1.0, mapped to viewport width.
let rects = swimlane 3 4.0 (viewport 800.0 300.0)
[ {lane: 0, start: 0.0, end: 0.4}
, {lane: 1, start: 0.2, end: 0.8}
, {lane: 2, start: 0.5, end: 1.0}
]
Re-exports from DataViz.Layout.Pattern.Types
#WaffleCell Source
type WaffleCell = { category :: Int, rect :: Rect }A cell in a waffle chart, tagged with its category index
#viewportWithPadding Source
viewportWithPadding :: Number -> Number -> Number -> ViewportCreate a viewport with uniform padding
#uniformPadding Source
uniformPadding :: Number -> PaddingUniform padding on all sides
- Modules
- DataViz.
Layout. Adjacency - DataViz.
Layout. Adjacency. Layout - DataViz.
Layout. Adjacency. Types - DataViz.
Layout. Chord - DataViz.
Layout. Chord. Layout - DataViz.
Layout. Chord. Types - DataViz.
Layout. Hierarchy. Cluster - DataViz.
Layout. Hierarchy. Core - DataViz.
Layout. Hierarchy. EdgeBundle - DataViz.
Layout. Hierarchy. EdgeBundle. Bilink - DataViz.
Layout. Hierarchy. EdgeBundle. BundleCurve - DataViz.
Layout. Hierarchy. EdgeBundle. Hierarchy - DataViz.
Layout. Hierarchy. EdgeBundle. RadialCluster - DataViz.
Layout. Hierarchy. EdgeBundle. Types - DataViz.
Layout. Hierarchy. Link - DataViz.
Layout. Hierarchy. Pack - DataViz.
Layout. Hierarchy. Partition - DataViz.
Layout. Hierarchy. Tree - DataViz.
Layout. Hierarchy. TreeStyle - DataViz.
Layout. Hierarchy. Treemap - DataViz.
Layout. Hierarchy. Types - DataViz.
Layout. Pattern - DataViz.
Layout. Pattern. Adapters - DataViz.
Layout. Pattern. Types - DataViz.
Layout. Sankey. CSV - DataViz.
Layout. Sankey. Compute - DataViz.
Layout. Sankey. ComputeWithSteps - DataViz.
Layout. Sankey. Path - DataViz.
Layout. Sankey. Types - DataViz.
Layout. StateMachine - DataViz.
Layout. StateMachine. Layout - DataViz.
Layout. StateMachine. Path - DataViz.
Layout. StateMachine. Types