MCPcopy Index your code
hub / github.com/csev/py4e / loadData

Function loadData

code/pagerank/force.js:25–69  ·  view source on GitHub ↗
(json)

Source from the content-addressed store, hash-verified

23 .attr("height", height);
24
25function loadData(json) {
26 force
27 .nodes(json.nodes)
28 .links(json.links);
29
30 var k = Math.sqrt(json.nodes.length / (width * height));
31
32 force
33 .charge(-10 / k)
34 .gravity(100 * k)
35 .start();
36
37 var link = svg.selectAll("line.link")
38 .data(json.links)
39 .enter().append("line")
40 .attr("class", "link")
41 .style("stroke-width", function(d) { return Math.sqrt(d.value); });
42
43 var node = svg.selectAll("circle.node")
44 .data(json.nodes)
45 .enter().append("circle")
46 .attr("class", "node")
47 .attr("r", function(d) { return getrank(d.rank); } )
48 .style("fill", function(d) { return getcolor(d.rank); })
49 .on("dblclick",function(d) {
50 if ( confirm('Do you want to open '+d.url) )
51 window.open(d.url,'_new','');
52 d3.event.stopPropagation();
53 })
54 .call(force.drag);
55
56 node.append("title")
57 .text(function(d) { return d.url; });
58
59 force.on("tick", function() {
60 link.attr("x1", function(d) { return d.source.x; })
61 .attr("y1", function(d) { return d.source.y; })
62 .attr("x2", function(d) { return d.target.x; })
63 .attr("y2", function(d) { return d.target.y; });
64
65 node.attr("cx", function(d) { return d.x; })
66 .attr("cy", function(d) { return d.y; });
67 });
68
69}
70loadData(spiderJson);

Callers 1

force.jsFile · 0.70

Calls 7

openMethod · 0.80
textMethod · 0.80
getrankFunction · 0.70
getcolorFunction · 0.70
startMethod · 0.45
appendMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected