Module

Hylograph.Internal.Behavior.FFI

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

Internal: FFI bindings for D3 behaviors (zoom, drag, mouse events).

Provides JavaScript bindings for:

  • Zoom: attachZoom_, attachZoomWithTransform_, getZoomTransform_
  • Drag: attachSimpleDrag_, attachSimulationDrag_
  • Mouse events: click, mouseenter, mouseleave, mousemove, mousedown
  • Coordinated highlighting across linked elements
  • Simulation registry for drag-to-reheat behavior

Internal module - use Hylograph.Behavior for the public API.

#attachZoom_ Source

attachZoom_ :: Element -> Number -> Number -> String -> Effect Element

Attach zoom behavior to a DOM element

Parameters:

  • element: The DOM element to attach zoom to (typically SVG)
  • scaleMin: Minimum zoom scale (e.g., 0.5 for 50%)
  • scaleMax: Maximum zoom scale (e.g., 4.0 for 400%)
  • targetSelector: CSS selector for the element to transform (e.g., ".zoom-group")

Returns the element for chaining.

#attachZoomWithTransform_ Source

attachZoomWithTransform_ :: Element -> Number -> Number -> String -> ZoomTransform -> Effect Element

Attach zoom behavior and restore a previous transform

Like attachZoom_ but also applies the given transform after setup. Use this to preserve zoom state across re-renders.

#attachZoomWithCallback_ Source

attachZoomWithCallback_ :: Element -> Number -> Number -> String -> ZoomTransform -> (ZoomTransform -> Effect Unit) -> Effect Element

Attach zoom behavior with callback on zoom events

Like attachZoomWithTransform_ but also calls a callback with the current transform on each zoom event. Use this when you need to update other UI elements (like arrows) that depend on the zoom state.

#getZoomTransform_ Source

getZoomTransform_ :: Element -> Effect ZoomTransform

Get the current zoom transform from a DOM element Returns identity transform {k:1, x:0, y:0} if none exists

#ZoomTransform Source

type ZoomTransform = { k :: Number, x :: Number, y :: Number }

Zoom transform record {k, x, y} for scale and translation

#updateAttr_ Source

updateAttr_ :: String -> String -> String -> Effect Unit

Update an element's attribute by CSS selector Useful for imperatively updating elements (e.g., arrows during zoom)

#attachSimpleDrag_ Source

attachSimpleDrag_ :: Element -> Unit -> Effect Element

Attach simple drag behavior to a DOM element

Enables dragging with transform translation. Returns the element for chaining.

#attachSimulationDrag_ Source

attachSimulationDrag_ :: Element -> Nullable D3Simulation_ -> String -> Effect Element

Attach simulation-aware drag behavior to a DOM element

Enables dragging with force simulation reheat. When dragging:

  • Dragstart: Sets fx/fy fixed positions, reheats simulation
  • Drag: Updates fx/fy to follow mouse
  • Dragend: Clears fx/fy, cools simulation

Returns the element for chaining.

#attachSimulationDragById_ Source

attachSimulationDragById_ :: Element -> String -> Effect Element

Attach simulation-aware drag using the simulation registry

Looks up the simulation by ID and calls its reheat function on drag start. This enables declarative SimulationDrag in TreeAPI.

When dragging:

  • Dragstart: Sets fx/fy, calls registered reheat function
  • Drag: Updates fx/fy to follow mouse
  • Dragend: Clears fx/fy

#attachSimulationDragNestedById_ Source

attachSimulationDragNestedById_ :: Element -> String -> Effect Element

Attach simulation-aware drag for nested datum structure

Like attachSimulationDragById_, but for datums that have a .node field containing the actual simulation node. Used when the bound datum is a wrapper (like RenderNode) that contains the simulation node.

Sets event.subject.node.fx/fy instead of event.subject.fx/fy

#attachClick_ Source

attachClick_ :: Element -> Effect Unit -> Effect Element

Attach click handler without datum access

Attaches a simple click handler that doesn't access the bound datum. Also sets cursor to pointer for clickable elements.

Returns the element for chaining.

#attachClickWithDatum_ Source

attachClickWithDatum_ :: forall datum. Element -> (datum -> Effect Unit) -> Effect Element

Attach click handler with datum access

Attaches a click handler that receives the datum bound to the element. The datum is recovered from D3's data property. Type safety is preserved through the Selection's phantom type. Also sets cursor to pointer for clickable elements.

Returns the element for chaining.

#attachMouseEnter_ Source

attachMouseEnter_ :: forall datum. Element -> (datum -> Effect Unit) -> Effect Element

Attach mouseenter handler with datum access

Attaches a handler that fires when mouse enters the element. Does not bubble (unlike mouseover). The datum is recovered from D3's data property.

Returns the element for chaining.

#attachMouseLeave_ Source

attachMouseLeave_ :: forall datum. Element -> (datum -> Effect Unit) -> Effect Element

Attach mouseleave handler with datum access

Attaches a handler that fires when mouse leaves the element. Does not bubble (unlike mouseout). The datum is recovered from D3's data property.

Returns the element for chaining.

#attachHighlight_ Source

attachHighlight_ :: Element -> Array { attr :: String, value :: String } -> Array { attr :: String, value :: String } -> Effect Element

Attach hover highlight behavior

Applies styles on mouseenter and resets on mouseleave. Also raises the element to front on hover.

Parameters:

  • element: DOM element to attach to
  • enterStyles: Array of {attr, value} to apply on enter
  • leaveStyles: Array of {attr, value} to apply on leave

Returns the element for chaining.

#attachMouseDown_ Source

attachMouseDown_ :: Element -> Effect Unit -> Effect Element

Attach mousedown handler without datum access

Attaches a handler that fires when mouse button is pressed. Useful for starting drag operations.

#attachMouseDownWithEvent_ Source

attachMouseDownWithEvent_ :: forall datum. Element -> EffectFn2 datum MouseEvent Unit -> Effect Element

Attach mousedown handler with event info (pure web-events version)

Like attachMouseDown_ but provides datum and raw MouseEvent. Use for drag-to-adjust controls where you need the start position.

#registerSimulation_ Source

registerSimulation_ :: String -> Effect Unit -> Effect Unit

Register a simulation with the global registry

This enables SimulationDrag to look up simulations by ID. The reheat function is called when dragging starts.

Usage:

registerSimulation_ "my-viz" (Sim.reheat sim)

#unregisterSimulation_ Source

unregisterSimulation_ :: String -> Effect Unit

Unregister a simulation from the global registry

Should be called when the visualization is destroyed.

#attachMouseMoveWithEvent_ Source

attachMouseMoveWithEvent_ :: forall datum. Element -> EffectFn2 datum MouseEvent Unit -> Effect Element

Attach mousemove handler with event info (pure web-events version)

Uses standard addEventListener instead of D3's .on() Handler receives raw MouseEvent - use Web.UIEvent.MouseEvent accessors

#attachMouseEnterWithEvent_ Source

attachMouseEnterWithEvent_ :: forall datum. Element -> EffectFn2 datum MouseEvent Unit -> Effect Element

Attach mouseenter handler with event info (pure web-events version)

#attachMouseLeaveWithEvent_ Source

attachMouseLeaveWithEvent_ :: forall datum. Element -> EffectFn2 datum MouseEvent Unit -> Effect Element

Attach mouseleave handler with event info (pure web-events version)

#attachMouseMoveWithInfo_ Source

attachMouseMoveWithInfo_ :: forall datum. Element -> (datum -> MouseEventInfoJS -> Effect Unit) -> Effect Element

DEPRECATED: Old D3-based versions - keeping for backwards compatibility during transition

#attachMouseEnterWithInfo_ Source

#attachMouseLeaveWithInfo_ Source

#MouseEventInfoJS Source

type MouseEventInfoJS = { clientX :: Number, clientY :: Number, offsetX :: Number, offsetY :: Number, pageX :: Number, pageY :: Number }

Mouse event info type (matches PureScript MouseEventInfo) DEPRECATED: Will be removed once Operations.purs is updated to use MouseEvent

#attachCoordinatedHighlight_ Source

attachCoordinatedHighlight_ :: forall datum. Element -> (datum -> String) -> (String -> datum -> Int) -> Nullable String -> Nullable (datum -> String) -> Int -> Effect Element

Attach coordinated highlight behavior to an element

Parameters:

  • element: DOM element to attach to
  • identifyFn: Function to extract identity string from datum
  • classifyFn: Function (hoveredId, datum) -> highlightClass (0=Primary, 1=Related, 2=Dimmed, 3=Neutral)
  • group: Optional group name (null for global)
  • tooltipContentFn: Optional function (datum -> String) for tooltip content
  • tooltipTrigger: When to show tooltip (0=OnHover, 1=WhenPrimary, 2=WhenRelated)

The library manages global highlight state. On mouseenter:

  1. Gets identity from datum using identifyFn
  2. Broadcasts to all registered elements
  3. Each element calls classifyFn to determine its highlight class
  4. Applies CSS classes (.highlight-primary, .highlight-related, .highlight-dimmed)
  5. Shows tooltips based on trigger conditions

Returns element for chaining.

#clearAllHighlights_ Source

clearAllHighlights_ :: Effect Unit

Clear all highlight classes from all registered elements

Removes .highlight-primary, .highlight-related, .highlight-dimmed from all elements participating in coordinated highlighting. Also hides all tooltips.

#scrollToElementById_ Source

scrollToElementById_ :: String -> String -> String -> Effect Unit

Scroll to an element by ID with configurable behavior

Parameters:

  • elementId: The ID of the element to scroll to
  • behavior: "smooth", "instant", or "auto"
  • block: Vertical alignment - "start", "center", "end", or "nearest"

Example:

scrollToElementById_ "my-element" "smooth" "center"

#scrollToElement Source

scrollToElement :: String -> Effect Unit

Scroll to an element by ID with smooth animation, centered in view

Convenience wrapper around scrollToElementById_ with sensible defaults.

Example:

scrollToElement "panel-moduleA"
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