shrinks isopleth function

This commit is contained in:
Francisco Dans 2015-05-14 16:43:17 +02:00
parent 5cdda8d8c7
commit ea4445ab8d

View File

@ -175,12 +175,6 @@ BallRenderer.prototype = {
var y = (index - 4 * x) / (4 * this.width); var y = (index - 4 * x) / (4 * this.width);
return [x,y]; return [x,y];
}, },
// Clockwise. Again, there definitely is a better way.
getNeighbors: function(index){
var n = index - this.chWidth;
var s = index + this.chWidth;
return [n, n + 4, index + 4, s + 4, s, s - 4, index - 4, n -4];
},
isEmpty: function(layer) { isEmpty: function(layer) {
for (var i = 0; i<layer.length; i+=4){ for (var i = 0; i<layer.length; i+=4){
if(layer[i+3] > 0) return false; if(layer[i+3] > 0) return false;
@ -230,37 +224,21 @@ BallRenderer.prototype = {
} }
}, },
isopleth: function(){ isopleth: function(){
var iso = this.createArray(); if(typeof this.isoplethLayer === 'undefined') this.isoplethLayer = new Uint8Array(this.size * 4);
var contour = this.contourLayer; for (var i = 0, len = this.contourLayer.length; i<len; i+=4){
var eq = false; var alpha = this.contourLayer[i + 3];
for (var i = 0, len = contour.length; i<len; i+=4){
if(!eq){
var alpha = contour[i + 3];
if (alpha > 20 && alpha < 255){ if (alpha > 20 && alpha < 255){
var neighbors = this.getNeighbors(i); var n = i - this.chWidth,
var refCol = contour[neighbors[0]+3]; s = i + this.chWidth,
for (var n = 1, ln = neighbors.length; n<ln; ++n){ neighbors = [n, n + 4, i + 4, s + 4, s, s - 4, i - 4, n -4];
if (contour[neighbors[n]+3] !== refCol) break;
if (n === ln-1) eq = true;
}
if(!eq){
for (var n = 0, ln = neighbors.length; n<ln; ++n){ for (var n = 0, ln = neighbors.length; n<ln; ++n){
var index = neighbors[n]; var index = neighbors[n];
if(index>0 && (contour[index+3] === 0 || contour[index+3] !== contour[i+3])){ if(index>0 && (this.contourLayer[index+3] === 0 || this.contourLayer[index+3] !== this.contourLayer[i+3])){
iso[index + 3] = contour[i+3]; this.isoplethLayer[index + 3] = Math.min(this.contourLayer[i+3],255);
iso[index] = 153;
iso[index + 1] = 60;
iso[index + 2] = 243;
} }
} }
} }
} }
}
else{
eq = false;
}
}
this.isoplethLayer = iso;
}, },
heatmap: function (gradient){ heatmap: function (gradient){