Changing the way viz templates are defined using macros instead
This commit is contained in:
parent
6daf92e3c1
commit
0bc2e71ac6
|
|
@ -113,7 +113,7 @@ form input.form-control {
|
|||
</h3>
|
||||
<hr/>
|
||||
<div class="viz" style="height: 600px;">
|
||||
{% block viz %}
|
||||
{% block viz_html %}
|
||||
{% if viz.error_msg %}
|
||||
<div class="alert alert-danger">{{ viz.error_msg }}</div>
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,16 @@
|
|||
{% import viz.template as viz_macros %}
|
||||
|
||||
{% if standalone %}
|
||||
{% extends 'panoramix/viz_standalone.html' %}
|
||||
{% else %}
|
||||
{% extends 'panoramix/datasource.html' %}
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% block viz_html %}
|
||||
{{ viz_macros.viz_html(viz) }}
|
||||
{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
{{super()}}
|
||||
{% if not skip_libs %}
|
||||
|
|
@ -11,6 +18,7 @@
|
|||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename=css) }}">
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{{ viz_macros.viz_css(viz) }}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
|
@ -25,4 +33,5 @@
|
|||
<script src="{{ url_for('static', filename=js) }}"></script>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{{ viz_macros.viz_js(viz) }}
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
{% extends "panoramix/viz.html" %}
|
||||
{% block viz %}
|
||||
{{ super() }}
|
||||
{% macro viz_html(viz) %}
|
||||
<div id="chart" style="height:100%; width:100%;"></div>
|
||||
{% endblock %}
|
||||
{% endmacro %}
|
||||
|
||||
{% block tail %}
|
||||
{{ super() }}
|
||||
{% macro viz_js(viz) %}
|
||||
<script>
|
||||
$( document ).ready(function() {
|
||||
Highcharts.setOptions({
|
||||
|
|
@ -20,9 +17,12 @@
|
|||
$("#viz_type").click(function(){
|
||||
$("#queryform").submit();
|
||||
})
|
||||
{% if chart_js %}
|
||||
{{ chart_js|safe }}
|
||||
{% if viz.chart_js %}
|
||||
{{ viz.chart_js|safe }}
|
||||
{% endif %}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro viz_css(viz) %}
|
||||
{% endmacro %}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
{% block tail %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
{% block viz %}
|
||||
{% block viz_html %}
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,45 +1,42 @@
|
|||
{% extends "panoramix/viz.html" %}
|
||||
{% macro viz_html(viz) %}
|
||||
{% set df = viz.df %}
|
||||
<table class="dataframe table table-striped table-bordered table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
{% for col in df.columns if not col.endswith('__perc') %}
|
||||
<th>{{ col }}</th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for row in df.to_dict(orient="records") %}
|
||||
<tr>
|
||||
{% for col in df.columns if not col.endswith('__perc') %}
|
||||
{% if col + '__perc' in df.columns %}
|
||||
<td style="background-image: linear-gradient(to right, lightgrey, lightgrey {{ row[col+'__perc'] }}%, rgba(0,0,0,0) {{ row[col+'__perc'] }}%">
|
||||
{{ row[col] }}
|
||||
</td>
|
||||
{% else %}
|
||||
<td>{{ row[col] }}</td>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endmacro %}
|
||||
|
||||
{% block viz %}
|
||||
{{ super() }}
|
||||
{% if not error_msg %}
|
||||
<table class="dataframe table table-striped table-bordered table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
{% for col in df.columns if not col.endswith('__perc') %}
|
||||
<th>{{ col }}</th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for row in df.to_dict(orient="records") %}
|
||||
<tr>
|
||||
{% for col in df.columns if not col.endswith('__perc') %}
|
||||
{% if col + '__perc' in df.columns %}
|
||||
<td style="background-image: linear-gradient(to right, lightgrey, lightgrey {{ row[col+'__perc'] }}%, rgba(0,0,0,0) {{ row[col+'__perc'] }}%">
|
||||
{{ row[col] }}
|
||||
</td>
|
||||
{% else %}
|
||||
<td>{{ row[col] }}</td>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block tail %}
|
||||
{{ super() }}
|
||||
<script>
|
||||
//$('table').css('background-color', 'white');
|
||||
{% macro viz_js(viz) %}
|
||||
<script>
|
||||
//$('table').css('background-color', 'white');
|
||||
$(document).ready(function() {
|
||||
var table = $('table').DataTable({
|
||||
paging: false,
|
||||
});
|
||||
table.column('-1').order( 'desc' ).draw();
|
||||
var table = $('table').DataTable({
|
||||
paging: false,
|
||||
});
|
||||
table.column('-1').order( 'desc' ).draw();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
</script>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro viz_css(viz) %}
|
||||
{% endmacro %}
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ class BaseViz(object):
|
|||
def render(self, *args, **kwargs):
|
||||
form = self.form_class(self.form_data)
|
||||
return self.view.render_template(
|
||||
self.template, form=form, viz=self, datasource=self.datasource,
|
||||
"panoramix/viz.html", form=form, viz=self, datasource=self.datasource,
|
||||
results=self.results,
|
||||
standalone=request.args.get('standalone') == 'true',
|
||||
skip_libs=request.args.get('skip_libs') == 'true',
|
||||
|
|
@ -211,7 +211,8 @@ class BubbleViz(HighchartsViz):
|
|||
df['name'] = df[[self.entity]]
|
||||
df['group'] = df[[self.series]]
|
||||
chart = HighchartBubble(df)
|
||||
return super(BubbleViz, self).render(chart_js=chart.javascript_cmd)
|
||||
self.chart_js = chart.javascript_cmd
|
||||
return super(BubbleViz, self).render()
|
||||
|
||||
|
||||
class TimeSeriesViz(HighchartsViz):
|
||||
|
|
@ -259,7 +260,8 @@ class TimeSeriesViz(HighchartsViz):
|
|||
stockchart=self.stockchart,
|
||||
sort_legend_y=self.sort_legend_y,
|
||||
**CHART_ARGS)
|
||||
return super(TimeSeriesViz, self).render(chart_js=chart.javascript_cmd)
|
||||
self.chart_js = chart.javascript_cmd
|
||||
return super(TimeSeriesViz, self).render()
|
||||
|
||||
def bake_query(self):
|
||||
"""
|
||||
|
|
@ -314,8 +316,8 @@ class DistributionBarViz(HighchartsViz):
|
|||
df = df.sort(self.metrics[0], ascending=False)
|
||||
chart = Highchart(
|
||||
df, chart_type=self.chart_type, **CHART_ARGS)
|
||||
return super(DistributionBarViz, self).render(
|
||||
chart_js=chart.javascript_cmd)
|
||||
self.chart_js = chart.javascript_cmd
|
||||
return super(DistributionBarViz, self).render()
|
||||
|
||||
|
||||
class DistributionPieViz(HighchartsViz):
|
||||
|
|
@ -337,8 +339,8 @@ class DistributionPieViz(HighchartsViz):
|
|||
df = df.sort(self.metrics[0], ascending=False)
|
||||
chart = Highchart(
|
||||
df, chart_type=self.chart_type, **CHART_ARGS)
|
||||
return super(DistributionPieViz, self).render(
|
||||
chart_js=chart.javascript_cmd)
|
||||
self.chart_js = chart.javascript_cmd
|
||||
return super(DistributionPieViz, self).render()
|
||||
|
||||
viz_types = OrderedDict([
|
||||
['table', TableViz],
|
||||
|
|
|
|||
Loading…
Reference in New Issue