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] No histogram brushing on number histograms #79570

Closed
Closed
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 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,80 @@ describe('xy_expression', () => {
});
});

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

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 = {
Expand Down
50 changes: 29 additions & 21 deletions x-pack/plugins/lens/public/xy_visualization/expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
GeometryValue,
XYChartSeriesIdentifier,
StackMode,
SettingsSpec,
} from '@elastic/charts';
import { I18nProvider } from '@kbn/i18n/react';
import {
Expand Down Expand Up @@ -380,30 +381,14 @@ export function XYChart({
return style;
};

return (
<Chart>
<Settings
showLegend={
legend.isVisible && !legend.showSingleSeries
? chartHasMoreThanOneSeries
: legend.isVisible
}
legendPosition={legend.position}
showLegendExtra={false}
theme={chartTheme}
baseTheme={chartBaseTheme}
tooltip={{
headerFormatter: (d) => safeXAccessorLabelRenderer(d.value),
}}
rotation={shouldRotate ? 90 : 0}
xDomain={xDomain}
onBrushEnd={({ x }) => {
const extraSettings: Partial<SettingsSpec> = isTimeViz
? {
onBrushEnd: ({ x }) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is entirely copy+pasted and moved. The diff shows it being a larger change than it was.

if (!x) {
return;
}
const [min, max] = x;
// in the future we want to make it also for histogram
if (!xAxisColumn || !isTimeViz) {
if (!xAxisColumn) {
return;
}

Expand All @@ -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],
Expand All @@ -421,7 +408,28 @@ export function XYChart({
timeFieldName,
};
onSelectRange(context);
},
}
: {};

return (
<Chart>
<Settings
{...extraSettings}
showLegend={
legend.isVisible && !legend.showSingleSeries
? chartHasMoreThanOneSeries
: legend.isVisible
}
legendPosition={legend.position}
showLegendExtra={false}
theme={chartTheme}
baseTheme={chartBaseTheme}
tooltip={{
headerFormatter: (d) => 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;
Expand Down