-
Notifications
You must be signed in to change notification settings - Fork 1
/
rrnatagger.html
executable file
·232 lines (197 loc) · 7.4 KB
/
rrnatagger.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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<script type="text/javascript" src="d3.js"></script>
<title></title>
</head>
<body>
<style type="text/css">
.title{
font: 20px Verdana; font-weight: bold;
}
.text1{
font: 10px Verdana; font-weight: normal; color: blue;
}
.node {
//stroke: #fff;
//stroke-width: 1.5px;
stroke: #333;
stroke-width: 1.5px;
}
.link {
stroke: black;
stroke-width: 1px;
stroke-opacity: 1;
fill:none;
}
text {
font: 10px sans-serif;
pointer-events: none;
text-shadow: 0 1px 0 #fff, 1px 0 0 #fff, 0 -1px 0 #fff, -1px 0 0 #fff;
}
div.tooltip {
position: absolute; text-align: center; width: 120px;
height: 100px; padding: 2px; font: 12px sans-serif;
background: lightsteelblue; border: 0px; border-radius: 8px;
pointer-events: none;
}
</style>
<p class="title">rRNATagger pipeline - for 16S/18S/ITS amplicons</p>
<p class="text1">By Julien Tremblay - jtremblay514@gmail.com</p>
<p class="text1">Version 0.1</p>
<script type="text/javascript">
//Width and height
var w = 1700;
var h = 800;
var radius = 6;
var dataset;
var nodes = [];
var links = [];
//Create SVG element
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h)
var div = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
/*
svg.append("rect")
.attr("width", "100%")
.attr("height", "100%")
.attr("fill", "#004C99");
*/
d3.json("./pipeline.json", function(error, json) {
if (error) return console.warn(error);
dataset = json;
console.log(json)
//visualizeit();
update();
});
function update() {
//Initialize a default force layout, using the nodes and edges in dataset
var force = d3.layout.force()
.nodes(dataset.nodes)
.links(dataset.links)
.size([w, h])
.linkDistance(30)
.charge(-300)
.start();
//var colors = d3.scale.category10();
var color = d3.scale.category20();
// Per-type markers (i.e. marker=arrow, as they don't inherit styles.
svg.append("defs").selectAll("marker")
.data(["next"])
.enter().append("marker")
.attr("id", function(d) { return d; })
.attr("viewBox", "0 -5 10 10")
.attr("refX", 15)
.attr("refY", -1.5)
.attr("markerWidth", 6)
.attr("markerHeight", 6)
.attr("orient", "auto")
.append("path")
.attr("d", "M0, -5L10,0L0,5");
//Create edges as lines
edges = svg.selectAll(".link")
.data(dataset.links)
.enter()
.append("path")
.attr("marker-end", function(d) { return "url(#next)"; })
.attr("class", "link");
//.style("stroke", "#ccc");
//.style("stroke-width", 1);
//Create nodes as circles
nodes = svg.selectAll(".node")
.data(dataset.nodes)
.enter()
.append("circle")
.attr('r', function(d) { if(d.value == 1){ return 5; }else{ return d.value; } })
.attr("class", "node")
.attr("group_name", function(d) { return d.group; })
.attr("selected", function(d){ return "false"; })
.style("fill", function(d) { return color(d.group); })
.on("click", click)
.call(force.drag);
nodes.on("mouseover", function(d) {
console.log(d);
div.transition()
.duration(200)
.style("opacity", .9)
//div .html(formatTime(d.date) + "<br/>" + d.close)
div.html("<br>" + d.desc + "<br>")
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
div.transition()
.duration(500)
.style("opacity", 0);
});
// Append the labels to each group
var text = svg.selectAll("text")
.data(force.nodes())
.enter().append("text")
.attr("x", 8)
.attr("y", ".31em")
.text(function (d) {
return d.name;
});
//Every time the simulation "ticks", this will be called
force.on("tick", function () {
edges.attr("d", linkArc);
//nodes
//nodes.attr("cx", function (d) {return d.x; })
//.attr("cy", function (d) { return d.y; });
//nodes to stay inside canvas
nodes.attr("cx", function(d) { return d.x = Math.max(radius, Math.min(w - radius, d.x)); })
.attr("cy", function(d) { return d.y = Math.max(radius, Math.min(h - radius, d.y)); });
text.attr("transform", transform);
});
function click(d) {
if (!d3.event.defaultPrevented) {
var curr_selection = d3.selectAll("circle[group_name=" + d.group + "]")
var curr_group = curr_selection.transition()
.duration(700)
.ease("bounce")
.attr({
r: function(d) {
currRadius = d3.select(this).attr("r");
if(d3.select(this).attr('selected') == "false"){
console.log("was selected: " + d3.select(this).attr('selected'))
console.log("currRadius: " + currRadius)
return (currRadius * 2);
}else{
//d3.select(this).attr('selected') = "true";
console.log("was not selected: " + d3.select(this).attr('selected'))
console.log("currRadius: " + currRadius)
return (currRadius / 2);
}
},
selected: function(d){
if(d3.select(this).attr('selected') == "false"){
return "true";
}else{
return "false";
}
}
})
console.log(curr_group)
console.log(new_selection)
//var curr_nodes = node
}
}
function linkArc(d) {
var dx = d.target.x - d.source.x;
var dy = d.target.y - d.source.y;
var dr = Math.sqrt(dx * dx + dy * dy);
return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y;
}
function transform(d) {
return "translate(" + d.x + "," + d.y + ")";
}
}
</script>
</body>
</html>