Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] Make histogram brushing possible #79435

Merged
merged 3 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions x-pack/plugins/lens/public/xy_visualization/expression.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,87 @@ describe('xy_expression', () => {
});
});

test('onBrushEnd returns correct context data 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(
<XYChart
data={numberHistogramData}
args={{
...args,
layers: [numberLayer],
}}
formatFactory={getFormatSpy}
timeZone="UTC"
chartsThemeService={chartsThemeService}
histogramBarTarget={50}
onClickValue={onClickValue}
onSelectRange={onSelectRange}
/>
);

wrapper.find(Settings).first().prop('onBrushEnd')!({ x: [5, 8] });

expect(onSelectRange).toHaveBeenCalledWith({
column: 0,
table: numberHistogramData.tables.numberLayer,
range: [5, 8],
timeFieldName: undefined,
});
});

test('onElementClick returns correct context data', () => {
const geometry: GeometryValue = { x: 5, y: 1, accessor: 'y1', mark: null, datum: {} };
const series = {
Expand Down
8 changes: 5 additions & 3 deletions x-pack/plugins/lens/public/xy_visualization/expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ export function XYChart({
}

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

const xDomain = isTimeViz
? {
Expand Down Expand Up @@ -402,8 +403,7 @@ export function XYChart({
return;
}
const [min, max] = x;
// in the future we want to make it also for histogram
if (!xAxisColumn || !isTimeViz) {
if (!xAxisColumn || !isHistogramViz) {
return;
}

Expand All @@ -412,7 +412,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],
Expand Down