flow

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package flow draws a directed diagram, such as a workflow, a dependency graph or a plan of tasks, and lays it out automatically: nodes fall into ranks along the edges' direction, ranks are ordered to avoid crossings and edges run between them as orthogonal lines. Applications build each node's content and own selection and what opening a node means; the view owns layout, routing and the camera.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Nodes []Node
	Edges []Edge
}

Data is what the diagram shows; the view never modifies it.

type Direction

type Direction uint8

Direction is the way edges point.

const (
	// TopToBottom places sources at the top and edges pointing down.
	TopToBottom Direction = iota
	// LeftToRight places sources at the left and edges pointing right.
	LeftToRight
)

type Edge

type Edge struct {
	Source, Target string
	Label          string
	Dashed         bool
	Color          core.Color
	Width          core.Points
}

Edge points from Source to Target. Edges to unknown nodes and self-loops are ignored; edges closing a cycle are drawn against the layout's direction. Label, when set, sits on the line. A zero Color takes the look's line and a zero Width 1.5 points.

type Look

type Look struct {
	Line, Emphasis                      core.Color
	Label, LabelBackground, LabelBorder core.Color
}

Look colors what the view draws itself. Line is an edge's color and Emphasis that of the edges of the hovered or selected node; Label, LabelBackground and LabelBorder color an edge's label. Zero fields take the text color the view has, as core.CurrentColor does, with lines, labels and the label's border faded, and a label with no background clears the edges under it; base reads no theme, and a styled form such as ui/flow sets its own look.

type Node

type Node struct {
	ID, Label     string
	Width, Height core.Points
	Muted         bool
	Content       core.Node
}

Node is one card of the diagram. ID must be nonempty, unique and stable across changes; later duplicates are ignored. Label is its accessible name, the ID when empty.

Content is the node's face, made when its ID first appears and kept while the ID stays, following the signals it reads. Positive Width and Height fix the node's size; otherwise the layout measures Content, laying the diagram out again when that size changes. Muted fades the node and its edges, as for skipped or inactive steps.

type State

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

State retains measured sizes and the layout between mounts, and takes the pointer for the view showing it. Its zero value is ready to use; keep one per diagram. Its methods run on the UI's goroutine and do nothing while no view shows it.

func (*State) Bounds

func (s *State) Bounds(id string) (core.Bounds, bool)

Bounds is the frame of the node with id in diagram coordinates, false when it is not laid out.

func (*State) Hover

func (s *State) Hover(p core.Point, over bool)

Hover moves the pointer to a point of the diagram, emphasizing the edges of the node there, or off it when over is false.

func (*State) Hovered

func (s *State) Hovered() string

Hovered is the node the pointer is over, "" for none, which a caller reading it follows, such as to show the arrow over nodes.

func (*State) NodeAt

func (s *State) NodeAt(p core.Point) string

NodeAt is the node at a point of the diagram, "" for none.

func (*State) Position

func (s *State) Position(id string) (x, y float32, ok bool)

Position returns the top left corner of the node with id in diagram coordinates, and false if it is not laid out.

func (*State) Press

func (s *State) Press(p core.Point, e core.PressEvent) bool

Press presses the diagram at a point of it, as a camera hands it on: the node there is selected, and opened on a double press, or empty space selects "". It says a node took the press.

func (*State) Ready

func (s *State) Ready() bool

Ready reports whether every node has been measured, laid out and shown.

func (*State) Reveal

func (s *State) Reveal(id string)

Reveal has the view's Camera center the node with id, if it is shown.

func (*State) Size

func (s *State) Size() core.Size

Size is the size the diagram's layout takes, which a caller reading it follows.

type View

type View struct {
	Data func() Data
	// Direction is the way edges point, read as a signal; nil is top to
	// bottom.
	Direction func() Direction
	// NodeGap separates nodes within a rank (40 when 0) and RankGap the
	// ranks (72 when 0).
	NodeGap, RankGap core.Points
	// Selected is the application's selected node, which the view rings
	// and whose edges it emphasizes.
	Selected func() string
	OnSelect func(id string)
	OnOpen   func(id string)
	// State holds measured sizes and the layout between mounts and takes
	// the pointer; nil keeps one of the view's own.
	State *State
	// Camera is the camera showing the diagram, which reveals the node the
	// keyboard focuses; the diagram's origin is the content's unless
	// Origin says where in it the diagram is.
	Camera *camera.State
	Origin func() core.Point
	// Empty replaces the diagram while it has no nodes, an em dash when
	// nil.
	Empty core.Node
	// Label describes the diagram for assistive technology, its count of
	// nodes and edges when empty.
	Label     string
	LabelFunc func() string
	LookFunc  func() Look
	// NodeClass, NodeStyle and NodeStyleFunc are each node's box, around
	// its Content, such as its focus ring; RingClass, RingStyle and
	// RingStyleFunc the ring around the selected node, 3 points outside
	// it, 2 points wide in the text's color unless they say otherwise.
	NodeClass     string
	NodeStyle     core.Style
	NodeStyleFunc func() core.Style
	RingClass     string
	RingStyle     core.Style
	RingStyleFunc func() core.Style
	Class         string
	Style         core.Style
	TestID        string
}

View is the diagram, laid out at the size its layout takes, again when Data, read as a signal, changes; put it on a camera.View to pan and zoom it, as several diagrams can share one. Nodes take the keyboard focus in data order when the application can select or open them, and Camera, when set, follows the focused node.

A press on a node selects it (OnSelect) and a double press opens it (OnOpen). Platforms hit-test views without a camera's transform, so on a camera the application hands the pointer to State's Press and Hover at points of the diagram, which find the node there themselves, and a press on empty space selects "".

func (View) Render

func (spec View) Render(cx *core.Scope) core.Node

Render implements core.Node.

Jump to

Keyboard shortcuts

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