| 
									
										
										
										
											2025-05-04 18:28:13 +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/>.
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | package dot | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"math" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-07 02:24:28 +00:00
										 |  |  | 	igraph "scm.dairydemon.net/filifa/gv2adj/cmd/internal/graph" | 
					
						
							| 
									
										
										
										
											2025-05-04 18:28:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"gonum.org/v1/gonum/graph" | 
					
						
							|  |  |  | 	"gonum.org/v1/gonum/graph/multi" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-07 02:46:03 +00:00
										 |  |  | // DOTDirectedGraph is a graph to unmarshal DOT graphs.
 | 
					
						
							| 
									
										
										
										
											2025-05-07 02:24:28 +00:00
										 |  |  | type DOTDirectedGraph struct { | 
					
						
							|  |  |  | 	*igraph.DirectedGraph | 
					
						
							| 
									
										
										
										
											2025-05-07 03:56:20 +00:00
										 |  |  | 	WeightAttribute string | 
					
						
							| 
									
										
										
										
											2025-05-04 18:28:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-07 02:46:03 +00:00
										 |  |  | // NewDOTDirectedGraph returns a graph with no nodes or edges.
 | 
					
						
							| 
									
										
										
										
											2025-05-07 03:56:20 +00:00
										 |  |  | func NewDOTDirectedGraph(weightAttr string) *DOTDirectedGraph { | 
					
						
							|  |  |  | 	return &DOTDirectedGraph{DirectedGraph: igraph.NewDirectedGraph(), WeightAttribute: weightAttr} | 
					
						
							| 
									
										
										
										
											2025-05-04 18:28:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // NewLine returns a DOT-aware weighted line.
 | 
					
						
							| 
									
										
										
										
											2025-05-07 02:24:28 +00:00
										 |  |  | func (g *DOTDirectedGraph) NewLine(from, to graph.Node) graph.Line { | 
					
						
							| 
									
										
										
										
											2025-05-07 04:12:43 +00:00
										 |  |  | 	var defaultWeight float64 | 
					
						
							|  |  |  | 	if g.WeightAttribute == "" { | 
					
						
							|  |  |  | 		defaultWeight = 1 | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		defaultWeight = math.NaN() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	e := g.DirectedGraph.NewWeightedLine(from, to, defaultWeight).(multi.WeightedLine) | 
					
						
							| 
									
										
										
										
											2025-05-07 03:56:20 +00:00
										 |  |  | 	return &weightedLine{WeightedLine: e, weightAttribute: g.WeightAttribute} | 
					
						
							| 
									
										
										
										
											2025-05-04 18:28:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // NewNode returns a DOT-aware Node.
 | 
					
						
							| 
									
										
										
										
											2025-05-07 02:24:28 +00:00
										 |  |  | func (g *DOTDirectedGraph) NewNode() graph.Node { | 
					
						
							|  |  |  | 	return &Node{Node: g.DirectedGraph.NewNode()} | 
					
						
							| 
									
										
										
										
											2025-05-04 18:28:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-07 02:46:03 +00:00
										 |  |  | // SetLine adds a DOT-aware weighted line to the graph.
 | 
					
						
							| 
									
										
										
										
											2025-05-07 02:24:28 +00:00
										 |  |  | func (g *DOTDirectedGraph) SetLine(e graph.Line) { | 
					
						
							|  |  |  | 	g.DirectedGraph.SetWeightedLine(e.(*weightedLine)) | 
					
						
							| 
									
										
										
										
											2025-05-04 18:28:13 +00:00
										 |  |  | } |