flow

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package flow implements a flow chart

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyLinked = errors.New("pads already linked")
View Source
var ErrIsRoot = errors.New("cannot delete the root node")

ErrIsRoot is returned if deletion of the root node is attempted.

View Source
var ErrSelfLink = errors.New("cannot link to self")

Functions

func AllocEdgeID

func AllocEdgeID(t string) string

func AllocNodeID

func AllocNodeID(t string) string

func AllocPadID

func AllocPadID(t string) string

Types

type DrawCommand

type DrawCommand interface {
	DrawObject() DrawObject
}

type DrawEdgeCmd

type DrawEdgeCmd struct {
	From, To             Pad
	FromLayout, ToLayout *PadLayout
	Edge                 Edge
}

func (DrawEdgeCmd) DrawObject

func (c DrawEdgeCmd) DrawObject() DrawObject

type DrawNodeCmd

type DrawNodeCmd struct {
	Node   Node
	Layout *NodeLayout
}

func (DrawNodeCmd) DrawObject

func (c DrawNodeCmd) DrawObject() DrawObject

type DrawObject

type DrawObject uint8
const (
	DrawNode DrawObject = iota
	DrawPad
	DrawEdge
)

Valid DrawObject types.

type DrawPadCmd

type DrawPadCmd struct {
	Pad    Pad
	Layout *PadLayout
}

func (DrawPadCmd) DrawObject

func (c DrawPadCmd) DrawObject() DrawObject

type Edge

type Edge interface {
	EdgeID() string
	From() Pad
	To() Pad
	Disconnect()
}

Edge describes a link between two pads.

type Layout

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

Layout keeps track of state describing how elements of a flowchart should be positioned.

func NewLayout

func NewLayout() *Layout

NewLayout constructs a new layout controller, to keep track of the position and compute the draw order of flowchart nodes.

func (*Layout) DeleteNode added in v0.3.0

func (fl *Layout) DeleteNode(n Node)

DeleteNode removes a node from the layout, destroying all edges to other nodes in the layout.

func (*Layout) DisplayList

func (fl *Layout) DisplayList() (min, max [2]float64, dl []DrawCommand, err error)

DisplayList returns a list of drawing commands for rendering the layout. The bounds of all objects in the layout are also returned.

func (*Layout) Dump added in v0.4.1

func (fl *Layout) Dump() []NodePosition

Dump returns a list of all nodes and their positions.

func (*Layout) MoveNode

func (fl *Layout) MoveNode(n Node, x, y float64)

func (*Layout) Node

func (fl *Layout) Node(n Node) *NodeLayout

Node returns the object storing the position of a node.

func (*Layout) Pad

func (fl *Layout) Pad(p Pad) *PadLayout

func (*Layout) RecomputePadPositions added in v0.6.2

func (fl *Layout) RecomputePadPositions(n Node)

RecomputePadPositions should be called by the user after the position of any pad on the node changes.

type Node

type Node interface {
	NodeID() string
	Pads() []Pad
	Size() (float64, float64)
}

Node describes a symbol in a flowchart.

type NodeLayout

type NodeLayout struct {
	X, Y float64
}

NodeLayout describes the layout state of a flowchart node.

func (*NodeLayout) Pos

func (fns *NodeLayout) Pos() (float64, float64)

type NodePosition added in v0.4.1

type NodePosition struct {
	Pos  NodeLayout
	Node Node
}

type NodeSide

type NodeSide uint8
const (
	SideRight NodeSide = iota
	SideLeft
	SideTop
	SideBottom
)

Valid NodeSide values.

type Pad

type Pad interface {
	PadID() string
	Size() (float64, float64)
	Parent() Node

	// Positioning returns the side the pad should be positioned on its node,
	// as well as how far down the axis from the leftmost part of the side.
	Positioning() (NodeSide, float64)

	StartEdges() []Edge
	EndEdges() []Edge
	Disconnect(del Edge)
	DisconnectAll()

	ConnectTo(Edge) error
	ConnectFrom(Edge) error
}

Pad describes a connection point on a node.

type PadLayout

type PadLayout struct {
	X, Y float64
}

PadLayout describes the layout state of a flowchart pad.

func (*PadLayout) Pos

func (fps *PadLayout) Pos() (float64, float64)

type SEdge

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

func NewSEdge

func NewSEdge(t string, from, to Pad) *SEdge

func NewSEdgeWithID added in v0.4.2

func NewSEdgeWithID(id string, from, to Pad) *SEdge

func (*SEdge) Disconnect added in v0.3.0

func (se *SEdge) Disconnect()

func (*SEdge) EdgeID

func (se *SEdge) EdgeID() string

func (*SEdge) From

func (se *SEdge) From() Pad

func (*SEdge) To

func (se *SEdge) To() Pad

type SNode

type SNode struct {
	Headline string
	// contains filtered or unexported fields
}

func NewSNode

func NewSNode(hl, t string) *SNode

func (*SNode) AppendPad

func (sn *SNode) AppendPad(pad Pad)

func (*SNode) AppendSPad

func (sn *SNode) AppendSPad(t string, side NodeSide, sideAmt float64)

func (*SNode) LinkPads

func (sn *SNode) LinkPads(toNode Node, fromPad, toPad Pad) (Edge, error)

LinkPads implements flowui.UserLinkable.

func (*SNode) NodeHeadline

func (sn *SNode) NodeHeadline() string

func (*SNode) NodeID

func (sn *SNode) NodeID() string

func (*SNode) Pads

func (sn *SNode) Pads() []Pad

func (*SNode) Size

func (sn *SNode) Size() (float64, float64)

type SPad

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

func NewSPad

func NewSPad(t string, parent Node, side NodeSide, sideAmt float64) *SPad

func (*SPad) ConnectFrom

func (sp *SPad) ConnectFrom(e Edge) error

func (*SPad) ConnectTo

func (sp *SPad) ConnectTo(e Edge) error

func (*SPad) Disconnect added in v0.3.0

func (sp *SPad) Disconnect(del Edge)

func (*SPad) DisconnectAll added in v0.3.0

func (sp *SPad) DisconnectAll()

func (*SPad) EndEdges

func (sp *SPad) EndEdges() []Edge

func (*SPad) PadColor

func (sp *SPad) PadColor() (float64, float64, float64)

func (*SPad) PadID

func (sp *SPad) PadID() string

func (*SPad) Parent

func (sp *SPad) Parent() Node

func (*SPad) Positioning

func (sp *SPad) Positioning() (NodeSide, float64)

func (*SPad) SetPadColor

func (sp *SPad) SetPadColor(r, g, b float64)

func (*SPad) Size

func (sp *SPad) Size() (float64, float64)

func (*SPad) StartEdges

func (sp *SPad) StartEdges() []Edge

Jump to

Keyboard shortcuts

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