force-layout

How do I capture keystroke events in D3 force layout?

╄→尐↘猪︶ㄣ 提交于 2019-11-29 02:38:47
问题 I would like to respond to keystroke events directed at nodes in my force layout. I've tried adding all the variants of "keystroke", "keypress", "keyup", "keydown" that I could think of, but none of them is firing. My mouse events fire just fine. I couldn't find any keystroke events in the d3 source.... is there a way to capture key strokes? nodes.enter().append("circle") .on("click", function(d) { return d.clickHandler(self); }) .on("mouseover", function(d) { return d.mouseOverHandler(self);

Curved line on d3 force directed tree

故事扮演 提交于 2019-11-28 23:29:58
New to d3 and trying to develop a force directed tree into which we can plug varioss dataset. I've managed to get the basic idea up and running but would like to make the links curved so I can deal with multiple links. I've looked at http://bl.ocks.org/1153292 and I'm just not getting it. The nearest I get is it all working with no path visible. This is my code for straight lines, I'd appreciate some help if you've got the time Thanks: //Sets up the svg that holds the data structure and puts it in the div called mapBox var svg = d3.select("div#mapBox.theMap").append("svg") .attr("width",

D3.js force directed graph, reduce edge crossings by making edges repel each other

…衆ロ難τιáo~ 提交于 2019-11-28 21:55:59
问题 So i have a page already which draws a force directed graph, like the one shown here. And that works fine. I'm using the JS from here, with a few tweaks to spread out the nodes slightly nicer. These are more or less the only differences: d3.json("force.json", function(json) { var force = d3.layout.force() .gravity(0.1) .charge(-2000) .linkDistance(1) .linkStrength(0.1) .nodes(json.nodes) .links(json.links) .size([w, h]) .start(); Where reducing the link strength seems to make the links more

Configure fixed-layout static graph in d3.js

梦想与她 提交于 2019-11-28 17:06:04
I have a working code example (only the <script type="text/javascript"> part) of a static graph using d3.js as below: /* Create graph data */ var nodes = []; for (var i = 0; i < 13; i++) { var datum = { "value": i }; nodes.push(datum); } var links = [{"source": 0, "target": 1}, {"source": 1, "target": 2}, {"source": 2, "target": 0}, {"source": 1, "target": 3}, {"source": 3, "target": 2}, {"source": 3, "target": 4}, {"source": 4, "target": 5}, {"source": 5, "target": 6}, {"source": 5, "target": 7}, {"source": 6, "target": 7}, {"source": 6, "target": 8}, {"source": 7, "target": 8}, {"source": 9,

How to make force layout graph in D3.js responsive to screen/browser size

血红的双手。 提交于 2019-11-28 15:25:34
I have a graph using force layout, but it has a fixed width w and height h : var svg = d3.select("#viz").append("svg") .attr("id", "playgraph") .attr("width", w) .attr("height", h) var force = d3.layout.force() .nodes(nodes) .links(links) .charge(-1600) .linkDistance(45) .size([w, h]); which results in a svg graph that does not scale or down despite of changes in screen or browser window size. In order to make it responsive (i.e. automatically resizes itself), I tried using viewBox and preserveAspectRatio attributes: var svg = d3.select("#viz").append("svg") .attr("id", "playgraph") .attr(

D3 Force Layout Graph - Self linking node

那年仲夏 提交于 2019-11-28 12:08:14
Using a force directed graph, how do you get a link to actually show up when the target and source are the same node. So basically just a nice little loop indicating that such an edge exists. There are two D3 examples that I already used or tried to use: I'm using http://bl.ocks.org/d3noob/5155181 to show direction, and the little endpoint arrow will show up pointing at itself, but no link line. http://bl.ocks.org/GerHobbelt/3616279 does does allow for self referencing and I even sort of got it to work with my data, but it is crazy complicated. mes5k The trick is to draw the self link as a

Introducing Arrow(directed), in Force Directed Graph d3

懵懂的女人 提交于 2019-11-28 09:20:38
I am using the force-directed graph in the sample here - http://bl.ocks.org/mbostock/4062045 But since my data is directed, I need the links in the graph to be represented as arrow connections. Maybe like in, http://bl.ocks.org/d3noob/5141278 . Can someone please suggest the alterations or additions that create a directed graph as in http://bl.ocks.org/mbostock/4062045 I am new to D3, and I couldn't find a solution, maybe its trivial, but a little help is appreciated. Merging these two examples is straightforward, and I created a JSFiddle to demo . First, add the definition of the arrow style

D3.js, force-graph, cannot display text/label of nodes

自作多情 提交于 2019-11-28 07:41:08
问题 I cannot display labels of nodes using a force-layout in d3.js. I'm trying with this example http://d3js.org/d3.v3.min.js I updated that code only adding zoom, like this: var svg = d3.select("body").append("svg").attr("width", width).attr("height", height).append('svg:g').call(d3.behavior.zoom().on("zoom", redraw)); function redraw() { console.log("here", d3.event.translate, d3.event.scale); svg.attr("transform", "translate(" + d3.event.translate + ")" + " scale(" + d3.event.scale + ")");

How to disable animation in a force-directed graph? [closed]

前提是你 提交于 2019-11-28 07:14:24
问题 Is there any way of disabling the animation in a D3 force-directed graph? I am working with this example: https://bl.ocks.org/mbostock/4062045 I want to render the graph without the initial animation, that is, showing all the nodes and links in their final positions. 回答1: EDIT This method simply hides the animation part of the simulation. Please see Gerardo Furtado's answer which performs the simulation without drawing the intermediary results, meaning that the user doesn't have to wait

Uncaught TypeError: Cannot call method 'push' of undefined (d3 force layout)

爷,独闯天下 提交于 2019-11-28 06:23:16
问题 I can't figure out why I'm getting this error for the life of me (using a force layout). It started when I switched over to reading my nodes from a json file. If I uncomment the lines below it doesn't throw an error. If I leave as is, I get "Cannot call method 'push' of undefined". I'm not sure what the issue is. Am I missing anything? <html> <script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script> <script> d3.json("http://katejustin.com/autosys1.json", function(data