dataviz: add table style to invert rows/columns (#67937)
This commit is contained in:
parent
ffe75d522d
commit
8078688a72
|
@ -48,6 +48,7 @@ class Migration(migrations.Migration):
|
|||
('pie', 'Pie'),
|
||||
('dot', 'Dot'),
|
||||
('table', 'Table'),
|
||||
('table-inverted', 'Table (inverted)'),
|
||||
],
|
||||
default='bar',
|
||||
max_length=20,
|
||||
|
|
|
@ -238,6 +238,7 @@ class ChartNgCell(CellBase):
|
|||
('pie', _('Pie')),
|
||||
('dot', _('Dot')),
|
||||
('table', _('Table')),
|
||||
('table-inverted', _('Table (inverted)')),
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -341,6 +342,7 @@ class ChartNgCell(CellBase):
|
|||
'pie': pygal.Pie,
|
||||
'dot': pygal.Dot,
|
||||
'table': pygal.Bar,
|
||||
'table-inverted': pygal.Bar,
|
||||
}[self.chart_type](config=pygal.Config(style=copy.copy(style), order_min=0.1, max_scale=5))
|
||||
|
||||
if self.statistic.service_slug == 'bijoe':
|
||||
|
@ -560,7 +562,7 @@ class ChartNgCell(CellBase):
|
|||
data = self.hide_values(chart, data)
|
||||
if data and self.sort_order != 'none':
|
||||
data = self.sort_values(chart, data)
|
||||
if getattr(chart, 'compute_sum', True) and self.chart_type == 'table':
|
||||
if getattr(chart, 'compute_sum', True) and self.chart_type in ('table', 'table-inverted'):
|
||||
data = self.add_total_to_line_table(chart, data)
|
||||
return data
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% load i18n %}
|
||||
{% if cell.title %}<h2>{{cell.title}}</h2>{% endif %}
|
||||
{% if cell.chart_type == "table" %}
|
||||
{% if cell.chart_type == "table" or cell.chart_type == "table-inverted" %}
|
||||
<div id="chart-{{cell.id}}"></div>
|
||||
<script>
|
||||
$(function() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<div style="position: relative">
|
||||
{{ form.as_p }}
|
||||
{% if cell.statistic and cell.chart_type != "table" %}
|
||||
{% if cell.statistic and cell.chart_type != "table" and cell.chart_type != "table-inverted" %}
|
||||
<div style="position: absolute; right: 0; top: 0; width: 300px; height: 150px">
|
||||
<embed type="image/svg+xml" src="{% url 'combo-dataviz-graph' cell=cell.id %}?width=300&height=150"/>
|
||||
</div>
|
||||
|
|
|
@ -92,12 +92,16 @@ class DatavizGraphView(DetailView):
|
|||
if self.filters_cell_id and self.cell.statistic.service_slug != 'bijoe':
|
||||
self.update_subfilters_cache(form.instance)
|
||||
|
||||
if self.cell.chart_type == 'table':
|
||||
if self.cell.chart_type in ('table', 'table-inverted'):
|
||||
if not chart.raw_series:
|
||||
return self.error(_('No data'))
|
||||
|
||||
transpose = bool(chart.axis_count == 2) # default behaviour
|
||||
if self.cell.chart_type == 'table-inverted':
|
||||
transpose = not transpose
|
||||
|
||||
rendered = chart.render_table(
|
||||
transpose=bool(chart.axis_count == 2) and self.cell.statistic.service_slug == 'bijoe',
|
||||
transpose=transpose,
|
||||
total=getattr(chart, 'compute_sum', True),
|
||||
)
|
||||
rendered = rendered.replace('<table>', '<table class="main">')
|
||||
|
@ -106,7 +110,7 @@ class DatavizGraphView(DetailView):
|
|||
return HttpResponse(chart.render(), content_type='image/svg+xml')
|
||||
|
||||
def error(self, error_text):
|
||||
if self.cell.chart_type == 'table':
|
||||
if self.cell.chart_type in ('table', 'table-inverted'):
|
||||
return HttpResponse('<p>%s</p>' % error_text)
|
||||
|
||||
context = {
|
||||
|
|
|
@ -1213,6 +1213,11 @@ def test_chartng_cell_view(app, normal_user, statistics):
|
|||
resp = app.get(location, status=200)
|
||||
assert '<td>222</td>' in resp.text
|
||||
|
||||
cell.chart_type = 'table-inverted'
|
||||
cell.save()
|
||||
resp = app.get(location, status=200)
|
||||
assert '<td>222</td>' in resp.text
|
||||
|
||||
# unsupported dataset
|
||||
cell.statistic = Statistic.objects.get(slug='seventh')
|
||||
cell.save()
|
||||
|
@ -1278,6 +1283,15 @@ def test_chartng_cell_view_new_api(app, normal_user, new_api_statistics):
|
|||
cell.save()
|
||||
resp = app.get(location, status=200)
|
||||
assert '<td>18</td>' in resp.text
|
||||
assert '<th>Serie 1</th>' in resp.text
|
||||
assert '<td>2020-10</td>' in resp.text
|
||||
|
||||
cell.chart_type = 'table-inverted'
|
||||
cell.save()
|
||||
resp = app.get(location, status=200)
|
||||
assert '<td>18</td>' in resp.text
|
||||
assert '<td>Serie 1</td>' in resp.text
|
||||
assert '<th>2020-10</th>' in resp.text
|
||||
|
||||
# deleted visualization
|
||||
cell.statistic = Statistic.objects.get(slug='not-found')
|
||||
|
|
Loading…
Reference in New Issue