Skip to content

Commit

Permalink
Charts review
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgaspar committed Apr 29, 2015
1 parent 9124ad2 commit 93ec5f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions flask_appbuilder/charts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
class BaseChartView(BaseModelView):
"""
This is the base class for all chart views.
Use DirectByChartView or GroupByChartView, override their properties and these
to customise your charts
Use DirectByChartView or GroupByChartView, override their properties and their base classes
(BaseView, BaseModelView, BaseChartView) to customise your charts
"""

chart_template = 'appbuilder/general/charts/chart.html'
Expand Down Expand Up @@ -118,12 +118,14 @@ def __init__(self, **kwargs):
super(GroupByChartView, self).__init__(**kwargs)
for definition in self.definitions:
col = definition.get('group')
# Setup labels
try:
self.label_columns[col] = definition.get('label') or self.label_columns[col]
except Exception:
self.label_columns[col] = self._prettify_column(col)
if not definition.get('label'):
definition['label'] = self.label_columns[col]
# Setup Series
for serie in definition['series']:
if isinstance(serie, tuple):
if hasattr(serie[0], '_label'):
Expand All @@ -136,6 +138,9 @@ def __init__(self, **kwargs):


def get_group_by_class(self, definition):
"""
intantiates the processing class (Direct or Grouped) and returns it.
"""
group_by = definition['group']
series = definition['series']
if 'formatter' in definition:
Expand Down
7 changes: 7 additions & 0 deletions flask_appbuilder/models/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def to_json(self, data, labels=None):
json_data['cols'].append({'id': aggr_col,
'label': label,
'type': 'number'})
# Create Structure with the data
json_data['rows'] = []
for item in data:
row = {'c': []}
Expand Down Expand Up @@ -302,7 +303,13 @@ def apply(self, data, sort=True):


class GroupByProcessData(BaseProcessData):
"""
Groups by data by chosen columns (property group_bys_cols).
:data: A list of objects
:sort: boolean, if true python will sort the data
:return: A List of lists with group column and aggregation
"""
def apply(self, data, sort=True):
if sort:
data = sorted(data, key=self.attrgetter(*self.group_bys_cols))
Expand Down

0 comments on commit 93ec5f9

Please sign in to comment.