Module

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

#grid Source

grid :: Viewport -> Int -> Array Point

Lay out N items in a grid, automatically choosing rows/columns to best fit the viewport's aspect ratio.

Items are centered within the viewport and evenly spaced.

#gridWithAspect Source

gridWithAspect :: Number -> Viewport -> Int -> Array Point

Grid with a specific target aspect ratio for cells (width/height)

#gridExact Source

gridExact :: Int -> Viewport -> Int -> Array Point

Grid with exact column count specified

#honeycomb Source

honeycomb :: Viewport -> Int -> Array Point

Honeycomb layout - offset alternating rows for hexagonal packing More compact than a regular grid for circular items.

#brick Source

brick :: Viewport -> Int -> Array Point

Brick layout - like honeycomb but with rectangular cells Good for text labels or rectangular items.

#phyllotaxis Source

phyllotaxis :: Viewport -> Int -> Array Point

Phyllotaxis layout - golden angle spiral like sunflower seeds Produces beautiful, naturally-looking distributions. Items are placed at increasing distances from center using golden angle.

#archimedean Source

archimedean :: Number -> Viewport -> Int -> Array Point

Archimedean spiral - constant spacing between arms

#fermat Source

fermat :: Number -> Viewport -> Int -> Array Point

Fermat spiral - like phyllotaxis but with configurable divergence angle

#radial Source

radial :: Viewport -> Int -> Array Point

Radial layout - items evenly distributed around a circle

#concentricRings Source

concentricRings :: Int -> Viewport -> Int -> Array Point

Concentric rings - distribute items across multiple rings Inner rings have fewer items proportional to their circumference.

#sunburst Source

sunburst :: Int -> Viewport -> Int -> Array Point

Sunburst layout - like concentric rings but with angular sectors

#horizontal Source

horizontal :: Viewport -> Int -> Array Point

Horizontal line across the viewport

#vertical Source

vertical :: Viewport -> Int -> Array Point

Vertical line down the viewport

#diagonal Source

diagonal :: Viewport -> Int -> Array Point

Diagonal from top-left to bottom-right

#along Source

along :: Point -> Point -> Int -> Array Point

Layout along an arbitrary line between two points

#layered Source

layered :: Viewport -> Array Int -> Array Point

Layered 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]

#layeredCentered Source

layeredCentered :: Viewport -> Array Int -> Array Point

Layered layout with items centered in each row. Unlike layered, this centers items using cell-based positioning (items are centered within evenly-divided cells, not edge-to-edge).

Better for when you want consistent margins at row edges.

Re-exports from DataViz.Layout.Pattern.Types

#Viewport Source

type Viewport = { height :: Number, padding :: Padding, width :: Number }

Viewport specification - the bounding box for layout

#Point Source

type Point = { x :: Number, y :: Number }

A 2D point

#Padding Source

type Padding = { bottom :: Number, left :: Number, right :: Number, top :: Number }

Padding specification (can be uniform or per-side)

#viewportWithPadding Source

viewportWithPadding :: Number -> Number -> Number -> Viewport

Create a viewport with uniform padding

#viewport Source

viewport :: Number -> Number -> Viewport

Create a viewport with no padding

#usableArea Source

usableArea :: Viewport -> { height :: Number, width :: Number, x :: Number, y :: Number }

Get the usable area after accounting for padding Returns { x, y, width, height } where x,y is the top-left of usable area

#uniformPadding Source

uniformPadding :: Number -> Padding

Uniform padding on all sides

#padding Source

padding :: { bottom :: Number, left :: Number, right :: Number, top :: Number } -> Padding

Per-side padding

#noPadding Source

noPadding :: Padding

No padding