From b717c051928b8183716a9218f50ce1bf3e566ade Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Fri, 4 Jun 2021 17:54:49 +0200 Subject: [PATCH] hide show value option for non-histogram charts --- .../xy_visualization/expression.test.tsx | 18 +++++++++++++++++- .../public/xy_visualization/expression.tsx | 2 +- .../xy_visualization/xy_config_panel.tsx | 11 ++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/lens/public/xy_visualization/expression.test.tsx b/x-pack/plugins/lens/public/xy_visualization/expression.test.tsx index 0fa7b25b965f3..ee1f66063ad1d 100644 --- a/x-pack/plugins/lens/public/xy_visualization/expression.test.tsx +++ b/x-pack/plugins/lens/public/xy_visualization/expression.test.tsx @@ -846,11 +846,27 @@ describe('xy_expression', () => { expect(component.find(Settings).at(0).prop('showLegendExtra')).toEqual(false); }); - test('enables legend extra', () => { + test('ignores legend extra for ordinal chart', () => { const { data, args } = sampleArgs(); const component = shallow( ); + expect(component.find(Settings).at(0).prop('showLegendExtra')).toEqual(false); + }); + + test('shows legend extra for histogram chart', () => { + const { args } = sampleArgs(); + const component = shallow( + + ); expect(component.find(Settings).at(0).prop('showLegendExtra')).toEqual(true); }); diff --git a/x-pack/plugins/lens/public/xy_visualization/expression.tsx b/x-pack/plugins/lens/public/xy_visualization/expression.tsx index 2ef816dcb8fb5..b5e8534d17c8a 100644 --- a/x-pack/plugins/lens/public/xy_visualization/expression.tsx +++ b/x-pack/plugins/lens/public/xy_visualization/expression.tsx @@ -629,7 +629,7 @@ export function XYChart({ xDomain={xDomain} onBrushEnd={renderMode !== 'noInteractivity' ? brushHandler : undefined} onElementClick={renderMode !== 'noInteractivity' ? clickHandler : undefined} - showLegendExtra={valuesInLegend} + showLegendExtra={isHistogramViz && valuesInLegend} /> + !layer.xAccessor || + getScaleType( + props.frame.datasourceLayers[layer.layerId].getOperationForColumnId(layer.xAccessor), + ScaleType.Linear + ) !== 'ordinal' + ); + // only allow changing endzone visibility if it could show up theoretically (if it's a time viz) const onChangeEndzoneVisiblity = state?.layers.every( (layer) => @@ -323,7 +332,7 @@ export const XyToolbar = memo(function XyToolbar(props: VisualizationToolbarProp legend: { ...state.legend, position: id as Position }, }); }} - renderValueInLegendSwitch={!!state} + renderValueInLegendSwitch={nonOrdinalXAxis} valueInLegend={state?.valuesInLegend} onValueInLegendChange={() => { setState({