dataviz: fix sorting when data is empty (#53596)
This commit is contained in:
parent
db649f7d04
commit
d9e1b61ecb
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue