phylotree 2.2.1 → 2.3.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/dist/phylotree.d.ts +423 -0
- package/dist/phylotree.js +465 -289
- package/dist/phylotree.min.js +1 -1
- package/package.json +3 -4
- package/src/render/draw.js +54 -23
- package/src/render/events.js +16 -8
- package/src/render/nodes.js +35 -34
- package/src/render/options.js +1 -13
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phylotree",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"main": "dist/phylotree.js",
|
|
5
|
+
"types": "dist/phylotree.d.ts",
|
|
5
6
|
"unpkg": "dist/phylotree.js",
|
|
6
7
|
"jsdelivr": "dist/phylotree.js",
|
|
7
8
|
"module": "src/index.js",
|
|
@@ -46,9 +47,7 @@
|
|
|
46
47
|
"rollup-plugin-copy": "^3.3.0",
|
|
47
48
|
"rollup-plugin-execute": "^1.1.1",
|
|
48
49
|
"rollup-plugin-terser": "^7.0.2",
|
|
49
|
-
"rollup-watch": "^3.2.2",
|
|
50
50
|
"tape": "5.2.2",
|
|
51
|
-
"tape-watch": "^2.3.0",
|
|
52
51
|
"yarn": "^1.22.11"
|
|
53
52
|
},
|
|
54
53
|
"scripts": {
|
|
@@ -56,7 +55,6 @@
|
|
|
56
55
|
"dev": "rollup -w -c rollup.config.js",
|
|
57
56
|
"serve": "concurrently 'rollup -w -c rollup.config.js' 'http-server'",
|
|
58
57
|
"build": "rollup -c rollup.config.js",
|
|
59
|
-
"watch": "tape-watch -r source-map-support/register test/*-test.js",
|
|
60
58
|
"test": "tape -r source-map-support/register 'test/*-test.js'",
|
|
61
59
|
"docs:generate": "jsdoc2md 'src/**/*.js' > API.md",
|
|
62
60
|
"docs:validate": "jsdoc2md 'src/**/*.js' --no-cache --partial 'partials/**/*.hbs'",
|
|
@@ -67,6 +65,7 @@
|
|
|
67
65
|
"dist/phylotree.css",
|
|
68
66
|
"dist/phylotree.js",
|
|
69
67
|
"dist/phylotree.min.js",
|
|
68
|
+
"dist/phylotree.d.ts",
|
|
70
69
|
"bin",
|
|
71
70
|
"src"
|
|
72
71
|
]
|
package/src/render/draw.js
CHANGED
|
@@ -129,6 +129,10 @@ class TreeRender {
|
|
|
129
129
|
this.node_styler = this.options['node-styler'];
|
|
130
130
|
this.edge_styler = this.options['edge-styler'];
|
|
131
131
|
|
|
132
|
+
// Store zoom state to preserve across updates
|
|
133
|
+
this.currentZoomTransform = null;
|
|
134
|
+
this.baseTransform = { x: 0, y: 0 };
|
|
135
|
+
|
|
132
136
|
this.nodeSpan = this.options['node-span'];
|
|
133
137
|
|
|
134
138
|
if(!this.nodeSpan) {
|
|
@@ -313,6 +317,10 @@ class TreeRender {
|
|
|
313
317
|
|
|
314
318
|
this.placenodes();
|
|
315
319
|
|
|
320
|
+
// Sync edge labels BEFORE drawing edges so that edge.selected reflects node.selected
|
|
321
|
+
// This is critical for custom edge stylers that rely on selection state
|
|
322
|
+
this.syncEdgeLabels();
|
|
323
|
+
|
|
316
324
|
transitions = this.transitions(transitions);
|
|
317
325
|
|
|
318
326
|
let node_id = 0;
|
|
@@ -321,15 +329,26 @@ class TreeRender {
|
|
|
321
329
|
.selectAll("." + css_classes["tree-container"])
|
|
322
330
|
.data([0]);
|
|
323
331
|
|
|
332
|
+
// Store base transform for composition with zoom
|
|
333
|
+
this.baseTransform = {
|
|
334
|
+
x: this.offsets[1] + this.options["left-offset"],
|
|
335
|
+
y: this.pad_height()
|
|
336
|
+
};
|
|
337
|
+
|
|
324
338
|
enclosure = enclosure
|
|
325
339
|
.enter()
|
|
326
340
|
.append("g")
|
|
327
341
|
.attr("class", css_classes["tree-container"])
|
|
328
342
|
.merge(enclosure)
|
|
329
343
|
.attr("transform", d => {
|
|
344
|
+
// Compose base transform with current zoom transform if present
|
|
345
|
+
if (this.currentZoomTransform && this.options["zoom"]) {
|
|
346
|
+
const zt = this.currentZoomTransform;
|
|
347
|
+
return `translate(${zt.x + this.baseTransform.x * zt.k}, ${zt.y + this.baseTransform.y * zt.k}) scale(${zt.k})`;
|
|
348
|
+
}
|
|
330
349
|
return this.d3PhylotreeSvgTranslate([
|
|
331
|
-
this.
|
|
332
|
-
this.
|
|
350
|
+
this.baseTransform.x,
|
|
351
|
+
this.baseTransform.y
|
|
333
352
|
]);
|
|
334
353
|
});
|
|
335
354
|
|
|
@@ -479,29 +498,39 @@ class TreeRender {
|
|
|
479
498
|
brush.call(brush_object);
|
|
480
499
|
}
|
|
481
500
|
|
|
482
|
-
|
|
501
|
+
// Note: syncEdgeLabels() is called at the start of update() before edges are drawn
|
|
502
|
+
// to ensure selection state is synced before reclassEdge and edge_styler run
|
|
483
503
|
|
|
484
504
|
if (this.options["zoom"]) {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
.
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
505
|
+
// Create zoom behavior if not already created
|
|
506
|
+
if (!this.zoomBehavior) {
|
|
507
|
+
this.zoomBehavior = d3
|
|
508
|
+
.zoom()
|
|
509
|
+
.scaleExtent([0.1, 10])
|
|
510
|
+
.on("zoom", (event) => {
|
|
511
|
+
// Store the current zoom transform
|
|
512
|
+
this.currentZoomTransform = event.transform;
|
|
513
|
+
|
|
514
|
+
// Compose zoom transform with base transform
|
|
515
|
+
const zt = event.transform;
|
|
516
|
+
const composedTransform = `translate(${zt.x + this.baseTransform.x * zt.k}, ${zt.y + this.baseTransform.y * zt.k}) scale(${zt.k})`;
|
|
517
|
+
|
|
518
|
+
// 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
|
+
|
|
521
|
+
// Apply same transform to scale bar
|
|
522
|
+
this.svg.select("." + css_classes["tree-scale-bar"]).attr("transform", d => {
|
|
523
|
+
return `translate(${zt.x + this.baseTransform.x * zt.k}, ${zt.y + (this.baseTransform.y - 10) * zt.k}) scale(${zt.k})`;
|
|
524
|
+
});
|
|
493
525
|
});
|
|
526
|
+
}
|
|
494
527
|
|
|
495
|
-
|
|
496
|
-
d3.select("." + css_classes["tree-scale-bar"]).attr("transform", d => {
|
|
497
|
-
let toTransform = event.transform;
|
|
498
|
-
toTransform.y -= 10;
|
|
499
|
-
return toTransform;
|
|
500
|
-
});
|
|
501
|
-
|
|
502
|
-
});
|
|
528
|
+
this.svg.call(this.zoomBehavior);
|
|
503
529
|
|
|
504
|
-
|
|
530
|
+
// Restore zoom transform if we have one stored (preserves zoom across updates)
|
|
531
|
+
if (this.currentZoomTransform) {
|
|
532
|
+
this.svg.call(this.zoomBehavior.transform, this.currentZoomTransform);
|
|
533
|
+
}
|
|
505
534
|
}
|
|
506
535
|
|
|
507
536
|
// Emit rendered event
|
|
@@ -1030,7 +1059,7 @@ class TreeRender {
|
|
|
1030
1059
|
this.size[0] = this.radial_center + this.radius / scaler;
|
|
1031
1060
|
this.size[1] = this.radial_center + this.radius / scaler;
|
|
1032
1061
|
} else {
|
|
1033
|
-
this.do_lr();
|
|
1062
|
+
this.do_lr();
|
|
1034
1063
|
|
|
1035
1064
|
this.draw_branch = draw_line;
|
|
1036
1065
|
this.edge_placer = lineSegmentPlacer;
|
|
@@ -1041,8 +1070,10 @@ this.do_lr();
|
|
|
1041
1070
|
d.x *= this.scales[0];
|
|
1042
1071
|
d.y *= this.scales[1]*.8;
|
|
1043
1072
|
|
|
1044
|
-
if (this.options["layout"] == "right-to-left") {
|
|
1045
|
-
|
|
1073
|
+
if (this.options["layout"] == "right-to-left") {
|
|
1074
|
+
// For RTL, always add label_width offset to shift tree right,
|
|
1075
|
+
// creating space on the left for labels (prevents labels overlapping branches)
|
|
1076
|
+
d.y = this._extents[1][1] * this.scales[1] - d.y + this.label_width;
|
|
1046
1077
|
}
|
|
1047
1078
|
|
|
1048
1079
|
|
package/src/render/events.js
CHANGED
|
@@ -53,17 +53,25 @@ export function resizeSvg(tree, svg, tr) {
|
|
|
53
53
|
sizes[0] + 2 * pad_radius + vertical_offset
|
|
54
54
|
];
|
|
55
55
|
|
|
56
|
+
// Update base transform for radial layout
|
|
57
|
+
this.baseTransform = {
|
|
58
|
+
x: pad_radius,
|
|
59
|
+
y: pad_radius + vertical_offset
|
|
60
|
+
};
|
|
61
|
+
|
|
56
62
|
if (svg) {
|
|
63
|
+
// Compose with zoom transform if present
|
|
64
|
+
let transform;
|
|
65
|
+
if (this.currentZoomTransform && this.options["zoom"]) {
|
|
66
|
+
const zt = this.currentZoomTransform;
|
|
67
|
+
transform = `translate(${zt.x + this.baseTransform.x * zt.k}, ${zt.y + this.baseTransform.y * zt.k}) scale(${zt.k})`;
|
|
68
|
+
} else {
|
|
69
|
+
transform = "translate(" + pad_radius + "," + (pad_radius + vertical_offset) + ")";
|
|
70
|
+
}
|
|
71
|
+
|
|
57
72
|
svg
|
|
58
73
|
.selectAll("." + css_classes["tree-container"])
|
|
59
|
-
.attr(
|
|
60
|
-
"transform",
|
|
61
|
-
"translate (" +
|
|
62
|
-
pad_radius +
|
|
63
|
-
"," +
|
|
64
|
-
(pad_radius + vertical_offset) +
|
|
65
|
-
")"
|
|
66
|
-
);
|
|
74
|
+
.attr("transform", transform);
|
|
67
75
|
}
|
|
68
76
|
} else {
|
|
69
77
|
|
package/src/render/nodes.js
CHANGED
|
@@ -14,8 +14,10 @@ export function shiftTip(d) {
|
|
|
14
14
|
];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
if (this.options["right-to-left"
|
|
18
|
-
|
|
17
|
+
if (this.options["layout"] == "right-to-left") {
|
|
18
|
+
// For RTL, shift labels to align at the left edge (x=0)
|
|
19
|
+
// screen_x is the node's horizontal position; shifting by -screen_x moves label to x=0
|
|
20
|
+
return [-d.screen_x, 0];
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
return [this.right_most_leaf - d.screen_x, 0];
|
|
@@ -72,18 +74,27 @@ export function drawNode(container, node, transitions) {
|
|
|
72
74
|
return d.text_align;
|
|
73
75
|
});
|
|
74
76
|
} else {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
const isRTL = this.options["layout"] == "right-to-left";
|
|
78
|
+
labels = labels
|
|
79
|
+
.attr("text-anchor", isRTL ? "end" : "start")
|
|
80
|
+
.attr("transform", d => {
|
|
81
|
+
return this.d3PhylotreeSvgTranslate(
|
|
82
|
+
this.alignTips() ? this.shiftTip(d) : null
|
|
83
|
+
);
|
|
84
|
+
});
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
if (this.alignTips()) {
|
|
86
88
|
tracers = tracers.data([node]);
|
|
89
|
+
const isRTL = this.options["layout"] == "right-to-left";
|
|
90
|
+
|
|
91
|
+
// Determine direction multiplier for tracer start position
|
|
92
|
+
const getX1Direction = (d) => {
|
|
93
|
+
if (this.radial()) {
|
|
94
|
+
return d.text_align == "end" ? -1 : 1;
|
|
95
|
+
}
|
|
96
|
+
return isRTL ? -1 : 1;
|
|
97
|
+
};
|
|
87
98
|
|
|
88
99
|
if (transitions) {
|
|
89
100
|
tracers = tracers
|
|
@@ -92,27 +103,12 @@ export function drawNode(container, node, transitions) {
|
|
|
92
103
|
.classed(this.css_classes["branch-tracer"], true)
|
|
93
104
|
.merge(tracers)
|
|
94
105
|
.attr("x1", d => {
|
|
95
|
-
return (
|
|
96
|
-
(d.text_align == "end" ? -1 : 1) * this.nodeBubbleSize(node)
|
|
97
|
-
);
|
|
106
|
+
return getX1Direction(d) * this.nodeBubbleSize(node);
|
|
98
107
|
})
|
|
99
108
|
.attr("x2", 0)
|
|
100
109
|
.attr("y1", 0)
|
|
101
110
|
.attr("y2", 0)
|
|
102
111
|
.attr("x2", d => {
|
|
103
|
-
if (this.options["layout"] == "right-to-left") {
|
|
104
|
-
return d.screen_x;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return this.shiftTip(d)[0];
|
|
108
|
-
})
|
|
109
|
-
.attr("transform", d => {
|
|
110
|
-
return this.d3PhylotreeSvgRotate(d.text_angle);
|
|
111
|
-
})
|
|
112
|
-
.attr("x2", d => {
|
|
113
|
-
if (this.options["layout"] == "right-to-left") {
|
|
114
|
-
return d.screen_x;
|
|
115
|
-
}
|
|
116
112
|
return this.shiftTip(d)[0];
|
|
117
113
|
})
|
|
118
114
|
.attr("transform", d => {
|
|
@@ -125,9 +121,7 @@ export function drawNode(container, node, transitions) {
|
|
|
125
121
|
.classed(this.css_classes["branch-tracer"], true)
|
|
126
122
|
.merge(tracers)
|
|
127
123
|
.attr("x1", d => {
|
|
128
|
-
return (
|
|
129
|
-
(d.text_align == "end" ? -1 : 1) * this.nodeBubbleSize(node)
|
|
130
|
-
);
|
|
124
|
+
return getX1Direction(d) * this.nodeBubbleSize(node);
|
|
131
125
|
})
|
|
132
126
|
.attr("y2", 0)
|
|
133
127
|
.attr("y1", 0)
|
|
@@ -157,17 +151,24 @@ export function drawNode(container, node, transitions) {
|
|
|
157
151
|
});
|
|
158
152
|
|
|
159
153
|
if (this.shown_font_size >= 5) {
|
|
154
|
+
const isRTL = this.options["layout"] == "right-to-left";
|
|
160
155
|
labels = labels.attr("dx", d => {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
(
|
|
164
|
-
|
|
156
|
+
// For radial, use text_align; for linear RTL, use negative offset; otherwise positive
|
|
157
|
+
const direction = this.radial()
|
|
158
|
+
? (d.text_align == "end" ? -1 : 1)
|
|
159
|
+
: (isRTL ? -1 : 1);
|
|
160
|
+
return direction * ((this.alignTips() ? 0 : shift) + this.shown_font_size * 0.33);
|
|
165
161
|
});
|
|
166
162
|
}
|
|
167
163
|
} else {
|
|
168
164
|
if (this.shown_font_size >= 5) {
|
|
165
|
+
const isRTL = this.options["layout"] == "right-to-left";
|
|
169
166
|
labels = labels.attr("dx", d => { // eslint-disable-line
|
|
170
|
-
|
|
167
|
+
// For radial, use text_align; for linear RTL, use negative offset; otherwise positive
|
|
168
|
+
const direction = this.radial()
|
|
169
|
+
? (d.text_align == "end" ? -1 : 1)
|
|
170
|
+
: (isRTL ? -1 : 1);
|
|
171
|
+
return direction * this.shown_font_size * 0.33;
|
|
171
172
|
});
|
|
172
173
|
}
|
|
173
174
|
}
|
package/src/render/options.js
CHANGED
|
@@ -61,19 +61,7 @@ export function nodeBubbleSize(node) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
if (this.options["is-radial"]) {
|
|
66
|
-
return [
|
|
67
|
-
(d.text_align == "end" ? -1 : 1) *
|
|
68
|
-
(this.radius_pad_for_bubbles - d.radius),
|
|
69
|
-
0
|
|
70
|
-
];
|
|
71
|
-
}
|
|
72
|
-
if (this.options["right-to-left"]) {
|
|
73
|
-
return [this.right_most_leaf - d.screen_x, 0];
|
|
74
|
-
}
|
|
75
|
-
return [this.right_most_leaf - d.screen_x, 0];
|
|
76
|
-
}
|
|
64
|
+
// shiftTip function is defined in nodes.js - removed duplicate here
|
|
77
65
|
|
|
78
66
|
export function layoutHandler(attr) {
|
|
79
67
|
if (!arguments.length) return this.layout_listener_handler;
|