From 1a0b9c82666e3bfa99c824047c311719567374c0 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 16 Feb 2023 16:09:18 +0100 Subject: [PATCH] dataviz: do not show total for single point data (#73685) --- combo/apps/dataviz/models.py | 5 +++++ tests/test_dataviz.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/combo/apps/dataviz/models.py b/combo/apps/dataviz/models.py index 5bdaf6f0..13526390 100644 --- a/combo/apps/dataviz/models.py +++ b/combo/apps/dataviz/models.py @@ -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 diff --git a/tests/test_dataviz.py b/tests/test_dataviz.py index 81f579ef..9b445429 100644 --- a/tests/test_dataviz.py +++ b/tests/test_dataviz.py @@ -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() -- 2.39.2