-
Notifications
You must be signed in to change notification settings - Fork 166
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
Extend usefulness of tip labels #1668
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { getTraitFromNode } from "../../../util/treeMiscHelpers"; | ||
import { numericToCalendar } from "../../../util/dateHelpers"; | ||
|
||
|
||
/** | ||
* Attempt to display the best name we can for a node, depending on how we are looking at a node. | ||
* The returned string will be rendered on a line of its own, so an empty string will look ok | ||
* Future enhancement: we could examine the coloring metadata (if available) and format the value accordingly | ||
*/ | ||
export function nodeDisplayName(t, node, tipLabelKey, branch) { | ||
let tipLabel = getTraitFromNode(node, tipLabelKey) | ||
if (tipLabelKey==='num_date' && tipLabel) tipLabel = numericToCalendar(tipLabel) | ||
const terminal = !node.hasChildren; | ||
|
||
if (branch) { | ||
if (terminal) { | ||
return tipLabel ? t("Branch leading to {{tipLabel}}", {tipLabel}) : t("Terminal branch") // hover + click | ||
} | ||
return t("Internal branch") // branch click only | ||
} | ||
/* TIP */ | ||
return tipLabel; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,15 @@ const pseudoRandomName = () => (Math.random()*1e32).toString(36).slice(0, 6); | |
* node.hasChildren {bool} | ||
* node.arrayIdx {integer} - the index of the node in the nodes array | ||
* @param {array} nodes redux tree nodes | ||
* @return {array} input array (kinda unnecessary) | ||
* @return {Object} ret | ||
* @return {Set} ret.nodeAttrKeys collection of all `node_attr` keys whose values are Objects | ||
* @return {Array} ret.nodes input array (kinda unnecessary) | ||
* | ||
* side-effects: node.hasChildren (bool) and node.arrayIdx (INT) for each node in nodes | ||
*/ | ||
const processNodes = (nodes) => { | ||
const nodeNamesSeen = new Set(); | ||
const nodeAttrKeys = new Set(); | ||
calcFullTipCounts(nodes[0]); /* recursive. Uses d.children */ | ||
nodes.forEach((d, idx) => { | ||
d.arrayIdx = idx; /* set an index so that we can access visibility / nodeColors if needed */ | ||
|
@@ -32,8 +36,15 @@ const processNodes = (nodes) => { | |
console.warn(`Tree node detected with a duplicate name. Changing '${prev}' to '${d.name}' and continuing...`); | ||
} | ||
nodeNamesSeen.add(d.name); | ||
|
||
for (const [attrKey, attrValue] of Object.entries(d.node_attrs || {})) { | ||
if (typeof attrValue === 'object' && 'value' in attrValue) { | ||
nodeAttrKeys.add(attrKey) | ||
} | ||
} | ||
Comment on lines
+40
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. non-blocking, probably more of a change in Augur I was looking at the augur export schema to figure out which attrs this would be included here. Worth noting that we would not be able to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that's a good point. I wish we had made the schema so that every node-attr was the same structure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to refrain from addressing this here, but I do think moving all |
||
|
||
}); | ||
return nodes; | ||
return {nodeAttrKeys, nodes}; | ||
}; | ||
|
||
/** | ||
|
@@ -165,7 +176,7 @@ export const treeJsonToState = (treeJSON) => { | |
nodesArray.push(...flattenTree(treeRootNode)); | ||
} | ||
nodesArray.unshift(makeSubtreeRootNode(nodesArray, subtreeIndicies)); | ||
const nodes = processNodes(nodesArray); | ||
const {nodeAttrKeys, nodes} = processNodes(nodesArray); | ||
addParentInfo(nodesArray); | ||
const vaccines = nodes.filter((d) => { | ||
const v = getVaccineFromNode(d); | ||
|
@@ -174,6 +185,6 @@ export const treeJsonToState = (treeJSON) => { | |
const availableBranchLabels = processBranchLabelsInPlace(nodesArray); | ||
const observedMutations = collectObservedMutations(nodesArray); | ||
return Object.assign({}, getDefaultTreeState(), { | ||
nodes, vaccines, observedMutations, availableBranchLabels, loaded: true | ||
nodes, nodeAttrKeys, vaccines, observedMutations, availableBranchLabels, loaded: true | ||
}); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One oddity I noticed here is the hardcoding of
node.name
to "Sample Name" which is a little jarring when we use accessions fornode.name
.