Skip to content

Commit

Permalink
Merge pull request #20 from k1LoW/hide-unnecessary-components
Browse files Browse the repository at this point in the history
Hide unlinked components on network tag group diagram and node diagram
  • Loading branch information
k1LoW authored Sep 27, 2020
2 parents 6288c46 + d066452 commit 9530644
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 26 deletions.
4 changes: 4 additions & 0 deletions output/dot/dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -81,6 +82,7 @@ L:
"RemainNodes": []*config.Node{},
"GlobalComponents": []*config.Component{},
"Edges": config.MergeEdges(edges),
"HideUnlinked": false,
}); err != nil {
return err
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
34 changes: 21 additions & 13 deletions output/dot/templates/diagram.dot.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -26,39 +28,45 @@ 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];
{{ end }}
}
{{ 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 }}

Expand Down
34 changes: 21 additions & 13 deletions output/dot/templates/node.dot.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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";
Expand All @@ -49,21 +53,25 @@ 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];
{{ end }}
}
{{ 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 }}

Expand Down
17 changes: 17 additions & 0 deletions output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9530644

Please sign in to comment.