diff --git a/demo/moulinrouge/__init__.py b/demo/moulinrouge/__init__.py index 4d1f644..16c1bae 100644 --- a/demo/moulinrouge/__init__.py +++ b/demo/moulinrouge/__init__.py @@ -21,6 +21,7 @@ from logging import getLogger, INFO, DEBUG import pygal from pygal.config import Config from pygal.util import cut +from pygal.graph import CHARTS_NAMES from pygal.style import styles from base64 import ( urlsafe_b64encode as b64encode, @@ -33,9 +34,9 @@ import pickle def random_label(): chars = string.letters + string.digits + u' àéèçêâäëï' return ''.join( - [random.choice(chars) - for i in range( - random.randrange(4, 30))]) + [random.choice(chars) + for i in range( + random.randrange(4, 30))]) def random_value(min=0, max=15): @@ -72,7 +73,7 @@ def create_app(): values = [( random_value((-max, min)[random.randrange(0, 2)], max), random_value((-max, min)[random.randrange(0, 2)], max)) - for i in range(data)] + for i in range(data)] else: values = [random_value((-max, min)[random.randrange(1, 2)], max) for i in range(data)] @@ -84,7 +85,9 @@ def create_app(): @app.route("/") def index(): - return render_template('index.jinja2', styles=styles, links=links) + return render_template( + 'index.jinja2', styles=styles, + links=links, charts_name=CHARTS_NAMES) @app.route("/svg///") def svg(type, series, config): @@ -179,5 +182,4 @@ def create_app(): svgs=svgs, width=width, height=height) - return app diff --git a/demo/moulinrouge/templates/index.jinja2 b/demo/moulinrouge/templates/index.jinja2 index 8888c97..9b8c700 100644 --- a/demo/moulinrouge/templates/index.jinja2 +++ b/demo/moulinrouge/templates/index.jinja2 @@ -13,7 +13,17 @@

Quick tests

{% for link in links %} -
{{ link.replace('test_', '').replace('_', ' ') | title }}
+ {% if link.endswith('_for') %} +
{{ link.replace('test_', '').replace('_for', '').replace('_', ' ') | title }} + + {% for chart_name in charts_name %} + {{ chart_name | title }} + {% endfor %} + +
+ {% else %} +
{{ link.replace('test_', '').replace('_', ' ') | title }}
+ {% endif %} {% endfor %}
{% endblock section %} diff --git a/demo/moulinrouge/tests.py b/demo/moulinrouge/tests.py index 667ef2a..494dd88 100644 --- a/demo/moulinrouge/tests.py +++ b/demo/moulinrouge/tests.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # This file is part of pygal -import pygal -from pygal import Bar, Gauge, Pyramid, Funnel, Dot +from pygal import Bar, Gauge, Pyramid, Funnel, Dot, CHARTS_BY_NAME from pygal.style import styles @@ -98,4 +97,11 @@ def get_test_routes(app): return dot.render_response() + @app.route('/test/interpolate/') + def test_interpolate_for(chart): + graph = CHARTS_BY_NAME[chart](interpolate='cubic') + graph.add('1', [1, 3, 12, 3, 4]) + graph.add('2', [7, -4, 10, None, 8, 3, 1]) + return graph.render_response() + return filter(lambda x: x.startswith('test'), locals()) diff --git a/pygal/__init__.py b/pygal/__init__.py index 4b28da7..ee19346 100644 --- a/pygal/__init__.py +++ b/pygal/__init__.py @@ -28,11 +28,13 @@ from pygal.ghost import Ghost from pygal.graph import CHARTS_NAMES CHARTS = [] +CHARTS_BY_NAME = {} for NAME in CHARTS_NAMES: _CHART = type(NAME, (Ghost,), {}) CHARTS.append(_CHART) + CHARTS_BY_NAME[NAME] = _CHART setattr(sys.modules[__name__], NAME, _CHART) -__all__ = CHARTS_NAMES + [Config.__name__, 'CHARTS'] +__all__ = CHARTS_NAMES + [Config.__name__, 'CHARTS', 'CHARTS_BY_NAME'] diff --git a/pygal/test/test_config.py b/pygal/test/test_config.py index 7d5073d..869136f 100644 --- a/pygal/test/test_config.py +++ b/pygal/test/test_config.py @@ -144,6 +144,14 @@ def test_logarithmic(): assert len(q(".dots")) == 3 +def test_interpolation(Chart): + chart = Chart(interpolate='cubic') + chart.add('1', [1, 3, 12, 3, 4]) + chart.add('2', [7, -4, 10, None, 8, 3, 1]) + q = chart.render_pyquery() + assert len(q(".legend")) == 2 + + def test_logarithmic_bad_interpolation(): try: import scipy