Module

Hylograph.Interaction.Pointer

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

Native Pointer Events based interactions

This module provides drag and other interactions using the modern Pointer Events API instead of D3. Benefits:

  • No d3-selection dependency
  • Unified mouse/touch/pen support
  • Multi-touch capable (via pointerId)
  • Better browser integration (setPointerCapture)

Usage

-- Simple drag with callbacks
cleanup <- attachPointerDrag element
  { onStart: \datum x y -> log "Started"
  , onDrag: \datum x y dx dy -> log $ "Moved: " <> show dx
  , onEnd: \datum x y -> log "Ended"
  }

-- Simulation-aware drag (for force simulations)
cleanup <- attachSimulationDrag element reheatSimulation

#attachPointerDrag Source

attachPointerDrag :: forall datum. Element -> PointerDragConfig datum -> Effect (Effect Unit)

Attach drag behavior using native Pointer Events

Returns a cleanup function that removes all event listeners.

Features:

  • Uses setPointerCapture for smooth dragging even outside element
  • Sets touch-action: none to prevent browser gestures
  • Sets cursor to 'grab' / 'grabbing'
  • Prevents native drag for images
cleanup <- attachPointerDrag circleElement
  { onStart: \node _ _ -> log $ "Dragging node " <> show node.id
  , onDrag: \node x y _ _ -> do
      node.fx = x
      node.fy = y
  , onEnd: \node _ _ -> do
      node.fx = null
      node.fy = null
  }

-- Later, to remove:
cleanup

#attachSimulationDrag Source

attachSimulationDrag :: Element -> Effect Unit -> Effect (Effect Unit)

Attach simulation-aware drag using Pointer Events

Simplified version for force simulation nodes:

  • Calls reheat function on drag start
  • Sets fx/fy during drag
  • Releases fx/fy on drag end

The element's __data__ must be the simulation node directly.

cleanup <- attachSimulationDrag circleElement reheatSimulation

#attachSimulationDragNested Source

attachSimulationDragNested :: Element -> Effect Unit -> Effect (Effect Unit)

Attach simulation-aware drag for nested datum structure

Like attachSimulationDrag but for when the element's datum has a .node field containing the actual simulation node.

-- Datum is { node :: SimNode, label :: String, ... }
cleanup <- attachSimulationDragNested groupElement reheatSimulation

#PointerDragConfig Source

type PointerDragConfig datum = { onDrag :: datum -> Number -> Number -> Number -> Number -> Effect Unit, onEnd :: datum -> Number -> Number -> Effect Unit, onStart :: datum -> Number -> Number -> Effect Unit }

Configuration for pointer drag behavior

All callbacks receive the datum bound to the element via __data__.

#attachSimpleDrag Source

attachSimpleDrag :: Element -> Unit -> Effect Element

Attach simple drag behavior using Pointer Events

Moves element via SVG transform attribute. No simulation awareness - just basic drag.

#registerSimulationForPointer Source

registerSimulationForPointer :: String -> Effect Unit -> Effect Unit

Register a simulation with the Pointer module's registry

This enables attachSimulationDragById to look up simulations by ID. Called automatically when using TreeAPI with SimulationDrag behavior.

#unregisterSimulationForPointer Source

unregisterSimulationForPointer :: String -> Effect Unit

Unregister a simulation from the Pointer module's registry

#attachSimulationDragById Source

attachSimulationDragById :: Element -> String -> Effect Element

Attach simulation drag by looking up simulation ID in registry

Used by TreeAPI's SimulationDrag simId behavior. Element's __data__ must be the simulation node directly.

#attachSimulationDragNestedById Source

attachSimulationDragNestedById :: Element -> String -> Effect Element

Attach simulation drag for nested datum by looking up simulation ID

Used by TreeAPI's SimulationDragNested simId behavior. Element's __data__ must have a .node field with the simulation node.

#pointerPosition Source

pointerPosition :: PointerEvent -> Element -> Effect Point

Get pointer position relative to a container element

Handles SVG coordinate transformation via CTM (Current Transform Matrix). Replacement for d3-selection's pointer() function.

handlePointerMove event = do
  { x, y } <- pointerPosition event svgElement
  log $ "SVG coords: " <> show x <> ", " <> show y

#Point Source

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

2D point

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