Module

Hylograph.Brush

Package
purescript-hylograph-selection
Repository
afcondon/purescript-hylograph-selection

D3 Brush API

PureScript bindings for d3-brush, enabling interactive rectangular region selection in SVG visualizations.

Basic Usage

import Hylograph.Brush (attachBrush, BrushSelection(..))

-- Attach a 2D brush to a <g> element
brushHandle <- attachBrush brushGroup
  { extent: { x0: 0.0, y0: 0.0, x1: width, y1: height }
  , onStart: Nothing
  , onBrush: Just \event -> case event.selection of
      Selection2D s -> log $ "Brushing: " <> show s
      _ -> pure unit
  , onEnd: Just \event -> updateSelection event.selection
  }

-- Later, clear the brush programmatically
clearBrush brushHandle

Cross-filtering (SPLOM)

-- In each cell's brush handler
onEnd: Just \event -> case event.selection of
  Selection2D s -> do
    -- Filter data points within selection
    let filtered = filter (isInSelection s) allData
    -- Update opacity of all points across all cells
    updatePointOpacity filtered
  NoSelection ->
    -- Brush cleared, show all points
    resetPointOpacity

#attachBrush Source

attachBrush :: Element -> BrushConfig -> Effect BrushHandle

Attach a 2D brush to an element

The brush allows users to select a rectangular region by clicking and dragging. Use this for scatterplots, heatmaps, and other 2D visualizations.

The element should typically be a <g> group element within your SVG. The brush will create overlay, selection, and handle elements as children.

Returns a BrushHandle for programmatic control (clear, move, get selection).

#attachBrushX Source

attachBrushX :: Element -> BrushConfig -> Effect BrushHandle

Attach a 1D horizontal brush (brushX)

Constrains selection to the x-axis only. Useful for time series or 1D distributions.

#attachBrushY Source

attachBrushY :: Element -> BrushConfig -> Effect BrushHandle

Attach a 1D vertical brush (brushY)

Constrains selection to the y-axis only.

#clearBrush Source

clearBrush :: BrushHandle -> Effect Unit

Clear the brush selection programmatically

Removes the visible brush selection without triggering end events.

#moveBrush Source

moveBrush :: BrushHandle -> BrushSelection -> Effect Unit

Move the brush selection programmatically

Sets the brush selection to the given bounds. Pass NoSelection to clear. Useful for syncing brushes across multiple views or setting initial selection.

#getBrushSelection Source

getBrushSelection :: BrushHandle -> Effect BrushSelection

Get the current brush selection

Returns NoSelection if no brush is active.

Re-exports from Hylograph.Brush.FFI

#BrushHandle Source

data BrushHandle

Opaque handle for controlling a brush programmatically

Re-exports from Hylograph.Brush.Types

#BrushSelection Source

data BrushSelection

Brush selection - the rectangular region selected by the user

For 2D brush: x0, y0 (top-left) to x1, y1 (bottom-right) For 1D brush: only x0/x1 or y0/y1 are meaningful

Constructors

Instances

#BrushExtent Source

type BrushExtent = { x0 :: Number, x1 :: Number, y0 :: Number, y1 :: Number }

Extent for brush (defines the brushable area)

#BrushEvent Source

type BrushEvent = { selection :: BrushSelection }

Brush event passed to handlers

#BrushConfig Source

type BrushConfig = { extent :: BrushExtent, onBrush :: Maybe (BrushEvent -> Effect Unit), onEnd :: Maybe (BrushEvent -> Effect Unit), onStart :: Maybe (BrushEvent -> Effect Unit) }

Configuration for creating a brush

  • extent: The brushable area bounds
  • onStart: Called when brush gesture starts
  • onBrush: Called during brush gesture (as selection changes)
  • onEnd: Called when brush gesture ends

#selectionWidth Source

selectionWidth :: BrushSelection -> Number

Get the width of a brush selection

#selectionHeight Source

selectionHeight :: BrushSelection -> Number

Get the height of a brush selection

#isInSelection Source

isInSelection :: Number -> Number -> BrushSelection -> Boolean

Check if a point is within a 2D brush selection

Returns true if the point (x, y) is inside the selection bounds. Returns false for 1D selections or NoSelection.

#defaultBrushConfig Source

defaultBrushConfig :: BrushConfig

Default brush configuration

Extent covers 0,0 to 100,100 with no handlers. Override as needed.

Modules
Data.DependencyGraph
Hylograph.AST
Hylograph.Axis.Axis
Hylograph.Brush
Hylograph.Brush.FFI
Hylograph.Brush.Types
Hylograph.Classify
Hylograph.Data.Graph
Hylograph.Data.Graph.Algorithms
Hylograph.Data.Node
Hylograph.Data.Tree
Hylograph.Expr.Animation
Hylograph.Expr.Attr
Hylograph.Expr.Datum
Hylograph.Expr.Expr
Hylograph.Expr.Friendly
Hylograph.Expr.Integration
Hylograph.Expr.Interpreter.CodeGen
Hylograph.Expr.Interpreter.Eval
Hylograph.Expr.Interpreter.Meta
Hylograph.Expr.Interpreter.PureSVG
Hylograph.Expr.Interpreter.SVG
Hylograph.Expr.Path
Hylograph.Expr.Path.Generators
Hylograph.Expr.Sugar
Hylograph.Expr.Units
Hylograph.HATS
Hylograph.HATS.Friendly
Hylograph.HATS.InterpreterTick
Hylograph.HATS.Transitions
Hylograph.Interaction.Brush
Hylograph.Interaction.Coordinated
Hylograph.Interaction.Pointer
Hylograph.Interaction.Zoom
Hylograph.Internal.Attribute
Hylograph.Internal.Behavior.FFI
Hylograph.Internal.Behavior.Types
Hylograph.Internal.Capabilities.Selection
Hylograph.Internal.Capabilities.Transition
Hylograph.Internal.FFI
Hylograph.Internal.Selection.Join
Hylograph.Internal.Selection.Operations
Hylograph.Internal.Selection.Operations.Conversions
Hylograph.Internal.Selection.Operations.Helpers
Hylograph.Internal.Selection.Operations.Selection
Hylograph.Internal.Selection.Query
Hylograph.Internal.Selection.Types
Hylograph.Internal.Transition.FFI
Hylograph.Internal.Transition.Manager
Hylograph.Internal.Transition.Scene
Hylograph.Internal.Transition.Types
Hylograph.Internal.Types
Hylograph.Interpreter.D3
Hylograph.Interpreter.English
Hylograph.Interpreter.Mermaid
Hylograph.Interpreter.MetaAST
Hylograph.Interpreter.SemiQuine
Hylograph.Interpreter.SemiQuine.TreeToCode
Hylograph.Interpreter.SemiQuine.Types
Hylograph.Render
Hylograph.Scale
Hylograph.Scale.FP
Hylograph.Shape.Arc
Hylograph.Shape.Pie
Hylograph.Shape.Polygon
Hylograph.Tooltip
Hylograph.Transform
Hylograph.TreeDSL
Hylograph.TreeDSL.ShapeTree
Hylograph.Unified
Hylograph.Unified.Attribute
Hylograph.Unified.DataDSL
Hylograph.Unified.Display
Hylograph.Unified.Examples
Hylograph.Unified.Join
Hylograph.Unified.Sugar