diff --git a/demo/moulinrouge/tests.py b/demo/moulinrouge/tests.py index c661412..fe3fdde 100644 --- a/demo/moulinrouge/tests.py +++ b/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 diff --git a/docs/changelog.rst b/docs/changelog.rst index 83c6ee7..358a4fc 100644 --- a/docs/changelog.rst +++ b/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 ===== diff --git a/pygal/__init__.py b/pygal/__init__.py index 27d05a4..9dad8d7 100644 --- a/pygal/__init__.py +++ b/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 diff --git a/pygal/graph/dual.py b/pygal/graph/dual.py index e86f675..ecc2f4b 100644 --- a/pygal/graph/dual.py +++ b/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))) diff --git a/pygal/graph/gauge.py b/pygal/graph/gauge.py index c943eb2..b54af9a 100644 --- a/pygal/graph/gauge.py +++ b/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( diff --git a/pygal/graph/graph.py b/pygal/graph/graph.py index cad4b12..6548908 100644 --- a/pygal/graph/graph.py +++ b/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: diff --git a/pygal/graph/radar.py b/pygal/graph/radar.py index 7cfc1ff..a5db4f8 100644 --- a/pygal/graph/radar.py +++ b/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) diff --git a/pygal/test/test_date.py b/pygal/test/test_date.py index 86b3b5e..495e3d0 100644 --- a/pygal/test/test_date.py +++ b/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' + ] diff --git a/pygal/test/test_line.py b/pygal/test/test_line.py index c1d44c4..09b68cc 100644 --- a/pygal/test/test_line.py +++ b/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():