Skip to content

Commit

Permalink
[Lens] No brushing on number histograms
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed Oct 5, 2020
1 parent 400e068 commit 762d3c3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 38 deletions.

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

11 changes: 2 additions & 9 deletions x-pack/plugins/lens/public/xy_visualization/expression.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ describe('xy_expression', () => {
});
});

test('onBrushEnd returns correct context data for number histogram data', () => {
test('onBrushEnd is not defined for number histogram data', () => {
const { args } = sampleArgs();

const numberLayer: LayerArgs = {
Expand Down Expand Up @@ -821,14 +821,7 @@ describe('xy_expression', () => {
/>
);

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

expect(onSelectRange).toHaveBeenCalledWith({
column: 0,
table: numberHistogramData.tables.numberLayer,
range: [5, 8],
timeFieldName: undefined,
});
expect(wrapper.find(Settings).first().prop('onBrushEnd')).not.toBeDefined();
});

test('onElementClick returns correct context data', () => {
Expand Down
48 changes: 26 additions & 22 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 @@ -337,9 +338,6 @@ 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 @@ -383,29 +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 }) => {
if (!x) {
return;
}
const [min, max] = x;
if (!xAxisColumn || !isHistogramViz) {
if (!xAxisColumn) {
return;
}

Expand All @@ -425,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

0 comments on commit 762d3c3

Please sign in to comment.