gorgonia.org/gorgonia@v0.9.17/encoding/dot/constantgraph.go (about)

     1  package dot
     2  
     3  import (
     4  	"gonum.org/v1/gonum/graph"
     5  	"gonum.org/v1/gonum/graph/encoding"
     6  	gonumDot "gonum.org/v1/gonum/graph/encoding/dot"
     7  	internalEncoding "gorgonia.org/gorgonia/internal/encoding"
     8  )
     9  
    10  type constantSubGraph struct {
    11  	name string
    12  	graph.DirectedBuilder
    13  	subs map[internalEncoding.Group]operatorSubGraph
    14  }
    15  
    16  func (g constantSubGraph) DOTID() string { return g.name }
    17  
    18  // DOTAttributers to specify the top-level graph attributes for the graphviz generation
    19  func (g constantSubGraph) DOTAttributers() (graph, node, edge encoding.Attributer) {
    20  	// Create a special attribute "rank" to place the input at the same level in the graph
    21  
    22  	graphAttributes := attributer{
    23  		encoding.Attribute{
    24  			Key:   "label",
    25  			Value: g.name,
    26  		},
    27  		encoding.Attribute{
    28  			Key:   "rank",
    29  			Value: `"max"`,
    30  		},
    31  	}
    32  	nodeAttributes := attributer{
    33  		encoding.Attribute{
    34  			Key:   "style",
    35  			Value: `"rounded,filled"`,
    36  		},
    37  		encoding.Attribute{
    38  			Key:   "shape",
    39  			Value: "record",
    40  		},
    41  		encoding.Attribute{
    42  			Key:   "fillcolor",
    43  			Value: "pink",
    44  		},
    45  	}
    46  	return graphAttributes, nodeAttributes, attributer{}
    47  }
    48  
    49  // Structure fulfils the dot.Structurer interface.
    50  func (g constantSubGraph) Structure() []gonumDot.Graph {
    51  	output := make([]gonumDot.Graph, 0, len(g.subs))
    52  	for _, subg := range g.subs {
    53  		output = append(output, subg)
    54  	}
    55  	return output
    56  }