From b66650808516a47242ba2a0ca45827ea0026cb45 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Sun, 6 Dec 2015 20:57:38 -0800 Subject: [PATCH 1/2] Introducing field sets --- panoramix/forms.py | 42 +++--- panoramix/static/panoramix.css | 28 ++++ panoramix/static/widgets/viz_nvd3.js | 3 + panoramix/templates/panoramix/explore.html | 161 +++++++++++++++------ panoramix/views.py | 2 +- panoramix/viz.py | 57 ++++++-- 6 files changed, 211 insertions(+), 82 deletions(-) diff --git a/panoramix/forms.py b/panoramix/forms.py index 9debfa9ee6306..43b1b17d7981b 100644 --- a/panoramix/forms.py +++ b/panoramix/forms.py @@ -38,18 +38,16 @@ def iter_choices(self): class OmgWtForm(Form): - field_order = tuple() + fieldsets = {} css_classes = dict() @property - def fields(self): - fields = [] - for field in self.field_order: - if hasattr(self, field): - obj = getattr(self, field) - if isinstance(obj, Field): - fields.append(getattr(self, field)) - return fields + def form_fields(self): + all_field_ids = set() + for k, fieldset in self.fieldsets: + all_field_ids |= fieldset + return all_field_ids + def get_field(self, fieldname): return getattr(self, fieldname) @@ -179,7 +177,7 @@ def __init__(self, viz): default="random", description="Rotation to apply to words in the cloud"), 'line_interpolation': SelectField( - "Line Interpolation", + "Line Style", choices=self.choicify([ 'linear', 'basis', 'cardinal', 'monotone', 'step-before', 'step-after']), @@ -204,7 +202,7 @@ def __init__(self, viz): default="150", description="Font size for the biggest value in the list"), 'show_brush': BetterBooleanField( - "Range Selector", default=True, + "Range Filter", default=True, description=( "Whether to display the time range interactive selector")), 'show_legend': BetterBooleanField( @@ -239,7 +237,7 @@ def __init__(self, viz): "[integer] Number of period to compare against, " "this is relative to the granularity selected")), 'time_compare': TextField( - "Time Shift Compare", + "Time Shift", default="", description=( "Overlay a timeseries from a " @@ -278,7 +276,7 @@ def get_form(self, previous=False): field_css_classes[field] += ['select2Sortable'] class QueryForm(OmgWtForm): - field_order = copy(viz.form_fields) + fieldsets = copy(viz.fieldsetizer()) css_classes = field_css_classes standalone = HiddenField() async = HiddenField() @@ -286,6 +284,7 @@ class QueryForm(OmgWtForm): slice_id = HiddenField() slice_name = HiddenField() previous_viz_type = HiddenField(default=viz.viz_type) + collapsed_fieldsets = HiddenField() filter_cols = datasource.filterable_column_names or [''] for i in range(10): @@ -300,16 +299,18 @@ class QueryForm(OmgWtForm): setattr( QueryForm, 'flt_eq_' + str(i), TextField("Super", default='')) - for ff in viz.form_fields: - if isinstance(ff, string_types): - ff = [ff] - for s in ff: - if s: - setattr(QueryForm, s, px_form_fields[s]) + for fieldset in viz.fieldsetizer(): + for ff in fieldset['fields']: + if isinstance(ff, string_types): + ff = [ff] + for s in ff: + if s: + setattr(QueryForm, s, px_form_fields[s]) # datasource type specific form elements if datasource.__class__.__name__ == 'SqlaTable': - QueryForm.field_order += ['where', 'having'] + QueryForm.fieldsets += ( + {'label': 'SQL', 'fields': ['where', 'having']},) setattr(QueryForm, 'where', px_form_fields['where']) setattr(QueryForm, 'having', px_form_fields['having']) @@ -318,5 +319,4 @@ class QueryForm(OmgWtForm): QueryForm, 'granularity', px_form_fields['granularity_sqla']) field_css_classes['granularity'] = ['form-control', 'select2'] - return QueryForm diff --git a/panoramix/static/panoramix.css b/panoramix/static/panoramix.css index a75335c163768..bbdb22b9f17cc 100644 --- a/panoramix/static/panoramix.css +++ b/panoramix/static/panoramix.css @@ -10,6 +10,34 @@ form div { .navbar-brand a { color: white; } +fieldset.fs-style { + font-family: Verdana, Arial, sans-serif; + font-size: small; + font-weight: normal; + border: 1px solid #CCC; + background-color: #F4F4F4; + border-radius: 6px; + padding: 10px; + margin: 10px 0px; +} +legend.legend-style { + font-size: 14px; + padding: 0px 6px; + cursor: pointer; + margin: 0px; + color: #444; + background-color: transparent; + font-weight: bold; +} +.nvtooltip{ + position: relative; !important + z-index: 10; +} + +legend { + width: auto; + border-bottom: 0px; +} .navbar { -webkit-box-shadow: 0px 3px 3px #AAA; -moz-box-shadow: 0px 3px 3px #AAA; diff --git a/panoramix/static/widgets/viz_nvd3.js b/panoramix/static/widgets/viz_nvd3.js index 86d1408dc2320..1fe55deb65b5f 100644 --- a/panoramix/static/widgets/viz_nvd3.js +++ b/panoramix/static/widgets/viz_nvd3.js @@ -53,6 +53,9 @@ function viz_nvd3(data_attribute) { // To alter the tooltip header // chart.interactiveLayer.tooltip.headerFormatter(function(){return '';}); chart.xScale(d3.time.scale.utc()); + chart.useInteractiveGuideline(false); + chart.interactiveLayer.tooltip.chartContainer(document.body); + chart.interpolate(viz.form_data.line_interpolation); chart.xAxis .showMaxMin(viz.form_data.x_axis_showminmax) diff --git a/panoramix/templates/panoramix/explore.html b/panoramix/templates/panoramix/explore.html index dedad101e2084..9ed8ea592c096 100644 --- a/panoramix/templates/panoramix/explore.html +++ b/panoramix/templates/panoramix/explore.html @@ -22,57 +22,74 @@