phylotree 2.5.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/README.md +1 -1
- package/dist/phylotree-menus.css +93 -0
- package/dist/phylotree.d.ts +475 -238
- package/dist/phylotree.js +3136 -801
- package/dist/phylotree.min.js +1 -1
- package/package.json +22 -13
- package/src/render/clades.js +5 -2
- package/src/render/draw.js +73 -34
- package/src/render/edges.js +5 -5
- package/src/render/events.js +20 -3
- package/src/render/menus.js +27 -4
- package/src/render/nodes.js +43 -12
- package/src/render/options.js +9 -1
- package/src/render/selection-sets.js +12 -14
- package/src/render/unrooted.js +157 -0
- package/src/rooting.js +3 -0
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phylotree",
|
|
3
|
-
"version": "2.
|
|
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,45 +26,51 @@
|
|
|
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.
|
|
33
|
+
"fast-xml-parser": "^5.7.0",
|
|
30
34
|
"jquery": "^3.7.1",
|
|
31
|
-
"lodash": "^4.
|
|
35
|
+
"lodash": "^4.18.1",
|
|
32
36
|
"moment": "^2.30.1",
|
|
33
37
|
"pretty-data": "^0.40.0",
|
|
34
|
-
"underscore": "^1.13.
|
|
38
|
+
"underscore": "^1.13.8",
|
|
35
39
|
"winston": "^3.17.0"
|
|
36
40
|
},
|
|
37
41
|
"devDependencies": {
|
|
42
|
+
"@eslint/js": "^9.39.0",
|
|
38
43
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
39
44
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
40
45
|
"@rollup/plugin-terser": "^0.4.4",
|
|
41
46
|
"concurrently": "^9.2.0",
|
|
42
|
-
"@eslint/js": "^9.39.0",
|
|
43
47
|
"eslint": "^9.39.0",
|
|
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.
|
|
53
|
+
"rollup": "^4.59.0",
|
|
49
54
|
"rollup-plugin-copy": "^3.5.0",
|
|
50
|
-
"
|
|
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
|
|
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
|
|
58
|
-
"
|
|
59
|
-
"docs:
|
|
60
|
-
"docs:
|
|
61
|
-
"
|
|
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",
|
package/src/render/clades.js
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
package/src/render/draw.js
CHANGED
|
@@ -3,13 +3,14 @@ import * as _ from "underscore";
|
|
|
3
3
|
|
|
4
4
|
import { drawArc, cartesianToPolar, arcSegmentPlacer } from "./radial";
|
|
5
5
|
import { default as draw_line, lineSegmentPlacer } from "./cartesian";
|
|
6
|
+
import { computeUnrootedLayout, drawUnrootedEdge, unrootedSegmentPlacer } from "./unrooted";
|
|
6
7
|
import { isLeafNode } from "../nodes";
|
|
7
8
|
import { xCoord, yCoord } from "./coordinates";
|
|
8
9
|
import * as clades from "./clades";
|
|
9
10
|
import * as render_nodes from "./nodes";
|
|
10
11
|
import * as render_edges from "./edges";
|
|
11
12
|
import * as events from "./events";
|
|
12
|
-
import { css_classes
|
|
13
|
+
import { css_classes } from "./options";
|
|
13
14
|
import * as opt from "./options";
|
|
14
15
|
import * as menus from "./menus";
|
|
15
16
|
import * as eventEmitter from "./event-emitter";
|
|
@@ -24,8 +25,7 @@ function constant(x) {
|
|
|
24
25
|
|
|
25
26
|
class TreeRender {
|
|
26
27
|
constructor(phylotree, options = {}) {
|
|
27
|
-
|
|
28
|
-
this.css_classes = css_classes;
|
|
28
|
+
this.css_classes = Object.assign({}, css_classes, options["css-classes"]);
|
|
29
29
|
this.phylotree = phylotree;
|
|
30
30
|
this.container = options.container;
|
|
31
31
|
this.separation = function(_node, _previous) {
|
|
@@ -84,6 +84,7 @@ class TreeRender {
|
|
|
84
84
|
"bubble-styler": this.radius_pad_for_bubbles,
|
|
85
85
|
"binary-selectable": false,
|
|
86
86
|
"is-radial": false,
|
|
87
|
+
"is-unrooted": false,
|
|
87
88
|
"attribute-list": [],
|
|
88
89
|
"max-radius": 768,
|
|
89
90
|
"annular-limit": 0.38196601125010515,
|
|
@@ -326,7 +327,7 @@ class TreeRender {
|
|
|
326
327
|
let node_id = 0;
|
|
327
328
|
|
|
328
329
|
let enclosure = this.svg
|
|
329
|
-
.selectAll("." + css_classes["tree-container"])
|
|
330
|
+
.selectAll("." + this.css_classes["tree-container"])
|
|
330
331
|
.data([0]);
|
|
331
332
|
|
|
332
333
|
// Store base transform for composition with zoom
|
|
@@ -338,7 +339,7 @@ class TreeRender {
|
|
|
338
339
|
enclosure = enclosure
|
|
339
340
|
.enter()
|
|
340
341
|
.append("g")
|
|
341
|
-
.attr("class", css_classes["tree-container"])
|
|
342
|
+
.attr("class", this.css_classes["tree-container"])
|
|
342
343
|
.merge(enclosure)
|
|
343
344
|
.attr("transform", d => {
|
|
344
345
|
// Compose base transform with current zoom transform if present
|
|
@@ -354,13 +355,13 @@ class TreeRender {
|
|
|
354
355
|
|
|
355
356
|
if (this.draw_scale_bar) {
|
|
356
357
|
let scale_bar = this.svg
|
|
357
|
-
.selectAll("." + css_classes["tree-scale-bar"])
|
|
358
|
+
.selectAll("." + this.css_classes["tree-scale-bar"])
|
|
358
359
|
.data([0]);
|
|
359
360
|
|
|
360
361
|
scale_bar
|
|
361
362
|
.enter()
|
|
362
363
|
.append("g")
|
|
363
|
-
.attr("class", css_classes["tree-scale-bar"])
|
|
364
|
+
.attr("class", this.css_classes["tree-scale-bar"])
|
|
364
365
|
.style("font-size", this.ensure_size_is_in_px(this.scale_bar_font_size))
|
|
365
366
|
.merge(scale_bar)
|
|
366
367
|
.attr("transform", d => {
|
|
@@ -373,17 +374,17 @@ class TreeRender {
|
|
|
373
374
|
|
|
374
375
|
scale_bar.selectAll("text").style("text-anchor", "end");
|
|
375
376
|
} else {
|
|
376
|
-
this.svg.selectAll("." + css_classes["tree-scale-bar"]).remove();
|
|
377
|
+
this.svg.selectAll("." + this.css_classes["tree-scale-bar"]).remove();
|
|
377
378
|
}
|
|
378
379
|
|
|
379
380
|
enclosure = this.svg
|
|
380
|
-
.selectAll("." + css_classes["tree-container"])
|
|
381
|
+
.selectAll("." + this.css_classes["tree-container"])
|
|
381
382
|
.data([0]);
|
|
382
383
|
|
|
383
384
|
this.updateCollapsedClades(transitions);
|
|
384
385
|
|
|
385
386
|
let drawn_links = enclosure
|
|
386
|
-
.selectAll(render_edges.edgeCssSelectors(css_classes))
|
|
387
|
+
.selectAll(render_edges.edgeCssSelectors(this.css_classes))
|
|
387
388
|
.data(this.links.filter(render_edges.edgeVisible), d => {
|
|
388
389
|
return d.target.id || (d.target.id = ++node_id);
|
|
389
390
|
});
|
|
@@ -403,7 +404,7 @@ class TreeRender {
|
|
|
403
404
|
});
|
|
404
405
|
|
|
405
406
|
let drawn_nodes = enclosure
|
|
406
|
-
.selectAll(render_nodes.nodeCssSelectors(css_classes))
|
|
407
|
+
.selectAll(render_nodes.nodeCssSelectors(this.css_classes))
|
|
407
408
|
.data(
|
|
408
409
|
this.phylotree.nodes.descendants().filter(render_nodes.nodeVisible),
|
|
409
410
|
d => {
|
|
@@ -416,8 +417,8 @@ class TreeRender {
|
|
|
416
417
|
drawn_nodes = drawn_nodes
|
|
417
418
|
.enter()
|
|
418
419
|
.append("g")
|
|
419
|
-
.attr("class", this.reclassNode)
|
|
420
420
|
.merge(drawn_nodes)
|
|
421
|
+
.attr("class", d => this.reclassNode(d))
|
|
421
422
|
.attr("transform", d => {
|
|
422
423
|
const should_shift =
|
|
423
424
|
this.options["layout"] == "right-to-left" && isLeafNode(d);
|
|
@@ -449,11 +450,11 @@ class TreeRender {
|
|
|
449
450
|
|
|
450
451
|
if (this.options["brush"]) {
|
|
451
452
|
var brush = enclosure
|
|
452
|
-
.selectAll("." + css_classes["tree-selection-brush"])
|
|
453
|
+
.selectAll("." + this.css_classes["tree-selection-brush"])
|
|
453
454
|
.data([0])
|
|
454
455
|
.enter()
|
|
455
456
|
.insert("g", ":first-child")
|
|
456
|
-
.attr("class", css_classes["tree-selection-brush"]);
|
|
457
|
+
.attr("class", this.css_classes["tree-selection-brush"]);
|
|
457
458
|
|
|
458
459
|
var brush_object = d3
|
|
459
460
|
.brush()
|
|
@@ -516,10 +517,10 @@ class TreeRender {
|
|
|
516
517
|
const composedTransform = `translate(${zt.x + this.baseTransform.x * zt.k}, ${zt.y + this.baseTransform.y * zt.k}) scale(${zt.k})`;
|
|
517
518
|
|
|
518
519
|
// Use this.svg.select() to target only this tree instance (not global d3.select)
|
|
519
|
-
this.svg.select("." + css_classes["tree-container"]).attr("transform", composedTransform);
|
|
520
|
+
this.svg.select("." + this.css_classes["tree-container"]).attr("transform", composedTransform);
|
|
520
521
|
|
|
521
522
|
// Apply same transform to scale bar
|
|
522
|
-
this.svg.select("." + css_classes["tree-scale-bar"]).attr("transform", d => {
|
|
523
|
+
this.svg.select("." + this.css_classes["tree-scale-bar"]).attr("transform", d => {
|
|
523
524
|
return `translate(${zt.x + this.baseTransform.x * zt.k}, ${zt.y + (this.baseTransform.y - 10) * zt.k}) scale(${zt.k})`;
|
|
524
525
|
});
|
|
525
526
|
});
|
|
@@ -826,6 +827,8 @@ class TreeRender {
|
|
|
826
827
|
* @returns The current ``phylotree``.
|
|
827
828
|
*/
|
|
828
829
|
placenodes() {
|
|
830
|
+
render_nodes.markNotshownSubtrees(this.phylotree.nodes);
|
|
831
|
+
|
|
829
832
|
this._extents = [
|
|
830
833
|
[0, 0],
|
|
831
834
|
[0, 0]
|
|
@@ -884,7 +887,42 @@ class TreeRender {
|
|
|
884
887
|
|
|
885
888
|
this.shown_font_size = Math.min(this.font_size, this.scales[0]);
|
|
886
889
|
|
|
887
|
-
if (this.
|
|
890
|
+
if (this.unrooted()) {
|
|
891
|
+
// Unrooted (equal-angle) layout
|
|
892
|
+
//
|
|
893
|
+
// For unrooted, there's no meaningful horizontal vs vertical axis.
|
|
894
|
+
// Both spacing buttons grow the canvas uniformly. Each click beyond
|
|
895
|
+
// the default adds pixels in both dimensions.
|
|
896
|
+
let pixelsPerClick = 40;
|
|
897
|
+
let deltaV = this.fixed_width[0] - 14; // clicks from default vertical
|
|
898
|
+
let deltaH = this.fixed_width[1] - 30; // clicks from default horizontal
|
|
899
|
+
let extraPx = (deltaV + deltaH) * pixelsPerClick;
|
|
900
|
+
|
|
901
|
+
let availWidth = this.width + extraPx;
|
|
902
|
+
let availHeight = this.height + extraPx;
|
|
903
|
+
if (availWidth < 100) availWidth = 100;
|
|
904
|
+
if (availHeight < 100) availHeight = 100;
|
|
905
|
+
|
|
906
|
+
// Reserve space for labels on all sides
|
|
907
|
+
this.shown_font_size = this.font_size;
|
|
908
|
+
this.label_width = this._label_width(this.shown_font_size);
|
|
909
|
+
let labelPad = this.label_width + this.shown_font_size;
|
|
910
|
+
|
|
911
|
+
computeUnrootedLayout(
|
|
912
|
+
this.phylotree.nodes,
|
|
913
|
+
this.scales,
|
|
914
|
+
availWidth,
|
|
915
|
+
availHeight,
|
|
916
|
+
labelPad
|
|
917
|
+
);
|
|
918
|
+
|
|
919
|
+
// Set size so resizeSvg sizes the SVG to fit the tree
|
|
920
|
+
this.size = [availHeight, availWidth];
|
|
921
|
+
|
|
922
|
+
this.draw_branch = drawUnrootedEdge;
|
|
923
|
+
this.edge_placer = unrootedSegmentPlacer;
|
|
924
|
+
this.draw_scale_bar = null;
|
|
925
|
+
} else if (this.radial()) {
|
|
888
926
|
// map the nodes to polar coordinates
|
|
889
927
|
this.draw_branch = _.partial(drawArc, this.radial_center);
|
|
890
928
|
this.edge_placer = arcSegmentPlacer;
|
|
@@ -908,7 +946,12 @@ class TreeRender {
|
|
|
908
946
|
|
|
909
947
|
let max_r = 0;
|
|
910
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
|
+
|
|
911
953
|
this.phylotree.nodes.each(d => {
|
|
954
|
+
if (!shown(d)) return;
|
|
912
955
|
let my_circ_position = d.x * this.scales[0];
|
|
913
956
|
d.angle = (2 * Math.PI * my_circ_position) / effective_span;
|
|
914
957
|
d.text_angle = d.angle - Math.PI / 2;
|
|
@@ -920,6 +963,7 @@ class TreeRender {
|
|
|
920
963
|
this.do_lr(at_least_one_dimension_fixed);
|
|
921
964
|
|
|
922
965
|
this.phylotree.nodes.each(d => {
|
|
966
|
+
if (!shown(d)) return;
|
|
923
967
|
d.radius = (d.y * this.scales[1]) / this.size[1];
|
|
924
968
|
max_r = Math.max(d.radius, max_r);
|
|
925
969
|
});
|
|
@@ -927,7 +971,7 @@ class TreeRender {
|
|
|
927
971
|
let annular_shift = 0;
|
|
928
972
|
|
|
929
973
|
this.phylotree.nodes.each(d => {
|
|
930
|
-
if (!d.children) {
|
|
974
|
+
if (!d.children && shown(d)) {
|
|
931
975
|
let my_circ_position = d.x * this.scales[0];
|
|
932
976
|
if (last_child_angle !== null) {
|
|
933
977
|
let required_spacing = my_circ_position - last_circ_position,
|
|
@@ -999,6 +1043,7 @@ class TreeRender {
|
|
|
999
1043
|
}
|
|
1000
1044
|
|
|
1001
1045
|
this.phylotree.nodes.each(d => {
|
|
1046
|
+
if (!shown(d)) return;
|
|
1002
1047
|
cartesianToPolar(
|
|
1003
1048
|
d,
|
|
1004
1049
|
this.radius,
|
|
@@ -1066,6 +1111,9 @@ class TreeRender {
|
|
|
1066
1111
|
this.right_most_leaf = 0;
|
|
1067
1112
|
|
|
1068
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;
|
|
1069
1117
|
|
|
1070
1118
|
d.x *= this.scales[0];
|
|
1071
1119
|
d.y *= this.scales[1]*.8;
|
|
@@ -1281,9 +1329,9 @@ class TreeRender {
|
|
|
1281
1329
|
return this.css(arg);
|
|
1282
1330
|
}
|
|
1283
1331
|
|
|
1284
|
-
for (var key in css_classes) {
|
|
1285
|
-
if (key in opt && opt[key] != css_classes[key]) {
|
|
1286
|
-
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];
|
|
1287
1335
|
}
|
|
1288
1336
|
}
|
|
1289
1337
|
|
|
@@ -1315,7 +1363,7 @@ class TreeRender {
|
|
|
1315
1363
|
|
|
1316
1364
|
let do_update = false;
|
|
1317
1365
|
|
|
1318
|
-
for (var key in css_classes) {
|
|
1366
|
+
for (var key in this.css_classes) {
|
|
1319
1367
|
if (key in opt && opt[key] != this.css_classes[key]) {
|
|
1320
1368
|
do_update = true;
|
|
1321
1369
|
this.css_classes[key] = opt[key];
|
|
@@ -1371,20 +1419,11 @@ class TreeRender {
|
|
|
1371
1419
|
.attr("class", this.reclassEdge.bind(this));
|
|
1372
1420
|
|
|
1373
1421
|
if (this.edge_styler) {
|
|
1374
|
-
|
|
1375
|
-
|
|
1422
|
+
let self = this;
|
|
1423
|
+
edges.each(function(d) {
|
|
1424
|
+
self.edge_styler(d3.select(this), d);
|
|
1376
1425
|
});
|
|
1377
1426
|
}
|
|
1378
|
-
|
|
1379
|
-
//let nodes = this.enclosure
|
|
1380
|
-
// .selectAll(inspector.nodeCssSelectors(this.css_classes))
|
|
1381
|
-
// .attr("class", this.phylotree.reclassNode);
|
|
1382
|
-
|
|
1383
|
-
//if (this.node_styler) {
|
|
1384
|
-
// nodes.each(function(d) {
|
|
1385
|
-
// this.node_styler(d3.select(this), d);
|
|
1386
|
-
// });
|
|
1387
|
-
//}
|
|
1388
1427
|
}
|
|
1389
1428
|
|
|
1390
1429
|
return this;
|
package/src/render/edges.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as d3 from "d3";
|
|
2
2
|
import { itemTagged, itemSelected } from "./helpers";
|
|
3
|
-
import {
|
|
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
|
|
131
|
+
return !(edge.target.hidden || nodeOrAncestorNotshown(edge.target));
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
export function edgeCssSelectors(css_classes) {
|
package/src/render/events.js
CHANGED
|
@@ -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
|
|
|
@@ -41,7 +40,25 @@ export function resizeSvg(tree, svg, tr) {
|
|
|
41
40
|
|
|
42
41
|
let sizes = this.size;
|
|
43
42
|
|
|
44
|
-
if (this.
|
|
43
|
+
if (this.unrooted()) {
|
|
44
|
+
// Unrooted layout: use the computed size (may differ from initial width/height
|
|
45
|
+
// due to spacing button scaling)
|
|
46
|
+
this.baseTransform = { x: 0, y: 0 };
|
|
47
|
+
|
|
48
|
+
if (svg) {
|
|
49
|
+
let transform;
|
|
50
|
+
if (this.currentZoomTransform && this.options["zoom"]) {
|
|
51
|
+
const zt = this.currentZoomTransform;
|
|
52
|
+
transform = `translate(${zt.x}, ${zt.y}) scale(${zt.k})`;
|
|
53
|
+
} else {
|
|
54
|
+
transform = "translate(0,0)";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
svg
|
|
58
|
+
.selectAll("." + this.css_classes["tree-container"])
|
|
59
|
+
.attr("transform", transform);
|
|
60
|
+
}
|
|
61
|
+
} else if (this.radial()) {
|
|
45
62
|
let pad_radius = this.pad_width(),
|
|
46
63
|
vertical_offset =
|
|
47
64
|
this.options["top-bottom-spacing"] != "fit-to-size"
|
|
@@ -70,7 +87,7 @@ export function resizeSvg(tree, svg, tr) {
|
|
|
70
87
|
}
|
|
71
88
|
|
|
72
89
|
svg
|
|
73
|
-
.selectAll("." + css_classes["tree-container"])
|
|
90
|
+
.selectAll("." + this.css_classes["tree-container"])
|
|
74
91
|
.attr("transform", transform);
|
|
75
92
|
}
|
|
76
93
|
} else {
|
package/src/render/menus.js
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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;
|
package/src/render/nodes.js
CHANGED
|
@@ -2,10 +2,14 @@ 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
|
|
|
8
|
+
if (this.unrooted()) {
|
|
9
|
+
// No tip alignment for unrooted layout
|
|
10
|
+
return [0, 0];
|
|
11
|
+
}
|
|
12
|
+
|
|
9
13
|
if (this.radial()) {
|
|
10
14
|
return [
|
|
11
15
|
(d.text_align == "end" ? -1 : 1) *
|
|
@@ -60,7 +64,15 @@ export function drawNode(container, node, transitions) {
|
|
|
60
64
|
return this.ensure_size_is_in_px(this.shown_font_size);
|
|
61
65
|
});
|
|
62
66
|
|
|
63
|
-
if (this.
|
|
67
|
+
if (this.unrooted()) {
|
|
68
|
+
labels = labels
|
|
69
|
+
.attr("transform", d => {
|
|
70
|
+
return this.d3PhylotreeSvgRotate(d.text_angle);
|
|
71
|
+
})
|
|
72
|
+
.attr("text-anchor", d => {
|
|
73
|
+
return d.text_align;
|
|
74
|
+
});
|
|
75
|
+
} else if (this.radial()) {
|
|
64
76
|
labels = labels
|
|
65
77
|
.attr("transform", d => {
|
|
66
78
|
return (
|
|
@@ -153,8 +165,7 @@ export function drawNode(container, node, transitions) {
|
|
|
153
165
|
if (this.shown_font_size >= 5) {
|
|
154
166
|
const isRTL = this.options["layout"] == "right-to-left";
|
|
155
167
|
labels = labels.attr("dx", d => {
|
|
156
|
-
|
|
157
|
-
const direction = this.radial()
|
|
168
|
+
const direction = (this.radial() || this.unrooted())
|
|
158
169
|
? (d.text_align == "end" ? -1 : 1)
|
|
159
170
|
: (isRTL ? -1 : 1);
|
|
160
171
|
return direction * ((this.alignTips() ? 0 : shift) + this.shown_font_size * 0.33);
|
|
@@ -164,8 +175,7 @@ export function drawNode(container, node, transitions) {
|
|
|
164
175
|
if (this.shown_font_size >= 5) {
|
|
165
176
|
const isRTL = this.options["layout"] == "right-to-left";
|
|
166
177
|
labels = labels.attr("dx", d => { // eslint-disable-line
|
|
167
|
-
|
|
168
|
-
const direction = this.radial()
|
|
178
|
+
const direction = (this.radial() || this.unrooted())
|
|
169
179
|
? (d.text_align == "end" ? -1 : 1)
|
|
170
180
|
: (isRTL ? -1 : 1);
|
|
171
181
|
return direction * this.shown_font_size * 0.33;
|
|
@@ -260,35 +270,56 @@ export function nodeSpan(attr) {
|
|
|
260
270
|
|
|
261
271
|
export function reclassNode(node) {
|
|
262
272
|
|
|
263
|
-
let class_var = css_classes[isLeafNode(node) ? "node" : "internal-node"];
|
|
273
|
+
let class_var = this.css_classes[isLeafNode(node) ? "node" : "internal-node"];
|
|
264
274
|
|
|
265
275
|
if (itemTagged(node)) {
|
|
266
|
-
class_var += " " + css_classes["tagged-node"];
|
|
276
|
+
class_var += " " + this.css_classes["tagged-node"];
|
|
267
277
|
}
|
|
268
278
|
|
|
269
279
|
if (itemSelected(node, this.selection_attribute_name)) {
|
|
270
|
-
class_var += " " + css_classes["selected-node"];
|
|
280
|
+
class_var += " " + this.css_classes["selected-node"];
|
|
271
281
|
}
|
|
272
282
|
|
|
273
283
|
if (!node["parent"]) {
|
|
274
|
-
class_var += " " + css_classes["root-node"];
|
|
284
|
+
class_var += " " + this.css_classes["root-node"];
|
|
275
285
|
}
|
|
276
286
|
|
|
277
287
|
if (isNodeCollapsed(node) || hasHiddenNodes(node)) {
|
|
278
|
-
class_var += " " + css_classes["collapsed-node"];
|
|
288
|
+
class_var += " " + this.css_classes["collapsed-node"];
|
|
279
289
|
}
|
|
280
290
|
|
|
281
291
|
return class_var;
|
|
282
292
|
}
|
|
283
293
|
|
|
284
294
|
export function nodeVisible(node) {
|
|
285
|
-
return !(node.hidden || node
|
|
295
|
+
return !(node.hidden || nodeOrAncestorNotshown(node));
|
|
286
296
|
}
|
|
287
297
|
|
|
288
298
|
export function nodeNotshown(node) {
|
|
289
299
|
return node.notshown;
|
|
290
300
|
}
|
|
291
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
|
+
|
|
292
323
|
export function hasHiddenNodes(node) {
|
|
293
324
|
return node.hasHiddenNodes || false;
|
|
294
325
|
}
|
package/src/render/options.js
CHANGED
|
@@ -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
|
|
|
@@ -36,6 +38,12 @@ export function radial(attr) {
|
|
|
36
38
|
return this;
|
|
37
39
|
}
|
|
38
40
|
|
|
41
|
+
export function unrooted(attr) {
|
|
42
|
+
if (!arguments.length) return this.options["is-unrooted"];
|
|
43
|
+
this.options["is-unrooted"] = attr;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
|
|
39
47
|
export function alignTips(attr) {
|
|
40
48
|
if (!arguments.length) return this.options["align-tips"];
|
|
41
49
|
this.options["align-tips"] = attr;
|