mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[XY] Fixes the broken chart when an agg is placed in another axis and then is hidden (#121488) (#121554)
* [XY] Fixes the broken chart when an agg is placed in another axis and then is hidden * Fix yAxes ticks * Fix test borkem due to the change of the implementation Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
This commit is contained in:
parent
38b51e6dc8
commit
edab4afd36
2 changed files with 37 additions and 11 deletions
|
@ -38,7 +38,31 @@ describe('getConfig', () => {
|
|||
it('assigns the correct formatter per y axis', () => {
|
||||
const config = getConfig(visData, visParamsWithTwoYAxes);
|
||||
expect(config.yAxes.length).toBe(2);
|
||||
expect(config.yAxes[0].ticks?.formatter).toStrictEqual(config.aspects.y[1].formatter);
|
||||
expect(config.yAxes[1].ticks?.formatter).toStrictEqual(config.aspects.y[0].formatter);
|
||||
expect(config.yAxes[0].ticks?.formatter).toStrictEqual(config.aspects.y[0].formatter);
|
||||
expect(config.yAxes[1].ticks?.formatter).toStrictEqual(config.aspects.y[1].formatter);
|
||||
});
|
||||
|
||||
it('assigns the correct number of yAxes if the agg is hidden', () => {
|
||||
// We have two axes but the one y dimension is hidden
|
||||
const newVisParams = {
|
||||
...visParamsWithTwoYAxes,
|
||||
dimensions: {
|
||||
...visParamsWithTwoYAxes.dimensions,
|
||||
y: [
|
||||
{
|
||||
label: 'Average memory',
|
||||
aggType: 'avg',
|
||||
params: {},
|
||||
accessor: 1,
|
||||
format: {
|
||||
id: 'number',
|
||||
params: {},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
const config = getConfig(visData, newVisParams);
|
||||
expect(config.yAxes.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -48,15 +48,17 @@ export function getConfig(
|
|||
} = params;
|
||||
const aspects = getAspects(table.columns, params.dimensions);
|
||||
const tooltip = getTooltip(aspects, params);
|
||||
const yAxes = params.valueAxes.map((a) => {
|
||||
// find the correct aspect for each value axis
|
||||
const aspectsIdx = params.seriesParams.findIndex((s) => s.valueAxis === a.id);
|
||||
return getAxis<YScaleType>(
|
||||
a,
|
||||
params.grid,
|
||||
aspects.y[aspectsIdx > -1 ? aspectsIdx : 0],
|
||||
params.seriesParams
|
||||
);
|
||||
|
||||
const yAxes: Array<AxisConfig<ScaleContinuousType>> = [];
|
||||
|
||||
params.dimensions.y.forEach((y) => {
|
||||
const accessor = y.accessor;
|
||||
const aspect = aspects.y.find(({ column }) => column === accessor);
|
||||
const serie = params.seriesParams.find(({ data: { id } }) => id === aspect?.aggId);
|
||||
const valueAxis = params.valueAxes.find(({ id }) => id === serie?.valueAxis);
|
||||
if (aspect && valueAxis) {
|
||||
yAxes.push(getAxis<YScaleType>(valueAxis, params.grid, aspect, params.seriesParams));
|
||||
}
|
||||
});
|
||||
|
||||
const rotation = getRotation(params.categoryAxes[0]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue