text: !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("d3-selection")):"function"==typeof define&&define.amd?define(["exports","d3-selection"],e):e((t=t||self).d3=t.d3||{},t.d3)}(this,function(t,i){"use strict";function h(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function e(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function s(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function p(t){return 0<t?1:t<0?-1:0}var a=function(){function o(t,e,n,r,i){h(this,o),this.node=t,this.name=e,this.x=n,this.y=r,this.d=i,this.dx=0,1===i?this.dx=1:3===i&&(this.dx=-1),(this.dy=0)===i?this.dy=-1:2===i&&(this.dy=1)}return e(o,[{key:"copy",value:function(t){return new o(t.node,t.name,t.x,t.y,t.d)}},{key:"moveTo",value:function(t,e){this.x=t,this.y=e}},{key:"slope",value:function(){return 0===this.dy?0:0===this.dx?this.dy:this.dx/this.dy}},{key:"intersects",value:function(t){var e=p(this.x-t.x),n=p(this.y-t.y),r=t.dx-this.dx,i=t.dy-this.dy;return e===r&&n===i}}]),o}();a.CENTER=-1,a.UP=0,a.DOWN=2,a.LEFT=3,a.RIGHT=1;var d=function(){function s(t,e,n,r,i){h(this,s),this.name=null,this.description=null,this.x=t,void 0===this.x&&(this.x=0),this.y=e,void 0===this.y&&(this.y=0),this.width=n,void 0===this.width&&(this.width=20),this.height=r,void 0===this.height&&(this.height=8),this.op=i;var o=this.height/2;this.anchors={label:new a(this,"label",this.x,this.y+o,a.DOWN)},this.anchorOrder=[this.anchors.north,this.anchors.east,this.anchors.south,this.anchors.west],this.inEdges=[],this.outEdges=[],this.inputEdgesByName={}}return e(s,[{key:"boundingBox",value:function(){var t=this.height/2,e=this.width/2;return[{x:this.x-e,y:this.y-t},{x:this.x+e,y:this.y+t}]}},{key:"setDescription",value:function(t){this.description=t}},{key:"addAnchor",value:function(t,e){var n=this.height/2,r=this.width/2,i=null,o=e;e.x&&"string"==typeof e.x?o=e.x:e.y&&"string"==typeof e.y&&(o=e.y),"center"===o?i=new a(this,t,this.x,this.y,a.CENTER):"north"===o?i=new a(this,t,this.x,this.y-n,a.UP):"east"===o?i=new a(this,t,this.x+r,this.y,a.RIGHT):"west"===o?i=new a(this,t,this.x-r,this.y,a.LEFT):"south"===o&&(i=new a(this,t,this.x,this.y+n,a.DOWN)),e.x&&"string"!=typeof e.x?i.x=e.x:e.y&&"string"!=typeof e.y&&(i.y=e.y),i&&(this.anchors[t]=i)}},{key:"getAnchor",value:function(t){return this.anchors[t]}},{key:"getAnchorIndex",value:function(t){return this.anchorOrder.indexOf(t)}},{key:"previousAnchor",value:function(t){var e=this.anchorOrder.length,n=this.getAnchorIndex(t);return n=(n+e-1)%e,this.anchorOrder[n]}},{key:"nextAnchor",value:function(t){var e=this.anchorOrder.length,n=(this.getAnchorIndex(t)+1)%e;return this.anchorOrder[n]}},{key:"getClosestAnchor",value:function(t){var e=null;for(var n in this.anchors){var r=this.anchors[n];r.intersects(t)&&(e=r)}return e}},{key:"getEdge",value:function(t){return this.inputEdgesByName[t]}},{key:"moveTo",value:function(t,e){for(var n in this.anchors){var r=this.anchors[n],i=r.x-this.x,o=r.y-this.y;r.moveTo(t+i,e+o)}this.x=t,this.y=e}},{key:"setLabel",value:function(t,e,n){void 0===e&&(e="label"),this.labelText=t,this.labelAnchor=this.getAnchor(e),this.labelOrientation=n}}]),s}(),g=function(t){function r(t,e){var n;return h(this,r),(n=s(this,o(r).call(this,t,e,0,0,null))).addAnchor("0","north"),n.addAnchor("1","east"),n.addAnchor("2","south"),n.addAnchor("3","west"),n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&n(t,e)}(r,d),r}();function x(t,e){return"L"+t+","+e}function v(t,e,n,r){return"Q"+t+","+e+","+n+","+r}var c=function(){function n(t,e){h(this,n),this.startAnchor=t,this.endAnchor=e,t instanceof d&&(this.startAnchor=t.getClosestAnchor(e)),e instanceof d&&(this.endAnchor=e.getClosestAnchor(t)),this.arcRadius=8,this.markerSize=6,this.controlPoints=[],this.startAnchor.node.outEdges.push(this),this.endAnchor.node.inEdges.push(this),this.endAnchor.node.inputEdgesByName[this.endAnchor.name]=this}return e(n,[{key:"addControlPoint",value:function(t,e){this.controlPoints.push({x:t,y:e})}},{key:"getJointAnchors",value:function(t,e,n){var r=n.getClosestAnchor(t),i=n.getClosestAnchor(e);return r===i&&(r=n.previousAnchor(r),i=n.nextAnchor(i)),[r,i]}},{key:"boundingBox",value:function(){for(var t=Math.min(this.startAnchor.x,this.endAnchor.x),e=Math.min(this.startAnchor.y,this.endAnchor.y),n=Math.max(this.startAnchor.x,this.endAnchor.x),r=Math.max(this.startAnchor.y,this.endAnchor.y),i=0;i<this.controlPoints.length;i++)t=Math.min(t,this.controlPoints[i].x),e=Math.min(e,this.controlPoints[i].y),n=Math.max(n,this.controlPoints[i].x),r=Math.max(r,this.controlPoints[i].y);return[{x:t,y:e},{x:n,y:r}]}},{key:"edgePiece",value:function(t,e){var n="",r=null,i=null,o=e.x-t.x,s=e.y-t.y;if(0===s||0===o){if(0===s&&t.dx===e.dx||0===o&&t.dy===e.dy){var h=this.copy(t);h.x+=20*h.dx,h.y+=20*h.dy;var a=this.copy(e);a.x+=20*a.dx,a.y+=20*a.dy;var d=a.x-h.x,c=a.y-h.y;r=new g(h.x+d/2,h.y+c/2),i=this.getJointAnchors(t,e,r),n+=this.edgePiece(t,i[0]),n+=this.edgePiece(i[1],e)}}else if(t.dy===e.dy||t.dx===e.dx)r=new g(t.x+o/2,t.y+s/2),i=this.getJointAnchors(t,e,r),n+=this.edgePiece(t,i[0]),n+=this.edgePiece(i[1],e);else{var l=p(o),u=p(s),f=this.arcRadius*l,y=this.arcRadius*u;n="",0!==t.dx?(n+=x(e.x-f,t.y),n+=v(e.x,t.y,e.x,t.y+y)):0!==t.dy&&(n+=x(t.x,e.y-y),n+=v(t.x,e.y,t.x+f,e.y))}return n}},{key:"pathData",value:function(){var t,e,n="";if(n+=(t=this.startAnchor.x,e=this.startAnchor.y,"M"+t+","+e),0<this.controlPoints.length){for(var r=this.startAnchor,i=0;i<this.controlPoints.length;i++){var o=this.controlPoints[i],s=new g(o.x,o.y),h=[s.getAnchor("3"),s.getAnchor("1")];n+=this.edgePiece(r,h[0]),r=h[1]}n+=this.edgePiece(r,this.endAnchor)}else n+=this.edgePiece(this.startAnchor,this.endAnchor);var a=this.endAnchor.dx*this.markerSize*.5,d=this.endAnchor.dy*this.markerSize*.5;return n+=x(this.endAnchor.x+a,this.endAnchor.y+d)}},{key:"drawControlPoints",value:function(t){for(var e=0;e<this.controlPoints.length;e++){var n=this.controlPoints[e];t.append("ellipse").attr("rx",3).attr("ry",3).attr("cx",n.x).attr("cy",n.y).style("fill","none").style("stroke","#f00").style("stroke-width",1)}}}]),n}(),l=function(){function i(t,e){h(this,i),this.rowOffsets=[0];for(var n=0,r=0;r<e.length;r++)n+=e[r],this.rowOffsets.push(n);for(this.height=n,this.columnOffsets=[0],r=n=0;r<t.length;r++)n+=t[r],this.columnOffsets.push(n);this.width=n,this.nodes=[]}return e(i,[{key:"placeNode",value:function(t,e,n){var r=this.columnOffsets[t],i=this.rowOffsets[e];return n.moveTo(r,i),this.nodes.push(n),n}},{key:"placeColumnAnchor",value:function(t,e,n,r){var i=this.columnOffsets[t],o=n.y-n.height/2;return e===a.DOWN&&(o=n.y+n.height/2),n.anchors[r]=new a(n,i,o,e),n.anchors[r]}},{key:"placeRowAnchor",value:function(t,e,n,r){var i=n.x-n.width/2,o=this.rowOffsets[t];return e===a.RIGHT&&(i=n.x+n.width/2),n.anchors[r]=new a(n,i,o,e),n.anchors[r]}},{key:"drawGridLine",value:function(t,e,n,r,i){t.append("line").attr("x1",e).attr("y1",n).attr("x2",r).attr("y2",i).style("stroke","rgba(0,0,0,0.2)").style("stroke-dasharray","5, 5").style("stroke-width",1)}},{key:"drawGridLines",value:function(t){for(var e=0;e<this.rowOffsets.length;e++)this.drawGridLine(t,0,this.rowOffsets[e],this.width,this.rowOffsets[e]);for(e=0;e<this.columnOffsets.length;e++)this.drawGridLine(t,this.columnOffsets[e],0,this.columnOffsets[e],this.height)}}]),i}(),u={"tf.concat":"M3 10.95l.833.833L5.85 9.767l-.833-.833L3 10.95zM10.333 5.333l0 2.067-3.3 0L3.833 4.2l-.833.833 3.55 3.55L10.333 8.583 10.333 10.667 13 8 10.333 5.333z","tf.sigmoid":"M6.684 3.681a4.489 4.489 0 0 0-1.542.745A4.302 4.302 0 0 0 3.91 5.885q-.497.921-.497 2.329a4.826 4.826 0 0 0 .31 1.729 4.311 4.311 0 0 0 .88 1.428A4.212 4.212 0 0 0 5.98 12.344a4.301 4.301 0 0 0 1.78.362 4.244 4.244 0 0 0 3.043-1.273 4.457 4.457 0 0 0 .952-1.49 5.284 5.284 0 0 0 .352-1.977 4.041 4.041 0 0 0-.321-1.615 5.495 5.495 0 0 0-.735-1.263 4.256 4.256 0 0 0 1.18.186 3.383 3.383 0 0 0 1.17-.186 2.023 2.023 0 0 0 .797-.497V3.556a2.169 2.169 0 0 1-.776.207q-.445.042-.756.041-.352 0-.89-.052t-1.159-.114q-.621-.062-1.273-.114T8.112 3.474A5.847 5.847 0 0 0 6.684 3.681Zm-.072 8.012a2.204 2.204 0 0 1-.787-.805A3.512 3.512 0 0 1 5.411 9.68a9.074 9.074 0 0 1-.114-1.476q0-1.61.724-2.508a2.287 2.287 0 0 1 1.863-.898 5.4 5.4 0 0 1 .859.062q.383.062 .859.165a5.84 5.84 0 0 1 .486 1.631 11.076 11.076 0 0 1 .135 1.651 10.546 10.546 0 0 1-.072 1.177A4.041 4.041 0 0 1 9.83 10.681a2.439 2.439 0 0 1-.714.929q-.466.372-1.273.371Q7.098 11.981 6.611 11.692Z","tf.split":"M12.583 9.15l-1.317 1.317-1.65-1.65-.817.817 1.65 1.65-1.317 1.317L12.583 12.6 12.583 9.15zM12.583 6.85 12.583 3.417l-3.433 0 1.317 1.317-2.7 2.7-4.35 0 0 1.15L8.233 8.583 11.267 5.533 12.583 6.85z","tf.tanh":"M7.3.7H8.7V7.2s1.202-.232 2.2-1.5 1.5-3.6 1.5-3.6l1.1 1.2s-.665 2.128-1.6 3.3C10.657 8.158 8.7 8.6 8.7 8.6v6.7H7.3V8.9s-1.439.242-2.3 1.5-1.4 3.4-1.4 3.4L2.4 12.7s.829-2.378 2.1-3.7A5.345 5.345 0 0 1 7.3 7.5V.7Zm8 6.7V8.6H11.8s.248-.185.7-.6.5-.7.5-.7ZM.7 7.3V8.7H3a2.111 2.111 0 0 1 .4-.7c.256-.261.9-.6.9-.6Z"};function f(t,e){t.append("path").attr("id",e.replace(/\./g,"_")+"_icon").attr("d",u[e]).style("fill","#a6a6a6").style("stroke-width",0)}function y(t){return t in u}var m=function(){function r(t,e,n){h(this,r),this.element=t,this.config=n,this.draw(e)}return e(r,[{key:"draw",value:function(t){this.nodes=[],this.nodesByName={};for(var e=0;e<t.nodes.length;e++){var n=t.nodes[e],r=this.buildNode(n);r.dataIndex=e,this.nodesByName[r.name]=r,this.nodes.push(r)}for(this.edges=[],e=0;e<t.nodes.length;e++)n=t.nodes[e],this.buildNodeEdges(n);if("control points"in t)for(e=0;e<t["control points"].length;e++){var i=t["control points"][e],o=i.edge.split(":");this.getNode(o[0]).getEdge(o[1]).addControlPoint(i.x,i.y)}var s=this.boundingBox(),h=this.element.append("svg").attr("class","d3-tensor-graph").attr("width",s[1].x+40).attr("height",s[1].y+40),a=h.append("svg:defs");this.arrowGlyph(a),f(a,"tf.split"),f(a,"tf.concat"),f(a,"tf.tanh"),f(a,"tf.sigmoid"),this.nodeElements=h.selectAll("g.d3-tensor-graph-node").data(this.nodes).enter().append("g").attr("class",function(t){return"tf.name_scope"===t.op?t.inEdges.length+t.outEdges.length===0?"d3-tensor-graph-node d3-tensor-graph-name-scope":"d3-tensor-graph-node d3-tensor-graph-module":"d3-tensor-graph-node"}),this.nodeElements.data(this.nodes).append("rect").attr("rx",8).attr("ry",8).attr("x",function(t){return t.x-t.width/2}).attr("y",function(t){return t.y-t.height/2}).attr("width",function(t){return t.width}).attr("height",function(t){return t.height}).style("stroke-dasharray",function(t){if("tf.placeholder"===t.op)return"2,2"}),this.nodeElements.filter(function(t){return y(t.op)}).append("use").attr("xlink:href",function(t){return"#"+t.icon}).attr("transform",function(t){return"translate("+(t.x-t.width/2)+", "+(t.y-t.height/2)+")"}),this.nodeElements.filter(function(t,e){return t.labelText}).append("text").attr("class","d3-tensor-graph-node-label").attr("transform",function(t){var e=t.labelAnchor.x,n=t.labelAnchor.y,r=0;"vertical"===t.labelOrientation?(r=-90,0<t.labelAnchor.dy?e+=16:t.labelAnchor.dy<0?e-=8:e+=3):0<t.labelAnchor.dy?n+=16:t.labelAnchor.dy<0?n-=8:n+=3;var i="translate("+e+", "+n+") ";return 0!==r&&(i+="rotate("+r+")"),i}).attr("text-anchor",function(t){return 0===t.labelAnchor.dx?"middle":t.labelAnchor.dx<0?"end":"start"}).text(function(t){return t.labelText}),this.edgeElements=h.selectAll("g.d3-tensor-graph-edge").data(this.edges).enter().append("path").attr("class","d3-tensor-graph-edge").attr("d",function(t){return t.pathData()}).attr("fill","none").attr("stroke-width",1).attr("stroke","#a6a6a6").attr("marker-end","url(#arrow)")}},{key:"buildNode",value:function(t){var e=new d;"name"in t&&(e.name=t.name),"caption"in t&&e.setDescription(t.caption),"x"in t&&(e.x=t.x),"y"in t&&(e.y=t.y),"width"in t&&(e.width=t.width),"height"in t&&(e.height=t.height),"label"in t&&(e.addAnchor("label",t.label.anchor),e.setLabel(t.label.name,"label",t.label.orientation)),"op"in t&&(e.op=t.op,y(e.op)&&(e.icon=e.op.replace(".","_")+"_icon",e.width=16,e.height=16));for(var n=0;n<t.anchors.length;n++)e.addAnchor(n.toString(),t.anchors[n]);return e}},{key:"buildNodeEdges",value:function(t){var e=this.nodesByName[t.name];for(var n in t.inputs){var r=t.inputs[n],i=r.split(":")[0],o=r.split(":")[1],s=this.nodesByName[i];null==s&&console.error("Unable to find start node: "+i);var h=s.getAnchor(o);null==h&&console.error("Unable to find start anchor: "+o);var a=e.getAnchor(n);null==a&&console.error("Unable to find end anchor: "+n);var d=new c(h,a);this.edges.push(d)}}},{key:"update",value:function(t,e,n){var r=n[n.length-1];this.element.selectAll(".d3-tensor-graph-node").classed("selected",function(t){return t.dataIndex===r&&t.description}),this.element.selectAll(".d3-tensor-graph-edge").classed("selected",function(t){return t.startAnchor.node.dataIndex===r&&t.startAnchor.node.description||t.endAnchor.node.dataIndex===r&&t.endAnchor.node.description})}},{key:"boundingBox",value:function(){for(var t=Number.MAX_VALUE,e=Number.MAX_VALUE,n=Number.MIN_VALUE,r=Number.MIN_VALUE,i=0;i<this.nodes.length;i++){var o=this.nodes[i].boundingBox();t=Math.min(t,o[0].x),e=Math.min(e,o[0].y),n=Math.max(n,o[1].x),r=Math.max(r,o[1].y)}for(i=0;i<this.edges.length;i++){var s=this.edges[i].boundingBox();t=Math.min(t,s[0].x),e=Math.min(e,s[0].y),n=Math.max(n,s[1].x),r=Math.max(r,s[1].y)}return[{x:t,y:e},{x:n,y:r}]}},{key:"getNode",value:function(t){return this.nodesByName[t]}},{key:"eachNodeElement",value:function(n){this.nodeElements.each(function(t,e){n(i.select(this),[e])})}},{key:"asJSON",value:function(){for(var t=[],e=0;e<this.nodes.length;e++){var n=this.nodes[e],r={name:n.name,op:n.op,x:n.x,y:n.y,caption:n.caption,label:{},anchors:{},inputs:{}};t.push(r)}return{nodes:t}}},{key:"arrowGlyph",value:function(t){t.append("svg:marker").attr("id","arrow").attr("viewBox","0 -5 10 10").attr("refX",5).attr("refY",0).attr("markerWidth",6).attr("markerHeight",6).attr("orient","auto").append("path").attr("d","M0,-5L10,0L0,5").attr("class","arrowHead"),t.append("svg:marker").attr("id","arrow-hover").attr("viewBox","0 -5 10 10").attr("refX",5).attr("refY",0).attr("markerWidth",6).attr("markerHeight",6).attr("orient","auto").append("path").attr("d","M0,-5L10,0L0,5").attr("class","arrowHead")}}]),r}();t.Anchor=a,t.DivisorNode=g,t.Edge=c,t.GridLayout=l,t.Node=d,t.tensorGraph=function(t,e,n){return new m(t,e,n)},Object.defineProperty(t,"__esModule",{value:!0})});