dag

package
v0.75.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CharHorizontal  = "─"
	CharVertical    = "│"
	CharTopLeft     = "┌"
	CharTopRight    = "┐"
	CharBottomLeft  = "└"
	CharBottomRight = "┘"
	CharArrowRight  = "►"
	CharArrowDown   = "▼"
	CharArrowLeft   = "◄"
	CharArrowUp     = "▲"
	CharSpace       = " "
	CharCross       = "┼" // Cross junction
	CharTeeRight    = "├" // T-junction pointing right
	CharTeeLeft     = "┤" // T-junction pointing left
	CharTeeDown     = "┬" // T-junction pointing down
	CharTeeUp       = "┴" // T-junction pointing up
)

Box-drawing characters (Unicode)

Variables

This section is empty.

Functions

func Render

func Render(g *Graph, selectedStepID string) (string, error)

Render performs the complete graph rendering pipeline Returns the ASCII visualization as a string, or an error if the graph cannot be rendered

func RenderCompact

func RenderCompact(g *Graph, selectedStepID string) (string, error)

RenderCompact attempts rendering in compact mode when normal mode fails

Types

type Canvas

type Canvas struct {
	// contains filtered or unexported fields
}

Canvas represents an ASCII drawing surface for rendering the graph

func NewCanvas

func NewCanvas(width, height int) *Canvas

NewCanvas creates a new canvas with the specified dimensions

func (*Canvas) Clear

func (c *Canvas) Clear()

Clear resets the canvas to empty

func (*Canvas) DrawArrow

func (c *Canvas) DrawArrow(x, y int, direction Direction)

DrawArrow draws a directional arrow character at the given position

func (*Canvas) DrawBox

func (c *Canvas) DrawBox(x, y, width, height int, text string, status rest.V1TaskStatus, selected bool)

DrawBox renders a node box with status coloring and optional selection

func (*Canvas) DrawHorizontalLine

func (c *Canvas) DrawHorizontalLine(x1, x2, y int)

DrawHorizontalLine draws a horizontal line from (x1, y) to (x2, y)

func (*Canvas) DrawPath

func (c *Canvas) DrawPath(path []Coord)

DrawPath draws a path connecting a series of coordinates

func (*Canvas) DrawVerticalLine

func (c *Canvas) DrawVerticalLine(x, y1, y2 int)

DrawVerticalLine draws a vertical line from (x, y1) to (x, y2)

func (*Canvas) GetDimensions

func (c *Canvas) GetDimensions() (width, height int)

GetDimensions returns the actual used dimensions

func (*Canvas) SetCell

func (c *Canvas) SetCell(x, y int, char string, style lipgloss.Style)

SetCell sets a cell using priority-based collision handling

func (*Canvas) ToString

func (c *Canvas) ToString() string

ToString converts the canvas to a styled string

type Cell

type Cell struct {
	Char  string         // The character to display
	Style lipgloss.Style // Optional styling (color, bold, etc.)
}

Cell represents a single character on the canvas with optional styling

type CellPriority

type CellPriority int

CellPriority defines priority for character collision resolution Higher priority characters overwrite lower priority ones

const (
	PriorityEmpty    CellPriority = iota // Empty cell (space)
	PriorityLine                         // Line characters (─ │)
	PriorityArrow                        // Arrow characters (► ▼ ◄ ▲)
	PriorityJunction                     // Junction characters (┌ ┐ └ ┘ ├ ┤ ┬ ┴ ┼)
	PriorityBox                          // Box borders and content
)

type Component

type Component struct {
	ID        int     // Component identifier
	Nodes     []*Node // All nodes in this component
	RootNodes []*Node // Nodes with no incoming edges (within this component)

	// Bounding box after layout (absolute canvas coordinates)
	BoundingBox Rect
}

Component represents a connected subgraph (part of the forest)

type ComponentStats

type ComponentStats struct {
	TotalComponents   int
	LargestComponent  int // Number of nodes
	SmallestComponent int // Number of nodes
	IsolatedNodes     int // Single-node components
}

ComponentStats returns statistics about the components

type Coord

type Coord struct {
	X int
	Y int
}

Coord represents a position on the canvas or in grid space

type Direction

type Direction int

Direction represents a cardinal direction for navigation or drawing

const (
	DirectionLeft Direction = iota
	DirectionRight
	DirectionUp
	DirectionDown
)

type Edge

type Edge struct {
	From   *Node   // Source node
	To     *Node   // Target node
	Points []Coord // Computed path points for drawing (set by edge router)
}

Edge represents a directed connection between two nodes

type Graph

type Graph struct {
	// Graph structure
	Nodes      map[string]*Node // Keyed by step ID
	Edges      []*Edge
	Components []*Component // Connected components

	// Layout configuration
	Direction string // "LR" (left-to-right) or "TD" (top-down)

	// Space constraints
	MaxWidth  int // Available terminal width
	MaxHeight int // Available terminal height

	// Actual dimensions after layout
	ActualWidth  int
	ActualHeight int
}

Graph represents the complete workflow execution graph May be a forest (multiple disconnected components)

func BuildGraph

func BuildGraph(
	shape rest.WorkflowRunShapeForWorkflowRunDetails,
	tasks []rest.V1TaskSummary,
	maxWidth, maxHeight int,
) (*Graph, error)

BuildGraph converts API shape and task data into the internal graph representation

func NewGraph

func NewGraph(maxWidth, maxHeight int) *Graph

NewGraph creates a new empty graph with the given space constraints

func (*Graph) AddEdge

func (g *Graph) AddEdge(from, to *Node) error

AddEdge adds a directed edge and updates the parent/child relationships

func (*Graph) AddNode

func (g *Graph) AddNode(node *Node) error

AddNode adds a node to the graph Returns error if a node with the same StepID already exists

func (*Graph) ComponentCount

func (g *Graph) ComponentCount() int

ComponentCount returns the number of connected components

func (*Graph) DetectComponents

func (g *Graph) DetectComponents() int

DetectComponents finds all connected components using DFS

func (*Graph) EdgeCount

func (g *Graph) EdgeCount() int

EdgeCount returns the total number of edges in the graph

func (*Graph) GetComponent

func (g *Graph) GetComponent(id int) *Component

GetComponent returns the component with the given ID

func (*Graph) GetComponentStats

func (g *Graph) GetComponentStats() ComponentStats

GetComponentStats returns component statistics

func (*Graph) GetNode

func (g *Graph) GetNode(stepID string) *Node

GetNode retrieves a node by its step ID

func (*Graph) GetNodeComponent

func (g *Graph) GetNodeComponent(stepID string) *Component

GetNodeComponent returns the component containing the node

func (*Graph) HasCycle

func (g *Graph) HasCycle() bool

HasCycle detects cycles using DFS

func (*Graph) IsEmpty

func (g *Graph) IsEmpty() bool

IsEmpty returns true if the graph has no nodes

func (*Graph) LayoutGraph

func (g *Graph) LayoutGraph(config *RenderConfig) error

LayoutGraph computes positions for all nodes within the available space

func (*Graph) NodeCount

func (g *Graph) NodeCount() int

NodeCount returns the total number of nodes in the graph

type Node

type Node struct {
	// Identity
	StepID         string // Unique step identifier from API
	TaskName       string // Display name for the task
	TaskExternalID string // Link to full task details

	// Status for coloring
	Status rest.V1TaskStatus

	// Graph topology
	Parents  []*Node // Incoming edges
	Children []*Node // Outgoing edges

	// Component membership
	ComponentID int // Which connected component this belongs to

	// Layout coordinates (relative to component, in grid units)
	GridX int
	GridY int
	Layer int // Computed layer in hierarchical layout

	// Drawing coordinates (absolute on canvas, in character units)
	DrawX int
	DrawY int

	// Dimensions in character units
	Width  int
	Height int
}

Node represents a single task node in the workflow graph

func GetNavigableNodes

func GetNavigableNodes(g *Graph) []*Node

GetNavigableNodes returns nodes in visual order for keyboard navigation

func GetNodeAtPosition

func GetNodeAtPosition(g *Graph, x, y int) *Node

GetNodeAtPosition returns the node at the given canvas position, or nil if none

type Rect

type Rect struct {
	X      int
	Y      int
	Width  int
	Height int
}

Rect represents a rectangular region with position and dimensions

type RenderConfig

type RenderConfig struct {
	// Node dimensions in character units
	NodeWidth  int
	NodeHeight int

	// Spacing between nodes
	PaddingX int
	PaddingY int

	// Available space
	MaxWidth  int
	MaxHeight int

	// Compact mode uses minimal spacing
	CompactMode bool
}

RenderConfig contains layout and rendering parameters

Jump to

Keyboard shortcuts

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