javascript - Weird behaviour of Fisheye Distortion plugin -



javascript - Weird behaviour of Fisheye Distortion plugin -

hi utilize fisheye distortion plugin force-directed graph in d3.js, when want apply plugin, behaviour of graph weird. new in d3.js , not @ computer graphics.

complete sample in jsfiddle

var fisheye = d3.fisheye.circular() .radius(200) .distortion(2); // graph - variable represents whole graph graph.svg.on("mousemove", function() { fisheye.focus(d3.mouse(this)); d3.select("svg").selectall("circle").each(function(d) { d.fisheye = fisheye(d); }) .attr("cx", function(d) { homecoming d.fisheye.x; }) .attr("cy", function(d) { homecoming d.fisheye.y; }) .attr("r", function(d) { homecoming d.fisheye.z * 4.5; }); d3.select("svg").selectall("line").attr("x1", function(d) { homecoming d.source.fisheye.x; }) .attr("y1", function(d) { homecoming d.source.fisheye.y; }) .attr("x2", function(d) { homecoming d.target.fisheye.x; }) .attr("y2", function(d) { homecoming d.target.fisheye.y; }); });

weird behaviour mean nodes of graph disappear (are hidden) after mouseover action.

the problem using code add together cx , cy circles, circles enclosed within nodeelements transformed place.

hence, changing fisheye code next solves problem:

graph.svg.on("mousemove", function() { fisheye.focus(d3.mouse(this)); // alter transform on .node d3.select("svg").selectall(".node") .each(function(d) { d.fisheye = fisheye({ x: graph.x(d.x), y: graph.y(d.y) }); console.log(d.fisheye, d); }) .attr("transform", function (d) { homecoming "translate(" + d.fisheye.x + "," + d.fisheye.y + ")"; }) // alter 'r'adius on circles within // 1 can scale font of text within nodeelements here .select("circle") .attr("r", function(d) { homecoming 15 * graph.nodesizefactor * d.fisheye.z; }); d3.select("svg").selectall("line") .attr("x1", function(d) { homecoming d.source.fisheye.x; }) .attr("y1", function(d) { homecoming d.source.fisheye.y; }) .attr("x2", function(d) { homecoming d.target.fisheye.x; }) .attr("y2", function(d) { homecoming d.target.fisheye.y; }); });

note have applied proper scales graph.x , graph.y transform attribute , 15 * graph.nodesizefactor radius of circles (instead of 4.5).

working demo: http://jsfiddle.net/90u4sjzm/23/

javascript graphics d3.js fisheye

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -