Browse Source

Add test platform moulinrouge

pull/8/head
Florian Mounier 13 years ago
parent
commit
4e192a5f52
  1. 22
      pygal/graph.py
  2. 0
      pygal/util/__init__.py
  3. 1
      pygal/util/boundary.py
  4. 47
      test/moulinrouge/__init__.py
  5. 7
      test/moulinrouge/data.py
  6. 11
      test/moulinrouge/static/css.css
  7. 13
      test/moulinrouge/templates/_layout.jinja2
  8. 5
      test/moulinrouge/templates/index.jinja2
  9. 10
      test/moulinrouge/templates/svgs.jinja2
  10. 8
      test/tests.py

22
pygal/graph.py

@ -99,7 +99,6 @@ class Graph(object):
y_title_font_size = 14
key_font_size = 10
css_inline = False
add_popups = False
top_align = top_font = right_align = right_font = 0
@ -179,7 +178,6 @@ class Graph(object):
self.draw_legend()
self.draw_data()
self.graph.append(self.foreground)
self.render_inline_styles()
return self._burn_compressed()
@ -612,20 +610,6 @@ class Graph(object):
y_offset += self.x_title_font_size + 5
return x_offset, y_offset
def render_inline_styles(self):
"Hard-code the styles into the SVG XML if style sheets are not used."
if not self.css_inline:
# do nothing
return
# styles = self.parse_css()
# for node in xpath.Evaluate('//*[@class]', self.root):
# cl = node.getAttribute('class')
# style = styles[cl]
# if node.hasAttribute('style'):
# style += node.getAttribute('style')
# node.setAttribute('style', style)
def parse_css(self):
"""
Take a .css file (classes only please) and parse it into a dictionary
@ -653,8 +637,8 @@ class Graph(object):
# 'a3': 'http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/',
}
self.root = etree.Element(SVG + "svg", attrib={
'width': str(self.width),
'height': str(self.height),
# 'width': str(self.width),
# 'height': str(self.height),
'viewBox': '0 0 100% 100%',
# '{http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/}'
# 'scriptImplementation': 'Adobe',
@ -675,7 +659,7 @@ class Graph(object):
defs = etree.SubElement(self.root, 'defs')
self.add_defs(defs)
if not hasattr(self, 'style_sheet_href') and not self.css_inline:
if not hasattr(self, 'style_sheet_href'):
self.root.append(etree.Comment(
' include default stylesheet if none specified '))
style = etree.SubElement(defs, 'style', type='text/css')

0
pygal/util.py → pygal/util/__init__.py

1
pygal/util/boundary.py

@ -0,0 +1 @@
# -*- coding: utf-8 -*-

47
test/moulinrouge/__init__.py

@ -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

7
test/moulinrouge/data.py

@ -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]
}

11
test/moulinrouge/static/css.css

@ -0,0 +1,11 @@
html, body, section, figure {
margin: 0;
padding: 0;
}
embed {
width: 375px;
height: 245px;
float: left;
border: 1px solid #ccc;
}

13
test/moulinrouge/templates/_layout.jinja2

@ -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>

5
test/moulinrouge/templates/index.jinja2

@ -0,0 +1,5 @@
{% extends '_layout.jinja2' %}
{% block section %}
<a href="{{ url_for('rotation') }}">Rotations test</a>
{% endblock section %}

10
test/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" />
<figcaption></figcaption>
</figure>
{% endfor %}
{% endblock section %}

8
test/tests.py

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