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

different colours for custom groups #38

Open
mihai-satmarean opened this issue Apr 10, 2018 · 3 comments
Open

different colours for custom groups #38

mihai-satmarean opened this issue Apr 10, 2018 · 3 comments

Comments

@mihai-satmarean
Copy link

Hi, again we find it very useful to toy around, in order to see some production use we could have different groups represented with different colours.
EG: Ansible reserved groups with grey and our defined groups with other colour, maybe even the children with specific colours.
Thanks!

@willthames
Copy link
Owner

willthames commented Apr 10, 2018

I'd suggest using a custom template (using the -t option) to achieve this. Other than all, there's not really any such thing as reserved groups, as far as I'm aware.

@mihai-satmarean
Copy link
Author

mihai-satmarean commented Apr 10, 2018 via email

@hryamzik
Copy link

{%- set group_colors = {
"group1": "green",
"group2": "blue",
"group3": "orange"
} -%}

{%- set fill_colors = {
"green": "aquamarine",
"blue":  "aqua",
"orange": "yellow"
} %}

{%- set narrow_target_styles = {
"group1": "dotted",
"group2":  "dotted",
"group3":        "dotted",
}%}

{%- set color_map = {} %}
{%- for edge in edges|sort(attribute='source') if edge.source != "all"%}
  {%- if edge.source in group_colors %}
      {%- set color_map=color_map.__setitem__(edge.source, group_colors[edge.source]) %}
  {%- endif %}
{%- endfor %}
{%- for edge in edges|sort(attribute='source') if edge.source != "all"%}
  {%- if edge.source in group_colors %}
      {%- set color_map=color_map.__setitem__(edge.target, group_colors[edge.source]) %}
  {%- endif %}
{%- endfor %}

# repeat step to paint more levels
{%- for edge in edges|sort(attribute='source') if edge.source != "all"%}
  {%- if edge.source in color_map %}
      {%- set color_map=color_map.__setitem__(edge.target, color_map[edge.source]) %}
  {%- endif %}
{%- endfor %}

digraph {{pattern|labelescape}} {
  {{ attributes }}

{% for node in nodes|sort(attribute='name') if node.name != "all" %}
  {{ node.name|labelescape }} [shape=record penwidth=2 {% if node.name in color_map %}color="{{ color_map[node.name] }}" fillcolor="{{ fill_colors[color_map[node.name]] }}" {% endif %}style="filled{% if node.leaf %},rounded{% endif %}" label=<
<table border="0" cellborder="0">
  <tr><td><b>
  <font face="Times New Roman, Bold" point-size="16">{{ node.name}}</font>
  </b></td></tr>
{% if node.vars and showvars %}<hr/><tr><td><font face="Times New Roman, Bold" point-size="14">{% for var in node.vars|sort %}{{var}}{% if var|is_visible %} =<b>{{node.vars[var]}}</b>{% endif %}<br/>{%endfor %}</font></td></tr>{% endif %}
</table>
>]
{% endfor %}

{% for edge in edges|sort(attribute='source') if edge.source != "all"%}
  {{ edge.source|labelescape }} -> {{ edge.target|labelescape }}[penwidth=3
  {%- if edge.target in narrow_target_styles %}
  style = "{{ narrow_target_styles[edge.target] }}"];
  {% else %}
    {% if edge.source in color_map %} color="{{ color_map[edge.source] }}"{% endif %}];
  {% endif %}
{% endfor %}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants