From 43459025bcac72318e4ef8a32c2d4455321bc191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Sat, 14 Sep 2013 23:05:07 +0200 Subject: Draw pies using highcharts JS-lib --- static/css/style.css | 21 +++++++++++-------- static/js/kosten.js | 47 ++++++++++++++++++++++++++++++++++++++++++- static/js/kosten.ls | 25 +++++++++++++++++++++++ templates/expenses/show.jinja | 12 +++++++---- templates/layout.jinja | 14 ++++++------- 5 files changed, 99 insertions(+), 20 deletions(-) diff --git a/static/css/style.css b/static/css/style.css index 64c612d..a79308e 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -112,6 +112,19 @@ ul.arrow { color: #E15418; } +div.pie { + display: inline-block; + width: 370px; + height: 250px; +} + +div.month_exp { + display: inline-block; + width: 270px; + vertical-align: top; + margin-bottom: 10px; +} + /* Header */ #header { @@ -277,14 +290,6 @@ ul.arrow { overflow: auto; } -/* Table of contents */ - -ul#toc { -} - -.tocLink { -} - /* Footer */ #footer-wrap { } diff --git a/static/js/kosten.js b/static/js/kosten.js index c1df1ca..279f351 100644 --- a/static/js/kosten.js +++ b/static/js/kosten.js @@ -29,7 +29,52 @@ } return $(this).nextAll('.details:first').toggle(); }); - return $('.details').hide(); + $('.details').hide(); + return $('.pie').each(function(){ + var x$, k, v; + x$ = $(this); + x$.highcharts({ + title: { + text: null + }, + tooltip: { + hideDelay: 200, + formatter: function(){ + return this.key + ": " + this.y.toFixed(2) + " € / " + this.percentage.toFixed(2) + "%"; + } + }, + chart: { + backgroundColor: null, + plotBorderWidth: null, + plotShadow: false, + margin: [0, 0, 0, 0] + }, + credits: { + enabled: false + }, + series: [{ + type: 'pie', + size: '50%', + allowPointSelect: true, + dataLabels: { + color: x$.css('color') + }, + data: (function(){ + var ref$, results$ = []; + for (k in ref$ = x$.data('pie')) { + v = ref$[k]; + results$.push({ + name: v > 0 ? k : '', + y: v, + visible: v > 0 + }); + } + return results$; + }()) + }] + }); + return x$; + }); }); out$.catsJS = catsJS = jq(function(){ var counter, add_img, new_input, new_image; diff --git a/static/js/kosten.ls b/static/js/kosten.ls index 8bf746d..fa96f4a 100644 --- a/static/js/kosten.ls +++ b/static/js/kosten.ls @@ -24,6 +24,31 @@ export showJS = jq -> $ \.details .hide! + # draw the pies + <- $ \.pie .each + $ @ + ..highcharts do + title: text: null + tooltip: + hideDelay: 200 + formatter: -> + "#{@key}: #{@y.toFixed 2} € / #{@percentage.toFixed 2}%" + chart: + backgroundColor: null + plotBorderWidth: null + plotShadow: off + margin: [0,0,0,0] + credits: enabled: false + series: [ + type: \pie + size: \50% + allowPointSelect: true + dataLabels: + color: ..css \color + data: [ {name: if v>0 then k else '' , y: v, visible: v > 0} \ + for k,v of ..data \pie ] + ] + # Categories export catsJS = jq -> counter = 0 diff --git a/templates/expenses/show.jinja b/templates/expenses/show.jinja index 4b6e362..395d1e5 100644 --- a/templates/expenses/show.jinja +++ b/templates/expenses/show.jinja @@ -3,6 +3,11 @@ {% set JSFunction = "showJS" %} +{% block js %} + {{ super() }} + +{% endblock %} + {% block heading %} {% if exps | length > 1 %} Aktuelle Kosten @@ -14,8 +19,8 @@ {% block content %} {% for e, p in zip(exps,pies) %} {% if exps | length > 1 %}

{{e|date}}

{% endif %} -
-
+
+
{% for c in e.catexps | sort(attribute="cat.name") %} {% call(exp) detail(name=c.cat.name, sum=c.expense, set=c.all) %} {{exp.day}}.{{exp.month}}. -- {{exp.description}}: {{exp.expense | eur }} @@ -30,8 +35,7 @@ {{exp.day}}.{{exp.month}}. -- {{exp.description}}: {{exp.expense | eur}} {% endcall %}
-
-
+
{% endfor %} diff --git a/templates/layout.jinja b/templates/layout.jinja index ee082f9..aa923d6 100644 --- a/templates/layout.jinja +++ b/templates/layout.jinja @@ -2,13 +2,6 @@ - {% if not g.is_mobile %} - {% block js %} - - - {% if JSFunction %} {% endif %} - {% endblock %} - {% endif %} {{ title or "Kostenverwaltung" }} {% block style %} @@ -54,5 +47,12 @@

{% endblock %}
+ {% if not g.is_mobile %} + {% block js %} + + + {% endblock %} + {% if JSFunction %} {% endif %} + {% endif %} -- cgit v1.2.3