Skip to content

Commit

Permalink
Add stack_from_top option to reverse stack graph data order. Fix Ko…
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Aug 18, 2014
1 parent 78dd5b3 commit 8f42442
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
V 1.5.1 - UNRELEASED
Add `stack_from_top` option to reverse stack graph data order

V 1.5.0
Add per serie configuration
Add half pie (thanks philt2001)
Expand Down
7 changes: 7 additions & 0 deletions demo/moulinrouge/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ def test_stacked():
stacked.add('2', [4, 5, 6])
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')
def test_show_dots():
line = Line(show_dots=False)
Expand Down
7 changes: 7 additions & 0 deletions pygal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ class Config(CommonConfig):
legend_box_size = Key(
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(
10, int, "Look",
"Space between titles/legend/axes")
Expand Down
6 changes: 6 additions & 0 deletions pygal/graph/stackedbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,9 @@ def _bar(self, serie, parent, x, y, i, zero, secondary=False):
class_='rect reactive tooltip-trigger')
transpose = swap if self.horizontal else ident
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 changes: 6 additions & 0 deletions pygal/graph/stackedline.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ def _points(self, x_pos):
serie.interpolated = self._interpolate(x_pos, accumulation)
else:
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 changes: 9 additions & 0 deletions pygal/test/test_stacked.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ def test_stacked_line():
('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():
stacked = StackedLine(logarithmic=True)
stacked.add('one_two', [1, 2])
Expand Down

0 comments on commit 8f42442

Please sign in to comment.