// JenScript - 1.3.2 2017-06-10 // http://jenscript.io - Copyright 2017 Sébastien Janaud. All Rights reserved !function(){JenScript.Donut3DPlugin=function(a){a=a||{},a.name="Donut3DPlugin",this.donuts=[],JenScript.Plugin.call(this,a)},JenScript.Model.inheritPrototype(JenScript.Donut3DPlugin,JenScript.Plugin),JenScript.Model.addMethods(JenScript.Donut3DPlugin,{addDonut:function(a){a.plugin=this,this.donuts[this.donuts.length]=a,this.repaintPlugin()},onProjectionRegister:function(){var a=this;this.getProjection().addProjectionListener("boundChanged",function(){a.repaintPlugin()},"donut3D projection bound changed")},repaintDonuts:function(){this.repaintPlugin()},paintPlugin:function(a,b){if(b===JenScript.ViewPart.Device)for(var c=0;cc;c++)a(c)},shift:function(a,b,c){function d(a){setTimeout(function(){g.startAngleDegree=g.startAngleDegree+f>360?g.startAngleDegree+f-360:g.startAngleDegree+f<0?g.startAngleDegree+f+360:g.startAngleDegree+f,g.plugin.repaintDonuts()},a*e)}for(var e=b/c,f=a/c,g=this,h=0;c>h;h++)d(h)},addSlice:function(a){return a.donut=this,this.slices[this.slices.length]=a,this.plugin.repaintDonuts(),this},slice:function(a){var b=new JenScript.Donut3DSlice(a);return this.addSlice(b),this},addSlices:function(a){for(var b=0;b0},solveDonut3D:function(){if(this.tilt<0||this.tilt>90)throw new Error("donut 3D tilt out of range[0,90]");var a=this;!function(){if(a.startAngleDegree>0){if(a.startAngleDegree>=360)for(;a.startAngleDegree>=360;)a.startAngleDegree=a.startAngleDegree-360}else for(;a.startAngleDegree>=0;)a.startAngleDegree=a.startAngleDegree+360}(),function(){var b=a.thickness/90;a.projectionThickness=b*(90-a.tilt)}(),function(){var b=a.outerRadius/90,c=a.innerRadius/90;a.outerA=a.outerRadius,a.outerB=b*a.tilt,a.innerA=a.innerRadius,a.innerB=c*a.tilt}(),function(){for(var b=0,c=0;c360&&(b-=360)},solveSliceFragments:function(a,b){a.clearFragments(),a.painted=!1;var c=b,d=360*a.normalizedValue;a.startAngleDegree=c,a.endAngleDegree=c+d;var e=c+d/2;e>360&&(e-=360),a.medianDegree=e;var f=this.getDonutCenter(),g=f.x+a.divergence*Math.cos(JenScript.Math.toRadians(e)),h=f.y-a.divergence*Math.sin(JenScript.Math.toRadians(e));a.sc={x:g,y:h};for(var i=c,j=d,k=d;k>0;){j=this.getFragmentExtendsDegree(c,d,i,k);var l=this.createSliceFragment(a,i,j);a.addFragment(l),k-=j,i+=j,i>=360&&(i-=360)}},getFragmentExtendsDegree:function(a,b,c,d){if(c>=0&&180>c){var e=180-c;return d>=e?e:d}if(c>=180&&360>c){var e=360-c;return d>=e?e:d}return 0},getDonutCenter:function(){return"User"===this.nature?this.plugin.getProjection().userToPixel({x:this.centerX,y:this.centerY}):"Device"==this.nature?{x:this.centerX,y:this.centerY}:void 0},createSliceFragment:function(a,b,c){var d=new JenScript.Donut3DSlice({name:a.name+".part",value:1,themeColor:a.themeColor});d.fragment=!0,d.parentSlice=a,b>=0&&180>b?(d.type="Back",d.name=d.name+".back"):b>=180&&360>b&&(d.type="Front",d.name=d.name+".front");var e=this.getDonutCenter(),f=a.divergence/90,g=f*this.tilt,h=a.divergence,i=g,j=e.x+h*Math.cos(JenScript.Math.toRadians(a.startAngleDegree+Math.abs(a.endAngleDegree-a.startAngleDegree)/2)),k=e.y-i*Math.sin(JenScript.Math.toRadians(a.startAngleDegree+Math.abs(a.endAngleDegree-a.startAngleDegree)/2)),l={x:j+this.outerA*Math.cos(JenScript.Math.toRadians(b)),y:k-this.outerB*Math.sin(JenScript.Math.toRadians(b))},m={x:j+this.outerA*Math.cos(JenScript.Math.toRadians(b+c)),y:k-this.outerB*Math.sin(JenScript.Math.toRadians(b+c))};d.sos=l,d.soe=m;var n=c>180?"1":"0",o="M"+l.x+","+l.y+" A"+this.outerA+","+this.outerB+" 0 "+n+",0 "+m.x+","+m.y,p="M"+l.x+","+(l.y+this.projectionThickness)+" A"+this.outerA+","+this.outerB+" 0 "+n+",0 "+m.x+","+(m.y+this.projectionThickness);d.outerArcTop=o,d.outerArcBottom=p;var q={x:j+this.innerA*Math.cos(JenScript.Math.toRadians(b)),y:k-this.innerB*Math.sin(JenScript.Math.toRadians(b))},r={x:j+this.innerA*Math.cos(JenScript.Math.toRadians(b+c)),y:k-this.innerB*Math.sin(JenScript.Math.toRadians(b+c))};d.sis=q,d.sie=r;var s="M"+q.x+","+q.y+" A"+this.innerA+","+this.innerB+" 0 "+n+",0 "+r.x+","+r.y,t="M"+q.x+","+(q.y+this.projectionThickness)+" A"+this.innerA+","+this.innerB+" 0 "+n+",0 "+r.x+","+(r.y+this.projectionThickness);d.innerArcTop=s,d.innerArcBottom=t;var u="M"+l.x+","+l.y+" A"+this.outerA+","+this.outerB+" 0 "+n+",0 "+m.x+","+m.y+" L "+r.x+","+r.y+" A"+this.innerA+","+this.innerB+" 0 "+n+",1 "+q.x+","+q.y+" Z";d.topFace=u;var v="M"+l.x+","+(l.y+this.projectionThickness)+" A"+this.outerA+","+this.outerB+" 0 "+n+",0 "+m.x+","+(m.y+this.projectionThickness)+" L "+r.x+","+(r.y+this.projectionThickness)+" A"+this.innerA+","+this.innerB+" 0 "+n+",1 "+q.x+","+(q.y+this.projectionThickness)+" Z";return d.bottomFace=v,d.startFace="M "+l.x+","+l.y+" L "+q.x+","+q.y+" L "+q.x+","+(q.y+this.projectionThickness)+" L "+l.x+","+(l.y+this.projectionThickness)+" Z",d.endFace="M "+m.x+","+m.y+" L "+r.x+","+r.y+" L "+r.x+","+(r.y+this.projectionThickness)+" L "+m.x+","+(m.y+this.projectionThickness)+" Z",d.innerFace="M "+q.x+","+q.y+" A "+this.innerA+","+this.innerB+" 0 "+n+",0 "+r.x+","+r.y+" L "+r.x+","+(r.y+this.projectionThickness)+" A "+this.innerA+","+this.innerB+" 0 "+n+",1 "+q.x+","+(q.y+this.projectionThickness)+" Z",d.outerFace="M "+l.x+","+l.y+" A "+this.outerA+","+this.outerB+" 0 "+n+",0 "+m.x+","+m.y+" L "+m.x+","+(m.y+this.projectionThickness)+" A "+this.outerA+","+this.outerB+" 0 "+n+",1 "+l.x+","+(l.y+this.projectionThickness)+" Z",d.startAngleDegree=b,d.endAngleDegree=b+c,d},isIn:function(a,b){for(var c=0;cb||b>360||0>c||c>360)throw new Error("StarAngleDegree and EndAngleDegree out of range [0,360]");if(b>c)throw new Error("EndAngleDegree should be greater than StartAngleDegree");for(var d=[],e=0;e=b&&f.endAngleDegree>=b&&f.startAngleDegree<=c&&f.endAngleDegree<=c?d[d.length]=f:f.startAngleDegree<=b&&f.endAngleDegree>=b&&f.startAngleDegree<=c&&f.endAngleDegree<=c?d[d.length]=f:f.startAngleDegree>=b&&f.endAngleDegree>=b&&f.startAngleDegree<=c&&f.endAngleDegree>=c?d[d.length]=f:f.startAngleDegree<=b&&f.endAngleDegree>=b&&f.startAngleDegree<=c&&f.endAngleDegree>=c&&(d[d.length]=f)}return d},getSliceOnAngle:function(a){if(0>a&&a>360)throw new Error("angleDegree out of range [0,360]");for(var b=0;b=a)return c}else if(c.endAngleDegree>360){var d=a;a=d;if(e&&f)return c}}return void 0},getSlicesOnAngle:function(a){if(0>a&&a>360)throw new Error("angleDegree out of range [0,360]");for(var b=[],c=0;c=a&&(b[b.length]=d);else if(d.endAngleDegree>360){var e=a;a=e;f&&g&&(b[b.length]=d)}}return b},getSlicesOnRangeAngle:function(a,b){if(0>a||a>360||0>b||b>360)throw new Error("StarAngleDegree and EndAngleDegree out of range [0,360]");if(a>b)throw new Error("EndAngleDegree should be greater than StartAngleDegree");for(var c=[],d=0;d=a&&e.endAngleDegree>=a&&e.startAngleDegree<=b&&e.endAngleDegree<=b?c[c.length]=e:e.startAngleDegree<=a&&e.endAngleDegree>=a&&e.startAngleDegree<=b&&e.endAngleDegree<=b?c[c.length]=e:e.startAngleDegree>=a&&e.endAngleDegree>=a&&e.startAngleDegree<=b&&e.endAngleDegree>=b?c[c.length]=e:e.startAngleDegree<=a&&e.endAngleDegree>=a&&e.startAngleDegree<=b&&e.endAngleDegree>=b&&(c[c.length]=e)}return c},getPaintOrder:function(){this.getPaintOrderFragments();for(var a=[],b=this.getSlicesOnAngle(90),c=this.getSlicesOnAngle(270),d=0;d=90&&(a[a.length]=k)}for(var d=0;d=0;d--){var w=v[d];if(void 0!==w&&!this.isIn(w,a))if(this.isIn(w,i))for(var g=0;g=270)}if(this.fillBackEnd&&"Back"===c.type&&c.parentSlice.isLast(c)){var k=(new JenScript.SVGElement).name("path").attr("d",c.endFace).attr("opacity",this.alphaFill).attr("fill",c.themeColor).buildHTML();b.svg.donutRoot.appendChild(k),c.parentSlice.isLast(c)&&c.endAngleDegree>=90&&c.endAngleDegree<=270}if(this.fillBackTop&&"Back"===c.type){var l=(new JenScript.SVGElement).name("path").attr("d",c.topFace).attr("opacity",this.alphaFill).attr("fill",c.themeColor).buildHTML();b.svg.donutRoot.appendChild(l)}if(this.fillFrontInner&&"Front"===c.type){var m=(new JenScript.SVGElement).name("path").attr("d",c.innerFace).attr("opacity",this.alphaFill).attr("fill",c.themeColor).buildHTML();b.svg.donutRoot.appendChild(m)}if(this.fillFrontBottom&&"Front"===c.type){var e=(new JenScript.SVGElement).name("path").attr("d",c.bottomFace).attr("opacity",this.alphaFill).attr("fill",c.themeColor).buildHTML();b.svg.donutRoot.appendChild(e)}if(this.fillFrontStart&&"Front"===c.type&&c.parentSlice.isFirst(c)){var j=(new JenScript.SVGElement).name("path").attr("d",c.startFace).attr("opacity",this.alphaFill).attr("fill",c.themeColor).buildHTML();b.svg.donutRoot.appendChild(j),c.parentSlice.isFirst(c)&&(c.startAngleDegree<90||c.startAngleDegree>270)}if(this.fillFrontEnd&&"Front"===c.type&&c.parentSlice.isLast(c)){var k=(new JenScript.SVGElement).name("path").attr("d",c.endFace).attr("opacity",this.alphaFill).attr("fill",c.themeColor).buildHTML();b.svg.donutRoot.appendChild(k),c.parentSlice.isLast(c)&&c.endAngleDegree>90&&c.endAngleDegree<270}if(this.fillFrontOuter&&"Front"===c.type){var d=(new JenScript.SVGElement).name("path").attr("d",c.outerFace).attr("opacity",this.alphaFill).attr("fill",c.themeColor).buildHTML();b.svg.donutRoot.appendChild(d)}if(this.fillFrontTop&&"Front"===c.type){var l=(new JenScript.SVGElement).name("path").attr("d",c.topFace).attr("opacity",this.alphaFill).attr("fill",c.themeColor).buildHTML();b.svg.donutRoot.appendChild(l)}}})}(),function(){JenScript.Donut3DAbstractLabel=function(a){this._init(a)},JenScript.Model.inheritPrototype(JenScript.Donut3DAbstractLabel,JenScript.AbstractLabel),JenScript.Model.addMethods(JenScript.Donut3DAbstractLabel,{_init:function(a){JenScript.AbstractLabel.call(this,a)},paintDonut3DSliceLabel:function(){throw new Error("paintDonut3DSliceLabel method should be provide by override")}}),JenScript.Donut3DBorderLabel=function(a){this.__init(a)},JenScript.Model.inheritPrototype(JenScript.Donut3DBorderLabel,JenScript.Donut3DAbstractLabel),JenScript.Model.addMethods(JenScript.Donut3DBorderLabel,{__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.Donut3DBorderLabel",JenScript.Donut3DAbstractLabel.call(this,a)},setMargin:function(a){this.margin=a;var b=this.slice.donut.plugin.getGraphicsContext(JenScript.ViewPart.Device);this.paintDonut3DSliceLabel(b,this.slice)},setLinkExtends:function(a){this.linkExtends=a;var b=this.slice.donut.plugin.getGraphicsContext(JenScript.ViewPart.Device);this.paintDonut3DSliceLabel(b,this.slice)},paintDonut3DSliceLabel:function(a,b){var c=b.donut.getDonutCenter(),d=b.startAngleDegree+Math.abs(b.endAngleDegree-b.startAngleDegree)/2;d>=360&&(d-=360);var e=c.x+(b.donut.outerA+b.divergence)*Math.cos(JenScript.Math.toRadians(d)),f=c.y-(b.donut.outerB+b.divergence)*Math.sin(JenScript.Math.toRadians(d)),g=c.x+(b.donut.outerA+this.linkExtends+b.divergence)*Math.cos(JenScript.Math.toRadians(d)),h=c.y-(b.donut.outerB+this.linkExtends+b.divergence)*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=c.x+b.donut.outerA+this.margin-5,k=c.x+b.donut.outerA+this.margin+5,m="start",270===d&&(m="middle"),90===d&&(m="middle")):(i=c.x-b.donut.outerA-this.margin+5,k=c.x-b.donut.outerA-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.paintLabel(a),this.svg.label.appendChild(o)}}),JenScript.Donut3DRadialLabel=function(a){this.__init(a)},JenScript.Model.inheritPrototype(JenScript.Donut3DRadialLabel,JenScript.Donut3DAbstractLabel),JenScript.Model.addMethods(JenScript.Donut3DRadialLabel,{__init:function(a){a=a||{},this.offsetRadius=void 0!==a.offsetRadius?a.offsetRadius:20,a.name="JenScript.Donut3DRadialLabel",JenScript.Donut2DAbstractLabel.call(this,a)},setOffsetRadius:function(a){this.offsetRadius=a,this.slice.donut.plugin.repaintPlugin()},paintDonut3DSliceLabel:function(a,b){var c={x:b.sc.x+(b.donut.outerA+this.offsetRadius)*Math.cos(JenScript.Math.toRadians(b.medianDegree)),y:b.sc.y-(b.donut.outerB+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.paintLabel(a)}})}(),function(){JenScript.Donut3DBuilder=function(a,b,c){a.registerProjection(b);var d=new JenScript.Donut3DPlugin;b.registerPlugin(d);var e=new JenScript.Donut3D(c);d.addDonut(e);var f,g=[],h=[],i=function(a){var b=new JenScript.Donut3DSlice(a);return f=b,e.addSlice(b),h.push(b),this},j=function(a,b){var c;return"radial"===a&&(c=new JenScript.Donut3DRadialLabel(b)),"border"===a&&(c=new JenScript.Donut3DBorderLabel(b)),f.addSliceLabel(c),g.push(c),this},k=function(a,b){var c;return"reflection"===a&&(c=new JenScript.Donut3DReflectionEffect(b)),e.addEffect(c),effects.push(c),this},l=function(a){return k("reflection",a),this};return{slice:i,label:j,effect:k,reflectFx:l,view:function(){return a},projection:function(){return b},donut:function(){return e},labels:function(){return g},slices:function(){return i}}}}(),function(){JenScript.AbstractDonut3DEffect=function(a){this.init(a)},JenScript.Model.addMethods(JenScript.AbstractDonut3DEffect,{init:function(a){a=a||{},this.name=a.name},effectDonut3D:function(){}}),JenScript.Donut3DReflectionEffect=function(a){this._init(a)},JenScript.Model.inheritPrototype(JenScript.Donut3DReflectionEffect,JenScript.AbstractDonut3DEffect),JenScript.Model.addMethods(JenScript.Donut3DReflectionEffect,{_init:function(a){a=a||{},this.deviation=void 0!==a.deviation?a.deviation:3,this.opacity=void 0!==a.opacity?a.opacity:.3,this.length=void 0!==a.length?a.length:.5,this.verticalOffset=void 0!==a.verticalOffset?a.verticalOffset:0,a.name="JenScript.Donut3DReflectionEffect",JenScript.AbstractDonut3DEffect.call(this,a)},effectDonut3D:function(a,b){var c=b.svg.donutRoot.getBBox(),d="clip"+JenScript.sequenceId++,e=(new JenScript.SVGRect).origin(c.x,c.y+c.height).size(c.width,c.height*this.length),f=(new JenScript.SVGClipPath).Id(d).appendPath(e);a.definesSVG(f.toSVG());var g="filter"+JenScript.sequenceId++,h=(new JenScript.SVGFilter).Id(g).from(c.x,c.y).size(c.width,c.height).toSVG(),i=(new JenScript.SVGElement).name("feGaussianBlur").attr("in","SourceGraphic").attr("stdDeviation",this.deviation);h.appendChild(i.buildHTML()),a.definesSVG(h);var j=b.svg.donutRoot.cloneNode(!0);j.removeAttribute("id"),j.setAttribute("filter","url(#"+g+")"),j.setAttribute("transform","translate(0,"+c.height+"), scale(1,-1), translate(0,"+(-2*(c.y+c.height/2)-this.verticalOffset)+")"),j.setAttribute("opacity",this.opacity);var k=(new JenScript.SVGElement).name("g").buildHTML();j.setAttribute("id",j.getAttribute("id")+"_reflection"+JenScript.sequenceId++),k.setAttribute("clip-path","url(#"+d+")"),k.appendChild(j),a.insertSVG(k)}})}(); //# sourceMappingURL=jenscript-donut3d.min.js.map