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.
[Field formats] Correctly format numeric histograms outside Discover (e…
…lastic#91576) (elastic#93486) * [Field formats] Correctly format numeric histograms outside Discover * Fix types * Fix types * Fix failures * Fix merge issue * Fix tests * Fix i18n * Fix i18n * Add doc and fix integration Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
5ef8a6f
commit d740ddf
Showing
32 changed files
with
415 additions
and
81 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
51 changes: 51 additions & 0 deletions
51
src/plugins/data/common/field_formats/converters/histogram.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,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { FieldFormat } from '../field_format'; | ||
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types'; | ||
import { TextContextTypeConvert, FIELD_FORMAT_IDS } from '../types'; | ||
import { BytesFormat } from './bytes'; | ||
import { NumberFormat } from './number'; | ||
import { PercentFormat } from './percent'; | ||
|
||
export class HistogramFormat extends FieldFormat { | ||
static id = FIELD_FORMAT_IDS.HISTOGRAM; | ||
static fieldType = KBN_FIELD_TYPES.HISTOGRAM; | ||
static title = i18n.translate('data.fieldFormats.histogram.title', { | ||
defaultMessage: 'Histogram', | ||
}); | ||
|
||
id = HistogramFormat.id; | ||
title = HistogramFormat.title; | ||
allowsNumericalAggregations = true; | ||
|
||
// Nested internal formatter | ||
getParamDefaults() { | ||
return { | ||
id: 'number', | ||
params: {}, | ||
}; | ||
} | ||
|
||
textConvert: TextContextTypeConvert = (val) => { | ||
if (typeof val === 'number') { | ||
const subFormatId = this.param('id'); | ||
const SubFormat = | ||
subFormatId === 'bytes' | ||
? BytesFormat | ||
: subFormatId === 'percent' | ||
? PercentFormat | ||
: NumberFormat; | ||
const converter = new SubFormat(this.param('params'), this.getConfig); | ||
return converter.textConvert(val); | ||
} else { | ||
return JSON.stringify(val); | ||
} | ||
}; | ||
} |
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
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
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
Oops, something went wrong.