0b18daa6dccb951ca6e7ad097ef56ca01f38bcc3
kate
  Thu Mar 1 23:03:50 2012 -0800
Factoring out a bit more shared code
diff --git src/hg/js/encodeDataMatrix.js src/hg/js/encodeDataMatrix.js
index b38d64e..731b423 100644
--- src/hg/js/encodeDataMatrix.js
+++ src/hg/js/encodeDataMatrix.js
@@ -40,31 +40,32 @@
         // set up structures for data types and their groups
         // data type labels tucked into their tiers
         dataGroups = encodeProject.getDataGroups(dataTypes);
 
         // set up structures for cell types and their tiers
         cellTiers = encodeProject.getCellTiers(cellTypes);
 
         // use to filter out experiments not in this assembly
         expIdHash = encodeProject.getExpIdHash(expIds);
 
         // gather experiments into matrix
         // NOTE: dataTypeExps is populated here
         matrix = makeExperimentMatrix(experiments, expIdHash, dataTypeExps);
 
         // fill in table using matrix
-        tableOut($matrixTable, matrix, cellTiers, dataGroups, dataTypeExps);
+        encodeMatrix.tableOut($matrixTable, matrix, cellTiers, 
+                    dataGroups, dataTypeExps, tableHeaderOut, rowAddCells);
     }
 
     function makeExperimentMatrix(experiments, expIdHash, dataTypeExps) {
         // Populate dataType vs. cellType array with counts of experiments
 
         var dataType, cellType;
         var matrix = {};
 
         $.each(experiments, function (i, exp) {
             // exclude ref genome annotations
             if (exp.cellType === 'None') {
                 return true;
             }
             // exclude experiments lacking an expID (not in this assembly)
             if (expIdHash[exp.ix] === undefined) {
@@ -175,86 +176,21 @@
                 });
                 $td.click(function() {
                     var url = encodeMatrix.getSearchUrl(encodeProject.getAssembly());
                     // TODO: encapsulate var names
                     url +=
                        ('&hgt_mdbVar1=dataType&hgt_mdbVal1=' + $(this).data().dataType +
                        '&hgt_mdbVar2=cell&hgt_mdbVal2=' + $(this).data().cellType +
                        '&hgt_mdbVar3=view&hgt_mdbVal3=Any');
                     // specifying window name limits open window glut
                     window.open(url, "searchWindow");
                 });
             });
         });
     }
 
-    function tableMatrixOut($table, matrix, cellTiers, dataGroups, dataTypeExps) {
-        // Fill in matrix --
-        // add rows with cell type labels (column 1) and cells for experiments
-        // add sections for each Tier of cell type
-
-        var maxLen, karyotype, cellType;
-        var $row;
-
-        $.each(cellTiers, function (i, tier) {
-            //skip bogus 4th tier (not my property ?)
-            if (tier === undefined) {
-                return true;
-            }
-            $row = $('<tr class="matrix"><th class="groupType">' + 
-                                "Tier " + tier.term + '</th></td></tr>');
-            rowAddCells($row, dataGroups, dataTypeExps, matrix, null);
-            $table.append($row);
-            maxLen = 0;
-
-            $.each(tier.cellTypes, function (i, term) {
-                if (!term) {
-                    return true;
-                }
-                if (!matrix[term]) {
-                    return true;
-                }
-                cellType = encodeProject.getCellType(term);
-                // TODO: recognize cancer*
-                // NOTE: coupled to CSS
-                karyotype = cellType.karyotype;
-                if (karyotype !== 'cancer' && karyotype !== 'normal') {
-                    karyotype = 'unknown';
-                }
-                // note karyotype bullet layout requires non-intuitive placement
-                // in code before the span that shows to it's left
-                $row = $('<tr>' +
-                    '<th class="elementType">' +
-                    '<span style="float:right; text-align: right;" title="karyotype: ' + karyotype + '" class="karyotype ' + karyotype + '">&bull;</span>' + 
-                    '<span title="' + cellType.description + '"><a href="/cgi-bin/hgEncodeVocab?ra=encode/cv.ra&term=' + cellType.term + '">' + cellType.term + '</a>' + 
-                    '</th>'
-                    );
-                maxLen = Math.max(maxLen, cellType.term.length);
-
-                rowAddCells($row, dataGroups, dataTypeExps, matrix, cellType.term);
-                $table.append($row);
-            });
-            // adjust size of row headers based on longest label length
-            $('tbody th').css('height', '1em');
-            $('tbody th').css('width', (String((maxLen/2 + 2)).concat('em')));
-        });
-        $('body').append($table);
-    }
-
-    function tableOut($table, matrix, cellTiers, dataGroups, dataTypeExps) {
-        // Create table with rows for each cell types and columns for each data type,
-        // based on matrix 
-
-        tableHeaderOut($table, dataGroups, dataTypeExps);
-        tableMatrixOut($table, matrix, cellTiers, dataGroups, dataTypeExps);
-
-        encodeMatrix.addTableFloatingHeader($table);
-        encodeMatrix.rotateTableCells($table);
-        encodeMatrix.hoverTableCrossHair($table);
-    }
-
     // initialize application
     encodeMatrix.start($matrixTable);
 
     // load data from server and do callback
     encodeProject.loadAllFromServer(requests, handleServerData);
 });