[TSVB] Formatting in the left axis is not respected when I have two separate axis (#123903)

Closes: #123891
This commit is contained in:
Alexey Antonov 2022-01-28 12:20:14 +03:00 committed by GitHub
parent 35f1c4d78e
commit 2c900c65ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 15 deletions

View file

@ -52,6 +52,20 @@ describe('checkIfSeriesHaveSameFormatters(seriesModel, fieldFormatMap)', () => {
expect(result).toBe(true);
});
it('should return true in case of separate y-axis and different field formatters', () => {
const seriesModel = [
{ formatter: DATA_FORMATTERS.DEFAULT, metrics: [{ type: 'avg', field: 'someField' }] },
{
formatter: DATA_FORMATTERS.DEFAULT,
separate_axis: 1,
metrics: [{ id: 'avg', field: 'anotherField' }],
},
] as Series[];
const result = checkIfSeriesHaveSameFormatters(seriesModel, fieldFormatMap);
expect(result).toBeTruthy();
});
it('should return false for the different field formatters', () => {
const seriesModel = [
{ formatter: DATA_FORMATTERS.DEFAULT, metrics: [{ type: 'avg', field: 'someField' }] },

View file

@ -18,24 +18,26 @@ export const checkIfSeriesHaveSameFormatters = (
const uniqFormatters = new Set();
seriesModel.forEach((seriesGroup) => {
if (seriesGroup.formatter === DATA_FORMATTERS.DEFAULT) {
const activeMetric = seriesGroup.metrics[seriesGroup.metrics.length - 1];
const aggMeta = aggs.find((agg) => agg.id === activeMetric.type);
if (!seriesGroup.separate_axis) {
if (seriesGroup.formatter === DATA_FORMATTERS.DEFAULT) {
const activeMetric = seriesGroup.metrics[seriesGroup.metrics.length - 1];
const aggMeta = aggs.find((agg) => agg.id === activeMetric.type);
if (
activeMetric.field &&
aggMeta?.meta.isFieldRequired &&
fieldFormatMap?.[activeMetric.field]
) {
return uniqFormatters.add(JSON.stringify(fieldFormatMap[activeMetric.field]));
if (
activeMetric.field &&
aggMeta?.meta.isFieldRequired &&
fieldFormatMap?.[activeMetric.field]
) {
return uniqFormatters.add(JSON.stringify(fieldFormatMap[activeMetric.field]));
}
}
uniqFormatters.add(
JSON.stringify({
// requirement: in the case of using TSVB formatters, we do not need to check the value_template, just formatter!
formatter: seriesGroup.formatter,
})
);
}
uniqFormatters.add(
JSON.stringify({
// requirement: in the case of using TSVB formatters, we do not need to check the value_template, just formatter!
formatter: seriesGroup.formatter,
})
);
});
return uniqFormatters.size === 1;