Current version and API is in experimental stage. Property names may change.
The graph layouting can be used as a command-line tool and as a library.
To install the command-line tool:
go get -u github.com/loov/layout/cmd/glay
To install the package:
go get -u github.com/loov/layout
Minimal usage:
package main
import (
"log"
"os"
"github.com/loov/layout"
"github.com/loov/layout/format/svg"
)
func main() {
graph := layout.NewDigraph()
graph.Edge("A", "B")
graph.Edge("A", "C")
graph.Edge("B", "D")
graph.Edge("C", "D")
if err := layout.Hierarchical(graph); err != nil {
log.Fatal(err)
}
svg.Write(os.Stdout, graph)
}
See other examples in examples folder.
Other layouts and outputs:
layout.Force(graph)— force-directed layout for undirected or cyclic graphs.layout.HierarchicalWith(graph, layout.Fast)orlayout.Quality— trade crossings for time.format/json— plain coordinates for drawing the graph elsewhere.format/text— Unicode box-drawing output for terminals; calltext.Prepare(graph)before laying out.
The same is available from the command line: glay -l force -q fast -t txt|json|svg|dot input.dot.
Currently the layout.Hierarchy algorithm output is significantly worse than graphviz. It is recommended to use graphviz dot, if possible.
