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

Miso.Flow.Utils.Edges

Description

Pure port of utils/edges/* from @xyflow/system: bezier, smooth step and straight edge paths, edge centers, z-indexes, visibility, addEdge / reconnectEdge, and edge / handle position resolution.

All path-producing functions return SVG path strings identical (to the byte) to the ones produced by the original TypeScript.

Synopsis

Path results

data EdgePath Source #

Everything needed to render an edge: the SVG path plus the label anchor. Port of the [path, labelX, labelY, offsetX, offsetY] tuples.

Constructors

EdgePath 

Fields

Instances

Instances details
Show EdgePath Source # 
Instance details

Defined in Miso.Flow.Utils.Edges

Eq EdgePath Source # 
Instance details

Defined in Miso.Flow.Utils.Edges

Bezier (bezier-edge.ts)

bezierPathParams Source #

Arguments

:: Double

source x

-> Double

source y

-> Double

target x

-> Double

target y

-> GetBezierPathParams 

Params with xyflow's defaults filled in.

getBezierPath :: GetBezierPathParams -> EdgePath Source #

Bezier path between two points; port of getBezierPath.

getBezierEdgeCenter Source #

Arguments

:: Double 
-> Double

source x, y

-> Double 
-> Double

target x, y

-> Double 
-> Double

source control x, y

-> Double 
-> Double

target control x, y

-> (Double, Double, Double, Double) 

Center of a cubic bezier edge (t = 0.5 point) and offsets from the source.

Simple bezier (from the framework packages)

getSimpleBezierPath Source #

Arguments

:: Double 
-> Double 
-> Position

source x, y, position

-> Double 
-> Double 
-> Position

target x, y, position

-> EdgePath 

Simple bezier path (control points halfway along the axis of the handle position); port of getSimpleBezierPath from the framework packages.

Smooth step (smoothstep-edge.ts)

smoothStepPathParams Source #

Arguments

:: Double

source x

-> Double

source y

-> Double

target x

-> Double

target y

-> GetSmoothStepPathParams 

Params with xyflow's defaults filled in.

getSmoothStepPath :: GetSmoothStepPathParams -> EdgePath Source #

Stepped path between two points with rounded corners; port of getSmoothStepPath. Use smoothBorderRadius = 0 for a plain step edge.

Straight (straight-edge.ts)

getStraightPath Source #

Arguments

:: Double

source x

-> Double

source y

-> Double

target x

-> Double

target y

-> EdgePath 

Straight line between two points; port of getStraightPath.

General (edges/general.ts)

getEdgeCenter :: Double -> Double -> Double -> Double -> (Double, Double, Double, Double) Source #

Center point of a straight edge and the offsets from the source; returns (centerX, centerY, offsetX, offsetY).

getElevatedEdgeZIndex Source #

Arguments

:: InternalNode n

source node

-> InternalNode n

target node

-> Bool

selected

-> Double

z-index (default 0)

-> Bool

elevate on select

-> ZIndexMode

default ZIndexBasic

-> Double 

Z-index for an edge based on its endpoint nodes and selection state; port of getElevatedEdgeZIndex.

isEdgeVisible Source #

Arguments

:: InternalNode n

source node

-> InternalNode n

target node

-> Double

viewport width

-> Double

viewport height

-> Transform 
-> Bool 

Whether any part of the edge's bounding box is inside the viewport.

getEdgeId :: Connection -> EdgeId Source #

Default edge id for a connection: xy-edge__<source><sourceHandle>-<target><targetHandle>.

connectionToEdge :: (Connection -> EdgeId) -> Connection -> Edge e Source #

Upgrade a Connection to an Edge using the given id generator.

addEdge :: Connection -> [Edge e] -> [Edge e] Source #

Add a connection to an array of edges, unless an equivalent connection already exists; port of addEdge (for the Connection overload — pass an existing Edge through addEdgeWith id).

addEdgeWith :: (Connection -> Edge e) -> Connection -> [Edge e] -> [Edge e] Source #

addEdge with a custom Connection -> Edge upgrade (covers the custom getEdgeId option and the edge overload of the original).

reconnectEdge :: Edge e -> Connection -> [Edge e] -> [Edge e] Source #

Replace an edge with a new connection; port of reconnectEdge with shouldReplaceId = True.

reconnectEdgeWith Source #

Arguments

:: Bool

replace the old id with the generated connection id

-> (Connection -> EdgeId) 
-> Edge e 
-> Connection 
-> [Edge e] 
-> [Edge e] 

reconnectEdge with explicit shouldReplaceId and id generator.

Positions (edges/positions.ts)

getEdgePosition Source #

Arguments

:: InternalNode n

source node

-> Maybe MisoString

source handle id

-> InternalNode n

target node

-> Maybe MisoString

target handle id

-> ConnectionMode 
-> Maybe EdgePosition 

Resolve the concrete start/end coordinates and positions of an edge from its endpoint nodes; port of getEdgePosition. Returns Nothing when either node is not yet initialized or a handle can't be found.

getHandlePosition Source #

Arguments

:: InternalNode n 
-> Maybe Handle 
-> Position

fallback position (original default: PositionLeft)

-> Bool

center: return the handle center instead of its edge anchor

-> XYPosition 

Absolute position of a handle on a node; port of getHandlePosition.

toHandleBounds :: NodeId -> Maybe [NodeHandle] -> Maybe NodeHandleBounds Source #

Group a node's declared handles by type; port of toHandleBounds.