mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
refactor total aggregations for table after review
This commit is contained in:
parent
60e18b3de6
commit
9d61c8f207
3 changed files with 11 additions and 9 deletions
|
@ -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>
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue