ToDOT exports the graph to DOT format for visualization
(name string)
| 157 | |
| 158 | // ToDOT exports the graph to DOT format for visualization |
| 159 | func (g *Graph[EdgeType, VertexType]) ToDOT(name string) (string, error) { |
| 160 | g.mu.RLock() |
| 161 | defer g.mu.RUnlock() |
| 162 | |
| 163 | if g.gonumGraph == nil { |
| 164 | return "", xerrors.New("graph is not initialized") |
| 165 | } |
| 166 | |
| 167 | // Marshal the graph to DOT format |
| 168 | dotBytes, err := dot.Marshal(g.gonumGraph, name, "", " ") |
| 169 | if err != nil { |
| 170 | return "", xerrors.Errorf("failed to marshal graph to DOT: %w", err) |
| 171 | } |
| 172 | |
| 173 | return string(dotBytes), nil |
| 174 | } |