forked from chrismattmann/tika-similarity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster-d3.html
172 lines (138 loc) · 4.12 KB
/
cluster-d3.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
<!DOCTYPE html>
<meta charset="utf-8">
<title>Flare Dendrogram</title>
<style>
.node circle {
fill: #fff;
stroke: steelblue;
stroke-width: 1.5px;
}
.node circle img{
}
.node {
font: 10px sans-serif;
}
.link {
fill: none;
stroke: #ccc;
stroke-width: 1.5px;
}
div.tooltip {
position: absolute;
text-align: center;
width: 400px;
height: 400px;
padding: 2px;
font: 12px sans-serif;
background: lightsteelblue;
border: 0px;
border-radius: 8px;
overflow: scroll;
/* pointer-events: none; This line needs to be removed */
}
div.tooltip:before{
content:'';
display:block;
width:0;
height:0;
position:absolute;
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
border-right:30px solid lightsteelblue;
left:-7px;
top:7px;
}
object {
max-height: 80%;
max-width: 80%;
}
p {
height: 40%;
width: 100%;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js"></script>
<script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
clusterJson = d3.json("clusters.json", function(error, root){
var i = 0;
function visit(parent, visitFn, childrenFn) {
if (!parent) return;
visitFn(parent);
var children = childrenFn(parent);
if (children) {
var count = children.length;
for (var i = 0; i < count; i++) {
visit(children[i], visitFn, childrenFn);
}
}
}
visit(root, function(d) {
if(d.children == null)
i++;
}, function(d) {
return d.children && d.children.length > 0 ? d.children : null;
});
var radius = 340+1.4*i;
var cluster = d3.layout.cluster()
.size([360, radius - 120]);
var translateX= radius+200;
var translateY = radius +200;
var diagonal = d3.svg.diagonal.radial()
.projection(function(d) { return [d.y, d.x / 180 * Math.PI]; });
var div = d3.select("body")
.append("div")
.attr("class", "tooltip")
.style("opacity", 0);
var svg = d3.select("body").append("svg")
.attr("width", radius * 2+400)
.attr("height", radius * 2+400)
.append("g")
.attr("transform", "translate(" + translateX + "," + translateY + ")");
var nodes = cluster.nodes(root);
var link = svg.selectAll("path.link")
.data(cluster.links(nodes))
.enter().append("path")
.attr("class", "link")
.attr("d", diagonal);
var node = svg.selectAll("g.node")
.data(nodes)
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; })
node.append("circle")
.attr("id", function(d){ return d.name;})
.attr("class", "node--cluster")
.attr("r", 6)
.on('mouseover',function(d){
div.style("visibility", "visible");
div.transition().duration(200)
.style("opacity", .9);
div.on('mouseover', function(d){
div.style("visibility", "visible");
div.transition().duration(200)
.style("opacity", .9);
});
div.on('mouseout', function(d){
div.style("visibility", "hidden");
div.transition().style('opacity', 0);
});
div .html( d.name.match(/^cluster(\d||\w)+$/)==null && d.name.match(/^group(\d||\w)+$/)==null ? '<h2>' + d.name +'</h2> <object data = "'+d.path+'"></object><p>'+d.metadata+'</p>' : '<h2>this is a cluster node </h2>')
.style("left", (d3.event.pageX) + "px" )
.style("top", (d3.event.pageY) + "px");
})
.on('mouseout', function(d){
div.transition().style('opacity', 0);
div.style("visibility", "hidden");
});
node.append("text")
.attr("dy", ".31em")
.attr("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
.attr("transform", function(d) { return d.x < 180 ? "translate(8)" : "rotate(180)translate(-8)"; })
.text(function(d) { return d.name; });
d3.select(self.frameElement).style("height", radius * 2 + "px");
});
</script>
</body>