Skip to content

Commit

Permalink
[Lens] Add median operation (elastic#79453)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Oct 16, 2020
1 parent 2d1aa11 commit a39934f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ export function DimensionEditor(props: DimensionEditorProps) {
<EuiListGroup
className={sideNavItems.length > 3 ? 'lnsIndexPatternDimensionEditor__columns' : ''}
gutterSize="none"
listItems={sideNavItems}
listItems={
// add a padding item containing a non breakable space if the number of operations is not even
// otherwise the column layout will break within an element
sideNavItems.length % 2 === 1 ? [...sideNavItems, { label: '\u00a0' }] : sideNavItems
}
maxWidth={false}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -993,9 +993,11 @@ describe('IndexPatternDimensionEditorPanel', () => {
'Average',
'Count',
'Maximum',
'Median',
'Minimum',
'Sum',
'Unique count',
'\u00a0',
]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
SumIndexPatternColumn,
maxOperation,
MaxIndexPatternColumn,
medianOperation,
MedianIndexPatternColumn,
} from './metrics';
import { dateHistogramOperation, DateHistogramIndexPatternColumn } from './date_histogram';
import { countOperation, CountIndexPatternColumn } from './count';
Expand All @@ -43,6 +45,7 @@ export type IndexPatternColumn =
| AvgIndexPatternColumn
| CardinalityIndexPatternColumn
| SumIndexPatternColumn
| MedianIndexPatternColumn
| CountIndexPatternColumn;

export type FieldBasedIndexPatternColumn = Extract<IndexPatternColumn, { sourceField: string }>;
Expand All @@ -59,6 +62,7 @@ const internalOperationDefinitions = [
averageOperation,
cardinalityOperation,
sumOperation,
medianOperation,
countOperation,
rangeOperation,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export type SumIndexPatternColumn = MetricColumn<'sum'>;
export type AvgIndexPatternColumn = MetricColumn<'avg'>;
export type MinIndexPatternColumn = MetricColumn<'min'>;
export type MaxIndexPatternColumn = MetricColumn<'max'>;
export type MedianIndexPatternColumn = MetricColumn<'median'>;

export const minOperation = buildMetricOperation<MinIndexPatternColumn>({
type: 'min',
Expand Down Expand Up @@ -137,3 +138,15 @@ export const sumOperation = buildMetricOperation<SumIndexPatternColumn>({
values: { name },
}),
});

export const medianOperation = buildMetricOperation<MedianIndexPatternColumn>({
type: 'median',
displayName: i18n.translate('xpack.lens.indexPattern.median', {
defaultMessage: 'Median',
}),
ofName: (name) =>
i18n.translate('xpack.lens.indexPattern.medianOf', {
defaultMessage: 'Median of {name}',
values: { name },
}),
});
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,12 @@ describe('getOperationTypesForField', () => {
},
Object {
"field": "bytes",
"operationType": "min",
"operationType": "max",
"type": "field",
},
Object {
"field": "bytes",
"operationType": "max",
"operationType": "min",
"type": "field",
},
Object {
Expand All @@ -338,6 +338,11 @@ describe('getOperationTypesForField', () => {
"operationType": "cardinality",
"type": "field",
},
Object {
"field": "bytes",
"operationType": "median",
"type": "field",
},
],
},
]
Expand Down

0 comments on commit a39934f

Please sign in to comment.