Skip to content

Commit 7321e43

Browse files
committed
🚧 split functionality out as 'focus'
Simply renaming this functionality and separating it from 'zoom' helped me understand the difference better. The separate buttons may be helpful too.
1 parent 1c0ad29 commit 7321e43

File tree

13 files changed

+78
-54
lines changed

13 files changed

+78
-54
lines changed

‎src/actions/recomputeReduxState.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ const modifyStateViaURLQuery = (state, query) => {
6464
if (query.m && state.branchLengthsToDisplay === "divAndDate") {
6565
state["distanceMeasure"] = query.m;
6666
}
67-
if (query.z) {
68-
state["treeZoom"] = query.z;
67+
if (query.focus) {
68+
state["treeFocus"] = query.focus;
6969
}
7070
if (query.c) {
7171
state["colorBy"] = query.c;

‎src/actions/types.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const SEARCH_INPUT_CHANGE = "SEARCH_INPUT_CHANGE";
77
export const CHANGE_LAYOUT = "CHANGE_LAYOUT";
88
export const CHANGE_BRANCH_LABEL = "CHANGE_BRANCH_LABEL";
99
export const CHANGE_DISTANCE_MEASURE = "CHANGE_DISTANCE_MEASURE";
10-
export const CHANGE_TREE_ZOOM = "CHANGE_TREE_ZOOM";
10+
export const CHANGE_TREE_FOCUS = "CHANGE_TREE_FOCUS";
1111
export const CHANGE_DATES_VISIBILITY_THICKNESS = "CHANGE_DATES_VISIBILITY_THICKNESS";
1212
export const CHANGE_ABSOLUTE_DATE_MIN = "CHANGE_ABSOLUTE_DATE_MIN";
1313
export const CHANGE_ABSOLUTE_DATE_MAX = "CHANGE_ABSOLUTE_DATE_MAX";

‎src/components/tree/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const Tree = connect((state) => ({
1515
temporalConfidence: state.controls.temporalConfidence,
1616
distanceMeasure: state.controls.distanceMeasure,
1717
explodeAttr: state.controls.explodeAttr,
18-
treeZoom: state.controls.treeZoom,
18+
treeFocus: state.controls.treeFocus,
1919
colorScale: state.controls.colorScale,
2020
colorings: state.metadata.colorings,
2121
genomeMap: state.entropy.genomeMap,

‎src/components/tree/phyloTree/change.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export const change = function change({
258258
/* change these things to provided value (unless undefined) */
259259
newDistance = undefined,
260260
newLayout = undefined,
261-
newTreeZoom = undefined,
261+
newTreeFocus = undefined,
262262
updateLayout = undefined, // todo - this seems identical to `newLayout`
263263
newBranchLabellingKey = undefined,
264264
showAllBranchLabels = undefined,
@@ -314,7 +314,7 @@ export const change = function change({
314314
svgPropsToUpdate.add("stroke-width");
315315
nodePropsToModify["stroke-width"] = branchThickness;
316316
}
317-
if (newDistance || newLayout || newTreeZoom || updateLayout || zoomIntoClade || svgHasChangedDimensions || changeNodeOrder) {
317+
if (newDistance || newLayout || newTreeFocus || updateLayout || zoomIntoClade || svgHasChangedDimensions || changeNodeOrder) {
318318
elemsToUpdate.add(".tip").add(".branch.S").add(".branch.T").add(".branch");
319319
elemsToUpdate.add(".vaccineCross").add(".vaccineDottedLine").add(".conf");
320320
elemsToUpdate.add('.branchLabel').add('.tipLabel');
@@ -360,10 +360,10 @@ export const change = function change({
360360
/* run calculations as needed - these update properties on the phylotreeNodes (similar to updateNodesWithNewData) */
361361
/* distance */
362362
if (newDistance || updateLayout) this.setDistance(newDistance);
363-
/* treeZoom */
364-
if (newTreeZoom || updateLayout) this.setTreeZoom(newTreeZoom);
365-
/* layout (must run after distance and treeZoom) */
366-
if (newDistance || newLayout || newTreeZoom || updateLayout || changeNodeOrder) {
363+
/* treeFocus */
364+
if (newTreeFocus || updateLayout) this.setTreeFocus(newTreeFocus);
365+
/* layout (must run after distance and treeFocus) */
366+
if (newDistance || newLayout || newTreeFocus || updateLayout || changeNodeOrder) {
367367
this.setLayout(newLayout || this.layout, scatterVariables);
368368
}
369369
/* show confidences - set this param which actually adds the svg paths for
@@ -380,7 +380,7 @@ export const change = function change({
380380
newDistance ||
381381
newLayout ||
382382
changeNodeOrder ||
383-
newTreeZoom ||
383+
newTreeFocus ||
384384
updateLayout ||
385385
zoomIntoClade ||
386386
svgHasChangedDimensions ||

‎src/components/tree/phyloTree/layouts.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ export const calcYValues = (nodes, spacing = "even") => {
301301
// console.log("calcYValues started with ", spacing);
302302
let total = 0; /* cumulative counter of y value at tip */
303303
let calcY; /* fn called calcY(node) to return some amount of y value at a tip */
304-
if (spacing.includes("zoom") && 'visibility' in nodes[0]) {
304+
if (spacing.includes("focus") && 'visibility' in nodes[0]) {
305305
const numberOfTips = nodes.length;
306306
const numTipsVisible = nodes.filter((d) => !d.hasChildren && d.visibility === NODE_VISIBLE).length;
307307
const yPerVisible = (0.8 * numberOfTips) / numTipsVisible;
@@ -334,19 +334,19 @@ export const calcYValues = (nodes, spacing = "even") => {
334334
};
335335

336336
/**
337-
* assigns the attribute this.treeZoom and calls the function that
338-
* recalculates yvalues based on treeZoom setting
339-
* @param treeZoom -- how to zoom nodes, eg ["even", "zoom"]
337+
* assigns the attribute this.treeFocus and calls the function that
338+
* recalculates yvalues based on treeFocus setting
339+
* @param treeFocus -- how to zoom nodes, eg ["even", "focus"]
340340
*/
341-
export const setTreeZoom = function setTreeZoom(treeZoom) {
342-
timerStart("setTreeZoom");
343-
if (typeof treeZoom === "undefined") {
344-
this.treeZoom = "even";
341+
export const setTreeFocus = function setTreeFocus(treeFocus) {
342+
timerStart("setTreeFocus");
343+
if (typeof treeFocus === "undefined") {
344+
this.treeFocus = "even";
345345
} else {
346-
this.treeZoom = treeZoom;
346+
this.treeFocus = treeFocus;
347347
}
348-
calcYValues(this.nodes, this.treeZoom);
349-
timerEnd("setTreeZoom");
348+
calcYValues(this.nodes, this.treeFocus);
349+
timerEnd("setTreeFocus");
350350
};
351351

352352
/**

‎src/components/tree/phyloTree/phyloTree.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ PhyloTree.prototype.updateColorBy = renderers.updateColorBy;
6363
/* C A L C U L A T E G E O M E T R I E S E T C ( M O D I F I E S N O D E S , N O T S V G ) */
6464
PhyloTree.prototype.setDistance = layouts.setDistance;
6565
PhyloTree.prototype.setLayout = layouts.setLayout;
66-
PhyloTree.prototype.setTreeZoom = layouts.setTreeZoom;
66+
PhyloTree.prototype.setTreeFocus = layouts.setTreeFocus;
6767
PhyloTree.prototype.rectangularLayout = layouts.rectangularLayout;
6868
PhyloTree.prototype.scatterplotLayout = layouts.scatterplotLayout;
6969
PhyloTree.prototype.unrootedLayout = layouts.unrootedLayout;

‎src/components/tree/phyloTree/renderers.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getEmphasizedColor } from "../../../util/colorHelpers";
77
* @param {d3 selection} svg -- the svg into which the tree is drawn
88
* @param {string} layout -- the layout to be used, e.g. "rect"
99
* @param {string} distance -- the property used as branch length, e.g. div or num_date
10-
* @param {string} treeZoom -- how to to treat spread of yValues, e.g. "even" or "zoom"
10+
* @param {string} treeFocus -- how to to treat spread of yValues, e.g. "even" or "focus"
1111
* @param {object} parameters -- an object that contains options that will be added to this.params
1212
* @param {object} callbacks -- an object with call back function defining mouse behavior
1313
* @param {array} branchThickness -- array of branch thicknesses (same ordering as tree nodes)
@@ -22,7 +22,7 @@ import { getEmphasizedColor } from "../../../util/colorHelpers";
2222
* @param {object} scatterVariables -- {x, y} properties to map nodes => scatterplot (only used if layout="scatter")
2323
* @return {null}
2424
*/
25-
export const render = function render(svg, layout, distance, treeZoom, parameters, callbacks, branchThickness, visibility, drawConfidence, vaccines, branchStroke, tipStroke, tipFill, tipRadii, dateRange, scatterVariables) {
25+
export const render = function render(svg, layout, distance, treeFocus, parameters, callbacks, branchThickness, visibility, drawConfidence, vaccines, branchStroke, tipStroke, tipFill, tipRadii, dateRange, scatterVariables) {
2626
timerStart("phyloTree render()");
2727
this.svg = svg;
2828
this.params = Object.assign(this.params, parameters);
@@ -43,7 +43,7 @@ export const render = function render(svg, layout, distance, treeZoom, parameter
4343
/* set x, y values & scale them to the screen */
4444
setDisplayOrder(this.nodes);
4545
this.setDistance(distance);
46-
this.setTreeZoom(treeZoom);
46+
this.setTreeFocus(treeFocus);
4747
this.setLayout(layout, scatterVariables);
4848
this.mapToScreen();
4949

‎src/components/tree/reactD3Interface/change.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ export const changePhyloTreeViaPropsComparison = (mainTree, phylotree, oldProps,
4949
args.changeNodeOrder = true;
5050
}
5151

52-
/* change treeZoom behavior */
53-
if (oldProps.treeZoom !== newProps.treeZoom) {
54-
args.newTreeZoom = newProps.treeZoom;
52+
/* change treeFocus behavior */
53+
if (oldProps.treeFocus !== newProps.treeFocus) {
54+
args.newTreeFocus = newProps.treeFocus;
5555
args.updateLayout = true;
5656
}
5757

‎src/components/tree/reactD3Interface/initialRender.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const renderTree = (that, main, phylotree, props) => {
2222
select(ref),
2323
props.layout,
2424
props.distanceMeasure,
25-
props.treeZoom,
25+
props.treeFocus,
2626
{ /* parameters (modifies PhyloTree's defaults) */
2727
grid: true,
2828
confidence: props.temporalConfidence.display,

‎src/components/tree/tree.js

+40-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22
import { withTranslation } from "react-i18next";
33
import { FaSearchMinus } from "react-icons/fa";
44
import { updateVisibleTipsAndBranchThicknesses } from "../../actions/tree";
5-
import { CHANGE_TREE_ZOOM } from "../../actions/types";
5+
import { CHANGE_TREE_FOCUS } from "../../actions/types";
66
import Card from "../framework/card";
77
import Legend from "./legend/legend";
88
import PhyloTree from "./phyloTree/phyloTree";
@@ -40,7 +40,7 @@ class Tree extends React.Component {
4040
this.clearSelectedNode = callbacks.clearSelectedNode.bind(this);
4141
// this.handleIconClickHOF = callbacks.handleIconClickHOF.bind(this);
4242
this.redrawTree = () => {
43-
this.props.dispatch({ type: CHANGE_TREE_ZOOM, data: "even" });
43+
this.props.dispatch({ type: CHANGE_TREE_FOCUS, data: "even" });
4444
this.props.dispatch(updateVisibleTipsAndBranchThicknesses({
4545
root: [0, 0]
4646
}));
@@ -112,9 +112,17 @@ class Tree extends React.Component {
112112
}
113113

114114
getStyles = () => {
115-
// FIXME: double-check this
116-
const activeResetTreeButton = true;
117-
const activeZoomButton = true;
115+
const activeResetTreeButton = this.props.tree.idxOfInViewRootNode !== 0 ||
116+
this.props.treeToo.idxOfInViewRootNode !== 0;
117+
118+
const filteredTree = !!this.props.tree.idxOfFilteredRoot &&
119+
this.props.tree.idxOfInViewRootNode !== this.props.tree.idxOfFilteredRoot;
120+
const filteredTreeToo = !!this.props.treeToo.idxOfFilteredRoot &&
121+
this.props.treeToo.idxOfInViewRootNode !== this.props.treeToo.idxOfFilteredRoot;
122+
const activeZoomButton = filteredTree || filteredTreeToo;
123+
124+
const activeFocusButton = true;
125+
118126
const treeIsZoomed = this.props.tree.idxOfInViewRootNode !== 0 ||
119127
this.props.treeToo.idxOfInViewRootNode !== 0;
120128

@@ -139,6 +147,13 @@ class Tree extends React.Component {
139147
color: activeZoomButton ? darkGrey : lightGrey,
140148
pointerEvents: activeZoomButton ? "auto" : "none"
141149
},
150+
focusOnSelectedButton: {
151+
zIndex: 100,
152+
display: "inline-block",
153+
cursor: activeFocusButton ? "pointer" : "auto",
154+
color: activeFocusButton ? darkGrey : lightGrey,
155+
pointerEvents: activeFocusButton ? "auto" : "none"
156+
},
142157
zoomOutButton: {
143158
zIndex: 100,
144159
display: "inline-block",
@@ -162,20 +177,23 @@ class Tree extends React.Component {
162177
);
163178
}
164179

165-
zoomToSelected = () => {
166-
// if currently set to "even", start at "zoom"
167-
let treeZoomData = "zoom";
168-
if (this.props.treeZoom.includes("zoom")) {
169-
// if currently at "zoom", increment to "zoom-2"
170-
if (!this.props.treeZoom.includes("-")) {
171-
treeZoomData = "zoom-2";
180+
focusOnSelected = () => {
181+
// if currently set to "even", start at "focus"
182+
let treeFocusData = "focus";
183+
if (this.props.treeFocus.includes("focus")) {
184+
// if currently at "focus", increment to "focus-2"
185+
if (!this.props.treeFocus.includes("-")) {
186+
treeFocusData = "focus-2";
172187
} else {
173-
// if currently at "zoom-2", increment to "zoom-3", etc...
174-
const increment = parseInt(this.props.treeZoom.split('-')[1], 10) + 1;
175-
treeZoomData = "zoom-" + increment.toString();
188+
// if currently at "focus-2", increment to "focus-3", etc...
189+
const increment = parseInt(this.props.treeFocus.split('-')[1], 10) + 1;
190+
treeFocusData = "focus-" + increment.toString();
176191
}
177192
}
178-
this.props.dispatch({ type: CHANGE_TREE_ZOOM, data: treeZoomData });
193+
this.props.dispatch({ type: CHANGE_TREE_FOCUS, data: treeFocusData });
194+
};
195+
196+
zoomToSelected = () => {
179197
this.props.dispatch(updateVisibleTipsAndBranchThicknesses({
180198
root: [this.props.tree.idxOfFilteredRoot, this.props.treeToo.idxOfFilteredRoot]
181199
}));
@@ -266,6 +284,12 @@ class Tree extends React.Component {
266284
>
267285
{t("Zoom to Selected")}
268286
</button>
287+
<button
288+
style={{...tabSingle, ...styles.focusOnSelectedButton}}
289+
onClick={this.focusOnSelected}
290+
>
291+
{t("Focus On Selected")}
292+
</button>
269293
<button
270294
style={{...tabSingle, ...styles.resetTreeButton}}
271295
onClick={this.redrawTree}

‎src/middleware/changeURL.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ export const changeURLMiddleware = (store) => (next) => (action) => {
140140
query.p = action.notInURLState === true ? undefined : action.data;
141141
break;
142142
}
143-
case types.CHANGE_TREE_ZOOM: {
144-
query.z = action.data === state.controls.defaults.treeZoom ? undefined : action.data;
143+
case types.CHANGE_TREE_FOCUS: {
144+
query.z = action.data === state.controls.defaults.treeFocus ? undefined : action.data;
145145
break;
146146
}
147147
case types.TOGGLE_SIDEBAR: {

‎src/reducers/controls.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { defaultGeoResolution,
44
defaultDateRange,
55
defaultDistanceMeasure,
66
defaultLayout,
7-
defaultTreeZoom,
7+
defaultTreeFocus,
88
controlsHiddenWidth,
99
strainSymbol,
1010
twoColumnBreakpoint } from "../util/globals";
@@ -44,7 +44,7 @@ export const getDefaultControlsState = () => {
4444
const defaults: Partial<ControlsState> = {
4545
distanceMeasure: defaultDistanceMeasure,
4646
layout: defaultLayout,
47-
treeZoom: defaultTreeZoom,
47+
treeFocus: defaultTreeFocus,
4848
geoResolution: defaultGeoResolution,
4949
filters: {},
5050
filtersInFooter: [],
@@ -72,7 +72,7 @@ export const getDefaultControlsState = () => {
7272
layout: defaults.layout,
7373
scatterVariables: {},
7474
distanceMeasure: defaults.distanceMeasure,
75-
treeZoom: defaults.treeZoom,
75+
treeFocus: defaults.treeFocus,
7676
dateMin,
7777
dateMinNumeric,
7878
dateMax,
@@ -195,9 +195,9 @@ const Controls = (state: ControlsState = getDefaultControlsState(), action): Con
195195
}
196196
return Object.assign({}, state, updatesToState);
197197
}
198-
case types.CHANGE_TREE_ZOOM:
198+
case types.CHANGE_TREE_FOCUS:
199199
return Object.assign({}, state, {
200-
treeZoom: action.data
200+
treeFocus: action.data
201201
});
202202
case types.CHANGE_DATES_VISIBILITY_THICKNESS: {
203203
const newDates: Partial<ControlsState> = { quickdraw: action.quickdraw };

‎src/util/globals.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const defaultColorBy = "country";
2727
export const defaultGeoResolution = "country";
2828
export const defaultLayout = "rect";
2929
export const defaultDistanceMeasure = "num_date";
30-
export const defaultTreeZoom = "even";
30+
export const defaultTreeFocus = "even";
3131
export const defaultDateRange = 6;
3232
export const date_select = true;
3333
export const file_prefix = "Zika_";

0 commit comments

Comments
 (0)