mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-04-20 19:38:39 +00:00
Change 'vertical' argument to a more generic 'layout', fix api
This commit is contained in:
12
api/graph.go
12
api/graph.go
@@ -11,20 +11,16 @@ import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// GET /api/graph.:ext/:vertical
|
||||
// GET /api/graph.:ext?layout=[vertical|horizontal(default)]
|
||||
func apiGraph(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
output []byte
|
||||
vertical bool = false
|
||||
)
|
||||
|
||||
ext := c.Params.ByName("ext")
|
||||
|
||||
// TODO: api is untested!
|
||||
if c.Params.ByName("vertical") == "vertical" {
|
||||
vertical = true
|
||||
}
|
||||
layout := c.Request.URL.Query().Get("layout")
|
||||
fmt.Printf("Layout is: "+layout)
|
||||
|
||||
factory := context.CollectionFactory()
|
||||
|
||||
@@ -37,7 +33,7 @@ func apiGraph(c *gin.Context) {
|
||||
factory.PublishedRepoCollection().RLock()
|
||||
defer factory.PublishedRepoCollection().RUnlock()
|
||||
|
||||
graph, err := deb.BuildGraph(factory, vertical)
|
||||
graph, err := deb.BuildGraph(factory, layout)
|
||||
if err != nil {
|
||||
c.JSON(500, err)
|
||||
return
|
||||
|
||||
@@ -21,10 +21,10 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
|
||||
return commander.ErrCommandError
|
||||
}
|
||||
|
||||
vertical := context.Flags().Lookup("vertical").Value.Get().(bool)
|
||||
layout := context.Flags().Lookup("layout").Value.String()
|
||||
|
||||
fmt.Printf("Generating graph...\n")
|
||||
graph, err := deb.BuildGraph(context.CollectionFactory(), vertical)
|
||||
graph, err := deb.BuildGraph(context.CollectionFactory(), layout)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -111,7 +111,7 @@ Example:
|
||||
|
||||
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.Bool("vertical", false, "try to achieve a more vertical graph layout")
|
||||
cmd.Flag.String("layout", "horizontal", "create a more 'vertical' or a more 'horizontal' graph layout")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
20
deb/graph.go
20
deb/graph.go
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
// BuildGraph generates graph contents from aptly object database
|
||||
func BuildGraph(collectionFactory *CollectionFactory, vertical bool) (gographviz.Interface, error) {
|
||||
func BuildGraph(collectionFactory *CollectionFactory, layout string) (gographviz.Interface, error) {
|
||||
var err error
|
||||
|
||||
graph := gographviz.NewEscape()
|
||||
@@ -17,14 +17,16 @@ func BuildGraph(collectionFactory *CollectionFactory, vertical bool) (gographviz
|
||||
var labelStart string
|
||||
var labelEnd string
|
||||
|
||||
if vertical {
|
||||
graph.AddAttr("aptly", "rankdir", "LR")
|
||||
labelStart = ""
|
||||
labelEnd = ""
|
||||
} else {
|
||||
graph.AddAttr("aptly", "rankdir", "TB")
|
||||
labelStart = "{"
|
||||
labelEnd = "}"
|
||||
switch layout {
|
||||
case "vertical":
|
||||
graph.AddAttr("aptly", "rankdir", "LR")
|
||||
labelStart = ""
|
||||
labelEnd = ""
|
||||
case "horizontal":
|
||||
fallthrough
|
||||
default:
|
||||
labelStart = "{"
|
||||
labelEnd = "}"
|
||||
}
|
||||
|
||||
existingNodes := map[string]bool{}
|
||||
|
||||
Reference in New Issue
Block a user