-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[XY, Pie] Long legend values support
- Loading branch information
Showing
29 changed files
with
257 additions
and
2 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
48 changes: 48 additions & 0 deletions
48
src/plugins/vis_default_editor/public/components/options/long_legend_options.test.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,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 { LongLegendOptions, LongLegendOptionsProps } from './long_legend_options'; | ||
import { EuiFieldNumber } from '@elastic/eui'; | ||
|
||
describe('LongLegendOptions', () => { | ||
let props: LongLegendOptionsProps; | ||
let component; | ||
beforeAll(() => { | ||
props = { | ||
truncateLegend: true, | ||
setValue: jest.fn(), | ||
}; | ||
}); | ||
|
||
it('renders the EuiFieldNumber', () => { | ||
component = mountWithIntl(<LongLegendOptions {...props} />); | ||
expect(component.find(EuiFieldNumber).length).toBe(1); | ||
}); | ||
|
||
it('should call setValue when value is changes in the number input', () => { | ||
component = mountWithIntl(<LongLegendOptions {...props} />); | ||
const numberField = component.find(EuiFieldNumber); | ||
numberField.props().onChange!(({ | ||
target: { | ||
value: 3, | ||
}, | ||
} as unknown) as React.ChangeEvent<HTMLInputElement>); | ||
|
||
expect(props.setValue).toHaveBeenCalledWith('maxLegendLines', 3); | ||
}); | ||
|
||
it('input number should be disabled when truncate is false', () => { | ||
props.truncateLegend = false; | ||
component = mountWithIntl(<LongLegendOptions {...props} />); | ||
const numberField = component.find(EuiFieldNumber); | ||
|
||
expect(numberField.props().disabled).toBeTruthy(); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
src/plugins/vis_default_editor/public/components/options/long_legend_options.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,64 @@ | ||
/* | ||
* 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 { EuiFieldNumber, EuiFormRow } from '@elastic/eui'; | ||
import { SwitchOption } from './switch'; | ||
|
||
export interface LongLegendOptionsProps { | ||
setValue: (paramName: 'maxLegendLines' | 'truncateLegend', value: boolean | number) => void; | ||
truncateLegend: boolean; | ||
maxLegendLines?: number; | ||
'data-test-subj'?: string; | ||
} | ||
|
||
function LongLegendOptions({ | ||
'data-test-subj': dataTestSubj, | ||
setValue, | ||
truncateLegend, | ||
maxLegendLines, | ||
}: LongLegendOptionsProps) { | ||
return ( | ||
<> | ||
<SwitchOption | ||
data-test-subj={dataTestSubj} | ||
label={i18n.translate('visDefaultEditor.options.longLegends.truncateLegendTextLabel', { | ||
defaultMessage: 'Truncate legend text', | ||
})} | ||
paramName="truncateLegend" | ||
value={truncateLegend} | ||
setValue={setValue} | ||
/> | ||
<EuiFormRow | ||
fullWidth | ||
label={ | ||
<FormattedMessage | ||
id="visDefaultEditor.options.longLegends.maxLegendLinesLabel" | ||
defaultMessage="Maximum legend lines" | ||
/> | ||
} | ||
> | ||
<EuiFieldNumber | ||
data-test-subj="timeSeriesEditorDataMaxLegendLines" | ||
value={maxLegendLines} | ||
min={1} | ||
max={5} | ||
fullWidth | ||
disabled={!Boolean(truncateLegend)} | ||
onChange={(e) => { | ||
setValue('maxLegendLines', Number(e.target.value)); | ||
}} | ||
/> | ||
</EuiFormRow> | ||
</> | ||
); | ||
} | ||
|
||
export { LongLegendOptions }; |
2 changes: 2 additions & 0 deletions
2
src/plugins/vis_type_pie/public/__snapshots__/pie_fn.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
6 changes: 6 additions & 0 deletions
6
src/plugins/vis_type_xy/public/__snapshots__/to_ast.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.