Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Jun 12, 2014
1 parent 08e44d2 commit df6619e
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
V 1.5.0 UNRELEASED
Add per serie configuration
Add half pie (thanks philt2001)
Add render_table (WIP)
Make lxml an optionnal dependency (huge speed boost in pypy)
Add render_table (WIP)

V 1.4.6
Add support for \n separated multiline titles (thanks sirlark)
Expand Down
9 changes: 8 additions & 1 deletion demo/moulinrouge/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# This file is part of pygal
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,
FrenchMap_Departments, FrenchMap_Regions, Pie)
from pygal.style import styles, Style
Expand Down Expand Up @@ -241,6 +241,13 @@ def test_zero_at_34_for(chart, zero=34):
graph.add('2', [73, -14, 10, None, -58, 32, 91])
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>')
def test_negative_for(chart):
graph = CHARTS_BY_NAME[chart]()
Expand Down
78 changes: 58 additions & 20 deletions perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@

from pygal import CHARTS, CHARTS_BY_NAME
from pygal.test import adapt
from pygal.etree import etree
from random import sample

import timeit
import sys


sizes = (1, 5, 10, 50, 100, 500, 1000)

rands = list(zip(
sample(range(1000), 1000),
sample(range(1000), 1000)))
Expand All @@ -37,11 +40,21 @@ def perf(chart_name, length, series):
chart.add('s %d' % i, adapt(chart, rands[:length]))
return chart

if '--bench' in sys.argv:
bench = True
def prt(s):
pass

def prt(s):
sys.stdout.write(s)
sys.stdout.flush()
def cht(s):
sys.stdout.write(s)
else:
bench = False
def prt(s):
sys.stdout.write(s)
sys.stdout.flush()

def cht(s):
pass

if '--profile' in sys.argv:
import cProfile
Expand All @@ -57,11 +70,14 @@ def prt(s):
pid = os.getpid()
process = psutil.Process(pid)
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():
mem = process.get_memory_info()[0] / _TWO_20
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' % (
f.f_code.co_name, f.f_lineno, mem, line))

Expand All @@ -82,20 +98,42 @@ def print_mem():

sys.exit(0)


charts = CHARTS if '--all' in sys.argv else 'Line',

for chart in charts:
prt('%s\n' % chart)
prt('s\\l\t1\t10\t100')

for series in (1, 10, 100):
prt('\n%d\t' % series)
for length in (1, 10, 100):
times = []
time = timeit.timeit(
"c.render()",
setup="from __main__ import perf; c = perf('%s', %d, %d)" % (
chart, length, series),
number=10)
prt('%d\t' % (1000 * time))
prt('\n')
for impl in ['lxml', 'etree']:
if impl == 'lxml':
etree.to_lxml()
else:
etree.to_etree()

for chart in charts:
prt('%s\n' % chart)
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

cht('bench.add("%s", ' % v)
diag = []
for series in sizes:
prt('\n%d\t' % series)
for length in sizes:
times = []
if series == length or not bench:
time = timeit.timeit(
"c.render()",
setup="from __main__ import perf; "
"c = perf('%s', %d, %d)" % (
chart, length, series),
number=10)
if series == length:
diag.append(1000 * time)
prt('%d\t' % (1000 * time))
cht(repr(diag))
cht(')\n')
prt('\n')
10 changes: 8 additions & 2 deletions pygal/ghost.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ def render_tree(self):

def render_table(self, **kwargs):
# Import here to avoid lxml import
from pygal.table import Table
try:
from pygal.table import Table
except ImportError:
raise ImportError('You must install lxml to use render table')
real_cls, self.cls = self.cls, Table
rv = self.make_instance().render(**kwargs)
self.cls = real_cls
Expand All @@ -128,7 +131,10 @@ def render_pyquery(self):

def render_in_browser(self):
"""Render the graph, open it in your browser with black magic"""
from lxml.html import open_in_browser
try:
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')

def render_response(self):
Expand Down

0 comments on commit df6619e

Please sign in to comment.