mirror of https://github.com/Kozea/pygal.git
Florian Mounier
12 years ago
4 changed files with 136 additions and 16 deletions
@ -0,0 +1,92 @@
|
||||
# -*- coding: utf-8 -*- |
||||
# This file is part of pygal |
||||
import pygal |
||||
from pygal import Bar, Gauge, Pyramid, Funnel, Dot |
||||
from pygal.style import styles |
||||
|
||||
|
||||
def get_test_routes(app): |
||||
lnk = lambda v, l=None: {'value': v, 'xlink': 'javascript:alert("Test %s")' % v, 'label': l} |
||||
|
||||
@app.route('/test/unsorted') |
||||
def test_unsorted(): |
||||
bar = Bar(style=styles['neon']) |
||||
bar.add('A', {'red': 10, 'green': 12, 'blue': 14}) |
||||
bar.add('B', {'green': 11, 'blue': 7}) |
||||
bar.add('C', {'blue': 7}) |
||||
bar.add('D', {}) |
||||
bar.add('E', {'blue': 2, 'red': 13}) |
||||
bar.x_labels = ('red', 'green', 'blue') |
||||
return bar.render_response() |
||||
|
||||
@app.route('/test/bar_links') |
||||
def test_bar_links(): |
||||
bar = Bar(style=styles['neon']) |
||||
bar.add('1234', [ |
||||
{'value': 10, |
||||
'label': 'Ten', |
||||
'xlink': 'http://google.com?q=10'}, |
||||
{'value': 20, |
||||
'label': 'Twenty', |
||||
'xlink': 'http://google.com?q=20'}, |
||||
30, |
||||
{'value': 40, |
||||
'label': 'Forty', |
||||
'xlink': 'http://google.com?q=40'} |
||||
]) |
||||
|
||||
bar.add('4321', [40, { |
||||
'value': 30, |
||||
'label': 'Thirty', |
||||
'xlink': 'http://google.com?q=30' |
||||
}, 20, 10]) |
||||
bar.x_labels = map(str, range(1, 5)) |
||||
bar.logarithmic = True |
||||
bar.zero = 1 |
||||
return bar.render_response() |
||||
|
||||
@app.route('/test/gauge') |
||||
def test_gauge(): |
||||
gauge = Gauge() |
||||
|
||||
gauge.range = [-10, 10] |
||||
gauge.add('Need l', [2.3, 5.12]) |
||||
gauge.add('No', [99, -99]) |
||||
return gauge.render_response() |
||||
|
||||
@app.route('/test/gauge') |
||||
def test_pyramid(): |
||||
pyramid = Pyramid() |
||||
|
||||
pyramid.x_labels = ['0-25', '25-45', '45-65', '65+'] |
||||
pyramid.add('Man single', [2, 4, 2, 1]) |
||||
pyramid.add('Woman single', [10, 6, 1, 1]) |
||||
pyramid.add('Man maried', [10, 3, 4, 2]) |
||||
pyramid.add('Woman maried', [3, 3, 5, 3]) |
||||
|
||||
return pyramid.render_response() |
||||
|
||||
@app.route('/test/funnel') |
||||
def test_funnel(): |
||||
funnel = Funnel() |
||||
|
||||
funnel.add('1', [1, 2, 3]) |
||||
funnel.add('3', [3, 4, 5]) |
||||
funnel.add('6', [6, 5, 4]) |
||||
funnel.add('12', [12, 2, 9]) |
||||
|
||||
return funnel.render_response() |
||||
|
||||
@app.route('/test/dot') |
||||
def test_dot(): |
||||
dot = Dot() |
||||
dot.x_labels = map(str, range(4)) |
||||
|
||||
dot.add('a', [1, lnk(3, 'Foo'), 5, 3]) |
||||
dot.add('b', [2, 2, 0, 2]) |
||||
dot.add('c', [5, 1, 5, lnk(3, 'Bar')]) |
||||
dot.add('d', [5, 5, lnk(0, 'Babar'), 3]) |
||||
|
||||
return dot.render_response() |
||||
|
||||
return filter(lambda x: x.startswith('test'), locals()) |
Loading…
Reference in new issue