@@ -15,6 +15,7 @@ import { get, each, find, sortBy, map, reduce } from 'lodash';
1515
1616import { buildConfig } from './explorer_chart_config_builder' ;
1717import { chartLimits , getChartType } from '../../util/chart_utils' ;
18+ import { getTimefilter } from '../../util/dependency_cache' ;
1819
1920import { getEntityFieldList } from '../../../../common/util/anomaly_utils' ;
2021import {
@@ -50,8 +51,8 @@ const MAX_CHARTS_PER_ROW = 4;
5051export const anomalyDataChange = function (
5152 chartsContainerWidth ,
5253 anomalyRecords ,
53- earliestMs ,
54- latestMs ,
54+ selectedEarliestMs ,
55+ selectedLatestMs ,
5556 severity = 0
5657) {
5758 const data = getDefaultChartsData ( ) ;
@@ -83,8 +84,8 @@ export const anomalyDataChange = function (
8384 const chartWidth = Math . floor ( chartsContainerWidth / chartsPerRow ) ;
8485 const { chartRange, tooManyBuckets } = calculateChartRange (
8586 seriesConfigs ,
86- earliestMs ,
87- latestMs ,
87+ selectedEarliestMs ,
88+ selectedLatestMs ,
8889 chartWidth ,
8990 recordsToPlot ,
9091 data . timeFieldName
@@ -408,8 +409,8 @@ export const anomalyDataChange = function (
408409 chartData : processedData [ i ] ,
409410 plotEarliest : chartRange . min ,
410411 plotLatest : chartRange . max ,
411- selectedEarliest : earliestMs ,
412- selectedLatest : latestMs ,
412+ selectedEarliest : selectedEarliestMs ,
413+ selectedLatest : selectedLatestMs ,
413414 chartLimits : USE_OVERALL_CHART_LIMITS ? overallChartLimits : chartLimits ( processedData [ i ] ) ,
414415 } ) ) ;
415416 explorerService . setCharts ( { ...data } ) ;
@@ -561,19 +562,21 @@ function processRecordsForDisplay(anomalyRecords) {
561562
562563function calculateChartRange (
563564 seriesConfigs ,
564- earliestMs ,
565- latestMs ,
565+ selectedEarliestMs ,
566+ selectedLatestMs ,
566567 chartWidth ,
567568 recordsToPlot ,
568569 timeFieldName
569570) {
570571 let tooManyBuckets = false ;
571572 // Calculate the time range for the charts.
572573 // Fit in as many points in the available container width plotted at the job bucket span.
573- const midpointMs = Math . ceil ( ( earliestMs + latestMs ) / 2 ) ;
574+ const midpointMs = Math . ceil ( ( selectedEarliestMs + selectedLatestMs ) / 2 ) ;
574575 const maxBucketSpanMs = Math . max . apply ( null , map ( seriesConfigs , 'bucketSpanSeconds' ) ) * 1000 ;
575576
576- const pointsToPlotFullSelection = Math . ceil ( ( latestMs - earliestMs ) / maxBucketSpanMs ) ;
577+ const pointsToPlotFullSelection = Math . ceil (
578+ ( selectedLatestMs - selectedEarliestMs ) / maxBucketSpanMs
579+ ) ;
577580
578581 // Optimally space points 5px apart.
579582 const optimumPointSpacing = 5 ;
@@ -583,9 +586,12 @@ function calculateChartRange(
583586 // at optimal point spacing.
584587 const plotPoints = Math . max ( optimumNumPoints , pointsToPlotFullSelection ) ;
585588 const halfPoints = Math . ceil ( plotPoints / 2 ) ;
589+ const timefilter = getTimefilter ( ) ;
590+ const bounds = timefilter . getActiveBounds ( ) ;
591+
586592 let chartRange = {
587- min : midpointMs - halfPoints * maxBucketSpanMs ,
588- max : midpointMs + halfPoints * maxBucketSpanMs ,
593+ min : Math . max ( midpointMs - halfPoints * maxBucketSpanMs , bounds . min . valueOf ( ) ) ,
594+ max : Math . min ( midpointMs + halfPoints * maxBucketSpanMs , bounds . max . valueOf ( ) ) ,
589595 } ;
590596
591597 if ( plotPoints > CHART_MAX_POINTS ) {
@@ -615,8 +621,8 @@ function calculateChartRange(
615621
616622 if ( maxMs - minMs < maxTimeSpan ) {
617623 // Expand out to cover as much as the requested time span as possible.
618- minMs = Math . max ( earliestMs , minMs - maxTimeSpan ) ;
619- maxMs = Math . min ( latestMs , maxMs + maxTimeSpan ) ;
624+ minMs = Math . max ( selectedEarliestMs , minMs - maxTimeSpan ) ;
625+ maxMs = Math . min ( selectedLatestMs , maxMs + maxTimeSpan ) ;
620626 }
621627
622628 chartRange = { min : minMs , max : maxMs } ;
0 commit comments