mess with dot types
This commit is contained in:
		
							parent
							
								
									3c6bd51bbc
								
							
						
					
					
						commit
						339fdc0bcf
					
				|  | @ -23,6 +23,7 @@ import ( | |||
| 
 | ||||
| type WeightedGraph interface { | ||||
| 	graph.Weighted | ||||
| 	graph.WeightedMultigraphBuilder | ||||
| 
 | ||||
| 	WeightedEdges() graph.WeightedEdges | ||||
| 
 | ||||
|  |  | |||
|  | @ -25,19 +25,23 @@ import ( | |||
| 	"gonum.org/v1/gonum/graph/multi" | ||||
| ) | ||||
| 
 | ||||
| // DOTDirectedGraph is a graph to unmarshal DOT graphs.
 | ||||
| type DOTDirectedGraph struct { | ||||
| 	*igraph.DirectedGraph | ||||
| // DOTWeightedGraph is a graph to unmarshal DOT graphs.
 | ||||
| type DOTWeightedGraph struct { | ||||
| 	igraph.WeightedGraph | ||||
| 	WeightAttribute string | ||||
| } | ||||
| 
 | ||||
| // NewDOTDirectedGraph returns a graph with no nodes or edges.
 | ||||
| func NewDOTDirectedGraph(weightAttr string) *DOTDirectedGraph { | ||||
| 	return &DOTDirectedGraph{DirectedGraph: igraph.NewDirectedGraph(), WeightAttribute: weightAttr} | ||||
| func NewDOTDirectedGraph(weightAttr string) DOTWeightedGraph { | ||||
| 	return DOTWeightedGraph{WeightedGraph: igraph.NewDirectedGraph(), WeightAttribute: weightAttr} | ||||
| } | ||||
| 
 | ||||
| func NewDOTUndirectedGraph(weightAttr string) DOTWeightedGraph { | ||||
| 	return DOTWeightedGraph{WeightedGraph: igraph.NewUndirectedGraph(), WeightAttribute: weightAttr} | ||||
| } | ||||
| 
 | ||||
| // NewLine returns a DOT-aware weighted line.
 | ||||
| func (g *DOTDirectedGraph) NewLine(from, to graph.Node) graph.Line { | ||||
| func (g *DOTWeightedGraph) NewLine(from, to graph.Node) graph.Line { | ||||
| 	var defaultWeight float64 | ||||
| 	if g.WeightAttribute == "" { | ||||
| 		defaultWeight = 1 | ||||
|  | @ -45,16 +49,16 @@ func (g *DOTDirectedGraph) NewLine(from, to graph.Node) graph.Line { | |||
| 		defaultWeight = math.NaN() | ||||
| 	} | ||||
| 
 | ||||
| 	e := g.DirectedGraph.NewWeightedLine(from, to, defaultWeight).(multi.WeightedLine) | ||||
| 	e := g.WeightedGraph.NewWeightedLine(from, to, defaultWeight).(multi.WeightedLine) | ||||
| 	return &weightedLine{WeightedLine: e, weightAttribute: g.WeightAttribute} | ||||
| } | ||||
| 
 | ||||
| // NewNode returns a DOT-aware Node.
 | ||||
| func (g *DOTDirectedGraph) NewNode() graph.Node { | ||||
| 	return &Node{Node: g.DirectedGraph.NewNode()} | ||||
| func (g *DOTWeightedGraph) NewNode() graph.Node { | ||||
| 	return &Node{Node: g.WeightedGraph.NewNode()} | ||||
| } | ||||
| 
 | ||||
| // SetLine adds a DOT-aware weighted line to the graph.
 | ||||
| func (g *DOTDirectedGraph) SetLine(e graph.Line) { | ||||
| 	g.DirectedGraph.SetWeightedLine(e.(*weightedLine)) | ||||
| func (g *DOTWeightedGraph) SetLine(e graph.Line) { | ||||
| 	g.WeightedGraph.SetWeightedLine(e.(*weightedLine)) | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue