Browse Source

Add secondary range option. Fix #203

pull/222/merge
Florian Mounier 10 years ago
parent
commit
657b0e1337
  1. 1
      CHANGELOG
  2. 4
      demo/moulinrouge/tests.py
  3. 5
      pygal/config.py
  4. 3
      pygal/graph/dot.py
  5. 6
      pygal/graph/graph.py

1
CHANGELOG

@ -8,6 +8,7 @@ V 2.0.0 UNRELEASED
Fix no data for graphs with only zeroes (#148) Fix no data for graphs with only zeroes (#148)
Support value formatter for pie graphs (#218) (thanks never-eat-yellow-snow) Support value formatter for pie graphs (#218) (thanks never-eat-yellow-snow)
Add new Box plot modes and outliers and set extremes as default (#226 #121 #149) (thanks djezar) Add new Box plot modes and outliers and set extremes as default (#226 #121 #149) (thanks djezar)
Add secondary_range option to set range for secondary values. (#203)
V 1.7.0 V 1.7.0
Remove DateY and replace it by real XY datetime, date, time and timedelta support. (#188) Remove DateY and replace it by real XY datetime, date, time and timedelta support. (#188)

4
demo/moulinrouge/tests.py

@ -175,7 +175,7 @@ def get_test_routes(app):
dot = Dot() dot = Dot()
dot.x_labels = map(str, range(4)) dot.x_labels = map(str, range(4))
dot.add('a', [1, lnk(3, 'Foo'), 5, 3]) dot.add('a', [1, lnk(3, 'Foo'), 5, 3])
dot.add('b', [2, 2, 0, 2]) dot.add('b', [2, 2, 0, 2, .1])
dot.add('c', [5, 1, 5, lnk(3, 'Bar')]) dot.add('c', [5, 1, 5, lnk(3, 'Bar')])
dot.add('d', [5, 5, lnk(0, 'Babar'), 3]) dot.add('d', [5, 5, lnk(0, 'Babar'), 3])
@ -582,6 +582,8 @@ def get_test_routes(app):
chart = Line(title=u'Some different points', interpolate='cubic') chart = Line(title=u'Some different points', interpolate='cubic')
chart.add('line', [1000, 2000, 7000]) chart.add('line', [1000, 2000, 7000])
chart.add('other line', [100, 500, 500], secondary=True) chart.add('other line', [100, 500, 500], secondary=True)
chart.range = 0, 10000
chart.secondary_range = 0, 1000
return chart.render_response() return chart.render_response()
@app.route('/test/legend_at_bottom/<chart>') @app.route('/test/legend_at_bottom/<chart>')

5
pygal/config.py

@ -354,6 +354,11 @@ class Config(CommonConfig):
None, list, "Value", "Explicitly specify min and max of values", None, list, "Value", "Explicitly specify min and max of values",
"(ie: (0, 100))", int) "(ie: (0, 100))", int)
secondary_range = Key(
None, list, "Value",
"Explicitly specify min and max of secondary values",
"(ie: (0, 100))", int)
xrange = Key( xrange = Key(
None, list, "Value", "Explicitly specify min and max of x values " None, list, "Value", "Explicitly specify min and max of x values "
"(used in XY and Date charts)", "(used in XY and Date charts)",

3
pygal/graph/dot.py

@ -72,6 +72,7 @@ class Dot(Graph):
def _plot(self): def _plot(self):
r_max = min( r_max = min(
self.view.x(1) - self.view.x(0), self.view.x(1) - self.view.x(0),
(self.view.y(0) or 0) - self.view.y(1)) / (2 * (self._max or 1) * 1.05) (self.view.y(0) or 0) - self.view.y(1)) / (
2 * (self._max or 1) * 1.05)
for serie in self.series: for serie in self.series:
self.dot(serie, r_max) self.dot(serie, r_max)

6
pygal/graph/graph.py

@ -633,7 +633,8 @@ class Graph(BaseGraph):
@cached_property @cached_property
def _secondary_min(self): def _secondary_min(self):
"""Getter for the minimum series value""" """Getter for the minimum series value"""
return (self.range[0] if (self.range and self.range[0] is not None) return (self.secondary_range[0] if (
self.secondary_range and self.secondary_range[0] is not None)
else (min(self._secondary_values) else (min(self._secondary_values)
if self._secondary_values else None)) if self._secondary_values else None))
@ -653,7 +654,8 @@ class Graph(BaseGraph):
@cached_property @cached_property
def _secondary_max(self): def _secondary_max(self):
"""Getter for the maximum series value""" """Getter for the maximum series value"""
return (self.range[1] if (self.range and self.range[1] is not None) return (self.secondary_range[1] if (
self.secondary_range and self.secondary_range[1] is not None)
else (max(self._secondary_values) else (max(self._secondary_values)
if self._secondary_values else None)) if self._secondary_values else None))

Loading…
Cancel
Save