mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[ML] Set zoom to start of forecast on opening in Single Metric Viewer (#29503)
This commit is contained in:
parent
1ce293e26d
commit
f5638bdce3
1 changed files with 30 additions and 9 deletions
|
@ -573,10 +573,12 @@ module.controller('MlTimeSeriesExplorerController', function (
|
||||||
// Store forecast ID in the appState.
|
// Store forecast ID in the appState.
|
||||||
$scope.appState.mlTimeSeriesExplorer.forecastId = forecastId;
|
$scope.appState.mlTimeSeriesExplorer.forecastId = forecastId;
|
||||||
|
|
||||||
// Set the zoom to show backwards from the end of the forecast range.
|
// Set the zoom to centre on the start of the forecast range, depending
|
||||||
|
// on the time range of the forecast and data.
|
||||||
const earliestDataDate = _.first($scope.contextChartData).date;
|
const earliestDataDate = _.first($scope.contextChartData).date;
|
||||||
const zoomLatestMs = resp.latest;
|
const zoomLatestMs = Math.min(earliest + ($scope.autoZoomDuration / 2), latest.valueOf());
|
||||||
const zoomEarliestMs = Math.max(earliestDataDate.getTime(), zoomLatestMs - $scope.autoZoomDuration);
|
const zoomEarliestMs = Math.max(zoomLatestMs - $scope.autoZoomDuration, earliestDataDate.getTime());
|
||||||
|
|
||||||
const zoomState = {
|
const zoomState = {
|
||||||
from: moment(zoomEarliestMs).toISOString(),
|
from: moment(zoomEarliestMs).toISOString(),
|
||||||
to: moment(zoomLatestMs).toISOString()
|
to: moment(zoomLatestMs).toISOString()
|
||||||
|
@ -588,9 +590,11 @@ module.controller('MlTimeSeriesExplorerController', function (
|
||||||
// Ensure the forecast data will be shown if hidden previously.
|
// Ensure the forecast data will be shown if hidden previously.
|
||||||
$scope.showForecast = true;
|
$scope.showForecast = true;
|
||||||
|
|
||||||
|
|
||||||
if (earliest.isBefore(bounds.min) || latest.isAfter(bounds.max)) {
|
if (earliest.isBefore(bounds.min) || latest.isAfter(bounds.max)) {
|
||||||
const earliestMs = Math.min(earliest.valueOf(), bounds.min.valueOf());
|
const earliestMs = Math.min(earliest.valueOf(), bounds.min.valueOf());
|
||||||
const latestMs = Math.max(latest.valueOf(), bounds.max.valueOf());
|
const latestMs = Math.max(latest.valueOf(), bounds.max.valueOf());
|
||||||
|
|
||||||
timefilter.setTime({
|
timefilter.setTime({
|
||||||
from: moment(earliestMs).toISOString(),
|
from: moment(earliestMs).toISOString(),
|
||||||
to: moment(latestMs).toISOString()
|
to: moment(latestMs).toISOString()
|
||||||
|
@ -677,6 +681,7 @@ module.controller('MlTimeSeriesExplorerController', function (
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultRange = calculateDefaultFocusRange();
|
const defaultRange = calculateDefaultFocusRange();
|
||||||
|
|
||||||
if ((selection.from.getTime() !== defaultRange[0].getTime() || selection.to.getTime() !== defaultRange[1].getTime()) &&
|
if ((selection.from.getTime() !== defaultRange[0].getTime() || selection.to.getTime() !== defaultRange[1].getTime()) &&
|
||||||
(isNaN(Date.parse(selection.from)) === false && isNaN(Date.parse(selection.to)) === false)) {
|
(isNaN(Date.parse(selection.from)) === false && isNaN(Date.parse(selection.to)) === false)) {
|
||||||
const zoomState = { from: selection.from.toISOString(), to: selection.to.toISOString() };
|
const zoomState = { from: selection.from.toISOString(), to: selection.to.toISOString() };
|
||||||
|
@ -905,18 +910,34 @@ module.controller('MlTimeSeriesExplorerController', function (
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateDefaultFocusRange() {
|
function calculateDefaultFocusRange() {
|
||||||
// Returns the range that shows the most recent data at bucket span granularity.
|
|
||||||
$scope.autoZoomDuration = getAutoZoomDuration();
|
$scope.autoZoomDuration = getAutoZoomDuration();
|
||||||
|
const isForecastData = $scope.contextForecastData !== undefined && $scope.contextForecastData.length > 0;
|
||||||
|
|
||||||
const combinedData = $scope.contextForecastData === undefined ?
|
const combinedData = (isForecastData === false) ?
|
||||||
$scope.contextChartData : $scope.contextChartData.concat($scope.contextForecastData);
|
$scope.contextChartData : $scope.contextChartData.concat($scope.contextForecastData);
|
||||||
|
|
||||||
const earliestDataDate = _.first(combinedData).date;
|
const earliestDataDate = _.first(combinedData).date;
|
||||||
const latestDataDate = _.last(combinedData).date;
|
const latestDataDate = _.last(combinedData).date;
|
||||||
const latestMsToLoad = latestDataDate.getTime() + $scope.contextAggregationInterval.asMilliseconds();
|
|
||||||
const earliestMsToLoad = Math.max(earliestDataDate.getTime(), latestMsToLoad - $scope.autoZoomDuration);
|
|
||||||
|
|
||||||
return [new Date(earliestMsToLoad), new Date(latestMsToLoad)];
|
let rangeEarliestMs;
|
||||||
|
let rangeLatestMs;
|
||||||
|
|
||||||
|
if (isForecastData === true) {
|
||||||
|
// Return a range centred on the start of the forecast range, depending
|
||||||
|
// on the time range of the forecast and data.
|
||||||
|
const earliestForecastDataDate = _.first($scope.contextForecastData).date;
|
||||||
|
const latestForecastDataDate = _.last($scope.contextForecastData).date;
|
||||||
|
|
||||||
|
rangeLatestMs = Math.min(earliestForecastDataDate.getTime() + ($scope.autoZoomDuration / 2), latestForecastDataDate.getTime());
|
||||||
|
rangeEarliestMs = Math.max(rangeLatestMs - $scope.autoZoomDuration, earliestDataDate.getTime());
|
||||||
|
} else {
|
||||||
|
// Returns the range that shows the most recent data at bucket span granularity.
|
||||||
|
rangeLatestMs = latestDataDate.getTime() + $scope.contextAggregationInterval.asMilliseconds();
|
||||||
|
rangeEarliestMs = Math.max(earliestDataDate.getTime(), rangeLatestMs - $scope.autoZoomDuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [new Date(rangeEarliestMs), new Date(rangeLatestMs)];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateAggregationInterval(bounds, bucketsTarget) {
|
function calculateAggregationInterval(bounds, bucketsTarget) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue