2025-05-04 17:02:57 +00:00
|
|
|
/*
|
|
|
|
Copyright © 2025 filifa
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2025-05-04 18:28:13 +00:00
|
|
|
package dot
|
2025-05-04 17:02:57 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"gonum.org/v1/gonum/graph"
|
|
|
|
"gonum.org/v1/gonum/graph/encoding"
|
|
|
|
"gonum.org/v1/gonum/graph/multi"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Node is a DOT-aware graph.Node.
|
|
|
|
type Node struct {
|
|
|
|
graph.Node
|
|
|
|
dotID string
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetDOTID sets the node's DOT ID. It enables storing the node name read from
|
|
|
|
// a DOT file.
|
|
|
|
func (n *Node) SetDOTID(id string) {
|
|
|
|
n.dotID = id
|
|
|
|
}
|
|
|
|
|
|
|
|
// DOTID returns the node's DOT ID.
|
|
|
|
func (n *Node) DOTID() string {
|
|
|
|
return n.dotID
|
|
|
|
}
|
|
|
|
|
2025-05-04 17:24:48 +00:00
|
|
|
// weightedLine is a DOT-aware multi.WeightedLine. By being a
|
2025-05-07 02:46:03 +00:00
|
|
|
// multi.WeightedLine, it allows for self-loops.
|
2025-05-04 17:24:48 +00:00
|
|
|
type weightedLine struct {
|
2025-05-04 17:02:57 +00:00
|
|
|
multi.WeightedLine
|
2025-05-07 03:56:20 +00:00
|
|
|
weightAttribute string
|
2025-05-04 17:02:57 +00:00
|
|
|
}
|
|
|
|
|
2025-05-10 02:36:18 +00:00
|
|
|
// SetAttribute enables storing the weight read from a DOT file. It only errors
|
|
|
|
// if the weight can't be parsed as a float.
|
2025-05-04 17:24:48 +00:00
|
|
|
func (e *weightedLine) SetAttribute(attr encoding.Attribute) error {
|
2025-05-04 17:02:57 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
switch attr.Key {
|
2025-05-07 03:56:20 +00:00
|
|
|
case e.weightAttribute:
|
2025-05-04 17:02:57 +00:00
|
|
|
e.W, err = strconv.ParseFloat(attr.Value, 64)
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|