dataviz: do not show total for single point data (#73685) #50

Merged
vdeniaud merged 1 commits from wip/73685-Cellule-Graphe-de-type-tableau-a into main 2023-02-16 16:31:34 +01:00
2 changed files with 11 additions and 0 deletions

View File

@ -609,6 +609,11 @@ class ChartNgCell(CellBase):
def add_total_to_line_table(chart, data):
# workaround pygal
chart.compute_sum = False
# do not add total for single point
if len(data) <= 1:
return data
data.append(sum(x for x in data if x is not None))
chart.x_labels.append(gettext('Total'))
return data

View File

@ -1954,6 +1954,12 @@ def test_table_cell_new_api(app, admin_user, new_api_statistics):
resp = app.get(location)
assert resp.text.count('Total') == 0
# no total for single point data
cell.statistic = Statistic.objects.get(slug='empty-x-labels')
cell.save()
resp = app.get(location)
assert resp.text.count('Total') == 0
def test_dataviz_hourly_unavailable_statistic(statistics, nocache):
all_stats_count = Statistic.objects.count()