diff --git a/x-pack/plugins/lens/public/xy_visualization/__snapshots__/expression.test.tsx.snap b/x-pack/plugins/lens/public/xy_visualization/__snapshots__/expression.test.tsx.snap index ca6ca9b2722fd..9d5117e2f5917 100644 --- a/x-pack/plugins/lens/public/xy_visualization/__snapshots__/expression.test.tsx.snap +++ b/x-pack/plugins/lens/public/xy_visualization/__snapshots__/expression.test.tsx.snap @@ -7,7 +7,6 @@ exports[`xy_expression XYChart component it renders area 1`] = ` { }); }); - test('onBrushEnd returns correct context data for number histogram data', () => { + test('onBrushEnd is not defined for number histogram data', () => { const { args } = sampleArgs(); const numberLayer: LayerArgs = { @@ -821,14 +821,7 @@ describe('xy_expression', () => { /> ); - wrapper.find(Settings).first().prop('onBrushEnd')!({ x: [5, 8] }); - - expect(onSelectRange).toHaveBeenCalledWith({ - column: 0, - table: numberHistogramData.tables.numberLayer, - range: [5, 8], - timeFieldName: undefined, - }); + expect(wrapper.find(Settings).first().prop('onBrushEnd')).not.toBeDefined(); }); test('onElementClick returns correct context data', () => { diff --git a/x-pack/plugins/lens/public/xy_visualization/expression.tsx b/x-pack/plugins/lens/public/xy_visualization/expression.tsx index 6c4f188cd4608..c647d6d091d75 100644 --- a/x-pack/plugins/lens/public/xy_visualization/expression.tsx +++ b/x-pack/plugins/lens/public/xy_visualization/expression.tsx @@ -20,6 +20,7 @@ import { GeometryValue, XYChartSeriesIdentifier, StackMode, + SettingsSpec, } from '@elastic/charts'; import { I18nProvider } from '@kbn/i18n/react'; import { @@ -337,9 +338,6 @@ export function XYChart({ } const isTimeViz = data.dateRange && filteredLayers.every((l) => l.xScaleType === 'time'); - const isHistogramViz = filteredLayers.every( - (l) => l.xScaleType === 'time' || l.xScaleType === 'linear' - ); const xDomain = isTimeViz ? { @@ -383,29 +381,14 @@ export function XYChart({ return style; }; - return ( - - safeXAccessorLabelRenderer(d.value), - }} - rotation={shouldRotate ? 90 : 0} - xDomain={xDomain} - onBrushEnd={({ x }) => { + const extraSettings: Partial = isTimeViz + ? { + onBrushEnd: ({ x }) => { if (!x) { return; } const [min, max] = x; - if (!xAxisColumn || !isHistogramViz) { + if (!xAxisColumn) { return; } @@ -425,7 +408,28 @@ export function XYChart({ timeFieldName, }; onSelectRange(context); + }, + } + : {}; + + return ( + + safeXAccessorLabelRenderer(d.value), }} + rotation={shouldRotate ? 90 : 0} + xDomain={xDomain} onElementClick={([[geometry, series]]) => { // for xyChart series is always XYChartSeriesIdentifier and geometry is always type of GeometryValue const xySeries = series as XYChartSeriesIdentifier;