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 is not defined for number histogram data', () => { + const { args } = sampleArgs(); + + const numberLayer: LayerArgs = { + layerId: 'numberLayer', + hide: false, + xAccessor: 'xAccessorId', + yScaleType: 'linear', + xScaleType: 'linear', + isHistogram: true, + seriesType: 'bar_stacked', + accessors: ['yAccessorId'], + }; + + const numberHistogramData: LensMultiTable = { + type: 'lens_multitable', + tables: { + numberLayer: { + type: 'kibana_datatable', + rows: [ + { + xAccessorId: 5, + yAccessorId: 1, + }, + { + xAccessorId: 7, + yAccessorId: 1, + }, + { + xAccessorId: 8, + yAccessorId: 1, + }, + { + xAccessorId: 10, + yAccessorId: 1, + }, + ], + columns: [ + { + id: 'xAccessorId', + name: 'bytes', + }, + { + id: 'yAccessorId', + name: 'Count of records', + }, + ], + }, + }, + dateRange: { + fromDate: new Date('2020-04-01T16:14:16.246Z'), + toDate: new Date('2020-04-01T17:15:41.263Z'), + }, + }; + + const wrapper = mountWithIntl( + + ); + + expect(wrapper.find(Settings).first().prop('onBrushEnd')).not.toBeDefined(); + }); + test('onElementClick returns correct context data', () => { const geometry: GeometryValue = { x: 5, y: 1, accessor: 'y1', mark: null, datum: {} }; const series = { diff --git a/x-pack/plugins/lens/public/xy_visualization/expression.tsx b/x-pack/plugins/lens/public/xy_visualization/expression.tsx index a59739ec78f7f..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 { @@ -380,30 +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; - // in the future we want to make it also for histogram - if (!xAxisColumn || !isTimeViz) { + if (!xAxisColumn) { return; } @@ -412,7 +397,9 @@ export function XYChart({ const xAxisColumnIndex = table.columns.findIndex( (el) => el.id === filteredLayers[0].xAccessor ); - const timeFieldName = table.columns[xAxisColumnIndex]?.meta?.aggConfigParams?.field; + const timeFieldName = isTimeViz + ? table.columns[xAxisColumnIndex]?.meta?.aggConfigParams?.field + : undefined; const context: LensBrushEvent['data'] = { range: [min, max], @@ -421,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;