Browse Source

Add multiple charts in moulinrouge

pull/8/head
Florian Mounier 13 years ago
parent
commit
d47694a221
  1. 14
      demo/moulinrouge/__init__.py
  2. 12
      demo/moulinrouge/templates/index.jinja2
  3. 10
      demo/moulinrouge/tests.py
  4. 4
      pygal/__init__.py
  5. 8
      pygal/test/test_config.py

14
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/<type>/<series>/<config>")
def svg(type, series, config):
@ -179,5 +182,4 @@ def create_app():
svgs=svgs,
width=width,
height=height)
return app

12
demo/moulinrouge/templates/index.jinja2

@ -13,7 +13,17 @@
<h3>Quick tests</h3>
<dl>
{% for link in links %}
<dd><a href="{{ url_for(link) }}">{{ link.replace('test_', '').replace('_', ' ') | title }}</a></dd>
{% if link.endswith('_for') %}
<dd>{{ link.replace('test_', '').replace('_for', '').replace('_', ' ') | title }}
<small>
{% for chart_name in charts_name %}
<a href="{{ url_for(link, chart=chart_name) }}">{{ chart_name | title }}</a>
{% endfor %}
</small>
</dd>
{% else %}
<dd><a href="{{ url_for(link) }}">{{ link.replace('test_', '').replace('_', ' ') | title }}</a></dd>
{% endif %}
{% endfor %}
</dl>
{% endblock section %}

10
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/<chart>')
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())

4
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']

8
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

Loading…
Cancel
Save