-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Control round and decimal places in Gauge Visualization when using aggregate functions like average #91293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Control round and decimal places in Gauge Visualization when using aggregate functions like average #91293
Changes from all commits
71fe33e
31d6702
03f193c
77b356e
813b1e3
553bb5d
26911f1
8270c43
0b3eedb
c7f99cf
7063469
80bb524
33c8c0c
1a5d9c3
30135b7
ce74a0b
025c5be
b8ede76
bdd9ee7
9ae6a34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * 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 React from 'react'; | ||
| import { mountWithIntl } from '@kbn/test/jest'; | ||
| import { PercentageModeOption, PercentageModeOptionProps } from './percentage_mode'; | ||
| import { EuiFieldText } from '@elastic/eui'; | ||
|
|
||
| describe('PercentageModeOption', () => { | ||
| let props: PercentageModeOptionProps; | ||
| let component; | ||
| beforeAll(() => { | ||
| props = { | ||
| percentageMode: true, | ||
| setValue: jest.fn(), | ||
| }; | ||
| }); | ||
|
|
||
| it('renders the EuiFieldText', () => { | ||
| component = mountWithIntl(<PercentageModeOption {...props} />); | ||
| expect(component.find(EuiFieldText).length).toBe(1); | ||
| }); | ||
|
|
||
| it('should call setValue when value was putted in fieldText', () => { | ||
| component = mountWithIntl(<PercentageModeOption {...props} />); | ||
| const fieldText = component.find(EuiFieldText); | ||
| fieldText.props().onChange!({ | ||
| target: { | ||
| value: '0.0%', | ||
| }, | ||
| } as React.ChangeEvent<HTMLInputElement>); | ||
|
|
||
| expect(props.setValue).toHaveBeenCalledWith('percentageFormatPattern', '0.0%'); | ||
| }); | ||
|
|
||
| it('fieldText should be disabled when percentageMode is false', () => { | ||
| props.percentageMode = false; | ||
| component = mountWithIntl(<PercentageModeOption {...props} />); | ||
| const fieldText = component.find(EuiFieldText); | ||
|
|
||
| expect(fieldText.props().disabled).toBeTruthy(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * 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 React from 'react'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { FormattedMessage } from '@kbn/i18n/react'; | ||
| import { EuiFieldText, EuiFormRow, EuiLink } from '@elastic/eui'; | ||
| import { SwitchOption } from './switch'; | ||
| import { useKibana } from '../../../../kibana_react/public'; | ||
| import { UI_SETTINGS } from '../../../../data/public'; | ||
|
|
||
| export interface PercentageModeOptionProps { | ||
| setValue: ( | ||
| paramName: 'percentageMode' | 'percentageFormatPattern', | ||
| value: boolean | string | undefined | ||
| ) => void; | ||
| percentageMode: boolean; | ||
| formatPattern?: string; | ||
| 'data-test-subj'?: string; | ||
| } | ||
|
|
||
| function PercentageModeOption({ | ||
| 'data-test-subj': dataTestSubj, | ||
| setValue, | ||
| percentageMode, | ||
| formatPattern, | ||
| }: PercentageModeOptionProps) { | ||
| const { services } = useKibana(); | ||
| const defaultPattern = services.uiSettings?.get(UI_SETTINGS.FORMAT_PERCENT_DEFAULT_PATTERN); | ||
|
|
||
| return ( | ||
| <> | ||
| <SwitchOption | ||
| data-test-subj={dataTestSubj} | ||
| label={i18n.translate('visDefaultEditor.options.percentageMode.percentageModeLabel', { | ||
| defaultMessage: 'Percentage mode', | ||
| })} | ||
| paramName="percentageMode" | ||
| value={percentageMode} | ||
| setValue={setValue} | ||
| /> | ||
| <EuiFormRow | ||
| fullWidth | ||
| label={ | ||
| <FormattedMessage | ||
| id="visDefaultEditor.options.percentageMode.numeralLabel" | ||
| defaultMessage="Format pattern" | ||
| /> | ||
| } | ||
| helpText={ | ||
| <EuiLink target="_blank" href="https://adamwdraper.github.io/Numeral-js/"> | ||
| <FormattedMessage | ||
| id="visDefaultEditor.options.percentageMode.documentationLabel" | ||
| defaultMessage="Numeral.js documentation" | ||
| /> | ||
| </EuiLink> | ||
| } | ||
| > | ||
| <EuiFieldText | ||
| fullWidth | ||
|
VladLasitsa marked this conversation as resolved.
|
||
| compressed | ||
| data-test-subj={`${dataTestSubj}FormatPattern`} | ||
| value={formatPattern || ''} | ||
| placeholder={defaultPattern} | ||
| onChange={(e) => { | ||
| setValue('percentageFormatPattern', e.target.value ? e.target.value : undefined); | ||
| }} | ||
| disabled={!percentageMode} | ||
| /> | ||
| </EuiFormRow> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| export { PercentageModeOption }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,7 +78,10 @@ export const toExpressionAst = async <TVisParams extends VisParams>( | |
| } | ||
| } | ||
| if (visConfig?.gauge?.percentageMode === true) { | ||
| yDimension.format = { id: 'percent' }; | ||
| yDimension.format = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a question because it is not clear to me, don't we need to also do it for heatmap?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't use it for heatmap. Only in gauge.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But the percentage mode also exists for heatmaps too 🤔 |
||
| id: 'percent', | ||
| params: { pattern: visConfig?.gauge?.percentageFormatPattern }, | ||
| }; | ||
| } | ||
| }); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.