Merge pull request #2739 from Conorbro/stack-graph-fix

Fixed graph ui max/min logic to accommodate for toggling of stacked graph option
This commit is contained in:
Frederic Branczyk 2017-05-18 16:49:30 +02:00 committed by GitHub
commit 363554f675
2 changed files with 53 additions and 14 deletions

File diff suppressed because one or more lines are too long

View file

@ -557,24 +557,40 @@ Prometheus.Graph.prototype.updateGraph = function() {
}); });
// Find and set graph's max/min // Find and set graph's max/min
var min = Infinity; if (self.isStacked() === true) {
var max = -Infinity; // When stacked is toggled
self.data.forEach(function(timeSeries) { var max = 0;
timeSeries.data.forEach(function(dataPoint) { self.data.forEach(function(timeSeries) {
var currSeriesMax = 0;
timeSeries.data.forEach(function(dataPoint) {
if (dataPoint.y > currSeriesMax && dataPoint.y != null) {
currSeriesMax = dataPoint.y;
}
});
max += currSeriesMax;
});
self.rickshawGraph.max = max*1.05;
self.rickshawGraph.min = 0;
} else {
var min = Infinity;
var max = -Infinity;
self.data.forEach(function(timeSeries) {
timeSeries.data.forEach(function(dataPoint) {
if (dataPoint.y < min && dataPoint.y != null) { if (dataPoint.y < min && dataPoint.y != null) {
min = dataPoint.y; min = dataPoint.y;
} }
if (dataPoint.y > max && dataPoint.y != null) { if (dataPoint.y > max && dataPoint.y != null) {
max = dataPoint.y; max = dataPoint.y;
} }
});
}); });
}); if (min === max) {
if (min === max) { self.rickshawGraph.max = max + 1;
self.rickshawGraph.max = max + 1; self.rickshawGraph.min = min - 1;
self.rickshawGraph.min = min - 1; } else {
} else { self.rickshawGraph.max = max + (0.1*(Math.abs(max - min)));
self.rickshawGraph.max = max + (0.1*(Math.abs(max - min))); self.rickshawGraph.min = min - (0.1*(Math.abs(max - min)));
self.rickshawGraph.min = min - (0.1*(Math.abs(max - min))); }
} }
var xAxis = new Rickshaw.Graph.Axis.Time({ graph: self.rickshawGraph }); var xAxis = new Rickshaw.Graph.Axis.Time({ graph: self.rickshawGraph });