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 a bottom row that aggregates each metric column for table viz #920

Closed
wants to merge 10 commits into from
Closed
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
25 changes: 25 additions & 0 deletions caravel/assets/visualizations/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@ function tableVis(slice) {
return d;
});

var all_columns = form_data.all_columns;
if (all_columns == null || all_columns.length == 0) {
var sum_row = data.records.pop();
var tfoot = table.append('tfoot');
tfoot.append('tr')
.selectAll('th')
.data(data.columns).enter()
.append('th')
.text(function (d) {
return "Total " + d;
});
tfoot.append('tr')
.selectAll('td')
.data(data.columns).enter()
.append('td')
.text(function (d) {
var val = sum_row[d];
if (metrics.indexOf(d) >= 0) {
return slice.d3format(d, val);
} else {
return val;
}
});
}

table.append('tbody')
.selectAll('tr')
.data(data.records)
Expand Down
7 changes: 7 additions & 0 deletions caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,13 @@ def get_df(self, query_obj=None):
self.form_data.get("granularity") == "all" and
'timestamp' in df):
del df['timestamp']
metrics = self.form_data.get('metrics') or ['count']
metrics = list(set(metrics) & set(df.columns.values))
if len(metrics) > 0 and not self.form_data.get('all_columns'):
sum_metrics = df[metrics].sum()
df_sum = pd.DataFrame(data=sum_metrics).T
df_sum = df_sum.reindex(columns=df.columns, fill_value="-")
df = df.append(df_sum, ignore_index=True)
return df

def get_data(self):
Expand Down