Skip to content

Commit

Permalink
Cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Dec 8, 2015
1 parent b666508 commit a32712d
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 101 deletions.
10 changes: 1 addition & 9 deletions panoramix/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ class OmgWtForm(Form):
fieldsets = {}
css_classes = dict()

@property
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)

Expand Down Expand Up @@ -314,7 +306,7 @@ class QueryForm(OmgWtForm):
setattr(QueryForm, 'where', px_form_fields['where'])
setattr(QueryForm, 'having', px_form_fields['having'])

if 'granularity' in viz.form_fields:
if 'granularity' in viz.flat_form_fields():
setattr(
QueryForm,
'granularity', px_form_fields['granularity_sqla'])
Expand Down
3 changes: 0 additions & 3 deletions panoramix/static/widgets/viz_nvd3.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ 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)
Expand Down
229 changes: 140 additions & 89 deletions panoramix/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ class BaseViz(object):
verbose_name = "Base Viz"
template = None
is_timeseries = False
form_fields = [
'viz_type',
'granularity',
('since', 'until'),
'metrics', 'groupby',
]
fieldsets = (
{
'label': None,
'fields': (
'viz_type',
'granularity',
('since', 'until'),
'metrics', 'groupby',
)
},)
js_files = []
css_files = []

Expand Down Expand Up @@ -75,20 +79,17 @@ def fieldsetizer(self):
Makes form_fields support either a list approach or a fieldsets
approach
"""
ff = self.fieldsets if hasattr(self, 'fieldsets') else self.form_fields
if isinstance(ff[0], dict):
return self.fieldsets
else:
return ({'label': None, 'fields': ff},)
return self.fieldsets

@classmethod
def flat_form_fields(cls):
l = []
for obj in cls.form_fields:
if isinstance(obj, (tuple, list)):
l += [a for a in obj]
else:
l.append(obj)
l = set()
for d in cls.fieldsets:
for obj in d['fields']:
if isinstance(obj, (tuple, list)):
l |= {a for a in obj}
else:
l.add(obj)
return l

def reassignments(self):
Expand Down Expand Up @@ -209,7 +210,17 @@ class TableViz(BaseViz):
viz_type = "table"
verbose_name = "Table View"
template = 'panoramix/viz_table.html'
form_fields = BaseViz.form_fields + ['row_limit']
fieldsets = (
{
'label': None,
'fields': (
'viz_type',
'granularity',
('since', 'until'),
'metrics', 'groupby',
'row_limit'
)
},)
css_files = ['lib/dataTables/dataTables.bootstrap.css']
is_timeseries = False
js_files = [
Expand Down Expand Up @@ -242,15 +253,19 @@ class PivotTableViz(BaseViz):
js_files = [
'lib/dataTables/jquery.dataTables.min.js',
'lib/dataTables/dataTables.bootstrap.js']
form_fields = [
'viz_type',
'granularity',
('since', 'until'),
'groupby',
'columns',
'metrics',
'pandas_aggfunc',
]
fieldsets = (
{
'label': None,
'fields': (
'viz_type',
'granularity',
('since', 'until'),
'groupby',
'columns',
'metrics',
'pandas_aggfunc',
)
},)

def query_obj(self):
d = super(PivotTableViz, self).query_obj()
Expand Down Expand Up @@ -295,7 +310,11 @@ class MarkupViz(BaseViz):
viz_type = "markup"
verbose_name = "Markup Widget"
template = 'panoramix/viz_markup.html'
form_fields = ['viz_type', 'markup_type', 'code']
fieldsets = (
{
'label': None,
'fields': ('viz_type', 'markup_type', 'code')
},)
is_timeseries = False

def rendered(self):
Expand All @@ -316,13 +335,17 @@ class WordCloudViz(BaseViz):
verbose_name = "Word Cloud"
template = 'panoramix/viz_word_cloud.html'
is_timeseries = False
form_fields = [
'viz_type',
('since', 'until'),
'groupby', 'metric', 'limit',
('size_from', 'size_to'),
'rotation',
]
fieldsets = (
{
'label': None,
'fields': (
'viz_type',
('since', 'until'),
'groupby', 'metric', 'limit',
('size_from', 'size_to'),
'rotation',
)
},)
js_files = [
'lib/d3.min.js',
'lib/d3.layout.cloud.js',
Expand Down Expand Up @@ -364,15 +387,19 @@ class BubbleViz(NVD3Viz):
viz_type = "bubble"
verbose_name = "Bubble Chart"
is_timeseries = False
form_fields = [
'viz_type',
('since', 'until'),
('series', 'entity'),
('x', 'y'),
('size', 'limit'),
('x_log_scale', 'y_log_scale'),
('show_legend', None),
]
fieldsets = (
{
'label': None,
'fields': (
'viz_type',
('since', 'until'),
('series', 'entity'),
('x', 'y'),
('size', 'limit'),
('x_log_scale', 'y_log_scale'),
('show_legend', None),
)
},)

def query_obj(self):
form_data = self.form_data
Expand Down Expand Up @@ -435,14 +462,18 @@ class BigNumberViz(BaseViz):
css_files = [
'widgets/viz_bignumber.css',
]
form_fields = [
'viz_type',
'granularity',
('since', 'until'),
'metric',
'compare_lag',
'compare_suffix',
]
fieldsets = (
{
'label': None,
'fields': (
'viz_type',
'granularity',
('since', 'until'),
'metric',
'compare_lag',
'compare_suffix',
)
},)

def reassignments(self):
metric = self.form_data.get('metric')
Expand Down Expand Up @@ -611,54 +642,70 @@ def get_json_data(self):
class NVD3TimeSeriesBarViz(NVD3TimeSeriesViz):
viz_type = "bar"
verbose_name = "Time Series - Bar Chart"
form_fields = [
'viz_type',
'granularity', ('since', 'until'),
'metrics',
'groupby', 'limit',
('rolling_type', 'rolling_periods'),
'show_legend',
]
fieldsets = (
{
'label': None,
'fields': (
'viz_type',
'granularity', ('since', 'until'),
'metrics',
'groupby', 'limit',
('rolling_type', 'rolling_periods'),
'show_legend',
)
},)


class NVD3CompareTimeSeriesViz(NVD3TimeSeriesViz):
viz_type = 'compare'
verbose_name = "Time Series - Percent Change"
form_fields = [
'viz_type',
'granularity', ('since', 'until'),
'metrics',
'groupby', 'limit',
('rolling_type', 'rolling_periods'),
'show_legend',
]
fieldsets = (
{
'label': None,
'fields': (
'viz_type',
'granularity', ('since', 'until'),
'metrics',
'groupby', 'limit',
('rolling_type', 'rolling_periods'),
'show_legend',
)
},)


class NVD3TimeSeriesStackedViz(NVD3TimeSeriesViz):
viz_type = "area"
verbose_name = "Time Series - Stacked"
sort_series = True
form_fields = [
'viz_type',
'granularity', ('since', 'until'),
'metrics',
'groupby', 'limit',
('rolling_type', 'rolling_periods'),
('rich_tooltip', 'show_legend'),
]
fieldsets = (
{
'label': None,
'fields': (
'viz_type',
'granularity', ('since', 'until'),
'metrics',
'groupby', 'limit',
('rolling_type', 'rolling_periods'),
('rich_tooltip', 'show_legend'),
)
},)


class DistributionPieViz(NVD3Viz):
viz_type = "pie"
verbose_name = "Distribution - NVD3 - Pie Chart"
is_timeseries = False
form_fields = [
'viz_type',
('since', 'until'),
'metrics', 'groupby',
'limit',
('donut', 'show_legend'),
]
fieldsets = (
{
'label': None,
'fields': (
'viz_type',
('since', 'until'),
'metrics', 'groupby',
'limit',
('donut', 'show_legend'),
)
},)

def query_obj(self):
d = super(DistributionPieViz, self).query_obj()
Expand Down Expand Up @@ -689,12 +736,16 @@ class DistributionBarViz(DistributionPieViz):
viz_type = "dist_bar"
verbose_name = "Distribution - Bar Chart"
is_timeseries = False
form_fields = [
'viz_type', 'metrics', 'groupby',
('since', 'until'),
'limit',
('show_legend', None),
]
fieldsets = (
{
'label': None,
'fields': (
'viz_type', 'metrics', 'groupby',
('since', 'until'),
'limit',
('show_legend', None),
)
},)

def get_df(self):
df = super(DistributionPieViz, self).get_df()
Expand Down

0 comments on commit a32712d

Please sign in to comment.