ishikawaDiagram-YF4QCWOH-CLhAstqo.js 17 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import{aa as l,dn as lt,fv as ct,g1 as ut,bc as dt,bZ as yt,c4 as ft,g6 as et,dg as pt,g4 as gt,df as kt,g3 as mt,dr as wt,cb as _t}from"./builder-DygomDiV.js";var Q=(function(){var t=l(function(T,e,s,i){for(s=s||{},i=T.length;i--;s[T[i]]=e);return s},"o"),d=[1,4],n=[1,14],a=[1,12],o=[1,13],y=[6,7,8],p=[1,20],u=[1,18],m=[1,19],c=[6,7,11],k=[1,6,13,14],g=[1,23],_=[1,24],x=[1,6,7,11,13,14],D={trace:l(function(){},"trace"),yy:{},symbols_:{error:2,start:3,ishikawa:4,spaceLines:5,SPACELINE:6,NL:7,ISHIKAWA:8,document:9,stop:10,EOF:11,statement:12,SPACELIST:13,TEXT:14,$accept:0,$end:1},terminals_:{2:"error",6:"SPACELINE",7:"NL",8:"ISHIKAWA",11:"EOF",13:"SPACELIST",14:"TEXT"},productions_:[0,[3,1],[3,2],[5,1],[5,2],[5,2],[4,2],[4,3],[10,1],[10,1],[10,1],[10,2],[10,2],[9,3],[9,2],[12,2],[12,1],[12,1],[12,1]],performAction:l(function(e,s,i,h,f,r,v){var w=r.length-1;switch(f){case 6:case 7:return h;case 15:h.addNode(r[w-1].length,r[w].trim());break;case 16:h.addNode(0,r[w].trim());break}},"anonymous"),table:[{3:1,4:2,5:3,6:[1,5],8:d},{1:[3]},{1:[2,1]},{4:6,6:[1,7],7:[1,8],8:d},{6:n,7:[1,10],9:9,12:11,13:a,14:o},t(y,[2,3]),{1:[2,2]},t(y,[2,4]),t(y,[2,5]),{1:[2,6],6:n,12:15,13:a,14:o},{6:n,9:16,12:11,13:a,14:o},{6:p,7:u,10:17,11:m},t(c,[2,18],{14:[1,21]}),t(c,[2,16]),t(c,[2,17]),{6:p,7:u,10:22,11:m},{1:[2,7],6:n,12:15,13:a,14:o},t(k,[2,14],{7:g,11:_}),t(x,[2,8]),t(x,[2,9]),t(x,[2,10]),t(c,[2,15]),t(k,[2,13],{7:g,11:_}),t(x,[2,11]),t(x,[2,12])],defaultActions:{2:[2,1],6:[2,2]},parseError:l(function(e,s){if(s.recoverable)this.trace(e);else{var i=new Error(e);throw i.hash=s,i}},"parseError"),parse:l(function(e){var s=this,i=[0],h=[],f=[null],r=[],v=this.table,w="",I=0,$=0,L=2,A=1,C=r.slice.call(arguments,1),b=Object.create(this.lexer),S={yy:{}};for(var P in this.yy)Object.prototype.hasOwnProperty.call(this.yy,P)&&(S.yy[P]=this.yy[P]);b.setInput(e,S.yy),S.yy.lexer=b,S.yy.parser=this,typeof b.yylloc>"u"&&(b.yylloc={});var R=b.yylloc;r.push(R);var H=b.options&&b.options.ranges;typeof S.yy.parseError=="function"?this.parseError=S.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function X(B){i.length=i.length-2*B,f.length=f.length-B,r.length=r.length-B}l(X,"popStack");function J(){var B;return B=h.pop()||b.lex()||A,typeof B!="number"&&(B instanceof Array&&(h=B,B=h.pop()),B=s.symbols_[B]||B),B}l(J,"lex");for(var M,W,N,Y,F={},G,V,tt,U;;){if(W=i[i.length-1],this.defaultActions[W]?N=this.defaultActions[W]:((M===null||typeof M>"u")&&(M=J()),N=v[W]&&v[W][M]),typeof N>"u"||!N.length||!N[0]){var K="";U=[];for(G in v[W])this.terminals_[G]&&G>L&&U.push("'"+this.terminals_[G]+"'");b.showPosition?K="Parse error on line "+(I+1)+`:
  2. `+b.showPosition()+`
  3. Expecting `+U.join(", ")+", got '"+(this.terminals_[M]||M)+"'":K="Parse error on line "+(I+1)+": Unexpected "+(M==A?"end of input":"'"+(this.terminals_[M]||M)+"'"),this.parseError(K,{text:b.match,token:this.terminals_[M]||M,line:b.yylineno,loc:R,expected:U})}if(N[0]instanceof Array&&N.length>1)throw new Error("Parse Error: multiple actions possible at state: "+W+", token: "+M);switch(N[0]){case 1:i.push(M),f.push(b.yytext),r.push(b.yylloc),i.push(N[1]),M=null,$=b.yyleng,w=b.yytext,I=b.yylineno,R=b.yylloc;break;case 2:if(V=this.productions_[N[1]][1],F.$=f[f.length-V],F._$={first_line:r[r.length-(V||1)].first_line,last_line:r[r.length-1].last_line,first_column:r[r.length-(V||1)].first_column,last_column:r[r.length-1].last_column},H&&(F._$.range=[r[r.length-(V||1)].range[0],r[r.length-1].range[1]]),Y=this.performAction.apply(F,[w,$,I,S.yy,N[1],f,r].concat(C)),typeof Y<"u")return Y;V&&(i=i.slice(0,-1*V*2),f=f.slice(0,-1*V),r=r.slice(0,-1*V)),i.push(this.productions_[N[1]][0]),f.push(F.$),r.push(F._$),tt=v[i[i.length-2]][i[i.length-1]],i.push(tt);break;case 3:return!0}}return!0},"parse")},O=(function(){var T={EOF:1,parseError:l(function(s,i){if(this.yy.parser)this.yy.parser.parseError(s,i);else throw new Error(s)},"parseError"),setInput:l(function(e,s){return this.yy=s||this.yy||{},this._input=e,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},"setInput"),input:l(function(){var e=this._input[0];this.yytext+=e,this.yyleng++,this.offset++,this.match+=e,this.matched+=e;var s=e.match(/(?:\r\n?|\n).*/g);return s?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),e},"input"),unput:l(function(e){var s=e.length,i=e.split(/(?:\r\n?|\n)/g);this._input=e+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-s),this.offset-=s;var h=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),i.length-1&&(this.yylineno-=i.length-1);var f=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:i?(i.length===h.length?this.yylloc.first_column:0)+h[h.length-i.length].length-i[0].length:this.yylloc.first_column-s},this.options.ranges&&(this.yylloc.range=[f[0],f[0]+this.yyleng-s]),this.yyleng=this.yytext.length,this},"unput"),more:l(function(){return this._more=!0,this},"more"),reject:l(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).
  4. `+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},"reject"),less:l(function(e){this.unput(this.match.slice(e))},"less"),pastInput:l(function(){var e=this.matched.substr(0,this.matched.length-this.match.length);return(e.length>20?"...":"")+e.substr(-20).replace(/\n/g,"")},"pastInput"),upcomingInput:l(function(){var e=this.match;return e.length<20&&(e+=this._input.substr(0,20-e.length)),(e.substr(0,20)+(e.length>20?"...":"")).replace(/\n/g,"")},"upcomingInput"),showPosition:l(function(){var e=this.pastInput(),s=new Array(e.length+1).join("-");return e+this.upcomingInput()+`
  5. `+s+"^"},"showPosition"),test_match:l(function(e,s){var i,h,f;if(this.options.backtrack_lexer&&(f={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&&(f.yylloc.range=this.yylloc.range.slice(0))),h=e[0].match(/(?:\r\n?|\n).*/g),h&&(this.yylineno+=h.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:h?h[h.length-1].length-h[h.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+e[0].length},this.yytext+=e[0],this.match+=e[0],this.matches=e,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(e[0].length),this.matched+=e[0],i=this.performAction.call(this,this.yy,this,s,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),i)return i;if(this._backtrack){for(var r in f)this[r]=f[r];return!1}return!1},"test_match"),next:l(function(){if(this.done)return this.EOF;this._input||(this.done=!0);var e,s,i,h;this._more||(this.yytext="",this.match="");for(var f=this._currentRules(),r=0;r<f.length;r++)if(i=this._input.match(this.rules[f[r]]),i&&(!s||i[0].length>s[0].length)){if(s=i,h=r,this.options.backtrack_lexer){if(e=this.test_match(i,f[r]),e!==!1)return e;if(this._backtrack){s=!1;continue}else return!1}else if(!this.options.flex)break}return s?(e=this.test_match(s,f[h]),e!==!1?e:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text.
  6. `+this.showPosition(),{text:"",token:null,line:this.yylineno})},"next"),lex:l(function(){var s=this.next();return s||this.lex()},"lex"),begin:l(function(s){this.conditionStack.push(s)},"begin"),popState:l(function(){var s=this.conditionStack.length-1;return s>0?this.conditionStack.pop():this.conditionStack[0]},"popState"),_currentRules:l(function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},"_currentRules"),topState:l(function(s){return s=this.conditionStack.length-1-Math.abs(s||0),s>=0?this.conditionStack[s]:"INITIAL"},"topState"),pushState:l(function(s){this.begin(s)},"pushState"),stateStackSize:l(function(){return this.conditionStack.length},"stateStackSize"),options:{"case-insensitive":!0},performAction:l(function(s,i,h,f){switch(h){case 0:return 6;case 1:return 8;case 2:return 8;case 3:return 6;case 4:return 7;case 5:return 13;case 6:return 14;case 7:return 11}},"anonymous"),rules:[/^(?:\s*%%.*)/i,/^(?:ishikawa-beta\b)/i,/^(?:ishikawa\b)/i,/^(?:[\s]+[\n])/i,/^(?:[\n]+)/i,/^(?:[\s]+)/i,/^(?:[^\n]+)/i,/^(?:$)/i],conditions:{INITIAL:{rules:[0,1,2,3,4,5,6,7],inclusive:!0}}};return T})();D.lexer=O;function E(){this.yy={}}return l(E,"Parser"),E.prototype=D,D.Parser=E,new E})();Q.parser=Q;var bt=Q,xt=class{constructor(){this.stack=[],this.clear=this.clear.bind(this),this.addNode=this.addNode.bind(this),this.getRoot=this.getRoot.bind(this)}static{l(this,"IshikawaDB")}clear(){this.root=void 0,this.stack=[],this.baseLevel=void 0,yt()}getRoot(){return this.root}addNode(t,d){const n=ft.sanitizeText(d,lt());if(!this.root){this.root={text:n,children:[]},this.stack=[{level:0,node:this.root}],et(n);return}this.baseLevel??=t;let a=t-this.baseLevel+1;for(a<=0&&(a=1);this.stack.length>1&&this.stack[this.stack.length-1].level>=a;)this.stack.pop();const o=this.stack[this.stack.length-1].node,y={text:n,children:[]};o.children.push(y),this.stack.push({level:a,node:y})}getAccTitle(){return pt()}setAccTitle(t){gt(t)}getAccDescription(){return kt()}setAccDescription(t){mt(t)}getDiagramTitle(){return wt()}setDiagramTitle(t){et(t)}},vt=14,j=250,St=30,$t=60,Et=5,ot=82*Math.PI/180,it=Math.cos(ot),st=Math.sin(ot),nt=l((t,d,n)=>{const a=t.node().getBBox(),o=a.width+d*2,y=a.height+d*2;_t(t,y,o,n),t.attr("viewBox",`${a.x-d} ${a.y-d} ${o} ${y}`)},"applyPaddedViewBox"),At=l((t,d,n,a)=>{const y=a.db.getRoot();if(!y)return;const p=lt(),{look:u,handDrawnSeed:m,themeVariables:c}=p,k=ct(p.fontSize)[0]??vt,g=u==="handDrawn",_=y.children??[],x=p.ishikawa?.diagramPadding??20,D=p.ishikawa?.useMaxWidth??!1,O=ut(d),E=O.append("g").attr("class","ishikawa"),T=g?dt.svg(O.node()):void 0,e=T?{roughSvg:T,seed:m??0,lineColor:c?.lineColor??"#333",fillColor:c?.mainBkg??"#fff"}:void 0,s=`ishikawa-arrow-${d}`;g||E.append("defs").append("marker").attr("id",s).attr("viewBox","0 0 10 10").attr("refX",0).attr("refY",5).attr("markerWidth",6).attr("markerHeight",6).attr("orient","auto").append("path").attr("d","M 10 0 L 0 5 L 10 10 Z").attr("class","ishikawa-arrow");let i=0,h=j;const f=g?void 0:z(E,i,h,i,h,"ishikawa-spine");if(It(E,i,h,y.text,k,e),!_.length){g&&z(E,i,h,i,h,"ishikawa-spine",e),nt(O,x,D);return}i-=20;const r=_.filter((S,P)=>P%2===0),v=_.filter((S,P)=>P%2===1),w=at(r),I=at(v),$=w.total+I.total;let L=j,A=j;if($>0){const S=j*2,P=j*.3;L=Math.max(P,S*(w.total/$)),A=Math.max(P,S*(I.total/$))}const C=k*2;L=Math.max(L,w.max*C),A=Math.max(A,I.max*C),h=Math.max(L,j),f&&f.attr("y1",h).attr("y2",h),E.select(".ishikawa-head-group").attr("transform",`translate(0,${h})`);const b=Math.ceil(_.length/2);for(let S=0;S<b;S++){const P=E.append("g").attr("class","ishikawa-pair");for(const[R,H,X]of[[_[S*2],-1,L],[_[S*2+1],1,A]])R&&Mt(P,R,i,h,H,X,k,e);i=P.selectAll("text").nodes().reduce((R,H)=>Math.min(R,H.getBBox().x),1/0)}if(g)z(E,i,h,0,h,"ishikawa-spine",e);else{f.attr("x1",i);const S=`url(#${s})`;E.selectAll("line.ishikawa-branch, line.ishikawa-sub-branch").attr("marker-start",S)}nt(O,x,D)},"draw"),at=l(t=>{const d=l(n=>n.children.reduce((a,o)=>a+1+d(o),0),"countDescendants");return t.reduce((n,a)=>{const o=d(a);return n.total+=o,n.max=Math.max(n.max,o),n},{total:0,max:0})},"sideStats"),It=l((t,d,n,a,o,y)=>{const p=Math.max(6,Math.floor(110/(o*.6))),u=t.append("g").attr("class","ishikawa-head-group").attr("transform",`translate(${d},${n})`),m=Z(u,ht(a,p),0,0,"ishikawa-head-label","start",o),c=m.node().getBBox(),k=Math.max(60,c.width+6),g=Math.max(40,c.height*2+40),_=`M 0 ${-g/2} L 0 ${g/2} Q ${k*2.4} 0 0 ${-g/2} Z`;if(y){const x=y.roughSvg.path(_,{roughness:1.5,seed:y.seed,fill:y.fillColor,fillStyle:"hachure",fillWeight:2.5,hachureGap:5,stroke:y.lineColor,strokeWidth:2});u.insert(()=>x,":first-child").attr("class","ishikawa-head")}else u.insert("path",":first-child").attr("class","ishikawa-head").attr("d",_);m.attr("transform",`translate(${(k-c.width)/2-c.x+3},${-c.y-c.height/2})`)},"drawHead"),Lt=l((t,d)=>{const n=[],a=[],o=l((y,p,u)=>{const m=d===-1?[...y].reverse():y;for(const c of m){const k=n.length,g=c.children??[];n.push({depth:u,text:ht(c.text,15),parentIndex:p,childCount:g.length}),u%2===0?(a.push(k),g.length&&o(g,k,u+1)):(g.length&&o(g,k,u+1),a.push(k))}},"walk");return o(t,-1,2),{entries:n,yOrder:a}},"flattenTree"),Tt=l((t,d,n,a,o,y,p)=>{const u=t.append("g").attr("class","ishikawa-label-group"),c=Z(u,d,n,a+11*o,"ishikawa-label cause","middle",y).node().getBBox();if(p){const k=p.roughSvg.rectangle(c.x-20,c.y-2,c.width+40,c.height+4,{roughness:1.5,seed:p.seed,fill:p.fillColor,fillStyle:"hachure",fillWeight:2.5,hachureGap:5,stroke:p.lineColor,strokeWidth:2});u.insert(()=>k,":first-child").attr("class","ishikawa-label-box")}else u.insert("rect",":first-child").attr("class","ishikawa-label-box").attr("x",c.x-20).attr("y",c.y-2).attr("width",c.width+40).attr("height",c.height+4)},"drawCauseLabel"),q=l((t,d,n,a,o,y)=>{const p=Math.sqrt(a*a+o*o);if(p===0)return;const u=a/p,m=o/p,c=6,k=-m*c,g=u*c,_=d,x=n,D=`M ${_} ${x} L ${_-u*c*2+k} ${x-m*c*2+g} L ${_-u*c*2-k} ${x-m*c*2-g} Z`,O=y.roughSvg.path(D,{roughness:1,seed:y.seed,fill:y.lineColor,fillStyle:"solid",stroke:y.lineColor,strokeWidth:1});t.append(()=>O)},"drawArrowMarker"),Mt=l((t,d,n,a,o,y,p,u)=>{const m=d.children??[],c=y*(m.length?1:.2),k=-it*c,g=st*c*o,_=n+k,x=a+g;if(z(t,n,a,_,x,"ishikawa-branch",u),u&&q(t,n,a,n-_,a-x,u),Tt(t,d.text,_,x,o,p,u),!m.length)return;const{entries:D,yOrder:O}=Lt(m,o),E=D.length,T=new Array(E);for(const[f,r]of O.entries())T[r]=a+g*((f+1)/(E+1));const e=new Map;e.set(-1,{x0:n,y0:a,x1:_,y1:x,childCount:m.length,childrenDrawn:0});const s=-it,i=st*o,h=o<0?"ishikawa-label up":"ishikawa-label down";for(const[f,r]of D.entries()){const v=T[f],w=e.get(r.parentIndex),I=t.append("g").attr("class","ishikawa-sub-group");let $=0,L=0,A=0;if(r.depth%2===0){const C=w.y1-w.y0;$=rt(w.x0,w.x1,C?(v-w.y0)/C:.5),L=v,A=$-(r.childCount>0?$t+r.childCount*Et:St),z(I,$,v,A,v,"ishikawa-sub-branch",u),u&&q(I,$,v,1,0,u),Z(I,r.text,A,v,"ishikawa-label align","end",p)}else{const C=w.childrenDrawn++;$=rt(w.x0,w.x1,(w.childCount-C)/(w.childCount+1)),L=w.y0,A=$+s*((v-L)/i),z(I,$,L,A,v,"ishikawa-sub-branch",u),u&&q(I,$,L,$-A,L-v,u),Z(I,r.text,A,v,h,"end",p)}r.childCount>0&&e.set(f,{x0:$,y0:L,x1:A,y1:v,childCount:r.childCount,childrenDrawn:0})}},"drawBranch"),Pt=l(t=>t.split(/<br\s*\/?>|\n/),"splitLines"),ht=l((t,d)=>{if(t.length<=d)return t;const n=[];for(const a of t.split(/\s+/)){const o=n.length-1;o>=0&&n[o].length+1+a.length<=d?n[o]+=" "+a:n.push(a)}return n.join(`
  7. `)},"wrapText"),Z=l((t,d,n,a,o,y,p)=>{const u=Pt(d),m=p*1.05,c=t.append("text").attr("class",o).attr("text-anchor",y).attr("x",n).attr("y",a-(u.length-1)*m/2);for(const[k,g]of u.entries())c.append("tspan").attr("x",n).attr("dy",k===0?0:m).text(g);return c},"drawMultilineText"),rt=l((t,d,n)=>t+(d-t)*n,"lerp"),z=l((t,d,n,a,o,y,p)=>{if(p){const u=p.roughSvg.line(d,n,a,o,{roughness:1.5,seed:p.seed,stroke:p.lineColor,strokeWidth:2});t.append(()=>u).attr("class",y);return}return t.append("line").attr("class",y).attr("x1",d).attr("y1",n).attr("x2",a).attr("y2",o)},"drawLine"),Bt={draw:At},Nt=l(t=>`
  8. .ishikawa .ishikawa-spine,
  9. .ishikawa .ishikawa-branch,
  10. .ishikawa .ishikawa-sub-branch {
  11. stroke: ${t.lineColor};
  12. stroke-width: 2;
  13. fill: none;
  14. }
  15. .ishikawa .ishikawa-sub-branch {
  16. stroke-width: 1;
  17. }
  18. .ishikawa .ishikawa-arrow {
  19. fill: ${t.lineColor};
  20. }
  21. .ishikawa .ishikawa-head {
  22. fill: ${t.mainBkg};
  23. stroke: ${t.lineColor};
  24. stroke-width: 2;
  25. }
  26. .ishikawa .ishikawa-label-box {
  27. fill: ${t.mainBkg};
  28. stroke: ${t.lineColor};
  29. stroke-width: 2;
  30. }
  31. .ishikawa text {
  32. font-family: ${t.fontFamily};
  33. font-size: ${t.fontSize};
  34. fill: ${t.textColor};
  35. }
  36. .ishikawa .ishikawa-head-label {
  37. font-weight: 600;
  38. text-anchor: middle;
  39. dominant-baseline: middle;
  40. font-size: 14px;
  41. }
  42. .ishikawa .ishikawa-label {
  43. text-anchor: end;
  44. }
  45. .ishikawa .ishikawa-label.cause {
  46. text-anchor: middle;
  47. dominant-baseline: middle;
  48. }
  49. .ishikawa .ishikawa-label.align {
  50. text-anchor: end;
  51. dominant-baseline: middle;
  52. }
  53. .ishikawa .ishikawa-label.up {
  54. dominant-baseline: baseline;
  55. }
  56. .ishikawa .ishikawa-label.down {
  57. dominant-baseline: hanging;
  58. }
  59. `,"getStyles"),Dt=Nt,Ct={parser:bt,get db(){return new xt},renderer:Bt,styles:Dt};export{Ct as diagram};