From 81bf023d09232e26478e8b2661df4262f6532577 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Wed, 8 Jan 2020 15:31:01 +0100 Subject: [PATCH] dataviz: handle empty percentage value (#38847) --- combo/apps/dataviz/models.py | 2 +- tests/test_dataviz.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/combo/apps/dataviz/models.py b/combo/apps/dataviz/models.py index 4224c93..77e1672 100644 --- a/combo/apps/dataviz/models.py +++ b/combo/apps/dataviz/models.py @@ -290,7 +290,7 @@ class ChartNgCell(CellBase): return force_text(value) chart.config.value_formatter = format_duration elif response.get('measure') == 'percent': - percent_formatter = lambda x: '{:.1f}%'.format(x) + percent_formatter = lambda x: '0%' if x is None else '{:.1f}%'.format(x) chart.config.value_formatter = percent_formatter return chart diff --git a/tests/test_dataviz.py b/tests/test_dataviz.py index 648516c..da4dcd5 100644 --- a/tests/test_dataviz.py +++ b/tests/test_dataviz.py @@ -220,7 +220,7 @@ def bijoe_mock(url, request): if url.path == '/visualization/10/json/': response = { 'format': '1', - 'data': [10, 20, 30, 40], + 'data': [10, 20, 30, 40, None], 'axis': { 'y_labels': ['web', 'mail', 'email', 'fax'] }, @@ -422,6 +422,7 @@ def test_chartng_cell_view(app, normal_user): resp = app.get('/api/dataviz/graph/1/') # get data in cache resp = app.get('/') assert '10.0%' in resp.text + assert '0%' in resp.text cell.chart_type = 'bar' cell.save() -- 2.20.1