Skip to content
Open
Changes from all 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
15 changes: 15 additions & 0 deletions src/render/menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,21 @@ export function nodeDropdownMenu(node, container, phylotree, options, event) {

}

/**
* Add a custom menu item to a node's menu.
*
* It is easy to add the menu items inside the `node-styler` function in tree.render(), which gets (element, node) as
* its two arguments -- that `node` can be passed to addCustomMenu() as its first argument. You may want to set
* `node.menu_items = []` to avoid adding the same menu item multiple times.
*
* The custom item will be added in addition to the default items: "Collapse Subtree", the "Toggle selection" submenu,
* "Reroot on this node" and "Hide this subtree". It will be added at the end of the menu after a menu divider.
*
* @param {Object} node The node to add the custom menu item to.
* @param {Function} name Given a node, returns the name of the menu item.
* @param {Function} callback Function to call when the menu item is clicked.
* @param {Function} condition Function to determine whether the menu item should be shown.
*/
export function addCustomMenu(node, name, callback, condition) {
if (!("menu_items" in node)) {
node["menu_items"] = [];
Expand Down
Loading