diff --git a/demo/cabaret/__init__.py b/demo/cabaret/__init__.py index a7d5dcf..91c6613 100644 --- a/demo/cabaret/__init__.py +++ b/demo/cabaret/__init__.py @@ -16,13 +16,14 @@ # # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . -from flask import Flask, render_template, request +from flask import Flask, render_template, request, jsonify from pygal import CHARTS_BY_NAME from pygal.graph import CHARTS_NAMES from pygal.config import CONFIG_ITEMS from pygal.interpolate import KINDS from pygal.style import styles from json import loads +from time import time def create_app(): @@ -50,6 +51,9 @@ def create_app(): chart = CHARTS_BY_NAME[values['type']](**config) for serie in loads(values['vals'])['vals']: chart.add(serie[0], serie[1]) - return chart.render_response() + t = time() + svg = chart.render() + tt = int((time() - t) * 1000) + return jsonify(svg=svg, time=tt) return app diff --git a/demo/cabaret/static/css.css b/demo/cabaret/static/css.css index d938ab3..02d3623 100644 --- a/demo/cabaret/static/css.css +++ b/demo/cabaret/static/css.css @@ -31,3 +31,7 @@ label { font-variant: small-caps; color: #777; } + +.time label { + display: inline; +} diff --git a/demo/cabaret/static/js.js b/demo/cabaret/static/js.js index ed5c006..8201537 100644 --- a/demo/cabaret/static/js.js +++ b/demo/cabaret/static/js.js @@ -22,6 +22,7 @@ function resend() { values = $(this).find('.serie-value').val(); vals.push([label, values.split(',').map(function (v) { return parseFloat(v); })]); }); + var t = new Date().getTime(); $.ajax({ url: '/svg', type: 'POST', @@ -31,11 +32,13 @@ function resend() { vals: JSON.stringify({vals: vals}), opts: JSON.stringify(opts) }, - dataType: 'html', + dataType: 'json', traditional: true }).done(function (data) { + $('.total-time').html('' + (new Date().getTime() - t) + 'ms'); + $('.server-time').html(' ' + data.time + 'ms'); // $fig.find('div').get(0).innerHTML = data; - $fig.find('div').html(data); + $fig.find('div').html(data.svg); init_svg($fig.find('svg').get(0)); $('.nav a').css({color: ''}); }).fail(function () { diff --git a/demo/cabaret/templates/_layout.jinja2 b/demo/cabaret/templates/_layout.jinja2 index 26a8ed6..ca03668 100644 --- a/demo/cabaret/templates/_layout.jinja2 +++ b/demo/cabaret/templates/_layout.jinja2 @@ -20,7 +20,7 @@ - Cabaret + Pygal Cabaret @@ -36,9 +36,19 @@ {% endblock section %} -
+
diff --git a/pygal/graph/line.py b/pygal/graph/line.py index a88a550..d4a706b 100644 --- a/pygal/graph/line.py +++ b/pygal/graph/line.py @@ -43,7 +43,7 @@ class Line(Graph): for serie in self.series for val in (serie.interpolated if self.interpolate else serie.points) - if val[1] is not None] + if val[1] is not None and (not self.logarithmic or val[1] > 0)] def _fill(self, values): """Add extra values to fill the line"""