Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add .hideEmpty(true) feature #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions cubism.v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '',
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/graphite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
19 changes: 18 additions & 1 deletion src/horizon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -212,5 +223,11 @@ cubism_contextPrototype.horizon = function() {
return horizon;
};

horizon.hideEmpty = function(_) {
if (!arguments.length) return hideEmpty;
hideEmpty = _;
return horizon;
};

return horizon;
};
5 changes: 5 additions & 0 deletions src/metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down