diff --git a/cubism.v1.js b/cubism.v1.js index 8b8fadb..7ff81ab 100644 --- a/cubism.v1.js +++ b/cubism.v1.js @@ -252,7 +252,8 @@ function cubism_graphiteParse(text) { .substring(i + 1) .split(",") .slice(1) // the first value is always None? - .map(function(d) { return +d; }); + .map(function(d) { return +d; }) + .filter(Boolean); // Remove any NaN and return and empty array } cubism_contextPrototype.gangliaWeb = function(config) { var host = '', @@ -433,6 +434,11 @@ cubism_contextPrototype.metric = function(request, name) { return values[i]; }; + // + metric.valueAll = function() { + return values; + }; + // metric.shift = function(offset) { return context.metric(cubism_metricShift(request, +offset)); @@ -558,7 +564,8 @@ cubism_contextPrototype.horizon = function() { extent = null, title = cubism_identity, format = d3.format(".2s"), - colors = ["#08519c","#3182bd","#6baed6","#bdd7e7","#bae4b3","#74c476","#31a354","#006d2c"]; + colors = ["#08519c","#3182bd","#6baed6","#bdd7e7","#bae4b3","#74c476","#31a354","#006d2c"], + hideEmpty = false; function horizon(selection) { @@ -687,6 +694,16 @@ cubism_contextPrototype.horizon = function() { // Note that someone still needs to listen to the metric, // so that it continues to update automatically. metric_.on("change.horizon-" + id, function(start, stop) { + + // Hide graphs if the retrieved data set is empty + if (hideEmpty) { + if (d.valueAll().length == 0) { + selection.style("display", "none"); + } else { + selection.style("display", "block"); + } + } + change(start, stop), focus(); if (ready) metric_.on("change.horizon-" + id, cubism_identity); }); @@ -761,6 +778,12 @@ cubism_contextPrototype.horizon = function() { return horizon; }; + horizon.hideEmpty = function(_) { + if (!arguments.length) return hideEmpty; + hideEmpty = _; + return horizon; + }; + return horizon; }; cubism_contextPrototype.comparison = function() { diff --git a/src/graphite.js b/src/graphite.js index 8a5d5c5..eb4ea86 100644 --- a/src/graphite.js +++ b/src/graphite.js @@ -65,5 +65,6 @@ function cubism_graphiteParse(text) { .substring(i + 1) .split(",") .slice(1) // the first value is always None? - .map(function(d) { return +d; }); + .map(function(d) { return +d; }) + .filter(Boolean); // Remove any NaN and return and empty array } diff --git a/src/horizon.js b/src/horizon.js index 3c779c0..a09821a 100644 --- a/src/horizon.js +++ b/src/horizon.js @@ -9,7 +9,8 @@ cubism_contextPrototype.horizon = function() { extent = null, title = cubism_identity, format = d3.format(".2s"), - colors = ["#08519c","#3182bd","#6baed6","#bdd7e7","#bae4b3","#74c476","#31a354","#006d2c"]; + colors = ["#08519c","#3182bd","#6baed6","#bdd7e7","#bae4b3","#74c476","#31a354","#006d2c"], + hideEmpty = false; function horizon(selection) { @@ -138,6 +139,16 @@ cubism_contextPrototype.horizon = function() { // Note that someone still needs to listen to the metric, // so that it continues to update automatically. metric_.on("change.horizon-" + id, function(start, stop) { + + // Hide graphs if the retrieved data set is empty + if (hideEmpty) { + if (d.valueAll().length == 0) { + selection.style("display", "none"); + } else { + selection.style("display", "block"); + } + } + change(start, stop), focus(); if (ready) metric_.on("change.horizon-" + id, cubism_identity); }); @@ -212,5 +223,11 @@ cubism_contextPrototype.horizon = function() { return horizon; }; + horizon.hideEmpty = function(_) { + if (!arguments.length) return hideEmpty; + hideEmpty = _; + return horizon; + }; + return horizon; }; diff --git a/src/metric.js b/src/metric.js index ff3e75f..27ed7af 100644 --- a/src/metric.js +++ b/src/metric.js @@ -84,6 +84,11 @@ cubism_contextPrototype.metric = function(request, name) { return values[i]; }; + // + metric.valueAll = function() { + return values; + }; + // metric.shift = function(offset) { return context.metric(cubism_metricShift(request, +offset));