1. galaxy
  2. galaxy-central

Commits

Dannon Baker  committed ccfcca6

Updates to tabular dataset display. Ship first data chunk with the page, and use metadata or datatype column_names as a table header row if available.

  • Participants
  • Parent commits 0bd0c35
  • Branches default

Comments (0)

Files changed (4)

File lib/galaxy/datatypes/tabular.py

View file
 
 class Tabular( data.Text ):
     """Tab delimited data"""
-    CHUNK_SIZE = 20000
+    CHUNK_SIZE = 50000
 
     """Add metadata elements"""
     MetadataElement( name="comment_lines", default=0, desc="Number of comment lines", readonly=False, optional=True, no_value=0 )
             raise Exception, "Can't create peek rows %s" % str( exc )
         return "".join( out )
 
+    def get_chunk(self, trans, dataset, chunk):
+        ck_index = int(chunk)
+        f = open(dataset.file_name)
+        f.seek(ck_index * self.CHUNK_SIZE)
+        # If we aren't at the start of the file, seek to next newline.  Do this better eventually.
+        if f.tell() != 0:
+            cursor = f.read(1)
+            while cursor and cursor != '\n':
+                cursor = f.read(1)
+        ck_data = f.read(self.CHUNK_SIZE)
+        cursor = f.read(1)
+        while cursor and ck_data[-1] != '\n':
+            ck_data += cursor
+            cursor = f.read(1)
+        return to_json_string({'ck_data': ck_data, 'ck_index': ck_index+1})
+
     def display_data(self, trans, dataset, preview=False, filename=None, to_ext=None, chunk=None):
         #TODO Prevent failure when displaying extremely long > 50kb lines.
         if to_ext:
             return self._serve_raw(trans, dataset, to_ext)
         if chunk:
-            ck_index = int(chunk)
-            f = open(dataset.file_name)
-            f.seek(ck_index * self.CHUNK_SIZE)
-            # If we aren't at the start of the file, seek to next newline.  Do this better eventually.
-            if f.tell() != 0:
-                cursor = f.read(1)
-                while cursor and cursor != '\n':
-                    cursor = f.read(1)
-            ck_data = f.read(self.CHUNK_SIZE)
-            cursor = f.read(1)
-            while cursor and ck_data[-1] != '\n':
-                ck_data += cursor
-                cursor = f.read(1)
-            return to_json_string({'ck_data': ck_data, 'ck_index': ck_index+1})
-        return trans.fill_template( "/dataset/tabular_chunked.mako",dataset = dataset)
+            return self.get_chunk(trans, dataset, chunk)
+        else:
+            column_names = 'null'
+            if dataset.metadata.column_names:
+                column_names = dataset.metadata.column_names
+            elif hasattr(dataset.datatype, 'column_names'):
+                column_names = dataset.datatype.column_names
+            return trans.fill_template( "/dataset/tabular_chunked.mako",
+                        dataset = dataset,
+                        chunk = self.get_chunk(trans, dataset, 0),
+                        column_number = dataset.metadata.columns,
+                        column_names = column_names,
+                        column_types = dataset.metadata.column_types)
 
     def set_peek( self, dataset, line_count=None, is_multi_byte=False):
         super(Tabular, self).set_peek( dataset, line_count=line_count, is_multi_byte=is_multi_byte)

File static/june_2007_style/base.less

View file
     top:10px;
     height:32px;
     width:32px;
+    display:none;
     background:url(largespinner.gif);
 }
 

File static/june_2007_style/blue/base.css

View file
 div.toolSectionBody div.toolPanelLabel{padding-top:5px;padding-bottom:5px;margin-left:16px;margin-right:10px;display:list-item;list-style:none outside;}
 div.toolTitleNoSection{padding-bottom:5px;font-weight:bold;}
 #tool-search{padding-top:5px;padding-bottom:10px;position:relative;}
-#loading_indicator{position:fixed;right:10px;top:10px;height:32px;width:32px;background:url(largespinner.gif);}
+#loading_indicator{position:fixed;right:10px;top:10px;height:32px;width:32px;display:none;background:url(largespinner.gif);}
 #content_table td{text-align:right;white-space:nowrap;padding:2px 10px;}
 #content_table td.stringalign{text-align:left;}
 .toolMenuAndView .toolForm{float:left;background-color:white;margin:10px;}

File templates/dataset/tabular_chunked.mako

View file
 <%def name="javascripts()">
     ${parent.javascripts()}
     <script type="text/javascript">
+        var DATASET_URL   = "${h.url_for( controller='/dataset', action='display', dataset_id=trans.security.encode_id( dataset.id ))}";
+        var COLUMN_NUMBER  = ${column_number};
+        var COLUMN_TYPES = ${column_types};
+        var COLUMN_NAMES = ${column_names};
 
-        var DATASET_URL   = "${h.url_for( controller='/dataset', action='display', dataset_id=trans.security.encode_id( dataset.id ))}";
-        var DATASET_COLS  = ${dataset.metadata.columns};
-        var DATASET_TYPES = ${dataset.metadata.column_types};
-
+        var chunk = ${chunk};
         var current_chunk = 0;
 
         function renderCell(cell_contents, index, colspan){
             if (colspan !== undefined){
                 return $('<td>').attr('colspan', colspan).addClass('stringalign').text(cell_contents);
             }
-            else if (DATASET_TYPES[index] == 'str'){
+            else if (COLUMN_TYPES[index] == 'str'){
                 /* Left align all str columns, right align the rest */
                 return $('<td>').addClass('stringalign').text(cell_contents);;
             }
             /* Check length of cells to ensure this is a complete row. */
             var cells = line.split('\t');
             var row = $('<tr>');
-            if (cells.length == DATASET_COLS){
+            if (cells.length == COLUMN_NUMBER){
                 $.each(cells, function(index, cell_contents){
                     row.append(renderCell(cell_contents, index));
                 });
             }
-            else if(cells.length > DATASET_COLS){
+            else if(cells.length > COLUMN_NUMBER){
                 /* SAM file or like format with optional metadata included */
-                $.each(cells.slice(0, DATASET_COLS -1), function(index, cell_contents){
+                $.each(cells.slice(0, COLUMN_NUMBER -1), function(index, cell_contents){
                     row.append(renderCell(cell_contents, index));
                 });
-                row.append(renderCell(cells.slice(DATASET_COLS -1).join('\t'), DATASET_COLS-1));
+                row.append(renderCell(cells.slice(COLUMN_NUMBER -1).join('\t'), COLUMN_NUMBER-1));
             }
-            else if(DATASET_COLS > 5 && cells.length == DATASET_COLS - 1 ){
+            else if(COLUMN_NUMBER > 5 && cells.length == COLUMN_NUMBER - 1 ){
                 /* SAM file or like format with optional metadata missing */
                 $.each(cells, function(index, cell_contents){
                     row.append(renderCell(cell_contents, index));
             }
             else{
                 /* Comment line, just return the one cell*/
-                row.append(renderCell(line, 0, DATASET_COLS));
+                row.append(renderCell(line, 0, COLUMN_NUMBER));
             }
             return row;
         }
 
-        function fillTable(){
-            if (current_chunk !== -1){
-                var table = $('#content_table');
-                $.getJSON(DATASET_URL, {chunk: current_chunk}, function (result) {
-                    if (result.ck_data !== ""){
-                        var lines = result.ck_data.split('\n');
-                        $.each(lines, function(index, line){
-                            table.append(renderRow(line));
-                        });
-                        current_chunk = result.ck_index;
-                    }
-                    else {
-                        current_chunk = -1;
-                    }
+        function renderChunk(chunk){
+            var table = $('#content_table');
+            if (chunk.ck_data == ""){
+                current_chunk = -1;
+            }
+            else if(chunk.ck_index === current_chunk + 1){
+                if (current_chunk === 0 && COLUMN_NAMES){
+                    table.append('<tr><th>' + COLUMN_NAMES.join('</th><th>') + '</th></tr>');
+                }
+                var lines = chunk.ck_data.split('\n');
+                $.each(lines, function(index, line){
+                    table.append(renderRow(line));
                 });
+                current_chunk = chunk.ck_index;
             }
         }
 
         $(document).ready(function(){
-            fillTable();
+            renderChunk(chunk);
             $(window).scroll(function(){
                 if ($(window).scrollTop() == $(document).height() - $(window).height()){
-                    fillTable();
+                    if (current_chunk !== -1){
+                        $.getJSON(DATASET_URL,
+                                  {chunk: current_chunk},
+                                  function(result){renderChunk(result)});
+                    }
                 }
             });
-        $('#loading_indicator').ajaxStart(function(){
-           $(this).show();
-        }).ajaxStop(function(){
-           $(this).hide();
-        });
+            $('#loading_indicator').ajaxStart(function(){
+               $(this).show();
+            }).ajaxStop(function(){
+               $(this).hide();
+            });
         });
     </script>
 </%def>