Browse Source

Add time

pull/8/head
Florian Mounier 12 years ago
parent
commit
1b6792cd05
  1. 8
      demo/cabaret/__init__.py
  2. 4
      demo/cabaret/static/css.css
  3. 7
      demo/cabaret/static/js.js
  4. 16
      demo/cabaret/templates/_layout.jinja2
  5. 2
      pygal/graph/line.py

8
demo/cabaret/__init__.py

@ -16,13 +16,14 @@
# #
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>. # along with pygal. If not, see <http://www.gnu.org/licenses/>.
from flask import Flask, render_template, request from flask import Flask, render_template, request, jsonify
from pygal import CHARTS_BY_NAME from pygal import CHARTS_BY_NAME
from pygal.graph import CHARTS_NAMES from pygal.graph import CHARTS_NAMES
from pygal.config import CONFIG_ITEMS from pygal.config import CONFIG_ITEMS
from pygal.interpolate import KINDS from pygal.interpolate import KINDS
from pygal.style import styles from pygal.style import styles
from json import loads from json import loads
from time import time
def create_app(): def create_app():
@ -50,6 +51,9 @@ def create_app():
chart = CHARTS_BY_NAME[values['type']](**config) chart = CHARTS_BY_NAME[values['type']](**config)
for serie in loads(values['vals'])['vals']: for serie in loads(values['vals'])['vals']:
chart.add(serie[0], serie[1]) 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 return app

4
demo/cabaret/static/css.css

@ -31,3 +31,7 @@ label {
font-variant: small-caps; font-variant: small-caps;
color: #777; color: #777;
} }
.time label {
display: inline;
}

7
demo/cabaret/static/js.js

@ -22,6 +22,7 @@ function resend() {
values = $(this).find('.serie-value').val(); values = $(this).find('.serie-value').val();
vals.push([label, values.split(',').map(function (v) { return parseFloat(v); })]); vals.push([label, values.split(',').map(function (v) { return parseFloat(v); })]);
}); });
var t = new Date().getTime();
$.ajax({ $.ajax({
url: '/svg', url: '/svg',
type: 'POST', type: 'POST',
@ -31,11 +32,13 @@ function resend() {
vals: JSON.stringify({vals: vals}), vals: JSON.stringify({vals: vals}),
opts: JSON.stringify(opts) opts: JSON.stringify(opts)
}, },
dataType: 'html', dataType: 'json',
traditional: true traditional: true
}).done(function (data) { }).done(function (data) {
$('.total-time').html('<label>Total time: </label>' + (new Date().getTime() - t) + 'ms');
$('.server-time').html('<label>Generation time:</label> ' + data.time + 'ms');
// $fig.find('div').get(0).innerHTML = data; // $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)); init_svg($fig.find('svg').get(0));
$('.nav a').css({color: ''}); $('.nav a').css({color: ''});
}).fail(function () { }).fail(function () {

16
demo/cabaret/templates/_layout.jinja2

@ -20,7 +20,7 @@
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</a> </a>
<a class="brand" href="#">Cabaret</a> <a class="brand" href="#">Pygal Cabaret</a>
</div> </div>
</div> </div>
</div> </div>
@ -36,9 +36,19 @@
{% endblock section %} {% endblock section %}
</div> </div>
</div> </div>
<hr> <hr />
<footer> <footer>
<p>&copy; Kozea 2012</p> <div class="container-fluid">
<div class="row-fluid">
<div class="span4">
<p class="time total-time"></p>
</div>
<div class="span4" style="text-align: center">
<p class="time server-time"></p>
</div>
<div class="span4" style="text-align: right">
<p class="pull-right">&copy; <a href="http://kozea.fr/">Kozea 2012</a></p>
</div>
</footer> </footer>
</body> </body>
</html> </html>

2
pygal/graph/line.py

@ -43,7 +43,7 @@ class Line(Graph):
for serie in self.series for serie in self.series
for val in (serie.interpolated for val in (serie.interpolated
if self.interpolate else serie.points) 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): def _fill(self, values):
"""Add extra values to fill the line""" """Add extra values to fill the line"""

Loading…
Cancel
Save