SoftTimur

test.xhtml

Nov 28th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
  3. <head>
  4. <style>
  5. .link {
  6. fill: none;
  7. stroke: #666;
  8. stroke-width: 1.5px;
  9. }
  10. </style>
  11. <script src="//d3js.org/d3.v3.min.js"></script>
  12. </head>
  13. <body>
  14. <div class="external-data">
  15. </div>
  16.  
  17. <script>
  18.  
  19. // http://blog.thomsonreuters.com/index.php/mobile-patent-suits-graphic-of-the-day/
  20. var links = [
  21. {source: "file1", target: "file2", type: "suit", shape: "rect"},
  22. {source: "file1", target: "file3", type: "suit", shape: "rect"}
  23. ];
  24.  
  25. var nodes = {};
  26.  
  27. // Compute the distinct nodes from the links.
  28. links.forEach(function(link) {
  29. link.source = nodes[link.source] || (nodes[link.source] = {name: link.source, shape: link.shape});
  30. link.target = nodes[link.target] || (nodes[link.target] = {name: link.target, shape: link.shape});
  31. });
  32.  
  33. var width = 960,
  34. height = 250;
  35.  
  36. var force = d3.layout.force()
  37. .nodes(d3.values(nodes))
  38. .links(links)
  39. .size([width, height])
  40. .linkDistance(150)
  41. .charge(-300)
  42. .on("tick", tick)
  43. .start();
  44.  
  45. var svg = d3.select(".external-data").append("svg")
  46. .attr("width", width)
  47. .attr("height", height);
  48.  
  49. // Per-type markers, as they don't inherit styles.
  50. svg.append("defs").selectAll("marker")
  51. .data(["suit"])
  52. .enter().append("marker")
  53. .attr("id", function(d) { return d; })
  54. .attr("viewBox", "0 -5 10 10")
  55. .attr("refX", 15)
  56. .attr("refY", -1.5)
  57. .attr("markerWidth", 6)
  58. .attr("markerHeight", 6)
  59. .attr("orient", "auto")
  60. .append("path")
  61. .attr("d", "M0,-5L10,0L0,5");
  62.  
  63. var path = svg.append("g").selectAll("path")
  64. .data(force.links())
  65. .enter().append("path")
  66. .attr("class", function(d) { return "link " + d.type; })
  67. .attr("marker-end", function(d) { return "url(#" + d.type + ")"; });
  68.  
  69. var circlesOrRects = svg.append("g").selectAll(".foo")
  70. .data(force.nodes())
  71. .enter()
  72. .append("path")
  73. .attr("d", d3.svg.symbol().size(200)
  74. .type(function(d) { return d.shape == "rect" ? "circle" : "square"; }))
  75. .attr("fill", function(d){return d.shape == "rect" ? "blue" : "red"})
  76. .call(force.drag);
  77.  
  78. var text = svg.append("g").selectAll("text")
  79. .data(force.nodes())
  80. .enter().append("text")
  81. .attr("x", 8)
  82. .attr("y", ".31em")
  83. .text(function(d) { return d.name; });
  84.  
  85. // Use elliptical arc path segments to doubly-encode directionality.
  86. function tick() {
  87. path.attr("d", linkArc);
  88. circlesOrRects.attr("transform", transform)
  89. text.attr("transform", transform);
  90. }
  91.  
  92. function linkArc(d) {
  93. var dx = d.target.x - d.source.x,
  94. dy = d.target.y - d.source.y,
  95. dr = 0;
  96. return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y;
  97. }
  98.  
  99. function transform(d) {
  100. return "translate(" + d.x + "," + d.y + ")";
  101. }
  102. </script>
  103.  
  104. </body>
  105. </html>
Add Comment
Please, Sign In to add comment