Migrate charts to jqPlot. Needs a bit of clean-up, especially separating out date & non-date reports.

This commit is contained in:
Ross Poulton 2011-05-02 22:32:51 +00:00
parent b42026ec33
commit 9175203fb1
2 changed files with 78 additions and 1 deletions

View File

@ -2,6 +2,16 @@
{% block helpdesk_title %}{% trans "Reports & Statistics" %}{% endblock %} {% block helpdesk_title %}{% trans "Reports & Statistics" %}{% endblock %}
{% block helpdesk_head %}
<!--[if IE]><script language="javascript" type="text/javascript" src="{{ MEDIA_URL }}helpdesk/jquery.jqplot/excanvas.min.js"></script><![endif]-->
<script src='{{ MEDIA_URL }}helpdesk/jquery.jqplot/jquery.jqplot.min.js' type='text/javascript' language='javascript'></script>
<link rel='stylesheet' typ='text/css' href='{{ MEDIA_URL }}helpdesk/jquery.jqplot/jquery.jqplot.min.css' />
<script type="text/javascript" src="{{ MEDIA_URL }}helpdesk/jquery.jqplot/plugins/jqplot.categoryAxisRenderer.min.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}helpdesk/jquery.jqplot/plugins/jqplot.barRenderer.min.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}helpdesk/jquery.jqplot/plugins/jqplot.dateAxisRenderer.min.js"></script>
{% endblock %}
{% block helpdesk_body %} {% block helpdesk_body %}
<h2>{% trans "Reports &amp; Statistics" %}</h2> <h2>{% trans "Reports &amp; Statistics" %}</h2>
@ -12,6 +22,69 @@
<tr class='row_{% cycle odd,even %}'>{% for f in d %}<td>{{ f }}</td>{% endfor %}</tr>{% endfor %} <tr class='row_{% cycle odd,even %}'>{% for f in d %}<td>{{ f }}</td>{% endfor %}</tr>{% endfor %}
</table> </table>
{% if chart %}<img src='{{ chart }}' />{% endif %} <div class='jqPlot' id='placeholder' style='width: 600px; height: 400px;'></div>
{% ifequal charttype "date" %}
<script type='text/javascript'>
$.jqplot.config.enablePlugins = true;
var dataset = [];
{% for d in data %}
dataset[{{ forloop.counter0 }}] = [{% for f in d %}{% if not forloop.first %}['{% for h in headings %}{% ifequal forloop.counter0 forloop.parentloop.counter0 %}{{ h }}{% endifequal %}{% endfor %}', {{ f }}]{% if not forloop.last %}, {% endif %}{% endif %}{% endfor %}];{% endfor %}
plot = $.jqplot('placeholder', dataset, {
legend: {show: true, location: 'nw', xoffset: 55},
title: "{{ title }}",
series: [{% for d in data %}
{
label:'{{ d.0 }}',
lineWidth: 4,
markerOptions: { style: 'square'}
}{% if not forloop.last %},{% endif %}{% endfor %}
],
axes: {
xaxis: {
renderer: $.jqplot.DateAxisRenderer
},
yaxis: {
min: 0
}
}
});
</script>
{% endifequal %}
{% ifequal charttype "bar" %}
<script type='text/javascript'>
$.jqplot.config.enablePlugins = true;
var dataset = [];
{% for d in data %}
dataset[{{ forloop.counter0 }}] = [{% for f in d %}{% if not forloop.first %}{{ f }}{% if not forloop.last %}, {% endif %}{% endif %}{% endfor %}];{% endfor %}
plot = $.jqplot('placeholder', dataset, {
legend: {show: true, location: 'nw', xoffset: 55},
title: "{{ title }}",
seriesDefaults: {
renderer: $.jqplot.BarRenderer,
rendererOptions: {barPadding: 8, barMargin: 20}
},
series: [{% for d in data %}
{label:'{{ d.0 }}'}{% if not forloop.last %},{% endif %}{% endfor %}
],
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks: [{% for h in headings %}{% if not forloop.first %}'{{ h }}'{% if not forloop.last %}, {% endif %}{% endif %}{% endfor %}]
},
yaxis: {
min: 0
}
}
});
</script>
{% endifequal %}
{% endblock %} {% endblock %}

View File

@ -896,10 +896,13 @@ def run_report(request, report):
if report in ('queuemonth', 'usermonth'): if report in ('queuemonth', 'usermonth'):
chart_url = line_chart([columns] + data) chart_url = line_chart([columns] + data)
charttype = 'date'
elif report in ('queuestatus', 'queuepriority', 'userstatus', 'userpriority'): elif report in ('queuestatus', 'queuepriority', 'userstatus', 'userpriority'):
chart_url = bar_chart([columns] + data) chart_url = bar_chart([columns] + data)
charttype = 'bar'
else: else:
chart_url = '' chart_url = ''
charttype = ''
return render_to_response('helpdesk/report_output.html', return render_to_response('helpdesk/report_output.html',
RequestContext(request, { RequestContext(request, {
@ -907,6 +910,7 @@ def run_report(request, report):
'data': data, 'data': data,
'chart': chart_url, 'chart': chart_url,
'title': title, 'title': title,
'charttype': charttype,
})) }))
run_report = staff_member_required(run_report) run_report = staff_member_required(run_report)