From a4fd21d94e5412e120e6483e750557d5c8501949 Mon Sep 17 00:00:00 2001 From: zsloan Date: Thu, 2 Jun 2016 21:04:01 +0000 Subject: Fixed some issues with global search result tables, including: - Wrong digits for mean expression and additive effect - Bad loooking width on some columns, like Max LRS Location - Janky functionality for column resizing and drag-and-dropping (just disabled these functions) - Geno and Pheno global search tables weren't built in the same way, so now they are I also fixed the sorting to always put N/A's at the bottom of the table by editing naturalSort.js --- .../DataTables/js/dataTables.naturalSort.js | 122 +++++++++++---------- wqflask/wqflask/templates/gsearch_gene.html | 82 ++++---------- wqflask/wqflask/templates/gsearch_pheno.html | 67 ++++++----- wqflask/wqflask/templates/search_result_page.html | 20 ---- 4 files changed, 124 insertions(+), 167 deletions(-) diff --git a/wqflask/wqflask/static/new/packages/DataTables/js/dataTables.naturalSort.js b/wqflask/wqflask/static/new/packages/DataTables/js/dataTables.naturalSort.js index c9e26682..0198fd48 100755 --- a/wqflask/wqflask/static/new/packages/DataTables/js/dataTables.naturalSort.js +++ b/wqflask/wqflask/static/new/packages/DataTables/js/dataTables.naturalSort.js @@ -1,56 +1,68 @@ -(function() { - -/* - * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license - * Author: Jim Palmer (based on chunking idea from Dave Koelle) - * Contributors: Mike Grier (mgrier.com), Clint Priest, Kyle Adams, guillermo - * See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js - */ -function naturalSort (a, b) { - var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi, - sre = /(^[ ]*|[ ]*$)/g, - dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/, - hre = /^0x[0-9a-f]+$/i, - ore = /^0/, - // convert all to strings and trim() - x = a.toString().replace(sre, '') || '', - y = b.toString().replace(sre, '') || '', - // chunk/tokenize - xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'), - yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'), - // numeric, hex or date detection - xD = parseInt(x.match(hre)) || (xN.length != 1 && x.match(dre) && Date.parse(x)), - yD = parseInt(y.match(hre)) || xD && y.match(dre) && Date.parse(y) || null; - // first try and sort Hex codes or Dates - if (yD) - if ( xD < yD ) return -1; - else if ( xD > yD ) return 1; - // natural sorting through split numeric strings and default strings - for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) { - // find floats not starting with '0', string or 0 if not defined (Clint Priest) - var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0; - var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0; - // handle numeric vs string comparison - number < string - (Kyle Adams) - if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1; - // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2' - else if (typeof oFxNcL !== typeof oFyNcL) { - oFxNcL += ''; - oFyNcL += ''; - } - if (oFxNcL < oFyNcL) return -1; - if (oFxNcL > oFyNcL) return 1; - } - return 0; -} - -jQuery.extend( jQuery.fn.dataTableExt.oSort, { - "natural-asc": function ( a, b ) { - return naturalSort(a,b); - }, - - "natural-desc": function ( a, b ) { - return naturalSort(a,b) * -1; - } -} ); - +(function() { + +/* + * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license + * Author: Jim Palmer (based on chunking idea from Dave Koelle) + * Contributors: Mike Grier (mgrier.com), Clint Priest, Kyle Adams, guillermo + * See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js + */ +function naturalSort (a, b) { + var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi, + sre = /(^[ ]*|[ ]*$)/g, + dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/, + hre = /^0x[0-9a-f]+$/i, + ore = /^0/, + // convert all to strings and trim() + x = a.toString().replace(sre, '') || '', + y = b.toString().replace(sre, '') || '', + // chunk/tokenize + xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'), + yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'), + // numeric, hex or date detection + xD = parseInt(x.match(hre)) || (xN.length != 1 && x.match(dre) && Date.parse(x)), + yD = parseInt(y.match(hre)) || xD && y.match(dre) && Date.parse(y) || null; + + // first try and sort Hex codes or Dates + if (yD) + if ( xD < yD ) return -1; + else if ( xD > yD ) return 1; + + // natural sorting through split numeric strings and default strings + for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) { + // find floats not starting with '0', string or 0 if not defined (Clint Priest) + var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0; + var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0; + // handle numeric vs string comparison - number < string - (Kyle Adams) + if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1; + // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2' + else if (typeof oFxNcL !== typeof oFyNcL) { + oFxNcL += ''; + oFyNcL += ''; + } + if (oFxNcL < oFyNcL) return -1; + if (oFxNcL > oFyNcL) return 1; + } + + return 0; +} + +jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "natural-asc": function ( a, b ) { + // first check if null or n/a + if (a == "N/A" || a == "NA") return 1; + else if (b == "N/A" || b == "NA") return -1; + else { + return naturalSort(a,b); + } + }, + + "natural-desc": function ( a, b ) { + if (a == "N/A" || a == "NA") return 1; + else if (b == "N/A" || b == "NA") return -1; + else { + return naturalSort(a,b) * -1; + } + } +} ); + }()); \ No newline at end of file diff --git a/wqflask/wqflask/templates/gsearch_gene.html b/wqflask/wqflask/templates/gsearch_gene.html index 37e26817..ff4254aa 100755 --- a/wqflask/wqflask/templates/gsearch_gene.html +++ b/wqflask/wqflask/templates/gsearch_gene.html @@ -38,7 +38,7 @@ Description Location Mean - Max
LRS ? + Max  
LRS ? Max LRS Location Additive
Effect ? @@ -55,11 +55,11 @@ {{ this_trait.name }} {{ this_trait.symbol }} {{ this_trait.description_display }} - {{ this_trait.location_repr }} - {{ this_trait.mean }} - {{ this_trait.LRS_score_repr }} - {{ this_trait.LRS_location_repr }} - {{ this_trait.additive }} + {{ this_trait.location_repr }} + {{ '%0.3f' % this_trait.mean|float }} + {{ '%0.1f' % this_trait.LRS_score_repr|float }} + {{ this_trait.LRS_location_repr }} + {{ '%0.3f' % this_trait.additive|float }} {% endfor %} @@ -100,42 +100,6 @@ } return parseFloat(x); } - - jQuery.fn.dataTableExt.oSort['cust-txt-asc'] = function (a, b) { - var x = getValue(a); - var y = getValue(b); - - if (x == 'N/A' || x == '') { - return 1; - } - else if (y == 'N/A' || y == '') { - return -1; - } - else { - return ((x < y) ? -1 : ((x > y) ? 1 : 0)); - } - }; - - jQuery.fn.dataTableExt.oSort['cust-txt-asc'] = function (a, b) { - var x = getValue(a); - var y = getValue(b); - - if (x == 'N/A' || x == '') { - return 1; - } - else if (y == 'N/A' || y == '') { - return -1; - } - else { - return ((x < y) ? -1 : ((x > y) ? 1 : 0)); - } - }; - - jQuery.fn.dataTableExt.oSort['cust-txt-desc'] = function (a, b) { - var x = getValue(a); - var y = getValue(b); - return ((x < y) ? 1 : ((x > y) ? -1 : 0)); - }; $.fn.dataTable.ext.order['dom-checkbox'] = function ( settings, col ) { @@ -167,25 +131,27 @@ } ], "columns": [ - { "data": "checkbox", "orderable" : false }, - { "data": "index", "orderable" : true }, - { "data": "species", "orderable" : true }, - { "data": "group", "orderable" : true }, - { "data": "tissue", "orderable" : true }, - { "data": "dataset", "orderable" : true }, - { "data": "record", "orderable" : true }, - { "data": "symbol", "orderable" : true }, - { "data": "description", "orderable" : true }, - { "data": "location", "orderable" : true }, - { "data": "mean", "orderable" : true }, - { "data": "max_lrs", "orderable" : true }, - { "data": "max_lrs_location", "orderable" : true }, - { "data": "additive_effect", "orderable" : true } + { "type": "natural" }, + { "type": "natural" }, + { "type": "natural" }, + { "type": "natural", "width": "8%" }, + { "type": "natural" }, + { "type": "natural" }, + { "type": "natural" }, + { "type": "natural" }, + { "type": "natural" }, + { "type": "natural", "width": "8%" }, + { "type": "natural" }, + { "type": "natural", "width": "5%" }, + { "type": "natural", "width": "8%" }, + { "type": "natural" } ], - "sDom": "RZBtir", + "order": [[1, "asc" ]], + "sDom": "Btir", "autoWidth": false, + "bDeferRender": true, "scrollY": "800px", - "bDeferRender": true + "scrollCollapse": false } ); console.timeEnd("Creating table"); diff --git a/wqflask/wqflask/templates/gsearch_pheno.html b/wqflask/wqflask/templates/gsearch_pheno.html index 3c9f6841..b1f86adc 100755 --- a/wqflask/wqflask/templates/gsearch_pheno.html +++ b/wqflask/wqflask/templates/gsearch_pheno.html @@ -25,10 +25,11 @@

- +
+
- + @@ -44,21 +45,22 @@ {% for this_trait in trait_list %} - - - - - - - - - - - + + + + + + + + + + + {% endfor %}
Index Species Group
{{ loop.index }}{{ this_trait.dataset.group.species }}{{ this_trait.dataset.group.name }}{{ this_trait.name }}{{ this_trait.description_display }}{{ this_trait.authors }}{{ this_trait.pubmed_text }}{{ this_trait.LRS_score_repr }}{{ this_trait.LRS_location_repr }}{{ '%0.3f' % this_trait.additive|float }}{{ loop.index }}{{ this_trait.dataset.group.species }}{{ this_trait.dataset.group.name }}{{ this_trait.name }}{{ this_trait.description_display }}{{ this_trait.authors }}{{ this_trait.pubmed_text }}{{ '%0.1f' % this_trait.LRS_score_repr|float }}{{ this_trait.LRS_location_repr }}{{ '%0.3f' % this_trait.additive|float }}
+ @@ -127,20 +129,7 @@ console.time("Creating table"); $('#trait_table').DataTable( { - "columns": [ - { "bSortClasses": false }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural", "width": "20%"}, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural", "width": "12%"}, - { "type": "natural" } - ], - "order": [[ 1, "asc" ]], + "paging": false, "buttons": [ { extend: 'csvHtml5', @@ -152,15 +141,25 @@ } } ], - "sDom": "RZBtir", + "columns": [ + { "type": "natural" }, + { "type": "natural" }, + { "type": "natural" }, + { "type": "natural" }, + { "type": "natural" }, + { "type": "natural", "width": "30%"}, + { "type": "natural", "width": "25%"}, + { "type": "natural" }, + { "type": "natural", "width": "8%"}, + { "type": "natural", "width": "12%"}, + { "type": "natural" } + ], + "order": [[1, "asc" ]], + "sDom": "Btir", "autoWidth": false, - "bLengthChange": true, "bDeferRender": true, - "scrollCollapse": false, - "colResize": { - "tableWidthFixed": false, - }, - "paging": false + "scrollY": "800px", + "scrollCollapse": false } ); console.timeEnd("Creating table"); }); diff --git a/wqflask/wqflask/templates/search_result_page.html b/wqflask/wqflask/templates/search_result_page.html index a4ef68b9..7d852e42 100755 --- a/wqflask/wqflask/templates/search_result_page.html +++ b/wqflask/wqflask/templates/search_result_page.html @@ -219,26 +219,6 @@ } }); -/* - serverSide: true, - ajax: function ( data, callback, settings ) { - var out = []; - - for ( var i=data.start, ien=data.start+data.length ; i