Demo Site

Friday, March 28, 2008

Google Chart API: Extended encoding function for Javascript !

couldnt find a javascript implementation for extended encoding for google chart api, so here it is. if the function looks a little strange to you, check out this article about memoizing

http://osteele.com/archives/2006/04/javascript-memoization


also, thanks to

http://www.felipebarone.com/node/52

for putting this out there for php!


BaseMap.prototype.extendedEncoding = function(valueArray){
var MAX = 4095, MIN = 0, delta = MAX - MIN;
var extendedString = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.';
var stringLength = extendedString.length;
var encoded = function(valueArray){
var chartdata = 'e:';
for(var i=0;i= MIN && i <= MAX){
var calc1 = Math.round((valueArray[i] - MIN) / stringLength * MAX / delta);
var calc2 = ((valueArray[i] - MIN) % stringLength) * MAX / delta;
var first = extendedString.substring(calc1,calc1+1);
var second = extendedString.substring(calc2,calc2+1);
chartdata += first + second;
}else {
chardata += '__'; // Value out of max range;
}
}
return chartdata;
}
this.extendedEncoding = function(valueArray){return encoded(valueArray);}
return encoded;
}

1 comment:

Anonymous said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Aluguel de Computadores, I hope you enjoy. The address is http://aluguel-de-computadores.blogspot.com. A hug.

Labels

Labels

Labels