diff --git a/output/dot/dot.go b/output/dot/dot.go index 348032b0..329c8c14 100644 --- a/output/dot/dot.go +++ b/output/dot/dot.go @@ -40,6 +40,7 @@ func (d *Dot) OutputDiagram(wr io.Writer, diag *config.Diagram) error { "RemainNodes": remain, "GlobalComponents": d.config.GlobalComponents(), "Edges": config.MergeEdges(nEdges), + "HideUnlinked": false, }); err != nil { return err } @@ -81,6 +82,7 @@ L: "RemainNodes": []*config.Node{}, "GlobalComponents": []*config.Component{}, "Edges": config.MergeEdges(edges), + "HideUnlinked": false, }); err != nil { return err } @@ -205,6 +207,7 @@ func (d *Dot) OutputTag(wr io.Writer, t *config.Tag) error { "RemainNodes": nodes, "GlobalComponents": globalComponents, "Edges": edges, + "HideUnlinked": true, }); err != nil { return err } @@ -268,6 +271,7 @@ func (d *Dot) OutputNetwork(wr io.Writer, nw *config.Network) error { "RemainNodes": nodes, "GlobalComponents": globalComponents, "Edges": edges, + "HideUnlinked": true, }); err != nil { return err } diff --git a/output/dot/templates/diagram.dot.tmpl b/output/dot/templates/diagram.dot.tmpl index 48e990c3..b59e037b 100644 --- a/output/dot/templates/diagram.dot.tmpl +++ b/output/dot/templates/diagram.dot.tmpl @@ -2,22 +2,24 @@ digraph ndiag { graph [rankdir=TB, layout=dot, fontname="Arial"]; {{ define "cluster" }} - subgraph "cluster_{{ . | id }}" { - label = "{{ .Layer }}:{{ .Name | unesc }}"; + subgraph "cluster_{{ .cluster | id }}" { + label = "{{ .cluster.Layer }}:{{ .cluster.Name | unesc }}"; style = "rounded,filled"; color = "#4B75B933" shape = box; fontname="Arial"; - {{ range $_, $n := .Nodes }} + {{ range $n := .cluster.Nodes }} subgraph "cluster_{{ $n | id }}" { label = "{{ $n.Name | unesc }} ({{ len $n.RealNodes }})"; style = "solid,bold,filled"; color = "#333333" fillcolor = "#FFFFFF" - {{ range $_, $co := $n.Components }} + {{ range $co := $n.Components }} + {{ if or (not $.hideUnlinked) (is_linked $co $.edges) }} "{{ $co | id }}"[label="{{ $co.Name | unesc }}", style="rounded,filled,bold", color="#FFFFFF", fillcolor="#4B75B9", fontcolor="#FFFFFF" shape=box, fontname="Arial"]; {{ end }} + {{ end }} {{ $length := len $n.Components }} {{ if eq $length 0 }} @@ -26,27 +28,31 @@ digraph ndiag { } {{ end }} - {{ range $_, $co := .Components }} + {{ range $co := .cluster.Components }} + {{ if or (not $.hideUnlinked) (is_linked $co $.edges) }} "{{ $co | id }}"[label="{{ $co.Name | unesc }}", style="rounded,filled,bold", color="#FFFFFF", fillcolor="#4B75B9", fontcolor="#FFFFFF" shape=box, fontname="Arial"]; + {{ end }} {{ end }} - {{ range .Children }} - {{ template "cluster" . }} + {{ range $c := .cluster.Children }} + {{ template "cluster" (dict "cluster" $c "edges" $.edges "hideUnlinked" $.hideUnlinked) }} {{ end }} } {{ end }} -{{ range .Clusters }} - {{ template "cluster" . }} +{{ range $c := .Clusters }} + {{ template "cluster" (dict "cluster" $c "edges" $.Edges "hideUnlinked" $.HideUnlinked) }} {{ end }} -{{ range $_, $n := .RemainNodes }} +{{ range $n := .RemainNodes }} subgraph "cluster_{{ $n.Name }}" { label = "{{ $n | fullname }} ({{ len $n.RealNodes }})"; style = "solid,bold"; - {{ range $_, $co := $n.Components }} + {{ range $co := $n.Components }} + {{ if or (not $.HideUnlinked) (is_linked $co $.Edges) }} "{{$co | id }}"[label="{{ $co.Name | unesc }}", style="rounded,filled,bold", color="#FFFFFF", fillcolor="#4B75B9", fontcolor="#FFFFFF" shape=box, fontname="Arial"]; {{ end }} + {{ end }} {{ $length := len $n.Components }} {{ if eq $length 0 }} "none"[label="", shape=none]; @@ -54,11 +60,13 @@ digraph ndiag { } {{ end }} -{{ range $_, $co := .GlobalComponents }} +{{ range $co := .GlobalComponents }} +{{ if or (not $.HideUnlinked) (is_linked $co $.Edges) }} "{{ $co | id }}"[label="{{ $co.Name | unesc }}", style="rounded,bold", shape=box, fontname="Arial"]; {{ end }} +{{ end }} -{{ range $_, $e := .Edges }} +{{ range $e := .Edges }} "{{ $e.Src | id }}" -> "{{ $e.Dst | id }}"[arrowhead=normal, arrowtail=normal, headlabel="", taillabel="", color="#33333399", labelfontcolor="#333333", style=bold, fontname="Arial"{{ $e.Attrs | attrs }}]; {{ end }} diff --git a/output/dot/templates/node.dot.tmpl b/output/dot/templates/node.dot.tmpl index b648e42e..84dfc99f 100644 --- a/output/dot/templates/node.dot.tmpl +++ b/output/dot/templates/node.dot.tmpl @@ -2,22 +2,24 @@ digraph ndiag { graph [rankdir=TB, layout=dot, fontname="Arial"]; {{ define "cluster" }} - subgraph "cluster_{{ . | id }}" { - label = "{{ .Layer }}:{{ .Name | unesc }}"; + subgraph "cluster_{{ .cluster | id }}" { + label = "{{ .cluster.Layer }}:{{ .cluster.Name | unesc }}"; style = "rounded,filled"; color = "#4B75B933" shape = box; fontname="Arial"; - {{ range $_, $n := .Nodes }} + {{ range $n := .cluster.Nodes }} subgraph "cluster_{{ $n | id }}" { label = "{{ $n.Name | unesc }} ({{ len $n.RealNodes }})"; style = "solid,bold,filled"; color = "#333333" fillcolor = "#FFFFFF" - {{ range $_, $co := $n.Components }} + {{ range $co := $n.Components }} + {{ if is_linked $co $.edges }} "{{ $co | id }}"[label="{{ $co.Name | unesc }}", style="rounded,filled,bold", color="#FFFFFF", fillcolor="#4B75B9", fontcolor="#FFFFFF" shape=box, fontname="Arial"]; {{ end }} + {{ end }} {{ $length := len $n.Components }} {{ if eq $length 0 }} @@ -26,21 +28,23 @@ digraph ndiag { } {{ end }} - {{ range $_, $co := .Components }} + {{ range $co := .cluster.Components }} + {{ if is_linked $co $.edges }} "{{ $co | id }}"[label="{{ $co.Name | unesc }}", style="rounded,filled,bold", color="#FFFFFF", fillcolor="#4B75B9", fontcolor="#FFFFFF" shape=box, fontname="Arial"]; + {{ end }} {{ end }} - {{ range .Children }} - {{ template "cluster" . }} + {{ range $c := .cluster.Children }} + {{ template "cluster" (dict "cluster" $c "edges" $.edges) }} {{ end }} } {{ end }} -{{ range .Clusters }} - {{ template "cluster" . }} +{{ range $c := .Clusters }} + {{ template "cluster" (dict "cluster" $c "edges" $.Edges) }} {{ end }} -{{ range $_, $n := .RemainNodes }} +{{ range $n := .RemainNodes }} subgraph "cluster_{{ $n.Name }}" { label = "{{ $n | fullname }} ({{ len $n.RealNodes }})"; style = "solid,bold"; @@ -49,9 +53,11 @@ digraph ndiag { fontcolor="#666666"; color="#999999"; {{ end }} - {{ range $_, $co := $n.Components }} + {{ range $co := $n.Components }} + {{ if or (eq $.MainNodeId ($n | id)) (is_linked $co $.Edges) }} "{{$co | id }}"[label="{{ $co.Name | unesc }}", style="rounded,filled,bold", color="#FFFFFF", fillcolor="#4B75B9", fontcolor="#FFFFFF" shape=box, fontname="Arial"]; {{ end }} + {{ end }} {{ $length := len $n.Components }} {{ if eq $length 0 }} "none"[label="", shape=none]; @@ -59,11 +65,13 @@ digraph ndiag { } {{ end }} -{{ range $_, $co := .GlobalComponents }} +{{ range $co := .GlobalComponents }} +{{ if is_linked $co $.Edges }} "{{ $co | id }}"[label="{{ $co.Name | unesc }}", style="rounded,bold", shape=box, fontname="Arial"]; {{ end }} +{{ end }} -{{ range $_, $e := .Edges }} +{{ range $e := .Edges }} "{{ $e.Src | id }}" -> "{{ $e.Dst | id }}"[arrowhead=normal, arrowtail=normal, headlabel="", taillabel="", color="#33333399", labelfontcolor="#333333", style=bold, fontname="Arial"{{ $e.Attrs | attrs }}]; {{ end }} diff --git a/output/output.go b/output/output.go index 1a6a29ff..3133bdc4 100644 --- a/output/output.go +++ b/output/output.go @@ -98,6 +98,23 @@ var FuncMap = template.FuncMap{ } return out }, + "dict": func(v ...interface{}) map[string]interface{} { + dict := map[string]interface{}{} + length := len(v) + for i := 0; i < length; i += 2 { + key := v[i].(string) + dict[key] = v[i+1] + } + return dict + }, + "is_linked": func(c *config.Component, edges []*config.NEdge) bool { + for _, e := range edges { + if c.Id() == e.Src.Id() || c.Id() == e.Dst.Id() { + return true + } + } + return false + }, } // componentLink