Documentation ¶
Overview ¶
Package dot provides interfaces and ready-to-use concrete types to create graphviz-compatible graphs using its dot language.
This package was inspired/initially forked from github.com/emicklei/dot, but has too many breaking changes compared to the original - namely interface usage and other distinct design decisions - that it was decided to maintain separately. If you need a simpler, no-brainy option, use the original one.
Copyright (c) William Artero. MIT License
Index ¶
- Variables
- type Edge
- type EdgeInitializerFn
- type Graph
- type GraphOptionFn
- func WithCluster() GraphOptionFn
- func WithEdgeInitializer(edgeInitializerFn EdgeInitializerFn) GraphOptionFn
- func WithGenerator(generator generators.IDGenerator) GraphOptionFn
- func WithID(id string) GraphOptionFn
- func WithNodeInitializer(nodeInitializerFn NodeInitializerFn) GraphOptionFn
- func WithParent(graph Graph) GraphOptionFn
- func WithStrict() GraphOptionFn
- func WithType(graphType GraphType) GraphOptionFn
- type GraphOptions
- type GraphType
- type Node
- type NodeInitializerFn
- type StyledEdge
- type StyledNode
Constants ¶
This section is empty.
Variables ¶
var ErrGraphWithoutGenerator = errors.New("cannot create a graph without an ID generator")
ErrGraphWithoutGenerator means a graph cannot be created without a generator
var ErrNilParent = errors.New("cannot create subgraph without a parent")
ErrNilParent means a nil parent was provided
var ErrRootAsCluster = errors.New("cannot create a root cluster graph")
ErrRootAsCluster means a cluster graph cannot be created at root level
var ErrRootWithParent = errors.New("cannot create [di]graph with parent")
ErrRootWithParent means a non-subgraph cannot be created with a parent
var ErrSubgraphWithoutParent = errors.New("cannot create subgraph without parent")
ErrSubgraphWithoutParent means a subgraph cannot be created without a parent
Functions ¶
This section is empty.
Types ¶
type Edge ¶
type Edge interface { attributes.Styleable attributes.Serializable // From returns the tail node this Edge is connected from From() Node // From returns the head node this Edge is connected to To() Node // Edge creates an Edge to a Node using the head node of this Edge as tail Edge(to Node) Edge // Edge creates an Edge with the provided attributes to a Node using the head // node of this Edge as tail EdgeWithAttributes(to Node, attributes attributes.Reader) Edge // EdgesTo returns all edges between the head Node of this Edge and the target // Node EdgesTo(to Node) []Edge }
Edge is implemented by dot-compatible edge values
type EdgeInitializerFn ¶ added in v0.4.0
type EdgeInitializerFn func(StyledEdge)
EdgeInitializerFn mutates Edges during their creation time
type Graph ¶
type Graph interface { attributes.Identity attributes.Styleable attributes.Serializable // Root returns the root graph (i.e. the topmost, without a parent graph) Root() Graph // Type returns the graph type: directed, undirected or sub Type() GraphType // FindSubgraph returns the subgraph of this graph or from one of its parents FindSubgraph(id string) (Graph, bool) // Subgraph creates a subgraph of this graph Subgraph(optionsFn ...GraphOptionFn) (Graph, error) // Node gets a node by id, or creates a new one if it doesn't exist Node(id string) Node // Edge creates a new edge between the two provided nodes Edge(n1, n2 Node) StyledEdge // Edge creates a new edge between the two provided nodes, and also set the // given attributes EdgeWithAttributes(n1, n2 Node, attributes attributes.Reader) StyledEdge // FindEdges gets all edges in the graph between the two provided nodes FindEdges(fromNode, toNode Node) (found []Edge) // FindNode gets a node by id FindNode(id string) (Node, bool) // VisitNodes runs the provided function on all nodes recursively VisitNodes(callback func(node Node) (done bool)) // AddToSameRank adds the given nodes to the specified rank group, forcing // them to be rendered in the same row AddToSameRank(group string, nodes ...Node) // FindNodeByID return node by id FindNodeByID(id string) (foundNode Node, found bool) // FindNodes returns all nodes recursively FindNodes() (nodes []Node) // HasSubgraphs returns true if the graph has any subgraphs HasSubgraphs() bool // HasNodes returns true if the graph has any nodes HasNodes() bool // HasEdges returns true if the graph has any nodes HasEdges() bool // HasSameRankNodes returns true if the graph has nodes grouped as same rank HasSameRankNodes() bool // IsStrict return true if the graph is set as strict IsStrict() bool }
Graph is implemented by dot-compatible graph values
func New ¶ added in v0.4.1
func New(optionsFn ...GraphOptionFn) (Graph, error)
New return a Graph after all option functions are processed
func NewWithOptions ¶ added in v0.4.1
func NewWithOptions(options GraphOptions) (Graph, error)
NewWithOptions returns a Graph using the options values
type GraphOptionFn ¶ added in v0.4.0
type GraphOptionFn func(GraphOptions) error
GraphOptionFn is a functor that mutates graph options
func WithCluster ¶ added in v0.4.0
func WithCluster() GraphOptionFn
WithCluster sets the graph as a cluster
func WithEdgeInitializer ¶ added in v0.4.0
func WithEdgeInitializer(edgeInitializerFn EdgeInitializerFn) GraphOptionFn
WithEdgeInitializer sets the graph edge initializer function
func WithGenerator ¶ added in v0.4.0
func WithGenerator(generator generators.IDGenerator) GraphOptionFn
WithGenerator sets the graph id generator
func WithID ¶ added in v0.4.0
func WithID(id string) GraphOptionFn
WithID sets the graph id, or generates one if id is "-"
func WithNodeInitializer ¶ added in v0.4.0
func WithNodeInitializer(nodeInitializerFn NodeInitializerFn) GraphOptionFn
WithNodeInitializer sets the graph node initializer function
func WithParent ¶ added in v0.4.0
func WithParent(graph Graph) GraphOptionFn
WithParent sets the graph parent
func WithStrict ¶ added in v0.4.0
func WithStrict() GraphOptionFn
WithStrict sets the graph as strict
func WithType ¶ added in v0.4.0
func WithType(graphType GraphType) GraphOptionFn
WithType sets the graph type
type GraphOptions ¶
type GraphOptions interface { // SetID changes the id SetID(string) // ID returns the id ID() string // SetParent changes the parent graph SetParent(Graph) // Parent return the parent graph Parent() Graph // SetType changes the graph type SetType(GraphType) // Type returns the graph type Type() GraphType // SetStrict changes the strict flag SetStrict(bool) // Strict returns the strict flag Strict() bool // SetGenerator changes the ID generator SetGenerator(generators.IDGenerator) // Generator return the ID generator Generator() generators.IDGenerator // SetNodeInitializer changes the node initializer function SetNodeInitializer(NodeInitializerFn) // NodeInitializer returns the node initializer function NodeInitializer() NodeInitializerFn // SetEdgeInitializer changes the node initializer function SetEdgeInitializer(EdgeInitializerFn) // EdgeInitializer returns the node initializer function EdgeInitializer() EdgeInitializerFn // SetCluster changes the cluster flag SetCluster(bool) // Cluster returns if the graph is a cluster Cluster() bool }
GraphOptions is implemented by values used to initialize graphs
func NewGraphOptions ¶ added in v0.4.0
func NewGraphOptions(optionsFn ...GraphOptionFn) (options GraphOptions, err error)
NewGraphOptions creates a new GraphOptions value that has all values initialized properly
type GraphType ¶ added in v0.3.0
type GraphType string
GraphType graphviz graph types
const ( // GraphTypeUndirected node edges will have no direction, i.e. a layout engine // can freely organize the graph and draw glyphless edges between the nodes GraphTypeUndirected GraphType = "graph" // GraphTypeDirected node edges will have direction, i.e. a layout engine will // organize the graph and draw glyph edges denoting its orientation GraphTypeDirected GraphType = "digraph" // GraphTypeSub can be used to group objects, serve as a context for attributes // or draw its contents as a independent cluster, on supported layout engines GraphTypeSub GraphType = "subgraph" )
type Node ¶
type Node interface { attributes.Identity attributes.Styleable attributes.Serializable // Edge creates an Edge to a Node Edge(to Node) Edge // EdgeWithAttributes creates an Edge with the provided attributes to a Node EdgeWithAttributes(to Node, attributes attributes.Reader) Edge // EdgesTo returns all edges between this Node and the target Node EdgesTo(to Node) []Edge }
Node is implemented by dot-compatible node values
type NodeInitializerFn ¶ added in v0.4.0
type NodeInitializerFn func(Node)
NodeInitializerFn mutates Nodes during their creation time
type StyledEdge ¶
type StyledEdge interface { Edge // Solid sets the edge style to solid Solid() Edge // Solid sets the edge style to bold Bold() Edge // Solid sets the edge style to dashed Dashed() Edge // Solid sets the edge style to dotted Dotted() Edge }
StyledEdge is implemented by dot-compatible edge values which have convenience styling methods
type StyledNode ¶
StyledNode is implemented by dot-compatible node values which have convenience styling methods
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package dottest provides helper values to create tests in a controlled and replicable environment, such as write errors
|
Package dottest provides helper values to create tests in a controlled and replicable environment, such as write errors |