diff --git a/src/plugins/chart_expressions/expression_partition_vis/common/expression_functions/__snapshots__/pie_vis_function.test.ts.snap b/src/plugins/chart_expressions/expression_partition_vis/common/expression_functions/__snapshots__/pie_vis_function.test.ts.snap index 28d5f35c89cbf..fa82b14c33eea 100644 --- a/src/plugins/chart_expressions/expression_partition_vis/common/expression_functions/__snapshots__/pie_vis_function.test.ts.snap +++ b/src/plugins/chart_expressions/expression_partition_vis/common/expression_functions/__snapshots__/pie_vis_function.test.ts.snap @@ -112,7 +112,7 @@ Object { }, "legendDisplay": "show", "legendPosition": "right", - "legendSize": undefined, + "legendSize": 80, "maxLegendLines": 2, "metric": Object { "accessor": 0, @@ -246,7 +246,7 @@ Object { }, "legendDisplay": "show", "legendPosition": "right", - "legendSize": undefined, + "legendSize": 80, "maxLegendLines": 2, "metric": Object { "accessor": 0, diff --git a/src/plugins/chart_expressions/expression_partition_vis/common/expression_functions/pie_vis_function.test.ts b/src/plugins/chart_expressions/expression_partition_vis/common/expression_functions/pie_vis_function.test.ts index 366683ce80ddb..c4b2fc1670ca0 100644 --- a/src/plugins/chart_expressions/expression_partition_vis/common/expression_functions/pie_vis_function.test.ts +++ b/src/plugins/chart_expressions/expression_partition_vis/common/expression_functions/pie_vis_function.test.ts @@ -31,6 +31,7 @@ describe('interpreter/functions#pieVis', () => { addTooltip: true, legendDisplay: LegendDisplay.SHOW, legendPosition: 'right', + legendSize: 80, isDonut: true, emptySizeRatio: EmptySizeRatios.SMALL, nestedLegend: true, diff --git a/src/plugins/chart_expressions/expression_partition_vis/common/types/expression_renderers.ts b/src/plugins/chart_expressions/expression_partition_vis/common/types/expression_renderers.ts index 7ac7e9deedc20..c5b7b6b16e454 100644 --- a/src/plugins/chart_expressions/expression_partition_vis/common/types/expression_renderers.ts +++ b/src/plugins/chart_expressions/expression_partition_vis/common/types/expression_renderers.ts @@ -84,6 +84,7 @@ export interface PieVisConfig extends VisCommonConfig { respectSourceOrder?: boolean; startFromSecondLargestSlice?: boolean; distinctColors?: boolean; + legendSize: number; nestedLegend: boolean; } diff --git a/src/plugins/vis_default_editor/public/components/options/legend_size_settings.test.tsx b/src/plugins/vis_default_editor/public/components/options/legend_size_settings.test.tsx index cc334bfaca503..d23cc24881fb9 100644 --- a/src/plugins/vis_default_editor/public/components/options/legend_size_settings.test.tsx +++ b/src/plugins/vis_default_editor/public/components/options/legend_size_settings.test.tsx @@ -7,7 +7,8 @@ */ import React from 'react'; -import { DEFAULT_LEGEND_SIZE, LegendSizes, LegendSizeSettings } from './legend_size_settings'; +import { LegendSizeSettings } from './legend_size_settings'; +import { LegendSizes, DEFAULT_LEGEND_SIZE } from '../../../../visualizations/public'; import { EuiSuperSelect } from '@elastic/eui'; import { shallow } from 'enzyme'; diff --git a/src/plugins/vis_default_editor/public/components/options/legend_size_settings.tsx b/src/plugins/vis_default_editor/public/components/options/legend_size_settings.tsx index 63efb13a8a8bd..3687eb1eb8fb7 100644 --- a/src/plugins/vis_default_editor/public/components/options/legend_size_settings.tsx +++ b/src/plugins/vis_default_editor/public/components/options/legend_size_settings.tsx @@ -10,20 +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 '../../../../visualizations/public'; -export enum LegendSizes { - AUTO = '0', - SMALL = '80', - MEDIUM = '130', - LARGE = '180', - EXTRA_LARGE = '230', -} - -export const DEFAULT_LEGEND_SIZE = Number(LegendSizes.MEDIUM); - -const legendSizeOptions: Array<{ value: LegendSizes; inputDisplay: string }> = [ +const legendSizeOptions: Array<{ value: string; inputDisplay: string }> = [ { - value: LegendSizes.SMALL, + value: LegendSizes.SMALL.toString(), inputDisplay: i18n.translate( 'visDefaultEditor.options.legendSizeSetting.legendSizeOptions.small', { @@ -32,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', { @@ -41,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', { @@ -50,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', { @@ -83,7 +74,7 @@ export const LegendSizeSettings = ({ ); const options = - legendSize?.toString() !== LegendSizes.AUTO + legendSize !== LegendSizes.AUTO ? legendSizeOptions : [ { diff --git a/src/plugins/vis_types/heatmap/public/to_ast.ts b/src/plugins/vis_types/heatmap/public/to_ast.ts index d6dc8a8038591..85fad86663486 100644 --- a/src/plugins/vis_types/heatmap/public/to_ast.ts +++ b/src/plugins/vis_types/heatmap/public/to_ast.ts @@ -11,6 +11,7 @@ import { buildExpression, buildExpressionFunction } from '../../../expressions/p import { getStopsWithColorsFromRanges, getStopsWithColorsFromColorsNumber } from './utils/palette'; import type { HeatmapVisParams } from './types'; import { getEsaggsFn } from './to_ast_esaggs'; +import { DEFAULT_LEGEND_SIZE } from '../../../visualizations/public'; const DEFAULT_PERCENT_DECIMALS = 2; @@ -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]); diff --git a/src/plugins/vis_types/pie/public/__snapshots__/to_ast.test.ts.snap b/src/plugins/vis_types/pie/public/__snapshots__/to_ast.test.ts.snap index 904dff6ee1192..89863518c2f14 100644 --- a/src/plugins/vis_types/pie/public/__snapshots__/to_ast.test.ts.snap +++ b/src/plugins/vis_types/pie/public/__snapshots__/to_ast.test.ts.snap @@ -93,6 +93,9 @@ Object { "legendPosition": Array [ "right", ], + "legendSize": Array [ + 130, + ], "metric": Array [ Object { "chain": Array [ diff --git a/src/plugins/vis_types/pie/public/to_ast.ts b/src/plugins/vis_types/pie/public/to_ast.ts index 37f01fcc59340..1ce6d522506d0 100644 --- a/src/plugins/vis_types/pie/public/to_ast.ts +++ b/src/plugins/vis_types/pie/public/to_ast.ts @@ -7,7 +7,12 @@ */ import type { PaletteOutput } from '@kbn/coloring'; -import { getVisSchemas, VisToExpressionAst, SchemaConfig } from '../../../visualizations/public'; +import { + getVisSchemas, + VisToExpressionAst, + SchemaConfig, + DEFAULT_LEGEND_SIZE, +} from '../../../visualizations/public'; import { buildExpression, buildExpressionFunction } from '../../../expressions/public'; import { PIE_VIS_EXPRESSION_NAME, @@ -65,7 +70,7 @@ export const toExpressionAst: VisToExpressionAst = async (vi nestedLegend: vis.params?.nestedLegend ?? false, truncateLegend: vis.params.truncateLegend, maxLegendLines: vis.params.maxLegendLines, - legendSize: vis.params.legendSize, + legendSize: vis.params.legendSize ?? DEFAULT_LEGEND_SIZE, distinctColors: vis.params?.distinctColors, isDonut: vis.params.isDonut ?? false, emptySizeRatio: vis.params.emptySizeRatio, diff --git a/src/plugins/vis_types/xy/public/__snapshots__/to_ast.test.ts.snap b/src/plugins/vis_types/xy/public/__snapshots__/to_ast.test.ts.snap index 7ee1b0d2b2053..6505b5e6250b8 100644 --- a/src/plugins/vis_types/xy/public/__snapshots__/to_ast.test.ts.snap +++ b/src/plugins/vis_types/xy/public/__snapshots__/to_ast.test.ts.snap @@ -32,6 +32,9 @@ Object { "legendPosition": Array [ "top", ], + "legendSize": Array [ + 130, + ], "maxLegendLines": Array [ 1, ], diff --git a/src/plugins/vis_types/xy/public/to_ast.ts b/src/plugins/vis_types/xy/public/to_ast.ts index 0046a6f89a6d5..2f9bcec7f1209 100644 --- a/src/plugins/vis_types/xy/public/to_ast.ts +++ b/src/plugins/vis_types/xy/public/to_ast.ts @@ -13,6 +13,7 @@ import { getVisSchemas, DateHistogramParams, HistogramParams, + DEFAULT_LEGEND_SIZE, } from '../../../visualizations/public'; import { buildExpression, buildExpressionFunction } from '../../../expressions/public'; import { BUCKET_TYPES } from '../../../data/public'; @@ -210,7 +211,7 @@ export const toExpressionAst: VisToExpressionAst = async (vis, params addTimeMarker: vis.params.addTimeMarker, truncateLegend: vis.params.truncateLegend, maxLegendLines: vis.params.maxLegendLines, - legendSize: vis.params.legendSize, + legendSize: vis.params.legendSize ?? DEFAULT_LEGEND_SIZE, addLegend: vis.params.addLegend, addTooltip: vis.params.addTooltip, legendPosition: vis.params.legendPosition, diff --git a/src/plugins/vis_types/xy/public/types/param.ts b/src/plugins/vis_types/xy/public/types/param.ts index c0913226f9614..f45d35cf0923f 100644 --- a/src/plugins/vis_types/xy/public/types/param.ts +++ b/src/plugins/vis_types/xy/public/types/param.ts @@ -165,7 +165,7 @@ export interface XYVisConfig { addTimeMarker: boolean; truncateLegend: boolean; maxLegendLines: number; - legendSize?: number; + legendSize: number; orderBucketsBySum?: boolean; labels: ExpressionValueLabel; thresholdLine: ExpressionValueThresholdLine; diff --git a/src/plugins/visualizations/common/constants.ts b/src/plugins/visualizations/common/constants.ts index 0b840c8ff13fc..48382fe80e487 100644 --- a/src/plugins/visualizations/common/constants.ts +++ b/src/plugins/visualizations/common/constants.ts @@ -26,3 +26,13 @@ export const VisualizeConstants = { EDIT_BY_VALUE_PATH: '/edit_by_value', APP_ID: 'visualize', }; + +export const LegendSizes = { + AUTO: 0, + SMALL: 80, + MEDIUM: 130, + LARGE: 180, + EXTRA_LARGE: 230, +} as const; + +export const DEFAULT_LEGEND_SIZE = LegendSizes.MEDIUM; diff --git a/src/plugins/visualizations/public/index.ts b/src/plugins/visualizations/public/index.ts index 73f02a44dac13..62c32e4a539a7 100644 --- a/src/plugins/visualizations/public/index.ts +++ b/src/plugins/visualizations/public/index.ts @@ -56,6 +56,8 @@ export { VISUALIZE_ENABLE_LABS_SETTING, SAVED_OBJECTS_LIMIT_SETTING, SAVED_OBJECTS_PER_PAGE_SETTING, + LegendSizes, + DEFAULT_LEGEND_SIZE, } from '../common/constants'; export type { SavedVisState, VisParams, Dimension } from '../common'; export { prepareLogTable } from '../common'; diff --git a/x-pack/plugins/lens/server/migrations/common_migrations.ts b/x-pack/plugins/lens/server/migrations/common_migrations.ts index 5c17e95af2a00..fdf0382eaa318 100644 --- a/x-pack/plugins/lens/server/migrations/common_migrations.ts +++ b/x-pack/plugins/lens/server/migrations/common_migrations.ts @@ -8,7 +8,6 @@ import { cloneDeep, mapValues } from 'lodash'; import type { PaletteOutput, CustomPaletteParams } from '@kbn/coloring'; import { SerializableRecord } from '@kbn/utility-types'; -import { LegendConfig as XYLegendConfig } from '../../../../../src/plugins/chart_expressions/expression_xy/common'; import { mergeMigrationFunctionMaps, MigrateFunction,