Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add combine config for metrics in pivot table #3086

Merged
merged 4 commits into from
Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! that looks much better!

return dict(
columns=list(df.columns),
html=df.to_html(
Expand Down