[Lens] Set horizontal legend size to auto (#133851)

This commit is contained in:
Joe Reuter 2022-06-09 11:41:04 +02:00 committed by GitHub
parent 129e044562
commit efda0f322a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 9 deletions

View file

@ -167,7 +167,7 @@ Object {
"legendSize": Array [],
"maxLines": Array [],
"position": Array [
"bottom",
"left",
],
"shouldTruncate": Array [
true,

View file

@ -72,7 +72,7 @@ describe('#toExpression', () => {
expect(
xyVisualization.toExpression(
{
legend: { position: Position.Bottom, isVisible: true },
legend: { position: Position.Left, isVisible: true },
valueLabels: 'hide',
preferredSeriesType: 'bar',
fittingFunction: 'Carry',
@ -371,7 +371,7 @@ describe('#toExpression', () => {
it('should set legend size for outside legend', () => {
const expression = xyVisualization.toExpression(
{
legend: { position: Position.Bottom, isVisible: true, legendSize: LegendSize.SMALL },
legend: { position: Position.Left, isVisible: true, legendSize: LegendSize.SMALL },
valueLabels: 'show',
preferredSeriesType: 'bar',
layers: [
@ -394,12 +394,43 @@ describe('#toExpression', () => {
).toEqual('small');
});
it('should ignore legend size for insidee legend', () => {
it('should use auto legend size for bottom/top legend', () => {
const expression = xyVisualization.toExpression(
{
legend: {
position: Position.Bottom,
isVisible: true,
isInside: false,
legendSize: LegendSize.SMALL,
},
valueLabels: 'show',
preferredSeriesType: 'bar',
layers: [
{
layerId: 'first',
layerType: layerTypes.DATA,
seriesType: 'area',
splitAccessor: 'd',
xAccessor: 'a',
accessors: ['b', 'c'],
},
],
},
frame.datasourceLayers,
undefined,
datasourceExpressionsByLayers
) as Ast;
expect((expression.chain[0].arguments.legend[0] as Ast).chain[0].arguments.legendSize[0]).toBe(
LegendSize.AUTO
);
});
it('should ignore legend size for inside legend', () => {
const expression = xyVisualization.toExpression(
{
legend: {
position: Position.Left,
isVisible: true,
isInside: true,
legendSize: LegendSize.SMALL,
},

View file

@ -6,11 +6,12 @@
*/
import { Ast, AstFunction } from '@kbn/interpreter';
import { ScaleType } from '@elastic/charts';
import { Position, ScaleType } from '@elastic/charts';
import type { PaletteRegistry } from '@kbn/coloring';
import { EventAnnotationServiceType } from '@kbn/event-annotation-plugin/public';
import type { AxisExtentConfig, YConfig, ExtendedYConfig } from '@kbn/expression-xy-plugin/common';
import { LegendSize } from '@kbn/visualizations-plugin/public';
import {
State,
XYDataLayerConfig,
@ -213,10 +214,14 @@ export const buildExpression = (
: [],
position: !state.legend.isInside ? [state.legend.position] : [],
isInside: state.legend.isInside ? [state.legend.isInside] : [],
legendSize:
!state.legend.isInside && state.legend.legendSize
? [state.legend.legendSize]
: [],
legendSize: state.legend.isInside
? []
: state.legend.position === Position.Top ||
state.legend.position === Position.Bottom
? [LegendSize.AUTO]
: state.legend.legendSize
? [state.legend.legendSize]
: [],
horizontalAlignment:
state.legend.horizontalAlignment && state.legend.isInside
? [state.legend.horizontalAlignment]