From dcf4833bb21857b5a65718b681f2df4c78656e70 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Wed, 16 Feb 2022 16:31:09 +0200 Subject: [PATCH] [TSVB] Formatting in the left axis is not respected when I have two separate axis (#123903) (#125779) Closes: #123891 (cherry picked from commit 2c900c65ba61aac0aaed9131ccec88413d4d9860) Co-authored-by: Alexey Antonov --- ...eck_if_series_have_same_formatters.test.ts | 14 ++++++++ .../check_if_series_have_same_formatters.ts | 32 ++++++++++--------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/plugins/vis_types/timeseries/public/application/components/lib/check_if_series_have_same_formatters.test.ts b/src/plugins/vis_types/timeseries/public/application/components/lib/check_if_series_have_same_formatters.test.ts index 674973b1173f5..9044db065beb2 100644 --- a/src/plugins/vis_types/timeseries/public/application/components/lib/check_if_series_have_same_formatters.test.ts +++ b/src/plugins/vis_types/timeseries/public/application/components/lib/check_if_series_have_same_formatters.test.ts @@ -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' }] }, diff --git a/src/plugins/vis_types/timeseries/public/application/components/lib/check_if_series_have_same_formatters.ts b/src/plugins/vis_types/timeseries/public/application/components/lib/check_if_series_have_same_formatters.ts index c92b7e7aedd3e..996cabb9f7963 100644 --- a/src/plugins/vis_types/timeseries/public/application/components/lib/check_if_series_have_same_formatters.ts +++ b/src/plugins/vis_types/timeseries/public/application/components/lib/check_if_series_have_same_formatters.ts @@ -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;