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

Global tree properties #212

Merged
merged 9 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
Binary file modified docs/moving-pictures/empress-tree-tandem.qzv
Binary file not shown.
Binary file modified docs/moving-pictures/empress-tree.qzv
Binary file not shown.
35 changes: 9 additions & 26 deletions empress/support_files/js/canvas-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,46 +349,29 @@ define(["glMatrix", "SelectedNodeMenu"], function (gl, SelectedNodeMenu) {
nodeId,
moveTree = true
) {
var empress = this.empress;
var selectedNodeMenu = this.selectedNodeMenu;
var drawer = this.drawer;

// multiple nodes can have the same name
var idList = empress._nameToKeys[nodeId];
var idList = this.empress._nameToKeys[nodeId];

if (idList !== undefined) {
// get first node
var node = empress._treeData[idList[0]];
var node = this.empress._treeData[idList[0]];

if (idList.length > 1) {
node = empress._treeData[empress._tree.size - 1];
node = this.empress._treeData[this.empress._tree.size - 1];
}

if (moveTree) {
// create matrix to translate node to center of screen
var center = gl.vec3.fromValues(
drawer.treeSpaceCenterX,
drawer.treeSpaceCenterY,
1
);
var centerMat = gl.mat4.create();
gl.mat4.fromTranslation(centerMat, center);

var nodePos = gl.vec3.fromValues(
-1 * empress.getX(node),
-1 * empress.getY(node),
1
this.drawer.centerCameraOn(
this.empress.getX(node),
this.empress.getY(node)
);
var worldMat = gl.mat4.create();
gl.mat4.fromTranslation(drawer.worldMat, nodePos);
gl.mat4.multiply(drawer.worldMat, drawer.worldMat, centerMat);
}

// show menu
selectedNodeMenu.setSelectedNodes(idList);
selectedNodeMenu.showNodeMenu();
this.selectedNodeMenu.setSelectedNodes(idList);
this.selectedNodeMenu.showNodeMenu();

empress.drawTree();
this.empress.drawTree();
} else {
this.quickSearchBar.classList.add("invalid-search");
}
Expand Down
56 changes: 49 additions & 7 deletions empress/support_files/js/drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ define(["glMatrix", "Camera"], function (gl, Camera) {

// the dimension of the canvas
this.dim = null;

this.showTreeNodes = true;
}

/**
Expand Down Expand Up @@ -131,6 +133,7 @@ define(["glMatrix", "Camera"], function (gl, Camera) {
this.cam.placeCamera([0, 0, this.dim / 2], [0, 0, 0], [0, 1, 0]);

this._findViewingCenter();
this.centerCameraOn(0, 0);
};

/**
Expand Down Expand Up @@ -286,6 +289,18 @@ define(["glMatrix", "Camera"], function (gl, Camera) {
this.fillBufferData_(this.sProg_.nodeVertBuff, data);
};

/**
* Display the tree nodes.
kwcantrell marked this conversation as resolved.
Show resolved Hide resolved
* Note: Currently Empress will only display the nodes that had an assigned
* name in the newick string. (I.E. Empress will not show any node that
* starts with EmpressNode)
*
* @param{Boolean} showTreeNodes If true the empress with display the tree
* nodes.
*/
Drawer.prototype.setTreeNodeVisibility = function (showTreeNodes) {
this.showTreeNodes = showTreeNodes;
};
/**
* Draws tree and other metadata
*/
Expand All @@ -306,10 +321,12 @@ define(["glMatrix", "Camera"], function (gl, Camera) {
c.uniformMatrix4fv(s.mvpMat, false, mvp);

// draw tree nodes
kwcantrell marked this conversation as resolved.
Show resolved Hide resolved
c.uniform1i(s.isSingle, 1);
c.uniform1f(s.pointSize, 4.0);
this.bindBuffer(s.nodeVertBuff);
c.drawArrays(c.POINTS, 0, this.nodeSize);
if (this.showTreeNodes) {
c.uniform1i(s.isSingle, 1);
c.uniform1f(s.pointSize, 4.0);
this.bindBuffer(s.nodeVertBuff);
c.drawArrays(c.POINTS, 0, this.nodeSize);
}
fedarko marked this conversation as resolved.
Show resolved Hide resolved

// draw selected node
c.uniform1f(s.pointSize, 9.0);
Expand Down Expand Up @@ -380,12 +397,37 @@ define(["glMatrix", "Camera"], function (gl, Camera) {
* @private
*/
Drawer.prototype._findViewingCenter = function () {
var width = this.treeContainer.offsetWidth;
var height = this.treeContainer.offsetHeight;
var center = this.toTreeCoords(width / 2, height / 2);
var width = this.treeContainer.offsetWidth,
height = this.treeContainer.offsetHeight,
center = this.toTreeCoords(width / 2, height / 2);
this.treeSpaceCenterX = center.x;
this.treeSpaceCenterY = center.y;
};

/**
* Makes the point (x, y) appear in the center of the viewing window. (I.E
* center of screen)
kwcantrell marked this conversation as resolved.
Show resolved Hide resolved
*
* @param{Number} x The x position
* @param{Number} y The y position
*/
Drawer.prototype.centerCameraOn = function (x, y) {
// create matrix to translate node to center of screen
var center = gl.vec3.fromValues(
this.treeSpaceCenterX,
this.treeSpaceCenterY,
0
);

var centerMat = gl.mat4.create();
gl.mat4.fromTranslation(centerMat, center);

var nodePos = gl.vec3.fromValues(-1 * x, -1 * y, 0);
kwcantrell marked this conversation as resolved.
Show resolved Hide resolved

var worldMat = gl.mat4.create();
gl.mat4.fromTranslation(worldMat, nodePos);
gl.mat4.multiply(this.worldMat, centerMat, worldMat);
};

return Drawer;
});
13 changes: 13 additions & 0 deletions empress/support_files/js/empress.js
Original file line number Diff line number Diff line change
Expand Up @@ -1092,5 +1092,18 @@ define([
return this._featureMetadataColumns;
};

/**
* Display the tree nodes.
* Note: Currently Empress will only display the nodes that had an assigned
* name in the newick string. (I.E. Empress will not show any node that
* starts with EmpressNode)
fedarko marked this conversation as resolved.
Show resolved Hide resolved
*
* @param{Boolean} showTreeNodes If true the empress with display the tree
kwcantrell marked this conversation as resolved.
Show resolved Hide resolved
* nodes.
*/
Empress.prototype.setTreeNodeVisibility = function (showTreeNodes) {
this._drawer.setTreeNodeVisibility(showTreeNodes);
};

return Empress;
});
1 change: 1 addition & 0 deletions empress/support_files/js/select-node-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ define(["underscore", "util"], function (_, util) {
this.fmTable.classList.add("hidden");
this.fmTable.innerHTML = "";
this.drawer.loadSelectedNodeBuff([]);
this.empress.drawTree();
fedarko marked this conversation as resolved.
Show resolved Hide resolved
};

/**
Expand Down
23 changes: 23 additions & 0 deletions empress/support_files/js/side-panel-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ define(["underscore", "Colorer"], function (_, Colorer) {

this.legend = legend;

// tree properties components
this.treeNodesChk = document.getElementById("display-nodes-chk");
this.recenterBtn = document.getElementById("center-tree-btn");

// sample GUI components
this.sChk = document.getElementById("sample-chk");
this.sSel = document.getElementById("sample-options");
Expand Down Expand Up @@ -346,6 +350,25 @@ define(["underscore", "Colorer"], function (_, Colorer) {
};
};

/**
* Add the callback events for the global tree properties tab. The callback
* events include things like centering the tree and showing tree nodes.
*
* Other things such as changing the defualt color of the tree will be
* added.
*/
SidePanel.prototype.addTreePropertiesTab = function () {
var scope = this;
this.treeNodesChk.onchange = function () {
scope.empress.setTreeNodeVisibility(scope.treeNodesChk.checked);
scope.empress.drawTree();
};
this.recenterBtn.onclick = function () {
scope.empress._drawer.centerCameraOn(0, 0);
scope.empress.drawTree();
};
fedarko marked this conversation as resolved.
Show resolved Hide resolved
};

SidePanel.prototype.updateFeatureMethodDesc = function () {
if (this.fMethodChk.checked) {
this.fMethodDesc.textContent =
Expand Down
5 changes: 3 additions & 2 deletions empress/support_files/templates/empress-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

<div>
<!-- The tree -->
<div id="tree-container" class="{{ emperor_classes }}">
<div class="container {{ emperor_classes }}">
<div class="{{ emperor_classes }}">
<div id="tree-container" class="container {{ emperor_classes }}">
<canvas class="tree-surface" id="tree-surface">
Your browser does not support HTML5
</canvas>
Expand Down Expand Up @@ -143,6 +143,7 @@ <h3 class="hidden" id="menu-sm-header">Sample Presence Information</h3>
// The side menu
var sPanel = new SidePanel(document.getElementById('side-panel'),
empress, legend);
sPanel.addTreePropertiesTab();
sPanel.addSampleTab();
if (fmCols.length > 0) {
sPanel.addFeatureTab();
Expand Down
19 changes: 19 additions & 0 deletions empress/support_files/templates/side-panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@
</p>
</div>

<!-- Global Tree properties -->
<button class="side-header collapsible">Tree Properties</button>
Copy link
Member

Choose a reason for hiding this comment

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

Can you move Tree Properties to the bottom of the side panel? i.e. after animations. Motivation is to keep the most frequently used things at the top (which I think might be a tie between sample and feature metadata).

<div class="side-content control hidden">
<p class="side-panel-notes">
If checked, this display node circles on all tree nodes that have a name
in the newick string that defined the tree.
kwcantrell marked this conversation as resolved.
Show resolved Hide resolved
</p>
<p>
<label for="display-nodes-chk">Show Node Circles</label>
kwcantrell marked this conversation as resolved.
Show resolved Hide resolved
<input id="display-nodes-chk" type="checkbox" checked="true">
</p>
<p class="side-panel-notes">
Make the root of the tree appear at the center of the screen.
kwcantrell marked this conversation as resolved.
Show resolved Hide resolved
</p>
<p>
<button id="center-tree-btn">Center Tree</button>
Copy link
Collaborator

Choose a reason for hiding this comment

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

The GUI is ok as is -- I think things are mostly self-explanatory -- but for my two cents, I'd suggest switching around the order of these two controls and their descriptions (putting the controls before their descriptions) and then applying the indented class to the description <p>s. Here's what this looks like on my end:

image

This 1) makes it clearer which descriptions map to which controls, and 2) makes these descriptions visually consistent with the "Only use tip-level metadata?" checkbox in the feature metadata section.

In general, I think this is the sort of situation where tooltips (#138) would be really useful (probably for later on, though... IMO there are more important things for us to address before taking the time to add those). Having tooltips set up would let us do things like just show a "Center Tree" button by itself, with a (?) or something next to it which would pop up this help text if people have further questions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, I'll adjust the order/description to be consistent with the others.

Copy link
Member

Choose a reason for hiding this comment

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

I think we need to be clearer:

Suggested change
<button id="center-tree-btn">Center Tree</button>
<button id="center-tree-btn">Reset Camera</button>

</p>
</div>

<!-- Sample Coloring Options -->
<button class="side-header collapsible">Sample Metadata Coloring</button>
<div class="side-content control hidden">
Expand Down