GraphOptionFn
Implemented by functor values that set properties on a GraphOptions
instance,
which are then used by Graph
s NewGraph
/Graph.Subgraph
to configure new
[sub]graphs.
A nil
error is expected as a return value if the functor has successfully set
the options it is intended to.
These functors are usually returned by With*
functions that are free to accept
any parameters to be used within the functor, e.g.
func WithMyOptions(id string) GraphOptionFn {
return func(options GraphOptions) error {
// use the given id
options.SetID(id)
// always create as strict
options.SetStrict(true)
// use undirected (graph) instead of the default directed (digraph)
options.SetType(GraphTypeUndirected)
return nil
}
}
then it can be used as
graph, _ := dot.New(WithMyOptions("some-id"))
implementation
// GraphOptionFn is a functor that mutates graph options
type GraphOptionFn func(GraphOptions) error
source
package dot
import (
"github.com/wwmoraes/dot/attributes"
)
// GraphOptionFn is a functor that mutates graph options
type GraphOptionFn func(GraphOptions) error
// NodeInitializerFn mutates Nodes during their creation time
type NodeInitializerFn func(Node)
// EdgeInitializerFn mutates Edges during their creation time
type EdgeInitializerFn func(StyledEdge)
// Graph is implemented by dot-compatible graph values
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
}