Skip to content

Commit

Permalink
Support cluster icon
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Jan 10, 2021
1 parent 59fde11 commit db4d853
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
1 change: 0 additions & 1 deletion config/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ func (cfg *Config) buildRelations() error {
Attrs: rel.Attrs,
}
for _, r := range rel.Components {
_, _ = fmt.Fprintf(os.Stderr, "rel.Components %v\n", r)
c, err := cfg.FindComponent(r)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion output/dot/templates/diagram.dot.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ digraph ndiag {

{{ define "cluster" }}
subgraph "cluster_{{ .cluster | id }}" {
label = "{{ .cluster.Layer }}:{{ .cluster.Name | unesc }}";
label = {{ .cluster | cluster_label }};
style = "rounded,filled,setlinewidth(2)";
color = "{{ .cluster.Metadata.Color | colorhex }}"
fillcolor = "{{ .cluster.Metadata.FillColor | colorhex }}"
Expand Down
2 changes: 1 addition & 1 deletion output/dot/templates/node.dot.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ digraph ndiag {

{{ define "cluster" }}
subgraph "cluster_{{ .cluster | id }}" {
label = "{{ .cluster.Layer }}:{{ .cluster.Name | unesc }}";
label = {{ .cluster | cluster_label }};
style = "rounded,filled,setlinewidth(2)";
color = "{{ .cluster.Metadata.Color | colorhex }}"
fillcolor = "{{ .cluster.Metadata.FillColor | colorhex }}"
Expand Down
12 changes: 12 additions & 0 deletions output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ func Funcs(cfg *config.Config) map[string]interface{} {
return fmt.Sprintf(`<<table border="0" cellborder="0" cellspacing="0" cellpadding="0"><tr><td><img src="%s" /></td></tr><tr><td>%s</td></tr></table>>`, i.Path, label)
}
},
"cluster_label": func(c config.Cluster) string {
label := unescRep.Replace(c.FullName())
if c.Metadata.Icon == "" {
return fmt.Sprintf(`"%s"`, label)
} else {
i, err := cfg.IconMap().Get(c.Metadata.Icon)
if err != nil {
panic(err)
}
return fmt.Sprintf(`<<table border="0" cellborder="0" cellspacing="0" cellpadding="0"><tr><td><img src="%s" /></td></tr><tr><td>%s</td></tr></table>>`, i.Path, label)
}
},
"component": func(c config.Component) string {
bc := cfg.BaseColor
tc := cfg.TextColor
Expand Down
1 change: 1 addition & 0 deletions sample/k8s/input/ndiag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ docPath: ../output
nodes:
- name: my-namespace
clusters:
- 'cluster:k8s'
- 'netpol:a'
- 'limits:b'
- 'quota:c'
Expand Down

0 comments on commit db4d853

Please sign in to comment.