Skip to content

Commit

Permalink
ENH: Scale barplot lengths by max displacement
Browse files Browse the repository at this point in the history
Relevant to biocore#276. The reliance on max displacement (which doesn't
seem to have an analogue in the unrooted layout? or maybe we can sort
of treat it the same way as circ layout, idk) means that this might
be too specific a solution to apply to line width thicknesses, but
it should make using barplots a lot less painful
  • Loading branch information
fedarko committed Sep 21, 2020
1 parent 22e2ae7 commit 9a46963
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions empress/support_files/js/empress.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ define([
*/
this._maxDisplacement = null;

/**
* @type {Number}
* A multiple of this._maxDisplacement. This is used as the unit for
* barplot lengths.
* @private
*/
this._barplotUnit = null;

/**
* @type{Boolean}
* Indicates whether or not barplots are currently drawn.
Expand Down Expand Up @@ -1390,10 +1398,13 @@ define([
Empress.prototype._computeMaxDisplacement = function () {
var maxD = -Infinity;
var compFunc;
var layoutFactor;
if (this._currentLayout === "Rectangular") {
compFunc = "_getMaxOfXAndNumber";
layoutFactor = 1;
} else if (this._currentLayout === "Circular") {
compFunc = "_getMaxOfRadiusAndNumber";
layoutFactor = 2;
} else {
this._maxDisplacement = null;
return;
Expand All @@ -1404,6 +1415,7 @@ define([
}
}
this._maxDisplacement = maxD;
this._barplotUnit = (this._maxDisplacement / 1000) * layoutFactor;
};

/**
Expand Down Expand Up @@ -1442,7 +1454,7 @@ define([
// start drawing barplots, and the first barplot layer. This could be
// made into a barplot-panel-level configurable thing if desired.
// (Note that, as with barplot lengths, the units here are arbitrary.)
var maxD = this._maxDisplacement + 100;
var maxD = 1.1 * this._maxDisplacement;

// As we iterate through the layers, we'll store the "previous layer
// max D" as a separate variable. This will help us easily work with
Expand Down Expand Up @@ -1620,7 +1632,8 @@ define([
// present in at least one sample with that value.
if (!_.isUndefined(freq)) {
var sectionColor = sm2color[smVal];
var barSectionLen = layer.lengthSM * freq;
var barSectionLen =
layer.lengthSM * scope._barplotUnit * freq;
// Assign each unique sample metadata value a length
// proportional to its, well, proportion within the sample
// presence information for this tip.
Expand Down Expand Up @@ -1842,7 +1855,7 @@ define([
}

// Update maxD if needed
var thisLayerMaxD = prevLayerMaxD + length;
var thisLayerMaxD = prevLayerMaxD + length * this._barplotUnit;
if (thisLayerMaxD > maxD) {
maxD = thisLayerMaxD;
}
Expand Down

0 comments on commit 9a46963

Please sign in to comment.