Skip to content
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

[Lens] update default legend size to medium #130336

Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
1bd3e8a
update lens legend default to medium
drewdaemon Apr 13, 2022
348b793
Remove auto option when not currently selected
drewdaemon Apr 13, 2022
a6449c6
update legend size settings
drewdaemon Apr 14, 2022
43011c6
Add lens legend migration
drewdaemon Apr 14, 2022
a43e87a
Default legend size at expression level
drewdaemon Apr 15, 2022
f50405c
hide auto option and update default legend size for agg-based visuali…
drewdaemon Apr 15, 2022
bacdef6
update default legend sizes for aggs-based visualizations
drewdaemon Apr 15, 2022
07b6ba4
fn name update
drewdaemon Apr 15, 2022
75e5770
add migration for aggs-based visualizations
drewdaemon Apr 15, 2022
cbd7483
Add visualizations as required bundle for editor
drewdaemon Apr 18, 2022
f7079d2
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Apr 18, 2022
9e97779
add test for visualize SO migration
drewdaemon Apr 19, 2022
6e87e68
Merge branch '129474/default-legend-size-to-fixed-migrations-strategy…
drewdaemon Apr 19, 2022
e252436
test lens saved object migrations
drewdaemon Apr 19, 2022
c018293
update unit test
drewdaemon Apr 19, 2022
ce369ec
Merge branch 'main' into 129474/default-legend-size-to-fixed-migratio…
kibanamachine Apr 19, 2022
1be5bbf
update baseline screenshot for area chart
drewdaemon Apr 19, 2022
538742a
Merge branch '129474/default-legend-size-to-fixed-migrations-strategy…
drewdaemon Apr 19, 2022
7f879f1
Merge branch 'main' into 129474/default-legend-size-to-fixed-migratio…
kibanamachine Apr 20, 2022
0efec68
wait to hide auto option - lens
drewdaemon Apr 21, 2022
17140fc
Merge branch '129474/default-legend-size-to-fixed-migrations-strategy…
drewdaemon Apr 21, 2022
b876e1a
wait to hide auto option - visualize
drewdaemon Apr 21, 2022
8d47281
Merge branch 'main' of github.com:elastic/kibana into 129474/default-…
drewdaemon May 2, 2022
0089aa4
remove unused setters
drewdaemon May 2, 2022
44ea016
fix some checks
drewdaemon May 2, 2022
180c5e7
adjust visual test error margin
drewdaemon May 2, 2022
ecb8604
Merge branch 'main' into 129474/default-legend-size-to-fixed-migratio…
kibanamachine May 3, 2022
ea1218e
import default legend size and LegendSizes from visualizations plugin
drewdaemon May 3, 2022
0c019bf
Merge branch '129474/default-legend-size-to-fixed-migrations-strategy…
drewdaemon May 3, 2022
cfbed11
Merge branch 'main' of github.com:elastic/kibana into 129474/default-…
drewdaemon May 3, 2022
70d8605
Merge branch 'main' of github.com:elastic/kibana into 129474/default-…
drewdaemon May 3, 2022
01ba9b7
fix test
drewdaemon May 3, 2022
7c8d259
fix test
drewdaemon May 3, 2022
befa54f
allow for undefined params in visualization migration function
drewdaemon May 3, 2022
127fbd4
fix migration types
drewdaemon May 3, 2022
7b44734
more typing fixes
drewdaemon May 3, 2022
0e3a30d
Interpret auto as auto instead of 0
drewdaemon May 4, 2022
922b5a9
update baseline snapshot
drewdaemon May 4, 2022
3a3cf3a
Using strings for legend sizes
drewdaemon May 5, 2022
43a69e9
Merge branch 'main' of github.com:elastic/kibana into 129474/default-…
drewdaemon May 5, 2022
bf828cb
move legendSize default and pixel translation to expression layer
drewdaemon May 5, 2022
8c28bbc
update aggs-based
drewdaemon May 6, 2022
c4f118d
update some unit tests
drewdaemon May 6, 2022
58b4dcd
remove unused import
drewdaemon May 6, 2022
eb4588f
Merge branch 'main' of github.com:elastic/kibana into 129474/default-…
drewdaemon May 6, 2022
3332ce1
remove unused imports
drewdaemon May 6, 2022
701a66c
update snaps
drewdaemon May 6, 2022
cd85c83
update translation path
drewdaemon May 7, 2022
cee8d53
restore i18n string
drewdaemon May 9, 2022
9ee0704
remove unnecessary optional chaining operators
drewdaemon May 9, 2022
bc69ec8
Merge branch 'main' into 129474/default-legend-size-to-fixed-migratio…
kibanamachine May 9, 2022
d612e4d
Merge branch 'main' into 129474/default-legend-size-to-fixed-migratio…
kibanamachine May 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('interpreter/functions#pieVis', () => {
addTooltip: true,
legendDisplay: LegendDisplay.SHOW,
legendPosition: 'right',
legendSize: 80,
isDonut: true,
emptySizeRatio: EmptySizeRatios.SMALL,
nestedLegend: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export interface PieVisConfig extends VisCommonConfig {
respectSourceOrder?: boolean;
startFromSecondLargestSlice?: boolean;
distinctColors?: boolean;
legendSize?: number;
nestedLegend: boolean;
}

Expand Down
11 changes: 10 additions & 1 deletion src/plugins/vis_default_editor/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
"version": "kibana",
"ui": true,
"optionalPlugins": ["visualizations"],
"requiredBundles": ["unifiedSearch", "kibanaUtils", "kibanaReact", "data", "fieldFormats", "discover", "esUiShared"],
"requiredBundles": [
"unifiedSearch",
"kibanaUtils",
"kibanaReact",
"data",
"fieldFormats",
"discover",
"esUiShared",
"visualizations"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding visualizations as a required bundle is the salient change here

],
"owner": {
"name": "Vis Editors",
"githubTeam": "kibana-vis-editors"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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 { LegendSizeSettings } from './legend_size_settings';
import { LegendSizes, DEFAULT_LEGEND_SIZE } from '@kbn/visualizations-plugin/public';
import { EuiSuperSelect } from '@elastic/eui';
import { shallow } from 'enzyme';

describe('legend size settings', () => {
it('select is disabled if not vertical legend', () => {
const instance = shallow(
<LegendSizeSettings
legendSize={undefined}
onLegendSizeChange={() => {}}
isVerticalLegend={false}
showAutoOption={true}
/>
);

expect(instance.find(EuiSuperSelect).props().disabled).toBeTruthy();
});

it('reflects current setting in select', () => {
const CURRENT_SIZE = LegendSizes.SMALL;

const instance = shallow(
<LegendSizeSettings
legendSize={Number(CURRENT_SIZE)}
onLegendSizeChange={() => {}}
isVerticalLegend={true}
showAutoOption={true}
/>
);

expect(instance.find(EuiSuperSelect).props().valueOfSelected).toBe(CURRENT_SIZE.toString());
});

it('allows user to select a new option', () => {
const onSizeChange = jest.fn();

const instance = shallow(
<LegendSizeSettings
legendSize={Number(LegendSizes.SMALL)}
onLegendSizeChange={onSizeChange}
isVerticalLegend={true}
showAutoOption={true}
/>
);

const onChange = instance.find(EuiSuperSelect).props().onChange;

onChange(LegendSizes.EXTRA_LARGE);
onChange(DEFAULT_LEGEND_SIZE);

expect(onSizeChange).toHaveBeenNthCalledWith(1, Number(LegendSizes.EXTRA_LARGE));
expect(onSizeChange).toHaveBeenNthCalledWith(2, undefined);
});

it('hides "auto" option if visualization not using it', () => {
const getOptions = (showAutoOption: boolean) =>
shallow(
<LegendSizeSettings
legendSize={LegendSizes.LARGE}
onLegendSizeChange={() => {}}
isVerticalLegend={true}
showAutoOption={showAutoOption}
/>
)
.find(EuiSuperSelect)
.props().options;

const autoOption = expect.objectContaining({ value: LegendSizes.AUTO.toString() });

expect(getOptions(true)).toContainEqual(autoOption);
expect(getOptions(false)).not.toContainEqual(autoOption);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,11 @@ import React, { useCallback, useEffect } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiFormRow, EuiSuperSelect, EuiToolTip } from '@elastic/eui';
import { LegendSizes, DEFAULT_LEGEND_SIZE } from '@kbn/visualizations-plugin/public';

enum LegendSizes {
AUTO = '0',
SMALL = '80',
MEDIUM = '130',
LARGE = '180',
EXTRA_LARGE = '230',
}

const legendSizeOptions: Array<{ value: LegendSizes; inputDisplay: string }> = [
const legendSizeOptions: Array<{ value: string; inputDisplay: string }> = [
{
value: LegendSizes.AUTO,
inputDisplay: i18n.translate(
'visDefaultEditor.options.legendSizeSetting.legendSizeOptions.auto',
{
defaultMessage: 'Auto',
}
),
},
{
value: LegendSizes.SMALL,
value: LegendSizes.SMALL.toString(),
inputDisplay: i18n.translate(
'visDefaultEditor.options.legendSizeSetting.legendSizeOptions.small',
{
Expand All @@ -39,7 +23,7 @@ const legendSizeOptions: Array<{ value: LegendSizes; inputDisplay: string }> = [
),
},
{
value: LegendSizes.MEDIUM,
value: LegendSizes.MEDIUM.toString(),
inputDisplay: i18n.translate(
'visDefaultEditor.options.legendSizeSetting.legendSizeOptions.medium',
{
Expand All @@ -48,7 +32,7 @@ const legendSizeOptions: Array<{ value: LegendSizes; inputDisplay: string }> = [
),
},
{
value: LegendSizes.LARGE,
value: LegendSizes.LARGE.toString(),
inputDisplay: i18n.translate(
'visDefaultEditor.options.legendSizeSetting.legendSizeOptions.large',
{
Expand All @@ -57,7 +41,7 @@ const legendSizeOptions: Array<{ value: LegendSizes; inputDisplay: string }> = [
),
},
{
value: LegendSizes.EXTRA_LARGE,
value: LegendSizes.EXTRA_LARGE.toString(),
inputDisplay: i18n.translate(
'visDefaultEditor.options.legendSizeSetting.legendSizeOptions.extraLarge',
{
Expand All @@ -71,12 +55,14 @@ interface LegendSizeSettingsProps {
legendSize?: number;
onLegendSizeChange: (size?: number) => void;
isVerticalLegend: boolean;
showAutoOption: boolean;
}

export const LegendSizeSettings = ({
legendSize,
onLegendSizeChange,
isVerticalLegend,
showAutoOption,
}: LegendSizeSettingsProps) => {
useEffect(() => {
if (legendSize && !isVerticalLegend) {
Expand All @@ -85,16 +71,31 @@ export const LegendSizeSettings = ({
}, [isVerticalLegend, legendSize, onLegendSizeChange]);

const onLegendSizeOptionChange = useCallback(
(option) => onLegendSizeChange(Number(option) || undefined),
(option) => onLegendSizeChange(option === DEFAULT_LEGEND_SIZE ? undefined : Number(option)),
[onLegendSizeChange]
);

const options = showAutoOption
? [
{
value: LegendSizes.AUTO.toString(),
inputDisplay: i18n.translate(
'visDefaultEditor.options.legendSizeSetting.legendSizeOptions.auto',
{
defaultMessage: 'Auto',
}
),
},
...legendSizeOptions,
]
: legendSizeOptions;

const legendSizeSelect = (
<EuiSuperSelect
fullWidth
compressed
valueOfSelected={legendSize?.toString() ?? LegendSizes.AUTO}
options={legendSizeOptions}
valueOfSelected={legendSize?.toString() || DEFAULT_LEGEND_SIZE.toString()}
options={options}
onChange={onLegendSizeOptionChange}
disabled={!isVerticalLegend}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
LegendSizeSettings,
} from '@kbn/vis-default-editor-plugin/public';
import { colorSchemas } from '@kbn/charts-plugin/public';
import { VisEditorOptionsProps } from '@kbn/visualizations-plugin/public';
import { LegendSizes, VisEditorOptionsProps } from '@kbn/visualizations-plugin/public';
import { HeatmapVisParams, HeatmapTypeProps, ValueAxis } from '../../types';
import { LabelsPanel } from './labels_panel';
import { legendPositions, scaleTypes } from '../collections';
Expand All @@ -42,6 +42,9 @@ const HeatmapOptions = (props: HeatmapOptionsProps) => {
const isColorsNumberInvalid = stateParams.colorsNumber < 2 || stateParams.colorsNumber > 10;
const [isColorRangesValid, setIsColorRangesValid] = useState(false);

const legendSize = stateParams.legendSize;
const [hadAutoLegendSize] = useState(() => legendSize === LegendSizes.AUTO);

const setValueAxisScale = useCallback(
<T extends keyof ValueAxis['scale']>(paramName: T, value: ValueAxis['scale'][T]) =>
setValue('valueAxes', [
Expand Down Expand Up @@ -91,12 +94,13 @@ const HeatmapOptions = (props: HeatmapOptionsProps) => {
setValue={setValue}
/>
<LegendSizeSettings
legendSize={stateParams.legendSize}
legendSize={legendSize}
onLegendSizeChange={handleLegendSizeChange}
isVerticalLegend={
stateParams.legendPosition === Position.Left ||
stateParams.legendPosition === Position.Right
}
showAutoOption={hadAutoLegendSize}
/>
</>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/vis_types/heatmap/public/to_ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { VisToExpressionAst, getVisSchemas, SchemaConfig } from '@kbn/visualizations-plugin/public';
import { buildExpression, buildExpressionFunction } from '@kbn/expressions-plugin/public';
import { DEFAULT_LEGEND_SIZE } from '@kbn/visualizations-plugin/public';
import { getStopsWithColorsFromRanges, getStopsWithColorsFromColorsNumber } from './utils/palette';
import type { HeatmapVisParams } from './types';
import { getEsaggsFn } from './to_ast_esaggs';
Expand All @@ -20,7 +21,7 @@ const prepareLegend = (params: HeatmapVisParams) => {
position: params.legendPosition,
shouldTruncate: params.truncateLegend ?? true,
maxLines: params.maxLegendLines ?? 1,
legendSize: params.legendSize,
legendSize: params.legendSize ?? DEFAULT_LEGEND_SIZE,
});

return buildExpression([legend]);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/plugins/vis_types/pie/public/editor/components/pie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
LongLegendOptions,
LegendSizeSettings,
} from '@kbn/vis-default-editor-plugin/public';
import { VisEditorOptionsProps } from '@kbn/visualizations-plugin/public';
import { LegendSizes, VisEditorOptionsProps } from '@kbn/visualizations-plugin/public';
import {
PartitionVisParams,
LabelPositions,
Expand Down Expand Up @@ -97,6 +97,9 @@ const PieOptions = (props: PieOptionsProps) => {
const hasSplitChart = Boolean(aggs?.aggs?.find((agg) => agg.schema === 'split' && agg.enabled));
const segments = aggs?.aggs?.filter((agg) => agg.schema === 'segment' && agg.enabled) ?? [];

const legendSize = stateParams.legendSize;
const [hadAutoLegendSize] = useState(() => legendSize === LegendSizes.AUTO);

const getLegendDisplay = useCallback(
(isVisible: boolean) => (isVisible ? LegendDisplay.SHOW : LegendDisplay.HIDE),
[]
Expand Down Expand Up @@ -234,12 +237,13 @@ const PieOptions = (props: PieOptionsProps) => {
setValue={setValue}
/>
<LegendSizeSettings
legendSize={stateParams.legendSize}
legendSize={legendSize}
onLegendSizeChange={handleLegendSizeChange}
isVerticalLegend={
stateParams.legendPosition === Position.Left ||
stateParams.legendPosition === Position.Right
}
showAutoOption={hadAutoLegendSize}
/>
</>
)}
Expand Down
13 changes: 11 additions & 2 deletions src/plugins/vis_types/pie/public/to_ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
*/

import type { PaletteOutput } from '@kbn/coloring';
import { getVisSchemas, VisToExpressionAst, SchemaConfig } from '@kbn/visualizations-plugin/public';
import {
getVisSchemas,
VisToExpressionAst,
SchemaConfig,
DEFAULT_LEGEND_SIZE,
LegendSizes,
} from '@kbn/visualizations-plugin/public';
import { buildExpression, buildExpressionFunction } from '@kbn/expressions-plugin/public';
import {
PIE_VIS_EXPRESSION_NAME,
Expand Down Expand Up @@ -65,7 +71,10 @@ export const toExpressionAst: VisToExpressionAst<PartitionVisParams> = async (vi
nestedLegend: vis.params?.nestedLegend ?? false,
truncateLegend: vis.params.truncateLegend,
maxLegendLines: vis.params.maxLegendLines,
legendSize: vis.params.legendSize,
legendSize:
vis.params.legendSize === LegendSizes.AUTO
? undefined
: vis.params.legendSize ?? DEFAULT_LEGEND_SIZE,
distinctColors: vis.params?.distinctColors,
isDonut: vis.params.isDonut ?? false,
emptySizeRatio: vis.params.emptySizeRatio,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading