Strange behavior of the Fisheye Distortion plugin

Hi, I would like to use the Fisheye Distortion plugin for my force-oriented graph in d3.js, but when I want to apply this plugin, the graph behavior is weird. I am new to d3.js and am not very good at computer graphics.

full sample in jsfiddle

var fisheye = d3.fisheye.circular()
                        .radius(200)
                        .distortion(2);

    // graph - variable which 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) { return d.fisheye.x; })
                                .attr("cy", function(d) { return d.fisheye.y; })
                                .attr("r", function(d) { return d.fisheye.z * 4.5; });


    d3.select("svg").selectAll("line").attr("x1", function(d) { return d.source.fisheye.x; })
                                .attr("y1", function(d) { return d.source.fisheye.y; })
                                .attr("x2", function(d) { return d.target.fisheye.x; })
                                .attr("y2", function(d) { return d.target.fisheye.y; });   
                    });

Strange behavior. I mean that the nodes of the graph disappear (hidden) after the mouse action.

enter image description here

+4
source share
1 answer

, cx cy , nodeElements, transform ed .

, :

graph.svg.on("mousemove", function() {
    fisheye.focus(d3.mouse(this));

    // Change transform on the .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) { return "translate(" + d.fisheye.x + "," + d.fisheye.y + ")"; })
    // Now change the 'r'adius on the circles within
    // One can also scale the font of the text inside nodeElements here
    .select("circle")
    .attr("r", function(d) { return 15 * graph.nodeSizeFactor * d.fisheye.z; });


    d3.select("svg").selectAll("line")
    .attr("x1", function(d) { return d.source.fisheye.x; })
    .attr("y1", function(d) { return d.source.fisheye.y; })
    .attr("x2", function(d) { return d.target.fisheye.x; })
    .attr("y2", function(d) { return d.target.fisheye.y; });   
});

, graph.x graph.y transform 15 * graph.nodeSizeFactor ( 4.5).

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

+3

All Articles