Browse Source

Add `stack_from_top` option to reverse stack graph data order. Fix #141

pull/146/head
Florian Mounier 11 years ago
parent
commit
8f42442524
  1. 3
      CHANGELOG
  2. 7
      demo/moulinrouge/tests.py
  3. 7
      pygal/config.py
  4. 6
      pygal/graph/stackedbar.py
  5. 6
      pygal/graph/stackedline.py
  6. 9
      pygal/test/test_stacked.py

3
CHANGELOG

@ -1,3 +1,6 @@
V 1.5.1 - UNRELEASED
Add `stack_from_top` option to reverse stack graph data order
V 1.5.0 V 1.5.0
Add per serie configuration Add per serie configuration
Add half pie (thanks philt2001) Add half pie (thanks philt2001)

7
demo/moulinrouge/tests.py

@ -338,6 +338,13 @@ def get_test_routes(app):
stacked.add('2', [4, 5, 6]) stacked.add('2', [4, 5, 6])
return stacked.render_response() return stacked.render_response()
@app.route('/test/stacked/reverse')
def test_stacked_reverse():
stacked = StackedBar(stack_from_top=True)
stacked.add('1', [1, 2, 3])
stacked.add('2', [4, 5, 6])
return stacked.render_response()
@app.route('/test/show_dots') @app.route('/test/show_dots')
def test_show_dots(): def test_show_dots():
line = Line(show_dots=False) line = Line(show_dots=False)

7
pygal/config.py

@ -224,6 +224,13 @@ class Config(CommonConfig):
legend_box_size = Key( legend_box_size = Key(
12, int, "Look", "Size of legend boxes") 12, int, "Look", "Size of legend boxes")
rounded_bars = Key(
None, int, "Look", "Set this to the desired radius in px")
stack_from_top = Key(
False, bool, "Look", "Stack from top to zero, this makes the stacked "
"data match the legend order")
spacing = Key( spacing = Key(
10, int, "Look", 10, int, "Look",
"Space between titles/legend/axes") "Space between titles/legend/axes")

6
pygal/graph/stackedbar.py

@ -128,3 +128,9 @@ class StackedBar(Bar):
class_='rect reactive tooltip-trigger') class_='rect reactive tooltip-trigger')
transpose = swap if self.horizontal else ident transpose = swap if self.horizontal else ident
return transpose((x + width / 2, y + height / 2)) return transpose((x + width / 2, y + height / 2))
def _plot(self):
for serie in self.series[::-1 if self.stack_from_top else 1]:
self.bar(serie)
for serie in self.secondary_series[::-1 if self.stack_from_top else 1]:
self.bar(serie, True)

6
pygal/graph/stackedline.py

@ -54,3 +54,9 @@ class StackedLine(Line):
serie.interpolated = self._interpolate(x_pos, accumulation) serie.interpolated = self._interpolate(x_pos, accumulation)
else: else:
serie.interpolated = [] serie.interpolated = []
def _plot(self):
for serie in self.series[::-1 if self.stack_from_top else 1]:
self.line(serie)
for serie in self.secondary_series[::-1 if self.stack_from_top else 1]:
self.line(serie, True)

9
pygal/test/test_stacked.py

@ -28,6 +28,15 @@ def test_stacked_line():
('1', '2', '11', '14')) ('1', '2', '11', '14'))
def test_stacked_line_reverse():
stacked = StackedLine(stack_from_top=True)
stacked.add('one_two', [1, 2])
stacked.add('ten_twelve', [10, 12])
q = stacked.render_pyquery()
assert set(q("desc.value").text().split(' ')) == set(
('11', '14', '1', '2'))
def test_stacked_line_log(): def test_stacked_line_log():
stacked = StackedLine(logarithmic=True) stacked = StackedLine(logarithmic=True)
stacked.add('one_two', [1, 2]) stacked.add('one_two', [1, 2])

Loading…
Cancel
Save