Skip to content

Commit

Permalink
make the graph more flexible with dynamic value.
Browse files Browse the repository at this point in the history
  • Loading branch information
tzangms authored and alex committed Nov 22, 2009
1 parent c93442d commit 06de537
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion django_histograms/templates/histograms/report.html
Expand Up @@ -20,7 +20,7 @@ <h2 style="padding-top: 1em;">{{ label }} ({{ count }})</h2>
{% if day_labels %}
<span class="label">{{ forloop.counter }}</span>
{% endif %}
<span class="count" style="height: {% widthratio num total 1000 %}%">
<span class="count" style="height: {% widthratio num total ratio %}%">
({{ num }})
</span>
</a>
Expand Down
8 changes: 7 additions & 1 deletion django_histograms/utils.py
Expand Up @@ -110,7 +110,13 @@ def get_report(self):
idx = grouper(data[self.attname])
months[idx][1][day_grouper(data[self.attname])] += data["num"]
months[idx][2] += data["num"]

total = sum(o for m in months.itervalues() for o in m[1])
max_num = max(o for m in months.itervalues() for o in m[1])
ratio = total / max_num * 100

return {
"results": months.values(),
"total": sum(o for m in months.itervalues() for o in m[1]),
"total": total,
"ratio": ratio
}

0 comments on commit 06de537

Please sign in to comment.