combo/combo/apps/dataviz/templates/combo/chartngcell.html

42 lines
1.7 KiB
HTML

{% load i18n %}
{% if cell.title %}<h2>{{cell.title}}</h2>{% endif %}
{% if cell.chart_type == "table" or cell.chart_type == "table-inverted" %}
<div id="chart-{{cell.id}}"></div>
<script>
$(function() {
var extra_context = $('#chart-{{cell.id}}').parents('.cell').data('extra-context');
$(window).on('combo:refresh-graphs', function() {
$.ajax({
url : "{% url 'combo-dataviz-graph' cell=cell.id %}" + get_graph_querystring(extra_context),
type: 'GET',
success: function(data) {
$('#chart-{{cell.id}}').html(data);
}
});
}).trigger('combo:refresh-graphs');
});
</script>
{% else %}
<div style="min-height: {{cell.height}}px">
<embed id="chart-{{cell.id}}" type="image/svg+xml" style="width: 100%"/>
</div>
<script>
$(function() {
var last_width = 1;
var extra_context = $('#chart-{{cell.id}}').parents('.cell').data('extra-context');
$(window).on('load resize gadjo:sidepage-toggled combo:resize-graphs', function() {
var chart_cell = $('#chart-{{cell.id}}').parent();
var new_width = Math.floor($(chart_cell).width());
var ratio = new_width / last_width;
if (ratio > 1.2 || ratio < 0.8) {
$('#chart-{{cell.id}}').attr('src', "{% url 'combo-dataviz-graph' cell=cell.id %}" + get_graph_querystring(extra_context, new_width));
last_width = new_width;
}
}).trigger('combo:resize-graphs');
$(window).on('combo:refresh-graphs', function() {
$('#chart-{{cell.id}}').attr('src', "{% url 'combo-dataviz-graph' cell=cell.id %}" + get_graph_querystring(extra_context, last_width));
});
});
</script>
{% endif %}