phylotree 2.1.7 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/phylotree.js +872 -51
- package/dist/phylotree.min.js +1 -1
- package/package.json +4 -1
- package/src/branches.js +52 -3
- package/src/formats/newick.js +90 -0
- package/src/main.js +86 -3
- package/src/nodes.js +53 -0
- package/src/render/draw.js +62 -5
- package/src/render/edges.js +15 -3
- package/src/render/event-emitter.js +64 -0
- package/src/render/events.js +11 -1
- package/src/render/menus.js +121 -33
- package/src/render/nodes.js +12 -4
- package/src/render/selection-sets.js +259 -0
- package/src/render/styles/phylotree-menus.css +93 -0
- package/src/rooting.js +22 -0
package/src/render/menus.js
CHANGED
|
@@ -17,7 +17,7 @@ export function nodeDropdownMenu(node, container, phylotree, options, event) {
|
|
|
17
17
|
.select(container)
|
|
18
18
|
.append("div")
|
|
19
19
|
.attr("id", d3_layout_phylotree_context_menu_id)
|
|
20
|
-
.attr("class", "dropdown-menu")
|
|
20
|
+
.attr("class", "phylotree-context-menu dropdown-menu")
|
|
21
21
|
.attr("role", "menu");
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -40,7 +40,7 @@ export function nodeDropdownMenu(node, container, phylotree, options, event) {
|
|
|
40
40
|
if (options["collapsible"]) {
|
|
41
41
|
menu_object
|
|
42
42
|
.append("a")
|
|
43
|
-
.attr("class", "dropdown-item")
|
|
43
|
+
.attr("class", "phylotree-menu-item dropdown-item")
|
|
44
44
|
.attr("tabindex", "-1")
|
|
45
45
|
.text(isNodeCollapsed(node) ? "Expand Subtree" : "Collapse Subtree")
|
|
46
46
|
.on("click", d => {
|
|
@@ -48,10 +48,10 @@ export function nodeDropdownMenu(node, container, phylotree, options, event) {
|
|
|
48
48
|
this.toggleCollapse(node).update();
|
|
49
49
|
});
|
|
50
50
|
if (options["selectable"]) {
|
|
51
|
-
menu_object.append("div").attr("class", "dropdown-divider");
|
|
51
|
+
menu_object.append("div").attr("class", "phylotree-menu-divider dropdown-divider");
|
|
52
52
|
menu_object
|
|
53
53
|
.append("h6")
|
|
54
|
-
.attr("class", "dropdown-header")
|
|
54
|
+
.attr("class", "phylotree-menu-header dropdown-header")
|
|
55
55
|
.text("Toggle selection");
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -59,38 +59,50 @@ export function nodeDropdownMenu(node, container, phylotree, options, event) {
|
|
|
59
59
|
if (options["selectable"]) {
|
|
60
60
|
menu_object
|
|
61
61
|
.append("a")
|
|
62
|
-
.attr("class", "dropdown-item")
|
|
62
|
+
.attr("class", "phylotree-menu-item dropdown-item")
|
|
63
63
|
.attr("tabindex", "-1")
|
|
64
64
|
.text("All descendant branches")
|
|
65
|
-
.on("click",
|
|
65
|
+
.on("click", (d) => {
|
|
66
66
|
menu_object.style("display", "none");
|
|
67
|
-
phylotree.
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
const nodes = phylotree.selectAllDescendants(node, true, true);
|
|
68
|
+
if (this.options["selection-mode"] === "multi-set" && this._activeSetName) {
|
|
69
|
+
nodes.forEach(n => this.addToSet(n, this._activeSetName));
|
|
70
|
+
this.update();
|
|
71
|
+
} else {
|
|
72
|
+
this.modifySelection(nodes);
|
|
73
|
+
}
|
|
70
74
|
});
|
|
71
75
|
|
|
72
76
|
menu_object
|
|
73
77
|
.append("a")
|
|
74
|
-
.attr("class", "dropdown-item")
|
|
78
|
+
.attr("class", "phylotree-menu-item dropdown-item")
|
|
75
79
|
.attr("tabindex", "-1")
|
|
76
80
|
.text("All terminal branches")
|
|
77
|
-
.on("click",
|
|
81
|
+
.on("click", (d) => {
|
|
78
82
|
menu_object.style("display", "none");
|
|
79
|
-
phylotree.
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
const nodes = phylotree.selectAllDescendants(node, true, false);
|
|
84
|
+
if (this.options["selection-mode"] === "multi-set" && this._activeSetName) {
|
|
85
|
+
nodes.forEach(n => this.addToSet(n, this._activeSetName));
|
|
86
|
+
this.update();
|
|
87
|
+
} else {
|
|
88
|
+
this.modifySelection(nodes);
|
|
89
|
+
}
|
|
82
90
|
});
|
|
83
91
|
|
|
84
92
|
menu_object
|
|
85
93
|
.append("a")
|
|
86
|
-
.attr("class", "dropdown-item")
|
|
94
|
+
.attr("class", "phylotree-menu-item dropdown-item")
|
|
87
95
|
.attr("tabindex", "-1")
|
|
88
96
|
.text("All internal branches")
|
|
89
|
-
.on("click",
|
|
97
|
+
.on("click", (d) => {
|
|
90
98
|
menu_object.style("display", "none");
|
|
91
|
-
phylotree.
|
|
92
|
-
|
|
93
|
-
|
|
99
|
+
const nodes = phylotree.selectAllDescendants(node, false, true);
|
|
100
|
+
if (this.options["selection-mode"] === "multi-set" && this._activeSetName) {
|
|
101
|
+
nodes.forEach(n => this.addToSet(n, this._activeSetName));
|
|
102
|
+
this.update();
|
|
103
|
+
} else {
|
|
104
|
+
this.modifySelection(nodes);
|
|
105
|
+
}
|
|
94
106
|
});
|
|
95
107
|
}
|
|
96
108
|
}
|
|
@@ -99,33 +111,44 @@ export function nodeDropdownMenu(node, container, phylotree, options, event) {
|
|
|
99
111
|
if (options["selectable"]) {
|
|
100
112
|
menu_object
|
|
101
113
|
.append("a")
|
|
102
|
-
.attr("class", "dropdown-item")
|
|
114
|
+
.attr("class", "phylotree-menu-item dropdown-item")
|
|
103
115
|
.attr("tabindex", "-1")
|
|
104
116
|
.text("Incident branch")
|
|
105
|
-
.on("click",
|
|
117
|
+
.on("click", (d) => {
|
|
106
118
|
menu_object.style("display", "none");
|
|
107
|
-
|
|
119
|
+
if (this.options["selection-mode"] === "multi-set" && this._activeSetName) {
|
|
120
|
+
this.addToSet(node, this._activeSetName);
|
|
121
|
+
this.update();
|
|
122
|
+
} else {
|
|
123
|
+
this.modifySelection([node]);
|
|
124
|
+
}
|
|
108
125
|
});
|
|
109
126
|
|
|
110
127
|
menu_object
|
|
111
128
|
.append("a")
|
|
112
|
-
.attr("class", "dropdown-item")
|
|
129
|
+
.attr("class", "phylotree-menu-item dropdown-item")
|
|
113
130
|
.attr("tabindex", "-1")
|
|
114
131
|
.text("Path to root")
|
|
115
|
-
.on("click", d => {
|
|
132
|
+
.on("click", (d) => {
|
|
116
133
|
menu_object.style("display", "none");
|
|
117
|
-
this.
|
|
134
|
+
const nodes = this.phylotree.pathToRoot(node);
|
|
135
|
+
if (this.options["selection-mode"] === "multi-set" && this._activeSetName) {
|
|
136
|
+
nodes.forEach(n => this.addToSet(n, this._activeSetName));
|
|
137
|
+
this.update();
|
|
138
|
+
} else {
|
|
139
|
+
this.modifySelection(nodes);
|
|
140
|
+
}
|
|
118
141
|
});
|
|
119
142
|
|
|
120
143
|
if (options["reroot"] || options["hide"]) {
|
|
121
|
-
menu_object.append("div").attr("class", "dropdown-divider");
|
|
144
|
+
menu_object.append("div").attr("class", "phylotree-menu-divider dropdown-divider");
|
|
122
145
|
}
|
|
123
146
|
}
|
|
124
147
|
|
|
125
148
|
if (options["reroot"]) {
|
|
126
149
|
menu_object
|
|
127
150
|
.append("a")
|
|
128
|
-
.attr("class", "dropdown-item")
|
|
151
|
+
.attr("class", "phylotree-menu-item dropdown-item")
|
|
129
152
|
.attr("tabindex", "-1")
|
|
130
153
|
.text("Reroot on this node")
|
|
131
154
|
.on("click", d => {
|
|
@@ -138,7 +161,7 @@ export function nodeDropdownMenu(node, container, phylotree, options, event) {
|
|
|
138
161
|
if (options["hide"]) {
|
|
139
162
|
menu_object
|
|
140
163
|
.append("a")
|
|
141
|
-
.attr("class", "dropdown-item")
|
|
164
|
+
.attr("class", "phylotree-menu-item dropdown-item")
|
|
142
165
|
.attr("tabindex", "-1")
|
|
143
166
|
.text("Hide this " + (isLeafNode(node) ? "node" : "subtree"))
|
|
144
167
|
.on("click", d => {
|
|
@@ -153,7 +176,7 @@ export function nodeDropdownMenu(node, container, phylotree, options, event) {
|
|
|
153
176
|
if (hasHiddenNodes(node)) {
|
|
154
177
|
menu_object
|
|
155
178
|
.append("a")
|
|
156
|
-
.attr("class", "dropdown-item")
|
|
179
|
+
.attr("class", "phylotree-menu-item dropdown-item")
|
|
157
180
|
.attr("tabindex", "-1")
|
|
158
181
|
.text("Show all descendant nodes")
|
|
159
182
|
.on("click", function(d) {
|
|
@@ -192,13 +215,13 @@ export function nodeDropdownMenu(node, container, phylotree, options, event) {
|
|
|
192
215
|
];
|
|
193
216
|
|
|
194
217
|
if (_.some(show_divider_options)) {
|
|
195
|
-
menu_object.append("div").attr("class", "dropdown-divider");
|
|
218
|
+
menu_object.append("div").attr("class", "phylotree-menu-divider dropdown-divider");
|
|
196
219
|
}
|
|
197
220
|
|
|
198
221
|
has_user_elements.forEach(function(d) {
|
|
199
222
|
menu_object
|
|
200
223
|
.append("a")
|
|
201
|
-
.attr("class", "dropdown-item")
|
|
224
|
+
.attr("class", "phylotree-menu-item dropdown-item")
|
|
202
225
|
.attr("tabindex", "-1")
|
|
203
226
|
.text((d[0])(node)) // eslint-disable-line
|
|
204
227
|
.on("click", _.partial(d[1], node));
|
|
@@ -388,8 +411,14 @@ export function modifySelection(
|
|
|
388
411
|
}
|
|
389
412
|
}
|
|
390
413
|
|
|
391
|
-
if (
|
|
392
|
-
this.
|
|
414
|
+
if (attr != "tag") {
|
|
415
|
+
const selection = this.getSelection();
|
|
416
|
+
// Call legacy callback for backward compatibility
|
|
417
|
+
if (this._selectionCallback) {
|
|
418
|
+
this._selectionCallback(selection);
|
|
419
|
+
}
|
|
420
|
+
// Emit event for new event system
|
|
421
|
+
this.emit('selectionChange', selection);
|
|
393
422
|
}
|
|
394
423
|
|
|
395
424
|
this.refresh();
|
|
@@ -451,3 +480,62 @@ export function selectionCallback(callback) {
|
|
|
451
480
|
this._selectionCallback = callback;
|
|
452
481
|
return this;
|
|
453
482
|
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Select nodes by their names.
|
|
486
|
+
*
|
|
487
|
+
* @param {string[]} names - Array of node names to select.
|
|
488
|
+
* @returns {this} For chaining.
|
|
489
|
+
* @example
|
|
490
|
+
* tree.selectNodes(['HUMAN', 'CHIMP', 'GORILLA']);
|
|
491
|
+
*/
|
|
492
|
+
export function selectNodes(names) {
|
|
493
|
+
if (!names || !Array.isArray(names) || names.length === 0) {
|
|
494
|
+
return this;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const nodesToSelect = this.phylotree.nodes.descendants()
|
|
498
|
+
.filter(node => names.includes(node.data.name));
|
|
499
|
+
|
|
500
|
+
if (nodesToSelect.length > 0) {
|
|
501
|
+
this.modifySelection(nodesToSelect, this.selection_attribute_name, false, false, 'true');
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
return this;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Deselect nodes by their names.
|
|
509
|
+
*
|
|
510
|
+
* @param {string[]} names - Array of node names to deselect.
|
|
511
|
+
* @returns {this} For chaining.
|
|
512
|
+
* @example
|
|
513
|
+
* tree.deselectNodes(['HUMAN']);
|
|
514
|
+
*/
|
|
515
|
+
export function deselectNodes(names) {
|
|
516
|
+
if (!names || !Array.isArray(names) || names.length === 0) {
|
|
517
|
+
return this;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
const nodesToDeselect = this.phylotree.nodes.descendants()
|
|
521
|
+
.filter(node => names.includes(node.data.name));
|
|
522
|
+
|
|
523
|
+
if (nodesToDeselect.length > 0) {
|
|
524
|
+
this.modifySelection(nodesToDeselect, this.selection_attribute_name, false, false, 'false');
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
return this;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Clear all current selection.
|
|
532
|
+
*
|
|
533
|
+
* @returns {this} For chaining.
|
|
534
|
+
* @example
|
|
535
|
+
* tree.clearSelection();
|
|
536
|
+
*/
|
|
537
|
+
export function clearSelection() {
|
|
538
|
+
const allNodes = this.phylotree.nodes.descendants();
|
|
539
|
+
this.modifySelection(allNodes, this.selection_attribute_name, false, false, 'false');
|
|
540
|
+
return this;
|
|
541
|
+
}
|
package/src/render/nodes.js
CHANGED
|
@@ -41,8 +41,12 @@ export function drawNode(container, node, transitions) {
|
|
|
41
41
|
.append("text")
|
|
42
42
|
.classed(this.css_classes["node_text"], true)
|
|
43
43
|
.merge(labels)
|
|
44
|
-
.on("click", d=> {
|
|
45
|
-
this.
|
|
44
|
+
.on("click", (event, d) => {
|
|
45
|
+
this.emit('nodeClick', node, event);
|
|
46
|
+
this.handle_node_click(node, event);
|
|
47
|
+
})
|
|
48
|
+
.on("mouseenter", (event) => {
|
|
49
|
+
this.emit('nodeHover', node, event);
|
|
46
50
|
})
|
|
47
51
|
.attr("dy", d => {
|
|
48
52
|
return this.shown_font_size * 0.33;
|
|
@@ -183,8 +187,12 @@ export function drawNode(container, node, transitions) {
|
|
|
183
187
|
.attr("r", d => {
|
|
184
188
|
return Math.min(this.shown_font_size * 0.75, radius);
|
|
185
189
|
})
|
|
186
|
-
.on("click", d => {
|
|
187
|
-
this.
|
|
190
|
+
.on("click", (event, d) => {
|
|
191
|
+
this.emit('nodeClick', node, event);
|
|
192
|
+
this.handle_node_click(node, event);
|
|
193
|
+
})
|
|
194
|
+
.on("mouseenter", (event) => {
|
|
195
|
+
this.emit('nodeHover', node, event);
|
|
188
196
|
});
|
|
189
197
|
} else {
|
|
190
198
|
circles.remove();
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-set selection management for phylotree
|
|
3
|
+
* @module render/selection-sets
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Initialize multi-set selection mode.
|
|
8
|
+
* Called automatically during render when selection-mode is 'multi-set'.
|
|
9
|
+
*
|
|
10
|
+
* @param {Array<{name: string, color: string}>} sets - Array of selection set definitions.
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
13
|
+
export function initializeSelectionSets(sets) {
|
|
14
|
+
this._selectionSets = {};
|
|
15
|
+
this._activeSetName = null;
|
|
16
|
+
|
|
17
|
+
sets.forEach(set => {
|
|
18
|
+
this._selectionSets[set.name] = {
|
|
19
|
+
name: set.name,
|
|
20
|
+
color: set.color,
|
|
21
|
+
members: new Set()
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Set first set as active by default
|
|
26
|
+
if (sets.length > 0) {
|
|
27
|
+
this._activeSetName = sets[0].name;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Inject CSS for set colors
|
|
31
|
+
this._injectSetStyles(sets);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Inject dynamic CSS styles for selection set colors.
|
|
36
|
+
*
|
|
37
|
+
* @param {Array<{name: string, color: string}>} sets - Array of selection set definitions.
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
export function _injectSetStyles(sets) {
|
|
41
|
+
const styleId = 'phylotree-selection-set-styles';
|
|
42
|
+
let styleEl = document.getElementById(styleId);
|
|
43
|
+
|
|
44
|
+
if (!styleEl) {
|
|
45
|
+
styleEl = document.createElement('style');
|
|
46
|
+
styleEl.id = styleId;
|
|
47
|
+
document.head.appendChild(styleEl);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const css = sets.map(set => {
|
|
51
|
+
const safeName = set.name.replace(/[^a-zA-Z0-9-_]/g, '_');
|
|
52
|
+
return `
|
|
53
|
+
.phylotree-set-${safeName} path.branch {
|
|
54
|
+
stroke: ${set.color} !important;
|
|
55
|
+
}
|
|
56
|
+
.phylotree-set-${safeName} .node circle {
|
|
57
|
+
fill: ${set.color} !important;
|
|
58
|
+
}
|
|
59
|
+
.phylotree-set-branch-${safeName} {
|
|
60
|
+
stroke: ${set.color} !important;
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
}).join('\n');
|
|
64
|
+
|
|
65
|
+
styleEl.textContent = css;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Set the active selection set. Clicks will add nodes to this set.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} name - Name of the set to activate.
|
|
72
|
+
* @returns {this} For chaining.
|
|
73
|
+
* @example
|
|
74
|
+
* tree.setActiveSet('foreground');
|
|
75
|
+
*/
|
|
76
|
+
export function setActiveSet(name) {
|
|
77
|
+
if (this._selectionSets && this._selectionSets[name]) {
|
|
78
|
+
this._activeSetName = name;
|
|
79
|
+
} else {
|
|
80
|
+
console.warn(`Selection set '${name}' not found`);
|
|
81
|
+
}
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get the currently active selection set name.
|
|
87
|
+
*
|
|
88
|
+
* @returns {string|null} Active set name or null if not in multi-set mode.
|
|
89
|
+
* @example
|
|
90
|
+
* const activeSet = tree.getActiveSet(); // 'foreground'
|
|
91
|
+
*/
|
|
92
|
+
export function getActiveSet() {
|
|
93
|
+
return this._activeSetName;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Get all members (nodes) of a selection set.
|
|
98
|
+
*
|
|
99
|
+
* @param {string} setName - Name of the selection set.
|
|
100
|
+
* @returns {Node[]} Array of nodes in the set.
|
|
101
|
+
* @example
|
|
102
|
+
* const foregroundNodes = tree.getSetMembers('foreground');
|
|
103
|
+
*/
|
|
104
|
+
export function getSetMembers(setName) {
|
|
105
|
+
if (!this._selectionSets || !this._selectionSets[setName]) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const memberNames = this._selectionSets[setName].members;
|
|
110
|
+
return this.phylotree.nodes.descendants()
|
|
111
|
+
.filter(node => memberNames.has(node.data.name));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Add a node to a selection set.
|
|
116
|
+
*
|
|
117
|
+
* @param {Node|string} node - Node object or node name.
|
|
118
|
+
* @param {string} setName - Target set name.
|
|
119
|
+
* @returns {this} For chaining.
|
|
120
|
+
* @example
|
|
121
|
+
* tree.addToSet('HUMAN', 'foreground');
|
|
122
|
+
* tree.addToSet(nodeObject, 'background');
|
|
123
|
+
*/
|
|
124
|
+
export function addToSet(node, setName) {
|
|
125
|
+
if (!this._selectionSets || !this._selectionSets[setName]) {
|
|
126
|
+
console.warn(`Selection set '${setName}' not found`);
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const nodeName = typeof node === 'string' ? node : node.data.name;
|
|
131
|
+
const nodeObj = typeof node === 'string'
|
|
132
|
+
? this.phylotree.getNodeByName(node)
|
|
133
|
+
: node;
|
|
134
|
+
|
|
135
|
+
if (nodeObj) {
|
|
136
|
+
// Remove from all other sets (mutually exclusive)
|
|
137
|
+
Object.keys(this._selectionSets).forEach(otherSet => {
|
|
138
|
+
this._selectionSets[otherSet].members.delete(nodeName);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
this._selectionSets[setName].members.add(nodeName);
|
|
142
|
+
nodeObj._selectionSet = setName;
|
|
143
|
+
|
|
144
|
+
this.emit('setChange', {
|
|
145
|
+
action: 'add',
|
|
146
|
+
set: setName,
|
|
147
|
+
node: nodeObj,
|
|
148
|
+
allSets: this._getSetsSummary()
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
this.refresh();
|
|
152
|
+
this.update();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Remove a node from a selection set.
|
|
160
|
+
*
|
|
161
|
+
* @param {Node|string} node - Node object or node name.
|
|
162
|
+
* @param {string} setName - Target set name.
|
|
163
|
+
* @returns {this} For chaining.
|
|
164
|
+
* @example
|
|
165
|
+
* tree.removeFromSet('HUMAN', 'foreground');
|
|
166
|
+
*/
|
|
167
|
+
export function removeFromSet(node, setName) {
|
|
168
|
+
if (!this._selectionSets || !this._selectionSets[setName]) {
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const nodeName = typeof node === 'string' ? node : node.data.name;
|
|
173
|
+
const nodeObj = typeof node === 'string'
|
|
174
|
+
? this.phylotree.getNodeByName(node)
|
|
175
|
+
: node;
|
|
176
|
+
|
|
177
|
+
if (this._selectionSets[setName].members.has(nodeName)) {
|
|
178
|
+
this._selectionSets[setName].members.delete(nodeName);
|
|
179
|
+
if (nodeObj) {
|
|
180
|
+
delete nodeObj._selectionSet;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
this.emit('setChange', {
|
|
184
|
+
action: 'remove',
|
|
185
|
+
set: setName,
|
|
186
|
+
node: nodeObj,
|
|
187
|
+
allSets: this._getSetsSummary()
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
this.refresh();
|
|
191
|
+
this.update();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Get a summary of all sets and their members.
|
|
199
|
+
*
|
|
200
|
+
* @returns {Object} Object with set names as keys and arrays of node names as values.
|
|
201
|
+
* @private
|
|
202
|
+
*/
|
|
203
|
+
export function _getSetsSummary() {
|
|
204
|
+
const summary = {};
|
|
205
|
+
if (this._selectionSets) {
|
|
206
|
+
Object.keys(this._selectionSets).forEach(setName => {
|
|
207
|
+
summary[setName] = Array.from(this._selectionSets[setName].members);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return summary;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Handle click in multi-set mode.
|
|
215
|
+
* Adds the clicked node to the active set.
|
|
216
|
+
*
|
|
217
|
+
* @param {Node} node - The clicked node.
|
|
218
|
+
* @private
|
|
219
|
+
*/
|
|
220
|
+
export function handleMultiSetClick(node) {
|
|
221
|
+
if (!this._activeSetName || !this._selectionSets) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const nodeName = node.data.name;
|
|
226
|
+
const currentSet = node._selectionSet;
|
|
227
|
+
|
|
228
|
+
if (currentSet === this._activeSetName) {
|
|
229
|
+
// Already in active set, remove it
|
|
230
|
+
this.removeFromSet(node, this._activeSetName);
|
|
231
|
+
} else {
|
|
232
|
+
// Add to active set (removes from other sets automatically)
|
|
233
|
+
this.addToSet(node, this._activeSetName);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Check if a node belongs to a specific set.
|
|
239
|
+
*
|
|
240
|
+
* @param {Node} node - The node to check.
|
|
241
|
+
* @param {string} setName - The set name to check.
|
|
242
|
+
* @returns {boolean} True if node is in the set.
|
|
243
|
+
*/
|
|
244
|
+
export function isInSet(node, setName) {
|
|
245
|
+
if (!this._selectionSets || !this._selectionSets[setName]) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
return this._selectionSets[setName].members.has(node.data.name);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Get the set name a node belongs to.
|
|
253
|
+
*
|
|
254
|
+
* @param {Node} node - The node to check.
|
|
255
|
+
* @returns {string|null} The set name or null if not in any set.
|
|
256
|
+
*/
|
|
257
|
+
export function getNodeSet(node) {
|
|
258
|
+
return node._selectionSet || null;
|
|
259
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* phylotree-menus.css - Standalone menu styles (no Bootstrap dependency)
|
|
3
|
+
*
|
|
4
|
+
* This file provides native styling for phylotree context menus.
|
|
5
|
+
* Include this CSS file to use menus without Bootstrap.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
.phylotree-context-menu {
|
|
9
|
+
position: absolute;
|
|
10
|
+
display: none;
|
|
11
|
+
min-width: 160px;
|
|
12
|
+
padding: 8px 0;
|
|
13
|
+
margin: 0;
|
|
14
|
+
background-color: #ffffff;
|
|
15
|
+
border: 1px solid rgba(0, 0, 0, 0.15);
|
|
16
|
+
border-radius: 4px;
|
|
17
|
+
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
|
|
18
|
+
z-index: 1000;
|
|
19
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
20
|
+
font-size: 14px;
|
|
21
|
+
color: #212529;
|
|
22
|
+
list-style: none;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.phylotree-menu-item {
|
|
26
|
+
display: block;
|
|
27
|
+
padding: 6px 20px;
|
|
28
|
+
color: #212529;
|
|
29
|
+
text-decoration: none;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
white-space: nowrap;
|
|
32
|
+
background-color: transparent;
|
|
33
|
+
border: none;
|
|
34
|
+
width: 100%;
|
|
35
|
+
text-align: left;
|
|
36
|
+
box-sizing: border-box;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.phylotree-menu-item:hover,
|
|
40
|
+
.phylotree-menu-item:focus {
|
|
41
|
+
background-color: #f8f9fa;
|
|
42
|
+
color: #16181b;
|
|
43
|
+
outline: none;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.phylotree-menu-item:active {
|
|
47
|
+
background-color: #e9ecef;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.phylotree-menu-divider {
|
|
51
|
+
height: 0;
|
|
52
|
+
margin: 8px 0;
|
|
53
|
+
overflow: hidden;
|
|
54
|
+
border-top: 1px solid #e9ecef;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.phylotree-menu-header {
|
|
58
|
+
display: block;
|
|
59
|
+
padding: 6px 20px;
|
|
60
|
+
margin-bottom: 0;
|
|
61
|
+
font-size: 12px;
|
|
62
|
+
font-weight: 600;
|
|
63
|
+
color: #6c757d;
|
|
64
|
+
white-space: nowrap;
|
|
65
|
+
text-transform: uppercase;
|
|
66
|
+
letter-spacing: 0.5px;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* Selection set color indicators */
|
|
70
|
+
.phylotree-set-indicator {
|
|
71
|
+
display: inline-block;
|
|
72
|
+
width: 10px;
|
|
73
|
+
height: 10px;
|
|
74
|
+
border-radius: 50%;
|
|
75
|
+
margin-right: 8px;
|
|
76
|
+
vertical-align: middle;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Animation for menu appearance */
|
|
80
|
+
.phylotree-context-menu[style*="display: block"] {
|
|
81
|
+
animation: phylotree-menu-fade-in 0.15s ease-out;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@keyframes phylotree-menu-fade-in {
|
|
85
|
+
from {
|
|
86
|
+
opacity: 0;
|
|
87
|
+
transform: translateY(-4px);
|
|
88
|
+
}
|
|
89
|
+
to {
|
|
90
|
+
opacity: 1;
|
|
91
|
+
transform: translateY(0);
|
|
92
|
+
}
|
|
93
|
+
}
|
package/src/rooting.js
CHANGED
|
@@ -9,6 +9,23 @@ import * as _ from "underscore";
|
|
|
9
9
|
the specified fraction
|
|
10
10
|
|
|
11
11
|
* @returns {Phylotree} The current ``phylotree``.
|
|
12
|
+
* @example
|
|
13
|
+
* // Reroot tree on a specific node
|
|
14
|
+
* const tree = new Phylotree("((A:0.1,B:0.2):0.05,(C:0.3,D:0.1):0.08);");
|
|
15
|
+
* const nodeC = tree.getNodeByName("C");
|
|
16
|
+
* tree.reroot(nodeC);
|
|
17
|
+
* // Tree is now rooted on the branch leading to C
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Reroot with custom branch length partitioning
|
|
21
|
+
* const nodeA = tree.getNodeByName("A");
|
|
22
|
+
* tree.reroot(nodeA, 0.3); // 30% of branch length goes to new root
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Reroot on midpoint of tree (balance tree)
|
|
26
|
+
* const tips = tree.getTips();
|
|
27
|
+
* const midpoint = tree.computeMidpoint();
|
|
28
|
+
* tree.reroot(midpoint);
|
|
12
29
|
*/
|
|
13
30
|
export function reroot(node, fraction) {
|
|
14
31
|
|
|
@@ -146,6 +163,11 @@ export function reroot(node, fraction) {
|
|
|
146
163
|
d3.select(rendered_tree.container).node().appendChild(rendered_tree.show());
|
|
147
164
|
d3.select(this.display.container).dispatch('reroot');
|
|
148
165
|
|
|
166
|
+
// Emit rerooted event via new event system
|
|
167
|
+
if (rendered_tree.emit) {
|
|
168
|
+
rendered_tree.emit('rerooted', this.nodes);
|
|
169
|
+
}
|
|
170
|
+
|
|
149
171
|
}
|
|
150
172
|
|
|
151
173
|
return this;
|