import{$a as lt,E as J,Ga as K,H as st,Ia as nt,J as vt,Qa as rt,_a as at,b as bt,c as kt,db as ct,fb as ot,gb as ht,hb as ut,ib as yt,jb as pt,kb as ft,l as it,lb as gt,nb as Q,rb as dt}from"./chunk-VNKGKUEF.js";import{h as H}from"./chunk-3NXJ7VWC.js";var Gt=H(bt(),1),Wt=H(kt(),1),Mt=H(vt(),1);var X=function(){var i=function(d,t,e,s){for(e=e||{},s=d.length;s--;e[d[s]]=t);return e},m=[1,3],F=[1,4],p=[1,5],g=[1,6],$=[1,10,12,14,16,18,19,20,21,22],N=[2,4],D=[1,5,10,12,14,16,18,19,20,21,22],o=[20,21,22],w=[2,7],x=[1,12],C=[1,13],O=[1,14],b=[1,15],P=[1,16],h=[1,17],k={trace:function(){},yy:{},symbols_:{error:2,start:3,eol:4,PIE:5,document:6,showData:7,line:8,statement:9,txt:10,value:11,title:12,title_value:13,acc_title:14,acc_title_value:15,acc_descr:16,acc_descr_value:17,acc_descr_multiline_value:18,section:19,NEWLINE:20,";":21,EOF:22,$accept:0,$end:1},terminals_:{2:"error",5:"PIE",7:"showData",10:"txt",11:"value",12:"title",13:"title_value",14:"acc_title",15:"acc_title_value",16:"acc_descr",17:"acc_descr_value",18:"acc_descr_multiline_value",19:"section",20:"NEWLINE",21:";",22:"EOF"},productions_:[0,[3,2],[3,2],[3,3],[6,0],[6,2],[8,2],[9,0],[9,2],[9,2],[9,2],[9,2],[9,1],[9,1],[4,1],[4,1],[4,1]],performAction:function(t,e,s,r,a,n,A){var u=n.length-1;switch(a){case 3:r.setShowData(!0);break;case 6:this.$=n[u-1];break;case 8:r.addSection(n[u-1],r.cleanupValue(n[u]));break;case 9:this.$=n[u].trim(),r.setDiagramTitle(this.$);break;case 10:this.$=n[u].trim(),r.setAccTitle(this.$);break;case 11:case 12:this.$=n[u].trim(),r.setAccDescription(this.$);break;case 13:r.addSection(n[u].substr(8)),this.$=n[u].substr(8);break}},table:[{3:1,4:2,5:m,20:F,21:p,22:g},{1:[3]},{3:7,4:2,5:m,20:F,21:p,22:g},i($,N,{6:8,7:[1,9]}),i(D,[2,14]),i(D,[2,15]),i(D,[2,16]),{1:[2,1]},i(o,w,{8:10,9:11,1:[2,2],10:x,12:C,14:O,16:b,18:P,19:h}),i($,N,{6:18}),i($,[2,5]),{4:19,20:F,21:p,22:g},{11:[1,20]},{13:[1,21]},{15:[1,22]},{17:[1,23]},i(o,[2,12]),i(o,[2,13]),i(o,w,{8:10,9:11,1:[2,3],10:x,12:C,14:O,16:b,18:P,19:h}),i($,[2,6]),i(o,[2,8]),i(o,[2,9]),i(o,[2,10]),i(o,[2,11])],defaultActions:{7:[2,1]},parseError:function(t,e){if(e.recoverable)this.trace(t);else{var s=new Error(t);throw s.hash=e,s}},parse:function(t){var e=this,s=[0],r=[],a=[null],n=[],A=this.table,u="",c=0,_=0,V=2,z=1,B=n.slice.call(arguments,1),l=Object.create(this.lexer),T={yy:{}};for(var U in this.yy)Object.prototype.hasOwnProperty.call(this.yy,U)&&(T.yy[U]=this.yy[U]);l.setInput(t,T.yy),T.yy.lexer=l,T.yy.parser=this,typeof l.yylloc=="undefined"&&(l.yylloc={});var Y=l.yylloc;n.push(Y);var mt=l.options&&l.options.ranges;typeof T.yy.parseError=="function"?this.parseError=T.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function xt(){var S;return S=r.pop()||l.lex()||z,typeof S!="number"&&(S instanceof Array&&(r=S,S=r.pop()),S=e.symbols_[S]||S),S}for(var y,I,f,q,L={},j,v,et,G;;){if(I=s[s.length-1],this.defaultActions[I]?f=this.defaultActions[I]:((y===null||typeof y=="undefined")&&(y=xt()),f=A[I]&&A[I][y]),typeof f=="undefined"||!f.length||!f[0]){var Z="";G=[];for(j in A[I])this.terminals_[j]&&j>V&&G.push("'"+this.terminals_[j]+"'");l.showPosition?Z="Parse error on line "+(c+1)+`:
`+l.showPosition()+`
Expecting `+G.join(", ")+", got '"+(this.terminals_[y]||y)+"'":Z="Parse error on line "+(c+1)+": Unexpected "+(y==z?"end of input":"'"+(this.terminals_[y]||y)+"'"),this.parseError(Z,{text:l.match,token:this.terminals_[y]||y,line:l.yylineno,loc:Y,expected:G})}if(f[0]instanceof Array&&f.length>1)throw new Error("Parse Error: multiple actions possible at state: "+I+", token: "+y);switch(f[0]){case 1:s.push(y),a.push(l.yytext),n.push(l.yylloc),s.push(f[1]),y=null,_=l.yyleng,u=l.yytext,c=l.yylineno,Y=l.yylloc;break;case 2:if(v=this.productions_[f[1]][1],L.$=a[a.length-v],L._$={first_line:n[n.length-(v||1)].first_line,last_line:n[n.length-1].last_line,first_column:n[n.length-(v||1)].first_column,last_column:n[n.length-1].last_column},mt&&(L._$.range=[n[n.length-(v||1)].range[0],n[n.length-1].range[1]]),q=this.performAction.apply(L,[u,_,c,T.yy,f[1],a,n].concat(B)),typeof q!="undefined")return q;v&&(s=s.slice(0,-1*v*2),a=a.slice(0,-1*v),n=n.slice(0,-1*v)),s.push(this.productions_[f[1]][0]),a.push(L.$),n.push(L._$),et=A[s[s.length-2]][s[s.length-1]],s.push(et);break;case 3:return!0}}return!0}},R=function(){var d={EOF:1,parseError:function(e,s){if(this.yy.parser)this.yy.parser.parseError(e,s);else throw new Error(e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t;var e=t.match(/(?:\r\n?|\n).*/g);return e?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,s=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),s.length-1&&(this.yylineno-=s.length-1);var a=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:s?(s.length===r.length?this.yylloc.first_column:0)+r[r.length-s.length].length-s[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[a[0],a[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).
`+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+`
`+e+"^"},test_match:function(t,e){var s,r,a;if(this.options.backtrack_lexer&&(a={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(a.yylloc.range=this.yylloc.range.slice(0))),r=t[0].match(/(?:\r\n?|\n).*/g),r&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],s=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),s)return s;if(this._backtrack){for(var n in a)this[n]=a[n];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var t,e,s,r;this._more||(this.yytext="",this.match="");for(var a=this._currentRules(),n=0;n<a.length;n++)if(s=this._input.match(this.rules[a[n]]),s&&(!e||s[0].length>e[0].length)){if(e=s,r=n,this.options.backtrack_lexer){if(t=this.test_match(s,a[n]),t!==!1)return t;if(this._backtrack){e=!1;continue}else return!1}else if(!this.options.flex)break}return e?(t=this.test_match(e,a[r]),t!==!1?t:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text.
`+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var e=this.next();return e||this.lex()},begin:function(e){this.conditionStack.push(e)},popState:function(){var e=this.conditionStack.length-1;return e>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(e){return e=this.conditionStack.length-1-Math.abs(e||0),e>=0?this.conditionStack[e]:"INITIAL"},pushState:function(e){this.begin(e)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(e,s,r,a){switch(r){case 0:break;case 1:break;case 2:return 20;case 3:break;case 4:break;case 5:return this.begin("title"),12;case 6:return this.popState(),"title_value";case 7:return this.begin("acc_title"),14;case 8:return this.popState(),"acc_title_value";case 9:return this.begin("acc_descr"),16;case 10:return this.popState(),"acc_descr_value";case 11:this.begin("acc_descr_multiline");break;case 12:this.popState();break;case 13:return"acc_descr_multiline_value";case 14:this.begin("string");break;case 15:this.popState();break;case 16:return"txt";case 17:return 5;case 18:return 7;case 19:return"value";case 20:return 22}},rules:[/^(?:%%(?!\{)[^\n]*)/i,/^(?:[^\}]%%[^\n]*)/i,/^(?:[\n\r]+)/i,/^(?:%%[^\n]*)/i,/^(?:[\s]+)/i,/^(?:title\b)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accTitle\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*:\s*)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:accDescr\s*\{\s*)/i,/^(?:[\}])/i,/^(?:[^\}]*)/i,/^(?:["])/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:pie\b)/i,/^(?:showData\b)/i,/^(?::[\s]*[\d]+(?:\.[\d]+)?)/i,/^(?:$)/i],conditions:{acc_descr_multiline:{rules:[12,13],inclusive:!1},acc_descr:{rules:[10],inclusive:!1},acc_title:{rules:[8],inclusive:!1},title:{rules:[6],inclusive:!1},string:{rules:[15,16],inclusive:!1},INITIAL:{rules:[0,1,2,3,4,5,7,9,11,14,17,18,19,20],inclusive:!0}}};return d}();k.lexer=R;function E(){this.yy={}}return E.prototype=k,k.Parser=E,new E}();X.parser=X;var St=X,_t=rt.pie,W={sections:{},showData:!1,config:_t},M=W.sections,tt=W.showData,Et=structuredClone(_t),$t=()=>structuredClone(Et),wt=()=>{M=structuredClone(W.sections),tt=W.showData,ot()},At=(i,m)=>{i=nt(i,Q()),M[i]===void 0&&(M[i]=m,K.debug(`added new section: ${i}, with value: ${m}`))},Tt=()=>M,It=i=>(i.substring(0,1)===":"&&(i=i.substring(1).trim()),Number(i.trim())),Dt=i=>{tt=i},Ct=()=>tt,Ot={getConfig:$t,clear:wt,setDiagramTitle:ft,getDiagramTitle:gt,setAccTitle:ht,getAccTitle:ut,setAccDescription:yt,getAccDescription:pt,addSection:At,getSections:Tt,cleanupValue:It,setShowData:Dt,getShowData:Ct},Pt=i=>`
  .pieCircle{
    stroke: ${i.pieStrokeColor};
    stroke-width : ${i.pieStrokeWidth};
    opacity : ${i.pieOpacity};
  }
  .pieOuterCircle{
    stroke: ${i.pieOuterStrokeColor};
    stroke-width: ${i.pieOuterStrokeWidth};
    fill: none;
  }
  .pieTitleText {
    text-anchor: middle;
    font-size: ${i.pieTitleTextSize};
    fill: ${i.pieTitleTextColor};
    font-family: ${i.fontFamily};
  }
  .slice {
    font-family: ${i.fontFamily};
    fill: ${i.pieSectionTextColor};
    font-size:${i.pieSectionTextSize};
    // fill: white;
  }
  .legend text {
    fill: ${i.pieLegendTextColor};
    font-family: ${i.fontFamily};
    font-size: ${i.pieLegendTextSize};
  }
`,Vt=Pt,Lt=i=>{let m=Object.entries(i).map(p=>({label:p[0],value:p[1]})).sort((p,g)=>g.value-p.value);return st().value(p=>p.value)(m)},Ft=(i,m,F,p)=>{K.debug(`rendering pie chart
`+i);let g=p.db,$=Q(),N=lt(g.getConfig(),$.pie),D=40,o=18,w=4,x=450,C=x,O=dt(m),b=O.append("g"),P=g.getSections();b.attr("transform","translate("+C/2+","+x/2+")");let{themeVariables:h}=$,[k]=at(h.pieOuterStrokeWidth);k!=null||(k=2);let R=N.textPosition,E=Math.min(C,x)/2-D,d=J().innerRadius(0).outerRadius(E),t=J().innerRadius(E*R).outerRadius(E*R);b.append("circle").attr("cx",0).attr("cy",0).attr("r",E+k/2).attr("class","pieOuterCircle");let e=Lt(P),s=[h.pie1,h.pie2,h.pie3,h.pie4,h.pie5,h.pie6,h.pie7,h.pie8,h.pie9,h.pie10,h.pie11,h.pie12],r=it(s);b.selectAll("mySlices").data(e).enter().append("path").attr("d",d).attr("fill",c=>r(c.data.label)).attr("class","pieCircle");let a=0;Object.keys(P).forEach(c=>{a+=P[c]}),b.selectAll("mySlices").data(e).enter().append("text").text(c=>(c.data.value/a*100).toFixed(0)+"%").attr("transform",c=>"translate("+t.centroid(c)+")").style("text-anchor","middle").attr("class","slice"),b.append("text").text(g.getDiagramTitle()).attr("x",0).attr("y",-(x-50)/2).attr("class","pieTitleText");let n=b.selectAll(".legend").data(r.domain()).enter().append("g").attr("class","legend").attr("transform",(c,_)=>{let V=o+w,z=V*r.domain().length/2,B=12*o,l=_*V-z;return"translate("+B+","+l+")"});n.append("rect").attr("width",o).attr("height",o).style("fill",r).style("stroke",r),n.data(e).append("text").attr("x",o+w).attr("y",o-w).text(c=>{let{label:_,value:V}=c.data;return g.getShowData()?`${_} [${V}]`:_});let A=Math.max(...n.selectAll("text").nodes().map(c=>{var _;return(_=c==null?void 0:c.getBoundingClientRect().width)!=null?_:0})),u=C+D+o+w+A;O.attr("viewBox",`0 0 ${u} ${x}`),ct(O,x,u,N.useMaxWidth)},Nt={draw:Ft},Bt={parser:St,db:Ot,renderer:Nt,styles:Vt};export{Bt as diagram};
