From 510a5c114e2f1ef344425abd0c323ba2b2985bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 10 Aug 2022 20:54:15 +0200 Subject: [PATCH] dataviz: truncate legend taking account the pie graph width (#68113) --- combo/apps/dataviz/models.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/combo/apps/dataviz/models.py b/combo/apps/dataviz/models.py index c900f29a..2ceb7fc9 100644 --- a/combo/apps/dataviz/models.py +++ b/combo/apps/dataviz/models.py @@ -554,8 +554,12 @@ class ChartNgCell(CellBase): chart.x_labels = [pygal.util.truncate(x, 15) for x in chart.x_labels] else: chart.show_legend = True - if width and width < 500: - chart.truncate_legend = 15 + if width and height: + # pies are as tall as wide, reserve the appropriate space and distribute + # the rest for the legend. + chart.truncate_legend = (width - height) // 10 + elif width: + chart.truncate_legend = width // 20 def process_one_dimensional_data(self, chart, data): if self.hide_null_values: