refactor total aggregations for table after review

This commit is contained in:
sonenko 2016-06-14 18:13:36 +03:00
parent 60e18b3de6
commit 9d61c8f207
3 changed files with 11 additions and 9 deletions

View file

@ -36,6 +36,6 @@
<select ng-disabled="!vis.params.showTotal"
class="form-control"
ng-model="vis.params.totalFunc"
ng-options="x for x in ['sum', 'avg', 'min', 'max', 'count']">
ng-options="x for x in totalAggregations">
</select>
</div>
</div>

View file

@ -8,6 +8,8 @@ uiModules.get('kibana/table_vis')
restrict: 'E',
template: tableVisParamsTemplate,
link: function ($scope) {
$scope.totalAggregations = ['sum', 'avg', 'min', 'max', 'count'];
$scope.$watchMulti([
'vis.params.showPartialRows',
'vis.params.showMeticsAtAllLevels'

View file

@ -95,20 +95,20 @@ uiModules
formattedColumn.class = 'visualize-table-right';
}
let isFirstValueNumeric =
table.rows && table.rows[0] && table.rows[0][i] && _.isNumber(table.rows[0][i].value);
const isFieldNumeric = (field && field.type === 'number');
const isFirstValueNumeric = _.isNumber(_.get(table, `rows[0][${i}].value`));
if ((field && field.type === 'number') || isFirstValueNumeric) {
function sum() {
return _.reduce(table.rows, function (prev, curr, n, all) {return prev + curr[i].value; }, 0);
if (isFieldNumeric || isFirstValueNumeric) {
function sum(tableRows) {
return _.reduce(tableRows, function (prev, curr, n, all) {return prev + curr[i].value; }, 0);
}
switch ($scope.totalFunc) {
case 'sum':
formattedColumn.total = sum();
formattedColumn.total = sum(table.rows);
break;
case 'avg':
formattedColumn.total = sum() / table.rows.length;
formattedColumn.total = sum(table.rows) / table.rows.length;
break;
case 'min':
formattedColumn.total = _.chain(table.rows).map(i).map('value').min().value();