Skip to content

Commit

Permalink
[TSVB] Formatting in the left axis is not respected when I have two s…
Browse files Browse the repository at this point in the history
…eparate axis (#123903) (#125779)

Closes: #123891
(cherry picked from commit 2c900c6)

Co-authored-by: Alexey Antonov <alexwizp@gmail.com>
  • Loading branch information
stratoula and alexwizp authored Feb 16, 2022
1 parent f1a4f21 commit dcf4833
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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' }] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit dcf4833

Please sign in to comment.