Skip to content

Commit

Permalink
Fix demo
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Apr 13, 2012
1 parent ee2ed90 commit 9a32037
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 44 deletions.
20 changes: 9 additions & 11 deletions demo/moulinrouge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import pygal
from pygal.config import Config
from pygal.util import cut
from pygal.style import styles, DefaultStyle
from pygal.serie import Serie
from pygal.style import styles
from base64 import (
urlsafe_b64encode as b64encode,
urlsafe_b64decode as b64decode)
Expand Down Expand Up @@ -69,7 +68,7 @@ def _random(data, order):
random_value((-max, min)[random.randrange(0, 2)], max),
random_value((-max, min)[random.randrange(0, 2)], max))
for i in range(data)]
series.append(Serie(random_label(), values, len(series)))
series.append((random_label(), values))
return series

def _random_series(type, data, order):
Expand All @@ -88,7 +87,7 @@ def _random_series(type, data, order):
else:
values = [random_value((-max, min)[random.randrange(1, 2)],
max) for i in range(data)]
series.append(Serie(random_label(), values, len(series)))
series.append((random_label(), values))
return series

@app.route("/")
Expand All @@ -98,7 +97,8 @@ def index():
@app.route("/svg/<type>/<series>/<config>")
def svg(type, series, config):
graph = getattr(pygal, type)(pickle.loads(b64decode(str(config))))
graph.series = pickle.loads(b64decode(str(series)))
for title, values in pickle.loads(b64decode(str(series))):
graph.add(title, values)
return graph.render_response()

@app.route("/all")
Expand All @@ -110,9 +110,9 @@ def all(style='default', interpolate=None):
order = random.randrange(1, 10)
xy_series = _random(data, order)
other_series = []
for serie in xy_series:
for title, values in xy_series:
other_series.append(
Serie(serie.title, cut(serie.values, 1), serie.index))
(title, cut(values, 1)))
xy_series = b64encode(pickle.dumps(xy_series))
other_series = b64encode(pickle.dumps(other_series))
config = Config()
Expand All @@ -124,10 +124,8 @@ def all(style='default', interpolate=None):
config.style = styles[style]
config.x_labels = [random_label() for i in range(data)]
svgs = []
for type in ('Bar', 'Line', 'XY', 'StackedBar',
'StackedLine', 'HorizontalBar',
'HorizontalStackedBar',
'Pie', 'Radar'):
for chart in pygal.CHARTS:
type = chart.__name__
svgs.append({'type': type,
'series': xy_series if type == 'XY' else other_series,
'config': b64encode(pickle.dumps(config))})
Expand Down
65 changes: 38 additions & 27 deletions demo/simple_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>.
import sys

from pygal import *
from pygal.style import *
from math import cos, sin

lnk = lambda v, l=None: {'value': v, 'xlink': 'javascript:alert("Test %s")' % v, 'label': l}

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])

dot.render_to_file('out-dot.svg')


bar = Bar(style=styles['neon'])
bar.add('1234', [
{'value': 10, 'label': 'Ten', 'xlink': 'http://google.com?q=10'},
Expand All @@ -34,11 +46,11 @@
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.included_js = []
bar.external_js = [
'http://localhost:7575/svg.jquery.js',
'http://localhost:7575/pygal.js',
]
# bar.included_js = []
# bar.external_js = [
# 'http://localhost:7575/svg.jquery.js',
# 'http://localhost:7575/pygal.js',
# ]
bar.fill = True
bar.render_to_file('out-bar.svg')

Expand All @@ -53,17 +65,17 @@
hbar.x_labels = map(
lambda x: '%s / %s' % x, zip(map(str, rng), map(str, rng2)))
hbar.title = "Horizontal Bar test"
# hbar.render_to_file('out-horizontalbar.svg')
hbar.render_to_file('out-horizontalbar.svg')

rng = [30, -32, 39, 12]
rng2 = [24, -8, 18, 12]
rng = [30, -32, 39, None, 12, lnk(21, '?')]
rng2 = [24, -8, lnk(18, '!'), 12]
rng3 = [6, 1, -10, 0]
config = Config()
config.x_label_rotation = 35
config.x_labels = map(lambda x: '%s / %s / %s' % x,
zip(map(str, rng),
map(str, rng2),
map(str, rng3)))
# config.x_labels = map(lambda x: '%s / %s / %s' % x,
# zip(map(str, rng),
# map(str, rng2),
# map(str, rng3)))
config.title = "Stacked Bar test"
config.style = NeonStyle

Expand All @@ -72,16 +84,15 @@
stackedbar.add('++++++', rng2)
stackedbar.add('--->', rng3)
stackedbar.add('None', [None, 42, 42])
# stackedbar.render_to_file('out-stackedbar.svg')
stackedbar.render_to_file('out-stackedbar.svg')

config.title = "Horizontal Stacked Bar test"
hstackedbar = HorizontalStackedBar(config)
hstackedbar.add('@@@@@@@', rng)
hstackedbar.add('++++++', rng2)
hstackedbar.add('--->', rng3)

# hstackedbar.render_to_file('out-horizontalstackedbar1.svg')
# hstackedbar.render_to_file('out-horizontalstackedbar2.svg')
hstackedbar.render_to_file('out-horizontalstackedbar.svg')

line = Line(Config(style=NeonStyle,
zero=.0001, fill=True,
Expand Down Expand Up @@ -112,11 +123,11 @@
stackedline = StackedLine(fill=True)
stackedline.add('test1', [1, 3, 2, None, 2, 13, 2, 5, 8])
stackedline.add('test2', [4, 1, 1, 3, 12, 3])
stackedline.add('test3', [9, 3, 2, 10, 8, 2])
stackedline.add('test3', [9, 3, 2, lnk(10, '!'), 8, 2])
stackedline.x_labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
stackedline.title = "Stackedline test"
stackedline.interpolate = "cubic"
# stackedline.render_to_file('out-stackedline.svg')
# stackedline.interpolate = "cubic"
stackedline.render_to_file('out-stackedline.svg')

xy = XY(Config(fill=True, style=NeonStyle, interpolate='cubic'))
xy.add('test1', [(1981, 1), (1999, -4), (2001, 2), (2003, 10), (2012, 8)])
Expand All @@ -125,20 +136,20 @@
# xy.add('test2', [(1980, 0), (1985, 2), (1995, -2), (2005, 4), (2020, -4)])
# (2005, 6), (2010, -6), (2015, 3), (2020, -3), (2025, 0)])
xy.title = "XY test"
# xy.render_to_file('out-xy.svg')
xy.render_to_file('out-xy.svg')

pie = Pie(Config(style=NeonStyle))
pie.add('test', [lnk(11, 'LOL'), {'value': 8, 'label': 'Lol2'}, 21])
pie.add('test', [lnk(11, 'Foo'), {'value': 8, 'label': 'Few'}, 21])
pie.add('test2', [lnk(29), None, 9])
pie.add('test3', [24, 10, 32])
pie.add('test4', [20, lnk(18), 9])
pie.add('test5', [17, 5, 10])
pie.add('test6', [None, None, 10])
pie.included_js = []
pie.external_js = [
'http://localhost:7575/svg.jquery.js',
'http://localhost:7575/pygal.js',
]
# pie.included_js = []
# pie.external_js = [
# 'http://localhost:7575/svg.jquery.js',
# 'http://localhost:7575/pygal.js',
# ]
# pie.add('test', {'value': 11, 'xlink': 'javascript:alert("lol 11")'})
# pie.add('test2', 1)
# pie.add('test3', 5)
Expand All @@ -152,7 +163,7 @@
'black', 'red', 'blue', 'yellow', 'orange', 'green', 'white')
config.interpolate = 'nearest'
radar = Radar(config)
radar.add('test', [1, 4, lnk(1), 5, None, 2, 5])
radar.add('test', [1, 4, lnk(10), 5, None, -2, 5])
radar.add('test2', [10, 2, 0, 5, 1, 9, 4])

radar.title = "Radar test"
Expand Down
22 changes: 16 additions & 6 deletions pygal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,29 @@

__version__ = '0.9.21'

from pygal.config import Config
from pygal.graph.bar import Bar
from pygal.graph.dot import Dot
from pygal.graph.horizontal import HorizontalBar
from pygal.graph.stackedbar import StackedBar
from pygal.graph.horizontal import HorizontalStackedBar
from pygal.graph.line import Line
from pygal.graph.stackedline import StackedLine
from pygal.graph.xy import XY
from pygal.graph.pie import Pie
from pygal.graph.radar import Radar
from pygal.config import Config
from pygal.graph.stackedbar import StackedBar
from pygal.graph.stackedline import StackedLine
from pygal.graph.xy import XY


#: List of all chart types
CHARTS = [
Bar, HorizontalBar, StackedBar, HorizontalStackedBar,
Line, StackedLine, XY, Pie, Radar]
Bar,
Dot,
HorizontalBar,
HorizontalStackedBar,
Line,
Pie,
Radar,
StackedBar,
StackedLine,
XY
]

0 comments on commit 9a32037

Please sign in to comment.