2 <!-- from http://bl.ocks.org/1153292 -->
5 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
6 <title>Object graph example</title>
7 <script src="d3.v3.min.js"></script>
8 <style type="text/css">
22 stroke-dasharray: 0,4 1;
31 stroke-dasharray: 0,4 1;
45 font: 12px sans-serif;
51 font: 12px sans-serif;
64 <script type="text/javascript">
67 {source: "user: customer", target: "project: customer_project", type: "can_read"},
68 {source: "user: import robot", target: "project: customer_project", type: "can_read"},
69 {source: "user: pipeline robot", target: "project: customer_project", type: "can_read"},
70 {source: "user: uploader", target: "collection: w3anr2hk2wgfpuo", type: "created"},
71 {source: "user: uploader", target: "project: customer_project", type: "created"},
72 {source: "collection: w3anr2hk2wgfpuo", target: "project: customer_project", type: "member_of"}
77 // Compute the distinct nodes from the links.
78 links.forEach(function(link) {
79 link.source = nodes[link.source] || (nodes[link.source] = {name: link.source});
80 link.target = nodes[link.target] || (nodes[link.target] = {name: link.target});
86 var force = d3.layout.force()
87 .nodes(d3.values(nodes))
95 var svg = d3.select("body").append("svg:svg")
99 // Per-type markers, as they don't inherit styles.
100 svg.append("svg:defs").selectAll("marker")
101 .data(["created", "member_of", "can_read", "can_write"])
102 .enter().append("svg:marker")
104 .attr("viewBox", "0 -5 10 10")
107 .attr("markerWidth", 6)
108 .attr("markerHeight", 6)
109 .attr("orient", "auto")
111 .attr("d", "M0,-5L10,0L0,5");
113 var path = svg.append("svg:g").selectAll("path")
115 .enter().append("svg:path")
116 .attr("class", function(d) { return "link " + d.type; })
117 .attr("marker-end", function(d) { return "url(#" + d.type + ")"; });
119 var circle = svg.append("svg:g").selectAll("circle")
121 .enter().append("svg:circle")
125 var text = svg.append("svg:g").selectAll("g")
127 .enter().append("svg:g");
129 // A copy of the text with a thick white stroke for legibility.
130 text.append("svg:text")
133 .attr("class", "shadow")
134 .text(function(d) { return d.name; });
136 text.append("svg:text")
139 .text(function(d) { return d.name; });
141 var edgetext = svg.append("svg:g").selectAll("g")
143 .enter().append("svg:g");
149 .text(function(d) { return d.type; });
151 // Use elliptical arc path segments to doubly-encode directionality.
153 path.attr("d", function(d) {
154 var dx = d.target.x - d.source.x,
155 dy = d.target.y - d.source.y,
156 // dr = Math.sqrt(dx * dx + dy * dy);
158 return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y;
161 circle.attr("transform", function(d) {
162 return "translate(" + d.x + "," + d.y + ")";
165 text.attr("transform", function(d) {
166 return "translate(" + d.x + "," + d.y + ")";
169 edgetext.attr("transform", function(d) {
170 return "translate(" +
171 (d.source.x + d.target.x)/2 + "," +
172 (d.source.y + d.target.y)/2 +
174 (Math.atan2(d.target.y - d.source.y, d.target.x - d.source.x) * 180 / Math.PI) +