-
Notifications
You must be signed in to change notification settings - Fork 2
/
call_dependency_wheel.html
188 lines (163 loc) · 5 KB
/
call_dependency_wheel.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us" prefix="og: http://ogp.me/ns#">
<!-- Use the Source, Luke -->
<head>
<title>DependencyWheel: An Interactive Visualization Of Package Dependencies</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<style>
#chart_placeholder {
text-align: center;
margin-bottom: 20px;
}
.dependencyWheel {
font: 20px sans-serif;
}
</style>
</head>
<body>
<div class="container">
<div id="chart_placeholder"></div>
</div>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script>
d3.chart = d3.chart || {};
d3.chart.dependencyWheel = function(options) {
var width = 1500;
var margin = 550;
var padding = 0.02;
function chart(selection) {
selection.each(function(data) {
var matrix = data.matrix;
var packageNames = data.packageNames;
var radius = width / 2 - margin;
// create the layout
var chord = d3.layout.chord()
.padding(padding)
.sortSubgroups(d3.descending);
// Select the svg element, if it exists.
var svg = d3.select(this).selectAll("svg").data([data]);
// Otherwise, create the skeletal chart.
var gEnter = svg.enter().append("svg:svg")
.attr("width", width)
.attr("height", width)
.attr("class", "dependencyWheel")
.append("g")
.attr("transform", "translate(" + (width / 2) + "," + (width / 2) + ") ");
var arc = d3.svg.arc()
.innerRadius(radius)
.outerRadius(radius + 20);
var fill = function(d) {
if (d.index === 0) return '#ccc';
var str = packageNames[d.index].toLowerCase();
var n = str.length;
var total=0;
for(var j=0;j<n;j++){
total = total +((parseInt(str.charCodeAt(j)-97)/26));
}
total=total/n;
return "hsl(" + parseInt(total* 360, 10) + ",90%,70%) ";
};
// Returns an event handler for fading a given chord group.
var fade = function(opacity) {
return function(g, i) {
svg.selectAll(".chord")
.filter(function(d) {
return d.source.index != i && d.target.index != i;
})
.transition()
.style("opacity", opacity);
var groups = [];
svg.selectAll(".chord")
.filter(function(d) {
if (d.source.index == i) {
groups.push(d.target.index);
}
if (d.target.index == i) {
groups.push(d.source.index);
}
});
groups.push(i);
var length = groups.length;
svg.selectAll('.group')
.filter(function(d) {
for (var i = 0; i < length; i++) {
if (groups[i] == d.index) return false;
}
return true;
})
.transition()
.style("opacity", opacity);
};
};
chord.matrix(matrix);
var rootGroup = chord.groups()[0];
var rotation = -(rootGroup.endAngle - rootGroup.startAngle) / 2 * (180 / Math.PI);
var g = gEnter.selectAll("g.group")
.data(chord.groups)
.enter().append("svg:g")
.attr("class", "group")
.attr("transform", function(d) {
return "rotate(" + rotation + ") ";
});
g.append("svg:path")
.style("fill", fill)
.style("stroke", fill)
.attr("d", arc)
.style("cursor", "pointer")
.on("mouseover", fade(0.1))
.on("mouseout", fade(1));
g.append("svg:text")
.each(function(d) { d.angle = (d.startAngle + d.endAngle) / 2; })
.attr("dy", ".35em")
.attr("text-anchor", function(d) { return d.angle > Math.PI ? "end" : null; })
.attr("transform", function(d) {
return "rotate(" + (d.angle * 180 / Math.PI - 90) + ") " +
"translate(" + (radius + 26) + ") " +
(d.angle > Math.PI ? "rotate(180) " : "");
})
.style("cursor", "pointer")
.text(function(d) { return packageNames[d.index]; })
.on("mouseover", fade(0.1))
.on("mouseout", fade(1));
gEnter.selectAll("path.chord")
.data(chord.chords)
.enter().append("svg:path")
.attr("class", "chord")
.style("stroke", function(d) { return d3.rgb(fill(d.source)).darker(); })
.style("fill", function(d) { return fill(d.source); })
.attr("d", d3.svg.chord().radius(radius))
.attr("transform", function(d) {
return "rotate(" + rotation + ") ";
})
.style("opacity", 1);
});
}
chart.width = function(value) {
if (!arguments.length) return width;
width = value;
return chart;
};
chart.margin = function(value) {
if (!arguments.length) return margin;
margin = value;
return chart;
};
chart.padding = function(value) {
if (!arguments.length) return padding;
padding = value;
return chart;
};
return chart;
};
var chart = d3.chart.dependencyWheel();
var data = {
packageNames: ['std_library','y','x','Concurrency','lambda_function','operator new','main'],
matrix : [[1,1,1,1,1,1,0],[1,0,0,0,0,0,0],[1,0,0,0,0,0,0],[1,0,0,1,1,1,0],[1,0,0,1,1,1,0],[0,0,0,0,0,0,0],[1,1,1,0,0,0,0]]
};
d3.select('#chart_placeholder')
.datum(data)
.call(chart);
</script>
</body>
</html>