javascript - Weird behaviour of Fisheye Distortion plugin -


Hi, I want to use d3.js for my self-directed graph, but When I want to apply this plugin, the graph's behavior is weird. I am new to d3.js and not good in computer graphics.

  var fisheye = d3.fisheye.circular () .radius (200). Disinfection (2); // graph - variable, which is the whole graph graph. Represents the SVG.On ("mousemov", function () {FISHIES FOCUS (D. 3.Mouse (this)); D3 selection ("SVG"). Successful ("circle") .each (function ( D) {d.fisheye = fisheye (d);}) .attr ("cx", function (d) {return d.fisheye.x;}) .attr ("cy", function (d) {return d. RTS ("R", function (D) {Return D. Fishes * 4.5;}); D3. Sealat ("SVG"). All ("line") .attr (" X1 ", function (d) {return d.source.fisheye.x;}) .attr (" y1 ", function (d) {return d.source.fisheye.y;}) .attr (" x2 ", function (D) {returns d.target.fisheye.x;}) .attr ("y2", function (d) {Return d.targ I.fisheye.y;})}}  

Strange behavior I mean that the nodes of the graph disappear after the mouseover action.

Enter image details here

The problem is that you were using code to add cx and cy to the circles, but your circles are actually Node elements were attached inside , which is transform

Changing the shisha code solves the problem:

  graph.svg.on ("mousemove", function () {fisheye focus (d3.mouse (this)); Change selection to .node d3 .select ("svg"). All (".node") .each (function (d) {d.fisheye = fisheye ({x: Graph.x (dx), y: graph .y (dy)}; console.log (d.fisheye, d);}) .attr ("transform", function (d) {return "translation (" + D.fisheye.x + "," + d .fisheye.y + ")";}) // Now replace 'R'Dials inside circles // Here one can also scale the text of the text inside the node elements. Selection ("circle") .attr ("r", function (d) {return 15 * graph.nodeSizeFactor * d.fisheye.z;}); D3.select ("svg"). All ("line") .attr ("x1", function (d) {return d.source.fisheye.x;}) .attr ("y1", function (d) { Return d.source.fisheye.y;}) .attr ("x2", function (d) {returns d.target.fisheye.x;}) .attr ("y2", function (d) {return d.target .fisheye.y;}); });  

Note that I have also implemented graph.x and graph.y for conversion > Attribute and 15 * graph.nodeSizeFactor for the radius of circles (instead of 4.5 ).

Work demo:


Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -