diff --git a/src/matrix/sort_key.js b/src/matrix/sort_key.js index bccec30e99257714a0451d9d06cb2004710df6a1..a884813fd048f9697694870792e1e0f59a379270 100644 --- a/src/matrix/sort_key.js +++ b/src/matrix/sort_key.js @@ -1,4 +1,4 @@ -morpheus.MatchesOnTopSortKey = function(project, modelIndices, name) { +morpheus.MatchesOnTopSortKey = function (project, modelIndices, name) { var modelHighlight = {}; var p = project; var viewIndices = []; @@ -6,7 +6,7 @@ morpheus.MatchesOnTopSortKey = function(project, modelIndices, name) { modelHighlight[modelIndices[i]] = true; viewIndices.push(i); } - this.comparator = function(i1, i2) { + this.comparator = function (i1, i2) { var a = modelHighlight[i1] === undefined ? 0 : 1; var b = modelHighlight[i2] == undefined ? 0 : 1; return (a > b ? -1 : (a === b ? 0 : 1)); @@ -15,22 +15,22 @@ morpheus.MatchesOnTopSortKey = function(project, modelIndices, name) { this.name = name; }; morpheus.MatchesOnTopSortKey.prototype = { - init : function() { + init: function () { }, - getSortOrder : function() { + getSortOrder: function () { return 2; }, - getComparator : function() { + getComparator: function () { return this.comparator; }, - getValue : function(i) { + getValue: function (i) { return i; }, - toString : function(i) { + toString: function (i) { return this.name; } }; -morpheus.SortKey = function(field, sortOrder) { +morpheus.SortKey = function (field, sortOrder) { if (typeof sortOrder === 'string') { sortOrder = morpheus.SortKey.SortOrder[sortOrder.toUpperCase()]; } @@ -42,16 +42,16 @@ morpheus.SortKey = function(field, sortOrder) { }; morpheus.SortKey.SortOrder = { - ASCENDING : 0, - DESCENDING : 1, - UNSORTED : 2, - CUSTOM : 3, - TOP_N : 4 + ASCENDING: 0, + DESCENDING: 1, + UNSORTED: 2, + CUSTOM: 3, + TOP_N: 4 }; -morpheus.SortKey.ASCENDING_COMPARATOR = function(a, b) { +morpheus.SortKey.ASCENDING_COMPARATOR = function (a, b) { // we want NaNs to end up at the bottom - var aNaN = (a == null || _.isNumber(a) && isNaN(a)); - var bNaN = (b == null || _.isNumber(b) && isNaN(b)); + var aNaN = (a == null || _.isNumber(a) && isNaN(a) || a.length === 0); + var bNaN = (b == null || _.isNumber(b) && isNaN(b) || b.length === 0); if (aNaN && bNaN) { return 0; } @@ -71,10 +71,10 @@ morpheus.SortKey.ASCENDING_COMPARATOR = function(a, b) { return (a === b ? 0 : (a < b ? -1 : 1)); }; -morpheus.SortKey.DESCENDING_COMPARATOR = function(a, b) { +morpheus.SortKey.DESCENDING_COMPARATOR = function (a, b) { - var aNaN = (a == null || _.isNumber(a) && isNaN(a)); - var bNaN = (b == null || _.isNumber(b) && isNaN(b)); + var aNaN = (a == null || _.isNumber(a) && isNaN(a) || a.length === 0); + var bNaN = (b == null || _.isNumber(b) && isNaN(b)) || b.length === 0; if (aNaN && bNaN) { return 0; } @@ -87,7 +87,7 @@ morpheus.SortKey.DESCENDING_COMPARATOR = function(a, b) { return (a === b ? 0 : (a < b ? 1 : -1)); }; -morpheus.SortKey.NUMBER_ASCENDING_COMPARATOR = function(a, b) { +morpheus.SortKey.NUMBER_ASCENDING_COMPARATOR = function (a, b) { // we want NaNs to end up at the bottom var aNaN = (a == null || isNaN(a)); var bNaN = (b == null || isNaN(b)); @@ -103,7 +103,7 @@ morpheus.SortKey.NUMBER_ASCENDING_COMPARATOR = function(a, b) { return (a === b ? 0 : (a < b ? -1 : 1)); }; -morpheus.SortKey.NUMBER_DESCENDING_COMPARATOR = function(a, b) { +morpheus.SortKey.NUMBER_DESCENDING_COMPARATOR = function (a, b) { var aNaN = (a == null || isNaN(a)); var bNaN = (b == null || isNaN(b)); if (aNaN && bNaN) { @@ -118,18 +118,18 @@ morpheus.SortKey.NUMBER_DESCENDING_COMPARATOR = function(a, b) { return (a === b ? 0 : (a < b ? 1 : -1)); }; -morpheus.SortKey.STRING_ASCENDING_COMPARATOR = function(a, b) { +morpheus.SortKey.STRING_ASCENDING_COMPARATOR = function (a, b) { a = (a == null || a.toLowerCase === undefined) ? null : a.toLowerCase(); b = (b == null || b.toLowerCase === undefined) ? null : b.toLowerCase(); return (a === b ? 0 : (a < b ? -1 : 1)); }; -morpheus.SortKey.STRING_DESCENDING_COMPARATOR = function(a, b) { +morpheus.SortKey.STRING_DESCENDING_COMPARATOR = function (a, b) { a = (a == null || a.toLowerCase === undefined) ? null : a.toLowerCase(); b = (b == null || b.toLowerCase === undefined) ? null : b.toLowerCase(); return (a === b ? 0 : (a < b ? 1 : -1)); }; -morpheus.SortKey.ELEMENT_ASCENDING_COMPARATOR = function(obj1, obj2) { +morpheus.SortKey.ELEMENT_ASCENDING_COMPARATOR = function (obj1, obj2) { var a = +obj1; var b = +obj2; var aNaN = isNaN(a); @@ -148,7 +148,7 @@ morpheus.SortKey.ELEMENT_ASCENDING_COMPARATOR = function(obj1, obj2) { if (obj1.toObject && obj2.toObject) { var a1 = obj1.toObject(); var b1 = obj2.toObject(); - for ( var name in a1) { + for (var name in a1) { a = a1[name]; b = b1[name]; @@ -162,7 +162,7 @@ morpheus.SortKey.ELEMENT_ASCENDING_COMPARATOR = function(obj1, obj2) { return (a === b ? 0 : (a < b ? -1 : 1)); }; -morpheus.SortKey.ELEMENT_DESCENDING_COMPARATOR = function(obj1, obj2) { +morpheus.SortKey.ELEMENT_DESCENDING_COMPARATOR = function (obj1, obj2) { // we want NaNs to end up at the bottom var a = +obj1; var b = +obj2; @@ -181,7 +181,7 @@ morpheus.SortKey.ELEMENT_DESCENDING_COMPARATOR = function(obj1, obj2) { if (obj1.toObject && obj2.toObject) { var a1 = obj1.toObject(); var b1 = obj2.toObject(); - for ( var name in a1) { + for (var name in a1) { a = a1[name]; b = b1[name]; var c = (a === b ? 0 : (a < b ? 1 : -1)); @@ -193,20 +193,20 @@ morpheus.SortKey.ELEMENT_DESCENDING_COMPARATOR = function(obj1, obj2) { } return (a === b ? 0 : (a < b ? 1 : -1)); }; -morpheus.SortKey.BOX_PLOT_SUMMARY_FUNCTION = function(array) { +morpheus.SortKey.BOX_PLOT_SUMMARY_FUNCTION = function (array) { var box = array.box; if (box == null) { var v = morpheus.VectorUtil.arrayAsVector(array); box = morpheus - .BoxPlotItem(this.indices != null ? new morpheus.SlicedVector( - v, this.indices) : v); + .BoxPlotItem(this.indices != null ? new morpheus.SlicedVector( + v, this.indices) : v); array.box = box; } return box.q3; }; -morpheus.SortKey.ARRAY_MAX_SUMMARY_FUNCTION = function(array) { +morpheus.SortKey.ARRAY_MAX_SUMMARY_FUNCTION = function (array) { var a = 0; if (array != null) { var aPosMax = -Number.MAX_VALUE; @@ -231,8 +231,8 @@ morpheus.SortKey.ARRAY_MAX_SUMMARY_FUNCTION = function(array) { } return a; }; -morpheus.SortKey.ARRAY_ASCENDING_COMPARATOR = function(summary) { - return function(a, b) { +morpheus.SortKey.ARRAY_ASCENDING_COMPARATOR = function (summary) { + return function (a, b) { var aNaN = a == null; var bNaN = b == null; if (aNaN && bNaN) { @@ -261,8 +261,8 @@ morpheus.SortKey.ARRAY_ASCENDING_COMPARATOR = function(summary) { }; }; -morpheus.SortKey.ARRAY_DESCENDING_COMPARATOR = function(summary) { - return function(a, b) { +morpheus.SortKey.ARRAY_DESCENDING_COMPARATOR = function (summary) { + return function (a, b) { var aNaN = a == null; var bNaN = b == null; if (aNaN && bNaN) { @@ -291,54 +291,54 @@ morpheus.SortKey.ARRAY_DESCENDING_COMPARATOR = function(summary) { }; }; -morpheus.SortKey.reverseComparator = function(c) { - return function(a, b) { +morpheus.SortKey.reverseComparator = function (c) { + return function (a, b) { return c(b, a); }; }; morpheus.SortKey.prototype = { - init : function(dataset) { + init: function (dataset) { this.v = dataset.getRowMetadata().getByName(this.field); if (!this.v) { this.v = {}; - this.v.getValue = function() { + this.v.getValue = function () { return 0; }; this.c = this.sortOrder === morpheus.SortKey.SortOrder.ASCENDING ? morpheus.SortKey.ASCENDING_COMPARATOR - : morpheus.SortKey.DESCENDING_COMPARATOR; + : morpheus.SortKey.DESCENDING_COMPARATOR; } else { var dataType = morpheus.VectorUtil.getDataType(this.v); if (dataType === 'number') { this.c = this.sortOrder === morpheus.SortKey.SortOrder.ASCENDING ? morpheus.SortKey.NUMBER_ASCENDING_COMPARATOR - : morpheus.SortKey.NUMBER_DESCENDING_COMPARATOR; + : morpheus.SortKey.NUMBER_DESCENDING_COMPARATOR; } else if (dataType === '[number]') { var summary = this.v.getProperties().get( morpheus.VectorKeys.ARRAY_SUMMARY_FUNCTION) - || morpheus.SortKey.ARRAY_MAX_SUMMARY_FUNCTION; + || morpheus.SortKey.ARRAY_MAX_SUMMARY_FUNCTION; this.c = this.sortOrder === morpheus.SortKey.SortOrder.ASCENDING ? morpheus.SortKey - .ARRAY_ASCENDING_COMPARATOR(summary) - : morpheus.SortKey.ARRAY_DESCENDING_COMPARATOR(summary); + .ARRAY_ASCENDING_COMPARATOR(summary) + : morpheus.SortKey.ARRAY_DESCENDING_COMPARATOR(summary); } else { this.c = this.sortOrder === morpheus.SortKey.SortOrder.ASCENDING ? morpheus.SortKey.ASCENDING_COMPARATOR - : morpheus.SortKey.DESCENDING_COMPARATOR; + : morpheus.SortKey.DESCENDING_COMPARATOR; } } }, - getComparator : function() { + getComparator: function () { return this.c; }, - getValue : function(i) { + getValue: function (i) { return this.v.getValue(i); }, - setSortOrder : function(sortOrder) { + setSortOrder: function (sortOrder) { this.sortOrder = sortOrder; }, - getSortOrder : function() { + getSortOrder: function () { return this.sortOrder; }, - toString : function() { + toString: function () { return this.field; } }; @@ -348,7 +348,7 @@ morpheus.SortKey.prototype = { * @param isColumnSort - * sort columns by selected rows. */ -morpheus.SortByValuesKey = function(modelIndices, sortOrder, isColumnSort) { +morpheus.SortByValuesKey = function (modelIndices, sortOrder, isColumnSort) { this.field = 'selection'; this.bothCount = 10; this.modelIndices = modelIndices; @@ -358,16 +358,16 @@ morpheus.SortByValuesKey = function(modelIndices, sortOrder, isColumnSort) { }; morpheus.SortByValuesKey.prototype = { - init : function(dataset, visibleModelIndices) { + init: function (dataset, visibleModelIndices) { // isColumnSort-sort columns by selected rows // dataset is transposed if !isColumnSort this.dataset = morpheus.DatasetUtil.slicedView(dataset, null, - this.modelIndices); + this.modelIndices); this.rowView = new morpheus.DatasetRowView(this.dataset); this.summaryFunction = this.modelIndices.length > 1 ? morpheus.Median - : function(row) { - return row.getValue(0); - }; + : function (row) { + return row.getValue(0); + }; if (this.sortOrder === morpheus.SortKey.SortOrder.TOP_N) { var pairs = []; @@ -377,8 +377,8 @@ morpheus.SortByValuesKey.prototype = { var value = this.summaryFunction(this.rowView.setIndex(index)); if (!isNaN(value)) { pairs.push({ - index : index, - value : value + index: index, + value: value }); } else { missingIndices.push(index); @@ -386,10 +386,10 @@ morpheus.SortByValuesKey.prototype = { } // sort values in descending order pairs - .sort(function(a, b) { - return (a.value < b.value ? 1 - : (a.value === b.value ? 0 : -1)); - }); + .sort(function (a, b) { + return (a.value < b.value ? 1 + : (a.value === b.value ? 0 : -1)); + }); var modelIndexToValue = []; var nInGroup = Math.min(pairs.length, this.bothCount); @@ -408,8 +408,8 @@ morpheus.SortByValuesKey.prototype = { } var indexCounterPairs = []; for (var i = 0; i < nInGroup && bottomIndex >= 0; i++, bottomIndex--, counter++) { - indexCounterPairs.push([ bottomPairs[bottomIndex].index, - counter ]); + indexCounterPairs.push([bottomPairs[bottomIndex].index, + counter]); } for (var i = indexCounterPairs.length - 1, j = 0; i >= 0; i--, j++) { var item_i = indexCounterPairs[i]; @@ -429,14 +429,14 @@ morpheus.SortByValuesKey.prototype = { delete this.modelIndexToValue; } }, - getComparator : function() { + getComparator: function () { return this.c; }, - getValue : function(i) { + getValue: function (i) { return this.modelIndexToValue ? this.modelIndexToValue[i] : this - .summaryFunction(this.rowView.setIndex(i)); + .summaryFunction(this.rowView.setIndex(i)); }, - setSortOrder : function(sortOrder) { + setSortOrder: function (sortOrder) { if (typeof sortOrder === 'string') { sortOrder = morpheus.SortKey.SortOrder[sortOrder.toUpperCase()]; } @@ -450,10 +450,10 @@ morpheus.SortByValuesKey.prototype = { } }, - getSortOrder : function() { + getSortOrder: function () { return this.sortOrder; }, - toString : function() { + toString: function () { return 'values'; } }; @@ -467,7 +467,7 @@ morpheus.SortByValuesKey.prototype = { * @param name * This sort key name */ -morpheus.SpecifiedModelSortOrder = function(modelIndices, nvisible, name) { +morpheus.SpecifiedModelSortOrder = function (modelIndices, nvisible, name) { this.nvisible = nvisible; var modelIndexToValue = []; for (var i = 0, length = modelIndices.length; i < length; i++) { @@ -478,27 +478,27 @@ morpheus.SpecifiedModelSortOrder = function(modelIndices, nvisible, name) { this.c = morpheus.SortKey.ASCENDING_COMPARATOR; }; morpheus.SpecifiedModelSortOrder.prototype = { - init : function(dataset) { + init: function (dataset) { }, - getComparator : function(a, b) { + getComparator: function (a, b) { return this.c; }, - getValue : function(i) { + getValue: function (i) { return this.modelIndexToValue[i]; }, - setSortOrder : function(sortOrder) { + setSortOrder: function (sortOrder) { this.sortOrder = sortOrder; this.c = this.sortOrder === morpheus.SortKey.SortOrder.ASCENDING ? morpheus.SortKey.NUMBER_ASCENDING_COMPARATOR - : morpheus.SortKey.NUMBER_DESCENDING_COMPARATOR; + : morpheus.SortKey.NUMBER_DESCENDING_COMPARATOR; }, - getSortOrder : function() { + getSortOrder: function () { return this.sortOrder; }, - getName : function() { + getName: function () { return this.name; } }; -morpheus.SortKey.keepExistingSortKeys = function(newSortKeys, existingSortKeys) { +morpheus.SortKey.keepExistingSortKeys = function (newSortKeys, existingSortKeys) { // keep MatchesOnTopSortKey and dendrogram // var existingOnTopSortKey = null; var existingSpecifiedSortKey = null; @@ -508,7 +508,7 @@ morpheus.SortKey.keepExistingSortKeys = function(newSortKeys, existingSortKeys) // existingOnTopSortKey = key; // } if (key instanceof morpheus.SpecifiedModelSortOrder - && key.name === 'dendrogram') { + && key.name === 'dendrogram') { existingSpecifiedSortKey = key; } } @@ -521,7 +521,7 @@ morpheus.SortKey.keepExistingSortKeys = function(newSortKeys, existingSortKeys) // newSortKeysHasTopSortKey = true; // } if (key instanceof morpheus.SpecifiedModelSortOrder - && key.name === 'dendrogram') { + && key.name === 'dendrogram') { newSortKeysHasSpecifiedSortKey = true; } } @@ -536,31 +536,31 @@ morpheus.SortKey.keepExistingSortKeys = function(newSortKeys, existingSortKeys) }; /** * Group by key - * + * * @param values */ -morpheus.SpecifiedGroupByKey = function(clusterIds) { +morpheus.SpecifiedGroupByKey = function (clusterIds) { this.clusterIds = clusterIds; - this.c = function(a, b) { + this.c = function (a, b) { return (a === b ? 0 : // Values are equal - (a < b ? -1 : // (-0.0, 0.0) or (!NaN, NaN) - 1)); + (a < b ? -1 : // (-0.0, 0.0) or (!NaN, NaN) + 1)); }; }; morpheus.SpecifiedGroupByKey.prototype = { - init : function(dataset) { + init: function (dataset) { }, - getComparator : function(a, b) { + getComparator: function (a, b) { return this.c; }, - getValue : function(i) { + getValue: function (i) { return this.clusterIds[i]; }, - setSortOrder : function(sortOrder) { + setSortOrder: function (sortOrder) { }, - getSortOrder : function() { + getSortOrder: function () { }, - getName : function() { + getName: function () { return 'Dendrogram Cut'; } -}; \ No newline at end of file +};