Skip to content

Commit

Permalink
hide show value option for non-histogram charts
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Jun 4, 2021
1 parent 575075a commit b717c05
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
18 changes: 17 additions & 1 deletion x-pack/plugins/lens/public/xy_visualization/expression.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<XYChart {...defaultProps} data={data} args={{ ...args, valuesInLegend: true }} />
);
expect(component.find(Settings).at(0).prop('showLegendExtra')).toEqual(false);
});

test('shows legend extra for histogram chart', () => {
const { args } = sampleArgs();
const component = shallow(
<XYChart
{...defaultProps}
data={dateHistogramData}
args={{
...args,
layers: [dateHistogramLayer],
valuesInLegend: true,
}}
/>
);
expect(component.find(Settings).at(0).prop('showLegendExtra')).toEqual(true);
});

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/xy_visualization/expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ export function XYChart({
xDomain={xDomain}
onBrushEnd={renderMode !== 'noInteractivity' ? brushHandler : undefined}
onElementClick={renderMode !== 'noInteractivity' ? clickHandler : undefined}
showLegendExtra={valuesInLegend}
showLegendExtra={isHistogramViz && valuesInLegend}
/>

<Axis
Expand Down
11 changes: 10 additions & 1 deletion x-pack/plugins/lens/public/xy_visualization/xy_config_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ export const XyToolbar = memo(function XyToolbar(props: VisualizationToolbarProp
});
};

const nonOrdinalXAxis = state?.layers.every(
(layer) =>
!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) =>
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit b717c05

Please sign in to comment.