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