livebook/static/assets/pieDiagram-157505fe-V6JD4T7X.js
2023-06-20 15:34:33 +00:00

35 lines
15 KiB
JavaScript

import{Ja as vt,Na as bt,b as St,c as wt,da as C,h as J,ha as ht,l as lt,na as F,oa as ut,qa as pt,ra as ft,sa as yt,ta as dt,u as nt,ua as mt,va as _t,wa as gt,x as ot,z as Et}from"./chunk-RQT2CUZQ.js";import{h as st}from"./chunk-2YVZDWG7.js";var Mt=st(St(),1),Bt=st(wt(),1),Yt=st(Et(),1);var rt=function(){var e=function(u,t,i,n){for(i=i||{},n=u.length;n--;i[u[n]]=t);return i},f=[1,4],E=[1,5],m=[1,6],D=[1,7],T=[1,9],y=[1,11,13,15,17,19,20,26,27,28,29],I=[2,5],S=[1,6,11,13,15,17,19,20,26,27,28,29],o=[26,27,28],V=[2,8],N=[1,18],R=[1,19],w=[1,20],M=[1,21],B=[1,22],P=[1,23],Y=[1,28],W=[6,26,27,28,29],O={trace:function(){},yy:{},symbols_:{error:2,start:3,eol:4,directive:5,PIE:6,document:7,showData:8,line:9,statement: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,openDirective:21,typeDirective:22,closeDirective:23,":":24,argDirective:25,NEWLINE:26,";":27,EOF:28,open_directive:29,type_directive:30,arg_directive:31,close_directive:32,$accept:0,$end:1},terminals_:{2:"error",6:"PIE",8:"showData",11:"txt",12:"value",13:"title",14:"title_value",15:"acc_title",16:"acc_title_value",17:"acc_descr",18:"acc_descr_value",19:"acc_descr_multiline_value",20:"section",24:":",26:"NEWLINE",27:";",28:"EOF",29:"open_directive",30:"type_directive",31:"arg_directive",32:"close_directive"},productions_:[0,[3,2],[3,2],[3,2],[3,3],[7,0],[7,2],[9,2],[10,0],[10,2],[10,2],[10,2],[10,2],[10,1],[10,1],[10,1],[5,3],[5,5],[4,1],[4,1],[4,1],[21,1],[22,1],[25,1],[23,1]],performAction:function(t,i,n,a,r,s,d){var c=s.length-1;switch(r){case 4:a.setShowData(!0);break;case 7:this.$=s[c-1];break;case 9:a.addSection(s[c-1],a.cleanupValue(s[c]));break;case 10:this.$=s[c].trim(),a.setDiagramTitle(this.$);break;case 11:this.$=s[c].trim(),a.setAccTitle(this.$);break;case 12:case 13:this.$=s[c].trim(),a.setAccDescription(this.$);break;case 14:a.addSection(s[c].substr(8)),this.$=s[c].substr(8);break;case 21:a.parseDirective("%%{","open_directive");break;case 22:a.parseDirective(s[c],"type_directive");break;case 23:s[c]=s[c].trim().replace(/'/g,'"'),a.parseDirective(s[c],"arg_directive");break;case 24:a.parseDirective("}%%","close_directive","pie");break}},table:[{3:1,4:2,5:3,6:f,21:8,26:E,27:m,28:D,29:T},{1:[3]},{3:10,4:2,5:3,6:f,21:8,26:E,27:m,28:D,29:T},{3:11,4:2,5:3,6:f,21:8,26:E,27:m,28:D,29:T},e(y,I,{7:12,8:[1,13]}),e(S,[2,18]),e(S,[2,19]),e(S,[2,20]),{22:14,30:[1,15]},{30:[2,21]},{1:[2,1]},{1:[2,2]},e(o,V,{21:8,9:16,10:17,5:24,1:[2,3],11:N,13:R,15:w,17:M,19:B,20:P,29:T}),e(y,I,{7:25}),{23:26,24:[1,27],32:Y},e([24,32],[2,22]),e(y,[2,6]),{4:29,26:E,27:m,28:D},{12:[1,30]},{14:[1,31]},{16:[1,32]},{18:[1,33]},e(o,[2,13]),e(o,[2,14]),e(o,[2,15]),e(o,V,{21:8,9:16,10:17,5:24,1:[2,4],11:N,13:R,15:w,17:M,19:B,20:P,29:T}),e(W,[2,16]),{25:34,31:[1,35]},e(W,[2,24]),e(y,[2,7]),e(o,[2,9]),e(o,[2,10]),e(o,[2,11]),e(o,[2,12]),{23:36,32:Y},{32:[2,23]},e(W,[2,17])],defaultActions:{9:[2,21],10:[2,1],11:[2,2],35:[2,23]},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],a=[],r=[null],s=[],d=this.table,c="",_=0,z=0,Q=2,q=1,X=s.slice.call(arguments,1),l=Object.create(this.lexer),$={yy:{}};for(var Z in this.yy)Object.prototype.hasOwnProperty.call(this.yy,Z)&&($.yy[Z]=this.yy[Z]);l.setInput(t,$.yy),$.yy.lexer=l,$.yy.parser=this,typeof l.yylloc=="undefined"&&(l.yylloc={});var tt=l.yylloc;s.push(tt);var kt=l.options&&l.options.ranges;typeof $.yy.parseError=="function"?this.parseError=$.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function xt(){var k;return k=a.pop()||l.lex()||q,typeof k!="number"&&(k instanceof Array&&(a=k,k=a.pop()),k=i.symbols_[k]||k),k}for(var h,A,p,et,L={},G,b,ct,H;;){if(A=n[n.length-1],this.defaultActions[A]?p=this.defaultActions[A]:((h===null||typeof h=="undefined")&&(h=xt()),p=d[A]&&d[A][h]),typeof p=="undefined"||!p.length||!p[0]){var it="";H=[];for(G in d[A])this.terminals_[G]&&G>Q&&H.push("'"+this.terminals_[G]+"'");l.showPosition?it="Parse error on line "+(_+1)+`:
`+l.showPosition()+`
Expecting `+H.join(", ")+", got '"+(this.terminals_[h]||h)+"'":it="Parse error on line "+(_+1)+": Unexpected "+(h==q?"end of input":"'"+(this.terminals_[h]||h)+"'"),this.parseError(it,{text:l.match,token:this.terminals_[h]||h,line:l.yylineno,loc:tt,expected:H})}if(p[0]instanceof Array&&p.length>1)throw new Error("Parse Error: multiple actions possible at state: "+A+", token: "+h);switch(p[0]){case 1:n.push(h),r.push(l.yytext),s.push(l.yylloc),n.push(p[1]),h=null,z=l.yyleng,c=l.yytext,_=l.yylineno,tt=l.yylloc;break;case 2:if(b=this.productions_[p[1]][1],L.$=r[r.length-b],L._$={first_line:s[s.length-(b||1)].first_line,last_line:s[s.length-1].last_line,first_column:s[s.length-(b||1)].first_column,last_column:s[s.length-1].last_column},kt&&(L._$.range=[s[s.length-(b||1)].range[0],s[s.length-1].range[1]]),et=this.performAction.apply(L,[c,z,_,$.yy,p[1],r,s].concat(X)),typeof et!="undefined")return et;b&&(n=n.slice(0,-1*b*2),r=r.slice(0,-1*b),s=s.slice(0,-1*b)),n.push(this.productions_[p[1]][0]),r.push(L.$),s.push(L._$),ct=d[n[n.length-2]][n[n.length-1]],n.push(ct);break;case 3:return!0}}return!0}},U=function(){var u={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 a=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 r=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===a.length?this.yylloc.first_column:0)+a[a.length-n.length].length-n[0].length:this.yylloc.first_column-i},this.options.ranges&&(this.yylloc.range=[r[0],r[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,a,r;if(this.options.backtrack_lexer&&(r={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&&(r.yylloc.range=this.yylloc.range.slice(0))),a=t[0].match(/(?:\r\n?|\n).*/g),a&&(this.yylineno+=a.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:a?a[a.length-1].length-a[a.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 r)this[s]=r[s];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var t,i,n,a;this._more||(this.yytext="",this.match="");for(var r=this._currentRules(),s=0;s<r.length;s++)if(n=this._input.match(this.rules[r[s]]),n&&(!i||n[0].length>i[0].length)){if(i=n,a=s,this.options.backtrack_lexer){if(t=this.test_match(n,r[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,r[a]),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,a,r){switch(a){case 0:return this.begin("open_directive"),29;case 1:return this.begin("type_directive"),30;case 2:return this.popState(),this.begin("arg_directive"),24;case 3:return this.popState(),this.popState(),32;case 4:return 31;case 5:break;case 6:break;case 7:return 26;case 8:break;case 9:break;case 10:return this.begin("title"),13;case 11:return this.popState(),"title_value";case 12:return this.begin("acc_title"),15;case 13:return this.popState(),"acc_title_value";case 14:return this.begin("acc_descr"),17;case 15:return this.popState(),"acc_descr_value";case 16:this.begin("acc_descr_multiline");break;case 17:this.popState();break;case 18:return"acc_descr_multiline_value";case 19:this.begin("string");break;case 20:this.popState();break;case 21:return"txt";case 22:return 6;case 23:return 8;case 24:return"value";case 25:return 28}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:%%(?!\{)[^\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:[17,18],inclusive:!1},acc_descr:{rules:[15],inclusive:!1},acc_title:{rules:[13],inclusive:!1},close_directive:{rules:[],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},open_directive:{rules:[1],inclusive:!1},title:{rules:[11],inclusive:!1},string:{rules:[20,21],inclusive:!1},INITIAL:{rules:[0,5,6,7,8,9,10,12,14,16,19,22,23,24,25],inclusive:!0}}};return u}();O.lexer=U;function v(){this.yy={}}return v.prototype=O,O.Parser=v,new v}();rt.parser=rt;var Dt=rt,K={},at=!1,Tt=function(e,f,E){bt.parseDirective(this,e,f,E)},$t=function(e,f){e=ht.sanitizeText(e,F()),K[e]===void 0&&(K[e]=f,C.debug("Added new section :",e))},At=()=>K,It=function(e){at=e},Vt=function(){return at},Pt=function(e){return e.substring(0,1)===":"&&(e=e.substring(1).trim()),Number(e.trim())},Ot=function(){K={},at=!1,pt()},Lt={parseDirective:Tt,getConfig:()=>F().pie,addSection:$t,getSections:At,cleanupValue:Pt,clear:Ot,setAccTitle:ft,getAccTitle:yt,setDiagramTitle:_t,getDiagramTitle:gt,setShowData:It,getShowData:Vt,getAccDescription:mt,setAccDescription:dt},Ct=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};
}
`,Ft=Ct,g=F(),x,j=450,Nt=(e,f,E,m)=>{var U;var D;try{g=F(),C.debug(`Rendering info diagram
`+e);let v=F().securityLevel,u;v==="sandbox"&&(u=J("#i"+f));let t=v==="sandbox"?J(u.nodes()[0].contentDocument.body):J("body"),i=v==="sandbox"?u.nodes()[0].contentDocument:document;m.db.clear(),m.parser.parse(e),C.debug("Parsed info diagram");let n=i.getElementById(f);x=n.parentElement.offsetWidth,x===void 0&&(x=1200),g.useWidth!==void 0&&(x=g.useWidth),g.pie.useWidth!==void 0&&(x=g.pie.useWidth);let a=t.select("#"+f);ut(a,j,x,g.pie.useMaxWidth),n.setAttribute("viewBox","0 0 "+x+" "+j);var T=40,y=18,I=4,S=Math.min(x,j)/2-T,o=a.append("g").attr("transform","translate("+x/2+","+j/2+")"),V=m.db.getSections(),N=0;Object.keys(V).forEach(function(c){N+=V[c]});let r=g.themeVariables;var R=[r.pie1,r.pie2,r.pie3,r.pie4,r.pie5,r.pie6,r.pie7,r.pie8,r.pie9,r.pie10,r.pie11,r.pie12];let s=(U=(D=g.pie)==null?void 0:D.textPosition)!=null?U:.75,[d]=vt(r.pieOuterStrokeWidth);d!=null||(d=2);var w=lt().range(R),M=Object.entries(V).map(function(c,_){return{order:_,name:c[0],value:c[1]}}),B=ot().value(function(c){return c.value}).sort(function(c,_){return c.order-_.order}),P=B(M),Y=nt().innerRadius(0).outerRadius(S),W=nt().innerRadius(S*s).outerRadius(S*s);o.append("circle").attr("cx",0).attr("cy",0).attr("r",S+d/2).attr("class","pieOuterCircle"),o.selectAll("mySlices").data(P).enter().append("path").attr("d",Y).attr("fill",function(c){return w(c.data.name)}).attr("class","pieCircle"),o.selectAll("mySlices").data(P).enter().append("text").text(function(c){return(c.data.value/N*100).toFixed(0)+"%"}).attr("transform",function(c){return"translate("+W.centroid(c)+")"}).style("text-anchor","middle").attr("class","slice"),o.append("text").text(m.db.getDiagramTitle()).attr("x",0).attr("y",-(j-50)/2).attr("class","pieTitleText");var O=o.selectAll(".legend").data(w.domain()).enter().append("g").attr("class","legend").attr("transform",function(c,_){let z=y+I,Q=z*w.domain().length/2,q=12*y,X=_*z-Q;return"translate("+q+","+X+")"});O.append("rect").attr("width",y).attr("height",y).style("fill",w).style("stroke",w),O.data(P).append("text").attr("x",y+I).attr("y",y-I).text(function(c){return m.db.getShowData()||g.showData||g.pie.showData?c.data.name+" ["+c.data.value+"]":c.data.name})}catch(v){C.error("Error while rendering info diagram"),C.error(v)}},Wt={draw:Nt},Ut={parser:Dt,db:Lt,renderer:Wt,styles:Ft};export{Ut as diagram};