Browse Source

Fix #49 and add a test for it

pull/58/merge
Florian Mounier 12 years ago
parent
commit
cc0ab1339a
  1. 11
      pygal/graph/datey.py
  2. 1
      pygal/graph/histogram.py
  3. 5
      pygal/graph/xy.py
  4. 25
      pygal/test/test_config.py

11
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)

1
pygal/graph/histogram.py

@ -31,7 +31,6 @@ class Histogram(Graph):
_dual = True
_series_margin = 0
_serie_margin = 0
@cached_property
def _values(self):

5
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

25
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 <http://www.gnu.org/licenses/>.
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)

Loading…
Cancel
Save