phylotree 2.6.0 → 2.7.0
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 +49 -5
- package/bin/phylotree-neighbor-join.js +4 -5
- package/bin/root-to-tip.js +1 -1
- package/bin/tip-date-extractor.js +26 -18
- package/dist/phylotree-menus.css +93 -0
- package/dist/phylotree.d.ts +509 -241
- package/dist/phylotree.js +5023 -1515
- package/dist/phylotree.min.js +1 -1
- package/package.json +25 -27
- package/src/branches.js +58 -34
- package/src/clustering/cluster-picker.js +18 -2
- package/src/clustering/phylopart.js +14 -6
- package/src/export.js +1 -1
- package/src/extract-dates.js +3 -3
- package/src/formats/beast.js +5 -1
- package/src/formats/newick.js +43 -7
- package/src/formats/nexml.js +87 -30
- package/src/formats/nexus.js +112 -32
- package/src/formats/phyloxml.js +74 -15
- package/src/formats/registry.js +5 -1
- package/src/index.js +1 -0
- package/src/main.js +76 -25
- package/src/metrics/center-of-tree.js +4 -2
- package/src/metrics/compute-midpoint.js +7 -1
- package/src/metrics/pairwise-distances.js +4 -2
- package/src/metrics/root-to-tip.js +43 -10
- package/src/metrics/sackins.js +7 -1
- package/src/msa-parsers/fasta.js +9 -12
- package/src/neighbor-join.js +107 -75
- package/src/nodes.js +43 -31
- package/src/render/clades.js +16 -4
- package/src/render/draw.js +128 -86
- package/src/render/edges.js +17 -8
- package/src/render/events.js +2 -3
- package/src/render/menus.js +110 -10
- package/src/render/nodes.js +42 -16
- package/src/render/options.js +3 -1
- package/src/render/selection-sets.js +30 -14
- package/src/render/unrooted.js +90 -12
- package/src/rooting.js +12 -3
- package/src/traversal.js +4 -3
package/src/render/draw.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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) {
|
|
@@ -103,6 +102,7 @@ class TreeRender {
|
|
|
103
102
|
"label-nodes-with-name": false,
|
|
104
103
|
zoom: false,
|
|
105
104
|
"show-menu": true,
|
|
105
|
+
"menu-trigger": "click",
|
|
106
106
|
"show-labels": true,
|
|
107
107
|
"node-styler": null,
|
|
108
108
|
"edge-styler": null,
|
|
@@ -143,16 +143,14 @@ class TreeRender {
|
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
this.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
.reduce(function(p, c) {
|
|
153
|
-
return Math.min(c, p || 1e200);
|
|
154
|
-
}, null) || 1;
|
|
146
|
+
const spans = this.phylotree.nodes
|
|
147
|
+
.descendants()
|
|
148
|
+
.filter(d => isLeafNode(d) || this.showInternalName(d))
|
|
149
|
+
.map(d => this.nodeSpan(d))
|
|
150
|
+
.filter(v => typeof v === "number" && isFinite(v) && v > 0);
|
|
151
|
+
this.rescale_nodeSpan = spans.length ? Math.min(...spans) : 1;
|
|
155
152
|
|
|
153
|
+
this.undef_BL = false;
|
|
156
154
|
this.initialize_svg(this.container);
|
|
157
155
|
this.links = this.phylotree.nodes.links();
|
|
158
156
|
this.initializeEdgeLabels();
|
|
@@ -161,6 +159,7 @@ class TreeRender {
|
|
|
161
159
|
|
|
162
160
|
// Initialize multi-set selection if configured
|
|
163
161
|
if (this.options["selection-mode"] === "multi-set" &&
|
|
162
|
+
Array.isArray(this.options["selection-sets"]) &&
|
|
164
163
|
this.options["selection-sets"].length > 0) {
|
|
165
164
|
this.initializeSelectionSets(this.options["selection-sets"]);
|
|
166
165
|
}
|
|
@@ -175,15 +174,22 @@ class TreeRender {
|
|
|
175
174
|
*/
|
|
176
175
|
applyInitialSelection() {
|
|
177
176
|
// Single selection mode
|
|
178
|
-
if (this.options["initial-selection"] &&
|
|
177
|
+
if (Array.isArray(this.options["initial-selection"]) &&
|
|
179
178
|
this.options["initial-selection"].length > 0) {
|
|
180
179
|
this.selectNodes(this.options["initial-selection"]);
|
|
181
180
|
}
|
|
182
181
|
|
|
183
182
|
// Multi-set mode
|
|
184
183
|
if (this.options["selection-mode"] === "multi-set" &&
|
|
185
|
-
this.options["initial-sets"]
|
|
184
|
+
this.options["initial-sets"] &&
|
|
185
|
+
typeof this.options["initial-sets"] === "object" &&
|
|
186
|
+
!Array.isArray(this.options["initial-sets"]) &&
|
|
187
|
+
this._selectionSets &&
|
|
188
|
+
!this.phylotree.__initialSetsApplied) {
|
|
189
|
+
// applied once per tree, and only once a requested set is defined
|
|
186
190
|
Object.entries(this.options["initial-sets"]).forEach(([setName, nodeNames]) => {
|
|
191
|
+
if (!Array.isArray(nodeNames) || !this._selectionSets[setName]) return;
|
|
192
|
+
this.phylotree.__initialSetsApplied = true;
|
|
187
193
|
nodeNames.forEach(nodeName => {
|
|
188
194
|
this.addToSet(nodeName, setName);
|
|
189
195
|
});
|
|
@@ -280,13 +286,21 @@ class TreeRender {
|
|
|
280
286
|
this.svg.append("defs");
|
|
281
287
|
}
|
|
282
288
|
|
|
283
|
-
d3.select(this.container)
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
289
|
+
d3.select(this.container)
|
|
290
|
+
.on(
|
|
291
|
+
"click",
|
|
292
|
+
d => {
|
|
293
|
+
this.handle_node_click(null);
|
|
294
|
+
},
|
|
295
|
+
true
|
|
296
|
+
)
|
|
297
|
+
.on(
|
|
298
|
+
"contextmenu",
|
|
299
|
+
d => {
|
|
300
|
+
if (this.menuOpensOn("contextmenu")) this.handle_node_click(null);
|
|
301
|
+
},
|
|
302
|
+
true
|
|
303
|
+
);
|
|
290
304
|
}
|
|
291
305
|
|
|
292
306
|
return this;
|
|
@@ -317,6 +331,9 @@ class TreeRender {
|
|
|
317
331
|
|
|
318
332
|
//if (!this.svg) return this;
|
|
319
333
|
|
|
334
|
+
// the topology may have changed since the last update
|
|
335
|
+
this.links = this.phylotree.nodes.links();
|
|
336
|
+
|
|
320
337
|
this.placenodes();
|
|
321
338
|
|
|
322
339
|
// Sync edge labels BEFORE drawing edges so that edge.selected reflects node.selected
|
|
@@ -328,7 +345,7 @@ class TreeRender {
|
|
|
328
345
|
let node_id = 0;
|
|
329
346
|
|
|
330
347
|
let enclosure = this.svg
|
|
331
|
-
.selectAll("." + css_classes["tree-container"])
|
|
348
|
+
.selectAll("." + this.css_classes["tree-container"])
|
|
332
349
|
.data([0]);
|
|
333
350
|
|
|
334
351
|
// Store base transform for composition with zoom
|
|
@@ -337,10 +354,10 @@ class TreeRender {
|
|
|
337
354
|
y: this.pad_height()
|
|
338
355
|
};
|
|
339
356
|
|
|
340
|
-
enclosure
|
|
357
|
+
enclosure
|
|
341
358
|
.enter()
|
|
342
359
|
.append("g")
|
|
343
|
-
.attr("class", css_classes["tree-container"])
|
|
360
|
+
.attr("class", this.css_classes["tree-container"])
|
|
344
361
|
.merge(enclosure)
|
|
345
362
|
.attr("transform", d => {
|
|
346
363
|
// Compose base transform with current zoom transform if present
|
|
@@ -356,13 +373,13 @@ class TreeRender {
|
|
|
356
373
|
|
|
357
374
|
if (this.draw_scale_bar) {
|
|
358
375
|
let scale_bar = this.svg
|
|
359
|
-
.selectAll("." + css_classes["tree-scale-bar"])
|
|
376
|
+
.selectAll("." + this.css_classes["tree-scale-bar"])
|
|
360
377
|
.data([0]);
|
|
361
378
|
|
|
362
379
|
scale_bar
|
|
363
380
|
.enter()
|
|
364
381
|
.append("g")
|
|
365
|
-
.attr("class", css_classes["tree-scale-bar"])
|
|
382
|
+
.attr("class", this.css_classes["tree-scale-bar"])
|
|
366
383
|
.style("font-size", this.ensure_size_is_in_px(this.scale_bar_font_size))
|
|
367
384
|
.merge(scale_bar)
|
|
368
385
|
.attr("transform", d => {
|
|
@@ -375,17 +392,17 @@ class TreeRender {
|
|
|
375
392
|
|
|
376
393
|
scale_bar.selectAll("text").style("text-anchor", "end");
|
|
377
394
|
} else {
|
|
378
|
-
this.svg.selectAll("." + css_classes["tree-scale-bar"]).remove();
|
|
395
|
+
this.svg.selectAll("." + this.css_classes["tree-scale-bar"]).remove();
|
|
379
396
|
}
|
|
380
397
|
|
|
381
398
|
enclosure = this.svg
|
|
382
|
-
.selectAll("." + css_classes["tree-container"])
|
|
399
|
+
.selectAll("." + this.css_classes["tree-container"])
|
|
383
400
|
.data([0]);
|
|
384
401
|
|
|
385
402
|
this.updateCollapsedClades(transitions);
|
|
386
403
|
|
|
387
404
|
let drawn_links = enclosure
|
|
388
|
-
.selectAll(render_edges.edgeCssSelectors(css_classes))
|
|
405
|
+
.selectAll(render_edges.edgeCssSelectors(this.css_classes))
|
|
389
406
|
.data(this.links.filter(render_edges.edgeVisible), d => {
|
|
390
407
|
return d.target.id || (d.target.id = ++node_id);
|
|
391
408
|
});
|
|
@@ -396,7 +413,7 @@ class TreeRender {
|
|
|
396
413
|
drawn_links.exit().remove();
|
|
397
414
|
}
|
|
398
415
|
|
|
399
|
-
drawn_links
|
|
416
|
+
drawn_links
|
|
400
417
|
.enter()
|
|
401
418
|
.insert("path", ":first-child")
|
|
402
419
|
.merge(drawn_links)
|
|
@@ -405,7 +422,7 @@ class TreeRender {
|
|
|
405
422
|
});
|
|
406
423
|
|
|
407
424
|
let drawn_nodes = enclosure
|
|
408
|
-
.selectAll(render_nodes.nodeCssSelectors(css_classes))
|
|
425
|
+
.selectAll(render_nodes.nodeCssSelectors(this.css_classes))
|
|
409
426
|
.data(
|
|
410
427
|
this.phylotree.nodes.descendants().filter(render_nodes.nodeVisible),
|
|
411
428
|
d => {
|
|
@@ -418,8 +435,8 @@ class TreeRender {
|
|
|
418
435
|
drawn_nodes = drawn_nodes
|
|
419
436
|
.enter()
|
|
420
437
|
.append("g")
|
|
421
|
-
.attr("class", this.reclassNode)
|
|
422
438
|
.merge(drawn_nodes)
|
|
439
|
+
.attr("class", d => this.reclassNode(d))
|
|
423
440
|
.attr("transform", d => {
|
|
424
441
|
const should_shift =
|
|
425
442
|
this.options["layout"] == "right-to-left" && isLeafNode(d);
|
|
@@ -442,7 +459,7 @@ class TreeRender {
|
|
|
442
459
|
});
|
|
443
460
|
|
|
444
461
|
if (this.options["label-nodes-with-name"]) {
|
|
445
|
-
drawn_nodes
|
|
462
|
+
drawn_nodes.attr("id", d => {
|
|
446
463
|
return "node-" + d.name;
|
|
447
464
|
});
|
|
448
465
|
}
|
|
@@ -451,11 +468,11 @@ class TreeRender {
|
|
|
451
468
|
|
|
452
469
|
if (this.options["brush"]) {
|
|
453
470
|
var brush = enclosure
|
|
454
|
-
.selectAll("." + css_classes["tree-selection-brush"])
|
|
471
|
+
.selectAll("." + this.css_classes["tree-selection-brush"])
|
|
455
472
|
.data([0])
|
|
456
473
|
.enter()
|
|
457
474
|
.insert("g", ":first-child")
|
|
458
|
-
.attr("class", css_classes["tree-selection-brush"]);
|
|
475
|
+
.attr("class", this.css_classes["tree-selection-brush"]);
|
|
459
476
|
|
|
460
477
|
var brush_object = d3
|
|
461
478
|
.brush()
|
|
@@ -481,7 +498,7 @@ class TreeRender {
|
|
|
481
498
|
|
|
482
499
|
this.modifySelection(
|
|
483
500
|
|
|
484
|
-
this.
|
|
501
|
+
this.links.map(d => {
|
|
485
502
|
return d.target;
|
|
486
503
|
}),
|
|
487
504
|
"tag",
|
|
@@ -518,10 +535,10 @@ class TreeRender {
|
|
|
518
535
|
const composedTransform = `translate(${zt.x + this.baseTransform.x * zt.k}, ${zt.y + this.baseTransform.y * zt.k}) scale(${zt.k})`;
|
|
519
536
|
|
|
520
537
|
// 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);
|
|
538
|
+
this.svg.select("." + this.css_classes["tree-container"]).attr("transform", composedTransform);
|
|
522
539
|
|
|
523
540
|
// Apply same transform to scale bar
|
|
524
|
-
this.svg.select("." + css_classes["tree-scale-bar"]).attr("transform", d => {
|
|
541
|
+
this.svg.select("." + this.css_classes["tree-scale-bar"]).attr("transform", d => {
|
|
525
542
|
return `translate(${zt.x + this.baseTransform.x * zt.k}, ${zt.y + (this.baseTransform.y - 10) * zt.k}) scale(${zt.k})`;
|
|
526
543
|
});
|
|
527
544
|
});
|
|
@@ -622,8 +639,6 @@ class TreeRender {
|
|
|
622
639
|
|
|
623
640
|
*/
|
|
624
641
|
|
|
625
|
-
let undef_BL = false;
|
|
626
|
-
|
|
627
642
|
/** _extents computes a bounding box for the tree (initially NOT in screen
|
|
628
643
|
coordinates)
|
|
629
644
|
|
|
@@ -641,14 +656,15 @@ class TreeRender {
|
|
|
641
656
|
|
|
642
657
|
if (a_node["parent"]) {
|
|
643
658
|
if (this.do_scaling) {
|
|
644
|
-
if (undef_BL) {
|
|
659
|
+
if (this.undef_BL) {
|
|
645
660
|
return 0;
|
|
646
661
|
}
|
|
647
662
|
|
|
648
663
|
a_node.y = this.phylotree.branch_length_accessor(a_node);
|
|
649
664
|
|
|
650
|
-
if (typeof a_node.y
|
|
651
|
-
|
|
665
|
+
if (typeof a_node.y !== "number" || !isFinite(a_node.y)) {
|
|
666
|
+
// placenodes() falls back to an unscaled layout
|
|
667
|
+
this.undef_BL = true;
|
|
652
668
|
return 0;
|
|
653
669
|
}
|
|
654
670
|
a_node.y += a_node.parent.y;
|
|
@@ -695,15 +711,20 @@ class TreeRender {
|
|
|
695
711
|
a_node.collapsed = [[a_node.x, a_node.y]];
|
|
696
712
|
|
|
697
713
|
var map_me = n => {
|
|
714
|
+
// hidden tips have no (or stale) coordinates
|
|
715
|
+
if (render_nodes.nodeNotshown(n)) return;
|
|
716
|
+
|
|
698
717
|
n.hidden = true;
|
|
699
718
|
|
|
700
|
-
if (isLeafNode(n)) {
|
|
719
|
+
if (isLeafNode(n)) {
|
|
720
|
+
if (typeof n.x !== "number" || typeof n.y !== "number") return;
|
|
721
|
+
|
|
701
722
|
this.x = n.x =
|
|
702
723
|
this.save_x +
|
|
703
724
|
(n.x - this.save_x) * this.options["compression"] +
|
|
704
725
|
this.save_span;
|
|
705
726
|
|
|
706
|
-
a_node.collapsed.push([n.x, n.y]);
|
|
727
|
+
a_node.collapsed.push([n.x, n.y]);
|
|
707
728
|
} else {
|
|
708
729
|
n.children.map(map_me);
|
|
709
730
|
}
|
|
@@ -749,7 +770,7 @@ class TreeRender {
|
|
|
749
770
|
displayed_children++;
|
|
750
771
|
}
|
|
751
772
|
|
|
752
|
-
if (displayed_children >= half_way && !managed_to_display) {
|
|
773
|
+
if (displayed_children > 0 && displayed_children >= half_way && !managed_to_display) {
|
|
753
774
|
this._handle_single_node_layout(a_node);
|
|
754
775
|
managed_to_display = true;
|
|
755
776
|
}
|
|
@@ -792,7 +813,7 @@ class TreeRender {
|
|
|
792
813
|
|
|
793
814
|
this.scales[1] =
|
|
794
815
|
(this.size[1] - this.offsets[1] - this.options["left-offset"]) /
|
|
795
|
-
this._extents[1][1];
|
|
816
|
+
(this._extents[1][1] || 1);
|
|
796
817
|
|
|
797
818
|
this.label_width = this._label_width(this.shown_font_size);
|
|
798
819
|
|
|
@@ -802,6 +823,8 @@ class TreeRender {
|
|
|
802
823
|
} else {
|
|
803
824
|
this.label_width = this._label_width(this.shown_font_size);
|
|
804
825
|
|
|
826
|
+
// Only updates the local parameter; the caller's flag is unchanged.
|
|
827
|
+
// eslint-disable-next-line no-useless-assignment
|
|
805
828
|
at_least_one_dimension_fixed = true;
|
|
806
829
|
|
|
807
830
|
let available_width =
|
|
@@ -817,7 +840,7 @@ class TreeRender {
|
|
|
817
840
|
this.offsets[1] -
|
|
818
841
|
this.options["left-offset"] -
|
|
819
842
|
this.label_width) /
|
|
820
|
-
this._extents[1][1];
|
|
843
|
+
(this._extents[1][1] || 1);
|
|
821
844
|
}
|
|
822
845
|
}
|
|
823
846
|
|
|
@@ -828,6 +851,8 @@ class TreeRender {
|
|
|
828
851
|
* @returns The current ``phylotree``.
|
|
829
852
|
*/
|
|
830
853
|
placenodes() {
|
|
854
|
+
render_nodes.markNotshownSubtrees(this.phylotree.nodes);
|
|
855
|
+
|
|
831
856
|
this._extents = [
|
|
832
857
|
[0, 0],
|
|
833
858
|
[0, 0]
|
|
@@ -844,22 +869,21 @@ class TreeRender {
|
|
|
844
869
|
(this.save_x = this.x), (this.save_span = this.last_span * 0.5);
|
|
845
870
|
|
|
846
871
|
this.do_scaling = this.options["scaling"];
|
|
847
|
-
|
|
872
|
+
this.undef_BL = false;
|
|
848
873
|
|
|
849
874
|
this.is_under_collapsed_parent = false;
|
|
850
|
-
|
|
851
|
-
|
|
875
|
+
// tree_layout() places the nodes by depth when scaling is off
|
|
876
|
+
this.max_depth = d3.max(this.phylotree.nodes.descendants(), n => {
|
|
877
|
+
return n.depth;
|
|
878
|
+
});
|
|
879
|
+
|
|
852
880
|
// Set initial x
|
|
853
881
|
this.phylotree.nodes.x = this.tree_layout(
|
|
854
882
|
this.phylotree.nodes,
|
|
855
883
|
this.do_scaling
|
|
856
884
|
);
|
|
857
885
|
|
|
858
|
-
this.
|
|
859
|
-
return n.depth;
|
|
860
|
-
});
|
|
861
|
-
|
|
862
|
-
if (this.do_scaling && undef_BL) {
|
|
886
|
+
if (this.do_scaling && this.undef_BL) {
|
|
863
887
|
// requested scaling, but some branches had no branch lengths
|
|
864
888
|
// redo layout without branch lengths
|
|
865
889
|
this.do_scaling = false;
|
|
@@ -880,7 +904,7 @@ class TreeRender {
|
|
|
880
904
|
this.size[0] = this._extents[0][1] * this.fixed_width[0];
|
|
881
905
|
this.scales[0] = this.fixed_width[0];
|
|
882
906
|
} else {
|
|
883
|
-
this.scales[0] = (this.size[0] - this.pad_height()) / this._extents[0][1];
|
|
907
|
+
this.scales[0] = (this.size[0] - this.pad_height()) / (this._extents[0][1] || 1);
|
|
884
908
|
at_least_one_dimension_fixed = true;
|
|
885
909
|
}
|
|
886
910
|
|
|
@@ -930,7 +954,7 @@ class TreeRender {
|
|
|
930
954
|
last_circ_position = null,
|
|
931
955
|
last_child_radius = null,
|
|
932
956
|
min_radius = 0,
|
|
933
|
-
effective_span = this._extents[0][1] * this.scales[0];
|
|
957
|
+
effective_span = (this._extents[0][1] || 1) * this.scales[0];
|
|
934
958
|
|
|
935
959
|
let compute_distance = function(r1, r2, a1, a2, annular_shift) {
|
|
936
960
|
annular_shift = annular_shift || 0;
|
|
@@ -945,7 +969,12 @@ class TreeRender {
|
|
|
945
969
|
|
|
946
970
|
let max_r = 0;
|
|
947
971
|
|
|
972
|
+
// hidden (notshown) nodes and their descendants are not laid out and
|
|
973
|
+
// keep stale coordinates; leave them out of the transforms and extents
|
|
974
|
+
const shown = d => !render_nodes.nodeOrAncestorNotshown(d);
|
|
975
|
+
|
|
948
976
|
this.phylotree.nodes.each(d => {
|
|
977
|
+
if (!shown(d)) return;
|
|
949
978
|
let my_circ_position = d.x * this.scales[0];
|
|
950
979
|
d.angle = (2 * Math.PI * my_circ_position) / effective_span;
|
|
951
980
|
d.text_angle = d.angle - Math.PI / 2;
|
|
@@ -957,6 +986,7 @@ class TreeRender {
|
|
|
957
986
|
this.do_lr(at_least_one_dimension_fixed);
|
|
958
987
|
|
|
959
988
|
this.phylotree.nodes.each(d => {
|
|
989
|
+
if (!shown(d)) return;
|
|
960
990
|
d.radius = (d.y * this.scales[1]) / this.size[1];
|
|
961
991
|
max_r = Math.max(d.radius, max_r);
|
|
962
992
|
});
|
|
@@ -964,7 +994,7 @@ class TreeRender {
|
|
|
964
994
|
let annular_shift = 0;
|
|
965
995
|
|
|
966
996
|
this.phylotree.nodes.each(d => {
|
|
967
|
-
if (!d.children) {
|
|
997
|
+
if (!d.children && shown(d)) {
|
|
968
998
|
let my_circ_position = d.x * this.scales[0];
|
|
969
999
|
if (last_child_angle !== null) {
|
|
970
1000
|
let required_spacing = my_circ_position - last_circ_position,
|
|
@@ -1036,6 +1066,7 @@ class TreeRender {
|
|
|
1036
1066
|
}
|
|
1037
1067
|
|
|
1038
1068
|
this.phylotree.nodes.each(d => {
|
|
1069
|
+
if (!shown(d)) return;
|
|
1039
1070
|
cartesianToPolar(
|
|
1040
1071
|
d,
|
|
1041
1072
|
this.radius,
|
|
@@ -1059,11 +1090,15 @@ class TreeRender {
|
|
|
1059
1090
|
);
|
|
1060
1091
|
}
|
|
1061
1092
|
|
|
1062
|
-
|
|
1093
|
+
// a clade nested in a collapsed clade is not laid out: its flag is
|
|
1094
|
+
// `true` or an outline left from an earlier layout
|
|
1095
|
+
if (Array.isArray(d.collapsed) && !d.hidden) {
|
|
1063
1096
|
d.collapsed = d.collapsed.map(p => {
|
|
1064
1097
|
let z = {};
|
|
1065
1098
|
z.x = p[0];
|
|
1066
1099
|
z.y = p[1];
|
|
1100
|
+
// same radius the nodes get above: d.radius = d.y * scales[1] / size[1]
|
|
1101
|
+
z.radius = (p[1] * this.scales[1]) / this.size[1];
|
|
1067
1102
|
z = cartesianToPolar(
|
|
1068
1103
|
z,
|
|
1069
1104
|
this.radius,
|
|
@@ -1103,6 +1138,9 @@ class TreeRender {
|
|
|
1103
1138
|
this.right_most_leaf = 0;
|
|
1104
1139
|
|
|
1105
1140
|
this.phylotree.nodes.each(d => {
|
|
1141
|
+
// hidden nodes (and their descendants) are not laid out; do not
|
|
1142
|
+
// rescale their stale coordinates
|
|
1143
|
+
if (render_nodes.nodeOrAncestorNotshown(d)) return;
|
|
1106
1144
|
|
|
1107
1145
|
d.x *= this.scales[0];
|
|
1108
1146
|
d.y *= this.scales[1]*.8;
|
|
@@ -1121,10 +1159,15 @@ class TreeRender {
|
|
|
1121
1159
|
);
|
|
1122
1160
|
}
|
|
1123
1161
|
|
|
1124
|
-
if (d.collapsed) {
|
|
1162
|
+
if (Array.isArray(d.collapsed) && !d.hidden) {
|
|
1125
1163
|
d.collapsed.forEach(p => {
|
|
1126
1164
|
p[0] *= this.scales[0];
|
|
1127
1165
|
p[1] *= this.scales[1]*.8;
|
|
1166
|
+
|
|
1167
|
+
if (this.options["layout"] == "right-to-left") {
|
|
1168
|
+
// same mirroring as d.y above
|
|
1169
|
+
p[1] = this._extents[1][1] * this.scales[1] - p[1] + this.label_width;
|
|
1170
|
+
}
|
|
1128
1171
|
});
|
|
1129
1172
|
|
|
1130
1173
|
let last_x = d.collapsed[1][0];
|
|
@@ -1149,13 +1192,13 @@ class TreeRender {
|
|
|
1149
1192
|
domain_limit = Math.pow(
|
|
1150
1193
|
10,
|
|
1151
1194
|
Math.ceil(
|
|
1152
|
-
Math.log((this._extents[1][1] * range_limit) / this.radius) /
|
|
1195
|
+
Math.log(((this._extents[1][1] || 1) * range_limit) / this.radius) /
|
|
1153
1196
|
Math.log(10)
|
|
1154
1197
|
)
|
|
1155
1198
|
);
|
|
1156
1199
|
|
|
1157
1200
|
|
|
1158
|
-
range_limit = domain_limit * (this.radius / this._extents[1][1]);
|
|
1201
|
+
range_limit = domain_limit * (this.radius / (this._extents[1][1] || 1));
|
|
1159
1202
|
|
|
1160
1203
|
if (range_limit < 30) {
|
|
1161
1204
|
let stretch = Math.ceil(30 / range_limit);
|
|
@@ -1163,7 +1206,7 @@ class TreeRender {
|
|
|
1163
1206
|
domain_limit *= stretch;
|
|
1164
1207
|
}
|
|
1165
1208
|
} else {
|
|
1166
|
-
domain_limit = this._extents[1][1];
|
|
1209
|
+
domain_limit = this._extents[1][1] || 1;
|
|
1167
1210
|
|
|
1168
1211
|
range_limit =
|
|
1169
1212
|
this.size[1] - this.offsets[1] - this.options["left-offset"] - this.shown_font_size;
|
|
@@ -1286,18 +1329,26 @@ class TreeRender {
|
|
|
1286
1329
|
}
|
|
1287
1330
|
|
|
1288
1331
|
/**
|
|
1289
|
-
* Get or set font size.
|
|
1332
|
+
* Get or set the label font size.
|
|
1290
1333
|
*
|
|
1291
|
-
* @param {
|
|
1292
|
-
* @returns The current ``font_size``
|
|
1334
|
+
* @param {Number} attr (Optional) The new font size; ``undefined`` resets it to 12.
|
|
1335
|
+
* @returns The current ``font_size`` if getting, or the current ``phylotree`` if setting.
|
|
1293
1336
|
*/
|
|
1294
|
-
|
|
1337
|
+
fontSize(attr) {
|
|
1295
1338
|
if (!arguments.length) return this.font_size;
|
|
1296
1339
|
this.font_size = attr === undefined ? 12 : attr;
|
|
1340
|
+
this.shown_font_size = this.font_size;
|
|
1341
|
+
this.offsets = [0, this.font_size / 2];
|
|
1297
1342
|
return this;
|
|
1298
1343
|
}
|
|
1299
1344
|
|
|
1300
|
-
|
|
1345
|
+
/**
|
|
1346
|
+
* Get or set the scale bar font size.
|
|
1347
|
+
*
|
|
1348
|
+
* @param {Number} attr (Optional) The new font size; ``undefined`` resets it to 12.
|
|
1349
|
+
* @returns The current ``scale_bar_font_size`` if getting, or the current ``phylotree`` if setting.
|
|
1350
|
+
*/
|
|
1351
|
+
scaleBarFontSize(attr) {
|
|
1301
1352
|
if (!arguments.length) return this.scale_bar_font_size;
|
|
1302
1353
|
this.scale_bar_font_size = attr === undefined ? 12 : attr;
|
|
1303
1354
|
return this;
|
|
@@ -1318,9 +1369,9 @@ class TreeRender {
|
|
|
1318
1369
|
return this.css(arg);
|
|
1319
1370
|
}
|
|
1320
1371
|
|
|
1321
|
-
for (var key in css_classes) {
|
|
1322
|
-
if (key in opt && opt[key] != css_classes[key]) {
|
|
1323
|
-
css_classes[key] = opt[key];
|
|
1372
|
+
for (var key in this.css_classes) {
|
|
1373
|
+
if (key in opt && opt[key] != this.css_classes[key]) {
|
|
1374
|
+
this.css_classes[key] = opt[key];
|
|
1324
1375
|
}
|
|
1325
1376
|
}
|
|
1326
1377
|
|
|
@@ -1352,7 +1403,7 @@ class TreeRender {
|
|
|
1352
1403
|
|
|
1353
1404
|
let do_update = false;
|
|
1354
1405
|
|
|
1355
|
-
for (var key in css_classes) {
|
|
1406
|
+
for (var key in this.css_classes) {
|
|
1356
1407
|
if (key in opt && opt[key] != this.css_classes[key]) {
|
|
1357
1408
|
do_update = true;
|
|
1358
1409
|
this.css_classes[key] = opt[key];
|
|
@@ -1408,20 +1459,11 @@ class TreeRender {
|
|
|
1408
1459
|
.attr("class", this.reclassEdge.bind(this));
|
|
1409
1460
|
|
|
1410
1461
|
if (this.edge_styler) {
|
|
1411
|
-
|
|
1412
|
-
|
|
1462
|
+
let self = this;
|
|
1463
|
+
edges.each(function(d) {
|
|
1464
|
+
self.edge_styler(d3.select(this), d);
|
|
1413
1465
|
});
|
|
1414
1466
|
}
|
|
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
1467
|
}
|
|
1426
1468
|
|
|
1427
1469
|
return this;
|
|
@@ -1467,7 +1509,7 @@ class TreeRender {
|
|
|
1467
1509
|
*/
|
|
1468
1510
|
style_edges(attr) {
|
|
1469
1511
|
if (!arguments.length) return this.edge_styler;
|
|
1470
|
-
this.edge_styler = attr.bind(this);
|
|
1512
|
+
this.edge_styler = typeof attr === "function" ? attr.bind(this) : attr;
|
|
1471
1513
|
return this;
|
|
1472
1514
|
}
|
|
1473
1515
|
|
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
|
|
@@ -82,13 +82,22 @@ export function reclassEdge(edge) {
|
|
|
82
82
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
const reserved_annotations = [
|
|
86
|
+
"children", "data", "parent", "depth", "height", "x", "y", "collapsed",
|
|
87
|
+
"hidden", "notshown", "id", "selected", "text_angle", "text_align",
|
|
88
|
+
"radius", "angle"
|
|
89
|
+
];
|
|
90
|
+
|
|
85
91
|
export function initializeEdgeLabels() {
|
|
86
92
|
|
|
87
93
|
this.links.forEach(d => {
|
|
88
94
|
|
|
89
95
|
// TODO: Move away from storing attribute data as root (BREAKS occasionally with d3>3)
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
// Annotations named like internal hierarchy fields must not overwrite them.
|
|
97
|
+
const annotation = d.target.data.annotation;
|
|
98
|
+
if(annotation && !reserved_annotations.includes(annotation) &&
|
|
99
|
+
!(annotation in d.target && d.target[annotation] !== annotation)) {
|
|
100
|
+
d.target[annotation] = annotation;
|
|
92
101
|
}
|
|
93
102
|
|
|
94
103
|
});
|
|
@@ -128,7 +137,7 @@ export function syncEdgeLabels() {
|
|
|
128
137
|
}
|
|
129
138
|
|
|
130
139
|
export function edgeVisible(edge) {
|
|
131
|
-
return !(edge.target.hidden || edge.target
|
|
140
|
+
return !(edge.target.hidden || nodeOrAncestorNotshown(edge.target));
|
|
132
141
|
}
|
|
133
142
|
|
|
134
143
|
export function edgeCssSelectors(css_classes) {
|
|
@@ -137,7 +146,7 @@ export function edgeCssSelectors(css_classes) {
|
|
|
137
146
|
css_classes["selected-branch"],
|
|
138
147
|
css_classes["tagged-branch"]
|
|
139
148
|
].reduce(function(p, c, i, a) {
|
|
140
|
-
return
|
|
149
|
+
return p + "path." + c + (i < a.length - 1 ? "," : "");
|
|
141
150
|
}, "");
|
|
142
151
|
}
|
|
143
152
|
|
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
|
|
|
@@ -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 {
|