From cc0ab1339a965c8ba2a61c1bac95621ea269db76 Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Tue, 3 Sep 2013 17:00:44 +0200 Subject: [PATCH] Fix #49 and add a test for it --- pygal/graph/datey.py | 11 +++++++++-- pygal/graph/histogram.py | 1 - pygal/graph/xy.py | 5 +++++ pygal/test/test_config.py | 25 ++++++++++++++++++++++++- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/pygal/graph/datey.py b/pygal/graph/datey.py index e624284..3c7719a 100644 --- a/pygal/graph/datey.py +++ b/pygal/graph/datey.py @@ -89,6 +89,13 @@ class DateY(XY): else: rng = None + if yvals: + ymin = min(yvals) + ymax = max(yvals) + if self.include_x_axis: + ymin = min(ymin or 0, 0) + ymax = max(ymax or 0, 0) + for serie in self.all_series: serie.points = serie.values if self.interpolate and rng: @@ -112,8 +119,8 @@ class DateY(XY): rng = None if rng: - self._box.xmin, self._box.xmax = min(xvals), max(xvals) - self._box.ymin, self._box.ymax = min(yvals), max(yvals) + self._box.xmin, self._box.xmax = xmin, xmax + self._box.ymin, self._box.ymax = ymin, ymax x_pos = compute_scale( self._box.xmin, self._box.xmax, self.logarithmic, self.order_min) diff --git a/pygal/graph/histogram.py b/pygal/graph/histogram.py index 5744b18..eefedad 100644 --- a/pygal/graph/histogram.py +++ b/pygal/graph/histogram.py @@ -31,7 +31,6 @@ class Histogram(Graph): _dual = True _series_margin = 0 - _serie_margin = 0 @cached_property def _values(self): diff --git a/pygal/graph/xy.py b/pygal/graph/xy.py index 490510e..cabce55 100644 --- a/pygal/graph/xy.py +++ b/pygal/graph/xy.py @@ -62,6 +62,11 @@ class XY(Line): if self.yvals: ymin = min(self.yvals) ymax = max(self.yvals) + + if self.include_x_axis: + ymin = min(ymin or 0, 0) + ymax = max(ymax or 0, 0) + yrng = (ymax - ymin) else: yrng = None diff --git a/pygal/test/test_config.py b/pygal/test/test_config.py index f8c7754..a8b83df 100644 --- a/pygal/test/test_config.py +++ b/pygal/test/test_config.py @@ -16,7 +16,8 @@ # # You should have received a copy of the GNU Lesser General Public License # along with pygal. If not, see . -from pygal import Line, Dot, Pie, Radar, Config +from pygal import ( + Line, Dot, Pie, Radar, Config, Bar, Funnel, Worldmap, Histogram, Gauge) from pygal._compat import u from pygal.test.utils import texts from pygal.test import pytest_generate_tests, make_data @@ -254,3 +255,25 @@ def test_no_data(): line.no_data_text = u("þæ®þ怀&ij¿’€") q = line.render_pyquery() assert q(".text-overlay text").text() == u("þæ®þ怀&ij¿’€") + + +def test_include_x_axis(Chart): + chart = Chart() + if Chart in (Pie, Radar, Funnel, Dot, Gauge, Worldmap, Histogram): + return + if not chart.cls._dual: + data = 100, 200, 150 + else: + data = (1, 100), (3, 200), (2, 150) + chart.add('_', data) + q = chart.render_pyquery() + # Ghost thing + yaxis = ".axis.%s .guides text" % ( + 'y' if not chart._last__inst.horizontal else 'x') + if not issubclass(chart.cls, Bar().cls): + assert '0.0' not in q(yaxis).map(texts) + else: + assert '0.0' in q(yaxis).map(texts) + chart.include_x_axis = True + q = chart.render_pyquery() + assert '0.0' in q(yaxis).map(texts)