Skip to content

Commit

Permalink
[ML] Fix reloading anomaly charts on resize. (#22967) (#22995)
Browse files Browse the repository at this point in the history
- Fixes a regression introduced in #22814. Because of the stricter checking for scope/props updates, resizing the browser window would miss updating the Anomaly Explorer Charts widths. This fixes it by adding a check to trigger anomalyDataChange in redrawOnResize().
- Additionally, if only one chart is up for display, this update makes sure a single chart always spans across the full available width.
  • Loading branch information
walterra authored Sep 13, 2018
1 parent 49bfcc6 commit ecfbfa7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Object {

exports[`explorerChartsContainerService call anomalyChangeListener with actual series config 2`] = `
Object {
"layoutCellsPerChart": 6,
"layoutCellsPerChart": 12,
"seriesToPlot": Array [
Object {
"bucketSpanSeconds": 900,
Expand Down Expand Up @@ -71,7 +71,7 @@ Object {

exports[`explorerChartsContainerService call anomalyChangeListener with actual series config 3`] = `
Object {
"layoutCellsPerChart": 6,
"layoutCellsPerChart": 12,
"seriesToPlot": Array [
Object {
"bucketSpanSeconds": 900,
Expand Down Expand Up @@ -603,8 +603,8 @@ Object {
"loading": false,
"metricFieldName": "responsetime",
"metricFunction": "avg",
"plotEarliest": 1486611900000,
"plotLatest": 1486714500000,
"plotEarliest": 1486560600000,
"plotLatest": 1486765800000,
"selectedEarliest": 1486656000000,
"selectedLatest": 1486670399999,
"timeField": "@timestamp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export function explorerChartsContainerServiceFactory(
const allSeriesRecords = processRecordsForDisplay(filteredRecords);
// Calculate the number of charts per row, depending on the width available, to a max of 4.
const chartsContainerWidth = Math.floor($chartContainer.width());
const chartsPerRow = Math.min(Math.max(Math.floor(chartsContainerWidth / 550), 1), MAX_CHARTS_PER_ROW);
let chartsPerRow = Math.min(Math.max(Math.floor(chartsContainerWidth / 550), 1), MAX_CHARTS_PER_ROW);
if (allSeriesRecords.length === 1) {
chartsPerRow = 1;
}

data.layoutCellsPerChart = DEFAULT_LAYOUT_CELLS_PER_CHART / chartsPerRow;

Expand All @@ -71,8 +74,15 @@ export function explorerChartsContainerServiceFactory(

// Calculate the time range of the charts, which is a function of the chart width and max job bucket span.
data.tooManyBuckets = false;
const { chartRange, tooManyBuckets } = calculateChartRange(seriesConfigs, earliestMs, latestMs,
Math.floor(chartsContainerWidth / chartsPerRow), recordsToPlot, data.timeFieldName);
const chartWidth = Math.floor(chartsContainerWidth / chartsPerRow);
const { chartRange, tooManyBuckets } = calculateChartRange(
seriesConfigs,
earliestMs,
latestMs,
chartWidth,
recordsToPlot,
data.timeFieldNam
);
data.tooManyBuckets = tooManyBuckets;

// initialize the charts with loading indicators
Expand Down
10 changes: 10 additions & 0 deletions x-pack/plugins/ml/public/explorer/explorer_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,16 @@ module.controller('MlExplorerController', function (

mlExplorerDashboardService.swimlaneDataChange.changed('overall');
mlExplorerDashboardService.swimlaneDataChange.changed('viewBy');

if (
mlCheckboxShowChartsService.state.get('showCharts') &&
$scope.anomalyChartRecords.length > 0
) {
const timerange = getSelectionTimeRange($scope.cellData);
mlExplorerDashboardService.anomalyDataChange.changed(
$scope.anomalyChartRecords, timerange.earliestMs, timerange.latestMs
);
}
}

// Refresh the data when the dashboard filters are updated.
Expand Down

0 comments on commit ecfbfa7

Please sign in to comment.