Skip to content

Commit

Permalink
Prevent D3 error when incorrect data is attempted to be drawn
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesrwhite committed Apr 13, 2014
1 parent 465c1fe commit f88da00
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions opcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,22 @@ function set_text(t) {
}

function change() {
if (typeof dataset[this.value] !== 'undefined') {
// Filter out any zero values to see if there is anything left
var remove_zero_values = dataset[this.value].filter(function(value) {
return value > 0;
});

// Skip if the value is undefined for some reason
if (typeof dataset[this.value] !== 'undefined' && remove_zero_values.length > 0) {
$('#graph').find('> svg').show();
path = path.data(pie(dataset[this.value])); // update the data
path.transition().duration(750).attrTween("d", arcTween); // redraw the arcs
set_text(this.value);
// Hide the graph if we can't draw it correctly, not ideal but this works
} else {
$('#graph').find('> svg').hide();
}

set_text(this.value);
}

function arcTween(a) {
Expand Down

0 comments on commit f88da00

Please sign in to comment.