"use strict";var trig_drag=undefined;var img_w=undefined;var img_h=undefined;var text_dx=undefined;var text_dy=undefined;var nodesInfo=undefined;var linksInfo=undefined;var width=undefined;var height=undefined;var node_drag=undefined;var outer=undefined;var vis=undefined;var drag_line=undefined;var force=undefined;var nodes=undefined;var links=undefined;var node=undefined;var link=undefined;var nodes_text=undefined;function showTopology(t,e,n,i){var r=d3.scale.category20();width=$(t).width();height=$(t).height();trig_drag=i.trig_drag;img_w=i.img_w;img_h=i.img_h;text_dx=i.text_dx;text_dy=i.text_dy;nodesInfo=e;linksInfo=n;node_drag=d3.behavior.drag().on("dragstart",dragstart).on("drag",dragmove).on("dragend",dragend);outer=d3.select(t).append("svg:svg").attr("width",width).attr("height",height).attr("pointer-events","all");vis=outer.append("svg:g").on("dblclick.zoom",null).append("svg:g");vis.append("svg:rect").attr("width",width).attr("height",height).attr("fill","white");linksInfo.forEach(function(t,e){t.distance=calcDistance(nodesInfo[[linksInfo[e].source]],nodesInfo[[linksInfo[e].target]])});force=d3.layout.force().size([width,height]).gravity(0).charge(0).nodes(nodesInfo).links(linksInfo).linkDistance(function(t){return t.distance}).on("tick",tick);nodes=force.nodes();links=force.links();node=vis.selectAll(".node");link=vis.selectAll(".link");nodes_text=vis.selectAll(".nodetext");redraw();force.start()}function tick(){nodes.forEach(function(t,e){t.x=t.x-img_w/2<0?img_w/2:t.x;t.x=t.x+img_w/2>width?width-img_w/2:t.x;t.y=t.y-img_h/2<0?img_h/2:t.y;t.y=t.y+img_h/2+text_dy>height?height-img_h/2-text_dy:t.y});link.attr("x1",function(t){return t.source.x}).attr("y1",function(t){return t.source.y}).attr("x2",function(t){return t.target.x}).attr("y2",function(t){return t.target.y});node.attr("x",function(t){return t.x-img_w/2}).attr("y",function(t){return t.y-img_h/2});nodes_text.attr("x",function(t){return t.x});nodes_text.attr("y",function(t){return t.y+img_h/2+text_dy})}function dragstart(t,e){if(trig_drag==true){force.stop()}}function dragmove(t,e){if(trig_drag==true){t.px+=d3.event.dx;t.py+=d3.event.dy;t.x+=d3.event.dx;t.y+=d3.event.dy;tick()}}function dragend(t,e){if(trig_drag==true){tick()}}function redraw(){link=link.data(links);link.enter().insert("line",".node").attr("class","link").style("cursor","crosshair");link.style("stroke",function(t){return t.lineStyle.lineColor});link.style("stroke-width",function(t){return t.lineStyle.lineStroke});node=node.data(nodes);node.enter().insert("image").attr("class","node").attr("width",img_w).attr("height",img_h);node.attr("xlink:href",function(t){return t.image});node.call(node_drag);nodes_text=nodes_text.data(nodes);nodes_text.enter().append("text").attr("class","nodetext").attr("text-anchor","middle");nodes_text.text(function(t){return t.name});if(d3.event){d3.event.preventDefault()}}function calcDistance(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)}