diff --git a/empress/support_files/js/empress.js b/empress/support_files/js/empress.js
index fc803003..4d249a91 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,36 @@ define([
this.redrawBarPlotsToMatchLayout();
};
+ /**
+ * 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 Name of a 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 a node has feature metadata.
+ *
+ * @param {Number} node Postorder position of a node in the tree.
+ *
+ * @return true if node has feature metadata, false otherwise.
+ */
+ Empress.prototype.hasFeatureMetadata = function (node) {
+ return _.has(this._tipMetadata, node) || _.has(this._intMetadata, node);
+ };
+
return Empress;
});
diff --git a/empress/support_files/js/select-node-menu.js b/empress/support_files/js/select-node-menu.js
index c9487bce..fc55826a 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 bcfbbc80..c36c9052 100644
--- a/tests/test-barplots.js
+++ b/tests/test-barplots.js
@@ -216,8 +216,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