From fa08d353e86e9e5fd3e3780d1522a2b6fdc0143a Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Wed, 30 Sep 2015 17:34:55 -0700 Subject: [PATCH] Bug fixes --- panoramix/forms.py | 16 ++++++++++++---- panoramix/viz.py | 13 +++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/panoramix/forms.py b/panoramix/forms.py index 1cc3b121343..693be7fcd5d 100644 --- a/panoramix/forms.py +++ b/panoramix/forms.py @@ -38,6 +38,8 @@ class FormFactory(object): from panoramix.viz import viz_types viz = self.viz datasource = viz.datasource + default_metric = datasource.metrics_combo[0][0] + default_groupby = datasource.groupby_column_names[0] group_by_choices = [(s, s) for s in datasource.groupby_column_names] # Pool of all the fields that can be used in Panoramix self.field_dict = { @@ -48,11 +50,11 @@ class FormFactory(object): description="The type of visualization to display"), 'metrics': SelectMultipleField( 'Metrics', choices=datasource.metrics_combo, - default=[datasource.metrics_combo[0][0]], + default=[default_metric], description="One or many metrics to display"), 'metric': SelectField( 'Metric', choices=datasource.metrics_combo, - default='', + default=default_metric, description="One or many metrics to display"), 'groupby': SelectMultipleField( 'Group by', @@ -90,18 +92,25 @@ class FormFactory(object): "relative to the 'granularity' field")), 'series': SelectField( 'Series', choices=group_by_choices, + default=default_groupby, description=( "Defines the grouping of entities. " "Each serie is shown as a specific color on the chart and " "has a legend toggle")), 'entity': SelectField('Entity', choices=group_by_choices, + default=default_groupby, description="This define the element to be plotted on the chart"), 'x': SelectField( 'X Axis', choices=datasource.metrics_combo, + default=default_metric, description="Metric assigned to the [X] axis"), 'y': SelectField('Y Axis', choices=datasource.metrics_combo, + default=default_metric, description="Metric assigned to the [Y] axis"), - 'size': SelectField('Bubble Size', choices=datasource.metrics_combo), + 'size': SelectField( + 'Bubble Size', + default=default_metric, + choices=datasource.metrics_combo), 'where': TextField('Custom WHERE clause', default=''), 'compare_lag': TextField('Comparison Period Lag', description="Based on granularity, number of time periods to compare against"), @@ -183,7 +192,6 @@ class FormFactory(object): async = HiddenField() json = HiddenField() previous_viz_type = HiddenField() - standalone = HiddenField() for i in range(10): diff --git a/panoramix/viz.py b/panoramix/viz.py index e20eaa0af3f..51009fa7b1d 100644 --- a/panoramix/viz.py +++ b/panoramix/viz.py @@ -71,7 +71,7 @@ class BaseViz(object): pass def get_url(self, **kwargs): - d = self.form_data.copy() + d = self.orig_form_data.copy() if 'action' in d: del d['action'] d.update(kwargs) @@ -285,6 +285,7 @@ class BubbleViz(NVD3Viz): self.z_metric = form_data.get('size') self.entity = form_data.get('entity') self.series = form_data.get('series') + d['metrics'] = [ self.z_metric, self.x_metric, @@ -309,13 +310,17 @@ class BubbleViz(NVD3Viz): series = defaultdict(list) for row in df.to_dict(orient='records'): series[row['group']].append(row) - data = [] + chart_data = [] for k, v in series.items(): - data.append({ + chart_data.append({ 'key': k, "color": utils.color(k), 'values': v }) - return json.dumps(data) + return dumps({ + 'chart_data': chart_data, + 'query': self.results.query, + 'duration': self.results.duration, + }) class BigNumberViz(BaseViz): verbose_name = "Big Number"