Permalink
Browse files

added horizontal bar chart tables

  • Loading branch information...
1 parent 86b40f4 commit d4835c9ff6a1ad380713dc35142c1bc6b3ac6cd2 @graingert committed Apr 12, 2012
Showing with 45 additions and 6 deletions.
  1. +27 −3 reviews/models.py
  2. +5 −0 reviews/static/things/style.css
  3. +13 −3 reviews/templates/reviews/thing_list_incl.html
View
@@ -83,7 +83,7 @@ def description(self):
def chart(self):
labels=[]
- count=[]
+ counts=[]
colors=[]
@@ -92,10 +92,34 @@ def chart(self):
labels.append(style["label"])
colors.append(style["color"])
- count.append(getattr(self, "review_%s_count" % str(point)))
+ counts.append(getattr(self, "review_%s_count" % str(point)))
- return unicode(Pie(count,apiurl="https://chart.googleapis.com/chart?").color(*colors).label(*labels))
+ return unicode(Pie(counts,apiurl="https://chart.googleapis.com/chart?").color(*colors).label(*labels))
+ def table(self):
+ points = []
+ total = 0
+ for point in range(SCALE):
+ style = SCORE_MAP[point]
+ count = getattr(self, "review_%s_count" % str(point))
+
+ if count > 0:
+ points.append({
+ "label" : style["label"],
+ "count" : count,
+ "color" : style["color"],
+ })
+
+ total += count
+
+ if total == 0:
+ return points
+
+ for point in points:
+ point["percentage"] = (point["count"]/float(total)) * 100.0
+
+ return points
+
@classmethod
def construct_from_uri(cls, uri):
return thingvalidator.construct_from_uri(uri)
@@ -5,3 +5,8 @@ small {
.thing .uri {
color: grey;
}
+
+.horiz-bar-chart {
+ color: white;
+ width: 100%;
+}
@@ -6,10 +6,20 @@
<a href="{{ thing.uri }}">
<h2 class="name">{{thing}}</h2>
</a>
- {% if thing.review__rating__sum %}
- Total rating = <span class="total">{{thing.review__rating__sum}}</span>
- {% endif %}
</header>
+
+ {% if thing.table %}
+ <table class="horiz-bar-chart">
+ <tr>
+ {% for cell in thing.table %}
+ <td style="background-color:#{{cell.color}};width:{{cell.percentage}}%">
+ {{cell.label}}
+ </td>
+ {% endfor %}
+ </tr>
+ </table>
+ {% endif %}
+
<div class="btn-group">
<a class="btn" href="{{ thing.get_absolute_url }}">View Reviews</a>
<a class="btn btn-primary" href="{% url create-review thing.slug %}">Review</a>

0 comments on commit d4835c9

Please sign in to comment.