Skip to content

Commit

Permalink
Add SVG export capability
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed Oct 2, 2023
1 parent 18a6390 commit 1d791f4
Show file tree
Hide file tree
Showing 3 changed files with 18,314 additions and 8 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ Check the integrity of the workflow, e.g.:

#### Export capabilities

Workflow graphs can be exported to [DOT][2], an open graph description language. Various programs can process DOT files. E.g. `dot` (GraphViz) can be used to render the graph in a graphical form. The following example renders the workflow as SVG:
Workflow graphs can be exported to SVG or [DOT][2] (an open graph description language). Various programs can process DOT files. E.g. `dot` (GraphViz) can be used to render the graph in a graphical form. The following example uses X11 to open an interactive graph viewer based on Xlib canvas:

amflow export --format=dot | dot -v -Tsvg 2>/dev/null > ~/graph.svg
amflow export --format=dot --latest | dot -v -Tx11

This is another example that uses X11 to open an interactive graph viewer based on Xlib canvas:
By default, amflow hides certain graph nodes to speed up rendering. It is possible to render the full graph using the optional argument `--full`, e.g.:

amflow export --format=dot | dot -v -Tx11
amflow export --full --format=dot --latest | dot -v -Tx11

By default, amflow hides certain graph nodes to speed up rendering. It is possible to render the full graph using the optional argument `--full`, e.g.:
Producing a SVG document can be done similarly:

amflow export --full --format=dot | dot -v -Tx11
amflow export --format=svg --file=workflow.json > /tmp/workflow.svg

## Limitations

Expand Down
16 changes: 14 additions & 2 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var (
exportFile string
exportFormat string
exportFull bool
exportLatest bool
)

func newCmdExport(out io.Writer) *cobra.Command {
Expand All @@ -31,23 +32,34 @@ Usage example:
}
cmd.Flags().StringVarP(&exportFile, "file", "f", "", "Path of JSON-encoded workflow document")
cmd.Flags().StringVarP(&exportFormat, "format", "", "dot", "Format of the export")
cmd.Flags().BoolVarP(&exportLatest, "latest", "", false, "Download the latest workflow available in QA")
cmd.Flags().BoolVarP(&exportFull, "full", "", false, "Include the full graph (slower)")
return cmd
}

func export(out io.Writer) error {
if exportLatest {
exportFile = latestWorkflow
}
w, err := load(exportFile)
if err != nil {
return err
}

checkDot()

// Print it out.
blob, err := w.DOT(&graph.VizOpts{Full: exportFull})
var blob []byte
switch exportFormat {
case "dot":
blob, err = w.DOT(&graph.VizOpts{Full: exportFull})
case "svg":
blob, err = w.SVG(&graph.VizOpts{Full: exportFull})
}
if err != nil {
return err
}

_, err = fmt.Fprint(out, string(blob))

return err
}
Loading

0 comments on commit 1d791f4

Please sign in to comment.