5 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/9b86d73f9aea/ Changeset: 9b86d73f9aea Branch: next-stable User: jeremy goecks Date: 2014-02-05 22:22:17 Summary: Fix bugs that prevented saving visualizations from Circster. To do this, introduced a mixin for custom toJSON methods. Pack scripts. Affected #: 4 files diff -r ce8a3e4414e6ea4e761d3b40b66541e8c53471fa -r 9b86d73f9aea574862eed1f6a0c02c9171ed2c3e static/scripts/packed/viz/circster.js --- a/static/scripts/packed/viz/circster.js +++ b/static/scripts/packed/viz/circster.js @@ -1,1 +1,1 @@ -define(["utils/utils","libs/underscore","libs/d3","viz/visualization"],function(g,h,m,j){g.cssLoadFile("static/style/circster.css");var n=Backbone.Model.extend({is_visible:function(r,o){var p=r.getBoundingClientRect(),q=$("svg")[0].getBoundingClientRect();if(p.right<0||p.left>q.right||p.bottom<0||p.top>q.bottom){return false}return true}});var i={drawTicks:function(s,r,w,q,o){var v=s.append("g").selectAll("g").data(r).enter().append("g").selectAll("g").data(w).enter().append("g").attr("class","tick").attr("transform",function(x){return"rotate("+(x.angle*180/Math.PI-90)+")translate("+x.radius+",0)"});var u=[],t=[],p=function(x){return x.angle>Math.PI?"end":null};if(o){u=[0,0,0,-4];t=[4,0,"",".35em"];p=null}else{u=[1,0,4,0];t=[0,4,".35em",""]}v.append("line").attr("x1",u[0]).attr("y1",u[1]).attr("x2",u[2]).attr("y1",u[3]).style("stroke","#000");v.append("text").attr("x",t[0]).attr("y",t[1]).attr("dx",t[2]).attr("dy",t[3]).attr("text-anchor",p).attr("transform",q).text(function(x){return x.label})},formatNum:function(p,o){if(o===undefined){o=2}if(p===null){return null}var r=null;if(p<1){r=p.toPrecision(o)}else{var q=Math.round(p.toPrecision(o));if(p<1000){r=q}else{if(p<1000000){r=Math.round((q/1000).toPrecision(3)).toFixed(0)+"K"}else{if(p<1000000000){r=Math.round((q/1000000).toPrecision(3)).toFixed(0)+"M"}}}}return r}};var c=Backbone.Model.extend({});var a=Backbone.View.extend({className:"circster",initialize:function(o){this.total_gap=o.total_gap;this.genome=o.genome;this.dataset_arc_height=o.dataset_arc_height;this.track_gap=10;this.label_arc_height=50;this.scale=1;this.circular_views=null;this.chords_views=null;this.model.get("tracks").on("add",this.add_track,this);this.model.get("tracks").on("remove",this.remove_track,this);this.get_circular_tracks()},get_circular_tracks:function(){return this.model.get("tracks").filter(function(o){return o.get("track_type")!=="DiagonalHeatmapTrack"})},get_chord_tracks:function(){return this.model.get("tracks").filter(function(o){return o.get("track_type")==="DiagonalHeatmapTrack"})},get_tracks_bounds:function(){var p=this.get_circular_tracks();dataset_arc_height=this.dataset_arc_height,min_dimension=Math.min(this.$el.width(),this.$el.height()),radius_start=min_dimension/2-p.length*(this.dataset_arc_height+this.track_gap)-(this.label_arc_height+this.track_gap),tracks_start_radii=m.range(radius_start,min_dimension/2,this.dataset_arc_height+this.track_gap);var o=this;return h.map(tracks_start_radii,function(q){return[q,q+o.dataset_arc_height]})},render:function(){var x=this,r=this.dataset_arc_height,o=x.$el.width(),w=x.$el.height(),t=this.get_circular_tracks(),q=this.get_chord_tracks(),s=this.get_tracks_bounds(),p=m.select(x.$el[0]).append("svg").attr("width",o).attr("height",w).attr("pointer-events","all").append("svg:g").call(m.behavior.zoom().on("zoom",function(){var y=m.event.scale;p.attr("transform","translate("+m.event.translate+") scale("+y+")");if(x.scale!==y){if(x.zoom_drag_timeout){clearTimeout(x.zoom_drag_timeout)}x.zoom_drag_timeout=setTimeout(function(){},400)}})).attr("transform","translate("+o/2+","+w/2+")").append("svg:g").attr("class","tracks");this.circular_views=t.map(function(z,A){var y=new d({el:p.append("g")[0],track:z,radius_bounds:s[A],genome:x.genome,total_gap:x.total_gap});y.render();return y});this.chords_views=q.map(function(z){var y=new k({el:p.append("g")[0],track:z,radius_bounds:s[0],genome:x.genome,total_gap:x.total_gap});y.render();return y});var v=this.circular_views[this.circular_views.length-1].radius_bounds[1],u=[v,v+this.label_arc_height];this.label_track_view=new b({el:p.append("g")[0],track:new c(),radius_bounds:u,genome:x.genome,total_gap:x.total_gap});this.label_track_view.render()},add_track:function(u){if(u.get("track_type")==="DiagonalHeatmapTrack"){var q=this.circular_views[0].radius_bounds,t=new k({el:m.select("g.tracks").append("g")[0],track:u,radius_bounds:q,genome:this.genome,total_gap:this.total_gap});t.render();this.chords_views.push(t)}else{var s=this.get_tracks_bounds();h.each(this.circular_views,function(v,w){v.update_radius_bounds(s[w])});h.each(this.chords_views,function(v){v.update_radius_bounds(s[0])});var r=this.circular_views.length,o=new d({el:m.select("g.tracks").append("g")[0],track:u,radius_bounds:s[r],genome:this.genome,total_gap:this.total_gap});o.render();this.circular_views.push(o);var p=s[s.length-1];p[1]=p[0];this.label_track_view.update_radius_bounds(p)}},remove_track:function(p,r,q){var o=this.circular_views[q.index];this.circular_views.splice(q.index,1);o.$el.remove();var s=this.get_tracks_bounds();h.each(this.circular_views,function(t,u){t.update_radius_bounds(s[u])})}});var l=Backbone.View.extend({tagName:"g",initialize:function(o){this.bg_stroke="ccc";this.loading_bg_fill="000";this.bg_fill="ccc";this.total_gap=o.total_gap;this.track=o.track;this.radius_bounds=o.radius_bounds;this.genome=o.genome;this.chroms_layout=this._chroms_layout();this.data_bounds=[];this.scale=1;this.parent_elt=m.select(this.$el[0])},get_fill_color:function(){var o=this.track.get("config").get_value("block_color");if(!o){o=this.track.get("config").get_value("color")}return o},render:function(){var s=this.parent_elt;if(!s){console.log("no parent elt")}var r=this.chroms_layout,u=m.svg.arc().innerRadius(this.radius_bounds[0]).outerRadius(this.radius_bounds[1]),o=s.selectAll("g").data(r).enter().append("svg:g"),q=o.append("path").attr("d",u).attr("class","chrom-background").style("stroke",this.bg_stroke).style("fill",this.loading_bg_fill);q.append("title").text(function(w){return w.data.chrom});var p=this,t=p.track.get("data_manager"),v=(t?t.data_is_ready():true);$.when(v).then(function(){$.when(p._render_data(s)).then(function(){q.style("fill",p.bg_fill);p.render_labels()})})},render_labels:function(){},update_radius_bounds:function(p){this.radius_bounds=p;var o=m.svg.arc().innerRadius(this.radius_bounds[0]).outerRadius(this.radius_bounds[1]);this.parent_elt.selectAll("g>path.chrom-background").transition().duration(1000).attr("d",o);this._transition_chrom_data();this._transition_labels()},update_scale:function(r){var q=this.scale;this.scale=r;if(r<=q){return}var p=this,o=new n();this.parent_elt.selectAll("path.chrom-data").filter(function(t,s){return o.is_visible(this)}).each(function(y,u){var x=m.select(this),t=x.attr("chrom"),w=p.genome.get_chrom_region(t),v=p.track.get("data_manager"),s;if(!v.can_get_more_detailed_data(w)){return}s=p.track.get("data_manager").get_more_detailed_data(w,"Coverage",0,r);$.when(s).then(function(B){x.remove();p._update_data_bounds();var A=h.find(p.chroms_layout,function(C){return C.data.chrom===t});var z=p.get_fill_color();p._render_chrom_data(p.parent_elt,A,B).style("stroke",z).style("fill",z)})});return p},_transition_chrom_data:function(){var p=this.track,r=this.chroms_layout,o=this.parent_elt.selectAll("g>path.chrom-data"),s=o[0].length;if(s>0){var q=this;$.when(p.get("data_manager").get_genome_wide_data(this.genome)).then(function(u){var t=h.reject(h.map(u,function(v,w){var x=null,y=q._get_path_function(r[w],v);if(y){x=y(v.data)}return x}),function(v){return v===null});o.each(function(w,v){m.select(this).transition().duration(1000).attr("d",t[v])})})}},_transition_labels:function(){},_update_data_bounds:function(){var o=this.data_bounds;this.data_bounds=this.get_data_bounds(this.track.get("data_manager").get_genome_wide_data(this.genome));if(this.data_bounds[0]<o[0]||this.data_bounds[1]>o[1]){this._transition_chrom_data()}},_render_data:function(r){var q=this,p=this.chroms_layout,o=this.track,s=$.Deferred();$.when(o.get("data_manager").get_genome_wide_data(this.genome)).then(function(u){q.data_bounds=q.get_data_bounds(u);layout_and_data=h.zip(p,u),chroms_data_layout=h.map(layout_and_data,function(v){var w=v[0],x=v[1];return q._render_chrom_data(r,w,x)});var t=q.get_fill_color();q.parent_elt.selectAll("path.chrom-data").style("stroke",t).style("fill",t);s.resolve(r)});return s},_render_chrom_data:function(o,p,q){},_get_path_function:function(p,o){},_chroms_layout:function(){var p=this.genome.get_chroms_info(),r=m.layout.pie().value(function(t){return t.len}).sort(null),s=r(p),o=this.total_gap/p.length,q=h.map(s,function(v,u){var t=v.endAngle-o;v.endAngle=(t>v.startAngle?t:v.startAngle);return v});return q}});var b=l.extend({initialize:function(o){l.prototype.initialize.call(this,o);this.innerRadius=this.radius_bounds[0];this.radius_bounds[0]=this.radius_bounds[1];this.bg_stroke="fff";this.bg_fill="fff";this.min_arc_len=0.05},_render_data:function(q){var p=this,o=q.selectAll("g");o.selectAll("path").attr("id",function(u){return"label-"+u.data.chrom});o.append("svg:text").filter(function(u){return u.endAngle-u.startAngle>p.min_arc_len}).attr("text-anchor","middle").append("svg:textPath").attr("class","chrom-label").attr("xlink:href",function(u){return"#label-"+u.data.chrom}).attr("startOffset","25%").text(function(u){return u.data.chrom});var r=function(w){var u=(w.endAngle-w.startAngle)/w.value,v=m.range(0,w.value,25000000).map(function(x,y){return{radius:p.innerRadius,angle:x*u+w.startAngle,label:y===0?0:(y%3?null:p.formatNum(x))}});if(v.length<4){v[v.length-1].label=p.formatNum(Math.round((v[v.length-1].angle-w.startAngle)/u))}return v};var t=function(u){return u.angle>Math.PI?"rotate(180)translate(-16)":null};var s=h.filter(this.chroms_layout,function(u){return u.endAngle-u.startAngle>p.min_arc_len});this.drawTicks(this.parent_elt,s,r,t)}});h.extend(b.prototype,i);var f=l.extend({_quantile:function(p,o){p.sort(m.ascending);return m.quantile(p,o)},_render_chrom_data:function(o,r,p){var s=this._get_path_function(r,p);if(!s){return null}var q=o.datum(p.data),t=q.append("path").attr("class","chrom-data").attr("chrom",r.data.chrom).attr("d",s);return t},_get_path_function:function(r,q){if(typeof q==="string"||!q.data||q.data.length===0){return null}var o=m.scale.linear().domain(this.data_bounds).range(this.radius_bounds).clamp(true);var s=m.scale.linear().domain([0,q.data.length]).range([r.startAngle,r.endAngle]);var p=m.svg.line.radial().interpolate("linear").radius(function(t){return o(t[1])}).angle(function(u,t){return s(t)});return m.svg.area.radial().interpolate(p.interpolate()).innerRadius(o(0)).outerRadius(p.radius()).angle(p.angle())},render_labels:function(){var o=this,p=function(){return"rotate(90)"};this.drawTicks(this.parent_elt,[this.chroms_layout[0]],this._data_bounds_ticks_fn(),p,true)},_transition_labels:function(){if(this.data_bounds.length===0){return}var p=this,r=h.filter(this.chroms_layout,function(s){return s.endAngle-s.startAngle>0.08}),q=h.filter(r,function(t,s){return s%3===0}),o=h.flatten(h.map(q,function(s){return p._data_bounds_ticks_fn()(s)}));this.parent_elt.selectAll("g.tick").data(o).transition().attr("transform",function(s){return"rotate("+(s.angle*180/Math.PI-90)+")translate("+s.radius+",0)"})},_data_bounds_ticks_fn:function(){var o=this;visibleChroms=0;return function(p){return[{radius:o.radius_bounds[0],angle:p.startAngle,label:o.formatNum(o.data_bounds[0])},{radius:o.radius_bounds[1],angle:p.startAngle,label:o.formatNum(o.data_bounds[1])}]}},get_data_bounds:function(o){}});h.extend(f.prototype,i);var d=f.extend({get_data_bounds:function(p){var o=h.flatten(h.map(p,function(q){if(q){return h.map(q.data,function(r){return parseInt(r[1],10)||0})}else{return 0}}));return[h.min(o),this._quantile(o,0.98)||h.max(o)]}});var k=l.extend({render:function(){var o=this;$.when(o.track.get("data_manager").data_is_ready()).then(function(){$.when(o.track.get("data_manager").get_genome_wide_data(o.genome)).then(function(r){var q=[],p=o.genome.get_chroms_info();h.each(r,function(v,u){var s=p[u].chrom;var t=h.map(v.data,function(x){var w=o._get_region_angle(s,x[1]),y=o._get_region_angle(x[3],x[4]);return{source:{startAngle:w,endAngle:w+0.01},target:{startAngle:y,endAngle:y+0.01}}});q=q.concat(t)});o.parent_elt.append("g").attr("class","chord").selectAll("path").data(q).enter().append("path").style("fill",o.get_fill_color()).attr("d",m.svg.chord().radius(o.radius_bounds[0])).style("opacity",1)})})},update_radius_bounds:function(o){this.radius_bounds=o;this.parent_elt.selectAll("path").transition().attr("d",m.svg.chord().radius(this.radius_bounds[0]))},_get_region_angle:function(q,o){var p=h.find(this.chroms_layout,function(r){return r.data.chrom===q});return p.endAngle-((p.endAngle-p.startAngle)*(p.data.len-o)/p.data.len)}});var e=Backbone.View.extend({initialize:function(){var o=new j.Genome(galaxy_config.app.genome),p=new j.GenomeVisualization(galaxy_config.app.viz_config),r=new a({el:$("#center .unified-panel-body"),total_gap:2*Math.PI*0.4,genome:o,model:p,dataset_arc_height:25});r.render();$("#center .unified-panel-header-inner").append(galaxy_config.app.viz_config.title+" "+galaxy_config.app.viz_config.dbkey);var q=create_icon_buttons_menu([{icon_class:"plus-button",title:"Add tracks",on_click:function(){j.select_datasets(galaxy_config.root+"visualization/list_current_history_datasets",galaxy_config.root+"api/datasets",p.get("dbkey"),function(s){p.add_tracks(s)})}},{icon_class:"disk--arrow",title:"Save",on_click:function(){Galaxy.modal.show({title:"Saving...",body:"progress"});var s=galaxy_config.app.viz_config;$.ajax({url:galaxy_config.root+"visualization/save",type:"POST",dataType:"json",data:{id:s.vis_id,title:s.title,dbkey:s.dbkey,type:"trackster",vis_json:JSON.stringify(s)}}).success(function(t){Galaxy.modal.hide();s.vis_id=t.vis_id;s.has_changes=false;window.history.pushState({},"",t.url+window.location.hash)}).error(function(){Galaxy.modal.show({title:"Could Not Save",body:"Could not save visualization. Please try again later.",buttons:{Cancel:function(){Galaxy.modal.hide()}}})})}},{icon_class:"cross-circle",title:"Close",on_click:function(){window.location=galaxy_config.root+"visualization/list"}}],{tooltip_config:{placement:"bottom"}});q.$el.attr("style","float: right");$("#center .unified-panel-header-inner").append(q.$el);$(".menu-button").tooltip({placement:"bottom"})}});return{GalaxyApp:e}}); \ No newline at end of file +define(["utils/utils","libs/underscore","libs/d3","viz/visualization"],function(g,h,m,j){g.cssLoadFile("static/style/circster.css");var n=Backbone.Model.extend({is_visible:function(r,o){var p=r.getBoundingClientRect(),q=$("svg")[0].getBoundingClientRect();if(p.right<0||p.left>q.right||p.bottom<0||p.top>q.bottom){return false}return true}});var i={drawTicks:function(s,r,w,q,o){var v=s.append("g").selectAll("g").data(r).enter().append("g").selectAll("g").data(w).enter().append("g").attr("class","tick").attr("transform",function(x){return"rotate("+(x.angle*180/Math.PI-90)+")translate("+x.radius+",0)"});var u=[],t=[],p=function(x){return x.angle>Math.PI?"end":null};if(o){u=[0,0,0,-4];t=[4,0,"",".35em"];p=null}else{u=[1,0,4,0];t=[0,4,".35em",""]}v.append("line").attr("x1",u[0]).attr("y1",u[1]).attr("x2",u[2]).attr("y1",u[3]).style("stroke","#000");v.append("text").attr("x",t[0]).attr("y",t[1]).attr("dx",t[2]).attr("dy",t[3]).attr("text-anchor",p).attr("transform",q).text(function(x){return x.label})},formatNum:function(p,o){if(o===undefined){o=2}if(p===null){return null}var r=null;if(p<1){r=p.toPrecision(o)}else{var q=Math.round(p.toPrecision(o));if(p<1000){r=q}else{if(p<1000000){r=Math.round((q/1000).toPrecision(3)).toFixed(0)+"K"}else{if(p<1000000000){r=Math.round((q/1000000).toPrecision(3)).toFixed(0)+"M"}}}}return r}};var c=Backbone.Model.extend({});var a=Backbone.View.extend({className:"circster",initialize:function(o){this.total_gap=o.total_gap;this.genome=o.genome;this.dataset_arc_height=o.dataset_arc_height;this.track_gap=10;this.label_arc_height=50;this.scale=1;this.circular_views=null;this.chords_views=null;this.model.get("drawables").on("add",this.add_track,this);this.model.get("drawables").on("remove",this.remove_track,this);this.get_circular_tracks()},get_circular_tracks:function(){return this.model.get("drawables").filter(function(o){return o.get("track_type")!=="DiagonalHeatmapTrack"})},get_chord_tracks:function(){return this.model.get("drawables").filter(function(o){return o.get("track_type")==="DiagonalHeatmapTrack"})},get_tracks_bounds:function(){var p=this.get_circular_tracks();dataset_arc_height=this.dataset_arc_height,min_dimension=Math.min(this.$el.width(),this.$el.height()),radius_start=min_dimension/2-p.length*(this.dataset_arc_height+this.track_gap)-(this.label_arc_height+this.track_gap),tracks_start_radii=m.range(radius_start,min_dimension/2,this.dataset_arc_height+this.track_gap);var o=this;return h.map(tracks_start_radii,function(q){return[q,q+o.dataset_arc_height]})},render:function(){var x=this,r=this.dataset_arc_height,o=x.$el.width(),w=x.$el.height(),t=this.get_circular_tracks(),q=this.get_chord_tracks(),s=this.get_tracks_bounds(),p=m.select(x.$el[0]).append("svg").attr("width",o).attr("height",w).attr("pointer-events","all").append("svg:g").call(m.behavior.zoom().on("zoom",function(){var y=m.event.scale;p.attr("transform","translate("+m.event.translate+") scale("+y+")");if(x.scale!==y){if(x.zoom_drag_timeout){clearTimeout(x.zoom_drag_timeout)}x.zoom_drag_timeout=setTimeout(function(){},400)}})).attr("transform","translate("+o/2+","+w/2+")").append("svg:g").attr("class","tracks");this.circular_views=t.map(function(z,A){var y=new d({el:p.append("g")[0],track:z,radius_bounds:s[A],genome:x.genome,total_gap:x.total_gap});y.render();return y});this.chords_views=q.map(function(z){var y=new k({el:p.append("g")[0],track:z,radius_bounds:s[0],genome:x.genome,total_gap:x.total_gap});y.render();return y});var v=this.circular_views[this.circular_views.length-1].radius_bounds[1],u=[v,v+this.label_arc_height];this.label_track_view=new b({el:p.append("g")[0],track:new c(),radius_bounds:u,genome:x.genome,total_gap:x.total_gap});this.label_track_view.render()},add_track:function(u){if(u.get("track_type")==="DiagonalHeatmapTrack"){var q=this.circular_views[0].radius_bounds,t=new k({el:m.select("g.tracks").append("g")[0],track:u,radius_bounds:q,genome:this.genome,total_gap:this.total_gap});t.render();this.chords_views.push(t)}else{var s=this.get_tracks_bounds();h.each(this.circular_views,function(v,w){v.update_radius_bounds(s[w])});h.each(this.chords_views,function(v){v.update_radius_bounds(s[0])});var r=this.circular_views.length,o=new d({el:m.select("g.tracks").append("g")[0],track:u,radius_bounds:s[r],genome:this.genome,total_gap:this.total_gap});o.render();this.circular_views.push(o);var p=s[s.length-1];p[1]=p[0];this.label_track_view.update_radius_bounds(p)}},remove_track:function(p,r,q){var o=this.circular_views[q.index];this.circular_views.splice(q.index,1);o.$el.remove();var s=this.get_tracks_bounds();h.each(this.circular_views,function(t,u){t.update_radius_bounds(s[u])})}});var l=Backbone.View.extend({tagName:"g",initialize:function(o){this.bg_stroke="ccc";this.loading_bg_fill="000";this.bg_fill="ccc";this.total_gap=o.total_gap;this.track=o.track;this.radius_bounds=o.radius_bounds;this.genome=o.genome;this.chroms_layout=this._chroms_layout();this.data_bounds=[];this.scale=1;this.parent_elt=m.select(this.$el[0])},get_fill_color:function(){var o=this.track.get("config").get_value("block_color");if(!o){o=this.track.get("config").get_value("color")}return o},render:function(){var s=this.parent_elt;if(!s){console.log("no parent elt")}var r=this.chroms_layout,u=m.svg.arc().innerRadius(this.radius_bounds[0]).outerRadius(this.radius_bounds[1]),o=s.selectAll("g").data(r).enter().append("svg:g"),q=o.append("path").attr("d",u).attr("class","chrom-background").style("stroke",this.bg_stroke).style("fill",this.loading_bg_fill);q.append("title").text(function(w){return w.data.chrom});var p=this,t=p.track.get("data_manager"),v=(t?t.data_is_ready():true);$.when(v).then(function(){$.when(p._render_data(s)).then(function(){q.style("fill",p.bg_fill);p.render_labels()})})},render_labels:function(){},update_radius_bounds:function(p){this.radius_bounds=p;var o=m.svg.arc().innerRadius(this.radius_bounds[0]).outerRadius(this.radius_bounds[1]);this.parent_elt.selectAll("g>path.chrom-background").transition().duration(1000).attr("d",o);this._transition_chrom_data();this._transition_labels()},update_scale:function(r){var q=this.scale;this.scale=r;if(r<=q){return}var p=this,o=new n();this.parent_elt.selectAll("path.chrom-data").filter(function(t,s){return o.is_visible(this)}).each(function(y,u){var x=m.select(this),t=x.attr("chrom"),w=p.genome.get_chrom_region(t),v=p.track.get("data_manager"),s;if(!v.can_get_more_detailed_data(w)){return}s=p.track.get("data_manager").get_more_detailed_data(w,"Coverage",0,r);$.when(s).then(function(B){x.remove();p._update_data_bounds();var A=h.find(p.chroms_layout,function(C){return C.data.chrom===t});var z=p.get_fill_color();p._render_chrom_data(p.parent_elt,A,B).style("stroke",z).style("fill",z)})});return p},_transition_chrom_data:function(){var p=this.track,r=this.chroms_layout,o=this.parent_elt.selectAll("g>path.chrom-data"),s=o[0].length;if(s>0){var q=this;$.when(p.get("data_manager").get_genome_wide_data(this.genome)).then(function(u){var t=h.reject(h.map(u,function(v,w){var x=null,y=q._get_path_function(r[w],v);if(y){x=y(v.data)}return x}),function(v){return v===null});o.each(function(w,v){m.select(this).transition().duration(1000).attr("d",t[v])})})}},_transition_labels:function(){},_update_data_bounds:function(){var o=this.data_bounds;this.data_bounds=this.get_data_bounds(this.track.get("data_manager").get_genome_wide_data(this.genome));if(this.data_bounds[0]<o[0]||this.data_bounds[1]>o[1]){this._transition_chrom_data()}},_render_data:function(r){var q=this,p=this.chroms_layout,o=this.track,s=$.Deferred();$.when(o.get("data_manager").get_genome_wide_data(this.genome)).then(function(u){q.data_bounds=q.get_data_bounds(u);layout_and_data=h.zip(p,u),chroms_data_layout=h.map(layout_and_data,function(v){var w=v[0],x=v[1];return q._render_chrom_data(r,w,x)});var t=q.get_fill_color();q.parent_elt.selectAll("path.chrom-data").style("stroke",t).style("fill",t);s.resolve(r)});return s},_render_chrom_data:function(o,p,q){},_get_path_function:function(p,o){},_chroms_layout:function(){var p=this.genome.get_chroms_info(),r=m.layout.pie().value(function(t){return t.len}).sort(null),s=r(p),o=this.total_gap/p.length,q=h.map(s,function(v,u){var t=v.endAngle-o;v.endAngle=(t>v.startAngle?t:v.startAngle);return v});return q}});var b=l.extend({initialize:function(o){l.prototype.initialize.call(this,o);this.innerRadius=this.radius_bounds[0];this.radius_bounds[0]=this.radius_bounds[1];this.bg_stroke="fff";this.bg_fill="fff";this.min_arc_len=0.05},_render_data:function(q){var p=this,o=q.selectAll("g");o.selectAll("path").attr("id",function(u){return"label-"+u.data.chrom});o.append("svg:text").filter(function(u){return u.endAngle-u.startAngle>p.min_arc_len}).attr("text-anchor","middle").append("svg:textPath").attr("class","chrom-label").attr("xlink:href",function(u){return"#label-"+u.data.chrom}).attr("startOffset","25%").text(function(u){return u.data.chrom});var r=function(w){var u=(w.endAngle-w.startAngle)/w.value,v=m.range(0,w.value,25000000).map(function(x,y){return{radius:p.innerRadius,angle:x*u+w.startAngle,label:y===0?0:(y%3?null:p.formatNum(x))}});if(v.length<4){v[v.length-1].label=p.formatNum(Math.round((v[v.length-1].angle-w.startAngle)/u))}return v};var t=function(u){return u.angle>Math.PI?"rotate(180)translate(-16)":null};var s=h.filter(this.chroms_layout,function(u){return u.endAngle-u.startAngle>p.min_arc_len});this.drawTicks(this.parent_elt,s,r,t)}});h.extend(b.prototype,i);var f=l.extend({_quantile:function(p,o){p.sort(m.ascending);return m.quantile(p,o)},_render_chrom_data:function(o,r,p){var s=this._get_path_function(r,p);if(!s){return null}var q=o.datum(p.data),t=q.append("path").attr("class","chrom-data").attr("chrom",r.data.chrom).attr("d",s);return t},_get_path_function:function(r,q){if(typeof q==="string"||!q.data||q.data.length===0){return null}var o=m.scale.linear().domain(this.data_bounds).range(this.radius_bounds).clamp(true);var s=m.scale.linear().domain([0,q.data.length]).range([r.startAngle,r.endAngle]);var p=m.svg.line.radial().interpolate("linear").radius(function(t){return o(t[1])}).angle(function(u,t){return s(t)});return m.svg.area.radial().interpolate(p.interpolate()).innerRadius(o(0)).outerRadius(p.radius()).angle(p.angle())},render_labels:function(){var o=this,p=function(){return"rotate(90)"};this.drawTicks(this.parent_elt,[this.chroms_layout[0]],this._data_bounds_ticks_fn(),p,true)},_transition_labels:function(){if(this.data_bounds.length===0){return}var p=this,r=h.filter(this.chroms_layout,function(s){return s.endAngle-s.startAngle>0.08}),q=h.filter(r,function(t,s){return s%3===0}),o=h.flatten(h.map(q,function(s){return p._data_bounds_ticks_fn()(s)}));this.parent_elt.selectAll("g.tick").data(o).transition().attr("transform",function(s){return"rotate("+(s.angle*180/Math.PI-90)+")translate("+s.radius+",0)"})},_data_bounds_ticks_fn:function(){var o=this;visibleChroms=0;return function(p){return[{radius:o.radius_bounds[0],angle:p.startAngle,label:o.formatNum(o.data_bounds[0])},{radius:o.radius_bounds[1],angle:p.startAngle,label:o.formatNum(o.data_bounds[1])}]}},get_data_bounds:function(o){}});h.extend(f.prototype,i);var d=f.extend({get_data_bounds:function(p){var o=h.flatten(h.map(p,function(q){if(q){return h.map(q.data,function(r){return parseInt(r[1],10)||0})}else{return 0}}));return[h.min(o),this._quantile(o,0.98)||h.max(o)]}});var k=l.extend({render:function(){var o=this;$.when(o.track.get("data_manager").data_is_ready()).then(function(){$.when(o.track.get("data_manager").get_genome_wide_data(o.genome)).then(function(r){var q=[],p=o.genome.get_chroms_info();h.each(r,function(v,u){var s=p[u].chrom;var t=h.map(v.data,function(x){var w=o._get_region_angle(s,x[1]),y=o._get_region_angle(x[3],x[4]);return{source:{startAngle:w,endAngle:w+0.01},target:{startAngle:y,endAngle:y+0.01}}});q=q.concat(t)});o.parent_elt.append("g").attr("class","chord").selectAll("path").data(q).enter().append("path").style("fill",o.get_fill_color()).attr("d",m.svg.chord().radius(o.radius_bounds[0])).style("opacity",1)})})},update_radius_bounds:function(o){this.radius_bounds=o;this.parent_elt.selectAll("path").transition().attr("d",m.svg.chord().radius(this.radius_bounds[0]))},_get_region_angle:function(q,o){var p=h.find(this.chroms_layout,function(r){return r.data.chrom===q});return p.endAngle-((p.endAngle-p.startAngle)*(p.data.len-o)/p.data.len)}});var e=Backbone.View.extend({initialize:function(){var o=new j.Genome(galaxy_config.app.genome),p=new j.GenomeVisualization(galaxy_config.app.viz_config),r=new a({el:$("#center .unified-panel-body"),total_gap:2*Math.PI*0.4,genome:o,model:p,dataset_arc_height:25});r.render();$("#center .unified-panel-header-inner").append(galaxy_config.app.viz_config.title+" "+galaxy_config.app.viz_config.dbkey);var q=create_icon_buttons_menu([{icon_class:"plus-button",title:"Add tracks",on_click:function(){j.select_datasets(galaxy_config.root+"visualization/list_current_history_datasets",galaxy_config.root+"api/datasets",p.get("dbkey"),function(s){p.add_tracks(s)})}},{icon_class:"disk--arrow",title:"Save",on_click:function(){Galaxy.modal.show({title:"Saving...",body:"progress"});$.ajax({url:galaxy_config.root+"visualization/save",type:"POST",dataType:"json",data:{id:p.get("vis_id"),title:p.get("title"),dbkey:p.get("dbkey"),type:"trackster",vis_json:JSON.stringify(p)}}).success(function(s){Galaxy.modal.hide();p.set("vis_id",s.vis_id)}).error(function(){Galaxy.modal.show({title:"Could Not Save",body:"Could not save visualization. Please try again later.",buttons:{Cancel:function(){Galaxy.modal.hide()}}})})}},{icon_class:"cross-circle",title:"Close",on_click:function(){window.location=galaxy_config.root+"visualization/list"}}],{tooltip_config:{placement:"bottom"}});q.$el.attr("style","float: right");$("#center .unified-panel-header-inner").append(q.$el);$(".menu-button").tooltip({placement:"bottom"})}});return{GalaxyApp:e}}); \ No newline at end of file diff -r ce8a3e4414e6ea4e761d3b40b66541e8c53471fa -r 9b86d73f9aea574862eed1f6a0c02c9171ed2c3e static/scripts/packed/viz/visualization.js --- a/static/scripts/packed/viz/visualization.js +++ b/static/scripts/packed/viz/visualization.js @@ -1,1 +1,1 @@ -define(["libs/underscore","mvc/data","viz/trackster/util","utils/config"],function(t,j,m,p){var a=function(v,y,x,w){$.ajax({url:v,data:x,error:function(){alert("Grid failed")},success:function(z){Galaxy.modal.show({title:"Select datasets for new tracks",body:z,buttons:{Cancel:function(){Galaxy.modal.hide()},Add:function(){var A=[];$("input[name=id]:checked,input[name=ldda_ids]:checked").each(function(){var B={data_type:"track_config",hda_ldda:"hda"},C=$(this).val();if($(this).attr("name")!=="id"){B.hda_ldda="ldda"}A[A.length]=$.ajax({url:y+"/"+C,data:B,dataType:"json"})});$.when.apply($,A).then(function(){var B=(arguments[0] instanceof Array?$.map(arguments,function(C){return C[0]}):[arguments[0]]);w(B)});Galaxy.modal.hide()}}})}})};var k=function(v){return("promise" in v)};var f=function(v){this.default_font=v!==undefined?v:"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")};t.extend(f.prototype,{load_pattern:function(v,z){var w=this.patterns,x=this.dummy_context,y=new Image();y.src=galaxy_config.root+"static/images"+z;y.onload=function(){w[v]=x.createPattern(y,"repeat")}},get_pattern:function(v){return this.patterns[v]},new_canvas:function(){var v=$("<canvas/>")[0];if(window.G_vmlCanvasManager){G_vmlCanvasManager.initElement(v)}v.manager=this;return v}});var r=Backbone.Model.extend({defaults:{num_elements:20,obj_cache:null,key_ary:null},initialize:function(v){this.clear()},get_elt:function(x){var y=this.attributes.obj_cache,z=this.attributes.key_ary,w=x.toString(),v=t.indexOf(z,function(A){return A.toString()===w});if(v!==-1){if(y[w].stale){z.splice(v,1);delete y[w]}else{this.move_key_to_end(x,v)}}return y[w]},set_elt:function(x,z){var A=this.attributes.obj_cache,B=this.attributes.key_ary,w=x.toString(),y=this.attributes.num_elements;if(!A[w]){if(B.length>=y){var v=B.shift();delete A[v.toString()]}B.push(x)}A[w]=z;return z},move_key_to_end:function(w,v){this.attributes.key_ary.splice(v,1);this.attributes.key_ary.push(w)},clear:function(){this.attributes.obj_cache={};this.attributes.key_ary=[]},size:function(){return this.attributes.key_ary.length},most_recently_added:function(){return this.size()===0?null:this.attributes.key_ary[this.attributes.key_ary.length-1]}});var d=r.extend({defaults:t.extend({},r.prototype.defaults,{dataset:null,genome:null,init_data:null,min_region_size:200,filters_manager:null,data_type:"data",data_mode_compatible:function(v,w){return true},can_subset:function(v){return false}}),initialize:function(v){r.prototype.initialize.call(this);var w=this.get("init_data");if(w){this.add_data(w)}},add_data:function(v){if(this.get("num_elements")<v.length){this.set("num_elements",v.length)}var w=this;t.each(v,function(x){w.set_data(x.region,x)})},data_is_ready:function(){var y=this.get("dataset"),x=$.Deferred(),v=(this.get("data_type")==="raw_data"?"state":this.get("data_type")==="data"?"converted_datasets_state":"error"),w=new m.ServerStateDeferred({ajax_settings:{url:this.get("dataset").url(),data:{hda_ldda:y.get("hda_ldda"),data_type:v},dataType:"json"},interval:5000,success_fn:function(z){return z!=="pending"}});$.when(w.go()).then(function(z){x.resolve(z==="ok"||z==="data")});return x},search_features:function(v){var w=this.get("dataset"),x={query:v,hda_ldda:w.get("hda_ldda"),data_type:"features"};return $.getJSON(w.url(),x)},load_data:function(D,C,w,B){var z=this.get("dataset"),y={data_type:this.get("data_type"),chrom:D.get("chrom"),low:D.get("start"),high:D.get("end"),mode:C,resolution:w,hda_ldda:z.get("hda_ldda")};$.extend(y,B);var F=this.get("filters_manager");if(F){var G=[];var v=F.filters;for(var A=0;A<v.length;A++){G.push(v[A].name)}y.filter_cols=JSON.stringify(G)}var x=this,E=$.getJSON(z.url(),y,function(H){H.region=D;x.set_data(D,H)});this.set_data(D,E);return E},get_data:function(C,B,x,z){var D=this.get_elt(C);if(D&&(k(D)||this.get("data_mode_compatible")(D,B))){return D}var E=this.get("key_ary"),v=this.get("obj_cache"),w,A;for(var y=0;y<E.length;y++){w=E[y];if(w.contains(C)){A=true;D=v[w.toString()];if(k(D)||(this.get("data_mode_compatible")(D,B)&&this.get("can_subset")(D))){this.move_key_to_end(w,y);if(!k(D)){var G=this.subset_entry(D,C);this.set(C,G);D=G}return D}}}if(!A&&C.length()<this.attributes.min_region_size){C=C.copy();var F=this.most_recently_added();if(!F||(C.get("start")>F.get("start"))){C.set("end",C.get("start")+this.attributes.min_region_size)}else{C.set("start",C.get("end")-this.attributes.min_region_size)}C.set("genome",this.attributes.genome);C.trim()}return this.load_data(C,B,x,z)},set_data:function(w,v){this.set_elt(w,v)},DEEP_DATA_REQ:"deep",BROAD_DATA_REQ:"breadth",get_more_data:function(D,C,y,B,z){var F=this._mark_stale(D);if(!(F&&this.get("data_mode_compatible")(F,C))){console.log("ERROR: problem with getting more data: current data is not compatible");return}var x=D.get("start");if(z===this.DEEP_DATA_REQ){$.extend(B,{start_val:F.data.length+1})}else{if(z===this.BROAD_DATA_REQ){x=(F.max_high?F.max_high:F.data[F.data.length-1][2])+1}}var E=D.copy().set("start",x);var w=this,A=this.load_data(E,C,y,B),v=$.Deferred();this.set_data(D,v);$.when(A).then(function(G){if(G.data){G.data=F.data.concat(G.data);if(G.max_low){G.max_low=F.max_low}if(G.message){G.message=G.message.replace(/[0-9]+/,G.data.length)}}w.set_data(D,G);v.resolve(G)});return v},can_get_more_detailed_data:function(w){var v=this.get_elt(w);return(v.dataset_type==="bigwig"&&v.data.length<8000)},get_more_detailed_data:function(y,A,w,z,x){var v=this._mark_stale(y);if(!v){console.log("ERROR getting more detailed data: no current data");return}if(!x){x={}}if(v.dataset_type==="bigwig"){x.num_samples=1000*z}return this.load_data(y,A,w,x)},_mark_stale:function(w){var v=this.get_elt(w);if(!v){console.log("ERROR: no data to mark as stale: ",this.get("dataset"),w.toString())}v.stale=true;return v},get_genome_wide_data:function(v){var x=this,z=true,y=t.map(v.get("chroms_info").chrom_info,function(B){var A=x.get_elt(new g({chrom:B.chrom,start:0,end:B.len}));if(!A){z=false}return A});if(z){return y}var w=$.Deferred();$.getJSON(this.get("dataset").url(),{data_type:"genome_data"},function(A){x.add_data(A.data);w.resolve(A.data)});return w},subset_entry:function(x,y){var v={bigwig:function(z,A){return t.filter(z,function(B){return B[0]>=A.get("start")&&B[0]<=A.get("end")})},refseq:function(A,B){var C=B.get("start")-x.region.get("start"),z=x.data.length-(x.region.get("end")-B.get("end"));return x.data.slice(C,z)}};var w=x.data;if(!x.region.same(y)&&x.dataset_type in v){w=v[x.dataset_type](x.data,y)}return{region:y,data:w,dataset_type:x.dataset_type}}});var q=d.extend({initialize:function(v){var w=new Backbone.Model();w.urlRoot=v.data_url;this.set("dataset",w)},load_data:function(x,y,v,w){return(x.length()<=100000?d.prototype.load_data.call(this,x,y,v,w):{data:null,region:x})}});var c=Backbone.Model.extend({defaults:{name:null,key:null,chroms_info:null},initialize:function(v){this.id=v.dbkey},get_chroms_info:function(){return this.attributes.chroms_info.chrom_info},get_chrom_region:function(v){var w=t.find(this.get_chroms_info(),function(x){return x.chrom===v});return new g({chrom:w.chrom,end:w.len})},get_chrom_len:function(v){return t.find(this.get_chroms_info(),function(w){return w.chrom===v}).len}});var g=Backbone.Model.extend({defaults:{chrom:null,start:0,end:0,str_val:null,genome:null},same:function(v){return this.attributes.chrom===v.get("chrom")&&this.attributes.start===v.get("start")&&this.attributes.end===v.get("end")},initialize:function(w){if(w.from_str){var y=w.from_str.split(":"),x=y[0],v=y[1].split("-");this.set({chrom:x,start:parseInt(v[0],10),end:parseInt(v[1],10)})}this.attributes.str_val=this.get("chrom")+":"+this.get("start")+"-"+this.get("end");this.on("change",function(){this.attributes.str_val=this.get("chrom")+":"+this.get("start")+"-"+this.get("end")},this)},copy:function(){return new g({chrom:this.get("chrom"),start:this.get("start"),end:this.get("end")})},length:function(){return this.get("end")-this.get("start")},toString:function(){return this.attributes.str_val},toJSON:function(){return{chrom:this.get("chrom"),start:this.get("start"),end:this.get("end")}},compute_overlap:function(C){var w=this.get("chrom"),B=C.get("chrom"),A=this.get("start"),y=C.get("start"),z=this.get("end"),x=C.get("end"),v;if(w&&B&&w!==B){return g.overlap_results.DIF_CHROMS}if(A<y){if(z<y){v=g.overlap_results.BEFORE}else{if(z<x){v=g.overlap_results.OVERLAP_START}else{v=g.overlap_results.CONTAINS}}}else{if(A>y){if(A>x){v=g.overlap_results.AFTER}else{if(z<=x){v=g.overlap_results.CONTAINED_BY}else{v=g.overlap_results.OVERLAP_END}}}else{v=(z>=x?g.overlap_results.CONTAINS:g.overlap_results.CONTAINED_BY)}}return v},trim:function(v){if(this.attributes.start<0){this.attributes.start=0}if(this.attributes.genome){var w=this.attributes.genome.get_chrom_len(this.attributes.chrom);if(this.attributes.end>w){this.attributes.end=w-1}}return this},contains:function(v){return this.compute_overlap(v)===g.overlap_results.CONTAINS},overlaps:function(v){return t.intersection([this.compute_overlap(v)],[g.overlap_results.DIF_CHROMS,g.overlap_results.BEFORE,g.overlap_results.AFTER]).length===0}},{overlap_results:{DIF_CHROMS:1000,BEFORE:1001,CONTAINS:1002,OVERLAP_START:1003,OVERLAP_END:1004,CONTAINED_BY:1005,AFTER:1006}});var n=Backbone.Collection.extend({model:g});var e=Backbone.Model.extend({defaults:{region:null,note:""},initialize:function(v){this.set("region",new g(v.region))}});var s=Backbone.Collection.extend({model:e});var u=Backbone.Model.extend({initialize:function(v){this.set("dataset",new j.Dataset(v.dataset));this.set("config",p.ConfigSettingCollection.from_config_dict(v.prefs));this.get("config").add([{key:"name",value:this.get("name")},{key:"color"}]);var w=this.get("preloaded_data");if(w){w=w.data}else{w=[]}this.set("data_manager",new d({dataset:this.get("dataset"),init_data:w}))}});var i=Backbone.Collection.extend({model:u});var o=Backbone.Model.extend({defaults:{title:"",type:""},url:galaxy_config.root+"visualization/save",save:function(){return $.ajax({url:this.url(),type:"POST",dataType:"json",data:{vis_json:JSON.stringify(this)}})}});var l=o.extend({defaults:t.extend({},o.prototype.defaults,{dbkey:"",tracks:null,bookmarks:null,viewport:null}),initialize:function(v){this.set("tracks",new i(v.tracks))},add_tracks:function(v){this.get("tracks").add(v)}});var b=Backbone.Model.extend({});var h=Backbone.Router.extend({initialize:function(w){this.view=w.view;this.route(/([\w]+)$/,"change_location");this.route(/([\w]+\:[\d,]+-[\d,]+)$/,"change_location");var v=this;v.view.on("navigate",function(x){v.navigate(x)})},change_location:function(v){this.view.go_to(v)}});return{BackboneTrack:u,BrowserBookmark:e,BrowserBookmarkCollection:s,Cache:r,CanvasManager:f,Genome:c,GenomeDataManager:d,GenomeRegion:g,GenomeRegionCollection:n,GenomeVisualization:l,GenomeReferenceDataManager:q,TrackBrowserRouter:h,TrackConfig:b,Visualization:o,select_datasets:a}}); \ No newline at end of file +define(["libs/underscore","mvc/data","viz/trackster/util","utils/config"],function(u,k,n,q){var f={toJSON:function(){var w=this,x={};u.each(w.constructor.to_json_keys,function(y){var z=w.get(y);if(y in w.constructor.to_json_mappers){z=w.constructor.to_json_mappers[y](z,w)}x[y]=z});return x}};var a=function(w,z,y,x){$.ajax({url:w,data:y,error:function(){alert("Grid failed")},success:function(A){Galaxy.modal.show({title:"Select datasets for new tracks",body:A,buttons:{Cancel:function(){Galaxy.modal.hide()},Add:function(){var B=[];$("input[name=id]:checked,input[name=ldda_ids]:checked").each(function(){var C={data_type:"track_config",hda_ldda:"hda"},D=$(this).val();if($(this).attr("name")!=="id"){C.hda_ldda="ldda"}B[B.length]=$.ajax({url:z+"/"+D,data:C,dataType:"json"})});$.when.apply($,B).then(function(){var C=(arguments[0] instanceof Array?$.map(arguments,function(D){return D[0]}):[arguments[0]]);x(C)});Galaxy.modal.hide()}}})}})};var l=function(w){return("promise" in w)};var g=function(w){this.default_font=w!==undefined?w:"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")};u.extend(g.prototype,{load_pattern:function(w,A){var x=this.patterns,y=this.dummy_context,z=new Image();z.src=galaxy_config.root+"static/images"+A;z.onload=function(){x[w]=y.createPattern(z,"repeat")}},get_pattern:function(w){return this.patterns[w]},new_canvas:function(){var w=$("<canvas/>")[0];if(window.G_vmlCanvasManager){G_vmlCanvasManager.initElement(w)}w.manager=this;return w}});var s=Backbone.Model.extend({defaults:{num_elements:20,obj_cache:null,key_ary:null},initialize:function(w){this.clear()},get_elt:function(y){var z=this.attributes.obj_cache,A=this.attributes.key_ary,x=y.toString(),w=u.indexOf(A,function(B){return B.toString()===x});if(w!==-1){if(z[x].stale){A.splice(w,1);delete z[x]}else{this.move_key_to_end(y,w)}}return z[x]},set_elt:function(y,A){var B=this.attributes.obj_cache,C=this.attributes.key_ary,x=y.toString(),z=this.attributes.num_elements;if(!B[x]){if(C.length>=z){var w=C.shift();delete B[w.toString()]}C.push(y)}B[x]=A;return A},move_key_to_end:function(x,w){this.attributes.key_ary.splice(w,1);this.attributes.key_ary.push(x)},clear:function(){this.attributes.obj_cache={};this.attributes.key_ary=[]},size:function(){return this.attributes.key_ary.length},most_recently_added:function(){return this.size()===0?null:this.attributes.key_ary[this.attributes.key_ary.length-1]}});var d=s.extend({defaults:u.extend({},s.prototype.defaults,{dataset:null,genome:null,init_data:null,min_region_size:200,filters_manager:null,data_type:"data",data_mode_compatible:function(w,x){return true},can_subset:function(w){return false}}),initialize:function(w){s.prototype.initialize.call(this);var x=this.get("init_data");if(x){this.add_data(x)}},add_data:function(w){if(this.get("num_elements")<w.length){this.set("num_elements",w.length)}var x=this;u.each(w,function(y){x.set_data(y.region,y)})},data_is_ready:function(){var z=this.get("dataset"),y=$.Deferred(),w=(this.get("data_type")==="raw_data"?"state":this.get("data_type")==="data"?"converted_datasets_state":"error"),x=new n.ServerStateDeferred({ajax_settings:{url:this.get("dataset").url(),data:{hda_ldda:z.get("hda_ldda"),data_type:w},dataType:"json"},interval:5000,success_fn:function(A){return A!=="pending"}});$.when(x.go()).then(function(A){y.resolve(A==="ok"||A==="data")});return y},search_features:function(w){var x=this.get("dataset"),y={query:w,hda_ldda:x.get("hda_ldda"),data_type:"features"};return $.getJSON(x.url(),y)},load_data:function(E,D,x,C){var A=this.get("dataset"),z={data_type:this.get("data_type"),chrom:E.get("chrom"),low:E.get("start"),high:E.get("end"),mode:D,resolution:x,hda_ldda:A.get("hda_ldda")};$.extend(z,C);var G=this.get("filters_manager");if(G){var H=[];var w=G.filters;for(var B=0;B<w.length;B++){H.push(w[B].name)}z.filter_cols=JSON.stringify(H)}var y=this,F=$.getJSON(A.url(),z,function(I){I.region=E;y.set_data(E,I)});this.set_data(E,F);return F},get_data:function(D,C,y,A){var E=this.get_elt(D);if(E&&(l(E)||this.get("data_mode_compatible")(E,C))){return E}var F=this.get("key_ary"),w=this.get("obj_cache"),x,B;for(var z=0;z<F.length;z++){x=F[z];if(x.contains(D)){B=true;E=w[x.toString()];if(l(E)||(this.get("data_mode_compatible")(E,C)&&this.get("can_subset")(E))){this.move_key_to_end(x,z);if(!l(E)){var H=this.subset_entry(E,D);this.set(D,H);E=H}return E}}}if(!B&&D.length()<this.attributes.min_region_size){D=D.copy();var G=this.most_recently_added();if(!G||(D.get("start")>G.get("start"))){D.set("end",D.get("start")+this.attributes.min_region_size)}else{D.set("start",D.get("end")-this.attributes.min_region_size)}D.set("genome",this.attributes.genome);D.trim()}return this.load_data(D,C,y,A)},set_data:function(x,w){this.set_elt(x,w)},DEEP_DATA_REQ:"deep",BROAD_DATA_REQ:"breadth",get_more_data:function(E,D,z,C,A){var G=this._mark_stale(E);if(!(G&&this.get("data_mode_compatible")(G,D))){console.log("ERROR: problem with getting more data: current data is not compatible");return}var y=E.get("start");if(A===this.DEEP_DATA_REQ){$.extend(C,{start_val:G.data.length+1})}else{if(A===this.BROAD_DATA_REQ){y=(G.max_high?G.max_high:G.data[G.data.length-1][2])+1}}var F=E.copy().set("start",y);var x=this,B=this.load_data(F,D,z,C),w=$.Deferred();this.set_data(E,w);$.when(B).then(function(H){if(H.data){H.data=G.data.concat(H.data);if(H.max_low){H.max_low=G.max_low}if(H.message){H.message=H.message.replace(/[0-9]+/,H.data.length)}}x.set_data(E,H);w.resolve(H)});return w},can_get_more_detailed_data:function(x){var w=this.get_elt(x);return(w.dataset_type==="bigwig"&&w.data.length<8000)},get_more_detailed_data:function(z,B,x,A,y){var w=this._mark_stale(z);if(!w){console.log("ERROR getting more detailed data: no current data");return}if(!y){y={}}if(w.dataset_type==="bigwig"){y.num_samples=1000*A}return this.load_data(z,B,x,y)},_mark_stale:function(x){var w=this.get_elt(x);if(!w){console.log("ERROR: no data to mark as stale: ",this.get("dataset"),x.toString())}w.stale=true;return w},get_genome_wide_data:function(w){var y=this,A=true,z=u.map(w.get("chroms_info").chrom_info,function(C){var B=y.get_elt(new h({chrom:C.chrom,start:0,end:C.len}));if(!B){A=false}return B});if(A){return z}var x=$.Deferred();$.getJSON(this.get("dataset").url(),{data_type:"genome_data"},function(B){y.add_data(B.data);x.resolve(B.data)});return x},subset_entry:function(y,z){var w={bigwig:function(A,B){return u.filter(A,function(C){return C[0]>=B.get("start")&&C[0]<=B.get("end")})},refseq:function(B,C){var D=C.get("start")-y.region.get("start"),A=y.data.length-(y.region.get("end")-C.get("end"));return y.data.slice(D,A)}};var x=y.data;if(!y.region.same(z)&&y.dataset_type in w){x=w[y.dataset_type](y.data,z)}return{region:z,data:x,dataset_type:y.dataset_type}}});var r=d.extend({initialize:function(w){var x=new Backbone.Model();x.urlRoot=w.data_url;this.set("dataset",x)},load_data:function(y,z,w,x){return(y.length()<=100000?d.prototype.load_data.call(this,y,z,w,x):{data:null,region:y})}});var c=Backbone.Model.extend({defaults:{name:null,key:null,chroms_info:null},initialize:function(w){this.id=w.dbkey},get_chroms_info:function(){return this.attributes.chroms_info.chrom_info},get_chrom_region:function(w){var x=u.find(this.get_chroms_info(),function(y){return y.chrom===w});return new h({chrom:x.chrom,end:x.len})},get_chrom_len:function(w){return u.find(this.get_chroms_info(),function(x){return x.chrom===w}).len}});var h=Backbone.Model.extend({defaults:{chrom:null,start:0,end:0,str_val:null,genome:null},same:function(w){return this.attributes.chrom===w.get("chrom")&&this.attributes.start===w.get("start")&&this.attributes.end===w.get("end")},initialize:function(x){if(x.from_str){var z=x.from_str.split(":"),y=z[0],w=z[1].split("-");this.set({chrom:y,start:parseInt(w[0],10),end:parseInt(w[1],10)})}this.attributes.str_val=this.get("chrom")+":"+this.get("start")+"-"+this.get("end");this.on("change",function(){this.attributes.str_val=this.get("chrom")+":"+this.get("start")+"-"+this.get("end")},this)},copy:function(){return new h({chrom:this.get("chrom"),start:this.get("start"),end:this.get("end")})},length:function(){return this.get("end")-this.get("start")},toString:function(){return this.attributes.str_val},toJSON:function(){return{chrom:this.get("chrom"),start:this.get("start"),end:this.get("end")}},compute_overlap:function(D){var x=this.get("chrom"),C=D.get("chrom"),B=this.get("start"),z=D.get("start"),A=this.get("end"),y=D.get("end"),w;if(x&&C&&x!==C){return h.overlap_results.DIF_CHROMS}if(B<z){if(A<z){w=h.overlap_results.BEFORE}else{if(A<y){w=h.overlap_results.OVERLAP_START}else{w=h.overlap_results.CONTAINS}}}else{if(B>z){if(B>y){w=h.overlap_results.AFTER}else{if(A<=y){w=h.overlap_results.CONTAINED_BY}else{w=h.overlap_results.OVERLAP_END}}}else{w=(A>=y?h.overlap_results.CONTAINS:h.overlap_results.CONTAINED_BY)}}return w},trim:function(w){if(this.attributes.start<0){this.attributes.start=0}if(this.attributes.genome){var x=this.attributes.genome.get_chrom_len(this.attributes.chrom);if(this.attributes.end>x){this.attributes.end=x-1}}return this},contains:function(w){return this.compute_overlap(w)===h.overlap_results.CONTAINS},overlaps:function(w){return u.intersection([this.compute_overlap(w)],[h.overlap_results.DIF_CHROMS,h.overlap_results.BEFORE,h.overlap_results.AFTER]).length===0}},{overlap_results:{DIF_CHROMS:1000,BEFORE:1001,CONTAINS:1002,OVERLAP_START:1003,OVERLAP_END:1004,CONTAINED_BY:1005,AFTER:1006}});var o=Backbone.Collection.extend({model:h});var e=Backbone.Model.extend({defaults:{region:null,note:""},initialize:function(w){this.set("region",new h(w.region))}});var t=Backbone.Collection.extend({model:e});var v=Backbone.Model.extend(f).extend({defaults:{mode:"Auto"},initialize:function(w){this.set("dataset",new k.Dataset(w.dataset));this.set("config",q.ConfigSettingCollection.from_config_dict(w.prefs));this.get("config").add([{key:"name",value:this.get("dataset").get("name")},{key:"color"}]);var x=this.get("preloaded_data");if(x){x=x.data}else{x=[]}this.set("data_manager",new d({dataset:this.get("dataset"),init_data:x}))}},{to_json_keys:["track_type","dataset","prefs","mode","filters","tool_state"],to_json_mappers:{prefs:function(x,w){if(u.size(x)===0){x={name:w.get("config").get("name").get("value"),color:w.get("config").get("color").get("value")}}return x},dataset:function(w){return{id:w.id,hda_ldda:w.get("hda_ldda")}}}});var j=Backbone.Collection.extend({model:v});var p=Backbone.Model.extend({defaults:{title:"",type:""},url:galaxy_config.root+"visualization/save",save:function(){return $.ajax({url:this.url(),type:"POST",dataType:"json",data:{vis_json:JSON.stringify(this)}})}});var m=p.extend(f).extend({defaults:u.extend({},p.prototype.defaults,{dbkey:"",drawables:null,bookmarks:null,viewport:null}),initialize:function(w){this.set("drawables",new j(w.tracks));this.set("config",q.ConfigSettingCollection.from_config_dict(w.prefs||{}));this.unset("tracks");this.get("drawables").each(function(x){x.unset("preloaded_data")})},add_tracks:function(w){this.get("drawables").add(w)}},{to_json_keys:["view","viewport","bookmarks"],to_json_mappers:{view:function(x,w){return{obj_type:"View",prefs:{name:w.get("title"),content_visible:true},drawables:w.get("drawables")}}}});var b=Backbone.Model.extend({});var i=Backbone.Router.extend({initialize:function(x){this.view=x.view;this.route(/([\w]+)$/,"change_location");this.route(/([\w]+\:[\d,]+-[\d,]+)$/,"change_location");var w=this;w.view.on("navigate",function(y){w.navigate(y)})},change_location:function(w){this.view.go_to(w)}});return{BackboneTrack:v,BrowserBookmark:e,BrowserBookmarkCollection:t,Cache:s,CanvasManager:g,Genome:c,GenomeDataManager:d,GenomeRegion:h,GenomeRegionCollection:o,GenomeVisualization:m,GenomeReferenceDataManager:r,TrackBrowserRouter:i,TrackConfig:b,Visualization:p,select_datasets:a}}); \ No newline at end of file diff -r ce8a3e4414e6ea4e761d3b40b66541e8c53471fa -r 9b86d73f9aea574862eed1f6a0c02c9171ed2c3e static/scripts/viz/circster.js --- a/static/scripts/viz/circster.js +++ b/static/scripts/viz/circster.js @@ -143,8 +143,8 @@ this.chords_views = null; // When tracks added to/removed from model, update view. - this.model.get('tracks').on('add', this.add_track, this); - this.model.get('tracks').on('remove', this.remove_track, this); + this.model.get('drawables').on('add', this.add_track, this); + this.model.get('drawables').on('remove', this.remove_track, this); this.get_circular_tracks(); }, @@ -154,7 +154,7 @@ * Returns tracks to be rendered using circular view. */ get_circular_tracks: function() { - return this.model.get('tracks').filter(function(track) { + return this.model.get('drawables').filter(function(track) { return track.get('track_type') !== 'DiagonalHeatmapTrack'; }); }, @@ -163,7 +163,7 @@ * Returns tracks to be rendered using chords view. */ get_chord_tracks: function() { - return this.model.get('tracks').filter(function(track) { + return this.model.get('drawables').filter(function(track) { return track.get('track_type') === 'DiagonalHeatmapTrack'; }); }, @@ -992,41 +992,36 @@ // setup menu var menu = create_icon_buttons_menu([ - { icon_class: 'plus-button', title: 'Add tracks', on_click: function() + { + icon_class: 'plus-button', title: 'Add tracks', on_click: function() { visualization.select_datasets(galaxy_config.root + "visualization/list_current_history_datasets", galaxy_config.root + "api/datasets", vis.get('dbkey'), function(tracks) { vis.add_tracks(tracks); }); } - },{ + }, + { icon_class: 'disk--arrow', title: 'Save', on_click: function() { // show saving dialog box Galaxy.modal.show({title: "Saving...", body: "progress" }); - // link configuration - var view = galaxy_config.app.viz_config; - // send to server $.ajax({ url: galaxy_config.root + "visualization/save", type: "POST", dataType: "json", data: { - 'id' : view.vis_id, - 'title' : view.title, - 'dbkey' : view.dbkey, + 'id' : vis.get('vis_id'), + 'title' : vis.get('title'), + 'dbkey' : vis.get('dbkey'), 'type' : 'trackster', - 'vis_json' : JSON.stringify(view) + 'vis_json' : JSON.stringify(vis) } }).success(function(vis_info) { Galaxy.modal.hide(); - view.vis_id = vis_info.vis_id; - view.has_changes = false; - - // needed to set URL when first saving a visualization - window.history.pushState({}, "", vis_info.url + window.location.hash); + vis.set('vis_id', vis_info.vis_id); }).error(function() { // show dialog Galaxy.modal.show({ @@ -1036,7 +1031,8 @@ }); }); } - },{ + }, + { icon_class: 'cross-circle', title: 'Close', on_click: function() { window.location = galaxy_config.root + "visualization/list"; diff -r ce8a3e4414e6ea4e761d3b40b66541e8c53471fa -r 9b86d73f9aea574862eed1f6a0c02c9171ed2c3e static/scripts/viz/visualization.js --- a/static/scripts/viz/visualization.js +++ b/static/scripts/viz/visualization.js @@ -1,6 +1,28 @@ define( ["libs/underscore", "mvc/data", "viz/trackster/util", "utils/config"], function(_, data_mod, util_mod, config_mod) { /** + * Mixin for returning custom JSON representation from toJSON. Class attribute to_json_keys defines a set of attributes + * to include in the representation; to_json_mappers defines mappers for returned objects. + */ +var CustomToJSON = { + /** + * Returns JSON representation of object using to_json_keys and to_json_mappers. + */ + toJSON: function() { + var self = this, + json = {}; + _.each(self.constructor.to_json_keys, function(k) { + var val = self.get(k); + if (k in self.constructor.to_json_mappers) { + val = self.constructor.to_json_mappers[k](val, self); + } + json[k] = val; + }); + return json; + } +}; + +/** * Model, view, and controller objects for Galaxy visualization framework. * * Models have no references to views, instead using events to indicate state @@ -872,7 +894,10 @@ * A track of data in a genome visualization. */ // TODO: rename to Track and merge with Trackster's Track object. -var BackboneTrack = Backbone.Model.extend({ +var BackboneTrack = Backbone.Model.extend(CustomToJSON).extend({ + defaults: { + mode: 'Auto' + }, initialize: function(options) { this.set('dataset', new data_mod.Dataset(options.dataset)); @@ -883,7 +908,7 @@ // Set up some minimal config. this.get('config').add( [ - { key: 'name', value: this.get('name') }, + { key: 'name', value: this.get('dataset').get('name') }, { key: 'color' } ] ); @@ -900,6 +925,34 @@ init_data: preloaded_data })); } +}, +{ + // This definition matches that produced by to_dict() methods in tracks.js + to_json_keys: [ + 'track_type', + 'dataset', + 'prefs', + 'mode', + 'filters', + 'tool_state' + ], + to_json_mappers: { + prefs: function(p, self) { + if (_.size(p) === 0) { + p = { + name: self.get('config').get('name').get('value'), + color: self.get('config').get('color').get('value') + }; + } + return p; + }, + dataset: function(d) { + return { + id: d.id, + hda_ldda: d.get('hda_ldda') + }; + } + } }); var BackboneTrackCollection = Backbone.Collection.extend({ @@ -938,25 +991,55 @@ /** * A visualization of genome data. */ -var GenomeVisualization = Visualization.extend({ +var GenomeVisualization = Visualization.extend(CustomToJSON).extend({ defaults: _.extend({}, Visualization.prototype.defaults, { dbkey: '', - tracks: null, + drawables: null, bookmarks: null, viewport: null }), initialize: function(options) { - this.set('tracks', new BackboneTrackCollection(options.tracks)); + // Replace drawables with tracks. + this.set('drawables', new BackboneTrackCollection(options.tracks)); + this.set('config', config_mod.ConfigSettingCollection.from_config_dict(options.prefs || {})); + + // Clear track and data definitions to avoid storing large objects. + this.unset('tracks'); + this.get('drawables').each(function(d) { + d.unset('preloaded_data'); + }); }, /** * Add a track or array of tracks to the visualization. */ add_tracks: function(tracks) { - this.get('tracks').add(tracks); + this.get('drawables').add(tracks); } -}); +}, +{ + // This definition matches that produced by to_dict() methods in tracks.js + to_json_keys: [ + 'view', + 'viewport', + 'bookmarks' + ], + + to_json_mappers: { + 'view': function(dummy, self) { + return { + obj_type: 'View', + prefs: { + name: self.get('title'), + content_visible: true + }, + drawables: self.get('drawables') + }; + } + } +} +); /** * Configuration data for a Trackster track. https://bitbucket.org/galaxy/galaxy-central/commits/c98072c51cf0/ Changeset: c98072c51cf0 User: jeremy goecks Date: 2014-02-05 22:22:45 Summary: Merge next-stable into default. Affected #: 4 files diff -r 0a8336ad8d4df064abcaa286814527ee8bbde34f -r c98072c51cf05de686c631739a5deb18c15734bf static/scripts/packed/viz/circster.js --- a/static/scripts/packed/viz/circster.js +++ b/static/scripts/packed/viz/circster.js @@ -1,1 +1,1 @@ -define(["utils/utils","libs/underscore","libs/d3","viz/visualization"],function(g,h,m,j){g.cssLoadFile("static/style/circster.css");var n=Backbone.Model.extend({is_visible:function(r,o){var p=r.getBoundingClientRect(),q=$("svg")[0].getBoundingClientRect();if(p.right<0||p.left>q.right||p.bottom<0||p.top>q.bottom){return false}return true}});var i={drawTicks:function(s,r,w,q,o){var v=s.append("g").selectAll("g").data(r).enter().append("g").selectAll("g").data(w).enter().append("g").attr("class","tick").attr("transform",function(x){return"rotate("+(x.angle*180/Math.PI-90)+")translate("+x.radius+",0)"});var u=[],t=[],p=function(x){return x.angle>Math.PI?"end":null};if(o){u=[0,0,0,-4];t=[4,0,"",".35em"];p=null}else{u=[1,0,4,0];t=[0,4,".35em",""]}v.append("line").attr("x1",u[0]).attr("y1",u[1]).attr("x2",u[2]).attr("y1",u[3]).style("stroke","#000");v.append("text").attr("x",t[0]).attr("y",t[1]).attr("dx",t[2]).attr("dy",t[3]).attr("text-anchor",p).attr("transform",q).text(function(x){return x.label})},formatNum:function(p,o){if(o===undefined){o=2}if(p===null){return null}var r=null;if(p<1){r=p.toPrecision(o)}else{var q=Math.round(p.toPrecision(o));if(p<1000){r=q}else{if(p<1000000){r=Math.round((q/1000).toPrecision(3)).toFixed(0)+"K"}else{if(p<1000000000){r=Math.round((q/1000000).toPrecision(3)).toFixed(0)+"M"}}}}return r}};var c=Backbone.Model.extend({});var a=Backbone.View.extend({className:"circster",initialize:function(o){this.total_gap=o.total_gap;this.genome=o.genome;this.dataset_arc_height=o.dataset_arc_height;this.track_gap=10;this.label_arc_height=50;this.scale=1;this.circular_views=null;this.chords_views=null;this.model.get("tracks").on("add",this.add_track,this);this.model.get("tracks").on("remove",this.remove_track,this);this.get_circular_tracks()},get_circular_tracks:function(){return this.model.get("tracks").filter(function(o){return o.get("track_type")!=="DiagonalHeatmapTrack"})},get_chord_tracks:function(){return this.model.get("tracks").filter(function(o){return o.get("track_type")==="DiagonalHeatmapTrack"})},get_tracks_bounds:function(){var p=this.get_circular_tracks();dataset_arc_height=this.dataset_arc_height,min_dimension=Math.min(this.$el.width(),this.$el.height()),radius_start=min_dimension/2-p.length*(this.dataset_arc_height+this.track_gap)-(this.label_arc_height+this.track_gap),tracks_start_radii=m.range(radius_start,min_dimension/2,this.dataset_arc_height+this.track_gap);var o=this;return h.map(tracks_start_radii,function(q){return[q,q+o.dataset_arc_height]})},render:function(){var x=this,r=this.dataset_arc_height,o=x.$el.width(),w=x.$el.height(),t=this.get_circular_tracks(),q=this.get_chord_tracks(),s=this.get_tracks_bounds(),p=m.select(x.$el[0]).append("svg").attr("width",o).attr("height",w).attr("pointer-events","all").append("svg:g").call(m.behavior.zoom().on("zoom",function(){var y=m.event.scale;p.attr("transform","translate("+m.event.translate+") scale("+y+")");if(x.scale!==y){if(x.zoom_drag_timeout){clearTimeout(x.zoom_drag_timeout)}x.zoom_drag_timeout=setTimeout(function(){},400)}})).attr("transform","translate("+o/2+","+w/2+")").append("svg:g").attr("class","tracks");this.circular_views=t.map(function(z,A){var y=new d({el:p.append("g")[0],track:z,radius_bounds:s[A],genome:x.genome,total_gap:x.total_gap});y.render();return y});this.chords_views=q.map(function(z){var y=new k({el:p.append("g")[0],track:z,radius_bounds:s[0],genome:x.genome,total_gap:x.total_gap});y.render();return y});var v=this.circular_views[this.circular_views.length-1].radius_bounds[1],u=[v,v+this.label_arc_height];this.label_track_view=new b({el:p.append("g")[0],track:new c(),radius_bounds:u,genome:x.genome,total_gap:x.total_gap});this.label_track_view.render()},add_track:function(u){if(u.get("track_type")==="DiagonalHeatmapTrack"){var q=this.circular_views[0].radius_bounds,t=new k({el:m.select("g.tracks").append("g")[0],track:u,radius_bounds:q,genome:this.genome,total_gap:this.total_gap});t.render();this.chords_views.push(t)}else{var s=this.get_tracks_bounds();h.each(this.circular_views,function(v,w){v.update_radius_bounds(s[w])});h.each(this.chords_views,function(v){v.update_radius_bounds(s[0])});var r=this.circular_views.length,o=new d({el:m.select("g.tracks").append("g")[0],track:u,radius_bounds:s[r],genome:this.genome,total_gap:this.total_gap});o.render();this.circular_views.push(o);var p=s[s.length-1];p[1]=p[0];this.label_track_view.update_radius_bounds(p)}},remove_track:function(p,r,q){var o=this.circular_views[q.index];this.circular_views.splice(q.index,1);o.$el.remove();var s=this.get_tracks_bounds();h.each(this.circular_views,function(t,u){t.update_radius_bounds(s[u])})}});var l=Backbone.View.extend({tagName:"g",initialize:function(o){this.bg_stroke="ccc";this.loading_bg_fill="000";this.bg_fill="ccc";this.total_gap=o.total_gap;this.track=o.track;this.radius_bounds=o.radius_bounds;this.genome=o.genome;this.chroms_layout=this._chroms_layout();this.data_bounds=[];this.scale=1;this.parent_elt=m.select(this.$el[0])},get_fill_color:function(){var o=this.track.get("config").get_value("block_color");if(!o){o=this.track.get("config").get_value("color")}return o},render:function(){var s=this.parent_elt;if(!s){console.log("no parent elt")}var r=this.chroms_layout,u=m.svg.arc().innerRadius(this.radius_bounds[0]).outerRadius(this.radius_bounds[1]),o=s.selectAll("g").data(r).enter().append("svg:g"),q=o.append("path").attr("d",u).attr("class","chrom-background").style("stroke",this.bg_stroke).style("fill",this.loading_bg_fill);q.append("title").text(function(w){return w.data.chrom});var p=this,t=p.track.get("data_manager"),v=(t?t.data_is_ready():true);$.when(v).then(function(){$.when(p._render_data(s)).then(function(){q.style("fill",p.bg_fill);p.render_labels()})})},render_labels:function(){},update_radius_bounds:function(p){this.radius_bounds=p;var o=m.svg.arc().innerRadius(this.radius_bounds[0]).outerRadius(this.radius_bounds[1]);this.parent_elt.selectAll("g>path.chrom-background").transition().duration(1000).attr("d",o);this._transition_chrom_data();this._transition_labels()},update_scale:function(r){var q=this.scale;this.scale=r;if(r<=q){return}var p=this,o=new n();this.parent_elt.selectAll("path.chrom-data").filter(function(t,s){return o.is_visible(this)}).each(function(y,u){var x=m.select(this),t=x.attr("chrom"),w=p.genome.get_chrom_region(t),v=p.track.get("data_manager"),s;if(!v.can_get_more_detailed_data(w)){return}s=p.track.get("data_manager").get_more_detailed_data(w,"Coverage",0,r);$.when(s).then(function(B){x.remove();p._update_data_bounds();var A=h.find(p.chroms_layout,function(C){return C.data.chrom===t});var z=p.get_fill_color();p._render_chrom_data(p.parent_elt,A,B).style("stroke",z).style("fill",z)})});return p},_transition_chrom_data:function(){var p=this.track,r=this.chroms_layout,o=this.parent_elt.selectAll("g>path.chrom-data"),s=o[0].length;if(s>0){var q=this;$.when(p.get("data_manager").get_genome_wide_data(this.genome)).then(function(u){var t=h.reject(h.map(u,function(v,w){var x=null,y=q._get_path_function(r[w],v);if(y){x=y(v.data)}return x}),function(v){return v===null});o.each(function(w,v){m.select(this).transition().duration(1000).attr("d",t[v])})})}},_transition_labels:function(){},_update_data_bounds:function(){var o=this.data_bounds;this.data_bounds=this.get_data_bounds(this.track.get("data_manager").get_genome_wide_data(this.genome));if(this.data_bounds[0]<o[0]||this.data_bounds[1]>o[1]){this._transition_chrom_data()}},_render_data:function(r){var q=this,p=this.chroms_layout,o=this.track,s=$.Deferred();$.when(o.get("data_manager").get_genome_wide_data(this.genome)).then(function(u){q.data_bounds=q.get_data_bounds(u);layout_and_data=h.zip(p,u),chroms_data_layout=h.map(layout_and_data,function(v){var w=v[0],x=v[1];return q._render_chrom_data(r,w,x)});var t=q.get_fill_color();q.parent_elt.selectAll("path.chrom-data").style("stroke",t).style("fill",t);s.resolve(r)});return s},_render_chrom_data:function(o,p,q){},_get_path_function:function(p,o){},_chroms_layout:function(){var p=this.genome.get_chroms_info(),r=m.layout.pie().value(function(t){return t.len}).sort(null),s=r(p),o=this.total_gap/p.length,q=h.map(s,function(v,u){var t=v.endAngle-o;v.endAngle=(t>v.startAngle?t:v.startAngle);return v});return q}});var b=l.extend({initialize:function(o){l.prototype.initialize.call(this,o);this.innerRadius=this.radius_bounds[0];this.radius_bounds[0]=this.radius_bounds[1];this.bg_stroke="fff";this.bg_fill="fff";this.min_arc_len=0.05},_render_data:function(q){var p=this,o=q.selectAll("g");o.selectAll("path").attr("id",function(u){return"label-"+u.data.chrom});o.append("svg:text").filter(function(u){return u.endAngle-u.startAngle>p.min_arc_len}).attr("text-anchor","middle").append("svg:textPath").attr("class","chrom-label").attr("xlink:href",function(u){return"#label-"+u.data.chrom}).attr("startOffset","25%").text(function(u){return u.data.chrom});var r=function(w){var u=(w.endAngle-w.startAngle)/w.value,v=m.range(0,w.value,25000000).map(function(x,y){return{radius:p.innerRadius,angle:x*u+w.startAngle,label:y===0?0:(y%3?null:p.formatNum(x))}});if(v.length<4){v[v.length-1].label=p.formatNum(Math.round((v[v.length-1].angle-w.startAngle)/u))}return v};var t=function(u){return u.angle>Math.PI?"rotate(180)translate(-16)":null};var s=h.filter(this.chroms_layout,function(u){return u.endAngle-u.startAngle>p.min_arc_len});this.drawTicks(this.parent_elt,s,r,t)}});h.extend(b.prototype,i);var f=l.extend({_quantile:function(p,o){p.sort(m.ascending);return m.quantile(p,o)},_render_chrom_data:function(o,r,p){var s=this._get_path_function(r,p);if(!s){return null}var q=o.datum(p.data),t=q.append("path").attr("class","chrom-data").attr("chrom",r.data.chrom).attr("d",s);return t},_get_path_function:function(r,q){if(typeof q==="string"||!q.data||q.data.length===0){return null}var o=m.scale.linear().domain(this.data_bounds).range(this.radius_bounds).clamp(true);var s=m.scale.linear().domain([0,q.data.length]).range([r.startAngle,r.endAngle]);var p=m.svg.line.radial().interpolate("linear").radius(function(t){return o(t[1])}).angle(function(u,t){return s(t)});return m.svg.area.radial().interpolate(p.interpolate()).innerRadius(o(0)).outerRadius(p.radius()).angle(p.angle())},render_labels:function(){var o=this,p=function(){return"rotate(90)"};this.drawTicks(this.parent_elt,[this.chroms_layout[0]],this._data_bounds_ticks_fn(),p,true)},_transition_labels:function(){if(this.data_bounds.length===0){return}var p=this,r=h.filter(this.chroms_layout,function(s){return s.endAngle-s.startAngle>0.08}),q=h.filter(r,function(t,s){return s%3===0}),o=h.flatten(h.map(q,function(s){return p._data_bounds_ticks_fn()(s)}));this.parent_elt.selectAll("g.tick").data(o).transition().attr("transform",function(s){return"rotate("+(s.angle*180/Math.PI-90)+")translate("+s.radius+",0)"})},_data_bounds_ticks_fn:function(){var o=this;visibleChroms=0;return function(p){return[{radius:o.radius_bounds[0],angle:p.startAngle,label:o.formatNum(o.data_bounds[0])},{radius:o.radius_bounds[1],angle:p.startAngle,label:o.formatNum(o.data_bounds[1])}]}},get_data_bounds:function(o){}});h.extend(f.prototype,i);var d=f.extend({get_data_bounds:function(p){var o=h.flatten(h.map(p,function(q){if(q){return h.map(q.data,function(r){return parseInt(r[1],10)||0})}else{return 0}}));return[h.min(o),this._quantile(o,0.98)||h.max(o)]}});var k=l.extend({render:function(){var o=this;$.when(o.track.get("data_manager").data_is_ready()).then(function(){$.when(o.track.get("data_manager").get_genome_wide_data(o.genome)).then(function(r){var q=[],p=o.genome.get_chroms_info();h.each(r,function(v,u){var s=p[u].chrom;var t=h.map(v.data,function(x){var w=o._get_region_angle(s,x[1]),y=o._get_region_angle(x[3],x[4]);return{source:{startAngle:w,endAngle:w+0.01},target:{startAngle:y,endAngle:y+0.01}}});q=q.concat(t)});o.parent_elt.append("g").attr("class","chord").selectAll("path").data(q).enter().append("path").style("fill",o.get_fill_color()).attr("d",m.svg.chord().radius(o.radius_bounds[0])).style("opacity",1)})})},update_radius_bounds:function(o){this.radius_bounds=o;this.parent_elt.selectAll("path").transition().attr("d",m.svg.chord().radius(this.radius_bounds[0]))},_get_region_angle:function(q,o){var p=h.find(this.chroms_layout,function(r){return r.data.chrom===q});return p.endAngle-((p.endAngle-p.startAngle)*(p.data.len-o)/p.data.len)}});var e=Backbone.View.extend({initialize:function(){var o=new j.Genome(galaxy_config.app.genome),p=new j.GenomeVisualization(galaxy_config.app.viz_config),r=new a({el:$("#center .unified-panel-body"),total_gap:2*Math.PI*0.4,genome:o,model:p,dataset_arc_height:25});r.render();$("#center .unified-panel-header-inner").append(galaxy_config.app.viz_config.title+" "+galaxy_config.app.viz_config.dbkey);var q=create_icon_buttons_menu([{icon_class:"plus-button",title:"Add tracks",on_click:function(){j.select_datasets(galaxy_config.root+"visualization/list_current_history_datasets",galaxy_config.root+"api/datasets",p.get("dbkey"),function(s){p.add_tracks(s)})}},{icon_class:"disk--arrow",title:"Save",on_click:function(){Galaxy.modal.show({title:"Saving...",body:"progress"});var s=galaxy_config.app.viz_config;$.ajax({url:galaxy_config.root+"visualization/save",type:"POST",dataType:"json",data:{id:s.vis_id,title:s.title,dbkey:s.dbkey,type:"trackster",vis_json:JSON.stringify(s)}}).success(function(t){Galaxy.modal.hide();s.vis_id=t.vis_id;s.has_changes=false;window.history.pushState({},"",t.url+window.location.hash)}).error(function(){Galaxy.modal.show({title:"Could Not Save",body:"Could not save visualization. Please try again later.",buttons:{Cancel:function(){Galaxy.modal.hide()}}})})}},{icon_class:"cross-circle",title:"Close",on_click:function(){window.location=galaxy_config.root+"visualization/list"}}],{tooltip_config:{placement:"bottom"}});q.$el.attr("style","float: right");$("#center .unified-panel-header-inner").append(q.$el);$(".menu-button").tooltip({placement:"bottom"})}});return{GalaxyApp:e}}); \ No newline at end of file +define(["utils/utils","libs/underscore","libs/d3","viz/visualization"],function(g,h,m,j){g.cssLoadFile("static/style/circster.css");var n=Backbone.Model.extend({is_visible:function(r,o){var p=r.getBoundingClientRect(),q=$("svg")[0].getBoundingClientRect();if(p.right<0||p.left>q.right||p.bottom<0||p.top>q.bottom){return false}return true}});var i={drawTicks:function(s,r,w,q,o){var v=s.append("g").selectAll("g").data(r).enter().append("g").selectAll("g").data(w).enter().append("g").attr("class","tick").attr("transform",function(x){return"rotate("+(x.angle*180/Math.PI-90)+")translate("+x.radius+",0)"});var u=[],t=[],p=function(x){return x.angle>Math.PI?"end":null};if(o){u=[0,0,0,-4];t=[4,0,"",".35em"];p=null}else{u=[1,0,4,0];t=[0,4,".35em",""]}v.append("line").attr("x1",u[0]).attr("y1",u[1]).attr("x2",u[2]).attr("y1",u[3]).style("stroke","#000");v.append("text").attr("x",t[0]).attr("y",t[1]).attr("dx",t[2]).attr("dy",t[3]).attr("text-anchor",p).attr("transform",q).text(function(x){return x.label})},formatNum:function(p,o){if(o===undefined){o=2}if(p===null){return null}var r=null;if(p<1){r=p.toPrecision(o)}else{var q=Math.round(p.toPrecision(o));if(p<1000){r=q}else{if(p<1000000){r=Math.round((q/1000).toPrecision(3)).toFixed(0)+"K"}else{if(p<1000000000){r=Math.round((q/1000000).toPrecision(3)).toFixed(0)+"M"}}}}return r}};var c=Backbone.Model.extend({});var a=Backbone.View.extend({className:"circster",initialize:function(o){this.total_gap=o.total_gap;this.genome=o.genome;this.dataset_arc_height=o.dataset_arc_height;this.track_gap=10;this.label_arc_height=50;this.scale=1;this.circular_views=null;this.chords_views=null;this.model.get("drawables").on("add",this.add_track,this);this.model.get("drawables").on("remove",this.remove_track,this);this.get_circular_tracks()},get_circular_tracks:function(){return this.model.get("drawables").filter(function(o){return o.get("track_type")!=="DiagonalHeatmapTrack"})},get_chord_tracks:function(){return this.model.get("drawables").filter(function(o){return o.get("track_type")==="DiagonalHeatmapTrack"})},get_tracks_bounds:function(){var p=this.get_circular_tracks();dataset_arc_height=this.dataset_arc_height,min_dimension=Math.min(this.$el.width(),this.$el.height()),radius_start=min_dimension/2-p.length*(this.dataset_arc_height+this.track_gap)-(this.label_arc_height+this.track_gap),tracks_start_radii=m.range(radius_start,min_dimension/2,this.dataset_arc_height+this.track_gap);var o=this;return h.map(tracks_start_radii,function(q){return[q,q+o.dataset_arc_height]})},render:function(){var x=this,r=this.dataset_arc_height,o=x.$el.width(),w=x.$el.height(),t=this.get_circular_tracks(),q=this.get_chord_tracks(),s=this.get_tracks_bounds(),p=m.select(x.$el[0]).append("svg").attr("width",o).attr("height",w).attr("pointer-events","all").append("svg:g").call(m.behavior.zoom().on("zoom",function(){var y=m.event.scale;p.attr("transform","translate("+m.event.translate+") scale("+y+")");if(x.scale!==y){if(x.zoom_drag_timeout){clearTimeout(x.zoom_drag_timeout)}x.zoom_drag_timeout=setTimeout(function(){},400)}})).attr("transform","translate("+o/2+","+w/2+")").append("svg:g").attr("class","tracks");this.circular_views=t.map(function(z,A){var y=new d({el:p.append("g")[0],track:z,radius_bounds:s[A],genome:x.genome,total_gap:x.total_gap});y.render();return y});this.chords_views=q.map(function(z){var y=new k({el:p.append("g")[0],track:z,radius_bounds:s[0],genome:x.genome,total_gap:x.total_gap});y.render();return y});var v=this.circular_views[this.circular_views.length-1].radius_bounds[1],u=[v,v+this.label_arc_height];this.label_track_view=new b({el:p.append("g")[0],track:new c(),radius_bounds:u,genome:x.genome,total_gap:x.total_gap});this.label_track_view.render()},add_track:function(u){if(u.get("track_type")==="DiagonalHeatmapTrack"){var q=this.circular_views[0].radius_bounds,t=new k({el:m.select("g.tracks").append("g")[0],track:u,radius_bounds:q,genome:this.genome,total_gap:this.total_gap});t.render();this.chords_views.push(t)}else{var s=this.get_tracks_bounds();h.each(this.circular_views,function(v,w){v.update_radius_bounds(s[w])});h.each(this.chords_views,function(v){v.update_radius_bounds(s[0])});var r=this.circular_views.length,o=new d({el:m.select("g.tracks").append("g")[0],track:u,radius_bounds:s[r],genome:this.genome,total_gap:this.total_gap});o.render();this.circular_views.push(o);var p=s[s.length-1];p[1]=p[0];this.label_track_view.update_radius_bounds(p)}},remove_track:function(p,r,q){var o=this.circular_views[q.index];this.circular_views.splice(q.index,1);o.$el.remove();var s=this.get_tracks_bounds();h.each(this.circular_views,function(t,u){t.update_radius_bounds(s[u])})}});var l=Backbone.View.extend({tagName:"g",initialize:function(o){this.bg_stroke="ccc";this.loading_bg_fill="000";this.bg_fill="ccc";this.total_gap=o.total_gap;this.track=o.track;this.radius_bounds=o.radius_bounds;this.genome=o.genome;this.chroms_layout=this._chroms_layout();this.data_bounds=[];this.scale=1;this.parent_elt=m.select(this.$el[0])},get_fill_color:function(){var o=this.track.get("config").get_value("block_color");if(!o){o=this.track.get("config").get_value("color")}return o},render:function(){var s=this.parent_elt;if(!s){console.log("no parent elt")}var r=this.chroms_layout,u=m.svg.arc().innerRadius(this.radius_bounds[0]).outerRadius(this.radius_bounds[1]),o=s.selectAll("g").data(r).enter().append("svg:g"),q=o.append("path").attr("d",u).attr("class","chrom-background").style("stroke",this.bg_stroke).style("fill",this.loading_bg_fill);q.append("title").text(function(w){return w.data.chrom});var p=this,t=p.track.get("data_manager"),v=(t?t.data_is_ready():true);$.when(v).then(function(){$.when(p._render_data(s)).then(function(){q.style("fill",p.bg_fill);p.render_labels()})})},render_labels:function(){},update_radius_bounds:function(p){this.radius_bounds=p;var o=m.svg.arc().innerRadius(this.radius_bounds[0]).outerRadius(this.radius_bounds[1]);this.parent_elt.selectAll("g>path.chrom-background").transition().duration(1000).attr("d",o);this._transition_chrom_data();this._transition_labels()},update_scale:function(r){var q=this.scale;this.scale=r;if(r<=q){return}var p=this,o=new n();this.parent_elt.selectAll("path.chrom-data").filter(function(t,s){return o.is_visible(this)}).each(function(y,u){var x=m.select(this),t=x.attr("chrom"),w=p.genome.get_chrom_region(t),v=p.track.get("data_manager"),s;if(!v.can_get_more_detailed_data(w)){return}s=p.track.get("data_manager").get_more_detailed_data(w,"Coverage",0,r);$.when(s).then(function(B){x.remove();p._update_data_bounds();var A=h.find(p.chroms_layout,function(C){return C.data.chrom===t});var z=p.get_fill_color();p._render_chrom_data(p.parent_elt,A,B).style("stroke",z).style("fill",z)})});return p},_transition_chrom_data:function(){var p=this.track,r=this.chroms_layout,o=this.parent_elt.selectAll("g>path.chrom-data"),s=o[0].length;if(s>0){var q=this;$.when(p.get("data_manager").get_genome_wide_data(this.genome)).then(function(u){var t=h.reject(h.map(u,function(v,w){var x=null,y=q._get_path_function(r[w],v);if(y){x=y(v.data)}return x}),function(v){return v===null});o.each(function(w,v){m.select(this).transition().duration(1000).attr("d",t[v])})})}},_transition_labels:function(){},_update_data_bounds:function(){var o=this.data_bounds;this.data_bounds=this.get_data_bounds(this.track.get("data_manager").get_genome_wide_data(this.genome));if(this.data_bounds[0]<o[0]||this.data_bounds[1]>o[1]){this._transition_chrom_data()}},_render_data:function(r){var q=this,p=this.chroms_layout,o=this.track,s=$.Deferred();$.when(o.get("data_manager").get_genome_wide_data(this.genome)).then(function(u){q.data_bounds=q.get_data_bounds(u);layout_and_data=h.zip(p,u),chroms_data_layout=h.map(layout_and_data,function(v){var w=v[0],x=v[1];return q._render_chrom_data(r,w,x)});var t=q.get_fill_color();q.parent_elt.selectAll("path.chrom-data").style("stroke",t).style("fill",t);s.resolve(r)});return s},_render_chrom_data:function(o,p,q){},_get_path_function:function(p,o){},_chroms_layout:function(){var p=this.genome.get_chroms_info(),r=m.layout.pie().value(function(t){return t.len}).sort(null),s=r(p),o=this.total_gap/p.length,q=h.map(s,function(v,u){var t=v.endAngle-o;v.endAngle=(t>v.startAngle?t:v.startAngle);return v});return q}});var b=l.extend({initialize:function(o){l.prototype.initialize.call(this,o);this.innerRadius=this.radius_bounds[0];this.radius_bounds[0]=this.radius_bounds[1];this.bg_stroke="fff";this.bg_fill="fff";this.min_arc_len=0.05},_render_data:function(q){var p=this,o=q.selectAll("g");o.selectAll("path").attr("id",function(u){return"label-"+u.data.chrom});o.append("svg:text").filter(function(u){return u.endAngle-u.startAngle>p.min_arc_len}).attr("text-anchor","middle").append("svg:textPath").attr("class","chrom-label").attr("xlink:href",function(u){return"#label-"+u.data.chrom}).attr("startOffset","25%").text(function(u){return u.data.chrom});var r=function(w){var u=(w.endAngle-w.startAngle)/w.value,v=m.range(0,w.value,25000000).map(function(x,y){return{radius:p.innerRadius,angle:x*u+w.startAngle,label:y===0?0:(y%3?null:p.formatNum(x))}});if(v.length<4){v[v.length-1].label=p.formatNum(Math.round((v[v.length-1].angle-w.startAngle)/u))}return v};var t=function(u){return u.angle>Math.PI?"rotate(180)translate(-16)":null};var s=h.filter(this.chroms_layout,function(u){return u.endAngle-u.startAngle>p.min_arc_len});this.drawTicks(this.parent_elt,s,r,t)}});h.extend(b.prototype,i);var f=l.extend({_quantile:function(p,o){p.sort(m.ascending);return m.quantile(p,o)},_render_chrom_data:function(o,r,p){var s=this._get_path_function(r,p);if(!s){return null}var q=o.datum(p.data),t=q.append("path").attr("class","chrom-data").attr("chrom",r.data.chrom).attr("d",s);return t},_get_path_function:function(r,q){if(typeof q==="string"||!q.data||q.data.length===0){return null}var o=m.scale.linear().domain(this.data_bounds).range(this.radius_bounds).clamp(true);var s=m.scale.linear().domain([0,q.data.length]).range([r.startAngle,r.endAngle]);var p=m.svg.line.radial().interpolate("linear").radius(function(t){return o(t[1])}).angle(function(u,t){return s(t)});return m.svg.area.radial().interpolate(p.interpolate()).innerRadius(o(0)).outerRadius(p.radius()).angle(p.angle())},render_labels:function(){var o=this,p=function(){return"rotate(90)"};this.drawTicks(this.parent_elt,[this.chroms_layout[0]],this._data_bounds_ticks_fn(),p,true)},_transition_labels:function(){if(this.data_bounds.length===0){return}var p=this,r=h.filter(this.chroms_layout,function(s){return s.endAngle-s.startAngle>0.08}),q=h.filter(r,function(t,s){return s%3===0}),o=h.flatten(h.map(q,function(s){return p._data_bounds_ticks_fn()(s)}));this.parent_elt.selectAll("g.tick").data(o).transition().attr("transform",function(s){return"rotate("+(s.angle*180/Math.PI-90)+")translate("+s.radius+",0)"})},_data_bounds_ticks_fn:function(){var o=this;visibleChroms=0;return function(p){return[{radius:o.radius_bounds[0],angle:p.startAngle,label:o.formatNum(o.data_bounds[0])},{radius:o.radius_bounds[1],angle:p.startAngle,label:o.formatNum(o.data_bounds[1])}]}},get_data_bounds:function(o){}});h.extend(f.prototype,i);var d=f.extend({get_data_bounds:function(p){var o=h.flatten(h.map(p,function(q){if(q){return h.map(q.data,function(r){return parseInt(r[1],10)||0})}else{return 0}}));return[h.min(o),this._quantile(o,0.98)||h.max(o)]}});var k=l.extend({render:function(){var o=this;$.when(o.track.get("data_manager").data_is_ready()).then(function(){$.when(o.track.get("data_manager").get_genome_wide_data(o.genome)).then(function(r){var q=[],p=o.genome.get_chroms_info();h.each(r,function(v,u){var s=p[u].chrom;var t=h.map(v.data,function(x){var w=o._get_region_angle(s,x[1]),y=o._get_region_angle(x[3],x[4]);return{source:{startAngle:w,endAngle:w+0.01},target:{startAngle:y,endAngle:y+0.01}}});q=q.concat(t)});o.parent_elt.append("g").attr("class","chord").selectAll("path").data(q).enter().append("path").style("fill",o.get_fill_color()).attr("d",m.svg.chord().radius(o.radius_bounds[0])).style("opacity",1)})})},update_radius_bounds:function(o){this.radius_bounds=o;this.parent_elt.selectAll("path").transition().attr("d",m.svg.chord().radius(this.radius_bounds[0]))},_get_region_angle:function(q,o){var p=h.find(this.chroms_layout,function(r){return r.data.chrom===q});return p.endAngle-((p.endAngle-p.startAngle)*(p.data.len-o)/p.data.len)}});var e=Backbone.View.extend({initialize:function(){var o=new j.Genome(galaxy_config.app.genome),p=new j.GenomeVisualization(galaxy_config.app.viz_config),r=new a({el:$("#center .unified-panel-body"),total_gap:2*Math.PI*0.4,genome:o,model:p,dataset_arc_height:25});r.render();$("#center .unified-panel-header-inner").append(galaxy_config.app.viz_config.title+" "+galaxy_config.app.viz_config.dbkey);var q=create_icon_buttons_menu([{icon_class:"plus-button",title:"Add tracks",on_click:function(){j.select_datasets(galaxy_config.root+"visualization/list_current_history_datasets",galaxy_config.root+"api/datasets",p.get("dbkey"),function(s){p.add_tracks(s)})}},{icon_class:"disk--arrow",title:"Save",on_click:function(){Galaxy.modal.show({title:"Saving...",body:"progress"});$.ajax({url:galaxy_config.root+"visualization/save",type:"POST",dataType:"json",data:{id:p.get("vis_id"),title:p.get("title"),dbkey:p.get("dbkey"),type:"trackster",vis_json:JSON.stringify(p)}}).success(function(s){Galaxy.modal.hide();p.set("vis_id",s.vis_id)}).error(function(){Galaxy.modal.show({title:"Could Not Save",body:"Could not save visualization. Please try again later.",buttons:{Cancel:function(){Galaxy.modal.hide()}}})})}},{icon_class:"cross-circle",title:"Close",on_click:function(){window.location=galaxy_config.root+"visualization/list"}}],{tooltip_config:{placement:"bottom"}});q.$el.attr("style","float: right");$("#center .unified-panel-header-inner").append(q.$el);$(".menu-button").tooltip({placement:"bottom"})}});return{GalaxyApp:e}}); \ No newline at end of file diff -r 0a8336ad8d4df064abcaa286814527ee8bbde34f -r c98072c51cf05de686c631739a5deb18c15734bf static/scripts/packed/viz/visualization.js --- a/static/scripts/packed/viz/visualization.js +++ b/static/scripts/packed/viz/visualization.js @@ -1,1 +1,1 @@ -define(["libs/underscore","mvc/data","viz/trackster/util","utils/config"],function(t,j,m,p){var a=function(v,y,x,w){$.ajax({url:v,data:x,error:function(){alert("Grid failed")},success:function(z){Galaxy.modal.show({title:"Select datasets for new tracks",body:z,buttons:{Cancel:function(){Galaxy.modal.hide()},Add:function(){var A=[];$("input[name=id]:checked,input[name=ldda_ids]:checked").each(function(){var B={data_type:"track_config",hda_ldda:"hda"},C=$(this).val();if($(this).attr("name")!=="id"){B.hda_ldda="ldda"}A[A.length]=$.ajax({url:y+"/"+C,data:B,dataType:"json"})});$.when.apply($,A).then(function(){var B=(arguments[0] instanceof Array?$.map(arguments,function(C){return C[0]}):[arguments[0]]);w(B)});Galaxy.modal.hide()}}})}})};var k=function(v){return("promise" in v)};var f=function(v){this.default_font=v!==undefined?v:"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")};t.extend(f.prototype,{load_pattern:function(v,z){var w=this.patterns,x=this.dummy_context,y=new Image();y.src=galaxy_config.root+"static/images"+z;y.onload=function(){w[v]=x.createPattern(y,"repeat")}},get_pattern:function(v){return this.patterns[v]},new_canvas:function(){var v=$("<canvas/>")[0];if(window.G_vmlCanvasManager){G_vmlCanvasManager.initElement(v)}v.manager=this;return v}});var r=Backbone.Model.extend({defaults:{num_elements:20,obj_cache:null,key_ary:null},initialize:function(v){this.clear()},get_elt:function(x){var y=this.attributes.obj_cache,z=this.attributes.key_ary,w=x.toString(),v=t.indexOf(z,function(A){return A.toString()===w});if(v!==-1){if(y[w].stale){z.splice(v,1);delete y[w]}else{this.move_key_to_end(x,v)}}return y[w]},set_elt:function(x,z){var A=this.attributes.obj_cache,B=this.attributes.key_ary,w=x.toString(),y=this.attributes.num_elements;if(!A[w]){if(B.length>=y){var v=B.shift();delete A[v.toString()]}B.push(x)}A[w]=z;return z},move_key_to_end:function(w,v){this.attributes.key_ary.splice(v,1);this.attributes.key_ary.push(w)},clear:function(){this.attributes.obj_cache={};this.attributes.key_ary=[]},size:function(){return this.attributes.key_ary.length},most_recently_added:function(){return this.size()===0?null:this.attributes.key_ary[this.attributes.key_ary.length-1]}});var d=r.extend({defaults:t.extend({},r.prototype.defaults,{dataset:null,genome:null,init_data:null,min_region_size:200,filters_manager:null,data_type:"data",data_mode_compatible:function(v,w){return true},can_subset:function(v){return false}}),initialize:function(v){r.prototype.initialize.call(this);var w=this.get("init_data");if(w){this.add_data(w)}},add_data:function(v){if(this.get("num_elements")<v.length){this.set("num_elements",v.length)}var w=this;t.each(v,function(x){w.set_data(x.region,x)})},data_is_ready:function(){var y=this.get("dataset"),x=$.Deferred(),v=(this.get("data_type")==="raw_data"?"state":this.get("data_type")==="data"?"converted_datasets_state":"error"),w=new m.ServerStateDeferred({ajax_settings:{url:this.get("dataset").url(),data:{hda_ldda:y.get("hda_ldda"),data_type:v},dataType:"json"},interval:5000,success_fn:function(z){return z!=="pending"}});$.when(w.go()).then(function(z){x.resolve(z==="ok"||z==="data")});return x},search_features:function(v){var w=this.get("dataset"),x={query:v,hda_ldda:w.get("hda_ldda"),data_type:"features"};return $.getJSON(w.url(),x)},load_data:function(D,C,w,B){var z=this.get("dataset"),y={data_type:this.get("data_type"),chrom:D.get("chrom"),low:D.get("start"),high:D.get("end"),mode:C,resolution:w,hda_ldda:z.get("hda_ldda")};$.extend(y,B);var F=this.get("filters_manager");if(F){var G=[];var v=F.filters;for(var A=0;A<v.length;A++){G.push(v[A].name)}y.filter_cols=JSON.stringify(G)}var x=this,E=$.getJSON(z.url(),y,function(H){H.region=D;x.set_data(D,H)});this.set_data(D,E);return E},get_data:function(C,B,x,z){var D=this.get_elt(C);if(D&&(k(D)||this.get("data_mode_compatible")(D,B))){return D}var E=this.get("key_ary"),v=this.get("obj_cache"),w,A;for(var y=0;y<E.length;y++){w=E[y];if(w.contains(C)){A=true;D=v[w.toString()];if(k(D)||(this.get("data_mode_compatible")(D,B)&&this.get("can_subset")(D))){this.move_key_to_end(w,y);if(!k(D)){var G=this.subset_entry(D,C);this.set(C,G);D=G}return D}}}if(!A&&C.length()<this.attributes.min_region_size){C=C.copy();var F=this.most_recently_added();if(!F||(C.get("start")>F.get("start"))){C.set("end",C.get("start")+this.attributes.min_region_size)}else{C.set("start",C.get("end")-this.attributes.min_region_size)}C.set("genome",this.attributes.genome);C.trim()}return this.load_data(C,B,x,z)},set_data:function(w,v){this.set_elt(w,v)},DEEP_DATA_REQ:"deep",BROAD_DATA_REQ:"breadth",get_more_data:function(D,C,y,B,z){var F=this._mark_stale(D);if(!(F&&this.get("data_mode_compatible")(F,C))){console.log("ERROR: problem with getting more data: current data is not compatible");return}var x=D.get("start");if(z===this.DEEP_DATA_REQ){$.extend(B,{start_val:F.data.length+1})}else{if(z===this.BROAD_DATA_REQ){x=(F.max_high?F.max_high:F.data[F.data.length-1][2])+1}}var E=D.copy().set("start",x);var w=this,A=this.load_data(E,C,y,B),v=$.Deferred();this.set_data(D,v);$.when(A).then(function(G){if(G.data){G.data=F.data.concat(G.data);if(G.max_low){G.max_low=F.max_low}if(G.message){G.message=G.message.replace(/[0-9]+/,G.data.length)}}w.set_data(D,G);v.resolve(G)});return v},can_get_more_detailed_data:function(w){var v=this.get_elt(w);return(v.dataset_type==="bigwig"&&v.data.length<8000)},get_more_detailed_data:function(y,A,w,z,x){var v=this._mark_stale(y);if(!v){console.log("ERROR getting more detailed data: no current data");return}if(!x){x={}}if(v.dataset_type==="bigwig"){x.num_samples=1000*z}return this.load_data(y,A,w,x)},_mark_stale:function(w){var v=this.get_elt(w);if(!v){console.log("ERROR: no data to mark as stale: ",this.get("dataset"),w.toString())}v.stale=true;return v},get_genome_wide_data:function(v){var x=this,z=true,y=t.map(v.get("chroms_info").chrom_info,function(B){var A=x.get_elt(new g({chrom:B.chrom,start:0,end:B.len}));if(!A){z=false}return A});if(z){return y}var w=$.Deferred();$.getJSON(this.get("dataset").url(),{data_type:"genome_data"},function(A){x.add_data(A.data);w.resolve(A.data)});return w},subset_entry:function(x,y){var v={bigwig:function(z,A){return t.filter(z,function(B){return B[0]>=A.get("start")&&B[0]<=A.get("end")})},refseq:function(A,B){var C=B.get("start")-x.region.get("start"),z=x.data.length-(x.region.get("end")-B.get("end"));return x.data.slice(C,z)}};var w=x.data;if(!x.region.same(y)&&x.dataset_type in v){w=v[x.dataset_type](x.data,y)}return{region:y,data:w,dataset_type:x.dataset_type}}});var q=d.extend({initialize:function(v){var w=new Backbone.Model();w.urlRoot=v.data_url;this.set("dataset",w)},load_data:function(x,y,v,w){return(x.length()<=100000?d.prototype.load_data.call(this,x,y,v,w):{data:null,region:x})}});var c=Backbone.Model.extend({defaults:{name:null,key:null,chroms_info:null},initialize:function(v){this.id=v.dbkey},get_chroms_info:function(){return this.attributes.chroms_info.chrom_info},get_chrom_region:function(v){var w=t.find(this.get_chroms_info(),function(x){return x.chrom===v});return new g({chrom:w.chrom,end:w.len})},get_chrom_len:function(v){return t.find(this.get_chroms_info(),function(w){return w.chrom===v}).len}});var g=Backbone.Model.extend({defaults:{chrom:null,start:0,end:0,str_val:null,genome:null},same:function(v){return this.attributes.chrom===v.get("chrom")&&this.attributes.start===v.get("start")&&this.attributes.end===v.get("end")},initialize:function(w){if(w.from_str){var y=w.from_str.split(":"),x=y[0],v=y[1].split("-");this.set({chrom:x,start:parseInt(v[0],10),end:parseInt(v[1],10)})}this.attributes.str_val=this.get("chrom")+":"+this.get("start")+"-"+this.get("end");this.on("change",function(){this.attributes.str_val=this.get("chrom")+":"+this.get("start")+"-"+this.get("end")},this)},copy:function(){return new g({chrom:this.get("chrom"),start:this.get("start"),end:this.get("end")})},length:function(){return this.get("end")-this.get("start")},toString:function(){return this.attributes.str_val},toJSON:function(){return{chrom:this.get("chrom"),start:this.get("start"),end:this.get("end")}},compute_overlap:function(C){var w=this.get("chrom"),B=C.get("chrom"),A=this.get("start"),y=C.get("start"),z=this.get("end"),x=C.get("end"),v;if(w&&B&&w!==B){return g.overlap_results.DIF_CHROMS}if(A<y){if(z<y){v=g.overlap_results.BEFORE}else{if(z<x){v=g.overlap_results.OVERLAP_START}else{v=g.overlap_results.CONTAINS}}}else{if(A>y){if(A>x){v=g.overlap_results.AFTER}else{if(z<=x){v=g.overlap_results.CONTAINED_BY}else{v=g.overlap_results.OVERLAP_END}}}else{v=(z>=x?g.overlap_results.CONTAINS:g.overlap_results.CONTAINED_BY)}}return v},trim:function(v){if(this.attributes.start<0){this.attributes.start=0}if(this.attributes.genome){var w=this.attributes.genome.get_chrom_len(this.attributes.chrom);if(this.attributes.end>w){this.attributes.end=w-1}}return this},contains:function(v){return this.compute_overlap(v)===g.overlap_results.CONTAINS},overlaps:function(v){return t.intersection([this.compute_overlap(v)],[g.overlap_results.DIF_CHROMS,g.overlap_results.BEFORE,g.overlap_results.AFTER]).length===0}},{overlap_results:{DIF_CHROMS:1000,BEFORE:1001,CONTAINS:1002,OVERLAP_START:1003,OVERLAP_END:1004,CONTAINED_BY:1005,AFTER:1006}});var n=Backbone.Collection.extend({model:g});var e=Backbone.Model.extend({defaults:{region:null,note:""},initialize:function(v){this.set("region",new g(v.region))}});var s=Backbone.Collection.extend({model:e});var u=Backbone.Model.extend({initialize:function(v){this.set("dataset",new j.Dataset(v.dataset));this.set("config",p.ConfigSettingCollection.from_config_dict(v.prefs));this.get("config").add([{key:"name",value:this.get("name")},{key:"color"}]);var w=this.get("preloaded_data");if(w){w=w.data}else{w=[]}this.set("data_manager",new d({dataset:this.get("dataset"),init_data:w}))}});var i=Backbone.Collection.extend({model:u});var o=Backbone.Model.extend({defaults:{title:"",type:""},url:galaxy_config.root+"visualization/save",save:function(){return $.ajax({url:this.url(),type:"POST",dataType:"json",data:{vis_json:JSON.stringify(this)}})}});var l=o.extend({defaults:t.extend({},o.prototype.defaults,{dbkey:"",tracks:null,bookmarks:null,viewport:null}),initialize:function(v){this.set("tracks",new i(v.tracks))},add_tracks:function(v){this.get("tracks").add(v)}});var b=Backbone.Model.extend({});var h=Backbone.Router.extend({initialize:function(w){this.view=w.view;this.route(/([\w]+)$/,"change_location");this.route(/([\w]+\:[\d,]+-[\d,]+)$/,"change_location");var v=this;v.view.on("navigate",function(x){v.navigate(x)})},change_location:function(v){this.view.go_to(v)}});return{BackboneTrack:u,BrowserBookmark:e,BrowserBookmarkCollection:s,Cache:r,CanvasManager:f,Genome:c,GenomeDataManager:d,GenomeRegion:g,GenomeRegionCollection:n,GenomeVisualization:l,GenomeReferenceDataManager:q,TrackBrowserRouter:h,TrackConfig:b,Visualization:o,select_datasets:a}}); \ No newline at end of file +define(["libs/underscore","mvc/data","viz/trackster/util","utils/config"],function(u,k,n,q){var f={toJSON:function(){var w=this,x={};u.each(w.constructor.to_json_keys,function(y){var z=w.get(y);if(y in w.constructor.to_json_mappers){z=w.constructor.to_json_mappers[y](z,w)}x[y]=z});return x}};var a=function(w,z,y,x){$.ajax({url:w,data:y,error:function(){alert("Grid failed")},success:function(A){Galaxy.modal.show({title:"Select datasets for new tracks",body:A,buttons:{Cancel:function(){Galaxy.modal.hide()},Add:function(){var B=[];$("input[name=id]:checked,input[name=ldda_ids]:checked").each(function(){var C={data_type:"track_config",hda_ldda:"hda"},D=$(this).val();if($(this).attr("name")!=="id"){C.hda_ldda="ldda"}B[B.length]=$.ajax({url:z+"/"+D,data:C,dataType:"json"})});$.when.apply($,B).then(function(){var C=(arguments[0] instanceof Array?$.map(arguments,function(D){return D[0]}):[arguments[0]]);x(C)});Galaxy.modal.hide()}}})}})};var l=function(w){return("promise" in w)};var g=function(w){this.default_font=w!==undefined?w:"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")};u.extend(g.prototype,{load_pattern:function(w,A){var x=this.patterns,y=this.dummy_context,z=new Image();z.src=galaxy_config.root+"static/images"+A;z.onload=function(){x[w]=y.createPattern(z,"repeat")}},get_pattern:function(w){return this.patterns[w]},new_canvas:function(){var w=$("<canvas/>")[0];if(window.G_vmlCanvasManager){G_vmlCanvasManager.initElement(w)}w.manager=this;return w}});var s=Backbone.Model.extend({defaults:{num_elements:20,obj_cache:null,key_ary:null},initialize:function(w){this.clear()},get_elt:function(y){var z=this.attributes.obj_cache,A=this.attributes.key_ary,x=y.toString(),w=u.indexOf(A,function(B){return B.toString()===x});if(w!==-1){if(z[x].stale){A.splice(w,1);delete z[x]}else{this.move_key_to_end(y,w)}}return z[x]},set_elt:function(y,A){var B=this.attributes.obj_cache,C=this.attributes.key_ary,x=y.toString(),z=this.attributes.num_elements;if(!B[x]){if(C.length>=z){var w=C.shift();delete B[w.toString()]}C.push(y)}B[x]=A;return A},move_key_to_end:function(x,w){this.attributes.key_ary.splice(w,1);this.attributes.key_ary.push(x)},clear:function(){this.attributes.obj_cache={};this.attributes.key_ary=[]},size:function(){return this.attributes.key_ary.length},most_recently_added:function(){return this.size()===0?null:this.attributes.key_ary[this.attributes.key_ary.length-1]}});var d=s.extend({defaults:u.extend({},s.prototype.defaults,{dataset:null,genome:null,init_data:null,min_region_size:200,filters_manager:null,data_type:"data",data_mode_compatible:function(w,x){return true},can_subset:function(w){return false}}),initialize:function(w){s.prototype.initialize.call(this);var x=this.get("init_data");if(x){this.add_data(x)}},add_data:function(w){if(this.get("num_elements")<w.length){this.set("num_elements",w.length)}var x=this;u.each(w,function(y){x.set_data(y.region,y)})},data_is_ready:function(){var z=this.get("dataset"),y=$.Deferred(),w=(this.get("data_type")==="raw_data"?"state":this.get("data_type")==="data"?"converted_datasets_state":"error"),x=new n.ServerStateDeferred({ajax_settings:{url:this.get("dataset").url(),data:{hda_ldda:z.get("hda_ldda"),data_type:w},dataType:"json"},interval:5000,success_fn:function(A){return A!=="pending"}});$.when(x.go()).then(function(A){y.resolve(A==="ok"||A==="data")});return y},search_features:function(w){var x=this.get("dataset"),y={query:w,hda_ldda:x.get("hda_ldda"),data_type:"features"};return $.getJSON(x.url(),y)},load_data:function(E,D,x,C){var A=this.get("dataset"),z={data_type:this.get("data_type"),chrom:E.get("chrom"),low:E.get("start"),high:E.get("end"),mode:D,resolution:x,hda_ldda:A.get("hda_ldda")};$.extend(z,C);var G=this.get("filters_manager");if(G){var H=[];var w=G.filters;for(var B=0;B<w.length;B++){H.push(w[B].name)}z.filter_cols=JSON.stringify(H)}var y=this,F=$.getJSON(A.url(),z,function(I){I.region=E;y.set_data(E,I)});this.set_data(E,F);return F},get_data:function(D,C,y,A){var E=this.get_elt(D);if(E&&(l(E)||this.get("data_mode_compatible")(E,C))){return E}var F=this.get("key_ary"),w=this.get("obj_cache"),x,B;for(var z=0;z<F.length;z++){x=F[z];if(x.contains(D)){B=true;E=w[x.toString()];if(l(E)||(this.get("data_mode_compatible")(E,C)&&this.get("can_subset")(E))){this.move_key_to_end(x,z);if(!l(E)){var H=this.subset_entry(E,D);this.set(D,H);E=H}return E}}}if(!B&&D.length()<this.attributes.min_region_size){D=D.copy();var G=this.most_recently_added();if(!G||(D.get("start")>G.get("start"))){D.set("end",D.get("start")+this.attributes.min_region_size)}else{D.set("start",D.get("end")-this.attributes.min_region_size)}D.set("genome",this.attributes.genome);D.trim()}return this.load_data(D,C,y,A)},set_data:function(x,w){this.set_elt(x,w)},DEEP_DATA_REQ:"deep",BROAD_DATA_REQ:"breadth",get_more_data:function(E,D,z,C,A){var G=this._mark_stale(E);if(!(G&&this.get("data_mode_compatible")(G,D))){console.log("ERROR: problem with getting more data: current data is not compatible");return}var y=E.get("start");if(A===this.DEEP_DATA_REQ){$.extend(C,{start_val:G.data.length+1})}else{if(A===this.BROAD_DATA_REQ){y=(G.max_high?G.max_high:G.data[G.data.length-1][2])+1}}var F=E.copy().set("start",y);var x=this,B=this.load_data(F,D,z,C),w=$.Deferred();this.set_data(E,w);$.when(B).then(function(H){if(H.data){H.data=G.data.concat(H.data);if(H.max_low){H.max_low=G.max_low}if(H.message){H.message=H.message.replace(/[0-9]+/,H.data.length)}}x.set_data(E,H);w.resolve(H)});return w},can_get_more_detailed_data:function(x){var w=this.get_elt(x);return(w.dataset_type==="bigwig"&&w.data.length<8000)},get_more_detailed_data:function(z,B,x,A,y){var w=this._mark_stale(z);if(!w){console.log("ERROR getting more detailed data: no current data");return}if(!y){y={}}if(w.dataset_type==="bigwig"){y.num_samples=1000*A}return this.load_data(z,B,x,y)},_mark_stale:function(x){var w=this.get_elt(x);if(!w){console.log("ERROR: no data to mark as stale: ",this.get("dataset"),x.toString())}w.stale=true;return w},get_genome_wide_data:function(w){var y=this,A=true,z=u.map(w.get("chroms_info").chrom_info,function(C){var B=y.get_elt(new h({chrom:C.chrom,start:0,end:C.len}));if(!B){A=false}return B});if(A){return z}var x=$.Deferred();$.getJSON(this.get("dataset").url(),{data_type:"genome_data"},function(B){y.add_data(B.data);x.resolve(B.data)});return x},subset_entry:function(y,z){var w={bigwig:function(A,B){return u.filter(A,function(C){return C[0]>=B.get("start")&&C[0]<=B.get("end")})},refseq:function(B,C){var D=C.get("start")-y.region.get("start"),A=y.data.length-(y.region.get("end")-C.get("end"));return y.data.slice(D,A)}};var x=y.data;if(!y.region.same(z)&&y.dataset_type in w){x=w[y.dataset_type](y.data,z)}return{region:z,data:x,dataset_type:y.dataset_type}}});var r=d.extend({initialize:function(w){var x=new Backbone.Model();x.urlRoot=w.data_url;this.set("dataset",x)},load_data:function(y,z,w,x){return(y.length()<=100000?d.prototype.load_data.call(this,y,z,w,x):{data:null,region:y})}});var c=Backbone.Model.extend({defaults:{name:null,key:null,chroms_info:null},initialize:function(w){this.id=w.dbkey},get_chroms_info:function(){return this.attributes.chroms_info.chrom_info},get_chrom_region:function(w){var x=u.find(this.get_chroms_info(),function(y){return y.chrom===w});return new h({chrom:x.chrom,end:x.len})},get_chrom_len:function(w){return u.find(this.get_chroms_info(),function(x){return x.chrom===w}).len}});var h=Backbone.Model.extend({defaults:{chrom:null,start:0,end:0,str_val:null,genome:null},same:function(w){return this.attributes.chrom===w.get("chrom")&&this.attributes.start===w.get("start")&&this.attributes.end===w.get("end")},initialize:function(x){if(x.from_str){var z=x.from_str.split(":"),y=z[0],w=z[1].split("-");this.set({chrom:y,start:parseInt(w[0],10),end:parseInt(w[1],10)})}this.attributes.str_val=this.get("chrom")+":"+this.get("start")+"-"+this.get("end");this.on("change",function(){this.attributes.str_val=this.get("chrom")+":"+this.get("start")+"-"+this.get("end")},this)},copy:function(){return new h({chrom:this.get("chrom"),start:this.get("start"),end:this.get("end")})},length:function(){return this.get("end")-this.get("start")},toString:function(){return this.attributes.str_val},toJSON:function(){return{chrom:this.get("chrom"),start:this.get("start"),end:this.get("end")}},compute_overlap:function(D){var x=this.get("chrom"),C=D.get("chrom"),B=this.get("start"),z=D.get("start"),A=this.get("end"),y=D.get("end"),w;if(x&&C&&x!==C){return h.overlap_results.DIF_CHROMS}if(B<z){if(A<z){w=h.overlap_results.BEFORE}else{if(A<y){w=h.overlap_results.OVERLAP_START}else{w=h.overlap_results.CONTAINS}}}else{if(B>z){if(B>y){w=h.overlap_results.AFTER}else{if(A<=y){w=h.overlap_results.CONTAINED_BY}else{w=h.overlap_results.OVERLAP_END}}}else{w=(A>=y?h.overlap_results.CONTAINS:h.overlap_results.CONTAINED_BY)}}return w},trim:function(w){if(this.attributes.start<0){this.attributes.start=0}if(this.attributes.genome){var x=this.attributes.genome.get_chrom_len(this.attributes.chrom);if(this.attributes.end>x){this.attributes.end=x-1}}return this},contains:function(w){return this.compute_overlap(w)===h.overlap_results.CONTAINS},overlaps:function(w){return u.intersection([this.compute_overlap(w)],[h.overlap_results.DIF_CHROMS,h.overlap_results.BEFORE,h.overlap_results.AFTER]).length===0}},{overlap_results:{DIF_CHROMS:1000,BEFORE:1001,CONTAINS:1002,OVERLAP_START:1003,OVERLAP_END:1004,CONTAINED_BY:1005,AFTER:1006}});var o=Backbone.Collection.extend({model:h});var e=Backbone.Model.extend({defaults:{region:null,note:""},initialize:function(w){this.set("region",new h(w.region))}});var t=Backbone.Collection.extend({model:e});var v=Backbone.Model.extend(f).extend({defaults:{mode:"Auto"},initialize:function(w){this.set("dataset",new k.Dataset(w.dataset));this.set("config",q.ConfigSettingCollection.from_config_dict(w.prefs));this.get("config").add([{key:"name",value:this.get("dataset").get("name")},{key:"color"}]);var x=this.get("preloaded_data");if(x){x=x.data}else{x=[]}this.set("data_manager",new d({dataset:this.get("dataset"),init_data:x}))}},{to_json_keys:["track_type","dataset","prefs","mode","filters","tool_state"],to_json_mappers:{prefs:function(x,w){if(u.size(x)===0){x={name:w.get("config").get("name").get("value"),color:w.get("config").get("color").get("value")}}return x},dataset:function(w){return{id:w.id,hda_ldda:w.get("hda_ldda")}}}});var j=Backbone.Collection.extend({model:v});var p=Backbone.Model.extend({defaults:{title:"",type:""},url:galaxy_config.root+"visualization/save",save:function(){return $.ajax({url:this.url(),type:"POST",dataType:"json",data:{vis_json:JSON.stringify(this)}})}});var m=p.extend(f).extend({defaults:u.extend({},p.prototype.defaults,{dbkey:"",drawables:null,bookmarks:null,viewport:null}),initialize:function(w){this.set("drawables",new j(w.tracks));this.set("config",q.ConfigSettingCollection.from_config_dict(w.prefs||{}));this.unset("tracks");this.get("drawables").each(function(x){x.unset("preloaded_data")})},add_tracks:function(w){this.get("drawables").add(w)}},{to_json_keys:["view","viewport","bookmarks"],to_json_mappers:{view:function(x,w){return{obj_type:"View",prefs:{name:w.get("title"),content_visible:true},drawables:w.get("drawables")}}}});var b=Backbone.Model.extend({});var i=Backbone.Router.extend({initialize:function(x){this.view=x.view;this.route(/([\w]+)$/,"change_location");this.route(/([\w]+\:[\d,]+-[\d,]+)$/,"change_location");var w=this;w.view.on("navigate",function(y){w.navigate(y)})},change_location:function(w){this.view.go_to(w)}});return{BackboneTrack:v,BrowserBookmark:e,BrowserBookmarkCollection:t,Cache:s,CanvasManager:g,Genome:c,GenomeDataManager:d,GenomeRegion:h,GenomeRegionCollection:o,GenomeVisualization:m,GenomeReferenceDataManager:r,TrackBrowserRouter:i,TrackConfig:b,Visualization:p,select_datasets:a}}); \ No newline at end of file diff -r 0a8336ad8d4df064abcaa286814527ee8bbde34f -r c98072c51cf05de686c631739a5deb18c15734bf static/scripts/viz/circster.js --- a/static/scripts/viz/circster.js +++ b/static/scripts/viz/circster.js @@ -143,8 +143,8 @@ this.chords_views = null; // When tracks added to/removed from model, update view. - this.model.get('tracks').on('add', this.add_track, this); - this.model.get('tracks').on('remove', this.remove_track, this); + this.model.get('drawables').on('add', this.add_track, this); + this.model.get('drawables').on('remove', this.remove_track, this); this.get_circular_tracks(); }, @@ -154,7 +154,7 @@ * Returns tracks to be rendered using circular view. */ get_circular_tracks: function() { - return this.model.get('tracks').filter(function(track) { + return this.model.get('drawables').filter(function(track) { return track.get('track_type') !== 'DiagonalHeatmapTrack'; }); }, @@ -163,7 +163,7 @@ * Returns tracks to be rendered using chords view. */ get_chord_tracks: function() { - return this.model.get('tracks').filter(function(track) { + return this.model.get('drawables').filter(function(track) { return track.get('track_type') === 'DiagonalHeatmapTrack'; }); }, @@ -992,41 +992,36 @@ // setup menu var menu = create_icon_buttons_menu([ - { icon_class: 'plus-button', title: 'Add tracks', on_click: function() + { + icon_class: 'plus-button', title: 'Add tracks', on_click: function() { visualization.select_datasets(galaxy_config.root + "visualization/list_current_history_datasets", galaxy_config.root + "api/datasets", vis.get('dbkey'), function(tracks) { vis.add_tracks(tracks); }); } - },{ + }, + { icon_class: 'disk--arrow', title: 'Save', on_click: function() { // show saving dialog box Galaxy.modal.show({title: "Saving...", body: "progress" }); - // link configuration - var view = galaxy_config.app.viz_config; - // send to server $.ajax({ url: galaxy_config.root + "visualization/save", type: "POST", dataType: "json", data: { - 'id' : view.vis_id, - 'title' : view.title, - 'dbkey' : view.dbkey, + 'id' : vis.get('vis_id'), + 'title' : vis.get('title'), + 'dbkey' : vis.get('dbkey'), 'type' : 'trackster', - 'vis_json' : JSON.stringify(view) + 'vis_json' : JSON.stringify(vis) } }).success(function(vis_info) { Galaxy.modal.hide(); - view.vis_id = vis_info.vis_id; - view.has_changes = false; - - // needed to set URL when first saving a visualization - window.history.pushState({}, "", vis_info.url + window.location.hash); + vis.set('vis_id', vis_info.vis_id); }).error(function() { // show dialog Galaxy.modal.show({ @@ -1036,7 +1031,8 @@ }); }); } - },{ + }, + { icon_class: 'cross-circle', title: 'Close', on_click: function() { window.location = galaxy_config.root + "visualization/list"; diff -r 0a8336ad8d4df064abcaa286814527ee8bbde34f -r c98072c51cf05de686c631739a5deb18c15734bf static/scripts/viz/visualization.js --- a/static/scripts/viz/visualization.js +++ b/static/scripts/viz/visualization.js @@ -1,6 +1,28 @@ define( ["libs/underscore", "mvc/data", "viz/trackster/util", "utils/config"], function(_, data_mod, util_mod, config_mod) { /** + * Mixin for returning custom JSON representation from toJSON. Class attribute to_json_keys defines a set of attributes + * to include in the representation; to_json_mappers defines mappers for returned objects. + */ +var CustomToJSON = { + /** + * Returns JSON representation of object using to_json_keys and to_json_mappers. + */ + toJSON: function() { + var self = this, + json = {}; + _.each(self.constructor.to_json_keys, function(k) { + var val = self.get(k); + if (k in self.constructor.to_json_mappers) { + val = self.constructor.to_json_mappers[k](val, self); + } + json[k] = val; + }); + return json; + } +}; + +/** * Model, view, and controller objects for Galaxy visualization framework. * * Models have no references to views, instead using events to indicate state @@ -872,7 +894,10 @@ * A track of data in a genome visualization. */ // TODO: rename to Track and merge with Trackster's Track object. -var BackboneTrack = Backbone.Model.extend({ +var BackboneTrack = Backbone.Model.extend(CustomToJSON).extend({ + defaults: { + mode: 'Auto' + }, initialize: function(options) { this.set('dataset', new data_mod.Dataset(options.dataset)); @@ -883,7 +908,7 @@ // Set up some minimal config. this.get('config').add( [ - { key: 'name', value: this.get('name') }, + { key: 'name', value: this.get('dataset').get('name') }, { key: 'color' } ] ); @@ -900,6 +925,34 @@ init_data: preloaded_data })); } +}, +{ + // This definition matches that produced by to_dict() methods in tracks.js + to_json_keys: [ + 'track_type', + 'dataset', + 'prefs', + 'mode', + 'filters', + 'tool_state' + ], + to_json_mappers: { + prefs: function(p, self) { + if (_.size(p) === 0) { + p = { + name: self.get('config').get('name').get('value'), + color: self.get('config').get('color').get('value') + }; + } + return p; + }, + dataset: function(d) { + return { + id: d.id, + hda_ldda: d.get('hda_ldda') + }; + } + } }); var BackboneTrackCollection = Backbone.Collection.extend({ @@ -938,25 +991,55 @@ /** * A visualization of genome data. */ -var GenomeVisualization = Visualization.extend({ +var GenomeVisualization = Visualization.extend(CustomToJSON).extend({ defaults: _.extend({}, Visualization.prototype.defaults, { dbkey: '', - tracks: null, + drawables: null, bookmarks: null, viewport: null }), initialize: function(options) { - this.set('tracks', new BackboneTrackCollection(options.tracks)); + // Replace drawables with tracks. + this.set('drawables', new BackboneTrackCollection(options.tracks)); + this.set('config', config_mod.ConfigSettingCollection.from_config_dict(options.prefs || {})); + + // Clear track and data definitions to avoid storing large objects. + this.unset('tracks'); + this.get('drawables').each(function(d) { + d.unset('preloaded_data'); + }); }, /** * Add a track or array of tracks to the visualization. */ add_tracks: function(tracks) { - this.get('tracks').add(tracks); + this.get('drawables').add(tracks); } -}); +}, +{ + // This definition matches that produced by to_dict() methods in tracks.js + to_json_keys: [ + 'view', + 'viewport', + 'bookmarks' + ], + + to_json_mappers: { + 'view': function(dummy, self) { + return { + obj_type: 'View', + prefs: { + name: self.get('title'), + content_visible: true + }, + drawables: self.get('drawables') + }; + } + } +} +); /** * Configuration data for a Trackster track. https://bitbucket.org/galaxy/galaxy-central/commits/90b76033686b/ Changeset: 90b76033686b User: jeremy goecks Date: 2014-02-05 22:23:24 Summary: Merge local into default. Affected #: 3 files diff -r c98072c51cf05de686c631739a5deb18c15734bf -r 90b76033686b5c363bca32edf7f6c292a1d0d080 static/style/blue/base.css --- a/static/style/blue/base.css +++ b/static/style/blue/base.css @@ -1605,46 +1605,46 @@ .history-panel .dataset:last-child{border-width:1px 0px 1px 0px} .history-panel .empty-history-message{display:none;margin:0px 10px 0px 10px} .history-panel .tag-button{display:inline-block;height:20px;margin:2px 2px 0px 0px;border:1px solid grey;border-radius:3px 10px 10px 3px;padding:2px 4px 2px 4px;background-color:#EEE;line-height:13px}.history-panel .tag-button .tag-name{margin-right:2px} -.dataset{border:1px solid #bfbfbf}.dataset .vertical-spacing{margin-bottom:8px} -.dataset .info-section{border-radius:3px;border:1px solid rgba(153,153,153,0.30000000000000004);padding:4px} -.dataset .dataset-padding{padding:6px 10px 6px 8px} -.dataset [class$=messagesmall]{margin:6px 10px 2px 8px;font-size:90%} -.dataset .help-text{font-weight:normal;color:#555} -.dataset .dataset-selector{float:left;display:none;width:0px;margin:0 0 -6px 0;padding:5px 0 2px 8px;cursor:pointer;vertical-align:middle} -.dataset .dataset-title-bar{cursor:pointer;outline:none;padding:6px 10px 6px 8px} -.dataset .dataset-title-bar .dataset-title{display:inline;font-weight:bold;text-decoration:underline;word-wrap:break-word;word-break:break-all;line-height:16px} -.dataset .dataset-primary-actions{display:inline-block;float:right;margin:6px 10px 0}.dataset .dataset-primary-actions .icon-btn:not(:last-child){margin:0px;border-radius:0px;border-right:none} -.dataset .dataset-primary-actions .icon-btn:first-child{margin-right:0px;border-top-left-radius:3px;border-bottom-left-radius:3px} -.dataset .dataset-primary-actions .icon-btn:last-child{margin-left:0px;border-radius:0px 3px 3px 0px} -.dataset .dataset-primary-actions .icon-btn{margin-left:2px} -.dataset .dataset-body{display:none;padding:6px 10px 6px 8px}.dataset .dataset-body [class$=messagesmall]{margin:0px 0px 8px 0px} -.dataset .dataset-body label{margin:0px;padding:0px;font-weight:normal} -.dataset .dataset-body .prompt{font-weight:normal;color:#555} -.dataset .dataset-body .prompt:after{content:':'} -.dataset .dataset-body .dataset-summary{margin-bottom:8px}.dataset .dataset-body .dataset-summary .dataset-blurb{margin-bottom:2px} -.dataset .dataset-body .dataset-summary .dataset-datatype,.dataset .dataset-body .dataset-summary .dataset-dbkey{display:inline}.dataset .dataset-body .dataset-summary .dataset-datatype .value,.dataset .dataset-body .dataset-summary .dataset-dbkey .value{font-weight:bold} -.dataset .dataset-body .dataset-summary .dataset-datatype .value:after{content:',';font-weight:normal;color:#555} -.dataset .dataset-body .dataset-summary .dataset-dbkey:after{content:' ';display:block;margin-bottom:8px} -.dataset .dataset-body .dataset-summary .dataset-info{border-radius:3px;border:1px solid rgba(153,153,153,0.30000000000000004);padding:4px}.dataset .dataset-body .dataset-summary .dataset-info .value{white-space:pre-line} -.dataset .dataset-body .dataset-summary .job-error-text{border-radius:3px;border:1px solid rgba(153,153,153,0.30000000000000004);padding:4px;overflow:auto;white-space:pre} -.dataset .dataset-body .dataset-actions .left{display:inline-block;float:left}.dataset .dataset-body .dataset-actions .left .icon-btn:not(:last-child){margin:0px;border-radius:0px;border-right:none} -.dataset .dataset-body .dataset-actions .left .icon-btn:first-child{margin-right:0px;border-top-left-radius:3px;border-bottom-left-radius:3px} -.dataset .dataset-body .dataset-actions .left .icon-btn:last-child{margin-left:0px;border-radius:0px 3px 3px 0px} -.dataset .dataset-body .dataset-actions .left .icon-btn{margin-right:2px} -.dataset .dataset-body .dataset-actions .left:not(:empty){margin-bottom:8px} -.dataset .dataset-body .dataset-actions .right{float:right}.dataset .dataset-body .dataset-actions .right .icon-btn{margin-left:2px} -.dataset .dataset-body .tags-display{display:none;margin-bottom:8px}.dataset .dataset-body .tags-display .select2-container{min-width:0px}.dataset .dataset-body .tags-display .select2-container .select2-choices{border-radius:3px} -.dataset .dataset-body .annotation-display{display:none;margin-bottom:8px}.dataset .dataset-body .annotation-display .annotation{border-radius:3px;border:1px solid rgba(153,153,153,0.30000000000000004);padding:4px;white-space:pre-line} -.dataset .dataset-body .annotation-display .annotation:empty{height:22px} -.dataset .dataset-body .annotation-display .annotation:empty:after{position:relative;top:-4px;font-size:10px;font-style:italic;color:grey;content:'Click here to edit annotation'} -.dataset .dataset-body .annotation-display textarea{margin:0px 0px 2px 0px;display:block;border-radius:3px;width:100%} -.dataset .dataset-body .dataset-display-applications .display-application:last-child{margin-bottom:8px} -.dataset .dataset-body .dataset-peek{margin-bottom:8px}.dataset .dataset-body .dataset-peek pre.peek{width:100%;margin:0px;border-radius:3px;background:white;color:black;font-size:10px;overflow:auto}.dataset .dataset-body .dataset-peek pre.peek th{color:white;background:#5f6990} -.dataset .dataset-body .dataset-peek pre.peek table,.dataset .dataset-body .dataset-peek pre.peek th,.dataset .dataset-body .dataset-peek pre.peek tr,.dataset .dataset-body .dataset-peek pre.peek td{font-family:Monaco,Menlo,Consolas,"Courier New",monospace;font-size:10px} -.dataset .icon-btn-group{display:inline-block}.dataset .icon-btn-group .icon-btn:not(:last-child){margin:0px;border-radius:0px;border-right:none} -.dataset .icon-btn-group .icon-btn:first-child{margin-right:0px;border-top-left-radius:3px;border-bottom-left-radius:3px} -.dataset .icon-btn-group .icon-btn:last-child{margin-left:0px;border-radius:0px 3px 3px 0px} -.dataset .state-icon{font-family:FontAwesome;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;display:inline-block;vertical-align:middle;width:16px;height:16px;line-height:16px;text-align:center;font-size:16px} +.dataset.hda{border:1px solid #bfbfbf}.dataset.hda .vertical-spacing{margin-bottom:8px} +.dataset.hda .info-section{border-radius:3px;border:1px solid rgba(153,153,153,0.30000000000000004);padding:4px} +.dataset.hda .dataset-padding{padding:6px 10px 6px 8px} +.dataset.hda [class$=messagesmall]{margin:6px 10px 2px 8px;font-size:90%} +.dataset.hda .help-text{font-weight:normal;color:#555} +.dataset.hda .dataset-selector{float:left;display:none;width:0px;margin:0 0 -6px 0;padding:5px 0 2px 8px;cursor:pointer;vertical-align:middle} +.dataset.hda .dataset-title-bar{cursor:pointer;outline:none;padding:6px 10px 6px 8px} +.dataset.hda .dataset-title-bar .dataset-title{display:inline;font-weight:bold;text-decoration:underline;word-wrap:break-word;word-break:break-all;line-height:16px} +.dataset.hda .dataset-primary-actions{display:inline-block;float:right;margin:6px 10px 0}.dataset.hda .dataset-primary-actions .icon-btn:not(:last-child){margin:0px;border-radius:0px;border-right:none} +.dataset.hda .dataset-primary-actions .icon-btn:first-child{margin-right:0px;border-top-left-radius:3px;border-bottom-left-radius:3px} +.dataset.hda .dataset-primary-actions .icon-btn:last-child{margin-left:0px;border-radius:0px 3px 3px 0px} +.dataset.hda .dataset-primary-actions .icon-btn{margin-left:2px} +.dataset.hda .dataset-body{display:none;padding:6px 10px 6px 8px}.dataset.hda .dataset-body [class$=messagesmall]{margin:0px 0px 8px 0px} +.dataset.hda .dataset-body label{margin:0px;padding:0px;font-weight:normal} +.dataset.hda .dataset-body .prompt{font-weight:normal;color:#555} +.dataset.hda .dataset-body .prompt:after{content:':'} +.dataset.hda .dataset-body .dataset-summary{margin-bottom:8px}.dataset.hda .dataset-body .dataset-summary .dataset-blurb{margin-bottom:2px} +.dataset.hda .dataset-body .dataset-summary .dataset-datatype,.dataset.hda .dataset-body .dataset-summary .dataset-dbkey{display:inline}.dataset.hda .dataset-body .dataset-summary .dataset-datatype .value,.dataset.hda .dataset-body .dataset-summary .dataset-dbkey .value{font-weight:bold} +.dataset.hda .dataset-body .dataset-summary .dataset-datatype .value:after{content:',';font-weight:normal;color:#555} +.dataset.hda .dataset-body .dataset-summary .dataset-dbkey:after{content:' ';display:block;margin-bottom:8px} +.dataset.hda .dataset-body .dataset-summary .dataset-info{border-radius:3px;border:1px solid rgba(153,153,153,0.30000000000000004);padding:4px}.dataset.hda .dataset-body .dataset-summary .dataset-info .value{white-space:pre-line} +.dataset.hda .dataset-body .dataset-summary .job-error-text{border-radius:3px;border:1px solid rgba(153,153,153,0.30000000000000004);padding:4px;overflow:auto;white-space:pre} +.dataset.hda .dataset-body .dataset-actions .left{display:inline-block;float:left}.dataset.hda .dataset-body .dataset-actions .left .icon-btn:not(:last-child){margin:0px;border-radius:0px;border-right:none} +.dataset.hda .dataset-body .dataset-actions .left .icon-btn:first-child{margin-right:0px;border-top-left-radius:3px;border-bottom-left-radius:3px} +.dataset.hda .dataset-body .dataset-actions .left .icon-btn:last-child{margin-left:0px;border-radius:0px 3px 3px 0px} +.dataset.hda .dataset-body .dataset-actions .left .icon-btn{margin-right:2px} +.dataset.hda .dataset-body .dataset-actions .left:not(:empty){margin-bottom:8px} +.dataset.hda .dataset-body .dataset-actions .right{float:right}.dataset.hda .dataset-body .dataset-actions .right .icon-btn{margin-left:2px} +.dataset.hda .dataset-body .tags-display{display:none;margin-bottom:8px}.dataset.hda .dataset-body .tags-display .select2-container{min-width:0px}.dataset.hda .dataset-body .tags-display .select2-container .select2-choices{border-radius:3px} +.dataset.hda .dataset-body .annotation-display{display:none;margin-bottom:8px}.dataset.hda .dataset-body .annotation-display .annotation{border-radius:3px;border:1px solid rgba(153,153,153,0.30000000000000004);padding:4px;white-space:pre-line} +.dataset.hda .dataset-body .annotation-display .annotation:empty{height:22px} +.dataset.hda .dataset-body .annotation-display .annotation:empty:after{position:relative;top:-4px;font-size:10px;font-style:italic;color:grey;content:'Click here to edit annotation'} +.dataset.hda .dataset-body .annotation-display textarea{margin:0px 0px 2px 0px;display:block;border-radius:3px;width:100%} +.dataset.hda .dataset-body .dataset-display-applications .display-application:last-child{margin-bottom:8px} +.dataset.hda .dataset-body .dataset-peek{margin-bottom:8px}.dataset.hda .dataset-body .dataset-peek pre.peek{width:100%;margin:0px;border-radius:3px;background:white;color:black;font-size:10px;overflow:auto}.dataset.hda .dataset-body .dataset-peek pre.peek th{color:white;background:#5f6990} +.dataset.hda .dataset-body .dataset-peek pre.peek table,.dataset.hda .dataset-body .dataset-peek pre.peek th,.dataset.hda .dataset-body .dataset-peek pre.peek tr,.dataset.hda .dataset-body .dataset-peek pre.peek td{font-family:Monaco,Menlo,Consolas,"Courier New",monospace;font-size:10px} +.dataset.hda .icon-btn-group{display:inline-block}.dataset.hda .icon-btn-group .icon-btn:not(:last-child){margin:0px;border-radius:0px;border-right:none} +.dataset.hda .icon-btn-group .icon-btn:first-child{margin-right:0px;border-top-left-radius:3px;border-bottom-left-radius:3px} +.dataset.hda .icon-btn-group .icon-btn:last-child{margin-left:0px;border-radius:0px 3px 3px 0px} +.dataset.hda .state-icon{font-family:FontAwesome;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;display:inline-block;vertical-align:middle;width:16px;height:16px;line-height:16px;text-align:center;font-size:16px} .state-icon-error{background-color:white;border-radius:8px}.state-icon-error:before{font-size:20px;line-height:16px;color:red;content:"\f057"} .state-icon-running{-webkit-animation:spin 2s infinite linear;-moz-animation:spin 2s infinite linear;-o-animation:spin 2s infinite linear;animation:spin 2s infinite linear}@-moz-keyframes spin{0%{-moz-transform:rotate(0deg)} 100%{-moz-transform:rotate(359deg)}}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0deg)} 100%{-webkit-transform:rotate(359deg)}}@-o-keyframes spin{0%{-o-transform:rotate(0deg)} 100%{-o-transform:rotate(359deg)}}@-ms-keyframes spin{0%{-ms-transform:rotate(0deg)} 100%{-ms-transform:rotate(359deg)}}@keyframes spin{0%{transform:rotate(0deg)} 100%{transform:rotate(359deg)}}.state-icon-running:before{content:"\f110"} .state-icon-upload{overflow:hidden}.state-icon-upload:before{display:inline-block;-webkit-animation:eclipse 2s infinite linear;-moz-animation:eclipse 2s infinite linear;-o-animation:eclipse 2s infinite linear;animation:eclipse 2s infinite linear;content:"\f062"}@-moz-keyframes eclipse{0%{-moz-transform:translate(0, 16px)} 100%{-moz-transform:translate(0, -16px)}}@-webkit-keyframes eclipse{0%{-webkit-transform:translate(0, 16px)} 100%{-webkit-transform:translate(0, -16px)}}@-o-keyframes eclipse{0%{-o-transform:translate(0, 16px)} 100%{-o-transform:translate(0, -16px)}}@-ms-keyframes eclipse{0%{-ms-transform:translate(0, 16px)} 100%{-ms-transform:translate(0, -16px)}}@keyframes eclipse{0%{transform:translate(0, 16px)} 100%{transform:translate(0, -16px)}} diff -r c98072c51cf05de686c631739a5deb18c15734bf -r 90b76033686b5c363bca32edf7f6c292a1d0d080 static/style/src/less/history.less --- a/static/style/src/less/history.less +++ b/static/style/src/less/history.less @@ -269,7 +269,7 @@ } // ---------------------------------------------------------------------------- datasets -.dataset { +.dataset.hda { border: 1px solid @border-default-color; // body mixins @@ -512,7 +512,7 @@ } -.dataset .state-icon { +.dataset.hda .state-icon { .fa-icon; display: inline-block; vertical-align: middle; diff -r c98072c51cf05de686c631739a5deb18c15734bf -r 90b76033686b5c363bca32edf7f6c292a1d0d080 templates/webapps/galaxy/dataset/embed.mako --- a/templates/webapps/galaxy/dataset/embed.mako +++ b/templates/webapps/galaxy/dataset/embed.mako @@ -4,10 +4,10 @@ %><%def name="render_item_links( dataset )"> - <a href="${h.url_for( controller='/dataset', action='display', dataset_id=trans.security.encode_id( dataset.id ), to_ext=dataset.ext )}" title="Save dataset" class="icon-button disk tooltip"></a> + <a href="${h.url_for( controller='/dataset', action='display', dataset_id=trans.security.encode_id( dataset.id ), to_ext=dataset.ext )}" title="Save dataset" class="icon-button disk"></a> ## Links for importing and viewing an item. - <a href="${h.url_for( controller='/dataset', action='imp', dataset_id=trans.security.encode_id( item.id ) )}" title="Import dataset" class="icon-button import tooltip"></a> - <a class="icon-button go-to-full-screen tooltip" href="${h.url_for( controller='/dataset', action='display_by_username_and_slug', username=dataset.history.user.username, slug=trans.security.encode_id( dataset.id ) )}" title="Go to dataset"></a> + <a href="${h.url_for( controller='/dataset', action='imp', dataset_id=trans.security.encode_id( item.id ) )}" title="Import dataset" class="icon-button import"></a> + <a class="icon-button go-to-full-screen" href="${h.url_for( controller='/dataset', action='display_by_username_and_slug', username=dataset.history.user.username, slug=trans.security.encode_id( dataset.id ) )}" title="Go to dataset"></a></%def> https://bitbucket.org/galaxy/galaxy-central/commits/d557d5dd942f/ Changeset: d557d5dd942f Branch: next-stable User: jeremy goecks Date: 2014-02-05 22:24:21 Summary: Automated merge. Affected #: 4 files diff -r 2b8e4f343a9abe4e936afec8a3d99bf8d9a01ef0 -r d557d5dd942f5bbf820e19ec3fe7278401489555 static/scripts/packed/viz/circster.js --- a/static/scripts/packed/viz/circster.js +++ b/static/scripts/packed/viz/circster.js @@ -1,1 +1,1 @@ -define(["utils/utils","libs/underscore","libs/d3","viz/visualization"],function(g,h,m,j){g.cssLoadFile("static/style/circster.css");var n=Backbone.Model.extend({is_visible:function(r,o){var p=r.getBoundingClientRect(),q=$("svg")[0].getBoundingClientRect();if(p.right<0||p.left>q.right||p.bottom<0||p.top>q.bottom){return false}return true}});var i={drawTicks:function(s,r,w,q,o){var v=s.append("g").selectAll("g").data(r).enter().append("g").selectAll("g").data(w).enter().append("g").attr("class","tick").attr("transform",function(x){return"rotate("+(x.angle*180/Math.PI-90)+")translate("+x.radius+",0)"});var u=[],t=[],p=function(x){return x.angle>Math.PI?"end":null};if(o){u=[0,0,0,-4];t=[4,0,"",".35em"];p=null}else{u=[1,0,4,0];t=[0,4,".35em",""]}v.append("line").attr("x1",u[0]).attr("y1",u[1]).attr("x2",u[2]).attr("y1",u[3]).style("stroke","#000");v.append("text").attr("x",t[0]).attr("y",t[1]).attr("dx",t[2]).attr("dy",t[3]).attr("text-anchor",p).attr("transform",q).text(function(x){return x.label})},formatNum:function(p,o){if(o===undefined){o=2}if(p===null){return null}var r=null;if(p<1){r=p.toPrecision(o)}else{var q=Math.round(p.toPrecision(o));if(p<1000){r=q}else{if(p<1000000){r=Math.round((q/1000).toPrecision(3)).toFixed(0)+"K"}else{if(p<1000000000){r=Math.round((q/1000000).toPrecision(3)).toFixed(0)+"M"}}}}return r}};var c=Backbone.Model.extend({});var a=Backbone.View.extend({className:"circster",initialize:function(o){this.total_gap=o.total_gap;this.genome=o.genome;this.dataset_arc_height=o.dataset_arc_height;this.track_gap=10;this.label_arc_height=50;this.scale=1;this.circular_views=null;this.chords_views=null;this.model.get("tracks").on("add",this.add_track,this);this.model.get("tracks").on("remove",this.remove_track,this);this.get_circular_tracks()},get_circular_tracks:function(){return this.model.get("tracks").filter(function(o){return o.get("track_type")!=="DiagonalHeatmapTrack"})},get_chord_tracks:function(){return this.model.get("tracks").filter(function(o){return o.get("track_type")==="DiagonalHeatmapTrack"})},get_tracks_bounds:function(){var p=this.get_circular_tracks();dataset_arc_height=this.dataset_arc_height,min_dimension=Math.min(this.$el.width(),this.$el.height()),radius_start=min_dimension/2-p.length*(this.dataset_arc_height+this.track_gap)-(this.label_arc_height+this.track_gap),tracks_start_radii=m.range(radius_start,min_dimension/2,this.dataset_arc_height+this.track_gap);var o=this;return h.map(tracks_start_radii,function(q){return[q,q+o.dataset_arc_height]})},render:function(){var x=this,r=this.dataset_arc_height,o=x.$el.width(),w=x.$el.height(),t=this.get_circular_tracks(),q=this.get_chord_tracks(),s=this.get_tracks_bounds(),p=m.select(x.$el[0]).append("svg").attr("width",o).attr("height",w).attr("pointer-events","all").append("svg:g").call(m.behavior.zoom().on("zoom",function(){var y=m.event.scale;p.attr("transform","translate("+m.event.translate+") scale("+y+")");if(x.scale!==y){if(x.zoom_drag_timeout){clearTimeout(x.zoom_drag_timeout)}x.zoom_drag_timeout=setTimeout(function(){},400)}})).attr("transform","translate("+o/2+","+w/2+")").append("svg:g").attr("class","tracks");this.circular_views=t.map(function(z,A){var y=new d({el:p.append("g")[0],track:z,radius_bounds:s[A],genome:x.genome,total_gap:x.total_gap});y.render();return y});this.chords_views=q.map(function(z){var y=new k({el:p.append("g")[0],track:z,radius_bounds:s[0],genome:x.genome,total_gap:x.total_gap});y.render();return y});var v=this.circular_views[this.circular_views.length-1].radius_bounds[1],u=[v,v+this.label_arc_height];this.label_track_view=new b({el:p.append("g")[0],track:new c(),radius_bounds:u,genome:x.genome,total_gap:x.total_gap});this.label_track_view.render()},add_track:function(u){if(u.get("track_type")==="DiagonalHeatmapTrack"){var q=this.circular_views[0].radius_bounds,t=new k({el:m.select("g.tracks").append("g")[0],track:u,radius_bounds:q,genome:this.genome,total_gap:this.total_gap});t.render();this.chords_views.push(t)}else{var s=this.get_tracks_bounds();h.each(this.circular_views,function(v,w){v.update_radius_bounds(s[w])});h.each(this.chords_views,function(v){v.update_radius_bounds(s[0])});var r=this.circular_views.length,o=new d({el:m.select("g.tracks").append("g")[0],track:u,radius_bounds:s[r],genome:this.genome,total_gap:this.total_gap});o.render();this.circular_views.push(o);var p=s[s.length-1];p[1]=p[0];this.label_track_view.update_radius_bounds(p)}},remove_track:function(p,r,q){var o=this.circular_views[q.index];this.circular_views.splice(q.index,1);o.$el.remove();var s=this.get_tracks_bounds();h.each(this.circular_views,function(t,u){t.update_radius_bounds(s[u])})}});var l=Backbone.View.extend({tagName:"g",initialize:function(o){this.bg_stroke="ccc";this.loading_bg_fill="000";this.bg_fill="ccc";this.total_gap=o.total_gap;this.track=o.track;this.radius_bounds=o.radius_bounds;this.genome=o.genome;this.chroms_layout=this._chroms_layout();this.data_bounds=[];this.scale=1;this.parent_elt=m.select(this.$el[0])},get_fill_color:function(){var o=this.track.get("config").get_value("block_color");if(!o){o=this.track.get("config").get_value("color")}return o},render:function(){var s=this.parent_elt;if(!s){console.log("no parent elt")}var r=this.chroms_layout,u=m.svg.arc().innerRadius(this.radius_bounds[0]).outerRadius(this.radius_bounds[1]),o=s.selectAll("g").data(r).enter().append("svg:g"),q=o.append("path").attr("d",u).attr("class","chrom-background").style("stroke",this.bg_stroke).style("fill",this.loading_bg_fill);q.append("title").text(function(w){return w.data.chrom});var p=this,t=p.track.get("data_manager"),v=(t?t.data_is_ready():true);$.when(v).then(function(){$.when(p._render_data(s)).then(function(){q.style("fill",p.bg_fill);p.render_labels()})})},render_labels:function(){},update_radius_bounds:function(p){this.radius_bounds=p;var o=m.svg.arc().innerRadius(this.radius_bounds[0]).outerRadius(this.radius_bounds[1]);this.parent_elt.selectAll("g>path.chrom-background").transition().duration(1000).attr("d",o);this._transition_chrom_data();this._transition_labels()},update_scale:function(r){var q=this.scale;this.scale=r;if(r<=q){return}var p=this,o=new n();this.parent_elt.selectAll("path.chrom-data").filter(function(t,s){return o.is_visible(this)}).each(function(y,u){var x=m.select(this),t=x.attr("chrom"),w=p.genome.get_chrom_region(t),v=p.track.get("data_manager"),s;if(!v.can_get_more_detailed_data(w)){return}s=p.track.get("data_manager").get_more_detailed_data(w,"Coverage",0,r);$.when(s).then(function(B){x.remove();p._update_data_bounds();var A=h.find(p.chroms_layout,function(C){return C.data.chrom===t});var z=p.get_fill_color();p._render_chrom_data(p.parent_elt,A,B).style("stroke",z).style("fill",z)})});return p},_transition_chrom_data:function(){var p=this.track,r=this.chroms_layout,o=this.parent_elt.selectAll("g>path.chrom-data"),s=o[0].length;if(s>0){var q=this;$.when(p.get("data_manager").get_genome_wide_data(this.genome)).then(function(u){var t=h.reject(h.map(u,function(v,w){var x=null,y=q._get_path_function(r[w],v);if(y){x=y(v.data)}return x}),function(v){return v===null});o.each(function(w,v){m.select(this).transition().duration(1000).attr("d",t[v])})})}},_transition_labels:function(){},_update_data_bounds:function(){var o=this.data_bounds;this.data_bounds=this.get_data_bounds(this.track.get("data_manager").get_genome_wide_data(this.genome));if(this.data_bounds[0]<o[0]||this.data_bounds[1]>o[1]){this._transition_chrom_data()}},_render_data:function(r){var q=this,p=this.chroms_layout,o=this.track,s=$.Deferred();$.when(o.get("data_manager").get_genome_wide_data(this.genome)).then(function(u){q.data_bounds=q.get_data_bounds(u);layout_and_data=h.zip(p,u),chroms_data_layout=h.map(layout_and_data,function(v){var w=v[0],x=v[1];return q._render_chrom_data(r,w,x)});var t=q.get_fill_color();q.parent_elt.selectAll("path.chrom-data").style("stroke",t).style("fill",t);s.resolve(r)});return s},_render_chrom_data:function(o,p,q){},_get_path_function:function(p,o){},_chroms_layout:function(){var p=this.genome.get_chroms_info(),r=m.layout.pie().value(function(t){return t.len}).sort(null),s=r(p),o=this.total_gap/p.length,q=h.map(s,function(v,u){var t=v.endAngle-o;v.endAngle=(t>v.startAngle?t:v.startAngle);return v});return q}});var b=l.extend({initialize:function(o){l.prototype.initialize.call(this,o);this.innerRadius=this.radius_bounds[0];this.radius_bounds[0]=this.radius_bounds[1];this.bg_stroke="fff";this.bg_fill="fff";this.min_arc_len=0.05},_render_data:function(q){var p=this,o=q.selectAll("g");o.selectAll("path").attr("id",function(u){return"label-"+u.data.chrom});o.append("svg:text").filter(function(u){return u.endAngle-u.startAngle>p.min_arc_len}).attr("text-anchor","middle").append("svg:textPath").attr("class","chrom-label").attr("xlink:href",function(u){return"#label-"+u.data.chrom}).attr("startOffset","25%").text(function(u){return u.data.chrom});var r=function(w){var u=(w.endAngle-w.startAngle)/w.value,v=m.range(0,w.value,25000000).map(function(x,y){return{radius:p.innerRadius,angle:x*u+w.startAngle,label:y===0?0:(y%3?null:p.formatNum(x))}});if(v.length<4){v[v.length-1].label=p.formatNum(Math.round((v[v.length-1].angle-w.startAngle)/u))}return v};var t=function(u){return u.angle>Math.PI?"rotate(180)translate(-16)":null};var s=h.filter(this.chroms_layout,function(u){return u.endAngle-u.startAngle>p.min_arc_len});this.drawTicks(this.parent_elt,s,r,t)}});h.extend(b.prototype,i);var f=l.extend({_quantile:function(p,o){p.sort(m.ascending);return m.quantile(p,o)},_render_chrom_data:function(o,r,p){var s=this._get_path_function(r,p);if(!s){return null}var q=o.datum(p.data),t=q.append("path").attr("class","chrom-data").attr("chrom",r.data.chrom).attr("d",s);return t},_get_path_function:function(r,q){if(typeof q==="string"||!q.data||q.data.length===0){return null}var o=m.scale.linear().domain(this.data_bounds).range(this.radius_bounds).clamp(true);var s=m.scale.linear().domain([0,q.data.length]).range([r.startAngle,r.endAngle]);var p=m.svg.line.radial().interpolate("linear").radius(function(t){return o(t[1])}).angle(function(u,t){return s(t)});return m.svg.area.radial().interpolate(p.interpolate()).innerRadius(o(0)).outerRadius(p.radius()).angle(p.angle())},render_labels:function(){var o=this,p=function(){return"rotate(90)"};this.drawTicks(this.parent_elt,[this.chroms_layout[0]],this._data_bounds_ticks_fn(),p,true)},_transition_labels:function(){if(this.data_bounds.length===0){return}var p=this,r=h.filter(this.chroms_layout,function(s){return s.endAngle-s.startAngle>0.08}),q=h.filter(r,function(t,s){return s%3===0}),o=h.flatten(h.map(q,function(s){return p._data_bounds_ticks_fn()(s)}));this.parent_elt.selectAll("g.tick").data(o).transition().attr("transform",function(s){return"rotate("+(s.angle*180/Math.PI-90)+")translate("+s.radius+",0)"})},_data_bounds_ticks_fn:function(){var o=this;visibleChroms=0;return function(p){return[{radius:o.radius_bounds[0],angle:p.startAngle,label:o.formatNum(o.data_bounds[0])},{radius:o.radius_bounds[1],angle:p.startAngle,label:o.formatNum(o.data_bounds[1])}]}},get_data_bounds:function(o){}});h.extend(f.prototype,i);var d=f.extend({get_data_bounds:function(p){var o=h.flatten(h.map(p,function(q){if(q){return h.map(q.data,function(r){return parseInt(r[1],10)||0})}else{return 0}}));return[h.min(o),this._quantile(o,0.98)||h.max(o)]}});var k=l.extend({render:function(){var o=this;$.when(o.track.get("data_manager").data_is_ready()).then(function(){$.when(o.track.get("data_manager").get_genome_wide_data(o.genome)).then(function(r){var q=[],p=o.genome.get_chroms_info();h.each(r,function(v,u){var s=p[u].chrom;var t=h.map(v.data,function(x){var w=o._get_region_angle(s,x[1]),y=o._get_region_angle(x[3],x[4]);return{source:{startAngle:w,endAngle:w+0.01},target:{startAngle:y,endAngle:y+0.01}}});q=q.concat(t)});o.parent_elt.append("g").attr("class","chord").selectAll("path").data(q).enter().append("path").style("fill",o.get_fill_color()).attr("d",m.svg.chord().radius(o.radius_bounds[0])).style("opacity",1)})})},update_radius_bounds:function(o){this.radius_bounds=o;this.parent_elt.selectAll("path").transition().attr("d",m.svg.chord().radius(this.radius_bounds[0]))},_get_region_angle:function(q,o){var p=h.find(this.chroms_layout,function(r){return r.data.chrom===q});return p.endAngle-((p.endAngle-p.startAngle)*(p.data.len-o)/p.data.len)}});var e=Backbone.View.extend({initialize:function(){var o=new j.Genome(galaxy_config.app.genome),p=new j.GenomeVisualization(galaxy_config.app.viz_config),r=new a({el:$("#center .unified-panel-body"),total_gap:2*Math.PI*0.4,genome:o,model:p,dataset_arc_height:25});r.render();$("#center .unified-panel-header-inner").append(galaxy_config.app.viz_config.title+" "+galaxy_config.app.viz_config.dbkey);var q=create_icon_buttons_menu([{icon_class:"plus-button",title:"Add tracks",on_click:function(){j.select_datasets(galaxy_config.root+"visualization/list_current_history_datasets",galaxy_config.root+"api/datasets",p.get("dbkey"),function(s){p.add_tracks(s)})}},{icon_class:"disk--arrow",title:"Save",on_click:function(){Galaxy.modal.show({title:"Saving...",body:"progress"});var s=galaxy_config.app.viz_config;$.ajax({url:galaxy_config.root+"visualization/save",type:"POST",dataType:"json",data:{id:s.vis_id,title:s.title,dbkey:s.dbkey,type:"trackster",vis_json:JSON.stringify(s)}}).success(function(t){Galaxy.modal.hide();s.vis_id=t.vis_id;s.has_changes=false;window.history.pushState({},"",t.url+window.location.hash)}).error(function(){Galaxy.modal.show({title:"Could Not Save",body:"Could not save visualization. Please try again later.",buttons:{Cancel:function(){Galaxy.modal.hide()}}})})}},{icon_class:"cross-circle",title:"Close",on_click:function(){window.location=galaxy_config.root+"visualization/list"}}],{tooltip_config:{placement:"bottom"}});q.$el.attr("style","float: right");$("#center .unified-panel-header-inner").append(q.$el);$(".menu-button").tooltip({placement:"bottom"})}});return{GalaxyApp:e}}); \ No newline at end of file +define(["utils/utils","libs/underscore","libs/d3","viz/visualization"],function(g,h,m,j){g.cssLoadFile("static/style/circster.css");var n=Backbone.Model.extend({is_visible:function(r,o){var p=r.getBoundingClientRect(),q=$("svg")[0].getBoundingClientRect();if(p.right<0||p.left>q.right||p.bottom<0||p.top>q.bottom){return false}return true}});var i={drawTicks:function(s,r,w,q,o){var v=s.append("g").selectAll("g").data(r).enter().append("g").selectAll("g").data(w).enter().append("g").attr("class","tick").attr("transform",function(x){return"rotate("+(x.angle*180/Math.PI-90)+")translate("+x.radius+",0)"});var u=[],t=[],p=function(x){return x.angle>Math.PI?"end":null};if(o){u=[0,0,0,-4];t=[4,0,"",".35em"];p=null}else{u=[1,0,4,0];t=[0,4,".35em",""]}v.append("line").attr("x1",u[0]).attr("y1",u[1]).attr("x2",u[2]).attr("y1",u[3]).style("stroke","#000");v.append("text").attr("x",t[0]).attr("y",t[1]).attr("dx",t[2]).attr("dy",t[3]).attr("text-anchor",p).attr("transform",q).text(function(x){return x.label})},formatNum:function(p,o){if(o===undefined){o=2}if(p===null){return null}var r=null;if(p<1){r=p.toPrecision(o)}else{var q=Math.round(p.toPrecision(o));if(p<1000){r=q}else{if(p<1000000){r=Math.round((q/1000).toPrecision(3)).toFixed(0)+"K"}else{if(p<1000000000){r=Math.round((q/1000000).toPrecision(3)).toFixed(0)+"M"}}}}return r}};var c=Backbone.Model.extend({});var a=Backbone.View.extend({className:"circster",initialize:function(o){this.total_gap=o.total_gap;this.genome=o.genome;this.dataset_arc_height=o.dataset_arc_height;this.track_gap=10;this.label_arc_height=50;this.scale=1;this.circular_views=null;this.chords_views=null;this.model.get("drawables").on("add",this.add_track,this);this.model.get("drawables").on("remove",this.remove_track,this);this.get_circular_tracks()},get_circular_tracks:function(){return this.model.get("drawables").filter(function(o){return o.get("track_type")!=="DiagonalHeatmapTrack"})},get_chord_tracks:function(){return this.model.get("drawables").filter(function(o){return o.get("track_type")==="DiagonalHeatmapTrack"})},get_tracks_bounds:function(){var p=this.get_circular_tracks();dataset_arc_height=this.dataset_arc_height,min_dimension=Math.min(this.$el.width(),this.$el.height()),radius_start=min_dimension/2-p.length*(this.dataset_arc_height+this.track_gap)-(this.label_arc_height+this.track_gap),tracks_start_radii=m.range(radius_start,min_dimension/2,this.dataset_arc_height+this.track_gap);var o=this;return h.map(tracks_start_radii,function(q){return[q,q+o.dataset_arc_height]})},render:function(){var x=this,r=this.dataset_arc_height,o=x.$el.width(),w=x.$el.height(),t=this.get_circular_tracks(),q=this.get_chord_tracks(),s=this.get_tracks_bounds(),p=m.select(x.$el[0]).append("svg").attr("width",o).attr("height",w).attr("pointer-events","all").append("svg:g").call(m.behavior.zoom().on("zoom",function(){var y=m.event.scale;p.attr("transform","translate("+m.event.translate+") scale("+y+")");if(x.scale!==y){if(x.zoom_drag_timeout){clearTimeout(x.zoom_drag_timeout)}x.zoom_drag_timeout=setTimeout(function(){},400)}})).attr("transform","translate("+o/2+","+w/2+")").append("svg:g").attr("class","tracks");this.circular_views=t.map(function(z,A){var y=new d({el:p.append("g")[0],track:z,radius_bounds:s[A],genome:x.genome,total_gap:x.total_gap});y.render();return y});this.chords_views=q.map(function(z){var y=new k({el:p.append("g")[0],track:z,radius_bounds:s[0],genome:x.genome,total_gap:x.total_gap});y.render();return y});var v=this.circular_views[this.circular_views.length-1].radius_bounds[1],u=[v,v+this.label_arc_height];this.label_track_view=new b({el:p.append("g")[0],track:new c(),radius_bounds:u,genome:x.genome,total_gap:x.total_gap});this.label_track_view.render()},add_track:function(u){if(u.get("track_type")==="DiagonalHeatmapTrack"){var q=this.circular_views[0].radius_bounds,t=new k({el:m.select("g.tracks").append("g")[0],track:u,radius_bounds:q,genome:this.genome,total_gap:this.total_gap});t.render();this.chords_views.push(t)}else{var s=this.get_tracks_bounds();h.each(this.circular_views,function(v,w){v.update_radius_bounds(s[w])});h.each(this.chords_views,function(v){v.update_radius_bounds(s[0])});var r=this.circular_views.length,o=new d({el:m.select("g.tracks").append("g")[0],track:u,radius_bounds:s[r],genome:this.genome,total_gap:this.total_gap});o.render();this.circular_views.push(o);var p=s[s.length-1];p[1]=p[0];this.label_track_view.update_radius_bounds(p)}},remove_track:function(p,r,q){var o=this.circular_views[q.index];this.circular_views.splice(q.index,1);o.$el.remove();var s=this.get_tracks_bounds();h.each(this.circular_views,function(t,u){t.update_radius_bounds(s[u])})}});var l=Backbone.View.extend({tagName:"g",initialize:function(o){this.bg_stroke="ccc";this.loading_bg_fill="000";this.bg_fill="ccc";this.total_gap=o.total_gap;this.track=o.track;this.radius_bounds=o.radius_bounds;this.genome=o.genome;this.chroms_layout=this._chroms_layout();this.data_bounds=[];this.scale=1;this.parent_elt=m.select(this.$el[0])},get_fill_color:function(){var o=this.track.get("config").get_value("block_color");if(!o){o=this.track.get("config").get_value("color")}return o},render:function(){var s=this.parent_elt;if(!s){console.log("no parent elt")}var r=this.chroms_layout,u=m.svg.arc().innerRadius(this.radius_bounds[0]).outerRadius(this.radius_bounds[1]),o=s.selectAll("g").data(r).enter().append("svg:g"),q=o.append("path").attr("d",u).attr("class","chrom-background").style("stroke",this.bg_stroke).style("fill",this.loading_bg_fill);q.append("title").text(function(w){return w.data.chrom});var p=this,t=p.track.get("data_manager"),v=(t?t.data_is_ready():true);$.when(v).then(function(){$.when(p._render_data(s)).then(function(){q.style("fill",p.bg_fill);p.render_labels()})})},render_labels:function(){},update_radius_bounds:function(p){this.radius_bounds=p;var o=m.svg.arc().innerRadius(this.radius_bounds[0]).outerRadius(this.radius_bounds[1]);this.parent_elt.selectAll("g>path.chrom-background").transition().duration(1000).attr("d",o);this._transition_chrom_data();this._transition_labels()},update_scale:function(r){var q=this.scale;this.scale=r;if(r<=q){return}var p=this,o=new n();this.parent_elt.selectAll("path.chrom-data").filter(function(t,s){return o.is_visible(this)}).each(function(y,u){var x=m.select(this),t=x.attr("chrom"),w=p.genome.get_chrom_region(t),v=p.track.get("data_manager"),s;if(!v.can_get_more_detailed_data(w)){return}s=p.track.get("data_manager").get_more_detailed_data(w,"Coverage",0,r);$.when(s).then(function(B){x.remove();p._update_data_bounds();var A=h.find(p.chroms_layout,function(C){return C.data.chrom===t});var z=p.get_fill_color();p._render_chrom_data(p.parent_elt,A,B).style("stroke",z).style("fill",z)})});return p},_transition_chrom_data:function(){var p=this.track,r=this.chroms_layout,o=this.parent_elt.selectAll("g>path.chrom-data"),s=o[0].length;if(s>0){var q=this;$.when(p.get("data_manager").get_genome_wide_data(this.genome)).then(function(u){var t=h.reject(h.map(u,function(v,w){var x=null,y=q._get_path_function(r[w],v);if(y){x=y(v.data)}return x}),function(v){return v===null});o.each(function(w,v){m.select(this).transition().duration(1000).attr("d",t[v])})})}},_transition_labels:function(){},_update_data_bounds:function(){var o=this.data_bounds;this.data_bounds=this.get_data_bounds(this.track.get("data_manager").get_genome_wide_data(this.genome));if(this.data_bounds[0]<o[0]||this.data_bounds[1]>o[1]){this._transition_chrom_data()}},_render_data:function(r){var q=this,p=this.chroms_layout,o=this.track,s=$.Deferred();$.when(o.get("data_manager").get_genome_wide_data(this.genome)).then(function(u){q.data_bounds=q.get_data_bounds(u);layout_and_data=h.zip(p,u),chroms_data_layout=h.map(layout_and_data,function(v){var w=v[0],x=v[1];return q._render_chrom_data(r,w,x)});var t=q.get_fill_color();q.parent_elt.selectAll("path.chrom-data").style("stroke",t).style("fill",t);s.resolve(r)});return s},_render_chrom_data:function(o,p,q){},_get_path_function:function(p,o){},_chroms_layout:function(){var p=this.genome.get_chroms_info(),r=m.layout.pie().value(function(t){return t.len}).sort(null),s=r(p),o=this.total_gap/p.length,q=h.map(s,function(v,u){var t=v.endAngle-o;v.endAngle=(t>v.startAngle?t:v.startAngle);return v});return q}});var b=l.extend({initialize:function(o){l.prototype.initialize.call(this,o);this.innerRadius=this.radius_bounds[0];this.radius_bounds[0]=this.radius_bounds[1];this.bg_stroke="fff";this.bg_fill="fff";this.min_arc_len=0.05},_render_data:function(q){var p=this,o=q.selectAll("g");o.selectAll("path").attr("id",function(u){return"label-"+u.data.chrom});o.append("svg:text").filter(function(u){return u.endAngle-u.startAngle>p.min_arc_len}).attr("text-anchor","middle").append("svg:textPath").attr("class","chrom-label").attr("xlink:href",function(u){return"#label-"+u.data.chrom}).attr("startOffset","25%").text(function(u){return u.data.chrom});var r=function(w){var u=(w.endAngle-w.startAngle)/w.value,v=m.range(0,w.value,25000000).map(function(x,y){return{radius:p.innerRadius,angle:x*u+w.startAngle,label:y===0?0:(y%3?null:p.formatNum(x))}});if(v.length<4){v[v.length-1].label=p.formatNum(Math.round((v[v.length-1].angle-w.startAngle)/u))}return v};var t=function(u){return u.angle>Math.PI?"rotate(180)translate(-16)":null};var s=h.filter(this.chroms_layout,function(u){return u.endAngle-u.startAngle>p.min_arc_len});this.drawTicks(this.parent_elt,s,r,t)}});h.extend(b.prototype,i);var f=l.extend({_quantile:function(p,o){p.sort(m.ascending);return m.quantile(p,o)},_render_chrom_data:function(o,r,p){var s=this._get_path_function(r,p);if(!s){return null}var q=o.datum(p.data),t=q.append("path").attr("class","chrom-data").attr("chrom",r.data.chrom).attr("d",s);return t},_get_path_function:function(r,q){if(typeof q==="string"||!q.data||q.data.length===0){return null}var o=m.scale.linear().domain(this.data_bounds).range(this.radius_bounds).clamp(true);var s=m.scale.linear().domain([0,q.data.length]).range([r.startAngle,r.endAngle]);var p=m.svg.line.radial().interpolate("linear").radius(function(t){return o(t[1])}).angle(function(u,t){return s(t)});return m.svg.area.radial().interpolate(p.interpolate()).innerRadius(o(0)).outerRadius(p.radius()).angle(p.angle())},render_labels:function(){var o=this,p=function(){return"rotate(90)"};this.drawTicks(this.parent_elt,[this.chroms_layout[0]],this._data_bounds_ticks_fn(),p,true)},_transition_labels:function(){if(this.data_bounds.length===0){return}var p=this,r=h.filter(this.chroms_layout,function(s){return s.endAngle-s.startAngle>0.08}),q=h.filter(r,function(t,s){return s%3===0}),o=h.flatten(h.map(q,function(s){return p._data_bounds_ticks_fn()(s)}));this.parent_elt.selectAll("g.tick").data(o).transition().attr("transform",function(s){return"rotate("+(s.angle*180/Math.PI-90)+")translate("+s.radius+",0)"})},_data_bounds_ticks_fn:function(){var o=this;visibleChroms=0;return function(p){return[{radius:o.radius_bounds[0],angle:p.startAngle,label:o.formatNum(o.data_bounds[0])},{radius:o.radius_bounds[1],angle:p.startAngle,label:o.formatNum(o.data_bounds[1])}]}},get_data_bounds:function(o){}});h.extend(f.prototype,i);var d=f.extend({get_data_bounds:function(p){var o=h.flatten(h.map(p,function(q){if(q){return h.map(q.data,function(r){return parseInt(r[1],10)||0})}else{return 0}}));return[h.min(o),this._quantile(o,0.98)||h.max(o)]}});var k=l.extend({render:function(){var o=this;$.when(o.track.get("data_manager").data_is_ready()).then(function(){$.when(o.track.get("data_manager").get_genome_wide_data(o.genome)).then(function(r){var q=[],p=o.genome.get_chroms_info();h.each(r,function(v,u){var s=p[u].chrom;var t=h.map(v.data,function(x){var w=o._get_region_angle(s,x[1]),y=o._get_region_angle(x[3],x[4]);return{source:{startAngle:w,endAngle:w+0.01},target:{startAngle:y,endAngle:y+0.01}}});q=q.concat(t)});o.parent_elt.append("g").attr("class","chord").selectAll("path").data(q).enter().append("path").style("fill",o.get_fill_color()).attr("d",m.svg.chord().radius(o.radius_bounds[0])).style("opacity",1)})})},update_radius_bounds:function(o){this.radius_bounds=o;this.parent_elt.selectAll("path").transition().attr("d",m.svg.chord().radius(this.radius_bounds[0]))},_get_region_angle:function(q,o){var p=h.find(this.chroms_layout,function(r){return r.data.chrom===q});return p.endAngle-((p.endAngle-p.startAngle)*(p.data.len-o)/p.data.len)}});var e=Backbone.View.extend({initialize:function(){var o=new j.Genome(galaxy_config.app.genome),p=new j.GenomeVisualization(galaxy_config.app.viz_config),r=new a({el:$("#center .unified-panel-body"),total_gap:2*Math.PI*0.4,genome:o,model:p,dataset_arc_height:25});r.render();$("#center .unified-panel-header-inner").append(galaxy_config.app.viz_config.title+" "+galaxy_config.app.viz_config.dbkey);var q=create_icon_buttons_menu([{icon_class:"plus-button",title:"Add tracks",on_click:function(){j.select_datasets(galaxy_config.root+"visualization/list_current_history_datasets",galaxy_config.root+"api/datasets",p.get("dbkey"),function(s){p.add_tracks(s)})}},{icon_class:"disk--arrow",title:"Save",on_click:function(){Galaxy.modal.show({title:"Saving...",body:"progress"});$.ajax({url:galaxy_config.root+"visualization/save",type:"POST",dataType:"json",data:{id:p.get("vis_id"),title:p.get("title"),dbkey:p.get("dbkey"),type:"trackster",vis_json:JSON.stringify(p)}}).success(function(s){Galaxy.modal.hide();p.set("vis_id",s.vis_id)}).error(function(){Galaxy.modal.show({title:"Could Not Save",body:"Could not save visualization. Please try again later.",buttons:{Cancel:function(){Galaxy.modal.hide()}}})})}},{icon_class:"cross-circle",title:"Close",on_click:function(){window.location=galaxy_config.root+"visualization/list"}}],{tooltip_config:{placement:"bottom"}});q.$el.attr("style","float: right");$("#center .unified-panel-header-inner").append(q.$el);$(".menu-button").tooltip({placement:"bottom"})}});return{GalaxyApp:e}}); \ No newline at end of file diff -r 2b8e4f343a9abe4e936afec8a3d99bf8d9a01ef0 -r d557d5dd942f5bbf820e19ec3fe7278401489555 static/scripts/packed/viz/visualization.js --- a/static/scripts/packed/viz/visualization.js +++ b/static/scripts/packed/viz/visualization.js @@ -1,1 +1,1 @@ -define(["libs/underscore","mvc/data","viz/trackster/util","utils/config"],function(t,j,m,p){var a=function(v,y,x,w){$.ajax({url:v,data:x,error:function(){alert("Grid failed")},success:function(z){Galaxy.modal.show({title:"Select datasets for new tracks",body:z,buttons:{Cancel:function(){Galaxy.modal.hide()},Add:function(){var A=[];$("input[name=id]:checked,input[name=ldda_ids]:checked").each(function(){var B={data_type:"track_config",hda_ldda:"hda"},C=$(this).val();if($(this).attr("name")!=="id"){B.hda_ldda="ldda"}A[A.length]=$.ajax({url:y+"/"+C,data:B,dataType:"json"})});$.when.apply($,A).then(function(){var B=(arguments[0] instanceof Array?$.map(arguments,function(C){return C[0]}):[arguments[0]]);w(B)});Galaxy.modal.hide()}}})}})};var k=function(v){return("promise" in v)};var f=function(v){this.default_font=v!==undefined?v:"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")};t.extend(f.prototype,{load_pattern:function(v,z){var w=this.patterns,x=this.dummy_context,y=new Image();y.src=galaxy_config.root+"static/images"+z;y.onload=function(){w[v]=x.createPattern(y,"repeat")}},get_pattern:function(v){return this.patterns[v]},new_canvas:function(){var v=$("<canvas/>")[0];if(window.G_vmlCanvasManager){G_vmlCanvasManager.initElement(v)}v.manager=this;return v}});var r=Backbone.Model.extend({defaults:{num_elements:20,obj_cache:null,key_ary:null},initialize:function(v){this.clear()},get_elt:function(x){var y=this.attributes.obj_cache,z=this.attributes.key_ary,w=x.toString(),v=t.indexOf(z,function(A){return A.toString()===w});if(v!==-1){if(y[w].stale){z.splice(v,1);delete y[w]}else{this.move_key_to_end(x,v)}}return y[w]},set_elt:function(x,z){var A=this.attributes.obj_cache,B=this.attributes.key_ary,w=x.toString(),y=this.attributes.num_elements;if(!A[w]){if(B.length>=y){var v=B.shift();delete A[v.toString()]}B.push(x)}A[w]=z;return z},move_key_to_end:function(w,v){this.attributes.key_ary.splice(v,1);this.attributes.key_ary.push(w)},clear:function(){this.attributes.obj_cache={};this.attributes.key_ary=[]},size:function(){return this.attributes.key_ary.length},most_recently_added:function(){return this.size()===0?null:this.attributes.key_ary[this.attributes.key_ary.length-1]}});var d=r.extend({defaults:t.extend({},r.prototype.defaults,{dataset:null,genome:null,init_data:null,min_region_size:200,filters_manager:null,data_type:"data",data_mode_compatible:function(v,w){return true},can_subset:function(v){return false}}),initialize:function(v){r.prototype.initialize.call(this);var w=this.get("init_data");if(w){this.add_data(w)}},add_data:function(v){if(this.get("num_elements")<v.length){this.set("num_elements",v.length)}var w=this;t.each(v,function(x){w.set_data(x.region,x)})},data_is_ready:function(){var y=this.get("dataset"),x=$.Deferred(),v=(this.get("data_type")==="raw_data"?"state":this.get("data_type")==="data"?"converted_datasets_state":"error"),w=new m.ServerStateDeferred({ajax_settings:{url:this.get("dataset").url(),data:{hda_ldda:y.get("hda_ldda"),data_type:v},dataType:"json"},interval:5000,success_fn:function(z){return z!=="pending"}});$.when(w.go()).then(function(z){x.resolve(z==="ok"||z==="data")});return x},search_features:function(v){var w=this.get("dataset"),x={query:v,hda_ldda:w.get("hda_ldda"),data_type:"features"};return $.getJSON(w.url(),x)},load_data:function(D,C,w,B){var z=this.get("dataset"),y={data_type:this.get("data_type"),chrom:D.get("chrom"),low:D.get("start"),high:D.get("end"),mode:C,resolution:w,hda_ldda:z.get("hda_ldda")};$.extend(y,B);var F=this.get("filters_manager");if(F){var G=[];var v=F.filters;for(var A=0;A<v.length;A++){G.push(v[A].name)}y.filter_cols=JSON.stringify(G)}var x=this,E=$.getJSON(z.url(),y,function(H){H.region=D;x.set_data(D,H)});this.set_data(D,E);return E},get_data:function(C,B,x,z){var D=this.get_elt(C);if(D&&(k(D)||this.get("data_mode_compatible")(D,B))){return D}var E=this.get("key_ary"),v=this.get("obj_cache"),w,A;for(var y=0;y<E.length;y++){w=E[y];if(w.contains(C)){A=true;D=v[w.toString()];if(k(D)||(this.get("data_mode_compatible")(D,B)&&this.get("can_subset")(D))){this.move_key_to_end(w,y);if(!k(D)){var G=this.subset_entry(D,C);this.set(C,G);D=G}return D}}}if(!A&&C.length()<this.attributes.min_region_size){C=C.copy();var F=this.most_recently_added();if(!F||(C.get("start")>F.get("start"))){C.set("end",C.get("start")+this.attributes.min_region_size)}else{C.set("start",C.get("end")-this.attributes.min_region_size)}C.set("genome",this.attributes.genome);C.trim()}return this.load_data(C,B,x,z)},set_data:function(w,v){this.set_elt(w,v)},DEEP_DATA_REQ:"deep",BROAD_DATA_REQ:"breadth",get_more_data:function(D,C,y,B,z){var F=this._mark_stale(D);if(!(F&&this.get("data_mode_compatible")(F,C))){console.log("ERROR: problem with getting more data: current data is not compatible");return}var x=D.get("start");if(z===this.DEEP_DATA_REQ){$.extend(B,{start_val:F.data.length+1})}else{if(z===this.BROAD_DATA_REQ){x=(F.max_high?F.max_high:F.data[F.data.length-1][2])+1}}var E=D.copy().set("start",x);var w=this,A=this.load_data(E,C,y,B),v=$.Deferred();this.set_data(D,v);$.when(A).then(function(G){if(G.data){G.data=F.data.concat(G.data);if(G.max_low){G.max_low=F.max_low}if(G.message){G.message=G.message.replace(/[0-9]+/,G.data.length)}}w.set_data(D,G);v.resolve(G)});return v},can_get_more_detailed_data:function(w){var v=this.get_elt(w);return(v.dataset_type==="bigwig"&&v.data.length<8000)},get_more_detailed_data:function(y,A,w,z,x){var v=this._mark_stale(y);if(!v){console.log("ERROR getting more detailed data: no current data");return}if(!x){x={}}if(v.dataset_type==="bigwig"){x.num_samples=1000*z}return this.load_data(y,A,w,x)},_mark_stale:function(w){var v=this.get_elt(w);if(!v){console.log("ERROR: no data to mark as stale: ",this.get("dataset"),w.toString())}v.stale=true;return v},get_genome_wide_data:function(v){var x=this,z=true,y=t.map(v.get("chroms_info").chrom_info,function(B){var A=x.get_elt(new g({chrom:B.chrom,start:0,end:B.len}));if(!A){z=false}return A});if(z){return y}var w=$.Deferred();$.getJSON(this.get("dataset").url(),{data_type:"genome_data"},function(A){x.add_data(A.data);w.resolve(A.data)});return w},subset_entry:function(x,y){var v={bigwig:function(z,A){return t.filter(z,function(B){return B[0]>=A.get("start")&&B[0]<=A.get("end")})},refseq:function(A,B){var C=B.get("start")-x.region.get("start"),z=x.data.length-(x.region.get("end")-B.get("end"));return x.data.slice(C,z)}};var w=x.data;if(!x.region.same(y)&&x.dataset_type in v){w=v[x.dataset_type](x.data,y)}return{region:y,data:w,dataset_type:x.dataset_type}}});var q=d.extend({initialize:function(v){var w=new Backbone.Model();w.urlRoot=v.data_url;this.set("dataset",w)},load_data:function(x,y,v,w){return(x.length()<=100000?d.prototype.load_data.call(this,x,y,v,w):{data:null,region:x})}});var c=Backbone.Model.extend({defaults:{name:null,key:null,chroms_info:null},initialize:function(v){this.id=v.dbkey},get_chroms_info:function(){return this.attributes.chroms_info.chrom_info},get_chrom_region:function(v){var w=t.find(this.get_chroms_info(),function(x){return x.chrom===v});return new g({chrom:w.chrom,end:w.len})},get_chrom_len:function(v){return t.find(this.get_chroms_info(),function(w){return w.chrom===v}).len}});var g=Backbone.Model.extend({defaults:{chrom:null,start:0,end:0,str_val:null,genome:null},same:function(v){return this.attributes.chrom===v.get("chrom")&&this.attributes.start===v.get("start")&&this.attributes.end===v.get("end")},initialize:function(w){if(w.from_str){var y=w.from_str.split(":"),x=y[0],v=y[1].split("-");this.set({chrom:x,start:parseInt(v[0],10),end:parseInt(v[1],10)})}this.attributes.str_val=this.get("chrom")+":"+this.get("start")+"-"+this.get("end");this.on("change",function(){this.attributes.str_val=this.get("chrom")+":"+this.get("start")+"-"+this.get("end")},this)},copy:function(){return new g({chrom:this.get("chrom"),start:this.get("start"),end:this.get("end")})},length:function(){return this.get("end")-this.get("start")},toString:function(){return this.attributes.str_val},toJSON:function(){return{chrom:this.get("chrom"),start:this.get("start"),end:this.get("end")}},compute_overlap:function(C){var w=this.get("chrom"),B=C.get("chrom"),A=this.get("start"),y=C.get("start"),z=this.get("end"),x=C.get("end"),v;if(w&&B&&w!==B){return g.overlap_results.DIF_CHROMS}if(A<y){if(z<y){v=g.overlap_results.BEFORE}else{if(z<x){v=g.overlap_results.OVERLAP_START}else{v=g.overlap_results.CONTAINS}}}else{if(A>y){if(A>x){v=g.overlap_results.AFTER}else{if(z<=x){v=g.overlap_results.CONTAINED_BY}else{v=g.overlap_results.OVERLAP_END}}}else{v=(z>=x?g.overlap_results.CONTAINS:g.overlap_results.CONTAINED_BY)}}return v},trim:function(v){if(this.attributes.start<0){this.attributes.start=0}if(this.attributes.genome){var w=this.attributes.genome.get_chrom_len(this.attributes.chrom);if(this.attributes.end>w){this.attributes.end=w-1}}return this},contains:function(v){return this.compute_overlap(v)===g.overlap_results.CONTAINS},overlaps:function(v){return t.intersection([this.compute_overlap(v)],[g.overlap_results.DIF_CHROMS,g.overlap_results.BEFORE,g.overlap_results.AFTER]).length===0}},{overlap_results:{DIF_CHROMS:1000,BEFORE:1001,CONTAINS:1002,OVERLAP_START:1003,OVERLAP_END:1004,CONTAINED_BY:1005,AFTER:1006}});var n=Backbone.Collection.extend({model:g});var e=Backbone.Model.extend({defaults:{region:null,note:""},initialize:function(v){this.set("region",new g(v.region))}});var s=Backbone.Collection.extend({model:e});var u=Backbone.Model.extend({initialize:function(v){this.set("dataset",new j.Dataset(v.dataset));this.set("config",p.ConfigSettingCollection.from_config_dict(v.prefs));this.get("config").add([{key:"name",value:this.get("name")},{key:"color"}]);var w=this.get("preloaded_data");if(w){w=w.data}else{w=[]}this.set("data_manager",new d({dataset:this.get("dataset"),init_data:w}))}});var i=Backbone.Collection.extend({model:u});var o=Backbone.Model.extend({defaults:{title:"",type:""},url:galaxy_config.root+"visualization/save",save:function(){return $.ajax({url:this.url(),type:"POST",dataType:"json",data:{vis_json:JSON.stringify(this)}})}});var l=o.extend({defaults:t.extend({},o.prototype.defaults,{dbkey:"",tracks:null,bookmarks:null,viewport:null}),initialize:function(v){this.set("tracks",new i(v.tracks))},add_tracks:function(v){this.get("tracks").add(v)}});var b=Backbone.Model.extend({});var h=Backbone.Router.extend({initialize:function(w){this.view=w.view;this.route(/([\w]+)$/,"change_location");this.route(/([\w]+\:[\d,]+-[\d,]+)$/,"change_location");var v=this;v.view.on("navigate",function(x){v.navigate(x)})},change_location:function(v){this.view.go_to(v)}});return{BackboneTrack:u,BrowserBookmark:e,BrowserBookmarkCollection:s,Cache:r,CanvasManager:f,Genome:c,GenomeDataManager:d,GenomeRegion:g,GenomeRegionCollection:n,GenomeVisualization:l,GenomeReferenceDataManager:q,TrackBrowserRouter:h,TrackConfig:b,Visualization:o,select_datasets:a}}); \ No newline at end of file +define(["libs/underscore","mvc/data","viz/trackster/util","utils/config"],function(u,k,n,q){var f={toJSON:function(){var w=this,x={};u.each(w.constructor.to_json_keys,function(y){var z=w.get(y);if(y in w.constructor.to_json_mappers){z=w.constructor.to_json_mappers[y](z,w)}x[y]=z});return x}};var a=function(w,z,y,x){$.ajax({url:w,data:y,error:function(){alert("Grid failed")},success:function(A){Galaxy.modal.show({title:"Select datasets for new tracks",body:A,buttons:{Cancel:function(){Galaxy.modal.hide()},Add:function(){var B=[];$("input[name=id]:checked,input[name=ldda_ids]:checked").each(function(){var C={data_type:"track_config",hda_ldda:"hda"},D=$(this).val();if($(this).attr("name")!=="id"){C.hda_ldda="ldda"}B[B.length]=$.ajax({url:z+"/"+D,data:C,dataType:"json"})});$.when.apply($,B).then(function(){var C=(arguments[0] instanceof Array?$.map(arguments,function(D){return D[0]}):[arguments[0]]);x(C)});Galaxy.modal.hide()}}})}})};var l=function(w){return("promise" in w)};var g=function(w){this.default_font=w!==undefined?w:"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")};u.extend(g.prototype,{load_pattern:function(w,A){var x=this.patterns,y=this.dummy_context,z=new Image();z.src=galaxy_config.root+"static/images"+A;z.onload=function(){x[w]=y.createPattern(z,"repeat")}},get_pattern:function(w){return this.patterns[w]},new_canvas:function(){var w=$("<canvas/>")[0];if(window.G_vmlCanvasManager){G_vmlCanvasManager.initElement(w)}w.manager=this;return w}});var s=Backbone.Model.extend({defaults:{num_elements:20,obj_cache:null,key_ary:null},initialize:function(w){this.clear()},get_elt:function(y){var z=this.attributes.obj_cache,A=this.attributes.key_ary,x=y.toString(),w=u.indexOf(A,function(B){return B.toString()===x});if(w!==-1){if(z[x].stale){A.splice(w,1);delete z[x]}else{this.move_key_to_end(y,w)}}return z[x]},set_elt:function(y,A){var B=this.attributes.obj_cache,C=this.attributes.key_ary,x=y.toString(),z=this.attributes.num_elements;if(!B[x]){if(C.length>=z){var w=C.shift();delete B[w.toString()]}C.push(y)}B[x]=A;return A},move_key_to_end:function(x,w){this.attributes.key_ary.splice(w,1);this.attributes.key_ary.push(x)},clear:function(){this.attributes.obj_cache={};this.attributes.key_ary=[]},size:function(){return this.attributes.key_ary.length},most_recently_added:function(){return this.size()===0?null:this.attributes.key_ary[this.attributes.key_ary.length-1]}});var d=s.extend({defaults:u.extend({},s.prototype.defaults,{dataset:null,genome:null,init_data:null,min_region_size:200,filters_manager:null,data_type:"data",data_mode_compatible:function(w,x){return true},can_subset:function(w){return false}}),initialize:function(w){s.prototype.initialize.call(this);var x=this.get("init_data");if(x){this.add_data(x)}},add_data:function(w){if(this.get("num_elements")<w.length){this.set("num_elements",w.length)}var x=this;u.each(w,function(y){x.set_data(y.region,y)})},data_is_ready:function(){var z=this.get("dataset"),y=$.Deferred(),w=(this.get("data_type")==="raw_data"?"state":this.get("data_type")==="data"?"converted_datasets_state":"error"),x=new n.ServerStateDeferred({ajax_settings:{url:this.get("dataset").url(),data:{hda_ldda:z.get("hda_ldda"),data_type:w},dataType:"json"},interval:5000,success_fn:function(A){return A!=="pending"}});$.when(x.go()).then(function(A){y.resolve(A==="ok"||A==="data")});return y},search_features:function(w){var x=this.get("dataset"),y={query:w,hda_ldda:x.get("hda_ldda"),data_type:"features"};return $.getJSON(x.url(),y)},load_data:function(E,D,x,C){var A=this.get("dataset"),z={data_type:this.get("data_type"),chrom:E.get("chrom"),low:E.get("start"),high:E.get("end"),mode:D,resolution:x,hda_ldda:A.get("hda_ldda")};$.extend(z,C);var G=this.get("filters_manager");if(G){var H=[];var w=G.filters;for(var B=0;B<w.length;B++){H.push(w[B].name)}z.filter_cols=JSON.stringify(H)}var y=this,F=$.getJSON(A.url(),z,function(I){I.region=E;y.set_data(E,I)});this.set_data(E,F);return F},get_data:function(D,C,y,A){var E=this.get_elt(D);if(E&&(l(E)||this.get("data_mode_compatible")(E,C))){return E}var F=this.get("key_ary"),w=this.get("obj_cache"),x,B;for(var z=0;z<F.length;z++){x=F[z];if(x.contains(D)){B=true;E=w[x.toString()];if(l(E)||(this.get("data_mode_compatible")(E,C)&&this.get("can_subset")(E))){this.move_key_to_end(x,z);if(!l(E)){var H=this.subset_entry(E,D);this.set(D,H);E=H}return E}}}if(!B&&D.length()<this.attributes.min_region_size){D=D.copy();var G=this.most_recently_added();if(!G||(D.get("start")>G.get("start"))){D.set("end",D.get("start")+this.attributes.min_region_size)}else{D.set("start",D.get("end")-this.attributes.min_region_size)}D.set("genome",this.attributes.genome);D.trim()}return this.load_data(D,C,y,A)},set_data:function(x,w){this.set_elt(x,w)},DEEP_DATA_REQ:"deep",BROAD_DATA_REQ:"breadth",get_more_data:function(E,D,z,C,A){var G=this._mark_stale(E);if(!(G&&this.get("data_mode_compatible")(G,D))){console.log("ERROR: problem with getting more data: current data is not compatible");return}var y=E.get("start");if(A===this.DEEP_DATA_REQ){$.extend(C,{start_val:G.data.length+1})}else{if(A===this.BROAD_DATA_REQ){y=(G.max_high?G.max_high:G.data[G.data.length-1][2])+1}}var F=E.copy().set("start",y);var x=this,B=this.load_data(F,D,z,C),w=$.Deferred();this.set_data(E,w);$.when(B).then(function(H){if(H.data){H.data=G.data.concat(H.data);if(H.max_low){H.max_low=G.max_low}if(H.message){H.message=H.message.replace(/[0-9]+/,H.data.length)}}x.set_data(E,H);w.resolve(H)});return w},can_get_more_detailed_data:function(x){var w=this.get_elt(x);return(w.dataset_type==="bigwig"&&w.data.length<8000)},get_more_detailed_data:function(z,B,x,A,y){var w=this._mark_stale(z);if(!w){console.log("ERROR getting more detailed data: no current data");return}if(!y){y={}}if(w.dataset_type==="bigwig"){y.num_samples=1000*A}return this.load_data(z,B,x,y)},_mark_stale:function(x){var w=this.get_elt(x);if(!w){console.log("ERROR: no data to mark as stale: ",this.get("dataset"),x.toString())}w.stale=true;return w},get_genome_wide_data:function(w){var y=this,A=true,z=u.map(w.get("chroms_info").chrom_info,function(C){var B=y.get_elt(new h({chrom:C.chrom,start:0,end:C.len}));if(!B){A=false}return B});if(A){return z}var x=$.Deferred();$.getJSON(this.get("dataset").url(),{data_type:"genome_data"},function(B){y.add_data(B.data);x.resolve(B.data)});return x},subset_entry:function(y,z){var w={bigwig:function(A,B){return u.filter(A,function(C){return C[0]>=B.get("start")&&C[0]<=B.get("end")})},refseq:function(B,C){var D=C.get("start")-y.region.get("start"),A=y.data.length-(y.region.get("end")-C.get("end"));return y.data.slice(D,A)}};var x=y.data;if(!y.region.same(z)&&y.dataset_type in w){x=w[y.dataset_type](y.data,z)}return{region:z,data:x,dataset_type:y.dataset_type}}});var r=d.extend({initialize:function(w){var x=new Backbone.Model();x.urlRoot=w.data_url;this.set("dataset",x)},load_data:function(y,z,w,x){return(y.length()<=100000?d.prototype.load_data.call(this,y,z,w,x):{data:null,region:y})}});var c=Backbone.Model.extend({defaults:{name:null,key:null,chroms_info:null},initialize:function(w){this.id=w.dbkey},get_chroms_info:function(){return this.attributes.chroms_info.chrom_info},get_chrom_region:function(w){var x=u.find(this.get_chroms_info(),function(y){return y.chrom===w});return new h({chrom:x.chrom,end:x.len})},get_chrom_len:function(w){return u.find(this.get_chroms_info(),function(x){return x.chrom===w}).len}});var h=Backbone.Model.extend({defaults:{chrom:null,start:0,end:0,str_val:null,genome:null},same:function(w){return this.attributes.chrom===w.get("chrom")&&this.attributes.start===w.get("start")&&this.attributes.end===w.get("end")},initialize:function(x){if(x.from_str){var z=x.from_str.split(":"),y=z[0],w=z[1].split("-");this.set({chrom:y,start:parseInt(w[0],10),end:parseInt(w[1],10)})}this.attributes.str_val=this.get("chrom")+":"+this.get("start")+"-"+this.get("end");this.on("change",function(){this.attributes.str_val=this.get("chrom")+":"+this.get("start")+"-"+this.get("end")},this)},copy:function(){return new h({chrom:this.get("chrom"),start:this.get("start"),end:this.get("end")})},length:function(){return this.get("end")-this.get("start")},toString:function(){return this.attributes.str_val},toJSON:function(){return{chrom:this.get("chrom"),start:this.get("start"),end:this.get("end")}},compute_overlap:function(D){var x=this.get("chrom"),C=D.get("chrom"),B=this.get("start"),z=D.get("start"),A=this.get("end"),y=D.get("end"),w;if(x&&C&&x!==C){return h.overlap_results.DIF_CHROMS}if(B<z){if(A<z){w=h.overlap_results.BEFORE}else{if(A<y){w=h.overlap_results.OVERLAP_START}else{w=h.overlap_results.CONTAINS}}}else{if(B>z){if(B>y){w=h.overlap_results.AFTER}else{if(A<=y){w=h.overlap_results.CONTAINED_BY}else{w=h.overlap_results.OVERLAP_END}}}else{w=(A>=y?h.overlap_results.CONTAINS:h.overlap_results.CONTAINED_BY)}}return w},trim:function(w){if(this.attributes.start<0){this.attributes.start=0}if(this.attributes.genome){var x=this.attributes.genome.get_chrom_len(this.attributes.chrom);if(this.attributes.end>x){this.attributes.end=x-1}}return this},contains:function(w){return this.compute_overlap(w)===h.overlap_results.CONTAINS},overlaps:function(w){return u.intersection([this.compute_overlap(w)],[h.overlap_results.DIF_CHROMS,h.overlap_results.BEFORE,h.overlap_results.AFTER]).length===0}},{overlap_results:{DIF_CHROMS:1000,BEFORE:1001,CONTAINS:1002,OVERLAP_START:1003,OVERLAP_END:1004,CONTAINED_BY:1005,AFTER:1006}});var o=Backbone.Collection.extend({model:h});var e=Backbone.Model.extend({defaults:{region:null,note:""},initialize:function(w){this.set("region",new h(w.region))}});var t=Backbone.Collection.extend({model:e});var v=Backbone.Model.extend(f).extend({defaults:{mode:"Auto"},initialize:function(w){this.set("dataset",new k.Dataset(w.dataset));this.set("config",q.ConfigSettingCollection.from_config_dict(w.prefs));this.get("config").add([{key:"name",value:this.get("dataset").get("name")},{key:"color"}]);var x=this.get("preloaded_data");if(x){x=x.data}else{x=[]}this.set("data_manager",new d({dataset:this.get("dataset"),init_data:x}))}},{to_json_keys:["track_type","dataset","prefs","mode","filters","tool_state"],to_json_mappers:{prefs:function(x,w){if(u.size(x)===0){x={name:w.get("config").get("name").get("value"),color:w.get("config").get("color").get("value")}}return x},dataset:function(w){return{id:w.id,hda_ldda:w.get("hda_ldda")}}}});var j=Backbone.Collection.extend({model:v});var p=Backbone.Model.extend({defaults:{title:"",type:""},url:galaxy_config.root+"visualization/save",save:function(){return $.ajax({url:this.url(),type:"POST",dataType:"json",data:{vis_json:JSON.stringify(this)}})}});var m=p.extend(f).extend({defaults:u.extend({},p.prototype.defaults,{dbkey:"",drawables:null,bookmarks:null,viewport:null}),initialize:function(w){this.set("drawables",new j(w.tracks));this.set("config",q.ConfigSettingCollection.from_config_dict(w.prefs||{}));this.unset("tracks");this.get("drawables").each(function(x){x.unset("preloaded_data")})},add_tracks:function(w){this.get("drawables").add(w)}},{to_json_keys:["view","viewport","bookmarks"],to_json_mappers:{view:function(x,w){return{obj_type:"View",prefs:{name:w.get("title"),content_visible:true},drawables:w.get("drawables")}}}});var b=Backbone.Model.extend({});var i=Backbone.Router.extend({initialize:function(x){this.view=x.view;this.route(/([\w]+)$/,"change_location");this.route(/([\w]+\:[\d,]+-[\d,]+)$/,"change_location");var w=this;w.view.on("navigate",function(y){w.navigate(y)})},change_location:function(w){this.view.go_to(w)}});return{BackboneTrack:v,BrowserBookmark:e,BrowserBookmarkCollection:t,Cache:s,CanvasManager:g,Genome:c,GenomeDataManager:d,GenomeRegion:h,GenomeRegionCollection:o,GenomeVisualization:m,GenomeReferenceDataManager:r,TrackBrowserRouter:i,TrackConfig:b,Visualization:p,select_datasets:a}}); \ No newline at end of file diff -r 2b8e4f343a9abe4e936afec8a3d99bf8d9a01ef0 -r d557d5dd942f5bbf820e19ec3fe7278401489555 static/scripts/viz/circster.js --- a/static/scripts/viz/circster.js +++ b/static/scripts/viz/circster.js @@ -143,8 +143,8 @@ this.chords_views = null; // When tracks added to/removed from model, update view. - this.model.get('tracks').on('add', this.add_track, this); - this.model.get('tracks').on('remove', this.remove_track, this); + this.model.get('drawables').on('add', this.add_track, this); + this.model.get('drawables').on('remove', this.remove_track, this); this.get_circular_tracks(); }, @@ -154,7 +154,7 @@ * Returns tracks to be rendered using circular view. */ get_circular_tracks: function() { - return this.model.get('tracks').filter(function(track) { + return this.model.get('drawables').filter(function(track) { return track.get('track_type') !== 'DiagonalHeatmapTrack'; }); }, @@ -163,7 +163,7 @@ * Returns tracks to be rendered using chords view. */ get_chord_tracks: function() { - return this.model.get('tracks').filter(function(track) { + return this.model.get('drawables').filter(function(track) { return track.get('track_type') === 'DiagonalHeatmapTrack'; }); }, @@ -992,41 +992,36 @@ // setup menu var menu = create_icon_buttons_menu([ - { icon_class: 'plus-button', title: 'Add tracks', on_click: function() + { + icon_class: 'plus-button', title: 'Add tracks', on_click: function() { visualization.select_datasets(galaxy_config.root + "visualization/list_current_history_datasets", galaxy_config.root + "api/datasets", vis.get('dbkey'), function(tracks) { vis.add_tracks(tracks); }); } - },{ + }, + { icon_class: 'disk--arrow', title: 'Save', on_click: function() { // show saving dialog box Galaxy.modal.show({title: "Saving...", body: "progress" }); - // link configuration - var view = galaxy_config.app.viz_config; - // send to server $.ajax({ url: galaxy_config.root + "visualization/save", type: "POST", dataType: "json", data: { - 'id' : view.vis_id, - 'title' : view.title, - 'dbkey' : view.dbkey, + 'id' : vis.get('vis_id'), + 'title' : vis.get('title'), + 'dbkey' : vis.get('dbkey'), 'type' : 'trackster', - 'vis_json' : JSON.stringify(view) + 'vis_json' : JSON.stringify(vis) } }).success(function(vis_info) { Galaxy.modal.hide(); - view.vis_id = vis_info.vis_id; - view.has_changes = false; - - // needed to set URL when first saving a visualization - window.history.pushState({}, "", vis_info.url + window.location.hash); + vis.set('vis_id', vis_info.vis_id); }).error(function() { // show dialog Galaxy.modal.show({ @@ -1036,7 +1031,8 @@ }); }); } - },{ + }, + { icon_class: 'cross-circle', title: 'Close', on_click: function() { window.location = galaxy_config.root + "visualization/list"; diff -r 2b8e4f343a9abe4e936afec8a3d99bf8d9a01ef0 -r d557d5dd942f5bbf820e19ec3fe7278401489555 static/scripts/viz/visualization.js --- a/static/scripts/viz/visualization.js +++ b/static/scripts/viz/visualization.js @@ -1,6 +1,28 @@ define( ["libs/underscore", "mvc/data", "viz/trackster/util", "utils/config"], function(_, data_mod, util_mod, config_mod) { /** + * Mixin for returning custom JSON representation from toJSON. Class attribute to_json_keys defines a set of attributes + * to include in the representation; to_json_mappers defines mappers for returned objects. + */ +var CustomToJSON = { + /** + * Returns JSON representation of object using to_json_keys and to_json_mappers. + */ + toJSON: function() { + var self = this, + json = {}; + _.each(self.constructor.to_json_keys, function(k) { + var val = self.get(k); + if (k in self.constructor.to_json_mappers) { + val = self.constructor.to_json_mappers[k](val, self); + } + json[k] = val; + }); + return json; + } +}; + +/** * Model, view, and controller objects for Galaxy visualization framework. * * Models have no references to views, instead using events to indicate state @@ -872,7 +894,10 @@ * A track of data in a genome visualization. */ // TODO: rename to Track and merge with Trackster's Track object. -var BackboneTrack = Backbone.Model.extend({ +var BackboneTrack = Backbone.Model.extend(CustomToJSON).extend({ + defaults: { + mode: 'Auto' + }, initialize: function(options) { this.set('dataset', new data_mod.Dataset(options.dataset)); @@ -883,7 +908,7 @@ // Set up some minimal config. this.get('config').add( [ - { key: 'name', value: this.get('name') }, + { key: 'name', value: this.get('dataset').get('name') }, { key: 'color' } ] ); @@ -900,6 +925,34 @@ init_data: preloaded_data })); } +}, +{ + // This definition matches that produced by to_dict() methods in tracks.js + to_json_keys: [ + 'track_type', + 'dataset', + 'prefs', + 'mode', + 'filters', + 'tool_state' + ], + to_json_mappers: { + prefs: function(p, self) { + if (_.size(p) === 0) { + p = { + name: self.get('config').get('name').get('value'), + color: self.get('config').get('color').get('value') + }; + } + return p; + }, + dataset: function(d) { + return { + id: d.id, + hda_ldda: d.get('hda_ldda') + }; + } + } }); var BackboneTrackCollection = Backbone.Collection.extend({ @@ -938,25 +991,55 @@ /** * A visualization of genome data. */ -var GenomeVisualization = Visualization.extend({ +var GenomeVisualization = Visualization.extend(CustomToJSON).extend({ defaults: _.extend({}, Visualization.prototype.defaults, { dbkey: '', - tracks: null, + drawables: null, bookmarks: null, viewport: null }), initialize: function(options) { - this.set('tracks', new BackboneTrackCollection(options.tracks)); + // Replace drawables with tracks. + this.set('drawables', new BackboneTrackCollection(options.tracks)); + this.set('config', config_mod.ConfigSettingCollection.from_config_dict(options.prefs || {})); + + // Clear track and data definitions to avoid storing large objects. + this.unset('tracks'); + this.get('drawables').each(function(d) { + d.unset('preloaded_data'); + }); }, /** * Add a track or array of tracks to the visualization. */ add_tracks: function(tracks) { - this.get('tracks').add(tracks); + this.get('drawables').add(tracks); } -}); +}, +{ + // This definition matches that produced by to_dict() methods in tracks.js + to_json_keys: [ + 'view', + 'viewport', + 'bookmarks' + ], + + to_json_mappers: { + 'view': function(dummy, self) { + return { + obj_type: 'View', + prefs: { + name: self.get('title'), + content_visible: true + }, + drawables: self.get('drawables') + }; + } + } +} +); /** * Configuration data for a Trackster track. https://bitbucket.org/galaxy/galaxy-central/commits/75a81fcf38c4/ Changeset: 75a81fcf38c4 User: jeremy goecks Date: 2014-02-05 22:24:47 Summary: Merge next-stable with default. Affected #: 0 files Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.