From 3e3e4a5a9dc9c2dd2e83e9567b75a3ea5546310b Mon Sep 17 00:00:00 2001 From: Gaurav Vaidya Date: Mon, 6 Jul 2026 01:29:06 -0400 Subject: [PATCH] Add starter documentation for addCustomMenu. --- src/render/menus.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/render/menus.js b/src/render/menus.js index 5413b8f6..08ee6da3 100644 --- a/src/render/menus.js +++ b/src/render/menus.js @@ -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"] = [];