Browse Source

Add moulin rouge

pull/8/head
Florian Mounier 13 years ago
parent
commit
8c1801d832
  1. 8
      demo/moulinrouge.py
  2. 120
      demo/moulinrouge/__init__.py
  3. 11
      demo/moulinrouge/data.py
  4. 9
      demo/moulinrouge/static/css.css
  5. 24
      demo/moulinrouge/static/js.js
  6. 15
      demo/moulinrouge/templates/_layout.jinja2
  7. 7
      demo/moulinrouge/templates/index.jinja2
  8. 10
      demo/moulinrouge/templates/svgs.jinja2
  9. 3
      pygal/style.py

8
demo/moulinrouge.py

@ -0,0 +1,8 @@
#!/usr/bin/env python
from moulinrouge import create_app
app = create_app()
if __name__ == "__main__":
app.run(debug=True, threaded=True, host='0.0.0.0', port=21112)

120
demo/moulinrouge/__init__.py

@ -0,0 +1,120 @@
# -*- 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, HorizontalBar
from pygal.line import Line
from pygal.bar import Bar
from pygal.config import Config
from pygal.style import styles
# from pygal.pie import Pie
import string
import random
def random_label():
chars = string.letters + string.digits + u' àéèçêâäëï'
return ''.join(
[random.choice(chars)
for i in range(
random.randrange(4, 30))])
def random_value():
return random.randrange(0, 15, 1)
# def generate_vbar(**opts):
# 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(DEBUG)
@app.route("/")
def index():
return render_template('index.jinja2')
@app.route("/all-<type>-<style>.svg")
def all_svg(type, style):
data = random.randrange(1, 10)
config = Config()
config.width = 600
config.height = 400
config.style = styles[style]
config.x_labels = [random_label() for i in range(data)]
if type == 'bar':
g = Bar(config)
# elif type == 'hbar':
# g = HorizontalBar(labels)
# elif type == 'pie':
# series = 1
# g = Pie({'fields': labels})
elif type == 'line':
g = Line(config)
else:
return
for i in range(random.randrange(1, 10)):
values = [random_value() for i in range(data)]
g.add(random_label(), values)
return Response(g.render(), mimetype='image/svg+xml')
@app.route("/all")
def all():
width, height = 600, 400
svgs = [url_for('all_svg', type=type, style=style)
for style in styles
for type in ('bar', 'line')]
return render_template('svgs.jinja2',
svgs=svgs,
width=width,
height=height)
# @app.route("/rotation[<int:angle>].svg")
# def rotation_svg(angle):
# return generate_vbar(
# show_graph_title=True,
# graph_title="Rotation %d" % angle,
# x_label_rotation=angle)
@app.route("/rotation")
def rotation():
width, height = 375, 245
svgs = [url_for('rotation_svg', angle=angle)
for angle in range(0, 91, 5)]
return render_template('svgs.jinja2',
svgs=svgs,
width=width,
height=height)
@app.route("/bigline.svg")
def big_line_svg():
g = Line(600, 400)
g.x_labels = ['a', 'b', 'c', 'd']
g.add('serie', [11, 50, 133, 2])
return Response(g.render(), mimetype='image/svg+xml')
@app.route("/bigline")
def big_line():
width, height = 900, 800
svgs = [url_for('big_line_svg')]
return render_template('svgs.jinja2',
svgs=svgs,
width=width,
height=height)
return app

11
demo/moulinrouge/data.py

@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
labels = ['AURSAUTRAUIA',
'dpvluiqhu enuie',
'su sru a nanan a',
'09_28_3023_98120398',
u'éàé瀮ð{æə|&']
series = {
'Female': [4, 2, 3, 0, 2],
'Male': [5, 1, 1, 3, 2]
}

9
demo/moulinrouge/static/css.css

@ -0,0 +1,9 @@
html, body, section, figure {
margin: 0;
padding: 0;
}
figure {
float: left;
border: 1px solid #ccc;
}

24
demo/moulinrouge/static/js.js

@ -0,0 +1,24 @@
$(function () {
$('figure figcaption').append(
$('<button>')
.text('⟳')
.click(function() {
var $fig, $embed, w, h, src;
$fig = $(this).closest('figure');
$embed = $fig.find('embed');
w = $embed.width();
h = $embed.height();
src = $embed.attr('src');
$embed.remove();
$fig.prepend(
$('<embed>')
.attr({
src: src,
type: 'image/svg+xml',
width: w,
height: h
})
);
})
);
});

15
demo/moulinrouge/templates/_layout.jinja2

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Moulin rouge - pygal test platform</title>
<script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js.js') }}"></script>
<link rel="stylesheet" href="{{ url_for('static', filename='css.css') }}" type="text/css" />
</head>
<body>
<section>
{% block section %}
{% endblock section %}
</section>
</body>
</html>

7
demo/moulinrouge/templates/index.jinja2

@ -0,0 +1,7 @@
{% extends '_layout.jinja2' %}
{% block section %}
<a href="{{ url_for('all') }}">All types</a>
<a href="{{ url_for('rotation') }}">Rotations test</a>
<a href="{{ url_for('big_line') }}">Big line</a>
{% endblock section %}

10
demo/moulinrouge/templates/svgs.jinja2

@ -0,0 +1,10 @@
{% extends '_layout.jinja2' %}
{% block section %}
{% for svg in svgs %}
<figure>
<embed src="{{ svg }}" type="image/svg+xml" width="{{ width }}" height="{{ height }}" />
<figcaption></figcaption>
</figure>
{% endfor %}
{% endblock section %}

3
pygal/style.py

@ -38,4 +38,5 @@ LightStyle = Style(
'#d0d293', '#9aacc3', '#bb77a4',
'#77bbb5', '#777777'))
styles = [DefaultStyle, LightStyle]
styles = {'default': DefaultStyle,
'light': LightStyle}

Loading…
Cancel
Save