Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hideRealNodes #25

Merged
merged 1 commit into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Config struct {
DocPath string `yaml:"docPath"`
DescPath string `yaml:"descPath"`
Graph *Graph `yaml:"graph,omitempty"`
HideRealNodes bool `yaml:"hideRealNodes"`
Diagrams []*Diagram `yaml:"diagrams"`
Nodes []*Node `yaml:"nodes"`
Relations []*Relation `yaml:"relations"`
Expand Down
20 changes: 11 additions & 9 deletions config/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import (

func (d *Config) UnmarshalYAML(data []byte) error {
raw := struct {
Name string `yaml:"name"`
Desc string `yaml:"desc,omitempty"`
DocPath string `yaml:"docPath"`
DescPath string `yaml:"descPath"`
Graph *Graph `yaml:"graph,omitempty"`
Diagrams []*Diagram `yaml:"diagrams"`
Nodes []*Node `yaml:"nodes"`
Networks []interface{} `yaml:"networks"`
Relations []interface{} `yaml:"relations"`
Name string `yaml:"name"`
Desc string `yaml:"desc,omitempty"`
DocPath string `yaml:"docPath"`
DescPath string `yaml:"descPath"`
Graph *Graph `yaml:"graph,omitempty"`
HideRealNodes bool `yaml:"hideRealNodes"`
Diagrams []*Diagram `yaml:"diagrams"`
Nodes []*Node `yaml:"nodes"`
Networks []interface{} `yaml:"networks"`
Relations []interface{} `yaml:"relations"`
}{}

if err := yaml.Unmarshal(data, &raw); err != nil {
Expand All @@ -30,6 +31,7 @@ func (d *Config) UnmarshalYAML(data []byte) error {
d.DocPath = raw.DocPath
d.DescPath = raw.DescPath
d.Graph = raw.Graph
d.HideRealNodes = raw.HideRealNodes
d.Diagrams = raw.Diagrams
d.Nodes = raw.Nodes

Expand Down
2 changes: 2 additions & 0 deletions output/dot/dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (d *Dot) OutputDiagram(wr io.Writer, diag *config.Diagram) error {
"GlobalComponents": d.config.GlobalComponents(),
"Edges": config.MergeEdges(nEdges),
"HideUnlinked": false,
"HideRealNodes": d.config.HideRealNodes,
}); err != nil {
return err
}
Expand Down Expand Up @@ -277,6 +278,7 @@ func (d *Dot) OutputRelation(wr io.Writer, rel *config.Relation) error {
"GlobalComponents": globalComponents,
"Edges": edges,
"HideUnlinked": true,
"HideRealNodes": d.config.HideRealNodes,
}); err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions output/dot/templates/diagram.dot.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ digraph ndiag {

{{ range $n := .cluster.Nodes }}
subgraph "cluster_{{ $n | id }}" {
label = "{{ $n.Name | unesc }} ({{ len $n.RealNodes }})";
label = "{{ $n.Name | unesc }}{{ if not $.hideRealNodes }} ({{ len $n.RealNodes }}){{ end }}";
style = "solid,bold,filled";
color = "#333333"
fillcolor = "#FFFFFF"
Expand All @@ -35,18 +35,18 @@ digraph ndiag {
{{ end }}

{{ range $c := .cluster.Children }}
{{ template "cluster" (dict "cluster" $c "edges" $.edges "hideUnlinked" $.hideUnlinked) }}
{{ template "cluster" (dict "cluster" $c "edges" $.edges "hideUnlinked" $.hideUnlinked "hideRealNodes" $.hideRealNodes) }}
{{ end }}
}
{{ end }}

{{ range $c := .Clusters }}
{{ template "cluster" (dict "cluster" $c "edges" $.Edges "hideUnlinked" $.HideUnlinked) }}
{{ template "cluster" (dict "cluster" $c "edges" $.Edges "hideUnlinked" $.HideUnlinked "hideRealNodes" $.HideRealNodes) }}
{{ end }}

{{ range $n := .RemainNodes }}
subgraph "cluster_{{ $n.Name }}" {
label = "{{ $n | fullname }} ({{ len $n.RealNodes }})";
label = "{{ $n | fullname }}{{ if not $.HideRealNodes }} ({{ len $n.RealNodes }}){{ end }}";
style = "solid,bold";
{{ range $co := $n.Components }}
{{ if or (not $.HideUnlinked) (is_linked $co $.Edges) }}
Expand Down
8 changes: 4 additions & 4 deletions output/dot/templates/node.dot.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ digraph ndiag {

{{ range $n := .cluster.Nodes }}
subgraph "cluster_{{ $n | id }}" {
label = "{{ $n.Name | unesc }} ({{ len $n.RealNodes }})";
label = "{{ $n.Name | unesc }}{{ if not $.hideRealNodes }} ({{ len $n.RealNodes }}){{ end }}";
style = "solid,bold,filled";
color = "#333333"
fillcolor = "#FFFFFF"
Expand All @@ -35,18 +35,18 @@ digraph ndiag {
{{ end }}

{{ range $c := .cluster.Children }}
{{ template "cluster" (dict "cluster" $c "edges" $.edges) }}
{{ template "cluster" (dict "cluster" $c "edges" $.edges "hideRealNodes" $.hideRealNodes) }}
{{ end }}
}
{{ end }}

{{ range $c := .Clusters }}
{{ template "cluster" (dict "cluster" $c "edges" $.Edges) }}
{{ template "cluster" (dict "cluster" $c "edges" $.Edges "hideRealNodes" $.HideRealNodes) }}
{{ end }}

{{ range $n := .RemainNodes }}
subgraph "cluster_{{ $n.Name }}" {
label = "{{ $n | fullname }} ({{ len $n.RealNodes }})";
label = "{{ $n | fullname }}{{ if not $.HideRealNodes }} ({{ len $n.RealNodes }}){{ end }}";
style = "solid,bold";
{{ if eq $.MainNodeId ($n | id) }}
{{ else }}
Expand Down
61 changes: 31 additions & 30 deletions output/md/md.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func (m *Md) OutputDiagram(wr io.Writer, d *config.Diagram) error {

tmpl := template.Must(template.New(d.Name).Funcs(output.FuncMap).Parse(ts))
tmplData := map[string]interface{}{
"Diagram": d,
"Format": m.config.Format(),
"DescPath": relPath,
"Layers": layers,
"Nodes": m.config.Nodes,
"Tags": m.config.Tags(),
"Diagram": d,
"Format": m.config.Format(),
"DescPath": relPath,
"Layers": layers,
"Nodes": m.config.Nodes,
"Tags": m.config.Tags(),
}
if err := tmpl.Execute(wr, tmplData); err != nil {
return err
Expand All @@ -76,10 +76,10 @@ func (m *Md) OutputLayer(wr io.Writer, l *config.Layer) error {

tmpl := template.Must(template.New(l.Name).Funcs(output.FuncMap).Parse(ts))
tmplData := map[string]interface{}{
"Layer": l,
"Format": m.config.Format(),
"DescPath": relPath,
"Clusters": clusters,
"Layer": l,
"Format": m.config.Format(),
"DescPath": relPath,
"Clusters": clusters,
}
if err := tmpl.Execute(wr, tmplData); err != nil {
return err
Expand Down Expand Up @@ -118,12 +118,13 @@ func (m *Md) OutputNode(wr io.Writer, n *config.Node) error {

tmpl := template.Must(template.New(n.Id()).Funcs(output.FuncMap).Parse(ts))
tmplData := map[string]interface{}{
"Node": n,
"Format": m.config.Format(),
"DescPath": relPath,
"Components": n.Components,
"RealNodes": n.RealNodes,
"Tags": tags,
"Node": n,
"Format": m.config.Format(),
"DescPath": relPath,
"Components": n.Components,
"RealNodes": n.RealNodes,
"Tags": tags,
"HideRealNodes": m.config.HideRealNodes,
}
if err := tmpl.Execute(wr, tmplData); err != nil {
return err
Expand All @@ -144,9 +145,9 @@ func (m *Md) OutputTag(wr io.Writer, t *config.Tag) error {

tmpl := template.Must(template.New(t.Id()).Funcs(output.FuncMap).Parse(ts))
tmplData := map[string]interface{}{
"Tag": t,
"Format": m.config.Format(),
"DescPath": relPath,
"Tag": t,
"Format": m.config.Format(),
"DescPath": relPath,
}

if err := tmpl.Execute(wr, tmplData); err != nil {
Expand All @@ -169,9 +170,9 @@ func (m *Md) OutputRelation(wr io.Writer, rel *config.Relation) error {

tmpl := template.Must(template.New(rel.Id()).Funcs(output.FuncMap).Parse(ts))
tmplData := map[string]interface{}{
"Relation": rel,
"Format": m.config.Format(),
"DescPath": relPath,
"Relation": rel,
"Format": m.config.Format(),
"DescPath": relPath,
}

if err := tmpl.Execute(wr, tmplData); err != nil {
Expand All @@ -194,14 +195,14 @@ func (m *Md) OutputIndex(wr io.Writer) error {

tmpl := template.Must(template.New("index").Funcs(output.FuncMap).Parse(ts))
tmplData := map[string]interface{}{
"Config": m.config,
"Diagram": m.config.PrimaryDiagram(),
"Format": m.config.Format(),
"DescPath": relPath,
"Diagrams": m.config.Diagrams,
"Layers": m.config.Layers(),
"Nodes": m.config.Nodes,
"Tags": m.config.Tags(),
"Config": m.config,
"Diagram": m.config.PrimaryDiagram(),
"Format": m.config.Format(),
"DescPath": relPath,
"Diagrams": m.config.Diagrams,
"Layers": m.config.Layers(),
"Nodes": m.config.Nodes,
"Tags": m.config.Tags(),
}
if err := tmpl.Execute(wr, tmplData); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion output/md/templates/diagram.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
| Name (node count) | Description |
| --- | --- |
{{- range $i, $n := .Nodes }}
| [{{ $n | fullname }}]({{ mdpath "node" ($n | id) }}) ({{ len $n.RealNodes }}) | {{ if ne $n.Desc "" }}{{ $n.Desc | summary }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_node" ($n | id)}}">:pencil2:</a>{{ end }} |
| [{{ $n | fullname }}]({{ mdpath "node" ($n | id) }}){{ if not $.HideRealNodes }} ({{ len $n.RealNodes }}){{ end }} | {{ if ne $n.Desc "" }}{{ $n.Desc | summary }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_node" ($n | id)}}">:pencil2:</a>{{ end }} |
{{- end }}
## Tag groups

Expand Down
2 changes: 1 addition & 1 deletion output/md/templates/index.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
| Name (node count) | Description |
| --- | --- |
{{- range $i, $n := .Nodes }}
| [{{ $n | fullname }}]({{ mdpath "node" ($n | id) }}) ({{ len $n.RealNodes }}) | {{ if ne $n.Desc "" }}{{ $n.Desc | summary }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_node" ($n | id)}}">:pencil2:</a>{{ end }} |
| [{{ $n | fullname }}]({{ mdpath "node" ($n | id) }}){{ if not $.HideRealNodes }} ({{ len $n.RealNodes }}){{ end }} | {{ if ne $n.Desc "" }}{{ $n.Desc | summary }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_node" ($n | id)}}">:pencil2:</a>{{ end }} |
{{- end }}

## Tag groups
Expand Down
2 changes: 1 addition & 1 deletion output/md/templates/layer.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
| Name (node count) | Description |
| --- | --- |
{{- range $i, $n := $c.Nodes }}
| [{{ $n | fullname }}]({{ mdpath "node" ($n | id) }}) ({{ len $n.RealNodes }}) | {{ if ne $n.Desc "" }}{{ $n.Desc | summary }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_node" ($n | id)}}">:pencil2:</a>{{ end }} |
| [{{ $n | fullname }}]({{ mdpath "node" ($n | id) }}){{ if not $.HideRealNodes }} ({{ len $n.RealNodes }}){{ end }} | {{ if ne $n.Desc "" }}{{ $n.Desc | summary }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_node" ($n | id)}}">:pencil2:</a>{{ end }} |
{{- end }}

{{- end}}
Expand Down
2 changes: 2 additions & 0 deletions output/md/templates/node.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
{{- range $i, $t := .Tags }}
| [{{ $t | fullname }}]({{ mdpath "tag" ($t | id) }}) | {{ if ne $t.Desc "" }}{{ $t.Desc | summary }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_tag" ($t | id)}}">:pencil2:</a>{{ end }} |
{{- end }}
{{- if not .HideRealNodes }}
## Real nodes
{{ range $i, $rn := .RealNodes }}
- {{ $rn | fullname }}
{{- end }}
{{- end }}

---

Expand Down