////////////////////////////////////////////// 
//            SoundOutTheBox pie            // 
//  Copyright © SoundOutTheBox 2012-2013    // 
//           License-CC-BY-NC-ND            // 
////////////////////////////////////////////// 
(function(d){d.widget("mui.pie",{options:{publicVariables:{Name:{value:"no name",type:"StringData",dynamic:!1},Left:{value:0,type:"IntegerData",dynamic:!1},Top:{value:0,type:"IntegerData",dynamic:!1},Width:{value:300,type:"IntegerData",dynamic:!1},Height:{value:300,type:"IntegerData",dynamic:!1},Datas:{value:'[ { value: 30, color:"#F38630" }, { value : 50, color : "#E0E4CC" },\t{ value : 100, color : "#69D2E7" } ]',type:"StringData",write:!0,dynamic:!0},SegmentStrokeWidth:{value:2,type:"IntegerData",
dynamic:!1},SegmentStrokeColor:{value:"255,255,255",type:"StringData",subtype:"Color",dynamic:!1},Visible:{value:["no","yes"],type:"EnumData",defaultvalue:"yes",write:!0,dynamic:!0}},privateVariables:{pageNumber:0,motifType:0,userScreen:0,canvasPie:null,myPie:null},config:{main:"pie.js",description:"Pies are divided into segments, the arc of each segment shows a the proportional value of each piece of data. They are excellent at showing the relational proportions between data.",author:"SoundOutTheBox",
version:"1.0.0.0.Final",dependencies:["./js/Chart.min.js"],widgetID:"67986b6763616297366b696c646060619637956a6a619561616b386a6d976168",widgetPackages:["696f6a689166649538689c97649662646d3264696d616296699663699c666764"]}},_create:function(){this.options.privateVariables.font=new goFont},_init:function(){},_destroy:function(){},_setOption:function(){d.Widget.prototype._setOption.apply(this,arguments)},_render:function(){var b=this.options.publicVariables,a=b.Top.value,c=b.Height.value,h=b.Left.value,e=b.Width.value,g=b.SegmentStrokeWidth.value,i=g===0?!1:!0,j=b.SegmentStrokeColor.value,
k=b.Datas.value,f=this.element;console.log("_render()  object="+b.Name);f.disableSelection();f.css({position:"absolute",left:h+"px",top:a+"px",width:e+"px",height:c+"px",zIndex:10});f.addClass("dynamicObject");a=d('<canvas style="width: '+e+"px; height: "+c+'px;"/>');a.appendTo(f);this.options.privateVariables.canvasPie=a;this.options.privateVariables.canvasPie[0].getContext("2d").canvas.width=e;this.options.privateVariables.canvasPie[0].getContext("2d").canvas.height=c;myPie=(new Chart(this.options.privateVariables.canvasPie[0].getContext("2d"))).Pie(eval(k),
{animation:!1,segmentStrokeWidth:g,segmentShowStroke:i,segmentStrokeColor:j});this.options.privateVariables.myPie=myPie;this.setVisible(b.Visible.value)},readFromXML:function(b){var a=this.options.publicVariables,b=d(b);a.Name.value=UTIL.getStringAttr(b,"Name",a.Name.value);a.Datas.value=UTIL.getStringAttr(b,"Datas",a.Datas.value);a.SegmentStrokeWidth.value=UTIL.getIntAttr(b,"SegmentStrokeWidth",a.SegmentStrokeWidth.value);a.SegmentStrokeColor.value=UTIL.getColorAttr(b,"SegmentStrokeColor",a.SegmentStrokeColor.value);
a.Visible.value=UTIL.getStringAttr(b,"Visible",a.Visible.value);UTIL.readPositionFromXML(b,a)},setDatas:function(b){var a=this.options.publicVariables,c=a.Datas.value,d=a.SegmentStrokeWidth.value,e=d===0?!1:!0,a=a.SegmentStrokeColor.value;if(!UTIL.isNull(c)&&!UTIL.isNull(b)&&eval(c)!==eval(b))this.options.privateVariables.myPie=null,c=(new Chart(this.options.privateVariables.canvasPie[0].getContext("2d"))).Pie(eval(b),{animation:!1,segmentStrokeWidth:d,segmentShowStroke:e,segmentStrokeColor:a}),this.options.publicVariables.Datas.value=
b,this.options.privateVariables.myPie=c},setVisible:function(b){var a=this.options.publicVariables,c=this.element;if(b!==a.Visible.value)a.Visible.value=b;a.Visible.value!=="no"?UTIL.setOpacity(c,1):UTIL.setOpacity(c,0)},onPropertyChange:function(b,a){switch(b){case "Datas":this.setDatas(a);break;case "Visible":this.setVisible(a)}},onReleaseCapture:function(){}})})(jQuery);
