Skip to content

Commit

Permalink
update default legend sizes for aggs-based visualizations
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon committed Apr 15, 2022
1 parent f50405c commit bacdef6
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 25 deletions.

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
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
{
Expand All @@ -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',
{
Expand All @@ -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',
{
Expand All @@ -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',
{
Expand Down Expand Up @@ -83,7 +74,7 @@ export const LegendSizeSettings = ({
);

const options =
legendSize?.toString() !== LegendSizes.AUTO
legendSize !== LegendSizes.AUTO
? legendSizeOptions
: [
{
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 @@ -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;

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.

9 changes: 7 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,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,
Expand Down Expand Up @@ -65,7 +70,7 @@ 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 ?? 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.

3 changes: 2 additions & 1 deletion src/plugins/vis_types/xy/public/to_ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -210,7 +211,7 @@ export const toExpressionAst: VisToExpressionAst<VisParams> = 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,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_types/xy/public/types/param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export interface XYVisConfig {
addTimeMarker: boolean;
truncateLegend: boolean;
maxLegendLines: number;
legendSize?: number;
legendSize: number;
orderBucketsBySum?: boolean;
labels: ExpressionValueLabel;
thresholdLine: ExpressionValueThresholdLine;
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/visualizations/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 2 additions & 0 deletions src/plugins/visualizations/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/lens/server/migrations/common_migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bacdef6

Please sign in to comment.