Guest User

Untitled

a guest
Oct 18th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. var graph = {
  2. nodes: [
  3. <% nodes.forEach(function(a){ %>
  4. {category: "<%= a.properties.Name %>"},
  5. <% }); %>
  6. ],
  7. links: [
  8. <% edges.forEach(function(a){ %>
  9. {"source": <%= a.source %>, "target": <%= a.target %>},
  10. <% }); %>
  11. ]
  12. }
  13.  
  14. var graph = {
  15. nodes: [
  16. {Name: "b"},
  17. {Name: "c"},
  18. {Name: "c"},
  19. {Name: "c"},
  20. {Name: "b"},
  21. {Name: "b"},
  22. {Name: "c"},
  23. {Name: "c"},
  24. {Name: "c"},
  25. {Name: "b"},
  26. {Name: "c"},
  27. {Name: "c"},
  28. {Name: "d"},
  29. {Name: "d"},
  30. {Name: "a"},
  31. {Name: "c"}
  32. ],
  33. links: [
  34. {source: 8, target: 3},
  35. {source: 3, target: 5},
  36. {source: 3, target: 6},
  37. {source: 3, target: 7},
  38. {source: 3, target: 11},
  39. {source: 3, target: 12},
  40. {source: 8, target: 0},
  41. {source: 0, target: 13},
  42. {source: 0, target: 14},
  43. {source: 8, target: 9},
  44. {source: 9, target: 17},
  45. {source: 9, target: 18},
  46. {source: 14,target: 15},
  47. {source: 14,target: 16},
  48. {source: 8, target: 10}
  49. ]
  50. }
  51.  
  52. var w = 800;
  53. var h = 400;
  54.  
  55. var svg = d3.select("body")
  56. .append("svg")
  57. .attr("width", w)
  58. .attr("height", h)
  59.  
  60. var force = d3.forceSimulation(graph.nodes)
  61. .force("charge", d3.forceManyBody())
  62. .force("link", d3.forceLink(graph.edges))
  63. .force("center", d3.forceCenter().x(w/1).y(h/1))
  64.  
  65. var edges = svg.selectAll("line")
  66. .data(graph.edges)
  67. .enter()
  68. .append("line")
  69. .style("stroke", "#ccc")
  70. .style("stroke-width", 1)
  71.  
  72.  
  73. var nodes = svg.selectAll("circle")
  74. .data(graph.nodes)
  75. .enter()
  76. .append("circle")
  77. .attr("r", 10)
  78.  
  79.  
  80. nodes.append("title")
  81. .text(function(d) {
  82. return d.name
  83. })
  84.  
  85. force.on("tick", function() {
  86. edges.attr("x1", function(d) { return d.source.x; })
  87. .attr("y1", function(d) { return d.source.y; })
  88. .attr("x2", function(d) { return d.target.x; })
  89. .attr("y2", function(d) { return d.target.y; })
  90. nodes.attr("cx", function(d) { return d.x; })
  91. .attr("cy", function(d) { return d.y; })
  92. })
  93.  
  94. var graph = {
  95. nodes: [
  96. { name: "Adam" },
  97. { name: "Bob" },
  98. { name: "Carrie" },
  99. { name: "Donovan" },
  100. { name: "Edward" },
  101. { name: "Felicity" },
  102. { name: "George" },
  103. { name: "Hannah" },
  104. { name: "Iris" },
  105. { name: "Jerry" }
  106. ],
  107. edges: [
  108. { source: 0, target: 1 },
  109. { source: 0, target: 2 },
  110. { source: 0, target: 3 },
  111. { source: 0, target: 4 },
  112. { source: 1, target: 5 },
  113. { source: 2, target: 5 },
  114. { source: 2, target: 5 },
  115. { source: 3, target: 4 },
  116. { source: 5, target: 8 },
  117. { source: 5, target: 9 },
  118. { source: 6, target: 7 },
  119. { source: 7, target: 8 },
  120. { source: 8, target: 9 }
  121. ]
  122. }
Add Comment
Please, Sign In to add comment