Browse Source

* Fix range option for some Charts (Fix #297 Fix #298)

pull/307/head
Florian Mounier 9 years ago
parent
commit
7430ac7b0b
  1. 7
      demo/moulinrouge/tests.py
  2. 2
      docs/changelog.rst
  3. 6
      pygal/graph/funnel.py
  4. 6
      pygal/graph/histogram.py
  5. 14
      pygal/graph/pyramid.py
  6. 6
      pygal/graph/stackedbar.py
  7. 17
      pygal/test/test_config.py
  8. 6
      pygal/view.py

7
demo/moulinrouge/tests.py

@ -354,6 +354,13 @@ def get_test_routes(app):
graph.add('2', [73, -14, 10, None, -58, 32, 91]) graph.add('2', [73, -14, 10, None, -58, 32, 91])
return graph.render_response() return graph.render_response()
@app.route('/test/range/<chart>')
def test_range_for(chart):
graph = CHARTS_BY_NAME[chart]()
graph.range = [0, 100]
graph.add('1', [1, 2, 10])
return graph.render_response()
@app.route('/test/fill_with_none/') @app.route('/test/fill_with_none/')
def test_fill_with_none(): def test_fill_with_none():
graph = XY(fill=True) graph = XY(fill=True)

2
docs/changelog.rst

@ -10,6 +10,8 @@ Changelog
* Add horizontal line charts (thanks @chartique #301) * Add horizontal line charts (thanks @chartique #301)
* There is now a `formatter` config option to format values as specified. The formatter callable may or may not take `chart`, `serie` and `index` as argument. The default value formatting is now chart dependent and is value_formatter for most graph but could be a combination of value_formatter and x_value_formatter for dual charts. * There is now a `formatter` config option to format values as specified. The formatter callable may or may not take `chart`, `serie` and `index` as argument. The default value formatting is now chart dependent and is value_formatter for most graph but could be a combination of value_formatter and x_value_formatter for dual charts.
* The `human_readable` option has been removed. Now you have to use the pygal.formatters.human_readable formatter (value_formatter=human_readable instead of human_readable=True) * The `human_readable` option has been removed. Now you have to use the pygal.formatters.human_readable formatter (value_formatter=human_readable instead of human_readable=True)
* New chart type: SolidGauge (thanks @chartique #295)
* Fix range option for some Charts (#297 #298)
2.1.1 2.1.1
===== =====

6
pygal/graph/funnel.py

@ -90,6 +90,12 @@ class Funnel(Graph):
self._box.ymin = -val_max self._box.ymin = -val_max
self._box.ymax = val_max self._box.ymax = val_max
if self.range and self.range[0] is not None:
self._box.ymin = self.range[0]
if self.range and self.range[1] is not None:
self._box.ymax = self.range[1]
def _compute_x_labels(self): def _compute_x_labels(self):
self._x_labels = list( self._x_labels = list(
zip(self.x_labels and zip(self.x_labels and

6
pygal/graph/histogram.py

@ -125,3 +125,9 @@ class Histogram(Dual, Bar):
self._box.xmin, self._box.xmax = xmin, xmax self._box.xmin, self._box.xmax = xmin, xmax
if yrng: if yrng:
self._box.ymin, self._box.ymax = ymin, ymax self._box.ymin, self._box.ymax = ymin, ymax
if self.range and self.range[0] is not None:
self._box.ymin = self.range[0]
if self.range and self.range[1] is not None:
self._box.ymax = self.range[1]

14
pygal/graph/pyramid.py

@ -54,9 +54,19 @@ class VerticalPyramid(StackedBar):
def _compute_box(self, positive_vals, negative_vals): def _compute_box(self, positive_vals, negative_vals):
"""Compute Y min and max""" """Compute Y min and max"""
self._box.ymax = max(max(positive_vals or [self.zero]), max_ = max(
max(positive_vals or [self.zero]),
max(negative_vals or [self.zero])) max(negative_vals or [self.zero]))
self._box.ymin = - self._box.ymax
if self.range and self.range[0] is not None:
self._box.ymin = self.range[0]
else:
self._box.ymin = - max_
if self.range and self.range[1] is not None:
self._box.ymax = self.range[1]
else:
self._box.ymax = max_
def _pre_compute_secondary(self, positive_vals, negative_vals): def _pre_compute_secondary(self, positive_vals, negative_vals):
"""Compute secondary y min and max""" """Compute secondary y min and max"""

6
pygal/graph/stackedbar.py

@ -50,8 +50,14 @@ class StackedBar(Bar):
def _compute_box(self, positive_vals, negative_vals): def _compute_box(self, positive_vals, negative_vals):
"""Compute Y min and max""" """Compute Y min and max"""
if self.range and self.range[0] is not None:
self._box.ymin = self.range[0]
else:
self._box.ymin = negative_vals and min( self._box.ymin = negative_vals and min(
min(negative_vals), self.zero) or self.zero min(negative_vals), self.zero) or self.zero
if self.range and self.range[1] is not None:
self._box.ymax = self.range[1]
else:
self._box.ymax = positive_vals and max( self._box.ymax = positive_vals and max(
max(positive_vals), self.zero) or self.zero max(positive_vals), self.zero) or self.zero

17
pygal/test/test_config.py

@ -390,6 +390,23 @@ def test_x_y_title(Chart):
assert len(q('.titles .title')) == 3 assert len(q('.titles .title')) == 3
def test_range(Chart):
"""Test y label major option"""
if Chart in (
Pie, Treemap, Dot, SolidGauge
) or issubclass(Chart, BaseMap):
return
chart = Chart()
chart.range = (0, 100)
chart.add('', [1, 2, 10])
q = chart.render_pyquery()
axis = map(str, range(0, 101, 10))
if Chart == Radar:
axis = map(str, range(100, -1, -20))
z = 'x' if getattr(chart, 'horizontal', False) or Chart == Gauge else 'y'
assert [t.text for t in q('.axis.%s .guides text' % z)] == list(axis)
def test_x_label_major(Chart): def test_x_label_major(Chart):
"""Test x label major option""" """Test x label major option"""
if Chart in ( if Chart in (

6
pygal/view.py

@ -79,7 +79,7 @@ class Box(object):
@xmin.setter @xmin.setter
def xmin(self, value): def xmin(self, value):
"""X minimum setter""" """X minimum setter"""
if value: if value is not None:
self._xmin = value self._xmin = value
@property @property
@ -90,7 +90,7 @@ class Box(object):
@ymin.setter @ymin.setter
def ymin(self, value): def ymin(self, value):
"""Y minimum setter""" """Y minimum setter"""
if value: if value is not None:
self._ymin = value self._ymin = value
@property @property
@ -101,7 +101,7 @@ class Box(object):
@xmax.setter @xmax.setter
def xmax(self, value): def xmax(self, value):
"""X maximum setter""" """X maximum setter"""
if value: if value is not None:
self._xmax = value self._xmax = value
@property @property

Loading…
Cancel
Save