Skip to content

Commit

Permalink
Hide leaf nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Feb 27, 2024
1 parent cc4056c commit cc5f80a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 34 deletions.
16 changes: 13 additions & 3 deletions lib/src/components/TreePanel/TreeNodeMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const TreeMenu = observer(function ({
model: MsaViewModel
onClose: () => void
}) {
const { selectedStructures, collapsed, structures } = model
const { selectedStructures, collapsed, collapsed2, structures } = model
const nodeDetails = node ? model.getRowData(node.name) : undefined

return (
Expand Down Expand Up @@ -56,11 +56,21 @@ const TreeMenu = observer(function ({
<MenuItem
dense
onClick={() => {
model.toggleCollapsed(node.id)
if (collapsed.includes(node.id)) {
model.toggleCollapsed(node.id)
} else {
if (node.id.endsWith('-leafnode')) {
model.toggleCollapsed2(`${node.id}`)
} else {
model.toggleCollapsed2(`${node.id}-leafnode`)
}
}
onClose()
}}
>
{collapsed.includes(node.id) ? 'Show node' : 'Hide node'}
{collapsed.includes(node.id) || collapsed2.includes(node.id)
? 'Show node'
: 'Hide node'}
</MenuItem>

{structures[node.name]?.map(entry =>
Expand Down
1 change: 1 addition & 0 deletions lib/src/components/TreePanel/renderTreeCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export function renderNodeBubbles({
} = node
const { branchset, id = '', name = '' } = data
if (
!id.endsWith('-leafnode') &&
branchset.length &&
y > offsetY - extendBounds &&
y < offsetY + by + extendBounds
Expand Down
64 changes: 33 additions & 31 deletions lib/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ export type BasicTrack = IBoxTrack | ITextTrack
*/
function x() {} // eslint-disable-line @typescript-eslint/no-unused-vars

function reparseTree(tree: NodeWithIds): NodeWithIds {
return {
...tree,
branchset: tree.branchset.map(r =>
r.branchset.length
? reparseTree(r)
: {
branchset: [r],
id: `${r.id}-leafnode`,
name: `${r.name}-hidden`,
},
),
}
}

export type DialogComponentType =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
| React.LazyExoticComponent<React.FC<any>>
Expand Down Expand Up @@ -239,12 +254,7 @@ const model = types
*/
collapsed: types.array(types.string),

/**
* #property
* array of leaf nodes that are 'hidden', similar to collapsed but for leaf nodes
*/
hidden: types.array(types.string),

collapsed2: types.array(types.string),
/**
* #property
* focus on particular subtree
Expand Down Expand Up @@ -426,20 +436,6 @@ const model = types
self.drawTree = arg
},

/**
* #action
*/
hideNode(arg: string) {
self.hidden.push(arg)
},

/**
* #action
*/
clearHidden() {
self.hidden.clear()
},

/**
* #action
*/
Expand All @@ -451,6 +447,16 @@ const model = types
}
},

/**
* #action
*/
toggleCollapsed2(node: string) {
if (self.collapsed2.includes(node)) {
self.collapsed2.remove(node)
} else {
self.collapsed2.push(node)
}
},
/**
* #action
*/
Expand Down Expand Up @@ -613,14 +619,15 @@ const model = types
* #getter
*/
get _tree(): NodeWithIds {
return self.data.tree
const ret = self.data.tree
? generateNodeIds(parseNewick(self.data.tree))
: this.MSA?.getTree() || {
noTree: true,
branchset: [],
id: 'empty',
name: 'empty',
}
return reparseTree(ret)
},
/**
* #getter
Expand Down Expand Up @@ -659,18 +666,13 @@ const model = types
}
}

if (self.collapsed.length) {
self.collapsed
if (self.collapsed.length || self.collapsed2.length) {
;[...self.collapsed, ...self.collapsed2]
.map(collapsedId => hier.find(node => node.data.id === collapsedId))
.filter(notEmpty)
.map(node => collapse(node))
}
if (self.hidden.length) {
self.hidden
.map(hiddenId => hier.find(node => node.data.id === hiddenId))
.filter(notEmpty)
.map(node => filterHiddenLeafNodes(node.parent, node.id))
}

return hier
},
/**
Expand Down Expand Up @@ -1093,7 +1095,7 @@ const model = types
relativePxToBp(rowName: string, position: number) {
const { rowNames, rows } = self
const index = rowNames.indexOf(rowName)
if (index !== -1) {
if (index !== -1 && rows[index]) {
const row = rows[index][1]

let k = 0
Expand All @@ -1115,7 +1117,7 @@ const model = types
relativePxToBp2(rowName: string, position: number) {
const { rowNames, rows } = self
const index = rowNames.indexOf(rowName)
if (index !== -1) {
if (index !== -1 && rows[index]) {
const row = rows[index][1]

let k = 0
Expand Down

0 comments on commit cc5f80a

Please sign in to comment.