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] Support stacking in xy visualization #40546

Merged
merged 4 commits into from
Jul 10, 2019
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

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.

Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export const buildExpression = (
},
],
splitSeriesAccessors: state.splitSeriesAccessors,
stackAccessors: state.stackAccessors,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,21 @@ export const xConfig: ExpressionFunction<'lens_xy_xConfig', null, XConfig, XConf
},
};

export type SeriesType = 'bar' | 'horizontal_bar' | 'line' | 'area';
export type SeriesType =
| 'bar'
| 'horizontal_bar'
| 'line'
| 'area'
| 'bar_stacked'
| 'horizontal_bar_stacked'
| 'area_stacked';

export interface XYArgs {
seriesType: SeriesType;
legend: LegendConfig;
y: YConfig;
x: XConfig;
splitSeriesAccessors: string[];
stackAccessors: string[];
}

export interface XYState {
Expand All @@ -163,7 +169,6 @@ export interface XYState {
y: YState;
x: XConfig;
splitSeriesAccessors: string[];
stackAccessors: string[];
}

export type State = XYState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import React from 'react';
import { ReactWrapper } from 'enzyme';
import { mountWithIntl as mount } from 'test_utils/enzyme_helpers';
import { EuiButtonGroupProps } from '@elastic/eui';
import { XYConfigPanel } from './xy_config_panel';
import { DatasourcePublicAPI, DatasourceDimensionPanelProps, Operation } from '../types';
import { State, SeriesType } from './types';
Expand All @@ -33,7 +34,6 @@ describe('XYConfigPanel', () => {
legend: { isVisible: true, position: Position.Right },
seriesType: 'bar',
splitSeriesAccessors: [],
stackAccessors: [],
x: {
accessor: 'foo',
position: Position.Bottom,
Expand All @@ -56,6 +56,56 @@ describe('XYConfigPanel', () => {
.props();
}

test('disables stacked chart types without a split series', () => {
const component = mount(
<XYConfigPanel
dragDropContext={dragDropContext}
datasource={mockDatasource()}
setState={() => {}}
state={testState()}
/>
);

const options = component
.find('[data-test-subj="lnsXY_seriesType"]')
.first()
.prop('options') as EuiButtonGroupProps['options'];

expect(options.map(({ id }) => id)).toEqual([
'line',
'area',
'bar',
'horizontal_bar',
'area_stacked',
'bar_stacked',
'horizontal_bar_stacked',
]);

expect(options.filter(({ isDisabled }) => isDisabled).map(({ id }) => id)).toEqual([
'area_stacked',
'bar_stacked',
'horizontal_bar_stacked',
]);
});

test('enables all stacked chart types when there is a split series', () => {
const component = mount(
<XYConfigPanel
dragDropContext={dragDropContext}
datasource={mockDatasource()}
setState={() => {}}
state={{ ...testState(), splitSeriesAccessors: ['c'] }}
/>
);

const options = component
.find('[data-test-subj="lnsXY_seriesType"]')
.first()
.prop('options') as EuiButtonGroupProps['options'];

expect(options.every(({ isDisabled }) => !isDisabled)).toEqual(true);
});

test('toggles axis position when going from horizontal bar to any other type', () => {
const changeSeriesType = (fromSeriesType: SeriesType, toSeriesType: SeriesType) => {
const setState = jest.fn();
Expand Down
Loading