dataviz: truncate horizontal bar labels in narrow graphs (#39920)

This commit is contained in:
Frédéric Péters 2020-02-16 10:02:20 +01:00
parent 196c6ce028
commit 2b770623d5
1 changed files with 4 additions and 0 deletions

View File

@ -26,6 +26,7 @@ from django.conf import settings
from jsonfield import JSONField from jsonfield import JSONField
from requests.exceptions import HTTPError from requests.exceptions import HTTPError
import pygal import pygal
import pygal.util
from combo.data.models import CellBase from combo.data.models import CellBase
from combo.data.library import register_cell_class from combo.data.library import register_cell_class
@ -272,6 +273,9 @@ class ChartNgCell(CellBase):
chart.add(serie_label, values) chart.add(serie_label, values)
if width and width < 500: if width and width < 500:
chart.legend_at_bottom = True 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: else:
# pie, create a serie by data, to get different colours # pie, create a serie by data, to get different colours
values = data values = data