From bf8ce1716a479bac34480ebb79c3252bc4e9f156 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Sun, 27 Sep 2015 08:52:26 -0700 Subject: [PATCH 1/7] nvd3 Stacked Area chart --- panoramix/bin/panoramix | 6 +- panoramix/forms.py | 6 +- panoramix/templates/panoramix/base.html | 1 + panoramix/templates/panoramix/datasource.html | 18 ++--- panoramix/templates/panoramix/viz_nvd3.html | 27 +++++++- panoramix/views.py | 4 ++ panoramix/viz.py | 69 +++++++++++++++---- 7 files changed, 102 insertions(+), 29 deletions(-) diff --git a/panoramix/bin/panoramix b/panoramix/bin/panoramix index 565df3341..062ac5939 100755 --- a/panoramix/bin/panoramix +++ b/panoramix/bin/panoramix @@ -219,12 +219,12 @@ def load_examples(sample): if not slc: slc = Slice( slice_name=slice_name, - viz_type='line', + viz_type='nvd3_line', datasource_type='table', table=tbl, params=get_slice_json( - slice_name, viz_type="line", groupby=['name'], - granularity='1 day')) + slice_name, viz_type="nvd3_line", groupby=['name'], + granularity='1 day', rich_tooltip='y', show_legend='y')) session.add(slc) slices.append(slc) diff --git a/panoramix/forms.py b/panoramix/forms.py index b636f12ed..e86cec632 100644 --- a/panoramix/forms.py +++ b/panoramix/forms.py @@ -120,6 +120,9 @@ def form_factory(viz): 'y_log_scale': BooleanField( "Y Log", default=False, description="Use a log scale for the Y axis"), + 'donut': BooleanField( + "Donut", default=False, + description="Do you want a donut or a pie?"), } field_css_classes = {k: ['form-control'] for k in px_form_fields.keys()} select2 = [ @@ -150,7 +153,8 @@ def form_factory(viz): if isinstance(ff, basestring): ff = [ff] for s in ff: - setattr(QueryForm, s, px_form_fields[s]) + if s: + setattr(QueryForm, s, px_form_fields[s]) # datasource type specific form elements if datasource.__class__.__name__ == 'Table': diff --git a/panoramix/templates/panoramix/base.html b/panoramix/templates/panoramix/base.html index 7a26ae00e..6d15fb194 100644 --- a/panoramix/templates/panoramix/base.html +++ b/panoramix/templates/panoramix/base.html @@ -3,6 +3,7 @@ {% block head_css %} {{super()}} + {% endblock %} @@ -167,7 +178,7 @@ $(".select2").select2(); $("form").slideDown("slow"); - $('[data-toggle="tooltip"]').tooltip(); + $('[data-toggle="tooltip"]').tooltip({container: 'body'}); function set_filters(){ for (var i=1; i<10; i++){ diff --git a/panoramix/templates/panoramix/viz_nvd3.html b/panoramix/templates/panoramix/viz_nvd3.html index 741b740b6..6c62ed1e7 100644 --- a/panoramix/templates/panoramix/viz_nvd3.html +++ b/panoramix/templates/panoramix/viz_nvd3.html @@ -53,8 +53,9 @@ .tickFormat(function (d) {return tickMultiFormat(new Date(d)); }); chart.showLegend({{ "{}".format(viz.args.show_legend=='y')|lower }}); chart.yAxis.tickFormat(d3.format('.3s')); - {% if viz.args.contribution=='y' %} + {% if viz.args.contribution=='y' or viz.args.get("num_period_compare") %} chart.yAxis.tickFormat(d3.format('.3p')); + chart.y2Axis.tickFormat(d3.format('.3p')); {% endif %} {% elif viz.chart_type == 'nvd3_bar' %} diff --git a/panoramix/viz.py b/panoramix/viz.py index 0799e8038..a903590ec 100644 --- a/panoramix/viz.py +++ b/panoramix/viz.py @@ -322,6 +322,7 @@ class NVD3TimeSeriesViz(NVD3Viz): 'metrics', 'groupby', 'limit', ('rolling_type', 'rolling_periods'), + ('num_period_compare', None), ('show_brush', 'show_legend'), ('rich_tooltip', 'y_axis_zero'), ('y_log_scale', 'contribution') @@ -346,6 +347,12 @@ class NVD3TimeSeriesViz(NVD3Viz): dft = df.T df = (dft / dft.sum()).T + num_period_compare = self.form_data.get("num_period_compare") + if num_period_compare: + num_period_compare = int(num_period_compare) + df = df / df.shift(num_period_compare) + df = df[num_period_compare:] + rolling_periods = args.get("rolling_periods") rolling_type = args.get("rolling_type") if rolling_periods and rolling_type: From 721113db0d93edfe040c059b1b98372f9600bc3d Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Mon, 28 Sep 2015 09:24:53 -0700 Subject: [PATCH 6/7] About to rip out args --- panoramix/templates/panoramix/datasource.html | 195 +++++++++--------- panoramix/templates/panoramix/viz_nvd3.html | 2 +- panoramix/viz.py | 3 +- 3 files changed, 102 insertions(+), 98 deletions(-) diff --git a/panoramix/templates/panoramix/datasource.html b/panoramix/templates/panoramix/datasource.html index 37ad684e7..c88eb9d0b 100644 --- a/panoramix/templates/panoramix/datasource.html +++ b/panoramix/templates/panoramix/datasource.html @@ -2,6 +2,8 @@ {% block head_css %} {{super()}}