render

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

ABOUTME: In-memory render cache that wraps a DOT rendering function with sha256-keyed caching. ABOUTME: Supports TTL-based expiry, concurrent access, and manual cache clearing.

ABOUTME: Converts attractor Graph structures to DOT text and renders to SVG/PNG via graphviz. ABOUTME: Provides ToDOT, ToDOTWithStatus (with execution status color overlay), and Render functions.

Index

Constants

View Source
const (
	StatusColorSuccess = "#4CAF50" // green
	StatusColorFailed  = "#F44336" // red
	StatusColorRunning = "#FFC107" // yellow
	StatusColorPending = "#9E9E9E" // gray
)

Status color constants used for node fill colors in status overlay rendering.

Variables

This section is empty.

Functions

func GraphvizAvailable

func GraphvizAvailable() bool

GraphvizAvailable checks whether the graphviz dot command is installed and reachable.

func Render

func Render(ctx context.Context, g *attractor.Graph, format string) ([]byte, error)

Render produces rendered output from a Graph in the specified format. Supported formats: "dot" (returns DOT text), "svg", "png" (shell out to graphviz dot command). Returns an error if the format is unsupported or graphviz is not installed for svg/png.

func RenderDOTSource

func RenderDOTSource(ctx context.Context, dotText string, format string) ([]byte, error)

RenderDOTSource takes raw DOT text and renders it to the specified format (svg, png). For "dot" format, it returns the input text as-is. This is useful when the DOT text has been augmented (e.g. with status colors) and should not be re-parsed before rendering.

func ToDOT

func ToDOT(g *attractor.Graph) string

ToDOT serializes an attractor Graph back into valid DOT digraph text. Node order is deterministic (sorted by ID) for reproducible output.

func ToDOTWithStatus

func ToDOTWithStatus(g *attractor.Graph, outcomes map[string]*attractor.Outcome) string

ToDOTWithStatus serializes a Graph to DOT text with color overlays based on execution status. Nodes with outcomes are colored: green for success/partial_success, red for fail, yellow for retry (running), and gray for pending (no outcome or skipped).

Types

type RenderCache

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

RenderCache wraps a DOT rendering function with an in-memory cache. Cache keys are derived from the sha256 hash of the DOT content combined with the format. Entries expire after the configured TTL.

func NewRenderCache

func NewRenderCache(renderFn RenderFunc, ttl time.Duration) *RenderCache

NewRenderCache creates a RenderCache wrapping the given rendering function. Cached entries expire after the specified TTL duration.

func (*RenderCache) Clear

func (c *RenderCache) Clear()

Clear removes all entries from the cache.

func (*RenderCache) Len

func (c *RenderCache) Len() int

Len returns the number of entries currently in the cache (including expired ones).

func (*RenderCache) RenderDOTSource

func (c *RenderCache) RenderDOTSource(ctx context.Context, dotText string, format string) ([]byte, error)

RenderDOTSource renders DOT text to the specified format, returning cached results when available and not expired. Errors are never cached.

type RenderFunc

type RenderFunc func(ctx context.Context, dotText string, format string) ([]byte, error)

RenderFunc is the signature for a DOT rendering function that the cache wraps.

Jump to

Keyboard shortcuts

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