mirror of https://github.com/Kozea/pygal.git
Florian Mounier
13 years ago
10 changed files with 105 additions and 19 deletions
@ -0,0 +1,47 @@
|
||||
# -*- coding: utf-8 -*- |
||||
from flask import Flask, Response, render_template, url_for |
||||
from log_colorizer import make_colored_stream_handler |
||||
from logging import getLogger, INFO, WARN, DEBUG |
||||
from moulinrouge.data import labels, series |
||||
from pygal.bar import VerticalBar |
||||
|
||||
|
||||
def generate_vbar(**opts): |
||||
opts.setdefault('width', 375) |
||||
opts.setdefault('height', 245) |
||||
|
||||
g = VerticalBar(labels, opts) |
||||
for serie, values in series.items(): |
||||
g.add_data({'data': values, 'title': serie}) |
||||
|
||||
return Response(g.burn(), mimetype='image/svg+xml') |
||||
|
||||
|
||||
def create_app(): |
||||
"""Creates the pygal test web app""" |
||||
|
||||
app = Flask(__name__) |
||||
handler = make_colored_stream_handler() |
||||
getLogger('werkzeug').addHandler(handler) |
||||
getLogger('werkzeug').setLevel(INFO) |
||||
getLogger('pygal').addHandler(handler) |
||||
getLogger('pygal').setLevel(INFO) |
||||
|
||||
@app.route("/") |
||||
def index(): |
||||
return render_template('index.jinja2') |
||||
|
||||
@app.route("/rotation[<int:angle>].svg") |
||||
def rotation_svg(angle): |
||||
return generate_vbar( |
||||
title="Rotation %d" % angle, |
||||
x_label_rotation=angle, |
||||
key_position='bottom') |
||||
|
||||
@app.route("/rotation") |
||||
def rotation(): |
||||
svgs = [url_for('rotation_svg', angle=angle) |
||||
for angle in range(0, 180, 10)] |
||||
return render_template('svgs.jinja2', svgs=svgs) |
||||
|
||||
return app |
@ -0,0 +1,7 @@
|
||||
# -*- coding: utf-8 -*- |
||||
|
||||
labels = ['Internet', 'TV', 'Newspaper', 'Magazine', 'Radio'] |
||||
series = { |
||||
'Female': [4, 2, 3, 0, 2], |
||||
'Male': [5, 1, 1, 3, 2] |
||||
} |
@ -0,0 +1,11 @@
|
||||
html, body, section, figure { |
||||
margin: 0; |
||||
padding: 0; |
||||
} |
||||
|
||||
embed { |
||||
width: 375px; |
||||
height: 245px; |
||||
float: left; |
||||
border: 1px solid #ccc; |
||||
} |
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html> |
||||
<html> |
||||
<head> |
||||
<title>Moulin rouge - pygal test platform</title> |
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css.css') }}" type="text/css" /> |
||||
</head> |
||||
<body> |
||||
<section> |
||||
{% block section %} |
||||
{% endblock section %} |
||||
</section> |
||||
</body> |
||||
</html> |
@ -0,0 +1,5 @@
|
||||
{% extends '_layout.jinja2' %} |
||||
|
||||
{% block section %} |
||||
<a href="{{ url_for('rotation') }}">Rotations test</a> |
||||
{% endblock section %} |
@ -0,0 +1,10 @@
|
||||
{% extends '_layout.jinja2' %} |
||||
|
||||
{% block section %} |
||||
{% for svg in svgs %} |
||||
<figure> |
||||
<embed src="{{ svg }}" type="image/svg+xml" /> |
||||
<figcaption></figcaption> |
||||
</figure> |
||||
{% endfor %} |
||||
{% endblock section %} |
Loading…
Reference in new issue