Browse Source

Minor fixes

pull/8/head
Florian Mounier 13 years ago
parent
commit
da93aac384
  1. 2
      demo/simple_test.py
  2. 2
      pygal/__init__.py
  3. 2
      pygal/graph/bar.py
  4. 3
      pygal/graph/base.py
  5. 2
      pygal/graph/line.py
  6. 2
      pygal/graph/stackedbar.py
  7. 6
      pygal/graph/xy.py
  8. 2
      pygal/test/test_util.py
  9. 2
      pygal/util.py

2
demo/simple_test.py

@ -23,6 +23,7 @@ from pygal import (
from pygal.style import NeonStyle
from math import cos, sin
bar = Bar()
rng = [-6, -19, 0, -1, 2]
bar.add('test1', rng)
@ -132,3 +133,4 @@ radar.add('test2', [10, 2, 0, 5, 1, 9, 4])
radar.title = "Radar test"
radar.render_to_file('out-radar.svg')

2
pygal/__init__.py

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>.
__version__ = '0.9.15'
__version__ = '0.9.16'
from collections import namedtuple
from pygal.graph.bar import Bar

2
pygal/graph/bar.py

@ -106,7 +106,7 @@ class Bar(Graph):
x_pos = [x / float(x_step) for x in range(x_step + 1)
] if x_step > 1 else [0, 1] # Center if only one value
y_pos = self._pos(self._box.ymin, self._box.ymax, self.y_scale
) if not self.y_labels else map(int, self.y_labels)
) if not self.y_labels else map(float, self.y_labels)
self._x_ranges = zip(x_pos, x_pos[1:])
self._x_labels = self.x_labels and zip(self.x_labels, [

3
pygal/graph/base.py

@ -91,7 +91,7 @@ class BaseGraph(object):
w * sin(rad(self.x_label_rotation)), h)
if self.x_label_rotation:
self.margin.right = max(
.5 * w * cos(rad(self.x_label_rotation)),
w * cos(rad(self.x_label_rotation)),
self.margin.right)
if self._y_labels:
h, w = self._get_texts_box(
@ -137,6 +137,7 @@ class BaseGraph(object):
def _in_browser(self):
from lxml.html import open_in_browser
self._draw()
self.svg.render()
open_in_browser(self.svg.root, encoding='utf-8')
def render_response(self):

2
pygal/graph/line.py

@ -100,7 +100,7 @@ class Line(Graph):
self._box.ymax = max(self._values)
self._y_pos = self._pos(self._box.ymin, self._box.ymax, self.y_scale
) if not self.y_labels else map(int, self.y_labels)
) if not self.y_labels else map(float, self.y_labels)
self._x_labels = self.x_labels and zip(self.x_labels, self._x_pos)
self._y_labels = zip(map(self.format, self._y_pos), self._y_pos)

2
pygal/graph/stackedbar.py

@ -39,7 +39,7 @@ class StackedBar(Bar):
for x in range(self._length + 1)
] if self._length > 1 else [0, 1] # Center if only one value
y_pos = self._pos(self._box.ymin, self._box.ymax, self.y_scale
) if not self.y_labels else map(int, self.y_labels)
) if not self.y_labels else map(float, self.y_labels)
self._x_ranges = zip(x_pos, x_pos[1:])
self._x_labels = self.x_labels and zip(self.x_labels, [

6
pygal/graph/xy.py

@ -18,13 +18,14 @@
# along with pygal. If not, see <http://www.gnu.org/licenses/>.
from pygal.graph.line import Line
from pygal.interpolate import interpolation
from math import isnan
class XY(Line):
"""XY Line graph"""
def _get_value(self, values, i):
return str(values[i])
return 'x=%s, y=%s' % tuple(map(self.format, values[i]))
def _compute(self):
xvals = [val[0]
@ -50,7 +51,8 @@ class XY(Line):
p = float(self.interpolation_precision)
for s in range(int(p + 1)):
x = xmin + r * (s / p)
if serie_xmin <= x <= serie_xmax:
if (serie_xmin <= x <= serie_xmax and not
isnan(float(interpolate(x)))):
serie.interpolated.append((x, float(interpolate(x))))
if self.interpolate:

2
pygal/test/test_util.py

@ -79,6 +79,7 @@ def test_format():
def test_humanize():
assert humanize(1) == '1'
assert humanize(1.) == '1'
assert humanize(10) == '10'
assert humanize(12.5) == '12.5'
assert humanize(1000) == '1k'
@ -100,6 +101,7 @@ def test_humanize():
assert humanize(0.0000000001) == u'100p'
assert humanize(0) == '0'
assert humanize(0.) == '0'
assert humanize(-1337) == '-1.337k'
assert humanize(-.000000042) == '-42n'

2
pygal/util.py

@ -29,7 +29,7 @@ def humanize(number):
order = number and int(floor(log(abs(number)) / log(1000)))
human_readable = ORDERS.split(" ")[int(order > 0)]
if order == 0 or order > len(human_readable):
return str(number)
return float_format(number / float(1000 ** int(order)))
return (
float_format(number / float(1000 ** int(order))) +
human_readable[int(order) - int(order > 0)])

Loading…
Cancel
Save