forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Lens] Calculation operations (elastic#83789)
- Loading branch information
Showing
14 changed files
with
552 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
.../lens/public/indexpattern_datasource/operations/definitions/calculations/counter_rate.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedIndexPatternColumn, ReferenceBasedIndexPatternColumn } from '../column_types'; | ||
import { IndexPatternLayer } from '../../../types'; | ||
import { checkForDateHistogram, dateBasedOperationToExpression, hasDateField } from './utils'; | ||
import { OperationDefinition } from '..'; | ||
|
||
const ofName = (name?: string) => { | ||
return i18n.translate('xpack.lens.indexPattern.CounterRateOf', { | ||
defaultMessage: 'Counter rate of {name}', | ||
values: { | ||
name: | ||
name ?? | ||
i18n.translate('xpack.lens.indexPattern.incompleteOperation', { | ||
defaultMessage: '(incomplete)', | ||
}), | ||
}, | ||
}); | ||
}; | ||
|
||
export type CounterRateIndexPatternColumn = FormattedIndexPatternColumn & | ||
ReferenceBasedIndexPatternColumn & { | ||
operationType: 'counter_rate'; | ||
}; | ||
|
||
export const counterRateOperation: OperationDefinition< | ||
CounterRateIndexPatternColumn, | ||
'fullReference' | ||
> = { | ||
type: 'counter_rate', | ||
priority: 1, | ||
displayName: i18n.translate('xpack.lens.indexPattern.counterRate', { | ||
defaultMessage: 'Counter rate', | ||
}), | ||
input: 'fullReference', | ||
selectionStyle: 'field', | ||
requiredReferences: [ | ||
{ | ||
input: ['field'], | ||
specificOperations: ['max'], | ||
validateMetadata: (meta) => meta.dataType === 'number' && !meta.isBucketed, | ||
}, | ||
], | ||
getPossibleOperation: () => { | ||
return { | ||
dataType: 'number', | ||
isBucketed: false, | ||
scale: 'ratio', | ||
}; | ||
}, | ||
getDefaultLabel: (column, indexPattern, columns) => { | ||
return ofName(columns[column.references[0]]?.label); | ||
}, | ||
toExpression: (layer, columnId) => { | ||
return dateBasedOperationToExpression(layer, columnId, 'lens_counter_rate'); | ||
}, | ||
buildColumn: ({ referenceIds, previousColumn, layer }) => { | ||
const metric = layer.columns[referenceIds[0]]; | ||
return { | ||
label: ofName(metric?.label), | ||
dataType: 'number', | ||
operationType: 'counter_rate', | ||
isBucketed: false, | ||
scale: 'ratio', | ||
references: referenceIds, | ||
params: | ||
previousColumn?.dataType === 'number' && | ||
previousColumn.params && | ||
'format' in previousColumn.params && | ||
previousColumn.params.format | ||
? { format: previousColumn.params.format } | ||
: undefined, | ||
}; | ||
}, | ||
isTransferable: (column, newIndexPattern) => { | ||
return hasDateField(newIndexPattern); | ||
}, | ||
getErrorMessage: (layer: IndexPatternLayer) => { | ||
return checkForDateHistogram( | ||
layer, | ||
i18n.translate('xpack.lens.indexPattern.counterRate', { | ||
defaultMessage: 'Counter rate', | ||
}) | ||
); | ||
}, | ||
}; |
91 changes: 91 additions & 0 deletions
91
...ens/public/indexpattern_datasource/operations/definitions/calculations/cumulative_sum.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedIndexPatternColumn, ReferenceBasedIndexPatternColumn } from '../column_types'; | ||
import { IndexPatternLayer } from '../../../types'; | ||
import { checkForDateHistogram, dateBasedOperationToExpression } from './utils'; | ||
import { OperationDefinition } from '..'; | ||
|
||
const ofName = (name?: string) => { | ||
return i18n.translate('xpack.lens.indexPattern.cumulativeSumOf', { | ||
defaultMessage: 'Cumulative sum rate of {name}', | ||
values: { | ||
name: | ||
name ?? | ||
i18n.translate('xpack.lens.indexPattern.incompleteOperation', { | ||
defaultMessage: '(incomplete)', | ||
}), | ||
}, | ||
}); | ||
}; | ||
|
||
export type CumulativeSumIndexPatternColumn = FormattedIndexPatternColumn & | ||
ReferenceBasedIndexPatternColumn & { | ||
operationType: 'cumulative_sum'; | ||
}; | ||
|
||
export const cumulativeSumOperation: OperationDefinition< | ||
CumulativeSumIndexPatternColumn, | ||
'fullReference' | ||
> = { | ||
type: 'cumulative_sum', | ||
priority: 1, | ||
displayName: i18n.translate('xpack.lens.indexPattern.cumulativeSum', { | ||
defaultMessage: 'Cumulative sum', | ||
}), | ||
input: 'fullReference', | ||
selectionStyle: 'field', | ||
requiredReferences: [ | ||
{ | ||
input: ['field'], | ||
specificOperations: ['count', 'sum'], | ||
validateMetadata: (meta) => meta.dataType === 'number' && !meta.isBucketed, | ||
}, | ||
], | ||
getPossibleOperation: () => { | ||
return { | ||
dataType: 'number', | ||
isBucketed: false, | ||
scale: 'ratio', | ||
}; | ||
}, | ||
getDefaultLabel: (column, indexPattern, columns) => { | ||
return ofName(columns[column.references[0]]?.label); | ||
}, | ||
toExpression: (layer, columnId) => { | ||
return dateBasedOperationToExpression(layer, columnId, 'cumulative_sum'); | ||
}, | ||
buildColumn: ({ referenceIds, previousColumn, layer }) => { | ||
const metric = layer.columns[referenceIds[0]]; | ||
return { | ||
label: ofName(metric?.label), | ||
dataType: 'number', | ||
operationType: 'cumulative_sum', | ||
isBucketed: false, | ||
scale: 'ratio', | ||
references: referenceIds, | ||
params: | ||
previousColumn?.dataType === 'number' && | ||
previousColumn.params && | ||
'format' in previousColumn.params && | ||
previousColumn.params.format | ||
? { format: previousColumn.params.format } | ||
: undefined, | ||
}; | ||
}, | ||
isTransferable: () => { | ||
return true; | ||
}, | ||
getErrorMessage: (layer: IndexPatternLayer) => { | ||
return checkForDateHistogram( | ||
layer, | ||
i18n.translate('xpack.lens.indexPattern.cumulativeSum', { | ||
defaultMessage: 'Cumulative sum', | ||
}) | ||
); | ||
}, | ||
}; |
90 changes: 90 additions & 0 deletions
90
...ns/lens/public/indexpattern_datasource/operations/definitions/calculations/derivative.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedIndexPatternColumn, ReferenceBasedIndexPatternColumn } from '../column_types'; | ||
import { IndexPatternLayer } from '../../../types'; | ||
import { checkForDateHistogram, dateBasedOperationToExpression, hasDateField } from './utils'; | ||
import { OperationDefinition } from '..'; | ||
|
||
const ofName = (name?: string) => { | ||
return i18n.translate('xpack.lens.indexPattern.derivativeOf', { | ||
defaultMessage: 'Differences of {name}', | ||
values: { | ||
name: | ||
name ?? | ||
i18n.translate('xpack.lens.indexPattern.incompleteOperation', { | ||
defaultMessage: '(incomplete)', | ||
}), | ||
}, | ||
}); | ||
}; | ||
|
||
export type DerivativeIndexPatternColumn = FormattedIndexPatternColumn & | ||
ReferenceBasedIndexPatternColumn & { | ||
operationType: 'derivative'; | ||
}; | ||
|
||
export const derivativeOperation: OperationDefinition< | ||
DerivativeIndexPatternColumn, | ||
'fullReference' | ||
> = { | ||
type: 'derivative', | ||
priority: 1, | ||
displayName: i18n.translate('xpack.lens.indexPattern.derivative', { | ||
defaultMessage: 'Differences', | ||
}), | ||
input: 'fullReference', | ||
selectionStyle: 'full', | ||
requiredReferences: [ | ||
{ | ||
input: ['field'], | ||
validateMetadata: (meta) => meta.dataType === 'number' && !meta.isBucketed, | ||
}, | ||
], | ||
getPossibleOperation: () => { | ||
return { | ||
dataType: 'number', | ||
isBucketed: false, | ||
scale: 'ratio', | ||
}; | ||
}, | ||
getDefaultLabel: (column, indexPattern, columns) => { | ||
return ofName(columns[column.references[0]]?.label); | ||
}, | ||
toExpression: (layer, columnId) => { | ||
return dateBasedOperationToExpression(layer, columnId, 'derivative'); | ||
}, | ||
buildColumn: ({ referenceIds, previousColumn, layer }) => { | ||
const metric = layer.columns[referenceIds[0]]; | ||
return { | ||
label: ofName(metric?.label), | ||
dataType: 'number', | ||
operationType: 'derivative', | ||
isBucketed: false, | ||
scale: 'ratio', | ||
references: referenceIds, | ||
params: | ||
previousColumn?.dataType === 'number' && | ||
previousColumn.params && | ||
'format' in previousColumn.params && | ||
previousColumn.params.format | ||
? { format: previousColumn.params.format } | ||
: undefined, | ||
}; | ||
}, | ||
isTransferable: (column, newIndexPattern) => { | ||
return hasDateField(newIndexPattern); | ||
}, | ||
getErrorMessage: (layer: IndexPatternLayer) => { | ||
return checkForDateHistogram( | ||
layer, | ||
i18n.translate('xpack.lens.indexPattern.derivative', { | ||
defaultMessage: 'Differences', | ||
}) | ||
); | ||
}, | ||
}; |
10 changes: 10 additions & 0 deletions
10
.../plugins/lens/public/indexpattern_datasource/operations/definitions/calculations/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { counterRateOperation, CounterRateIndexPatternColumn } from './counter_rate'; | ||
export { cumulativeSumOperation, CumulativeSumIndexPatternColumn } from './cumulative_sum'; | ||
export { derivativeOperation, DerivativeIndexPatternColumn } from './derivative'; | ||
export { movingAverageOperation, MovingAverageIndexPatternColumn } from './moving_average'; |
Oops, something went wrong.