Skip to content

Commit

Permalink
move legendSize default and pixel translation to expression layer
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon committed May 5, 2022
1 parent 43a69e9 commit bf828cb
Show file tree
Hide file tree
Showing 24 changed files with 118 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { Position } from '@elastic/charts';
import { i18n } from '@kbn/i18n';
import type { ExpressionFunctionDefinition } from '@kbn/expressions-plugin/common';
import { DEFAULT_LEGEND_SIZE, LegendSize } from '@kbn/visualizations-plugin/common/constants';
import { EXPRESSION_HEATMAP_LEGEND_NAME } from '../constants';
import { HeatmapLegendConfig, HeatmapLegendConfigResult } from '../types';

Expand Down Expand Up @@ -52,10 +53,19 @@ export const heatmapLegendConfig: ExpressionFunctionDefinition<
}),
},
legendSize: {
types: ['number'],
types: ['string'],
default: DEFAULT_LEGEND_SIZE,
help: i18n.translate('expressionHeatmap.function.args.legendSize.help', {
defaultMessage: 'Specifies the legend size in pixels.',
defaultMessage: 'Specifies the legend size.',
}),
options: [
LegendSize.AUTO,
LegendSize.SMALL,
LegendSize.MEDIUM,
LegendSize.LARGE,
LegendSize.EXTRA_LARGE,
],
strict: true,
},
},
fn(input, args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import {
getAccessorByDimension,
getFormatByAccessor,
} from '@kbn/visualizations-plugin/common/utils';
import {
DEFAULT_LEGEND_SIZE,
LegendSizeToPixels,
} from '@kbn/visualizations-plugin/common/constants';
import type { HeatmapRenderProps, FilterEvent, BrushEvent } from '../../common';
import { applyPaletteParams, findMinMaxByColumnId, getSortPredicate } from './helpers';
import {
Expand Down Expand Up @@ -485,7 +489,7 @@ export const HeatmapComponent: FC<HeatmapRenderProps> = memo(
onElementClick={interactive ? (onElementClick as ElementClickListener) : undefined}
showLegend={showLegend ?? args.legend.isVisible}
legendPosition={args.legend.position}
legendSize={args.legend.legendSize}
legendSize={LegendSizeToPixels[args.legend.legendSize ?? DEFAULT_LEGEND_SIZE]}
legendColorPicker={uiState ? LegendColorPickerWrapper : undefined}
debugState={window._echDebugStateFlag ?? false}
tooltip={tooltip}
Expand Down

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

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

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

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 @@ -47,7 +47,7 @@ export const strings = {
}),
getLegendSizeArgHelp: () =>
i18n.translate('expressionPartitionVis.reusable.function.args.legendSizeHelpText', {
defaultMessage: 'Specifies the legend size in pixels',
defaultMessage: 'Specifies the legend size',
}),
getNestedLegendArgHelp: () =>
i18n.translate('expressionPartitionVis.reusable.function.args.nestedLegendHelpText', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { Position } from '@elastic/charts';
import { prepareLogTable, validateAccessor } from '@kbn/visualizations-plugin/common/utils';
import { DEFAULT_LEGEND_SIZE, LegendSize } from '@kbn/visualizations-plugin/common/constants';
import { LegendDisplay, PartitionVisParams } from '../types/expression_renderers';
import { ChartTypes, MosaicVisExpressionFunctionDefinition } from '../types';
import {
Expand Down Expand Up @@ -64,8 +65,17 @@ export const mosaicVisFunction = (): MosaicVisExpressionFunctionDefinition => ({
strict: true,
},
legendSize: {
types: ['number'],
types: ['string'],
default: DEFAULT_LEGEND_SIZE,
help: strings.getLegendSizeArgHelp(),
options: [
LegendSize.AUTO,
LegendSize.SMALL,
LegendSize.MEDIUM,
LegendSize.LARGE,
LegendSize.EXTRA_LARGE,
],
strict: true,
},
nestedLegend: {
types: ['boolean'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ValueFormats,
LegendDisplay,
} from '../types/expression_renderers';
import { ExpressionValueVisDimension } from '@kbn/visualizations-plugin/common';
import { ExpressionValueVisDimension, LegendSize } from '@kbn/visualizations-plugin/common';
import { Datatable } from '@kbn/expressions-plugin/common/expression_types/specs';
import { pieVisFunction } from './pie_vis_function';
import { PARTITION_LABELS_VALUE } from '../constants';
Expand All @@ -31,7 +31,7 @@ describe('interpreter/functions#pieVis', () => {
addTooltip: true,
legendDisplay: LegendDisplay.SHOW,
legendPosition: 'right',
legendSize: 80,
legendSize: LegendSize.SMALL,
isDonut: true,
emptySizeRatio: EmptySizeRatios.SMALL,
nestedLegend: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { Position } from '@elastic/charts';
import { prepareLogTable, validateAccessor } from '@kbn/visualizations-plugin/common/utils';
import { DEFAULT_LEGEND_SIZE, LegendSize } from '@kbn/visualizations-plugin/common/constants';
import { EmptySizeRatios, LegendDisplay, PartitionVisParams } from '../types/expression_renderers';
import { ChartTypes, PieVisExpressionFunctionDefinition } from '../types';
import {
Expand Down Expand Up @@ -64,8 +65,17 @@ export const pieVisFunction = (): PieVisExpressionFunctionDefinition => ({
strict: true,
},
legendSize: {
types: ['number'],
types: ['string'],
default: DEFAULT_LEGEND_SIZE,
help: strings.getLegendSizeArgHelp(),
options: [
LegendSize.AUTO,
LegendSize.SMALL,
LegendSize.MEDIUM,
LegendSize.LARGE,
LegendSize.EXTRA_LARGE,
],
strict: true,
},
nestedLegend: {
types: ['boolean'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { Position } from '@elastic/charts';
import { prepareLogTable, validateAccessor } from '@kbn/visualizations-plugin/common/utils';
import { DEFAULT_LEGEND_SIZE, LegendSize } from '@kbn/visualizations-plugin/common/constants';
import { LegendDisplay, PartitionVisParams } from '../types/expression_renderers';
import { ChartTypes, TreemapVisExpressionFunctionDefinition } from '../types';
import {
Expand Down Expand Up @@ -64,8 +65,17 @@ export const treemapVisFunction = (): TreemapVisExpressionFunctionDefinition =>
strict: true,
},
legendSize: {
types: ['number'],
types: ['string'],
default: DEFAULT_LEGEND_SIZE,
help: strings.getLegendSizeArgHelp(),
options: [
LegendSize.AUTO,
LegendSize.SMALL,
LegendSize.MEDIUM,
LegendSize.LARGE,
LegendSize.EXTRA_LARGE,
],
strict: true,
},
nestedLegend: {
types: ['boolean'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { Position } from '@elastic/charts';
import { prepareLogTable, validateAccessor } from '@kbn/visualizations-plugin/common/utils';
import { DEFAULT_LEGEND_SIZE, LegendSize } from '@kbn/visualizations-plugin/common/constants';
import { LegendDisplay, PartitionVisParams } from '../types/expression_renderers';
import { ChartTypes, WaffleVisExpressionFunctionDefinition } from '../types';
import {
Expand Down Expand Up @@ -63,8 +64,17 @@ export const waffleVisFunction = (): WaffleVisExpressionFunctionDefinition => ({
strict: true,
},
legendSize: {
types: ['number'],
types: ['string'],
default: DEFAULT_LEGEND_SIZE,
help: strings.getLegendSizeArgHelp(),
options: [
LegendSize.AUTO,
LegendSize.SMALL,
LegendSize.MEDIUM,
LegendSize.LARGE,
LegendSize.EXTRA_LARGE,
],
strict: true,
},
truncateLegend: {
types: ['boolean'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,28 @@ export type ExpressionValuePartitionLabels = ExpressionValueBoxed<
export type PieVisExpressionFunctionDefinition = ExpressionFunctionDefinition<
typeof PIE_VIS_EXPRESSION_NAME,
Datatable,
Omit<PieVisConfig, 'legendSize'> & { legendSize: number | undefined },
PieVisConfig,
ExpressionValueRender<RenderValue>
>;

export type TreemapVisExpressionFunctionDefinition = ExpressionFunctionDefinition<
typeof TREEMAP_VIS_EXPRESSION_NAME,
Datatable,
Omit<TreemapVisConfig, 'legendSize'> & { legendSize: number | undefined },
TreemapVisConfig,
ExpressionValueRender<RenderValue>
>;

export type MosaicVisExpressionFunctionDefinition = ExpressionFunctionDefinition<
typeof MOSAIC_VIS_EXPRESSION_NAME,
Datatable,
Omit<MosaicVisConfig, 'legendSize'> & { legendSize: number | undefined },
MosaicVisConfig,
ExpressionValueRender<RenderValue>
>;

export type WaffleVisExpressionFunctionDefinition = ExpressionFunctionDefinition<
typeof WAFFLE_VIS_EXPRESSION_NAME,
Datatable,
Omit<WaffleVisConfig, 'legendSize'> & { legendSize: number | undefined },
WaffleVisConfig,
ExpressionValueRender<RenderValue>
>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export interface PieVisConfig extends VisCommonConfig {
respectSourceOrder?: boolean;
startFromSecondLargestSlice?: boolean;
distinctColors?: boolean;
legendSize?: LegendSize;
nestedLegend: boolean;
}

Expand Down

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 @@ -22,7 +22,11 @@ import {
import { useEuiTheme } from '@elastic/eui';
import type { PaletteRegistry } from '@kbn/coloring';
import { LegendToggle, ChartsPluginSetup } from '@kbn/charts-plugin/public';
import type { PersistedState } from '@kbn/visualizations-plugin/public';
import {
DEFAULT_LEGEND_SIZE,
LegendSizeToPixels,
} from '@kbn/visualizations-plugin/common/constants';
import { PersistedState } from '@kbn/visualizations-plugin/public';
import { getColumnByAccessor } from '@kbn/visualizations-plugin/common/utils';
import {
Datatable,
Expand Down Expand Up @@ -387,7 +391,7 @@ const PartitionVisComponent = (props: PartitionVisComponentProps) => {
showLegend ?? shouldShowLegend(visType, visParams.legendDisplay, bucketColumns)
}
legendPosition={legendPosition}
legendSize={visParams.legendSize}
legendSize={LegendSizeToPixels[visParams.legendSize ?? DEFAULT_LEGEND_SIZE]}
legendMaxDepth={visParams.nestedLegend ? undefined : 1}
legendColorPicker={props.uiState ? LegendColorPickerWrapper : undefined}
flatLegend={flatLegend}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { HorizontalAlignment, Position, VerticalAlignment } from '@elastic/charts';
import { i18n } from '@kbn/i18n';
import { DEFAULT_LEGEND_SIZE, LegendSize } from '@kbn/visualizations-plugin/common/constants';
import { LEGEND_CONFIG } from '../constants';
import { LegendConfigFn } from '../types';

Expand Down Expand Up @@ -85,10 +86,19 @@ export const legendConfigFunction: LegendConfigFn = {
}),
},
legendSize: {
types: ['number'],
types: ['string'],
default: DEFAULT_LEGEND_SIZE,
help: i18n.translate('expressionXY.legendConfig.legendSize.help', {
defaultMessage: 'Specifies the legend size in pixels.',
defaultMessage: 'Specifies the legend size.',
}),
options: [
LegendSize.AUTO,
LegendSize.SMALL,
LegendSize.MEDIUM,
LegendSize.LARGE,
LegendSize.EXTRA_LARGE,
],
strict: true,
},
},
async fn(input, args, handlers) {
Expand Down
Loading

0 comments on commit bf828cb

Please sign in to comment.