{#-----------------constants---------------------------#} {% set barThickness = 96 %} {% set barToValue = 6 %} {% set arrowHead = 6 %} {% set graphPadding = 48 %} {% set topPadding = 48.0 %} {% set bottomPadding = 24.0 %} {#------calculate values from template elements--------#} {% set values = elementsToValues(elements, 'tx-..-([1-9]\d*)-value') %} {% set n = values | length %} {% if n == 0 %} {% set values = [ 0 ] %} {% set n = 1 %} {% endif %} {% set maxValue = values | max %} {% set minValue = values | min %} {% if maxValue == minValue %} {% set maxValue = minValue + 1 %} {% endif %} {% set height = 240 %} {% set width = barThickness * n %} {# labels #} {%for i in range(n) %} {% set textWidth = barThickness - 2 %} {% set x = barThickness/2 + textWidth/2 + barThickness * i %} {% endfor %} {# buttons #} {%for i in range(n+1) %} {% set x = barThickness * i %} {% if n > 1 and n > i %} {% endif %} {% endfor %} {# back #} {% set half_n = (n+1) // 2 %} {%for i in range(half_n) %} {% set x = barThickness * i * 2 %} {% endfor %} {# axes #} {# line #} {% set ns = namespace(path='') %} {%for i in range(n) %} {% set x = barThickness/2 + barThickness * i %} {% set y = (height - topPadding - bottomPadding) * (maxValue - values[i]) / (maxValue - minValue) + topPadding | round(3) %} {% set action = 'M' if i == 0 else 'L' %} {% set ns.path = ns.path ~ action ~ x | round(3) ~ " " ~ y | round(3) %} {% endfor %} {# dots #} {%for i in range(n) %} {% set x = barThickness/2 + barThickness * i %} {% set y = (height - topPadding - bottomPadding) * (maxValue - values[i]) / (maxValue - minValue) + topPadding | round(3) %} {% endfor %} {# values #} {%for i in range(n) %} {% set x = barThickness/2 + barThickness * i %} {% set y = (height - topPadding - bottomPadding) * (maxValue - values[i]) / (maxValue - minValue) + topPadding - 12 | round(3) %} {% endfor %}