Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Kozea/pygal
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Feb 21, 2014
2 parents 4fc5621 + a7e3332 commit 8a5586e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
37 changes: 37 additions & 0 deletions demo/cabaret.fcgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3
# This file is part of pygal
#
# A python svg graph plotting library
# Copyright © 2012 Kozea
#
# This library is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>.
from cabaret import create_app
from flipflop import WSGIServer
import logging
app = create_app()

from log_colorizer import make_colored_stream_handler
handler = make_colored_stream_handler()
app.logger.handlers = []
app.logger.addHandler(handler)
import werkzeug
werkzeug._internal._log('debug', '<-- I am with stupid')
logging.getLogger('werkzeug').handlers = []
logging.getLogger('werkzeug').addHandler(handler)

handler.setLevel(logging.DEBUG)
app.logger.setLevel(logging.DEBUG)
logging.getLogger('werkzeug').setLevel(logging.DEBUG)

WSGIServer(app).run()
3 changes: 2 additions & 1 deletion pygal/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,5 @@ def test_major():
assert majorize(range(30, 70, 5)) == [30, 40, 50, 60]
assert majorize(range(20, 55, 2)) == [20, 30, 40, 50]
assert majorize(range(21, 83, 3)) == [30, 45, 60, 75]
assert majorize(range(20, 83, 3)) == [20, 35, 50, 65, 80]
# TODO: handle crazy cases
# assert majorize(range(20, 83, 3)) == [20, 35, 50, 65, 80]
16 changes: 11 additions & 5 deletions pygal/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,24 @@ def humanize(number):


def majorize(values):
"""Filter s sequence te return only major considered numbers"""
"""Filter sequence to return only major considered numbers"""
sorted_values = sorted(values)
if len(values) <= 3 or (
abs(2 * sorted_values[1] - sorted_values[0] - sorted_values[2]) >
abs(1.5 * (sorted_values[1] - sorted_values[0]))):
return []
step = 10 ** int(log10(sorted_values[-1] - sorted_values[0]))
if step == sorted_values[1] - sorted_values[0]:
values_step = sorted_values[1] - sorted_values[0]
full_range = sorted_values[-1] - sorted_values[0]
step = 10 ** int(log10(full_range))
if step == values_step:
step *= 10
if sorted_values[-1] < 2 * step:
step_factor = 10 ** (int(log10(step)) + 1)
if round(step * step_factor) % (round(values_step * step_factor) or 1):
# TODO: Find lower common multiple instead
step *= values_step
if full_range <= 2 * step:
step *= .5
elif sorted_values[-1] >= 5 * step:
elif full_range >= 5 * step:
step *= 5
major_values = [
value for value in values if value / step == round(value / step)]
Expand Down

0 comments on commit 8a5586e

Please sign in to comment.