Browse Source

Fix label adaptation. Fix #256 Fix wrong radar truncation. Fix #255

pull/264/head 2.0.3
Florian Mounier 9 years ago
parent
commit
755c5ab3ef
  1. 12
      demo/moulinrouge/tests.py
  2. 8
      docs/changelog.rst
  3. 2
      pygal/__init__.py
  4. 10
      pygal/graph/dual.py
  5. 10
      pygal/graph/gauge.py
  6. 10
      pygal/graph/graph.py
  7. 26
      pygal/graph/radar.py
  8. 26
      pygal/test/test_date.py
  9. 17
      pygal/test/test_line.py

12
demo/moulinrouge/tests.py

@ -683,9 +683,15 @@ def get_test_routes(app):
radar = Radar()
for i in range(10):
radar.add(str(i), [i * j for j in range(8)])
radar.x_labels = range(8)
radar.x_label_rotation = 35
radar.y_label_rotation = 35
radar.x_labels = [
'lol',
'rofl',
'mao',
'lolroflmao',
'12345678901234567890'
]
# radar.x_label_rotation = 35
# radar.y_label_rotation = 35
radar.y_labels = [{
'label': '500',
'value': 10

8
docs/changelog.rst

@ -2,6 +2,13 @@
Changelog
=========
2.0.3
=====
* Fix label adaptation. Fix #256
* Fix wrong radar truncation. Fix #255
2.0.2
=====
@ -9,6 +16,7 @@ Changelog
* Fix broken font_family default
* Fix non namespaced svg (without embed) javascript by adding uuid in config object. (config is in window.pygal now).
2.0.1
=====

2
pygal/__init__.py

@ -24,7 +24,7 @@ and the maps extensions namespace module.
"""
__version__ = '2.0.2'
__version__ = '2.0.3'
import pkg_resources
import sys

10
pygal/graph/dual.py

@ -36,14 +36,14 @@ class Dual(Graph):
self._x_labels = []
for i, x_label in enumerate(self.x_labels):
if isinstance(x_label, dict):
pos = float(x_label.get('value'))
title = x_label.get('label', self._format(pos))
pos = self._x_adapt(x_label.get('value'))
title = x_label.get('label', self._x_format(pos))
elif is_str(x_label):
pos = x_pos[i % len(x_pos)]
pos = self._x_adapt(x_pos[i % len(x_pos)])
title = x_label
else:
pos = self._x_adapt(float(x_label))
title = self._x_format(x_label)
pos = self._x_adapt(x_label)
title = self._x_format(pos)
self._x_labels.append((title, pos))
self._box.xmin = min(self._box.xmin, min(cut(self._x_labels, 1)))

10
pygal/graph/gauge.py

@ -153,15 +153,15 @@ class Gauge(Graph):
self._y_labels = []
for i, y_label in enumerate(self.y_labels):
if isinstance(y_label, dict):
pos = float(y_label.get('value'))
pos = self._adapt(y_label.get('value'))
title = y_label.get('label', self._format(pos))
elif is_str(y_label):
pos = y_pos[i]
pos = self._adapt(y_pos[i])
title = y_label
else:
pos = float(y_label)
title = self._format(y_label)
self._y_labels.append((title, self._adapt(pos)))
pos = self._adapt(y_label)
title = self._format(pos)
self._y_labels.append((title, pos))
self.min_ = min(self.min_, min(cut(self._y_labels, 1)))
self.max_ = max(self.max_, max(cut(self._y_labels, 1)))
self._box.set_polar_box(

10
pygal/graph/graph.py

@ -758,15 +758,15 @@ class Graph(PublicApi):
self._y_labels = []
for i, y_label in enumerate(self.y_labels):
if isinstance(y_label, dict):
pos = float(y_label.get('value'))
pos = self._adapt(y_label.get('value'))
title = y_label.get('label', self._format(pos))
elif is_str(y_label):
pos = y_pos[i % len(y_pos)]
pos = self._adapt(y_pos[i % len(y_pos)])
title = y_label
else:
pos = float(y_label)
title = self._format(y_label)
self._y_labels.append((title, self._adapt(pos)))
pos = self._adapt(y_label)
title = self._format(pos)
self._y_labels.append((title, pos))
self._box.ymin = min(self._box.ymin, min(cut(self._y_labels, 1)))
self._box.ymax = max(self._box.ymax, max(cut(self._y_labels, 1)))
else:

26
pygal/graph/radar.py

@ -86,19 +86,9 @@ class Radar(Line):
format_ = lambda x: '%f %f' % x
center = self.view((0, 0))
r = self._rmax
truncation = self.truncate_label
if not truncation:
if self.x_label_rotation or len(self._x_labels) <= 1:
truncation = 25
else:
first_label_position = self.view.x(self._x_labels[0][1]) or 0
last_label_position = self.view.x(self._x_labels[-1][1]) or 0
available_space = (
last_label_position - first_label_position) / (
len(self._x_labels) - 1)
truncation = reverse_text_len(
available_space, self.style.label_font_size)
truncation = max(truncation, 1)
# Can't simply determine truncation
truncation = self.truncate_label or 25
for label, theta in self._x_labels:
major = label in self._x_major_labels
@ -208,15 +198,15 @@ class Radar(Line):
self._y_labels = []
for i, y_label in enumerate(self.y_labels):
if isinstance(y_label, dict):
pos = float(y_label.get('value'))
pos = self._adapt(y_label.get('value'))
title = y_label.get('label', self._format(pos))
elif is_str(y_label):
pos = y_pos[i]
pos = self._adapt(y_pos[i])
title = y_label
else:
pos = float(y_label)
title = self._format(y_label)
self._y_labels.append((title, self._adapt(pos)))
pos = self._adapt(y_label)
title = self._format(pos)
self._y_labels.append((title, pos))
self._rmin = min(self._rmin, min(cut(self._y_labels, 1)))
self._rmax = max(self._rmax, max(cut(self._y_labels, 1)))
self._box.set_polar_box(self._rmin, self._rmax)

26
pygal/test/test_date.py

@ -133,3 +133,29 @@ def test_date_xrange():
'2013-02-04',
'2013-02-16',
'2013-02-27']
def test_date_labels():
"""Test dateline with xrange"""
datey = DateLine(truncate_label=1000)
datey.add('dates', [
(date(2013, 1, 2), 300),
(date(2013, 1, 12), 412),
(date(2013, 2, 2), 823),
(date(2013, 2, 22), 672)
])
datey.x_labels = [
date(2013, 1, 1),
date(2013, 2, 1),
date(2013, 3, 1)
]
q = datey.render_pyquery()
assert list(
map(lambda t: t.split(' ')[0],
q(".axis.x text").map(texts))) == [
'2013-01-01',
'2013-02-01',
'2013-03-01'
]

17
pygal/test/test_line.py

@ -100,8 +100,21 @@ def test_not_equal_x_labels():
q = line.render_pyquery()
assert len(q(".dots")) == 100
assert len(q(".axis.x")) == 1
assert q(".axis.x text").map(texts) == ['0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '10']
assert q(".axis.x text").map(texts) == [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
def test_int_x_labels():
"""Test x_labels"""
line = Line()
line.add('test1', range(100))
line.truncate_label = -1
line.x_labels = list(range(11))
q = line.render_pyquery()
assert len(q(".dots")) == 100
assert len(q(".axis.x")) == 1
assert q(".axis.x text").map(texts) == [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
def test_only_major_dots_every():

Loading…
Cancel
Save