flowgraph

package
v0.0.0-...-e968d04 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package flowgraph provides graph layout algorithms for flow nodes. It supports both horizontal (left-to-right) and vertical (top-to-bottom) layouts using BFS-based level assignment.

Index

Constants

View Source
const DefaultMaxEdgesForReduction = 2000

DefaultMaxEdgesForReduction is the default threshold for skipping transitive reduction. Graphs with more edges than this will not be reduced (performance optimization).

Variables

This section is empty.

Functions

func ApplyLayout

func ApplyLayout(nodes []mflow.Node, result *LayoutResult)

ApplyLayout applies the layout result to a slice of nodes.

func ApplyLayoutToNodePtrs

func ApplyLayoutToNodePtrs(nodeMap map[idwrap.IDWrap]*mflow.Node, result *LayoutResult)

ApplyLayoutToNodePtrs applies the layout result to a map of node pointers.

func ApplyTransitiveReduction

func ApplyTransitiveReduction(edges []mflow.Edge, maxEdges int) []mflow.Edge

ApplyTransitiveReduction removes redundant edges from the graph. An edge A->C is redundant if there exists a path A->...->C via other edges.

If maxEdges is > 0 and len(edges) > maxEdges, the reduction is skipped for performance. Pass 0 to use DefaultMaxEdgesForReduction.

func BuildIncomingAdjacency

func BuildIncomingAdjacency(edges []mflow.Edge) map[idwrap.IDWrap][]idwrap.IDWrap

BuildIncomingAdjacency builds a map of node ID -> list of source node IDs.

func BuildNodeMap

func BuildNodeMap(nodes []mflow.Node) map[idwrap.IDWrap]*mflow.Node

BuildNodeMap creates a map of node ID -> node pointer for quick lookup.

func BuildOutgoingAdjacency

func BuildOutgoingAdjacency(edges []mflow.Edge) map[idwrap.IDWrap][]idwrap.IDWrap

BuildOutgoingAdjacency builds a map of node ID -> list of target node IDs.

func ConnectOrphans

func ConnectOrphans(nodes []mflow.Node, edges []mflow.Edge, flowID, startNodeID idwrap.IDWrap) []mflow.Edge

ConnectOrphans creates edges from startNode to all nodes with no incoming edges. This ensures all nodes are reachable from the start node.

func EdgeExists

func EdgeExists(edges []mflow.Edge, source, target idwrap.IDWrap) bool

EdgeExists checks if an edge exists between source and target.

func FindStartNode

func FindStartNode(nodes []mflow.Node) (*mflow.Node, bool)

FindStartNode finds the start node (NODE_KIND_MANUAL_START or NODE_KIND_SUB_FLOW_TRIGGER) in a node slice.

func HasAlternativePath

func HasAlternativePath(adjMap map[idwrap.IDWrap][]idwrap.IDWrap, source, target idwrap.IDWrap) bool

HasAlternativePath checks if there's a path from source to target that doesn't use the direct edge (i.e., goes through other nodes).

func LayoutNodes

func LayoutNodes(nodes []mflow.Node, edges []mflow.Edge, config LayoutConfig) error

LayoutNodes is a convenience function that performs layout and applies positions. It returns an error if the start node is not found.

func LinearizeNodes

func LinearizeNodes(startNodeID idwrap.IDWrap, allNodes []mflow.Node, edges []mflow.Edge) []mflow.Node

LinearizeNodes returns nodes in BFS traversal order (for YAML export). Neighbors are sorted alphabetically by name for deterministic ordering. Disconnected nodes are appended at the end, also sorted alphabetically.

Types

type LayoutConfig

type LayoutConfig struct {
	// Orientation controls whether depth maps to X (horizontal) or Y (vertical).
	Orientation LayoutOrientation

	// SpacingPrimary is spacing along the primary axis (direction of flow).
	SpacingPrimary float64

	// SpacingSecondary is spacing perpendicular to flow (for parallel nodes).
	SpacingSecondary float64

	// StartX is the starting X position.
	StartX float64

	// StartY is the starting Y position.
	StartY float64
}

LayoutConfig configures the layout algorithm.

func DefaultHorizontalConfig

func DefaultHorizontalConfig() LayoutConfig

DefaultHorizontalConfig returns the default configuration for horizontal layout. This matches the harv2 layout: nodes flow left-to-right with vertical stacking.

func DefaultVerticalConfig

func DefaultVerticalConfig() LayoutConfig

DefaultVerticalConfig returns the default configuration for vertical layout. This matches the ioworkspace layout: nodes flow top-to-bottom with horizontal stacking.

type LayoutOrientation

type LayoutOrientation int

LayoutOrientation defines the primary direction of flow.

const (
	// LayoutHorizontal: nodes flow left-to-right (X increases with depth).
	// Used by HAR import (harv2).
	LayoutHorizontal LayoutOrientation = iota

	// LayoutVertical: nodes flow top-to-bottom (Y increases with depth).
	// Used by YAML import (ioworkspace).
	LayoutVertical
)

type LayoutResult

type LayoutResult struct {
	// Positions maps node IDs to their computed positions.
	Positions map[idwrap.IDWrap]Position

	// Levels maps node IDs to their depth level (0 = start node).
	Levels map[idwrap.IDWrap]int

	// MaxLevel is the deepest level in the graph.
	MaxLevel int
}

LayoutResult contains the computed positions for each node.

func Layout

func Layout(nodes []mflow.Node, edges []mflow.Edge, startNodeID idwrap.IDWrap, config LayoutConfig) (*LayoutResult, error)

Layout computes node positions using BFS-based level assignment. Each node's level is max(parent_levels) + 1, ensuring proper dependency ordering.

type Position

type Position struct {
	X float64
	Y float64
}

Position holds X and Y coordinates.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL