(function(a){a.fn.simpledraw=function(c,b,d){if(d&&this[0].vcanvas)return this[0].vcanvas;if(c==undefined)c=a(this).innerWidth();if(b==undefined)b=a(this).innerHeight();return a.browser.hasCanvas?new e(c,b,this):a.browser.msie?new f(c,b,this):false};var c=[];a.fn.sparkline=function(d,b){var b=a.extend({type:"line",lineColor:"#00f",fillColor:"#cdf",defaultPixelsPerValue:3,width:"auto",height:"auto",composite:false},b?b:{});return this.each(function(){var e=function(){var e=d=="html"||d==undefined?a(this).text().split(","):d,f=b.width=="auto"?e.length*b.defaultPixelsPerValue:b.width;if(b.height=="auto"){if(!b.composite||!this.vcanvas){var c=document.createElement("span");c.innerHTML="a";a(this).html(c);height=a(c).innerHeight();a(c).remove()}}else height=b.height;a.fn.sparkline[b.type].call(this,e,b,f,height)};if(a(this).html()&&a(this).is(":hidden")||a.fn.jquery<"1.3.0"&&a(this).parents().is(":hidden"))c.push([this,e]);else e.call(this)})};a.sparkline_display_visible=function(){for(var b=c.length-1;b>=0;b--){var d=c[b][0];if(a(d).is(":visible")&&!a(d).parents().is(":hidden")){c[b][1].call(d);c.splice(b,1)}}};a.fn.sparkline.line=function(h,b,D,A){var b=a.extend({spotColor:"#f80",spotRadius:1.5,minSpotColor:"#f80",maxSpotColor:"#f80",lineWidth:1,normalRangeMin:undefined,normalRangeMax:undefined,normalRangeColor:"#ccc",chartRangeMin:undefined,chartRangeMax:undefined,chartRangeMinX:undefined,chartRangeMaxX:undefined},b?b:{}),j=[],f=[],s=[];for(c=0;c<h.length;c++){var J=h[c],B=typeof h[c]=="string",C=typeof h[c]=="object"&&h[c]instanceof Array,v=B&&h[c].split(":");if(B&&v.length==2){j.push(Number(v[0]));f.push(Number(v[1]));s.push(Number(v[1]))}else if(C){j.push(h[c][0]);f.push(h[c][1]);s.push(h[c][1])}else{j.push(c);if(h[c]===null||h[c]=="null")f.push(null);else{f.push(Number(h[c]));s.push(Number(h[c]))}}}if(b.xvalues)j=b.xvalues;var i=Math.max.apply(Math,s),z=i,g=Math.min.apply(Math,s),x=g,u=Math.max.apply(Math,j),H=u,m=Math.min.apply(Math,j),I=m;if(b.normalRangeMin!=undefined){if(b.normalRangeMin<g)g=b.normalRangeMin;if(b.normalRangeMax>i)i=b.normalRangeMax}if(b.chartRangeMin!=undefined&&(b.chartRangeClip||b.chartRangeMin<g))g=b.chartRangeMin;if(b.chartRangeMax!=undefined&&(b.chartRangeClip||b.chartRangeMax>i))i=b.chartRangeMax;if(b.chartRangeMinX!=undefined&&(b.chartRangeClipX||b.chartRangeMinX<m))m=b.chartRangeMinX;if(b.chartRangeMaxX!=undefined&&(b.chartRangeClipX||b.chartRangeMaxX>u))u=b.chartRangeMaxX;var t=u-m==0?1:u-m,p=i-g==0?1:i-g,q=f.length-1;if(q<1){this.innerHTML="";return}var l=a(this).simpledraw(D,A,b.composite);if(l){var k=l.pixel_width,e=l.pixel_height,n=0,o=0;if(b.spotRadius&&(k<b.spotRadius*4||e<b.spotRadius*4))b.spotRadius=0;if(b.spotRadius){if(b.minSpotColor||b.spotColor&&f[q]==g)e-=Math.ceil(b.spotRadius);if(b.maxSpotColor||b.spotColor&&f[q]==i){e-=Math.ceil(b.spotRadius);n+=Math.ceil(b.spotRadius)}if(b.minSpotColor||b.maxSpotColor&&(f[0]==g||f[0]==i)){o+=Math.ceil(b.spotRadius);k-=Math.ceil(b.spotRadius)}if(b.spotColor||(b.minSpotColor||b.maxSpotColor&&(f[q]==g||f[q]==i)))k-=Math.ceil(b.spotRadius)}e--;if(b.normalRangeMin!=undefined){var G=n+Math.round(e-e*((b.normalRangeMax-g)/p)),A=Math.round(e*(b.normalRangeMax-b.normalRangeMin)/p);l.drawRect(o,G,k,A,undefined,b.normalRangeColor)}for(var d=[],y=[d],c=0,F=f.length;c<F;c++){var w=j[c],r=f[c];if(r===null){if(c)if(f[c-1]!==null){d=[];y.push(d)}}else{if(r<g)r=g;if(r>i)r=i;!d.length&&d.push([o+Math.round((w-m)*(k/t)),n+e]);d.push([o+Math.round((w-m)*(k/t)),n+Math.round(e-e*((r-g)/p))])}}for(var c=0,E=y.length;c<E;c++){d=y[c];if(!d.length)continue;if(b.fillColor){d.push([d[d.length-1][0],n+e-1]);l.drawShape(d,undefined,b.fillColor);d.pop()}if(d.length>2)d[0]=[d[0][0],d[1][1]];l.drawShape(d,b.lineColor,undefined,b.lineWidth)}b.spotRadius&&b.spotColor&&l.drawCircle(o+Math.round(j[j.length-1]*(k/t)),n+Math.round(e-e*((f[q]-g)/p)),b.spotRadius,undefined,b.spotColor);if(i!=x){if(b.spotRadius&&b.minSpotColor){var w=j[f.indexOf(x)];l.drawCircle(o+Math.round((w-m)*(k/t)),n+Math.round(e-e*((x-g)/p)),b.spotRadius,undefined,b.minSpotColor)}if(b.spotRadius&&b.maxSpotColor){var w=j[f.indexOf(z)];l.drawCircle(o+Math.round((w-m)*(k/t)),n+Math.round(e-e*((z-g)/p)),b.spotRadius,undefined,b.maxSpotColor)}}}else this.innerHTML=""};a.fn.sparkline.bar=function(f,b,r,j){for(var b=a.extend({type:"bar",barColor:"#00f",negBarColor:"#f44",zeroColor:undefined,nullColor:undefined,zeroAxis:undefined,barWidth:4,barSpacing:1,chartRangeMax:undefined,chartRangeMin:undefined,chartRangeClip:false,colorMap:undefined},b?b:{}),r=f.length*b.barWidth+(f.length-1)*b.barSpacing,n=[],d=0,q=f.length;d<q;d++)if(f[d]=="null"||f[d]===null)f[d]=null;else{f[d]=Number(f[d]);n.push(Number(f[d]))}var i=Math.max.apply(Math,n),c=Math.min.apply(Math,n);if(b.chartRangeMin!=undefined&&(b.chartRangeClip||b.chartRangeMin<c))c=b.chartRangeMin;if(b.chartRangeMax!=undefined&&(b.chartRangeClip||b.chartRangeMax>i))i=b.chartRangeMax;if(b.zeroAxis==undefined)b.zeroAxis=c<0;var o=i-c==0?1:i-c;if(a.isArray(b.colorMap))var l=b.colorMap,m=null;else var l=null,m=b.colorMap;var k=a(this).simpledraw(r,j,b.composite);if(k)for(var u=k.pixel_width,g=k.pixel_height,p=c<0&&b.zeroAxis?g-Math.round(g*(Math.abs(c)/o))-1:g-1,d=0,q=f.length;d<q;d++){var s=d*(b.barWidth+b.barSpacing),e=f[d];if(e===null)if(b.nullColor){h=b.nullColor;e=b.zeroAxis&&c<0?0:c;var j=1,t=b.zeroAxis&&c<0?p:g-j}else continue;else{if(e<c)e=c;if(e>i)e=i;var h=e<0?b.negBarColor:b.barColor;if(b.zeroAxis&&c<0)var j=Math.round(g*(Math.abs(e)/o))+1,t=e<0?p:p-j;else var j=Math.round(g*((e-c)/o))+1,t=g-j;if(e==0&&b.zeroColor!=undefined)h=b.zeroColor;if(m&&m[e])h=m[e];else if(l&&l.length>d)h=l[d];if(h===null)continue}k.drawRect(s,t,b.barWidth-1,j-1,h,h)}else this.innerHTML=""};a.fn.sparkline.tristate=function(c,b,l,j){c=a.map(c,Number);var b=a.extend({barWidth:4,barSpacing:1,posBarColor:"#6f6",negBarColor:"#f44",zeroBarColor:"#999",colorMap:{}},b),l=c.length*b.barWidth+(c.length-1)*b.barSpacing;if(a.isArray(b.colorMap))var h=b.colorMap,i=null;else var h=null,i=b.colorMap;var g=a(this).simpledraw(l,j,b.composite);if(g)for(var p=g.pixel_width,k=g.pixel_height,f=Math.round(k/2),d=0,m=c.length;d<m;d++){var n=d*(b.barWidth+b.barSpacing);if(c[d]<0)var o=f,j=f-1,e=b.negBarColor;else if(c[d]>0)var o=0,j=f-1,e=b.posBarColor;else var o=f-1,j=2,e=b.zeroBarColor;if(i&&i[c[d]])e=i[c[d]];else if(h&&h.length>d)e=h[d];if(e===null)continue;g.drawRect(n,o,b.barWidth-1,j-1,e,e)}else this.innerHTML=""};a.fn.sparkline.discrete=function(c,b,h,p){c=a.map(c,Number);var b=a.extend({lineHeight:"auto",thresholdColor:undefined,thresholdValue:0,chartRangeMax:undefined,chartRangeMin:undefined,chartRangeClip:false},b);h=b.width=="auto"?c.length*2:h;var o=Math.floor(h/c.length),g=a(this).simpledraw(h,p,b.composite);if(g){var s=g.pixel_width,j=g.pixel_height,k=b.lineHeight=="auto"?Math.round(j*.3):b.lineHeight,l=j-k,d=Math.min.apply(Math,c),f=Math.max.apply(Math,c);if(b.chartRangeMin!=undefined&&(b.chartRangeClip||b.chartRangeMin<d))d=b.chartRangeMin;if(b.chartRangeMax!=undefined&&(b.chartRangeClip||b.chartRangeMax>f))f=b.chartRangeMax;for(var q=f-d,i=0,r=c.length;i<r;i++){var e=c[i];if(e<d)e=d;if(e>f)e=f;var n=i*o,m=Math.round(l-l*((e-d)/q));g.drawLine(n,m,n,m+k,b.thresholdColor&&e<b.thresholdValue?b.thresholdColor:b.lineColor)}}else this.innerHTML=""};a.fn.sparkline.bullet=function(c,b,j,r){c=a.map(c,Number);var b=a.extend({targetColor:"red",targetWidth:3,performanceColor:"blue",rangeColors:["#D3DAFE","#A8B6FF","#7F94FF"],base:undefined},b);j=b.width=="auto"?"4.0em":j;var e=a(this).simpledraw(j,r,b.composite);if(e&&c.length>1){var g=e.pixel_width-Math.ceil(b.targetWidth/2),f=e.pixel_height,d=Math.min.apply(Math,c),s=Math.max.apply(Math,c);if(b.base==undefined)var d=d<0?d:0;else d=b.base;var h=s-d;for(i=2,vlen=c.length;i<vlen;i++){var p=parseInt(c[i]),m=Math.round(g*((p-d)/h));e.drawRect(0,0,m-1,f-1,b.rangeColors[i-2],b.rangeColors[i-2])}var q=parseInt(c[1]),n=Math.round(g*((q-d)/h));e.drawRect(0,Math.round(f*.3),n-1,Math.round(f*.4)-1,b.performanceColor,b.performanceColor);var o=parseInt(c[0]),t=Math.round(g*((o-d)/h)-b.targetWidth/2),k=Math.round(f*.1),l=f-k*2;e.drawRect(t,k,b.targetWidth-1,l-1,b.targetColor,b.targetColor)}else this.innerHTML=""};a.fn.sparkline.pie=function(c,b,i,k){c=a.map(c,Number);var b=a.extend({sliceColors:["#f00","#0f0","#00f"]},b);i=b.width=="auto"?k:i;var f=a(this).simpledraw(i,k,b.composite);if(f&&c.length>1){for(var n=f.pixel_width,m=f.pixel_height,g=Math.floor(Math.min(n,m)/2),h=0,d=0,l=c.length;d<l;d++)h+=c[d];var e=0;if(b.offset)e+=2*Math.PI*(b.offset/360);for(var o=2*Math.PI,d=0,l=c.length;d<l;d++){var p=e,j=e;if(h>0)j=e+o*(c[d]/h);f.drawPieSlice(g,g,g,p,j,undefined,b.sliceColors[d%b.sliceColors.length]);e=j}}};function d(a,b){if(b==2){var c=Math.floor(a.length/2);return a.length%2?a[c]:(a[c]+a[c+1])/2}else{var d=Math.floor(a.length/4);return a.length%2?(a[d*b]+a[d*b+1])/2:a[d*b]}}a.fn.sparkline.box=function(c,b,p,u){c=a.map(c,Number);var b=a.extend({raw:false,boxLineColor:"black",boxFillColor:"#cdf",whiskerColor:"black",outlierLineColor:"#333",outlierFillColor:"white",medianColor:"red",showOutliers:true,outlierIQR:1.5,spotRadius:1.5,target:undefined,targetColor:"#4a2",chartRangeMax:undefined,chartRangeMin:undefined},b);p=b.width=="auto"?"4.0em":p;minvalue=b.chartRangeMin==undefined?Math.min.apply(Math,c):b.chartRangeMin;maxvalue=b.chartRangeMax==undefined?Math.max.apply(Math,c):b.chartRangeMax;var h=a(this).simpledraw(p,u,b.composite);if(h&&c.length>1){var o=h.pixel_width,e=h.pixel_height;if(b.raw)if(b.showOutliers&&c.length>5)var q=c[0],i=c[1],l=c[2],t=c[3],n=c[4],k=c[5],r=c[6];else var i=c[0],l=c[1],t=c[2],n=c[3],k=c[4];else{c.sort(function(a,b){return a-b});var l=d(c,1),t=d(c,2),n=d(c,3),s=n-l;if(b.showOutliers){for(var i=undefined,k=undefined,j=0,v=c.length;j<v;j++){if(i==undefined&&c[j]>l-s*b.outlierIQR)i=c[j];if(c[j]<n+s*b.outlierIQR)k=c[j]}var q=c[0],r=c[c.length-1]}else var i=c[0],k=c[c.length-1]}var g=o/(maxvalue-minvalue+1),f=0;if(b.showOutliers){f=Math.ceil(b.spotRadius);o-=2*Math.ceil(b.spotRadius);var g=o/(maxvalue-minvalue+1);q<i&&h.drawCircle((q-minvalue)*g+f,e/2,b.spotRadius,b.outlierLineColor,b.outlierFillColor);r>k&&h.drawCircle((r-minvalue)*g+f,e/2,b.spotRadius,b.outlierLineColor,b.outlierFillColor)}h.drawRect(Math.round((l-minvalue)*g+f),Math.round(e*.1),Math.round((n-l)*g),Math.round(e*.8),b.boxLineColor,b.boxFillColor);h.drawLine(Math.round((i-minvalue)*g+f),Math.round(e/2),Math.round((l-minvalue)*g+f),Math.round(e/2),b.lineColor);h.drawLine(Math.round((i-minvalue)*g+f),Math.round(e/4),Math.round((i-minvalue)*g+f),Math.round(e-e/4),b.whiskerColor);h.drawLine(Math.round((k-minvalue)*g+f),Math.round(e/2),Math.round((n-minvalue)*g+f),Math.round(e/2),b.lineColor);h.drawLine(Math.round((k-minvalue)*g+f),Math.round(e/4),Math.round((k-minvalue)*g+f),Math.round(e-e/4),b.whiskerColor);h.drawLine(Math.round((t-minvalue)*g+f),Math.round(e*.1),Math.round((t-minvalue)*g+f),Math.round(e*.9),b.medianColor);if(b.target){var m=Math.ceil(b.spotRadius);h.drawLine(Math.round((b.target-minvalue)*g+f),Math.round(e/2-m),Math.round((b.target-minvalue)*g+f),Math.round(e/2+m),b.targetColor);h.drawLine(Math.round((b.target-minvalue)*g+f-m),Math.round(e/2),Math.round((b.target-minvalue)*g+f+m),Math.round(e/2),b.targetColor)}}else this.innerHTML=""};if(!Array.prototype.indexOf)Array.prototype.indexOf=function(b){for(var a=0,c=this.length;a<c;a++)if(this[a]==b)return a;return-1};a.browser.msie&&!document.namespaces.v&&document.namespaces.add("v","urn:schemas-microsoft-com:vml","#default#VML");if(a.browser.hasCanvas==undefined){var g=document.createElement("canvas");a.browser.hasCanvas=g.getContext!=undefined}var b=function(){};b.prototype={init:function(c,b,a){this.width=c;this.height=b;this.target=a;if(a[0])a=a[0];a.vcanvas=this},drawShape:function(){alert("drawShape not implemented")},drawLine:function(c,e,d,f,a,b){return this.drawShape([[c,e],[d,f]],a,b)},drawCircle:function(){alert("drawCircle not implemented")},drawPieSlice:function(){alert("drawPieSlice not implemented")},drawRect:function(){alert("drawRect not implemented")},getElement:function(){return this.canvas},_insert:function(c,b){a(b).html(c)}};var e=function(c,a,b){return this.init(c,a,b)};e.prototype=a.extend(new b,{_super:b.prototype,init:function(d,c,b){this._super.init(d,c,b);this.canvas=document.createElement("canvas");if(b[0])b=b[0];b.vcanvas=this;a(this.canvas).css({display:"inline-block",width:d,height:c,verticalAlign:"top"});this._insert(this.canvas,b);this.pixel_height=a(this.canvas).height();this.pixel_width=a(this.canvas).width();this.canvas.width=this.pixel_width;this.canvas.height=this.pixel_height;a(this.canvas).css({width:this.pixel_width,height:this.pixel_height})},_getContext:function(c,b,d){var a=this.canvas.getContext("2d");if(c!=undefined)a.strokeStyle=c;a.lineWidth=d==undefined?1:d;if(b!=undefined)a.fillStyle=b;return a},drawShape:function(b,e,d,f){var a=this._getContext(e,d,f);a.beginPath();a.moveTo(b[0][0]+.5,b[0][1]+.5);for(var c=1,g=b.length;c<g;c++)a.lineTo(b[c][0]+.5,b[c][1]+.5);e!=undefined&&a.stroke();d!=undefined&&a.fill()},drawCircle:function(e,f,d,c,b){var a=this._getContext(c,b);a.beginPath();a.arc(e,f,d,0,2*Math.PI,false);c!=undefined&&a.stroke();b!=undefined&&a.fill()},drawPieSlice:function(b,c,h,f,g,e,d){var a=this._getContext(e,d);a.beginPath();a.moveTo(b,c);a.arc(b,c,h,f,g,false);a.lineTo(b,c);a.closePath();e!=undefined&&a.stroke();d&&a.fill()},drawRect:function(a,b,d,c,f,e){return this.drawShape([[a,b],[a+d,b],[a+d,b+c],[a,b+c],[a,b]],f,e)}});var f=function(c,a,b){return this.init(c,a,b)};f.prototype=a.extend(new b,{_super:b.prototype,init:function(d,c,b){this._super.init(d,c,b);if(b[0])b=b[0];b.vcanvas=this;this.canvas=document.createElement("span");a(this.canvas).css({display:"inline-block",position:"relative",overflow:"hidden",width:d,height:c,margin:"0px",padding:"0px",verticalAlign:"top"});this._insert(this.canvas,b);this.pixel_height=a(this.canvas).height();this.pixel_width=a(this.canvas).width();this.canvas.width=this.pixel_width;this.canvas.height=this.pixel_height;var e='<v:group coordorigin="0 0" coordsize="'+this.pixel_width+" "+this.pixel_height+'" style="position:absolute;top:0;left:0;width:'+this.pixel_width+"px;height="+this.pixel_height+'px;"></v:group>';this.canvas.insertAdjacentHTML("beforeEnd",e);this.group=a(this.canvas).children()[0]},drawShape:function(d,f,e,c){for(var a=[],b=0,k=d.length;b<k;b++)a[b]=""+d[b][0]+","+d[b][1];var g=a.splice(0,1);c=c==undefined?1:c;var i=f==undefined?' stroked="false" ':' strokeWeight="'+c+'" strokeColor="'+f+'" ',j=e==undefined?' filled="false"':' fillColor="'+e+'" filled="true" ',h=a[0]==a[a.length-1]?"x ":"",l='<v:shape coordorigin="0 0" coordsize="'+this.pixel_width+" "+this.pixel_height+'" '+i+j+' style="position:absolute;left:0px;top:0px;height:'+this.pixel_height+"px;width:"+this.pixel_width+'px;padding:0px;margin:0px;"  path="m '+g+" l "+a.join(", ")+" "+h+'e"> </v:shape>';this.group.insertAdjacentHTML("beforeEnd",l)},drawCircle:function(d,e,a,c,b){d-=a+1;e-=a+1;var f=c==undefined?' stroked="false" ':' strokeWeight="1" strokeColor="'+c+'" ',g=b==undefined?' filled="false"':' fillColor="'+b+'" filled="true" ',h="<v:oval "+f+g+' style="position:absolute;top:'+e+"px; left:"+d+"px; width:"+a*2+"px; height:"+a*2+'px"></v:oval>';this.group.insertAdjacentHTML("beforeEnd",h)},drawPieSlice:function(d,e,a,b,c,g,f){if(b==c)return;if(c-b==2*Math.PI){b=0;c=2*Math.PI}var h=d+Math.round(Math.cos(b)*a),i=e+Math.round(Math.sin(b)*a),j=d+Math.round(Math.cos(c)*a),k=e+Math.round(Math.sin(c)*a);if(h==j&&i==k&&c-b<Math.PI)return;var m=[d-a,e-a,d+a,e+a,h,i,j,k],l=g==undefined?' stroked="false" ':' strokeWeight="1" strokeColor="'+g+'" ',n=f==undefined?' filled="false"':' fillColor="'+f+'" filled="true" ',o='<v:shape coordorigin="0 0" coordsize="'+this.pixel_width+" "+this.pixel_height+'" '+l+n+' style="position:absolute;left:0px;top:0px;height:'+this.pixel_height+"px;width:"+this.pixel_width+'px;padding:0px;margin:0px;"  path="m '+d+","+e+" wa "+m.join(", ")+' x e"> </v:shape>';this.group.insertAdjacentHTML("beforeEnd",o)},drawRect:function(a,b,d,c,f,e){return this.drawShape([[a,b],[a,b+c],[a+d,b+c],[a+d,b],[a,b]],f,e)}})})(jQuery)
