UNPKG

react-phylogeny-tree-gl

Version:

React integration of phylocanvas.gl. Component and hook for phylogenetic tree visualistion.

101 lines 3.69 kB
import { getNodeLeafOffspringsIDs } from '../../utils'; import { download, createBlobURL } from './fileDownload'; export const treeMenuItems = [ [ { label: 'Show labels', handler: (tree) => { const current = Boolean(tree.props.showLabels && tree.props.showLeafLabels); tree.setProps({ showLabels: !current, showLeafLabels: !current, }); }, isActive: (tree) => Boolean(tree.props.showLabels && tree.props.showLeafLabels), }, ], [ { label: 'Fit in panel', handler: (tree) => tree === null || tree === void 0 ? void 0 : tree.fitInCanvas(), }, { label: 'Expand collapsed subtrees', visible: (tree) => { var _a, _b; return (((_b = (_a = tree === null || tree === void 0 ? void 0 : tree.props) === null || _a === void 0 ? void 0 : _a.collapsedIds) === null || _b === void 0 ? void 0 : _b.length) || 0) > 0; }, handler: (tree) => tree === null || tree === void 0 ? void 0 : tree.setProps({ collapsedIds: [] }), }, { label: 'Redraw original tree', handler: (tree) => tree === null || tree === void 0 ? void 0 : tree.setSource(tree.getGraphWithoutLayout().originalSource), }, ], [ { label: 'Export leaf labels', handler: (tree) => { const leafs = tree.getGraphAfterLayout().leaves.map((value) => value.label || value.id); download(createBlobURL(leafs.join('\n')), 'leaf_labels.txt'); }, }, { label: 'Export selected labels', handler: (tree) => { const leafs = tree.props.selectedIds || []; download(createBlobURL(leafs.join('\n')), 'leaf_labels.txt'); }, visible: (tree) => Boolean(tree.props.selectedIds && tree.props.selectedIds.length > 0), }, { label: 'Export as newick file', handler: (tree) => download(createBlobURL(tree.exportNewick()), 'phylogeny_tree.nwk'), }, { label: 'Export as image', handler: (tree) => { download(tree.exportPNG(), 'phylogeny_tree.png'); }, }, ], ]; export const nodeMenuItems = [ [ { label: (tree, node) => { var _a; return tree.props.collapsedIds === undefined || ((_a = tree.props.collapsedIds) === null || _a === void 0 ? void 0 : _a.indexOf(node.id)) === -1 ? 'Collapse subtree' : 'Expand subtree'; }, handler: (tree, node) => tree.collapseNode(node), }, { label: 'Rotate subtree', handler: (tree, node) => tree.rotateNode(node), }, ], [ { label: 'View subtree', handler: (tree, node) => tree.setRoot(node), }, { label: 'Re-root tree', handler: (tree, node) => tree.rerootNode(node), }, ], [ { label: 'Export subtree leaf labels', handler: (tree, node) => { const ids = getNodeLeafOffspringsIDs(node).join('\n'); download(createBlobURL(ids), 'leaf_labels.txt'); }, }, { label: 'Export subtree as newick file', handler: (tree, node) => download(createBlobURL(tree.exportNewick(node)), 'phylogeny_tree.nwk'), }, ], ]; //# sourceMappingURL=menuItems.js.map