Mercurial > repos > mzeidler > virana_main
comparison jqBarGraph.2.1.js @ 12:af2085ce7001 draft
Uploaded
| author | mzeidler |
|---|---|
| date | Sun, 29 Sep 2013 19:20:43 -0400 |
| parents | |
| children | 73c223d283a4 |
comparison
equal
deleted
inserted
replaced
| 11:4699815b211a | 12:af2085ce7001 |
|---|---|
| 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 | |
| 408 out = "<div><b>Files for Sample "+arr.sample+"</b></div><p/>"; | |
| 409 | |
| 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'>"; | |
| 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; | |
| 482 $('.files'+elid).css({'height': curr_hei+'px', 'width':'915px','position':'relative', 'overflow' : 'auto','background-color':'rgb(223, 229, 249)', 'border':'2px solid silver', 'display':'block' }).animate({'height':hei+'px'}, 1000); | |
| 483 } | |
| 484 }; | |
| 485 | |
| 486 | |
| 487 showImage = function (elid,region, consensus_image,wi) { | |
| 488 var div = document.getElementById("image" + elid); | |
| 489 div.innerHTML=""; | |
| 490 out="<div>Consensus Image for Region "+region+"</div>"; | |
| 491 out+="<img id='image_file"+elid+"' src="+consensus_image+" alt="+consensus_image+">"; | |
| 492 $(div).append(out) | |
| 493 | |
| 494 | |
| 495 $(div).append("<div class='close_image"+elid+"'style='cursor:pointer;'>x</div>"); | |
| 496 $(".close_image"+elid).click(function(){ | |
| 497 | |
| 498 $('.image'+elid).css({'display':'none'}); | |
| 499 $('.image'+elid).removeClass("selected"); | |
| 500 | |
| 501 | |
| 502 }); | |
| 503 $("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'}); | |
| 504 $("a.close_image"+elid).css({'color':'white', 'text-decoration': 'none'}); | |
| 505 | |
| 506 wi=$('.files'+elid).width(); | |
| 507 | |
| 508 | |
| 509 if(!$('.image'+elid).hasClass("selected")){ | |
| 510 $('.image'+elid).css({'width':wi+'px','position':'relative','height':'auto', 'overflow' : 'auto','background-color':'rgb(223, 229, 249)', 'border':'2px solid silver', 'display':'block' }); | |
| 511 | |
| 512 } | |
| 513 | |
| 514 }; | |
| 515 | |
| 516 | |
| 517 this.each ( | |
| 518 function() | |
| 519 { init(this); } | |
| 520 ) | |
| 521 | |
| 522 }; | |
| 523 | |
| 524 // default values | |
| 525 $.fn.jqBarGraph.defaults = { | |
| 526 sample: 'no_sample_id', | |
| 527 barSpace: 10, | |
| 528 width: 400, | |
| 529 height: 600, | |
| 530 color: '#000000', | |
| 531 colors: false, | |
| 532 lbl: '', | |
| 533 sort: false, // 'asc' or 'desc' | |
| 534 sortBar: false, | |
| 535 tab: 'reads', | |
| 536 position: 'bottom', // or 'top' doesn't work for multi type | |
| 537 prefix: '', | |
| 538 postfix: '', | |
| 539 animate: true, | |
| 540 speed: 3.0, | |
| 541 legendWidth: 150, | |
| 542 legend: false, | |
| 543 type: false, // or 'multi' | |
| 544 showValues: false, | |
| 545 borderSize: 1, | |
| 546 showValuesColor: '#fff', | |
| 547 title: false | |
| 548 }; | |
| 549 | |
| 550 | |
| 551 //sorting functions | |
| 552 function sortReadsAsc(a,b){ | |
| 553 sum_a=0 | |
| 554 for(var values in a){ | |
| 555 if(a[values] instanceof Array){ | |
| 556 for(var val in a[values]){ | |
| 557 sum_a+=a[values][val][0]; | |
| 558 } | |
| 559 } | |
| 560 } | |
| 561 sum_b=0 | |
| 562 for(var values in b){ | |
| 563 if(b[values] instanceof Array){ | |
| 564 for(var val in b[values]){ | |
| 565 sum_b+=b[values][val][0]; | |
| 566 } | |
| 567 } | |
| 568 } | |
| 569 | |
| 570 if (sum_a<sum_b) return -1; | |
| 571 if (sum_a>sum_b) return 1; | |
| 572 return 0; | |
| 573 } | |
| 574 function sortBasesAsc(a,b){ | |
| 575 sum_a=0 | |
| 576 for(var values in a){ | |
| 577 if(a[values] instanceof Array){ | |
| 578 for(var val in a[values]){ | |
| 579 sum_a+=a[values][val][1]; | |
| 580 } | |
| 581 } | |
| 582 } | |
| 583 sum_b=0 | |
| 584 for(var values in b){ | |
| 585 if(b[values] instanceof Array){ | |
| 586 for(var val in b[values]){ | |
| 587 sum_b+=b[values][val][1]; | |
| 588 } | |
| 589 } | |
| 590 } | |
| 591 | |
| 592 if (sum_a<sum_b) return -1; | |
| 593 if (sum_a>sum_b) return 1; | |
| 594 return 0; | |
| 595 } | |
| 596 | |
| 597 function sortReadsDesc(a,b){ | |
| 598 sum_a=0 | |
| 599 for(var values in a){ | |
| 600 if(a[values] instanceof Array){ | |
| 601 for(var val in a[values]){ | |
| 602 sum_a+=a[values][val][0]; | |
| 603 } | |
| 604 } | |
| 605 } | |
| 606 sum_b=0 | |
| 607 for(var values in b){ | |
| 608 if(b[values] instanceof Array){ | |
| 609 for(var val in b[values]){ | |
| 610 sum_b+=b[values][val][0]; | |
| 611 } | |
| 612 } | |
| 613 } | |
| 614 | |
| 615 if (sum_a<sum_b) return 1; | |
| 616 if (sum_a>sum_b) return -1; | |
| 617 return 0; | |
| 618 } | |
| 619 function sortBasesDesc(a,b){ | |
| 620 sum_a=0 | |
| 621 for(var values in a){ | |
| 622 if(a[values] instanceof Array){ | |
| 623 for(var val in a[values]){ | |
| 624 sum_a+=a[values][val][1]; | |
| 625 } | |
| 626 } | |
| 627 } | |
| 628 sum_b=0 | |
| 629 for(var values in b){ | |
| 630 if(b[values] instanceof Array){ | |
| 631 for(var val in b[values]){ | |
| 632 sum_b+=b[values][val][1]; | |
| 633 } | |
| 634 } | |
| 635 } | |
| 636 | |
| 637 if (sum_a<sum_b) return 1; | |
| 638 if (sum_a>sum_b) return -1; | |
| 639 return 0; | |
| 640 } | |
| 641 | |
| 642 function sortBars(data,fun){ | |
| 643 for(var values in data){ | |
| 644 last = data[values].pop(); | |
| 645 for(var val in data[values]){ | |
| 646 data[values][val].sort(fun); | |
| 647 } | |
| 648 data[values].push(last); | |
| 649 } | |
| 650 } | |
| 651 | |
| 652 function sortBars(data,fun){ | |
| 653 for(var values in data){ | |
| 654 last = data[values].pop(); | |
| 655 for(var val in data[values]){ | |
| 656 data[values][val].sort(fun); | |
| 657 } | |
| 658 data[values].push(last); | |
| 659 } | |
| 660 } | |
| 661 | |
| 662 | |
| 663 | |
| 664 function barAsc(a,b){ | |
| 665 if(a[0]<b[0]) return -1; | |
| 666 if(a[0]>b[0]) return 1; | |
| 667 return 0; | |
| 668 } | |
| 669 | |
| 670 function barDesc(a,b){ | |
| 671 if(a[0]<b[0]) return 1; | |
| 672 if(a[0]>b[0]) return -1; | |
| 673 return 0; | |
| 674 } | |
| 675 | |
| 676 })(jQuery); |
