summaryrefslogtreecommitdiffhomepage
path: root/apioforum/templates/common.html
diff options
context:
space:
mode:
authorubq323 <ubq323>2021-07-18 14:38:07 +0000
committerubq323 <ubq323>2021-07-18 14:38:07 +0000
commit153ac274490c08375d58fa83042406c6ec52f968 (patch)
tree26e878a1c7df08b1a68c7ab02bd2c85550c8a3b4 /apioforum/templates/common.html
parent8d2e7d0f6562f42730b8bc62576f10e7d06e5117 (diff)
vote meter on view thread page
Diffstat (limited to 'apioforum/templates/common.html')
-rw-r--r--apioforum/templates/common.html37
1 files changed, 37 insertions, 0 deletions
diff --git a/apioforum/templates/common.html b/apioforum/templates/common.html
index 3321085..c8afd9e 100644
--- a/apioforum/templates/common.html
+++ b/apioforum/templates/common.html
@@ -49,3 +49,40 @@
{% macro tag(the_tag) -%}
<span class="tag" style="color: {{the_tag.text_colour}}; background-color: {{the_tag.bg_colour}}">{{the_tag.name}}</span>
{%- endmacro %}
+
+{% macro vote_meter(poll) %}
+ {% set total_votes = poll.total_votes %}
+ {% set n = namespace() %}
+ {% set n.runningtotal = 0 %}
+ <svg width="100%" height="15px" xmlns="http://www.w3.org/2000/svg">
+ {% if total_votes == 0 %}
+ <text text-anchor="middle" dominant-baseline="middle" x="11%" y="55%" fill="black" style="font-size:15px">no votes</text>
+ {% else %}
+ {% for opt in poll.options %}
+ {% set opt_count = opt.num or 0 %}
+ {% set colour = (loop.count|string + opt.text)|gen_colour %}
+ {% if opt_count != 0 %}
+ {% set percentage = 100*(opt_count/total_votes) %}
+ {# todo: do this in css somehow #}
+ {% if opt.text|length > 10 %}
+ {% set opt_text = opt.text[:7] + "..." %}
+ {% else %}
+ {% set opt_text = opt.text %}
+ {% endif %}
+ <rect y="0" height="100%" x="{{n.runningtotal}}%" width="{{percentage}}%" stroke="black" fill="{{colour}}" />
+ <text text-anchor="middle" dominant-baseline="middle" y="55%" fill="black" style="font-size:15px" x="{{n.runningtotal+(percentage/2)}}%">
+ {{opt_text}}: {{opt_count}}
+ </text>
+ {% set n.runningtotal = n.runningtotal + percentage %}
+ {% endif %}
+ {% endfor %}
+ {% endif %}
+ <desc>
+ poll: {{poll.title}}
+ {% for opt in poll.options %}
+ option "{{opt.text}}": {{opt.num or 0}} votes
+ {% endfor %}
+ total votes: {{total_votes}}
+ </desc>
+ </svg>
+{% endmacro %}