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
# 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.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

4
demo/cabaret/static/css.css

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

7
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('<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').html(data);
$fig.find('div').html(data.svg);
init_svg($fig.find('svg').get(0));
$('.nav a').css({color: ''});
}).fail(function () {

16
demo/cabaret/templates/_layout.jinja2

@ -20,7 +20,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">Cabaret</a>
<a class="brand" href="#">Pygal Cabaret</a>
</div>
</div>
</div>
@ -36,9 +36,19 @@
{% endblock section %}
</div>
</div>
<hr>
<hr />
<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>
</body>
</html>

2
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"""

Loading…
Cancel
Save