phylotree 2.6.0 → 2.6.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/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "phylotree",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "main": "dist/phylotree.js",
5
5
  "types": "dist/phylotree.d.ts",
6
6
  "unpkg": "dist/phylotree.js",
7
7
  "jsdelivr": "dist/phylotree.js",
8
8
  "module": "src/index.js",
9
+ "engines": {
10
+ "node": ">=20"
11
+ },
9
12
  "bin": {
10
13
  "root-to-tip": "./bin/root-to-tip.js",
11
14
  "tag-branches": "./bin/phylotree-tag.js",
@@ -23,15 +26,16 @@
23
26
  "index.html"
24
27
  ],
25
28
  "dependencies": {
29
+ "@types/d3": "^7.4.3",
26
30
  "commander": "^14.0.0",
27
31
  "csv-stringify": "^6.6.0",
28
32
  "d3": "^7.9.0",
29
- "fast-xml-parser": "^5.3.8",
33
+ "fast-xml-parser": "^5.7.0",
30
34
  "jquery": "^3.7.1",
31
- "lodash": "^4.17.23",
35
+ "lodash": "^4.18.1",
32
36
  "moment": "^2.30.1",
33
37
  "pretty-data": "^0.40.0",
34
- "underscore": "^1.13.7",
38
+ "underscore": "^1.13.8",
35
39
  "winston": "^3.17.0"
36
40
  },
37
41
  "devDependencies": {
@@ -44,24 +48,29 @@
44
48
  "globals": "^16.2.0",
45
49
  "http-server": "^14.1.1",
46
50
  "jsdoc-to-markdown": "^9.1.0",
51
+ "jsdom": "26.1.0",
47
52
  "prettier": "^3.7.0",
48
- "rollup": "^4.40.0",
53
+ "rollup": "^4.59.0",
49
54
  "rollup-plugin-copy": "^3.5.0",
50
- "tape": "^5.9.0"
55
+ "source-map-support": "0.5.21",
56
+ "tape": "^5.9.0",
57
+ "typescript": "5.9.3"
51
58
  },
52
59
  "scripts": {
53
60
  "lint": "eslint .",
54
61
  "dev": "rollup -w -c rollup.config.mjs",
55
- "serve": "concurrently 'rollup -w -c rollup.config.mjs' 'http-server'",
62
+ "serve": "concurrently \"rollup -w -c rollup.config.mjs\" \"http-server\"",
56
63
  "build": "rollup -c rollup.config.mjs",
57
- "test": "tape -r source-map-support/register 'test/*-test.js'",
58
- "docs:generate": "jsdoc2md 'src/**/*.js' > API.md",
59
- "docs:validate": "jsdoc2md 'src/**/*.js' --no-cache --partial 'partials/**/*.hbs'",
60
- "docs:watch": "jsdoc2md 'src/**/*.js' -w > API.md",
61
- "postpublish": "zip -j dist/phylotree.js.zip -- LICENSE README.md dist/phylotree.js dist/phylotree.min.js dist/phylotree.css"
64
+ "test": "tape --strict -r source-map-support/register \"test/*-test.js\"",
65
+ "typecheck": "tsc -p test/types",
66
+ "docs:generate": "node scripts/docs.mjs generate",
67
+ "docs:validate": "node scripts/docs.mjs validate",
68
+ "docs:watch": "node scripts/docs.mjs watch",
69
+ "prepublishOnly": "npm run build && npm test"
62
70
  },
63
71
  "files": [
64
72
  "dist/phylotree.css",
73
+ "dist/phylotree-menus.css",
65
74
  "dist/phylotree.js",
66
75
  "dist/phylotree.min.js",
67
76
  "dist/phylotree.d.ts",
@@ -1,6 +1,6 @@
1
1
  import * as d3 from "d3";
2
2
  import * as _ from "underscore";
3
- import { isNodeCollapsed } from "./nodes";
3
+ import { isNodeCollapsed, nodeOrAncestorNotshown } from "./nodes";
4
4
 
5
5
  export function cladeCssSelectors(css_classes) {
6
6
  return [css_classes["clade"]].reduce(function(p, c, i, a) {
@@ -16,7 +16,10 @@ export function updateCollapsedClades(transitions) {
16
16
  let collapsed_clades = enclosure
17
17
  .selectAll(cladeCssSelectors(this.css_classes))
18
18
  .data(
19
- this.phylotree.nodes.descendants().filter(isNodeCollapsed),
19
+ // a hidden clade is not laid out, so do not draw its stale polygon
20
+ this.phylotree.nodes
21
+ .descendants()
22
+ .filter(d => isNodeCollapsed(d) && !nodeOrAncestorNotshown(d)),
20
23
  function(d) {
21
24
  return d.id || (d.id = ++node_id);
22
25
  }
@@ -10,7 +10,7 @@ import * as clades from "./clades";
10
10
  import * as render_nodes from "./nodes";
11
11
  import * as render_edges from "./edges";
12
12
  import * as events from "./events";
13
- import { css_classes, initializeCssClasses } from "./options";
13
+ import { css_classes } from "./options";
14
14
  import * as opt from "./options";
15
15
  import * as menus from "./menus";
16
16
  import * as eventEmitter from "./event-emitter";
@@ -25,8 +25,7 @@ function constant(x) {
25
25
 
26
26
  class TreeRender {
27
27
  constructor(phylotree, options = {}) {
28
- initializeCssClasses(options['css-classes']);
29
- this.css_classes = css_classes;
28
+ this.css_classes = Object.assign({}, css_classes, options["css-classes"]);
30
29
  this.phylotree = phylotree;
31
30
  this.container = options.container;
32
31
  this.separation = function(_node, _previous) {
@@ -328,7 +327,7 @@ class TreeRender {
328
327
  let node_id = 0;
329
328
 
330
329
  let enclosure = this.svg
331
- .selectAll("." + css_classes["tree-container"])
330
+ .selectAll("." + this.css_classes["tree-container"])
332
331
  .data([0]);
333
332
 
334
333
  // Store base transform for composition with zoom
@@ -340,7 +339,7 @@ class TreeRender {
340
339
  enclosure = enclosure
341
340
  .enter()
342
341
  .append("g")
343
- .attr("class", css_classes["tree-container"])
342
+ .attr("class", this.css_classes["tree-container"])
344
343
  .merge(enclosure)
345
344
  .attr("transform", d => {
346
345
  // Compose base transform with current zoom transform if present
@@ -356,13 +355,13 @@ class TreeRender {
356
355
 
357
356
  if (this.draw_scale_bar) {
358
357
  let scale_bar = this.svg
359
- .selectAll("." + css_classes["tree-scale-bar"])
358
+ .selectAll("." + this.css_classes["tree-scale-bar"])
360
359
  .data([0]);
361
360
 
362
361
  scale_bar
363
362
  .enter()
364
363
  .append("g")
365
- .attr("class", css_classes["tree-scale-bar"])
364
+ .attr("class", this.css_classes["tree-scale-bar"])
366
365
  .style("font-size", this.ensure_size_is_in_px(this.scale_bar_font_size))
367
366
  .merge(scale_bar)
368
367
  .attr("transform", d => {
@@ -375,17 +374,17 @@ class TreeRender {
375
374
 
376
375
  scale_bar.selectAll("text").style("text-anchor", "end");
377
376
  } else {
378
- this.svg.selectAll("." + css_classes["tree-scale-bar"]).remove();
377
+ this.svg.selectAll("." + this.css_classes["tree-scale-bar"]).remove();
379
378
  }
380
379
 
381
380
  enclosure = this.svg
382
- .selectAll("." + css_classes["tree-container"])
381
+ .selectAll("." + this.css_classes["tree-container"])
383
382
  .data([0]);
384
383
 
385
384
  this.updateCollapsedClades(transitions);
386
385
 
387
386
  let drawn_links = enclosure
388
- .selectAll(render_edges.edgeCssSelectors(css_classes))
387
+ .selectAll(render_edges.edgeCssSelectors(this.css_classes))
389
388
  .data(this.links.filter(render_edges.edgeVisible), d => {
390
389
  return d.target.id || (d.target.id = ++node_id);
391
390
  });
@@ -405,7 +404,7 @@ class TreeRender {
405
404
  });
406
405
 
407
406
  let drawn_nodes = enclosure
408
- .selectAll(render_nodes.nodeCssSelectors(css_classes))
407
+ .selectAll(render_nodes.nodeCssSelectors(this.css_classes))
409
408
  .data(
410
409
  this.phylotree.nodes.descendants().filter(render_nodes.nodeVisible),
411
410
  d => {
@@ -418,8 +417,8 @@ class TreeRender {
418
417
  drawn_nodes = drawn_nodes
419
418
  .enter()
420
419
  .append("g")
421
- .attr("class", this.reclassNode)
422
420
  .merge(drawn_nodes)
421
+ .attr("class", d => this.reclassNode(d))
423
422
  .attr("transform", d => {
424
423
  const should_shift =
425
424
  this.options["layout"] == "right-to-left" && isLeafNode(d);
@@ -451,11 +450,11 @@ class TreeRender {
451
450
 
452
451
  if (this.options["brush"]) {
453
452
  var brush = enclosure
454
- .selectAll("." + css_classes["tree-selection-brush"])
453
+ .selectAll("." + this.css_classes["tree-selection-brush"])
455
454
  .data([0])
456
455
  .enter()
457
456
  .insert("g", ":first-child")
458
- .attr("class", css_classes["tree-selection-brush"]);
457
+ .attr("class", this.css_classes["tree-selection-brush"]);
459
458
 
460
459
  var brush_object = d3
461
460
  .brush()
@@ -518,10 +517,10 @@ class TreeRender {
518
517
  const composedTransform = `translate(${zt.x + this.baseTransform.x * zt.k}, ${zt.y + this.baseTransform.y * zt.k}) scale(${zt.k})`;
519
518
 
520
519
  // Use this.svg.select() to target only this tree instance (not global d3.select)
521
- this.svg.select("." + css_classes["tree-container"]).attr("transform", composedTransform);
520
+ this.svg.select("." + this.css_classes["tree-container"]).attr("transform", composedTransform);
522
521
 
523
522
  // Apply same transform to scale bar
524
- this.svg.select("." + css_classes["tree-scale-bar"]).attr("transform", d => {
523
+ this.svg.select("." + this.css_classes["tree-scale-bar"]).attr("transform", d => {
525
524
  return `translate(${zt.x + this.baseTransform.x * zt.k}, ${zt.y + (this.baseTransform.y - 10) * zt.k}) scale(${zt.k})`;
526
525
  });
527
526
  });
@@ -828,6 +827,8 @@ class TreeRender {
828
827
  * @returns The current ``phylotree``.
829
828
  */
830
829
  placenodes() {
830
+ render_nodes.markNotshownSubtrees(this.phylotree.nodes);
831
+
831
832
  this._extents = [
832
833
  [0, 0],
833
834
  [0, 0]
@@ -945,7 +946,12 @@ class TreeRender {
945
946
 
946
947
  let max_r = 0;
947
948
 
949
+ // hidden (notshown) nodes and their descendants are not laid out and
950
+ // keep stale coordinates; leave them out of the transforms and extents
951
+ const shown = d => !render_nodes.nodeOrAncestorNotshown(d);
952
+
948
953
  this.phylotree.nodes.each(d => {
954
+ if (!shown(d)) return;
949
955
  let my_circ_position = d.x * this.scales[0];
950
956
  d.angle = (2 * Math.PI * my_circ_position) / effective_span;
951
957
  d.text_angle = d.angle - Math.PI / 2;
@@ -957,6 +963,7 @@ class TreeRender {
957
963
  this.do_lr(at_least_one_dimension_fixed);
958
964
 
959
965
  this.phylotree.nodes.each(d => {
966
+ if (!shown(d)) return;
960
967
  d.radius = (d.y * this.scales[1]) / this.size[1];
961
968
  max_r = Math.max(d.radius, max_r);
962
969
  });
@@ -964,7 +971,7 @@ class TreeRender {
964
971
  let annular_shift = 0;
965
972
 
966
973
  this.phylotree.nodes.each(d => {
967
- if (!d.children) {
974
+ if (!d.children && shown(d)) {
968
975
  let my_circ_position = d.x * this.scales[0];
969
976
  if (last_child_angle !== null) {
970
977
  let required_spacing = my_circ_position - last_circ_position,
@@ -1036,6 +1043,7 @@ class TreeRender {
1036
1043
  }
1037
1044
 
1038
1045
  this.phylotree.nodes.each(d => {
1046
+ if (!shown(d)) return;
1039
1047
  cartesianToPolar(
1040
1048
  d,
1041
1049
  this.radius,
@@ -1103,6 +1111,9 @@ class TreeRender {
1103
1111
  this.right_most_leaf = 0;
1104
1112
 
1105
1113
  this.phylotree.nodes.each(d => {
1114
+ // hidden nodes (and their descendants) are not laid out; do not
1115
+ // rescale their stale coordinates
1116
+ if (render_nodes.nodeOrAncestorNotshown(d)) return;
1106
1117
 
1107
1118
  d.x *= this.scales[0];
1108
1119
  d.y *= this.scales[1]*.8;
@@ -1318,9 +1329,9 @@ class TreeRender {
1318
1329
  return this.css(arg);
1319
1330
  }
1320
1331
 
1321
- for (var key in css_classes) {
1322
- if (key in opt && opt[key] != css_classes[key]) {
1323
- css_classes[key] = opt[key];
1332
+ for (var key in this.css_classes) {
1333
+ if (key in opt && opt[key] != this.css_classes[key]) {
1334
+ this.css_classes[key] = opt[key];
1324
1335
  }
1325
1336
  }
1326
1337
 
@@ -1352,7 +1363,7 @@ class TreeRender {
1352
1363
 
1353
1364
  let do_update = false;
1354
1365
 
1355
- for (var key in css_classes) {
1366
+ for (var key in this.css_classes) {
1356
1367
  if (key in opt && opt[key] != this.css_classes[key]) {
1357
1368
  do_update = true;
1358
1369
  this.css_classes[key] = opt[key];
@@ -1408,20 +1419,11 @@ class TreeRender {
1408
1419
  .attr("class", this.reclassEdge.bind(this));
1409
1420
 
1410
1421
  if (this.edge_styler) {
1411
- edges.each(d => {
1412
- this.edge_styler(d3.select(this), d);
1422
+ let self = this;
1423
+ edges.each(function(d) {
1424
+ self.edge_styler(d3.select(this), d);
1413
1425
  });
1414
1426
  }
1415
-
1416
- //let nodes = this.enclosure
1417
- // .selectAll(inspector.nodeCssSelectors(this.css_classes))
1418
- // .attr("class", this.phylotree.reclassNode);
1419
-
1420
- //if (this.node_styler) {
1421
- // nodes.each(function(d) {
1422
- // this.node_styler(d3.select(this), d);
1423
- // });
1424
- //}
1425
1427
  }
1426
1428
 
1427
1429
  return this;
@@ -1,6 +1,6 @@
1
1
  import * as d3 from "d3";
2
2
  import { itemTagged, itemSelected } from "./helpers";
3
- import { css_classes } from "./options";
3
+ import { nodeOrAncestorNotshown } from "./nodes";
4
4
 
5
5
  export function drawEdge(container, edge, transition) {
6
6
 
@@ -62,14 +62,14 @@ export function drawEdge(container, edge, transition) {
62
62
 
63
63
  export function reclassEdge(edge) {
64
64
 
65
- let class_var = css_classes["branch"];
65
+ let class_var = this.css_classes["branch"];
66
66
 
67
67
  if (itemTagged(edge)) {
68
- class_var += " " + css_classes["tagged-branch"];
68
+ class_var += " " + this.css_classes["tagged-branch"];
69
69
  }
70
70
 
71
71
  if (itemSelected(edge, this.selection_attribute_name)) {
72
- class_var += " " + css_classes["selected-branch"];
72
+ class_var += " " + this.css_classes["selected-branch"];
73
73
  }
74
74
 
75
75
  // Multi-set selection mode: add set-specific class
@@ -128,7 +128,7 @@ export function syncEdgeLabels() {
128
128
  }
129
129
 
130
130
  export function edgeVisible(edge) {
131
- return !(edge.target.hidden || edge.target.notshown || false);
131
+ return !(edge.target.hidden || nodeOrAncestorNotshown(edge.target));
132
132
  }
133
133
 
134
134
  export function edgeCssSelectors(css_classes) {
@@ -1,5 +1,4 @@
1
1
  import { isLeafNode } from "../nodes";
2
- import { css_classes } from "./options";
3
2
 
4
3
  let d3_layout_phylotree_event_id = "phylotree.event";
5
4
 
@@ -56,7 +55,7 @@ export function resizeSvg(tree, svg, tr) {
56
55
  }
57
56
 
58
57
  svg
59
- .selectAll("." + css_classes["tree-container"])
58
+ .selectAll("." + this.css_classes["tree-container"])
60
59
  .attr("transform", transform);
61
60
  }
62
61
  } else if (this.radial()) {
@@ -88,7 +87,7 @@ export function resizeSvg(tree, svg, tr) {
88
87
  }
89
88
 
90
89
  svg
91
- .selectAll("." + css_classes["tree-container"])
90
+ .selectAll("." + this.css_classes["tree-container"])
92
91
  .attr("transform", transform);
93
92
  }
94
93
  } else {
@@ -166,7 +166,14 @@ export function nodeDropdownMenu(node, container, phylotree, options, event) {
166
166
  .text("Hide this " + (isLeafNode(node) ? "node" : "subtree"))
167
167
  .on("click", d => {
168
168
  menu_object.style("display", "none");
169
- this.modifySelection([node], "notshown", true, true)
169
+ // hide the whole subtree, mirroring "Show all descendant nodes"
170
+ this.modifySelection(
171
+ [node].concat(selectAllDescendants(node, true, true)),
172
+ "notshown",
173
+ true,
174
+ true,
175
+ "true"
176
+ )
170
177
  .updateHasHiddenNodes()
171
178
  .update();
172
179
  });
@@ -353,8 +360,12 @@ export function modifySelection(
353
360
  }
354
361
  }
355
362
  } else if (this.options["binary-selectable"]) {
363
+ // Only selection attributes are mutually exclusive; hiding ("notshown")
364
+ // or brushing ("tag") must not clear the attributes in attribute-list.
365
+ const exclusive = attr != "notshown" && attr != "tag";
366
+
356
367
  if (typeof node_selecter === "function") {
357
- this.links.forEach(function(d) {
368
+ this.links.forEach(d => {
358
369
  var select_me = node_selecter(d);
359
370
  d[attr] = d[attr] || false;
360
371
 
@@ -364,6 +375,7 @@ export function modifySelection(
364
375
  d.target[attr] = select_me;
365
376
  }
366
377
 
378
+ if (!exclusive) return;
367
379
  this.options["attribute-list"].forEach(function(type) {
368
380
  if (type != attr && d[attr] === true) {
369
381
  d[type] = false;
@@ -374,7 +386,17 @@ export function modifySelection(
374
386
  } else {
375
387
  node_selecter.forEach(function(d) {
376
388
  var new_value;
377
- new_value = !d[attr];
389
+ switch (mode) {
390
+ case "true":
391
+ new_value = true;
392
+ break;
393
+ case "false":
394
+ new_value = false;
395
+ break;
396
+ default:
397
+ new_value = !d[attr];
398
+ break;
399
+ }
378
400
 
379
401
  if (d[attr] != new_value) {
380
402
  d[attr] = new_value;
@@ -382,8 +404,9 @@ export function modifySelection(
382
404
  }
383
405
  });
384
406
 
385
- this.links.forEach(function(d) {
407
+ this.links.forEach(d => {
386
408
  d[attr] = d.target[attr];
409
+ if (!exclusive) return;
387
410
  this.options["attribute-list"].forEach(function(type) {
388
411
  if (type != attr && d[attr] !== true) {
389
412
  d[type] = false;
@@ -2,7 +2,6 @@ import * as d3 from "d3";
2
2
 
3
3
  import { itemTagged, itemSelected } from "./helpers";
4
4
  import { isLeafNode } from "../nodes";
5
- import { css_classes } from "./options";
6
5
 
7
6
  export function shiftTip(d) {
8
7
 
@@ -271,35 +270,56 @@ export function nodeSpan(attr) {
271
270
 
272
271
  export function reclassNode(node) {
273
272
 
274
- let class_var = css_classes[isLeafNode(node) ? "node" : "internal-node"];
273
+ let class_var = this.css_classes[isLeafNode(node) ? "node" : "internal-node"];
275
274
 
276
275
  if (itemTagged(node)) {
277
- class_var += " " + css_classes["tagged-node"];
276
+ class_var += " " + this.css_classes["tagged-node"];
278
277
  }
279
278
 
280
279
  if (itemSelected(node, this.selection_attribute_name)) {
281
- class_var += " " + css_classes["selected-node"];
280
+ class_var += " " + this.css_classes["selected-node"];
282
281
  }
283
282
 
284
283
  if (!node["parent"]) {
285
- class_var += " " + css_classes["root-node"];
284
+ class_var += " " + this.css_classes["root-node"];
286
285
  }
287
286
 
288
287
  if (isNodeCollapsed(node) || hasHiddenNodes(node)) {
289
- class_var += " " + css_classes["collapsed-node"];
288
+ class_var += " " + this.css_classes["collapsed-node"];
290
289
  }
291
290
 
292
291
  return class_var;
293
292
  }
294
293
 
295
294
  export function nodeVisible(node) {
296
- return !(node.hidden || node.notshown || false);
295
+ return !(node.hidden || nodeOrAncestorNotshown(node));
297
296
  }
298
297
 
299
298
  export function nodeNotshown(node) {
300
299
  return node.notshown;
301
300
  }
302
301
 
302
+ // true if the node or any of its ancestors is hidden (notshown); the layout
303
+ // skips a hidden node's whole subtree, so its descendants are hidden too.
304
+ // Reads the flag cached by markNotshownSubtrees() (run by placenodes) so the
305
+ // check stays O(1) on deep trees; walks the ancestors if it is not set yet.
306
+ export function nodeOrAncestorNotshown(node) {
307
+ if (node.notshown) return true;
308
+ if (node.notshown_ancestor !== undefined) return node.notshown_ancestor;
309
+ for (let n = node.parent; n; n = n.parent) {
310
+ if (n.notshown) return true;
311
+ }
312
+ return false;
313
+ }
314
+
315
+ // cache, on every node, whether one of its ancestors is notshown
316
+ export function markNotshownSubtrees(root) {
317
+ root.eachBefore(d => {
318
+ d.notshown_ancestor =
319
+ !!d.parent && (!!d.parent.notshown || d.parent.notshown_ancestor);
320
+ });
321
+ }
322
+
303
323
  export function hasHiddenNodes(node) {
304
324
  return node.hasHiddenNodes || false;
305
325
  }
@@ -1,5 +1,7 @@
1
1
  import { isLeafNode } from "../nodes";
2
2
 
3
+ // Default class names. Each TreeRender works on its own copy
4
+ // (this.css_classes), so this object is never mutated.
3
5
  export const css_classes = {
4
6
  "tree-container": "phylotree-container",
5
7
  "tree-scale-bar": "tree-scale-bar",
@@ -20,7 +22,7 @@ export const css_classes = {
20
22
 
21
23
  export function initializeCssClasses(classes = {}) {
22
24
  Object.keys(classes).forEach(key => {
23
- css_classes[key] = classes[key]
25
+ this.css_classes[key] = classes[key]
24
26
  })
25
27
  }
26
28
 
@@ -106,9 +106,9 @@ export function getSetMembers(setName) {
106
106
  return [];
107
107
  }
108
108
 
109
- const memberNames = this._selectionSets[setName].members;
109
+ const members = this._selectionSets[setName].members;
110
110
  return this.phylotree.nodes.descendants()
111
- .filter(node => memberNames.has(node.data.name));
111
+ .filter(node => members.has(node));
112
112
  }
113
113
 
114
114
  /**
@@ -127,7 +127,8 @@ export function addToSet(node, setName) {
127
127
  return this;
128
128
  }
129
129
 
130
- const nodeName = typeof node === "string" ? node : node.data.name;
130
+ // Membership is keyed by node identity; names are resolved here so that
131
+ // unnamed or duplicate-named nodes do not share membership.
131
132
  const nodeObj = typeof node === "string"
132
133
  ? this.phylotree.getNodeByName(node)
133
134
  : node;
@@ -135,10 +136,10 @@ export function addToSet(node, setName) {
135
136
  if (nodeObj) {
136
137
  // Remove from all other sets (mutually exclusive)
137
138
  Object.keys(this._selectionSets).forEach(otherSet => {
138
- this._selectionSets[otherSet].members.delete(nodeName);
139
+ this._selectionSets[otherSet].members.delete(nodeObj);
139
140
  });
140
141
 
141
- this._selectionSets[setName].members.add(nodeName);
142
+ this._selectionSets[setName].members.add(nodeObj);
142
143
  nodeObj._selectionSet = setName;
143
144
 
144
145
  this.emit("setChange", {
@@ -169,16 +170,13 @@ export function removeFromSet(node, setName) {
169
170
  return this;
170
171
  }
171
172
 
172
- const nodeName = typeof node === "string" ? node : node.data.name;
173
173
  const nodeObj = typeof node === "string"
174
174
  ? this.phylotree.getNodeByName(node)
175
175
  : node;
176
176
 
177
- if (this._selectionSets[setName].members.has(nodeName)) {
178
- this._selectionSets[setName].members.delete(nodeName);
179
- if (nodeObj) {
180
- delete nodeObj._selectionSet;
181
- }
177
+ if (nodeObj && this._selectionSets[setName].members.has(nodeObj)) {
178
+ this._selectionSets[setName].members.delete(nodeObj);
179
+ delete nodeObj._selectionSet;
182
180
 
183
181
  this.emit("setChange", {
184
182
  action: "remove",
@@ -204,7 +202,8 @@ export function _getSetsSummary() {
204
202
  const summary = {};
205
203
  if (this._selectionSets) {
206
204
  Object.keys(this._selectionSets).forEach(setName => {
207
- summary[setName] = Array.from(this._selectionSets[setName].members);
205
+ summary[setName] = Array.from(this._selectionSets[setName].members,
206
+ node => node.data.name);
208
207
  });
209
208
  }
210
209
  return summary;
@@ -222,7 +221,6 @@ export function handleMultiSetClick(node) {
222
221
  return;
223
222
  }
224
223
 
225
- const nodeName = node.data.name;
226
224
  const currentSet = node._selectionSet;
227
225
 
228
226
  if (currentSet === this._activeSetName) {
@@ -245,7 +243,7 @@ export function isInSet(node, setName) {
245
243
  if (!this._selectionSets || !this._selectionSets[setName]) {
246
244
  return false;
247
245
  }
248
- return this._selectionSets[setName].members.has(node.data.name);
246
+ return this._selectionSets[setName].members.has(node);
249
247
  }
250
248
 
251
249
  /**
package/src/rooting.js CHANGED
@@ -155,6 +155,9 @@ export function reroot(node, fraction) {
155
155
  // retain selection
156
156
  let selectionName = this.display.selection_attribute_name
157
157
 
158
+ // retain class names, including any set at runtime with css()
159
+ options["css-classes"] = Object.assign({}, this.display.css_classes);
160
+
158
161
  delete this.display;
159
162
 
160
163
  let rendered_tree = this.render(options);