[ML] Fix link to Single Metric Viewer zoom for sparse data (#20144) (#20146)

This commit is contained in:
Pete Harverson 2018-06-22 16:00:29 +01:00 committed by GitHub
parent 60215bdb91
commit 462dbd1fcf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -794,20 +794,20 @@ module.controller('MlTimeSeriesExplorerController', function (
// Calculate the 'auto' zoom duration which shows data at bucket span granularity.
$scope.autoZoomDuration = getAutoZoomDuration();
// Check that the zoom times are valid.
// zoomFrom must be at or after dashboard earliest,
// zoomTo must be at or before dashboard latest plus context chart agg interval.
const zoomFrom = moment(zoomState.from, 'YYYY-MM-DDTHH:mm:ss.SSSZ', true);
const zoomTo = moment(zoomState.to, 'YYYY-MM-DDTHH:mm:ss.SSSZ', true);
// Get the time span of data in the context chart.
// Valid zoomTo is the time of the last bucket plus the aggregation interval.
const combinedData = $scope.contextForecastData === undefined ?
$scope.contextChartData : $scope.contextChartData.concat($scope.contextForecastData);
const earliestDataDate = _.first(combinedData).date;
const latestDataDate = new Date(_.last(combinedData).date.valueOf() +
$scope.contextAggregationInterval.asMilliseconds());
const aggIntervalMs = $scope.contextAggregationInterval.asMilliseconds();
const bounds = timefilter.getActiveBounds();
const earliest = bounds.min;
const latest = moment(bounds.max).add(aggIntervalMs, 'ms');
if (zoomFrom.isValid() && zoomTo.isValid &&
zoomFrom.isBetween(earliestDataDate, latestDataDate, null, '[]') &&
zoomTo.isBetween(earliestDataDate, latestDataDate, null, '[]')) {
zoomTo.isAfter(zoomFrom) &&
zoomFrom.isBetween(earliest, latest, null, '[]') &&
zoomTo.isBetween(earliest, latest, null, '[]')) {
return [zoomFrom.toDate(), zoomTo.toDate()];
}
}