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 ElementAttach 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 ElementAttach 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 ElementAttach 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 ZoomTransformGet 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
#attachSimpleDrag_ Source
attachSimpleDrag_ :: Element -> Unit -> Effect ElementAttach 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 ElementAttach 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 ElementAttach 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 ElementAttach 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
#attachClickWithDatum_ Source
attachClickWithDatum_ :: forall datum. Element -> (datum -> Effect Unit) -> Effect ElementAttach 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 ElementAttach 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 ElementAttach 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 ElementAttach 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.
#attachMouseDownWithEvent_ Source
attachMouseDownWithEvent_ :: forall datum. Element -> EffectFn2 datum MouseEvent Unit -> Effect ElementAttach 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.
#unregisterSimulation_ Source
unregisterSimulation_ :: String -> Effect UnitUnregister 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 ElementAttach 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 ElementAttach mouseenter handler with event info (pure web-events version)
#attachMouseLeaveWithEvent_ Source
attachMouseLeaveWithEvent_ :: forall datum. Element -> EffectFn2 datum MouseEvent Unit -> Effect ElementAttach mouseleave handler with event info (pure web-events version)
#attachMouseMoveWithInfo_ Source
attachMouseMoveWithInfo_ :: forall datum. Element -> (datum -> MouseEventInfoJS -> Effect Unit) -> Effect ElementDEPRECATED: Old D3-based versions - keeping for backwards compatibility during transition
#attachMouseEnterWithInfo_ Source
attachMouseEnterWithInfo_ :: forall datum. Element -> (datum -> MouseEventInfoJS -> Effect Unit) -> Effect Element#attachMouseLeaveWithInfo_ Source
attachMouseLeaveWithInfo_ :: forall datum. Element -> (datum -> MouseEventInfoJS -> Effect Unit) -> Effect Element#attachCoordinatedHighlight_ Source
attachCoordinatedHighlight_ :: forall datum. Element -> (datum -> String) -> (String -> datum -> Int) -> Nullable String -> Nullable (datum -> String) -> Int -> Effect ElementAttach 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:
- Gets identity from datum using identifyFn
- Broadcasts to all registered elements
- Each element calls classifyFn to determine its highlight class
- Applies CSS classes (.highlight-primary, .highlight-related, .highlight-dimmed)
- Shows tooltips based on trigger conditions
Returns element for chaining.
#clearAllHighlights_ Source
clearAllHighlights_ :: Effect UnitClear 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 UnitScroll 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"
- 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