-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·378 lines (349 loc) · 16.3 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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Canvas Vizualization</title>
<link href="http://localhost:9876/loadCSS.css" rel="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-latest.js">
</script>
<script src="http://localhost:9876/flot?include=jquery.flot.js">
</script>
<script src="http://localhost:9876/flot?jquery.flot.navigate.js">
</script>
<script src="http://localhost:9876/flot?include=jquery.megaselectlist.js">
</script>
<script src="http://localhost:9876/flot?include=multiselect.js">
</script>
<script src="http://localhost:9876/flot?include=jquery.flot.resize.js">
</script>
<script src="http://localhost:9876/flot?include=jquery.flot.navigate.js">
</script>
</head>
<body>
<h1>Canvas Dotplot</h1>
<div id="placeholder" style="width:700px;height:750px;">
</div>
<br/>
<br/>
<div class="borderedText" id="hoverdata">
<!-- Mouse hovers at
(<span id="x">0</span>, <span id="y">0</span>). <span id="clickdata"></span>
-->
<div class="message">
</div>
<br/>
<div id="flag">
</div>
</div>
<script>
/* $(document).ready(function(){
$("select").custSelectBox({
selectwidth: "auto"
});
});*/
</script>
<div class="select_wrap" class="select_field">
<select name="referenceSelect" id="referenceSelect" style="width:1000px;">
<option value='-1'>Reference Organism</option>
</select>
</div>
<div class="select_wrap">
<select name="querySelect" class="select_field" multiple="multiple" id="querySelect" style="width:1000px;">
<option value='-1'>Query Organisms</option>
</select>
</div>
<!--
<form action="#" method="get" name="form" id="form">
<div class="examples">
<label class="examples">
First example of MultiSelect
</label>
<select name="querySelect" multiple="multiple" id="querySelect" style="width:1000px;" class="arc90_multiselect">
<option value='-1'>Query Organisms</option>
</select>
</div>
</form>
-->
<br clear="all" />
<br/>
<script type="text/javascript">
$(function(){
var refVal = -1;
var queryVals = [];
var queryString = "";
var resultFiles = [];
var data = [];
var alreadyFetched = {};
var placeholder = $("#placeholder");
var options = {
series: {
lines: {
show: false
},
points: {
show: true
},
shadowSize: 0
},
grid: {
hoverable: true,
clickable: true
},
xaxis: {
zoomRange: [0.1, 3000000],
panRange: [0, 3000000]
},
yaxis: {
zoomRange: [0.1, 3000000],
panRange: [-200000, 3000000]
},
zoom: {
interactive: true
},
pan: {
interactive: true
}
};
var plot = $.plot(placeholder, data, options);
$(document).ready(function(){
$.ajax({
url: 'http://localhost:9876/getOrg',
dataType: "html",
jsonpCallback: "_callback",
cache: false,
timeout: 5000,
success: function(data){
$('select').append(data);
/*$("select").custSelectBox({
selectwidth: "auto"
});*/
$("#referenceSelect").change(onReferenceChange);
$("#querySelect").change(onQueryChange);
/*
a$.NO_SELECTION = 'No selection'; // TEXT for 'No selection' when nothing selected
a$.SELECTED = 'Options selected'; // TEXT for 'XX Options selected' when over 1 selected
a$.SELECT_ALL = 'Select All'; // TEXT for 'Select All' for checkboxes
a$.SelectAllMin = 6; // minimum number of options needed to show 'Select All'
a$.WhenToUse = 'class'; // class | multiple | all : for how to make selects become multiselects
a$.msSeparator = '|'; // separator for values (can be multiple characters)
*/
},
error: function(jqXHR, textStatus, errorThrown){
alert('error ' + textStatus + " " + errorThrown);
}
});
});
function onReferenceChange(){
var selected = $("#referenceSelect option:selected");
var output = "";
if (selected.val() != -1) {
output = "You selected " + selected.val();
refVal = selected.val();
if (queryVals.length >= 1) //If there are query values selected already...
{
//Don't allow users to select the same values for reference/query.
for (var i in queryVals) {
//$("#flag").text("Queryval: " + queryVals[i] + "::: Ref:" + refVal + '\n');
if (refVal == queryVals[i]) {
$('#querySelect :selected').each(function(i, selected){
var selectedVal = $(selected).val();
if (selectedVal == refVal) {
var selectedText = $(selected).text();
alert(selectedText + " selected as reference. Removed from query set.");
$(selected).removeAttr("selected");
queryVals.splice(i, 1)
}
});
}
}
//In case the last query element is removed by the above code.
if (queryVals.length >= 1) {
fetchData();
}
}
}
}
function onQueryChange(){
queryVals = [];
$('#querySelect :selected').each(function(i, selected){
var selectedVal = $(selected).val();
if (selectedVal >= 1) //Only accept valid values.
{
if (selectedVal == refVal) {
var selectedText = $(selected).text();
alert(selectedText + " cannot be selected as both reference and query.");
$(selected).removeAttr("selected");
}
else {
queryVals[i] = selectedVal;
var val = queryVals[i];
}
}
});
if (refVal != -1 && queryVals.length >= 1) //If there is a valid reference selected already...
{
fetchData();
}
}
function buildQueryString(){
//$("#flag").text("Running buildQueryString: ");
//$("#flag").append('<br />');
queryString = "?reference=" + refVal;
for (var i in queryVals) {
//$("#flag").append("loop " + i + "val: " + queryVals[i]);
queryString = queryString + "&qry=" + queryVals[i];
}
//$("#flag").append(queryString);
}
function fetchData(){
buildQueryString();
$.ajax({
url: 'http://localhost:9876/fetchData' + queryString,
dataType: "html",
jsonpCallback: "_callback",
cache: false,
timeout: 5000,
success: function(data){
var substring = data.substring(data.indexOf("'") + 1, data.lastIndexOf("'"));
resultFiles = substring.split(",");
clearPlot();
for (var i in resultFiles) {
$.ajax({
url: "http://localhost:9876/getJSON?file=" + resultFiles[i],
method: 'GET',
dataType: 'json',
success: function(data){
sleep(500);
onDataReceived(data);
$("#flag").append("Loaded " + data.label + ".");
$("#flag").append("<br />");
}
});
}
},
error: function(jqXHR, textStatus, errorThrown){
alert('error ' + textStatus + " " + errorThrown);
}
});
}
function sleep(ms){
var dt = new Date();
dt.setTime(dt.getTime() + ms);
while (new Date().getTime() < dt.getTime())
;
}
$("p").click(function(){
$.ajax({
url: 'http://localhost:9876/query',
dataType: "jsonp",
jsonpCallback: "_callback",
cache: false,
timeout: 5000,
success: function(data){
//$("#flag").append(data);
//buildQueryString();
},
error: function(jqXHR, textStatus, errorThrown){
alert('error ' + textStatus + " " + errorThrown);
}
});
});
function clearPlot(){
$("#flag").html("");
$("#clickdata").html("");
data = [];
$.plot(placeholder, data, options);
}
function onDataReceived(series){
//$("#flag").html("Loaded " + series.label + ".<br />");
/*if(!alreadyFetched[series.label]){
alreadyFetched[series.label] = true;
data.push(series);
}*/
data.push(series);
$.plot(placeholder, data, options);
}
function showTooltip(x, y, contents){
$('<div id="tooltip">' + contents + '</div>').css({
position: 'absolute',
display: 'none',
top: y + 5,
left: x + 5,
border: '1px solid #fdd',
padding: '2px',
'background-color': '#fee',
opacity: 0.80
}).appendTo("body").fadeIn(200);
}
var previousPoint = null;
$("#placeholder").bind("plothover", function(event, pos, item){
//$("#x").text(pos.x.toFixed(0));
//$("#y").text(pos.y.toFixed(0));
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
$("#tooltip").remove();
var x = item.datapoint[0].toFixed(0), y = item.datapoint[1].toFixed(0);
showTooltip(item.pageX, item.pageY, item.series.label + ": " + x + ", " + y);
}
}
else {
$("#tooltip").remove();
previousPoint = null;
}
});
$("#placeholder").bind("plotclick", function(event, pos, item){
if (item) {
$("#clickdata").append("<br />");
$("#clickdata").append(item.series.label + ": " + item.datapoint[0] + "," + item.datapoint[1]);
//plot.highlight(item.series, item.datapoint); //Doesn't work with zoom right now. Fix this.
}
});
// show pan/zoom messages to illustrate events
placeholder.bind('plotpan', function(event, plot){
var axes = plot.getAxes();
$(".message").html("Panning to x: " + axes.xaxis.min.toFixed(2) +
" – " +
axes.xaxis.max.toFixed(2) +
" and y: " +
axes.yaxis.min.toFixed(2) +
" – " +
axes.yaxis.max.toFixed(2));
});
placeholder.bind('plotzoom', function(event, plot){
var axes = plot.getAxes();
$(".message").html("Zooming to x: " + axes.xaxis.min.toFixed(2) +
" – " +
axes.xaxis.max.toFixed(2) +
" and y: " +
axes.yaxis.min.toFixed(2) +
" – " +
axes.yaxis.max.toFixed(2));
});
// and add panning buttons
// little helper for taking the repetitive work out of placing
// panning arrows
function addArrow(dir, right, top, offset){
$('<img class="button" src="http://localhost:9876/getImg?include=arrow-' + dir + '.gif" style="right:' + right + 'px;top:' + top + 'px">').appendTo(placeholder).click(function(e){
e.preventDefault();
plot.pan(offset);
});
}
/*
addArrow('left', 44, 231, {
left: -100
});
addArrow('right', 16, 231, {
left: 100
});
addArrow('up', 30, 215, {
top: -100
});
addArrow('down', 30, 245, {
top: 100
});
*/
});
</script>
</body>
</html>