Skip to content

Commit 3a0ed5c

Browse files
authored
[Lens as code] unify legend schemas (elastic#260034)
## Summary Close elastic#258612 - unifies legend visibility schemas: elastic@ee1a916 - removes `position` from the API schema for heatmaps elastic@7ec24f8 - unifies legend size elastic@d190721 ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
1 parent 23b0201 commit 3a0ed5c

10 files changed

Lines changed: 30 additions & 31 deletions

File tree

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/heatmap.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@ import {
2222
legendTruncateAfterLinesSchema,
2323
} from '../shared';
2424
import {
25+
baseLegendVisibilitySchema,
2526
legendSizeSchema,
2627
mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps,
2728
xScaleSchema,
2829
} from './shared';
29-
import { positionSchema } from '../alignments';
3030
import { builderEnums } from '../enums';
3131
import { bucketOperationDefinitionSchema } from '../bucket_ops';
3232

3333
const legendSchemaProps = {
3434
truncate_after_lines: legendTruncateAfterLinesSchema,
35-
visible: schema.maybe(schema.boolean({ meta: { description: 'Show the legend' } })),
35+
visibility: baseLegendVisibilitySchema,
3636
size: legendSizeSchema,
37-
position: schema.maybe(positionSchema({ meta: { description: 'Legend position' } })),
3837
};
3938

4039
const labelsSchemaProps = {

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ import {
1919
legendTruncateAfterLinesSchema,
2020
sharedPanelInfoSchema,
2121
} from '../shared';
22-
import { legendNestedSchema, legendVisibilitySchema, valueDisplaySchema } from './partition_shared';
22+
import { legendNestedSchema, valueDisplaySchema } from './partition_shared';
2323
import {
2424
legendSizeSchema,
25+
legendVisibilitySchemaWithAuto,
2526
mergeAllBucketsWithChartDimensionSchema,
2627
mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps,
2728
} from './shared';
@@ -33,7 +34,7 @@ const mosaicStateSharedSchema = {
3334
{
3435
nested: legendNestedSchema,
3536
truncate_after_lines: legendTruncateAfterLinesSchema,
36-
visibility: legendVisibilitySchema,
37+
visibility: legendVisibilitySchemaWithAuto,
3738
size: legendSizeSchema,
3839
},
3940
{

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/partition_shared.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ import { schema } from '@kbn/config-schema';
1111
import type { ColorMappingType, StaticColorType } from '../color';
1212
import { groupIsNotCollapsed } from '../../utils';
1313

14-
export const legendVisibilitySchema = schema.maybe(
15-
schema.oneOf([schema.literal('auto'), schema.literal('visible'), schema.literal('hidden')], {
16-
meta: { description: 'Legend visibility' },
17-
})
18-
);
19-
2014
export const valueDisplaySchema = schema.maybe(
2115
schema.object(
2216
{

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ import {
2121
} from '../shared';
2222
import {
2323
legendSizeSchema,
24+
legendVisibilitySchemaWithAuto,
2425
mergeAllBucketsWithChartDimensionSchema,
2526
mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps,
2627
} from './shared';
2728
import type { PartitionMetric } from './partition_shared';
2829
import {
2930
legendNestedSchema,
30-
legendVisibilitySchema,
3131
validateColoringAssignments,
3232
valueDisplaySchema,
3333
} from './partition_shared';
@@ -42,7 +42,7 @@ const pieStateSharedSchema = {
4242
{
4343
nested: legendNestedSchema,
4444
truncate_after_lines: legendTruncateAfterLinesSchema,
45-
visibility: legendVisibilitySchema,
45+
visibility: legendVisibilitySchemaWithAuto,
4646
size: legendSizeSchema,
4747
},
4848
{

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/shared.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ import {
3232
bucketFiltersOperationSchema,
3333
} from '../bucket_ops';
3434

35+
export const baseLegendVisibilitySchema = schema.maybe(
36+
schema.oneOf([schema.literal('visible'), schema.literal('hidden')], {
37+
meta: { description: 'Legend visibility' },
38+
})
39+
);
40+
41+
export const legendVisibilitySchemaWithAuto = schema.maybe(
42+
schema.oneOf([schema.literal('auto'), schema.literal('visible'), schema.literal('hidden')], {
43+
meta: { description: 'Legend visibility' },
44+
})
45+
);
46+
3547
export const legendSizeSchema = schema.maybe(
3648
schema.oneOf(
3749
[

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import {
2323
import type { PartitionMetric } from './partition_shared';
2424
import {
2525
legendNestedSchema,
26-
legendVisibilitySchema,
2726
validateColoringAssignments,
2827
valueDisplaySchema,
2928
} from './partition_shared';
3029
import {
3130
legendSizeSchema,
31+
legendVisibilitySchemaWithAuto,
3232
mergeAllBucketsWithChartDimensionSchema,
3333
mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps,
3434
} from './shared';
@@ -40,7 +40,7 @@ const treemapSharedStateSchema = {
4040
{
4141
nested: legendNestedSchema,
4242
truncate_after_lines: legendTruncateAfterLinesSchema,
43-
visibility: legendVisibilitySchema,
43+
visibility: legendVisibilitySchemaWithAuto,
4444
size: legendSizeSchema,
4545
},
4646
{

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@ import {
1919
sharedPanelInfoSchema,
2020
legendTruncateAfterLinesSchema,
2121
} from '../shared';
22-
import {
23-
legendVisibilitySchema,
24-
validateMultipleMetricsCriteria,
25-
valueDisplaySchema,
26-
} from './partition_shared';
22+
import { validateMultipleMetricsCriteria, valueDisplaySchema } from './partition_shared';
2723
import {
2824
legendSizeSchema,
25+
legendVisibilitySchemaWithAuto,
2926
mergeAllBucketsWithChartDimensionSchema,
3027
mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps,
3128
} from './shared';
@@ -49,7 +46,7 @@ export const waffleStateSharedSchema = {
4946
)
5047
),
5148
truncate_after_lines: legendTruncateAfterLinesSchema,
52-
visibility: legendVisibilitySchema,
49+
visibility: legendVisibilitySchemaWithAuto,
5350
size: legendSizeSchema,
5451
},
5552
{

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import { datasetEsqlTableSchema, datasetSchema } from '../dataset';
2222
import {
2323
legendSizeSchema,
24+
legendVisibilitySchemaWithAuto,
2425
mergeAllBucketsWithChartDimensionSchema,
2526
mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps,
2627
mergeAllMetricsWithChartDimensionSchemaWithStaticOps,
@@ -190,10 +191,7 @@ const xyDataLayerSharedSchema = {
190191
* Common legend configuration properties for positioning and statistics
191192
*/
192193
const sharedLegendSchema = {
193-
visibility: schema.oneOf(
194-
[schema.literal('auto'), schema.literal('visible'), schema.literal('hidden')],
195-
{ meta: { description: 'Show the legend' } }
196-
),
194+
visibility: legendVisibilitySchemaWithAuto,
197195
statistics: schema.maybe(
198196
schema.arrayOf(statisticsSchema, {
199197
meta: { description: 'Statistics to display in legend' },

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/heatmap/from_api.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ function buildVisualizationState(config: HeatmapState): HeatmapVisualizationStat
7474
}),
7575
},
7676
legend: {
77-
isVisible: layer.legend?.visible ?? true,
78-
position: layer.legend?.position ?? 'right',
77+
isVisible: layer.legend?.visibility !== 'hidden',
7978
type: 'heatmap_legend',
79+
position: 'right',
8080
...stripUndefined<HeatmapLegendConfigResult>({
8181
maxLines: layer.legend?.truncate_after_lines,
8282
legendSize: legendSizeCompat.toState(layer.legend?.size),
@@ -140,8 +140,7 @@ type HeatmapAttributesWithoutFiltersAndQuery = Omit<HeatmapAttributes, 'state'>
140140
};
141141

142142
export function fromAPItoLensState(config: HeatmapState): HeatmapAttributesWithoutFiltersAndQuery {
143-
const _buildDataLayer = (cfg: unknown, i: number) =>
144-
buildFormBasedLayer(cfg as HeatmapStateNoESQL);
143+
const _buildDataLayer = (cfg: unknown) => buildFormBasedLayer(cfg as HeatmapStateNoESQL);
145144

146145
const { layers, usedDataviews } = buildDatasourceStates(config, _buildDataLayer, getValueColumns);
147146

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/heatmap/to_api.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ import { axisLabelOrientationCompat } from '../common';
4242

4343
function getLegendProps(legend: HeatmapVisualizationState['legend']): HeatmapState['legend'] {
4444
return {
45-
visible: legend.isVisible,
46-
position: legend.position,
45+
visibility: legend.isVisible ? 'visible' : 'hidden',
4746
...stripUndefined<HeatmapState['legend']>({
4847
truncate_after_lines: getLegendTruncateAfterLines(legend),
4948
size: legendSizeCompat.toAPI(legend.legendSize),

0 commit comments

Comments
 (0)