From 552978478ab7c48791b2e4417a12576884a2a29e Mon Sep 17 00:00:00 2001 From: filifa Date: Wed, 7 May 2025 00:12:43 -0400 Subject: [PATCH] output 0-1 matrix by default --- cmd/internal/graph/dot/graph.go | 9 ++++++++- cmd/internal/graph/dot/nodes_edges.go | 3 --- cmd/root.go | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd/internal/graph/dot/graph.go b/cmd/internal/graph/dot/graph.go index ecdc50b..8645851 100644 --- a/cmd/internal/graph/dot/graph.go +++ b/cmd/internal/graph/dot/graph.go @@ -38,7 +38,14 @@ func NewDOTDirectedGraph(weightAttr string) *DOTDirectedGraph { // NewLine returns a DOT-aware weighted line. func (g *DOTDirectedGraph) NewLine(from, to graph.Node) graph.Line { - e := g.DirectedGraph.NewWeightedLine(from, to, math.NaN()).(multi.WeightedLine) + var defaultWeight float64 + if g.WeightAttribute == "" { + defaultWeight = 1 + } else { + defaultWeight = math.NaN() + } + + e := g.DirectedGraph.NewWeightedLine(from, to, defaultWeight).(multi.WeightedLine) return &weightedLine{WeightedLine: e, weightAttribute: g.WeightAttribute} } diff --git a/cmd/internal/graph/dot/nodes_edges.go b/cmd/internal/graph/dot/nodes_edges.go index d876346..b686ec8 100644 --- a/cmd/internal/graph/dot/nodes_edges.go +++ b/cmd/internal/graph/dot/nodes_edges.go @@ -17,7 +17,6 @@ along with this program. If not, see . package dot import ( - "errors" "strconv" "gonum.org/v1/gonum/graph" @@ -57,8 +56,6 @@ func (e *weightedLine) SetAttribute(attr encoding.Attribute) error { switch attr.Key { case e.weightAttribute: e.W, err = strconv.ParseFloat(attr.Value, 64) - default: - err = errors.New("unknown key:" + attr.Key) } return err diff --git a/cmd/root.go b/cmd/root.go index cd9a692..770dd51 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -150,7 +150,7 @@ func init() { rootCmd.Flags().BoolVar(&oneline, "oneline", false, "output on one line") - rootCmd.Flags().StringVar(&weightAttr, "weight-attr", "len", "edge attribute to use as weight") + rootCmd.Flags().StringVar(&weightAttr, "weight-attr", "", "edge attribute to use as weight") rootCmd.Flags().StringSliceVarP(&nodeOrder, "order", "o", nil, "order of nodes in rows/columns of output") }