1 <%#= render :partial => 'nav' %>
2 <table class="table table-bordered">
11 <% content_for :head do %>
12 <%= javascript_include_tag '/d3.v3.min.js' %>
14 <style type="text/css">
22 path.link.derived_from {
24 stroke-dasharray: 0,4 1;
33 stroke-dasharray: 0,4 1;
47 font: 12px sans-serif;
53 font: 12px sans-serif;
66 <% content_for :js do %>
70 var links = <%= raw d3ify_links(@links).to_json %>;
74 // Compute the distinct nodes from the links.
75 links.forEach(function(link) {
76 link.source = nodes[link.source] || (nodes[link.source] = {name: link.source});
77 link.target = nodes[link.target] || (nodes[link.target] = {name: link.target});
80 var fill_for = {'ldvyl': 'green',
83 jQuery.each(nodes, function(i, node) {
84 var m = node.name.match(/-([a-z0-9]{5})-/)
86 node.fill = fill_for[m[1]] || '#ccc';
87 else if (node.name.match(/^[0-9a-f]{32}/))
88 node.fill = fill_for['4zz18'];
96 var force = d3.layout.force()
97 .nodes(d3.values(nodes))
105 var svg = d3.select("td.d3").append("svg:svg")
109 // Per-type markers, as they don't inherit styles.
110 svg.append("svg:defs").selectAll("marker")
111 .data(["member_of", "owner", "derived_from"])
112 .enter().append("svg:marker")
114 .attr("viewBox", "0 -5 10 10")
117 .attr("markerWidth", 6)
118 .attr("markerHeight", 6)
119 .attr("orient", "auto")
121 .attr("d", "M0,-5L10,0L0,5");
123 var path = svg.append("svg:g").selectAll("path")
125 .enter().append("svg:path")
126 .attr("class", function(d) { return "link " + d.type; })
127 .attr("marker-end", function(d) { return "url(#" + d.type + ")"; });
129 var circle = svg.append("svg:g").selectAll("circle")
131 .enter().append("svg:circle")
133 .style("fill", function(d) { return d.fill; })
136 var text = svg.append("svg:g").selectAll("g")
138 .enter().append("svg:g");
140 // A copy of the text with a thick white stroke for legibility.
141 text.append("svg:text")
144 .attr("class", "shadow")
145 .text(function(d) { return d.name.replace(/^([0-9a-z]{5}-){2}/,''); });
147 text.append("svg:text")
150 .text(function(d) { return d.name.replace(/^([0-9a-z]{5}-){2}/,''); });
152 var edgetext = svg.append("svg:g").selectAll("g")
154 .enter().append("svg:g");
160 .text(function(d) { return d.type; });
162 // Use elliptical arc path segments to doubly-encode directionality.
164 path.attr("d", function(d) {
165 var dx = d.target.x - d.source.x,
166 dy = d.target.y - d.source.y,
167 // dr = Math.sqrt(dx * dx + dy * dy);
169 return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y;
172 circle.attr("transform", function(d) {
173 return "translate(" + d.x + "," + d.y + ")";
176 text.attr("transform", function(d) {
177 return "translate(" + d.x + "," + d.y + ")";
180 edgetext.attr("transform", function(d) {
181 return "translate(" +
182 (d.source.x + d.target.x)/2 + "," +
183 (d.source.y + d.target.y)/2 +
185 (Math.atan2(d.target.y - d.source.y, d.target.x - d.source.x) * 180 / Math.PI) +