Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shear UI #505

Merged
merged 75 commits into from
Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
cbf4060
bp shear
kwcantrell Mar 1, 2021
227ec29
style fix
kwcantrell Mar 1, 2021
66c2e56
checkpoint
kwcantrell Mar 6, 2021
1183aa7
checkpoint
kwcantrell Mar 9, 2021
eafbea3
Finished TreeController
kwcantrell Mar 10, 2021
7301e82
tree-controller
kwcantrell Mar 17, 2021
888cf72
merged with master
kwcantrell Mar 17, 2021
f4f668f
fix doc issue
kwcantrell Mar 17, 2021
a408326
style fix
kwcantrell Mar 17, 2021
b043826
Apply suggestions from code review
kwcantrell Mar 19, 2021
caa916e
Merge branch 'master' of https://github.com/biocore/empress into tree…
kwcantrell Mar 19, 2021
f598928
fix style
kwcantrell Mar 19, 2021
5ca5809
addressed comments
kwcantrell Mar 23, 2021
89a4326
removed shear
kwcantrell Mar 23, 2021
654df69
start ui
kwcantrell Mar 24, 2021
d6aa515
finished basic shear ui
kwcantrell Mar 25, 2021
de01d93
fixed test issue
kwcantrell Mar 25, 2021
fcb6b5b
removed old comments
kwcantrell Mar 25, 2021
55f6f7e
merged master
kwcantrell Mar 25, 2021
b3acbd1
Apply suggestions from code review
kwcantrell Mar 30, 2021
263dd6a
started addressing PR suggestions
kwcantrell Mar 30, 2021
5bb8729
Merge branch 'shear-ui' of https://github.com/kwcantrell/empress into…
kwcantrell Mar 30, 2021
68d0d63
fixed style
kwcantrell Mar 30, 2021
603bf97
still addressing comments
kwcantrell Apr 1, 2021
31b5af3
fixed style
kwcantrell Apr 1, 2021
7f56e68
fix unselect all
kwcantrell Apr 1, 2021
9a9bb75
Fixed unselect all for circ layout
kwcantrell Apr 1, 2021
9dc26bc
fixed issue were tree disappears if all tips sheared
kwcantrell Apr 1, 2021
4445ebd
check point
kwcantrell Apr 1, 2021
15f81ab
fixed clade collapse
kwcantrell Apr 1, 2021
4630689
fixed style
kwcantrell Apr 1, 2021
73892fd
fixed test
kwcantrell Apr 1, 2021
3ca595e
fixed no biom error
kwcantrell Apr 2, 2021
66e5ded
checkpoint
kwcantrell Apr 6, 2021
9eb4243
performance improvemens
kwcantrell Apr 7, 2021
e3d128f
merged master
kwcantrell Apr 8, 2021
4b4d8e3
finished documenting
kwcantrell Apr 9, 2021
3d05f17
style fix
kwcantrell Apr 9, 2021
d909e83
added warning to shear
kwcantrell Apr 9, 2021
3b6d854
Major performance increase!
kwcantrell Apr 11, 2021
0803dc0
Apply suggestions from code review
kwcantrell Apr 12, 2021
cc754e9
fix style
kwcantrell Apr 12, 2021
3a2eede
Add warning message to shear panel
kwcantrell Apr 13, 2021
95392a5
starting addressing @fedarko's comments
kwcantrell May 4, 2021
45e2d49
addressed @fedarko's comments
kwcantrell May 4, 2021
3570a19
Merge branch 'master' of https://github.com/biocore/empress into shea…
kwcantrell May 4, 2021
e78ecd1
fix test
kwcantrell May 4, 2021
c95adf8
Apply suggestions from code review
kwcantrell May 17, 2021
af71569
added more @fedarko's suggestions + stle fix
kwcantrell May 17, 2021
35a2aa9
Merge branch 'master' of https://github.com/biocore/empress into shea…
kwcantrell May 28, 2021
928a2ce
address @fedarko's PR comments
kwcantrell May 28, 2021
6d4571a
Merge branch 'master' of https://github.com/biocore/empress into shea…
kwcantrell Jun 6, 2021
6074e5d
fixed collapse issue
kwcantrell Jun 10, 2021
0b081ca
Merge branch 'master' of https://github.com/biocore/empress into shea…
kwcantrell Jun 10, 2021
0bd1160
Apply suggestions from code review
kwcantrell Jun 10, 2021
d3c2a61
fixed callback for emperor selections
kwcantrell Jun 10, 2021
ac544fb
fixed style
kwcantrell Jun 10, 2021
55ca475
modified node circle text
kwcantrell Jun 10, 2021
aedb860
merged with master
kwcantrell Jun 11, 2021
90571be
disabled tabs during animation
kwcantrell Jun 11, 2021
149ecb5
fixed tests/lint issues
kwcantrell Jun 11, 2021
288a140
Apply suggestions from code review
kwcantrell Jun 29, 2021
7faa70a
modified message
kwcantrell Jun 29, 2021
cb085ba
addressed comments
kwcantrell Jun 29, 2021
8af9b93
fixed python test
kwcantrell Jun 29, 2021
c0fbd57
Merge branch 'master' of https://github.com/biocore/empress into pr50…
fedarko Jul 17, 2021
0505705
Remove extra " in side panel disabled message
fedarko Jul 17, 2021
924b938
rm another extra "
fedarko Jul 17, 2021
0bae2ce
space after "
fedarko Jul 17, 2021
953abd8
fix problem i introduced in the last commit ._.
fedarko Jul 17, 2021
8767132
MNT: RM \t chars, make e-d-*.js docs consistent
fedarko Jul 17, 2021
01d7022
DOC: Adjust tab-disabled prefix using isEmpirePlot
fedarko Jul 17, 2021
c57a5d2
DOC: Make uses of bold fonts consistent
fedarko Jul 17, 2021
00b7dee
STY: prettify
fedarko Jul 17, 2021
b664bfd
Cleaner toast msg for no-FM-b/c-shearing case
fedarko Jul 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 38 additions & 14 deletions empress/support_files/js/emperor-callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,12 @@ plotView.on("click", function (name, object) {
});

plotView.on("select", function (samples, view) {
// remove any strangling observers
kwcantrell marked this conversation as resolved.
Show resolved Hide resolved
shearer.unregisterObserver("emperor-select");

// cancel any ongoing timers
clearTimeout(empress.timer);

// if there's any coloring setup remove it, and re-enable the update button
sPanel.sUpdateBtn.classList.remove("hidden");
sPanel.fUpdateBtn.classList.remove("hidden");
empress.clearLegend();
empress.resetTree();

// fetch a mapping of colors to plottable objects
var groups = view.groupByColor(samples);
var namesOnly = {};
Expand All @@ -83,9 +80,23 @@ plotView.on("select", function (samples, view) {
return item.name;
});
}
empress.colorSampleGroups(namesOnly);

var colorEmpress = () => {
// if there's any coloring setup remove it, and re-enable the update button
sPanel.sUpdateBtn.classList.remove("hidden");
sPanel.fUpdateBtn.classList.remove("hidden");
empress.clearLegend();
empress.resetTree();
empress.colorSampleGroups(namesOnly);
};
colorEmpress();
kwcantrell marked this conversation as resolved.
Show resolved Hide resolved

// 4 seconds before resetting
var shearObs = {
shearerObserverName: "emperor-select",
shearUpdate: colorEmpress,
};
shearer.registerObserver(shearObs);
empress.timer = setTimeout(function () {
empress.resetTree();
empress.drawTree();
Expand All @@ -95,6 +106,7 @@ plotView.on("select", function (samples, view) {
}

plotView.needsUpdate = true;
shearer.unregisterObserver("emperor-select");
}, 4000);
});

Expand Down Expand Up @@ -164,6 +176,9 @@ ec.controllers.animations.addEventListener("animation-ended", function (
ec.controllers.color.addEventListener("value-double-clicked", function (
payload
) {
// remove any strangling observers
kwcantrell marked this conversation as resolved.
Show resolved Hide resolved
shearer.unregisterObserver("emperor-value-double-clicked");

// when dealing with a biplot ignore arrow-emitted events
if (payload.target.decompositionName() !== "scatter") {
return;
Expand All @@ -177,24 +192,33 @@ ec.controllers.color.addEventListener("value-double-clicked", function (
ec.decViews.scatter.setEmissive(0x000000);
plotView.needsUpdate = true;

// if there's any coloring setup remove it, and re-enable the update button
sPanel.sUpdateBtn.classList.remove("hidden");
sPanel.fUpdateBtn.classList.remove("hidden");
empress.clearLegend();
empress.resetTree();

var names = _.map(payload.message.group, function (item) {
return item.name;
});
var container = {};
container[payload.message.attribute] = names;
empress.colorSampleGroups(container);

var colorEmpress = () => {
// if there's any coloring setup remove it, and re-enable the update button
sPanel.sUpdateBtn.classList.remove("hidden");
sPanel.fUpdateBtn.classList.remove("hidden");
empress.clearLegend();
empress.resetTree();
empress.colorSampleGroups(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);
});
10 changes: 2 additions & 8 deletions empress/support_files/js/empress.js
Original file line number Diff line number Diff line change
Expand Up @@ -2656,19 +2656,13 @@ define([
this.setNodeInfo(node, "isColored", false);
this.setNodeInfo(node, "visible", true);
}
this._collapsedClades = {};
this._dontCollapse = new Set();
this._collapsedCladeBuffer = [];
this._drawer.loadThickNodeBuff([]);
this._drawer.loadCladeBuff([]);
this._group = new Array(this._tree.size + 1).fill(-1);

// if _collapsedClades is empty then there is no need to call
// getTreeCoords which can save a fair amount of time depending on the
// size of the tree
if (Object.keys(this._collapsedClades).length > 0) {
this._drawer.loadTreeCoordsBuff(this.getTreeCoords());
}
this._collapsedClades = {};
this._drawer.loadTreeCoordsBuff(this.getTreeCoords());
};

/**
Expand Down
52 changes: 49 additions & 3 deletions empress/support_files/js/shearer.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,34 @@ define(["underscore", "util", "TreeController"], function (
* the model is updated. Note this object must implement a shearUpdate()
* method.
*
* @param{Object} obs The object to register.
* @param{Object} obs The object to register. A '.shearerObserverName'
* property must be provided if this observer will at
* some point be unregistered.
*/
ShearModel.prototype.registerObserver = function (obs) {
this.observers.push(obs);
};

/**
* Unregisters an observer to the model. The method will remove all
* observers with a '.shearerObserverName' === to removeObsName.
*
* @param{String} removeObsName The name of the observer to unregister.
*/
ShearModel.prototype.unregisterObserver = function (removeObsName) {
var removeIndx;
var tempObs = [];
_.each(this.observers, function (obs, indx) {
if (
!obs.hasOwnProperty("shearerObserverName") ||
obs.shearerObserverName !== removeObsName
) {
tempObs.push(obs);
}
});
this.observers = tempObs;
};

/**
* Removes a shear layer from a ShearModel
* @param{ShearModel} model The ShearModel to use
Expand Down Expand Up @@ -354,12 +376,24 @@ define(["underscore", "util", "TreeController"], function (
/**
* Registers an observer to the model.
*
* @param{Object} obs The object to register to the model
* @param{Object} obs The object to register to the model. A
* '.shearerObserverName' property must be provided if
* this observer will at some point be unregistered.
*/
ShearController.prototype.registerObserver = function (obs) {
this.model.registerObserver(obs);
};

/**
* Unregisters an observer to the model. The method will remove all
* observers with a '.shearerObserverName' === to removeObsName.
*
* @param{String} removeObsName The name of the observer to unregister.
*/
ShearController.prototype.unregisterObserver = function (removeObsName) {
this.model.unregisterObserver(removeObsName);
};

/**
* @class Shearer
*
Expand Down Expand Up @@ -421,11 +455,23 @@ define(["underscore", "util", "TreeController"], function (
/**
* Registers an observer to the model.
*
* @param{Object} obs The object to register to the model
* @param{Object} obs The object to register to the model. A
* '.shearerObserverName' property must be provided if
* this observer will at some point be unregistered.
*/
Shearer.prototype.registerObserver = function (obs) {
this.controller.registerObserver(obs);
};

/**
* Unregisters an observer to the model. The method will remove all
* observers with a '.shearerObserverName' === to removeObsName.
*
* @param{String} removeObsName The name of the observer to unregister.
*/
Shearer.prototype.unregisterObserver = function (removeObsName) {
this.controller.unregisterObserver(removeObsName);
};

return Shearer;
});
8 changes: 5 additions & 3 deletions empress/support_files/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,12 @@ define(["underscore"], function (_) {
}

/**
* Removes all keys from a if that same key is found in b and contains an
* empty array.
* Given two Objects that map keys to arrays, removes all keys from object
* "a" that are present in object "b" and point to a zero-length array in
* "b".
*
* @param{Object} obj The object to remove keys from
* @param {Object} a The object from which keys will be removed.
* @param {Object} b The object used as a guide to remove keys from a.
*/
function removeEmptyArrayKeys(a, b) {
for (var key in b) {
Expand Down
12 changes: 11 additions & 1 deletion empress/support_files/templates/side-panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@
(specified by the trajectory) at different timepoints throughout a
gradient.
</p>
<p class="side-panel-notes">
<b>Warning:</b> Do not shear the tree while an animation is running. Please
stop and restart if the tree was sheared during an animation.
</p>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this -- looks good!

If we are going to completely say that the user shouldn't do shearing during an animation, I think it might make sense to just explicitly prevent this -- I assume this warning would also apply to synchronized animations that Emperor starts?

Maybe we could have the Animator class update the Empress class somehow (so that the Empress class always has knowledge of if an animation is ongoing), and then ShearModel could use that knowledge to only apply shearing changes when an animation isn't ongoing. Or, IDK, you would know best how to do that :)

...We don't have to do this before merging, tho -- I recognize that this PR has been waiting for a while, so I'm ok if we want to get this in and then take care of preventing this case later.

<p>
<label for="animate-color-select">Color Map</label>
<label class="select-container">
Expand Down Expand Up @@ -428,7 +432,9 @@
</p>
<p class="needs-feature-metadata side-panel-notes">
These statistics will be automatically updated as the tree is sheared
using the "Shear Tree" functionality.
using the "Shear Tree" functionality. Note that, in the rare case when
the tree is sheared to only contain the root node, the root node will
be counted as a tip instead of an internal node.
</p>
<p class="needs-metadata side-panel-notes">
Note that these statistics only pertain to the tree shown here,
Expand Down Expand Up @@ -465,6 +471,10 @@
</p>
<p class="side-panel-notes indented">
Controls behavior of when to draw circles at nodes' positions.
Note that, in the rare case when the tree is sheared to only
contain the root node, a circle will nonetheless always be
drawn for it to serve as a visual marker (unless "Hide all node
circles" is selected).
</p>
<hr />
<p class="side-panel-inner-header">
Expand Down