Browse Source

Minor fixes

pull/130/head
Florian Mounier 11 years ago
parent
commit
df6619e6f8
  1. 2
      CHANGELOG
  2. 9
      demo/moulinrouge/tests.py
  3. 48
      perf.py
  4. 6
      pygal/ghost.py

2
CHANGELOG

@ -1,8 +1,8 @@
V 1.5.0 UNRELEASED V 1.5.0 UNRELEASED
Add per serie configuration Add per serie configuration
Add half pie (thanks philt2001) Add half pie (thanks philt2001)
Add render_table (WIP)
Make lxml an optionnal dependency (huge speed boost in pypy) Make lxml an optionnal dependency (huge speed boost in pypy)
Add render_table (WIP)
V 1.4.6 V 1.4.6
Add support for \n separated multiline titles (thanks sirlark) Add support for \n separated multiline titles (thanks sirlark)

9
demo/moulinrouge/tests.py

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# This file is part of pygal # This file is part of pygal
from pygal import ( from pygal import (
Bar, Gauge, Pyramid, Funnel, Dot, StackedBar, XY, Bar, Gauge, Pyramid, Funnel, Dot, StackedBar, StackedLine, XY,
CHARTS_BY_NAME, Config, Line, DateY, Worldmap, Histogram, Box, CHARTS_BY_NAME, Config, Line, DateY, Worldmap, Histogram, Box,
FrenchMap_Departments, FrenchMap_Regions, Pie) FrenchMap_Departments, FrenchMap_Regions, Pie)
from pygal.style import styles, Style from pygal.style import styles, Style
@ -241,6 +241,13 @@ def get_test_routes(app):
graph.add('2', [73, -14, 10, None, -58, 32, 91]) graph.add('2', [73, -14, 10, None, -58, 32, 91])
return graph.render_response() return graph.render_response()
@app.route('/test/fill_with_none/')
def test_fill_with_none():
graph = XY(fill=True)
graph.add('1', [(1, 2), (3, 3), (3.5, 5), (5, 1)])
graph.add('2', [(1, 9), (None, 5), (5, 23)])
return graph.render_response()
@app.route('/test/negative/<chart>') @app.route('/test/negative/<chart>')
def test_negative_for(chart): def test_negative_for(chart):
graph = CHARTS_BY_NAME[chart]() graph = CHARTS_BY_NAME[chart]()

48
perf.py

@ -20,12 +20,15 @@
from pygal import CHARTS, CHARTS_BY_NAME from pygal import CHARTS, CHARTS_BY_NAME
from pygal.test import adapt from pygal.test import adapt
from pygal.etree import etree
from random import sample from random import sample
import timeit import timeit
import sys import sys
sizes = (1, 5, 10, 50, 100, 500, 1000)
rands = list(zip( rands = list(zip(
sample(range(1000), 1000), sample(range(1000), 1000),
sample(range(1000), 1000))) sample(range(1000), 1000)))
@ -37,11 +40,21 @@ def perf(chart_name, length, series):
chart.add('s %d' % i, adapt(chart, rands[:length])) chart.add('s %d' % i, adapt(chart, rands[:length]))
return chart return chart
if '--bench' in sys.argv:
bench = True
def prt(s):
pass
def cht(s):
sys.stdout.write(s)
else:
bench = False
def prt(s): def prt(s):
sys.stdout.write(s) sys.stdout.write(s)
sys.stdout.flush() sys.stdout.flush()
def cht(s):
pass
if '--profile' in sys.argv: if '--profile' in sys.argv:
import cProfile import cProfile
@ -57,11 +70,14 @@ if '--mem' in sys.argv:
pid = os.getpid() pid = os.getpid()
process = psutil.Process(pid) process = psutil.Process(pid)
import gc import gc
gc.set_debug(gc.DEBUG_UNCOLLECTABLE | gc.DEBUG_INSTANCES | gc.DEBUG_OBJECTS) gc.set_debug(
gc.DEBUG_UNCOLLECTABLE | gc.DEBUG_INSTANCES | gc.DEBUG_OBJECTS)
def print_mem(): def print_mem():
mem = process.get_memory_info()[0] / _TWO_20 mem = process.get_memory_info()[0] / _TWO_20
f = sys._getframe(1) f = sys._getframe(1)
line = linecache.getline(f.f_code.co_filename, f.f_lineno - 1).replace('\n', '') line = linecache.getline(
f.f_code.co_filename, f.f_lineno - 1).replace('\n', '')
print('%s:%d \t| %.6f \t| %s' % ( print('%s:%d \t| %.6f \t| %s' % (
f.f_code.co_name, f.f_lineno, mem, line)) f.f_code.co_name, f.f_lineno, mem, line))
@ -82,20 +98,42 @@ if '--mem' in sys.argv:
sys.exit(0) sys.exit(0)
charts = CHARTS if '--all' in sys.argv else 'Line', charts = CHARTS if '--all' in sys.argv else 'Line',
for impl in ['lxml', 'etree']:
if impl == 'lxml':
etree.to_lxml()
else:
etree.to_etree()
for chart in charts: for chart in charts:
prt('%s\n' % chart) prt('%s\n' % chart)
prt('s\\l\t1\t10\t100') prt('s\\l\t1\t10\t100')
v = sys.version.split(' ')[0]
if hasattr(sys, 'subversion'):
v += ' ' + sys.subversion[0]
v += ' ' + impl
if len(charts) > 1:
v += ' ' + chart
for series in (1, 10, 100): cht('bench.add("%s", ' % v)
diag = []
for series in sizes:
prt('\n%d\t' % series) prt('\n%d\t' % series)
for length in (1, 10, 100): for length in sizes:
times = [] times = []
if series == length or not bench:
time = timeit.timeit( time = timeit.timeit(
"c.render()", "c.render()",
setup="from __main__ import perf; c = perf('%s', %d, %d)" % ( setup="from __main__ import perf; "
"c = perf('%s', %d, %d)" % (
chart, length, series), chart, length, series),
number=10) number=10)
if series == length:
diag.append(1000 * time)
prt('%d\t' % (1000 * time)) prt('%d\t' % (1000 * time))
cht(repr(diag))
cht(')\n')
prt('\n') prt('\n')

6
pygal/ghost.py

@ -115,7 +115,10 @@ class Ghost(object):
def render_table(self, **kwargs): def render_table(self, **kwargs):
# Import here to avoid lxml import # Import here to avoid lxml import
try:
from pygal.table import Table from pygal.table import Table
except ImportError:
raise ImportError('You must install lxml to use render table')
real_cls, self.cls = self.cls, Table real_cls, self.cls = self.cls, Table
rv = self.make_instance().render(**kwargs) rv = self.make_instance().render(**kwargs)
self.cls = real_cls self.cls = real_cls
@ -128,7 +131,10 @@ class Ghost(object):
def render_in_browser(self): def render_in_browser(self):
"""Render the graph, open it in your browser with black magic""" """Render the graph, open it in your browser with black magic"""
try:
from lxml.html import open_in_browser from lxml.html import open_in_browser
except ImportError:
raise ImportError('You must install lxml to use render in browser')
open_in_browser(self.render_tree(), encoding='utf-8') open_in_browser(self.render_tree(), encoding='utf-8')
def render_response(self): def render_response(self):

Loading…
Cancel
Save