From 2b770623d550ececd802b4efcd99454101b5015e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 16 Feb 2020 10:02:20 +0100 Subject: [PATCH] dataviz: truncate horizontal bar labels in narrow graphs (#39920) --- combo/apps/dataviz/models.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/combo/apps/dataviz/models.py b/combo/apps/dataviz/models.py index 88a81e2d..756cafe2 100644 --- a/combo/apps/dataviz/models.py +++ b/combo/apps/dataviz/models.py @@ -26,6 +26,7 @@ from django.conf import settings from jsonfield import JSONField from requests.exceptions import HTTPError import pygal +import pygal.util from combo.data.models import CellBase from combo.data.library import register_cell_class @@ -272,6 +273,9 @@ class ChartNgCell(CellBase): chart.add(serie_label, values) if width and width < 500: chart.legend_at_bottom = True + if self.chart_type == 'horizontal-bar': + # truncate labels + chart.x_labels = [pygal.util.truncate(x, 15) for x in chart.x_labels] else: # pie, create a serie by data, to get different colours values = data