commit/galaxy-central: jgoecks: Viz framework: (a) add generic method to datatypes to get available visualizations and (b) attach available visualizations to dataset visualization icon.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/32091cc60876/ changeset: 32091cc60876 user: jgoecks date: 2012-09-18 17:40:57 summary: Viz framework: (a) add generic method to datatypes to get available visualizations and (b) attach available visualizations to dataset visualization icon. affected #: 5 files diff -r 5359d1066d91849fbf075f95f4999613d17a9c45 -r 32091cc60876e9720f2ae2b855e9e7f43e8c775a lib/galaxy/datatypes/data.py --- a/lib/galaxy/datatypes/data.py +++ b/lib/galaxy/datatypes/data.py @@ -545,6 +545,15 @@ raise Exception('Result %s from %s' % (result, cmd)) merge = staticmethod(merge) + def get_visualizations( self ): + """ + Returns a list of visualizations for datatype. + """ + + if hasattr( self, 'get_track_type' ): + return [ 'trackster', 'circster' ] + return [] + class Text( Data ): file_ext = 'txt' line_class = 'line' diff -r 5359d1066d91849fbf075f95f4999613d17a9c45 -r 32091cc60876e9720f2ae2b855e9e7f43e8c775a lib/galaxy/datatypes/tabular.py --- a/lib/galaxy/datatypes/tabular.py +++ b/lib/galaxy/datatypes/tabular.py @@ -301,6 +301,12 @@ def as_ucsc_display_file( self, dataset, **kwd ): return open( dataset.file_name ) + def get_visualizations( self ): + """ + Returns a list of visualizations for datatype. + """ + return super( Tabular, self ).get_visualizations() + [ 'scatterplot' ] + class Taxonomy( Tabular ): def __init__(self, **kwd): """Initialize taxonomy datatype""" diff -r 5359d1066d91849fbf075f95f4999613d17a9c45 -r 32091cc60876e9720f2ae2b855e9e7f43e8c775a lib/galaxy/web/controllers/visualization.py --- a/lib/galaxy/web/controllers/visualization.py +++ b/lib/galaxy/web/controllers/visualization.py @@ -708,9 +708,12 @@ # Get new dataset if specified. new_dataset = kwargs.get("dataset_id", None) + ''' + FIXME: if new_dataset is not None: if trans.security.decode_id(new_dataset) in [ d["dataset_id"] for d in viz_config.get("tracks") ]: new_dataset = None # Already in browser, so don't add + ''' return trans.fill_template( 'tracks/browser.mako', config=viz_config, add_dataset=new_dataset ) @web.json diff -r 5359d1066d91849fbf075f95f4999613d17a9c45 -r 32091cc60876e9720f2ae2b855e9e7f43e8c775a templates/root/history.mako --- a/templates/root/history.mako +++ b/templates/root/history.mako @@ -116,6 +116,95 @@ }); }; +// Create trackster action function. +function create_trackster_action_fn(vis_url, dataset_params, dbkey) { + return function() { + var params = {}; + if (dbkey) { params['dbkey'] = dbkey; } + $.ajax({ + url: vis_url + '/list_tracks?f-' + $.param(params), + dataType: "html", + error: function() { alert( "Could not add this dataset to browser." ); }, + success: function(table_html) { + var parent = window.parent; + + parent.show_modal("View Data in a New or Saved Visualization", "", { + "Cancel": function() { + parent.hide_modal(); + }, + "View in saved visualization": function() { + // Show new modal with saved visualizations. + parent.show_modal("Add Data to Saved Visualization", table_html, { + "Cancel": function() { + parent.hide_modal(); + }, + "Add to visualization": function() { + $(parent.document).find('input[name=id]:checked').each(function() { + var vis_id = $(this).val(); + dataset_params['id'] = vis_id + parent.location = vis_url + "/trackster?" + $.param(dataset_params); + }); + }, + }); + }, + "View in new visualization": function() { + parent.location = vis_url + "/trackster?" + $.param(dataset_params); + } + }); + } + }); + return false; + }; +}; + +/** + * Create popup menu for visualization icon. + */ +function init_viz_icon(icon) { + var icon = $(icon), + vis_url = icon.attr('href'), + dataset_id = icon.attr('dataset_id'), + visualizations = icon.attr('visualizations').split(','), + dbkey = icon.attr('dbkey'), + popup_menu_dict = {}, + + // Create visualization action. + create_viz_action = function(visualization) { + var action; + if (visualization === 'trackster') { + action = create_trackster_action_fn(vis_url, params, dbkey); + } + else { + action = function() { + window.parent.location = vis_url + '/' + visualization + '?' + + $.param(params); + }; + } + return action; + }, + params = {dataset_id: dataset_id}; + + // Add dbkey to params if it exists. + if (dbkey) { params['dbkey'] = dbkey; } + + // Populate menu dict with visualizations. + _.each(visualizations, function(visualization) { + popup_menu_dict[ + visualization.charAt(0).toUpperCase() + visualization.slice(1) + ] = create_viz_action(visualization); + }); + + // Set up action or menu. + if (visualizations.length === 1) { + // No need for popup menu because there's a single visualization. + icon.click(create_viz_action(visualizations[0])); + } + else { + make_popupmenu(icon, popup_menu_dict); + } +}; + + // Update the message for async operations function render_message(message, status) { $("div#message-container").html( "<div class=\"" + status + "message\">" + message + "</div><br/>" ); @@ -258,96 +347,6 @@ }); - // Trackster links - function init_trackster_links() { - // Add to trackster browser functionality - $(".trackster-add").live("click", function() { - var dataset = this, - dataset_jquery = $(this); - $.ajax({ - url: dataset_jquery.attr("data-url"), - dataType: "html", - error: function() { alert( "Could not add this dataset to browser." ); }, - success: function(table_html) { - var parent = window.parent; - - parent.show_modal("View Data in a New or Saved Visualization", "", { - "Cancel": function() { - parent.hide_modal(); - }, - "View in saved visualization": function() { - // Show new modal with saved visualizations. - parent.show_modal("Add Data to Saved Visualization", table_html, { - "Cancel": function() { - parent.hide_modal(); - }, - "Add to visualization": function() { - $(parent.document).find('input[name=id]:checked').each(function() { - var vis_id = $(this).val(); - parent.location = dataset_jquery.attr("action-url") + "&id=" + vis_id; - }); - }, - }); - }, - "View in new visualization": function() { - parent.location = dataset_jquery.attr("new-url"); - } - }); - } - }); - }); - } - - /** - * Create popup menu for visualization icon. - */ - function init_viz_icon(icon) { - var icon_link = $(icon); - make_popupmenu( icon_link , { - "${_("Trackster")}": function() { - $.ajax({ - url: icon_link.attr("data-url"), - dataType: "html", - error: function() { alert( "Could not add this dataset to browser." ); }, - success: function(table_html) { - var parent = window.parent; - - parent.show_modal("View Data in a New or Saved Visualization", "", { - "Cancel": function() { - parent.hide_modal(); - }, - "View in saved visualization": function() { - // Show new modal with saved visualizations. - parent.hide_modal(); - parent.show_modal("Add Data to Saved Visualization", table_html, { - "Cancel": function() { - parent.hide_modal(); - }, - "Add to visualization": function() { - $(parent.document).find('input[name=id]:checked').each(function() { - var vis_id = $(this).val(); - parent.location = icon_link.attr("action-url") + "&id=" + vis_id; - }); - }, - }); - }, - "View in new visualization": function() { - parent.location = icon_link.attr("new-url"); - } - }); - } - }); - }, - //"${_("Scatterplot")}": function() { - // var data_id = icon_link.parents(".historyItemContainer").attr("id").split("-")[1]; - // parent.galaxy_main.location = - // "${h.url_for( controller='visualization', action='scatterplot', col1=9, col2=13 )}" - // + "&dataset_id=" + data_id; - //} - } ); - return icon; - }; - _.each( $(".visualize-icon"), function(icon) { init_viz_icon(icon); }); @@ -472,6 +471,9 @@ init_history_items( $("div.historyItemWrapper"), "noinit" ); tag_handling(container); annotation_handling(container); + var viz_icon = container.find(".visualize-icon")[0]; + if (viz_icon) { init_viz_icon(viz_icon); } + // If new state is terminal, stop tracking if (TERMINAL_STATES.indexOf(val.state) !== -1) { if ( val.force_history_refresh ){ diff -r 5359d1066d91849fbf075f95f4999613d17a9c45 -r 32091cc60876e9720f2ae2b855e9e7f43e8c775a templates/root/history_common.mako --- a/templates/root/history_common.mako +++ b/templates/root/history_common.mako @@ -226,17 +226,24 @@ %if for_editing: <a href="${h.url_for( controller='tool_runner', action='rerun', id=data.id )}" target="galaxy_main" title='${_("Run this job again")}' class="icon-button arrow-circle tooltip"></a> - %if data.ext in app.datatypes_registry.get_available_tracks(): - <% - if data.dbkey != '?': - data_url = h.url_for( controller='visualization', action='list_tracks', dbkey=data.dbkey ) - data_url = data_url.replace( 'dbkey', 'f-dbkey' ) - else: - data_url = h.url_for( controller='visualization', action='list_tracks' ) - %> - <a href="javascript:void(0)" data-url="${data_url}" class="icon-button chart_curve tooltip visualize-icon" - action-url="${h.url_for( controller='tracks', action='browser', dataset_id=dataset_id)}" - new-url="${h.url_for( controller='tracks', action='index', dataset_id=dataset_id, default_dbkey=data.dbkey)}" title="Visualize"></a> + ## Visualization icon + visualizations. Using anchor attributes is a HACK to encode needed + ## information--URL base, dataset id, dbkey, visualizations--in anchor. + <% + visualizations = data.datatype.get_visualizations() + ## HACK: if there are visualizations, only provide trackster for now since others + ## are not ready. + if visualizations: + visualizations = [ 'trackster' ] + %> + %if visualizations: + <a href="${h.url_for( controller='visualization' )}" + class="icon-button chart_curve tooltip visualize-icon" + title="Visualize" + dataset_id="${dataset_id}" + %if data.dbkey != '?': + dbkey="${data.dbkey}" + %endif + visualizations="${','.join(visualizations)}"></a> %endif <% isPhylogenyData = isinstance(data.datatype, (Phyloxml, Nexus, Newick)) 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.
participants (1)
-
Bitbucket