Skip to content

Commit 018c2bd

Browse files
authored
[Lens] Make histogram brushing possible (#79435)
1 parent 8f49154 commit 018c2bd

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-3
lines changed

x-pack/plugins/lens/public/xy_visualization/expression.test.tsx

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,87 @@ describe('xy_expression', () => {
750750
});
751751
});
752752

753+
test('onBrushEnd returns correct context data for number histogram data', () => {
754+
const { args } = sampleArgs();
755+
756+
const numberLayer: LayerArgs = {
757+
layerId: 'numberLayer',
758+
hide: false,
759+
xAccessor: 'xAccessorId',
760+
yScaleType: 'linear',
761+
xScaleType: 'linear',
762+
isHistogram: true,
763+
seriesType: 'bar_stacked',
764+
accessors: ['yAccessorId'],
765+
};
766+
767+
const numberHistogramData: LensMultiTable = {
768+
type: 'lens_multitable',
769+
tables: {
770+
numberLayer: {
771+
type: 'kibana_datatable',
772+
rows: [
773+
{
774+
xAccessorId: 5,
775+
yAccessorId: 1,
776+
},
777+
{
778+
xAccessorId: 7,
779+
yAccessorId: 1,
780+
},
781+
{
782+
xAccessorId: 8,
783+
yAccessorId: 1,
784+
},
785+
{
786+
xAccessorId: 10,
787+
yAccessorId: 1,
788+
},
789+
],
790+
columns: [
791+
{
792+
id: 'xAccessorId',
793+
name: 'bytes',
794+
},
795+
{
796+
id: 'yAccessorId',
797+
name: 'Count of records',
798+
},
799+
],
800+
},
801+
},
802+
dateRange: {
803+
fromDate: new Date('2020-04-01T16:14:16.246Z'),
804+
toDate: new Date('2020-04-01T17:15:41.263Z'),
805+
},
806+
};
807+
808+
const wrapper = mountWithIntl(
809+
<XYChart
810+
data={numberHistogramData}
811+
args={{
812+
...args,
813+
layers: [numberLayer],
814+
}}
815+
formatFactory={getFormatSpy}
816+
timeZone="UTC"
817+
chartsThemeService={chartsThemeService}
818+
histogramBarTarget={50}
819+
onClickValue={onClickValue}
820+
onSelectRange={onSelectRange}
821+
/>
822+
);
823+
824+
wrapper.find(Settings).first().prop('onBrushEnd')!({ x: [5, 8] });
825+
826+
expect(onSelectRange).toHaveBeenCalledWith({
827+
column: 0,
828+
table: numberHistogramData.tables.numberLayer,
829+
range: [5, 8],
830+
timeFieldName: undefined,
831+
});
832+
});
833+
753834
test('onElementClick returns correct context data', () => {
754835
const geometry: GeometryValue = { x: 5, y: 1, accessor: 'y1', mark: null, datum: {} };
755836
const series = {

x-pack/plugins/lens/public/xy_visualization/expression.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ export function XYChart({
337337
}
338338

339339
const isTimeViz = data.dateRange && filteredLayers.every((l) => l.xScaleType === 'time');
340+
const isHistogramViz = filteredLayers.every((l) => l.isHistogram);
340341

341342
const xDomain = isTimeViz
342343
? {
@@ -402,8 +403,7 @@ export function XYChart({
402403
return;
403404
}
404405
const [min, max] = x;
405-
// in the future we want to make it also for histogram
406-
if (!xAxisColumn || !isTimeViz) {
406+
if (!xAxisColumn || !isHistogramViz) {
407407
return;
408408
}
409409

@@ -412,7 +412,9 @@ export function XYChart({
412412
const xAxisColumnIndex = table.columns.findIndex(
413413
(el) => el.id === filteredLayers[0].xAccessor
414414
);
415-
const timeFieldName = table.columns[xAxisColumnIndex]?.meta?.aggConfigParams?.field;
415+
const timeFieldName = isTimeViz
416+
? table.columns[xAxisColumnIndex]?.meta?.aggConfigParams?.field
417+
: undefined;
416418

417419
const context: LensBrushEvent['data'] = {
418420
range: [min, max],

0 commit comments

Comments
 (0)