From 625bd9dd82006d2f287f54538640d87c8239f68d Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Mon, 28 Sep 2015 08:41:39 -0700 Subject: [PATCH] Period ratio compare --- TODO.md | 1 - panoramix/forms.py | 7 ++++++- panoramix/templates/panoramix/datasource.html | 13 ++++++++++++- panoramix/templates/panoramix/viz_nvd3.html | 3 ++- panoramix/viz.py | 7 +++++++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/TODO.md b/TODO.md index 6d900d8d9011c..8b5c61be6f7c8 100644 --- a/TODO.md +++ b/TODO.md @@ -15,7 +15,6 @@ List of TODO items for Panoramix * Contribution to total (added to line chart already) * Time comparison * Time ratios -* Use legend shapes that match line markers (useful?) * Line types (dash, dotted) ## New Features diff --git a/panoramix/forms.py b/panoramix/forms.py index 5185ff083ef83..5045eb93d0a45 100644 --- a/panoramix/forms.py +++ b/panoramix/forms.py @@ -1,6 +1,6 @@ from wtforms import ( Field, Form, SelectMultipleField, SelectField, TextField, TextAreaField, - BooleanField) + BooleanField, IntegerField) from copy import copy @@ -138,6 +138,11 @@ def form_factory(viz): 'contribution': BooleanField( "Contribution", default=False, description="Compute the contribution to the total"), + 'num_period_compare': IntegerField( + "Period Ratio", default=None, + description=( + "Number of period to compare against, " + "this is relative to the granularity selected")), } field_css_classes = {k: ['form-control'] for k in px_form_fields.keys()} select2 = [ diff --git a/panoramix/templates/panoramix/datasource.html b/panoramix/templates/panoramix/datasource.html index 2874d4ab8d933..37ad684e784e7 100644 --- a/panoramix/templates/panoramix/datasource.html +++ b/panoramix/templates/panoramix/datasource.html @@ -23,6 +23,17 @@ img.loading { width: 30px; } + .row { + margin-right: -5px; + margin-left: -5px; + } + .col-sm-1, .col-md-1, .col-lg-1, .col-xs-2, .col-sm-2, .col-md-2, .col-lg-2, .col-xs-3, .col-sm-3, .col-md-3, .col-lg-3, .col-xs-4, .col-sm-4, .col-md-4, .col-lg-4, .col-xs-5, .col-sm-5, .col-md-5, .col-lg-5, .col-xs-6, .col-sm-6, .col-md-6, .col-lg-6, .col-xs-7, .col-sm-7, .col-md-7, .col-lg-7, .col-xs-8, .col-sm-8, .col-md-8, .col-lg-8, .col-xs-9, .col-sm-9, .col-md-9, .col-lg-9, .col-xs-10, .col-sm-10, .col-md-10, .col-lg-10, .col-xs-11, .col-sm-11, .col-md-11, .col-lg-11, .col-xs-12, .col-sm-12, .col-md-12, .col-lg-12 { + position: relative; + min-height: 1px; + padding-right: 5px; + padding-left: 5px; + } + {% 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 741b740b61363..6c62ed1e74802 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 0799e8038bb85..a903590ec0248 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 @@ def get_df(self): 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: