@@ -61,32 +61,43 @@ function useSuspectAttributes({
61
61
const formattedStartTimestamp = getUtcDateString ( startTimestamp ) ;
62
62
const formattedEndTimestamp = getUtcDateString ( endTimestamp ) ;
63
63
64
+ const yAxis = chartInfo . yAxes [ 0 ] ;
65
+ const parsedFunction = parseFunction ( yAxis ?? '' ) ;
66
+ const plottedFunctionName = parsedFunction ?. name ;
67
+ const plottedFunctionParameter = parsedFunction ?. arguments [ 0 ] ;
68
+
69
+ const useYAxisCoords = plottedFunctionName !== 'count' && plottedFunctionParameter ;
70
+
64
71
// Add the selected region by x-axis to the query, timestamp: [x1, x2]
65
72
selectedRegionQuery . addFilterValue ( FieldKey . TIMESTAMP , `>=${ formattedStartTimestamp } ` ) ;
66
73
selectedRegionQuery . addFilterValue ( FieldKey . TIMESTAMP , `<=${ formattedEndTimestamp } ` ) ;
67
74
75
+ // If selected region query is 'timestamp >= x0 and timestamp <= x1 and span.duration >= y0 and span.duration <= y1',
76
+ // then the baseline region query should be '((timestamp < x0 or timestamp > x1) or (span.duration < y0 or span.duration > y1))'.
77
+ // This is only required if the y-axis aggregate is not count.
78
+ if ( useYAxisCoords ) {
79
+ baselineRegionQuery . addOp ( '(' ) ;
80
+ }
81
+
68
82
// Add the baseline region by x-axis to the query, timestamp: <x1 or timestamp:>x2
69
83
baselineRegionQuery . addDisjunctionFilterValues ( FieldKey . TIMESTAMP , [
70
84
`<${ formattedStartTimestamp } ` ,
71
85
`>${ formattedEndTimestamp } ` ,
72
86
] ) ;
73
87
74
- const yAxis = chartInfo . yAxes [ 0 ] ;
75
- const parsedFunction = parseFunction ( yAxis ?? '' ) ;
76
- const plottedFunctionName = parsedFunction ?. name ;
77
- const plottedFunctionParameter = parsedFunction ?. arguments [ 0 ] ;
78
-
79
- // If the y-axis is not count, we add the field that has been aggregated on, to the queries to complete the boxed region.
88
+ // If the y-axis aggregate is not count, we add the field that has been aggregated on, to the queries to complete the boxed region.
80
89
// For example, if the y-axis is avg(span.duration), we add span.duration: [y1, y2] to query in the selected region
81
90
// and span.duration: <y1 or span.duration:>y2 to the baseline query.
82
- if ( plottedFunctionName !== 'count' && plottedFunctionParameter ) {
91
+ if ( useYAxisCoords ) {
83
92
selectedRegionQuery . addFilterValue ( plottedFunctionParameter , `>=${ y1 } ` ) ;
84
93
selectedRegionQuery . addFilterValue ( plottedFunctionParameter , `<=${ y2 } ` ) ;
85
94
95
+ baselineRegionQuery . addOp ( 'OR' ) ;
86
96
baselineRegionQuery . addDisjunctionFilterValues ( plottedFunctionParameter , [
87
97
`<${ y1 } ` ,
88
98
`>${ y2 } ` ,
89
99
] ) ;
100
+ baselineRegionQuery . addOp ( ')' ) ;
90
101
}
91
102
92
103
const query1 = selectedRegionQuery . formatString ( ) ;
0 commit comments