Skip to content

Commit

Permalink
fix: Table visualization shows total for duration, percentage… (#54240)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbondyra authored Jan 9, 2020
1 parent 719ff25 commit 982df2e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,15 @@ export function KbnAggTable(config, RecursionHelper) {
}

const isDate =
_.get(dimension, 'format.id') === 'date' ||
_.get(dimension, 'format.params.id') === 'date';
const isNumeric =
_.get(dimension, 'format.id') === 'number' ||
_.get(dimension, 'format.params.id') === 'number';
dimension.format?.id === 'date' || dimension.format?.params?.id === 'date';
const allowsNumericalAggregations = formatter?.allowsNumericalAggregations;

let { totalFunc } = $scope;
if (typeof totalFunc === 'undefined' && showPercentage) {
totalFunc = 'sum';
}

if (isNumeric || isDate || totalFunc === 'count') {
if (allowsNumericalAggregations || isDate || totalFunc === 'count') {
const sum = tableRows => {
return _.reduce(
tableRows,
Expand All @@ -161,7 +158,6 @@ export function KbnAggTable(config, RecursionHelper) {
};

formattedColumn.sumTotal = sum(table.rows);

switch (totalFunc) {
case 'sum': {
if (!isDate) {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/field_formats/converters/bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export class BytesFormat extends NumeralFormat {

id = BytesFormat.id;
title = BytesFormat.title;
allowsNumericalAggregations = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export class DurationFormat extends FieldFormat {
static fieldType = KBN_FIELD_TYPES.NUMBER;
static inputFormats = inputFormats;
static outputFormats = outputFormats;
allowsNumericalAggregations = true;

isHuman() {
return this.param('outputFormat') === HUMAN_FRIENDLY;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/field_formats/converters/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export class NumberFormat extends NumeralFormat {

id = NumberFormat.id;
title = NumberFormat.title;
allowsNumericalAggregations = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class PercentFormat extends NumeralFormat {

id = PercentFormat.id;
title = PercentFormat.title;
allowsNumericalAggregations = true;

getParamDefaults = () => ({
pattern: this.getConfig!('format:percent:defaultPattern'),
Expand Down

0 comments on commit 982df2e

Please sign in to comment.