Commits

jeremy goecks  committed 732ad7e

Trackster: introduce collections of tracks. Track 'groups' can be created and tracks can be added or removed from groups. Currently groups do not have a dropdown menu and cannot be saved.

  • Participants
  • Parent commits ef955e3

Comments (0)

Files changed (6)

File static/images/tracks/block.png

Added
New image

File static/june_2007_style/blue/trackster.css

 .viewport-canvas{width:100%;height:100px;}
 .yaxislabel{color:#777;z-index:100;}
 .line-track .track-content{border-top:1px solid #eee;border-bottom:1px solid #eee;}
+.group-handle{cursor:move;float:left;background:#eee url('/static/images/tracks/block.png');width:12px;height:12px;}
+.group{min-height:20px;border-top:2px solid #888;border-bottom:2px solid #888;}
 .track{background:white;}
 .track-header{text-align:left;padding:4px 0px;color:#666;}
 .track-header .menubutton{margin-left:0px;}

File static/june_2007_style/trackster.css.tmpl

     border-top: 1px solid #eee;
     border-bottom: 1px solid #eee;
 }
-    
+
+.group-handle {
+    cursor: move;
+    float: left;
+    background: #eee url('/static/images/tracks/block.png');
+    width: 12px;
+    height: 12px;
+}
+.group {
+    min-height: 20px;
+    border-top: 2px solid #888;
+    border-bottom: 2px solid #888;
+}    
 .track {
     /* border-top: solid #DDDDDD 1px; */
     /* border-bottom: solid #DDDDDD 1px; */

File static/scripts/packed/trackster.js

-var class_module=function(b,a){var c=function(){var f=arguments[0];for(var e=1;e<arguments.length;e++){var d=arguments[e];for(key in d){f[key]=d[key]}}return f};a.extend=c};var requestAnimationFrame=(function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(b,a){window.setTimeout(b,1000/60)}})();var BEFORE=1001,CONTAINS=1002,OVERLAP_START=1003,OVERLAP_END=1004,CONTAINED_BY=1005,AFTER=1006;var compute_overlap=function(e,b){var g=e[0],f=e[1],d=b[0],c=b[1],a;if(g<d){if(f<d){a=BEFORE}else{if(f<=c){a=OVERLAP_START}else{a=CONTAINS}}}else{if(g>c){a=AFTER}else{if(f<=c){a=CONTAINED_BY}else{a=OVERLAP_END}}}return a};var is_overlap=function(c,b){var a=compute_overlap(c,b);return(a!==BEFORE&&a!==AFTER)};var trackster_module=function(f,U){var n=f("class").extend,p=f("slotting"),I=f("painters");var ab=function(ac,ad){this.document=ac;this.default_font=ad!==undefined?ad:"9px Monaco, Lucida Console, monospace";this.dummy_canvas=this.new_canvas();this.dummy_context=this.dummy_canvas.getContext("2d");this.dummy_context.font=this.default_font;this.char_width_px=this.dummy_context.measureText("A").width;this.patterns={};this.load_pattern("right_strand","/visualization/strand_right.png");this.load_pattern("left_strand","/visualization/strand_left.png");this.load_pattern("right_strand_inv","/visualization/strand_right_inv.png");this.load_pattern("left_strand_inv","/visualization/strand_left_inv.png")};n(ab.prototype,{load_pattern:function(ac,ag){var ad=this.patterns,ae=this.dummy_context,af=new Image();af.src=image_path+ag;af.onload=function(){ad[ac]=ae.createPattern(af,"repeat")}},get_pattern:function(ac){return this.patterns[ac]},new_canvas:function(){var ac=this.document.createElement("canvas");if(window.G_vmlCanvasManager){G_vmlCanvasManager.initElement(ac)}ac.manager=this;return ac}});var C=function(ac,ad){ac.bind("drag",{handle:ad,relative:true},function(ah,ai){var ag=$(this).parent();var af=ag.children();var ae;for(ae=0;ae<af.length;ae++){if(ai.offsetY<$(af.get(ae)).position().top){break}}if(ae===af.length){if(this!==af.get(ae-1)){ag.append(this)}}else{if(this!==af.get(ae)){$(this).insertBefore(af.get(ae))}}}).bind("dragstart",function(){$(this).css({"border-top":"1px solid blue","border-bottom":"1px solid blue"})}).bind("dragend",function(){$(this).css("border","0px")})};U.sortable=C;var aa=16,D=9,A=20,P=D+2,w=100,F=12000,N=200,z=5,s=10,H=5000,t=100,m="There was an error in indexing this dataset. ",G="A converter for this dataset is not installed. Please check your datatypes_conf.xml file.",B="No data for this chrom/contig.",q="Currently indexing... please wait",v="Tool cannot be rerun: ",a="Loading data...",V="Ready for display",d=10,r=5,y=5;function u(ac){return Math.round(ac*1000)/1000}var c=function(ac){this.num_elements=ac;this.clear()};n(c.prototype,{get:function(ad){var ac=this.key_ary.indexOf(ad);if(ac!==-1){if(this.obj_cache[ad].stale){this.key_ary.splice(ac,1);delete this.obj_cache[ad]}else{this.move_key_to_end(ad,ac)}}return this.obj_cache[ad]},set:function(ad,ae){if(!this.obj_cache[ad]){if(this.key_ary.length>=this.num_elements){var ac=this.key_ary.shift();delete this.obj_cache[ac]}this.key_ary.push(ad)}this.obj_cache[ad]=ae;return ae},move_key_to_end:function(ad,ac){this.key_ary.splice(ac,1);this.key_ary.push(ad)},clear:function(){this.obj_cache={};this.key_ary=[]},size:function(){return this.key_ary.length}});var O=function(ad,ac,ae){c.call(this,ad);this.track=ac;this.subset=(ae!==undefined?ae:true)};n(O.prototype,c.prototype,{load_data:function(al,ag,aj,ad,ai){var ak=this.track.view.chrom,af={chrom:ak,low:al,high:ag,mode:aj,resolution:ad,dataset_id:this.track.dataset_id,hda_ldda:this.track.hda_ldda};$.extend(af,ai);if(this.track.filters_manager){var am=[];var ac=this.track.filters_manager.filters;for(var ah=0;ah<ac.length;ah++){am[am.length]=ac[ah].name}af.filter_cols=JSON.stringify(am)}var ae=this;return $.getJSON(this.track.data_url,af,function(an){ae.set_data(al,ag,aj,an)})},get_data:function(ac,ag,ah,ad,af){var ae=this.get_data_from_cache(ac,ag,ah);if(ae){return ae}ae=this.load_data(ac,ag,ah,ad,af);this.set_data(ac,ag,ah,ae);return ae},DEEP_DATA_REQ:"deep",BROAD_DATA_REQ:"breadth",get_more_data:function(ak,af,aj,ae,ai,ag){var al=this.get_data_from_cache(ak,af,aj);if(!al){console.log("ERROR: no current data for: ",this.track,ak,af,aj,ae,ai);return}al.stale=true;var ad=ak;if(ag===this.DEEP_DATA_REQ){$.extend(ai,{start_val:al.data.length+1})}else{if(ag===this.BROAD_DATA_REQ){ad=al.data[al.data.length-1][2]+1}}var ac=this,ah=this.load_data(ad,af,aj,ae,ai);new_data_available=$.Deferred();this.set_data(ak,af,aj,new_data_available);$.when(ah).then(function(am){if(am.data){am.data=al.data.concat(am.data);if(am.message){am.message=am.message.replace(/[0-9]+/,am.data.length)}}ac.set_data(ak,af,aj,am);new_data_available.resolve(am)});return new_data_available},get_data_from_cache:function(ac,ad,ae){return this.get(this.gen_key(ac,ad,ae))},set_data:function(ad,ae,af,ac){return this.set(this.gen_key(ad,ae,af),ac)},gen_key:function(ac,ae,af){var ad=ac+"_"+ae+"_"+af;return ad},split_key:function(ac){return ac.split("_")}});var E=function(ad,ac,ae){O.call(this,ad,ac,ae)};n(E.prototype,O.prototype,c.prototype,{load_data:function(ae,ac,ag,ah,ad,af){if(ad>1){return}return O.prototype.load_data.call(this,ae,ac,ag,ah,ad,af)}});var Z=function(ac,af,ae,ad,ag){this.container=ac;this.chrom=null;this.vis_id=ae;this.dbkey=ad;this.title=af;this.tracks=[];this.label_tracks=[];this.tracks_to_be_redrawn=[];this.max_low=0;this.max_high=0;this.num_tracks=0;this.track_id_counter=0;this.zoom_factor=3;this.min_separation=30;this.has_changes=false;this.init(ag);this.canvas_manager=new ab(ac.get(0).ownerDocument);this.reset()};n(Z.prototype,{init:function(ag){var ae=this.container,ac=this;this.top_container=$("<div/>").addClass("top-container").appendTo(ae);this.content_div=$("<div/>").addClass("content").css("position","relative").appendTo(ae);this.bottom_container=$("<div/>").addClass("bottom-container").appendTo(ae);this.top_labeltrack=$("<div/>").addClass("top-labeltrack").appendTo(this.top_container);this.viewport_container=$("<div/>").addClass("viewport-container").addClass("viewport-container").appendTo(this.content_div);this.intro_div=$("<div/>").addClass("intro").appendTo(this.viewport_container).hide();var af=$("<div/>").text("Add Datasets to Visualization").addClass("action-button").appendTo(this.intro_div).click(function(){add_tracks()});this.nav_labeltrack=$("<div/>").addClass("nav-labeltrack").appendTo(this.bottom_container);this.nav_container=$("<div/>").addClass("nav-container").prependTo(this.top_container);this.nav=$("<div/>").addClass("nav").appendTo(this.nav_container);this.overview=$("<div/>").addClass("overview").appendTo(this.bottom_container);this.overview_viewport=$("<div/>").addClass("overview-viewport").appendTo(this.overview);this.overview_close=$("<a href='javascript:void(0);'>Close Overview</a>").addClass("overview-close").hide().appendTo(this.overview_viewport);this.overview_highlight=$("<div/>").addClass("overview-highlight").hide().appendTo(this.overview_viewport);this.overview_box_background=$("<div/>").addClass("overview-boxback").appendTo(this.overview_viewport);this.overview_box=$("<div/>").addClass("overview-box").appendTo(this.overview_viewport);this.default_overview_height=this.overview_box.height();this.nav_controls=$("<div/>").addClass("nav-controls").appendTo(this.nav);this.chrom_select=$("<select/>").attr({name:"chrom"}).css("width","15em").addClass("no-autocomplete").append("<option value=''>Loading</option>").appendTo(this.nav_controls);var ad=function(ah){if(ah.type==="focusout"||(ah.keyCode||ah.which)===13||(ah.keyCode||ah.which)===27){if((ah.keyCode||ah.which)!==27){ac.go_to($(this).val())}$(this).hide();$(this).val("");ac.location_span.show();ac.chrom_select.show()}};this.nav_input=$("<input/>").addClass("nav-input").hide().bind("keyup focusout",ad).appendTo(this.nav_controls);this.location_span=$("<span/>").addClass("location").appendTo(this.nav_controls);this.location_span.click(function(){ac.location_span.hide();ac.chrom_select.hide();ac.nav_input.val(ac.chrom+":"+ac.low+"-"+ac.high);ac.nav_input.css("display","inline-block");ac.nav_input.select();ac.nav_input.focus()});if(this.vis_id!==undefined){this.hidden_input=$("<input/>").attr("type","hidden").val(this.vis_id).appendTo(this.nav_controls)}this.zo_link=$("<a id='zoom-out' />").click(function(){ac.zoom_out();ac.request_redraw()}).appendTo(this.nav_controls);this.zi_link=$("<a id='zoom-in' />").click(function(){ac.zoom_in();ac.request_redraw()}).appendTo(this.nav_controls);this.load_chroms({low:0},ag);this.chrom_select.bind("change",function(){ac.change_chrom(ac.chrom_select.val())});this.content_div.click(function(ah){$(this).find("input").trigger("blur")});this.content_div.bind("dblclick",function(ah){ac.zoom_in(ah.pageX,this.viewport_container)});this.overview_box.bind("dragstart",function(ah,ai){this.current_x=ai.offsetX}).bind("drag",function(ah,aj){var ak=aj.offsetX-this.current_x;this.current_x=aj.offsetX;var ai=Math.round(ak/ac.viewport_container.width()*(ac.max_high-ac.max_low));ac.move_delta(-ai)});this.overview_close.click(function(){ac.reset_overview()});this.viewport_container.bind("draginit",function(ah,ai){if(ah.clientX>ac.viewport_container.width()-16){return false}}).bind("dragstart",function(ah,ai){ai.original_low=ac.low;ai.current_height=ah.clientY;ai.current_x=ai.offsetX}).bind("drag",function(aj,al){var ah=$(this);var am=al.offsetX-al.current_x;var ai=ah.scrollTop()-(aj.clientY-al.current_height);ah.scrollTop(ai);al.current_height=aj.clientY;al.current_x=al.offsetX;var ak=Math.round(am/ac.viewport_container.width()*(ac.high-ac.low));ac.move_delta(ak)}).bind("mousewheel",function(aj,al,ai,ah){if(ai){var ak=Math.round(-ai/ac.viewport_container.width()*(ac.high-ac.low));ac.move_delta(ak)}});this.top_labeltrack.bind("dragstart",function(ah,ai){return $("<div />").css({height:ac.content_div.height()+ac.top_labeltrack.height()+ac.nav_labeltrack.height()+1,top:"0px",position:"absolute","background-color":"#ccf",opacity:0.5,"z-index":1000}).appendTo($(this))}).bind("drag",function(al,am){$(am.proxy).css({left:Math.min(al.pageX,am.startX),width:Math.abs(al.pageX-am.startX)});var ai=Math.min(al.pageX,am.startX)-ac.container.offset().left,ah=Math.max(al.pageX,am.startX)-ac.container.offset().left,ak=(ac.high-ac.low),aj=ac.viewport_container.width();ac.update_location(Math.round(ai/aj*ak)+ac.low,Math.round(ah/aj*ak)+ac.low)}).bind("dragend",function(am,an){var ai=Math.min(am.pageX,an.startX),ah=Math.max(am.pageX,an.startX),ak=(ac.high-ac.low),aj=ac.viewport_container.width(),al=ac.low;ac.low=Math.round(ai/aj*ak)+al;ac.high=Math.round(ah/aj*ak)+al;$(an.proxy).remove();ac.request_redraw()});this.add_label_track(new Y(this,this.top_labeltrack));this.add_label_track(new Y(this,this.nav_labeltrack));$(window).bind("resize",function(){ac.resize_window()});$(document).bind("redraw",function(){ac.redraw()});this.reset();$(window).trigger("resize");this.update_intro_div()},update_intro_div:function(){if(this.num_tracks===0){this.intro_div.show()}else{this.intro_div.hide()}},update_location:function(ac,ad){this.location_span.text(commatize(ac)+" - "+commatize(ad));this.nav_input.val(this.chrom+":"+commatize(ac)+"-"+commatize(ad))},load_chroms:function(ad,ae){ad.num=t;$.extend(ad,(this.vis_id!==undefined?{vis_id:this.vis_id}:{dbkey:this.dbkey}));var ac=this;$.ajax({url:chrom_url,data:ad,dataType:"json",success:function(ag){if(ag.chrom_info.length===0){alert("Invalid chromosome: "+ad.chrom);return}if(ag.reference){ac.add_label_track(new x(ac))}ac.chrom_data=ag.chrom_info;var aj='<option value="">Select Chrom/Contig</option>';for(var ai=0,af=ac.chrom_data.length;ai<af;ai++){var ah=ac.chrom_data[ai].chrom;aj+='<option value="'+ah+'">'+ah+"</option>"}if(ag.prev_chroms){aj+='<option value="previous">Previous '+t+"</option>"}if(ag.next_chroms){aj+='<option value="next">Next '+t+"</option>"}ac.chrom_select.html(aj);if(ae){ae()}ac.chrom_start_index=ag.start_index},error:function(){alert("Could not load chroms for this dbkey:",ac.dbkey)}})},change_chrom:function(ag,ad,ai){if(!ag||ag==="None"){return}var af=this;if(ag==="previous"){af.load_chroms({low:this.chrom_start_index-t});return}if(ag==="next"){af.load_chroms({low:this.chrom_start_index+t});return}var ah=$.grep(af.chrom_data,function(ak,al){return ak.chrom===ag})[0];if(ah===undefined){af.load_chroms({chrom:ag},function(){af.change_chrom(ag,ad,ai)});return}else{if(ag!==af.chrom){af.chrom=ag;af.chrom_select.val(af.chrom);af.max_high=ah.len-1;af.reset();af.request_redraw(true);for(var aj=0,ac=af.tracks.length;aj<ac;aj++){var ae=af.tracks[aj];if(ae.init){ae.init()}}}if(ad!==undefined&&ai!==undefined){af.low=Math.max(ad,0);af.high=Math.min(ai,af.max_high)}af.reset_overview();af.request_redraw()}},go_to:function(ag){var ak=this,ac,af,ad=ag.split(":"),ai=ad[0],aj=ad[1];if(aj!==undefined){try{var ah=aj.split("-");ac=parseInt(ah[0].replace(/,/g,""),10);af=parseInt(ah[1].replace(/,/g,""),10)}catch(ae){return false}}ak.change_chrom(ai,ac,af)},move_fraction:function(ae){var ac=this;var ad=ac.high-ac.low;this.move_delta(ae*ad)},move_delta:function(ae){var ac=this;var ad=ac.high-ac.low;if(ac.low-ae<ac.max_low){ac.low=ac.max_low;ac.high=ac.max_low+ad}else{if(ac.high-ae>ac.max_high){ac.high=ac.max_high;ac.low=ac.max_high-ad}else{ac.high-=ae;ac.low-=ae}}ac.request_redraw()},add_track:function(ac){ac.view=this;ac.track_id=this.track_id_counter;this.tracks.push(ac);if(ac.init){ac.init()}ac.container_div.attr("id","track_"+ac.track_id);C(ac.container_div,".draghandle");this.track_id_counter+=1;this.num_tracks+=1;this.has_changes=true;this.update_intro_div()},add_label_track:function(ac){ac.view=this;this.label_tracks.push(ac)},remove_track:function(ad){this.has_changes=true;delete this.tracks[this.tracks.indexOf(ad)];this.num_tracks-=1;var ac=this;ad.container_div.fadeOut("slow",function(){$(this).remove();ac.update_intro_div()})},reset:function(){this.low=this.max_low;this.high=this.max_high;this.viewport_container.find(".yaxislabel").remove()},request_redraw:function(ak,ac,aj,ad){var ai=this,ag=(ad?[ad]:ai.tracks),ae;var ad;for(var ah=0;ah<ag.length;ah++){ad=ag[ah];ae=-1;for(var af=0;af<ai.tracks_to_be_redrawn.length;af++){if(ai.tracks_to_be_redrawn[af][0]===ad){ae=af;break}}if(ae<0){ai.tracks_to_be_redrawn.push([ad,ac,aj])}else{ai.tracks_to_be_redrawn[ah][1]=ac;ai.tracks_to_be_redrawn[ah][2]=aj}}requestAnimationFrame(function(){ai._redraw(ak)})},_redraw:function(am){var aj=this.low,af=this.high;if(aj<this.max_low){aj=this.max_low}if(af>this.max_high){af=this.max_high}var al=this.high-this.low;if(this.high!==0&&al<this.min_separation){af=aj+this.min_separation}this.low=Math.floor(aj);this.high=Math.ceil(af);this.resolution=Math.pow(z,Math.ceil(Math.log((this.high-this.low)/N)/Math.log(z)));this.zoom_res=Math.pow(s,Math.max(0,Math.ceil(Math.log(this.resolution,s)/Math.log(s))));var ac=(this.low/(this.max_high-this.max_low)*this.overview_viewport.width())||0;var ai=((this.high-this.low)/(this.max_high-this.max_low)*this.overview_viewport.width())||0;var an=13;this.overview_box.css({left:ac,width:Math.max(an,ai)}).show();if(ai<an){this.overview_box.css("left",ac-(an-ai)/2)}if(this.overview_highlight){this.overview_highlight.css({left:ac,width:ai})}this.update_location(this.low,this.high);if(!am){var ae,ad,ak;for(var ag=0,ah=this.tracks_to_be_redrawn.length;ag<ah;ag++){ae=this.tracks_to_be_redrawn[ag][0];ad=this.tracks_to_be_redrawn[ag][1];ak=this.tracks_to_be_redrawn[ag][2];if(ae&&ae.enabled){ae._draw(ad,ak)}}this.tracks_to_be_redrawn=[];for(ag=0,ah=this.label_tracks.length;ag<ah;ag++){this.label_tracks[ag]._draw()}}},zoom_in:function(ad,ae){if(this.max_high===0||this.high-this.low<this.min_separation){return}var af=this.high-this.low,ag=af/2+this.low,ac=(af/this.zoom_factor)/2;if(ad){ag=ad/this.viewport_container.width()*(this.high-this.low)+this.low}this.low=Math.round(ag-ac);this.high=Math.round(ag+ac);this.request_redraw()},zoom_out:function(){if(this.max_high===0){return}var ad=this.high-this.low,ae=ad/2+this.low,ac=(ad*this.zoom_factor)/2;this.low=Math.round(ae-ac);this.high=Math.round(ae+ac);this.request_redraw()},resize_window:function(){this.viewport_container.height(this.container.height()-this.top_container.height()-this.bottom_container.height());this.nav_container.width(this.container.width());this.request_redraw()},set_overview:function(ac){$.when(ac.get_overview_tile()).then(function(ad){view.overview_viewport.find(".track-tile").remove();view.overview_close.show();view.overview_viewport.append(ad.canvas);view.overview_highlight.show().height(ad.canvas.height());view.overview_viewport.height(ad.canvas.height()+view.overview_box.outerHeight());view.resize_window();if(view.overview_track){view.overview_track.set_is_overview(false)}view.overview_track=ac;ac.set_is_overview(true)});view.has_changes=true},reset_overview:function(){this.overview_viewport.find(".track-tile").remove();this.overview_viewport.height(this.default_overview_height);this.overview_box.height(this.default_overview_height);this.overview_close.hide();this.overview_highlight.hide();view.resize_window();if(view.overview_track){view.overview_track.set_is_overview(false)}view.overview_track=null}});var o=function(ae,ai){this.track=ae;this.name=ai.name;this.params=[];var ap=ai.params;for(var af=0;af<ap.length;af++){var ak=ap[af],ad=ak.name,ao=ak.label,ag=unescape(ak.html),aq=ak.value,am=ak.type;if(am==="number"){this.params[this.params.length]=new g(ad,ao,ag,aq,ak.min,ak.max)}else{if(am=="select"){this.params[this.params.length]=new K(ad,ao,ag,aq)}else{console.log("WARNING: unrecognized tool parameter type:",ad,am)}}}this.parent_div=$("<div/>").addClass("dynamic-tool").hide();this.parent_div.bind("drag",function(at){at.stopPropagation()}).click(function(at){at.stopPropagation()}).bind("dblclick",function(at){at.stopPropagation()});var an=$("<div class='tool-name'>").appendTo(this.parent_div).text(this.name);var al=this.params;var aj=this;$.each(this.params,function(au,ax){var aw=$("<div>").addClass("param-row").appendTo(aj.parent_div);var at=$("<div>").addClass("param-label").text(ax.label).appendTo(aw);var av=$("<div/>").addClass("slider").html(ax.html).appendTo(aw);av.find(":input").val(ax.value);$("<div style='clear: both;'/>").appendTo(aw)});this.parent_div.find("input").click(function(){$(this).select()});var ar=$("<div>").addClass("param-row").appendTo(this.parent_div);var ah=$("<input type='submit'>").attr("value","Run on complete dataset").appendTo(ar);var ac=$("<input type='submit'>").attr("value","Run on visible region").css("margin-left","3em").appendTo(ar);var aj=this;ac.click(function(){aj.run_on_region()});ah.click(function(){aj.run_on_dataset()})};n(o.prototype,{get_param_values_dict:function(){var ac={};this.parent_div.find(":input").each(function(){var ad=$(this).attr("name"),ae=$(this).val();ac[ad]=JSON.stringify(ae)});return ac},get_param_values:function(){var ad=[];var ac={};this.parent_div.find(":input").each(function(){var ae=$(this).attr("name"),af=$(this).val();if(ae){ad[ad.length]=af}});return ad},run_on_dataset:function(){var ac=this;ac.run({dataset_id:this.track.original_dataset_id,tool_id:ac.name},null,function(ad){show_modal(ac.name+" is Running",ac.name+" is running on the complete dataset. Tool outputs are in dataset's history.",{Close:hide_modal})})},run_on_region:function(){var ac={dataset_id:this.track.original_dataset_id,chrom:this.track.view.chrom,low:this.track.view.low,high:this.track.view.high,tool_id:this.name},ae=this.track,ad=ac.tool_id+ae.tool_region_and_parameters_str(ac.chrom,ac.low,ac.high),af;if(ae instanceof e){af=new R(ad,view,ae.hda_ldda,undefined,{},{},ae);af.change_mode(ae.mode)}this.track.add_track(af);af.content_div.text("Starting job.");this.run(ac,af,function(ag){af.dataset_id=ag.dataset_id;af.content_div.text("Running job.");af.init()})},run:function(ad,ae,af){$.extend(ad,this.get_param_values_dict());var ac=function(){$.getJSON(rerun_tool_url,ad,function(ag){if(ag==="no converter"){ae.container_div.addClass("error");ae.content_div.text(G)}else{if(ag.error){ae.container_div.addClass("error");ae.content_div.text(v+ag.message)}else{if(ag==="pending"){ae.container_div.addClass("pending");ae.content_div.text("Converting input data so that it can be used quickly with tool.");setTimeout(ac,2000)}else{af(ag)}}}})};ac()}});var K=function(ad,ac,ae,af){this.name=ad;this.label=ac;this.html=ae;this.value=af};var g=function(ae,ad,ag,ah,af,ac){K.call(this,ae,ad,ag,ah);this.min=af;this.max=ac};var h=function(ad,ac,ae,af){this.name=ad;this.index=ac;this.tool_id=ae;this.tool_exp_name=af};var S=function(ad,ac,ae,af){h.call(this,ad,ac,ae,af);this.low=-Number.MAX_VALUE;this.high=Number.MAX_VALUE;this.min=Number.MAX_VALUE;this.max=-Number.MAX_VALUE;this.container=null;this.slider=null;this.slider_label=null};n(S.prototype,{applies_to:function(ac){if(ac.length>this.index){return true}return false},keep:function(ac){if(!this.applies_to(ac)){return true}var ad=parseFloat(ac[this.index]);return(isNaN(ad)||(ad>=this.low&&ad<=this.high))},update_attrs:function(ad){var ac=false;if(!this.applies_to(ad)){return ac}if(ad[this.index]<this.min){this.min=Math.floor(ad[this.index]);ac=true}if(ad[this.index]>this.max){this.max=Math.ceil(ad[this.index]);ac=true}return ac},update_ui_elt:function(){if(this.min!=this.max){this.container.show()}else{this.container.hide()}var ae=function(ah,af){var ag=af-ah;return(ag<=2?0.01:1)};var ad=this.slider.slider("option","min"),ac=this.slider.slider("option","max");if(this.min<ad||this.max>ac){this.slider.slider("option","min",this.min);this.slider.slider("option","max",this.max);this.slider.slider("option","step",ae(this.min,this.max));this.slider.slider("option","values",[this.min,this.max])}}});var X=function(am,at){this.track=am;this.filters=[];for(var an=0;an<at.length;an++){var ao=at[an],au=ao.name,ac=ao.type,af=ao.index,ar=ao.tool_id,aq=ao.tool_exp_name;if(ac==="int"||ac==="float"){this.filters[an]=new S(au,af,ar,aq)}else{console.log("ERROR: unsupported filter: ",au,ac)}}var ag=function(av,aw,ax){av.click(function(){var ay=aw.text();max=parseFloat(ax.slider("option","max")),input_size=(max<=1?4:max<=1000000?max.toString().length:6),multi_value=false;if(ax.slider("option","values")){input_size=2*input_size+1;multi_value=true}aw.text("");$("<input type='text'/>").attr("size",input_size).attr("maxlength",input_size).attr("value",ay).appendTo(aw).focus().select().click(function(az){az.stopPropagation()}).blur(function(){$(this).remove();aw.text(ay)}).keyup(function(aD){if(aD.keyCode===27){$(this).trigger("blur")}else{if(aD.keyCode===13){var aB=ax.slider("option","min"),az=ax.slider("option","max"),aC=function(aE){return(isNaN(aE)||aE>az||aE<aB)},aA=$(this).val();if(!multi_value){aA=parseFloat(aA);if(aC(aA)){alert("Parameter value must be in the range ["+aB+"-"+az+"]");return $(this)}}else{aA=aA.split("-");aA=[parseFloat(aA[0]),parseFloat(aA[1])];if(aC(aA[0])||aC(aA[1])){alert("Parameter value must be in the range ["+aB+"-"+az+"]");return $(this)}}ax.slider((multi_value?"values":"value"),aA)}}})})};this.parent_div=$("<div/>").addClass("filters").hide();this.parent_div.bind("drag",function(av){av.stopPropagation()}).click(function(av){av.stopPropagation()}).bind("dblclick",function(av){av.stopPropagation()}).bind("keydown",function(av){av.stopPropagation()});var ap=$("<div/>").addClass("sliders").appendTo(this.parent_div);var ak=this;$.each(this.filters,function(ay,aA){aA.container=$("<div/>").addClass("slider-row").appendTo(ap);var az=$("<div/>").addClass("elt-label").appendTo(aA.container);var ax=$("<span/>").addClass("slider-name").text(aA.name+"  ").appendTo(az);var aw=$("<span/>");var aC=$("<span/>").addClass("slider-value").appendTo(az).append("[").append(aw).append("]");var av=$("<div/>").addClass("slider").appendTo(aA.container);aA.control_element=$("<div/>").attr("id",aA.name+"-filter-control").appendTo(av);var aB=[0,0];aA.control_element.slider({range:true,min:Number.MAX_VALUE,max:-Number.MIN_VALUE,values:[0,0],slide:function(aE,aF){var aD=aF.values;aw.text(aD[0]+"-"+aD[1]);aA.low=aD[0];aA.high=aD[1];ak.track.request_draw(true,true)},change:function(aD,aE){aA.control_element.slider("option","slide").call(aA.control_element,aD,aE)}});aA.slider=aA.control_element;aA.slider_label=aw;ag(aC,aw,aA.control_element);$("<div style='clear: both;'/>").appendTo(aA.container)});if(this.filters.length!==0){var ah=$("<div/>").addClass("param-row").appendTo(ap);var aj=$("<input type='submit'/>").attr("value","Run on complete dataset").appendTo(ah);var ae=this;aj.click(function(){ae.run_on_dataset()})}var al=$("<div/>").addClass("display-controls").appendTo(this.parent_div),ai=$("<span/>").addClass("elt-label").text("Transparency:").appendTo(al),ad=$("<select/>").attr("name","alpha_dropdown").appendTo(al);this.alpha_filter=null;$("<option/>").attr("value",-1).text("== None ==").appendTo(ad);for(var an=0;an<this.filters.length;an++){$("<option/>").attr("value",an).text(this.filters[an].name).appendTo(ad)}ad.change(function(){$(this).children("option:selected").each(function(){var av=parseInt($(this).val());ak.alpha_filter=(av>=0?ak.filters[av]:null);ak.track.request_draw(true,true)})});$("<div style='clear: both;'/>").appendTo(this.parent_div)};n(X.prototype,{reset_filters:function(){for(var ac=0;ac<this.filters.length;ac++){filter=this.filters[ac];filter.slider.slider("option","values",[filter.min,filter.max])}this.alpha_filter=null},run_on_dataset:function(){var ak=function(ao,am,an){if(!(am in ao)){ao[am]=an}return ao[am]};var ae={},ac,ad,af;for(var ag=0;ag<this.filters.length;ag++){ac=this.filters[ag];if(ac.tool_id){if(ac.min!=ac.low){ad=ak(ae,ac.tool_id,[]);ad[ad.length]=ac.tool_exp_name+" >= "+ac.low}if(ac.max!=ac.high){ad=ak(ae,ac.tool_id,[]);ad[ad.length]=ac.tool_exp_name+" <= "+ac.high}}}var ai=[];for(var al in ae){ai[ai.length]=[al,ae[al]]}var aj=ai.length;(function ah(at,ap){var an=ap[0],ao=an[0],ar=an[1],aq="("+ar.join(") and (")+")",am={cond:aq,input:at,target_dataset_id:at,tool_id:ao},ap=ap.slice(1);$.getJSON(run_tool_url,am,function(au){if(au.error){show_modal("Filter Dataset","Error running tool "+ao,{Close:hide_modal})}else{if(ap.length===0){show_modal("Filtering Dataset","Filter(s) are running on the complete dataset. Outputs are in dataset's history.",{Close:hide_modal})}else{ah(au.dataset_id,ap)}}})})(this.track.dataset_id,ai)}});var L=function(ad,ac){I.AlphaGenerator.call(this,ac);this.filter=ad};L.prototype.gen_alpha=function(ac){if(this.filter.high===Number.MAX_VALUE||this.filter.low===-Number.MAX_VALUE||this.filter.low===this.filter.high){return this.default_alpha}return((parseFloat(ac[this.filter.index])-this.filter.low)/(this.filter.high-this.filter.low))};var W=function(ac){this.track=ac.track;this.params=ac.params;this.values={};if(ac.saved_values){this.restore_values(ac.saved_values)}this.onchange=ac.onchange};n(W.prototype,{restore_values:function(ac){var ad=this;$.each(this.params,function(ae,af){if(ac[af.key]!==undefined){ad.values[af.key]=ac[af.key]}else{ad.values[af.key]=af.default_value}})},build_form:function(){var ad=this;var ac=$("<div />");$.each(this.params,function(ah,af){if(!af.hidden){var ae="param_"+ah;var am=$("<div class='form-row' />").appendTo(ac);am.append($("<label />").attr("for",ae).text(af.label+":"));if(af.type==="bool"){am.append($('<input type="checkbox" />').attr("id",ae).attr("name",ae).attr("checked",ad.values[af.key]))}else{if(af.type==="color"){var aj=ad.values[af.key];var ai=$("<input />").attr("id",ae).attr("name",ae).val(aj);var ak=$("<div class='tipsy tipsy-north' style='position: absolute;' />").hide();var ag=$("<div style='background-color: black; padding: 10px;'></div>").appendTo(ak);var al=$("<div/>").appendTo(ag).farbtastic({width:100,height:100,callback:ai,color:aj});$("<div />").append(ai).append(ak).appendTo(am).bind("click",function(an){ak.css({left:$(this).position().left+($(ai).width()/2)-60,top:$(this).position().top+$(this.height)}).show();$(document).bind("click.color-picker",function(){ak.hide();$(document).unbind("click.color-picker")});an.stopPropagation()})}else{am.append($("<input />").attr("id",ae).attr("name",ae).val(ad.values[af.key]))}}}});return ac},update_from_form:function(ac){var ae=this;var ad=false;$.each(this.params,function(af,ah){if(!ah.hidden){var ai="param_"+af;var ag=ac.find("#"+ai).val();if(ah.type==="float"){ag=parseFloat(ag)}else{if(ah.type==="int"){ag=parseInt(ag)}else{if(ah.type==="bool"){ag=ac.find("#"+ai).is(":checked")}}}if(ag!==ae.values[ah.key]){ae.values[ah.key]=ag;ad=true}}});if(ad){this.onchange()}}});var b=function(ae,ad,ac,af){this.index=ae;this.low=ae*N*ad;this.high=(ae+1)*N*ad;this.resolution=ad;this.canvas=$("<div class='track-tile'/>").append(ac);this.data=af;this.stale=false};var l=function(ae,ad,ac,af,ag){b.call(this,ae,ad,ac,af);this.max_val=ag};var M=function(ae,ad,ac,ag,af){b.call(this,ae,ad,ac,ag);this.message=af};var j=function(ad,ac,ag,ae,af){this.name=ad;this.view=ac;this.parent_element=ag;this.data_url=(ae?ae:default_data_url);this.data_url_extra_params={};this.data_query_wait=(af?af:H);this.dataset_check_url=converted_datasets_state_url;this.container_div=$("<div />").addClass("track").css("position","relative");if(!this.hidden){this.header_div=$("<div class='track-header' />").appendTo(this.container_div);if(this.view.editor){this.drag_div=$("<div class='draghandle' />").appendTo(this.header_div)}this.name_div=$("<div class='menubutton popup' />").appendTo(this.header_div);this.name_div.text(this.name);this.name_div.attr("id",this.name.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9\-]/g,"").toLowerCase())}this.content_div=$("<div class='track-content'>").appendTo(this.container_div);this.parent_element.append(this.container_div)};n(j.prototype,{get_type:function(){if(this instanceof Y){return"LabelTrack"}else{if(this instanceof x){return"ReferenceTrack"}else{if(this instanceof k){return"LineTrack"}else{if(this instanceof T){return"ReadTrack"}else{if(this instanceof R){return"ToolDataFeatureTrack"}else{if(this instanceof Q){return"VcfTrack"}else{if(this instanceof e){return"FeatureTrack"}}}}}}}return""},init:function(){var ac=this;ac.enabled=false;ac.tile_cache.clear();ac.data_manager.clear();ac.initial_canvas=undefined;ac.content_div.css("height","auto");ac.container_div.removeClass("nodata error pending");if(!ac.dataset_id){return}$.getJSON(converted_datasets_state_url,{hda_ldda:ac.hda_ldda,dataset_id:ac.dataset_id,chrom:ac.view.chrom},function(ad){if(!ad||ad==="error"||ad.kind==="error"){ac.container_div.addClass("error");ac.content_div.text(m);if(ad.message){var af=ac.view.tracks.indexOf(ac);var ae=$(" <a href='javascript:void(0);'></a>").text("View error").click(function(){show_modal("Trackster Error","<pre>"+ad.message+"</pre>",{Close:hide_modal})});ac.content_div.append(ae)}}else{if(ad==="no converter"){ac.container_div.addClass("error");ac.content_div.text(G)}else{if(ad==="no data"||(ad.data!==undefined&&(ad.data===null||ad.data.length===0))){ac.container_div.addClass("nodata");ac.content_div.text(B)}else{if(ad==="pending"){ac.container_div.addClass("pending");ac.content_div.text(q);setTimeout(function(){ac.init()},ac.data_query_wait)}else{if(ad.status==="data"){if(ad.valid_chroms){ac.valid_chroms=ad.valid_chroms;ac.make_name_popup_menu()}ac.content_div.text(V);if(ac.view.chrom){ac.content_div.text("");ac.content_div.css("height",ac.height_px+"px");ac.enabled=true;$.when(ac.predraw_init()).done(function(){ac.container_div.removeClass("nodata error pending");ac.request_draw()})}}}}}}})},predraw_init:function(){},update_name:function(ac){this.old_name=this.name;this.name=ac;this.name_div.text(this.name)},revert_name:function(){this.name=this.old_name;this.name_div.text(this.name)}});var J=function(aj,ah,ak){var ad=this,al=ad.view;this.filters_manager=(aj!==undefined?new X(this,aj):undefined);this.filters_available=false;this.filters_visible=false;this.tool=(ah!==undefined&&obj_length(ah)>0?new o(this,ah):undefined);this.is_overview=false;this.parent_track=ak;this.child_tracks=[];if(ad.hidden){return}if(this.parent_track){this.header_div.find(".draghandle").removeClass("draghandle").addClass("child-track-icon").addClass("icon-button");this.parent_element.addClass("child-track");this.tool=undefined}ad.child_tracks_container=$("<div/>").addClass("child-tracks-container").hide();ad.container_div.append(ad.child_tracks_container);if(this.filters_manager){this.filters_div=this.filters_manager.parent_div;this.header_div.after(this.filters_div)}if(this.tool){this.dynamic_tool_div=this.tool.parent_div;this.header_div.after(this.dynamic_tool_div)}if(ad.display_modes!==undefined){if(ad.mode_div===undefined){ad.mode_div=$("<div class='right-float menubutton popup' />").appendTo(ad.header_div);var ae=(ad.track_config&&ad.track_config.values.mode?ad.track_config.values.mode:ad.display_modes[0]);ad.mode=ae;ad.mode_div.text(ae);var ac={};for(var af=0,ai=ad.display_modes.length;af<ai;af++){var ag=ad.display_modes[af];ac[ag]=function(am){return function(){ad.change_mode(am)}}(ag)}make_popupmenu(ad.mode_div,ac)}else{ad.mode_div.hide()}}this.make_name_popup_menu()};n(J.prototype,j.prototype,{change_mode:function(ad){var ac=this;ac.mode_div.text(ad);ac.mode=ad;ac.track_config.values.mode=ad;ac.tile_cache.clear();ac.request_draw()},make_name_popup_menu:function(){var ad=this;var ac={};ac[(this.is_overview?"Hide overview":"Set as overview")]=function(){if(ad.is_overview){ad.view.reset_overview()}else{ad.view.set_overview(ad)}};ac["Edit configuration"]=function(){var aj=function(){hide_modal();$(window).unbind("keypress.check_enter_esc")},ah=function(){ad.track_config.update_from_form($(".dialog-box"));hide_modal();$(window).unbind("keypress.check_enter_esc")},ai=function(ak){if((ak.keyCode||ak.which)===27){aj()}else{if((ak.keyCode||ak.which)===13){ah()}}};$(window).bind("keypress.check_enter_esc",ai);show_modal("Configure Track",ad.track_config.build_form(),{Cancel:aj,OK:ah})};if(ad.filters_available>0){var ag=(ad.filters_div.is(":visible")?"Hide filters":"Show filters");ac[ag]=function(){ad.filters_visible=(ad.filters_div.is(":visible"));if(ad.filters_visible){ad.filters_manager.reset_filters()}ad.filters_div.toggle();ad.make_name_popup_menu()}}if(ad.tool){var ag=(ad.dynamic_tool_div.is(":visible")?"Hide tool":"Show tool");ac[ag]=function(){if(!ad.dynamic_tool_div.is(":visible")){ad.update_name(ad.name+ad.tool_region_and_parameters_str())}else{menu_option_text="Show dynamic tool";ad.revert_name()}ad.dynamic_tool_div.toggle();ad.make_name_popup_menu()}}if(ad.valid_chroms){ac["List chrom/contigs with data"]=function(){show_modal("Chrom/contigs with data","<p>"+ad.valid_chroms.join("<br/>")+"</p>",{Close:function(){hide_modal()}})}}var ae=view;var af=function(){$("#no-tracks").show()};if(this.parent_track){ae=this.parent_track;af=function(){}}ac.Remove=function(){ae.remove_track(ad);if(ae.num_tracks===0){af()}};make_popupmenu(ad.name_div,ac)},set_is_overview:function(ac){this.is_overview=ac;this.make_name_popup_menu()},get_overview_tile:function(){var ac=this;view=ac.view,resolution=Math.pow(z,Math.ceil(Math.log((view.max_high-view.max_low)/N)/Math.log(z))),view_width=view.container.width(),w_scale=view_width/(view.max_high-view.max_low),overview_tile=$.Deferred();$.when(ac.data_manager.get_data(view.max_low,view.max_high,"Auto",resolution,ac.data_url_extra_params)).then(function(ad){var af=ac._gen_tile_cache_key(view_width,w_scale,0),ah=ac.tile_cache.get(af);if(!ah){ah=ac.draw_tile(ad,resolution,0,w_scale);ac.tile_cache.set(af,ah)}var ak=$(ah.canvas.find("canvas")),ag=ak.clone(),aj=ak.get(0).getContext("2d"),ae=ag.get(0).getContext("2d"),ai=aj.getImageData(0,0,aj.canvas.width,aj.canvas.height);ae.putImageData(ai,-ac.left_offset,(ah.data.dataset_type==="summary_tree"?P:0));new_tile=new b(-1,resolution,ag);overview_tile.resolve(new_tile)});return overview_tile},_gen_tile_cache_key:function(ad,ae,ac){return ad+"_"+ae+"_"+ac},request_draw:function(ad,ac){this.view.request_redraw(false,ad,ac,this)},_draw:function(ae,an){if(!this.dataset_id){return}var am=this.view.low,ai=this.view.high,ak=ai-am,af=this.view.container.width(),aq=af/ak,ah=this.view.resolution,ap=$("<div style='position: relative;'></div>");if(!an){this.content_div.children().remove()}this.content_div.append(ap);this.max_height=0;var ad=Math.floor(am/ah/N);var al=true;var ao=[];var ac=0;while((ad*N*ah)<ai){tile=this.draw_helper(ae,af,ad,ah,ap,aq);if(tile){ao.push(tile)}else{al=false}ad+=1;ac++}var ag=this;if(al){ag.postdraw_actions(ao,af,aq,an)}for(var aj=0;aj<this.child_tracks.length;aj++){this.child_tracks[aj].request_draw(ae,an)}},postdraw_actions:function(ag,ah,ai,ac){var ae=this;var af=false;for(var ad=0;ad<ag.length;ad++){if(ag[ad].message){af=true;break}}if(af){for(var ad=0;ad<ag.length;ad++){tile=ag[ad];if(!tile.message){tile.canvas.css("padding-top",A)}}}},draw_helper:function(ad,ae,af,ai,ao,at,ap,aj){var ag=this,an=this._gen_tile_cache_key(ae,at,af),ak=af*N*ai,ar=ak+N*ai;var al=(ad?undefined:ag.tile_cache.get(an));if(al){ag.show_tile(al,ao,at);return al}var am=function(au){return("isResolved" in au)};var ah=true;var ac=ag.data_manager.get_data(ak,ar,ag.mode,ai,ag.data_url_extra_params);if(am(ac)){ah=false}var aq;if(view.reference_track&&at>view.canvas_manager.char_width_px){aq=view.reference_track.data_manager.get_data(ak,ar,ag.mode,ai,view.reference_track.data_url_extra_params);if(am(aq)){ah=false}}if(ah){n(ac,aj);var al=ag.draw_tile(ac,ai,af,at,aq);ag.tile_cache.set(an,al);if(al!==undefined){ag.show_tile(al,ao,at)}return al}$.when(ac,aq).then(function(){view.request_redraw()});return null},show_tile:function(aj,al,am){var ae=this,ad=aj.canvas,ai=ad;if(aj.message){var an=$("<div/>"),ak=$("<div/>").addClass("tile-message").text(aj.message).css({height:A-1,width:aj.canvas.width}).appendTo(an),ag=$("<a href='javascript:void(0);'/>").addClass("icon more-down").appendTo(ak),ac=$("<a href='javascript:void(0);'/>").addClass("icon more-across").appendTo(ak);an.append(ad);ai=an;ag.click(function(){aj.stale=true;ae.data_manager.get_more_data(aj.low,aj.high,ae.mode,aj.resolution,{},ae.data_manager.DEEP_DATA_REQ);ae.request_draw()}).dblclick(function(ao){ao.stopPropagation()});ac.click(function(){aj.stale=true;ae.data_manager.get_more_data(aj.low,aj.high,ae.mode,aj.resolution,{},ae.data_manager.BROAD_DATA_REQ);ae.request_draw()}).dblclick(function(ao){ao.stopPropagation()})}var ah=this.view.high-this.view.low,af=(aj.low-this.view.low)*am;if(this.left_offset){af-=this.left_offset}ai.css({position:"absolute",top:0,left:af,height:""});al.append(ai);ae.max_height=Math.max(ae.max_height,ai.height());ae.content_div.css("height",ae.max_height+"px");al.children().css("height",ae.max_height+"px")},tool_region_and_parameters_str:function(ae,ac,af){var ad=this,ag=(ae!==undefined&&ac!==undefined&&af!==undefined?ae+":"+ac+"-"+af:"all");return" - region=["+ag+"], parameters=["+ad.tool.get_param_values().join(", ")+"]"},add_track:function(ac){ac.track_id=this.track_id+"_"+this.child_tracks.length;ac.container_div.attr("id","track_"+ac.track_id);this.child_tracks_container.append(ac.container_div);C(ac.container_div,".child-track-icon");if(!$(this.child_tracks_container).is(":visible")){this.child_tracks_container.show()}this.child_tracks.push(ac);this.view.has_changes=true},remove_track:function(ac){ac.container_div.fadeOut("slow",function(){$(this).remove()})}});var Y=function(ac,ad){this.hidden=true;j.call(this,null,ac,ad);this.container_div.addClass("label-track")};n(Y.prototype,j.prototype,{_draw:function(){var ae=this.view,af=ae.high-ae.low,ai=Math.floor(Math.pow(10,Math.floor(Math.log(af)/Math.log(10)))),ac=Math.floor(ae.low/ai)*ai,ag=this.view.container.width(),ad=$("<div style='position: relative; height: 1.3em;'></div>");while(ac<ae.high){var ah=(ac-ae.low)/af*ag;ad.append($("<div class='label'>"+commatize(ac)+"</div>").css({position:"absolute",left:ah-1}));ac+=ai}this.content_div.children(":first").remove();this.content_div.append(ad)}});var x=function(ac){this.hidden=true;j.call(this,null,ac,ac.top_labeltrack);J.call(this);ac.reference_track=this;this.left_offset=200;this.height_px=12;this.container_div.addClass("reference-track");this.content_div.css("background","none");this.content_div.css("min-height","0px");this.content_div.css("border","none");this.data_url=reference_url;this.data_url_extra_params={dbkey:ac.dbkey};this.data_manager=new E(y,this,false);this.tile_cache=new c(r)};n(x.prototype,J.prototype,{draw_tile:function(ak,ah,ad,am){var ag=this,ae=N*ah;if(am>this.view.canvas_manager.char_width_px){if(ak===null){ag.content_div.css("height","0px");return}var af=this.view.canvas_manager.new_canvas();var al=af.getContext("2d");af.width=Math.ceil(ae*am+ag.left_offset);af.height=ag.height_px;al.font=al.canvas.manager.default_font;al.textAlign="center";for(var ai=0,aj=ak.length;ai<aj;ai++){var ac=Math.round(ai*am);al.fillText(ak[ai],ac+ag.left_offset,10)}return new b(ad,ah,af,ak)}this.content_div.css("height","0px")}});var k=function(ag,ae,ah,ac,af){var ad=this;this.display_modes=["Histogram","Line","Filled","Intensity"];this.mode="Histogram";j.call(this,ag,ae,ae.viewport_container);J.call(this);this.min_height_px=16;this.max_height_px=400;this.height_px=80;this.hda_ldda=ah;this.dataset_id=ac;this.original_dataset_id=ac;this.data_manager=new O(y,this);this.tile_cache=new c(r);this.track_config=new W({track:this,params:[{key:"color",label:"Color",type:"color",default_value:"black"},{key:"min_value",label:"Min Value",type:"float",default_value:undefined},{key:"max_value",label:"Max Value",type:"float",default_value:undefined},{key:"mode",type:"string",default_value:this.mode,hidden:true},{key:"height",type:"int",default_value:this.height_px,hidden:true}],saved_values:af,onchange:function(){ad.vertical_range=ad.prefs.max_value-ad.prefs.min_value;$("#linetrack_"+ad.track_id+"_minval").text(ad.prefs.min_value);$("#linetrack_"+ad.track_id+"_maxval").text(ad.prefs.max_value);ad.tile_cache.clear();ad.request_draw()}});this.prefs=this.track_config.values;this.height_px=this.track_config.values.height;this.vertical_range=this.track_config.values.max_value-this.track_config.values.min_value;this.add_resize_handle()};n(k.prototype,J.prototype,{add_resize_handle:function(){var ac=this;var af=false;var ae=false;var ad=$("<div class='track-resize'>");$(ac.container_div).hover(function(){af=true;ad.show()},function(){af=false;if(!ae){ad.hide()}});ad.hide().bind("dragstart",function(ag,ah){ae=true;ah.original_height=$(ac.content_div).height()}).bind("drag",function(ah,ai){var ag=Math.min(Math.max(ai.original_height+ai.deltaY,ac.min_height_px),ac.max_height_px);$(ac.content_div).css("height",ag);ac.height_px=ag;ac.request_draw(true)}).bind("dragend",function(ag,ah){ac.tile_cache.clear();ae=false;if(!af){ad.hide()}ac.track_config.values.height=ac.height_px}).appendTo(ac.container_div)},predraw_init:function(){var ac=this,ad=ac.view.tracks.indexOf(ac);ac.vertical_range=undefined;return $.getJSON(ac.data_url,{stats:true,chrom:ac.view.chrom,low:null,high:null,hda_ldda:ac.hda_ldda,dataset_id:ac.dataset_id},function(ae){ac.container_div.addClass("line-track");var ag=ae.data;if(isNaN(parseFloat(ac.prefs.min_value))||isNaN(parseFloat(ac.prefs.max_value))){ac.prefs.min_value=ag.min;ac.prefs.max_value=ag.max;$("#track_"+ad+"_minval").val(ac.prefs.min_value);$("#track_"+ad+"_maxval").val(ac.prefs.max_value)}ac.vertical_range=ac.prefs.max_value-ac.prefs.min_value;ac.total_frequency=ag.total_frequency;ac.container_div.find(".yaxislabel").remove();var ah=$("<div />").addClass("yaxislabel").attr("id","linetrack_"+ad+"_minval").text(u(ac.prefs.min_value));var af=$("<div />").addClass("yaxislabel").attr("id","linetrack_"+ad+"_maxval").text(u(ac.prefs.max_value));af.css({position:"absolute",top:"24px",left:"10px"});af.prependTo(ac.container_div);ah.css({position:"absolute",bottom:"2px",left:"10px"});ah.prependTo(ac.container_div)})},draw_tile:function(am,ag,ad,al){if(this.vertical_range===undefined){return}var ah=ad*N*ag,af=N*ag,ac=Math.ceil(af*al),aj=this.height_px;var ae=this.view.canvas_manager.new_canvas();ae.width=ac,ae.height=aj;var ak=ae.getContext("2d");var ai=new I.LinePainter(am.data,ah,ah+af,this.prefs,this.mode);ai.draw(ak,ac,aj);return new b(ad,ag,ae,am.data)}});var e=function(ac,ah,ag,ak,aj,ae,af,ai){var ad=this;this.display_modes=["Auto","Histogram","Dense","Squish","Pack"];this.track_config=new W({track:this,params:[{key:"block_color",label:"Block color",type:"color",default_value:"#444"},{key:"label_color",label:"Label color",type:"color",default_value:"black"},{key:"show_counts",label:"Show summary counts",type:"bool",default_value:true},{key:"mode",type:"string",default_value:this.mode,hidden:true},],saved_values:aj,onchange:function(){ad.tile_cache.clear();ad.request_draw()}});this.prefs=this.track_config.values;j.call(this,ac,ah,ah.viewport_container);J.call(this,ae,af,ai);this.height_px=0;this.container_div.addClass("feature-track");this.hda_ldda=ag;this.dataset_id=ak;this.original_dataset_id=ak;this.show_labels_scale=0.001;this.showing_details=false;this.summary_draw_height=30;this.inc_slots={};this.start_end_dct={};this.tile_cache=new c(d);this.data_manager=new O(20,this);this.left_offset=200;this.painter=I.LinkedFeaturePainter};n(e.prototype,J.prototype,{postdraw_actions:function(ar,ac,at,aq){J.prototype.postdraw_actions.call(this,ar,aq);var af=this;if(aq){var ah=af.content_div.children();var ai=false;for(var ag=ah.length-1,am=0;ag>=am;ag--){var ae=$(ah[ag]);if(ai){ae.remove()}else{if(ae.children().length!==0){ai=true}}}}if(af.mode=="Histogram"){var al=-1;for(var ag=0;ag<ar.length;ag++){var ap=ar[ag].max_val;if(ap>al){al=ap}}for(var ag=0;ag<ar.length;ag++){var ao=ar[ag];if(ao.max_val!==al){ao.canvas.remove();af.draw_helper(true,ac,ao.index,ao.resolution,ao.canvas.parent(),at,[],{max:al})}}}if(af.filters_manager){var ad=af.filters_manager.filters;for(var ak=0;ak<ad.length;ak++){ad[ak].update_ui_elt()}var aj=false,an;for(var ag=0;ag<ar.length;ag++){if(ar[ag].data.length){an=ar[ag].data[0];for(var ak=0;ak<ad.length;ak++){if(ad[ak].applies_to(an)){aj=true;break}}}}if(af.filters_available!==aj){af.filters_available=aj;if(!af.filters_available){af.filters_div.hide()}af.make_name_popup_menu()}}},update_auto_mode:function(ac){if(this.mode=="Auto"){if(ac=="no_detail"){ac="feature spans"}else{if(ac=="summary_tree"){ac="coverage histogram"}}this.mode_div.text("Auto ("+ac+")")}},incremental_slots:function(ag,ad,af){var ae=this.view.canvas_manager.dummy_context,ac=this.inc_slots[ag];if(!ac||(ac.mode!==af)){ac=new (p.FeatureSlotter)(ag,af==="Pack",w,function(ah){return ae.measureText(ah)});ac.mode=af;this.inc_slots[ag]=ac}return ac.slot_features(ad)},get_summary_tree_data:function(ag,aj,ae,ar){if(ar>ae-aj){ar=ae-aj}var an=Math.floor((ae-aj)/ar),aq=[],af=0;var ah=0,ai=0,am,ap=0,ak=[],ao,al;var ad=function(av,au,aw,at){av[0]=au+aw*at;av[1]=au+(aw+1)*at};while(ap<ar&&ah!==ag.length){var ac=false;for(;ap<ar&&!ac;ap++){ad(ak,aj,ap,an);for(ai=ah;ai<ag.length;ai++){am=ag[ai].slice(1,3);if(is_overlap(am,ak)){ac=true;break}}if(ac){break}}data_start_index=ai;aq[aq.length]=ao=[ak[0],0];for(;ai<ag.length;ai++){am=ag[ai].slice(1,3);if(is_overlap(am,ak)){ao[1]++}else{break}}if(ao[1]>af){af=ao[1]}ap++}return{max:af,delta:an,data:aq}},draw_tile:function(ap,ay,aC,al,af){var av=this,aE=aC*N*ay,ad=(aC+1)*N*ay,ar=ad-aE,aw=Math.ceil(ar*al),at=this.mode,aI=25,ag=this.left_offset,aq,ah;if(at==="Auto"){if(ap.dataset_type==="summary_tree"){at=ap.dataset_type}else{if(ap.extra_info==="no_detail"){at="no_detail"}else{var aH=ap.data;if(this.view.high-this.view.low>F){at="Squish"}else{at="Pack"}}}this.update_auto_mode(at)}if(at==="summary_tree"||at==="Histogram"){ah=this.summary_draw_height;this.container_div.find(".yaxislabel").remove();var ac=$("<div />").addClass("yaxislabel");ac.text(ap.max);ac.css({position:"absolute",top:"24px",left:"10px",color:this.prefs.label_color});ac.prependTo(this.container_div);var ae=this.view.canvas_manager.new_canvas();ae.width=aw+ag;ae.height=ah+P;if(ap.dataset_type!="summary_tree"){var am=this.get_summary_tree_data(ap.data,aE,ad,200);if(ap.max){am.max=ap.max}ap=am}var aF=new I.SummaryTreePainter(ap,aE,ad,this.prefs);var ax=ae.getContext("2d");ax.translate(ag,P);aF.draw(ax,aw,ah);return new l(aC,ay,ae,ap.data,ap.max)}var aq,aj=1;if(at==="no_detail"||at==="Squish"||at==="Pack"){aj=this.incremental_slots(al,ap.data,at);aq=this.inc_slots[al].slots}var ak=[];if(ap.data){var an=this.filters_manager.filters;for(var az=0,aB=ap.data.length;az<aB;az++){var ai=ap.data[az];var aA=false;var ao;for(var aD=0,aG=an.length;aD<aG;aD++){ao=an[aD];ao.update_attrs(ai);if(!ao.keep(ai)){aA=true;break}}if(!aA){ak.push(ai)}}}var au=(this.filters_manager.alpha_filter?new L(this.filters_manager.alpha_filter):null);var aF=new (this.painter)(ak,aE,ad,this.prefs,at,au,af);var ah=Math.max(aa,aF.get_required_height(aj));var ae=this.view.canvas_manager.new_canvas();ae.width=aw+ag;ae.height=ah;var ax=ae.getContext("2d");ax.fillStyle=this.prefs.block_color;ax.font=ax.canvas.manager.default_font;ax.textAlign="right";this.container_div.find(".yaxislabel").remove();if(ap.data){ax.translate(ag,0);aF.draw(ax,aw,ah,aq)}return new M(aC,ay,ae,ap.data,ap.message)}});var Q=function(af,ad,ah,ac,ae,ag){e.call(this,af,ad,ah,ac,ae,ag);this.painter=I.VariantPainter};n(Q.prototype,J.prototype,e.prototype);var T=function(af,ad,ah,ac,ae,ag){e.call(this,af,ad,ah,ac,ae,ag);this.track_config=new W({track:this,params:[{key:"block_color",label:"Block color",type:"color",default_value:"#444"},{key:"label_color",label:"Label color",type:"color",default_value:"black"},{key:"show_insertions",label:"Show insertions",type:"bool",default_value:false},{key:"show_differences",label:"Show differences only",type:"bool",default_value:true},{key:"show_counts",label:"Show summary counts",type:"bool",default_value:true},{key:"mode",type:"string",default_value:this.mode,hidden:true},],saved_values:ae,onchange:function(){this.track.tile_cache.clear();this.track.request_draw()}});this.prefs=this.track_config.values;this.painter=I.ReadPainter;this.make_name_popup_menu()};n(T.prototype,J.prototype,e.prototype);var R=function(ag,ae,ai,ac,af,ah,ad){e.call(this,ag,ae,ai,ac,af,ah,{},ad);this.data_url=raw_data_url;this.data_query_wait=1000;this.dataset_check_url=dataset_state_url};n(R.prototype,J.prototype,e.prototype,{predraw_init:function(){var ad=this;var ac=function(){if(ad.data_manager.size()===0){setTimeout(ac,300)}else{ad.data_url=default_data_url;ad.data_query_wait=H;ad.dataset_state_url=converted_datasets_state_url;$.getJSON(ad.dataset_state_url,{dataset_id:ad.dataset_id,hda_ldda:ad.hda_ldda},function(ae){})}};ac()}});U.View=Z;U.LineTrack=k;U.FeatureTrack=e;U.ReadTrack=T};var slotting_module=function(c,b){var e=c("class").extend;var d=2,a=5;b.FeatureSlotter=function(j,h,f,g){this.slots={};this.start_end_dct={};this.w_scale=j;this.include_label=h;this.max_rows=f;this.measureText=g};e(b.FeatureSlotter.prototype,{slot_features:function(m){var p=this.w_scale,s=this.slots,h=this.start_end_dct,y=[],A=[],n=0,z=this.max_rows;for(var w=0,x=m.length;w<x;w++){var l=m[w],o=l[0];if(s[o]!==undefined){n=Math.max(n,s[o]);A.push(s[o])}else{y.push(w)}}var q=function(G,H){for(var F=0;F<=z;F++){var D=false,I=h[F];if(I!==undefined){for(var C=0,E=I.length;C<E;C++){var B=I[C];if(H>B[0]&&G<B[1]){D=true;break}}}if(!D){return F}}return -1};for(var w=0,x=y.length;w<x;w++){var l=m[y[w]],o=l[0],u=l[1],f=l[2],r=l[3],g=Math.floor(u*p),k=Math.ceil(f*p),v=this.measureText(r).width,j;if(r!==undefined&&this.include_label){v+=(d+a);if(g-v>=0){g-=v;j="left"}else{k+=v;j="right"}}var t=q(g,k);if(t>=0){if(h[t]===undefined){h[t]=[]}h[t].push([g,k]);s[o]=t;n=Math.max(n,t)}else{}}return n+1}})};var painters_module=function(k,x){var u=k("class").extend;var p=function(I,A,G,z,F,D){if(D===undefined){D=4}var C=z-A;var B=F-G;var E=Math.floor(Math.sqrt(C*C+B*B)/D);var J=C/E;var H=B/E;var y;for(y=0;y<E;y++,A+=J,G+=H){if(y%2!==0){continue}I.fillRect(A,G,D,1)}};var q=function(B,A,z,E){var D=A-E/2,C=A+E/2,F=z-Math.sqrt(E*3/2);B.beginPath();B.moveTo(D,F);B.lineTo(C,F);B.lineTo(A,z);B.lineTo(D,F);B.strokeStyle=this.fillStyle;B.fill();B.stroke();B.closePath()};var g=function(y){this.default_alpha=(y?y:1)};g.prototype.gen_alpha=function(y){return this.default_alpha};var n=function(A,C,y,z,B){this.data=A;this.view_start=C;this.view_end=y;this.prefs=u({},this.default_prefs,z);this.mode=B};n.prototype.default_prefs={};var v=function(A,C,y,z,B){n.call(this,A,C,y,z,B)};v.prototype.default_prefs={show_counts:false};v.prototype.draw=function(M,z,L){var E=this.view_start,O=this.view_end-this.view_start,N=z/O;var J=this.data.data,I=this.data.delta,G=this.data.max,B=L;delta_x_px=Math.ceil(I*N);M.save();for(var C=0,D=J.length;C<D;C++){var H=Math.floor((J[C][0]-E)*N);var F=J[C][1];if(!F){continue}var K=F/G*L;if(F!==0&&K<1){K=1}M.fillStyle=this.prefs.block_color;M.fillRect(H,B-K,delta_x_px,K);var A=4;if(this.prefs.show_counts&&(M.measureText(F).width+A)<delta_x_px){M.fillStyle=this.prefs.label_color;M.textAlign="center";M.fillText(F,H+(delta_x_px/2),10)}}M.restore()};var c=function(y,C,E,F,A){n.call(this,y,C,E,F,A);if(this.prefs.min_value===undefined){var G=Infinity;for(var z=0,B=this.data.length;z<B;z++){G=Math.min(G,this.data[z][1])}this.prefs.min_value=G}if(this.prefs.max_value===undefined){var D=-Infinity;for(var z=0,B=this.data.length;z<B;z++){D=Math.max(D,this.data[z][1])}this.prefs.max_value=D}};c.prototype.default_prefs={min_value:undefined,max_value:undefined,mode:"Histogram",color:"#000",overflow_color:"#F66"};c.prototype.draw=function(N,M,K){var F=false,H=this.prefs.min_value,D=this.prefs.max_value,J=D-H,z=K,A=this.view_start,L=this.view_end-this.view_start,B=M/L,I=this.mode,T=this.data;N.save();var U=Math.round(K+H/J*K);if(I!=="Intensity"){N.fillStyle="#aaa";N.fillRect(0,U,M,1)}N.beginPath();var R,E,C;if(T.length>1){C=Math.ceil((T[1][0]-T[0][0])*B)}else{C=10}for(var O=0,P=T.length;O<P;O++){N.fillStyle=this.prefs.color;R=Math.round((T[O][0]-A)*B);E=T[O][1];var Q=false,G=false;if(E===null){if(F&&I==="Filled"){N.lineTo(R,z)}F=false;continue}if(E<H){G=true;E=H}else{if(E>D){Q=true;E=D}}if(I==="Histogram"){E=Math.round(E/J*z);N.fillRect(R,U,C,-E)}else{if(I==="Intensity"){E=255-Math.floor((E-H)/J*255);N.fillStyle="rgb("+E+","+E+","+E+")";N.fillRect(R,0,C,z)}else{E=Math.round(z-(E-H)/J*z);if(F){N.lineTo(R,E)}else{F=true;if(I==="Filled"){N.moveTo(R,z);N.lineTo(R,E)}else{N.moveTo(R,E)}}}}N.fillStyle=this.prefs.overflow_color;if(Q||G){var S;if(I==="Histogram"||I==="Intensity"){S=C}else{R-=2;S=4}if(Q){N.fillRect(R,0,S,3)}if(G){N.fillRect(R,z-3,S,3)}}N.fillStyle=this.prefs.color}if(I==="Filled"){if(F){N.lineTo(R,U);N.lineTo(0,U)}N.fill()}else{N.stroke()}N.restore()};var o=function(B,D,y,A,C,z){n.call(this,B,D,y,A,C);this.alpha_generator=(z?z:new g())};o.prototype.default_prefs={block_color:"#FFF",connector_color:"#FFF"};u(o.prototype,{get_required_height:function(z){var y=y_scale=this.get_row_height(),A=this.mode;if(A==="no_detail"||A==="Squish"||A==="Pack"){y=z*y_scale}return y+Math.max(Math.round(y_scale/2),5)},draw:function(K,B,J,G){var E=this.data,H=this.view_start,L=this.view_end;K.save();K.fillStyle=this.prefs.block_color;K.textAlign="right";var O=this.view_end-this.view_start,N=B/O,A=this.get_row_height();for(var D=0,F=E.length;D<F;D++){var M=E[D],C=M[0],y=M[1],z=M[2],I=(G&&G[C]!==undefined?G[C]:null);if((y<L&&z>H)&&(this.mode=="Dense"||I!==null)){this.draw_element(K,this.mode,M,I,H,L,N,A,B)}}K.restore()},draw_element:function(E,A,G,C,B,D,F,z,y){console.log("WARNING: Unimplemented function.")}});var d=10,j=3,m=5,w=10,f=1,s=3,e=3,a=9,l=2,h="#ccc";var r=function(B,D,y,A,C,z){o.call(this,B,D,y,A,C,z)};u(r.prototype,o.prototype,{get_row_height:function(){var z=this.mode,y;if(z==="Dense"){y=d}else{if(z==="no_detail"){y=j}else{if(z==="Squish"){y=m}else{y=w}}}return y},draw_element:function(K,D,S,F,M,ac,ag,ah,y){var P=S[0],ae=S[1],W=S[2],N=S[3],X=Math.floor(Math.max(0,(ae-M)*ag)),L=Math.ceil(Math.min(y,Math.max(0,(W-M)*ag))),V=(D==="Dense"?0:(0+F))*ah,J,aa,O=null,ai=null,B=this.prefs.block_color,Z=this.prefs.label_color;K.globalAlpha=this.alpha_generator.gen_alpha(S);if(D=="Dense"){F=1}if(D==="no_detail"){K.fillStyle=B;K.fillRect(X,V+5,L-X,f)}else{var I=S[4],U=S[5],Y=S[6],C=S[7];if(U&&Y){O=Math.floor(Math.max(0,(U-M)*ag));ai=Math.ceil(Math.min(y,Math.max(0,(Y-M)*ag)))}var af,Q;if(D==="Squish"||D==="Dense"){af=1;Q=e}else{af=5;Q=a}if(!C){if(S.strand){if(S.strand==="+"){K.fillStyle=K.canvas.manager.get_pattern("right_strand_inv")}else{if(S.strand==="-"){K.fillStyle=K.canvas.manager.get_pattern("left_strand_inv")}}}else{K.fillStyle=B}K.fillRect(X,V,L-X,Q)}else{var H,R;if(D==="Squish"||D==="Dense"){K.fillStyle=h;H=V+Math.floor(e/2)+1;R=1}else{if(I){var H=V;var R=Q;if(I==="+"){K.fillStyle=K.canvas.manager.get_pattern("right_strand")}else{if(I==="-"){K.fillStyle=K.canvas.manager.get_pattern("left_strand")}}}else{K.fillStyle=h;H+=(e/2)+1;R=1}}K.fillRect(X,H,L-X,R);for(var ad=0,A=C.length;ad<A;ad++){var E=C[ad],z=Math.floor(Math.max(0,(E[0]-M)*ag)),T=Math.ceil(Math.min(y,Math.max((E[1]-M)*ag)));if(z>T){continue}K.fillStyle=B;K.fillRect(z,V+(Q-af)/2+1,T-z,af);if(O!==undefined&&Y>U&&!(z>ai||T<O)){var ab=Math.max(z,O),G=Math.min(T,ai);K.fillRect(ab,V+1,G-ab,Q);if(C.length==1&&D=="Pack"){if(I==="+"){K.fillStyle=K.canvas.manager.get_pattern("right_strand_inv")}else{if(I==="-"){K.fillStyle=K.canvas.manager.get_pattern("left_strand_inv")}}if(ab+14<G){ab+=2;G-=2}K.fillRect(ab,V+1,G-ab,Q)}}}}if(D==="Pack"&&ae>M){K.fillStyle=Z;if(M===0&&X-K.measureText(N).width<0){K.textAlign="left";K.fillText(N,L+l,V+8)}else{K.textAlign="right";K.fillText(N,X-l,V+8)}}}K.globalAlpha=1}});var b=function(B,D,y,A,C,z){o.call(this,B,D,y,A,C,z)};u(b.prototype,o.prototype,{draw_element:function(R,M,G,C,U,A,J,S,P){var G=data[i],I=G[0],Q=G[1],B=G[2],L=G[3],E=Math.floor(Math.max(0,(Q-U)*J)),H=Math.ceil(Math.min(P,Math.max(0,(B-U)*J))),D=(M==="Dense"?0:(0+C))*S,y,V,z=null,K=null;if(no_label){R.fillStyle=block_color;R.fillRect(E+left_offset,D+5,H-E,1)}else{var T=G[4],O=G[5],F=G[6];y=9;V=1;R.fillRect(E+left_offset,D,H-E,y);if(M!=="Dense"&&L!==undefined&&Q>U){R.fillStyle=label_color;if(U===0&&E-R.measureText(L).width<0){R.textAlign="left";R.fillText(L,H+2+left_offset,D+8)}else{R.textAlign="right";R.fillText(L,E-2+left_offset,D+8)}R.fillStyle=block_color}var N=T+" / "+O;if(Q>U&&R.measureText(N).width<(H-E)){R.fillStyle="white";R.textAlign="center";R.fillText(N,left_offset+E+(H-E)/2,D+8);R.fillStyle=block_color}}}});var t=function(C,E,y,B,D,z,A){o.call(this,C,E,y,B,D,z);this.ref_seq=A};t.prototype.default_prefs=u({},o.prototype.default_prefs,{show_insertions:false});u(t.prototype,o.prototype,{get_row_height:function(){var y,z=this.mode;if(z==="Dense"){y=d}else{if(z==="Squish"){y=m}else{y=w;if(this.prefs.show_insertions){y*=2}}}return y},draw_read:function(U,P,L,Z,A,T,I,F,E){U.textAlign="center";var S=this,z=[Z,A],O=0,V=0,R=0;ref_seq=this.ref_seq,char_width_px=U.canvas.manager.char_width_px;var ae=[];if((P==="Pack"||this.mode==="Auto")&&F!==undefined&&L>char_width_px){R=Math.round(L/2)}if(!I){I=[[0,F.length]]}for(var M=0,X=I.length;M<X;M++){var J=I[M],B="MIDNSHP=X"[J[0]],N=J[1];if(B==="H"||B==="S"){O-=N}var G=T+O,ad=Math.floor(Math.max(0,(G-Z)*L)),H=Math.floor(Math.max(0,(G+N-Z)*L));if(ad===H){H+=1}switch(B){case"H":break;case"S":case"M":case"=":if(is_overlap([G,G+N],z)){var Q=F.slice(V,V+N);if(R>0){U.fillStyle=this.prefs.block_color;U.fillRect(ad-R,E+1,H-ad,9);U.fillStyle=h;for(var ab=0,y=Q.length;ab<y;ab++){if(this.prefs.show_differences&&ref_seq){var K=ref_seq[G-Z+ab];if(!K||K.toLowerCase()===Q[ab].toLowerCase()){continue}}if(G+ab>=Z&&G+ab<=A){var ac=Math.floor(Math.max(0,(G+ab-Z)*L));U.fillText(Q[ab],ac,E+9)}}}else{U.fillStyle=this.prefs.block_color;U.fillRect(ad,E+4,H-ad,e)}}V+=N;O+=N;break;case"N":U.fillStyle=h;U.fillRect(ad-R,E+5,H-ad,1);O+=N;break;case"D":U.fillStyle="red";U.fillRect(ad-R,E+4,H-ad,3);O+=N;break;case"P":break;case"I":var Y=ad-R;if(is_overlap([G,G+N],z)){var Q=F.slice(V,V+N);if(this.prefs.show_insertions){var D=ad-(H-ad)/2;if((P==="Pack"||this.mode==="Auto")&&F!==undefined&&L>char_width_px){U.fillStyle="yellow";U.fillRect(D-R,E-9,H-ad,9);ae[ae.length]={type:"triangle",data:[Y,E+4,5]};U.fillStyle=h;switch(seq_tile_overlap){case (OVERLAP_START):Q=Q.slice(Z-G);break;case (OVERLAP_END):Q=Q.slice(0,G-A);break;case (CONTAINED_BY):break;case (CONTAINS):Q=Q.slice(Z-G,G-A);break}for(var ab=0,y=Q.length;ab<y;ab++){var ac=Math.floor(Math.max(0,(G+ab-Z)*L));U.fillText(Q[ab],ac-(H-ad)/2,E)}}else{U.fillStyle="yellow";U.fillRect(D,E+(this.mode!=="Dense"?2:5),H-ad,(P!=="Dense"?e:s))}}else{if((P==="Pack"||this.mode==="Auto")&&F!==undefined&&L>char_width_px){ae[ae.length]={type:"text",data:[Q.length,Y,E+9]}}else{}}}V+=N;break;case"X":V+=N;break}}U.fillStyle="yellow";var aa,C,af;for(var W=0;W<ae.length;W++){aa=ae[W];C=aa.type;af=aa.data;if(C==="text"){U.save();U.font="bold "+U.font;U.fillText(af[0],af[1],af[2]);U.restore()}else{if(C=="triangle"){q(U,af[0],af[1],af[2])}}}},draw_element:function(R,M,E,B,U,z,I,S,P){var H=E[0],Q=E[1],A=E[2],J=E[3],D=Math.floor(Math.max(0,(Q-U)*I)),F=Math.ceil(Math.min(P,Math.max(0,(A-U)*I))),C=(M==="Dense"?0:(0+B))*S,V=this.prefs.block_color,G=this.prefs.label_color,O=0;if((M==="Pack"||this.mode==="Auto")&&I>R.canvas.manager.char_width_px){var O=Math.round(I/2)}R.fillStyle=V;if(E[5] instanceof Array){var N=Math.floor(Math.max(0,(E[4][0]-U)*I)),L=Math.ceil(Math.min(P,Math.max(0,(E[4][1]-U)*I))),K=Math.floor(Math.max(0,(E[5][0]-U)*I)),y=Math.ceil(Math.min(P,Math.max(0,(E[5][1]-U)*I)));if(E[4][1]>=U&&E[4][0]<=z&&E[4][2]){this.draw_read(R,M,I,U,z,E[4][0],E[4][2],E[4][3],C)}if(E[5][1]>=U&&E[5][0]<=z&&E[5][2]){this.draw_read(R,M,I,U,z,E[5][0],E[5][2],E[5][3],C)}if(K>L){R.fillStyle=h;p(R,L-O,C+5,K-O,C+5)}}else{R.fillStyle=V;this.draw_read(R,M,I,U,z,Q,E[4],E[5],C)}if(M==="Pack"&&Q>U){R.fillStyle=this.prefs.label_color;var T=1;if(T===0&&D-R.measureText(J).width<0){R.textAlign="left";R.fillText(J,F+l-O,C+8)}else{R.textAlign="right";R.fillText(J,D-l-O,C+8)}R.fillStyle=V}}});x.AlphaGenerator=g;x.SummaryTreePainter=v;x.LinePainter=c;x.LinkedFeaturePainter=r;x.ReadPainter=t;x.VariantPainter=b};(function(d){var c={};var b=function(e){return c[e]};var a=function(f,g){var e={};g(b,e);c[f]=e};a("class",class_module);a("slotting",slotting_module);a("painters",painters_module);a("trackster",trackster_module);for(key in c.trackster){d[key]=c.trackster[key]}})(window);
+var class_module=function(b,a){var c=function(){var f=arguments[0];for(var e=1;e<arguments.length;e++){var d=arguments[e];for(key in d){f[key]=d[key]}}return f};a.extend=c};var requestAnimationFrame=(function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(b,a){window.setTimeout(b,1000/60)}})();var BEFORE=1001,CONTAINS=1002,OVERLAP_START=1003,OVERLAP_END=1004,CONTAINED_BY=1005,AFTER=1006;var compute_overlap=function(e,b){var g=e[0],f=e[1],d=b[0],c=b[1],a;if(g<d){if(f<d){a=BEFORE}else{if(f<=c){a=OVERLAP_START}else{a=CONTAINS}}}else{if(g>c){a=AFTER}else{if(f<=c){a=CONTAINED_BY}else{a=OVERLAP_END}}}return a};var is_overlap=function(c,b){var a=compute_overlap(c,b);return(a!==BEFORE&&a!==AFTER)};var trackster_module=function(f,W){var p=f("class").extend,r=f("slotting"),K=f("painters");var ad=function(ae,af){this.document=ae;this.default_font=af!==undefined?af:"9px Monaco, Lucida Console, monospace";this.dummy_canvas=this.new_canvas();this.dummy_context=this.dummy_canvas.getContext("2d");this.dummy_context.font=this.default_font;this.char_width_px=this.dummy_context.measureText("A").width;this.patterns={};this.load_pattern("right_strand","/visualization/strand_right.png");this.load_pattern("left_strand","/visualization/strand_left.png");this.load_pattern("right_strand_inv","/visualization/strand_right_inv.png");this.load_pattern("left_strand_inv","/visualization/strand_left_inv.png")};p(ad.prototype,{load_pattern:function(ae,ai){var af=this.patterns,ag=this.dummy_context,ah=new Image();ah.src=image_path+ai;ah.onload=function(){af[ae]=ag.createPattern(ah,"repeat")}},get_pattern:function(ae){return this.patterns[ae]},new_canvas:function(){var ae=this.document.createElement("canvas");if(window.G_vmlCanvasManager){G_vmlCanvasManager.initElement(ae)}ae.manager=this;return ae}});var m=function(ae,ag,ah){ah=".group";var af={};ae.bind("drag",{handle:ag,relative:true},function(an,ao){var aq=$(this).parent(),al=aq.children(),ak,aj,ap,ai,am;aj=$(this).parents(ah);if(aj.length!==0){ap=aj.position().top;ai=ap+aj.outerHeight();if(ao.offsetY<ap){$(this).insertBefore(aj);return}else{if(ao.offsetY>ai){$(this).insertAfter(aj);return}}}aj=null;for(am=0;am<al.length;am++){ak=$(al.get(am));ap=ak.position().top;ai=ap+ak.outerHeight();if(ak.is(ah)&&this!==ak.get(0)&&ao.offsetY>=ap&&ao.offsetY<=ai){if(ao.offsetY-ap<ai-ao.offsetY){ak.find(".content-div").prepend(this)}else{ak.find(".content-div").append(this)}return}}for(am=0;am<al.length;am++){if(ao.offsetY<$(al.get(am)).position().top){break}}if(am===al.length){if(this!==al.get(am-1)){aq.append(this)}}else{if(this!==al.get(am)){$(this).insertBefore(al.get(am))}}}).bind("dragstart",function(){af["border-top"]=ae.css("border-top");af["border-bottom"]=ae.css("border-bottom");$(this).css({"border-top":"1px solid blue","border-bottom":"1px solid blue"})}).bind("dragend",function(){$(this).css(af)})};W.moveable=m;var ac=16,F=9,D=20,R=F+2,z=100,H=12000,P=200,C=5,u=10,J=5000,v=100,n="There was an error in indexing this dataset. ",I="A converter for this dataset is not installed. Please check your datatypes_conf.xml file.",E="No data for this chrom/contig.",s="Currently indexing... please wait",x="Tool cannot be rerun: ",a="Loading data...",X="Ready for display",d=10,t=5,B=5;function w(ae){return Math.round(ae*1000)/1000}var c=function(ae){this.num_elements=ae;this.clear()};p(c.prototype,{get:function(af){var ae=this.key_ary.indexOf(af);if(ae!==-1){if(this.obj_cache[af].stale){this.key_ary.splice(ae,1);delete this.obj_cache[af]}else{this.move_key_to_end(af,ae)}}return this.obj_cache[af]},set:function(af,ag){if(!this.obj_cache[af]){if(this.key_ary.length>=this.num_elements){var ae=this.key_ary.shift();delete this.obj_cache[ae]}this.key_ary.push(af)}this.obj_cache[af]=ag;return ag},move_key_to_end:function(af,ae){this.key_ary.splice(ae,1);this.key_ary.push(af)},clear:function(){this.obj_cache={};this.key_ary=[]},size:function(){return this.key_ary.length}});var Q=function(af,ae,ag){c.call(this,af);this.track=ae;this.subset=(ag!==undefined?ag:true)};p(Q.prototype,c.prototype,{load_data:function(an,ai,al,af,ak){var am=this.track.view.chrom,ah={chrom:am,low:an,high:ai,mode:al,resolution:af,dataset_id:this.track.dataset_id,hda_ldda:this.track.hda_ldda};$.extend(ah,ak);if(this.track.filters_manager){var ao=[];var ae=this.track.filters_manager.filters;for(var aj=0;aj<ae.length;aj++){ao[ao.length]=ae[aj].name}ah.filter_cols=JSON.stringify(ao)}var ag=this;return $.getJSON(this.track.data_url,ah,function(ap){ag.set_data(an,ai,al,ap)})},get_data:function(ae,ai,aj,af,ah){var ag=this.get_data_from_cache(ae,ai,aj);if(ag){return ag}ag=this.load_data(ae,ai,aj,af,ah);this.set_data(ae,ai,aj,ag);return ag},DEEP_DATA_REQ:"deep",BROAD_DATA_REQ:"breadth",get_more_data:function(am,ah,al,ag,ak,ai){var an=this.get_data_from_cache(am,ah,al);if(!an){console.log("ERROR: no current data for: ",this.track,am,ah,al,ag,ak);return}an.stale=true;var af=am;if(ai===this.DEEP_DATA_REQ){$.extend(ak,{start_val:an.data.length+1})}else{if(ai===this.BROAD_DATA_REQ){af=an.data[an.data.length-1][2]+1}}var ae=this,aj=this.load_data(af,ah,al,ag,ak);new_data_available=$.Deferred();this.set_data(am,ah,al,new_data_available);$.when(aj).then(function(ao){if(ao.data){ao.data=an.data.concat(ao.data);if(ao.message){ao.message=ao.message.replace(/[0-9]+/,ao.data.length)}}ae.set_data(am,ah,al,ao);new_data_available.resolve(ao)});return new_data_available},get_data_from_cache:function(ae,af,ag){return this.get(this.gen_key(ae,af,ag))},set_data:function(af,ag,ah,ae){return this.set(this.gen_key(af,ag,ah),ae)},gen_key:function(ae,ag,ah){var af=ae+"_"+ag+"_"+ah;return af},split_key:function(ae){return ae.split("_")}});var G=function(af,ae,ag){Q.call(this,af,ae,ag)};p(G.prototype,Q.prototype,c.prototype,{load_data:function(ag,ae,ai,aj,af,ah){if(af>1){return}return Q.prototype.load_data.call(this,ag,ae,ai,aj,af,ah)}});var ab=function(ae,ah,ag,af,ai){this.container=ae;this.chrom=null;this.vis_id=ag;this.dbkey=af;this.title=ah;this.tracks=[];this.label_tracks=[];this.tracks_to_be_redrawn=[];this.max_low=0;this.max_high=0;this.num_tracks=0;this.track_id_counter=0;this.zoom_factor=3;this.min_separation=30;this.has_changes=false;this.init(ai);this.canvas_manager=new ad(ae.get(0).ownerDocument);this.reset()};p(ab.prototype,{init:function(ai){var ag=this.container,ae=this;this.top_container=$("<div/>").addClass("top-container").appendTo(ag);this.content_div=$("<div/>").addClass("content").css("position","relative").appendTo(ag);this.bottom_container=$("<div/>").addClass("bottom-container").appendTo(ag);this.top_labeltrack=$("<div/>").addClass("top-labeltrack").appendTo(this.top_container);this.viewport_container=$("<div/>").addClass("viewport-container").addClass("viewport-container").appendTo(this.content_div);this.intro_div=$("<div/>").addClass("intro").appendTo(this.viewport_container).hide();var ah=$("<div/>").text("Add Datasets to Visualization").addClass("action-button").appendTo(this.intro_div).click(function(){add_tracks()});this.nav_labeltrack=$("<div/>").addClass("nav-labeltrack").appendTo(this.bottom_container);this.nav_container=$("<div/>").addClass("nav-container").prependTo(this.top_container);this.nav=$("<div/>").addClass("nav").appendTo(this.nav_container);this.overview=$("<div/>").addClass("overview").appendTo(this.bottom_container);this.overview_viewport=$("<div/>").addClass("overview-viewport").appendTo(this.overview);this.overview_close=$("<a href='javascript:void(0);'>Close Overview</a>").addClass("overview-close").hide().appendTo(this.overview_viewport);this.overview_highlight=$("<div/>").addClass("overview-highlight").hide().appendTo(this.overview_viewport);this.overview_box_background=$("<div/>").addClass("overview-boxback").appendTo(this.overview_viewport);this.overview_box=$("<div/>").addClass("overview-box").appendTo(this.overview_viewport);this.default_overview_height=this.overview_box.height();this.nav_controls=$("<div/>").addClass("nav-controls").appendTo(this.nav);this.chrom_select=$("<select/>").attr({name:"chrom"}).css("width","15em").addClass("no-autocomplete").append("<option value=''>Loading</option>").appendTo(this.nav_controls);var af=function(aj){if(aj.type==="focusout"||(aj.keyCode||aj.which)===13||(aj.keyCode||aj.which)===27){if((aj.keyCode||aj.which)!==27){ae.go_to($(this).val())}$(this).hide();$(this).val("");ae.location_span.show();ae.chrom_select.show()}};this.nav_input=$("<input/>").addClass("nav-input").hide().bind("keyup focusout",af).appendTo(this.nav_controls);this.location_span=$("<span/>").addClass("location").appendTo(this.nav_controls);this.location_span.click(function(){ae.location_span.hide();ae.chrom_select.hide();ae.nav_input.val(ae.chrom+":"+ae.low+"-"+ae.high);ae.nav_input.css("display","inline-block");ae.nav_input.select();ae.nav_input.focus()});if(this.vis_id!==undefined){this.hidden_input=$("<input/>").attr("type","hidden").val(this.vis_id).appendTo(this.nav_controls)}this.zo_link=$("<a id='zoom-out' />").click(function(){ae.zoom_out();ae.request_redraw()}).appendTo(this.nav_controls);this.zi_link=$("<a id='zoom-in' />").click(function(){ae.zoom_in();ae.request_redraw()}).appendTo(this.nav_controls);this.load_chroms({low:0},ai);this.chrom_select.bind("change",function(){ae.change_chrom(ae.chrom_select.val())});this.content_div.click(function(aj){$(this).find("input").trigger("blur")});this.content_div.bind("dblclick",function(aj){ae.zoom_in(aj.pageX,this.viewport_container)});this.overview_box.bind("dragstart",function(aj,ak){this.current_x=ak.offsetX}).bind("drag",function(aj,al){var am=al.offsetX-this.current_x;this.current_x=al.offsetX;var ak=Math.round(am/ae.viewport_container.width()*(ae.max_high-ae.max_low));ae.move_delta(-ak)});this.overview_close.click(function(){ae.reset_overview()});this.viewport_container.bind("draginit",function(aj,ak){if(aj.clientX>ae.viewport_container.width()-16){return false}}).bind("dragstart",function(aj,ak){ak.original_low=ae.low;ak.current_height=aj.clientY;ak.current_x=ak.offsetX}).bind("drag",function(al,an){var aj=$(this);var ao=an.offsetX-an.current_x;var ak=aj.scrollTop()-(al.clientY-an.current_height);aj.scrollTop(ak);an.current_height=al.clientY;an.current_x=an.offsetX;var am=Math.round(ao/ae.viewport_container.width()*(ae.high-ae.low));ae.move_delta(am)}).bind("mousewheel",function(al,an,ak,aj){if(ak){var am=Math.round(-ak/ae.viewport_container.width()*(ae.high-ae.low));ae.move_delta(am)}});this.top_labeltrack.bind("dragstart",function(aj,ak){return $("<div />").css({height:ae.content_div.height()+ae.top_labeltrack.height()+ae.nav_labeltrack.height()+1,top:"0px",position:"absolute","background-color":"#ccf",opacity:0.5,"z-index":1000}).appendTo($(this))}).bind("drag",function(an,ao){$(ao.proxy).css({left:Math.min(an.pageX,ao.startX),width:Math.abs(an.pageX-ao.startX)});var ak=Math.min(an.pageX,ao.startX)-ae.container.offset().left,aj=Math.max(an.pageX,ao.startX)-ae.container.offset().left,am=(ae.high-ae.low),al=ae.viewport_container.width();ae.update_location(Math.round(ak/al*am)+ae.low,Math.round(aj/al*am)+ae.low)}).bind("dragend",function(ao,ap){var ak=Math.min(ao.pageX,ap.startX),aj=Math.max(ao.pageX,ap.startX),am=(ae.high-ae.low),al=ae.viewport_container.width(),an=ae.low;ae.low=Math.round(ak/al*am)+an;ae.high=Math.round(aj/al*am)+an;$(ap.proxy).remove();ae.request_redraw()});this.add_label_track(new aa(this,this.top_labeltrack));this.add_label_track(new aa(this,this.nav_labeltrack));$(window).bind("resize",function(){ae.resize_window()});$(document).bind("redraw",function(){ae.redraw()});this.reset();$(window).trigger("resize");this.update_intro_div()},update_intro_div:function(){if(this.num_tracks===0){this.intro_div.show()}else{this.intro_div.hide()}},update_location:function(ae,af){this.location_span.text(commatize(ae)+" - "+commatize(af));this.nav_input.val(this.chrom+":"+commatize(ae)+"-"+commatize(af))},load_chroms:function(af,ag){af.num=v;$.extend(af,(this.vis_id!==undefined?{vis_id:this.vis_id}:{dbkey:this.dbkey}));var ae=this;$.ajax({url:chrom_url,data:af,dataType:"json",success:function(ai){if(ai.chrom_info.length===0){alert("Invalid chromosome: "+af.chrom);return}if(ai.reference){ae.add_label_track(new A(ae))}ae.chrom_data=ai.chrom_info;var al='<option value="">Select Chrom/Contig</option>';for(var ak=0,ah=ae.chrom_data.length;ak<ah;ak++){var aj=ae.chrom_data[ak].chrom;al+='<option value="'+aj+'">'+aj+"</option>"}if(ai.prev_chroms){al+='<option value="previous">Previous '+v+"</option>"}if(ai.next_chroms){al+='<option value="next">Next '+v+"</option>"}ae.chrom_select.html(al);if(ag){ag()}ae.chrom_start_index=ai.start_index},error:function(){alert("Could not load chroms for this dbkey:",ae.dbkey)}})},change_chrom:function(ai,af,ak){if(!ai||ai==="None"){return}var ah=this;if(ai==="previous"){ah.load_chroms({low:this.chrom_start_index-v});return}if(ai==="next"){ah.load_chroms({low:this.chrom_start_index+v});return}var aj=$.grep(ah.chrom_data,function(am,an){return am.chrom===ai})[0];if(aj===undefined){ah.load_chroms({chrom:ai},function(){ah.change_chrom(ai,af,ak)});return}else{if(ai!==ah.chrom){ah.chrom=ai;ah.chrom_select.val(ah.chrom);ah.max_high=aj.len-1;ah.reset();ah.request_redraw(true);for(var al=0,ae=ah.tracks.length;al<ae;al++){var ag=ah.tracks[al];if(ag.init){ag.init()}}}if(af!==undefined&&ak!==undefined){ah.low=Math.max(af,0);ah.high=Math.min(ak,ah.max_high)}ah.reset_overview();ah.request_redraw()}},go_to:function(ai){var am=this,ae,ah,af=ai.split(":"),ak=af[0],al=af[1];if(al!==undefined){try{var aj=al.split("-");ae=parseInt(aj[0].replace(/,/g,""),10);ah=parseInt(aj[1].replace(/,/g,""),10)}catch(ag){return false}}am.change_chrom(ak,ae,ah)},move_fraction:function(ag){var ae=this;var af=ae.high-ae.low;this.move_delta(ag*af)},move_delta:function(ag){var ae=this;var af=ae.high-ae.low;if(ae.low-ag<ae.max_low){ae.low=ae.max_low;ae.high=ae.max_low+af}else{if(ae.high-ag>ae.max_high){ae.high=ae.max_high;ae.low=ae.max_high-af}else{ae.high-=ag;ae.low-=ag}}ae.request_redraw()},add_track:function(ae){ae.view=this;ae.track_id=this.track_id_counter;this.tracks.push(ae);if(ae.init){ae.init()}ae.container_div.attr("id","track_"+ae.track_id);m(ae.container_div,ae.drag_handle);this.track_id_counter+=1;this.num_tracks+=1;this.has_changes=true;this.update_intro_div()},add_label_track:function(ae){ae.view=this;this.label_tracks.push(ae)},remove_track:function(af){this.has_changes=true;delete this.tracks[this.tracks.indexOf(af)];this.num_tracks-=1;var ae=this;af.container_div.fadeOut("slow",function(){$(this).remove();ae.update_intro_div()})},reset:function(){this.low=this.max_low;this.high=this.max_high;this.viewport_container.find(".yaxislabel").remove()},request_redraw:function(am,ae,al,af){var ak=this,ai=(af?[af]:ak.tracks),ag;var af;for(var aj=0;aj<ai.length;aj++){af=ai[aj];ag=-1;for(var ah=0;ah<ak.tracks_to_be_redrawn.length;ah++){if(ak.tracks_to_be_redrawn[ah][0]===af){ag=ah;break}}if(ag<0){ak.tracks_to_be_redrawn.push([af,ae,al])}else{ak.tracks_to_be_redrawn[aj][1]=ae;ak.tracks_to_be_redrawn[aj][2]=al}}requestAnimationFrame(function(){ak._redraw(am)})},_redraw:function(ao){var al=this.low,ah=this.high;if(al<this.max_low){al=this.max_low}if(ah>this.max_high){ah=this.max_high}var an=this.high-this.low;if(this.high!==0&&an<this.min_separation){ah=al+this.min_separation}this.low=Math.floor(al);this.high=Math.ceil(ah);this.resolution=Math.pow(C,Math.ceil(Math.log((this.high-this.low)/P)/Math.log(C)));this.zoom_res=Math.pow(u,Math.max(0,Math.ceil(Math.log(this.resolution,u)/Math.log(u))));var ae=(this.low/(this.max_high-this.max_low)*this.overview_viewport.width())||0;var ak=((this.high-this.low)/(this.max_high-this.max_low)*this.overview_viewport.width())||0;var ap=13;this.overview_box.css({left:ae,width:Math.max(ap,ak)}).show();if(ak<ap){this.overview_box.css("left",ae-(ap-ak)/2)}if(this.overview_highlight){this.overview_highlight.css({left:ae,width:ak})}this.update_location(this.low,this.high);if(!ao){var ag,af,am;for(var ai=0,aj=this.tracks_to_be_redrawn.length;ai<aj;ai++){ag=this.tracks_to_be_redrawn[ai][0];af=this.tracks_to_be_redrawn[ai][1];am=this.tracks_to_be_redrawn[ai][2];if(ag&&ag.enabled){ag._draw(af,am)}}this.tracks_to_be_redrawn=[];for(ai=0,aj=this.label_tracks.length;ai<aj;ai++){this.label_tracks[ai]._draw()}}},zoom_in:function(af,ag){if(this.max_high===0||this.high-this.low<this.min_separation){return}var ah=this.high-this.low,ai=ah/2+this.low,ae=(ah/this.zoom_factor)/2;if(af){ai=af/this.viewport_container.width()*(this.high-this.low)+this.low}this.low=Math.round(ai-ae);this.high=Math.round(ai+ae);this.request_redraw()},zoom_out:function(){if(this.max_high===0){return}var af=this.high-this.low,ag=af/2+this.low,ae=(af*this.zoom_factor)/2;this.low=Math.round(ag-ae);this.high=Math.round(ag+ae);this.request_redraw()},resize_window:function(){this.viewport_container.height(this.container.height()-this.top_container.height()-this.bottom_container.height());this.nav_container.width(this.container.width());this.request_redraw()},set_overview:function(ae){$.when(ae.get_overview_tile()).then(function(af){view.overview_viewport.find(".track-tile").remove();view.overview_close.show();view.overview_viewport.append(af.canvas);view.overview_highlight.show().height(af.canvas.height());view.overview_viewport.height(af.canvas.height()+view.overview_box.outerHeight());view.resize_window();if(view.overview_track){view.overview_track.set_is_overview(false)}view.overview_track=ae;ae.set_is_overview(true)});view.has_changes=true},reset_overview:function(){this.overview_viewport.find(".track-tile").remove();this.overview_viewport.height(this.default_overview_height);this.overview_box.height(this.default_overview_height);this.overview_close.hide();this.overview_highlight.hide();view.resize_window();if(view.overview_track){view.overview_track.set_is_overview(false)}view.overview_track=null}});var q=function(ag,ak){this.track=ag;this.name=ak.name;this.params=[];var ar=ak.params;for(var ah=0;ah<ar.length;ah++){var am=ar[ah],af=am.name,aq=am.label,ai=unescape(am.html),at=am.value,ao=am.type;if(ao==="number"){this.params[this.params.length]=new g(af,aq,ai,at,am.min,am.max)}else{if(ao=="select"){this.params[this.params.length]=new M(af,aq,ai,at)}else{console.log("WARNING: unrecognized tool parameter type:",af,ao)}}}this.parent_div=$("<div/>").addClass("dynamic-tool").hide();this.parent_div.bind("drag",function(av){av.stopPropagation()}).click(function(av){av.stopPropagation()}).bind("dblclick",function(av){av.stopPropagation()});var ap=$("<div class='tool-name'>").appendTo(this.parent_div).text(this.name);var an=this.params;var al=this;$.each(this.params,function(aw,az){var ay=$("<div>").addClass("param-row").appendTo(al.parent_div);var av=$("<div>").addClass("param-label").text(az.label).appendTo(ay);var ax=$("<div/>").addClass("slider").html(az.html).appendTo(ay);ax.find(":input").val(az.value);$("<div style='clear: both;'/>").appendTo(ay)});this.parent_div.find("input").click(function(){$(this).select()});var au=$("<div>").addClass("param-row").appendTo(this.parent_div);var aj=$("<input type='submit'>").attr("value","Run on complete dataset").appendTo(au);var ae=$("<input type='submit'>").attr("value","Run on visible region").css("margin-left","3em").appendTo(au);var al=this;ae.click(function(){al.run_on_region()});aj.click(function(){al.run_on_dataset()})};p(q.prototype,{get_param_values_dict:function(){var ae={};this.parent_div.find(":input").each(function(){var af=$(this).attr("name"),ag=$(this).val();ae[af]=JSON.stringify(ag)});return ae},get_param_values:function(){var af=[];var ae={};this.parent_div.find(":input").each(function(){var ag=$(this).attr("name"),ah=$(this).val();if(ag){af[af.length]=ah}});return af},run_on_dataset:function(){var ae=this;ae.run({dataset_id:this.track.original_dataset_id,tool_id:ae.name},null,function(af){show_modal(ae.name+" is Running",ae.name+" is running on the complete dataset. Tool outputs are in dataset's history.",{Close:hide_modal})})},run_on_region:function(){var ae={dataset_id:this.track.original_dataset_id,chrom:this.track.view.chrom,low:this.track.view.low,high:this.track.view.high,tool_id:this.name},ag=this.track,af=ae.tool_id+ag.tool_region_and_parameters_str(ae.chrom,ae.low,ae.high),ah;if(ag instanceof e){ah=new T(af,view,ag.hda_ldda,undefined,{},{},ag);ah.change_mode(ag.mode)}this.track.add_track(ah);ah.content_div.text("Starting job.");this.run(ae,ah,function(ai){ah.dataset_id=ai.dataset_id;ah.content_div.text("Running job.");ah.init()})},run:function(af,ag,ah){$.extend(af,this.get_param_values_dict());var ae=function(){$.getJSON(rerun_tool_url,af,function(ai){if(ai==="no converter"){ag.container_div.addClass("error");ag.content_div.text(I)}else{if(ai.error){ag.container_div.addClass("error");ag.content_div.text(x+ai.message)}else{if(ai==="pending"){ag.container_div.addClass("pending");ag.content_div.text("Converting input data so that it can be used quickly with tool.");setTimeout(ae,2000)}else{ah(ai)}}}})};ae()}});var M=function(af,ae,ag,ah){this.name=af;this.label=ae;this.html=ag;this.value=ah};var g=function(ag,af,ai,aj,ah,ae){M.call(this,ag,af,ai,aj);this.min=ah;this.max=ae};var h=function(af,ae,ag,ah){this.name=af;this.index=ae;this.tool_id=ag;this.tool_exp_name=ah};var U=function(af,ae,ag,ah){h.call(this,af,ae,ag,ah);this.low=-Number.MAX_VALUE;this.high=Number.MAX_VALUE;this.min=Number.MAX_VALUE;this.max=-Number.MAX_VALUE;this.container=null;this.slider=null;this.slider_label=null};p(U.prototype,{applies_to:function(ae){if(ae.length>this.index){return true}return false},keep:function(ae){if(!this.applies_to(ae)){return true}var af=parseFloat(ae[this.index]);return(isNaN(af)||(af>=this.low&&af<=this.high))},update_attrs:function(af){var ae=false;if(!this.applies_to(af)){return ae}if(af[this.index]<this.min){this.min=Math.floor(af[this.index]);ae=true}if(af[this.index]>this.max){this.max=Math.ceil(af[this.index]);ae=true}return ae},update_ui_elt:function(){if(this.min!=this.max){this.container.show()}else{this.container.hide()}var ag=function(aj,ah){var ai=ah-aj;return(ai<=2?0.01:1)};var af=this.slider.slider("option","min"),ae=this.slider.slider("option","max");if(this.min<af||this.max>ae){this.slider.slider("option","min",this.min);this.slider.slider("option","max",this.max);this.slider.slider("option","step",ag(this.min,this.max));this.slider.slider("option","values",[this.min,this.max])}}});var Z=function(ao,av){this.track=ao;this.filters=[];for(var ap=0;ap<av.length;ap++){var aq=av[ap],aw=aq.name,ae=aq.type,ah=aq.index,au=aq.tool_id,at=aq.tool_exp_name;if(ae==="int"||ae==="float"){this.filters[ap]=new U(aw,ah,au,at)}else{console.log("ERROR: unsupported filter: ",aw,ae)}}var ai=function(ax,ay,az){ax.click(function(){var aA=ay.text();max=parseFloat(az.slider("option","max")),input_size=(max<=1?4:max<=1000000?max.toString().length:6),multi_value=false;if(az.slider("option","values")){input_size=2*input_size+1;multi_value=true}ay.text("");$("<input type='text'/>").attr("size",input_size).attr("maxlength",input_size).attr("value",aA).appendTo(ay).focus().select().click(function(aB){aB.stopPropagation()}).blur(function(){$(this).remove();ay.text(aA)}).keyup(function(aF){if(aF.keyCode===27){$(this).trigger("blur")}else{if(aF.keyCode===13){var aD=az.slider("option","min"),aB=az.slider("option","max"),aE=function(aG){return(isNaN(aG)||aG>aB||aG<aD)},aC=$(this).val();if(!multi_value){aC=parseFloat(aC);if(aE(aC)){alert("Parameter value must be in the range ["+aD+"-"+aB+"]");return $(this)}}else{aC=aC.split("-");aC=[parseFloat(aC[0]),parseFloat(aC[1])];if(aE(aC[0])||aE(aC[1])){alert("Parameter value must be in the range ["+aD+"-"+aB+"]");return $(this)}}az.slider((multi_value?"values":"value"),aC)}}})})};this.parent_div=$("<div/>").addClass("filters").hide();this.parent_div.bind("drag",function(ax){ax.stopPropagation()}).click(function(ax){ax.stopPropagation()}).bind("dblclick",function(ax){ax.stopPropagation()}).bind("keydown",function(ax){ax.stopPropagation()});var ar=$("<div/>").addClass("sliders").appendTo(this.parent_div);var am=this;$.each(this.filters,function(aA,aC){aC.container=$("<div/>").addClass("slider-row").appendTo(ar);var aB=$("<div/>").addClass("elt-label").appendTo(aC.container);var az=$("<span/>").addClass("slider-name").text(aC.name+"  ").appendTo(aB);var ay=$("<span/>");var aE=$("<span/>").addClass("slider-value").appendTo(aB).append("[").append(ay).append("]");var ax=$("<div/>").addClass("slider").appendTo(aC.container);aC.control_element=$("<div/>").attr("id",aC.name+"-filter-control").appendTo(ax);var aD=[0,0];aC.control_element.slider({range:true,min:Number.MAX_VALUE,max:-Number.MIN_VALUE,values:[0,0],slide:function(aG,aH){var aF=aH.values;ay.text(aF[0]+"-"+aF[1]);aC.low=aF[0];aC.high=aF[1];am.track.request_draw(true,true)},change:function(aF,aG){aC.control_element.slider("option","slide").call(aC.control_element,aF,aG)}});aC.slider=aC.control_element;aC.slider_label=ay;ai(aE,ay,aC.control_element);$("<div style='clear: both;'/>").appendTo(aC.container)});if(this.filters.length!==0){var aj=$("<div/>").addClass("param-row").appendTo(ar);var al=$("<input type='submit'/>").attr("value","Run on complete dataset").appendTo(aj);var ag=this;al.click(function(){ag.run_on_dataset()})}var an=$("<div/>").addClass("display-controls").appendTo(this.parent_div),ak=$("<span/>").addClass("elt-label").text("Transparency:").appendTo(an),af=$("<select/>").attr("name","alpha_dropdown").appendTo(an);this.alpha_filter=null;$("<option/>").attr("value",-1).text("== None ==").appendTo(af);for(var ap=0;ap<this.filters.length;ap++){$("<option/>").attr("value",ap).text(this.filters[ap].name).appendTo(af)}af.change(function(){$(this).children("option:selected").each(function(){var ax=parseInt($(this).val());am.alpha_filter=(ax>=0?am.filters[ax]:null);am.track.request_draw(true,true)})});$("<div style='clear: both;'/>").appendTo(this.parent_div)};p(Z.prototype,{reset_filters:function(){for(var ae=0;ae<this.filters.length;ae++){filter=this.filters[ae];filter.slider.slider("option","values",[filter.min,filter.max])}this.alpha_filter=null},run_on_dataset:function(){var am=function(aq,ao,ap){if(!(ao in aq)){aq[ao]=ap}return aq[ao]};var ag={},ae,af,ah;for(var ai=0;ai<this.filters.length;ai++){ae=this.filters[ai];if(ae.tool_id){if(ae.min!=ae.low){af=am(ag,ae.tool_id,[]);af[af.length]=ae.tool_exp_name+" >= "+ae.low}if(ae.max!=ae.high){af=am(ag,ae.tool_id,[]);af[af.length]=ae.tool_exp_name+" <= "+ae.high}}}var ak=[];for(var an in ag){ak[ak.length]=[an,ag[an]]}var al=ak.length;(function aj(av,ar){var ap=ar[0],aq=ap[0],au=ap[1],at="("+au.join(") and (")+")",ao={cond:at,input:av,target_dataset_id:av,tool_id:aq},ar=ar.slice(1);$.getJSON(run_tool_url,ao,function(aw){if(aw.error){show_modal("Filter Dataset","Error running tool "+aq,{Close:hide_modal})}else{if(ar.length===0){show_modal("Filtering Dataset","Filter(s) are running on the complete dataset. Outputs are in dataset's history.",{Close:hide_modal})}else{aj(aw.dataset_id,ar)}}})})(this.track.dataset_id,ak)}});var N=function(af,ae){K.AlphaGenerator.call(this,ae);this.filter=af};N.prototype.gen_alpha=function(ae){if(this.filter.high===Number.MAX_VALUE||this.filter.low===-Number.MAX_VALUE||this.filter.low===this.filter.high){return this.default_alpha}return((parseFloat(ae[this.filter.index])-this.filter.low)/(this.filter.high-this.filter.low))};var Y=function(ae){this.track=ae.track;this.params=ae.params;this.values={};if(ae.saved_values){this.restore_values(ae.saved_values)}this.onchange=ae.onchange};p(Y.prototype,{restore_values:function(ae){var af=this;$.each(this.params,function(ag,ah){if(ae[ah.key]!==undefined){af.values[ah.key]=ae[ah.key]}else{af.values[ah.key]=ah.default_value}})},build_form:function(){var af=this;var ae=$("<div />");$.each(this.params,function(aj,ah){if(!ah.hidden){var ag="param_"+aj;var ao=$("<div class='form-row' />").appendTo(ae);ao.append($("<label />").attr("for",ag).text(ah.label+":"));if(ah.type==="bool"){ao.append($('<input type="checkbox" />').attr("id",ag).attr("name",ag).attr("checked",af.values[ah.key]))}else{if(ah.type==="color"){var al=af.values[ah.key];var ak=$("<input />").attr("id",ag).attr("name",ag).val(al);var am=$("<div class='tipsy tipsy-north' style='position: absolute;' />").hide();var ai=$("<div style='background-color: black; padding: 10px;'></div>").appendTo(am);var an=$("<div/>").appendTo(ai).farbtastic({width:100,height:100,callback:ak,color:al});$("<div />").append(ak).append(am).appendTo(ao).bind("click",function(ap){am.css({left:$(this).position().left+($(ak).width()/2)-60,top:$(this).position().top+$(this.height)}).show();$(document).bind("click.color-picker",function(){am.hide();$(document).unbind("click.color-picker")});ap.stopPropagation()})}else{ao.append($("<input />").attr("id",ag).attr("name",ag).val(af.values[ah.key]))}}}});return ae},update_from_form:function(ae){var ag=this;var af=false;$.each(this.params,function(ah,aj){if(!aj.hidden){var ak="param_"+ah;var ai=ae.find("#"+ak).val();if(aj.type==="float"){ai=parseFloat(ai)}else{if(aj.type==="int"){ai=parseInt(ai)}else{if(aj.type==="bool"){ai=ae.find("#"+ak).is(":checked")}}}if(ai!==ag.values[aj.key]){ag.values[aj.key]=ai;af=true}}});if(af){this.onchange()}}});var b=function(ag,af,ae,ah){this.index=ag;this.low=ag*P*af;this.high=(ag+1)*P*af;this.resolution=af;this.canvas=$("<div class='track-tile'/>").append(ae);this.data=ah;this.stale=false};var l=function(ag,af,ae,ah,ai){b.call(this,ag,af,ae,ah);this.max_val=ai};var O=function(ag,af,ae,ai,ah){b.call(this,ag,af,ae,ai);this.message=ah};var o=function(af,ae){this.name=af;this.view=ae;this.parent_element=ae.viewport_container};o.prototype.request_draw=function(){};o.prototype.draw=function(){};var y=function(af,ae){o.call(this,af,ae);this.members=[];this.drag_handle_class="group-handle";this.container_div=$("<div/>").addClass("group").appendTo(this.parent_element);this.container_div.append($("<div/>").addClass(this.drag_handle_class));this.name_div=$("<div/>").addClass("group-name").text(this.name).appendTo(this.container_div);this.content_div=$("<div/>").addClass("content-div").appendTo(this.container_div)};p(y.prototype,o.prototype,{request_draw:function(af,ae){},draw:function(){}});var j=function(af,ae,ai,ag,ah){this.name=af;this.view=ae;this.parent_element=ai;this.data_url=(ag?ag:default_data_url);this.data_url_extra_params={};this.data_query_wait=(ah?ah:J);this.dataset_check_url=converted_datasets_state_url;this.drag_handle_class="draghandle";this.container_div=$("<div />").addClass("track").css("position","relative");if(!this.hidden){this.header_div=$("<div class='track-header' />").appendTo(this.container_div);if(this.view.editor){this.drag_div=$("<div/>").addClass(this.drag_handle_class).appendTo(this.header_div)}this.name_div=$("<div class='menubutton popup' />").appendTo(this.header_div);this.name_div.text(this.name);this.name_div.attr("id",this.name.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9\-]/g,"").toLowerCase())}this.content_div=$("<div class='track-content'>").appendTo(this.container_div);this.parent_element.append(this.container_div)};p(j.prototype,{get_type:function(){if(this instanceof aa){return"LabelTrack"}else{if(this instanceof A){return"ReferenceTrack"}else{if(this instanceof k){return"LineTrack"}else{if(this instanceof V){return"ReadTrack"}else{if(this instanceof T){return"ToolDataFeatureTrack"}else{if(this instanceof S){return"VcfTrack"}else{if(this instanceof e){return"FeatureTrack"}}}}}}}return""},init:function(){var ae=this;ae.enabled=false;ae.tile_cache.clear();ae.data_manager.clear();ae.initial_canvas=undefined;ae.content_div.css("height","auto");ae.container_div.removeClass("nodata error pending");if(!ae.dataset_id){return}$.getJSON(converted_datasets_state_url,{hda_ldda:ae.hda_ldda,dataset_id:ae.dataset_id,chrom:ae.view.chrom},function(af){if(!af||af==="error"||af.kind==="error"){ae.container_div.addClass("error");ae.content_div.text(n);if(af.message){var ah=ae.view.tracks.indexOf(ae);var ag=$(" <a href='javascript:void(0);'></a>").text("View error").click(function(){show_modal("Trackster Error","<pre>"+af.message+"</pre>",{Close:hide_modal})});ae.content_div.append(ag)}}else{if(af==="no converter"){ae.container_div.addClass("error");ae.content_div.text(I)}else{if(af==="no data"||(af.data!==undefined&&(af.data===null||af.data.length===0))){ae.container_div.addClass("nodata");ae.content_div.text(E)}else{if(af==="pending"){ae.container_div.addClass("pending");ae.content_div.text(s);setTimeout(function(){ae.init()},ae.data_query_wait)}else{if(af.status==="data"){if(af.valid_chroms){ae.valid_chroms=af.valid_chroms;ae.make_name_popup_menu()}ae.content_div.text(X);if(ae.view.chrom){ae.content_div.text("");ae.content_div.css("height",ae.height_px+"px");ae.enabled=true;$.when(ae.predraw_init()).done(function(){ae.container_div.removeClass("nodata error pending");ae.request_draw()})}}}}}}})},predraw_init:function(){},update_name:function(ae){this.old_name=this.name;this.name=ae;this.name_div.text(this.name)},revert_name:function(){this.name=this.old_name;this.name_div.text(this.name)}});var L=function(al,aj,am){var af=this,an=af.view;this.filters_manager=(al!==undefined?new Z(this,al):undefined);this.filters_available=false;this.filters_visible=false;this.tool=(aj!==undefined&&obj_length(aj)>0?new q(this,aj):undefined);this.is_overview=false;this.parent_track=am;this.child_tracks=[];if(af.hidden){return}if(this.parent_track){this.header_div.find(".draghandle").removeClass("draghandle").addClass("child-track-icon").addClass("icon-button");this.parent_element.addClass("child-track");this.tool=undefined}af.child_tracks_container=$("<div/>").addClass("child-tracks-container").hide();af.container_div.append(af.child_tracks_container);if(this.filters_manager){this.filters_div=this.filters_manager.parent_div;this.header_div.after(this.filters_div)}if(this.tool){this.dynamic_tool_div=this.tool.parent_div;this.header_div.after(this.dynamic_tool_div)}if(af.display_modes!==undefined){if(af.mode_div===undefined){af.mode_div=$("<div class='right-float menubutton popup' />").appendTo(af.header_div);var ag=(af.track_config&&af.track_config.values.mode?af.track_config.values.mode:af.display_modes[0]);af.mode=ag;af.mode_div.text(ag);var ae={};for(var ah=0,ak=af.display_modes.length;ah<ak;ah++){var ai=af.display_modes[ah];ae[ai]=function(ao){return function(){af.change_mode(ao)}}(ai)}make_popupmenu(af.mode_div,ae)}else{af.mode_div.hide()}}this.make_name_popup_menu()};p(L.prototype,j.prototype,{change_mode:function(af){var ae=this;ae.mode_div.text(af);ae.mode=af;ae.track_config.values.mode=af;ae.tile_cache.clear();ae.request_draw()},make_name_popup_menu:function(){var af=this;var ae={};ae[(this.is_overview?"Hide overview":"Set as overview")]=function(){if(af.is_overview){af.view.reset_overview()}else{af.view.set_overview(af)}};ae["Edit configuration"]=function(){var al=function(){hide_modal();$(window).unbind("keypress.check_enter_esc")},aj=function(){af.track_config.update_from_form($(".dialog-box"));hide_modal();$(window).unbind("keypress.check_enter_esc")},ak=function(am){if((am.keyCode||am.which)===27){al()}else{if((am.keyCode||am.which)===13){aj()}}};$(window).bind("keypress.check_enter_esc",ak);show_modal("Configure Track",af.track_config.build_form(),{Cancel:al,OK:aj})};if(af.filters_available>0){var ai=(af.filters_div.is(":visible")?"Hide filters":"Show filters");ae[ai]=function(){af.filters_visible=(af.filters_div.is(":visible"));if(af.filters_visible){af.filters_manager.reset_filters()}af.filters_div.toggle();af.make_name_popup_menu()}}if(af.tool){var ai=(af.dynamic_tool_div.is(":visible")?"Hide tool":"Show tool");ae[ai]=function(){if(!af.dynamic_tool_div.is(":visible")){af.update_name(af.name+af.tool_region_and_parameters_str())}else{menu_option_text="Show dynamic tool";af.revert_name()}af.dynamic_tool_div.toggle();af.make_name_popup_menu()}}if(af.valid_chroms){ae["List chrom/contigs with data"]=function(){show_modal("Chrom/contigs with data","<p>"+af.valid_chroms.join("<br/>")+"</p>",{Close:function(){hide_modal()}})}}var ag=view;var ah=function(){$("#no-tracks").show()};if(this.parent_track){ag=this.parent_track;ah=function(){}}ae.Remove=function(){ag.remove_track(af);if(ag.num_tracks===0){ah()}};make_popupmenu(af.name_div,ae)},set_is_overview:function(ae){this.is_overview=ae;this.make_name_popup_menu()},get_overview_tile:function(){var ae=this;view=ae.view,resolution=Math.pow(C,Math.ceil(Math.log((view.max_high-view.max_low)/P)/Math.log(C))),view_width=view.container.width(),w_scale=view_width/(view.max_high-view.max_low),overview_tile=$.Deferred();$.when(ae.data_manager.get_data(view.max_low,view.max_high,"Auto",resolution,ae.data_url_extra_params)).then(function(af){var ah=ae._gen_tile_cache_key(view_width,w_scale,0),aj=ae.tile_cache.get(ah);if(!aj){aj=ae.draw_tile(af,resolution,0,w_scale);ae.tile_cache.set(ah,aj)}var am=$(aj.canvas.find("canvas")),ai=am.clone(),al=am.get(0).getContext("2d"),ag=ai.get(0).getContext("2d"),ak=al.getImageData(0,0,al.canvas.width,al.canvas.height);ag.putImageData(ak,-ae.left_offset,(aj.data.dataset_type==="summary_tree"?R:0));new_tile=new b(-1,resolution,ai);overview_tile.resolve(new_tile)});return overview_tile},_gen_tile_cache_key:function(af,ag,ae){return af+"_"+ag+"_"+ae},request_draw:function(af,ae){this.view.request_redraw(false,af,ae,this)},_draw:function(ag,ap){if(!this.dataset_id){return}var ao=this.view.low,ak=this.view.high,am=ak-ao,ah=this.view.container.width(),at=ah/am,aj=this.view.resolution,ar=$("<div style='position: relative;'></div>");if(!ap){this.content_div.children().remove()}this.content_div.append(ar);this.max_height=0;var af=Math.floor(ao/aj/P);var an=true;var aq=[];var ae=0;while((af*P*aj)<ak){tile=this.draw_helper(ag,ah,af,aj,ar,at);if(tile){aq.push(tile)}else{an=false}af+=1;ae++}var ai=this;if(an){ai.postdraw_actions(aq,ah,at,ap)}for(var al=0;al<this.child_tracks.length;al++){this.child_tracks[al].request_draw(ag,ap)}},postdraw_actions:function(ai,aj,ak,ae){var ag=this;var ah=false;for(var af=0;af<ai.length;af++){if(ai[af].message){ah=true;break}}if(ah){for(var af=0;af<ai.length;af++){tile=ai[af];if(!tile.message){tile.canvas.css("padding-top",D)}}}},draw_helper:function(af,ag,ah,ak,aq,av,ar,al){var ai=this,ap=this._gen_tile_cache_key(ag,av,ah),am=ah*P*ak,au=am+P*ak;var an=(af?undefined:ai.tile_cache.get(ap));if(an){ai.show_tile(an,aq,av);return an}var ao=function(aw){return("isResolved" in aw)};var aj=true;var ae=ai.data_manager.get_data(am,au,ai.mode,ak,ai.data_url_extra_params);if(ao(ae)){aj=false}var at;if(view.reference_track&&av>view.canvas_manager.char_width_px){at=view.reference_track.data_manager.get_data(am,au,ai.mode,ak,view.reference_track.data_url_extra_params);if(ao(at)){aj=false}}if(aj){p(ae,al);var an=ai.draw_tile(ae,ak,ah,av,at);ai.tile_cache.set(ap,an);if(an!==undefined){ai.show_tile(an,aq,av)}return an}$.when(ae,at).then(function(){view.request_redraw()});return null},show_tile:function(al,an,ao){var ag=this,af=al.canvas,ak=af;if(al.message){var ap=$("<div/>"),am=$("<div/>").addClass("tile-message").text(al.message).css({height:D-1,width:al.canvas.width}).appendTo(ap),ai=$("<a href='javascript:void(0);'/>").addClass("icon more-down").appendTo(am),ae=$("<a href='javascript:void(0);'/>").addClass("icon more-across").appendTo(am);ap.append(af);ak=ap;ai.click(function(){al.stale=true;ag.data_manager.get_more_data(al.low,al.high,ag.mode,al.resolution,{},ag.data_manager.DEEP_DATA_REQ);ag.request_draw()}).dblclick(function(aq){aq.stopPropagation()});ae.click(function(){al.stale=true;ag.data_manager.get_more_data(al.low,al.high,ag.mode,al.resolution,{},ag.data_manager.BROAD_DATA_REQ);ag.request_draw()}).dblclick(function(aq){aq.stopPropagation()})}var aj=this.view.high-this.view.low,ah=(al.low-this.view.low)*ao;if(this.left_offset){ah-=this.left_offset}ak.css({position:"absolute",top:0,left:ah,height:""});an.append(ak);ag.max_height=Math.max(ag.max_height,ak.height());ag.content_div.css("height",ag.max_height+"px");an.children().css("height",ag.max_height+"px")},tool_region_and_parameters_str:function(ag,ae,ah){var af=this,ai=(ag!==undefined&&ae!==undefined&&ah!==undefined?ag+":"+ae+"-"+ah:"all");return" - region=["+ai+"], parameters=["+af.tool.get_param_values().join(", ")+"]"},add_track:function(ae){ae.track_id=this.track_id+"_"+this.child_tracks.length;ae.container_div.attr("id","track_"+ae.track_id);this.child_tracks_container.append(ae.container_div);m(ae.container_div,".child-track-icon");if(!$(this.child_tracks_container).is(":visible")){this.child_tracks_container.show()}this.child_tracks.push(ae);this.view.has_changes=true},remove_track:function(ae){ae.container_div.fadeOut("slow",function(){$(this).remove()})}});var aa=function(ae,af){this.hidden=true;j.call(this,null,ae,af);this.container_div.addClass("label-track")};p(aa.prototype,j.prototype,{_draw:function(){var ag=this.view,ah=ag.high-ag.low,ak=Math.floor(Math.pow(10,Math.floor(Math.log(ah)/Math.log(10)))),ae=Math.floor(ag.low/ak)*ak,ai=this.view.container.width(),af=$("<div style='position: relative; height: 1.3em;'></div>");while(ae<ag.high){var aj=(ae-ag.low)/ah*ai;af.append($("<div class='label'>"+commatize(ae)+"</div>").css({position:"absolute",left:aj-1}));ae+=ak}this.content_div.children(":first").remove();this.content_div.append(af)}});var A=function(ae){this.hidden=true;j.call(this,null,ae,ae.top_labeltrack);L.call(this);ae.reference_track=this;this.left_offset=200;this.height_px=12;this.container_div.addClass("reference-track");this.content_div.css("background","none");this.content_div.css("min-height","0px");this.content_div.css("border","none");this.data_url=reference_url;this.data_url_extra_params={dbkey:ae.dbkey};this.data_manager=new G(B,this,false);this.tile_cache=new c(t)};p(A.prototype,L.prototype,{draw_tile:function(am,aj,af,ao){var ai=this,ag=P*aj;if(ao>this.view.canvas_manager.char_width_px){if(am===null){ai.content_div.css("height","0px");return}var ah=this.view.canvas_manager.new_canvas();var an=ah.getContext("2d");ah.width=Math.ceil(ag*ao+ai.left_offset);ah.height=ai.height_px;an.font=an.canvas.manager.default_font;an.textAlign="center";for(var ak=0,al=am.length;ak<al;ak++){var ae=Math.round(ak*ao);an.fillText(am[ak],ae+ai.left_offset,10)}return new b(af,aj,ah,am)}this.content_div.css("height","0px")}});var k=function(ai,ag,aj,ae,ah){var af=this;this.display_modes=["Histogram","Line","Filled","Intensity"];this.mode="Histogram";j.call(this,ai,ag,ag.viewport_container);L.call(this);this.min_height_px=16;this.max_height_px=400;this.height_px=80;this.hda_ldda=aj;this.dataset_id=ae;this.original_dataset_id=ae;this.data_manager=new Q(B,this);this.tile_cache=new c(t);this.track_config=new Y({track:this,params:[{key:"color",label:"Color",type:"color",default_value:"black"},{key:"min_value",label:"Min Value",type:"float",default_value:undefined},{key:"max_value",label:"Max Value",type:"float",default_value:undefined},{key:"mode",type:"string",default_value:this.mode,hidden:true},{key:"height",type:"int",default_value:this.height_px,hidden:true}],saved_values:ah,onchange:function(){af.vertical_range=af.prefs.max_value-af.prefs.min_value;$("#linetrack_"+af.track_id+"_minval").text(af.prefs.min_value);$("#linetrack_"+af.track_id+"_maxval").text(af.prefs.max_value);af.tile_cache.clear();af.request_draw()}});this.prefs=this.track_config.values;this.height_px=this.track_config.values.height;this.vertical_range=this.track_config.values.max_value-this.track_config.values.min_value;this.add_resize_handle()};p(k.prototype,L.prototype,{add_resize_handle:function(){var ae=this;var ah=false;var ag=false;var af=$("<div class='track-resize'>");$(ae.container_div).hover(function(){ah=true;af.show()},function(){ah=false;if(!ag){af.hide()}});af.hide().bind("dragstart",function(ai,aj){ag=true;aj.original_height=$(ae.content_div).height()}).bind("drag",function(aj,ak){var ai=Math.min(Math.max(ak.original_height+ak.deltaY,ae.min_height_px),ae.max_height_px);$(ae.content_div).css("height",ai);ae.height_px=ai;ae.request_draw(true)}).bind("dragend",function(ai,aj){ae.tile_cache.clear();ag=false;if(!ah){af.hide()}ae.track_config.values.height=ae.height_px}).appendTo(ae.container_div)},predraw_init:function(){var ae=this,af=ae.view.tracks.indexOf(ae);ae.vertical_range=undefined;return $.getJSON(ae.data_url,{stats:true,chrom:ae.view.chrom,low:null,high:null,hda_ldda:ae.hda_ldda,dataset_id:ae.dataset_id},function(ag){ae.container_div.addClass("line-track");var ai=ag.data;if(isNaN(parseFloat(ae.prefs.min_value))||isNaN(parseFloat(ae.prefs.max_value))){ae.prefs.min_value=ai.min;ae.prefs.max_value=ai.max;$("#track_"+af+"_minval").val(ae.prefs.min_value);$("#track_"+af+"_maxval").val(ae.prefs.max_value)}ae.vertical_range=ae.prefs.max_value-ae.prefs.min_value;ae.total_frequency=ai.total_frequency;ae.container_div.find(".yaxislabel").remove();var aj=$("<div />").addClass("yaxislabel").attr("id","linetrack_"+af+"_minval").text(w(ae.prefs.min_value));var ah=$("<div />").addClass("yaxislabel").attr("id","linetrack_"+af+"_maxval").text(w(ae.prefs.max_value));ah.css({position:"absolute",top:"24px",left:"10px"});ah.prependTo(ae.container_div);aj.css({position:"absolute",bottom:"2px",left:"10px"});aj.prependTo(ae.container_div)})},draw_tile:function(ao,ai,af,an){if(this.vertical_range===undefined){return}var aj=af*P*ai,ah=P*ai,ae=Math.ceil(ah*an),al=this.height_px;var ag=this.view.canvas_manager.new_canvas();ag.width=ae,ag.height=al;var am=ag.getContext("2d");var ak=new K.LinePainter(ao.data,aj,aj+ah,this.prefs,this.mode);ak.draw(am,ae,al);return new b(af,ai,ag,ao.data)}});var e=function(ae,aj,ai,am,al,ag,ah,ak){var af=this;this.display_modes=["Auto","Histogram","Dense","Squish","Pack"];this.track_config=new Y({track:this,params:[{key:"block_color",label:"Block color",type:"color",default_value:"#444"},{key:"label_color",label:"Label color",type:"color",default_value:"black"},{key:"show_counts",label:"Show summary counts",type:"bool",default_value:true},{key:"mode",type:"string",default_value:this.mode,hidden:true},],saved_values:al,onchange:function(){af.tile_cache.clear();af.request_draw()}});this.prefs=this.track_config.values;j.call(this,ae,aj,aj.viewport_container);L.call(this,ag,ah,ak);this.height_px=0;this.container_div.addClass("feature-track");this.hda_ldda=ai;this.dataset_id=am;this.original_dataset_id=am;this.show_labels_scale=0.001;this.showing_details=false;this.summary_draw_height=30;this.inc_slots={};this.start_end_dct={};this.tile_cache=new c(d);this.data_manager=new Q(20,this);this.left_offset=200;this.painter=K.LinkedFeaturePainter};p(e.prototype,L.prototype,{postdraw_actions:function(au,ae,av,at){L.prototype.postdraw_actions.call(this,au,at);var ah=this;if(at){var aj=ah.content_div.children();var ak=false;for(var ai=aj.length-1,ao=0;ai>=ao;ai--){var ag=$(aj[ai]);if(ak){ag.remove()}else{if(ag.children().length!==0){ak=true}}}}if(ah.mode=="Histogram"){var an=-1;for(var ai=0;ai<au.length;ai++){var ar=au[ai].max_val;if(ar>an){an=ar}}for(var ai=0;ai<au.length;ai++){var aq=au[ai];if(aq.max_val!==an){aq.canvas.remove();ah.draw_helper(true,ae,aq.index,aq.resolution,aq.canvas.parent(),av,[],{max:an})}}}if(ah.filters_manager){var af=ah.filters_manager.filters;for(var am=0;am<af.length;am++){af[am].update_ui_elt()}var al=false,ap;for(var ai=0;ai<au.length;ai++){if(au[ai].data.length){ap=au[ai].data[0];for(var am=0;am<af.length;am++){if(af[am].applies_to(ap)){al=true;break}}}}if(ah.filters_available!==al){ah.filters_available=al;if(!ah.filters_available){ah.filters_div.hide()}ah.make_name_popup_menu()}}},update_auto_mode:function(ae){if(this.mode=="Auto"){if(ae=="no_detail"){ae="feature spans"}else{if(ae=="summary_tree"){ae="coverage histogram"}}this.mode_div.text("Auto ("+ae+")")}},incremental_slots:function(ai,af,ah){var ag=this.view.canvas_manager.dummy_context,ae=this.inc_slots[ai];if(!ae||(ae.mode!==ah)){ae=new (r.FeatureSlotter)(ai,ah==="Pack",z,function(aj){return ag.measureText(aj)});ae.mode=ah;this.inc_slots[ai]=ae}return ae.slot_features(af)},get_summary_tree_data:function(ai,al,ag,au){if(au>ag-al){au=ag-al}var ap=Math.floor((ag-al)/au),at=[],ah=0;var aj=0,ak=0,ao,ar=0,am=[],aq,an;var af=function(ax,aw,ay,av){ax[0]=aw+ay*av;ax[1]=aw+(ay+1)*av};while(ar<au&&aj!==ai.length){var ae=false;for(;ar<au&&!ae;ar++){af(am,al,ar,ap);for(ak=aj;ak<ai.length;ak++){ao=ai[ak].slice(1,3);if(is_overlap(ao,am)){ae=true;break}}if(ae){break}}data_start_index=ak;at[at.length]=aq=[am[0],0];for(;ak<ai.length;ak++){ao=ai[ak].slice(1,3);if(is_overlap(ao,am)){aq[1]++}else{break}}if(aq[1]>ah){ah=aq[1]}ar++}return{max:ah,delta:ap,data:at}},draw_tile:function(ar,aA,aE,an,ah){var ax=this,aG=aE*P*aA,af=(aE+1)*P*aA,au=af-aG,ay=Math.ceil(au*an),av=this.mode,aK=25,ai=this.left_offset,at,aj;if(av==="Auto"){if(ar.dataset_type==="summary_tree"){av=ar.dataset_type}else{if(ar.extra_info==="no_detail"){av="no_detail"}else{var aJ=ar.data;if(this.view.high-this.view.low>H){av="Squish"}else{av="Pack"}}}this.update_auto_mode(av)}if(av==="summary_tree"||av==="Histogram"){aj=this.summary_draw_height;this.container_div.find(".yaxislabel").remove();var ae=$("<div />").addClass("yaxislabel");ae.text(ar.max);ae.css({position:"absolute",top:"24px",left:"10px",color:this.prefs.label_color});ae.prependTo(this.container_div);var ag=this.view.canvas_manager.new_canvas();ag.width=ay+ai;ag.height=aj+R;if(ar.dataset_type!="summary_tree"){var ao=this.get_summary_tree_data(ar.data,aG,af,200);if(ar.max){ao.max=ar.max}ar=ao}var aH=new K.SummaryTreePainter(ar,aG,af,this.prefs);var az=ag.getContext("2d");az.translate(ai,R);aH.draw(az,ay,aj);return new l(aE,aA,ag,ar.data,ar.max)}var at,al=1;if(av==="no_detail"||av==="Squish"||av==="Pack"){al=this.incremental_slots(an,ar.data,av);at=this.inc_slots[an].slots}var am=[];if(ar.data){var ap=this.filters_manager.filters;for(var aB=0,aD=ar.data.length;aB<aD;aB++){var ak=ar.data[aB];var aC=false;var aq;for(var aF=0,aI=ap.length;aF<aI;aF++){aq=ap[aF];aq.update_attrs(ak);if(!aq.keep(ak)){aC=true;break}}if(!aC){am.push(ak)}}}var aw=(this.filters_manager.alpha_filter?new N(this.filters_manager.alpha_filter):null);var aH=new (this.painter)(am,aG,af,this.prefs,av,aw,ah);var aj=Math.max(ac,aH.get_required_height(al));var ag=this.view.canvas_manager.new_canvas();ag.width=ay+ai;ag.height=aj;var az=ag.getContext("2d");az.fillStyle=this.prefs.block_color;az.font=az.canvas.manager.default_font;az.textAlign="right";this.container_div.find(".yaxislabel").remove();if(ar.data){az.translate(ai,0);aH.draw(az,ay,aj,at)}return new O(aE,aA,ag,ar.data,ar.message)}});var S=function(ah,af,aj,ae,ag,ai){e.call(this,ah,af,aj,ae,ag,ai);this.painter=K.VariantPainter};p(S.prototype,L.prototype,e.prototype);var V=function(ah,af,aj,ae,ag,ai){e.call(this,ah,af,aj,ae,ag,ai);this.track_config=new Y({track:this,params:[{key:"block_color",label:"Block color",type:"color",default_value:"#444"},{key:"label_color",label:"Label color",type:"color",default_value:"black"},{key:"show_insertions",label:"Show insertions",type:"bool",default_value:false},{key:"show_differences",label:"Show differences only",type:"bool",default_value:true},{key:"show_counts",label:"Show summary counts",type:"bool",default_value:true},{key:"mode",type:"string",default_value:this.mode,hidden:true},],saved_values:ag,onchange:function(){this.track.tile_cache.clear();this.track.request_draw()}});this.prefs=this.track_config.values;this.painter=K.ReadPainter;this.make_name_popup_menu()};p(V.prototype,L.prototype,e.prototype);var T=function(ai,ag,ak,ae,ah,aj,af){e.call(this,ai,ag,ak,ae,ah,aj,{},af);this.data_url=raw_data_url;this.data_query_wait=1000;this.dataset_check_url=dataset_state_url};p(T.prototype,L.prototype,e.prototype,{predraw_init:function(){var af=this;var ae=function(){if(af.data_manager.size()===0){setTimeout(ae,300)}else{af.data_url=default_data_url;af.data_query_wait=J;af.dataset_state_url=converted_datasets_state_url;$.getJSON(af.dataset_state_url,{dataset_id:af.dataset_id,hda_ldda:af.hda_ldda},function(ag){})}};ae()}});W.View=ab;W.DrawableCollection=y;W.LineTrack=k;W.FeatureTrack=e;W.ReadTrack=V};var slotting_module=function(c,b){var e=c("class").extend;var d=2,a=5;b.FeatureSlotter=function(j,h,f,g){this.slots={};this.start_end_dct={};this.w_scale=j;this.include_label=h;this.max_rows=f;this.measureText=g};e(b.FeatureSlotter.prototype,{slot_features:function(m){var p=this.w_scale,s=this.slots,h=this.start_end_dct,y=[],A=[],n=0,z=this.max_rows;for(var w=0,x=m.length;w<x;w++){var l=m[w],o=l[0];if(s[o]!==undefined){n=Math.max(n,s[o]);A.push(s[o])}else{y.push(w)}}var q=function(G,H){for(var F=0;F<=z;F++){var D=false,I=h[F];if(I!==undefined){for(var C=0,E=I.length;C<E;C++){var B=I[C];if(H>B[0]&&G<B[1]){D=true;break}}}if(!D){return F}}return -1};for(var w=0,x=y.length;w<x;w++){var l=m[y[w]],o=l[0],u=l[1],f=l[2],r=l[3],g=Math.floor(u*p),k=Math.ceil(f*p),v=this.measureText(r).width,j;if(r!==undefined&&this.include_label){v+=(d+a);if(g-v>=0){g-=v;j="left"}else{k+=v;j="right"}}var t=q(g,k);if(t>=0){if(h[t]===undefined){h[t]=[]}h[t].push([g,k]);s[o]=t;n=Math.max(n,t)}else{}}return n+1}})};var painters_module=function(k,x){var u=k("class").extend;var p=function(I,A,G,z,F,D){if(D===undefined){D=4}var C=z-A;var B=F-G;var E=Math.floor(Math.sqrt(C*C+B*B)/D);var J=C/E;var H=B/E;var y;for(y=0;y<E;y++,A+=J,G+=H){if(y%2!==0){continue}I.fillRect(A,G,D,1)}};var q=function(B,A,z,E){var D=A-E/2,C=A+E/2,F=z-Math.sqrt(E*3/2);B.beginPath();B.moveTo(D,F);B.lineTo(C,F);B.lineTo(A,z);B.lineTo(D,F);B.strokeStyle=this.fillStyle;B.fill();B.stroke();B.closePath()};var g=function(y){this.default_alpha=(y?y:1)};g.prototype.gen_alpha=function(y){return this.default_alpha};var n=function(A,C,y,z,B){this.data=A;this.view_start=C;this.view_end=y;this.prefs=u({},this.default_prefs,z);this.mode=B};n.prototype.default_prefs={};var v=function(A,C,y,z,B){n.call(this,A,C,y,z,B)};v.prototype.default_prefs={show_counts:false};v.prototype.draw=function(M,z,L){var E=this.view_start,O=this.view_end-this.view_start,N=z/O;var J=this.data.data,I=this.data.delta,G=this.data.max,B=L;delta_x_px=Math.ceil(I*N);M.save();for(var C=0,D=J.length;C<D;C++){var H=Math.floor((J[C][0]-E)*N);var F=J[C][1];if(!F){continue}var K=F/G*L;if(F!==0&&K<1){K=1}M.fillStyle=this.prefs.block_color;M.fillRect(H,B-K,delta_x_px,K);var A=4;if(this.prefs.show_counts&&(M.measureText(F).width+A)<delta_x_px){M.fillStyle=this.prefs.label_color;M.textAlign="center";M.fillText(F,H+(delta_x_px/2),10)}}M.restore()};var c=function(y,C,E,F,A){n.call(this,y,C,E,F,A);if(this.prefs.min_value===undefined){var G=Infinity;for(var z=0,B=this.data.length;z<B;z++){G=Math.min(G,this.data[z][1])}this.prefs.min_value=G}if(this.prefs.max_value===undefined){var D=-Infinity;for(var z=0,B=this.data.length;z<B;z++){D=Math.max(D,this.data[z][1])}this.prefs.max_value=D}};c.prototype.default_prefs={min_value:undefined,max_value:undefined,mode:"Histogram",color:"#000",overflow_color:"#F66"};c.prototype.draw=function(N,M,K){var F=false,H=this.prefs.min_value,D=this.prefs.max_value,J=D-H,z=K,A=this.view_start,L=this.view_end-this.view_start,B=M/L,I=this.mode,T=this.data;N.save();var U=Math.round(K+H/J*K);if(I!=="Intensity"){N.fillStyle="#aaa";N.fillRect(0,U,M,1)}N.beginPath();var R,E,C;if(T.length>1){C=Math.ceil((T[1][0]-T[0][0])*B)}else{C=10}for(var O=0,P=T.length;O<P;O++){N.fillStyle=this.prefs.color;R=Math.round((T[O][0]-A)*B);E=T[O][1];var Q=false,G=false;if(E===null){if(F&&I==="Filled"){N.lineTo(R,z)}F=false;continue}if(E<H){G=true;E=H}else{if(E>D){Q=true;E=D}}if(I==="Histogram"){E=Math.round(E/J*z);N.fillRect(R,U,C,-E)}else{if(I==="Intensity"){E=255-Math.floor((E-H)/J*255);N.fillStyle="rgb("+E+","+E+","+E+")";N.fillRect(R,0,C,z)}else{E=Math.round(z-(E-H)/J*z);if(F){N.lineTo(R,E)}else{F=true;if(I==="Filled"){N.moveTo(R,z);N.lineTo(R,E)}else{N.moveTo(R,E)}}}}N.fillStyle=this.prefs.overflow_color;if(Q||G){var S;if(I==="Histogram"||I==="Intensity"){S=C}else{R-=2;S=4}if(Q){N.fillRect(R,0,S,3)}if(G){N.fillRect(R,z-3,S,3)}}N.fillStyle=this.prefs.color}if(I==="Filled"){if(F){N.lineTo(R,U);N.lineTo(0,U)}N.fill()}else{N.stroke()}N.restore()};var o=function(B,D,y,A,C,z){n.call(this,B,D,y,A,C);this.alpha_generator=(z?z:new g())};o.prototype.default_prefs={block_color:"#FFF",connector_color:"#FFF"};u(o.prototype,{get_required_height:function(z){var y=y_scale=this.get_row_height(),A=this.mode;if(A==="no_detail"||A==="Squish"||A==="Pack"){y=z*y_scale}return y+Math.max(Math.round(y_scale/2),5)},draw:function(K,B,J,G){var E=this.data,H=this.view_start,L=this.view_end;K.save();K.fillStyle=this.prefs.block_color;K.textAlign="right";var O=this.view_end-this.view_start,N=B/O,A=this.get_row_height();for(var D=0,F=E.length;D<F;D++){var M=E[D],C=M[0],y=M[1],z=M[2],I=(G&&G[C]!==undefined?G[C]:null);if((y<L&&z>H)&&(this.mode=="Dense"||I!==null)){this.draw_element(K,this.mode,M,I,H,L,N,A,B)}}K.restore()},draw_element:function(E,A,G,C,B,D,F,z,y){console.log("WARNING: Unimplemented function.")}});var d=10,j=3,m=5,w=10,f=1,s=3,e=3,a=9,l=2,h="#ccc";var r=function(B,D,y,A,C,z){o.call(this,B,D,y,A,C,z)};u(r.prototype,o.prototype,{get_row_height:function(){var z=this.mode,y;if(z==="Dense"){y=d}else{if(z==="no_detail"){y=j}else{if(z==="Squish"){y=m}else{y=w}}}return y},draw_element:function(K,D,S,F,M,ac,ag,ah,y){var P=S[0],ae=S[1],W=S[2],N=S[3],X=Math.floor(Math.max(0,(ae-M)*ag)),L=Math.ceil(Math.min(y,Math.max(0,(W-M)*ag))),V=(D==="Dense"?0:(0+F))*ah,J,aa,O=null,ai=null,B=this.prefs.block_color,Z=this.prefs.label_color;K.globalAlpha=this.alpha_generator.gen_alpha(S);if(D=="Dense"){F=1}if(D==="no_detail"){K.fillStyle=B;K.fillRect(X,V+5,L-X,f)}else{var I=S[4],U=S[5],Y=S[6],C=S[7];if(U&&Y){O=Math.floor(Math.max(0,(U-M)*ag));ai=Math.ceil(Math.min(y,Math.max(0,(Y-M)*ag)))}var af,Q;if(D==="Squish"||D==="Dense"){af=1;Q=e}else{af=5;Q=a}if(!C){if(S.strand){if(S.strand==="+"){K.fillStyle=K.canvas.manager.get_pattern("right_strand_inv")}else{if(S.strand==="-"){K.fillStyle=K.canvas.manager.get_pattern("left_strand_inv")}}}else{K.fillStyle=B}K.fillRect(X,V,L-X,Q)}else{var H,R;if(D==="Squish"||D==="Dense"){K.fillStyle=h;H=V+Math.floor(e/2)+1;R=1}else{if(I){var H=V;var R=Q;if(I==="+"){K.fillStyle=K.canvas.manager.get_pattern("right_strand")}else{if(I==="-"){K.fillStyle=K.canvas.manager.get_pattern("left_strand")}}}else{K.fillStyle=h;H+=(e/2)+1;R=1}}K.fillRect(X,H,L-X,R);for(var ad=0,A=C.length;ad<A;ad++){var E=C[ad],z=Math.floor(Math.max(0,(E[0]-M)*ag)),T=Math.ceil(Math.min(y,Math.max((E[1]-M)*ag)));if(z>T){continue}K.fillStyle=B;K.fillRect(z,V+(Q-af)/2+1,T-z,af);if(O!==undefined&&Y>U&&!(z>ai||T<O)){var ab=Math.max(z,O),G=Math.min(T,ai);K.fillRect(ab,V+1,G-ab,Q);if(C.length==1&&D=="Pack"){if(I==="+"){K.fillStyle=K.canvas.manager.get_pattern("right_strand_inv")}else{if(I==="-"){K.fillStyle=K.canvas.manager.get_pattern("left_strand_inv")}}if(ab+14<G){ab+=2;G-=2}K.fillRect(ab,V+1,G-ab,Q)}}}}if(D==="Pack"&&ae>M){K.fillStyle=Z;if(M===0&&X-K.measureText(N).width<0){K.textAlign="left";K.fillText(N,L+l,V+8)}else{K.textAlign="right";K.fillText(N,X-l,V+8)}}}K.globalAlpha=1}});var b=function(B,D,y,A,C,z){o.call(this,B,D,y,A,C,z)};u(b.prototype,o.prototype,{draw_element:function(R,M,G,C,U,A,J,S,P){var G=data[i],I=G[0],Q=G[1],B=G[2],L=G[3],E=Math.floor(Math.max(0,(Q-U)*J)),H=Math.ceil(Math.min(P,Math.max(0,(B-U)*J))),D=(M==="Dense"?0:(0+C))*S,y,V,z=null,K=null;if(no_label){R.fillStyle=block_color;R.fillRect(E+left_offset,D+5,H-E,1)}else{var T=G[4],O=G[5],F=G[6];y=9;V=1;R.fillRect(E+left_offset,D,H-E,y);if(M!=="Dense"&&L!==undefined&&Q>U){R.fillStyle=label_color;if(U===0&&E-R.measureText(L).width<0){R.textAlign="left";R.fillText(L,H+2+left_offset,D+8)}else{R.textAlign="right";R.fillText(L,E-2+left_offset,D+8)}R.fillStyle=block_color}var N=T+" / "+O;if(Q>U&&R.measureText(N).width<(H-E)){R.fillStyle="white";R.textAlign="center";R.fillText(N,left_offset+E+(H-E)/2,D+8);R.fillStyle=block_color}}}});var t=function(C,E,y,B,D,z,A){o.call(this,C,E,y,B,D,z);this.ref_seq=A};t.prototype.default_prefs=u({},o.prototype.default_prefs,{show_insertions:false});u(t.prototype,o.prototype,{get_row_height:function(){var y,z=this.mode;if(z==="Dense"){y=d}else{if(z==="Squish"){y=m}else{y=w;if(this.prefs.show_insertions){y*=2}}}return y},draw_read:function(U,P,L,Z,A,T,I,F,E){U.textAlign="center";var S=this,z=[Z,A],O=0,V=0,R=0;ref_seq=this.ref_seq,char_width_px=U.canvas.manager.char_width_px;var ae=[];if((P==="Pack"||this.mode==="Auto")&&F!==undefined&&L>char_width_px){R=Math.round(L/2)}if(!I){I=[[0,F.length]]}for(var M=0,X=I.length;M<X;M++){var J=I[M],B="MIDNSHP=X"[J[0]],N=J[1];if(B==="H"||B==="S"){O-=N}var G=T+O,ad=Math.floor(Math.max(0,(G-Z)*L)),H=Math.floor(Math.max(0,(G+N-Z)*L));if(ad===H){H+=1}switch(B){case"H":break;case"S":case"M":case"=":if(is_overlap([G,G+N],z)){var Q=F.slice(V,V+N);if(R>0){U.fillStyle=this.prefs.block_color;U.fillRect(ad-R,E+1,H-ad,9);U.fillStyle=h;for(var ab=0,y=Q.length;ab<y;ab++){if(this.prefs.show_differences&&ref_seq){var K=ref_seq[G-Z+ab];if(!K||K.toLowerCase()===Q[ab].toLowerCase()){continue}}if(G+ab>=Z&&G+ab<=A){var ac=Math.floor(Math.max(0,(G+ab-Z)*L));U.fillText(Q[ab],ac,E+9)}}}else{U.fillStyle=this.prefs.block_color;U.fillRect(ad,E+4,H-ad,e)}}V+=N;O+=N;break;case"N":U.fillStyle=h;U.fillRect(ad-R,E+5,H-ad,1);O+=N;break;case"D":U.fillStyle="red";U.fillRect(ad-R,E+4,H-ad,3);O+=N;break;case"P":break;case"I":var Y=ad-R;if(is_overlap([G,G+N],z)){var Q=F.slice(V,V+N);if(this.prefs.show_insertions){var D=ad-(H-ad)/2;if((P==="Pack"||this.mode==="Auto")&&F!==undefined&&L>char_width_px){U.fillStyle="yellow";U.fillRect(D-R,E-9,H-ad,9);ae[ae.length]={type:"triangle",data:[Y,E+4,5]};U.fillStyle=h;switch(seq_tile_overlap){case (OVERLAP_START):Q=Q.slice(Z-G);break;case (OVERLAP_END):Q=Q.slice(0,G-A);break;case (CONTAINED_BY):break;case (CONTAINS):Q=Q.slice(Z-G,G-A);break}for(var ab=0,y=Q.length;ab<y;ab++){var ac=Math.floor(Math.max(0,(G+ab-Z)*L));U.fillText(Q[ab],ac-(H-ad)/2,E)}}else{U.fillStyle="yellow";U.fillRect(D,E+(this.mode!=="Dense"?2:5),H-ad,(P!=="Dense"?e:s))}}else{if((P==="Pack"||this.mode==="Auto")&&F!==undefined&&L>char_width_px){ae[ae.length]={type:"text",data:[Q.length,Y,E+9]}}else{}}}V+=N;break;case"X":V+=N;break}}U.fillStyle="yellow";var aa,C,af;for(var W=0;W<ae.length;W++){aa=ae[W];C=aa.type;af=aa.data;if(C==="text"){U.save();U.font="bold "+U.font;U.fillText(af[0],af[1],af[2]);U.restore()}else{if(C=="triangle"){q(U,af[0],af[1],af[2])}}}},draw_element:function(R,M,E,B,U,z,I,S,P){var H=E[0],Q=E[1],A=E[2],J=E[3],D=Math.floor(Math.max(0,(Q-U)*I)),F=Math.ceil(Math.min(P,Math.max(0,(A-U)*I))),C=(M==="Dense"?0:(0+B))*S,V=this.prefs.block_color,G=this.prefs.label_color,O=0;if((M==="Pack"||this.mode==="Auto")&&I>R.canvas.manager.char_width_px){var O=Math.round(I/2)}R.fillStyle=V;if(E[5] instanceof Array){var N=Math.floor(Math.max(0,(E[4][0]-U)*I)),L=Math.ceil(Math.min(P,Math.max(0,(E[4][1]-U)*I))),K=Math.floor(Math.max(0,(E[5][0]-U)*I)),y=Math.ceil(Math.min(P,Math.max(0,(E[5][1]-U)*I)));if(E[4][1]>=U&&E[4][0]<=z&&E[4][2]){this.draw_read(R,M,I,U,z,E[4][0],E[4][2],E[4][3],C)}if(E[5][1]>=U&&E[5][0]<=z&&E[5][2]){this.draw_read(R,M,I,U,z,E[5][0],E[5][2],E[5][3],C)}if(K>L){R.fillStyle=h;p(R,L-O,C+5,K-O,C+5)}}else{R.fillStyle=V;this.draw_read(R,M,I,U,z,Q,E[4],E[5],C)}if(M==="Pack"&&Q>U){R.fillStyle=this.prefs.label_color;var T=1;if(T===0&&D-R.measureText(J).width<0){R.textAlign="left";R.fillText(J,F+l-O,C+8)}else{R.textAlign="right";R.fillText(J,D-l-O,C+8)}R.fillStyle=V}}});x.AlphaGenerator=g;x.SummaryTreePainter=v;x.LinePainter=c;x.LinkedFeaturePainter=r;x.ReadPainter=t;x.VariantPainter=b};(function(d){var c={};var b=function(e){return c[e]};var a=function(f,g){var e={};g(b,e);c[f]=e};a("class",class_module);a("slotting",slotting_module);a("painters",painters_module);a("trackster",trackster_module);for(key in c.trackster){d[key]=c.trackster[key]}})(window);

File static/scripts/trackster.js

 // ---- Web UI specific utilities ----
 
 /** 
- * Make `element` sortable in parent by dragging `handle` (a selector)
+ * Make `element` moveable within parent and sibling elements by dragging `handle` (a selector).
  */
-var sortable = function( element, handle ) {
+var moveable = function( element, handle, container_selector ) {
+    // HACK: set default value for container selector.
+    container_selector = ".group";
+    var css_border_props = {};
     element.bind( "drag", { handle: handle, relative: true }, function ( e, d ) {
-        var parent = $(this).parent();
-        var children = parent.children();
-        var i;
+        var 
+            parent = $(this).parent(),
+            children = parent.children(),
+            child,
+            container,
+            top,
+            bottom,
+            i;
+            
+        //
+        // Enable three types of dragging: (a) out of container; (b) into container; 
+        // (c) sibling movement, aka sorting. Handle in this order for simplicity.
+        //
+        
+        // Handle dragging out of container.
+        container = $(this).parents(container_selector);
+        if (container.length !== 0) {
+            top = container.position().top;
+            bottom = top + container.outerHeight();
+            if (d.offsetY < top) {
+                // Moving above container.
+                $(this).insertBefore(container);
+                return;
+            }
+            else if (d.offsetY > bottom) {
+                // Moving below container.
+                $(this).insertAfter(container);
+                return;
+            }
+        }
+        
+        // Handle dragging into container.
+        container = null;
+        for ( i = 0; i < children.length; i++ ) {
+            child = $(children.get(i));
+            top = child.position().top;
+            bottom = top + child.outerHeight();
+            // Dragging into container if child is a container and offset is inside container.
+            if ( child.is(container_selector) && this !== child.get(0) && 
+                 d.offsetY >= top && d.offsetY <= bottom ) {
+                // Append/prepend based on where offsetY is closest to and return.
+                if (d.offsetY - top < bottom - d.offsetY) {
+                    child.find(".content-div").prepend(this);
+                }
+                else {
+                    child.find(".content-div").append(this);
+                }
+                return;
+            }
+        }
+
+        // Handle sibling movement, aka sorting.
+        
         // Determine new position
         for ( i = 0; i < children.length; i++ ) {
             if ( d.offsetY < $(children.get(i)).position().top ) {
             $(this).insertBefore( children.get(i) );
         }
     }).bind("dragstart", function() {
+        css_border_props["border-top"] = element.css("border-top");
+        css_border_props["border-bottom"] = element.css("border-bottom");
         $(this).css({
             "border-top": "1px solid blue",
             "border-bottom": "1px solid blue"
         });
     }).bind("dragend", function() {
-        $(this).css("border", "0px");
+        $(this).css(css_border_props);
     });
 };
-exports.sortable = sortable;
+
+// TODO: do we need to export?
+exports.moveable = moveable;
 
 /**
  * Init constants & functions used throughout trackster.
         this.tracks.push(track);
         if (track.init) { track.init(); }
         track.container_div.attr('id', 'track_' + track.track_id);
-        sortable( track.container_div, '.draghandle' );
+        moveable(track.container_div, track.drag_handle);
         this.track_id_counter += 1;
         this.num_tracks += 1;
         this.has_changes = true;
 };
 
 /**
+ * Base interface for all drawable objects.
+ * TODO: Tracks should use this interface.
+ */
+var Drawable = function(name, view) {
+    this.name = name;
+    this.view = view;
+    this.parent_element = view.viewport_container;
+};
+
+Drawable.prototype.request_draw = function() {};
+Drawable.prototype.draw = function() {};
+
+/**
+ * A collection of drawable objects.
+ */
+var DrawableCollection = function(name, view) {
+    Drawable.call(this, name, view);
+    
+    // Attribute init.
+    this.members = [];
+    this.drag_handle_class = "group-handle";
+    
+    // HTML elements.
+    this.container_div = $("<div/>").addClass("group").appendTo(this.parent_element);
+    this.container_div.append($("<div/>").addClass(this.drag_handle_class));
+    this.name_div = $("<div/>").addClass("group-name").text(this.name).appendTo(this.container_div);
+    this.content_div = $("<div/>").addClass("content-div").appendTo(this.container_div);
+};
+extend(DrawableCollection.prototype, Drawable.prototype, {
+    request_draw: function(force, clear_after) {
+        
+    },
+    draw: function() {
+        
+    }
+});
+
+/**
  * Tracks are objects can be added to the View. 
  * 
  * Track object hierarchy:
     this.data_url_extra_params = {}
     this.data_query_wait = (data_query_wait ? data_query_wait : DEFAULT_DATA_QUERY_WAIT);
     this.dataset_check_url = converted_datasets_state_url;
+    this.drag_handle_class = "draghandle";
     
     //
     // Create HTML element structure for track.
     this.container_div = $("<div />").addClass('track').css("position", "relative");
     if (!this.hidden) {
         this.header_div = $("<div class='track-header' />").appendTo(this.container_div);
-        if (this.view.editor) { this.drag_div = $("<div class='draghandle' />").appendTo(this.header_div); }
+        if (this.view.editor) { this.drag_div = $("<div/>").addClass(this.drag_handle_class).appendTo(this.header_div); }
         this.name_div = $("<div class='menubutton popup' />").appendTo(this.header_div);
         this.name_div.text(this.name);
         this.name_div.attr( "id", this.name.replace(/\s+/g,'-').replace(/[^a-zA-Z0-9\-]/g,'').toLowerCase() );
         child_track.track_id = this.track_id + "_" + this.child_tracks.length;
         child_track.container_div.attr('id', 'track_' + child_track.track_id);
         this.child_tracks_container.append(child_track.container_div);
-        sortable( child_track.container_div, '.child-track-icon' );
+        moveable( child_track.container_div, '.child-track-icon' );
         if (!$(this.child_tracks_container).is(":visible")) {
             this.child_tracks_container.show();
         }
 // Exports
 
 exports.View = View;
+exports.DrawableCollection = DrawableCollection;
 exports.LineTrack = LineTrack;
 exports.FeatureTrack = FeatureTrack;
 exports.ReadTrack = ReadTrack;

File templates/tracks/browser.mako

             $("#viz-actions-button").css( "position", "relative" );
             make_popupmenu( $("#viz-actions-button"), {
                 "Add Tracks": add_tracks,
+                "Add Group": function() {
+                    var group = new DrawableCollection("New Group", view);
+                    view.add_track(group);
+                },
                 "Save": function() {
                     // Show saving dialog box
                     show_modal("Saving...", "<img src='${h.url_for('/static/images/yui/rel_interstitial_loading.gif')}'/>");