dataviz: fix sorting when data is empty (#53596)
gitea-wip/combo/pipeline/head Build started... Details
gitea/combo/pipeline/head Build started... Details

This commit is contained in:
Lauréline Guérin 2021-04-30 16:30:02 +02:00
parent db649f7d04
commit d9e1b61ecb
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 32 additions and 1 deletions

View File

@ -464,7 +464,7 @@ class ChartNgCell(CellBase):
def process_one_dimensional_data(self, chart, data):
if self.hide_null_values:
data = self.hide_values(chart, data)
if self.sort_order != 'none':
if data and self.sort_order != 'none':
data = self.sort_values(chart, data)
if getattr(chart, 'compute_sum', True) and self.chart_type == 'table':
data = self.add_total_to_line_table(chart, data)

View File

@ -131,6 +131,12 @@ VISUALIZATION_JSON = [
'name': 'thirteenth visualization (loop with empty x_labels)',
'slug': 'thirteenth',
},
{
'data-url': 'https://bijoe.example.com/visualization/14/json/',
'path': 'https://bijoe.example.com/visualization/14/iframe/?signature=123',
'name': 'fourteenth visualization (empty data)',
'slug': 'fourteenth',
},
]
@ -273,6 +279,17 @@ def bijoe_mock(url, request):
},
}
return {'content': json.dumps(response), 'request': request, 'status_code': 200}
if url.path == '/visualization/14/json/':
response = {
'format': '1',
'data': [],
'axis': {
'x_labels': ['a', 'b', 'c'],
'y_labels': [],
},
'measure': 'integer',
}
return {'content': json.dumps(response), 'request': request, 'status_code': 200}
STATISTICS_LIST = {
@ -791,6 +808,13 @@ def test_chartng_cell_sort_order_alpha(app, statistics):
([122, 114, 2, 33], {'title': u'bar'}),
]
# empty data
cell.statistic = Statistic.objects.get(slug='fourteenth')
cell.save()
chart = cell.get_chart()
assert chart.x_labels == ['a', 'b', 'c']
assert chart.raw_series == [([], {'title': ''})]
@with_httmock(bijoe_mock)
def test_chartng_cell_sort_order_desc(app, statistics):
@ -876,6 +900,13 @@ def test_chartng_cell_sort_order_desc(app, statistics):
([122, 114, 2, 33], {'title': u'bar'}),
]
# empty data
cell.statistic = Statistic.objects.get(slug='fourteenth')
cell.save()
chart = cell.get_chart()
assert chart.x_labels == ['a', 'b', 'c']
assert chart.raw_series == [([], {'title': ''})]
@with_httmock(new_api_mock)
def test_chartng_cell_sort_order_new_api(app, new_api_statistics):