Skip to content

Commit

Permalink
divide the types
Browse files Browse the repository at this point in the history
  • Loading branch information
mbondyra committed Apr 30, 2024
1 parent 8cd7dbb commit f28dd3e
Show file tree
Hide file tree
Showing 27 changed files with 93 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
import type { DataView } from '@kbn/data-views-plugin/public';
import type { SavedObjectReference } from '@kbn/core/server';
import { AxesSettingsConfig } from '@kbn/visualizations-plugin/common';
import type { LegendValue } from '@kbn/visualizations-plugin/common/constants';
import type { XYLegendValue } from '@kbn/visualizations-plugin/common/constants';
import type { Chart, ChartConfig, ChartLayer } from '../types';
import { DEFAULT_LAYER_ID } from '../utils';
import { XY_ID } from './constants';
Expand Down Expand Up @@ -131,7 +131,7 @@ export const getXYVisualizationState = (
isVisible: false,
position: 'right',
showSingleSeries: false,
legendStats: ['currentAndLastValue' as LegendValue.CurrentAndLastValue],
legendStats: ['currentAndLastValue' as XYLegendValue.CurrentAndLastValue],
},
valueLabels: 'show',
yLeftScale: 'linear',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
ValueFormats,
LegendDisplay,
} from '../types/expression_renderers';
import { ExpressionValueVisDimension, LegendValue } from '@kbn/visualizations-plugin/common';
import {
ExpressionValueVisDimension,
PartitionLegendValue,
} from '@kbn/visualizations-plugin/common';
import { Datatable } from '@kbn/expressions-plugin/common/expression_types/specs';
import { waffleVisFunction } from './waffle_vis_function';
import { PARTITION_LABELS_VALUE, PARTITION_VIS_RENDERER_NAME } from '../constants';
Expand All @@ -34,7 +37,7 @@ describe('interpreter/functions#waffleVis', () => {

const visConfig: WaffleVisConfig = {
addTooltip: true,
legendStats: [LegendValue.Value],
legendStats: [PartitionLegendValue.Value],
metricsToLabels: JSON.stringify({}),
legendDisplay: LegendDisplay.SHOW,
legendPosition: 'right',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import type { AllowedChartOverrides, AllowedSettingsOverrides } from '@kbn/chart
import type { PaletteOutput } from '@kbn/coloring';
import type { Datatable, DatatableColumn } from '@kbn/expressions-plugin/common';
import type { SerializedFieldFormat } from '@kbn/field-formats-plugin/common';
import type { ExpressionValueVisDimension, LegendValue } from '@kbn/visualizations-plugin/common';
import type {
ExpressionValueVisDimension,
PartitionLegendValue,
} from '@kbn/visualizations-plugin/common';
import type { LegendSize } from '@kbn/visualizations-plugin/public';
import {
type AllowedPartitionOverrides,
Expand Down Expand Up @@ -80,7 +83,7 @@ export interface PartitionVisParams extends VisCommonParams {
labels: LabelsParams;
palette: PaletteOutput;
isDonut?: boolean;
legendStats?: LegendValue[];
legendStats?: PartitionLegendValue[];
respectSourceOrder?: boolean;
emptySizeRatio?: EmptySizeRatios;
startFromSecondLargestSlice?: boolean;
Expand Down Expand Up @@ -110,7 +113,7 @@ export interface MosaicVisConfig

export interface WaffleVisConfig extends Omit<VisCommonConfig, 'buckets'> {
bucket?: ExpressionValueVisDimension | string;
legendStats?: LegendValue[];
legendStats?: PartitionLegendValue[];
}

export interface PartitionChartProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { Position } from '@elastic/charts';
import { ArgTypes } from '@storybook/addons';
import { LegendValue } from '@kbn/visualizations-plugin/common/constants';
import { PartitionLegendValue } from '@kbn/visualizations-plugin/common/constants';
import { EmptySizeRatios, LegendDisplay } from '../../../common';
import { ChartTypes } from '../../../common/types';

Expand Down Expand Up @@ -212,7 +212,7 @@ export const waffleArgTypes: ArgTypes = {
description: 'Legend stats',
type: { name: 'string', required: false },
table: { type: { summary: 'string' }, defaultValue: { summary: undefined } },
options: [LegendValue.Value],
options: [PartitionLegendValue.Value],
control: { type: 'select' },
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
} from '@kbn/expressions-plugin/public';
import type { FieldFormat } from '@kbn/field-formats-plugin/common';
import { getOverridesFor } from '@kbn/chart-expressions-common';
import { LegendValue } from '@kbn/visualizations-plugin/common/constants';
import { PartitionLegendValue } from '@kbn/visualizations-plugin/common/constants';
import { consolidateMetricColumns } from '../../common/utils';
import { DEFAULT_PERCENT_DECIMALS } from '../../common/constants';
import {
Expand Down Expand Up @@ -564,7 +564,7 @@ const PartitionVisComponent = (props: PartitionVisComponentProps) => {
legendColorPicker={props.uiState ? LegendColorPickerWrapper : undefined}
flatLegend={flatLegend}
legendSort={customLegendSort}
showLegendExtra={visParams.legendStats?.[0] === LegendValue.Value}
showLegendExtra={visParams.legendStats?.[0] === PartitionLegendValue.Value}
onElementClick={([elementEvent]) => {
// this cast is safe because we are rendering a partition chart
const [layerValues] = elementEvent as PartitionElementEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Datatable } from '@kbn/expressions-plugin/public';
import { LegendValue } from '@kbn/visualizations-plugin/common/constants';
import { PartitionLegendValue } from '@kbn/visualizations-plugin/common/constants';
import {
BucketColumns,
PartitionVisParams,
Expand Down Expand Up @@ -382,6 +382,6 @@ export const createMockWaffleParams = (): PartitionVisParams => {
},
],
},
legendStats: [LegendValue.Value],
legendStats: [PartitionLegendValue.Value],
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
DatatableColumnMeta,
ExpressionFunctionDefinition,
} from '@kbn/expressions-plugin/common';
import { LegendSize, LegendValue } from '@kbn/visualizations-plugin/common';
import { LegendSize, XYLegendValue } from '@kbn/visualizations-plugin/common';
import { EventAnnotationOutput } from '@kbn/event-annotation-plugin/common';
import { ExpressionValueVisDimension } from '@kbn/visualizations-plugin/common';

Expand Down Expand Up @@ -217,7 +217,7 @@ export interface LegendConfig {
/**
* metrics to display in the legend
*/
legendStats?: LegendValue[];
legendStats?: XYLegendValue[];
}

// Arguments to XY chart expression, with computed properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import { XYChart, XYChartRenderProps } from './xy_chart';
import { ExtendedDataLayerConfig, XYProps, AnnotationLayerConfigResult } from '../../common/types';
import { DataLayers } from './data_layers';
import { SplitChart } from './split_chart';
import { LegendSize, LegendValue } from '@kbn/visualizations-plugin/common';
import { LegendSize, XYLegendValue } from '@kbn/visualizations-plugin/common';
import type { LayerCellValueActions } from '../types';

const onClickValue = jest.fn();
Expand Down Expand Up @@ -744,7 +744,7 @@ describe('XYChart component', () => {
{...defaultProps}
args={{
...args,
legend: { ...args.legend, legendStats: [LegendValue.CurrentAndLastValue] },
legend: { ...args.legend, legendStats: [XYLegendValue.CurrentAndLastValue] },
}}
/>
);
Expand All @@ -760,7 +760,7 @@ describe('XYChart component', () => {
...args,
legend: {
...args.legend,
legendStats: [LegendValue.CurrentAndLastValue],
legendStats: [XYLegendValue.CurrentAndLastValue],
},
layers: [dateHistogramLayer],
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import {
import {
DEFAULT_LEGEND_SIZE,
LegendSizeToPixels,
LegendValue,
XYLegendValue,
} from '@kbn/visualizations-plugin/common/constants';
import { PersistedState } from '@kbn/visualizations-plugin/public';
import { getOverridesFor, ChartSizeSpec } from '@kbn/chart-expressions-common';
Expand Down Expand Up @@ -870,7 +870,7 @@ export function XYChart({
: undefined
}
showLegendExtra={
isHistogramViz && legend.legendStats?.[0] === LegendValue.CurrentAndLastValue
isHistogramViz && legend.legendStats?.[0] === XYLegendValue.CurrentAndLastValue
}
ariaLabel={args.ariaLabel}
ariaUseDefaultSummary={!args.ariaLabel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { LegendValue } from '@kbn/visualizations-plugin/common/constants';
import { PartitionLegendValue } from '@kbn/visualizations-plugin/common/constants';
import { getConfiguration } from '.';
import { samplePieVis } from '../../sample_vis.test.mocks';

Expand Down Expand Up @@ -39,7 +39,7 @@ describe('getConfiguration', () => {
percentDecimals: 2,
primaryGroups: ['bucket-1'],
secondaryGroups: [],
legendStats: [LegendValue.Value],
legendStats: [PartitionLegendValue.Value],
truncateLegend: true,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { LegendDisplay, PartitionVisParams } from '@kbn/expression-partition-vis-plugin/common';
import { LegendValue } from '@kbn/visualizations-plugin/common/constants';
import { PartitionLegendValue } from '@kbn/visualizations-plugin/common/constants';
import {
CategoryDisplayTypes,
NumberDisplayTypes,
Expand All @@ -28,7 +28,7 @@ const getLayers = (
const showValuesInLegend =
vis.params.labels.values ??
(vis.params.legendStats
? vis.params.legendStats?.[0] === LegendValue.Value
? vis.params.legendStats?.[0] === PartitionLegendValue.Value
: vis.type.visConfig.defaults.showValuesInLegend);

return [
Expand All @@ -50,7 +50,7 @@ const getLayers = (
vis.params.legendDisplay ??
vis.type.visConfig.defaults.legendDisplay,
legendPosition: vis.params.legendPosition ?? vis.type.visConfig.defaults.legendPosition,
legendStats: showValuesInLegend ? [LegendValue.Value] : undefined,
legendStats: showValuesInLegend ? [PartitionLegendValue.Value] : undefined,
nestedLegend: vis.params.nestedLegend ?? vis.type.visConfig.defaults.nestedLegend,
percentDecimals:
vis.params.labels.percentDecimals ?? vis.type.visConfig.defaults.labels.percentDecimals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
XYReferenceLineLayerConfig,
} from '@kbn/visualizations-plugin/common/convert_to_lens';
import { Vis } from '@kbn/visualizations-plugin/public';
import { LegendValue } from '@kbn/visualizations-plugin/common/constants';
import { XYLegendValue } from '@kbn/visualizations-plugin/common/constants';
import { Layer } from '..';
import { ChartType } from '../../../common';
import {
Expand Down Expand Up @@ -237,7 +237,7 @@ export const getConfiguration = (
maxLines: vis.params.maxLegendLines ?? vis.type.visConfig.defaults.maxLegendLines,
showSingleSeries: true,
legendStats: Boolean(vis.params.labels.show ?? vis.type.visConfig.defaults.labels?.show)
? [LegendValue.CurrentAndLastValue]
? [XYLegendValue.CurrentAndLastValue]
: undefined,
},
fittingFunction: fittingFunction
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/vis_types/xy/public/to_ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { buildExpression, buildExpressionFunction } from '@kbn/expressions-plugi
import { BUCKET_TYPES } from '@kbn/data-plugin/public';
import type { TimeRangeBounds } from '@kbn/data-plugin/common';
import type { PaletteOutput } from '@kbn/charts-plugin/common/expressions/palette/types';
import { LegendValue } from '@kbn/visualizations-plugin/common/constants';
import { XYLegendValue } from '@kbn/visualizations-plugin/common/constants';
import {
Dimensions,
Dimension,
Expand Down Expand Up @@ -48,7 +48,7 @@ const prepareLengend = (params: VisParams, legendSize?: LegendSize) => {
shouldTruncate: params.truncateLegend,
showSingleSeries: true,
legendSize,
legendStats: params.labels.show ? [LegendValue.CurrentAndLastValue] : undefined,
legendStats: params.labels.show ? [XYLegendValue.CurrentAndLastValue] : undefined,
});

return buildExpression([legend]);
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/visualizations/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export const SUPPORTED_AGGREGATIONS = [
...Object.values(BUCKET_TYPES),
] as const;

export enum LegendValue {
export enum XYLegendValue {
CurrentAndLastValue = 'currentAndLastValue',
}

export enum PartitionLegendValue {
Value = 'value',
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { HorizontalAlignment, LayoutDirection, Position, VerticalAlignment } fro
import { $Values } from '@kbn/utility-types';
import type { CustomPaletteParams, PaletteOutput } from '@kbn/coloring';
import { KibanaQueryOutput } from '@kbn/data-plugin/common';
import { LegendSize, LegendValue } from '../../constants';
import { LegendSize, XYLegendValue, PartitionLegendValue } from '../../constants';
import {
CategoryDisplayTypes,
PartitionChartTypes,
Expand Down Expand Up @@ -142,7 +142,7 @@ export interface LegendConfig {
maxLines?: number;
shouldTruncate?: boolean;
legendSize?: LegendSize;
legendStats?: LegendValue[];
legendStats?: XYLegendValue[];
}

export interface XYConfiguration {
Expand Down Expand Up @@ -238,7 +238,7 @@ export interface PartitionLayerState {
categoryDisplay: CategoryDisplayType;
legendDisplay: LegendDisplayType;
legendPosition?: Position;
legendStats?: LegendValue[];
legendStats?: PartitionLegendValue[];
nestedLegend?: boolean;
percentDecimals?: number;
emptySizeRatio?: number;
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/visualizations/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ export * from './expression_functions';
export * from './convert_to_lens';
export { convertToSchemaConfig } from './vis_schemas';

export { LegendSize, LegendSizeToPixels, DEFAULT_LEGEND_SIZE, LegendValue } from './constants';
export {
LegendSize,
LegendSizeToPixels,
DEFAULT_LEGEND_SIZE,
XYLegendValue,
PartitionLegendValue,
} from './constants';
4 changes: 2 additions & 2 deletions x-pack/plugins/lens/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { Position } from '@elastic/charts';
import type { $Values } from '@kbn/utility-types';
import { CustomPaletteParams, PaletteOutput, ColorMapping } from '@kbn/coloring';
import type { ColorMode } from '@kbn/charts-plugin/common';
import type { LegendSize, LegendValue } from '@kbn/visualizations-plugin/common/constants';
import type { LegendSize, PartitionLegendValue } from '@kbn/visualizations-plugin/common/constants';
import { CategoryDisplay, LegendDisplay, NumberDisplay, PieChartTypes } from './constants';
import { layerTypes } from './layer_types';
import { CollapseFunction } from './expressions';
Expand Down Expand Up @@ -64,7 +64,7 @@ export interface SharedPieLayerState {
categoryDisplay: CategoryDisplayType;
legendDisplay: LegendDisplayType;
legendPosition?: Position;
legendStats?: LegendValue[];
legendStats?: PartitionLegendValue[];
nestedLegend?: boolean;
percentDecimals?: number;
emptySizeRatio?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import {
import { Position, VerticalAlignment, HorizontalAlignment } from '@elastic/charts';
import { LegendSize } from '@kbn/visualizations-plugin/public';
import { useDebouncedValue } from '@kbn/visualization-ui-components';
import { LegendValue } from '@kbn/visualizations-plugin/common/constants';
import { XYLegendValue } from '@kbn/visualizations-plugin/common/constants';
import { ToolbarPopover, type ToolbarPopoverProps } from '../toolbar_popover';
import { LegendLocationSettings } from './location/legend_location_settings';
import { ColumnsNumberSetting } from './layout/columns_number_setting';
import { LegendSizeSettings } from './size/legend_size_settings';

export interface LegendSettingsPopoverProps {
export interface LegendSettingsPopoverProps<S = XYLegendValue> {
/**
* Determines the legend display options
*/
Expand Down Expand Up @@ -109,7 +109,7 @@ export interface LegendSettingsPopoverProps {
/**
* value in legend status
*/
legendStats?: LegendValue[];
legendStats?: S[];
/**
* Callback on value in legend status change
*/
Expand Down Expand Up @@ -182,7 +182,7 @@ const PANEL_STYLE = {
width: '500px',
};

export const LegendSettingsPopover: React.FunctionComponent<LegendSettingsPopoverProps> = ({
export function LegendSettingsPopover<T = XYLegendValue>({
legendOptions,
mode,
onDisplayChange,
Expand All @@ -209,7 +209,7 @@ export const LegendSettingsPopover: React.FunctionComponent<LegendSettingsPopove
legendSize,
onLegendSizeChange,
showAutoLegendSizeOption,
}) => {
}: LegendSettingsPopoverProps<T>) {
return (
<ToolbarPopover
title={i18n.translate('xpack.lens.shared.legendLabel', {
Expand Down Expand Up @@ -344,4 +344,4 @@ export const LegendSettingsPopover: React.FunctionComponent<LegendSettingsPopove
)}
</ToolbarPopover>
);
};
}
Loading

0 comments on commit f28dd3e

Please sign in to comment.