[Lens] Applies new time axis for area and line charts with breakdown dimension (#120891)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Stratoula Kalafateli 2021-12-13 16:21:48 +02:00 committed by GitHub
parent 205f77c8ff
commit b0442e396b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 112 additions and 2 deletions

View file

@ -636,6 +636,117 @@ describe('xy_expression', () => {
`);
});
describe('axis time', () => {
const defaultTimeLayer: LayerArgs = {
layerId: 'first',
layerType: layerTypes.DATA,
seriesType: 'line',
xAccessor: 'c',
accessors: ['a', 'b'],
splitAccessor: 'd',
columnToLabel: '{"a": "Label A", "b": "Label B", "d": "Label D"}',
xScaleType: 'time',
yScaleType: 'linear',
isHistogram: true,
palette: mockPaletteOutput,
};
test('it should disable the new time axis for a line time layer when isHistogram is set to false', () => {
const { data } = sampleArgs();
const instance = shallow(
<XYChart
{...defaultProps}
data={{
...data,
dateRange: {
fromDate: new Date('2019-01-02T05:00:00.000Z'),
toDate: new Date('2019-01-03T05:00:00.000Z'),
},
}}
args={multiLayerArgs}
/>
);
const axisStyle = instance.find(Axis).first().prop('timeAxisLayerCount');
expect(axisStyle).toBe(0);
});
test('it should enable the new time axis for a line time layer when isHistogram is set to true', () => {
const { data } = sampleArgs();
const timeLayerArgs = createArgsWithLayers([defaultTimeLayer]);
const instance = shallow(
<XYChart
{...defaultProps}
data={{
...data,
dateRange: {
fromDate: new Date('2019-01-02T05:00:00.000Z'),
toDate: new Date('2019-01-03T05:00:00.000Z'),
},
}}
args={timeLayerArgs}
/>
);
const axisStyle = instance.find(Axis).first().prop('timeAxisLayerCount');
expect(axisStyle).toBe(3);
});
test('it should disable the new time axis for a vertical bar with break down dimension', () => {
const { data } = sampleArgs();
const timeLayer: LayerArgs = {
...defaultTimeLayer,
seriesType: 'bar',
};
const timeLayerArgs = createArgsWithLayers([timeLayer]);
const instance = shallow(
<XYChart
{...defaultProps}
data={{
...data,
dateRange: {
fromDate: new Date('2019-01-02T05:00:00.000Z'),
toDate: new Date('2019-01-03T05:00:00.000Z'),
},
}}
args={timeLayerArgs}
/>
);
const axisStyle = instance.find(Axis).first().prop('timeAxisLayerCount');
expect(axisStyle).toBe(0);
});
test('it should enable the new time axis for a stacked vertical bar with break down dimension', () => {
const { data } = sampleArgs();
const timeLayer: LayerArgs = {
...defaultTimeLayer,
seriesType: 'bar_stacked',
};
const timeLayerArgs = createArgsWithLayers([timeLayer]);
const instance = shallow(
<XYChart
{...defaultProps}
data={{
...data,
dateRange: {
fromDate: new Date('2019-01-02T05:00:00.000Z'),
toDate: new Date('2019-01-03T05:00:00.000Z'),
},
}}
args={timeLayerArgs}
/>
);
const axisStyle = instance.find(Axis).first().prop('timeAxisLayerCount');
expect(axisStyle).toBe(3);
});
});
describe('endzones', () => {
const { args } = sampleArgs();
const data: LensMultiTable = {

View file

@ -562,9 +562,8 @@ export function XYChart({
} as LegendPositionConfig;
const isHistogramModeEnabled = filteredLayers.some(
({ isHistogram, seriesType, splitAccessor }) =>
({ isHistogram, seriesType }) =>
isHistogram &&
(seriesType.includes('stacked') || !splitAccessor) &&
(seriesType.includes('stacked') ||
!seriesType.includes('bar') ||
!chartHasMoreThanOneBarSeries)