/*
 TeeChart(tm) for JavaScript(tm)
 @fileOverview TeeChart for JavaScript(tm)
 v1.4 - December 2012
 Copyright(c) 2012 by Steema Software SL. All Rights Reserved.
 http://www.steema.com

 Licensed with commercial and non-commercial attributes,
 specifically: http://www.steema.com/licensing/html5

 JavaScript is a trademark of Oracle Corporation.
*/
var Tee=Tee||{};
(function(){Tee.CircularGauge=function(n,l){function G(b,d){b.hover.value!=d&&(b.hover.value=d,b.hover.valid=null!==d,requestAnimFrame(function(){b.chart.draw()}))}Tee.Series.call(this,n,l);this.useAxes=!1;this.min=0;this.max=100;this.value=this.step=0;this.angle=280;this.rotation=0;this.rotateText=!1;this.shape="circle";this.drag={enabled:!0};var j=this.bevel=new Tee.Format(this.chart);j.gradient.visible=!0;j.gradient.colors=["white","blue","white"];j.shadow.visible=!1;j.visible=!0;j.stroke.fill=
"";var i=this.center=new Tee.Format(this.chart);i.stroke.fill="";i.gradient.visible=!0;i.size=10;i.visible=!0;i.shadow.visible=!0;i.gradient.offset={x:2,y:-2};i.location={x:0,y:0};i.top=new Tee.Format(this.chart);i.top.size=40;i.top.visible=!0;i.top.stroke.fill="";i.top.gradient.colors=["silver","white"];i.top.gradient.visible=!0;i.top.gradient.direction="topbottom";var r=this.ticks=new Tee.Format(this.chart);r.length=6;r.stroke.fill="silver";r.visible=!0;r.outside=!0;r.triangle=!1;r.fill="white";
var B=this.ticksBack=new Tee.Format(this.chart);B.stroke.fill="";B.fill="black";B.gradient.visible=!0;B.gradient.colors=["red","yellow","green"];B.gradient.direction="rightleft";B.visible=!0;B.radius=0;var f=this.minor=new Tee.Format(this.chart);f.stroke.fill="silver";f.visible=!0;f.count=4;f.shape="";var C=this.minorBack=new Tee.Format(this.chart);C.stroke.fill="";C.visible=!0;C.fill="white";C.gradient.visible=!0;C.gradient.direction="bottomtop";C.gradient.colors=["white","gray","white","silver"];
C.radius=0;this.hands=[];this.addHand=function(){var b=new Tee.Format(this.chart);b.size=6;b.length=60;b.back=20;b.gradient.visible=!0;b.gradient.colors[0]="orange";b.shadow.visible=!0;b.shadow.blur=12;b.shadow.color="black";b.stroke.fill="";b.pointer=!0;b.shape="needle";b.visible=!0;this.hands.push(b);return b};var R=this.hand=this.addHand(),H=this.back=new Tee.Format(this.chart);H.fill="black";H.visible=!0;H.gradient.visible=!0;H.gradient.colors=["black","gray"];H.stroke.fill="";var D=this.pointer=
new Tee.Format(this.chart);D.size=3;D.fill="black";D.stroke.fill="";D.visible=!0;var s=this.marks,j=s.format;s.location={x:0,y:10};s.visible=!0;j.fill="black";j.font.fill="white";j.gradient.visible=!0;j.gradient.colors=["gray","black"];j.shadow.visible=!0;j.shadow.blur=8;j.shadow.color="black";var d=this.format;d.visible=!0;d.gradient.visible=!0;d.gradient.colors=["white","black","white"];d.shadow.visible=!0;d.font.style="12px Verdana";d.font.fill="white";d.font.visible=!0;d.size=14;d.round={x:6,
y:6};d.padding=0.5;this.units=new Tee.Annotation(this.chart);this.units.transparent=!0;this.units.format.font.fill="orange";this.units.location={x:0,y:24};this.bounds=this.getRect();this.hover.enabled=!0;var I,P,v=this;this.animate=new Tee.Animation(this.chart,function(b){v.value=I+b*(P-I);v.chart.draw()});this.animate.duration=100;this.animate.onstop=function(){v.value=P;if(v.onchange)v.onchange(v);v.chart.draw()};var K,t,J,O,q,w,z,A,L,M;this.calcBounds=function(){return this.bounds.custom?this.bounds:
this.cellRect(this.bounds,!0)};this.draw=function(){function b(b,c,e,d,g){0<b.radius&&(e=0.01*m*b.radius);a.beginPath();a.arc(0,0,c,d,g,!1);a.arc(0,0,e,g,d,!0);b.draw(a,null,-e,-e,2*e,2*e)}function n(a,c,e){if(a.visible&&""!==a.fill)if(a.ranges&&0<a.ranges.length){var d=l,g,h=a.fill,i=a.gradient.visible,x=k.max-k.min,j=w-q;a.gradient.visible=!1;k.inverted&&(d+=j);for(var f=0;f<a.ranges.length;f++){var m=Math.min(k.max,a.ranges[f].value);g=0===f?m:m-a.ranges[f-1].value+k.min;g=k.inverted?d-j*(g-k.min)/
x:d+j*(g-k.min)/x;a.fill=a.ranges[f].fill;""!==a.fill&&(k.inverted?b(a,c,e,g,d):b(a,c,e,d,g));d=g;if(m>=k.max)break}a.fill=h;a.gradient.visible=i}else b(a,c,e,l,l+(w-q))}function h(b){if(b.visible)if("circle"==k.shape)b.ellipse(z,A,e,g);else if("segment"==k.shape){a.beginPath();var c=k.units.visible?275:240,d=l+0.01745*k.rotation+0.5*(6.283-0.01745*Math.max(c,k.angle)),h=0.5*e,i=0.5*g;a.arc(z,A,h,d,d+Math.max(0.01745*c,x),!1);a.closePath();b.draw(a,null,z-h,A-i,e,g)}else b.rectangle(z-0.5*e,A-0.5*
g,e,g);return b.visible}var x=0.01745*this.angle,c=this.calcBounds(),e,g;z=c.x+0.5*c.width;A=c.y+0.5*c.height;this.bounds.custom?(e=c.width,g=c.height):g=e=Math.min(c.width,c.height);var k=this,a=k.chart.ctx,l=1.57,m=e;for(q=0.01745*k.rotation+0.5*(6.283-x);6.283<=q;)q-=6.283;for(w=q+x;6.283<=w;)w-=6.283;this.drawHand=function(b){b.value=this.limitValue(b.value);var c=0.01745*this.rotation+0.5*(9.4248-x)+x*((this.inverted?this.max-b.value:b.value)-this.min)/j;L=z+0.0050*e*i.location.x;M=A+0.0050*
g*i.location.y;a.save();a.translate(L,M);a.rotate(c);var c=b.size,d=0.0050*m*b.back,h=Math.min(c,6),f=0.0050*m*b.length;a.beginPath();1<c?(a.moveTo(-d+h,-c),"needle"==b.shape?(a.quadraticCurveTo(-d,-c,-d,-c+h),a.lineTo(-d,c-h),a.quadraticCurveTo(-d,c,-d+h,c),a.lineTo(f,0)):(a.lineTo(-d+h,c),a.lineTo(f,c),a.lineTo(f,-c)),a.closePath()):(a.moveTo(-d,0),a.lineTo(f,0));1<c?b.draw(a,null,-d,-c,d+f,2*c):(b.stroke.prepare(),a.strokeStyle=b.fill,a.stroke());if(this.ondrawHand)this.ondrawHand(this,b);b.pointer&&
D.visible&&D.ellipse(0.5*(J+t),0,D.size,D.size);a.restore()};h(d)&&(e*=1-0.01*d.size,g*=1-0.01*d.size,this.bounds.custom||(m=g=e));h(this.bevel)&&(e*=1-0.0020*d.size,g*=1-0.0020*d.size,this.bounds.custom||(m=g=e));h(H);var p=r.outside,c=this.min,j=this.max-this.min,y=this.step;0===y&&(y=j/20);y=Math.max(0.1,y);t=p?0.48*m:0.41*m;K=t-m*0.01*r.length;O=p?0.39*m:this.rotateText?0.46*m:0.48*m;J=p?0.45*m:0.38*m;d.font.prepare();var v=d.textHeight("Wj"),v=Math.max(1,j/y/(m*x/6.283/v)|0);a.fillStyle=d.font.fill;
a.save();var E=z,F=A;k.bounds.custom&&(e>g?F+=0.75*g*g/e:E+=0.75*e*e/g);a.translate(E,F);a.rotate(q);n(B,K,t);n(C,J,t);var E=y*x/j/f.count,F=q,G=this.rotateText?0:0.3*d.textHeight("Wj"),I=0;for(!r.visible&&p&&(O=0.9*J);c<=this.max;){r.visible&&(p=(this.hover.enabled&&this.hover.valid?Math.abs(c-this.hover.value)<0.2*y?this.hover:null:null)||r,a.beginPath(),a.moveTo(0,K),r.triangle?(a.lineTo(-3,t),a.lineTo(3,t),a.closePath(),p.draw(a,-3,K,3,t)):(a.lineTo(0,t),p.stroke.prepare(),a.stroke()));if(d.font.visible&&
0===I%v&&(360!=this.angle||c+y<=this.max)){p=O-d.textHeight()*d.padding;a.translate(0,p);var N=this.rotateText?3.1416:F;a.rotate(-N);d.font.prepare();a.fillStyle=d.font.fill;var u=k.inverted?this.max-c:c,u=k.ongetText?k.ongetText(u):(u|0)==u?u.toFixed(0):u.toFixed(this.decimals);a.fillText(u,0,G);a.rotate(N);a.translate(0,-p)}if(f.visible){if(c<this.max)for(p=0;p<f.count;p++)if(a.rotate(E),p<f.count-1){u=y/f.count;N=c+(p+1)*u;u=(this.hover.enabled&&this.hover.valid?Math.abs(N-this.hover.value)<0.2*
u?this.hover:null:null)||f;if(N>this.max)break;"ellipse"==f.shape?f.ellipse(0,0.5*(J+t),f.size,f.size):(a.beginPath(),a.moveTo(0,J),a.lineTo(0,t),u.stroke.prepare(),a.stroke())}}else a.rotate(E*f.count);F+=E*f.count;c+=y;I++}a.restore();s.visible&&(s.text=this.value.toFixed(this.decimals),s.resize(),s.position.x=z-0.5*s.bounds.width+0.01*s.location.x*e,s.position.y=A+0.01*s.location.y*g,s.draw());c=this.units;c.visible&&(c.resize(),c.position.x=z-0.5*c.bounds.width+0.01*c.location.x*e,c.position.y=
A+0.01*c.location.y*g,c.draw(a));a.save();R.value=this.value;for(c=0;c<this.hands.length;c++)this.hands[c].visible&&this.drawHand(this.hands[c]);a.restore();i.visible&&(c=0.01*m*i.size,i.ellipse(L,M,c,c),i.top.visible&&(c=0.01*c*i.top.size,i.top.ellipse(L,M,c,c)))};this.limitValue=function(b){return Math.min(this.max,Math.max(this.min,b))};this.setValue=function(b){var b=this.limitValue(b),d=this.value!=b;if(d)if(this.animate.active&&0<this.animate.duration)I=this.value,P=b,this.animate.animate(this.chart);
else if(this.value=b,this.onchange)this.onchange(this);return d};this.onclick=function(){};this.clicked=function(){this.dragging=!1;return-1};this.inValue=function(b,d){if(!d.contains(b))return!1;for(var h=b.x-L,f=b.y-M,c=Math.sqrt(h*h+f*f),h=Math.atan2(f,h)-0.5*Math.PI;0>h;)h+=6.283;var e,g;q>w?(f=w,e=q,g=h>=e||h<=f):(e=w,f=q,g=h>=f&&h<=e);return g?(h=this.min+(this.max-this.min)*(q>w?h>e?(h-e)/(6.283-e+f):(6.283-e+h)/(6.283-e+f):(h-f)/(e-f)),this.inverted&&(h=this.max-h),b.value=h,b.inTicks=c>=
Math.min(K,O)&&c<=t,!0):b.inTicks=!1};this.mousemove=function(b){var d=this.calcBounds(),d=this.inValue(b,d);this.dragging?(d&&this.setValue(b.value)&&this.chart.draw(),this.chart.newCursor="pointer"):b.inTicks&&this.drag.enabled?(G(this,b.value),this.chart.newCursor="pointer"):G(this,null)};var Q={x:0,y:0};this.mousedown=function(b){if(this.drag.enabled){var d=this.calcBounds();this.chart.calcMouse(b,Q);this.inValue(Q,d)?(this.dragging=!0,this.hover.value=null,this.hover.valid=!1,this.setValue(Q.value)&&
this.chart.draw()):this.dragging=!1;return this.dragging}return!1}};Tee.CircularGauge.prototype=new Tee.Series;Tee.CircularGauge.prototype.setChart=function(n,l){var G=Tee.Series.prototype.setChart;G(n,l);n.back.setChart(l);n.center.setChart(l);n.center.top.setChart(l);n.ticks.setChart(l);n.ticksBack.setChart(l);n.minor.setChart(l);n.minorBack.setChart(l);n.hand.setChart(l);n.units.setChart(l);n.pointer.setChart(l);n.bevel.setChart(l)}})();
