@@ -159,12 +159,13 @@ export class AnomalyExplorerChartsService {
159159 const halfPoints = Math . ceil ( plotPoints / 2 ) ;
160160 const bounds = timeFilter . getActiveBounds ( ) ;
161161 const boundsMin = bounds ?. min ? bounds . min . valueOf ( ) : undefined ;
162+ const boundsMax = bounds ?. max ? bounds . max . valueOf ( ) : undefined ;
162163 let chartRange : ChartRange = {
163164 min : boundsMin
164165 ? Math . max ( midpointMs - halfPoints * minBucketSpanMs , boundsMin )
165166 : midpointMs - halfPoints * minBucketSpanMs ,
166- max : bounds ?. max
167- ? Math . min ( midpointMs + halfPoints * minBucketSpanMs , bounds . max . valueOf ( ) )
167+ max : boundsMax
168+ ? Math . min ( midpointMs + halfPoints * minBucketSpanMs , boundsMax )
168169 : midpointMs + halfPoints * minBucketSpanMs ,
169170 } ;
170171
@@ -210,15 +211,21 @@ export class AnomalyExplorerChartsService {
210211 }
211212
212213 // Elasticsearch aggregation returns points at start of bucket,
213- // so align the min to the length of the longest bucket.
214+ // so align the min to the length of the longest bucket,
215+ // and use the start of the latest selected bucket in the check
216+ // for too many selected buckets, respecting the max bounds set in the view.
214217 chartRange . min = Math . floor ( chartRange . min / maxBucketSpanMs ) * maxBucketSpanMs ;
215218 if ( boundsMin !== undefined && chartRange . min < boundsMin ) {
216219 chartRange . min = chartRange . min + maxBucketSpanMs ;
217220 }
218221
222+ const selectedLatestBucketStart = boundsMax
223+ ? Math . floor ( Math . min ( selectedLatestMs , boundsMax ) / maxBucketSpanMs ) * maxBucketSpanMs
224+ : Math . floor ( selectedLatestMs / maxBucketSpanMs ) * maxBucketSpanMs ;
225+
219226 if (
220- ( chartRange . min > selectedEarliestMs || chartRange . max < selectedLatestMs ) &&
221- chartRange . max - chartRange . min < selectedLatestMs - selectedEarliestMs
227+ ( chartRange . min > selectedEarliestMs || chartRange . max < selectedLatestBucketStart ) &&
228+ chartRange . max - chartRange . min < selectedLatestBucketStart - selectedEarliestMs
222229 ) {
223230 tooManyBuckets = true ;
224231 }
0 commit comments