Skip to content

Commit

Permalink
make histogram brushing possible
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Oct 5, 2020
1 parent ce97982 commit bc1dafc
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 3 deletions.
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
10 changes: 7 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,9 @@ 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
? {
Expand Down Expand Up @@ -402,8 +405,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 +414,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

0 comments on commit bc1dafc

Please sign in to comment.