Skip to content

Commit

Permalink
[Lens] Specify Y axis extent (elastic#99203) (elastic#100255)
Browse files Browse the repository at this point in the history
Co-authored-by: Joe Reuter <[email protected]>
  • Loading branch information
kibanamachine and flash1293 authored May 18, 2021
1 parent ee3c3c6 commit ac41730
Show file tree
Hide file tree
Showing 14 changed files with 834 additions and 27 deletions.

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

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

18 changes: 16 additions & 2 deletions x-pack/plugins/lens/public/xy_visualization/axes_configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { XYLayerConfig } from './types';
import { AxisExtentConfig, XYLayerConfig } from './types';
import { Datatable, SerializedFieldFormat } from '../../../../../src/plugins/expressions/public';
import { IFieldFormat } from '../../../../../src/plugins/data/public';

Expand All @@ -15,7 +15,7 @@ interface FormattedMetric {
fieldFormat: SerializedFieldFormat;
}

type GroupsConfiguration = Array<{
export type GroupsConfiguration = Array<{
groupId: string;
position: 'left' | 'right' | 'bottom' | 'top';
formatter?: IFieldFormat;
Expand Down Expand Up @@ -111,3 +111,17 @@ export function getAxesConfiguration(

return axisGroups;
}

export function validateExtent(hasBarOrArea: boolean, extent?: AxisExtentConfig) {
const inclusiveZeroError =
extent &&
hasBarOrArea &&
((extent.lowerBound !== undefined && extent.lowerBound > 0) ||
(extent.upperBound !== undefined && extent.upperBound) < 0);
const boundaryError =
extent &&
extent.lowerBound !== undefined &&
extent.upperBound !== undefined &&
extent.upperBound <= extent.lowerBound;
return { inclusiveZeroError, boundaryError };
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('Axes Settings', () => {
toggleAxisTitleVisibility: jest.fn(),
toggleTickLabelsVisibility: jest.fn(),
toggleGridlinesVisibility: jest.fn(),
hasBarOrAreaOnAxis: false,
};
});

Expand Down Expand Up @@ -91,4 +92,26 @@ describe('Axes Settings', () => {
);
expect(component.find('[data-test-subj="lnsshowEndzones"]').prop('checked')).toBe(true);
});

describe('axis extent', () => {
it('hides the extent section if no extent is passed in', () => {
const component = shallow(<AxisSettingsPopover {...props} />);
expect(component.find('[data-test-subj="lnsXY_axisBounds_groups"]').length).toBe(0);
});

it('renders bound inputs if mode is custom', () => {
const setSpy = jest.fn();
const component = shallow(
<AxisSettingsPopover
{...props}
extent={{ mode: 'custom', lowerBound: 123, upperBound: 456 }}
setExtent={setSpy}
/>
);
const lower = component.find('[data-test-subj="lnsXY_axisExtent_lowerBound"]');
const upper = component.find('[data-test-subj="lnsXY_axisExtent_upperBound"]');
expect(lower.prop('value')).toEqual(123);
expect(upper.prop('value')).toEqual(456);
});
});
});
Loading

0 comments on commit ac41730

Please sign in to comment.