0b18daa6dccb951ca6e7ad097ef56ca01f38bcc3
kate
  Thu Mar 1 23:03:50 2012 -0800
Factoring out a bit more shared code
diff --git src/hg/js/encodeChipMatrix.js src/hg/js/encodeChipMatrix.js
index bddb781..775f8e4 100644
--- src/hg/js/encodeChipMatrix.js
+++ src/hg/js/encodeChipMatrix.js
@@ -32,31 +32,32 @@
         encodeMatrix.show($matrixTable);
 
         // set up structures for antibody targets and groups
         antibodyGroups = encodeProject.getAntibodyGroups(antibodies);
 
         // 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
         matrix = makeExperimentMatrix(experiments, expIdHash, antibodyTargetExps);
 
        // fill in table using matrix
-        tableOut($matrixTable, matrix, cellTiers, antibodyGroups, antibodyTargetExps);
+        encodeMatrix.tableOut($matrixTable, matrix, cellTiers, 
+                        antibodyGroups, antibodyTargetExps, tableHeaderOut, rowAddCells);
     }
 
     function makeExperimentMatrix(experiments, expIdHash, antibodyTargetExps) {
         // Populate antibodyTarget vs. cellType array with counts of experiments
 
         var antibody, target, cellType;
         var matrix = {};
 
         $.each(experiments, function (i, exp) {
             // exclude ref genome annotations
             if (exp.cellType === 'None') {
                 return true;
             }
             if (expIdHash[exp.ix] === undefined) {
                 return true;
@@ -101,30 +102,31 @@
         var antibodyTarget;
 
         // fill in column headers from antibody targets returned by server
         $tableHeader = $('#columnHeaders');
         $thead = $('thead');
 
         // 1st column is row headers
         // colgroups are needed to support cross-hair hover effect
         $thead.before('<colgroup></colgroup>');
 
         $.each(antibodyGroups, function (i, group) {
             $tableHeader.append('<th class="groupType"><div class="verticalText">' + 
                                 group.label + '</div></th>');
             maxLen = Math.max(maxLen, group.label.length);
             $thead.before('<colgroup></colgroup>');
+
             $.each(group.targets, function (i, target) {
                 // prune out targets with no experiments 
                 if (antibodyTargetExps[target] === undefined) {
                     return true;
                 }
                 antibodyTarget = encodeProject.getAntibodyTarget(target);
                 $tableHeader.append('<th class="elementType" title="' +
                                 antibodyTarget.description +
                                 '"><div class="verticalText">' + target + '</div></th>');
                 // add colgroup element to support cross-hair hover effect
                 $thead.before('<colgroup class="experimentCol"></colgroup>');
                 maxLen = Math.max(maxLen, target.length);
             });
         });
         // adjust size of headers based on longest label length
@@ -185,85 +187,21 @@
                        '&hgt_mdbVar2=cell&hgt_mdbVal2=' + $(this).data().cellType +
                        '&hgt_mdbVar3=antibody');
                     // TODO: html encode ?
                     antibodyTarget = encodeProject.getAntibodyTarget($(this).data().target);
                     $.each(antibodyTarget.antibodies, function (i, antibody) {
                         url += ('&hgt_mdbVal3=' + antibody);
                     });
                     url += '&hgt_mdbVar4=view&hgt_mdbVal4=Any';
                         // TODO: open search window 
                     window.open(url, "searchWindow");
                 });
             });
         });
     }
 
-    function tableMatrixOut($table, matrix, cellTiers, antibodyGroups, antibodyTargetExps) {
-        // 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;
-
-        // add sections for each Tier of cells
-        $.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, antibodyGroups, antibodyTargetExps, 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);
-                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, antibodyGroups, antibodyTargetExps, 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, antibodyGroups, antibodyTargetExps) {
-        // Create table with rows for each cell type and columns for each antibody target
-
-        tableHeaderOut($table, antibodyGroups, antibodyTargetExps);
-        tableMatrixOut($table, matrix, cellTiers, antibodyGroups, antibodyTargetExps);
-
-        encodeMatrix.addTableFloatingHeader($table);
-        encodeMatrix.rotateTableCells($table);
-        encodeMatrix.hoverTableCrossHair($table);
-    }
-
     // initialize
     encodeMatrix.start($matrixTable);
 
     // load data from server and set up callback
     encodeProject.loadAllFromServer(requests, handleServerData);
 });