From 9f54080010a154646585d227da46ba67f31ea5e6 Mon Sep 17 00:00:00 2001 From: kcantrel Date: Thu, 12 Aug 2021 05:05:55 -0700 Subject: [PATCH 1/3] sorted all menus --- empress/support_files/js/empress.js | 42 ++++++++++++++++++-- empress/support_files/js/select-node-menu.js | 20 ++++------ tests/test-barplots.js | 8 ++-- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/empress/support_files/js/empress.js b/empress/support_files/js/empress.js index fc8030035..763a9c89f 100644 --- a/empress/support_files/js/empress.js +++ b/empress/support_files/js/empress.js @@ -2712,7 +2712,7 @@ define([ }; /** - * Returns a list of sample categories. + * Returns a sorted list of sample categories. * * If this.isCommunityPlot is false (no table / sample metadata were * provided), this just returns []. @@ -2721,7 +2721,7 @@ define([ */ Empress.prototype.getSampleCategories = function () { if (this.isCommunityPlot) { - return this._biom.getSampleCategories(); + return util.naturalSort(this._biom.getSampleCategories()); } else { return []; } @@ -2849,12 +2849,12 @@ define([ }; /** - * Returns an array of feature metadata column names. + * Returns a sorted list of feature metadata column names. * * @return {Array} */ Empress.prototype.getFeatureMetadataCategories = function () { - return this._featureMetadataColumns; + return util.naturalSort(this._featureMetadataColumns); }; /** @@ -3792,5 +3792,39 @@ define([ this.redrawBarPlotsToMatchLayout(); }; + /** + * Returns the col variable value for the node. + * + * @param {Number} node Postorder position of a node in the tree. + * @param {String} col The name of the feature metadata column. + * + * @return {String} The col variable value for the node or undefined if + * no value exists. + */ + Empress.prototype.getNodeFeatureMetadataValue = function (node, col) { + var colIndx = _.indexOf(this._featureMetadataColumns, col); + if (_.has(this._tipMetadata, node)) { + return this._tipMetadata[node][colIndx]; + } + if (_.has(this._intMetadata, node)) { + return this._intMetadata[node][colIndx]; + } + return undefined; + }; + + /** + * Checks to see if node has feature metadata. + * + * @param {Number} node Postorder position of a node in the tree. + * + * @return true if node has feature metadata else false. + */ + Empress.prototype.hasFeatureMetadata = function (node) { + if (_.has(this._tipMetadata, node) || _.has(this._intMetadata, node)) { + return true; + } + return false; + }; + return Empress; }); diff --git a/empress/support_files/js/select-node-menu.js b/empress/support_files/js/select-node-menu.js index c9487bceb..fc55826a7 100644 --- a/empress/support_files/js/select-node-menu.js +++ b/empress/support_files/js/select-node-menu.js @@ -288,23 +288,17 @@ define(["underscore", "util"], function (_, util) { ) { if (this.hasFeatureMetadata) { this.fmTable.innerHTML = ""; - var mdObj; - if (tipOrInt === "tip") { - mdObj = this.empress._tipMetadata; - } else if (tipOrInt === "int") { - mdObj = this.empress._intMetadata; - } else { - throw new Error("Invalid tipOrInt value: " + tipOrInt); - } - if (_.has(mdObj, nodeName)) { + if (this.empress.hasFeatureMetadata(nodeName)) { var headerRow = this.fmTable.insertRow(-1); var featureRow = this.fmTable.insertRow(-1); - for (var x = 0; x < this.fmCols.length; x++) { - var colName = this.fmCols[x]; + for (var col of this.fmCols) { var colCell = headerRow.insertCell(-1); - colCell.innerHTML = "" + colName + ""; + colCell.innerHTML = "" + col + ""; var dataCell = featureRow.insertCell(-1); - dataCell.innerHTML = mdObj[nodeName][x]; + dataCell.innerHTML = this.empress.getNodeFeatureMetadataValue( + nodeName, + col + ); } show(this.fmTable); hide(this.fmNoDataNote); diff --git a/tests/test-barplots.js b/tests/test-barplots.js index bcfbbc803..4d40b491a 100644 --- a/tests/test-barplots.js +++ b/tests/test-barplots.js @@ -6,6 +6,7 @@ require([ "BarplotLayer", "UtilitiesForTesting", "Colorer", + "util", ], function ( $, _, @@ -13,7 +14,8 @@ require([ Empress, BarplotLayer, UtilitiesForTesting, - Colorer + Colorer, + util ) { module("Barplots", { setup: function () { @@ -216,8 +218,8 @@ require([ _.each(empress._barplotPanel.layers, function (layer, i) { // Basic information about the visualization -- should be the same // across every layer - equal(layer.fmCols, scope.testData.fmCols); - equal(layer.smCols, empress._barplotPanel.smCols); + deepEqual(layer.fmCols, scope.testData.fmCols); + deepEqual(layer.smCols, empress._barplotPanel.smCols); equal(layer.barplotPanel, empress._barplotPanel); equal(layer.layerContainer, empress._barplotPanel.layerContainer); // Check that the "num" and "unique num" of each barplot layer were From 4a769a745a2c54f1bd9dd4154e81cd926944cde0 Mon Sep 17 00:00:00 2001 From: kcantrel Date: Thu, 26 Aug 2021 12:04:41 -0700 Subject: [PATCH 2/3] address @fedarko's comments --- empress/support_files/js/empress.js | 5 +---- tests/test-barplots.js | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/empress/support_files/js/empress.js b/empress/support_files/js/empress.js index 763a9c89f..cba5795aa 100644 --- a/empress/support_files/js/empress.js +++ b/empress/support_files/js/empress.js @@ -3820,10 +3820,7 @@ define([ * @return true if node has feature metadata else false. */ Empress.prototype.hasFeatureMetadata = function (node) { - if (_.has(this._tipMetadata, node) || _.has(this._intMetadata, node)) { - return true; - } - return false; + return _.has(this._tipMetadata, node) || _.has(this._intMetadata, node); }; return Empress; diff --git a/tests/test-barplots.js b/tests/test-barplots.js index 4d40b491a..c36c90522 100644 --- a/tests/test-barplots.js +++ b/tests/test-barplots.js @@ -6,7 +6,6 @@ require([ "BarplotLayer", "UtilitiesForTesting", "Colorer", - "util", ], function ( $, _, @@ -14,8 +13,7 @@ require([ Empress, BarplotLayer, UtilitiesForTesting, - Colorer, - util + Colorer ) { module("Barplots", { setup: function () { From e3a15b5fa2f7b44106434d18cb61877f51aef0eb Mon Sep 17 00:00:00 2001 From: kwcantrell Date: Thu, 26 Aug 2021 12:05:10 -0700 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Marcus Fedarko --- empress/support_files/js/empress.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/empress/support_files/js/empress.js b/empress/support_files/js/empress.js index cba5795aa..4d249a91c 100644 --- a/empress/support_files/js/empress.js +++ b/empress/support_files/js/empress.js @@ -3793,10 +3793,10 @@ define([ }; /** - * Returns the col variable value for the node. + * Returns the feature metadata value at a f. m. column for a node. * * @param {Number} node Postorder position of a node in the tree. - * @param {String} col The name of the feature metadata column. + * @param {String} col Name of a feature metadata column. * * @return {String} The col variable value for the node or undefined if * no value exists. @@ -3813,11 +3813,11 @@ define([ }; /** - * Checks to see if node has feature metadata. + * Checks to see if a node has feature metadata. * * @param {Number} node Postorder position of a node in the tree. * - * @return true if node has feature metadata else false. + * @return true if node has feature metadata, false otherwise. */ Empress.prototype.hasFeatureMetadata = function (node) { return _.has(this._tipMetadata, node) || _.has(this._intMetadata, node);