/* * jQuery TagCloud 0.5.0 * Copyright (c) 2008 Ron Valstar * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html */ ;(function($) { // private variables var oSettings; var oUlCss = {}; var oLiCss = {}; var fGAng = 2.399963; // sphere angle in radians*pi // default settings $.tagcloud = { id: "TagCloud" ,version: "0.5.0" ,defaults: { height: null ,type: "cloud" // "cloud", "list" or "sphere" ,sizemax: 20 ,sizemin: 10 ,colormax: "00F" ,colormin: "B4D2FF" ,seed: null // only for type=="cloud" ,power: .5 // only for type=="sphere" } }; $.fn.extend({ tagcloud: function(_settings) { oSettings = $.extend({}, $.tagcloud.defaults, _settings); if (oSettings.seed===null) oSettings.seed = Math.ceil(Math.random()*45309714203); switch (oSettings.type) { // treemap :: http://www.jquery.info/The-TreeMap-plugin case "sphere": case "cloud": oUlCss = {position:"relative"}; oLiCss = {position:"absolute",display:"block"}; break; case "list": oUlCss = {height:"auto"}; oLiCss = {position:"static",display:"inline"}; break; } Rng.setSeed(oSettings.seed+123456); return this.each(function(i,o) { var mUl = $(o); var aLi = mUl.find(">li"); var iNumLi = aLi.length; var iUlW = mUl.width(); // var iUlH = oSettings.height===null?mUl.height():oSettings.height; var iUlH = oSettings.height===null?(.004*iUlW*iNumLi):oSettings.height; // var iUlH = oSettings.height===null?(aLi.height()*iNumLi):oSettings.height; mUl.css({width:iUlW,height:iUlH,listStyle:"none",margin:0,padding:0}); mUl.css(oUlCss); var iValMx = -2147483647; var iValMn = 2147483648; var iLastVal = -1; for (var j=0;jiValMx) iValMx = iVal; if (iVal0?0:this.M); return (this.seed*this.oneOverM); } Rng.rand = function(lrn, urn) { return Math.floor((urn - lrn + 1) * this.next() + lrn); } // hex dec function d2h(d) {return d.toString(16);} function h2d(h) {return parseInt(h,16);} // function getC(s,rgb) { // var aRng = [[[0,1],[1,2],[2,3]],[[0,2],[2,4],[4,6]]][s.length==3?0:1][rgb]; // return s.substring(aRng[0],aRng[1]); // } function getRGB(s) { var b3 = s.length==3; var aClr = []; for (var i=0;i<3;i++) { var sClr = s.substring( i*(b3?1:2), (i+1)*(b3?1:2) ); aClr.push(h2d(b3?sClr+sClr:sClr)); } return aClr; } function getHex(a) { var s = ""; for (var i=0;i<3;i++) { var c = d2h(a[i]); if (c.length==1) c = "0"+c; // todo: this can be better s += c; } return s; } function colorRng(mn,mx,prt) { var aMin = getRGB(mn); var aMax = getRGB(mx); var aRtr = []; for (var i=0;i<3;i++) aRtr.push( aMin[i] + Math.floor(prt*(aMax[i]-aMin[i])) ); return getHex(aRtr); } // trace function trace(o) { if (window.console&&window.console.log) { if (typeof(o)=="string") window.console.log(o); else for (var prop in o) window.console.log(prop+": "+o[prop]); } }; // set functions $.fn.TagCloud = $.fn.Tagcloud = $.fn.tagcloud; })(jQuery);