// JenScript - 1.3.2 2017-06-10 // http://jenscript.io - Copyright 2017 Sébastien Janaud. All Rights reserved !function(){JenScript.PiePlugin=function(a){a=a||{},this.pies=[],this.pieListeners=[],JenScript.Plugin.call(this,{name:"PiePlugin"})},JenScript.Model.inheritPrototype(JenScript.PiePlugin,JenScript.Plugin),JenScript.Model.addMethods(JenScript.PiePlugin,{addPie:function(a){a.plugin=this,this.pies[this.pies.length]=a,this.repaintPlugin()},onProjectionRegister:function(){var a=this;this.getProjection().addProjectionListener("boundChanged",function(){a.repaintPlugin()},"Pie projection bound changed")},addPieListener:function(a,b){var c={action:a,onEvent:b};this.pieListeners[this.pieListeners.length]=c},firePieEvent:function(a,b){for(var c=0;ck.sc.x&&dk.sc.x&&d>=k.sc.y?m=Math.atan((k.sc.y-d)/(c-k.sc.x))+2*Math.PI:ck.sc.y&&(m=3*Math.PI/2),JenScript.Math.toDegrees(m)>k.startAngleDegree&&JenScript.Math.toDegrees(m)360&&k.startAngleDegree+k.extendsDegree-360>=JenScript.Math.toDegrees(m)?f(k):g(k)):g(k)}}return!1},onPress:function(a,b,c,d){this.dispatchPieAction(a,"press",c,d)},onRelease:function(a,b,c,d){this.dispatchPieAction(a,"release",c,d)},onMove:function(a,b,c,d){this.dispatchPieAction(a,"move",c,d)},onClick:function(a,b,c,d){this.dispatchPieAction(a,"click",c,d)},onEnter:function(a,b,c,d){this.dispatchPieAction(a,"enter",c,d)},onExit:function(a,b,c,d){this.dispatchPieAction(a,"exit",c,d)},paintPlugin:function(a,b){if(b===JenScript.ViewPart.Device)for(var c=0;c360&&(this.startAngleDegree=this.startAngleDegree-360),a.startAngleDegree=this.startAngleDegree,a.endAngleDegree=this.startAngleDegree+b;var c=this.startAngleDegree+b/2;c>360&&(c-=360),a.medianDegree=c;var d=function(a,b,c){return{x:a.x+b*Math.cos(JenScript.Math.toRadians(c)),y:a.y-b*Math.sin(JenScript.Math.toRadians(c))}},e=d(this.buildCenter,a.divergence,c),f=d(e,this.radius,a.startAngleDegree),g=d(e,this.radius,a.endAngleDegree);a.sc=e,a.ss=f,a.se=g;var h="0";b>180&&(h="1"),a.svgPath="M"+f.x+","+f.y+" A"+this.radius+","+this.radius+" 0 "+h+",0 "+g.x+","+g.y+" L"+e.x+","+e.y+" Z",this.startAngleDegree=this.startAngleDegree+b},projection:function(){if("User"==this.nature){var a=this.plugin.getProjection().userToPixel(new JenScript.Point2D(this.x,this.y));this.buildCenterX=a.x,this.buildCenterY=a.y,this.buildCenter=new JenScript.Point2D(this.buildCenterX,this.buildCenterY)}else"Device"==this.nature&&(this.buildCenterX=this.centerX,this.buildCenterY=this.centerY,this.buildCenter=new JenScript.Point2D(this.buildCenterX,this.buildCenterY))},solvePie:function(){{var a=this;!function(){for(var b=0,c=0;c0},shift:function(){function a(a){setTimeout(function(){b.startAngleDegree=b.startAngleDegree+36,b.plugin.repaintPlugin()},100*a)}for(var b=this,c=0;10>c;c++)a(c)}})}(),function(){JenScript.PieSlice=function(a){this.init(a)},JenScript.Model.addMethods(JenScript.PieSlice,{init:function(a){if(a=a||{},this.Id=void 0!==a.Id?a.Id:"slice"+JenScript.sequenceId++,this.name=void 0!==a.name?a.name:"PieSlice name undefined",this.value=void 0!==a.value?a.value:1,this.opacity=void 0!==a.opacity?a.opacity:1,this.themeColor=void 0!==a.themeColor?a.themeColor:JenScript.createColor(),this.divergence=void 0!==a.divergence?a.divergence:0,this.value<0)throw new Error("Slice value should be greater than 0")},repaint:function(){void 0!==this.pie&&this.pie.repaint()},setName:function(a){this.name=a},getName:function(){return this.name},setValue:function(a){if(this.value<0)throw new Error("Slice value should be greater than 0");this.value=a,this.repaint()},getValue:function(){return this.value},getRatio:function(){return this.ratio},setSliceLabel:function(a){void 0!==a&&(a.slice=this),this.sliceLabel=a,this.repaint()},getSliceLabel:function(){return this.sliceLabel},setThemeColor:function(a){this.themeColor=a,this.repaint()},getThemeColor:function(){return this.themeColor},setDivergence:function(a){this.divergence=a,this.repaint()},getDivergence:function(){return this.divergence}})}(),function(){JenScript.AbstractPieStroke=function(a){this.init(a)},JenScript.Model.addMethods(JenScript.AbstractPieStroke,{init:function(a){a=a||{},this.name=a.name},strokePie:function(){}}),JenScript.PieDefaultStroke=function(a){this._init(a)},JenScript.Model.inheritPrototype(JenScript.PieDefaultStroke,JenScript.AbstractPieStroke),JenScript.Model.addMethods(JenScript.PieDefaultStroke,{_init:function(a){a=a||{},this.strokeColor=a.strokeColor,this.strokeWidth=void 0!==a.strokeWidth?a.strokeWidth:1,a.name="JenScript.PieDefaultStroke",JenScript.AbstractPieStroke.call(this,a)},strokePie:function(a,b){for(var c=0;c180&&(f="1");var g=function(a,b,c){return{x:a.x+b*Math.cos(JenScript.Math.toRadians(c)),y:a.y-b*Math.sin(JenScript.Math.toRadians(c))}},h=g(e.sc,b.radius-this.offset,e.startAngleDegree),i=g(e.sc,b.radius-this.offset,e.endAngleDegree),j=g(e.sc,b.radius-this.offset,this.incidence),k=g(e.sc,b.radius-this.offset,this.incidence+180),l=["0%","49%","51%","100%"],m=["rgb(60,60,60)","rgb(255,255,255)","rgb(255,255,255)","rgb(255,255,255)"],n=[.8,0,0,.8];void 0===this.shader&&(this.shader={percents:l,colors:m,opacity:n});var o="gradient"+JenScript.sequenceId++;this.gradientIds[this.gradientIds.length]=o;var p=(new JenScript.SVGLinearGradient).Id(o).from(j.x,j.y).to(k.x,k.y).shade(this.shader.percents,this.shader.colors,this.shader.opacity).toSVG();a.definesSVG(p);var q="M"+h.x+","+h.y+" A"+(b.radius-this.offset)+","+(b.radius-this.offset)+" 0 "+f+",0 "+i.x+","+i.y+" L"+e.sc.x+","+e.sc.y+" Z",r=(new JenScript.SVGElement).name("path").attr("fill","url(#"+o+")").attr("d",q).attr("fill-opacity",this.fillOpacity).buildHTML();a.deleteGraphicsElement(b.Id+this.Id+e.Id);var s=(new JenScript.SVGGroup).Id(b.Id+this.Id+e.Id).opacity(e.opacity).toSVG();s.appendChild(r),c.appendChild(s)}b.svg.pieRoot.appendChild(c)}})}(),function(){JenScript.PieAbstractLabel=function(a){this._init(a)},JenScript.Model.inheritPrototype(JenScript.PieAbstractLabel,JenScript.AbstractLabel),JenScript.Model.addMethods(JenScript.PieAbstractLabel,{_init:function(a){JenScript.AbstractLabel.call(this,a)},paintPieSliceLabel:function(){throw new Error("paintPieSliceLabel method should be provide by override")}}),JenScript.PieBorderLabel=function(a){this.__init(a)},JenScript.Model.inheritPrototype(JenScript.PieBorderLabel,JenScript.PieAbstractLabel),JenScript.Model.addMethods(JenScript.PieBorderLabel,{__init:function(a){a=a||{},this.margin=void 0!==a.margin?a.margin:50,this.linkExtends=void 0!==a.linkExtends?a.linkExtends:30,a.name="JenScript.PieBorderLabel",JenScript.PieAbstractLabel.call(this,a)},setMargin:function(a){this.margin=a,this.slice.pie.plugin.repaintPlugin()},setLinkExtends:function(a){this.linkExtends=a,this.slice.pie.plugin.repaintPlugin()},paintPieSliceLabel:function(a,b){var c=b.pie.radius,d=b.medianDegree,e=b.pie.buildCenterX+(c+b.getDivergence())*Math.cos(JenScript.Math.toRadians(d)),f=b.pie.buildCenterY-(c+b.getDivergence())*Math.sin(JenScript.Math.toRadians(d)),g=b.pie.buildCenterX+(c+this.linkExtends+b.getDivergence())*Math.cos(JenScript.Math.toRadians(d)),h=b.pie.buildCenterY-(c+this.linkExtends+b.getDivergence())*Math.sin(JenScript.Math.toRadians(d)),i=0,j=h,k=0,l=h,m="middle";d>=270&&360>=d||d>=0&&90>=d?(i=b.pie.buildCenterX+c+this.margin-5,k=b.pie.buildCenterX+c+this.margin+5,m="start",270===d&&(m="middle"),90===d&&(m="middle")):(i=b.pie.buildCenterX-c-this.margin+5,k=b.pie.buildCenterX-c-this.margin-5,m="end");var n="M "+e+","+f+" Q "+g+","+h+" "+i+","+j,o=(new JenScript.SVGElement).name("path").attr("d",n).attr("fill","none").attr("stroke","darkgray").buildHTML();this.setTextAnchor(m),this.setLocation(new JenScript.Point2D(k,l));var p=void 0!==this.textColor?this.textColor:b.themeColor;this.setTextColor(p),this.setOpacity(b.opacity),this.paintLabel(a),this.svg.label.appendChild(o)}}),JenScript.PieRadialLabel=function(a){this.__init(a)},JenScript.Model.inheritPrototype(JenScript.PieRadialLabel,JenScript.PieAbstractLabel),JenScript.Model.addMethods(JenScript.PieRadialLabel,{__init:function(a){a=a||{},this.offsetRadius=void 0!==a.offsetRadius?a.offsetRadius:20,a.name="JenScript.PieRadialLabel",JenScript.PieAbstractLabel.call(this,a)},setOffsetRadius:function(a){this.offsetRadius=a,this.slice.pie.plugin.repaintPlugin()},paintPieSliceLabel:function(a,b){var c={x:b.sc.x+(b.pie.radius+this.offsetRadius)*Math.cos(JenScript.Math.toRadians(b.medianDegree)),y:b.sc.y-(b.pie.radius+this.offsetRadius)*Math.sin(JenScript.Math.toRadians(b.medianDegree))},d="middle",e=0;b.medianDegree>0&&b.medianDegree<90?(d="start",e=10):b.medianDegree>90&&b.medianDegree<270?(d="end",e=-10):b.medianDegree>270&&b.medianDegree<=360?(d="start",e=10):(90===b.medianDegree||270===b.medianDegree)&&(d="middle"),this.setLocation(new JenScript.Point2D(c.x,c.y)),this.setTextAnchor(d);var f=void 0!==this.textColor?this.textColor:b.themeColor;this.setTextColor(f),this.setOpacity(b.opacity),this.paintLabel(a)}})}(),function(){JenScript.PieBuilder=function(a,b,c){a.registerProjection(b);var d=new JenScript.PiePlugin;b.registerPlugin(d);var e=new JenScript.Pie(c);d.addPie(e);var f=new JenScript.PieDefaultFill;e.setFill(f);var g,h=[],i=[],j=[],k=function(a){var b=new JenScript.PieSlice(a);return g=b,e.addSlice(b),i.push(b),this},l=function(a,b){var c;return"radial"===a&&(c=new JenScript.PieRadialLabel(b)),"border"===a&&(c=new JenScript.PieBorderLabel(b)),g.setSliceLabel(c),h.push(c),this},m=function(a,b){var c;return"linear"===a&&(c=new JenScript.PieLinearEffect(b)),"reflection"===a&&(c=new JenScript.PieReflectionEffect(b)),e.addEffect(c),j.push(c),this},n=function(a){return m("linear",a),this},o=function(a){return m("reflection",a),this};return{slice:k,label:l,effect:m,linearFx:n,reflectFx:o,view:function(){return a},projection:function(){return b},pie:function(){return e},labels:function(){return h},slices:function(){return k},effects:function(){return j}}}}(); //# sourceMappingURL=jenscript-pie.min.js.map