mirror of https://github.com/apache/superset.git
add combine config for metrics in pivot table (#3086)
* add combine config for metrics in pivot table * change method to stack/unstack * update backendSync
This commit is contained in:
parent
1e325d9645
commit
b58cfbcb91
|
@ -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",
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -337,7 +337,7 @@ export const visTypes = {
|
|||
controlSetRows: [
|
||||
['groupby', 'columns'],
|
||||
['metrics', 'pandas_aggfunc'],
|
||||
['number_format', 'pivot_margins'],
|
||||
['number_format', 'combine_metric', 'pivot_margins'],
|
||||
],
|
||||
},
|
||||
],
|
||||
|
|
|
@ -402,6 +402,9 @@ class PivotTableViz(BaseViz):
|
|||
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(
|
||||
|
|
Loading…
Reference in New Issue