(self.webpackChunk_cocalc_static=self.webpackChunk_cocalc_static||[]).push([[1421],{1421:(t,e,r)=>{var n,a,i,o,c,s;n=window.$,c=r(24620),({defaults:o,required:s}=c),a=r(24565),"undefined"!=typeof window&&null!==window&&(window.d3=a),n.fn.extend({d3:function(t={}){return t=o(t,{viewer:s,data:s}),this.each((function(){var e,r;return r=n(this),e=n("<div>"),r.replaceWith(e),"graph"===t.viewer?i(e,t.data):e.append(n(`<span>unknown d3 viewer '${t.viewer}'</span>`)),e}))}}),i=function(t,e){var r,n,i,o,s,l,u,d,p,f,h,x,g,v,y;if(n=a.scale.category20(),null==(y=e.width)&&(y=Math.min(t.width(),700)),null==(s=e.height)&&(s=.6*y),t.width(y),t.height(s),t.addClass("smc-d3-graph"),o=a.layout.force().charge(e.charge).linkDistance(e.link_distance).linkStrength(e.link_strength).gravity(e.gravity).size([y,s]).links(e.links).nodes(e.nodes),g=function(t,e,r){var n,a,i,o,c,s,l,u;return e.x,t.x,e.y,t.y,l=t.x,u=t.y,a=e.x,n=((i=e.y)+u)/2,s=-(a-l),[(a+l)/2+r*(c=i-u)/(o=Math.sqrt(c*c+s*s)),n+r*s/o]},r=function(t){var e,r,n,a,i,c,l,u,d;return n=t.pos[0][0],e=t.pos[0][0],a=t.pos[0][1],r=t.pos[0][1],t.nodes.forEach((function(i,o){return e=Math.max(e,t.pos[o][0]),n=Math.min(n,t.pos[o][0]),r=Math.max(r,t.pos[o][1]),a=Math.min(a,t.pos[o][1])})),l=e-n,d=r-a,i=Math.min((s-60)/d,(y-60)/l),c=(y-i*l)/2,u=(s-i*d)/2,o.nodes().forEach((function(e,r){return e.x=i*(t.pos[r][0]-n)+c,e.y=i*(t.pos[r][1]-a)+u}))},0!==e.pos.length&&r(e),l="a"+c.uuid(),t.attr("id",l),x=a.select(`#${l}`).append("svg").attr("width",y).attr("height",s),p=x.selectAll(".link").data(o.links()).enter().append("path").attr("class",(function(t){return"link directed"})).attr("marker-end",(function(t){return"url(#directed)"})).style("stroke",(function(t){return t.color})).style("stroke-width",e.edge_thickness+"px"),f=x.selectAll(".loop").data(e.loops).enter().append("circle").attr("class","link").attr("r",(function(t){return t.curve})).style("stroke",(function(t){return t.color})).style("stroke-width",e.edge_thickness+"px"),(h=x.selectAll(".node").data(o.nodes()).enter().append("circle").attr("class","node").attr("r",e.vertex_size).style("fill",(function(t){return n(t.group)})).call(o.drag)).append("title").text((function(t){return t.name})),e.vertex_labels&&(v=x.selectAll(".v_label").data(o.nodes()).enter().append("svg:text").attr("vertical-align","middle").text((function(t){return t.name}))),e.edge_labels&&(i=x.selectAll(".e_label").data(o.links()).enter().append("svg:text").attr("text-anchor","middle").text((function(t){return t.name})),u=x.selectAll(".l_label").data(e.loops).enter().append("svg:text").attr("text-anchor","middle").text((function(t,r){return e.loops[r].name}))),e.directed&&x.append("svg:defs").selectAll("marker").data(["directed"]).enter().append("svg:marker").attr("id",String).attr("viewBox","0 -2 4 4").attr("refX",Math.ceil(2*Math.sqrt(e.vertex_size))).attr("refY",0).attr("markerWidth",4).attr("markerHeight",4).attr("orient","auto").append("svg:path").attr("d","M0,-2L4,0L0,2"),d=a.svg.line().interpolate("cardinal").tension(.2).x((function(t){return t.x})).y((function(t){return t.y})),o.on("tick",(function(){if(h.attr("cx",(function(t){return t.x})).attr("cy",(function(t){return t.y})),p.attr("d",(function(t){var e;return 0===t.curve?`M${t.source.x},${t.source.y} L${t.target.x},${t.target.y}`:(e=g(t.source,t.target,t.curve),d([{x:t.source.x,y:t.source.y},{x:e[0],y:e[1]},{x:t.target.x,y:t.target.y}]))})),0!==e.loops.length&&f.attr("cx",(function(t){return o.nodes()[t.source].x})).attr("cy",(function(t){return o.nodes()[t.source].y-t.curve})),e.vertex_labels&&v.attr("x",(function(t){return t.x+e.vertex_size})).attr("y",(function(t){return t.y})),e.edge_labels)return i.attr("x",(function(t){return g(t.source,t.target,t.curve+3)[0]})).attr("y",(function(t){return g(t.source,t.target,t.curve+3)[1]})),u.attr("x",(function(t,e){return o.nodes()[t.source].x})).attr("y",(function(t,e){return o.nodes()[t.source].y-2*t.curve-1}))})),o.start(),0!==e.pos.length)return o.tick(),o.stop(),e.nodes.forEach((function(t,e){return t.fixed=!0}))}}}]);