"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./layers.BUx-KQN_.js");require("./layers.BENyixGk.js");require("lodash-es/memoize.js");require("lodash-es/merge.js");require("lodash-es/isEmpty.js");const tt=require("./layers.BeB6nS-_.js"),nt=require("./layers.B19hGmey.js"),st=require("./layers.9pNaFvaX.js"),R=require("./layers.DOrgOHBr.js");function rt(e,y){return y<e?-1:y>e?1:y>=e?0:NaN}function at(e){return e}function lt(){var e=at,y=rt,$=null,g=R.constant(0),d=R.constant(u.tau),E=R.constant(0);function f(a){var l,m=(a=st.array(a)).length,v,I,D=0,_=new Array(m),b=new Array(m),o=+g.apply(this,arguments),w=Math.min(u.tau,Math.max(-u.tau,d.apply(this,arguments)-o)),P,T=Math.min(Math.abs(w)/m,E.apply(this,arguments)),S=T*(w<0?-1:1),t;for(l=0;l<m;++l)(t=b[_[l]=l]=+e(a[l],l,a))>0&&(D+=t);for(y!=null?_.sort(function(i,n){return y(b[i],b[n])}):$!=null&&_.sort(function(i,n){return $(a[i],a[n])}),l=0,I=D?(w-m*S)/D:0;l<m;++l,o=P)v=_[l],t=b[v],P=o+(t>0?t*I:0)+S,b[v]={data:a[v],index:l,value:t,startAngle:o,endAngle:P,padAngle:T};return b}return f.value=function(a){return arguments.length?(e=typeof a=="function"?a:R.constant(+a),f):e},f.sortValues=function(a){return arguments.length?(y=a,$=null,f):y},f.sort=function(a){return arguments.length?($=a,y=null,f):$},f.startAngle=function(a){return arguments.length?(g=typeof a=="function"?a:R.constant(+a),f):g},f.endAngle=function(a){return arguments.length?(d=typeof a=="function"?a:R.constant(+a),f):d},f.padAngle=function(a){return arguments.length?(E=typeof a=="function"?a:R.constant(+a),f):E},f}var K=(function(){var e=function(S,t,i,n){for(i=i||{},n=S.length;n--;i[S[n]]=t);return i},y=[1,3],$=[1,4],g=[1,5],d=[1,6],E=[1,10,12,14,16,18,19,20,21,22],f=[2,4],a=[1,5,10,12,14,16,18,19,20,21,22],l=[20,21,22],m=[2,7],v=[1,12],I=[1,13],D=[1,14],_=[1,15],b=[1,16],o=[1,17],w={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,i,n,r,c,s,V){var x=s.length-1;switch(c){case 3:r.setShowData(!0);break;case 6:this.$=s[x-1];break;case 8:r.addSection(s[x-1],r.cleanupValue(s[x]));break;case 9:this.$=s[x].trim(),r.setDiagramTitle(this.$);break;case 10:this.$=s[x].trim(),r.setAccTitle(this.$);break;case 11:case 12:this.$=s[x].trim(),r.setAccDescription(this.$);break;case 13:r.addSection(s[x].substr(8)),this.$=s[x].substr(8);break}},table:[{3:1,4:2,5:y,20:$,21:g,22:d},{1:[3]},{3:7,4:2,5:y,20:$,21:g,22:d},e(E,f,{6:8,7:[1,9]}),e(a,[2,14]),e(a,[2,15]),e(a,[2,16]),{1:[2,1]},e(l,m,{8:10,9:11,1:[2,2],10:v,12:I,14:D,16:_,18:b,19:o}),e(E,f,{6:18}),e(E,[2,5]),{4:19,20:$,21:g,22:d},{11:[1,20]},{13:[1,21]},{15:[1,22]},{17:[1,23]},e(l,[2,12]),e(l,[2,13]),e(l,m,{8:10,9:11,1:[2,3],10:v,12:I,14:D,16:_,18:b,19:o}),e(E,[2,6]),e(l,[2,8]),e(l,[2,9]),e(l,[2,10]),e(l,[2,11])],defaultActions:{7:[2,1]},parseError:function(t,i){if(i.recoverable)this.trace(t);else{var n=new Error(t);throw n.hash=i,n}},parse:function(t){var i=this,n=[0],r=[],c=[null],s=[],V=this.table,x="",p=0,N=0,z=2,j=1,B=s.slice.call(arguments,1),h=Object.create(this.lexer),L={yy:{}};for(var Y in this.yy)Object.prototype.hasOwnProperty.call(this.yy,Y)&&(L.yy[Y]=this.yy[Y]);h.setInput(t,L.yy),L.yy.lexer=h,L.yy.parser=this,typeof h.yylloc>"u"&&(h.yylloc={});var Z=h.yylloc;s.push(Z);var et=h.options&&h.options.ranges;typeof L.yy.parseError=="function"?this.parseError=L.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function it(){var O;return O=r.pop()||h.lex()||j,typeof O!="number"&&(O instanceof Array&&(r=O,O=r.pop()),O=i.symbols_[O]||O),O}for(var k,F,A,H,M={},W,C,X,q;;){if(F=n[n.length-1],this.defaultActions[F]?A=this.defaultActions[F]:((k===null||typeof k>"u")&&(k=it()),A=V[F]&&V[F][k]),typeof A>"u"||!A.length||!A[0]){var J="";q=[];for(W in V[F])this.terminals_[W]&&W>z&&q.push("'"+this.terminals_[W]+"'");h.showPosition?J="Parse error on line "+(p+1)+`:
`+h.showPosition()+`
Expecting `+q.join(", ")+", got '"+(this.terminals_[k]||k)+"'":J="Parse error on line "+(p+1)+": Unexpected "+(k==j?"end of input":"'"+(this.terminals_[k]||k)+"'"),this.parseError(J,{text:h.match,token:this.terminals_[k]||k,line:h.yylineno,loc:Z,expected:q})}if(A[0]instanceof Array&&A.length>1)throw new Error("Parse Error: multiple actions possible at state: "+F+", token: "+k);switch(A[0]){case 1:n.push(k),c.push(h.yytext),s.push(h.yylloc),n.push(A[1]),k=null,N=h.yyleng,x=h.yytext,p=h.yylineno,Z=h.yylloc;break;case 2:if(C=this.productions_[A[1]][1],M.$=c[c.length-C],M._$={first_line:s[s.length-(C||1)].first_line,last_line:s[s.length-1].last_line,first_column:s[s.length-(C||1)].first_column,last_column:s[s.length-1].last_column},et&&(M._$.range=[s[s.length-(C||1)].range[0],s[s.length-1].range[1]]),H=this.performAction.apply(M,[x,N,p,L.yy,A[1],c,s].concat(B)),typeof H<"u")return H;C&&(n=n.slice(0,-1*C*2),c=c.slice(0,-1*C),s=s.slice(0,-1*C)),n.push(this.productions_[A[1]][0]),c.push(M.$),s.push(M._$),X=V[n[n.length-2]][n[n.length-1]],n.push(X);break;case 3:return!0}}return!0}},P=(function(){var S={EOF:1,parseError:function(i,n){if(this.yy.parser)this.yy.parser.parseError(i,n);else throw new Error(i)},setInput:function(t,i){return this.yy=i||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 i=t.match(/(?:\r\n?|\n).*/g);return i?(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 i=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-i),this.offset-=i;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),n.length-1&&(this.yylineno-=n.length-1);var c=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:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-i},this.options.ranges&&(this.yylloc.range=[c[0],c[0]+this.yyleng-i]),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(),i=new Array(t.length+1).join("-");return t+this.upcomingInput()+`
`+i+"^"},test_match:function(t,i){var n,r,c;if(this.options.backtrack_lexer&&(c={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&&(c.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],n=this.performAction.call(this,this.yy,this,i,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var s in c)this[s]=c[s];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var t,i,n,r;this._more||(this.yytext="",this.match="");for(var c=this._currentRules(),s=0;s<c.length;s++)if(n=this._input.match(this.rules[c[s]]),n&&(!i||n[0].length>i[0].length)){if(i=n,r=s,this.options.backtrack_lexer){if(t=this.test_match(n,c[s]),t!==!1)return t;if(this._backtrack){i=!1;continue}else return!1}else if(!this.options.flex)break}return i?(t=this.test_match(i,c[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 i=this.next();return i||this.lex()},begin:function(i){this.conditionStack.push(i)},popState:function(){var i=this.conditionStack.length-1;return i>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(i){return i=this.conditionStack.length-1-Math.abs(i||0),i>=0?this.conditionStack[i]:"INITIAL"},pushState:function(i){this.begin(i)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(i,n,r,c){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 S})();w.lexer=P;function T(){this.yy={}}return T.prototype=w,w.Parser=T,new T})();K.parser=K;const ct=K,ot=u.defaultConfig$2.pie,G={sections:{},showData:!1};let U=G.sections,Q=G.showData;const ht=structuredClone(ot),ut=()=>structuredClone(ht),yt=()=>{U=structuredClone(G.sections),Q=G.showData,u.clear()},ft=(e,y)=>{e=u.sanitizeText$2(e,u.getConfig()),U[e]===void 0&&(U[e]=y,u.log$1.debug(`added new section: ${e}, with value: ${y}`))},pt=()=>U,gt=e=>(e.substring(0,1)===":"&&(e=e.substring(1).trim()),Number(e.trim())),dt=e=>{Q=e},mt=()=>Q,_t={getConfig:ut,clear:yt,setDiagramTitle:u.setDiagramTitle,getDiagramTitle:u.getDiagramTitle,setAccTitle:u.setAccTitle,getAccTitle:u.getAccTitle,setAccDescription:u.setAccDescription,getAccDescription:u.getAccDescription,addSection:ft,getSections:pt,cleanupValue:gt,setShowData:dt,getShowData:mt},xt=e=>`
  .pieCircle{
    stroke: ${e.pieStrokeColor};
    stroke-width : ${e.pieStrokeWidth};
    opacity : ${e.pieOpacity};
  }
  .pieOuterCircle{
    stroke: ${e.pieOuterStrokeColor};
    stroke-width: ${e.pieOuterStrokeWidth};
    fill: none;
  }
  .pieTitleText {
    text-anchor: middle;
    font-size: ${e.pieTitleTextSize};
    fill: ${e.pieTitleTextColor};
    font-family: ${e.fontFamily};
  }
  .slice {
    font-family: ${e.fontFamily};
    fill: ${e.pieSectionTextColor};
    font-size:${e.pieSectionTextSize};
    // fill: white;
  }
  .legend text {
    fill: ${e.pieLegendTextColor};
    font-family: ${e.fontFamily};
    font-size: ${e.pieLegendTextSize};
  }
`,kt=xt,vt=e=>{const y=Object.entries(e).map(g=>({label:g[0],value:g[1]})).sort((g,d)=>d.value-g.value);return lt().value(g=>g.value)(y)},bt=(e,y,$,g)=>{u.log$1.debug(`rendering pie chart
`+e);const d=g.db,E=u.getConfig(),f=u.cleanAndMerge(d.getConfig(),E.pie),a=40,l=18,m=4,v=450,I=v,D=u.selectSvgElement(y),_=D.append("g"),b=d.getSections();_.attr("transform","translate("+I/2+","+v/2+")");const{themeVariables:o}=E;let[w]=u.parseFontSize(o.pieOuterStrokeWidth);w??(w=2);const P=f.textPosition,T=Math.min(I,v)/2-a,S=tt.arc().innerRadius(0).outerRadius(T),t=tt.arc().innerRadius(T*P).outerRadius(T*P);_.append("circle").attr("cx",0).attr("cy",0).attr("r",T+w/2).attr("class","pieOuterCircle");const i=vt(b),n=[o.pie1,o.pie2,o.pie3,o.pie4,o.pie5,o.pie6,o.pie7,o.pie8,o.pie9,o.pie10,o.pie11,o.pie12],r=nt.ordinal(n);_.selectAll("mySlices").data(i).enter().append("path").attr("d",S).attr("fill",p=>r(p.data.label)).attr("class","pieCircle");let c=0;Object.keys(b).forEach(p=>{c+=b[p]}),_.selectAll("mySlices").data(i).enter().append("text").text(p=>(p.data.value/c*100).toFixed(0)+"%").attr("transform",p=>"translate("+t.centroid(p)+")").style("text-anchor","middle").attr("class","slice"),_.append("text").text(d.getDiagramTitle()).attr("x",0).attr("y",-400/2).attr("class","pieTitleText");const s=_.selectAll(".legend").data(r.domain()).enter().append("g").attr("class","legend").attr("transform",(p,N)=>{const z=l+m,j=z*r.domain().length/2,B=12*l,h=N*z-j;return"translate("+B+","+h+")"});s.append("rect").attr("width",l).attr("height",l).style("fill",r).style("stroke",r),s.data(i).append("text").attr("x",l+m).attr("y",l-m).text(p=>{const{label:N,value:z}=p.data;return d.getShowData()?`${N} [${z}]`:N});const V=Math.max(...s.selectAll("text").nodes().map(p=>(p==null?void 0:p.getBoundingClientRect().width)??0)),x=I+a+l+m+V;D.attr("viewBox",`0 0 ${x} ${v}`),u.configureSvgSize(D,v,x,f.useMaxWidth)},St={draw:bt},At={parser:ct,db:_t,renderer:St,styles:kt};exports.diagram=At;
