diff --git a/pygal/graph.py b/pygal/graph.py index 5553729..d53037a 100644 --- a/pygal/graph.py +++ b/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') diff --git a/pygal/util.py b/pygal/util/__init__.py similarity index 100% rename from pygal/util.py rename to pygal/util/__init__.py diff --git a/pygal/util/boundary.py b/pygal/util/boundary.py new file mode 100644 index 0000000..40a96af --- /dev/null +++ b/pygal/util/boundary.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/test/moulinrouge/__init__.py b/test/moulinrouge/__init__.py new file mode 100644 index 0000000..1b4deba --- /dev/null +++ b/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[].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 diff --git a/test/moulinrouge/data.py b/test/moulinrouge/data.py new file mode 100644 index 0000000..e0d23f6 --- /dev/null +++ b/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] +} diff --git a/test/moulinrouge/static/css.css b/test/moulinrouge/static/css.css new file mode 100644 index 0000000..3101bd3 --- /dev/null +++ b/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; +} diff --git a/test/moulinrouge/templates/_layout.jinja2 b/test/moulinrouge/templates/_layout.jinja2 new file mode 100644 index 0000000..1e09955 --- /dev/null +++ b/test/moulinrouge/templates/_layout.jinja2 @@ -0,0 +1,13 @@ + + + + Moulin rouge - pygal test platform + + + +
+ {% block section %} + {% endblock section %} +
+ + diff --git a/test/moulinrouge/templates/index.jinja2 b/test/moulinrouge/templates/index.jinja2 new file mode 100644 index 0000000..8d96744 --- /dev/null +++ b/test/moulinrouge/templates/index.jinja2 @@ -0,0 +1,5 @@ +{% extends '_layout.jinja2' %} + +{% block section %} + Rotations test +{% endblock section %} diff --git a/test/moulinrouge/templates/svgs.jinja2 b/test/moulinrouge/templates/svgs.jinja2 new file mode 100644 index 0000000..6175167 --- /dev/null +++ b/test/moulinrouge/templates/svgs.jinja2 @@ -0,0 +1,10 @@ +{% extends '_layout.jinja2' %} + +{% block section %} + {% for svg in svgs %} +
+ +
+
+ {% endfor %} +{% endblock section %} diff --git a/test/tests.py b/test/tests.py new file mode 100755 index 0000000..e70b44d --- /dev/null +++ b/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)