Commits

Anonymous committed 54898b0

Visualization framework improvements.

Comments (0)

Files changed (5)

static/scripts/mvc/tools.js

     },
     
     /**
+     * Set many input values at once.
+     */
+    set_input_values: function(inputs_dict) {
+        var self = this;
+        _.each(_.keys(inputs_dict), function(input_name) {
+            self.set_input_value(input_name, inputs_dict[input_name]); 
+        });
+    },
+    
+    /**
      * Run tool; returns a Deferred that resolves to the tool's output(s).
      */
     run: function() {

static/scripts/viz/trackster.js

 var extend = require('class').extend,
     slotting = require('slotting'),
     painters = require('painters');
-    
-    
-// ---- Canvas management and extensions ----
-
-/**
- * Canvas manager is used to create canvases, for browsers, this deals with
- * backward comparibility using excanvas, as well as providing a pattern cache
- */
-var CanvasManager = function( document, default_font ) {
-    this.document = document;
-    this.default_font = default_font !== undefined ? default_font : "9px Monaco, Lucida Console, monospace";
-    
-    this.dummy_canvas = this.new_canvas();
-    this.dummy_context = this.dummy_canvas.getContext('2d');
-    this.dummy_context.font = this.default_font;
-    
-    this.char_width_px = this.dummy_context.measureText("A").width;
-    
-    this.patterns = {};
-
-    // FIXME: move somewhere to make this more general
-    this.load_pattern( 'right_strand', "/visualization/strand_right.png" );
-    this.load_pattern( 'left_strand', "/visualization/strand_left.png" );
-    this.load_pattern( 'right_strand_inv', "/visualization/strand_right_inv.png" );
-    this.load_pattern( 'left_strand_inv', "/visualization/strand_left_inv.png" );
-}
-
-extend( CanvasManager.prototype, {
-    load_pattern: function( key, path ) {
-        var patterns = this.patterns,
-            dummy_context = this.dummy_context,
-            image = new Image();
-        image.src = galaxy_paths.attributes.image_path + path;
-        image.onload = function() {
-            patterns[key] = dummy_context.createPattern( image, "repeat" );
-        }
-    },
-    get_pattern: function( key ) {
-        return this.patterns[key];
-    },
-    new_canvas: function() {
-        var canvas = this.document.createElement("canvas");
-        // If using excanvas in IE, we need to explicately attach the canvas
-        // methods to the DOM element
-        if (window.G_vmlCanvasManager) { G_vmlCanvasManager.initElement(canvas); }
-        // Keep a reference back to the manager
-        canvas.manager = this;
-        return canvas;
-    }
-});
 
 // ---- Web UI specific utilities ----
 
     this.data_url = ('data_url' in obj_dict ? obj_dict.data_url : default_data_url);
     this.data_url_extra_params = {}
     this.data_query_wait = ('data_query_wait' in obj_dict ? obj_dict.data_query_wait : DEFAULT_DATA_QUERY_WAIT);
-    this.dataset_check_url = converted_datasets_state_url;
+    this.dataset_check_url = ('converted_datasets_state_url' in obj_dict ? obj_dict.converted_datasets_state_url : converted_datasets_state_url);
     
     // A little ugly creating data manager right now due to transition to Backbone-based objects.
-    var dataset = new Dataset({
-        id: obj_dict.dataset_id,
-        hda_ldda: obj_dict.hda_ldda
-    });
+    var track = this,
+        dataset = new Dataset({
+            id: obj_dict.dataset_id,
+            hda_ldda: obj_dict.hda_ldda
+        });
     this.data_manager = ('data_manager' in obj_dict ? 
                          obj_dict.data_manager : 
                          new GenomeDataManager({
                              dataset: dataset,
-                             data_url: default_data_url,
+                             data_url: track.data_url,
+                             dataset_state_url: track.dataset_check_url,
                              data_mode_compatible: this.data_and_mode_compatible,
                              can_subset: this.can_subset,
                          }));

static/scripts/viz/trackster_ui.js

  * Create new object from a template. A template can be either an object dictionary or an 
  * object itself.
  */
-var object_from_template = function(template, container) {
+var object_from_template = function(template, view, container) {
     if ('copy' in template) {
         // Template is an object.
         return template.copy(container);
                 drawable_type,
                 drawable;
             for (var i = 0; i < drawables_config.length; i++) {
-                view.add_drawable( object_from_template( drawables_config[i], view ) );
+                view.add_drawable( object_from_template( drawables_config[i], view, view ) );
             }
         }
         

static/scripts/viz/visualization.js

 /**
- * Model, view, and controller objects for Galaxy tools and tool panel.
+ * Model, view, and controller objects for Galaxy visualization framework.
+ * 
+ * Required libraries: Backbone, jQuery
  *
  * Models have no references to views, instead using events to indicate state 
  * changes; this is advantageous because multiple views can use the same object 
     }
 });
 
+// TODO: move to Backbone
+
+/**
+ * Canvas manager is used to create canvases, for browsers, this deals with
+ * backward comparibility using excanvas, as well as providing a pattern cache
+ */
+var CanvasManager = function(default_font) {
+    this.default_font = default_font !== undefined ? default_font : "9px Monaco, Lucida Console, monospace";
+    
+    this.dummy_canvas = this.new_canvas();
+    this.dummy_context = this.dummy_canvas.getContext('2d');
+    this.dummy_context.font = this.default_font;
+    
+    this.char_width_px = this.dummy_context.measureText("A").width;
+    
+    this.patterns = {};
+
+    // FIXME: move somewhere to make this more general
+    this.load_pattern( 'right_strand', "/visualization/strand_right.png" );
+    this.load_pattern( 'left_strand', "/visualization/strand_left.png" );
+    this.load_pattern( 'right_strand_inv', "/visualization/strand_right_inv.png" );
+    this.load_pattern( 'left_strand_inv', "/visualization/strand_left_inv.png" );
+}
+
+_.extend( CanvasManager.prototype, {
+    load_pattern: function( key, path ) {
+        var patterns = this.patterns,
+            dummy_context = this.dummy_context,
+            image = new Image();
+        image.src = galaxy_paths.attributes.image_path + path;
+        image.onload = function() {
+            patterns[key] = dummy_context.createPattern( image, "repeat" );
+        }
+    },
+    get_pattern: function( key ) {
+        return this.patterns[key];
+    },
+    new_canvas: function() {
+        var canvas = $("<canvas/>")[0];
+        // If using excanvas in IE, we need to explicately attach the canvas
+        // methods to the DOM element
+        if (window.G_vmlCanvasManager) { G_vmlCanvasManager.initElement(canvas); }
+        // Keep a reference back to the manager
+        canvas.manager = this;
+        return canvas;
+    }
+});
+
 /**
  * Generic cache that handles key/value pairs.
  */ 
 var Cache = Backbone.Model.extend({
     defaults: {
         num_elements: 20,
-        obj_cache: {},
-        key_ary: []
+        obj_cache: null,
+        key_ary: null
+    },
+
+    initialize: function(options) {
+        this.clear();
     },
     
     get_elt: function(key) {
         dataset: null,
         filters_manager: null,
         data_url: null,
+        dataset_state_url: null,
         data_mode_compatible: function(entry, mode) { return true; },
         can_subset: function(entry) { return false; }
     }),
+
+    /**
+     * Returns deferred that resolves to true when dataset is ready (or false if dataset
+     * cannot be used).
+     */
+    data_is_ready: function() {
+        var dataset = this.get('dataset'),
+            ready_deferred = $.Deferred(),
+            ss_deferred = new ServerStateDeferred({
+                ajax_settings: {
+                    url: this.get('dataset_state_url'),
+                    data: {
+                        dataset_id: dataset.id,
+                        hda_ldda: dataset.get('hda_ldda')
+                    },
+                    dataType: "json"
+                },
+                interval: 5000,
+                success_fn: function(response) { return response !== "pending"; }
+            });
+
+        $.when(ss_deferred.go()).then(function(response) {
+            ready_deferred.resolve(response === "ok" || response === "data" );
+        });
+        return ready_deferred;
+    },
     
     /**
      * Load data from server; returns AJAX object so that use of Deferred is possible.
             end: this.get('end') 
         });
     },
+
+    length: function() {
+        return this.get('end') - this.get('start');
+    },
     
     /** Returns region in canonical form chrom:start-end */
     toString: function() {
     }
 });
 
+var GenomeRegionCollection = Backbone.Collection.extend({
+    model: GenomeRegion
+});
+
 /**
  * A genome browser bookmark.
  */

templates/base_panels.mako

         var galaxy_paths = new GalaxyPaths({
             root_path: '${h.url_for( "/" )}',
             image_path: '${h.url_for( "/static/images" )}',
-            tool_url: '${h.url_for( controller="/api/tools" )}'
+            tool_url: '${h.url_for( controller="/api/tools" )}',
+            data_url: '${h.url_for( controller="tracks", action="data" )}',
+            raw_data_url: '${h.url_for( controller="tracks", action="raw_data" )}',
+            converted_datasets_state_url: '${h.url_for( controller="tracks", action="converted_datasets_state" )}',
+            dataset_state_url: '${h.url_for( controller="tracks", action="dataset_state" )}'
         });
     </script>
 </%def>