output 0-1 matrix by default

This commit is contained in:
filifa 2025-05-07 00:12:43 -04:00
parent fd26e49734
commit 552978478a
3 changed files with 9 additions and 5 deletions

View File

@ -38,7 +38,14 @@ func NewDOTDirectedGraph(weightAttr string) *DOTDirectedGraph {
// 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 *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} return &weightedLine{WeightedLine: e, weightAttribute: g.WeightAttribute}
} }

View File

@ -17,7 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package dot package dot
import ( import (
"errors"
"strconv" "strconv"
"gonum.org/v1/gonum/graph" "gonum.org/v1/gonum/graph"
@ -57,8 +56,6 @@ func (e *weightedLine) SetAttribute(attr encoding.Attribute) error {
switch attr.Key { switch attr.Key {
case e.weightAttribute: case e.weightAttribute:
e.W, err = strconv.ParseFloat(attr.Value, 64) e.W, err = strconv.ParseFloat(attr.Value, 64)
default:
err = errors.New("unknown key:" + attr.Key)
} }
return err return err

View File

@ -150,7 +150,7 @@ func init() {
rootCmd.Flags().BoolVar(&oneline, "oneline", false, "output on one line") 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") rootCmd.Flags().StringSliceVarP(&nodeOrder, "order", "o", nil, "order of nodes in rows/columns of output")
} }