Hylograph.Interaction.Zoom
- Package
- purescript-hylograph-selection
- Repository
- afcondon/purescript-hylograph-selection
Native Zoom using Pointer Events (no D3 dependency)
This module provides zoom and pan behavior using native browser events:
- Wheel events for zoom
- Pointer events for pan/drag
- Gesture events for trackpad pinch (Safari)
The zoom transform math is adapted from d3-zoom (ISC licensed).
Usage
Simple API (drop-in replacement for existing zoom)
import Hylograph.Interaction.Zoom (attachZoomNative)
svgElement <- select "#my-svg"
handle <- attachZoomNative svgElement
{ scaleMin: 0.5, scaleMax: 4.0, targetSelector: ".zoom-group" }
-- Later:
handle.destroy
With Initial Transform
handle <- attachZoomWithTransform svgElement
0.5 4.0 ".zoom-group" savedTransform
With Callback
handle <- attachZoomWithCallback svgElement
0.5 4.0 ".zoom-group" initialTransform \t -> do
log $ "Scale: " <> show t.k
Full Control
handle <- attachNativeZoom svgElement
{ scaleMin: 0.1
, scaleMax: 10.0
, targetSelector: ".zoom-group"
, initialTransform: Just { k: 1.0, x: 0.0, y: 0.0 }
, translateExtent: Nothing
, onZoom: Just \t -> log $ "Zoom: " <> show t.k
}
-- Programmatic zoom
handle.zoomTo 2.0 { x: 400.0, y: 300.0 }
handle.zoomBy 1.5
handle.resetZoom
-- Get current state
t <- handle.getTransform
-- Cleanup
handle.destroy
#ZoomTransform Source
type ZoomTransform = { k :: Number, x :: Number, y :: Number }Zoom transform record {k, x, y}
- k: scale factor (1.0 = 100%)
- x: translate x
- y: translate y
The transform represents: translate(x, y) scale(k)
#ZoomConfig Source
type ZoomConfig = { initialTransform :: Maybe ZoomTransform, onZoom :: Maybe (ZoomTransform -> Effect Unit), scaleMax :: Number, scaleMin :: Number, targetSelector :: String, translateExtent :: Maybe BoundingBox }Configuration for native zoom behavior
#ZoomHandle Source
type ZoomHandle = { destroy :: Effect Unit, getTransform :: Effect ZoomTransform, resetZoom :: Effect Unit, setTransform :: ZoomTransform -> Effect Unit, zoomBy :: Number -> Effect Unit, zoomTo :: Number -> Point -> Effect Unit }Handle returned by attachNativeZoom
Provides methods for programmatic zoom control and cleanup.
#BoundingBox Source
type BoundingBox = { x0 :: Number, x1 :: Number, y0 :: Number, y1 :: Number }Bounding box for translate extent
#attachNativeZoom Source
attachNativeZoom :: Element -> ZoomConfig -> Effect ZoomHandleAttach native zoom behavior with full configuration
This is the main entry point for the zoom module.
#attachZoomNative Source
attachZoomNative :: Element -> Number -> Number -> String -> Effect ZoomHandleAttach zoom behavior (simplified API)
Drop-in replacement for the D3-based attachZoom_.
#attachZoomWithTransform Source
attachZoomWithTransform :: Element -> Number -> Number -> String -> ZoomTransform -> Effect ZoomHandleAttach zoom with initial transform
Drop-in replacement for attachZoomWithTransform_.
#attachZoomWithCallback Source
attachZoomWithCallback :: Element -> Number -> Number -> String -> ZoomTransform -> (ZoomTransform -> Effect Unit) -> Effect ZoomHandleAttach zoom with callback
Drop-in replacement for attachZoomWithCallback_.
#identity Source
identity :: ZoomTransformIdentity transform (no zoom, no pan)
- 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