-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
295 lines (256 loc) · 8.38 KB
/
index.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<!DOCTYPE html>
<meta charset="utf-8">
<div id="vis"></div>
<form>
<label><input class='unshard_button' type="checkbox" name="mode" >Show Unsharded Collections</label>
<label><input class='select_size' type='radio' name='mode' value='size' checked>Size</label>
<label><input class='select_size' type='radio' name='mode' value='object'>Objects</label>
</form>
<style>
path {
stroke: #fff;
fill-rule: evenodd;
}
text {
font-family: Arial, sans-serif;
font-size: 12px;
}
</style>
<!--
<script src="d3.v3/d3.v3.min.js"></script>
-->
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 800,
height = width,
radius = width / 2,
x = d3.scale.linear().range([0, 2 * Math.PI]),
y = d3.scale.pow().exponent(1.3).domain([0, 1]).range([0, radius]),
padding = 5,
duration = 1000,
rings = 4;
var div = d3.select("#vis");
var color = d3.scale.category20c();
var vis = div.append("svg")
.attr("width", width + padding * 2)
.attr("height", width + padding * 2)
.append("g")
.attr("transform", "translate(" + [radius + padding, radius + padding] + ")");
var dat = div.append("svg")
.attr("width", 400 + padding * 2)
.attr("height", height + padding * 2)
.append("g")
.attr("transform", "translate(100,50)");
var partition = d3.layout.partition()
.sort(null)
.value(function(d) { return 5 - d.depth; });
var arc = d3.svg.arc()
.startAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x))); })
.endAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))); })
.innerRadius(function(d) { return Math.max(0, y(d.y)); })
.outerRadius(function(d) { return Math.max(0, y(d.y + d.dy)); });
d3.json("output.json", function(json) {
var orig_json = json;
var nodes = partition.nodes(json);
var path = vis.datum(json).selectAll("path")
.data(partition.nodes(json))
.enter().append("path")
.attr("d", arc)
.attr("class", function(d) { return d.depth < rings ? 'branch' : "leaf"+d.parent.parent.name.replace(".","") + d.parent.name; } )
.attr("node", function(d) { return d.depth < rings ? 'branch' : 'leafnode' } )
.style("stroke", "#fff")
.style("fill", function(d) { return color((d.children ? d : d.parent).name); })
.style("fill-rule", "evenodd")
.style("visibility", function(d) { return d.depth < rings ? null : "hidden" } )
.on("click", click)
.each(stash);
var infotextEnter = dat.append("text")
.style("visibility", 'hidden')
.attr("id", "infotext")
infotextEnter.append('tspan')
.text("chunk information:")
infotextEnter.append('tspan')
.attr("id", "infotextdatatitle")
infotextEnter.append('tspan')
.attr('y', '20')
.attr('x', '0')
.attr("id", "infotextdata1")
var text = vis.selectAll("text").data(nodes);
var textEnter = text.enter().append("text")
.style("fill-opacity", 1)
.attr("text-anchor", function(d) {
return x(d.x + d.dx / 2) > Math.PI ? "end" : "start";
})
.attr("dy", ".2em")
.attr("transform", function(d) {
//var multiline = (d.name || "").split(" ").length > 1,
var angle = x(d.x + d.dx / 2) * 180 / Math.PI - 90,
//rotate = angle + (multiline ? -.5 : 0);
rotate = angle -.5;
return "rotate(" + rotate + ")translate(" + (y(d.y) + padding) + ")rotate(" + (angle > 90 ? -180 : 0) + ")";
})
//.on("click", click);
textEnter.append("tspan")
.attr("x", 0)
.attr("class", function(d) { return d.depth < rings ? d._id : d.parent.parent.name.replace(".","")+d.parent.name; } )
.text(function(d) { return d.depth != 0 ? d.name : "" })
//.style("visbiluty", null)
.style("visibility", function(e) {
return e.depth < rings ? null : "hidden";
});
d3.selectAll(".select_size").on("change", change)
d3.selectAll(".unshard_button").on("change", change)
function click(d) {
var curDepth = getDepth(d)
//infotextEnter.style("visibility", "hidden");
if(curDepth>1) {
dat.select('#infotext')
.style('visibility', 'hidden');
}
if(curDepth > 2) {
vis.selectAll('[node="leafnode"]')
.style("visibility", "hidden")
} else if (curDepth <= 2 ) {
//d3.select(this).style("visibility", null );
var superParent = d.parent.name.replace(".","")+d.name
var leafnodes = vis.selectAll(".leaf"+superParent);
leafnodes.style("visibility", null)
var textSpan = text.selectAll('.'+superParent);
textSpan.style("visibility", null);
if (curDepth == 1 ) {
var infTextSpan = dat.select('#infotext');
infTextSpan.style('visibility', null);
infTextSpan.select('#infotextdatatitle')
.text(d.name);
infTextSpan.select("#infotextdata1")
.text(d._id);
}
}
if(d._id) {
path.select()
}
path.transition()
.duration(duration)
.attrTween("d", arcTween(d));
// Somewhat of a hack as we rely on arcTween updating the scales.
text.style("visibility", function(e) {
//return isParentOf(d, e) ? null : d3.select(this).style("visibility");
return curDepth <= 2 ? null : check_visibility(e);
})
.transition()
.duration(duration)
.attrTween("text-anchor", transformTextAnchor )
.attrTween("transform", transformText )
.style("fill-opacity", function(e) { return isParentOf(d, e) ? 1 : 1e-6; })
}
function change() {
var value = function(e) { return select_matrix( e ) }
path
.data(partition.value(value).nodes)
.transition()
.duration(duration)
.attrTween("d", arcTween2);
text.style("visibility", "hidden")
.transition()
.duration(duration)
.attrTween("text-anchor", transformTextAnchor )
.attrTween("transform", transformText )
.each("end", function(e) {
d3.select(this).style("visibility", check_visibility(e) );
})
}
});
function isParentOf(p, c) {
if (p === c) return true;
if (p.children) {
return p.children.some(function(d) {
return isParentOf(d, c);
});
}
return false;
}
// Interpolate the scales!
function arcTween(d) {
var my = maxY(d),
xd = d3.interpolate(x.domain(), [d.x, d.x + d.dx]),
yd = d3.interpolate(y.domain(), [d.y, my]),
yr = d3.interpolate(y.range(), [d.y ? 20 : 0, radius]);
return function(d) {
return function(t) { x.domain(xd(t)); y.domain(yd(t)).range(yr(t)); return arc(d); };
};
}
function arcTween2(a) {
var i = d3.interpolate({x: a.x0, dx: a.dx0}, a);
return function(t) {
var b = i(t);
a.x0 = b.x;
a.dx0 = b.dx;
return arc(b);
};
}
function maxY(d) {
return d.children && d.children.length ? Math.max.apply(Math, d.children.map(maxY)) : d.y + d.dy;
}
function transformText(d) {
//var multiline = (d.name || "").split(" ").length > 1;
return function() {
var angle = x(d.x + d.dx / 2) * 180 / Math.PI - 90,
rotate = angle -.5;
return "rotate(" + rotate + ")translate(" + (y(d.y) + padding) + ")rotate(" + (angle > 90 ? -180 : 0) + ")";
}
}
function transformTextAnchor(d) {
return function() {
return x(d.x + d.dx / 2) > Math.PI ? "end" : "start";
}
}
// Stash the old values for transition.
function stash(d) {
d.x0 = d.x;
d.dx0 = d.dx;
}
function getDepth(d) {
var depth = 0;
if (d.children) {
d.children.forEach(function (e) {
var tmpDepth = getDepth(e)
if (tmpDepth > depth) {
depth = tmpDepth
}
})
}
return 1 + depth
}
function select_matrix(d) {
un = d3.select('.unshard_button').property('checked');
size = d3.selectAll('.select_size').property('checked');
if (un) {
if (size) {
return d.size && d.size > 0 ? d.size : 100;
}
if (!size) {
return d.objects && d.objects > 0 ? d.objects : 1
}
}
if(!un) {
if(size) {
return d.size && d.size > 0 ? d.size : 0;
}
if(!size) {
return d.objects && d.objects > 0 ? d.objects : 0;
}
}
}
function check_visibility(d) {
un = d3.select('.unshard_button').property('checked');
if(un) {
return d.depth < rings ? null : 'hidden'
} else {
return d.children && d.children.length > 0 ? null : 'hidden'
}
}
</script>
<script>
if (top != self) top.location.replace(location);
</script>