0001-dataviz-add-table-style-to-invert-rows-columns-67937.patch
combo/apps/dataviz/migrations/0011_auto_20200813_1100.py | ||
---|---|---|
48 | 48 |
('pie', 'Pie'), |
49 | 49 |
('dot', 'Dot'), |
50 | 50 |
('table', 'Table'), |
51 |
('table-inverted', 'Table (inverted)'), |
|
51 | 52 |
], |
52 | 53 |
default='bar', |
53 | 54 |
max_length=20, |
combo/apps/dataviz/models.py | ||
---|---|---|
238 | 238 |
('pie', _('Pie')), |
239 | 239 |
('dot', _('Dot')), |
240 | 240 |
('table', _('Table')), |
241 |
('table-inverted', _('Table (inverted)')), |
|
241 | 242 |
), |
242 | 243 |
) |
243 | 244 | |
... | ... | |
341 | 342 |
'pie': pygal.Pie, |
342 | 343 |
'dot': pygal.Dot, |
343 | 344 |
'table': pygal.Bar, |
345 |
'table-inverted': pygal.Bar, |
|
344 | 346 |
}[self.chart_type](config=pygal.Config(style=copy.copy(style), order_min=0.1, max_scale=5)) |
345 | 347 | |
346 | 348 |
if self.statistic.service_slug == 'bijoe': |
... | ... | |
560 | 562 |
data = self.hide_values(chart, data) |
561 | 563 |
if data and self.sort_order != 'none': |
562 | 564 |
data = self.sort_values(chart, data) |
563 |
if getattr(chart, 'compute_sum', True) and self.chart_type == 'table':
|
|
565 |
if getattr(chart, 'compute_sum', True) and self.chart_type in ('table', 'table-inverted'):
|
|
564 | 566 |
data = self.add_total_to_line_table(chart, data) |
565 | 567 |
return data |
566 | 568 |
combo/apps/dataviz/templates/combo/chartngcell.html | ||
---|---|---|
1 | 1 |
{% load i18n %} |
2 | 2 |
{% if cell.title %}<h2>{{cell.title}}</h2>{% endif %} |
3 |
{% if cell.chart_type == "table" %} |
|
3 |
{% if cell.chart_type == "table" or cell.chart_type == "table-inverted" %}
|
|
4 | 4 |
<div id="chart-{{cell.id}}"></div> |
5 | 5 |
<script> |
6 | 6 |
$(function() { |
combo/apps/dataviz/templates/combo/chartngcell_form.html | ||
---|---|---|
1 | 1 |
<div style="position: relative"> |
2 | 2 |
{{ form.as_p }} |
3 |
{% if cell.statistic and cell.chart_type != "table" %} |
|
3 |
{% if cell.statistic and cell.chart_type != "table" and cell.chart_type != "table-inverted" %}
|
|
4 | 4 |
<div style="position: absolute; right: 0; top: 0; width: 300px; height: 150px"> |
5 | 5 |
<embed type="image/svg+xml" src="{% url 'combo-dataviz-graph' cell=cell.id %}?width=300&height=150"/> |
6 | 6 |
</div> |
combo/apps/dataviz/views.py | ||
---|---|---|
92 | 92 |
if self.filters_cell_id and self.cell.statistic.service_slug != 'bijoe': |
93 | 93 |
self.update_subfilters_cache(form.instance) |
94 | 94 | |
95 |
if self.cell.chart_type == 'table':
|
|
95 |
if self.cell.chart_type in ('table', 'table-inverted'):
|
|
96 | 96 |
if not chart.raw_series: |
97 | 97 |
return self.error(_('No data')) |
98 | 98 | |
99 |
transpose = bool(chart.axis_count == 2) # default behaviour |
|
100 |
if self.cell.chart_type == 'table-inverted': |
|
101 |
transpose = not transpose |
|
102 | ||
99 | 103 |
rendered = chart.render_table( |
100 |
transpose=bool(chart.axis_count == 2) and self.cell.statistic.service_slug == 'bijoe',
|
|
104 |
transpose=transpose,
|
|
101 | 105 |
total=getattr(chart, 'compute_sum', True), |
102 | 106 |
) |
103 | 107 |
rendered = rendered.replace('<table>', '<table class="main">') |
... | ... | |
106 | 110 |
return HttpResponse(chart.render(), content_type='image/svg+xml') |
107 | 111 | |
108 | 112 |
def error(self, error_text): |
109 |
if self.cell.chart_type == 'table':
|
|
113 |
if self.cell.chart_type in ('table', 'table-inverted'):
|
|
110 | 114 |
return HttpResponse('<p>%s</p>' % error_text) |
111 | 115 | |
112 | 116 |
context = { |
tests/test_dataviz.py | ||
---|---|---|
1213 | 1213 |
resp = app.get(location, status=200) |
1214 | 1214 |
assert '<td>222</td>' in resp.text |
1215 | 1215 | |
1216 |
cell.chart_type = 'table-inverted' |
|
1217 |
cell.save() |
|
1218 |
resp = app.get(location, status=200) |
|
1219 |
assert '<td>222</td>' in resp.text |
|
1220 | ||
1216 | 1221 |
# unsupported dataset |
1217 | 1222 |
cell.statistic = Statistic.objects.get(slug='seventh') |
1218 | 1223 |
cell.save() |
... | ... | |
1278 | 1283 |
cell.save() |
1279 | 1284 |
resp = app.get(location, status=200) |
1280 | 1285 |
assert '<td>18</td>' in resp.text |
1286 |
assert '<th>Serie 1</th>' in resp.text |
|
1287 |
assert '<td>2020-10</td>' in resp.text |
|
1288 | ||
1289 |
cell.chart_type = 'table-inverted' |
|
1290 |
cell.save() |
|
1291 |
resp = app.get(location, status=200) |
|
1292 |
assert '<td>18</td>' in resp.text |
|
1293 |
assert '<td>Serie 1</td>' in resp.text |
|
1294 |
assert '<th>2020-10</th>' in resp.text |
|
1281 | 1295 | |
1282 | 1296 |
# deleted visualization |
1283 | 1297 |
cell.statistic = Statistic.objects.get(slug='not-found') |
1284 |
- |