Change 'vertical' argument to a more generic 'layout', fix api

This commit is contained in:
jolo
2017-01-16 22:13:01 +01:00
parent 0e8ea6363a
commit 91561b40f6
3 changed files with 18 additions and 20 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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{}