text: !function(a){"use strict";var b="d3pie",c="0.1.0",d=0,e={header:{title:{text:"",color:"#333333",fontSize:18,font:"arial"},subtitle:{text:"",color:"#666666",fontSize:14,font:"arial"},location:"top-center",titleSubtitlePadding:8},footer:{text:"",color:"#666666",fontSize:14,font:"arial",location:"left"},size:{canvasHeight:500,canvasWidth:500,pieInnerRadius:"0%",pieOuterRadius:null},data:{sortOrder:"none",content:[]},labels:{outer:{format:"label",hideWhenLessThanPercentage:null,pieDistance:30},inner:{format:"percentage",hideWhenLessThanPercentage:null},mainLabel:{color:"#333333",font:"arial",fontSize:10},percentage:{color:"#dddddd",font:"arial",fontSize:10,decimalPlaces:0},value:{color:"#cccc44",font:"arial",fontSize:10},lines:{enabled:!0,style:"curved",color:"segment"},truncation:{enabled:!1,length:30}},effects:{load:{effect:"default",speed:1e3},pullOutSegmentOnClick:{effect:"bounce",speed:300,size:10},highlightSegmentOnMouseover:!0,highlightLuminosity:-.2},misc:{colors:{background:null,segments:["#98abc5","#8a89a6","#7b6888","#6b486b","#a05d56","#d0743c","#ff8c00","#635222","#00dd00"],segmentStroke:"#ffffff"},canvasPadding:{top:5,right:5,bottom:5,left:5},pieCenterOffset:{x:0,y:0},cssPrefix:null},callbacks:{onload:null,onMouseoverSegment:null,onMouseoutSegment:null,onClickSegment:null}},f={initialCheck:function(b){var c=b.cssPrefix,d=b.element,e=b.options;if(!window.d3||!window.d3.hasOwnProperty("version"))return console.error("d3pie error: d3 is not available"),!1;if(!(d instanceof HTMLElement))return console.error("d3pie error: the first d3pie() param must be a valid DOM element (not jQuery) or a ID string."),!1;if(!/[a-zA-Z][a-zA-Z0-9_-]*$/.test(c))return console.error("d3pie error: invalid options.misc.cssPrefix"),!1;if(!a.isArray(e.data.content))return console.error("d3pie error: invalid config structure: missing data.content property."),!1;if(0===e.data.content.length)return console.error("d3pie error: no data supplied."),!1;for(var f=[],g=0;g<e.data.content.length;g++)"number"==typeof e.data.content[g].value?f.push(e.data.content[g]):console.log("not valid: ",e.data.content[g]);return b.options.data.content=f,!0}},g={addSVGSpace:function(a){var b=a.element,c=a.options.size.canvasWidth,d=a.options.size.canvasHeight,e=a.options.misc.colors.background,f=d3.select(b).append("svg:svg").attr("width",c).attr("height",d);return"transparent"!==e&&f.style("background-color",function(){return e}),f},whenIdExists:function(a,b){var c=1,d=1e3,e=setInterval(function(){document.getElementById(a)&&(clearInterval(e),b()),c>d&&clearInterval(e),c++},1)},whenElementsExist:function(a,b){var c=1,d=1e3,e=setInterval(function(){for(var f=!0,g=0;g<a.length;g++)if(!document.getElementById(a[g])){f=!1;break}f&&(clearInterval(e),b()),c>d&&clearInterval(e),c++},1)},shuffleArray:function(a){for(var b,c,d=a.length;0!==d;)c=Math.floor(Math.random()*d),d-=1,b=a[d],a[d]=a[c],a[c]=b;return a},processObj:function(a,b,c){return"string"==typeof b?g.processObj(a,b.split("."),c):1==b.length&&void 0!==c?a[b[0]]=c:0==b.length?a:g.processObj(a[b[0]],b.slice(1),c)},getDimensions:function(a){var b=document.getElementById(a),c=0,d=0;if(b){var e=b.getBBox();c=e.width,d=e.height}else console.log("error: getDimensions() "+a+" not found.");return{w:c,h:d}},rectIntersect:function(a,b){var c=b.x>a.x+a.w||b.x+b.w<a.x||b.y+b.h<a.y||b.y>a.y+a.h;return!c},getColorShade:function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;for(var c="#",d=0;3>d;d++){var e=parseInt(a.substr(2*d,2),16);e=Math.round(Math.min(Math.max(0,e+e*b),255)).toString(16),c+=("00"+e).substr(e.length)}return c},initSegmentColors:function(a){for(var b=a.options.data,c=a.options.misc.colors.segments,d=[],e=0;e<b.length;e++)d.push(b[e].hasOwnProperty("color")?b[e].color:c[e]);return d},showPoint:function(a,b,c){a.append("circle").attr("cx",b).attr("cy",c).attr("r",2).style("fill","black")}},h={toRadians:function(a){return a*(Math.PI/180)},toDegrees:function(a){return a*(180/Math.PI)},computePieRadius:function(a){var b=a.options.size,c=a.options.misc.canvasPadding,d=b.canvasWidth-c.left-c.right,e=b.canvasHeight-c.top-c.bottom;a.textComponents.footer.exists&&(e-=a.textComponents.footer.h);var f,g,h=(e>d?d:e)/3;if(null!==b.pieOuterRadius)if(/%/.test(b.pieOuterRadius)){g=parseInt(b.pieOuterRadius.replace(/[\D]/,""),10),g=g>99?99:g,g=0>g?0:g;var i=e>d?d:e;h=Math.floor(i/100*g)/2}else h=parseInt(b.pieOuterRadius,10);/%/.test(b.pieInnerRadius)?(g=parseInt(b.pieInnerRadius.replace(/[\D]/,""),10),g=g>99?99:g,g=0>g?0:g,f=Math.floor(h/100*g)):f=parseInt(b.pieInnerRadius,10),a.innerRadius=f,a.outerRadius=h},getTotalPieSize:function(a){for(var b=0,c=0;c<a.length;c++)b+=a[c].value;return b},sortPieData:function(a){var b=a.options.data.content,c=a.options.data.sortOrder;switch(c){case"none":break;case"random":b=g.shuffleArray(b);break;case"value-asc":b.sort(function(a,b){return a.value<b.value?-1:1});break;case"value-desc":b.sort(function(a,b){return a.value<b.value?1:-1});break;case"label-asc":b.sort(function(a,b){return a.label.toLowerCase()>b.label.toLowerCase()?1:-1});break;case"label-desc":b.sort(function(a,b){return a.label.toLowerCase()<b.label.toLowerCase()?1:-1})}return b},getPieTranslateCenter:function(a){return"translate("+a.x+","+a.y+")"},calculatePieCenter:function(a){var b=a.options.misc.pieCenterOffset,c=a.textComponents.title.exists&&"pie-center"!==a.options.header.location,d=a.textComponents.subtitle.exists&&"pie-center"!==a.options.header.location,e=a.options.misc.canvasPadding.top;c&&d?e+=a.textComponents.title.h+a.options.header.titleSubtitlePadding+a.textComponents.subtitle.h:c?e+=a.textComponents.title.h:d&&(e+=a.textComponents.subtitle.h);var f=0;a.textComponents.footer.exists&&(f=a.textComponents.footer.h+a.options.misc.canvasPadding.bottom);var g=(a.options.size.canvasWidth-a.options.misc.canvasPadding.left-a.options.misc.canvasPadding.right)/2+a.options.misc.canvasPadding.left,h=(a.options.size.canvasHeight-f-e)/2+e;g+=b.x,h+=b.y,a.pieCenter={x:g,y:h}},rotate:function(a,b,c,d,e){var f=Math.cos,g=Math.sin,e=e*Math.PI/180,h=(a-c)*f(e)-(b-d)*g(e)+c,i=(a-c)*g(e)+(b-d)*f(e)+d;return{x:h,y:i}},translate:function(a,b,c,d){var e=h.toRadians(d);return{x:a+c*Math.sin(e),y:b-c*Math.cos(e)}},pointIsInArc:function(a,b,c){var d=c.innerRadius()(b),e=c.outerRadius()(b),f=c.startAngle()(b),g=c.endAngle()(b),h=a.x*a.x+a.y*a.y,i=Math.atan2(a.x,-a.y);return i=0>i?i+2*Math.PI:i,h>=d*d&&e*e>=h&&i>=f&&g>=i}},i={add:function(a,b,c){var d=i.getIncludes(c),e=a.options.labels,f=a.svg.insert("g","."+a.cssPrefix+"labels-"+b).attr("class",a.cssPrefix+"labels-"+b),g=f.selectAll("."+a.cssPrefix+"labelGroup-"+b).data(a.options.data).enter().append("g").attr("id",function(c,d){return a.cssPrefix+"labelGroup"+d+"-"+b}).attr("class",a.cssPrefix+"labelGroup-"+b).style("opacity",0);d.mainLabel&&g.append("text").attr("id",function(c,d){return a.cssPrefix+"segmentMainLabel"+d+"-"+b}).attr("class",a.cssPrefix+"segmentMainLabel-"+b).text(function(a){var b=a.label;return e.truncation.enabled&&a.label.length>e.truncation.length&&(b=a.label.substring(0,e.truncation.length)+"..."),b}).style("font-size",e.mainLabel.fontSize).style("font-family",e.mainLabel.font).style("fill",e.mainLabel.color),d.percentage&&g.append("text").attr("id",function(c,d){return a.cssPrefix+"segmentPercentage"+d+"-"+b}).attr("class",a.cssPrefix+"segmentPercentage-"+b).text(function(b){var c=b.value/a.totalSize*100;return c.toFixed(a.options.labels.percentage.decimalPlaces)+"%"}).style("font-size",e.percentage.fontSize).style("font-family",e.percentage.font).style("fill",e.percentage.color),d.value&&g.append("text").attr("id",function(c,d){return a.cssPrefix+"segmentValue"+d+"-"+b}).attr("class",a.cssPrefix+"segmentValue-"+b).text(function(a){return a.value}).style("font-size",e.value.fontSize).style("font-family",e.value.font).style("fill",e.value.color)},positionLabelElements:function(b,c,d){i["dimensions-"+c]=[];for(var e=a("."+b.cssPrefix+"labelGroup-"+c),f=0;f<e.length;f++){var g=a(e[f]).find("."+b.cssPrefix+"segmentMainLabel-"+c),h=a(e[f]).find("."+b.cssPrefix+"segmentPercentage-"+c),j=a(e[f]).find("."+b.cssPrefix+"segmentValue-"+c);i["dimensions-"+c].push({mainLabel:g.length>0?g[0].getBBox():null,percentage:h.length>0?h[0].getBBox():null,value:j.length>0?j[0].getBBox():null})}var k=5,l=i["dimensions-"+c];switch(d){case"label-value1":d3.selectAll("."+b.cssPrefix+"segmentValue-"+c).attr("dx",function(a,b){return l[b].mainLabel.width+k});break;case"label-value2":d3.selectAll("."+b.cssPrefix+"segmentValue-"+c).attr("dy",function(a,b){return l[b].mainLabel.height});break;case"label-percentage1":d3.selectAll("."+b.cssPrefix+"segmentPercentage-"+c).attr("dx",function(a,b){return l[b].mainLabel.width+k});break;case"label-percentage2":d3.selectAll("."+b.cssPrefix+"segmentPercentage-"+c).attr("dx",function(a,b){return l[b].mainLabel.width/2-l[b].percentage.width/2}).attr("dy",function(a,b){return l[b].mainLabel.height})}},computeLabelLinePositions:function(a){a.lineCoordGroups=[],d3.selectAll("."+a.cssPrefix+"labelGroup-outer").each(function(b,c){return i.computeLinePosition(a,c)})},computeLinePosition:function(a,b){var c,d,e,f,g=j.getSegmentAngle(b,a.options.data,a.totalSize,{midpoint:!0}),i=h.rotate(a.pieCenter.x,a.pieCenter.y-a.outerRadius,a.pieCenter.x,a.pieCenter.y,g),k=a.outerLabelGroupData[b].h/5,l=6,m=Math.floor(g/90),n=4;switch(m){case 0:c=a.outerLabelGroupData[b].x-l-(a.outerLabelGroupData[b].x-l-i.x)/2,d=a.outerLabelGroupData[b].y+(i.y-a.outerLabelGroupData[b].y)/n,e=a.outerLabelGroupData[b].x-l,f=a.outerLabelGroupData[b].y-k;break;case 1:c=i.x+(a.outerLabelGroupData[b].x-i.x)/n,d=i.y+(a.outerLabelGroupData[b].y-i.y)/n,e=a.outerLabelGroupData[b].x-l,f=a.outerLabelGroupData[b].y-k;break;case 2:var o=a.outerLabelGroupData[b].x+a.outerLabelGroupData[b].w+l;c=i.x-(i.x-o)/n,d=i.y+(a.outerLabelGroupData[b].y-i.y)/n,e=a.outerLabelGroupData[b].x+a.outerLabelGroupData[b].w+l,f=a.outerLabelGroupData[b].y-k;break;case 3:var p=a.outerLabelGroupData[b].x+a.outerLabelGroupData[b].w+l;c=p+(i.x-p)/n,d=a.outerLabelGroupData[b].y+(i.y-a.outerLabelGroupData[b].y)/n,e=a.outerLabelGroupData[b].x+a.outerLabelGroupData[b].w+l,f=a.outerLabelGroupData[b].y-k}a.lineCoordGroups[b]="straight"===a.options.labels.lines.style?[{x:i.x,y:i.y},{x:e,y:f}]:[{x:i.x,y:i.y},{x:c,y:d},{x:e,y:f}]},addLabelLines:function(a){var b=a.svg.insert("g","."+a.cssPrefix+"pieChart").attr("class",a.cssPrefix+"lineGroups").style("opacity",0),c=b.selectAll("."+a.cssPrefix+"lineGroup").data(a.lineCoordGroups).enter().append("g").attr("class",a.cssPrefix+"lineGroup"),d=d3.svg.line().interpolate("basis").x(function(a){return a.x}).y(function(a){return a.y});c.append("path").attr("d",d).attr("stroke",function(b,c){return"segment"===a.options.labels.lines.color?a.options.colors[c]:a.options.labels.lines.color}).attr("stroke-width",1).attr("fill","none").style("opacity",function(b,c){var d=a.options.labels.outer.hideWhenLessThanPercentage,e=j.getPercentage(a,c);return null!==d&&d>e?0:1})},positionLabelGroups:function(b,c){d3.selectAll("."+b.cssPrefix+"labelGroup-"+c).style("opacity",0).attr("transform",function(d,e){var f,i;if("outer"===c)f=b.outerLabelGroupData[e].x,i=b.outerLabelGroupData[e].y;else{var k=a.extend(!0,{},b.pieCenter);if(b.innerRadius>0){var l=j.getSegmentAngle(e,b.options.data,b.totalSize,{midpoint:!0}),m=h.translate(b.pieCenter.x,b.pieCenter.y,b.innerRadius,l);k.x=m.x,k.y=m.y}var n=g.getDimensions(b.cssPrefix+"labelGroup"+e+"-inner"),o=n.w/2,p=n.h/4;f=k.x+(b.lineCoordGroups[e][0].x-k.x)/1.8,i=k.y+(b.lineCoordGroups[e][0].y-k.y)/1.8,f-=o,i+=p}return"translate("+f+","+i+")"})},fadeInLabelsAndLines:function(b){var c="default"===b.options.effects.load.effect?b.options.effects.load.speed:1;setTimeout(function(){var c="default"===b.options.effects.load.effect?400:1;d3.selectAll("."+b.cssPrefix+"labelGroup-outer").transition().duration(c).style("opacity",function(a,c){var d=b.options.labels.outer.hideWhenLessThanPercentage,e=j.getPercentage(b,c);return null!==d&&d>e?0:1}),d3.selectAll("."+b.cssPrefix+"labelGroup-inner").transition().duration(c).style("opacity",function(a,c){var d=b.options.labels.inner.hideWhenLessThanPercentage,e=j.getPercentage(b,c);return null!==d&&d>e?0:1}),d3.selectAll("g."+b.cssPrefix+"lineGroups").transition().duration(c).style("opacity",1),a.isFunction(b.options.callbacks.onload)&&setTimeout(function(){try{b.options.callbacks.onload()}catch(a){}},c)},c)},getIncludes:function(a){var b=!1,c=!1,d=!1;switch(a){case"label":b=!0;break;case"value":c=!0;break;case"percentage":d=!0;break;case"label-value1":case"label-value2":b=!0,c=!0;break;case"label-percentage1":case"label-percentage2":b=!0,d=!0}return{mainLabel:b,value:c,percentage:d}},computeOuterLabelCoords:function(a){a.svg.selectAll("."+a.cssPrefix+"labelGroup-outer").each(function(b,c){return i.getIdealOuterLabelPositions(a,c)}),i.resolveOuterLabelCollisions(a)},resolveOuterLabelCollisions:function(a){var b=a.options.data.length;i.checkConflict(a,0,"clockwise",b),i.checkConflict(a,b-1,"anticlockwise",b)},checkConflict:function(a,b,c,d){var e=a.outerLabelGroupData[b].hs;if(!("clockwise"===c&&"right"!=e||"anticlockwise"===c&&"left"!=e)){var f="clockwise"===c?b+1:b-1,h=a.outerLabelGroupData[b],j=a.outerLabelGroupData[f],k={labelHeights:a.outerLabelGroupData[0].h,center:a.pieCenter,lineLength:a.outerRadius+a.options.labels.outer.pieDistance,heightChange:a.outerLabelGroupData[0].h+1};if("clockwise"===c)for(var l=0;b>=l;l++){var m=a.outerLabelGroupData[l];if(g.rectIntersect(m,j)){i.adjustLabelPos(a,f,h,k);break}}else for(var l=d-1;l>=b;l--){var m=a.outerLabelGroupData[l];if(g.rectIntersect(m,j)){i.adjustLabelPos(a,f,h,k);break}}i.checkConflict(a,f,c,d)}},adjustLabelPos:function(a,b,c,d){var e,f,g,h;h=c.y+d.heightChange,f=d.center.y-h,e=Math.sqrt(Math.abs(d.lineLength)>Math.abs(f)?d.lineLength*d.lineLength-f*f:f*f-d.lineLength*d.lineLength),g="right"===c.hs?d.center.x+e:d.center.x-e-a.outerLabelGroupData[b].w,g||console.log(c.hs,e),a.outerLabelGroupData[b].x=g,a.outerLabelGroupData[b].y=h},getIdealOuterLabelPositions:function(b,c){var d=a("#"+b.cssPrefix+"labelGroup"+c+"-outer")[0].getBBox(),e=j.getSegmentAngle(c,b.options.data,b.totalSize,{midpoint:!0}),f=b.pieCenter.x,g=b.pieCenter.y-(b.outerRadius+b.options.labels.outer.pieDistance),i=h.rotate(f,g,b.pieCenter.x,b.pieCenter.y,e),k="right";e>180?(i.x-=d.width+8,k="left"):i.x+=8,b.outerLabelGroupData[c]={x:i.x,y:i.y,w:d.width,h:d.height,hs:k}}},j={create:function(a){var b=a.pieCenter,c=a.options.colors,d=a.options.effects.load,e=a.options.misc.colors.segmentStroke,f=a.svg.insert("g","#"+a.cssPrefix+"title").attr("transform",function(){return h.getPieTranslateCenter(b)}).attr("class",a.cssPrefix+"pieChart"),g=d3.svg.arc().innerRadius(a.innerRadius).outerRadius(a.outerRadius).startAngle(0).endAngle(function(b){return b.value/a.totalSize*2*Math.PI}),i=f.selectAll("."+a.cssPrefix+"arc").data(a.options.data).enter().append("g").attr("class",a.cssPrefix+"arc"),k=d.speed;"none"===d.effect&&(k=0),i.append("path").attr("id",function(b,c){return a.cssPrefix+"segment"+c}).style("fill",function(a,b){return c[b]}).style("stroke",e).style("stroke-width",1).transition().ease("cubic-in-out").duration(k).attr("data-index",function(a,b){return b}).attrTween("d",function(b){var c=d3.interpolate({value:0},b);return function(b){return a.arc(c(b))}}),a.svg.selectAll("g."+a.cssPrefix+"arc").attr("transform",function(b,c){var d=0;return c>0&&(d=j.getSegmentAngle(c-1,a.options.data,a.totalSize)),"rotate("+d+")"}),a.arc=g},addSegmentEventHandlers:function(b){var c=a("."+b.cssPrefix+"arc");c.on("click",function(c){var d=a(c.currentTarget).find("path"),e=d.attr("class")===b.cssPrefix+"expanded";j.onSegmentEvent(b.options.callbacks.onClickSegment,d,e),"none"!==b.options.effects.pullOutSegmentOnClick.effect&&(e?j.closeSegment(b,d[0]):j.openSegment(b,d[0]))}),c.on("mouseover",function(c){var d=a(c.currentTarget).find("path");if(b.options.effects.highlightSegmentOnMouseover){var e=d.data("index"),f=b.options.colors[e];d3.select(d[0]).style("fill",g.getColorShade(f,b.options.effects.highlightLuminosity))}var h=d.attr("class")===b.cssPrefix+"expanded";j.onSegmentEvent(b,b.options.callbacks.onMouseoverSegment,d,h)}),c.on("mouseout",function(c){var d=a(c.currentTarget).find("path");if(b.options.effects.highlightSegmentOnMouseover){var e=d.data("index");d3.select(d[0]).style("fill",b.options.colors[e])}var f=d.attr("class")===b.cssPrefix+"expanded";j.onSegmentEvent(b,b.options.callbacks.onMouseoutSegment,d,f)})},onSegmentEvent:function(b,c,d,e){if(a.isFunction(c))try{var f=parseInt(d.data("index"),10);c({segment:d[0],index:f,expanded:e,data:b.options.data[f]})}catch(g){}},openSegment:function(b,c){b.isOpeningSegment||(b.isOpeningSegment=!0,a("."+b.cssPrefix+"expanded").length>0&&j.closeSegment(b,a("."+b.cssPrefix+"expanded")[0]),d3.select(c).transition().ease(b.options.effects.pullOutSegmentOnClick.effect).duration(b.options.effects.pullOutSegmentOnClick.speed).attr("transform",function(a){var c=b.arc.centroid(a),d=c[0],e=c[1],f=Math.sqrt(d*d+e*e),g=parseInt(b.options.effects.pullOutSegmentOnClick.size,10);return"translate("+d/f*g+","+e/f*g+")"}).each("end",function(){b.currentlyOpenSegment=c,b.isOpeningSegment=!1,a(this).attr("class",b.cssPrefix+"expanded")}))},closeSegment:function(b,c){d3.select(c).transition().duration(400).attr("transform","translate(0,0)").each("end",function(){a(this).attr("class",""),b.currentlyOpenSegment=null})},getCentroid:function(a){var b=a.getBBox();return{x:b.x+b.width/2,y:b.y+b.height/2}},getSegmentAngle:function(b,c,d,e){var f,g=a.extend({compounded:!0,midpoint:!1},e),h=c[b].value;if(g.compounded){f=0;for(var i=0;b>=i;i++)f+=c[i].value}"undefined"==typeof f&&(f=h);var j=f/d*360;if(g.midpoint){var k=h/d*360;j-=k/2}return j},getPercentage:function(a,b){return Math.floor(a.options.data[b].value/a.totalSize*100)}},k={offscreenCoord:-1e4,addTitle:function(a){a.svg.selectAll("."+a.cssPrefix+"title").data([a.options.header.title]).enter().append("text").text(function(a){return a.text}).attr("id",a.cssPrefix+"title").attr("class",a.cssPrefix+"title").attr("x",k.offscreenCoord).attr("y",k.offscreenCoord).attr("text-anchor",function(){var b;return b="top-center"===a.options.header.location||"pie-center"===a.options.header.location?"middle":"left"}).attr("fill",function(a){return a.color}).style("font-size",function(a){return a.fontSize}).style("font-family",function(a){return a.font})},positionTitle:function(a){var b=a.textComponents,c=a.options.header.location,d=a.options.misc.canvasPadding,e=a.options.size.canvasWidth,f=a.options.header.titleSubtitlePadding,g="top-left"===c?d.left:e/2,h=d.top+b.title.h;if("pie-center"===c)if(h=a.pieCenter.y,b.subtitle.exists){var i=b.title.h+f+b.subtitle.h;h=h-i/2+b.title.h}else h+=b.title.h/4;a.svg.select("#"+a.cssPrefix+"title").attr("x",g).attr("y",h)},addSubtitle:function(a){var b=a.options.header.location;a.svg.selectAll("."+a.cssPrefix+"subtitle").data([a.options.header.subtitle]).enter().append("text").text(function(a){return a.text}).attr("x",k.offscreenCoord).attr("y",k.offscreenCoord).attr("id",a.cssPrefix+"subtitle").attr("class",a.cssPrefix+"subtitle").attr("text-anchor",function(){var a;return a="top-center"===b||"pie-center"===b?"middle":"left"}).attr("fill",function(a){return a.color}).style("font-size",function(a){return a.fontSize}).style("font-family",function(a){return a.font})},positionSubtitle:function(a){var b="top-left"===a.options.header.location?a.options.misc.canvasPadding.left:a.options.size.canvasWidth/2,c=k.getHeaderHeight(a);a.svg.select("#"+a.cssPrefix+"subtitle").attr("x",b).attr("y",c)},addFooter:function(a){a.svg.selectAll("."+a.cssPrefix+"footer").data([a.options.footer]).enter().append("text").text(function(a){return a.text}).attr("x",k.offscreenCoord).attr("y",k.offscreenCoord).attr("id",a.cssPrefix+"footer").attr("class",a.cssPrefix+"footer").attr("text-anchor",function(){var b="left";return"bottom-center"===a.options.footer.location?b="middle":"bottom-right"===a.options.footer.location&&(b="left"),b}).attr("fill",function(a){return a.color}).style("font-size",function(a){return a.fontSize}).style("font-family",function(a){return a.font})},positionFooter:function(a){var b,c=a.options.footer.location,d=a.textComponents.footer.w,e=a.options.size.canvasWidth,f=a.options.size.canvasHeight,g=a.options.misc.canvasPadding;b="bottom-left"===c?g.left:"bottom-right"===c?e-d-g.right:e/2,a.svg.select("#"+a.cssPrefix+"footer").attr("x",b).attr("y",f-g.bottom)},getHeaderHeight:function(a){var b;if(a.textComponents.title.exists){var c=a.textComponents.title.h+a.options.header.titleSubtitlePadding+a.textComponents.subtitle.h;b="pie-center"===a.options.header.location?a.pieCenter.y-c/2+c:c+a.options.misc.canvasPadding.top}else if("pie-center"===a.options.header.location){var d=a.options.misc.canvasPadding.bottom+a.textComponents.footer.h;b=(a.options.size.canvasHeight-d)/2+a.options.misc.canvasPadding.top+a.textComponents.subtitle.h/2}else b=a.options.misc.canvasPadding.top+a.textComponents.subtitle.h;return b}},l=function(i,j){this.element=i,"string"==typeof i&&(this.element=/#/.test(i)?a(i)[0]:a("#"+i)[0]),this.options=a.extend(!0,{},e,j),null!==this.options.misc.cssPrefix?this.cssPrefix=this.options.misc.cssPrefix:(this.cssPrefix="p"+d+"_",d++),f.initialCheck(this)&&(a(this.element).data(b,c),this.options.data=h.sortPieData(this),this.options.colors=g.initSegmentColors(this),this.totalSize=h.getTotalPieSize(this.options.data),m.call(this))};l.prototype.redraw=function(){this.element.innerHTML="",m.call(this)},l.prototype.destroy=function(){this.element.innerHTML="",a(this.element).removeData(b)},l.prototype.getOpenSegment=function(){var b=this.currentlyOpenSegment;if(null!==b){var c=parseInt(a(b).data("index"),10);return{element:b,index:c,data:this.options.data[c]}}return null},l.prototype.openSegment=function(b){var b=parseInt(b,10);0>b||b>this.options.data.length-1||j.openSegment(this,a("#"+this.cssPrefix+"segment"+b)[0])},l.prototype.closeSegment=function(b){var b=parseInt(b,10);0>b||b>this.options.data.length-1||j.closeSegment(this,a("#"+this.cssPrefix+"segment"+b)[0])},l.prototype.updateProp=function(b,c){switch(b){case"header.title.text":var d=g.processObj(this.options,b);g.processObj(this.options,b,c),a("#"+this.cssPrefix+"title").html(c),(""===d&&""!==c||""!==d&&""===c)&&this.redraw();break;case"header.subtitle.text":var e=g.processObj(this.options,b);g.processObj(this.options,b,c),a("#"+this.cssPrefix+"subtitle").html(c),(""===e&&""!==c||""!==e&&""===c)&&this.redraw();break;case"callbacks.onload":case"callbacks.onMouseoverSegment":case"callbacks.onMouseoutSegment":case"callbacks.onClickSegment":case"effects.pullOutSegmentOnClick.effect":case"effects.pullOutSegmentOnClick.speed":case"effects.pullOutSegmentOnClick.size":case"effects.highlightSegmentOnMouseover":case"effects.highlightLuminosity":g.processObj(this.options,b,c)}};var m=function(){this.svg=g.addSVGSpace(this),this.textComponents={title:{exists:""!==this.options.header.title.text,h:0,w:0},subtitle:{exists:""!==this.options.header.subtitle.text,h:0,w:0},footer:{exists:""!==this.options.footer.text,h:0,w:0}},this.outerLabelGroupData=[],this.textComponents.title.exists&&k.addTitle(this),this.textComponents.subtitle.exists&&k.addSubtitle(this),k.addFooter(this);var a=this;g.whenIdExists(this.cssPrefix+"footer",function(){k.positionFooter(a);var b=g.getDimensions(a.cssPrefix+"footer");a.textComponents.footer.h=b.h,a.textComponents.footer.w=b.w});var b=[];this.textComponents.title.exists&&b.push(this.cssPrefix+"title"),this.textComponents.subtitle.exists&&b.push(this.cssPrefix+"subtitle"),this.textComponents.footer.exists&&b.push(this.cssPrefix+"footer"),g.whenElementsExist(b,function(){if(a.textComponents.title.exists){var b=g.getDimensions(a.cssPrefix+"title");a.textComponents.title.h=b.h,a.textComponents.title.w=b.w}if(a.textComponents.subtitle.exists){var c=g.getDimensions(a.cssPrefix+"subtitle");a.textComponents.subtitle.h=c.h,a.textComponents.subtitle.w=c.w}h.computePieRadius(a),h.calculatePieCenter(a),k.positionTitle(a),k.positionSubtitle(a),j.create(a),i.add(a,"inner",a.options.labels.inner.format),i.add(a,"outer",a.options.labels.outer.format),i.positionLabelElements(a,"inner",a.options.labels.inner.format),i.positionLabelElements(a,"outer",a.options.labels.outer.format),i.computeOuterLabelCoords(a),i.positionLabelGroups(a,"outer"),i.computeLabelLinePositions(a),a.options.labels.lines.enabled&&"none"!==a.options.labels.outer.format&&i.addLabelLines(a),i.positionLabelGroups(a,"inner"),i.fadeInLabelsAndLines(a),j.addSegmentEventHandlers(a)})};window.d3pie=l}(jQuery);