Skip to content

Commit

Permalink
add combine config for metrics in pivot table (#3086)
Browse files Browse the repository at this point in the history
* add combine config for metrics in pivot table

* change method to stack/unstack

* update backendSync
  • Loading branch information
roganw authored and mistercrunch committed Jul 28, 2017
1 parent 1e325d9 commit b58cfbc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions superset/assets/backendSync.json
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,12 @@
"default": false,
"description": "Sort bars by x labels."
},
"combine_metric": {
"type": "CheckboxControl",
"label": "Combine Metrics",
"default": false,
"description": "Display metrics side by side within each column, as opposed to each column being displayed side by side for each metric."
},
"show_controls": {
"type": "CheckboxControl",
"label": "Extra Controls",
Expand Down
8 changes: 8 additions & 0 deletions superset/assets/javascripts/explore/stores/controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ export const controls = {
description: 'Sort bars by x labels.',
},

combine_metric: {
type: 'CheckboxControl',
label: 'Combine Metrics',
default: false,
description: 'Display metrics side by side within each column, as ' +
'opposed to each column being displayed side by side for each metric.',
},

show_controls: {
type: 'CheckboxControl',
label: 'Extra Controls',
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/javascripts/explore/stores/visTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export const visTypes = {
controlSetRows: [
['groupby', 'columns'],
['metrics', 'pandas_aggfunc'],
['number_format', 'pivot_margins'],
['number_format', 'combine_metric', 'pivot_margins'],
],
},
],
Expand Down
3 changes: 3 additions & 0 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ def get_data(self, df):
aggfunc=self.form_data.get('pandas_aggfunc'),
margins=self.form_data.get('pivot_margins'),
)
# Display metrics side by side with each column
if self.form_data.get('combine_metric'):
df = df.stack(0).unstack()
return dict(
columns=list(df.columns),
html=df.to_html(
Expand Down

0 comments on commit b58cfbc

Please sign in to comment.