miso-flow
LicenseBSD3-style (see the file LICENSE)
Safe HaskellNone
LanguageHaskell2010

Miso.Flow.Utils.General

Description

Pure port of utils/general.ts from @xyflow/system: clamping, box/rect algebra, viewport math and getViewportForBounds.

Synopsis

Documentation

clamp :: Double -> Double -> Double -> Double Source #

clamp val min max.

clampPosition :: XYPosition -> CoordinateExtent -> Dimensions -> XYPosition Source #

Clamp a position into a CoordinateExtent, accounting for the element's dimensions.

clampPositionToParent :: XYPosition -> Dimensions -> InternalNode n -> XYPosition Source #

Clamp a child position into the bounds of its parent node.

calcAutoPanVelocity :: Double -> Double -> Double -> Double Source #

Velocity (-1..1) of auto panning when the pointer is close to a pane edge. calcAutoPanVelocity value min max.

calcAutoPan Source #

Arguments

:: XYPosition

pointer position

-> Dimensions

pane bounds

-> Double

speed (original default: 15)

-> Double

distance (original default: 40)

-> (Double, Double) 

X/Y auto-pan movement for the given pointer position and pane bounds. Speed defaults to 15, edge distance to 40 in the original.

nodeToRect :: Node n -> NodeOrigin -> Rect Source #

Bounding rect of a user node (positioned by origin). Port of nodeToRect for the non-internal case.

internalNodeToRect :: InternalNode n -> Rect Source #

Bounding rect of an internal node (uses positionAbsolute). Port of nodeToRect for the internal case.

isNumeric :: Double -> Bool Source #

JS isNumeric: finite and not NaN.

pointToRendererPoint Source #

Arguments

:: XYPosition 
-> Transform 
-> Bool

snap to grid

-> SnapGrid 
-> XYPosition 

Screen point → flow point, optionally snapped to grid.

rendererPointToPoint :: XYPosition -> Transform -> XYPosition Source #

Flow point → screen point.

parsePadding :: PaddingWithUnit -> Double -> Double Source #

Resolve a single padding value to pixels; parsePadding padding viewport where viewport is the relevant viewport dimension.

parsePaddings :: Padding -> Double -> Double -> ParsedPaddings Source #

Resolve a Padding to per-side pixel values for the given viewport width and height.

getViewportForBounds Source #

Arguments

:: Rect

bounds to fit

-> Double

viewport width

-> Double

viewport height

-> Double

min zoom

-> Double

max zoom

-> Padding 
-> Viewport 

Viewport that encloses the given bounds with padding; port of getViewportForBounds.

getNodeDimensions :: Node n -> Dimensions Source #

measured.width ?? width ?? initialWidth ?? 0 (and same for height).

getInternalNodeDimensions :: InternalNode n -> Dimensions Source #

getNodeDimensions with the internal measured taking precedence.

evaluateAbsolutePosition Source #

Arguments

:: XYPosition 
-> Maybe Dimensions

dimensions (defaults to 0x0)

-> NodeId

parent id

-> NodeLookup n 
-> NodeOrigin 
-> XYPosition 

Convert a child position to an absolute position; port of evaluateAbsolutePosition.