From 6fa510d6fada68cb5e363d2f59c06ceb2d7d041e Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Mon, 16 Mar 2015 22:50:35 +0100 Subject: [PATCH] More fixes around special values in graphs. --- web/static/js/graph.js | 13 +++++++------ web/static/js/prom_console.js | 12 +++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/web/static/js/graph.js b/web/static/js/graph.js index 4f045e4cb8..4ead10192a 100644 --- a/web/static/js/graph.js +++ b/web/static/js/graph.js @@ -384,16 +384,17 @@ Prometheus.Graph.prototype.metricToTsName = function(labels) { }; Prometheus.Graph.prototype.parseValue = function(value) { - if (value == "NaN" || value == "Inf" || value == "-Inf") { - // Can't display these values on a graph, so display a gap instead. - return null; - } else { - return parseFloat(value); + var val = parseFloat(value); + if (isNaN(val)) { + // "+Inf", "-Inf", "+Inf" will be parsed into NaN by parseFloat(). The + // can't be graphed, so show them as gaps (null). + return null } + return val; }; Prometheus.Graph.prototype.transformData = function(json) { - self = this; + var self = this; var palette = new Rickshaw.Color.Palette(); if (json.type != "matrix") { self.showError("Result is not of matrix type! Please enter a correct expression."); diff --git a/web/static/js/prom_console.js b/web/static/js/prom_console.js index 889e19edd1..93042d335e 100644 --- a/web/static/js/prom_console.js +++ b/web/static/js/prom_console.js @@ -377,15 +377,17 @@ PromConsole.Graph = function(params) { }; PromConsole.Graph.prototype._parseValue = function(value) { - if (value == "NaN" || value == "Inf" || value == "-Inf") { - // Can't display these values on a graph, so display a gap instead. - return null; - } else { - return parseFloat(value); + var val = parseFloat(value); + if (isNaN(val)) { + // "+Inf", "-Inf", "+Inf" will be parsed into NaN by parseFloat(). The + // can't be graphed, so show them as gaps (null). + return null } + return val; } PromConsole.Graph.prototype._render = function(data) { + var self = this; var palette = new Rickshaw.Color.Palette(); var series = [];