diff --git a/demo/moulinrouge/tests.py b/demo/moulinrouge/tests.py index 56a52eb..87cdb50 100644 --- a/demo/moulinrouge/tests.py +++ b/demo/moulinrouge/tests.py @@ -511,9 +511,10 @@ def get_test_routes(app): @app.route('/test/half_pie') def test_half_pie(): pie = Pie(half_pie=True) - for i in range(10): + for i in range(100): pie.add(str(i), i, inner_radius=.1) - + pie.legend_at_bottom = True + pie.legend_at_bottom_columns = 4 return pie.render_response() @app.route('/test/legend_at_bottom/') diff --git a/pygal/config.py b/pygal/config.py index 6b5cbf3..2de0aa4 100644 --- a/pygal/config.py +++ b/pygal/config.py @@ -221,6 +221,9 @@ class Config(CommonConfig): legend_at_bottom = Key( False, bool, "Look", "Set to true to position legend at bottom") + legend_at_bottom_columns = Key( + None, int, "Look", "Set to true to position legend at bottom") + legend_box_size = Key( 12, int, "Look", "Size of legend boxes") diff --git a/pygal/graph/base.py b/pygal/graph/base.py index 12659ef..ff5ac22 100644 --- a/pygal/graph/base.py +++ b/pygal/graph/base.py @@ -27,7 +27,7 @@ from pygal.util import ( get_text_box, get_texts_box, cut, rad, humanize, truncate, split_title) from pygal.svg import Svg from pygal.util import cached_property, majorize -from math import sin, cos, sqrt +from math import sin, cos, sqrt, ceil class BaseGraph(object): @@ -93,8 +93,11 @@ class BaseGraph(object): self.legend_font_size) if self.legend_at_bottom: h_max = max(h, self.legend_box_size) + cols = (self._order // self.legend_at_bottom_columns + if self.legend_at_bottom_columns + else ceil(sqrt(self._order)) or 1) self.margin.bottom += self.spacing + h_max * round( - sqrt(self._order) - 1) * 1.5 + h_max + cols - 1) * 1.5 + h_max else: if series_group is self.series: legend_width = self.spacing + w + self.legend_box_size diff --git a/pygal/graph/graph.py b/pygal/graph/graph.py index fca3101..3578610 100644 --- a/pygal/graph/graph.py +++ b/pygal/graph/graph.py @@ -279,7 +279,8 @@ class Graph(BaseGraph): y = (self.margin.top + self.view.height + self._x_title_height + self._x_labels_height + self.spacing) - cols = ceil(sqrt(self._order)) or 1 + cols = self.legend_at_bottom_columns or ceil( + sqrt(self._order)) or 1 if not truncation: available_space = self.view.width / cols - (