mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-26 13:47:40 +00:00
Support vertical graph layouts
This commit is contained in:
+8
-2
@@ -11,15 +11,21 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GET /api/graph.:ext
|
// GET /api/graph.:ext/:vertical
|
||||||
func apiGraph(c *gin.Context) {
|
func apiGraph(c *gin.Context) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
output []byte
|
output []byte
|
||||||
|
vertical bool = false
|
||||||
)
|
)
|
||||||
|
|
||||||
ext := c.Params.ByName("ext")
|
ext := c.Params.ByName("ext")
|
||||||
|
|
||||||
|
// TODO: api is untested!
|
||||||
|
if c.Params.ByName("vertical") == "vertical" {
|
||||||
|
vertical = true
|
||||||
|
}
|
||||||
|
|
||||||
factory := context.CollectionFactory()
|
factory := context.CollectionFactory()
|
||||||
|
|
||||||
factory.RemoteRepoCollection().RLock()
|
factory.RemoteRepoCollection().RLock()
|
||||||
@@ -31,7 +37,7 @@ func apiGraph(c *gin.Context) {
|
|||||||
factory.PublishedRepoCollection().RLock()
|
factory.PublishedRepoCollection().RLock()
|
||||||
defer factory.PublishedRepoCollection().RUnlock()
|
defer factory.PublishedRepoCollection().RUnlock()
|
||||||
|
|
||||||
graph, err := deb.BuildGraph(factory)
|
graph, err := deb.BuildGraph(factory, vertical)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, err)
|
c.JSON(500, err)
|
||||||
return
|
return
|
||||||
|
|||||||
+5
-1
@@ -21,8 +21,11 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
|
|||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vertical := context.Flags().Lookup("vertical").Value.Get().(bool)
|
||||||
|
|
||||||
fmt.Printf("Generating graph...\n")
|
fmt.Printf("Generating graph...\n")
|
||||||
graph, err := deb.BuildGraph(context.CollectionFactory())
|
graph, err := deb.BuildGraph(context.CollectionFactory(), vertical)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -108,6 +111,7 @@ Example:
|
|||||||
|
|
||||||
cmd.Flag.String("format", "png", "render graph to specified format (png, svg, pdf, etc.)")
|
cmd.Flag.String("format", "png", "render graph to specified format (png, svg, pdf, etc.)")
|
||||||
cmd.Flag.String("output", "", "specify output filename, default is to open result in viewer")
|
cmd.Flag.String("output", "", "specify output filename, default is to open result in viewer")
|
||||||
|
cmd.Flag.Bool("vertical", false, "try to achieve a more vertical graph layout")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-10
@@ -7,13 +7,26 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// BuildGraph generates graph contents from aptly object database
|
// BuildGraph generates graph contents from aptly object database
|
||||||
func BuildGraph(collectionFactory *CollectionFactory) (gographviz.Interface, error) {
|
func BuildGraph(collectionFactory *CollectionFactory, vertical bool) (gographviz.Interface, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
graph := gographviz.NewEscape()
|
graph := gographviz.NewEscape()
|
||||||
graph.SetDir(true)
|
graph.SetDir(true)
|
||||||
graph.SetName("aptly")
|
graph.SetName("aptly")
|
||||||
|
|
||||||
|
var labelStart string
|
||||||
|
var labelEnd string
|
||||||
|
|
||||||
|
if vertical {
|
||||||
|
graph.AddAttr("aptly", "rankdir", "LR")
|
||||||
|
labelStart = ""
|
||||||
|
labelEnd = ""
|
||||||
|
} else {
|
||||||
|
graph.AddAttr("aptly", "rankdir", "TB")
|
||||||
|
labelStart = "{"
|
||||||
|
labelEnd = "}"
|
||||||
|
}
|
||||||
|
|
||||||
existingNodes := map[string]bool{}
|
existingNodes := map[string]bool{}
|
||||||
|
|
||||||
err = collectionFactory.RemoteRepoCollection().ForEach(func(repo *RemoteRepo) error {
|
err = collectionFactory.RemoteRepoCollection().ForEach(func(repo *RemoteRepo) error {
|
||||||
@@ -26,9 +39,9 @@ func BuildGraph(collectionFactory *CollectionFactory) (gographviz.Interface, err
|
|||||||
"shape": "Mrecord",
|
"shape": "Mrecord",
|
||||||
"style": "filled",
|
"style": "filled",
|
||||||
"fillcolor": "darkgoldenrod1",
|
"fillcolor": "darkgoldenrod1",
|
||||||
"label": fmt.Sprintf("{Mirror %s|url: %s|dist: %s|comp: %s|arch: %s|pkgs: %d}",
|
"label": fmt.Sprintf("%sMirror %s|url: %s|dist: %s|comp: %s|arch: %s|pkgs: %d%s", labelStart, repo.Name, repo.ArchiveRoot,
|
||||||
repo.Name, repo.ArchiveRoot, repo.Distribution, strings.Join(repo.Components, ", "),
|
repo.Distribution, strings.Join(repo.Components, ", "),
|
||||||
strings.Join(repo.Architectures, ", "), repo.NumPackages()),
|
strings.Join(repo.Architectures, ", "), repo.NumPackages(), labelEnd),
|
||||||
})
|
})
|
||||||
existingNodes[repo.UUID] = true
|
existingNodes[repo.UUID] = true
|
||||||
return nil
|
return nil
|
||||||
@@ -48,8 +61,8 @@ func BuildGraph(collectionFactory *CollectionFactory) (gographviz.Interface, err
|
|||||||
"shape": "Mrecord",
|
"shape": "Mrecord",
|
||||||
"style": "filled",
|
"style": "filled",
|
||||||
"fillcolor": "mediumseagreen",
|
"fillcolor": "mediumseagreen",
|
||||||
"label": fmt.Sprintf("{Repo %s|comment: %s|pkgs: %d}",
|
"label": fmt.Sprintf("%sRepo %s|comment: %s|pkgs: %d%s", labelStart,
|
||||||
repo.Name, repo.Comment, repo.NumPackages()),
|
repo.Name, repo.Comment, repo.NumPackages(), labelEnd),
|
||||||
})
|
})
|
||||||
existingNodes[repo.UUID] = true
|
existingNodes[repo.UUID] = true
|
||||||
return nil
|
return nil
|
||||||
@@ -72,14 +85,15 @@ func BuildGraph(collectionFactory *CollectionFactory) (gographviz.Interface, err
|
|||||||
|
|
||||||
description := snapshot.Description
|
description := snapshot.Description
|
||||||
if snapshot.SourceKind == "repo" {
|
if snapshot.SourceKind == "repo" {
|
||||||
description = "Snapshot from repo"
|
description = "Snapshot from repo\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
graph.AddNode("aptly", snapshot.UUID, map[string]string{
|
graph.AddNode("aptly", snapshot.UUID, map[string]string{
|
||||||
"shape": "Mrecord",
|
"shape": "Mrecord",
|
||||||
"style": "filled",
|
"style": "filled",
|
||||||
"fillcolor": "cadetblue1",
|
"fillcolor": "cadetblue1",
|
||||||
"label": fmt.Sprintf("{Snapshot %s|%s|pkgs: %d}", snapshot.Name, description, snapshot.NumPackages()),
|
"label": fmt.Sprintf("%sSnapshot %s|%s|pkgs: %d%s", labelStart,
|
||||||
|
snapshot.Name, description, snapshot.NumPackages(), labelEnd),
|
||||||
})
|
})
|
||||||
|
|
||||||
if snapshot.SourceKind == "repo" || snapshot.SourceKind == "local" || snapshot.SourceKind == "snapshot" {
|
if snapshot.SourceKind == "repo" || snapshot.SourceKind == "local" || snapshot.SourceKind == "snapshot" {
|
||||||
@@ -102,8 +116,9 @@ func BuildGraph(collectionFactory *CollectionFactory) (gographviz.Interface, err
|
|||||||
"shape": "Mrecord",
|
"shape": "Mrecord",
|
||||||
"style": "filled",
|
"style": "filled",
|
||||||
"fillcolor": "darkolivegreen1",
|
"fillcolor": "darkolivegreen1",
|
||||||
"label": fmt.Sprintf("{Published %s/%s|comp: %s|arch: %s}", repo.Prefix, repo.Distribution,
|
"label": fmt.Sprintf("%sPublished %s/%s|comp: %s|arch: %s%s", labelStart,
|
||||||
strings.Join(repo.Components(), " "), strings.Join(repo.Architectures, ", ")),
|
repo.Prefix, repo.Distribution, strings.Join(repo.Components(), " "),
|
||||||
|
strings.Join(repo.Architectures, ", "), labelEnd),
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, uuid := range repo.Sources {
|
for _, uuid := range repo.Sources {
|
||||||
|
|||||||
Reference in New Issue
Block a user