-
-
-
-
-
-
-
-
+
Date: Fri, 28 May 2021 23:12:56 -0700
Subject: [PATCH 02/17] remove commented code
---
empress/support_files/js/side-panel-handler.js | 3 ---
1 file changed, 3 deletions(-)
diff --git a/empress/support_files/js/side-panel-handler.js b/empress/support_files/js/side-panel-handler.js
index ef5828adc..fa3f078b1 100644
--- a/empress/support_files/js/side-panel-handler.js
+++ b/empress/support_files/js/side-panel-handler.js
@@ -56,9 +56,6 @@ define(["underscore", "Colorer", "ColorOptionsHandler", "util"], function (_, Co
document.getElementById('sample-color-options-div')
);
this.sColorOptions.registerObserver(this);
- // this.sReverseColor = document.getElementById(
- // "sample-reverse-color-chk"
- // );
this.sCollapseCladesChk = document.getElementById(
"sample-collapse-chk"
);
From eedede251ace684bfdf66282fa65dbf8e3f2f61c Mon Sep 17 00:00:00 2001
From: kcantrel
Date: Fri, 28 May 2021 23:21:03 -0700
Subject: [PATCH 03/17] Fix ColorOptionsHandler typo
---
empress/support_files/js/barplot-layer.js | 10 +-
.../support_files/js/color-options-handler.js | 405 +++++++++---------
empress/support_files/js/colorer.js | 10 +-
empress/support_files/js/empress.js | 6 +-
.../support_files/js/side-panel-handler.js | 19 +-
5 files changed, 218 insertions(+), 232 deletions(-)
diff --git a/empress/support_files/js/barplot-layer.js b/empress/support_files/js/barplot-layer.js
index be82451e2..75dca4f55 100644
--- a/empress/support_files/js/barplot-layer.js
+++ b/empress/support_files/js/barplot-layer.js
@@ -301,7 +301,7 @@ define([
var fColorOptions = new ColorOptionsHandler(
colorDetailsDiv,
- enableContinuousColoring=true
+ (enableContinuousColoring = true)
);
// Initialize defaults to match the UI defaults (e.g. the default
@@ -342,7 +342,7 @@ define([
// register color options
fColorOptions.registerObserver({
- colorOptionsUpdate: function(options) {
+ colorOptionsUpdate: function (options) {
scope.colorByFMColorMap = options.color;
scope.colorByFMColorReverse = options.reverse;
scope.colorByFMColorMapDiscrete = !options.continuousColoring;
@@ -350,8 +350,8 @@ define([
scope.colorByFMContinuousScale = options.continuousScale;
scope.colorByFMContinuousMin = options.min;
scope.colorByFMContinuousMax = options.max;
- }
- })
+ },
+ });
// create default length settings
var dfltLenP = document.createElement("p");
@@ -533,7 +533,7 @@ define([
options = sColorOptions.getOptions();
scope.colorBySMColorMap = options.color;
scope.colorBySMColorReverse = options.reverse;
- }
+ },
});
$(lenInput).change(function () {
diff --git a/empress/support_files/js/color-options-handler.js b/empress/support_files/js/color-options-handler.js
index b2dbdc27f..d8e3a4cea 100644
--- a/empress/support_files/js/color-options-handler.js
+++ b/empress/support_files/js/color-options-handler.js
@@ -1,21 +1,18 @@
-define(["underscore", "Colorer", "util"], function(_, Colorer, util) {
-
- var TotalColorOptionsHanlders = 0;
-
- function ColorOptionsHanlder(container, enableContinuousColoring=false) {
- this.container = container;
- this.observers = [];
- this.defaultColor = "discrete-coloring-qiime";
- this.defaultReverseChk = false;
- // create unique num
- TotalColorOptionsHanlders += 1;
- this.uniqueNum = TotalColorOptionsHanlders;
- this.enableContinuousColoring = enableContinuousColoring
-
- // Add a row for choosing the color map
- var colormapP = this.container.appendChild(
- document.createElement("p")
- );
+define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
+ var TotalColorOptionsHanlders = 0;
+
+ function ColorOptionsHandler(container, enableContinuousColoring = false) {
+ this.container = container;
+ this.observers = [];
+ this.defaultColor = "discrete-coloring-qiime";
+ this.defaultReverseChk = false;
+ // create unique num
+ TotalColorOptionsHanlders += 1;
+ this.uniqueNum = TotalColorOptionsHanlders;
+ this.enableContinuousColoring = enableContinuousColoring;
+
+ // Add a row for choosing the color map
+ var colormapP = this.container.appendChild(document.createElement("p"));
var colormapLbl = colormapP.appendChild(
document.createElement("label")
);
@@ -26,9 +23,7 @@ define(["underscore", "Colorer", "util"], function(_, Colorer, util) {
Colorer.addColorsToSelect(this.colormapSelector);
colormapSC.appendChild(this.colormapSelector);
this.colormapSelector.id =
- "color-options-hanlder-" +
- this.uniqueNum +
- "-colormap-select";
+ "color-options-hanlder-" + this.uniqueNum + "-colormap-select";
colormapLbl.setAttribute("for", this.colormapSelector.id);
// Add a row for choosing whether the color scale should
@@ -44,227 +39,213 @@ define(["underscore", "Colorer", "util"], function(_, Colorer, util) {
document.createElement("input")
);
this.reverseColormapCheckbox.id =
- "color-options-hanlder-" +
- this.uniqueNum +
- "-reverse-chk";
+ "color-options-hanlder-" + this.uniqueNum + "-reverse-chk";
this.reverseColormapCheckbox.setAttribute("type", "checkbox");
this.reverseColormapCheckbox.classList.add("empress-input");
reverseColormapLbl.setAttribute("for", this.reverseColormapCheckbox.id);
-
+
var scope = this;
- var notify = function() {
- var options = scope.getOptions();
- _.each(scope.observers, function(obs) {
- obs.colorOptionsUpdate(options);
- });
+ var notify = function () {
+ var options = scope.getOptions();
+ _.each(scope.observers, function (obs) {
+ obs.colorOptionsUpdate(options);
+ });
};
if (this.enableContinuousColoring) {
- // add continuous values checkbox
- var continuousValP = this.container.appendChild(
- document.createElement("p")
- );
- var continuousValLbl = continuousValP.appendChild(
- document.createElement("label")
- );
- continuousValLbl.innerText = "Continuous values?";
- this.continuousValCheckbox = continuousValP.appendChild(
- document.createElement("input")
- );
- this.continuousValCheckbox.id =
- "color-options-hanlder-" +
- this.uniqueNum +
- "-continuous-chk";
- this.continuousValCheckbox.setAttribute("type", "checkbox");
- this.continuousValCheckbox.classList.add("empress-input");
- continuousValLbl.setAttribute("for", this.continuousValCheckbox.id);
- // Hide the "Continuous values?" stuff by default, since the default
- // colormap is discrete
- continuousValP.classList.add("hidden");
-
- // add continuous values min/middle/max inputs
- var continuousScaleDiv = this.container.appendChild(
- document.createElement("div")
- );
- continuousScaleDiv.classList.add("hidden");
- var continuousScaleP = continuousScaleDiv.appendChild(
- document.createElement("p")
- );
- var continuousScaleLbl = continuousScaleP.appendChild(
- document.createElement("label")
- );
- continuousScaleLbl.innerText = "Manually set boundaries";
- this.continuousScaleCheckbox = continuousScaleP.appendChild(
- document.createElement("input")
- );
- this.continuousScaleCheckbox.id =
- "color-options-hanlder-" +
- this.uniqueNum +
- "-continuous-scale-chk";
- this.continuousScaleCheckbox.setAttribute("type", "checkbox");
- this.continuousScaleCheckbox.classList.add("empress-input");
- continuousScaleLbl.setAttribute(
- "for",
- this.continuousScaleCheckbox.id
- );
- var continuousMinMaxDiv = continuousScaleDiv.appendChild(
- document.createElement("div")
- );
- continuousMinMaxDiv.classList.add("hidden");
-
- // add min scale input
- var continuousMinP = continuousMinMaxDiv.appendChild(
- document.createElement("p")
- );
- var continuousMinLbl = continuousMinP.appendChild(
- document.createElement("label")
- );
- continuousMinLbl.innerText = "Min";
- this.continuousMinInput = continuousMinP.appendChild(
- document.createElement("input")
- );
- this.continuousMinInput.setAttribute("type", "number");
- this.continuousMinInput.classList.add("empress-input");
- this.continuousMinInput.value = null;
- this.continuousMinInput.id =
- "color-options-hanlder-" +
- this.uniqueNum +
- "-continuous-min-input";
- continuousMinLbl.setAttribute("for", this.continuousMinInput.id);
-
- // add max scale input
- var continuousMaxP = continuousMinMaxDiv.appendChild(
- document.createElement("p")
- );
- var continuousMaxLbl = continuousMaxP.appendChild(
- document.createElement("label")
- );
- continuousMaxLbl.innerText = "Max";
- this.continuousMaxInput = continuousMaxP.appendChild(
- document.createElement("input")
- );
- this.continuousMaxInput.setAttribute("type", "number");
- this.continuousMaxInput.classList.add("empress-input");
- this.continuousMaxInput.value = null;
- this.continuousMaxInput.id =
- "color-options-hanlder-" +
- this.uniqueNum +
- "-continuous-max-input";
- continuousMaxLbl.setAttribute("for", this.continuousMaxInput.id);
-
- var validateNumInput = function(input) {
- util.parseAndValidateNum(
- input,
- null
- );
- };
-
- // add events
- this.continuousValCheckbox.onchange = () => {
- if(scope.continuousValCheckbox.checked) {
- continuousScaleDiv.classList.remove("hidden");
- } else {
- continuousScaleDiv.classList.add("hidden");
- }
- notify();
- };
- this.continuousScaleCheckbox.onchange = () => {
- if(scope.continuousScaleCheckbox.checked) {
- scope.continuousMinInput.value = null;
- scope.continuousMaxInput.value = null;
- continuousMinMaxDiv.classList.remove("hidden");
- } else {
- continuousMinMaxDiv.classList.add("hidden");
- }
- notify();
- }
- this.continuousMinInput.onchange = () => {
- validateNumInput(scope.continuousMinInput, null);
- notify();
- };
- this.continuousMinInput.addEventListener(
- "focusout",
- () => {
- validateNumInput(scope.continuousMinInput, null);
- notify();
- }
- );
- this.continuousMaxInput.onchange = () => {
- validateNumInput(scope.continuousMaxInput, null);
- notify();
- };
- this.continuousMaxInput.addEventListener(
- "focusout",
- () => {
- validateNumInput(scope.continuousMaxInput, null);
- notify();
- }
- );
+ // add continuous values checkbox
+ var continuousValP = this.container.appendChild(
+ document.createElement("p")
+ );
+ var continuousValLbl = continuousValP.appendChild(
+ document.createElement("label")
+ );
+ continuousValLbl.innerText = "Continuous values?";
+ this.continuousValCheckbox = continuousValP.appendChild(
+ document.createElement("input")
+ );
+ this.continuousValCheckbox.id =
+ "color-options-hanlder-" + this.uniqueNum + "-continuous-chk";
+ this.continuousValCheckbox.setAttribute("type", "checkbox");
+ this.continuousValCheckbox.classList.add("empress-input");
+ continuousValLbl.setAttribute("for", this.continuousValCheckbox.id);
+ // Hide the "Continuous values?" stuff by default, since the default
+ // colormap is discrete
+ continuousValP.classList.add("hidden");
+
+ // add continuous values min/middle/max inputs
+ var continuousScaleDiv = this.container.appendChild(
+ document.createElement("div")
+ );
+ continuousScaleDiv.classList.add("hidden");
+ var continuousScaleP = continuousScaleDiv.appendChild(
+ document.createElement("p")
+ );
+ var continuousScaleLbl = continuousScaleP.appendChild(
+ document.createElement("label")
+ );
+ continuousScaleLbl.innerText = "Manually set boundaries";
+ this.continuousScaleCheckbox = continuousScaleP.appendChild(
+ document.createElement("input")
+ );
+ this.continuousScaleCheckbox.id =
+ "color-options-hanlder-" +
+ this.uniqueNum +
+ "-continuous-scale-chk";
+ this.continuousScaleCheckbox.setAttribute("type", "checkbox");
+ this.continuousScaleCheckbox.classList.add("empress-input");
+ continuousScaleLbl.setAttribute(
+ "for",
+ this.continuousScaleCheckbox.id
+ );
+ var continuousMinMaxDiv = continuousScaleDiv.appendChild(
+ document.createElement("div")
+ );
+ continuousMinMaxDiv.classList.add("hidden");
+
+ // add min scale input
+ var continuousMinP = continuousMinMaxDiv.appendChild(
+ document.createElement("p")
+ );
+ var continuousMinLbl = continuousMinP.appendChild(
+ document.createElement("label")
+ );
+ continuousMinLbl.innerText = "Min";
+ this.continuousMinInput = continuousMinP.appendChild(
+ document.createElement("input")
+ );
+ this.continuousMinInput.setAttribute("type", "number");
+ this.continuousMinInput.classList.add("empress-input");
+ this.continuousMinInput.value = null;
+ this.continuousMinInput.id =
+ "color-options-hanlder-" +
+ this.uniqueNum +
+ "-continuous-min-input";
+ continuousMinLbl.setAttribute("for", this.continuousMinInput.id);
+
+ // add max scale input
+ var continuousMaxP = continuousMinMaxDiv.appendChild(
+ document.createElement("p")
+ );
+ var continuousMaxLbl = continuousMaxP.appendChild(
+ document.createElement("label")
+ );
+ continuousMaxLbl.innerText = "Max";
+ this.continuousMaxInput = continuousMaxP.appendChild(
+ document.createElement("input")
+ );
+ this.continuousMaxInput.setAttribute("type", "number");
+ this.continuousMaxInput.classList.add("empress-input");
+ this.continuousMaxInput.value = null;
+ this.continuousMaxInput.id =
+ "color-options-hanlder-" +
+ this.uniqueNum +
+ "-continuous-max-input";
+ continuousMaxLbl.setAttribute("for", this.continuousMaxInput.id);
+
+ var validateNumInput = function (input) {
+ util.parseAndValidateNum(input, null);
+ };
+
+ // add events
+ this.continuousValCheckbox.onchange = () => {
+ if (scope.continuousValCheckbox.checked) {
+ continuousScaleDiv.classList.remove("hidden");
+ } else {
+ continuousScaleDiv.classList.add("hidden");
+ }
+ notify();
+ };
+ this.continuousScaleCheckbox.onchange = () => {
+ if (scope.continuousScaleCheckbox.checked) {
+ scope.continuousMinInput.value = null;
+ scope.continuousMaxInput.value = null;
+ continuousMinMaxDiv.classList.remove("hidden");
+ } else {
+ continuousMinMaxDiv.classList.add("hidden");
+ }
+ notify();
+ };
+ this.continuousMinInput.onchange = () => {
+ validateNumInput(scope.continuousMinInput, null);
+ notify();
+ };
+ this.continuousMinInput.addEventListener("focusout", () => {
+ validateNumInput(scope.continuousMinInput, null);
+ notify();
+ });
+ this.continuousMaxInput.onchange = () => {
+ validateNumInput(scope.continuousMaxInput, null);
+ notify();
+ };
+ this.continuousMaxInput.addEventListener("focusout", () => {
+ validateNumInput(scope.continuousMaxInput, null);
+ notify();
+ });
}
-
this.colormapSelector.onchange = () => {
- if (scope.enableContinuousColoring) {
- if (Colorer.isColorMapDiscrete(scope.colormapSelector.value)) {
- continuousValP.classList.add("hidden");
- } else {
- continuousValP.classList.remove("hidden");
- }
- }
- notify();
+ if (scope.enableContinuousColoring) {
+ if (Colorer.isColorMapDiscrete(scope.colormapSelector.value)) {
+ continuousValP.classList.add("hidden");
+ } else {
+ continuousValP.classList.remove("hidden");
+ }
+ }
+ notify();
};
this.reverseColormapCheckbox.onchange = notify;
- }
+ }
- ColorOptionsHanlder.prototype.registerObserver = function(obs) {
- this.observers.push(obs);
- };
+ ColorOptionsHandler.prototype.registerObserver = function (obs) {
+ this.observers.push(obs);
+ };
- ColorOptionsHanlder.prototype.getOptions = function() {
- var options = {
- "color": this.colormapSelector.value,
- "reverse": this.reverseColormapCheckbox.checked,
- };
- if(this.enableContinuousColoring) {
- options.continuousColoring = this.continuousValCheckbox.checked;
- options.continuousScale = this.continuousScaleCheckbox.checked;
- options.min = this.verifyMinBoundary();
- options.max = this.verifyMaxBoundary();
- }
- return options;
- };
+ ColorOptionsHandler.prototype.getOptions = function () {
+ var options = {
+ color: this.colormapSelector.value,
+ reverse: this.reverseColormapCheckbox.checked,
+ };
+ if (this.enableContinuousColoring) {
+ options.continuousColoring = this.continuousValCheckbox.checked;
+ options.continuousScale = this.continuousScaleCheckbox.checked;
+ options.min = this.verifyMinBoundary();
+ options.max = this.verifyMaxBoundary();
+ }
+ return options;
+ };
- ColorOptionsHanlder.prototype.reset = function() {
- this.colormapSelector.value = this.defaultColor;
+ ColorOptionsHandler.prototype.reset = function () {
+ this.colormapSelector.value = this.defaultColor;
this.reverseColormapCheckbox.checked = this.defaultReverseChk;
- };
+ };
+
+ ColorOptionsHandler.prototype.verifyMinBoundary = function () {
+ var min = parseFloat(this.continuousMinInput.value);
- ColorOptionsHanlder.prototype.verifyMinBoundary = function( ) {
- var min = parseFloat(this.continuousMinInput.value);
-
if (isNaN(min)) {
- return "Min boundary field is missing."
+ return "Min boundary field is missing.";
}
return min;
- };
+ };
+
+ ColorOptionsHandler.prototype.verifyMaxBoundary = function () {
+ var min = parseFloat(this.continuousMinInput.value);
+ var max = parseFloat(this.continuousMaxInput.value);
- ColorOptionsHanlder.prototype.verifyMaxBoundary = function( ) {
- var min = parseFloat(this.continuousMinInput.value);
- var max = parseFloat(this.continuousMaxInput.value);
-
if (isNaN(max)) {
- return "Max boundary field is missing."
+ return "Max boundary field is missing.";
}
// It should be noted that if min isNaN that this will always return
// false
if (max <= min) {
- return "Max boundary must be greater than Min boundary."
+ return "Max boundary must be greater than Min boundary.";
}
return max;
};
- return ColorOptionsHanlder;
-});
\ No newline at end of file
+ return ColorOptionsHandler;
+});
diff --git a/empress/support_files/js/colorer.js b/empress/support_files/js/colorer.js
index 0566f7992..3894bf030 100644
--- a/empress/support_files/js/colorer.js
+++ b/empress/support_files/js/colorer.js
@@ -31,11 +31,11 @@ define(["chroma", "underscore", "util"], function (chroma, _, util) {
* @param{Boolean} reverse Defaults to false. If true, the color scale
* will be reversed, with respect to its default
* orientation.
- * @param{Object} domain [min, max] or null, default null.
+ * @param{Object} domain [min, max] or null, default null.
* [min, max] set the min and max of the color
* gradient.
* null will use default min/max for color gradient.
- *
+ *
* @return{Colorer}
* constructs Colorer
*/
@@ -45,7 +45,7 @@ define(["chroma", "underscore", "util"], function (chroma, _, util) {
useQuantScale = false,
gradientIDSuffix = 0,
reverse = false,
- domain=null,
+ domain = null
) {
var scope = this;
@@ -222,7 +222,7 @@ define(["chroma", "underscore", "util"], function (chroma, _, util) {
Colorer.prototype.getContinuousColorRange = function (nums) {
var min, mid, max;
- if (this.domain!==null) {
+ if (this.domain !== null) {
min = this.domain[0];
max = this.domain[1];
} else {
@@ -232,7 +232,7 @@ define(["chroma", "underscore", "util"], function (chroma, _, util) {
return {
min: min,
max: max,
- }
+ };
};
/**
diff --git a/empress/support_files/js/empress.js b/empress/support_files/js/empress.js
index 544a082c9..218364918 100644
--- a/empress/support_files/js/empress.js
+++ b/empress/support_files/js/empress.js
@@ -1904,7 +1904,7 @@ define([
if (layer.colorByFMContinuousScale) {
var min = layer.colorByFMContinuousMin;
var max = layer.colorByFMContinuousMax;
-
+
if (isNaN(min)) {
msg += min;
util.toastMsg(msg, 5000);
@@ -1915,7 +1915,7 @@ define([
msg += max;
util.toastMsg(msg, 5000);
throw msg;
- }
+ }
domain = [min, max];
}
try {
@@ -1925,7 +1925,7 @@ define([
layer.colorByFMContinuous,
layer.uniqueNum,
layer.colorByFMColorReverse,
- domain,
+ domain
);
} catch (err) {
// If the Colorer construction failed (should only have
diff --git a/empress/support_files/js/side-panel-handler.js b/empress/support_files/js/side-panel-handler.js
index fa3f078b1..cd4b6d5b2 100644
--- a/empress/support_files/js/side-panel-handler.js
+++ b/empress/support_files/js/side-panel-handler.js
@@ -1,4 +1,9 @@
-define(["underscore", "Colorer", "ColorOptionsHandler", "util"], function (_, Colorer, ColorOptionsHandler, util) {
+define(["underscore", "Colorer", "ColorOptionsHandler", "util"], function (
+ _,
+ Colorer,
+ ColorOptionsHandler,
+ util
+) {
/**
*
* @class SidePanel
@@ -53,7 +58,7 @@ define(["underscore", "Colorer", "ColorOptionsHandler", "util"], function (_, Co
this.sSel = document.getElementById("sample-options");
this.sAddOpts = document.getElementById("sample-add");
this.sColorOptions = new ColorOptionsHandler(
- document.getElementById('sample-color-options-div')
+ document.getElementById("sample-color-options-div")
);
this.sColorOptions.registerObserver(this);
this.sCollapseCladesChk = document.getElementById(
@@ -67,7 +72,7 @@ define(["underscore", "Colorer", "ColorOptionsHandler", "util"], function (_, Co
this.fSel = document.getElementById("feature-options");
this.fAddOpts = document.getElementById("feature-add");
this.fColorOptions = new ColorOptionsHandler(
- document.getElementById('feature-color-options-div')
+ document.getElementById("feature-color-options-div")
);
this.fColorOptions.registerObserver(this);
this.fCollapseCladesChk = document.getElementById(
@@ -187,11 +192,11 @@ define(["underscore", "Colorer", "ColorOptionsHandler", "util"], function (_, Co
};
}
- SidePanel.prototype.colorOptionsUpdate = function(options) {
+ SidePanel.prototype.colorOptionsUpdate = function (options) {
this.showUpdateBtn();
};
- SidePanel.prototype.resetColorOptions = function() {
+ SidePanel.prototype.resetColorOptions = function () {
if (this.sChk.checked) {
this.fColorOptions.reset();
} else if (this.fChk.checked) {
@@ -494,13 +499,13 @@ define(["underscore", "Colorer", "ColorOptionsHandler", "util"], function (_, Co
};
};
- SidePanel.prototype.showUpdateBtn = function() {
+ SidePanel.prototype.showUpdateBtn = function () {
if (this.sChk.checked) {
this.sUpdateBtn.classList.remove("hidden");
} else if (this.fChk.checked) {
this.fUpdateBtn.classList.remove("hidden");
}
- }
+ };
/**
* Initializes sample components
From 29ab14b05aa7bd0c4a23480f8b044e522b141337 Mon Sep 17 00:00:00 2001
From: kcantrel
Date: Fri, 28 May 2021 23:36:26 -0700
Subject: [PATCH 04/17] fixed style
---
empress/support_files/js/colorer.js | 2 +-
empress/support_files/js/empress.js | 5 +----
empress/support_files/js/side-panel-handler.js | 2 +-
3 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/empress/support_files/js/colorer.js b/empress/support_files/js/colorer.js
index 3894bf030..ff2c4c0ed 100644
--- a/empress/support_files/js/colorer.js
+++ b/empress/support_files/js/colorer.js
@@ -251,7 +251,7 @@ define(["chroma", "underscore", "util"], function (chroma, _, util) {
*
* @throws Error if this method is called when using a custom colormap.
*/
- Colorer.prototype.assignContinuousScaledColors = function (nums) {
+ Colorer.prototype.assignContinuousScaledColors = function () {
var scope = this;
if (_.isObject(this.color)) {
diff --git a/empress/support_files/js/empress.js b/empress/support_files/js/empress.js
index 218364918..cc1dbec4b 100644
--- a/empress/support_files/js/empress.js
+++ b/empress/support_files/js/empress.js
@@ -1936,10 +1936,7 @@ define([
// name / barplot layer number). This lets us bail out of
// drawing barplots while still keeping the user aware of why
// nothing just got drawn/updated.
- var msg =
- "Error with assigning colors in barplot layer " +
- layer.num +
- ": " +
+ msg +=
'the feature metadata field "' +
layer.colorByFMField +
'" has less than 2 unique numeric values.';
diff --git a/empress/support_files/js/side-panel-handler.js b/empress/support_files/js/side-panel-handler.js
index cd4b6d5b2..bc40b2d52 100644
--- a/empress/support_files/js/side-panel-handler.js
+++ b/empress/support_files/js/side-panel-handler.js
@@ -627,7 +627,7 @@ define(["underscore", "Colorer", "ColorOptionsHandler", "util"], function (
scope.showUpdateBtn();
};
this.fLineWidth.onchange = () => {
- scope.showUpdateBtn;
+ scope.showUpdateBtn();
};
this.fMethodChk.onchange = function () {
scope.updateFeatureMethodDesc();
From fac0812d0e735f04b26fbec88d33417b8619bd8f Mon Sep 17 00:00:00 2001
From: kcantrel
Date: Sun, 6 Jun 2021 13:25:23 -0700
Subject: [PATCH 05/17] fixed make-dev-page
---
tests/python/make-dev-page.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/tests/python/make-dev-page.py b/tests/python/make-dev-page.py
index 61daa5602..c1b2b3ca3 100755
--- a/tests/python/make-dev-page.py
+++ b/tests/python/make-dev-page.py
@@ -69,7 +69,6 @@ def main(tree, table, sample_metadata, feature_metadata, ordination,
table = table.view(biom.Table)
sample_metadata = sample_metadata.to_dataframe()
feature_metadata = feature_metadata.to_dataframe()
- ordination=None
if ordination is not None:
ordination = ordination.view(OrdinationResults)
From b705358114ef864dd64d24778ff2d20a1004f803 Mon Sep 17 00:00:00 2001
From: kcantrel
Date: Sun, 6 Jun 2021 15:06:59 -0700
Subject: [PATCH 06/17] fixed js test
---
tests/index.html | 1 +
1 file changed, 1 insertion(+)
diff --git a/tests/index.html b/tests/index.html
index 78f79dc83..eb7cb9753 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -204,6 +204,7 @@
'LayoutsUtil' : './support_files/js/layouts-util',
'ExportUtil' : './support_files/js/export-util',
'TreeController' : './support_files/js/tree-controller',
+ 'ColorOptionsHandler' : './support_files/js/color-options-handler',
/* test utility code */
'UtilitiesForTesting' : './../tests/utilities-for-testing',
From c536595a9a0f67be57132520ae69cf53ef7d6a46 Mon Sep 17 00:00:00 2001
From: kwcantrell
Date: Sun, 13 Jun 2021 20:13:00 -0700
Subject: [PATCH 07/17] Apply suggestions from code review
Co-authored-by: Marcus Fedarko
---
empress/support_files/js/color-options-handler.js | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/empress/support_files/js/color-options-handler.js b/empress/support_files/js/color-options-handler.js
index d8e3a4cea..aa81d6473 100644
--- a/empress/support_files/js/color-options-handler.js
+++ b/empress/support_files/js/color-options-handler.js
@@ -1,5 +1,5 @@
define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
- var TotalColorOptionsHanlders = 0;
+ var TotalColorOptionsHandlers = 0;
function ColorOptionsHandler(container, enableContinuousColoring = false) {
this.container = container;
@@ -23,7 +23,7 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
Colorer.addColorsToSelect(this.colormapSelector);
colormapSC.appendChild(this.colormapSelector);
this.colormapSelector.id =
- "color-options-hanlder-" + this.uniqueNum + "-colormap-select";
+ "color-options-handler-" + this.uniqueNum + "-colormap-select";
colormapLbl.setAttribute("for", this.colormapSelector.id);
// Add a row for choosing whether the color scale should
@@ -84,7 +84,7 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
var continuousScaleLbl = continuousScaleP.appendChild(
document.createElement("label")
);
- continuousScaleLbl.innerText = "Manually set boundaries";
+ continuousScaleLbl.innerText = "Manually set gradient boundaries?";
this.continuousScaleCheckbox = continuousScaleP.appendChild(
document.createElement("input")
);
@@ -110,7 +110,7 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
var continuousMinLbl = continuousMinP.appendChild(
document.createElement("label")
);
- continuousMinLbl.innerText = "Min";
+ continuousMinLbl.innerText = "Minimum value";
this.continuousMinInput = continuousMinP.appendChild(
document.createElement("input")
);
@@ -130,7 +130,7 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
var continuousMaxLbl = continuousMaxP.appendChild(
document.createElement("label")
);
- continuousMaxLbl.innerText = "Max";
+ continuousMaxLbl.innerText = "Maximum value";
this.continuousMaxInput = continuousMaxP.appendChild(
document.createElement("input")
);
From c11e7cdf5fb5b9c425be640494051ccbd9b40f10 Mon Sep 17 00:00:00 2001
From: kcantrel
Date: Tue, 15 Jun 2021 22:50:45 -0700
Subject: [PATCH 08/17] addressed inital comments
---
empress/support_files/js/barplot-layer.js | 10 ++-
.../support_files/js/color-options-handler.js | 70 ++++++++++++-------
empress/support_files/js/colorer.js | 18 ++---
empress/support_files/js/empress.js | 5 +-
.../support_files/js/side-panel-handler.js | 4 +-
empress/support_files/js/util.js | 5 +-
6 files changed, 69 insertions(+), 43 deletions(-)
diff --git a/empress/support_files/js/barplot-layer.js b/empress/support_files/js/barplot-layer.js
index 75dca4f55..cc73d7f93 100644
--- a/empress/support_files/js/barplot-layer.js
+++ b/empress/support_files/js/barplot-layer.js
@@ -97,7 +97,7 @@ define([
this.colorByFMColorMap = null;
this.colorByFMColorReverse = false;
this.colorByFMContinuous = false;
- this.colorByFMContinuousScale = false;
+ this.colorByFMContinuousManualScale = false;
this.colorByFMContinuousMin = null;
this.colorByFMContinuousMax = null;
this.colorByFMColorMapDiscrete = true;
@@ -299,10 +299,7 @@ define([
colorDetailsDiv.classList.add("indented");
colorDetailsDiv.classList.add("hidden");
- var fColorOptions = new ColorOptionsHandler(
- colorDetailsDiv,
- (enableContinuousColoring = true)
- );
+ var fColorOptions = new ColorOptionsHandler(colorDetailsDiv, true);
// Initialize defaults to match the UI defaults (e.g. the default
// feature metadata field for coloring is the first in the selector)
@@ -347,7 +344,8 @@ define([
scope.colorByFMColorReverse = options.reverse;
scope.colorByFMColorMapDiscrete = !options.continuousColoring;
scope.colorByFMContinuous = options.continuousColoring;
- scope.colorByFMContinuousScale = options.continuousScale;
+ scope.colorByFMContinuousManualScale =
+ options.continuousManualScale;
scope.colorByFMContinuousMin = options.min;
scope.colorByFMContinuousMax = options.max;
},
diff --git a/empress/support_files/js/color-options-handler.js b/empress/support_files/js/color-options-handler.js
index aa81d6473..d9023c25b 100644
--- a/empress/support_files/js/color-options-handler.js
+++ b/empress/support_files/js/color-options-handler.js
@@ -2,13 +2,15 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
var TotalColorOptionsHandlers = 0;
function ColorOptionsHandler(container, enableContinuousColoring = false) {
+ // add count
+ TotalColorOptionsHandlers += 1;
+
this.container = container;
this.observers = [];
this.defaultColor = "discrete-coloring-qiime";
this.defaultReverseChk = false;
// create unique num
- TotalColorOptionsHanlders += 1;
- this.uniqueNum = TotalColorOptionsHanlders;
+ this.uniqueNum = TotalColorOptionsHandlers;
this.enableContinuousColoring = enableContinuousColoring;
// Add a row for choosing the color map
@@ -74,34 +76,37 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
continuousValP.classList.add("hidden");
// add continuous values min/middle/max inputs
- var continuousScaleDiv = this.container.appendChild(
+ var continuousManualScaleDiv = this.container.appendChild(
document.createElement("div")
);
- continuousScaleDiv.classList.add("hidden");
- var continuousScaleP = continuousScaleDiv.appendChild(
+ continuousManualScaleDiv.classList.add("hidden");
+ continuousManualScaleDiv.classList.add("indented");
+ var continuousManualScaleManualP = continuousManualScaleDiv.appendChild(
document.createElement("p")
);
- var continuousScaleLbl = continuousScaleP.appendChild(
+ var continuousManualScaleLbl = continuousManualScaleManualP.appendChild(
document.createElement("label")
);
- continuousScaleLbl.innerText = "Manually set gradient boundaries?";
- this.continuousScaleCheckbox = continuousScaleP.appendChild(
+ continuousManualScaleLbl.innerText =
+ "Manually set gradient boundaries?";
+ this.continuousManualScaleCheckbox = continuousManualScaleManualP.appendChild(
document.createElement("input")
);
- this.continuousScaleCheckbox.id =
+ this.continuousManualScaleCheckbox.id =
"color-options-hanlder-" +
this.uniqueNum +
"-continuous-scale-chk";
- this.continuousScaleCheckbox.setAttribute("type", "checkbox");
- this.continuousScaleCheckbox.classList.add("empress-input");
- continuousScaleLbl.setAttribute(
+ this.continuousManualScaleCheckbox.setAttribute("type", "checkbox");
+ this.continuousManualScaleCheckbox.classList.add("empress-input");
+ continuousManualScaleLbl.setAttribute(
"for",
- this.continuousScaleCheckbox.id
+ this.continuousManualScaleCheckbox.id
);
- var continuousMinMaxDiv = continuousScaleDiv.appendChild(
+ var continuousMinMaxDiv = continuousManualScaleDiv.appendChild(
document.createElement("div")
);
continuousMinMaxDiv.classList.add("hidden");
+ continuousMinMaxDiv.classList.add("indented");
// add min scale input
var continuousMinP = continuousMinMaxDiv.appendChild(
@@ -150,16 +155,14 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
// add events
this.continuousValCheckbox.onchange = () => {
if (scope.continuousValCheckbox.checked) {
- continuousScaleDiv.classList.remove("hidden");
+ continuousManualScaleDiv.classList.remove("hidden");
} else {
- continuousScaleDiv.classList.add("hidden");
+ continuousManualScaleDiv.classList.add("hidden");
}
notify();
};
- this.continuousScaleCheckbox.onchange = () => {
- if (scope.continuousScaleCheckbox.checked) {
- scope.continuousMinInput.value = null;
- scope.continuousMaxInput.value = null;
+ this.continuousManualScaleCheckbox.onchange = () => {
+ if (scope.continuousManualScaleCheckbox.checked) {
continuousMinMaxDiv.classList.remove("hidden");
} else {
continuousMinMaxDiv.classList.add("hidden");
@@ -187,7 +190,9 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
this.colormapSelector.onchange = () => {
if (scope.enableContinuousColoring) {
if (Colorer.isColorMapDiscrete(scope.colormapSelector.value)) {
+ scope.continuousValCheckbox.checked = false;
continuousValP.classList.add("hidden");
+ continuousManualScaleDiv.classList.add("hidden");
} else {
continuousValP.classList.remove("hidden");
}
@@ -207,14 +212,31 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
reverse: this.reverseColormapCheckbox.checked,
};
if (this.enableContinuousColoring) {
- options.continuousColoring = this.continuousValCheckbox.checked;
- options.continuousScale = this.continuousScaleCheckbox.checked;
- options.min = this.verifyMinBoundary();
- options.max = this.verifyMaxBoundary();
+ this._getContinuousColoringOptions(options);
}
return options;
};
+ ColorOptionsHandler.prototype._getContinuousColoringOptions = function (
+ options
+ ) {
+ options.continuousColoring = this.continuousValCheckbox.checked;
+ options.continuousManualScale = this.continuousManualScaleCheckbox.checked;
+ options.min = this.verifyMinBoundary();
+ options.max = this.verifyMaxBoundary();
+
+ if (!options.continuousColoring) {
+ // set options to not use continuous coloring
+ options.continuousManualScale = false;
+ options.min = null;
+ options.max = null;
+ } else if (!options.continuousManualScale) {
+ // set options to use default continuous scale
+ options.min = null;
+ options.max = null;
+ }
+ };
+
ColorOptionsHandler.prototype.reset = function () {
this.colormapSelector.value = this.defaultColor;
this.reverseColormapCheckbox.checked = this.defaultReverseChk;
diff --git a/empress/support_files/js/colorer.js b/empress/support_files/js/colorer.js
index ff2c4c0ed..38fcb7ba9 100644
--- a/empress/support_files/js/colorer.js
+++ b/empress/support_files/js/colorer.js
@@ -31,10 +31,12 @@ define(["chroma", "underscore", "util"], function (chroma, _, util) {
* @param{Boolean} reverse Defaults to false. If true, the color scale
* will be reversed, with respect to its default
* orientation.
- * @param{Object} domain [min, max] or null, default null.
- * [min, max] set the min and max of the color
+ * @param{Array} domain [min, max] or null, default null object.
+ * min and max will set the min or max of the color
+ * gradient. if either min or max are null then the
+ * default min or max values will be used.
+ * null will use default min/max for color
* gradient.
- * null will use default min/max for color gradient.
*
* @return{Colorer}
* constructs Colorer
@@ -221,13 +223,13 @@ define(["chroma", "underscore", "util"], function (chroma, _, util) {
};
Colorer.prototype.getContinuousColorRange = function (nums) {
- var min, mid, max;
- if (this.domain !== null) {
+ var min = _.min(nums);
+ var max = _.max(nums);
+ if (this.domain !== null && this.domain[0] !== null) {
min = this.domain[0];
+ }
+ if (this.domain !== null && this.domain[1] !== null) {
max = this.domain[1];
- } else {
- min = _.min(nums);
- max = _.max(nums);
}
return {
min: min,
diff --git a/empress/support_files/js/empress.js b/empress/support_files/js/empress.js
index 8507c2871..d7f16b28b 100644
--- a/empress/support_files/js/empress.js
+++ b/empress/support_files/js/empress.js
@@ -1905,7 +1905,10 @@ define([
"Error with assigning colors in barplot layer " +
layer.num +
": ";
- if (layer.colorByFMContinuousScale) {
+ if (
+ layer.colorByFMContinuous &&
+ layer.colorByFMContinuousManualScale
+ ) {
var min = layer.colorByFMContinuousMin;
var max = layer.colorByFMContinuousMax;
diff --git a/empress/support_files/js/side-panel-handler.js b/empress/support_files/js/side-panel-handler.js
index d5b6b5102..38fa2cdd0 100644
--- a/empress/support_files/js/side-panel-handler.js
+++ b/empress/support_files/js/side-panel-handler.js
@@ -200,7 +200,7 @@ define(["underscore", "Colorer", "ColorOptionsHandler", "util"], function (
if (this.sChk.checked) {
this.fColorOptions.reset();
} else if (this.fChk.checked) {
- this.fColorOptions.reset();
+ this.sColorOptions.reset();
}
};
@@ -225,7 +225,6 @@ define(["underscore", "Colorer", "ColorOptionsHandler", "util"], function (
*/
SidePanel.prototype._resetTab = function (eleNameToProperties, elesToHide) {
var scope = this;
- this.resetColorOptions();
_.each(eleNameToProperties, function (properties, eleName) {
_.each(properties, function (propVal, prop) {
scope[eleName][prop] = propVal;
@@ -234,6 +233,7 @@ define(["underscore", "Colorer", "ColorOptionsHandler", "util"], function (
_.each(elesToHide, function (ele) {
ele.classList.add("hidden");
});
+ this.resetColorOptions();
// Reset tree and then clear legend
this.empress.resetTree();
this.empress.drawTree();
diff --git a/empress/support_files/js/util.js b/empress/support_files/js/util.js
index 42676d8d2..0bd317890 100644
--- a/empress/support_files/js/util.js
+++ b/empress/support_files/js/util.js
@@ -171,14 +171,15 @@ define(["underscore", "toastr"], function (_, toastr) {
* element.
* @param {Number} min Defaults to 0. Minimum acceptable value for line
* width/for whatever numeric quality is being
- * considered.
+ * considered. min can also be set to null if
+ * inputEle.value can be null.
* @return {Number} Sanitized number that can be used as input to
* Empress.thickenColoredNodes().
*/
function parseAndValidateNum(inputEle, min = 0) {
if (isValidNumber(inputEle.value)) {
var pfVal = parseFloat(inputEle.value);
- if (min === null || pfVal >= min) {
+ if (pfVal >= min) {
return pfVal;
}
}
From 89ea3381263fff720f8ec49b607e43750b923546 Mon Sep 17 00:00:00 2001
From: Marcus Fedarko
Date: Thu, 19 May 2022 21:56:22 -0700
Subject: [PATCH 09/17] DOC: adjust handler ID, flesh out a comment
---
empress/support_files/js/color-options-handler.js | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/empress/support_files/js/color-options-handler.js b/empress/support_files/js/color-options-handler.js
index d9023c25b..4e4d8cf28 100644
--- a/empress/support_files/js/color-options-handler.js
+++ b/empress/support_files/js/color-options-handler.js
@@ -41,7 +41,7 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
document.createElement("input")
);
this.reverseColormapCheckbox.id =
- "color-options-hanlder-" + this.uniqueNum + "-reverse-chk";
+ "color-options-handler-" + this.uniqueNum + "-reverse-chk";
this.reverseColormapCheckbox.setAttribute("type", "checkbox");
this.reverseColormapCheckbox.classList.add("empress-input");
reverseColormapLbl.setAttribute("for", this.reverseColormapCheckbox.id);
@@ -67,7 +67,7 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
document.createElement("input")
);
this.continuousValCheckbox.id =
- "color-options-hanlder-" + this.uniqueNum + "-continuous-chk";
+ "color-options-handler-" + this.uniqueNum + "-continuous-chk";
this.continuousValCheckbox.setAttribute("type", "checkbox");
this.continuousValCheckbox.classList.add("empress-input");
continuousValLbl.setAttribute("for", this.continuousValCheckbox.id);
@@ -75,7 +75,9 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
// colormap is discrete
continuousValP.classList.add("hidden");
- // add continuous values min/middle/max inputs
+ // When we're working with a continuous colormap, provide users
+ // the ability to set the min/max of the input manually. See
+ // https://github.com/biocore/empress/pull/521.
var continuousManualScaleDiv = this.container.appendChild(
document.createElement("div")
);
@@ -93,7 +95,7 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
document.createElement("input")
);
this.continuousManualScaleCheckbox.id =
- "color-options-hanlder-" +
+ "color-options-handler-" +
this.uniqueNum +
"-continuous-scale-chk";
this.continuousManualScaleCheckbox.setAttribute("type", "checkbox");
@@ -123,7 +125,7 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
this.continuousMinInput.classList.add("empress-input");
this.continuousMinInput.value = null;
this.continuousMinInput.id =
- "color-options-hanlder-" +
+ "color-options-handler-" +
this.uniqueNum +
"-continuous-min-input";
continuousMinLbl.setAttribute("for", this.continuousMinInput.id);
@@ -143,7 +145,7 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
this.continuousMaxInput.classList.add("empress-input");
this.continuousMaxInput.value = null;
this.continuousMaxInput.id =
- "color-options-hanlder-" +
+ "color-options-handler-" +
this.uniqueNum +
"-continuous-max-input";
continuousMaxLbl.setAttribute("for", this.continuousMaxInput.id);
From 70668f2e874c11ec11d93bef54a14ff768cc5ce3 Mon Sep 17 00:00:00 2001
From: Marcus Fedarko
Date: Thu, 19 May 2022 22:13:16 -0700
Subject: [PATCH 10/17] BUG: Add back null check in parseAndValidateNum()
This fixes the issue with negative numbers in #521.
---
empress/support_files/js/util.js | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/empress/support_files/js/util.js b/empress/support_files/js/util.js
index 514937db5..7b83e8659 100644
--- a/empress/support_files/js/util.js
+++ b/empress/support_files/js/util.js
@@ -179,7 +179,12 @@ define(["underscore", "toastr"], function (_, toastr) {
function parseAndValidateNum(inputEle, min = 0) {
if (isValidNumber(inputEle.value)) {
var pfVal = parseFloat(inputEle.value);
- if (pfVal >= min) {
+ // if min is null, then the number in the input element doesn't
+ // have a defined lower limit -- so, for example, negative numbers
+ // will be accepted. This is the case when, for example, we want
+ // to allow users to set continuous colormaps that range from
+ // [-5, 5] or something.
+ if (_.isNull(min) || pfVal >= min) {
return pfVal;
}
}
From 11d04029ec83a692c979906cf2cec449d16f1918 Mon Sep 17 00:00:00 2001
From: Marcus Fedarko
Date: Thu, 19 May 2022 22:28:19 -0700
Subject: [PATCH 11/17] DOC: min -> Minimum, etc in two toasts
---
empress/support_files/js/color-options-handler.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/empress/support_files/js/color-options-handler.js b/empress/support_files/js/color-options-handler.js
index 4e4d8cf28..d55aa72f6 100644
--- a/empress/support_files/js/color-options-handler.js
+++ b/empress/support_files/js/color-options-handler.js
@@ -248,7 +248,7 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
var min = parseFloat(this.continuousMinInput.value);
if (isNaN(min)) {
- return "Min boundary field is missing.";
+ return "Minimum boundary value is missing.";
}
return min;
@@ -259,7 +259,7 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
var max = parseFloat(this.continuousMaxInput.value);
if (isNaN(max)) {
- return "Max boundary field is missing.";
+ return "Maximum boundary value is missing.";
}
// It should be noted that if min isNaN that this will always return
From adb55c78bfd938f054f7742bec40d5ea09c05af9 Mon Sep 17 00:00:00 2001
From: Marcus Fedarko
Date: Thu, 19 May 2022 22:56:51 -0700
Subject: [PATCH 12/17] ENH: tidy up barplot coloring error handling
---
.../support_files/js/color-options-handler.js | 2 +-
empress/support_files/js/empress.js | 44 +++++++++++++------
2 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/empress/support_files/js/color-options-handler.js b/empress/support_files/js/color-options-handler.js
index d55aa72f6..c9e06a3ba 100644
--- a/empress/support_files/js/color-options-handler.js
+++ b/empress/support_files/js/color-options-handler.js
@@ -265,7 +265,7 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
// It should be noted that if min isNaN that this will always return
// false
if (max <= min) {
- return "Max boundary must be greater than Min boundary.";
+ return "Maximum boundary must be greater than minimum boundary.";
}
return max;
diff --git a/empress/support_files/js/empress.js b/empress/support_files/js/empress.js
index c8dd51390..f62fbd292 100644
--- a/empress/support_files/js/empress.js
+++ b/empress/support_files/js/empress.js
@@ -1932,28 +1932,47 @@ define([
// in the Colorer tests; ctrl-F for "CVALDISCRETETEST" in
// tests/test-colorer.js to see this.)
var domain = null;
- var msg =
- "Error with assigning colors in barplot layer " +
- layer.num +
- ": ";
+ var msg = "Layer " + layer.num + ": ";
if (
layer.colorByFMContinuous &&
layer.colorByFMContinuousManualScale
) {
+ // If the min / max boundary fields are missing, these will not
+ // be numeric values. Instead, they'll actually be string error
+ // messages returned by ColorOptionsHandler.verifyMaxBoundary()
+ // -- we can check for this using _.isFinite().
var min = layer.colorByFMContinuousMin;
var max = layer.colorByFMContinuousMax;
- if (isNaN(min)) {
- msg += min;
- util.toastMsg(msg, 5000);
- throw msg;
+ var msgHeader = "Barplot coloring error";
+ var minErr = !_.isFinite(min);
+ var maxErr = !_.isFinite(max);
+ var boundaryErrors = true;
+ if (minErr) {
+ if (maxErr) {
+ // Just concatenate the error messages together.
+ // I guess if we wanna get ~~really~~ fancy with
+ // this we could separate them by a semicolon or
+ // something (and then make the first character of
+ // the "max" error message lowercase), but that's
+ // probs too much work
+ msg += min + " " + max;
+ } else {
+ msg += min;
+ }
+ } else {
+ if (maxErr) {
+ msg += max;
+ } else {
+ boundaryErrors = false;
+ }
}
- if (isNaN(max)) {
- msg += max;
- util.toastMsg(msg, 5000);
+ if (boundaryErrors) {
+ util.toastMsg(msgHeader, msg, (duration = 5000));
throw msg;
}
+
domain = [min, max];
}
try {
@@ -1974,8 +1993,7 @@ define([
// name / barplot layer number). This lets us bail out of
// drawing barplots while still keeping the user aware of why
// nothing just got drawn/updated.
- msg +=
- 'the feature metadata field "' +
+ msg += ' the feature metadata field "' +
layer.colorByFMField +
'" has less than 2 unique numeric values.';
util.toastMsg("Barplot coloring error", msg, (duration = 5000));
From 2445743ae65334bd098a6a808f1913d79350fdf6 Mon Sep 17 00:00:00 2001
From: Marcus Fedarko
Date: Thu, 19 May 2022 23:06:45 -0700
Subject: [PATCH 13/17] STY: Run prettier on everything
The build will still fail to dependency issues (documented in #555),
but when those are fixed it should at least pass.
---
.../support_files/js/color-options-handler.js | 24 +-
empress/support_files/js/emperor-callbacks.js | 160 +++----
empress/support_files/js/empress.js | 8 +-
empress/support_files/js/export-util.js | 5 +-
empress/support_files/js/select-node-menu.js | 15 +-
empress/support_files/js/shearer.js | 11 +-
tests/test-bp-tree.js | 403 ++----------------
tests/test-colorer.js | 3 +-
tests/test-empress.js | 75 +---
tests/test-layouts-util.js | 71 +--
tests/test-select-node-menu.js | 6 +-
11 files changed, 189 insertions(+), 592 deletions(-)
diff --git a/empress/support_files/js/color-options-handler.js b/empress/support_files/js/color-options-handler.js
index c9e06a3ba..27b31aab8 100644
--- a/empress/support_files/js/color-options-handler.js
+++ b/empress/support_files/js/color-options-handler.js
@@ -83,17 +83,20 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
);
continuousManualScaleDiv.classList.add("hidden");
continuousManualScaleDiv.classList.add("indented");
- var continuousManualScaleManualP = continuousManualScaleDiv.appendChild(
- document.createElement("p")
- );
- var continuousManualScaleLbl = continuousManualScaleManualP.appendChild(
- document.createElement("label")
- );
+ var continuousManualScaleManualP =
+ continuousManualScaleDiv.appendChild(
+ document.createElement("p")
+ );
+ var continuousManualScaleLbl =
+ continuousManualScaleManualP.appendChild(
+ document.createElement("label")
+ );
continuousManualScaleLbl.innerText =
"Manually set gradient boundaries?";
- this.continuousManualScaleCheckbox = continuousManualScaleManualP.appendChild(
- document.createElement("input")
- );
+ this.continuousManualScaleCheckbox =
+ continuousManualScaleManualP.appendChild(
+ document.createElement("input")
+ );
this.continuousManualScaleCheckbox.id =
"color-options-handler-" +
this.uniqueNum +
@@ -223,7 +226,8 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
options
) {
options.continuousColoring = this.continuousValCheckbox.checked;
- options.continuousManualScale = this.continuousManualScaleCheckbox.checked;
+ options.continuousManualScale =
+ this.continuousManualScaleCheckbox.checked;
options.min = this.verifyMinBoundary();
options.max = this.verifyMaxBoundary();
diff --git a/empress/support_files/js/emperor-callbacks.js b/empress/support_files/js/emperor-callbacks.js
index c46d7fa6a..4faf3dec7 100644
--- a/empress/support_files/js/emperor-callbacks.js
+++ b/empress/support_files/js/emperor-callbacks.js
@@ -149,25 +149,26 @@ plotView.on("select", function (samples, view) {
* For more information about Emperor callbacks visit:
* http://biocore.github.io/emperor/build/html/js_integration.html#subscribing-to-events-from-a-3rd-party-application
*/
-ec.controllers.animations.addEventListener("animation-started", function (
- payload
-) {
- // reset and disable the animation controls once an Emperor-driven
- // animation starts
- animationPanel.startOptions();
- animationPanel.setEnabled(false);
- animationPanel.disableTab();
-
- animator.setAnimationParameters(
- payload.message.trajectory,
- payload.message.gradient,
- payload.target.getColors(),
- animator.collapse,
- animator.lWidth
- );
- animator.initAnimation();
- animator.disableSidePanelTabs();
-});
+ec.controllers.animations.addEventListener(
+ "animation-started",
+ function (payload) {
+ // reset and disable the animation controls once an Emperor-driven
+ // animation starts
+ animationPanel.startOptions();
+ animationPanel.setEnabled(false);
+ animationPanel.disableTab();
+
+ animator.setAnimationParameters(
+ payload.message.trajectory,
+ payload.message.gradient,
+ payload.target.getColors(),
+ animator.collapse,
+ animator.lWidth
+ );
+ animator.initAnimation();
+ animator.disableSidePanelTabs();
+ }
+);
ec.controllers.animations.addEventListener(
"animation-new-frame-started",
@@ -176,69 +177,72 @@ ec.controllers.animations.addEventListener(
}
);
-ec.controllers.animations.addEventListener("animation-cancelled", function (
- payload
-) {
- // if the animation is cancelled enable the animation controls
- animationPanel.setEnabled(true);
- animationPanel.enableTab();
- animator.stopAnimation();
-});
-
-ec.controllers.animations.addEventListener("animation-ended", function (
- payload
-) {
- // if the animation ends enable the controls
- animationPanel.setEnabled(true);
- util.toastMsg(
- "Animation complete.",
- "",
- (duration = 3000),
- (toastType = "success")
- );
-});
-
-ec.controllers.color.addEventListener("value-double-clicked", function (
- payload
-) {
- // remove any ongoing observers
- shearer.unregisterObserver("emperor-value-double-clicked");
-
- // when dealing with a biplot ignore arrow-emitted events
- if (payload.target.decompositionName() !== "scatter") {
- return;
+ec.controllers.animations.addEventListener(
+ "animation-cancelled",
+ function (payload) {
+ // if the animation is cancelled enable the animation controls
+ animationPanel.setEnabled(true);
+ animationPanel.enableTab();
+ animator.stopAnimation();
}
+);
- // cancel any ongoing timers
- clearTimeout(empress.timer);
-
- // reset emissive settings for all markers since an ongoing timer may have
- // been cancelled
- ec.decViews.scatter.setEmissive(0x000000);
- plotView.needsUpdate = true;
+ec.controllers.animations.addEventListener(
+ "animation-ended",
+ function (payload) {
+ // if the animation ends enable the controls
+ animationPanel.setEnabled(true);
+ util.toastMsg(
+ "Animation complete.",
+ "",
+ (duration = 3000),
+ (toastType = "success")
+ );
+ }
+);
- var names = _.map(payload.message.group, function (item) {
- return item.name;
- });
- var container = {};
- container[payload.message.attribute] = names;
+ec.controllers.color.addEventListener(
+ "value-double-clicked",
+ function (payload) {
+ // remove any ongoing observers
+ shearer.unregisterObserver("emperor-value-double-clicked");
- var colorEmpress = () => {
- emperorCallbackColorEmpress(container);
- };
- colorEmpress();
+ // when dealing with a biplot ignore arrow-emitted events
+ if (payload.target.decompositionName() !== "scatter") {
+ return;
+ }
- // 4 seconds before resetting
- var shearObs = {
- shearerObserverName: "emperor-value-double-clicked",
- shearUpdate: colorEmpress,
- };
- shearer.registerObserver(shearObs);
- empress.timer = setTimeout(function () {
- empress.resetTree();
- empress.drawTree();
+ // cancel any ongoing timers
+ clearTimeout(empress.timer);
+ // reset emissive settings for all markers since an ongoing timer may have
+ // been cancelled
+ ec.decViews.scatter.setEmissive(0x000000);
plotView.needsUpdate = true;
- shearer.unregisterObserver("emperor-value-double-clicked");
- }, 4000);
-});
+
+ var names = _.map(payload.message.group, function (item) {
+ return item.name;
+ });
+ var container = {};
+ container[payload.message.attribute] = names;
+
+ var colorEmpress = () => {
+ emperorCallbackColorEmpress(container);
+ };
+ colorEmpress();
+
+ // 4 seconds before resetting
+ var shearObs = {
+ shearerObserverName: "emperor-value-double-clicked",
+ shearUpdate: colorEmpress,
+ };
+ shearer.registerObserver(shearObs);
+ empress.timer = setTimeout(function () {
+ empress.resetTree();
+ empress.drawTree();
+
+ plotView.needsUpdate = true;
+ shearer.unregisterObserver("emperor-value-double-clicked");
+ }, 4000);
+ }
+);
diff --git a/empress/support_files/js/empress.js b/empress/support_files/js/empress.js
index f62fbd292..125d4bfba 100644
--- a/empress/support_files/js/empress.js
+++ b/empress/support_files/js/empress.js
@@ -400,9 +400,8 @@ define([
j = 1;
// set up length getter
var branchMethod = this.branchMethod;
- var checkLengthsChange = LayoutsUtil.shouldCheckBranchLengthsChanged(
- branchMethod
- );
+ var checkLengthsChange =
+ LayoutsUtil.shouldCheckBranchLengthsChanged(branchMethod);
var lengthGetter = LayoutsUtil.getLengthMethod(
branchMethod,
this._tree.getTree()
@@ -1993,7 +1992,8 @@ define([
// name / barplot layer number). This lets us bail out of
// drawing barplots while still keeping the user aware of why
// nothing just got drawn/updated.
- msg += ' the feature metadata field "' +
+ msg +=
+ ' the feature metadata field "' +
layer.colorByFMField +
'" has less than 2 unique numeric values.';
util.toastMsg("Barplot coloring error", msg, (duration = 5000));
diff --git a/empress/support_files/js/export-util.js b/empress/support_files/js/export-util.js
index ff0c83f18..31d1f1e76 100644
--- a/empress/support_files/js/export-util.js
+++ b/empress/support_files/js/export-util.js
@@ -326,8 +326,9 @@ define(["underscore", "chroma", "Colorer"], function (_, chroma, Colorer) {
// Draw barplots.
if (empress._barplotsDrawn) {
svg += "\n";
- var bpCoords = empress.getBarplotData(empress.getBarplotLayers())
- .coords;
+ var bpCoords = empress.getBarplotData(
+ empress.getBarplotLayers()
+ ).coords;
var bpResults = _addPolygonsToSVG(svg, 6, bb, bpCoords);
svg = bpResults.svg;
bb = bpResults.boundingBox;
diff --git a/empress/support_files/js/select-node-menu.js b/empress/support_files/js/select-node-menu.js
index c9487bceb..8c328f27f 100644
--- a/empress/support_files/js/select-node-menu.js
+++ b/empress/support_files/js/select-node-menu.js
@@ -208,9 +208,8 @@ define(["underscore", "util"], function (_, util) {
_.keys(ctData[field])
);
for (var j = 0; j < categories.length; j++) {
- var categoryHeaderCell = fieldHeaderRow.insertCell(
- -1
- );
+ var categoryHeaderCell =
+ fieldHeaderRow.insertCell(-1);
categoryHeaderCell.innerHTML =
"" + categories[j] + "";
var categoryDataCell = fieldDataRow.insertCell(-1);
@@ -408,9 +407,8 @@ define(["underscore", "util"], function (_, util) {
this.makeSampleMetadataTable(ctData, "tip");
// 2.1 The samples represented by this tip are sent to Emperor.
if (this.empress._biom.hasFeatureID(node)) {
- this._samplesInSelection = this.empress._biom.getSamplesByObservations(
- [node]
- );
+ this._samplesInSelection =
+ this.empress._biom.getSamplesByObservations([node]);
} else {
this._samplesInSelection = [];
}
@@ -444,9 +442,8 @@ define(["underscore", "util"], function (_, util) {
// determine whether or not to show a warning about duplicate names
// in the menu.
if (name !== null) {
- var keysOfNodesWithThisName = this.empress._tree.getNodesWithName(
- name
- );
+ var keysOfNodesWithThisName =
+ this.empress._tree.getNodesWithName(name);
if (keysOfNodesWithThisName.length > 1) {
updateAndShow(
this.nodeNameWarning,
diff --git a/empress/support_files/js/shearer.js b/empress/support_files/js/shearer.js
index d3f4827f4..621fd9193 100644
--- a/empress/support_files/js/shearer.js
+++ b/empress/support_files/js/shearer.js
@@ -183,8 +183,10 @@ define(["underscore", "util", "TreeController"], function (
* from.
*/
ShearModel.prototype.addLayer = function (layer) {
- var fVals = this.empress.getUniqueFeatureMetadataInfo(layer, "tip")
- .sortedUniqueValues;
+ var fVals = this.empress.getUniqueFeatureMetadataInfo(
+ layer,
+ "tip"
+ ).sortedUniqueValues;
var layerObj = new ShearLayer(
layer,
fVals,
@@ -415,9 +417,8 @@ define(["underscore", "util", "TreeController"], function (
// this holds the 'Shear by...' select menu and the
// 'Add shear filter' button
- this.shearOptionsContainer = document.getElementById(
- "shear-add-options"
- );
+ this.shearOptionsContainer =
+ document.getElementById("shear-add-options");
var scope = this;
_.each(this.fCols, function (col) {
diff --git a/tests/test-bp-tree.js b/tests/test-bp-tree.js
index 42486fcc0..31f5ab882 100644
--- a/tests/test-bp-tree.js
+++ b/tests/test-bp-tree.js
@@ -6,28 +6,8 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
module("Succinct Tree", {
setup: function () {
this.bpArray = new Uint8Array([
- 1,
- 1,
- 1,
- 0,
- 1,
- 0,
- 1,
- 1,
- 0,
- 0,
- 0,
- 1,
- 0,
- 1,
- 1,
- 1,
- 0,
- 1,
- 0,
- 0,
- 0,
- 0,
+ 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0,
+ 0, 0,
]);
this.bpObj = new BPTree(
this.bpArray,
@@ -137,27 +117,7 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test excess", function () {
var exp = [
- 1,
- 2,
- 3,
- 2,
- 3,
- 2,
- 3,
- 4,
- 3,
- 2,
- 1,
- 2,
- 1,
- 2,
- 3,
- 4,
- 3,
- 4,
- 3,
- 2,
- 1,
+ 1, 2, 3, 2, 3, 2, 3, 4, 3, 2, 1, 2, 1, 2, 3, 4, 3, 4, 3, 2, 1,
0,
];
for (var i = 0; i < exp.length; i++) {
@@ -168,27 +128,7 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
// Note: depth should equal to excess
test("Test depth", function () {
var exp = [
- 1,
- 2,
- 3,
- 2,
- 3,
- 2,
- 3,
- 4,
- 3,
- 2,
- 1,
- 2,
- 1,
- 2,
- 3,
- 4,
- 3,
- 4,
- 3,
- 2,
- 1,
+ 1, 2, 3, 2, 3, 2, 3, 4, 3, 2, 1, 2, 1, 2, 3, 4, 3, 4, 3, 2, 1,
0,
];
for (var i = 0; i < exp.length; i++) {
@@ -259,25 +199,7 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test enclose", function () {
var exp = [
- 0,
- 1,
- 1,
- 1,
- 1,
- 1,
- 6,
- 6,
- 1,
- 0,
- 0,
- 0,
- 0,
- 13,
- 14,
- 14,
- 14,
- 14,
- 13,
+ 0, 1, 1, 1, 1, 1, 6, 6, 1, 0, 0, 0, 0, 13, 14, 14, 14, 14, 13,
0,
];
for (var i = 1; i < this.bpArray.length - 1; i++) {
@@ -291,28 +213,8 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test parent", function () {
var exp = [
- -1,
- 0,
- 1,
- 1,
- 1,
- 1,
- 1,
- 6,
- 6,
- 1,
- 0,
- 0,
- 0,
- 0,
- 13,
- 14,
- 14,
- 14,
- 14,
- 13,
- 0,
- -1,
+ -1, 0, 1, 1, 1, 1, 1, 6, 6, 1, 0, 0, 0, 0, 13, 14, 14, 14, 14,
+ 13, 0, -1,
];
for (var i = 0; i < this.bpArray.length; i++) {
equal(this.bpObj.parent(i), exp[i], `Parent for ${i}-th index`);
@@ -325,27 +227,7 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test isleaf", function () {
var exp = [
- 0,
- 0,
- 1,
- 0,
- 1,
- 0,
- 0,
- 1,
- 0,
- 0,
- 0,
- 1,
- 0,
- 0,
- 0,
- 1,
- 0,
- 1,
- 0,
- 0,
- 0,
+ 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0,
0,
];
for (var i = 0; i < this.bpArray.length; i++) {
@@ -355,28 +237,8 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test fchild", function () {
var exp = [
- 1,
- 2,
- 0,
- 0,
- 0,
- 0,
- 7,
- 0,
- 0,
- 7,
- 2,
- 0,
- 0,
- 14,
- 15,
- 0,
- 0,
- 0,
- 0,
- 15,
- 14,
- 1,
+ 1, 2, 0, 0, 0, 0, 7, 0, 0, 7, 2, 0, 0, 14, 15, 0, 0, 0, 0, 15,
+ 14, 1,
];
for (var i = 0; i < this.bpArray.length; i++) {
equal(this.bpObj.fchild(i), exp[i], `${i}-th index`);
@@ -385,28 +247,8 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test lchild", function () {
var exp = [
- 13,
- 6,
- 0,
- 0,
- 0,
- 0,
- 7,
- 0,
- 0,
- 7,
- 6,
- 0,
- 0,
- 14,
- 17,
- 0,
- 0,
- 0,
- 0,
- 17,
- 14,
- 13,
+ 13, 6, 0, 0, 0, 0, 7, 0, 0, 7, 6, 0, 0, 14, 17, 0, 0, 0, 0, 17,
+ 14, 13,
];
for (var i = 0; i < this.bpArray.length; i++) {
equal(this.bpObj.lchild(i), exp[i], `${i}-th index`);
@@ -415,28 +257,8 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test nsibling", function () {
var exp = [
- 0,
- 11,
- 4,
- 4,
- 6,
- 6,
- 0,
- 0,
- 0,
- 0,
- 11,
- 13,
- 13,
- 0,
- 0,
- 17,
- 17,
- 0,
- 0,
- 0,
- 0,
- 0,
+ 0, 11, 4, 4, 6, 6, 0, 0, 0, 0, 11, 13, 13, 0, 0, 17, 17, 0, 0,
+ 0, 0, 0,
];
for (var i = 0; i < this.bpArray.length; i++) {
equal(this.bpObj.nsibling(i), exp[i], `${i}-th index`);
@@ -445,28 +267,8 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test psibling", function () {
var exp = [
- 0,
- 0,
- 0,
- 0,
- 2,
- 2,
- 4,
- 0,
- 0,
- 4,
- 0,
- 1,
- 1,
- 11,
- 0,
- 0,
- 0,
- 15,
- 15,
- 0,
- 11,
- 0,
+ 0, 0, 0, 0, 2, 2, 4, 0, 0, 4, 0, 1, 1, 11, 0, 0, 0, 15, 15, 0,
+ 11, 0,
];
for (var i = 0; i < this.bpArray.length; i++) {
equal(this.bpObj.psibling(i), exp[i], `${i}-th index`);
@@ -475,28 +277,8 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test postorder", function () {
var exp = [
- 11,
- 5,
- 1,
- 1,
- 2,
- 2,
- 4,
- 3,
- 3,
- 4,
- 5,
- 6,
- 6,
- 10,
- 9,
- 7,
- 7,
- 8,
- 8,
- 9,
- 10,
- 11,
+ 11, 5, 1, 1, 2, 2, 4, 3, 3, 4, 5, 6, 6, 10, 9, 7, 7, 8, 8, 9,
+ 10, 11,
];
for (var i = 0; i < exp.length; i++) {
equal(this.bpObj.postorder(i), exp[i]);
@@ -512,28 +294,8 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test preorder", function () {
exp = [
- 1,
- 2,
- 3,
- 3,
- 4,
- 4,
- 5,
- 6,
- 6,
- 5,
- 2,
- 7,
- 7,
- 8,
- 9,
- 10,
- 10,
- 11,
- 11,
- 9,
- 8,
- 1,
+ 1, 2, 3, 3, 4, 4, 5, 6, 6, 5, 2, 7, 7, 8, 9, 10, 10, 11, 11, 9,
+ 8, 1,
];
for (var i = 0; i < exp.length; i++) {
equal(this.bpObj.preorder(i), exp[i]);
@@ -563,62 +325,9 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
equal(obj.b_.length, 50 + 4);
exp = [
- 5,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
+ 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
];
obj = new BPTree(exp);
equal(obj.b_.length, 51 + 51 + 4);
@@ -827,16 +536,14 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test getSortedChildren", function () {
// Root's children -- see pretty ASCII diagram in
// postorderLeafSortedNodes test above
- deepEqual(this.bpObj.getSortedChildren(0, "ascending"), [
- 11,
- 13,
- 1,
- ]);
- deepEqual(this.bpObj.getSortedChildren(0, "descending"), [
- 1,
- 13,
- 11,
- ]);
+ deepEqual(
+ this.bpObj.getSortedChildren(0, "ascending"),
+ [11, 13, 1]
+ );
+ deepEqual(
+ this.bpObj.getSortedChildren(0, "descending"),
+ [1, 13, 11]
+ );
// Node at index 1's children -- all have the same number of tips
// Note that getSortedChildren() uses a stable sort, so the
@@ -883,27 +590,7 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
// newick represenation
// ((3,4,(6)5)2, 7, ((10, 11)9)8)r;
var preShearArr = [
- 1,
- 1,
- 1,
- 0,
- 1,
- 0,
- 1,
- 1,
- 0,
- 0,
- 0,
- 1,
- 0,
- 1,
- 1,
- 1,
- 0,
- 1,
- 0,
- 0,
- 0,
+ 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0,
0,
];
var preShearNames = [
@@ -957,28 +644,10 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
[11, 10],
]);
var result = preShearBPTree.shear(remove);
- deepEqual(result.tree.b_, [
- 1,
- 1,
- 1,
- 0,
- 1,
- 1,
- 0,
- 0,
- 0,
- 1,
- 0,
- 1,
- 1,
- 1,
- 0,
- 1,
- 0,
- 0,
- 0,
- 0,
- ]);
+ deepEqual(
+ result.tree.b_,
+ [1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0]
+ );
deepEqual(result.tree.names_, [
null,
"4",
diff --git a/tests/test-colorer.js b/tests/test-colorer.js
index 112d0adc9..643dbf88d 100644
--- a/tests/test-colorer.js
+++ b/tests/test-colorer.js
@@ -583,7 +583,8 @@ require([
ok(gradInfo.missingNonNumerics);
});
test("Test Colorer.getGradientInfo (error: no gradient data)", function () {
- var expectedErrorRegex = /No gradient data defined for this Colorer; check that useQuantScale is true and that the selected color map is not discrete./;
+ var expectedErrorRegex =
+ /No gradient data defined for this Colorer; check that useQuantScale is true and that the selected color map is not discrete./;
// Error case 1: useQuantScale is false
var eles = ["0", "1", "2", "3", "4"];
diff --git a/tests/test-empress.js b/tests/test-empress.js
index 10ed7598a..2a425ca84 100644
--- a/tests/test-empress.js
+++ b/tests/test-empress.js
@@ -19,12 +19,10 @@ require([
// _treeData and _tdToInd are created on client-side. The test were
// originally written when coordinates were calculated on python
// side. Thus we need to set them back.
- this.empress._treeData = UtilitiesForTesting.getTestData(
- false
- ).treeData;
- this.empress._tdToInd = UtilitiesForTesting.getTestData(
- false
- ).tdToInd;
+ this.empress._treeData =
+ UtilitiesForTesting.getTestData(false).treeData;
+ this.empress._tdToInd =
+ UtilitiesForTesting.getTestData(false).tdToInd;
},
teardown: function () {
@@ -496,23 +494,20 @@ require([
this.empress._colorTree(obs, cm);
for (var node = 1; node <= 7; node++) {
if (g1Nodes.has(node)) {
- deepEqual(this.empress.getNodeInfo(node, "color"), [
- 1,
- 0,
- 0,
- ]);
+ deepEqual(
+ this.empress.getNodeInfo(node, "color"),
+ [1, 0, 0]
+ );
} else if (g2Nodes.has(node)) {
- deepEqual(this.empress.getNodeInfo(node, "color"), [
- 0,
- 1,
- 0,
- ]);
+ deepEqual(
+ this.empress.getNodeInfo(node, "color"),
+ [0, 1, 0]
+ );
} else {
- deepEqual(this.empress.getNodeInfo(node, "color"), [
- 0,
- 0,
- 1,
- ]);
+ deepEqual(
+ this.empress.getNodeInfo(node, "color"),
+ [0, 0, 1]
+ );
}
}
});
@@ -695,24 +690,8 @@ require([
// make sure the correct the correct collapsed clade buffer has the
// correct shape.
var collapseClades = [
- 35,
- 36,
- 3289650,
- 33,
- 34,
- 3289650,
- 31,
- 32,
- 3289650,
- 35,
- 36,
- 3289650,
- 33,
- 34,
- 3289650,
- 33,
- 34,
- 3289650,
+ 35, 36, 3289650, 33, 34, 3289650, 31, 32, 3289650, 35, 36,
+ 3289650, 33, 34, 3289650, 33, 34, 3289650,
];
deepEqual(this.empress._collapsedCladeBuffer, collapseClades);
@@ -810,23 +789,7 @@ require([
// check unrooted layout shape
this.empress.createCollapsedCladeShape(1);
var exp = [
- 0,
- 1,
- 255,
- 0,
- 5,
- 255,
- 1,
- 1,
- 255,
- 0,
- 1,
- 255,
- 0,
- 5,
- 255,
- -1,
- -1,
+ 0, 1, 255, 0, 5, 255, 1, 1, 255, 0, 1, 255, 0, 5, 255, -1, -1,
255,
];
deepEqual(this.empress._collapsedCladeBuffer, exp);
diff --git a/tests/test-layouts-util.js b/tests/test-layouts-util.js
index 718690bb7..593f5e287 100644
--- a/tests/test-layouts-util.js
+++ b/tests/test-layouts-util.js
@@ -15,24 +15,7 @@ require([
// In Newick format: "(((a:1,e:2)f:1,b:2)g:1,(c:1,d:3)h:2)i:1;"
this.tree = new BPTree(
new Uint8Array([
- 1,
- 1,
- 1,
- 1,
- 0,
- 1,
- 0,
- 0,
- 1,
- 0,
- 0,
- 1,
- 1,
- 0,
- 1,
- 0,
- 0,
- 0,
+ 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0,
]),
["", "a", "e", "f", "b", "g", "c", "d", "h", "i"],
[null, 1.0, 2.0, 1.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0],
@@ -194,16 +177,8 @@ require([
],
xCoord: [0, 3, 4, 2, 3, 1, 3, 5, 2, 0],
yCoord: [
- 0,
- -2.375,
- -1.375,
- -1.875,
- -0.375,
- -1.125,
- 0.625,
- 1.625,
- 1.125,
- 0,
+ 0, -2.375, -1.375, -1.875, -0.375, -1.125, 0.625, 1.625,
+ 1.125, 0,
],
yScalingFactor: 0.25,
};
@@ -274,16 +249,8 @@ require([
],
xCoord: [0, 3, 4, 2, 3, 1, 3, 5, 2, 0],
yCoord: [
- 0,
- 1.375,
- 2.375,
- 1.875,
- 0.375,
- 1.125,
- -1.625,
- -0.625,
- -1.125,
- 0.0,
+ 0, 1.375, 2.375, 1.875, 0.375, 1.125, -1.625, -0.625,
+ -1.125, 0.0,
],
yScalingFactor: 0.25,
};
@@ -579,28 +546,16 @@ require([
var obs = LayoutsUtil.unrootedLayout(this.tree, 1, 1);
var exp = {
xCoord: [
- 0,
- -0.4650449880443435,
- -0.7105255165406029,
- -0.35526275827030146,
- -0.1776313791351507,
- -0.1776313791351507,
- 0.5328941374054522,
- 0.6846094475924276,
- 0.35526275827030146,
- 0,
+ 0, -0.4650449880443435, -0.7105255165406029,
+ -0.35526275827030146, -0.1776313791351507,
+ -0.1776313791351507, 0.5328941374054522, 0.6846094475924276,
+ 0.35526275827030146, 0,
],
yCoord: [
- 0,
- -0.1511022762500036,
- 0.1154318675000508,
- 0,
- 0.4312613037499384,
- 0.05771593375002539,
- -0.05771593375002535,
- -0.5687386962500616,
- -0.11543186750005074,
- 0,
+ 0, -0.1511022762500036, 0.1154318675000508, 0,
+ 0.4312613037499384, 0.05771593375002539,
+ -0.05771593375002535, -0.5687386962500616,
+ -0.11543186750005074, 0,
],
};
this.eq(obs.xCoord, exp.xCoord, "x-coordinates");
diff --git a/tests/test-select-node-menu.js b/tests/test-select-node-menu.js
index e87e27dbb..17c1532a8 100644
--- a/tests/test-select-node-menu.js
+++ b/tests/test-select-node-menu.js
@@ -16,7 +16,8 @@ require([
// needs the Drawer to have been initialized first).
this.testData.empress.initialize();
- this.selectedNodeMenu = this.testData.empress._events.selectedNodeMenu;
+ this.selectedNodeMenu =
+ this.testData.empress._events.selectedNodeMenu;
var _isHidden = function (attrEle) {
return scope.selectedNodeMenu[attrEle].classList.contains(
@@ -70,7 +71,8 @@ require([
});
test("setSelectedNodes: throws error if multiple nodes that don't share the same name selected", function () {
var scope = this;
- var errRegex = /setSelectedNodes\(\): keys do not represent the same node name./;
+ var errRegex =
+ /setSelectedNodes\(\): keys do not represent the same node name./;
// Two internal nodes
throws(function () {
scope.selectedNodeMenu.setSelectedNodes([7, 4]);
From 2493252f19dd3a6e7a2c450788b3640d10b83fb4 Mon Sep 17 00:00:00 2001
From: Marcus Fedarko
Date: Thu, 19 May 2022 23:36:59 -0700
Subject: [PATCH 14/17] STY: okay never mind let's use prettier 2.0.5
matches what we use on the GitHub Actions CI
---
.../support_files/js/color-options-handler.js | 24 +-
empress/support_files/js/emperor-callbacks.js | 160 ++++---
empress/support_files/js/empress.js | 5 +-
empress/support_files/js/export-util.js | 5 +-
empress/support_files/js/select-node-menu.js | 15 +-
empress/support_files/js/shearer.js | 11 +-
tests/test-bp-tree.js | 403 ++++++++++++++++--
tests/test-colorer.js | 3 +-
tests/test-empress.js | 75 +++-
tests/test-layouts-util.js | 71 ++-
tests/test-select-node-menu.js | 6 +-
11 files changed, 591 insertions(+), 187 deletions(-)
diff --git a/empress/support_files/js/color-options-handler.js b/empress/support_files/js/color-options-handler.js
index 27b31aab8..c9e06a3ba 100644
--- a/empress/support_files/js/color-options-handler.js
+++ b/empress/support_files/js/color-options-handler.js
@@ -83,20 +83,17 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
);
continuousManualScaleDiv.classList.add("hidden");
continuousManualScaleDiv.classList.add("indented");
- var continuousManualScaleManualP =
- continuousManualScaleDiv.appendChild(
- document.createElement("p")
- );
- var continuousManualScaleLbl =
- continuousManualScaleManualP.appendChild(
- document.createElement("label")
- );
+ var continuousManualScaleManualP = continuousManualScaleDiv.appendChild(
+ document.createElement("p")
+ );
+ var continuousManualScaleLbl = continuousManualScaleManualP.appendChild(
+ document.createElement("label")
+ );
continuousManualScaleLbl.innerText =
"Manually set gradient boundaries?";
- this.continuousManualScaleCheckbox =
- continuousManualScaleManualP.appendChild(
- document.createElement("input")
- );
+ this.continuousManualScaleCheckbox = continuousManualScaleManualP.appendChild(
+ document.createElement("input")
+ );
this.continuousManualScaleCheckbox.id =
"color-options-handler-" +
this.uniqueNum +
@@ -226,8 +223,7 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
options
) {
options.continuousColoring = this.continuousValCheckbox.checked;
- options.continuousManualScale =
- this.continuousManualScaleCheckbox.checked;
+ options.continuousManualScale = this.continuousManualScaleCheckbox.checked;
options.min = this.verifyMinBoundary();
options.max = this.verifyMaxBoundary();
diff --git a/empress/support_files/js/emperor-callbacks.js b/empress/support_files/js/emperor-callbacks.js
index 4faf3dec7..c46d7fa6a 100644
--- a/empress/support_files/js/emperor-callbacks.js
+++ b/empress/support_files/js/emperor-callbacks.js
@@ -149,26 +149,25 @@ plotView.on("select", function (samples, view) {
* For more information about Emperor callbacks visit:
* http://biocore.github.io/emperor/build/html/js_integration.html#subscribing-to-events-from-a-3rd-party-application
*/
-ec.controllers.animations.addEventListener(
- "animation-started",
- function (payload) {
- // reset and disable the animation controls once an Emperor-driven
- // animation starts
- animationPanel.startOptions();
- animationPanel.setEnabled(false);
- animationPanel.disableTab();
-
- animator.setAnimationParameters(
- payload.message.trajectory,
- payload.message.gradient,
- payload.target.getColors(),
- animator.collapse,
- animator.lWidth
- );
- animator.initAnimation();
- animator.disableSidePanelTabs();
- }
-);
+ec.controllers.animations.addEventListener("animation-started", function (
+ payload
+) {
+ // reset and disable the animation controls once an Emperor-driven
+ // animation starts
+ animationPanel.startOptions();
+ animationPanel.setEnabled(false);
+ animationPanel.disableTab();
+
+ animator.setAnimationParameters(
+ payload.message.trajectory,
+ payload.message.gradient,
+ payload.target.getColors(),
+ animator.collapse,
+ animator.lWidth
+ );
+ animator.initAnimation();
+ animator.disableSidePanelTabs();
+});
ec.controllers.animations.addEventListener(
"animation-new-frame-started",
@@ -177,72 +176,69 @@ ec.controllers.animations.addEventListener(
}
);
-ec.controllers.animations.addEventListener(
- "animation-cancelled",
- function (payload) {
- // if the animation is cancelled enable the animation controls
- animationPanel.setEnabled(true);
- animationPanel.enableTab();
- animator.stopAnimation();
- }
-);
+ec.controllers.animations.addEventListener("animation-cancelled", function (
+ payload
+) {
+ // if the animation is cancelled enable the animation controls
+ animationPanel.setEnabled(true);
+ animationPanel.enableTab();
+ animator.stopAnimation();
+});
-ec.controllers.animations.addEventListener(
- "animation-ended",
- function (payload) {
- // if the animation ends enable the controls
- animationPanel.setEnabled(true);
- util.toastMsg(
- "Animation complete.",
- "",
- (duration = 3000),
- (toastType = "success")
- );
+ec.controllers.animations.addEventListener("animation-ended", function (
+ payload
+) {
+ // if the animation ends enable the controls
+ animationPanel.setEnabled(true);
+ util.toastMsg(
+ "Animation complete.",
+ "",
+ (duration = 3000),
+ (toastType = "success")
+ );
+});
+
+ec.controllers.color.addEventListener("value-double-clicked", function (
+ payload
+) {
+ // remove any ongoing observers
+ shearer.unregisterObserver("emperor-value-double-clicked");
+
+ // when dealing with a biplot ignore arrow-emitted events
+ if (payload.target.decompositionName() !== "scatter") {
+ return;
}
-);
-ec.controllers.color.addEventListener(
- "value-double-clicked",
- function (payload) {
- // remove any ongoing observers
- shearer.unregisterObserver("emperor-value-double-clicked");
+ // cancel any ongoing timers
+ clearTimeout(empress.timer);
- // when dealing with a biplot ignore arrow-emitted events
- if (payload.target.decompositionName() !== "scatter") {
- return;
- }
+ // reset emissive settings for all markers since an ongoing timer may have
+ // been cancelled
+ ec.decViews.scatter.setEmissive(0x000000);
+ plotView.needsUpdate = true;
- // cancel any ongoing timers
- clearTimeout(empress.timer);
+ var names = _.map(payload.message.group, function (item) {
+ return item.name;
+ });
+ var container = {};
+ container[payload.message.attribute] = names;
- // reset emissive settings for all markers since an ongoing timer may have
- // been cancelled
- ec.decViews.scatter.setEmissive(0x000000);
- plotView.needsUpdate = true;
+ var colorEmpress = () => {
+ emperorCallbackColorEmpress(container);
+ };
+ colorEmpress();
- var names = _.map(payload.message.group, function (item) {
- return item.name;
- });
- var container = {};
- container[payload.message.attribute] = names;
-
- var colorEmpress = () => {
- emperorCallbackColorEmpress(container);
- };
- colorEmpress();
-
- // 4 seconds before resetting
- var shearObs = {
- shearerObserverName: "emperor-value-double-clicked",
- shearUpdate: colorEmpress,
- };
- shearer.registerObserver(shearObs);
- empress.timer = setTimeout(function () {
- empress.resetTree();
- empress.drawTree();
-
- plotView.needsUpdate = true;
- shearer.unregisterObserver("emperor-value-double-clicked");
- }, 4000);
- }
-);
+ // 4 seconds before resetting
+ var shearObs = {
+ shearerObserverName: "emperor-value-double-clicked",
+ shearUpdate: colorEmpress,
+ };
+ shearer.registerObserver(shearObs);
+ empress.timer = setTimeout(function () {
+ empress.resetTree();
+ empress.drawTree();
+
+ plotView.needsUpdate = true;
+ shearer.unregisterObserver("emperor-value-double-clicked");
+ }, 4000);
+});
diff --git a/empress/support_files/js/empress.js b/empress/support_files/js/empress.js
index 125d4bfba..23f3a7678 100644
--- a/empress/support_files/js/empress.js
+++ b/empress/support_files/js/empress.js
@@ -400,8 +400,9 @@ define([
j = 1;
// set up length getter
var branchMethod = this.branchMethod;
- var checkLengthsChange =
- LayoutsUtil.shouldCheckBranchLengthsChanged(branchMethod);
+ var checkLengthsChange = LayoutsUtil.shouldCheckBranchLengthsChanged(
+ branchMethod
+ );
var lengthGetter = LayoutsUtil.getLengthMethod(
branchMethod,
this._tree.getTree()
diff --git a/empress/support_files/js/export-util.js b/empress/support_files/js/export-util.js
index 31d1f1e76..ff0c83f18 100644
--- a/empress/support_files/js/export-util.js
+++ b/empress/support_files/js/export-util.js
@@ -326,9 +326,8 @@ define(["underscore", "chroma", "Colorer"], function (_, chroma, Colorer) {
// Draw barplots.
if (empress._barplotsDrawn) {
svg += "\n";
- var bpCoords = empress.getBarplotData(
- empress.getBarplotLayers()
- ).coords;
+ var bpCoords = empress.getBarplotData(empress.getBarplotLayers())
+ .coords;
var bpResults = _addPolygonsToSVG(svg, 6, bb, bpCoords);
svg = bpResults.svg;
bb = bpResults.boundingBox;
diff --git a/empress/support_files/js/select-node-menu.js b/empress/support_files/js/select-node-menu.js
index 8c328f27f..c9487bceb 100644
--- a/empress/support_files/js/select-node-menu.js
+++ b/empress/support_files/js/select-node-menu.js
@@ -208,8 +208,9 @@ define(["underscore", "util"], function (_, util) {
_.keys(ctData[field])
);
for (var j = 0; j < categories.length; j++) {
- var categoryHeaderCell =
- fieldHeaderRow.insertCell(-1);
+ var categoryHeaderCell = fieldHeaderRow.insertCell(
+ -1
+ );
categoryHeaderCell.innerHTML =
"" + categories[j] + "";
var categoryDataCell = fieldDataRow.insertCell(-1);
@@ -407,8 +408,9 @@ define(["underscore", "util"], function (_, util) {
this.makeSampleMetadataTable(ctData, "tip");
// 2.1 The samples represented by this tip are sent to Emperor.
if (this.empress._biom.hasFeatureID(node)) {
- this._samplesInSelection =
- this.empress._biom.getSamplesByObservations([node]);
+ this._samplesInSelection = this.empress._biom.getSamplesByObservations(
+ [node]
+ );
} else {
this._samplesInSelection = [];
}
@@ -442,8 +444,9 @@ define(["underscore", "util"], function (_, util) {
// determine whether or not to show a warning about duplicate names
// in the menu.
if (name !== null) {
- var keysOfNodesWithThisName =
- this.empress._tree.getNodesWithName(name);
+ var keysOfNodesWithThisName = this.empress._tree.getNodesWithName(
+ name
+ );
if (keysOfNodesWithThisName.length > 1) {
updateAndShow(
this.nodeNameWarning,
diff --git a/empress/support_files/js/shearer.js b/empress/support_files/js/shearer.js
index 621fd9193..d3f4827f4 100644
--- a/empress/support_files/js/shearer.js
+++ b/empress/support_files/js/shearer.js
@@ -183,10 +183,8 @@ define(["underscore", "util", "TreeController"], function (
* from.
*/
ShearModel.prototype.addLayer = function (layer) {
- var fVals = this.empress.getUniqueFeatureMetadataInfo(
- layer,
- "tip"
- ).sortedUniqueValues;
+ var fVals = this.empress.getUniqueFeatureMetadataInfo(layer, "tip")
+ .sortedUniqueValues;
var layerObj = new ShearLayer(
layer,
fVals,
@@ -417,8 +415,9 @@ define(["underscore", "util", "TreeController"], function (
// this holds the 'Shear by...' select menu and the
// 'Add shear filter' button
- this.shearOptionsContainer =
- document.getElementById("shear-add-options");
+ this.shearOptionsContainer = document.getElementById(
+ "shear-add-options"
+ );
var scope = this;
_.each(this.fCols, function (col) {
diff --git a/tests/test-bp-tree.js b/tests/test-bp-tree.js
index 31f5ab882..42486fcc0 100644
--- a/tests/test-bp-tree.js
+++ b/tests/test-bp-tree.js
@@ -6,8 +6,28 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
module("Succinct Tree", {
setup: function () {
this.bpArray = new Uint8Array([
- 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0,
- 0, 0,
+ 1,
+ 1,
+ 1,
+ 0,
+ 1,
+ 0,
+ 1,
+ 1,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ 1,
+ 1,
+ 1,
+ 0,
+ 1,
+ 0,
+ 0,
+ 0,
+ 0,
]);
this.bpObj = new BPTree(
this.bpArray,
@@ -117,7 +137,27 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test excess", function () {
var exp = [
- 1, 2, 3, 2, 3, 2, 3, 4, 3, 2, 1, 2, 1, 2, 3, 4, 3, 4, 3, 2, 1,
+ 1,
+ 2,
+ 3,
+ 2,
+ 3,
+ 2,
+ 3,
+ 4,
+ 3,
+ 2,
+ 1,
+ 2,
+ 1,
+ 2,
+ 3,
+ 4,
+ 3,
+ 4,
+ 3,
+ 2,
+ 1,
0,
];
for (var i = 0; i < exp.length; i++) {
@@ -128,7 +168,27 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
// Note: depth should equal to excess
test("Test depth", function () {
var exp = [
- 1, 2, 3, 2, 3, 2, 3, 4, 3, 2, 1, 2, 1, 2, 3, 4, 3, 4, 3, 2, 1,
+ 1,
+ 2,
+ 3,
+ 2,
+ 3,
+ 2,
+ 3,
+ 4,
+ 3,
+ 2,
+ 1,
+ 2,
+ 1,
+ 2,
+ 3,
+ 4,
+ 3,
+ 4,
+ 3,
+ 2,
+ 1,
0,
];
for (var i = 0; i < exp.length; i++) {
@@ -199,7 +259,25 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test enclose", function () {
var exp = [
- 0, 1, 1, 1, 1, 1, 6, 6, 1, 0, 0, 0, 0, 13, 14, 14, 14, 14, 13,
+ 0,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 6,
+ 6,
+ 1,
+ 0,
+ 0,
+ 0,
+ 0,
+ 13,
+ 14,
+ 14,
+ 14,
+ 14,
+ 13,
0,
];
for (var i = 1; i < this.bpArray.length - 1; i++) {
@@ -213,8 +291,28 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test parent", function () {
var exp = [
- -1, 0, 1, 1, 1, 1, 1, 6, 6, 1, 0, 0, 0, 0, 13, 14, 14, 14, 14,
- 13, 0, -1,
+ -1,
+ 0,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 6,
+ 6,
+ 1,
+ 0,
+ 0,
+ 0,
+ 0,
+ 13,
+ 14,
+ 14,
+ 14,
+ 14,
+ 13,
+ 0,
+ -1,
];
for (var i = 0; i < this.bpArray.length; i++) {
equal(this.bpObj.parent(i), exp[i], `Parent for ${i}-th index`);
@@ -227,7 +325,27 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test isleaf", function () {
var exp = [
- 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ 1,
+ 0,
+ 0,
+ 1,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ 1,
+ 0,
+ 0,
+ 0,
0,
];
for (var i = 0; i < this.bpArray.length; i++) {
@@ -237,8 +355,28 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test fchild", function () {
var exp = [
- 1, 2, 0, 0, 0, 0, 7, 0, 0, 7, 2, 0, 0, 14, 15, 0, 0, 0, 0, 15,
- 14, 1,
+ 1,
+ 2,
+ 0,
+ 0,
+ 0,
+ 0,
+ 7,
+ 0,
+ 0,
+ 7,
+ 2,
+ 0,
+ 0,
+ 14,
+ 15,
+ 0,
+ 0,
+ 0,
+ 0,
+ 15,
+ 14,
+ 1,
];
for (var i = 0; i < this.bpArray.length; i++) {
equal(this.bpObj.fchild(i), exp[i], `${i}-th index`);
@@ -247,8 +385,28 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test lchild", function () {
var exp = [
- 13, 6, 0, 0, 0, 0, 7, 0, 0, 7, 6, 0, 0, 14, 17, 0, 0, 0, 0, 17,
- 14, 13,
+ 13,
+ 6,
+ 0,
+ 0,
+ 0,
+ 0,
+ 7,
+ 0,
+ 0,
+ 7,
+ 6,
+ 0,
+ 0,
+ 14,
+ 17,
+ 0,
+ 0,
+ 0,
+ 0,
+ 17,
+ 14,
+ 13,
];
for (var i = 0; i < this.bpArray.length; i++) {
equal(this.bpObj.lchild(i), exp[i], `${i}-th index`);
@@ -257,8 +415,28 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test nsibling", function () {
var exp = [
- 0, 11, 4, 4, 6, 6, 0, 0, 0, 0, 11, 13, 13, 0, 0, 17, 17, 0, 0,
- 0, 0, 0,
+ 0,
+ 11,
+ 4,
+ 4,
+ 6,
+ 6,
+ 0,
+ 0,
+ 0,
+ 0,
+ 11,
+ 13,
+ 13,
+ 0,
+ 0,
+ 17,
+ 17,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
];
for (var i = 0; i < this.bpArray.length; i++) {
equal(this.bpObj.nsibling(i), exp[i], `${i}-th index`);
@@ -267,8 +445,28 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test psibling", function () {
var exp = [
- 0, 0, 0, 0, 2, 2, 4, 0, 0, 4, 0, 1, 1, 11, 0, 0, 0, 15, 15, 0,
- 11, 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 2,
+ 2,
+ 4,
+ 0,
+ 0,
+ 4,
+ 0,
+ 1,
+ 1,
+ 11,
+ 0,
+ 0,
+ 0,
+ 15,
+ 15,
+ 0,
+ 11,
+ 0,
];
for (var i = 0; i < this.bpArray.length; i++) {
equal(this.bpObj.psibling(i), exp[i], `${i}-th index`);
@@ -277,8 +475,28 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test postorder", function () {
var exp = [
- 11, 5, 1, 1, 2, 2, 4, 3, 3, 4, 5, 6, 6, 10, 9, 7, 7, 8, 8, 9,
- 10, 11,
+ 11,
+ 5,
+ 1,
+ 1,
+ 2,
+ 2,
+ 4,
+ 3,
+ 3,
+ 4,
+ 5,
+ 6,
+ 6,
+ 10,
+ 9,
+ 7,
+ 7,
+ 8,
+ 8,
+ 9,
+ 10,
+ 11,
];
for (var i = 0; i < exp.length; i++) {
equal(this.bpObj.postorder(i), exp[i]);
@@ -294,8 +512,28 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test preorder", function () {
exp = [
- 1, 2, 3, 3, 4, 4, 5, 6, 6, 5, 2, 7, 7, 8, 9, 10, 10, 11, 11, 9,
- 8, 1,
+ 1,
+ 2,
+ 3,
+ 3,
+ 4,
+ 4,
+ 5,
+ 6,
+ 6,
+ 5,
+ 2,
+ 7,
+ 7,
+ 8,
+ 9,
+ 10,
+ 10,
+ 11,
+ 11,
+ 9,
+ 8,
+ 1,
];
for (var i = 0; i < exp.length; i++) {
equal(this.bpObj.preorder(i), exp[i]);
@@ -325,9 +563,62 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
equal(obj.b_.length, 50 + 4);
exp = [
- 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 5,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
];
obj = new BPTree(exp);
equal(obj.b_.length, 51 + 51 + 4);
@@ -536,14 +827,16 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
test("Test getSortedChildren", function () {
// Root's children -- see pretty ASCII diagram in
// postorderLeafSortedNodes test above
- deepEqual(
- this.bpObj.getSortedChildren(0, "ascending"),
- [11, 13, 1]
- );
- deepEqual(
- this.bpObj.getSortedChildren(0, "descending"),
- [1, 13, 11]
- );
+ deepEqual(this.bpObj.getSortedChildren(0, "ascending"), [
+ 11,
+ 13,
+ 1,
+ ]);
+ deepEqual(this.bpObj.getSortedChildren(0, "descending"), [
+ 1,
+ 13,
+ 11,
+ ]);
// Node at index 1's children -- all have the same number of tips
// Note that getSortedChildren() uses a stable sort, so the
@@ -590,7 +883,27 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
// newick represenation
// ((3,4,(6)5)2, 7, ((10, 11)9)8)r;
var preShearArr = [
- 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0,
+ 1,
+ 1,
+ 1,
+ 0,
+ 1,
+ 0,
+ 1,
+ 1,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ 1,
+ 1,
+ 1,
+ 0,
+ 1,
+ 0,
+ 0,
+ 0,
0,
];
var preShearNames = [
@@ -644,10 +957,28 @@ require(["jquery", "ByteArray", "BPTree"], function ($, ByteArray, BPTree) {
[11, 10],
]);
var result = preShearBPTree.shear(remove);
- deepEqual(
- result.tree.b_,
- [1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0]
- );
+ deepEqual(result.tree.b_, [
+ 1,
+ 1,
+ 1,
+ 0,
+ 1,
+ 1,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ 1,
+ 1,
+ 1,
+ 0,
+ 1,
+ 0,
+ 0,
+ 0,
+ 0,
+ ]);
deepEqual(result.tree.names_, [
null,
"4",
diff --git a/tests/test-colorer.js b/tests/test-colorer.js
index 643dbf88d..112d0adc9 100644
--- a/tests/test-colorer.js
+++ b/tests/test-colorer.js
@@ -583,8 +583,7 @@ require([
ok(gradInfo.missingNonNumerics);
});
test("Test Colorer.getGradientInfo (error: no gradient data)", function () {
- var expectedErrorRegex =
- /No gradient data defined for this Colorer; check that useQuantScale is true and that the selected color map is not discrete./;
+ var expectedErrorRegex = /No gradient data defined for this Colorer; check that useQuantScale is true and that the selected color map is not discrete./;
// Error case 1: useQuantScale is false
var eles = ["0", "1", "2", "3", "4"];
diff --git a/tests/test-empress.js b/tests/test-empress.js
index 2a425ca84..10ed7598a 100644
--- a/tests/test-empress.js
+++ b/tests/test-empress.js
@@ -19,10 +19,12 @@ require([
// _treeData and _tdToInd are created on client-side. The test were
// originally written when coordinates were calculated on python
// side. Thus we need to set them back.
- this.empress._treeData =
- UtilitiesForTesting.getTestData(false).treeData;
- this.empress._tdToInd =
- UtilitiesForTesting.getTestData(false).tdToInd;
+ this.empress._treeData = UtilitiesForTesting.getTestData(
+ false
+ ).treeData;
+ this.empress._tdToInd = UtilitiesForTesting.getTestData(
+ false
+ ).tdToInd;
},
teardown: function () {
@@ -494,20 +496,23 @@ require([
this.empress._colorTree(obs, cm);
for (var node = 1; node <= 7; node++) {
if (g1Nodes.has(node)) {
- deepEqual(
- this.empress.getNodeInfo(node, "color"),
- [1, 0, 0]
- );
+ deepEqual(this.empress.getNodeInfo(node, "color"), [
+ 1,
+ 0,
+ 0,
+ ]);
} else if (g2Nodes.has(node)) {
- deepEqual(
- this.empress.getNodeInfo(node, "color"),
- [0, 1, 0]
- );
+ deepEqual(this.empress.getNodeInfo(node, "color"), [
+ 0,
+ 1,
+ 0,
+ ]);
} else {
- deepEqual(
- this.empress.getNodeInfo(node, "color"),
- [0, 0, 1]
- );
+ deepEqual(this.empress.getNodeInfo(node, "color"), [
+ 0,
+ 0,
+ 1,
+ ]);
}
}
});
@@ -690,8 +695,24 @@ require([
// make sure the correct the correct collapsed clade buffer has the
// correct shape.
var collapseClades = [
- 35, 36, 3289650, 33, 34, 3289650, 31, 32, 3289650, 35, 36,
- 3289650, 33, 34, 3289650, 33, 34, 3289650,
+ 35,
+ 36,
+ 3289650,
+ 33,
+ 34,
+ 3289650,
+ 31,
+ 32,
+ 3289650,
+ 35,
+ 36,
+ 3289650,
+ 33,
+ 34,
+ 3289650,
+ 33,
+ 34,
+ 3289650,
];
deepEqual(this.empress._collapsedCladeBuffer, collapseClades);
@@ -789,7 +810,23 @@ require([
// check unrooted layout shape
this.empress.createCollapsedCladeShape(1);
var exp = [
- 0, 1, 255, 0, 5, 255, 1, 1, 255, 0, 1, 255, 0, 5, 255, -1, -1,
+ 0,
+ 1,
+ 255,
+ 0,
+ 5,
+ 255,
+ 1,
+ 1,
+ 255,
+ 0,
+ 1,
+ 255,
+ 0,
+ 5,
+ 255,
+ -1,
+ -1,
255,
];
deepEqual(this.empress._collapsedCladeBuffer, exp);
diff --git a/tests/test-layouts-util.js b/tests/test-layouts-util.js
index 593f5e287..718690bb7 100644
--- a/tests/test-layouts-util.js
+++ b/tests/test-layouts-util.js
@@ -15,7 +15,24 @@ require([
// In Newick format: "(((a:1,e:2)f:1,b:2)g:1,(c:1,d:3)h:2)i:1;"
this.tree = new BPTree(
new Uint8Array([
- 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0,
+ 1,
+ 1,
+ 1,
+ 1,
+ 0,
+ 1,
+ 0,
+ 0,
+ 1,
+ 0,
+ 0,
+ 1,
+ 1,
+ 0,
+ 1,
+ 0,
+ 0,
+ 0,
]),
["", "a", "e", "f", "b", "g", "c", "d", "h", "i"],
[null, 1.0, 2.0, 1.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0],
@@ -177,8 +194,16 @@ require([
],
xCoord: [0, 3, 4, 2, 3, 1, 3, 5, 2, 0],
yCoord: [
- 0, -2.375, -1.375, -1.875, -0.375, -1.125, 0.625, 1.625,
- 1.125, 0,
+ 0,
+ -2.375,
+ -1.375,
+ -1.875,
+ -0.375,
+ -1.125,
+ 0.625,
+ 1.625,
+ 1.125,
+ 0,
],
yScalingFactor: 0.25,
};
@@ -249,8 +274,16 @@ require([
],
xCoord: [0, 3, 4, 2, 3, 1, 3, 5, 2, 0],
yCoord: [
- 0, 1.375, 2.375, 1.875, 0.375, 1.125, -1.625, -0.625,
- -1.125, 0.0,
+ 0,
+ 1.375,
+ 2.375,
+ 1.875,
+ 0.375,
+ 1.125,
+ -1.625,
+ -0.625,
+ -1.125,
+ 0.0,
],
yScalingFactor: 0.25,
};
@@ -546,16 +579,28 @@ require([
var obs = LayoutsUtil.unrootedLayout(this.tree, 1, 1);
var exp = {
xCoord: [
- 0, -0.4650449880443435, -0.7105255165406029,
- -0.35526275827030146, -0.1776313791351507,
- -0.1776313791351507, 0.5328941374054522, 0.6846094475924276,
- 0.35526275827030146, 0,
+ 0,
+ -0.4650449880443435,
+ -0.7105255165406029,
+ -0.35526275827030146,
+ -0.1776313791351507,
+ -0.1776313791351507,
+ 0.5328941374054522,
+ 0.6846094475924276,
+ 0.35526275827030146,
+ 0,
],
yCoord: [
- 0, -0.1511022762500036, 0.1154318675000508, 0,
- 0.4312613037499384, 0.05771593375002539,
- -0.05771593375002535, -0.5687386962500616,
- -0.11543186750005074, 0,
+ 0,
+ -0.1511022762500036,
+ 0.1154318675000508,
+ 0,
+ 0.4312613037499384,
+ 0.05771593375002539,
+ -0.05771593375002535,
+ -0.5687386962500616,
+ -0.11543186750005074,
+ 0,
],
};
this.eq(obs.xCoord, exp.xCoord, "x-coordinates");
diff --git a/tests/test-select-node-menu.js b/tests/test-select-node-menu.js
index 17c1532a8..e87e27dbb 100644
--- a/tests/test-select-node-menu.js
+++ b/tests/test-select-node-menu.js
@@ -16,8 +16,7 @@ require([
// needs the Drawer to have been initialized first).
this.testData.empress.initialize();
- this.selectedNodeMenu =
- this.testData.empress._events.selectedNodeMenu;
+ this.selectedNodeMenu = this.testData.empress._events.selectedNodeMenu;
var _isHidden = function (attrEle) {
return scope.selectedNodeMenu[attrEle].classList.contains(
@@ -71,8 +70,7 @@ require([
});
test("setSelectedNodes: throws error if multiple nodes that don't share the same name selected", function () {
var scope = this;
- var errRegex =
- /setSelectedNodes\(\): keys do not represent the same node name./;
+ var errRegex = /setSelectedNodes\(\): keys do not represent the same node name./;
// Two internal nodes
throws(function () {
scope.selectedNodeMenu.setSelectedNodes([7, 4]);
From 097eae73a49510ece34c414ce547db237bfd9772 Mon Sep 17 00:00:00 2001
From: Marcus Fedarko
Date: Fri, 20 May 2022 00:52:58 -0700
Subject: [PATCH 15/17] DOC/TST: tidy up, test, and add sanity checking
One of the tests is failing in a weird way -- something wrong?
---
empress/support_files/js/colorer.js | 61 +++++++++++++++++++++------
empress/support_files/js/empress.js | 22 ++++++----
tests/test-colorer.js | 65 +++++++++++++++++++++++++++++
3 files changed, 127 insertions(+), 21 deletions(-)
diff --git a/empress/support_files/js/colorer.js b/empress/support_files/js/colorer.js
index 38fcb7ba9..e3d6dc018 100644
--- a/empress/support_files/js/colorer.js
+++ b/empress/support_files/js/colorer.js
@@ -31,12 +31,12 @@ define(["chroma", "underscore", "util"], function (chroma, _, util) {
* @param{Boolean} reverse Defaults to false. If true, the color scale
* will be reversed, with respect to its default
* orientation.
- * @param{Array} domain [min, max] or null, default null object.
- * min and max will set the min or max of the color
- * gradient. if either min or max are null then the
- * default min or max values will be used.
- * null will use default min/max for color
- * gradient.
+ * @param{Array} domain Defaults to null. If this is not null, it is
+ * assumed to be an array of [min, max], where min and
+ * max are Numbers. If useQuantScale is true and the
+ * color map is sequential or diverging (i.e. we are
+ * creating a continuous colorscheme), then min and
+ * max will be used as the domain of the color map.
*
* @return{Colorer}
* constructs Colorer
@@ -56,7 +56,6 @@ define(["chroma", "underscore", "util"], function (chroma, _, util) {
this.color = color;
this.reverse = reverse;
- this.domain = domain;
// This object will describe a mapping of unique field values to colors
this.__valueToColor = {};
@@ -90,6 +89,28 @@ define(["chroma", "underscore", "util"], function (chroma, _, util) {
// whether or not to show a warning)
this._missingNonNumerics = false;
+ // Optional custom domain (or this will just be null)
+ this.domain = domain;
+ if (!_.isNull(this.domain)) {
+ // Perform sanity checking on the domain's entries (... or lack
+ // thereof). These problems should already have been caught by the
+ // ColorOptionsHandler, so this is just verifying that the code
+ // hasn't become haunted.
+ if (this.domain.length !== 2) {
+ throw new Error(
+ "Custom domain must have exactly 2 entries"
+ );
+ }
+ if (!_.isFinite(this.domain[0]) || !_.isFinite(this.domain[1])) {
+ throw new Error("Custom domain entries must be finite nums");
+ }
+ // I think chroma can actually handle this case -- it'll just
+ // flip the numbers. But let's not rely on that.
+ if(this.domain[0] >= this.domain[1]) {
+ throw new Error("Custom domain min must be < max");
+ }
+ }
+
/*** End continuous-scaling-specific things ***/
// Based on the color map, container, type and the value of
@@ -222,13 +243,27 @@ define(["chroma", "underscore", "util"], function (chroma, _, util) {
}
};
+ /**
+ * Returns the minimum and maximum of a set of values, accounting for
+ * the possibility of a custom domain.
+ *
+ * Usually, this will just return the min and max values of the input
+ * array, but if this.domain has been set then this will just return the
+ * values from that instead.
+ *
+ * @param{Array} nums An array of values to be mapped to colors.
+ *
+ * @return {Object} minAndMax An object containing two keys: min (maps to
+ * the minimum value) and max (maps to the
+ * maximum value).
+ */
Colorer.prototype.getContinuousColorRange = function (nums) {
- var min = _.min(nums);
- var max = _.max(nums);
- if (this.domain !== null && this.domain[0] !== null) {
+ var min, max;
+ if (_.isNull(this.domain)) {
+ min = _.min(nums);
+ max = _.max(nums);
+ } else {
min = this.domain[0];
- }
- if (this.domain !== null && this.domain[1] !== null) {
max = this.domain[1];
}
return {
@@ -292,7 +327,7 @@ define(["chroma", "underscore", "util"], function (chroma, _, util) {
// Create SVG describing the gradient: basically, we sample the color
// map along the domain 101 times, and use these 101 colors to define
- // the for each integer percentage in the inclusve
+ // the for each integer percentage in the inclusive
// range [0%, 100%]. See https://github.com/biocore/emperor/issues/788.
var mid = (min + max) / 2;
var stopColors = interpolator.colors(101);
diff --git a/empress/support_files/js/empress.js b/empress/support_files/js/empress.js
index 23f3a7678..b4377dce3 100644
--- a/empress/support_files/js/empress.js
+++ b/empress/support_files/js/empress.js
@@ -1924,15 +1924,13 @@ define([
this._featureMetadataColumns,
layer.colorByFMField
);
- // We pass the true/false value of the "Continuous values?"
- // checkbox to Colorer regardless of if the selected color map
- // is discrete or sequential/diverging. This is because the Colorer
- // class constructor is smart enough to ignore useQuantScale = true
- // if the color map is discrete in the first place. (This is tested
- // in the Colorer tests; ctrl-F for "CVALDISCRETETEST" in
- // tests/test-colorer.js to see this.)
- var domain = null;
+ // Prepare for having to throw an error at some point, maybe...
var msg = "Layer " + layer.num + ": ";
+
+ // Has the user requested a custom domain for a gradient colormap?
+ // (If not, we'll leave domain as null when we create a Colorer
+ // object later, and it'll handle things normally.)
+ var domain = null;
if (
layer.colorByFMContinuous &&
layer.colorByFMContinuousManualScale
@@ -1976,6 +1974,14 @@ define([
domain = [min, max];
}
try {
+ // We pass the true/false value of the "Continuous values?"
+ // checkbox to Colorer regardless of if the selected color map
+ // is discrete or sequential/diverging. This is because the
+ // Colorer class constructor is smart enough to ignore
+ // useQuantScale = true if the color map is discrete in the
+ // first place. (This is tested in the Colorer tests; ctrl-F
+ // for "CVALDISCRETETEST" in tests/test-colorer.js to see
+ // this.)
colorer = new Colorer(
layer.colorByFMColorMap,
sortedUniqueColorValues,
diff --git a/tests/test-colorer.js b/tests/test-colorer.js
index 112d0adc9..85a08dfb0 100644
--- a/tests/test-colorer.js
+++ b/tests/test-colorer.js
@@ -656,5 +656,70 @@ require([
var colorer = new Colorer(colormap, eles, true);
}, /Quantitative scales are not supported for custom colormaps/);
});
+ test("Test custom domains with a valid domain", function () {
+ var colorer = new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [-2.5, 2.5]);
+ hexmap = colorer.getMapHex();
+ equal(_.keys(hexmap).length, 5);
+ // Expected colors determined by trying
+ // chroma.scale(chroma.brewer.RdBu).domain([-2.5, 2.5])(n);
+ equal(hexmap["-2"], "#b2182b");
+ equal(hexmap["-1"], "#f4a582");
+ equal(hexmap["0"], "#f7f7f7");
+ equal(hexmap["1"], "#92c5de");
+ equal(hexmap["2.5"], "#053061");
+ });
+ test("Test custom domains that don't overlap values", function() {
+ // Silly thing that is technically allowed: the custom domain can
+ // not overlap at all with the values. in that case, the values
+ // will all either be equal to the lowest color (if the custom
+ // domain is higher than them) or equal to the highest color (if
+ // the custom domain is lower than them).
+ strVals = ["-2", "-1", "0", "1", "2.5"];
+
+ // Case 1: all the values are lower than the custom domain
+ var colorer = new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [5, 10]);
+ hexmap = colorer.getMapHex();
+ equal(_.keys(hexmap).length, 5);
+ for (i = 0; i < strVals.length; i++) {
+ equal(hexmap[strVals[i]], "#b2182b");
+ }
+
+ // Case 2: all the values are higher than the custom domain
+ colorer = new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [-101, -100]);
+ hexmap = colorer.getMapHex();
+ equal(_.keys(hexmap).length, 5);
+ for (i = 0; i < strVals.length; i++) {
+ equal(hexmap[strVals[i]], "#053061");
+ }
+ });
+ test("Test custom domains with invalid domains", function () {
+ throws(function () {
+ new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [1]);
+ }, /Custom domain must have exactly 2 entries/);
+ throws(function () {
+ new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, []);
+ }, /Custom domain must have exactly 2 entries/);
+ throws(function () {
+ new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [1,2,3]);
+ }, /Custom domain must have exactly 2 entries/);
+ throws(function () {
+ new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [NaN,2]);
+ }, /Custom domain entries must be finite nums/);
+ throws(function () {
+ new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [1,NaN]);
+ }, /Custom domain entries must be finite nums/);
+ throws(function () {
+ new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [null, null]);
+ }, /Custom domain entries must be finite nums/);
+ throws(function () {
+ new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [null, 3]);
+ }, /Custom domain entries must be finite nums/);
+ throws(function () {
+ new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [3, 1]);
+ }, /Custom domain min must be < max/);
+ throws(function () {
+ new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [1, 1]);
+ }, /Custom domain min must be < max/);
+ });
});
});
From f89b0fd1eb950f222efb88a865ce2f9a15a43c33 Mon Sep 17 00:00:00 2001
From: Marcus Fedarko
Date: Fri, 20 May 2022 00:56:21 -0700
Subject: [PATCH 16/17] BUG: fix the side panel handler being broken w/ fm
Still seems slightly off. The update button doesn't show up sometimes.
---
empress/support_files/js/side-panel-handler.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/empress/support_files/js/side-panel-handler.js b/empress/support_files/js/side-panel-handler.js
index 1cebafc18..a57ade1fb 100644
--- a/empress/support_files/js/side-panel-handler.js
+++ b/empress/support_files/js/side-panel-handler.js
@@ -356,7 +356,7 @@ define(["underscore", "Colorer", "ColorOptionsHandler", "util"], function (
var colBy = this.fSel.value;
var coloringMethod = this.fMethodChk.checked ? "tip" : "all";
var colorOptions = this.fColorOptions.getOptions();
- this.empress.colorByFeatureMetadata(
+ var keyInfo = this.empress.colorByFeatureMetadata(
colBy,
colorOptions.color,
coloringMethod,
From 27999287a34aea20cc7eba43529008c5b5645ec2 Mon Sep 17 00:00:00 2001
From: Marcus Fedarko
Date: Fri, 20 May 2022 01:09:19 -0700
Subject: [PATCH 17/17] STY/TST: prettify; fix a test
was using the wrong lower limit, b/c for the other test the lowest
color in the values wasn't the absolutely lowest color of the
color map (-2.5 vs. -2). silly!
---
empress/support_files/js/colorer.js | 6 +--
tests/test-colorer.js | 57 ++++++++++++++++++++++-------
2 files changed, 46 insertions(+), 17 deletions(-)
diff --git a/empress/support_files/js/colorer.js b/empress/support_files/js/colorer.js
index e3d6dc018..ee90b4c71 100644
--- a/empress/support_files/js/colorer.js
+++ b/empress/support_files/js/colorer.js
@@ -97,16 +97,14 @@ define(["chroma", "underscore", "util"], function (chroma, _, util) {
// ColorOptionsHandler, so this is just verifying that the code
// hasn't become haunted.
if (this.domain.length !== 2) {
- throw new Error(
- "Custom domain must have exactly 2 entries"
- );
+ throw new Error("Custom domain must have exactly 2 entries");
}
if (!_.isFinite(this.domain[0]) || !_.isFinite(this.domain[1])) {
throw new Error("Custom domain entries must be finite nums");
}
// I think chroma can actually handle this case -- it'll just
// flip the numbers. But let's not rely on that.
- if(this.domain[0] >= this.domain[1]) {
+ if (this.domain[0] >= this.domain[1]) {
throw new Error("Custom domain min must be < max");
}
}
diff --git a/tests/test-colorer.js b/tests/test-colorer.js
index 85a08dfb0..29e3f2c66 100644
--- a/tests/test-colorer.js
+++ b/tests/test-colorer.js
@@ -657,7 +657,14 @@ require([
}, /Quantitative scales are not supported for custom colormaps/);
});
test("Test custom domains with a valid domain", function () {
- var colorer = new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [-2.5, 2.5]);
+ var colorer = new Colorer(
+ "RdBu",
+ [-2, -1, 0, 1, 2.5],
+ true,
+ 0,
+ false,
+ [-2.5, 2.5]
+ );
hexmap = colorer.getMapHex();
equal(_.keys(hexmap).length, 5);
// Expected colors determined by trying
@@ -668,24 +675,26 @@ require([
equal(hexmap["1"], "#92c5de");
equal(hexmap["2.5"], "#053061");
});
- test("Test custom domains that don't overlap values", function() {
+ test("Test custom domains that don't overlap values", function () {
// Silly thing that is technically allowed: the custom domain can
// not overlap at all with the values. in that case, the values
// will all either be equal to the lowest color (if the custom
// domain is higher than them) or equal to the highest color (if
// the custom domain is lower than them).
- strVals = ["-2", "-1", "0", "1", "2.5"];
+ var strVals = ["-2", "-1", "0", "1", "2.5"];
+ var numVals = [-2, -1, 0, 1, 2.5];
// Case 1: all the values are lower than the custom domain
- var colorer = new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [5, 10]);
+ var colorer = new Colorer("RdBu", numVals, true, 0, false, [5, 10]);
+ console.log(colorer);
hexmap = colorer.getMapHex();
equal(_.keys(hexmap).length, 5);
for (i = 0; i < strVals.length; i++) {
- equal(hexmap[strVals[i]], "#b2182b");
+ equal(hexmap[strVals[i]], "#67001f");
}
// Case 2: all the values are higher than the custom domain
- colorer = new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [-101, -100]);
+ colorer = new Colorer("RdBu", numVals, true, 0, false, [-10, -5]);
hexmap = colorer.getMapHex();
equal(_.keys(hexmap).length, 5);
for (i = 0; i < strVals.length; i++) {
@@ -700,25 +709,47 @@ require([
new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, []);
}, /Custom domain must have exactly 2 entries/);
throws(function () {
- new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [1,2,3]);
+ new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [
+ 1,
+ 2,
+ 3,
+ ]);
}, /Custom domain must have exactly 2 entries/);
throws(function () {
- new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [NaN,2]);
+ new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [
+ NaN,
+ 2,
+ ]);
}, /Custom domain entries must be finite nums/);
throws(function () {
- new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [1,NaN]);
+ new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [
+ 1,
+ NaN,
+ ]);
}, /Custom domain entries must be finite nums/);
throws(function () {
- new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [null, null]);
+ new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [
+ null,
+ null,
+ ]);
}, /Custom domain entries must be finite nums/);
throws(function () {
- new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [null, 3]);
+ new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [
+ null,
+ 3,
+ ]);
}, /Custom domain entries must be finite nums/);
throws(function () {
- new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [3, 1]);
+ new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [
+ 3,
+ 1,
+ ]);
}, /Custom domain min must be < max/);
throws(function () {
- new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [1, 1]);
+ new Colorer("RdBu", [-2, -1, 0, 1, 2.5], true, 0, false, [
+ 1,
+ 1,
+ ]);
}, /Custom domain min must be < max/);
});
});