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