1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/31c50ee29579/ Changeset: 31c50ee29579 User: carlfeberhard Date: 2014-12-09 18:28:57+00:00 Summary: Client build: remove ui.js; modularize icon button from ui.js Affected #: 21 files diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 client/galaxy/scripts/mvc/data.js --- a/client/galaxy/scripts/mvc/data.js +++ b/client/galaxy/scripts/mvc/data.js @@ -1,5 +1,5 @@ // Additional dependencies: jQuery, underscore. -define(['mvc/ui/ui-modal', 'mvc/ui/ui-frames'], function(Modal, Frames) { +define(['mvc/ui/ui-modal', 'mvc/ui/ui-frames', 'mvc/ui/icon-button'], function(Modal, Frames, mod_icon_btn) { /** * Dataset metedata. @@ -447,8 +447,8 @@ } // create the icon - var btn_viz = new IconButtonView({ - model : new IconButton({ + var btn_viz = new mod_icon_btn.IconButtonView({ + model : new mod_icon_btn.IconButton({ title : 'Visualize', icon_class : 'chart_curve', id : 'btn_viz' diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 client/galaxy/scripts/mvc/ui.js --- a/client/galaxy/scripts/mvc/ui.js +++ /dev/null @@ -1,171 +0,0 @@ -/** - * functions for creating major ui elements - */ - -/** - * backbone model for icon buttons - */ -var IconButton = Backbone.Model.extend({ - defaults: { - title : "", - icon_class : "", - on_click : null, - menu_options : null, - is_menu_button : true, - id : null, - href : null, - target : null, - enabled : true, - visible : true, - tooltip_config : {} - } -}); - -/** - * backbone view for icon buttons - */ -var IconButtonView = Backbone.View.extend({ - - initialize : function(){ - // better rendering this way - this.model.attributes.tooltip_config = { placement : 'bottom' }; - this.model.bind( 'change', this.render, this ); - }, - - render : function( ){ - // hide tooltip - this.$el.tooltip( 'hide' ); - - var new_elem = this.template( this.model.toJSON() ); - // configure tooltip - new_elem.tooltip( this.model.get( 'tooltip_config' )); - this.$el.replaceWith( new_elem ); - this.setElement( new_elem ); - return this; - }, - - events : { - 'click' : 'click' - }, - - click : function( event ){ - // if on_click pass to that function - if( _.isFunction( this.model.get( 'on_click' ) ) ){ - this.model.get( 'on_click' )( event ); - return false; - } - // otherwise, bubble up ( to href or whatever ) - return true; - }, - - // generate html element - template: function( options ){ - var buffer = 'title="' + options.title + '" class="icon-button'; - - if( options.is_menu_button ){ - buffer += ' menu-button'; - } - - buffer += ' ' + options.icon_class; - - if( !options.enabled ){ - buffer += '_disabled'; - } - - // close class tag - buffer += '"'; - - if( options.id ){ - buffer += ' id="' + options.id + '"'; - } - - buffer += ' href="' + options.href + '"'; - // add target for href - if( options.target ){ - buffer += ' target="' + options.target + '"'; - } - // set visibility - if( !options.visible ){ - buffer += ' style="display: none;"'; - } - - // enabled/disabled - if ( options.enabled ){ - buffer = '<a ' + buffer + '/>'; - } else { - buffer = '<span ' + buffer + '/>'; - } - - // return element - return $( buffer ); - } -} ); - -// define collection -var IconButtonCollection = Backbone.Collection.extend({ - model: IconButton -}); - -/** - * menu with multiple icon buttons - * views are not needed nor used for individual buttons - */ -var IconButtonMenuView = Backbone.View.extend({ - - tagName: 'div', - - initialize: function(){ - this.render(); - }, - - render: function(){ - // initialize icon buttons - var self = this; - this.collection.each(function(button){ - // create and add icon button to menu - var elt = $('<a/>') - .attr('href', 'javascript:void(0)') - .attr('title', button.attributes.title) - .addClass('icon-button menu-button') - .addClass(button.attributes.icon_class) - .appendTo(self.$el) - .click(button.attributes.on_click); - - // configure tooltip - if (button.attributes.tooltip_config){ - elt.tooltip(button.attributes.tooltip_config); - } - - // add popup menu to icon - var menu_options = button.get('options'); - if (menu_options){ - make_popupmenu(elt, menu_options); - } - }); - - // return - return this; - } -}); - -/** - * Returns an IconButtonMenuView for the provided configuration. - * Configuration is a list of dictionaries where each dictionary - * defines an icon button. Each dictionary must have the following - * elements: icon_class, title, and on_click. - */ -var create_icon_buttons_menu = function(config, global_config) -{ - // initialize global configuration - if (!global_config) global_config = {}; - - // create and initialize menu - var buttons = new IconButtonCollection( - _.map(config, function(button_config){ - return new IconButton(_.extend(button_config, global_config)); - }) - ); - - // return menu - return new IconButtonMenuView( {collection: buttons} ); -}; diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 client/galaxy/scripts/mvc/ui/icon-button.js --- /dev/null +++ b/client/galaxy/scripts/mvc/ui/icon-button.js @@ -0,0 +1,183 @@ +define([ + //jquery + //backbone +], function(){ +//============================================================================= +/** + * backbone model for icon buttons + */ +var IconButton = Backbone.Model.extend({ + defaults: { + title : "", + icon_class : "", + on_click : null, + menu_options : null, + is_menu_button : true, + id : null, + href : null, + target : null, + enabled : true, + visible : true, + tooltip_config : {} + } +}); + +/** + * backbone view for icon buttons + */ +var IconButtonView = Backbone.View.extend({ + + initialize : function(){ + // better rendering this way + this.model.attributes.tooltip_config = { placement : 'bottom' }; + this.model.bind( 'change', this.render, this ); + }, + + render : function( ){ + // hide tooltip + this.$el.tooltip( 'hide' ); + + var new_elem = this.template( this.model.toJSON() ); + // configure tooltip + new_elem.tooltip( this.model.get( 'tooltip_config' )); + this.$el.replaceWith( new_elem ); + this.setElement( new_elem ); + return this; + }, + + events : { + 'click' : 'click' + }, + + click : function( event ){ + // if on_click pass to that function + if( _.isFunction( this.model.get( 'on_click' ) ) ){ + this.model.get( 'on_click' )( event ); + return false; + } + // otherwise, bubble up ( to href or whatever ) + return true; + }, + + // generate html element + template: function( options ){ + var buffer = 'title="' + options.title + '" class="icon-button'; + + if( options.is_menu_button ){ + buffer += ' menu-button'; + } + + buffer += ' ' + options.icon_class; + + if( !options.enabled ){ + buffer += '_disabled'; + } + + // close class tag + buffer += '"'; + + if( options.id ){ + buffer += ' id="' + options.id + '"'; + } + + buffer += ' href="' + options.href + '"'; + // add target for href + if( options.target ){ + buffer += ' target="' + options.target + '"'; + } + // set visibility + if( !options.visible ){ + buffer += ' style="display: none;"'; + } + + // enabled/disabled + if ( options.enabled ){ + buffer = '<a ' + buffer + '/>'; + } else { + buffer = '<span ' + buffer + '/>'; + } + + // return element + return $( buffer ); + } +} ); + +// define collection +var IconButtonCollection = Backbone.Collection.extend({ + model: IconButton +}); + +/** + * menu with multiple icon buttons + * views are not needed nor used for individual buttons + */ +var IconButtonMenuView = Backbone.View.extend({ + + tagName: 'div', + + initialize: function(){ + this.render(); + }, + + render: function(){ + // initialize icon buttons + var self = this; + this.collection.each(function(button){ + // create and add icon button to menu + var elt = $('<a/>') + .attr('href', 'javascript:void(0)') + .attr('title', button.attributes.title) + .addClass('icon-button menu-button') + .addClass(button.attributes.icon_class) + .appendTo(self.$el) + .click(button.attributes.on_click); + + // configure tooltip + if (button.attributes.tooltip_config){ + elt.tooltip(button.attributes.tooltip_config); + } + + // add popup menu to icon + var menu_options = button.get('options'); + if (menu_options){ + make_popupmenu(elt, menu_options); + } + }); + + // return + return this; + } +}); + +/** + * Returns an IconButtonMenuView for the provided configuration. + * Configuration is a list of dictionaries where each dictionary + * defines an icon button. Each dictionary must have the following + * elements: icon_class, title, and on_click. + */ +var create_icon_buttons_menu = function(config, global_config) +{ + // initialize global configuration + if (!global_config) global_config = {}; + + // create and initialize menu + var buttons = new IconButtonCollection( + _.map(config, function(button_config){ + return new IconButton(_.extend(button_config, global_config)); + }) + ); + + // return menu + return new IconButtonMenuView( {collection: buttons} ); +}; + + +//============================================================================= + return { + IconButton : IconButton, + IconButtonView : IconButtonView, + IconButtonCollection : IconButtonCollection, + IconButtonMenuView : IconButtonMenuView, + create_icon_buttons_menu: create_icon_buttons_menu + }; +}) diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 client/galaxy/scripts/viz/circster.js --- a/client/galaxy/scripts/viz/circster.js +++ b/client/galaxy/scripts/viz/circster.js @@ -2,8 +2,9 @@ require( [ 'utils/utils', + 'mvc/ui/icon-button', 'libs/farbtastic', -], function(mod_utils) +], function(mod_utils, mod_icon_btn) { // load css mod_utils.cssLoadFile("static/style/circster.css"); @@ -1075,7 +1076,7 @@ $('#center .unified-panel-header-inner').append(galaxy_config.app.viz_config.title + " " + galaxy_config.app.viz_config.dbkey); // setup menu - var menu = create_icon_buttons_menu([ + var menu = mod_icon_btn.create_icon_buttons_menu([ { icon_class: 'plus-button', title: 'Add tracks', on_click: function() { diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 client/galaxy/scripts/viz/phyloviz.js --- a/client/galaxy/scripts/viz/phyloviz.js +++ b/client/galaxy/scripts/viz/phyloviz.js @@ -1,4 +1,9 @@ -define(['libs/d3', 'viz/visualization', 'mvc/data'], function(d3, visualization_mod, data_mod) { +define([ + 'libs/d3', + 'viz/visualization', + 'mvc/data', + 'mvc/ui/icon-button' +], function(d3, visualization_mod, data_mod, mod_icon_btn) { /** * Base class of any menus that takes in user interaction. Contains checking methods. @@ -720,7 +725,7 @@ initRightHeaderBtns : function(){ var self = this; - rightMenu = create_icon_buttons_menu([ + rightMenu = mod_icon_btn.create_icon_buttons_menu([ { icon_class: 'gear', title: 'PhyloViz Settings', on_click: function(){ $("#SettingsMenu").show(); self.settingsMenu.updateUI(); @@ -748,7 +753,7 @@ initNavBtns: function() { var self = this, - navMenu = create_icon_buttons_menu([ + navMenu = mod_icon_btn.create_icon_buttons_menu([ { icon_class: 'zoom-in', title: 'Zoom in', on_click: function() { self.phylovizView.zoomAndPan({ zoom : "+"}); } }, diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 client/galaxy/scripts/viz/sweepster.js --- a/client/galaxy/scripts/viz/sweepster.js +++ b/client/galaxy/scripts/viz/sweepster.js @@ -3,8 +3,8 @@ * genomic visualization. */ -define(["libs/underscore", "libs/d3", "viz/trackster/util", "viz/visualization", "viz/trackster/tracks", "mvc/tools", "mvc/data", "utils/config"], - function(_, d3, util, visualization, tracks, tools, data, config) { +define(["libs/underscore", "libs/d3", "viz/trackster/util", "viz/visualization", "viz/trackster/tracks", "mvc/tools", "mvc/data", "utils/config", "mvc/ui/icon-button"], + function(_, d3, util, visualization, tracks, tools, data, config, mod_icon_btn) { /** * A collection of tool input settings. Object is useful for keeping a list of settings @@ -375,7 +375,7 @@ settings_div.toggle(); self.trigger('run_on_dataset', settings); }); - var icon_menu = create_icon_buttons_menu([ + var icon_menu = mod_icon_btn.create_icon_buttons_menu([ { title: 'Settings', icon_class: 'gear track-settings', @@ -486,7 +486,7 @@ // Add buttons for adding/removing parameter. var self = this, - menu = create_icon_buttons_menu([ + menu = mod_icon_btn.create_icon_buttons_menu([ { title: 'Add parameter to tree', icon_class: 'plus-button', @@ -723,7 +723,7 @@ // Help includes text and a close button. var help_div = $(this.helpText).addClass('help'), - close_button = create_icon_buttons_menu([ + close_button = mod_icon_btn.create_icon_buttons_menu([ { title: 'Close', icon_class: 'cross-circle', @@ -745,7 +745,7 @@ this.handle_node_clicks(); // Set up visualization menu. - var menu = create_icon_buttons_menu( + var menu = mod_icon_btn.create_icon_buttons_menu( [ // Save. /* @@ -939,4 +939,4 @@ SweepsterVisualizationView: SweepsterVisualizationView }; -}); \ No newline at end of file +}); diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 client/galaxy/scripts/viz/trackster.js --- a/client/galaxy/scripts/viz/trackster.js +++ b/client/galaxy/scripts/viz/trackster.js @@ -12,6 +12,7 @@ [ // load js libraries 'utils/utils', + 'mvc/ui/icon-button', 'libs/jquery/jquery.event.drag', 'libs/jquery/jquery.event.hover', 'libs/jquery/jquery.mousewheel', @@ -21,7 +22,7 @@ 'libs/jquery/jquery.form', 'libs/jquery/jquery.rating', 'mvc/ui' -], function(mod_utils) +], function(mod_utils, mod_icon_btn) { // load css mod_utils.cssLoadFile("static/style/jquery.rating.css"); @@ -101,7 +102,7 @@ */ createButtonMenu: function() { var self = this, - menu = create_icon_buttons_menu([ + menu = mod_icon_btn.create_icon_buttons_menu([ { 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", { 'f-dbkey': view.dbkey }, function(new_tracks) { @@ -571,4 +572,4 @@ GalaxyApp : TracksterView }; -}); \ No newline at end of file +}); diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 static/scripts/mvc/data.js --- a/static/scripts/mvc/data.js +++ b/static/scripts/mvc/data.js @@ -1,5 +1,5 @@ // Additional dependencies: jQuery, underscore. -define(['mvc/ui/ui-modal', 'mvc/ui/ui-frames'], function(Modal, Frames) { +define(['mvc/ui/ui-modal', 'mvc/ui/ui-frames', 'mvc/ui/icon-button'], function(Modal, Frames, mod_icon_btn) { /** * Dataset metedata. @@ -447,8 +447,8 @@ } // create the icon - var btn_viz = new IconButtonView({ - model : new IconButton({ + var btn_viz = new mod_icon_btn.IconButtonView({ + model : new mod_icon_btn.IconButton({ title : 'Visualize', icon_class : 'chart_curve', id : 'btn_viz' diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 static/scripts/mvc/ui.js --- a/static/scripts/mvc/ui.js +++ /dev/null @@ -1,171 +0,0 @@ -/** - * functions for creating major ui elements - */ - -/** - * backbone model for icon buttons - */ -var IconButton = Backbone.Model.extend({ - defaults: { - title : "", - icon_class : "", - on_click : null, - menu_options : null, - is_menu_button : true, - id : null, - href : null, - target : null, - enabled : true, - visible : true, - tooltip_config : {} - } -}); - -/** - * backbone view for icon buttons - */ -var IconButtonView = Backbone.View.extend({ - - initialize : function(){ - // better rendering this way - this.model.attributes.tooltip_config = { placement : 'bottom' }; - this.model.bind( 'change', this.render, this ); - }, - - render : function( ){ - // hide tooltip - this.$el.tooltip( 'hide' ); - - var new_elem = this.template( this.model.toJSON() ); - // configure tooltip - new_elem.tooltip( this.model.get( 'tooltip_config' )); - this.$el.replaceWith( new_elem ); - this.setElement( new_elem ); - return this; - }, - - events : { - 'click' : 'click' - }, - - click : function( event ){ - // if on_click pass to that function - if( _.isFunction( this.model.get( 'on_click' ) ) ){ - this.model.get( 'on_click' )( event ); - return false; - } - // otherwise, bubble up ( to href or whatever ) - return true; - }, - - // generate html element - template: function( options ){ - var buffer = 'title="' + options.title + '" class="icon-button'; - - if( options.is_menu_button ){ - buffer += ' menu-button'; - } - - buffer += ' ' + options.icon_class; - - if( !options.enabled ){ - buffer += '_disabled'; - } - - // close class tag - buffer += '"'; - - if( options.id ){ - buffer += ' id="' + options.id + '"'; - } - - buffer += ' href="' + options.href + '"'; - // add target for href - if( options.target ){ - buffer += ' target="' + options.target + '"'; - } - // set visibility - if( !options.visible ){ - buffer += ' style="display: none;"'; - } - - // enabled/disabled - if ( options.enabled ){ - buffer = '<a ' + buffer + '/>'; - } else { - buffer = '<span ' + buffer + '/>'; - } - - // return element - return $( buffer ); - } -} ); - -// define collection -var IconButtonCollection = Backbone.Collection.extend({ - model: IconButton -}); - -/** - * menu with multiple icon buttons - * views are not needed nor used for individual buttons - */ -var IconButtonMenuView = Backbone.View.extend({ - - tagName: 'div', - - initialize: function(){ - this.render(); - }, - - render: function(){ - // initialize icon buttons - var self = this; - this.collection.each(function(button){ - // create and add icon button to menu - var elt = $('<a/>') - .attr('href', 'javascript:void(0)') - .attr('title', button.attributes.title) - .addClass('icon-button menu-button') - .addClass(button.attributes.icon_class) - .appendTo(self.$el) - .click(button.attributes.on_click); - - // configure tooltip - if (button.attributes.tooltip_config){ - elt.tooltip(button.attributes.tooltip_config); - } - - // add popup menu to icon - var menu_options = button.get('options'); - if (menu_options){ - make_popupmenu(elt, menu_options); - } - }); - - // return - return this; - } -}); - -/** - * Returns an IconButtonMenuView for the provided configuration. - * Configuration is a list of dictionaries where each dictionary - * defines an icon button. Each dictionary must have the following - * elements: icon_class, title, and on_click. - */ -var create_icon_buttons_menu = function(config, global_config) -{ - // initialize global configuration - if (!global_config) global_config = {}; - - // create and initialize menu - var buttons = new IconButtonCollection( - _.map(config, function(button_config){ - return new IconButton(_.extend(button_config, global_config)); - }) - ); - - // return menu - return new IconButtonMenuView( {collection: buttons} ); -}; diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 static/scripts/mvc/ui/icon-button.js --- /dev/null +++ b/static/scripts/mvc/ui/icon-button.js @@ -0,0 +1,183 @@ +define([ + //jquery + //backbone +], function(){ +//============================================================================= +/** + * backbone model for icon buttons + */ +var IconButton = Backbone.Model.extend({ + defaults: { + title : "", + icon_class : "", + on_click : null, + menu_options : null, + is_menu_button : true, + id : null, + href : null, + target : null, + enabled : true, + visible : true, + tooltip_config : {} + } +}); + +/** + * backbone view for icon buttons + */ +var IconButtonView = Backbone.View.extend({ + + initialize : function(){ + // better rendering this way + this.model.attributes.tooltip_config = { placement : 'bottom' }; + this.model.bind( 'change', this.render, this ); + }, + + render : function( ){ + // hide tooltip + this.$el.tooltip( 'hide' ); + + var new_elem = this.template( this.model.toJSON() ); + // configure tooltip + new_elem.tooltip( this.model.get( 'tooltip_config' )); + this.$el.replaceWith( new_elem ); + this.setElement( new_elem ); + return this; + }, + + events : { + 'click' : 'click' + }, + + click : function( event ){ + // if on_click pass to that function + if( _.isFunction( this.model.get( 'on_click' ) ) ){ + this.model.get( 'on_click' )( event ); + return false; + } + // otherwise, bubble up ( to href or whatever ) + return true; + }, + + // generate html element + template: function( options ){ + var buffer = 'title="' + options.title + '" class="icon-button'; + + if( options.is_menu_button ){ + buffer += ' menu-button'; + } + + buffer += ' ' + options.icon_class; + + if( !options.enabled ){ + buffer += '_disabled'; + } + + // close class tag + buffer += '"'; + + if( options.id ){ + buffer += ' id="' + options.id + '"'; + } + + buffer += ' href="' + options.href + '"'; + // add target for href + if( options.target ){ + buffer += ' target="' + options.target + '"'; + } + // set visibility + if( !options.visible ){ + buffer += ' style="display: none;"'; + } + + // enabled/disabled + if ( options.enabled ){ + buffer = '<a ' + buffer + '/>'; + } else { + buffer = '<span ' + buffer + '/>'; + } + + // return element + return $( buffer ); + } +} ); + +// define collection +var IconButtonCollection = Backbone.Collection.extend({ + model: IconButton +}); + +/** + * menu with multiple icon buttons + * views are not needed nor used for individual buttons + */ +var IconButtonMenuView = Backbone.View.extend({ + + tagName: 'div', + + initialize: function(){ + this.render(); + }, + + render: function(){ + // initialize icon buttons + var self = this; + this.collection.each(function(button){ + // create and add icon button to menu + var elt = $('<a/>') + .attr('href', 'javascript:void(0)') + .attr('title', button.attributes.title) + .addClass('icon-button menu-button') + .addClass(button.attributes.icon_class) + .appendTo(self.$el) + .click(button.attributes.on_click); + + // configure tooltip + if (button.attributes.tooltip_config){ + elt.tooltip(button.attributes.tooltip_config); + } + + // add popup menu to icon + var menu_options = button.get('options'); + if (menu_options){ + make_popupmenu(elt, menu_options); + } + }); + + // return + return this; + } +}); + +/** + * Returns an IconButtonMenuView for the provided configuration. + * Configuration is a list of dictionaries where each dictionary + * defines an icon button. Each dictionary must have the following + * elements: icon_class, title, and on_click. + */ +var create_icon_buttons_menu = function(config, global_config) +{ + // initialize global configuration + if (!global_config) global_config = {}; + + // create and initialize menu + var buttons = new IconButtonCollection( + _.map(config, function(button_config){ + return new IconButton(_.extend(button_config, global_config)); + }) + ); + + // return menu + return new IconButtonMenuView( {collection: buttons} ); +}; + + +//============================================================================= + return { + IconButton : IconButton, + IconButtonView : IconButtonView, + IconButtonCollection : IconButtonCollection, + IconButtonMenuView : IconButtonMenuView, + create_icon_buttons_menu: create_icon_buttons_menu + }; +}) diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 static/scripts/packed/mvc/data.js --- a/static/scripts/packed/mvc/data.js +++ b/static/scripts/packed/mvc/data.js @@ -1,1 +1,1 @@ -define(["mvc/ui/ui-modal","mvc/ui/ui-frames"],function(j,i){var g=Backbone.Model.extend({});var b=Backbone.Model.extend({defaults:{id:"",type:"",name:"",hda_ldda:"hda",metadata:null},initialize:function(){if(!this.get("metadata")){this._set_metadata()}this.on("change",this._set_metadata,this)},_set_metadata:function(){var m=new g();_.each(_.keys(this.attributes),function(n){if(n.indexOf("metadata_")===0){var o=n.split("metadata_")[1];m.set(o,this.attributes[n]);delete this.attributes[n]}},this);this.set("metadata",m,{silent:true})},get_metadata:function(m){return this.attributes.metadata.get(m)},urlRoot:galaxy_config.root+"api/datasets"});var h=b.extend({defaults:_.extend({},b.prototype.defaults,{chunk_url:null,first_data_chunk:null,chunk_index:-1,at_eof:false}),initialize:function(m){b.prototype.initialize.call(this);this.attributes.chunk_index=(this.attributes.first_data_chunk?1:0);this.attributes.chunk_url=galaxy_config.root+"dataset/display?dataset_id="+this.id;this.attributes.url_viz=galaxy_config.root+"visualization"},get_next_chunk:function(){if(this.attributes.at_eof){return null}var m=this,n=$.Deferred();$.getJSON(this.attributes.chunk_url,{chunk:m.attributes.chunk_index++}).success(function(o){var p;if(o.ck_data!==""){p=o}else{m.attributes.at_eof=true;p=null}n.resolve(p)});return n}});var e=Backbone.Collection.extend({model:b});var a=Backbone.View.extend({initialize:function(m){this.row_count=0;this.loading_chunk=false;this.header_color="#AAA";this.dark_row_color="#DDD";new d({model:m.model,$el:this.$el})},expand_to_container:function(){if(this.$el.height()<this.scroll_elt.height()){this.attempt_to_fetch()}},attempt_to_fetch:function(n){var m=this;if(!this.loading_chunk&&this.scrolled_to_bottom()){this.loading_chunk=true;this.loading_indicator.show();$.when(m.model.get_next_chunk()).then(function(o){if(o){m._renderChunk(o);m.loading_chunk=false}m.loading_indicator.hide();m.expand_to_container()})}},render:function(){this.loading_indicator=$("<div/>").attr("id","loading_indicator");this.$el.append(this.loading_indicator);var p=$("<table/>").attr({id:"content_table",cellpadding:0});this.$el.append(p);var m=this.model.get_metadata("column_names"),q=$("<tr/>").css("background-color",this.header_color).appendTo(p);if(m){q.append("<th>"+m.join("</th><th>")+"</th>")}var o=this,n=this.model.get("first_data_chunk");if(n){this._renderChunk(n)}else{$.when(o.model.get_next_chunk()).then(function(r){o._renderChunk(r)})}this.scroll_elt.scroll(function(){o.attempt_to_fetch()})},scrolled_to_bottom:function(){return false},_renderCell:function(p,m,q){var n=$("<td>").text(p);var o=this.model.get_metadata("column_types");if(q!==undefined){n.attr("colspan",q).addClass("stringalign")}else{if(o){if(m<o.length){if(o[m]==="str"||o[m]==="list"){n.addClass("stringalign")}}}}return n},_renderRow:function(m){var n=m.split("\t"),p=$("<tr>"),o=this.model.get_metadata("columns");if(this.row_count%2!==0){p.css("background-color",this.dark_row_color)}if(n.length===o){_.each(n,function(r,q){p.append(this._renderCell(r,q))},this)}else{if(n.length>o){_.each(n.slice(0,o-1),function(r,q){p.append(this._renderCell(r,q))},this);p.append(this._renderCell(n.slice(o-1).join("\t"),o-1))}else{if(o>5&&n.length===o-1){_.each(n,function(r,q){p.append(this._renderCell(r,q))},this);p.append($("<td>"))}else{p.append(this._renderCell(m,0,o))}}}this.row_count++;return p},_renderChunk:function(m){var n=this.$el.find("table");_.each(m.ck_data.split("\n"),function(o,p){if(o!==""){n.append(this._renderRow(o))}},this)}});var f=a.extend({initialize:function(m){a.prototype.initialize.call(this,m);scroll_elt=_.find(this.$el.parents(),function(n){return $(n).css("overflow")==="auto"});if(!scroll_elt){scroll_elt=window}this.scroll_elt=$(scroll_elt)},scrolled_to_bottom:function(){return(this.$el.height()-this.scroll_elt.scrollTop()-this.scroll_elt.height()<=0)}});var l=a.extend({initialize:function(m){a.prototype.initialize.call(this,m);this.scroll_elt=this.$el.css({position:"relative",overflow:"scroll",height:this.options.height||"500px"})},scrolled_to_bottom:function(){return this.$el.scrollTop()+this.$el.innerHeight()>=this.el.scrollHeight}});var d=Backbone.View.extend({col:{chrom:null,start:null,end:null},url_viz:null,dataset_id:null,genome_build:null,file_ext:null,initialize:function(o){var r=parent.Galaxy;if(r&&r.modal){this.modal=r.modal}if(r&&r.frame){this.frame=r.frame}if(!this.modal||!this.frame){return}var n=o.model;var q=n.get("metadata");if(!n.get("file_ext")){return}this.file_ext=n.get("file_ext");if(this.file_ext=="bed"){if(q.get("chromCol")&&q.get("startCol")&&q.get("endCol")){this.col.chrom=q.get("chromCol")-1;this.col.start=q.get("startCol")-1;this.col.end=q.get("endCol")-1}else{console.log("TabularButtonTrackster : Bed-file metadata incomplete.");return}}if(this.file_ext=="vcf"){function p(t,u){for(var s=0;s<u.length;s++){if(u[s].match(t)){return s}}return -1}this.col.chrom=p("Chrom",q.get("column_names"));this.col.start=p("Pos",q.get("column_names"));this.col.end=null;if(this.col.chrom==-1||this.col.start==-1){console.log("TabularButtonTrackster : VCF-file metadata incomplete.");return}}if(this.col.chrom===undefined){return}if(n.id){this.dataset_id=n.id}else{console.log("TabularButtonTrackster : Dataset identification is missing.");return}if(n.get("url_viz")){this.url_viz=n.get("url_viz")}else{console.log("TabularButtonTrackster : Url for visualization controller is missing.");return}if(n.get("genome_build")){this.genome_build=n.get("genome_build")}var m=new IconButtonView({model:new IconButton({title:"Visualize",icon_class:"chart_curve",id:"btn_viz"})});this.setElement(o.$el);this.$el.append(m.render().$el);this.hide()},events:{"mouseover tr":"show",mouseleave:"hide"},show:function(r){function q(w){return !isNaN(parseFloat(w))&&isFinite(w)}if(this.col.chrom===null){return}var v=$(r.target).parent();var s=v.children().eq(this.col.chrom).html();var m=v.children().eq(this.col.start).html();var o=this.col.end?v.children().eq(this.col.end).html():m;if(!s.match("^#")&&s!==""&&q(m)){var u={dataset_id:this.dataset_id,gene_region:s+":"+m+"-"+o};var p=v.offset();var n=p.left-10;var t=p.top-$(window).scrollTop()+3;$("#btn_viz").css({position:"fixed",top:t+"px",left:n+"px"});$("#btn_viz").off("click");$("#btn_viz").click(this.create_trackster_action(this.url_viz,u,this.genome_build));$("#btn_viz").show()}else{$("#btn_viz").hide()}},hide:function(){this.$el.find("#btn_viz").hide()},create_trackster_action:function(m,p,o){var n=this;return function(){var q={};if(o){q["f-dbkey"]=o}$.ajax({url:m+"/list_tracks?"+$.param(q),dataType:"html",error:function(){n.modal.show({title:"Something went wrong!",body:"Unfortunately we could not add this dataset to the track browser. Please try again or contact us.",buttons:{Cancel:function(){n.modal.hide()}}})},success:function(r){n.modal.show({title:"View Data in a New or Saved Visualization",buttons:{Cancel:function(){n.modal.hide()},"View in saved visualization":function(){n.modal.show({title:"Add Data to Saved Visualization",body:r,buttons:{Cancel:function(){n.modal.hide()},"Add to visualization":function(){n.modal.hide();n.modal.$el.find("input[name=id]:checked").each(function(){var s=$(this).val();p.id=s;n.frame.add({title:"Trackster",type:"url",content:m+"/trackster?"+$.param(p)})})}}})},"View in new visualization":function(){n.modal.hide();n.frame.add({title:"Trackster",type:"url",content:m+"/trackster?"+$.param(p)})}}})}});return false}}});var k=function(p,n,q,m){var o=new n({model:new p(q)});o.render();if(m){m.append(o.$el)}return o};var c=function(o){if(!o.model){o.model=new h(o.dataset_config)}var n=o.parent_elt;var p=o.embedded;delete o.embedded;delete o.parent_elt;delete o.dataset_config;var m=(p?new l(o):new f(o));m.render();if(n){n.append(m.$el);m.expand_to_container()}return m};return{Dataset:b,TabularDataset:h,DatasetCollection:e,TabularDatasetChunkedView:a,createTabularDatasetChunkedView:c}}); \ No newline at end of file +define(["mvc/ui/ui-modal","mvc/ui/ui-frames","mvc/ui/icon-button"],function(k,j,f){var h=Backbone.Model.extend({});var b=Backbone.Model.extend({defaults:{id:"",type:"",name:"",hda_ldda:"hda",metadata:null},initialize:function(){if(!this.get("metadata")){this._set_metadata()}this.on("change",this._set_metadata,this)},_set_metadata:function(){var n=new h();_.each(_.keys(this.attributes),function(o){if(o.indexOf("metadata_")===0){var p=o.split("metadata_")[1];n.set(p,this.attributes[o]);delete this.attributes[o]}},this);this.set("metadata",n,{silent:true})},get_metadata:function(n){return this.attributes.metadata.get(n)},urlRoot:galaxy_config.root+"api/datasets"});var i=b.extend({defaults:_.extend({},b.prototype.defaults,{chunk_url:null,first_data_chunk:null,chunk_index:-1,at_eof:false}),initialize:function(n){b.prototype.initialize.call(this);this.attributes.chunk_index=(this.attributes.first_data_chunk?1:0);this.attributes.chunk_url=galaxy_config.root+"dataset/display?dataset_id="+this.id;this.attributes.url_viz=galaxy_config.root+"visualization"},get_next_chunk:function(){if(this.attributes.at_eof){return null}var n=this,o=$.Deferred();$.getJSON(this.attributes.chunk_url,{chunk:n.attributes.chunk_index++}).success(function(p){var q;if(p.ck_data!==""){q=p}else{n.attributes.at_eof=true;q=null}o.resolve(q)});return o}});var e=Backbone.Collection.extend({model:b});var a=Backbone.View.extend({initialize:function(n){this.row_count=0;this.loading_chunk=false;this.header_color="#AAA";this.dark_row_color="#DDD";new d({model:n.model,$el:this.$el})},expand_to_container:function(){if(this.$el.height()<this.scroll_elt.height()){this.attempt_to_fetch()}},attempt_to_fetch:function(o){var n=this;if(!this.loading_chunk&&this.scrolled_to_bottom()){this.loading_chunk=true;this.loading_indicator.show();$.when(n.model.get_next_chunk()).then(function(p){if(p){n._renderChunk(p);n.loading_chunk=false}n.loading_indicator.hide();n.expand_to_container()})}},render:function(){this.loading_indicator=$("<div/>").attr("id","loading_indicator");this.$el.append(this.loading_indicator);var q=$("<table/>").attr({id:"content_table",cellpadding:0});this.$el.append(q);var n=this.model.get_metadata("column_names"),r=$("<tr/>").css("background-color",this.header_color).appendTo(q);if(n){r.append("<th>"+n.join("</th><th>")+"</th>")}var p=this,o=this.model.get("first_data_chunk");if(o){this._renderChunk(o)}else{$.when(p.model.get_next_chunk()).then(function(s){p._renderChunk(s)})}this.scroll_elt.scroll(function(){p.attempt_to_fetch()})},scrolled_to_bottom:function(){return false},_renderCell:function(q,n,r){var o=$("<td>").text(q);var p=this.model.get_metadata("column_types");if(r!==undefined){o.attr("colspan",r).addClass("stringalign")}else{if(p){if(n<p.length){if(p[n]==="str"||p[n]==="list"){o.addClass("stringalign")}}}}return o},_renderRow:function(n){var o=n.split("\t"),q=$("<tr>"),p=this.model.get_metadata("columns");if(this.row_count%2!==0){q.css("background-color",this.dark_row_color)}if(o.length===p){_.each(o,function(s,r){q.append(this._renderCell(s,r))},this)}else{if(o.length>p){_.each(o.slice(0,p-1),function(s,r){q.append(this._renderCell(s,r))},this);q.append(this._renderCell(o.slice(p-1).join("\t"),p-1))}else{if(p>5&&o.length===p-1){_.each(o,function(s,r){q.append(this._renderCell(s,r))},this);q.append($("<td>"))}else{q.append(this._renderCell(n,0,p))}}}this.row_count++;return q},_renderChunk:function(n){var o=this.$el.find("table");_.each(n.ck_data.split("\n"),function(p,q){if(p!==""){o.append(this._renderRow(p))}},this)}});var g=a.extend({initialize:function(n){a.prototype.initialize.call(this,n);scroll_elt=_.find(this.$el.parents(),function(o){return $(o).css("overflow")==="auto"});if(!scroll_elt){scroll_elt=window}this.scroll_elt=$(scroll_elt)},scrolled_to_bottom:function(){return(this.$el.height()-this.scroll_elt.scrollTop()-this.scroll_elt.height()<=0)}});var m=a.extend({initialize:function(n){a.prototype.initialize.call(this,n);this.scroll_elt=this.$el.css({position:"relative",overflow:"scroll",height:this.options.height||"500px"})},scrolled_to_bottom:function(){return this.$el.scrollTop()+this.$el.innerHeight()>=this.el.scrollHeight}});var d=Backbone.View.extend({col:{chrom:null,start:null,end:null},url_viz:null,dataset_id:null,genome_build:null,file_ext:null,initialize:function(p){var s=parent.Galaxy;if(s&&s.modal){this.modal=s.modal}if(s&&s.frame){this.frame=s.frame}if(!this.modal||!this.frame){return}var o=p.model;var r=o.get("metadata");if(!o.get("file_ext")){return}this.file_ext=o.get("file_ext");if(this.file_ext=="bed"){if(r.get("chromCol")&&r.get("startCol")&&r.get("endCol")){this.col.chrom=r.get("chromCol")-1;this.col.start=r.get("startCol")-1;this.col.end=r.get("endCol")-1}else{console.log("TabularButtonTrackster : Bed-file metadata incomplete.");return}}if(this.file_ext=="vcf"){function q(u,v){for(var t=0;t<v.length;t++){if(v[t].match(u)){return t}}return -1}this.col.chrom=q("Chrom",r.get("column_names"));this.col.start=q("Pos",r.get("column_names"));this.col.end=null;if(this.col.chrom==-1||this.col.start==-1){console.log("TabularButtonTrackster : VCF-file metadata incomplete.");return}}if(this.col.chrom===undefined){return}if(o.id){this.dataset_id=o.id}else{console.log("TabularButtonTrackster : Dataset identification is missing.");return}if(o.get("url_viz")){this.url_viz=o.get("url_viz")}else{console.log("TabularButtonTrackster : Url for visualization controller is missing.");return}if(o.get("genome_build")){this.genome_build=o.get("genome_build")}var n=new f.IconButtonView({model:new f.IconButton({title:"Visualize",icon_class:"chart_curve",id:"btn_viz"})});this.setElement(p.$el);this.$el.append(n.render().$el);this.hide()},events:{"mouseover tr":"show",mouseleave:"hide"},show:function(s){function r(x){return !isNaN(parseFloat(x))&&isFinite(x)}if(this.col.chrom===null){return}var w=$(s.target).parent();var t=w.children().eq(this.col.chrom).html();var n=w.children().eq(this.col.start).html();var p=this.col.end?w.children().eq(this.col.end).html():n;if(!t.match("^#")&&t!==""&&r(n)){var v={dataset_id:this.dataset_id,gene_region:t+":"+n+"-"+p};var q=w.offset();var o=q.left-10;var u=q.top-$(window).scrollTop()+3;$("#btn_viz").css({position:"fixed",top:u+"px",left:o+"px"});$("#btn_viz").off("click");$("#btn_viz").click(this.create_trackster_action(this.url_viz,v,this.genome_build));$("#btn_viz").show()}else{$("#btn_viz").hide()}},hide:function(){this.$el.find("#btn_viz").hide()},create_trackster_action:function(n,q,p){var o=this;return function(){var r={};if(p){r["f-dbkey"]=p}$.ajax({url:n+"/list_tracks?"+$.param(r),dataType:"html",error:function(){o.modal.show({title:"Something went wrong!",body:"Unfortunately we could not add this dataset to the track browser. Please try again or contact us.",buttons:{Cancel:function(){o.modal.hide()}}})},success:function(s){o.modal.show({title:"View Data in a New or Saved Visualization",buttons:{Cancel:function(){o.modal.hide()},"View in saved visualization":function(){o.modal.show({title:"Add Data to Saved Visualization",body:s,buttons:{Cancel:function(){o.modal.hide()},"Add to visualization":function(){o.modal.hide();o.modal.$el.find("input[name=id]:checked").each(function(){var t=$(this).val();q.id=t;o.frame.add({title:"Trackster",type:"url",content:n+"/trackster?"+$.param(q)})})}}})},"View in new visualization":function(){o.modal.hide();o.frame.add({title:"Trackster",type:"url",content:n+"/trackster?"+$.param(q)})}}})}});return false}}});var l=function(q,o,r,n){var p=new o({model:new q(r)});p.render();if(n){n.append(p.$el)}return p};var c=function(p){if(!p.model){p.model=new i(p.dataset_config)}var o=p.parent_elt;var q=p.embedded;delete p.embedded;delete p.parent_elt;delete p.dataset_config;var n=(q?new m(p):new g(p));n.render();if(o){o.append(n.$el);n.expand_to_container()}return n};return{Dataset:b,TabularDataset:i,DatasetCollection:e,TabularDatasetChunkedView:a,createTabularDatasetChunkedView:c}}); \ No newline at end of file diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 static/scripts/packed/mvc/ui.js --- a/static/scripts/packed/mvc/ui.js +++ /dev/null @@ -1,1 +0,0 @@ -var IconButton=Backbone.Model.extend({defaults:{title:"",icon_class:"",on_click:null,menu_options:null,is_menu_button:true,id:null,href:null,target:null,enabled:true,visible:true,tooltip_config:{}}});var IconButtonView=Backbone.View.extend({initialize:function(){this.model.attributes.tooltip_config={placement:"bottom"};this.model.bind("change",this.render,this)},render:function(){this.$el.tooltip("hide");var a=this.template(this.model.toJSON());a.tooltip(this.model.get("tooltip_config"));this.$el.replaceWith(a);this.setElement(a);return this},events:{click:"click"},click:function(a){if(_.isFunction(this.model.get("on_click"))){this.model.get("on_click")(a);return false}return true},template:function(b){var a='title="'+b.title+'" class="icon-button';if(b.is_menu_button){a+=" menu-button"}a+=" "+b.icon_class;if(!b.enabled){a+="_disabled"}a+='"';if(b.id){a+=' id="'+b.id+'"'}a+=' href="'+b.href+'"';if(b.target){a+=' target="'+b.target+'"'}if(!b.visible){a+=' style="display: none;"'}if(b.enabled){a="<a "+a+"/>"}else{a="<span "+a+"/>"}return $(a)}});var IconButtonCollection=Backbone.Collection.extend({model:IconButton});var IconButtonMenuView=Backbone.View.extend({tagName:"div",initialize:function(){this.render()},render:function(){var a=this;this.collection.each(function(d){var b=$("<a/>").attr("href","javascript:void(0)").attr("title",d.attributes.title).addClass("icon-button menu-button").addClass(d.attributes.icon_class).appendTo(a.$el).click(d.attributes.on_click);if(d.attributes.tooltip_config){b.tooltip(d.attributes.tooltip_config)}var c=d.get("options");if(c){make_popupmenu(b,c)}});return this}});var create_icon_buttons_menu=function(b,a){if(!a){a={}}var c=new IconButtonCollection(_.map(b,function(d){return new IconButton(_.extend(d,a))}));return new IconButtonMenuView({collection:c})}; \ No newline at end of file diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 static/scripts/packed/mvc/ui/icon-button.js --- /dev/null +++ b/static/scripts/packed/mvc/ui/icon-button.js @@ -0,0 +1,1 @@ +define([],function(){var e=Backbone.Model.extend({defaults:{title:"",icon_class:"",on_click:null,menu_options:null,is_menu_button:true,id:null,href:null,target:null,enabled:true,visible:true,tooltip_config:{}}});var d=Backbone.View.extend({initialize:function(){this.model.attributes.tooltip_config={placement:"bottom"};this.model.bind("change",this.render,this)},render:function(){this.$el.tooltip("hide");var f=this.template(this.model.toJSON());f.tooltip(this.model.get("tooltip_config"));this.$el.replaceWith(f);this.setElement(f);return this},events:{click:"click"},click:function(f){if(_.isFunction(this.model.get("on_click"))){this.model.get("on_click")(f);return false}return true},template:function(g){var f='title="'+g.title+'" class="icon-button';if(g.is_menu_button){f+=" menu-button"}f+=" "+g.icon_class;if(!g.enabled){f+="_disabled"}f+='"';if(g.id){f+=' id="'+g.id+'"'}f+=' href="'+g.href+'"';if(g.target){f+=' target="'+g.target+'"'}if(!g.visible){f+=' style="display: none;"'}if(g.enabled){f="<a "+f+"/>"}else{f="<span "+f+"/>"}return $(f)}});var a=Backbone.Collection.extend({model:e});var b=Backbone.View.extend({tagName:"div",initialize:function(){this.render()},render:function(){var f=this;this.collection.each(function(i){var g=$("<a/>").attr("href","javascript:void(0)").attr("title",i.attributes.title).addClass("icon-button menu-button").addClass(i.attributes.icon_class).appendTo(f.$el).click(i.attributes.on_click);if(i.attributes.tooltip_config){g.tooltip(i.attributes.tooltip_config)}var h=i.get("options");if(h){make_popupmenu(g,h)}});return this}});var c=function(g,f){if(!f){f={}}var h=new a(_.map(g,function(i){return new e(_.extend(i,f))}));return new b({collection:h})};return{IconButton:e,IconButtonView:d,IconButtonCollection:a,IconButtonMenuView:b,create_icon_buttons_menu:c}}); \ No newline at end of file diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 static/scripts/packed/viz/circster.js --- a/static/scripts/packed/viz/circster.js +++ b/static/scripts/packed/viz/circster.js @@ -1,1 +1,1 @@ -require(["utils/utils","libs/farbtastic",],function(a){a.cssLoadFile("static/style/circster.css")});define(["libs/underscore","libs/d3","viz/visualization","utils/config"],function(h,m,j,c){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");return 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(Math.abs(p)<1){r=p.toPrecision(o)}else{var q=Math.round(p.toPrecision(o));p=Math.abs(p);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 d=Backbone.Model.extend({});var a=Backbone.View.extend({className:"circster",initialize:function(o){this.genome=o.genome;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);var p=this.model.get("config");p.get("arc_dataset_height").on("change:value",this.update_track_bounds,this);p.get("track_gap").on("change:value",this.update_track_bounds,this)},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 q=this.get_circular_tracks(),s=this.model.get("config").get_value("arc_dataset_height"),r=this.model.get("config").get_value("track_gap"),o=Math.min(this.$el.width(),this.$el.height())-20,u=o/2-q.length*(s+r)+r-this.label_arc_height,t=m.range(u,o/2,s+r);var p=this;return h.map(t,function(v){return[v,v+s]})},render:function(){var x=this,o=x.$el.width(),w=x.$el.height(),t=this.get_circular_tracks(),r=this.get_chord_tracks(),q=x.model.get("config").get_value("total_gap"),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 e({el:p.append("g")[0],track:z,radius_bounds:s[A],genome:x.genome,total_gap:q});y.render();return y});this.chords_views=r.map(function(z){var y=new k({el:p.append("g")[0],track:z,radius_bounds:s[0],genome:x.genome,total_gap:q});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 d(),radius_bounds:u,genome:x.genome,total_gap:q});this.label_track_view.render()},add_track:function(u){var p=this.model.get("config").get_value("total_gap");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:p});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 e({el:m.select("g.tracks").append("g")[0],track:u,radius_bounds:s[r],genome:this.genome,total_gap:p});o.render();this.circular_views.push(o)}},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])})},update_track_bounds:function(){var o=this.get_tracks_bounds();h.each(this.circular_views,function(p,q){p.update_radius_bounds(o[q])});h.each(this.chords_views,function(p){p.update_radius_bounds(o[0])})}});var l=Backbone.View.extend({tagName:"g",initialize:function(o){this.bg_stroke="#ddd";this.loading_bg_fill="#ffc";this.bg_fill="#ddd";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;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(v){var u=h.reject(h.map(v,function(w,x){var y=null,z=q._get_path_function(r[x],w);if(z){y=z(w.data)}return y}),function(w){return w===null});var t=p.get("config").get_value("color");o.each(function(x,w){m.select(this).transition().duration(1000).style("stroke",t).style("fill",t).attr("d",u[w])})})}},_transition_labels:function(){},_update_data_bounds:function(p){var o=this.data_bounds;this.data_bounds=p||this.get_data_bounds(this.track.get("data_manager").get_genome_wide_data(this.genome));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);o.get("config").set_value("min_value",q.data_bounds[0],{silent:true});o.get("config").set_value("max_value",q.data_bounds[1],{silent:true});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=2*Math.PI*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 g=l.extend({initialize:function(o){l.prototype.initialize.call(this,o);var p=this.track.get("config");p.get("min_value").on("change:value",this._update_min_max,this);p.get("max_value").on("change:value",this._update_min_max,this);p.get("color").on("change:value",this._transition_chrom_data,this)},_update_min_max:function(){var p=this.track.get("config"),o=[p.get_value("min_value"),p.get_value("max_value")];this._update_data_bounds(o);this.parent_elt.selectAll(".min_max").text(function(r,q){return o[q]})},_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,q=function(){return"rotate(90)"};var p=this.drawTicks(this.parent_elt,[this.chroms_layout[0]],this._data_bounds_ticks_fn(),q,true).classed("min_max",true);h.each(p,function(r){$(r).click(function(){var s=new c.ConfigSettingCollectionView({collection:o.track.get("config")});s.render_in_modal("Configure Track")})})},_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(g.prototype,i);var e=g.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 f=Backbone.View.extend({initialize:function(){var o=new j.Genome(galaxy_config.app.genome),p=new j.GenomeVisualization(galaxy_config.app.viz_config);p.get("config").add([{key:"arc_dataset_height",label:"Arc Dataset Height",type:"int",value:25,view:"circster"},{key:"track_gap",label:"Gap Between Tracks",type:"int",value:5,view:"circster"},{key:"total_gap",label:"Gap [0-1]",type:"float",value:0.4,view:"circster",hidden:true}]);var r=new a({el:$("#center .unified-panel-body"),genome:o,model:p});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:"gear",title:"Settings",on_click:function(){var s=new c.ConfigSettingCollectionView({collection:p.get("config")});s.render_in_modal("Configure Visualization")}},{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:f}}); \ No newline at end of file +require(["utils/utils","mvc/ui/icon-button","libs/farbtastic",],function(b,a){b.cssLoadFile("static/style/circster.css")});define(["libs/underscore","libs/d3","viz/visualization","utils/config"],function(h,m,j,c){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");return 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(Math.abs(p)<1){r=p.toPrecision(o)}else{var q=Math.round(p.toPrecision(o));p=Math.abs(p);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 d=Backbone.Model.extend({});var a=Backbone.View.extend({className:"circster",initialize:function(o){this.genome=o.genome;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);var p=this.model.get("config");p.get("arc_dataset_height").on("change:value",this.update_track_bounds,this);p.get("track_gap").on("change:value",this.update_track_bounds,this)},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 q=this.get_circular_tracks(),s=this.model.get("config").get_value("arc_dataset_height"),r=this.model.get("config").get_value("track_gap"),o=Math.min(this.$el.width(),this.$el.height())-20,u=o/2-q.length*(s+r)+r-this.label_arc_height,t=m.range(u,o/2,s+r);var p=this;return h.map(t,function(v){return[v,v+s]})},render:function(){var x=this,o=x.$el.width(),w=x.$el.height(),t=this.get_circular_tracks(),r=this.get_chord_tracks(),q=x.model.get("config").get_value("total_gap"),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 e({el:p.append("g")[0],track:z,radius_bounds:s[A],genome:x.genome,total_gap:q});y.render();return y});this.chords_views=r.map(function(z){var y=new k({el:p.append("g")[0],track:z,radius_bounds:s[0],genome:x.genome,total_gap:q});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 d(),radius_bounds:u,genome:x.genome,total_gap:q});this.label_track_view.render()},add_track:function(u){var p=this.model.get("config").get_value("total_gap");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:p});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 e({el:m.select("g.tracks").append("g")[0],track:u,radius_bounds:s[r],genome:this.genome,total_gap:p});o.render();this.circular_views.push(o)}},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])})},update_track_bounds:function(){var o=this.get_tracks_bounds();h.each(this.circular_views,function(p,q){p.update_radius_bounds(o[q])});h.each(this.chords_views,function(p){p.update_radius_bounds(o[0])})}});var l=Backbone.View.extend({tagName:"g",initialize:function(o){this.bg_stroke="#ddd";this.loading_bg_fill="#ffc";this.bg_fill="#ddd";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;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(v){var u=h.reject(h.map(v,function(w,x){var y=null,z=q._get_path_function(r[x],w);if(z){y=z(w.data)}return y}),function(w){return w===null});var t=p.get("config").get_value("color");o.each(function(x,w){m.select(this).transition().duration(1000).style("stroke",t).style("fill",t).attr("d",u[w])})})}},_transition_labels:function(){},_update_data_bounds:function(p){var o=this.data_bounds;this.data_bounds=p||this.get_data_bounds(this.track.get("data_manager").get_genome_wide_data(this.genome));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);o.get("config").set_value("min_value",q.data_bounds[0],{silent:true});o.get("config").set_value("max_value",q.data_bounds[1],{silent:true});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=2*Math.PI*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 g=l.extend({initialize:function(o){l.prototype.initialize.call(this,o);var p=this.track.get("config");p.get("min_value").on("change:value",this._update_min_max,this);p.get("max_value").on("change:value",this._update_min_max,this);p.get("color").on("change:value",this._transition_chrom_data,this)},_update_min_max:function(){var p=this.track.get("config"),o=[p.get_value("min_value"),p.get_value("max_value")];this._update_data_bounds(o);this.parent_elt.selectAll(".min_max").text(function(r,q){return o[q]})},_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,q=function(){return"rotate(90)"};var p=this.drawTicks(this.parent_elt,[this.chroms_layout[0]],this._data_bounds_ticks_fn(),q,true).classed("min_max",true);h.each(p,function(r){$(r).click(function(){var s=new c.ConfigSettingCollectionView({collection:o.track.get("config")});s.render_in_modal("Configure Track")})})},_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(g.prototype,i);var e=g.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 f=Backbone.View.extend({initialize:function(){var o=new j.Genome(galaxy_config.app.genome),p=new j.GenomeVisualization(galaxy_config.app.viz_config);p.get("config").add([{key:"arc_dataset_height",label:"Arc Dataset Height",type:"int",value:25,view:"circster"},{key:"track_gap",label:"Gap Between Tracks",type:"int",value:5,view:"circster"},{key:"total_gap",label:"Gap [0-1]",type:"float",value:0.4,view:"circster",hidden:true}]);var r=new a({el:$("#center .unified-panel-body"),genome:o,model:p});r.render();$("#center .unified-panel-header-inner").append(galaxy_config.app.viz_config.title+" "+galaxy_config.app.viz_config.dbkey);var q=mod_icon_btn.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:"gear",title:"Settings",on_click:function(){var s=new c.ConfigSettingCollectionView({collection:p.get("config")});s.render_in_modal("Configure Visualization")}},{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:f}}); \ No newline at end of file diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 static/scripts/packed/viz/phyloviz.js --- a/static/scripts/packed/viz/phyloviz.js +++ b/static/scripts/packed/viz/phyloviz.js @@ -1,1 +1,1 @@ -define(["libs/d3","viz/visualization","mvc/data"],function(m,f,g){var l=Backbone.View.extend({className:"UserMenuBase",isAcceptableValue:function(q,o,n){var r=q.val(),s=q.attr("displayLabel")||q.attr("id").replace("phyloViz","");function p(t){return !isNaN(parseFloat(t))&&isFinite(t)}if(!p(r)){alert(s+" is not a number!");return false}if(r>n){alert(s+" is too large.");return false}else{if(r<o){alert(s+" is too small.");return false}}return true},hasIllegalJsonCharacters:function(n){if(n.val().search(/"|'|\\/)!==-1){alert("Named fields cannot contain these illegal characters: double quote(\"), single guote('), or back slash(\\). ");return true}return false}});function h(){var w=this,r=m.layout.hierarchy().sort(null).value(null),v=360,q="Linear",u=18,s=200,t=0,p=0.5,n=50;w.leafHeight=function(x){if(typeof x==="undefined"){return u}else{u=x;return w}};w.layoutMode=function(x){if(typeof x==="undefined"){return q}else{q=x;return w}};w.layoutAngle=function(x){if(typeof x==="undefined"){return v}if(isNaN(x)||x<0||x>360){return w}else{v=x;return w}};w.separation=function(x){if(typeof x==="undefined"){return s}else{s=x;return w}};w.links=function(x){return m.layout.tree().links(x)};w.nodes=function(A,y){if(toString.call(A)==="[object Array]"){A=A[0]}var z=r.call(w,A,y),x=[],C=0,B=0;window._d=A;window._nodes=z;z.forEach(function(D){C=D.depth>C?D.depth:C;x.push(D)});x.forEach(function(D){if(!D.children){B+=1;D.depth=C}});u=q==="Circular"?v/B:u;t=0;o(x[0],C,u,null);return x};function o(B,D,A,z){var y=B.children,x=0;var C=B.dist||p;C=C>1?1:C;B.dist=C;if(z!==null){B.y0=z.y0+C*s}else{B.y0=n}if(!y){B.x0=t*A;t+=1}else{y.forEach(function(E){E.parent=B;x+=o(E,D,A,B)});B.x0=x/y.length}B.x=B.x0;B.y=B.y0;return B.x0}return w}var b=f.Visualization.extend({defaults:{layout:"Linear",separation:250,leafHeight:18,type:"phyloviz",title:"Title",scaleFactor:1,translate:[0,0],fontSize:12,selectedNode:null,nodeAttrChangedTime:0},initialize:function(n){this.set("dataset",new g.Dataset({id:n.dataset_id}))},root:{},toggle:function(n){if(typeof n==="undefined"){return}if(n.children){n._children=n.children;n.children=null}else{n.children=n._children;n._children=null}},toggleAll:function(n){if(n.children&&n.children.length!==0){n.children.forEach(this.toggleAll);toggle(n)}},getData:function(){return this.root},save:function(){var n=this.root;o(n);function o(q){delete q.parent;if(q._selected){delete q._selected}if(q.children){q.children.forEach(o)}if(q._children){q._children.forEach(o)}}var p=jQuery.extend(true,{},this.attributes);p.selectedNode=null;show_message("Saving to Galaxy","progress");return $.ajax({url:this.url(),type:"POST",dataType:"json",data:{config:JSON.stringify(p),type:"phyloviz"},success:function(q){hide_modal()}})}});var d=Backbone.View.extend({defaults:{nodeRadius:4.5},stdInit:function(o){var n=this;n.model.on("change:separation change:leafHeight change:fontSize change:nodeAttrChangedTime",n.updateAndRender,n);n.vis=o.vis;n.i=0;n.maxDepth=-1;n.width=o.width;n.height=o.height},updateAndRender:function(p){var o=m.select(".vis"),n=this;p=p||n.model.root;n.renderNodes(p);n.renderLinks(p);n.addTooltips()},renderLinks:function(n){var w=this;var o=w.diagonal;var p=w.duration;var r=w.layoutMode;var t=w.vis.selectAll("g.completeLink").data(w.tree.links(w.nodes),function(x){return x.target.id});var v=function(x){x.pos0=x.source.y0+" "+x.source.x0;x.pos1=x.source.y0+" "+x.target.x0;x.pos2=x.target.y0+" "+x.target.x0};var u=t.enter().insert("svg:g","g.node").attr("class","completeLink");u.append("svg:path").attr("class","link").attr("d",function(x){v(x);return"M "+x.pos0+" L "+x.pos1});var s=t.transition().duration(500);s.select("path.link").attr("d",function(x){v(x);return"M "+x.pos0+" L "+x.pos1+" L "+x.pos2});var q=t.exit().remove()},selectNode:function(o){var n=this;m.selectAll("g.node").classed("selectedHighlight",function(p){if(o.id===p.id){if(o._selected){delete o._selected;return false}else{o._selected=true;return true}}return false});n.model.set("selectedNode",o);$("#phyloVizSelectedNodeName").val(o.name);$("#phyloVizSelectedNodeDist").val(o.dist);$("#phyloVizSelectedNodeAnnotation").val(o.annotation||"")},addTooltips:function(){$(".tooltip").remove();$(".node").attr("data-original-title",function(){var o=this.__data__,n=o.annotation||"None";return o?(o.name?o.name+"<br/>":"")+"Dist: "+o.dist+" <br/>Annotation: "+n:""}).tooltip({placement:"top",trigger:"hover"})}});var a=d.extend({initialize:function(o){var n=this;n.margins=o.margins;n.layoutMode="Linear";n.stdInit(o);n.layout();n.updateAndRender(n.model.root)},layout:function(){var n=this;n.tree=new h().layoutMode("Linear");n.diagonal=m.svg.diagonal().projection(function(o){return[o.y,o.x]})},renderNodes:function(n){var u=this,v=u.model.get("fontSize")+"px";u.tree.separation(u.model.get("separation")).leafHeight(u.model.get("leafHeight"));var q=500,o=u.tree.separation(u.model.get("separation")).nodes(u.model.root);var p=u.vis.selectAll("g.node").data(o,function(w){return w.name+w.id||(w.id=++u.i)});u.nodes=o;u.duration=q;var r=p.enter().append("svg:g").attr("class","node").on("dblclick",function(){m.event.stopPropagation()}).on("click",function(w){if(m.event.altKey){u.selectNode(w)}else{if(w.children&&w.children.length===0){return}u.model.toggle(w);u.updateAndRender(w)}});if(toString.call(n)==="[object Array]"){n=n[0]}r.attr("transform",function(w){return"translate("+n.y0+","+n.x0+")"});r.append("svg:circle").attr("r",0.000001).style("fill",function(w){return w._children?"lightsteelblue":"#fff"});r.append("svg:text").attr("class","nodeLabel").attr("x",function(w){return w.children||w._children?-10:10}).attr("dy",".35em").attr("text-anchor",function(w){return w.children||w._children?"end":"start"}).style("fill-opacity",0.000001);var s=p.transition().duration(q);s.attr("transform",function(w){return"translate("+w.y+","+w.x+")"});s.select("circle").attr("r",u.defaults.nodeRadius).style("fill",function(w){return w._children?"lightsteelblue":"#fff"});s.select("text").style("fill-opacity",1).style("font-size",v).text(function(w){return w.name});var t=p.exit().transition().duration(q).remove();t.select("circle").attr("r",0.000001);t.select("text").style("fill-opacity",0.000001);o.forEach(function(w){w.x0=w.x;w.y0=w.y})}});var j=Backbone.View.extend({className:"phyloviz",initialize:function(o){var n=this;n.MIN_SCALE=0.05;n.MAX_SCALE=5;n.MAX_DISPLACEMENT=500;n.margins=[10,60,10,80];n.width=$("#PhyloViz").width();n.height=$("#PhyloViz").height();n.radius=n.width;n.data=o.data;$(window).resize(function(){n.width=$("#PhyloViz").width();n.height=$("#PhyloViz").height();n.render()});n.phyloTree=new b(o.config);n.phyloTree.root=n.data;n.zoomFunc=m.behavior.zoom().scaleExtent([n.MIN_SCALE,n.MAX_SCALE]);n.zoomFunc.translate(n.phyloTree.get("translate"));n.zoomFunc.scale(n.phyloTree.get("scaleFactor"));n.navMenu=new c(n);n.settingsMenu=new i({phyloTree:n.phyloTree});n.nodeSelectionView=new e({phyloTree:n.phyloTree});n.search=new k();setTimeout(function(){n.zoomAndPan()},1000)},render:function(){var o=this;$("#PhyloViz").empty();o.mainSVG=m.select("#PhyloViz").append("svg:svg").attr("width",o.width).attr("height",o.height).attr("pointer-events","all").call(o.zoomFunc.on("zoom",function(){o.zoomAndPan()}));o.boundingRect=o.mainSVG.append("svg:rect").attr("class","boundingRect").attr("width",o.width).attr("height",o.height).attr("stroke","black").attr("fill","white");o.vis=o.mainSVG.append("svg:g").attr("class","vis");o.layoutOptions={model:o.phyloTree,width:o.width,height:o.height,vis:o.vis,margins:o.margins};$("#title").text("Phylogenetic Tree from "+o.phyloTree.get("title")+":");var n=new a(o.layoutOptions)},zoomAndPan:function(n){var t,p;if(typeof n!=="undefined"){t=n.zoom;p=n.translate}var w=this,r=w.zoomFunc.scale(),v=w.zoomFunc.translate(),s="",u="";switch(t){case"reset":r=1;v=[0,0];break;case"+":r*=1.1;break;case"-":r*=0.9;break;default:if(typeof t==="number"){r=t}else{if(m.event!==null){r=m.event.scale}}}if(r<w.MIN_SCALE||r>w.MAX_SCALE){return}w.zoomFunc.scale(r);s="translate("+w.margins[3]+","+w.margins[0]+") scale("+r+")";if(m.event!==null){u="translate("+m.event.translate+")"}else{if(typeof p!=="undefined"){var q=p.split(",")[0];var o=p.split(",")[1];if(!isNaN(q)&&!isNaN(o)){v=[v[0]+parseFloat(q),v[1]+parseFloat(o)]}}w.zoomFunc.translate(v);u="translate("+v+")"}w.phyloTree.set("scaleFactor",r);w.phyloTree.set("translate",v);w.vis.attr("transform",u+s)},reloadViz:function(){var n=this,o=$("#phylovizNexSelector :selected").val();$.getJSON(n.phyloTree.get("dataset").url(),{tree_index:o,data_type:"raw_data"},function(p){n.data=p.data;n.config=p;n.render()})}});var c=Backbone.View.extend({initialize:function(o){var n=this;n.phylovizView=o;$("#panelHeaderRightBtns").empty();$("#phyloVizNavBtns").empty();$("#phylovizNexSelector").off();n.initNavBtns();n.initRightHeaderBtns();$("#phylovizNexSelector").off().on("change",function(){n.phylovizView.reloadViz()})},initRightHeaderBtns:function(){var n=this;rightMenu=create_icon_buttons_menu([{icon_class:"gear",title:"PhyloViz Settings",on_click:function(){$("#SettingsMenu").show();n.settingsMenu.updateUI()}},{icon_class:"disk",title:"Save visualization",on_click:function(){var o=$("#phylovizNexSelector option:selected").text();if(o){n.phylovizView.phyloTree.set("title",o)}n.phylovizView.phyloTree.save()}},{icon_class:"chevron-expand",title:"Search / Edit Nodes",on_click:function(){$("#nodeSelectionView").show()}},{icon_class:"information",title:"Phyloviz Help",on_click:function(){window.open("https://wiki.galaxyproject.org/Learn/Visualization/PhylogeneticTree")}}],{tooltip_config:{placement:"bottom"}});$("#panelHeaderRightBtns").append(rightMenu.$el)},initNavBtns:function(){var n=this,o=create_icon_buttons_menu([{icon_class:"zoom-in",title:"Zoom in",on_click:function(){n.phylovizView.zoomAndPan({zoom:"+"})}},{icon_class:"zoom-out",title:"Zoom out",on_click:function(){n.phylovizView.zoomAndPan({zoom:"-"})}},{icon_class:"arrow-circle",title:"Reset Zoom/Pan",on_click:function(){n.phylovizView.zoomAndPan({zoom:"reset"})}}],{tooltip_config:{placement:"bottom"}});$("#phyloVizNavBtns").append(o.$el)}});var i=l.extend({className:"Settings",initialize:function(o){var n=this;n.phyloTree=o.phyloTree;n.el=$("#SettingsMenu");n.inputs={separation:$("#phyloVizTreeSeparation"),leafHeight:$("#phyloVizTreeLeafHeight"),fontSize:$("#phyloVizTreeFontSize")};$("#settingsCloseBtn").off().on("click",function(){n.el.hide()});$("#phylovizResetSettingsBtn").off().on("click",function(){n.resetToDefaults()});$("#phylovizApplySettingsBtn").off().on("click",function(){n.apply()})},apply:function(){var n=this;if(!n.isAcceptableValue(n.inputs.separation,50,2500)||!n.isAcceptableValue(n.inputs.leafHeight,5,30)||!n.isAcceptableValue(n.inputs.fontSize,5,20)){return}$.each(n.inputs,function(o,p){n.phyloTree.set(o,p.val())})},updateUI:function(){var n=this;$.each(n.inputs,function(o,p){p.val(n.phyloTree.get(o))})},resetToDefaults:function(){$(".tooltip").remove();var n=this;$.each(n.phyloTree.defaults,function(o,p){n.phyloTree.set(o,p)});n.updateUI()},render:function(){}});var e=l.extend({className:"Settings",initialize:function(o){var n=this;n.el=$("#nodeSelectionView");n.phyloTree=o.phyloTree;n.UI={enableEdit:$("#phylovizEditNodesCheck"),saveChanges:$("#phylovizNodeSaveChanges"),cancelChanges:$("#phylovizNodeCancelChanges"),name:$("#phyloVizSelectedNodeName"),dist:$("#phyloVizSelectedNodeDist"),annotation:$("#phyloVizSelectedNodeAnnotation")};n.valuesOfConcern={name:null,dist:null,annotation:null};$("#nodeSelCloseBtn").off().on("click",function(){n.el.hide()});n.UI.saveChanges.off().on("click",function(){n.updateNodes()});n.UI.cancelChanges.off().on("click",function(){n.cancelChanges()});(function(p){p.fn.enable=function(q){return p(this).each(function(){if(q){p(this).removeAttr("disabled")}else{p(this).attr("disabled","disabled")}})}})(jQuery);n.UI.enableEdit.off().on("click",function(){n.toggleUI()})},toggleUI:function(){var n=this,o=n.UI.enableEdit.is(":checked");if(!o){n.cancelChanges()}$.each(n.valuesOfConcern,function(p,q){n.UI[p].enable(o)});if(o){n.UI.saveChanges.show();n.UI.cancelChanges.show()}else{n.UI.saveChanges.hide();n.UI.cancelChanges.hide()}},cancelChanges:function(){var n=this,o=n.phyloTree.get("selectedNode");if(o){$.each(n.valuesOfConcern,function(p,q){n.UI[p].val(o[p])})}},updateNodes:function(){var n=this,o=n.phyloTree.get("selectedNode");if(o){if(!n.isAcceptableValue(n.UI.dist,0,1)||n.hasIllegalJsonCharacters(n.UI.name)||n.hasIllegalJsonCharacters(n.UI.annotation)){return}$.each(n.valuesOfConcern,function(p,q){(o[p])=n.UI[p].val()});n.phyloTree.set("nodeAttrChangedTime",new Date())}else{alert("No node selected")}}});var k=l.extend({initialize:function(){var n=this;$("#phyloVizSearchBtn").on("click",function(){var p=$("#phyloVizSearchTerm"),q=$("#phyloVizSearchCondition").val().split("-"),o=q[0],r=q[1];n.hasIllegalJsonCharacters(p);if(o==="dist"){n.isAcceptableValue(p,0,1)}n.searchTree(o,r,p.val())})},searchTree:function(n,p,o){m.selectAll("g.node").classed("searchHighlight",function(r){var q=r[n];if(typeof q!=="undefined"&&q!==null){if(n==="dist"){switch(p){case"greaterEqual":return q>=+o;case"lesserEqual":return q<=+o;default:return}}else{if(n==="name"||n==="annotation"){return q.toLowerCase().indexOf(o.toLowerCase())!==-1}}}})}});return{PhylovizView:j}}); \ No newline at end of file +define(["libs/d3","viz/visualization","mvc/data","mvc/ui/icon-button"],function(n,g,h,c){var m=Backbone.View.extend({className:"UserMenuBase",isAcceptableValue:function(r,p,o){var s=r.val(),t=r.attr("displayLabel")||r.attr("id").replace("phyloViz","");function q(u){return !isNaN(parseFloat(u))&&isFinite(u)}if(!q(s)){alert(t+" is not a number!");return false}if(s>o){alert(t+" is too large.");return false}else{if(s<p){alert(t+" is too small.");return false}}return true},hasIllegalJsonCharacters:function(o){if(o.val().search(/"|'|\\/)!==-1){alert("Named fields cannot contain these illegal characters: double quote(\"), single guote('), or back slash(\\). ");return true}return false}});function i(){var x=this,s=n.layout.hierarchy().sort(null).value(null),w=360,r="Linear",v=18,t=200,u=0,q=0.5,o=50;x.leafHeight=function(y){if(typeof y==="undefined"){return v}else{v=y;return x}};x.layoutMode=function(y){if(typeof y==="undefined"){return r}else{r=y;return x}};x.layoutAngle=function(y){if(typeof y==="undefined"){return w}if(isNaN(y)||y<0||y>360){return x}else{w=y;return x}};x.separation=function(y){if(typeof y==="undefined"){return t}else{t=y;return x}};x.links=function(y){return n.layout.tree().links(y)};x.nodes=function(B,z){if(toString.call(B)==="[object Array]"){B=B[0]}var A=s.call(x,B,z),y=[],D=0,C=0;window._d=B;window._nodes=A;A.forEach(function(E){D=E.depth>D?E.depth:D;y.push(E)});y.forEach(function(E){if(!E.children){C+=1;E.depth=D}});v=r==="Circular"?w/C:v;u=0;p(y[0],D,v,null);return y};function p(C,E,B,A){var z=C.children,y=0;var D=C.dist||q;D=D>1?1:D;C.dist=D;if(A!==null){C.y0=A.y0+D*t}else{C.y0=o}if(!z){C.x0=u*B;u+=1}else{z.forEach(function(F){F.parent=C;y+=p(F,E,B,C)});C.x0=y/z.length}C.x=C.x0;C.y=C.y0;return C.x0}return x}var b=g.Visualization.extend({defaults:{layout:"Linear",separation:250,leafHeight:18,type:"phyloviz",title:"Title",scaleFactor:1,translate:[0,0],fontSize:12,selectedNode:null,nodeAttrChangedTime:0},initialize:function(o){this.set("dataset",new h.Dataset({id:o.dataset_id}))},root:{},toggle:function(o){if(typeof o==="undefined"){return}if(o.children){o._children=o.children;o.children=null}else{o.children=o._children;o._children=null}},toggleAll:function(o){if(o.children&&o.children.length!==0){o.children.forEach(this.toggleAll);toggle(o)}},getData:function(){return this.root},save:function(){var o=this.root;p(o);function p(r){delete r.parent;if(r._selected){delete r._selected}if(r.children){r.children.forEach(p)}if(r._children){r._children.forEach(p)}}var q=jQuery.extend(true,{},this.attributes);q.selectedNode=null;show_message("Saving to Galaxy","progress");return $.ajax({url:this.url(),type:"POST",dataType:"json",data:{config:JSON.stringify(q),type:"phyloviz"},success:function(r){hide_modal()}})}});var e=Backbone.View.extend({defaults:{nodeRadius:4.5},stdInit:function(p){var o=this;o.model.on("change:separation change:leafHeight change:fontSize change:nodeAttrChangedTime",o.updateAndRender,o);o.vis=p.vis;o.i=0;o.maxDepth=-1;o.width=p.width;o.height=p.height},updateAndRender:function(q){var p=n.select(".vis"),o=this;q=q||o.model.root;o.renderNodes(q);o.renderLinks(q);o.addTooltips()},renderLinks:function(o){var x=this;var p=x.diagonal;var q=x.duration;var s=x.layoutMode;var u=x.vis.selectAll("g.completeLink").data(x.tree.links(x.nodes),function(y){return y.target.id});var w=function(y){y.pos0=y.source.y0+" "+y.source.x0;y.pos1=y.source.y0+" "+y.target.x0;y.pos2=y.target.y0+" "+y.target.x0};var v=u.enter().insert("svg:g","g.node").attr("class","completeLink");v.append("svg:path").attr("class","link").attr("d",function(y){w(y);return"M "+y.pos0+" L "+y.pos1});var t=u.transition().duration(500);t.select("path.link").attr("d",function(y){w(y);return"M "+y.pos0+" L "+y.pos1+" L "+y.pos2});var r=u.exit().remove()},selectNode:function(p){var o=this;n.selectAll("g.node").classed("selectedHighlight",function(q){if(p.id===q.id){if(p._selected){delete p._selected;return false}else{p._selected=true;return true}}return false});o.model.set("selectedNode",p);$("#phyloVizSelectedNodeName").val(p.name);$("#phyloVizSelectedNodeDist").val(p.dist);$("#phyloVizSelectedNodeAnnotation").val(p.annotation||"")},addTooltips:function(){$(".tooltip").remove();$(".node").attr("data-original-title",function(){var p=this.__data__,o=p.annotation||"None";return p?(p.name?p.name+"<br/>":"")+"Dist: "+p.dist+" <br/>Annotation: "+o:""}).tooltip({placement:"top",trigger:"hover"})}});var a=e.extend({initialize:function(p){var o=this;o.margins=p.margins;o.layoutMode="Linear";o.stdInit(p);o.layout();o.updateAndRender(o.model.root)},layout:function(){var o=this;o.tree=new i().layoutMode("Linear");o.diagonal=n.svg.diagonal().projection(function(p){return[p.y,p.x]})},renderNodes:function(o){var v=this,w=v.model.get("fontSize")+"px";v.tree.separation(v.model.get("separation")).leafHeight(v.model.get("leafHeight"));var r=500,p=v.tree.separation(v.model.get("separation")).nodes(v.model.root);var q=v.vis.selectAll("g.node").data(p,function(x){return x.name+x.id||(x.id=++v.i)});v.nodes=p;v.duration=r;var s=q.enter().append("svg:g").attr("class","node").on("dblclick",function(){n.event.stopPropagation()}).on("click",function(x){if(n.event.altKey){v.selectNode(x)}else{if(x.children&&x.children.length===0){return}v.model.toggle(x);v.updateAndRender(x)}});if(toString.call(o)==="[object Array]"){o=o[0]}s.attr("transform",function(x){return"translate("+o.y0+","+o.x0+")"});s.append("svg:circle").attr("r",0.000001).style("fill",function(x){return x._children?"lightsteelblue":"#fff"});s.append("svg:text").attr("class","nodeLabel").attr("x",function(x){return x.children||x._children?-10:10}).attr("dy",".35em").attr("text-anchor",function(x){return x.children||x._children?"end":"start"}).style("fill-opacity",0.000001);var t=q.transition().duration(r);t.attr("transform",function(x){return"translate("+x.y+","+x.x+")"});t.select("circle").attr("r",v.defaults.nodeRadius).style("fill",function(x){return x._children?"lightsteelblue":"#fff"});t.select("text").style("fill-opacity",1).style("font-size",w).text(function(x){return x.name});var u=q.exit().transition().duration(r).remove();u.select("circle").attr("r",0.000001);u.select("text").style("fill-opacity",0.000001);p.forEach(function(x){x.x0=x.x;x.y0=x.y})}});var k=Backbone.View.extend({className:"phyloviz",initialize:function(p){var o=this;o.MIN_SCALE=0.05;o.MAX_SCALE=5;o.MAX_DISPLACEMENT=500;o.margins=[10,60,10,80];o.width=$("#PhyloViz").width();o.height=$("#PhyloViz").height();o.radius=o.width;o.data=p.data;$(window).resize(function(){o.width=$("#PhyloViz").width();o.height=$("#PhyloViz").height();o.render()});o.phyloTree=new b(p.config);o.phyloTree.root=o.data;o.zoomFunc=n.behavior.zoom().scaleExtent([o.MIN_SCALE,o.MAX_SCALE]);o.zoomFunc.translate(o.phyloTree.get("translate"));o.zoomFunc.scale(o.phyloTree.get("scaleFactor"));o.navMenu=new d(o);o.settingsMenu=new j({phyloTree:o.phyloTree});o.nodeSelectionView=new f({phyloTree:o.phyloTree});o.search=new l();setTimeout(function(){o.zoomAndPan()},1000)},render:function(){var p=this;$("#PhyloViz").empty();p.mainSVG=n.select("#PhyloViz").append("svg:svg").attr("width",p.width).attr("height",p.height).attr("pointer-events","all").call(p.zoomFunc.on("zoom",function(){p.zoomAndPan()}));p.boundingRect=p.mainSVG.append("svg:rect").attr("class","boundingRect").attr("width",p.width).attr("height",p.height).attr("stroke","black").attr("fill","white");p.vis=p.mainSVG.append("svg:g").attr("class","vis");p.layoutOptions={model:p.phyloTree,width:p.width,height:p.height,vis:p.vis,margins:p.margins};$("#title").text("Phylogenetic Tree from "+p.phyloTree.get("title")+":");var o=new a(p.layoutOptions)},zoomAndPan:function(o){var u,q;if(typeof o!=="undefined"){u=o.zoom;q=o.translate}var z=this,s=z.zoomFunc.scale(),w=z.zoomFunc.translate(),t="",v="";switch(u){case"reset":s=1;w=[0,0];break;case"+":s*=1.1;break;case"-":s*=0.9;break;default:if(typeof u==="number"){s=u}else{if(n.event!==null){s=n.event.scale}}}if(s<z.MIN_SCALE||s>z.MAX_SCALE){return}z.zoomFunc.scale(s);t="translate("+z.margins[3]+","+z.margins[0]+") scale("+s+")";if(n.event!==null){v="translate("+n.event.translate+")"}else{if(typeof q!=="undefined"){var r=q.split(",")[0];var p=q.split(",")[1];if(!isNaN(r)&&!isNaN(p)){w=[w[0]+parseFloat(r),w[1]+parseFloat(p)]}}z.zoomFunc.translate(w);v="translate("+w+")"}z.phyloTree.set("scaleFactor",s);z.phyloTree.set("translate",w);z.vis.attr("transform",v+t)},reloadViz:function(){var o=this,p=$("#phylovizNexSelector :selected").val();$.getJSON(o.phyloTree.get("dataset").url(),{tree_index:p,data_type:"raw_data"},function(q){o.data=q.data;o.config=q;o.render()})}});var d=Backbone.View.extend({initialize:function(p){var o=this;o.phylovizView=p;$("#panelHeaderRightBtns").empty();$("#phyloVizNavBtns").empty();$("#phylovizNexSelector").off();o.initNavBtns();o.initRightHeaderBtns();$("#phylovizNexSelector").off().on("change",function(){o.phylovizView.reloadViz()})},initRightHeaderBtns:function(){var o=this;rightMenu=c.create_icon_buttons_menu([{icon_class:"gear",title:"PhyloViz Settings",on_click:function(){$("#SettingsMenu").show();o.settingsMenu.updateUI()}},{icon_class:"disk",title:"Save visualization",on_click:function(){var p=$("#phylovizNexSelector option:selected").text();if(p){o.phylovizView.phyloTree.set("title",p)}o.phylovizView.phyloTree.save()}},{icon_class:"chevron-expand",title:"Search / Edit Nodes",on_click:function(){$("#nodeSelectionView").show()}},{icon_class:"information",title:"Phyloviz Help",on_click:function(){window.open("https://wiki.galaxyproject.org/Learn/Visualization/PhylogeneticTree")}}],{tooltip_config:{placement:"bottom"}});$("#panelHeaderRightBtns").append(rightMenu.$el)},initNavBtns:function(){var o=this,p=c.create_icon_buttons_menu([{icon_class:"zoom-in",title:"Zoom in",on_click:function(){o.phylovizView.zoomAndPan({zoom:"+"})}},{icon_class:"zoom-out",title:"Zoom out",on_click:function(){o.phylovizView.zoomAndPan({zoom:"-"})}},{icon_class:"arrow-circle",title:"Reset Zoom/Pan",on_click:function(){o.phylovizView.zoomAndPan({zoom:"reset"})}}],{tooltip_config:{placement:"bottom"}});$("#phyloVizNavBtns").append(p.$el)}});var j=m.extend({className:"Settings",initialize:function(p){var o=this;o.phyloTree=p.phyloTree;o.el=$("#SettingsMenu");o.inputs={separation:$("#phyloVizTreeSeparation"),leafHeight:$("#phyloVizTreeLeafHeight"),fontSize:$("#phyloVizTreeFontSize")};$("#settingsCloseBtn").off().on("click",function(){o.el.hide()});$("#phylovizResetSettingsBtn").off().on("click",function(){o.resetToDefaults()});$("#phylovizApplySettingsBtn").off().on("click",function(){o.apply()})},apply:function(){var o=this;if(!o.isAcceptableValue(o.inputs.separation,50,2500)||!o.isAcceptableValue(o.inputs.leafHeight,5,30)||!o.isAcceptableValue(o.inputs.fontSize,5,20)){return}$.each(o.inputs,function(p,q){o.phyloTree.set(p,q.val())})},updateUI:function(){var o=this;$.each(o.inputs,function(p,q){q.val(o.phyloTree.get(p))})},resetToDefaults:function(){$(".tooltip").remove();var o=this;$.each(o.phyloTree.defaults,function(p,q){o.phyloTree.set(p,q)});o.updateUI()},render:function(){}});var f=m.extend({className:"Settings",initialize:function(p){var o=this;o.el=$("#nodeSelectionView");o.phyloTree=p.phyloTree;o.UI={enableEdit:$("#phylovizEditNodesCheck"),saveChanges:$("#phylovizNodeSaveChanges"),cancelChanges:$("#phylovizNodeCancelChanges"),name:$("#phyloVizSelectedNodeName"),dist:$("#phyloVizSelectedNodeDist"),annotation:$("#phyloVizSelectedNodeAnnotation")};o.valuesOfConcern={name:null,dist:null,annotation:null};$("#nodeSelCloseBtn").off().on("click",function(){o.el.hide()});o.UI.saveChanges.off().on("click",function(){o.updateNodes()});o.UI.cancelChanges.off().on("click",function(){o.cancelChanges()});(function(q){q.fn.enable=function(r){return q(this).each(function(){if(r){q(this).removeAttr("disabled")}else{q(this).attr("disabled","disabled")}})}})(jQuery);o.UI.enableEdit.off().on("click",function(){o.toggleUI()})},toggleUI:function(){var o=this,p=o.UI.enableEdit.is(":checked");if(!p){o.cancelChanges()}$.each(o.valuesOfConcern,function(q,r){o.UI[q].enable(p)});if(p){o.UI.saveChanges.show();o.UI.cancelChanges.show()}else{o.UI.saveChanges.hide();o.UI.cancelChanges.hide()}},cancelChanges:function(){var o=this,p=o.phyloTree.get("selectedNode");if(p){$.each(o.valuesOfConcern,function(q,r){o.UI[q].val(p[q])})}},updateNodes:function(){var o=this,p=o.phyloTree.get("selectedNode");if(p){if(!o.isAcceptableValue(o.UI.dist,0,1)||o.hasIllegalJsonCharacters(o.UI.name)||o.hasIllegalJsonCharacters(o.UI.annotation)){return}$.each(o.valuesOfConcern,function(q,r){(p[q])=o.UI[q].val()});o.phyloTree.set("nodeAttrChangedTime",new Date())}else{alert("No node selected")}}});var l=m.extend({initialize:function(){var o=this;$("#phyloVizSearchBtn").on("click",function(){var q=$("#phyloVizSearchTerm"),r=$("#phyloVizSearchCondition").val().split("-"),p=r[0],s=r[1];o.hasIllegalJsonCharacters(q);if(p==="dist"){o.isAcceptableValue(q,0,1)}o.searchTree(p,s,q.val())})},searchTree:function(o,q,p){n.selectAll("g.node").classed("searchHighlight",function(s){var r=s[o];if(typeof r!=="undefined"&&r!==null){if(o==="dist"){switch(q){case"greaterEqual":return r>=+p;case"lesserEqual":return r<=+p;default:return}}else{if(o==="name"||o==="annotation"){return r.toLowerCase().indexOf(p.toLowerCase())!==-1}}}})}});return{PhylovizView:k}}); \ No newline at end of file diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 static/scripts/packed/viz/sweepster.js --- a/static/scripts/packed/viz/sweepster.js +++ b/static/scripts/packed/viz/sweepster.js @@ -1,1 +1,1 @@ -define(["libs/underscore","libs/d3","viz/trackster/util","viz/visualization","viz/trackster/tracks","mvc/tools","mvc/data","utils/config"],function(q,p,e,j,m,n,r,o){var k=Backbone.Model.extend({defaults:{inputs:null,values:null}});var a=Backbone.Model.extend({defaults:{tool:null,tree_data:null},initialize:function(t){var s=this;this.get("tool").get("inputs").each(function(u){u.on("change:min change:max change:num_samples",function(v){if(v.get("in_ptree")){s.set_tree_data()}},s);u.on("change:in_ptree",function(v){if(v.get("in_ptree")){s.add_param(v)}else{s.remove_param(v)}s.set_tree_data()},s)});if(t.config){q.each(t.config,function(v){var u=s.get("tool").get("inputs").find(function(w){return w.get("name")===v.name});s.add_param(u);u.set(v)})}},add_param:function(s){if(s.get("ptree_index")){return}s.set("in_ptree",true);s.set("ptree_index",this.get_tree_params().length)},remove_param:function(s){s.set("in_ptree",false);s.set("ptree_index",null);q(this.get_tree_params()).each(function(t,u){t.set("ptree_index",u+1)})},set_tree_data:function(){var t=q.map(this.get_tree_params(),function(v){return{param:v,samples:v.get_samples()}});var s=0,u=function(y,v){var A=y[v],z=A.param,x=z.get("label"),w=A.samples;if(y.length-1===v){return q.map(w,function(B){return{id:s++,name:B,param:z,value:B}})}return q.map(w,function(B){return{id:s++,name:B,param:z,value:B,children:u(y,v+1)}})};this.set("tree_data",{name:"Root",id:s++,children:(t.length!==0?u(t,0):null)})},get_tree_params:function(){return q(this.get("tool").get("inputs").where({in_ptree:true})).sortBy(function(s){return s.get("ptree_index")})},get_num_leaves:function(){return this.get_tree_params().reduce(function(s,t){return s*t.get_samples().length},1)},get_node_settings:function(w){var u=this.get("tool").get_inputs_dict();var x=w.parent;if(x){while(x.depth!==0){u[x.param.get("name")]=x.value;x=x.parent}}var s=this,t=function(z,y){if(z.param){y[z.param.get("name")]=z.value}if(!z.children){return new k({inputs:s.get("tool").get("inputs"),values:y})}else{return q.flatten(q.map(z.children,function(A){return t(A,q.clone(y))}))}},v=t(w,u);if(!q.isArray(v)){v=[v]}return v},get_connected_nodes:function(u){var v=function(w){if(!w.children){return w}else{return q.flatten([w,q.map(w.children,function(x){return v(x)})])}};var t=[],s=u.parent;while(s){t.push(s);s=s.parent}return q.flatten([t,v(u)])},get_leaf:function(t){var u=this.get("tree_data"),s=function(v){return q.find(v,function(w){return t[w.param.get("name")]===w.value})};while(u.children){u=s(u.children)}return u},toJSON:function(){return this.get_tree_params().map(function(s){return{name:s.get("name"),min:s.get("min"),max:s.get("max"),num_samples:s.get("num_samples")}})}});var d=Backbone.Model.extend({defaults:{track:null,mode:"Pack",settings:null,regions:null},initialize:function(s){this.set("regions",s.regions);if(s.track){var t=q.extend({data_url:galaxy_config.root+"dummy1",converted_datasets_state_url:galaxy_config.root+"dummy2"},s.track);this.set("track",m.object_from_template(t,{},null))}},same_settings:function(s){var t=this.get("settings"),u=s.get("settings");for(var v in t){if(!u[v]||t[v]!==u[v]){return false}}return true},toJSON:function(){return{track:this.get("track").to_dict(),settings:this.get("settings"),regions:this.get("regions")}}});var l=Backbone.Collection.extend({model:d});var c=j.Visualization.extend({defaults:q.extend({},j.Visualization.prototype.defaults,{dataset:null,tool:null,parameter_tree:null,regions:null,tracks:null,default_mode:"Pack"}),initialize:function(s){this.set("dataset",new r.Dataset(s.dataset));this.set("tool",new n.Tool(s.tool));this.set("regions",new j.GenomeRegionCollection(s.regions));this.set("tracks",new l(s.tracks));var t=this.get("tool");this.set("tool_with_samplable_inputs",t);t.remove_inputs(["data","hidden_data","conditional","text"]);this.set("parameter_tree",new a({tool:t,config:s.tree_config}))},add_track:function(s){this.get("tracks").add(s)},toJSON:function(){return{id:this.get("id"),title:"Parameter exploration for dataset '"+this.get("dataset").get("name")+"'",type:"sweepster",dataset_id:this.get("dataset").id,tool_id:this.get("tool").id,regions:this.get("regions").toJSON(),tree_config:this.get("parameter_tree").toJSON(),tracks:this.get("tracks").toJSON()}}});var h=Backbone.View.extend({tagName:"tr",TILE_LEN:250,initialize:function(s){this.canvas_manager=s.canvas_manager;this.render();this.model.on("change:track change:mode",this.draw_tiles,this)},render:function(){var x=this.model.get("settings"),t=x.get("values"),v=$("<td/>").addClass("settings").appendTo(this.$el),u=$("<div/>").addClass("track-info").hide().appendTo(v);u.append($("<div/>").css("font-weight","bold").text("Track Settings"));x.get("inputs").each(function(z){u.append(z.get("label")+": "+t[z.get("name")]+"<br/>")});var s=this,y=$("<button/>").appendTo(u).text("Run on complete dataset").click(function(){u.toggle();s.trigger("run_on_dataset",x)});var w=create_icon_buttons_menu([{title:"Settings",icon_class:"gear track-settings",on_click:function(){u.toggle()}},{title:"Remove",icon_class:"cross-circle",on_click:function(){s.$el.remove();$(".tooltip").remove()}}]);v.prepend(w.$el);this.model.get("regions").each(function(){s.$el.append($("<td/>").addClass("tile").html($("<img/>").attr("src",galaxy_config.root+"images/loading_large_white_bg.gif")))});if(this.model.get("track")){this.draw_tiles()}},draw_tiles:function(){var t=this,s=this.model.get("track"),v=this.model.get("regions"),u=this.$el.find("td.tile");if(!s){return}$.when(s.data_manager.data_is_ready()).then(function(w){v.each(function(z,y){var x=z.length()/t.TILE_LEN,B=1/x,A=t.model.get("mode");$.when(s.data_manager.get_data(z,A,x,{})).then(function(D){var C=t.canvas_manager.new_canvas();C.width=t.TILE_LEN;C.height=s.get_canvas_height(D,A,B,C.width);s.draw_tile(D,C.getContext("2d"),A,z,B);$(u[y]).empty().append(C)})})})}});var g=Backbone.View.extend({number_input_template:'<div class="form-row-input sweep"><input class="min" type="text" size="6" value="<%= min %>"> - <input class="max" type="text" size="6" value="<%= max %>"> samples: <input class="num_samples" type="text" size="1" value="<%= num_samples %>"></div>',select_input_template:'<div class="form-row-input sweep"><%= options %></div>',initialize:function(s){this.$el=s.tool_row;this.render()},render:function(){var t=this.model,x=t.get("type"),z=this.$el.find(".form-row-input"),v=null;z.find(":input").change(function(){t.set("value",$(this).val())});if(t instanceof n.IntegerToolParameter){v=$(q.template(this.number_input_template,this.model.toJSON()))}else{if(t instanceof n.SelectToolParameter){var u=q.map(this.$el.find("select option"),function(A){return $(A).val()}),w=u.join(", ");v=$(q.template(this.select_input_template,{options:w}))}}v.insertAfter(z);var s=this,y=create_icon_buttons_menu([{title:"Add parameter to tree",icon_class:"plus-button",on_click:function(){t.set("in_ptree",true);z.hide();v.show();$(this).hide();s.$el.find(".icon-button.toggle").show()}},{title:"Remove parameter from tree",icon_class:"toggle",on_click:function(){t.set("in_ptree",false);v.hide();z.show();$(this).hide();s.$el.find(".icon-button.plus-button").show()}}],{});this.$el.prepend(y.$el);if(t.get("in_ptree")){z.hide();s.$el.find(".icon-button.plus-button").hide()}else{s.$el.find(".icon-button.toggle").hide();v.hide()}q.each(["min","max","num_samples"],function(A){v.find("."+A).change(function(){t.set(A,parseFloat($(this).val()))})})}});var i=Backbone.View.extend({className:"tree-design",initialize:function(s){this.render()},render:function(){var u=new n.ToolFormView({model:this.model.get("tool")});u.render();this.$el.append(u.$el);var t=this,s=t.model.get("tool").get("inputs");this.$el.find(".form-row").not(".form-actions").each(function(v){var w=new g({model:s.at(v),tool_row:$(this)})})}});var b=Backbone.View.extend({className:"tool-parameter-tree",initialize:function(s){this.model.on("change:tree_data",this.render,this)},render:function(){this.$el.children().remove();var A=this.model.get_tree_params();if(!A.length){return}this.width=100*(2+A.length);this.height=15*this.model.get_num_leaves();var z=this;var y=p.layout.cluster().size([this.height,this.width-160]);var u=p.svg.diagonal().projection(function(B){return[B.y,B.x]});var s=y.nodes(this.model.get("tree_data"));var v=q.uniq(q.pluck(s,"y"));q.each(A,function(D,C){var B=v[C+1],E=$("#center").position().left;z.$el.append($("<div>").addClass("label").text(D.get("label")).css("left",B+E))});var t=p.select(this.$el[0]).append("svg").attr("width",this.width).attr("height",this.height+30).append("g").attr("transform","translate(40, 20)");var x=t.selectAll("path.link").data(y.links(s)).enter().append("path").attr("class","link").attr("d",u);var w=t.selectAll("g.node").data(s).enter().append("g").attr("class","node").attr("transform",function(B){return"translate("+B.y+","+B.x+")"}).on("mouseover",function(C){var B=q.pluck(z.model.get_connected_nodes(C),"id");w.filter(function(D){return q.find(B,function(E){return E===D.id})!==undefined}).style("fill","#f00")}).on("mouseout",function(){w.style("fill","#000")});w.append("circle").attr("r",9);w.append("text").attr("dx",function(B){return B.children?-12:12}).attr("dy",3).attr("text-anchor",function(B){return B.children?"end":"start"}).text(function(B){return B.name})}});var f=Backbone.View.extend({className:"Sweepster",helpText:"<div><h4>Getting Started</h4><ol><li>Create a parameter tree by using the icons next to the tool's parameter names to add or remove parameters.<li>Adjust the tree by using parameter inputs to select min, max, and number of samples<li>Run the tool with different settings by clicking on tree nodes</ol></div>",initialize:function(t){this.canvas_manager=new j.CanvasManager(this.$el.parents("body"));this.tool_param_tree_view=new b({model:this.model.get("parameter_tree")});this.track_collection_container=$("<table/>").addClass("tracks");this.model.get("parameter_tree").on("change:tree_data",this.handle_node_clicks,this);var s=this;this.model.get("tracks").each(function(u){u.get("track").view=s});this.config=o.ConfigSettingCollection.from_models_and_saved_values([{key:"name",label:"Name",type:"text",default_value:""},{key:"a_color",label:"A Color",type:"color",default_value:"#FF0000"},{key:"c_color",label:"C Color",type:"color",default_value:"#00FF00"},{key:"g_color",label:"G Color",type:"color",default_value:"#0000FF"},{key:"t_color",label:"T Color",type:"color",default_value:"#FF00FF"},{key:"n_color",label:"N Color",type:"color",default_value:"#AAAAAA"},{key:"block_color",label:"Block color",type:"color"},{key:"reverse_strand_color",label:"Antisense strand color",type:"color"},],{})},render:function(){var y=new i({model:this.model.get("parameter_tree")});$("#left").append(y.$el);var B=this,v=B.model.get("regions"),z=$("<tr/>").appendTo(this.track_collection_container);v.each(function(C){z.append($("<th>").text(C.toString()))});z.children().first().attr("colspan",2);var w=$("<div>").addClass("tiles");$("#right").append(w.append(this.track_collection_container));B.model.get("tracks").each(function(C){B.add_track(C)});var A=$(this.helpText).addClass("help"),x=create_icon_buttons_menu([{title:"Close",icon_class:"cross-circle",on_click:function(){$(".tooltip").remove();A.remove()}}]);A.prepend(x.$el.css("float","right"));$("#center").append(A);this.tool_param_tree_view.render();$("#center").append(this.tool_param_tree_view.$el);this.handle_node_clicks();var u=create_icon_buttons_menu([{icon_class:"chevron-expand",title:"Set display mode"},{icon_class:"cross-circle",title:"Close",on_click:function(){window.location="${h.url_for( controller='visualization', action='list' )}"}}],{tooltip_config:{placement:"bottom"}});var t=["Squish","Pack"],s={};q.each(t,function(C){s[C]=function(){B.model.set("default_mode",C);B.model.get("tracks").each(function(D){D.set("mode",C)})}});make_popupmenu(u.$el.find(".chevron-expand"),s);u.$el.attr("style","float: right");$("#right .unified-panel-header-inner").append(u.$el)},get_base_color:function(s){return this.config.get_value(s.toLowerCase()+"_color")||this.config.get_value("n_color")},run_tool_on_dataset:function(t){var s=this.model.get("tool"),v=s.get("name"),u=this.model.get("dataset");s.set_input_values(t.get("values"));$.when(s.rerun(u)).then(function(w){});show_modal("Running "+v+" on complete dataset",v+" is running on dataset '"+u.get("name")+"'. Outputs are in the dataset's history.",{Ok:function(){hide_modal()}})},add_track:function(v){var t=this,u=this.model.get("parameter_tree");t.model.add_track(v);var s=new h({model:v,canvas_manager:t.canvas_manager});s.on("run_on_dataset",t.run_tool_on_dataset,t);t.track_collection_container.append(s.$el);s.$el.hover(function(){var x=u.get_leaf(v.get("settings").get("values"));var w=q.pluck(u.get_connected_nodes(x),"id");p.select(t.tool_param_tree_view.$el[0]).selectAll("g.node").filter(function(y){return q.find(w,function(z){return z===y.id})!==undefined}).style("fill","#f00")},function(){p.select(t.tool_param_tree_view.$el[0]).selectAll("g.node").style("fill","#000")});return v},handle_node_clicks:function(){var s=this,t=this.model.get("parameter_tree"),v=this.model.get("regions"),u=p.select(this.tool_param_tree_view.$el[0]).selectAll("g.node");u.on("click",function(B,y){var x=s.model.get("tool"),A=s.model.get("dataset"),z=t.get_node_settings(B),w=$.Deferred();if(z.length>=10){show_modal("Whoa there cowboy!","You clicked on a node to try "+s.model.get("tool").get("name")+" with "+z.length+" different combinations of settings. You can only run 10 jobs at a time.",{Ok:function(){hide_modal();w.resolve(false)}})}else{w.resolve(true)}$.when(w).then(function(C){if(!C){return}var D=q.map(z,function(E){var F=new d({settings:E,regions:v,mode:s.model.get("default_mode")});s.add_track(F);return F});q.each(D,function(F,E){setTimeout(function(){x.set_input_values(F.get("settings").get("values"));$.when(x.rerun(A,v)).then(function(H){var I=H.first(),J=I.get("track_config");J.dataset=I;J.tool=null;J.prefs=s.config.to_key_value_dict();var G=m.object_from_template(J,s,null);G.init_for_tool_data();F.set("track",G)})},E*10000)})})})}});return{SweepsterVisualization:c,SweepsterVisualizationView:f}}); \ No newline at end of file +define(["libs/underscore","libs/d3","viz/trackster/util","viz/visualization","viz/trackster/tracks","mvc/tools","mvc/data","utils/config","mvc/ui/icon-button"],function(r,q,e,k,n,o,s,p,i){var l=Backbone.Model.extend({defaults:{inputs:null,values:null}});var b=Backbone.Model.extend({defaults:{tool:null,tree_data:null},initialize:function(u){var t=this;this.get("tool").get("inputs").each(function(v){v.on("change:min change:max change:num_samples",function(w){if(w.get("in_ptree")){t.set_tree_data()}},t);v.on("change:in_ptree",function(w){if(w.get("in_ptree")){t.add_param(w)}else{t.remove_param(w)}t.set_tree_data()},t)});if(u.config){r.each(u.config,function(w){var v=t.get("tool").get("inputs").find(function(x){return x.get("name")===w.name});t.add_param(v);v.set(w)})}},add_param:function(t){if(t.get("ptree_index")){return}t.set("in_ptree",true);t.set("ptree_index",this.get_tree_params().length)},remove_param:function(t){t.set("in_ptree",false);t.set("ptree_index",null);r(this.get_tree_params()).each(function(u,v){u.set("ptree_index",v+1)})},set_tree_data:function(){var u=r.map(this.get_tree_params(),function(w){return{param:w,samples:w.get_samples()}});var t=0,v=function(z,w){var B=z[w],A=B.param,y=A.get("label"),x=B.samples;if(z.length-1===w){return r.map(x,function(C){return{id:t++,name:C,param:A,value:C}})}return r.map(x,function(C){return{id:t++,name:C,param:A,value:C,children:v(z,w+1)}})};this.set("tree_data",{name:"Root",id:t++,children:(u.length!==0?v(u,0):null)})},get_tree_params:function(){return r(this.get("tool").get("inputs").where({in_ptree:true})).sortBy(function(t){return t.get("ptree_index")})},get_num_leaves:function(){return this.get_tree_params().reduce(function(t,u){return t*u.get_samples().length},1)},get_node_settings:function(x){var v=this.get("tool").get_inputs_dict();var y=x.parent;if(y){while(y.depth!==0){v[y.param.get("name")]=y.value;y=y.parent}}var t=this,u=function(A,z){if(A.param){z[A.param.get("name")]=A.value}if(!A.children){return new l({inputs:t.get("tool").get("inputs"),values:z})}else{return r.flatten(r.map(A.children,function(B){return u(B,r.clone(z))}))}},w=u(x,v);if(!r.isArray(w)){w=[w]}return w},get_connected_nodes:function(v){var w=function(x){if(!x.children){return x}else{return r.flatten([x,r.map(x.children,function(y){return w(y)})])}};var u=[],t=v.parent;while(t){u.push(t);t=t.parent}return r.flatten([u,w(v)])},get_leaf:function(u){var v=this.get("tree_data"),t=function(w){return r.find(w,function(x){return u[x.param.get("name")]===x.value})};while(v.children){v=t(v.children)}return v},toJSON:function(){return this.get_tree_params().map(function(t){return{name:t.get("name"),min:t.get("min"),max:t.get("max"),num_samples:t.get("num_samples")}})}});var d=Backbone.Model.extend({defaults:{track:null,mode:"Pack",settings:null,regions:null},initialize:function(t){this.set("regions",t.regions);if(t.track){var u=r.extend({data_url:galaxy_config.root+"dummy1",converted_datasets_state_url:galaxy_config.root+"dummy2"},t.track);this.set("track",n.object_from_template(u,{},null))}},same_settings:function(t){var u=this.get("settings"),v=t.get("settings");for(var w in u){if(!v[w]||u[w]!==v[w]){return false}}return true},toJSON:function(){return{track:this.get("track").to_dict(),settings:this.get("settings"),regions:this.get("regions")}}});var m=Backbone.Collection.extend({model:d});var c=k.Visualization.extend({defaults:r.extend({},k.Visualization.prototype.defaults,{dataset:null,tool:null,parameter_tree:null,regions:null,tracks:null,default_mode:"Pack"}),initialize:function(t){this.set("dataset",new s.Dataset(t.dataset));this.set("tool",new o.Tool(t.tool));this.set("regions",new k.GenomeRegionCollection(t.regions));this.set("tracks",new m(t.tracks));var u=this.get("tool");this.set("tool_with_samplable_inputs",u);u.remove_inputs(["data","hidden_data","conditional","text"]);this.set("parameter_tree",new b({tool:u,config:t.tree_config}))},add_track:function(t){this.get("tracks").add(t)},toJSON:function(){return{id:this.get("id"),title:"Parameter exploration for dataset '"+this.get("dataset").get("name")+"'",type:"sweepster",dataset_id:this.get("dataset").id,tool_id:this.get("tool").id,regions:this.get("regions").toJSON(),tree_config:this.get("parameter_tree").toJSON(),tracks:this.get("tracks").toJSON()}}});var h=Backbone.View.extend({tagName:"tr",TILE_LEN:250,initialize:function(t){this.canvas_manager=t.canvas_manager;this.render();this.model.on("change:track change:mode",this.draw_tiles,this)},render:function(){var y=this.model.get("settings"),u=y.get("values"),w=$("<td/>").addClass("settings").appendTo(this.$el),v=$("<div/>").addClass("track-info").hide().appendTo(w);v.append($("<div/>").css("font-weight","bold").text("Track Settings"));y.get("inputs").each(function(A){v.append(A.get("label")+": "+u[A.get("name")]+"<br/>")});var t=this,z=$("<button/>").appendTo(v).text("Run on complete dataset").click(function(){v.toggle();t.trigger("run_on_dataset",y)});var x=i.create_icon_buttons_menu([{title:"Settings",icon_class:"gear track-settings",on_click:function(){v.toggle()}},{title:"Remove",icon_class:"cross-circle",on_click:function(){t.$el.remove();$(".tooltip").remove()}}]);w.prepend(x.$el);this.model.get("regions").each(function(){t.$el.append($("<td/>").addClass("tile").html($("<img/>").attr("src",galaxy_config.root+"images/loading_large_white_bg.gif")))});if(this.model.get("track")){this.draw_tiles()}},draw_tiles:function(){var u=this,t=this.model.get("track"),w=this.model.get("regions"),v=this.$el.find("td.tile");if(!t){return}$.when(t.data_manager.data_is_ready()).then(function(x){w.each(function(A,z){var y=A.length()/u.TILE_LEN,C=1/y,B=u.model.get("mode");$.when(t.data_manager.get_data(A,B,y,{})).then(function(E){var D=u.canvas_manager.new_canvas();D.width=u.TILE_LEN;D.height=t.get_canvas_height(E,B,C,D.width);t.draw_tile(E,D.getContext("2d"),B,A,C);$(v[z]).empty().append(D)})})})}});var g=Backbone.View.extend({number_input_template:'<div class="form-row-input sweep"><input class="min" type="text" size="6" value="<%= min %>"> - <input class="max" type="text" size="6" value="<%= max %>"> samples: <input class="num_samples" type="text" size="1" value="<%= num_samples %>"></div>',select_input_template:'<div class="form-row-input sweep"><%= options %></div>',initialize:function(t){this.$el=t.tool_row;this.render()},render:function(){var u=this.model,y=u.get("type"),A=this.$el.find(".form-row-input"),w=null;A.find(":input").change(function(){u.set("value",$(this).val())});if(u instanceof o.IntegerToolParameter){w=$(r.template(this.number_input_template,this.model.toJSON()))}else{if(u instanceof o.SelectToolParameter){var v=r.map(this.$el.find("select option"),function(B){return $(B).val()}),x=v.join(", ");w=$(r.template(this.select_input_template,{options:x}))}}w.insertAfter(A);var t=this,z=i.create_icon_buttons_menu([{title:"Add parameter to tree",icon_class:"plus-button",on_click:function(){u.set("in_ptree",true);A.hide();w.show();$(this).hide();t.$el.find(".icon-button.toggle").show()}},{title:"Remove parameter from tree",icon_class:"toggle",on_click:function(){u.set("in_ptree",false);w.hide();A.show();$(this).hide();t.$el.find(".icon-button.plus-button").show()}}],{});this.$el.prepend(z.$el);if(u.get("in_ptree")){A.hide();t.$el.find(".icon-button.plus-button").hide()}else{t.$el.find(".icon-button.toggle").hide();w.hide()}r.each(["min","max","num_samples"],function(B){w.find("."+B).change(function(){u.set(B,parseFloat($(this).val()))})})}});var j=Backbone.View.extend({className:"tree-design",initialize:function(t){this.render()},render:function(){var v=new o.ToolFormView({model:this.model.get("tool")});v.render();this.$el.append(v.$el);var u=this,t=u.model.get("tool").get("inputs");this.$el.find(".form-row").not(".form-actions").each(function(w){var x=new g({model:t.at(w),tool_row:$(this)})})}});var a=Backbone.View.extend({className:"tool-parameter-tree",initialize:function(t){this.model.on("change:tree_data",this.render,this)},render:function(){this.$el.children().remove();var B=this.model.get_tree_params();if(!B.length){return}this.width=100*(2+B.length);this.height=15*this.model.get_num_leaves();var A=this;var z=q.layout.cluster().size([this.height,this.width-160]);var v=q.svg.diagonal().projection(function(C){return[C.y,C.x]});var t=z.nodes(this.model.get("tree_data"));var w=r.uniq(r.pluck(t,"y"));r.each(B,function(E,D){var C=w[D+1],F=$("#center").position().left;A.$el.append($("<div>").addClass("label").text(E.get("label")).css("left",C+F))});var u=q.select(this.$el[0]).append("svg").attr("width",this.width).attr("height",this.height+30).append("g").attr("transform","translate(40, 20)");var y=u.selectAll("path.link").data(z.links(t)).enter().append("path").attr("class","link").attr("d",v);var x=u.selectAll("g.node").data(t).enter().append("g").attr("class","node").attr("transform",function(C){return"translate("+C.y+","+C.x+")"}).on("mouseover",function(D){var C=r.pluck(A.model.get_connected_nodes(D),"id");x.filter(function(E){return r.find(C,function(F){return F===E.id})!==undefined}).style("fill","#f00")}).on("mouseout",function(){x.style("fill","#000")});x.append("circle").attr("r",9);x.append("text").attr("dx",function(C){return C.children?-12:12}).attr("dy",3).attr("text-anchor",function(C){return C.children?"end":"start"}).text(function(C){return C.name})}});var f=Backbone.View.extend({className:"Sweepster",helpText:"<div><h4>Getting Started</h4><ol><li>Create a parameter tree by using the icons next to the tool's parameter names to add or remove parameters.<li>Adjust the tree by using parameter inputs to select min, max, and number of samples<li>Run the tool with different settings by clicking on tree nodes</ol></div>",initialize:function(u){this.canvas_manager=new k.CanvasManager(this.$el.parents("body"));this.tool_param_tree_view=new a({model:this.model.get("parameter_tree")});this.track_collection_container=$("<table/>").addClass("tracks");this.model.get("parameter_tree").on("change:tree_data",this.handle_node_clicks,this);var t=this;this.model.get("tracks").each(function(v){v.get("track").view=t});this.config=p.ConfigSettingCollection.from_models_and_saved_values([{key:"name",label:"Name",type:"text",default_value:""},{key:"a_color",label:"A Color",type:"color",default_value:"#FF0000"},{key:"c_color",label:"C Color",type:"color",default_value:"#00FF00"},{key:"g_color",label:"G Color",type:"color",default_value:"#0000FF"},{key:"t_color",label:"T Color",type:"color",default_value:"#FF00FF"},{key:"n_color",label:"N Color",type:"color",default_value:"#AAAAAA"},{key:"block_color",label:"Block color",type:"color"},{key:"reverse_strand_color",label:"Antisense strand color",type:"color"},],{})},render:function(){var z=new j({model:this.model.get("parameter_tree")});$("#left").append(z.$el);var C=this,w=C.model.get("regions"),A=$("<tr/>").appendTo(this.track_collection_container);w.each(function(D){A.append($("<th>").text(D.toString()))});A.children().first().attr("colspan",2);var x=$("<div>").addClass("tiles");$("#right").append(x.append(this.track_collection_container));C.model.get("tracks").each(function(D){C.add_track(D)});var B=$(this.helpText).addClass("help"),y=i.create_icon_buttons_menu([{title:"Close",icon_class:"cross-circle",on_click:function(){$(".tooltip").remove();B.remove()}}]);B.prepend(y.$el.css("float","right"));$("#center").append(B);this.tool_param_tree_view.render();$("#center").append(this.tool_param_tree_view.$el);this.handle_node_clicks();var v=i.create_icon_buttons_menu([{icon_class:"chevron-expand",title:"Set display mode"},{icon_class:"cross-circle",title:"Close",on_click:function(){window.location="${h.url_for( controller='visualization', action='list' )}"}}],{tooltip_config:{placement:"bottom"}});var u=["Squish","Pack"],t={};r.each(u,function(D){t[D]=function(){C.model.set("default_mode",D);C.model.get("tracks").each(function(E){E.set("mode",D)})}});make_popupmenu(v.$el.find(".chevron-expand"),t);v.$el.attr("style","float: right");$("#right .unified-panel-header-inner").append(v.$el)},get_base_color:function(t){return this.config.get_value(t.toLowerCase()+"_color")||this.config.get_value("n_color")},run_tool_on_dataset:function(u){var t=this.model.get("tool"),w=t.get("name"),v=this.model.get("dataset");t.set_input_values(u.get("values"));$.when(t.rerun(v)).then(function(x){});show_modal("Running "+w+" on complete dataset",w+" is running on dataset '"+v.get("name")+"'. Outputs are in the dataset's history.",{Ok:function(){hide_modal()}})},add_track:function(w){var u=this,v=this.model.get("parameter_tree");u.model.add_track(w);var t=new h({model:w,canvas_manager:u.canvas_manager});t.on("run_on_dataset",u.run_tool_on_dataset,u);u.track_collection_container.append(t.$el);t.$el.hover(function(){var y=v.get_leaf(w.get("settings").get("values"));var x=r.pluck(v.get_connected_nodes(y),"id");q.select(u.tool_param_tree_view.$el[0]).selectAll("g.node").filter(function(z){return r.find(x,function(A){return A===z.id})!==undefined}).style("fill","#f00")},function(){q.select(u.tool_param_tree_view.$el[0]).selectAll("g.node").style("fill","#000")});return w},handle_node_clicks:function(){var t=this,u=this.model.get("parameter_tree"),w=this.model.get("regions"),v=q.select(this.tool_param_tree_view.$el[0]).selectAll("g.node");v.on("click",function(C,z){var y=t.model.get("tool"),B=t.model.get("dataset"),A=u.get_node_settings(C),x=$.Deferred();if(A.length>=10){show_modal("Whoa there cowboy!","You clicked on a node to try "+t.model.get("tool").get("name")+" with "+A.length+" different combinations of settings. You can only run 10 jobs at a time.",{Ok:function(){hide_modal();x.resolve(false)}})}else{x.resolve(true)}$.when(x).then(function(D){if(!D){return}var E=r.map(A,function(F){var G=new d({settings:F,regions:w,mode:t.model.get("default_mode")});t.add_track(G);return G});r.each(E,function(G,F){setTimeout(function(){y.set_input_values(G.get("settings").get("values"));$.when(y.rerun(B,w)).then(function(I){var J=I.first(),K=J.get("track_config");K.dataset=J;K.tool=null;K.prefs=t.config.to_key_value_dict();var H=n.object_from_template(K,t,null);H.init_for_tool_data();G.set("track",H)})},F*10000)})})})}});return{SweepsterVisualization:c,SweepsterVisualizationView:f}}); \ No newline at end of file diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 static/scripts/packed/viz/trackster.js --- a/static/scripts/packed/viz/trackster.js +++ b/static/scripts/packed/viz/trackster.js @@ -1,1 +1,1 @@ -var ui=null;var view=null;var browser_router=null;require(["utils/utils","libs/jquery/jquery.event.drag","libs/jquery/jquery.event.hover","libs/jquery/jquery.mousewheel","libs/jquery/jquery-ui","libs/jquery/select2","libs/farbtastic","libs/jquery/jquery.form","libs/jquery/jquery.rating","mvc/ui"],function(a){a.cssLoadFile("static/style/jquery.rating.css");a.cssLoadFile("static/style/autocomplete_tagging.css");a.cssLoadFile("static/style/jquery-ui/smoothness/jquery-ui.css");a.cssLoadFile("static/style/library.css");a.cssLoadFile("static/style/trackster.css")});define(["libs/underscore","base","viz/trackster/tracks","viz/visualization"],function(b,e,a,c){var d=e.Base.extend({initialize:function(g){this.baseURL=g},save_viz:function(){Galaxy.modal.show({title:"Saving...",body:"progress"});var g=[];$(".bookmark").each(function(){g.push({position:$(this).children(".position").text(),annotation:$(this).children(".annotation").text()})});var h=(view.overview_drawable?view.overview_drawable.config.get_value("name"):null),j={view:view.to_dict(),viewport:{chrom:view.chrom,start:view.low,end:view.high,overview:h},bookmarks:g};return $.ajax({url:galaxy_config.root+"visualization/save",type:"POST",dataType:"json",data:{id:view.vis_id,title:view.config.get_value("name"),dbkey:view.dbkey,type:"trackster",vis_json:JSON.stringify(j)}}).success(function(k){Galaxy.modal.hide();view.vis_id=k.vis_id;view.has_changes=false;window.history.pushState({},"",k.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()}}})})},createButtonMenu:function(){var g=this,h=create_icon_buttons_menu([{icon_class:"plus-button",title:"Add tracks",on_click:function(){c.select_datasets(galaxy_config.root+"visualization/list_current_history_datasets",galaxy_config.root+"api/datasets",{"f-dbkey":view.dbkey},function(j){b.each(j,function(k){view.add_drawable(a.object_from_template(k,view,view))})})}},{icon_class:"block--plus",title:"Add group",on_click:function(){view.add_drawable(new a.DrawableGroup(view,view,{name:"New Group"}))}},{icon_class:"bookmarks",title:"Bookmarks",on_click:function(){force_right_panel(($("div#right").css("right")=="0px"?"hide":"show"))}},{icon_class:"globe",title:"Circster",on_click:function(){window.location=g.baseURL+"visualization/circster?id="+view.vis_id}},{icon_class:"disk--arrow",title:"Save",on_click:function(){g.save_viz()}},{icon_class:"cross-circle",title:"Close",on_click:function(){g.handle_unsaved_changes(view)}}],{tooltip_config:{placement:"bottom"}});this.buttonMenu=h;return h},add_bookmarks:function(){var g=this,h=this.baseURL;Galaxy.modal.show({title:"Select dataset for new bookmarks",body:"progress"});$.ajax({url:this.baseURL+"/visualization/list_histories",data:{"f-dbkey":view.dbkey},error:function(){alert("Grid failed")},success:function(j){Galaxy.modal.show({title:"Select dataset for new bookmarks",body:j,buttons:{Cancel:function(){Galaxy.modal.hide()},Insert:function(){$("input[name=id]:checked,input[name=ldda_ids]:checked").first().each(function(){var k,l=$(this).val();if($(this).attr("name")==="id"){k={hda_id:l}}else{k={ldda_id:l}}$.ajax({url:this.baseURL+"/visualization/bookmarks_from_dataset",data:k,dataType:"json"}).then(function(m){for(i=0;i<m.data.length;i++){var n=m.data[i];g.add_bookmark(n[0],n[1])}})});Galaxy.modal.hide()}}})}})},add_bookmark:function(l,j,g){var n=$("#right .unified-panel-body"),p=$("<div/>").addClass("bookmark").appendTo(n);var q=$("<div/>").addClass("position").appendTo(p),m=$("<a href=''/>").text(l).appendTo(q).click(function(){view.go_to(l);return false}),k=$("<div/>").text(j).appendTo(p);if(g){var o=$("<div/>").addClass("delete-icon-container").prependTo(p).click(function(){p.slideUp("fast");p.remove();view.has_changes=true;return false}),h=$("<a href=''/>").addClass("icon-button delete").appendTo(o);k.make_text_editable({num_rows:3,use_textarea:true,help_text:"Edit bookmark note"}).addClass("annotation")}view.has_changes=true;return p},create_visualization:function(m,g,l,n,k){var j=this,h=new a.TracksterView(b.extend(m,{header:false}));h.editor=true;$.when(h.load_chroms_deferred).then(function(y){if(g){var w=g.chrom,o=g.start,t=g.end,q=g.overview;if(w&&(o!==undefined)&&t){h.change_chrom(w,o,t)}else{h.change_chrom(y[0].chrom)}}else{h.change_chrom(y[0].chrom)}if(l){var r,p,s;for(var u=0;u<l.length;u++){h.add_drawable(a.object_from_template(l[u],h,h))}}var x;for(var u=0;u<h.drawables.length;u++){if(h.drawables[u].config.get_value("name")===q){h.set_overview(h.drawables[u]);break}}if(n){var v;for(var u=0;u<n.length;u++){v=n[u];j.add_bookmark(v.position,v.annotation,k)}}h.has_changes=false});this.set_up_router({view:h});return h},set_up_router:function(g){new c.TrackBrowserRouter(g);Backbone.history.start()},init_keyboard_nav:function(g){$(document).keyup(function(h){if($(h.srcElement).is(":input")){return}switch(h.which){case 37:g.move_fraction(0.25);break;case 38:var j=Math.round(g.viewport_container.height()/15);g.viewport_container.scrollTop(g.viewport_container.scrollTop()-20);break;case 39:g.move_fraction(-0.25);break;case 40:var j=Math.round(g.viewport_container.height()/15);g.viewport_container.scrollTop(g.viewport_container.scrollTop()+20);break}})},handle_unsaved_changes:function(g){if(g.has_changes){var h=this;Galaxy.modal.show({title:"Close visualization",body:"There are unsaved changes to your visualization which will be lost if you do not save them.",buttons:{Cancel:function(){Galaxy.modal.hide()},"Leave without Saving":function(){$(window).off("beforeunload");window.location=galaxy_config.root+"visualization"},Save:function(){$.when(h.save_viz()).then(function(){window.location=galaxy_config.root+"visualization"})}}})}else{window.location=galaxy_config.root+"visualization"}}});var f=e.Backbone.View.extend({initialize:function(){ui=new d(galaxy_config.root);ui.createButtonMenu();ui.buttonMenu.$el.attr("style","float: right");$("#center .unified-panel-header-inner").append(ui.buttonMenu.$el);$("#right .unified-panel-title").append("Bookmarks");$("#right .unified-panel-icons").append("<a id='add-bookmark-button' class='icon-button menu-button plus-button' href='javascript:void(0);' title='Add bookmark'></a>");$("#right-border").click(function(){view.resize_window()});force_right_panel("hide");if(galaxy_config.app.id){this.view_existing()}else{this.view_new()}},view_existing:function(){var g=galaxy_config.app.viz_config;view=ui.create_visualization({container:$("#center .unified-panel-body"),name:g.title,vis_id:g.vis_id,dbkey:g.dbkey},g.viewport,g.tracks,g.bookmarks,true);this.init_editor()},view_new:function(){var g=this;$.ajax({url:galaxy_config.root+"api/genomes?chrom_info=True",data:{},error:function(){alert("Couldn't create new browser.")},success:function(h){Galaxy.modal.show({title:"New Visualization",body:g.template_view_new(h),buttons:{Cancel:function(){window.location=galaxy_config.root+"visualization/list"},Create:function(){g.create_browser($("#new-title").val(),$("#new-dbkey").val());Galaxy.modal.hide()}}});if(galaxy_config.app.default_dbkey){$("#new-dbkey").val(galaxy_config.app.default_dbkey)}$("#new-title").focus();$("select[name='dbkey']").select2();$("#overlay").css("overflow","auto")}})},template_view_new:function(g){var j='<form id="new-browser-form" action="javascript:void(0);" method="post" onsubmit="return false;"><div class="form-row"><label for="new-title">Browser name:</label><div class="form-row-input"><input type="text" name="title" id="new-title" value="Unnamed"></input></div><div style="clear: both;"></div></div><div class="form-row"><label for="new-dbkey">Reference genome build (dbkey): </label><div class="form-row-input"><select name="dbkey" id="new-dbkey">';for(var h=0;h<g.length;h++){j+='<option value="'+g[h][1]+'">'+g[h][0]+"</option>"}j+='</select></div><div style="clear: both;"></div></div><div class="form-row">Is the build not listed here? <a href="'+galaxy_config.root+'user/dbkeys?use_panels=True">Add a Custom Build</a></div></form>';return j},create_browser:function(h,g){$(document).trigger("convert_to_values");view=ui.create_visualization({container:$("#center .unified-panel-body"),name:h,dbkey:g},galaxy_config.app.gene_region);this.init_editor();view.editor=true},init_editor:function(){$("#center .unified-panel-title").text(view.config.get_value("name")+" ("+view.dbkey+")");if(galaxy_config.app.add_dataset){$.ajax({url:galaxy_config.root+"api/datasets/"+galaxy_config.app.add_dataset,data:{hda_ldda:"hda",data_type:"track_config"},dataType:"json",success:function(g){view.add_drawable(a.object_from_template(g,view,view))}})}$("#add-bookmark-button").click(function(){var h=view.chrom+":"+view.low+"-"+view.high,g="Bookmark description";return ui.add_bookmark(h,g,true)});ui.init_keyboard_nav(view);$(window).on("beforeunload",function(){if(view.has_changes){return"There are unsaved changes to your visualization that will be lost if you leave this page."}})}});return{TracksterUI:d,GalaxyApp:f}}); \ No newline at end of file +var ui=null;var view=null;var browser_router=null;require(["utils/utils","mvc/ui/icon-button","libs/jquery/jquery.event.drag","libs/jquery/jquery.event.hover","libs/jquery/jquery.mousewheel","libs/jquery/jquery-ui","libs/jquery/select2","libs/farbtastic","libs/jquery/jquery.form","libs/jquery/jquery.rating","mvc/ui"],function(b,a){b.cssLoadFile("static/style/jquery.rating.css");b.cssLoadFile("static/style/autocomplete_tagging.css");b.cssLoadFile("static/style/jquery-ui/smoothness/jquery-ui.css");b.cssLoadFile("static/style/library.css");b.cssLoadFile("static/style/trackster.css")});define(["libs/underscore","base","viz/trackster/tracks","viz/visualization"],function(b,e,a,c){var d=e.Base.extend({initialize:function(g){this.baseURL=g},save_viz:function(){Galaxy.modal.show({title:"Saving...",body:"progress"});var g=[];$(".bookmark").each(function(){g.push({position:$(this).children(".position").text(),annotation:$(this).children(".annotation").text()})});var h=(view.overview_drawable?view.overview_drawable.config.get_value("name"):null),j={view:view.to_dict(),viewport:{chrom:view.chrom,start:view.low,end:view.high,overview:h},bookmarks:g};return $.ajax({url:galaxy_config.root+"visualization/save",type:"POST",dataType:"json",data:{id:view.vis_id,title:view.config.get_value("name"),dbkey:view.dbkey,type:"trackster",vis_json:JSON.stringify(j)}}).success(function(k){Galaxy.modal.hide();view.vis_id=k.vis_id;view.has_changes=false;window.history.pushState({},"",k.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()}}})})},createButtonMenu:function(){var g=this,h=mod_icon_btn.create_icon_buttons_menu([{icon_class:"plus-button",title:"Add tracks",on_click:function(){c.select_datasets(galaxy_config.root+"visualization/list_current_history_datasets",galaxy_config.root+"api/datasets",{"f-dbkey":view.dbkey},function(j){b.each(j,function(k){view.add_drawable(a.object_from_template(k,view,view))})})}},{icon_class:"block--plus",title:"Add group",on_click:function(){view.add_drawable(new a.DrawableGroup(view,view,{name:"New Group"}))}},{icon_class:"bookmarks",title:"Bookmarks",on_click:function(){force_right_panel(($("div#right").css("right")=="0px"?"hide":"show"))}},{icon_class:"globe",title:"Circster",on_click:function(){window.location=g.baseURL+"visualization/circster?id="+view.vis_id}},{icon_class:"disk--arrow",title:"Save",on_click:function(){g.save_viz()}},{icon_class:"cross-circle",title:"Close",on_click:function(){g.handle_unsaved_changes(view)}}],{tooltip_config:{placement:"bottom"}});this.buttonMenu=h;return h},add_bookmarks:function(){var g=this,h=this.baseURL;Galaxy.modal.show({title:"Select dataset for new bookmarks",body:"progress"});$.ajax({url:this.baseURL+"/visualization/list_histories",data:{"f-dbkey":view.dbkey},error:function(){alert("Grid failed")},success:function(j){Galaxy.modal.show({title:"Select dataset for new bookmarks",body:j,buttons:{Cancel:function(){Galaxy.modal.hide()},Insert:function(){$("input[name=id]:checked,input[name=ldda_ids]:checked").first().each(function(){var k,l=$(this).val();if($(this).attr("name")==="id"){k={hda_id:l}}else{k={ldda_id:l}}$.ajax({url:this.baseURL+"/visualization/bookmarks_from_dataset",data:k,dataType:"json"}).then(function(m){for(i=0;i<m.data.length;i++){var n=m.data[i];g.add_bookmark(n[0],n[1])}})});Galaxy.modal.hide()}}})}})},add_bookmark:function(l,j,g){var n=$("#right .unified-panel-body"),p=$("<div/>").addClass("bookmark").appendTo(n);var q=$("<div/>").addClass("position").appendTo(p),m=$("<a href=''/>").text(l).appendTo(q).click(function(){view.go_to(l);return false}),k=$("<div/>").text(j).appendTo(p);if(g){var o=$("<div/>").addClass("delete-icon-container").prependTo(p).click(function(){p.slideUp("fast");p.remove();view.has_changes=true;return false}),h=$("<a href=''/>").addClass("icon-button delete").appendTo(o);k.make_text_editable({num_rows:3,use_textarea:true,help_text:"Edit bookmark note"}).addClass("annotation")}view.has_changes=true;return p},create_visualization:function(m,g,l,n,k){var j=this,h=new a.TracksterView(b.extend(m,{header:false}));h.editor=true;$.when(h.load_chroms_deferred).then(function(y){if(g){var w=g.chrom,o=g.start,t=g.end,q=g.overview;if(w&&(o!==undefined)&&t){h.change_chrom(w,o,t)}else{h.change_chrom(y[0].chrom)}}else{h.change_chrom(y[0].chrom)}if(l){var r,p,s;for(var u=0;u<l.length;u++){h.add_drawable(a.object_from_template(l[u],h,h))}}var x;for(var u=0;u<h.drawables.length;u++){if(h.drawables[u].config.get_value("name")===q){h.set_overview(h.drawables[u]);break}}if(n){var v;for(var u=0;u<n.length;u++){v=n[u];j.add_bookmark(v.position,v.annotation,k)}}h.has_changes=false});this.set_up_router({view:h});return h},set_up_router:function(g){new c.TrackBrowserRouter(g);Backbone.history.start()},init_keyboard_nav:function(g){$(document).keyup(function(h){if($(h.srcElement).is(":input")){return}switch(h.which){case 37:g.move_fraction(0.25);break;case 38:var j=Math.round(g.viewport_container.height()/15);g.viewport_container.scrollTop(g.viewport_container.scrollTop()-20);break;case 39:g.move_fraction(-0.25);break;case 40:var j=Math.round(g.viewport_container.height()/15);g.viewport_container.scrollTop(g.viewport_container.scrollTop()+20);break}})},handle_unsaved_changes:function(g){if(g.has_changes){var h=this;Galaxy.modal.show({title:"Close visualization",body:"There are unsaved changes to your visualization which will be lost if you do not save them.",buttons:{Cancel:function(){Galaxy.modal.hide()},"Leave without Saving":function(){$(window).off("beforeunload");window.location=galaxy_config.root+"visualization"},Save:function(){$.when(h.save_viz()).then(function(){window.location=galaxy_config.root+"visualization"})}}})}else{window.location=galaxy_config.root+"visualization"}}});var f=e.Backbone.View.extend({initialize:function(){ui=new d(galaxy_config.root);ui.createButtonMenu();ui.buttonMenu.$el.attr("style","float: right");$("#center .unified-panel-header-inner").append(ui.buttonMenu.$el);$("#right .unified-panel-title").append("Bookmarks");$("#right .unified-panel-icons").append("<a id='add-bookmark-button' class='icon-button menu-button plus-button' href='javascript:void(0);' title='Add bookmark'></a>");$("#right-border").click(function(){view.resize_window()});force_right_panel("hide");if(galaxy_config.app.id){this.view_existing()}else{this.view_new()}},view_existing:function(){var g=galaxy_config.app.viz_config;view=ui.create_visualization({container:$("#center .unified-panel-body"),name:g.title,vis_id:g.vis_id,dbkey:g.dbkey},g.viewport,g.tracks,g.bookmarks,true);this.init_editor()},view_new:function(){var g=this;$.ajax({url:galaxy_config.root+"api/genomes?chrom_info=True",data:{},error:function(){alert("Couldn't create new browser.")},success:function(h){Galaxy.modal.show({title:"New Visualization",body:g.template_view_new(h),buttons:{Cancel:function(){window.location=galaxy_config.root+"visualization/list"},Create:function(){g.create_browser($("#new-title").val(),$("#new-dbkey").val());Galaxy.modal.hide()}}});if(galaxy_config.app.default_dbkey){$("#new-dbkey").val(galaxy_config.app.default_dbkey)}$("#new-title").focus();$("select[name='dbkey']").select2();$("#overlay").css("overflow","auto")}})},template_view_new:function(g){var j='<form id="new-browser-form" action="javascript:void(0);" method="post" onsubmit="return false;"><div class="form-row"><label for="new-title">Browser name:</label><div class="form-row-input"><input type="text" name="title" id="new-title" value="Unnamed"></input></div><div style="clear: both;"></div></div><div class="form-row"><label for="new-dbkey">Reference genome build (dbkey): </label><div class="form-row-input"><select name="dbkey" id="new-dbkey">';for(var h=0;h<g.length;h++){j+='<option value="'+g[h][1]+'">'+g[h][0]+"</option>"}j+='</select></div><div style="clear: both;"></div></div><div class="form-row">Is the build not listed here? <a href="'+galaxy_config.root+'user/dbkeys?use_panels=True">Add a Custom Build</a></div></form>';return j},create_browser:function(h,g){$(document).trigger("convert_to_values");view=ui.create_visualization({container:$("#center .unified-panel-body"),name:h,dbkey:g},galaxy_config.app.gene_region);this.init_editor();view.editor=true},init_editor:function(){$("#center .unified-panel-title").text(view.config.get_value("name")+" ("+view.dbkey+")");if(galaxy_config.app.add_dataset){$.ajax({url:galaxy_config.root+"api/datasets/"+galaxy_config.app.add_dataset,data:{hda_ldda:"hda",data_type:"track_config"},dataType:"json",success:function(g){view.add_drawable(a.object_from_template(g,view,view))}})}$("#add-bookmark-button").click(function(){var h=view.chrom+":"+view.low+"-"+view.high,g="Bookmark description";return ui.add_bookmark(h,g,true)});ui.init_keyboard_nav(view);$(window).on("beforeunload",function(){if(view.has_changes){return"There are unsaved changes to your visualization that will be lost if you leave this page."}})}});return{TracksterUI:d,GalaxyApp:f}}); \ No newline at end of file diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 static/scripts/viz/circster.js --- a/static/scripts/viz/circster.js +++ b/static/scripts/viz/circster.js @@ -2,8 +2,9 @@ require( [ 'utils/utils', + 'mvc/ui/icon-button', 'libs/farbtastic', -], function(mod_utils) +], function(mod_utils, mod_icon_btn) { // load css mod_utils.cssLoadFile("static/style/circster.css"); @@ -1075,7 +1076,7 @@ $('#center .unified-panel-header-inner').append(galaxy_config.app.viz_config.title + " " + galaxy_config.app.viz_config.dbkey); // setup menu - var menu = create_icon_buttons_menu([ + var menu = mod_icon_btn.create_icon_buttons_menu([ { icon_class: 'plus-button', title: 'Add tracks', on_click: function() { diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 static/scripts/viz/phyloviz.js --- a/static/scripts/viz/phyloviz.js +++ b/static/scripts/viz/phyloviz.js @@ -1,4 +1,9 @@ -define(['libs/d3', 'viz/visualization', 'mvc/data'], function(d3, visualization_mod, data_mod) { +define([ + 'libs/d3', + 'viz/visualization', + 'mvc/data', + 'mvc/ui/icon-button' +], function(d3, visualization_mod, data_mod, mod_icon_btn) { /** * Base class of any menus that takes in user interaction. Contains checking methods. @@ -720,7 +725,7 @@ initRightHeaderBtns : function(){ var self = this; - rightMenu = create_icon_buttons_menu([ + rightMenu = mod_icon_btn.create_icon_buttons_menu([ { icon_class: 'gear', title: 'PhyloViz Settings', on_click: function(){ $("#SettingsMenu").show(); self.settingsMenu.updateUI(); @@ -748,7 +753,7 @@ initNavBtns: function() { var self = this, - navMenu = create_icon_buttons_menu([ + navMenu = mod_icon_btn.create_icon_buttons_menu([ { icon_class: 'zoom-in', title: 'Zoom in', on_click: function() { self.phylovizView.zoomAndPan({ zoom : "+"}); } }, diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 static/scripts/viz/sweepster.js --- a/static/scripts/viz/sweepster.js +++ b/static/scripts/viz/sweepster.js @@ -3,8 +3,8 @@ * genomic visualization. */ -define(["libs/underscore", "libs/d3", "viz/trackster/util", "viz/visualization", "viz/trackster/tracks", "mvc/tools", "mvc/data", "utils/config"], - function(_, d3, util, visualization, tracks, tools, data, config) { +define(["libs/underscore", "libs/d3", "viz/trackster/util", "viz/visualization", "viz/trackster/tracks", "mvc/tools", "mvc/data", "utils/config", "mvc/ui/icon-button"], + function(_, d3, util, visualization, tracks, tools, data, config, mod_icon_btn) { /** * A collection of tool input settings. Object is useful for keeping a list of settings @@ -375,7 +375,7 @@ settings_div.toggle(); self.trigger('run_on_dataset', settings); }); - var icon_menu = create_icon_buttons_menu([ + var icon_menu = mod_icon_btn.create_icon_buttons_menu([ { title: 'Settings', icon_class: 'gear track-settings', @@ -486,7 +486,7 @@ // Add buttons for adding/removing parameter. var self = this, - menu = create_icon_buttons_menu([ + menu = mod_icon_btn.create_icon_buttons_menu([ { title: 'Add parameter to tree', icon_class: 'plus-button', @@ -723,7 +723,7 @@ // Help includes text and a close button. var help_div = $(this.helpText).addClass('help'), - close_button = create_icon_buttons_menu([ + close_button = mod_icon_btn.create_icon_buttons_menu([ { title: 'Close', icon_class: 'cross-circle', @@ -745,7 +745,7 @@ this.handle_node_clicks(); // Set up visualization menu. - var menu = create_icon_buttons_menu( + var menu = mod_icon_btn.create_icon_buttons_menu( [ // Save. /* @@ -939,4 +939,4 @@ SweepsterVisualizationView: SweepsterVisualizationView }; -}); \ No newline at end of file +}); diff -r 5b5dde05d21f02afa23cfe1c98396002d907de21 -r 31c50ee295791a8797ff8391986a469778091ee9 static/scripts/viz/trackster.js --- a/static/scripts/viz/trackster.js +++ b/static/scripts/viz/trackster.js @@ -12,6 +12,7 @@ [ // load js libraries 'utils/utils', + 'mvc/ui/icon-button', 'libs/jquery/jquery.event.drag', 'libs/jquery/jquery.event.hover', 'libs/jquery/jquery.mousewheel', @@ -21,7 +22,7 @@ 'libs/jquery/jquery.form', 'libs/jquery/jquery.rating', 'mvc/ui' -], function(mod_utils) +], function(mod_utils, mod_icon_btn) { // load css mod_utils.cssLoadFile("static/style/jquery.rating.css"); @@ -101,7 +102,7 @@ */ createButtonMenu: function() { var self = this, - menu = create_icon_buttons_menu([ + menu = mod_icon_btn.create_icon_buttons_menu([ { 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", { 'f-dbkey': view.dbkey }, function(new_tracks) { @@ -571,4 +572,4 @@ GalaxyApp : TracksterView }; -}); \ No newline at end of file +}); 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.