| License | BSD3-style (see the file LICENSE) |
|---|---|
| Safe Haskell | None |
| Language | Haskell2010 |
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
- data EdgePath = EdgePath {
- edgePath :: !MisoString
- edgePathLabelX :: !Double
- edgePathLabelY :: !Double
- edgePathOffsetX :: !Double
- edgePathOffsetY :: !Double
- data GetBezierPathParams = GetBezierPathParams {}
- bezierPathParams :: Double -> Double -> Double -> Double -> GetBezierPathParams
- getBezierPath :: GetBezierPathParams -> EdgePath
- getBezierEdgeCenter :: Double -> Double -> Double -> Double -> Double -> Double -> Double -> Double -> (Double, Double, Double, Double)
- getSimpleBezierPath :: Double -> Double -> Position -> Double -> Double -> Position -> EdgePath
- data GetSmoothStepPathParams = GetSmoothStepPathParams {
- smoothSourceX :: !Double
- smoothSourceY :: !Double
- smoothSourcePosition :: !Position
- smoothTargetX :: !Double
- smoothTargetY :: !Double
- smoothTargetPosition :: !Position
- smoothBorderRadius :: !Double
- smoothCenterX :: !(Maybe Double)
- smoothCenterY :: !(Maybe Double)
- smoothOffset :: !Double
- smoothStepPosition' :: !Double
- smoothStepPathParams :: Double -> Double -> Double -> Double -> GetSmoothStepPathParams
- getSmoothStepPath :: GetSmoothStepPathParams -> EdgePath
- getStraightPath :: Double -> Double -> Double -> Double -> EdgePath
- getEdgeCenter :: Double -> Double -> Double -> Double -> (Double, Double, Double, Double)
- getElevatedEdgeZIndex :: InternalNode n -> InternalNode n -> Bool -> Double -> Bool -> ZIndexMode -> Double
- isEdgeVisible :: InternalNode n -> InternalNode n -> Double -> Double -> Transform -> Bool
- getEdgeId :: Connection -> EdgeId
- connectionToEdge :: (Connection -> EdgeId) -> Connection -> Edge e
- addEdge :: Connection -> [Edge e] -> [Edge e]
- addEdgeWith :: (Connection -> Edge e) -> Connection -> [Edge e] -> [Edge e]
- reconnectEdge :: Edge e -> Connection -> [Edge e] -> [Edge e]
- reconnectEdgeWith :: Bool -> (Connection -> EdgeId) -> Edge e -> Connection -> [Edge e] -> [Edge e]
- getEdgePosition :: InternalNode n -> Maybe MisoString -> InternalNode n -> Maybe MisoString -> ConnectionMode -> Maybe EdgePosition
- getHandlePosition :: InternalNode n -> Maybe Handle -> Position -> Bool -> XYPosition
- toHandleBounds :: NodeId -> Maybe [NodeHandle] -> Maybe NodeHandleBounds
Path results
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
| |
Bezier (bezier-edge.ts)
data GetBezierPathParams Source #
Constructors
| GetBezierPathParams | |
Fields
| |
Instances
| Show GetBezierPathParams Source # | |
Defined in Miso.Flow.Utils.Edges Methods showsPrec :: Int -> GetBezierPathParams -> ShowS # show :: GetBezierPathParams -> String # showList :: [GetBezierPathParams] -> ShowS # | |
| Eq GetBezierPathParams Source # | |
Defined in Miso.Flow.Utils.Edges Methods (==) :: GetBezierPathParams -> GetBezierPathParams -> Bool # (/=) :: GetBezierPathParams -> GetBezierPathParams -> Bool # | |
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.
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)
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)
data GetSmoothStepPathParams Source #
Constructors
| GetSmoothStepPathParams | |
Fields
| |
Instances
| Show GetSmoothStepPathParams Source # | |
Defined in Miso.Flow.Utils.Edges Methods showsPrec :: Int -> GetSmoothStepPathParams -> ShowS # show :: GetSmoothStepPathParams -> String # showList :: [GetSmoothStepPathParams] -> ShowS # | |
| Eq GetSmoothStepPathParams Source # | |
Defined in Miso.Flow.Utils.Edges Methods (==) :: GetSmoothStepPathParams -> GetSmoothStepPathParams -> Bool # (/=) :: GetSmoothStepPathParams -> GetSmoothStepPathParams -> Bool # | |
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)
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 |
| -> Double |
Z-index for an edge based on its endpoint nodes and selection state;
port of getElevatedEdgeZIndex.
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.
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)
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.
Arguments
| :: InternalNode n | |
| -> Maybe Handle | |
| -> Position | fallback position (original default: |
| -> 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.