1 <!-- Copyright (C) The Arvados Authors. All rights reserved.
3 SPDX-License-Identifier: AGPL-3.0 -->
6 <!-- from http://bl.ocks.org/1153292 -->
9 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
10 <title>Object graph example</title>
11 <script src="d3.v3.min.js"></script>
12 <style type="text/css">
26 stroke-dasharray: 0,4 1;
35 stroke-dasharray: 0,4 1;
49 font: 12px sans-serif;
55 font: 12px sans-serif;
68 <script type="text/javascript">
71 {source: "user: customer", target: "project: customer_project", type: "can_read"},
72 {source: "user: import robot", target: "project: customer_project", type: "can_read"},
73 {source: "user: pipeline robot", target: "project: customer_project", type: "can_read"},
74 {source: "user: uploader", target: "collection: w3anr2hk2wgfpuo", type: "created"},
75 {source: "user: uploader", target: "project: customer_project", type: "created"},
76 {source: "collection: w3anr2hk2wgfpuo", target: "project: customer_project", type: "member_of"}
81 // Compute the distinct nodes from the links.
82 links.forEach(function(link) {
83 link.source = nodes[link.source] || (nodes[link.source] = {name: link.source});
84 link.target = nodes[link.target] || (nodes[link.target] = {name: link.target});
90 var force = d3.layout.force()
91 .nodes(d3.values(nodes))
99 var svg = d3.select("body").append("svg:svg")
103 // Per-type markers, as they don't inherit styles.
104 svg.append("svg:defs").selectAll("marker")
105 .data(["created", "member_of", "can_read", "can_write"])
106 .enter().append("svg:marker")
108 .attr("viewBox", "0 -5 10 10")
111 .attr("markerWidth", 6)
112 .attr("markerHeight", 6)
113 .attr("orient", "auto")
115 .attr("d", "M0,-5L10,0L0,5");
117 var path = svg.append("svg:g").selectAll("path")
119 .enter().append("svg:path")
120 .attr("class", function(d) { return "link " + d.type; })
121 .attr("marker-end", function(d) { return "url(#" + d.type + ")"; });
123 var circle = svg.append("svg:g").selectAll("circle")
125 .enter().append("svg:circle")
129 var text = svg.append("svg:g").selectAll("g")
131 .enter().append("svg:g");
133 // A copy of the text with a thick white stroke for legibility.
134 text.append("svg:text")
137 .attr("class", "shadow")
138 .text(function(d) { return d.name; });
140 text.append("svg:text")
143 .text(function(d) { return d.name; });
145 var edgetext = svg.append("svg:g").selectAll("g")
147 .enter().append("svg:g");
153 .text(function(d) { return d.type; });
155 // Use elliptical arc path segments to doubly-encode directionality.
157 path.attr("d", function(d) {
158 var dx = d.target.x - d.source.x,
159 dy = d.target.y - d.source.y,
160 // dr = Math.sqrt(dx * dx + dy * dy);
162 return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y;
165 circle.attr("transform", function(d) {
166 return "translate(" + d.x + "," + d.y + ")";
169 text.attr("transform", function(d) {
170 return "translate(" + d.x + "," + d.y + ")";
173 edgetext.attr("transform", function(d) {
174 return "translate(" +
175 (d.source.x + d.target.x)/2 + "," +
176 (d.source.y + d.target.y)/2 +
178 (Math.atan2(d.target.y - d.source.y, d.target.x - d.source.x) * 180 / Math.PI) +