12
|
1 /**
|
|
2 * jqBarGraph - jQuery plugin
|
|
3 * @version: 1.1 (2011/04/03)
|
|
4 * @requires jQuery v1.2.2 or later
|
|
5 * @author Ivan Lazarevic
|
|
6 * Examples and documentation at: http://www.workshop.rs/jqbargraph/
|
|
7 *
|
|
8 * Dual licensed under the MIT and GPL licenses:
|
|
9 * http://www.opensource.org/licenses/mit-license.php
|
|
10 * http://www.gnu.org/licenses/gpl.html
|
|
11 *
|
|
12 * @param data: arrayOfData // array of data for your graph
|
|
13 * @param title: false // title of your graph, accept HTML
|
|
14 * @param barSpace: 10 // this is default space between bars in pixels
|
|
15 * @param width: 400 // default width of your graph ghhjgjhg
|
|
16 * @param height: 200 //default height of your graph
|
|
17 * @param color: '#000000' // if you don't send colors for your data this will be default bars color
|
|
18 * @param colors: false // array of colors that will be used for your bars and legends
|
|
19 * @param lbl: '' // if there is no label in your array
|
|
20 * @param sort: false // sort your data before displaying graph, you can sort as 'asc' or 'desc'
|
|
21 * @param position: 'bottom' // position of your bars, can be 'bottom' or 'top'. 'top' doesn't work for multi type
|
|
22 * @param prefix: '' // text that will be shown before every label
|
|
23 * @param postfix: '' // text that will be shown after every label
|
|
24 * @param animate: true // if you don't need animated appereance change to false
|
|
25 * @param speed: 2 // speed of animation in seconds
|
|
26 * @param legendWidth: 100 // width of your legend box
|
|
27 * @param legend: false // if you want legend change to true
|
|
28 * @param legends: false // array for legend. for simple graph type legend will be extracted from labels if you don't set this
|
|
29 * @param type: false // for multi array data default graph type is stacked, you can change to 'multi' for multi bar type
|
|
30 * @param showValues: true // you can use this for multi and stacked type and it will show values of every bar part
|
|
31 * @param showValuesColor: '#fff' // color of font for values
|
|
32
|
|
33 * @example $('#divForGraph').jqBarGraph({ data: arrayOfData });
|
|
34
|
|
35 **/
|
|
36
|
|
37 (function($) {
|
|
38 var opts = new Array;
|
|
39 var level = new Array;
|
|
40
|
|
41 $.fn.jqBarGraph = $.fn.jqbargraph = function(options){
|
|
42
|
|
43 init = function(el){
|
|
44
|
|
45 opts[el.id] = $.extend({}, $.fn.jqBarGraph.defaults, options);
|
|
46 $(el).css({ 'width': opts[el.id].width, 'height': opts[el.id].height, 'position':'relative', 'text-align':'center' });
|
|
47
|
|
48
|
|
49 doGraph(el);
|
|
50
|
|
51 };
|
|
52
|
|
53 // sum of array elements
|
|
54 sum = function(ar,index){
|
|
55 total = 0;
|
|
56 for(val in ar){
|
|
57 total += ar[val][index];
|
|
58 }
|
|
59 return total.toFixed(2);
|
|
60 };
|
|
61
|
|
62 // count max value of array
|
|
63 max = function(ar,index){
|
|
64 maxvalue = 0;
|
|
65 for(var val in ar){
|
|
66 value = ar[val][0];
|
|
67 if(value instanceof Array) value = sum(value,index);
|
|
68 if (parseFloat(value) > parseFloat(maxvalue)) maxvalue=value;
|
|
69 }
|
|
70 return maxvalue;
|
|
71 };
|
|
72
|
|
73 // max value of multi array
|
|
74 maxMulti = function(ar,index){
|
|
75 maxvalue = 0;
|
|
76 maxvalue2 = 0;
|
|
77
|
|
78 for(var val in ar){
|
|
79 ar2 = ar[val][0];
|
|
80
|
|
81 for(var val2 in ar2){
|
|
82 if(ar2[val2][index]>maxvalue2) maxvalue2 = ar2[val2][index];
|
|
83 }
|
|
84
|
|
85 if (maxvalue2>maxvalue) maxvalue=maxvalue2;
|
|
86 }
|
|
87
|
|
88 return maxvalue;
|
|
89 };
|
|
90
|
|
91
|
|
92 doGraph = function(el){
|
|
93
|
|
94 arr = opts[el.id];
|
|
95 data = arr.data;
|
|
96 if(arr.tab=='reads'){
|
|
97 val_index=0;
|
|
98 }
|
|
99 else{
|
|
100 val_index=1;
|
|
101 }
|
|
102
|
|
103 //check if array is bad or empty
|
|
104 if(data == undefined) {
|
|
105 $(el).html('There is not enought data for graph');
|
|
106 return;
|
|
107 }
|
|
108 //sorting ascending or descending
|
|
109 if(arr.tab == 'reads'){
|
|
110 if(arr.sort == 'asc'){
|
|
111 data.sort(sortReadsAsc);
|
|
112 }
|
|
113 if(arr.sort == 'desc'){
|
|
114 data.sort(sortReadsDesc);
|
|
115 }
|
|
116 }
|
|
117 if(arr.tab == 'basepairs'){
|
|
118 if(arr.sort == 'asc'){
|
|
119 data.sort(sortBasesAsc);
|
|
120 }
|
|
121 if(arr.sort == 'desc'){
|
|
122 data.sort(sortBasesDesc);
|
|
123 }
|
|
124 }
|
|
125 if(arr.sortBar == 'asc') sortBars(data, barAsc);
|
|
126 if(arr.sortBar == 'desc')sortBars(data, barDesc);
|
|
127
|
|
128
|
|
129
|
|
130 legend = '';
|
|
131 prefix = arr.prefix;
|
|
132 postfix = arr.postfix;
|
|
133 space = arr.barSpace; //space between bars
|
|
134 legendWidth = arr.legend ? arr.legendWidth : 0; //width of legend box
|
|
135 fieldWidth = ($(el).width()-legendWidth)/data.length; //width of bar
|
|
136 totalHeight = $(el).height(); //total height of graph box
|
|
137 var leg = new Array(); //legends array
|
|
138
|
|
139 //max value in data, I use this to calculate height of bar
|
|
140 max = max(data,val_index);
|
|
141
|
|
142 color_map={};
|
|
143 color_map["pathogen"]=arr.colors[0];
|
|
144 color_map["ambiguous"]=arr.colors[1];
|
|
145 color_map["human"]=arr.colors[2];
|
|
146
|
|
147 if(arr.tab=='reads'){
|
|
148 val_index=0;
|
|
149 }
|
|
150 else{
|
|
151 val_index=1;
|
|
152
|
|
153 }
|
|
154
|
|
155 for(var val in data){
|
|
156
|
|
157 valueData = data[val][0];
|
|
158 if (valueData instanceof Array)
|
|
159 value = sum(valueData,val_index);
|
|
160 else
|
|
161 value = valueData;
|
|
162
|
|
163 lbl = data[val][1];
|
|
164 unique = val+el.id; //unique identifier
|
|
165 divid=""+el.id;
|
|
166
|
|
167 if(arr.type == 'multi') color = 'none';
|
|
168
|
|
169 if (lbl == undefined) lbl = arr.lbl;
|
|
170
|
|
171 margin_top=14/(data.length);
|
|
172
|
|
173
|
|
174 out = "<div class='graphField"+el.id+"' id='graphField"+unique+"' style='position: absolute'>";
|
|
175 out += "<div class='graphValue"+el.id+"' id='graphValue"+unique+"'>"+parseInt(value)+"</div>";
|
|
176
|
|
177 out += "<div class='graphBar"+el.id+"' id='graphFieldBar"+unique+"' style='background-color:#fff;position: relative; overflow: hidden;'></div>";
|
|
178 //console.log(color)
|
|
179 // if there is no legend or exist legends display lbl at the bottom
|
|
180
|
|
181 out += "<a class='graphLabelLink' href=#files"+el.id+" onclick=fillDiv('"+el.id+"','"+valueData[0][3]+"_"+lbl+"')><div class='graphLabel"+el.id+"' id='graphLabel"+unique+"'style='margin-top:"+margin_top+"px;'>"+lbl+"</div></a>";
|
|
182 out += "</div>";
|
|
183
|
|
184
|
|
185
|
|
186 $(el).append(out);
|
|
187 $(".graphLabel"+el.id).css({'-webkit-transform': 'rotate(30deg)', '-moz-transform': 'rotate(30deg)','-o-transform': 'rotate(30deg)', '-ms-transform': 'rotate(30deg)','transform': 'rotate(30deg)', 'height':'100'});
|
|
188 $('a.graphLabel').css({
|
|
189 'text-decoration': 'none',
|
|
190 'color':'black'
|
|
191 });
|
|
192
|
|
193 //$('#graphLabel'+el.id).rotateLeft();
|
|
194
|
|
195 //size of bar
|
|
196 totalHeightBar = totalHeight - $('.graphLabel'+el.id).height() - $('.graphValue'+el.id).height()-margin_top;
|
|
197 fieldHeight = (totalHeightBar*value)/max;
|
|
198 $('#graphField'+unique).css({
|
|
199 'left': (fieldWidth)*val,
|
|
200 'width': fieldWidth-space,
|
|
201 'margin-left': space});
|
|
202
|
|
203 // multi array
|
|
204 if(valueData instanceof Array){
|
|
205
|
|
206 if(arr.type=="multi"){
|
|
207
|
|
208 maxe = maxMulti(data,val_index);
|
|
209 totalHeightBar = fieldHeight = totalHeight - $('.graphLabel'+el.id).height()-margin_top;
|
|
210 $('.graphValue'+el.id).remove();
|
|
211 } else {
|
|
212
|
|
213 maxe = max;
|
|
214 }
|
|
215
|
|
216 for (i in valueData){
|
|
217 heig = (totalHeightBar*valueData[i][val_index]/maxe);
|
|
218 if(navigator.userAgent.match('Safari') && !navigator.userAgent.match('Chrom')){
|
|
219
|
|
220 heig = heig + (arr.borderSize/1.85);
|
|
221 }
|
|
222
|
|
223 wid = parseInt((fieldWidth-space)/valueData.length);
|
|
224
|
|
225 sv = ''; // show values
|
|
226 fs = 0; // font size
|
|
227 if (arr.showValues){
|
|
228 sv = arr.prefix+valueData[i][0]+arr.postfix;
|
|
229 fs = 12; // font-size is 0 if showValues = false
|
|
230 }
|
|
231 o = "<a class='subBarLink' href=#files"+el.id+" onclick=fillDiv('"+el.id+"','"+valueData[i][3]+"_"+lbl+"','"+valueData[i][5]+"')><div class='subBars"+el.id+"' style=' box-sizing:border-box; -moz-box-sizing:border-box; -ms-box-sizing:border-box; -webkit-box-sizing:border-box; height:"+heig+"px; border-top:"+arr.borderSize+"px solid; border-color: "+arr.showValuesColor+"; background-color: "+color_map[valueData[i][2]]+"; left:"+wid*i+"px; color:"+arr.showValuesColor+"; font-size:"+fs+"px' >"+sv+"</div></a>";
|
|
232 $('#graphFieldBar'+unique).prepend(o);
|
|
233 }
|
|
234 }
|
|
235
|
|
236 if(arr.type=='multi')
|
|
237 $('.subBars'+el.id).css({ 'width': wid, 'position': 'absolute', 'bottom': 0 });
|
|
238
|
|
239 //position of bars
|
|
240 if(arr.position == 'bottom') $('.graphField'+el.id).css('bottom',0);
|
|
241
|
|
242
|
|
243
|
|
244
|
|
245
|
|
246 // animated apearing
|
|
247 if(arr.animate){
|
|
248 $('#graphFieldBar'+unique).css({ 'height' : 0 });
|
|
249 $('#graphFieldBar'+unique).animate({'height': fieldHeight},arr.speed*1000);
|
|
250 } else {
|
|
251 $('#graphFieldBar'+unique).css({'height': fieldHeight});
|
|
252 }
|
|
253
|
|
254 }
|
|
255
|
|
256
|
|
257
|
|
258 createLegend(color_map,el.id); // create legend from array
|
|
259 createLinks(el.id);
|
|
260 //position of legend
|
|
261
|
|
262 $(el).append("<div id='legendHolder"+unique+"'></div>");
|
|
263 $('#legendHolder'+unique).css({ 'width': legendWidth, 'float': 'right', 'margin-left':'100px','text-align' : 'left'});
|
|
264 $('#legendHolder'+unique).append(legend);
|
|
265 $('#legendHolder'+unique).append(links);
|
|
266 $('.legendBar'+el.id).css({ 'float':'left', 'margin': 3, 'margin-left':'10','height': 12, 'width': 20, 'font-size': 0});
|
|
267 $('.linkBar'+el.id).css({'margin-left':'10'});
|
|
268
|
|
269
|
|
270 $("#sortAsc"+el.id).click(function(){
|
|
271 if(opts[el.id].sort!='asc'){
|
|
272 opts[el.id].sort='asc';
|
|
273 $('#graphHolder'+el.id).html('');
|
|
274 $('#graphHolder'+el.id).jqbargraph(opts[el.id]);
|
|
275 }
|
|
276
|
|
277 });
|
|
278 $("#sortDesc"+el.id).click(function(){
|
|
279 if(opts[el.id].sort!='desc'){
|
|
280 opts[el.id].sort='desc';
|
|
281 $('#graphHolder'+el.id).html('');
|
|
282 $('#graphHolder'+el.id).jqbargraph(opts[el.id]);
|
|
283 }
|
|
284
|
|
285 });
|
|
286 $("#sortBarAsc"+el.id).click(function(){
|
|
287 if(opts[el.id].sortBar!='asc'){
|
|
288 opts[el.id].sortBar='asc';
|
|
289 $('#graphHolder'+el.id).html('');
|
|
290 $('#graphHolder'+el.id).jqbargraph(opts[el.id]);
|
|
291 }
|
|
292
|
|
293 });
|
|
294 $("#sortBarDesc"+el.id).click(function(){
|
|
295 if(opts[el.id].sortBar!='desc'){
|
|
296 opts[el.id].sortBar='desc';
|
|
297 $('#graphHolder'+el.id).html('');
|
|
298 $('#graphHolder'+el.id).jqbargraph(opts[el.id]);
|
|
299 }
|
|
300
|
|
301 });
|
|
302
|
|
303 $("#showBasepairs"+el.id).click(function(){
|
|
304 opts[el.id].tab='basepairs';
|
|
305 $('#graphHolder'+el.id).html('');
|
|
306 $('#graphHolder'+el.id).jqbargraph(opts[el.id]);
|
|
307
|
|
308
|
|
309
|
|
310 });
|
|
311 $("#showReads"+el.id).click(function(){
|
|
312 opts[el.id].tab='reads';
|
|
313 $('#graphHolder'+el.id).html('');
|
|
314 $('#graphHolder'+el.id).jqbargraph(opts[el.id]);
|
|
315
|
|
316
|
|
317
|
|
318 });
|
|
319
|
|
320
|
|
321
|
|
322 //position of title
|
|
323 if(arr.title){
|
|
324 $(el).wrap("<div id='graphHolder"+el.id+"'></div>");
|
|
325 if(arr.tab=='reads'){
|
|
326 $('#graphHolder'+el.id).prepend("<div id='label"+el.id+"'>Cumulative reads assigned to family</div>").css({ 'width' : arr.width+'px', 'text-align' : 'center' });
|
|
327 }else{
|
|
328 $('#graphHolder'+el.id).prepend("<div id='label"+el.id+"'>Cumulative basepairs assigned to family</div>").css({ 'width' : arr.width+'px', 'text-align' : 'center' });
|
|
329 }
|
|
330 $('#graphHolder'+el.id).prepend("<a href=#files"+el.id+" onclick=fillDiv('"+el.id+"')>"+arr.title+"</a>").css({ 'width' : arr.width+'px', 'text-align' : 'center' });
|
|
331
|
|
332 }
|
|
333 $("#graphHolder"+el.id).append("<div class='files"+el.id+"' id='files"+el.id+"' ></div><p/>");
|
|
334 $('.files'+el.id).css({'width' : arr.width+'px','background-color':'silver', 'border':'2px solid gray', 'display':'none'})
|
|
335
|
|
336 $("#graphHolder"+el.id).append("<div class='image"+el.id+"' id='image"+el.id+"' ></div>");
|
|
337 $('.image'+el.id).css({'width' : arr.width+'px','background-color':'silver', 'border':'2px solid gray', 'display':'none'})
|
|
338
|
|
339 };
|
|
340
|
|
341
|
|
342 //creating legend from array
|
|
343 createLegend = function(color_map,id){
|
|
344 legend = '';
|
|
345 for(var val in color_map){
|
|
346 legend += "<div id='legend"+val+"' style='overflow: hidden; zoom: 1;'>";
|
|
347 legend += "<div class='legendBar"+id+"' id='legendColor"+val+"' style='background-color:"+color_map[val]+"'></div>";
|
|
348 legend += "<div class='legendLabel"+id+"' id='graphLabel"+unique+"'>"+val+"</div>";
|
|
349 legend += "</div>";
|
|
350 }
|
|
351 };
|
|
352
|
|
353 createLinks = function(id){
|
|
354 links="<div class='linkBar"+id+"'>";
|
|
355 links+="<div ><a href='javascript:void(0);' id='sortAsc"+id+"' >sort ascending</a></div>"
|
|
356 links+="<div ><a href='javascript:void(0);' id='sortDesc"+id+"'>sort descending</a></div>"
|
|
357 links+="<div ><a href='javascript:void(0);' id='sortBarAsc"+id+"'>sort bars ascending</a></div>"
|
|
358 links+="<div ><a href='javascript:void(0);' id='sortBarDesc"+id+"'>sort bars descending</a></div>"
|
|
359 if(opts[id].tab=='reads'){
|
|
360 links+="<div ><a href='javascript:void(0);' id='showBasepairs"+id+"'>show basepair chart </a></div>"
|
|
361 }else{
|
|
362 links+="<div ><a href='javascript:void(0);' id='showReads"+id+"'>show read chart </a></div>"
|
|
363 }
|
|
364 links+="</div>"
|
|
365
|
|
366
|
|
367 };
|
|
368
|
|
369 fillDiv = function (elid, dir, region) {
|
|
370
|
|
371
|
|
372
|
|
373 arr=opts[elid];
|
|
374
|
|
375 dict=arr.files;
|
|
376
|
|
377 generateDownloadLink = function(family,region,filetype){
|
|
378 out=" no file ";
|
|
379
|
|
380 if($.inArray("region_"+region+"_"+filetype,dict[family][region])!=-1){
|
|
381 out="<a href="+family+"/region_"+region+"_"+filetype+">download</a>";
|
|
382 }
|
|
383 return out;
|
|
384
|
|
385 };
|
|
386 generateShowLink = function(family,region){
|
|
387 out=" no image ";
|
|
388
|
|
389 if($.inArray("region_"+region+"_consensus.png",dict[family][region])!=-1){
|
|
390 out="<a href=#image"+elid+" onclick=showImage('"+elid+"','"+region+"','"+ family +"/region_"+region+"_consensus.png')>show</a>";
|
|
391 }
|
|
392 return out;
|
|
393
|
|
394 };
|
|
395
|
|
396
|
|
397 data = arr.data
|
|
398 for(var val in data){
|
|
399 for(var element in data[val][0]){
|
|
400 dict[data[val][0][0][3]+"_"+data[val][1]][data[val][0][element][5]].push([data[val][0][element][0],data[val][0][element][1],data[val][0][element][4]]);
|
|
401
|
|
402 }
|
|
403 }
|
|
404
|
|
405 var div = document.getElementById("files" + elid);
|
|
406 div.innerHTML="";
|
|
407
|
15
|
408 out = "<div><H3>Files for Sample "+arr.sample+"</H3></div><p/>";
|
12
|
409
|
15
|
410 out += "<div class='" + elid + "_files' id='" + elid + "_files'><table id='"+elid+"table' class='"+elid+"table' border=1 cellpadding=3 cellspacing=0 style=' border: 1pt solid #000000; border-Collapse: collapse; font-size: 12px;'>";
|
12
|
411 out += "<tr><th>family</th><th>region</th><th>#reads</th><th>#basepairs</th><th>region length</th><th>unaligned fasta</th><th>bam alignment</th><th>consensus fasta</th><th>consensus diagram</th></tr>"
|
|
412 if (!dir) {
|
|
413 for (var directory in dict) {
|
|
414 //out += "<b>"+directory+"</b>";
|
|
415 //out += "<div class='dirlist' id='" + directory + "_files'";
|
|
416 for (var region in dict[directory]) {
|
|
417 last = dict[directory][region][dict[directory][region].length-1];
|
|
418 if(last instanceof Array && last[0]){
|
|
419 out += "<tr><td>"+directory+"</td><td>"+region+"</td><td>"+last[0]+"</td><td>"+last[1]+"</td><td>"+last[2]+"</td><td>"+generateDownloadLink(directory,region,"unaligned.fa.bzip2")+"</td><td>"+generateDownloadLink(directory,region,"alignment.bam")+"</td><td>"+generateDownloadLink(directory,region,"consensus.fa")+"</td><td>"+generateShowLink(directory,region)+" "+generateDownloadLink(directory,region,"consensus.png")+"</td></tr>";
|
|
420 }
|
|
421 }
|
|
422 out += "</div>";
|
|
423 }
|
|
424 } else {
|
|
425 out += "<b>"+ dir+"</b>" ;
|
|
426
|
|
427 if (!region) {
|
|
428 for (var region in dict[dir]) {
|
|
429 last = dict[dir][region][dict[dir][region].length-1];
|
|
430 if(last instanceof Array && last[0]){
|
|
431 out += "<tr><td>"+dir+"</td><td>"+region+"</td><td>"+last[0]+"</td><td>"+last[1]+"</td><td>"+last[2]+"</td><td>"+generateDownloadLink(dir,region,"unaligned.fa.bzip2")+"</td><td>"+generateDownloadLink(dir,region,"alignment.bam")+"</td><td>"+generateDownloadLink(dir,region,"consensus.fa")+"</td><td>"+generateShowLink(dir,region)+" "+generateDownloadLink(dir,region,"consensus.png")+"</td></tr>";
|
|
432 }
|
|
433 }
|
|
434 } else {
|
|
435
|
|
436 last = dict[dir][region][dict[dir][region].length-1];
|
|
437 if(last instanceof Array && last[0]){
|
|
438 out += "<tr><td>"+dir+"</td><td>"+region+"</td><td>"+last[0]+"</td><td>"+last[1]+"</td><td>"+last[2]+"</td><td>"+generateDownloadLink(dir,region,"unaligned.fa.bzip2")+"</td><td>"+generateDownloadLink(dir,region,"alignment.bam")+"</td><td>"+generateDownloadLink(dir,region,"consensus.fa")+"</td><td>"+generateShowLink(dir,region)+" "+generateDownloadLink(dir,region,"consensus.png")+"</td></tr>";
|
|
439 }
|
|
440 }
|
|
441 }
|
|
442 out += "</div>";
|
|
443
|
|
444 $(div).append(out);
|
|
445 $(div).append("<div class='close_files"+elid+"'style='cursor:pointer;'>x</div>");
|
|
446 $("a").css({'color':'black'});
|
|
447 $("table").css({'border':'collapse'});
|
|
448
|
|
449 $(".close_files"+elid).click(function(){
|
|
450 $('.files'+elid).animate({'height':'0px'},1000,'',function(){
|
|
451 $('.files'+elid).css({'display':'none'});
|
|
452 $('.files'+elid).removeClass("selected");
|
|
453 });
|
|
454
|
|
455
|
|
456 });
|
|
457 $("div.close_files"+elid).css({'color':'white','position':'absolute','top':'2','left':'2','background-color':arr.colors[1],'border':'1px solid white','border-radius':'20px','height':'20px','width':'20px','text-align': 'center'});
|
|
458 $("a.close_files"+elid).css({'color':'white', 'text-decoration': 'none'});
|
|
459 $('.files'+elid).css({'width': 'auto','display':'none'});
|
|
460 wi=$('.files'+elid).width()+15;
|
|
461
|
|
462
|
|
463
|
|
464 if(!$('.files'+elid).hasClass("selected")){
|
|
465 $('.files'+elid).css({'height': 'auto','display':'none'});
|
|
466 hei=$('.files'+elid).height();
|
|
467 hei=parseInt(hei)+10;
|
|
468 hei=hei>400? hei=400 : hei;
|
|
469 $('.files'+elid).css({'width':wi+'px','position':'relative','height':'0px', 'overflow' : 'auto','background-color':'rgb(223, 229, 249)', 'border':'2px solid silver', 'display':'block' });
|
|
470 $('.files'+elid).animate({'height':hei+'px'}, 1000,'',function(){
|
|
471
|
|
472 $('.files'+elid).addClass("selected");
|
|
473 });
|
|
474 }
|
|
475 else{
|
|
476
|
|
477 curr_hei=$('.files'+elid).height();
|
|
478 $('.files'+elid).css({'height': 'auto','display':'none'});
|
|
479 hei=$('.files'+elid).height();
|
|
480 hei=parseInt(hei)+10;
|
|
481 hei=hei>400? hei=400 : hei;
|
36
|
482 $('.files'+elid).css({'height': curr_hei+'px', 'width':wi+'px','position':'relative', 'overflow' : 'auto','background-color':'rgb(223, 229, 249)', 'border':'2px solid silver', 'display':'block' }).animate({'height':hei+'px'}, 1000);
|
12
|
483 }
|
|
484 };
|
|
485
|
|
486
|
|
487 showImage = function (elid,region, consensus_image,wi) {
|
|
488 var div = document.getElementById("image" + elid);
|
|
489 div.innerHTML="";
|
15
|
490 out="<div><H3>Consensus Image for Region "+region+"</H3></div>";
|
35
|
491 newImg= new Image();
|
36
|
492 newImg.src=consensus_image;
|
37
|
493 wid=0;
|
|
494 hig=0;
|
|
495 newImg.onload = function(){
|
|
496 wid=this.width;
|
|
497 hig=this.height;
|
|
498 };
|
|
499
|
34
|
500 out+="<img id='image_file"+elid+"' src="+consensus_image+" alt="+consensus_image+" style='width:"+wid+";height:"+hig+";'>";
|
12
|
501 $(div).append(out)
|
|
502
|
|
503
|
|
504 $(div).append("<div class='close_image"+elid+"'style='cursor:pointer;'>x</div>");
|
|
505 $(".close_image"+elid).click(function(){
|
|
506
|
|
507 $('.image'+elid).css({'display':'none'});
|
|
508 $('.image'+elid).removeClass("selected");
|
|
509
|
|
510
|
|
511 });
|
|
512 $("div.close_image"+elid).css({'color':'white','position':'absolute','top':'2','left':'2','background-color':arr.colors[1],'border':'1px solid white','border-radius':'20px','height':'20px','width':'20px','text-align': 'center'});
|
|
513 $("a.close_image"+elid).css({'color':'white', 'text-decoration': 'none'});
|
|
514
|
|
515 wi=$('.files'+elid).width();
|
|
516
|
|
517
|
|
518 if(!$('.image'+elid).hasClass("selected")){
|
|
519 $('.image'+elid).css({'width':wi+'px','position':'relative','height':'auto', 'overflow' : 'auto','background-color':'rgb(223, 229, 249)', 'border':'2px solid silver', 'display':'block' });
|
|
520
|
|
521 }
|
|
522
|
|
523 };
|
|
524
|
|
525
|
|
526 this.each (
|
|
527 function()
|
|
528 { init(this); }
|
|
529 )
|
|
530
|
|
531 };
|
|
532
|
|
533 // default values
|
|
534 $.fn.jqBarGraph.defaults = {
|
|
535 sample: 'no_sample_id',
|
|
536 barSpace: 10,
|
|
537 width: 400,
|
|
538 height: 600,
|
|
539 color: '#000000',
|
|
540 colors: false,
|
|
541 lbl: '',
|
|
542 sort: false, // 'asc' or 'desc'
|
|
543 sortBar: false,
|
|
544 tab: 'reads',
|
|
545 position: 'bottom', // or 'top' doesn't work for multi type
|
|
546 prefix: '',
|
|
547 postfix: '',
|
|
548 animate: true,
|
|
549 speed: 3.0,
|
|
550 legendWidth: 150,
|
|
551 legend: false,
|
|
552 type: false, // or 'multi'
|
|
553 showValues: false,
|
|
554 borderSize: 1,
|
|
555 showValuesColor: '#fff',
|
|
556 title: false
|
|
557 };
|
|
558
|
|
559
|
|
560 //sorting functions
|
|
561 function sortReadsAsc(a,b){
|
|
562 sum_a=0
|
|
563 for(var values in a){
|
|
564 if(a[values] instanceof Array){
|
|
565 for(var val in a[values]){
|
|
566 sum_a+=a[values][val][0];
|
|
567 }
|
|
568 }
|
|
569 }
|
|
570 sum_b=0
|
|
571 for(var values in b){
|
|
572 if(b[values] instanceof Array){
|
|
573 for(var val in b[values]){
|
|
574 sum_b+=b[values][val][0];
|
|
575 }
|
|
576 }
|
|
577 }
|
|
578
|
|
579 if (sum_a<sum_b) return -1;
|
|
580 if (sum_a>sum_b) return 1;
|
|
581 return 0;
|
|
582 }
|
|
583 function sortBasesAsc(a,b){
|
|
584 sum_a=0
|
|
585 for(var values in a){
|
|
586 if(a[values] instanceof Array){
|
|
587 for(var val in a[values]){
|
|
588 sum_a+=a[values][val][1];
|
|
589 }
|
|
590 }
|
|
591 }
|
|
592 sum_b=0
|
|
593 for(var values in b){
|
|
594 if(b[values] instanceof Array){
|
|
595 for(var val in b[values]){
|
|
596 sum_b+=b[values][val][1];
|
|
597 }
|
|
598 }
|
|
599 }
|
|
600
|
|
601 if (sum_a<sum_b) return -1;
|
|
602 if (sum_a>sum_b) return 1;
|
|
603 return 0;
|
|
604 }
|
|
605
|
|
606 function sortReadsDesc(a,b){
|
|
607 sum_a=0
|
|
608 for(var values in a){
|
|
609 if(a[values] instanceof Array){
|
|
610 for(var val in a[values]){
|
|
611 sum_a+=a[values][val][0];
|
|
612 }
|
|
613 }
|
|
614 }
|
|
615 sum_b=0
|
|
616 for(var values in b){
|
|
617 if(b[values] instanceof Array){
|
|
618 for(var val in b[values]){
|
|
619 sum_b+=b[values][val][0];
|
|
620 }
|
|
621 }
|
|
622 }
|
|
623
|
|
624 if (sum_a<sum_b) return 1;
|
|
625 if (sum_a>sum_b) return -1;
|
|
626 return 0;
|
|
627 }
|
|
628 function sortBasesDesc(a,b){
|
|
629 sum_a=0
|
|
630 for(var values in a){
|
|
631 if(a[values] instanceof Array){
|
|
632 for(var val in a[values]){
|
|
633 sum_a+=a[values][val][1];
|
|
634 }
|
|
635 }
|
|
636 }
|
|
637 sum_b=0
|
|
638 for(var values in b){
|
|
639 if(b[values] instanceof Array){
|
|
640 for(var val in b[values]){
|
|
641 sum_b+=b[values][val][1];
|
|
642 }
|
|
643 }
|
|
644 }
|
|
645
|
|
646 if (sum_a<sum_b) return 1;
|
|
647 if (sum_a>sum_b) return -1;
|
|
648 return 0;
|
|
649 }
|
|
650
|
|
651 function sortBars(data,fun){
|
|
652 for(var values in data){
|
|
653 last = data[values].pop();
|
|
654 for(var val in data[values]){
|
|
655 data[values][val].sort(fun);
|
|
656 }
|
|
657 data[values].push(last);
|
|
658 }
|
|
659 }
|
|
660
|
|
661 function sortBars(data,fun){
|
|
662 for(var values in data){
|
|
663 last = data[values].pop();
|
|
664 for(var val in data[values]){
|
|
665 data[values][val].sort(fun);
|
|
666 }
|
|
667 data[values].push(last);
|
|
668 }
|
|
669 }
|
|
670
|
|
671
|
|
672
|
|
673 function barAsc(a,b){
|
|
674 if(a[0]<b[0]) return -1;
|
|
675 if(a[0]>b[0]) return 1;
|
|
676 return 0;
|
|
677 }
|
|
678
|
|
679 function barDesc(a,b){
|
|
680 if(a[0]<b[0]) return 1;
|
|
681 if(a[0]>b[0]) return -1;
|
|
682 return 0;
|
|
683 }
|
|
684
|
|
685 })(jQuery); |