graph

package
v1.33.1 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package graph provides the Graph type, which is used to display topology in the UI

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EdgeID added in v1.25.0

func EdgeID(source, target string) string

EdgeID constructs an id for an edge from the source and target

Types

type Edge

type Edge struct {
	ID     string
	Source string
	Target string
}

Edge represents an single edge in the graph and connects a source node to a target node.

func NewEdge

func NewEdge(source, target string) *Edge

NewEdge constructs a new Edge with the specified source and target and sets the id to "source|target"

type Graph

type Graph struct {
	Sources       []*Node
	Intermediates []*Node
	Targets       []*Node
	Edges         []*Edge

	// Attributes allow arbitrary information to be included with the Graph
	Attributes map[string]any
}

Graph represents a horizontal directed flow graph that groups nodes by their position. Sources will appear on the left and should only be the source of edges, intermediates will appear it the middle and can be the target and source of edges, and targets will appear on the right and should only be the target of edges.

func NewGraph

func NewGraph() *Graph

NewGraph constructs a new graph with empty nodes and edges

func (*Graph) AddEdge

func (f *Graph) AddEdge(edge *Edge)

AddEdge adds an edge to the graph

func (*Graph) AddIntermediate

func (f *Graph) AddIntermediate(intermediate *Node)

AddIntermediate adds an intermediate node (not a source or target) to the graph

func (*Graph) AddSource

func (f *Graph) AddSource(source *Node)

AddSource adds another source to the graph

func (*Graph) AddTarget

func (f *Graph) AddTarget(target *Node)

AddTarget adds another target to the graph

func (*Graph) Connect

func (f *Graph) Connect(source, target *Node)

Connect will construct an Edge that joins two Nodes

func (*Graph) HasEdge

func (f *Graph) HasEdge(edge *Edge) bool

HasEdge adds an edge to the graph

type Node

type Node struct {
	// ID is used to connect this Node to other Nodes via Edges
	ID string

	// Type is used to identify similar nodes and may impact rendering, e.g. "Processor"
	Type string

	// Label will be displayed on the Node in a rendering of the graph
	Label string

	// Attributes allow arbitrary information to be included with the Node
	Attributes map[string]any
}

Node represents a single node in a graph and will be connected to other nodes by Edges.

type NodeAttributes

type NodeAttributes map[string]any

NodeAttributes allow additional information, like the kind of the node and active telemetry types, to be associated with nodes.

func MakeAttributes

func MakeAttributes(resourceKind, resourceID string) NodeAttributes

MakeAttributes adds the expected attributes to a map for a Node

func (NodeAttributes) AddAttribute

func (n NodeAttributes) AddAttribute(key string, value any)

AddAttribute adds a key value pair to a NodeAttributes map.

Jump to

Keyboard shortcuts

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