@microbiome-informatics/genome-properties-viewer 1.0.0-beta.1 → 1.0.0-beta.2
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/gp-style.css +7 -2
- package/package.json +3 -3
- package/src/gp-controller.js +10 -1
- package/src/gp-scroller.js +107 -37
- package/src/gp-steps.js +5 -14
- package/src/gp-tax-node.js +12 -8
- package/src/gp-taxonomy.js +38 -32
- package/src/gp-totals.js +107 -15
- package/src/gp-ui-utils.js +139 -28
- package/src/gp-uploader.js +20 -11
- package/src/gp-viewer.js +256 -246
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A heatmap-styled web viewer for the Genome Properties project.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Each column is a species and each row is a Genome Property. Species are selected from a taxonomy tree at the top of the viewer, with property names on the left.
|
|
6
6
|
|
|
7
7
|
Published on npm as [`@microbiome-informatics/genome-properties-viewer`](https://www.npmjs.com/package/@microbiome-informatics/genome-properties-viewer). This is a new scoped package, not a continuation of the unscoped `genome-properties-viewer` name.
|
|
8
8
|
|
package/gp-style.css
CHANGED
|
@@ -42,7 +42,7 @@ text.active,
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
g.node.loaded {
|
|
45
|
-
cursor:
|
|
45
|
+
cursor: ew-resize;
|
|
46
46
|
opacity: 1;
|
|
47
47
|
}
|
|
48
48
|
g.node.loaded:hover .node-type {
|
|
@@ -79,7 +79,7 @@ g.node.loaded text.label-species {
|
|
|
79
79
|
pointer-events: none;
|
|
80
80
|
}
|
|
81
81
|
.height-dragger {
|
|
82
|
-
cursor:
|
|
82
|
+
cursor: ns-resize;
|
|
83
83
|
opacity: 0.7;
|
|
84
84
|
}
|
|
85
85
|
.height-dragger:hover {
|
|
@@ -433,6 +433,11 @@ div.container .top-block .minimise.on::after {
|
|
|
433
433
|
}
|
|
434
434
|
.gpv-scrollbar rect.gpv-scrollbar-handle {
|
|
435
435
|
fill: rgba(100, 100, 100, 0.6);
|
|
436
|
+
}
|
|
437
|
+
.gpv-scrollbar-x rect.gpv-scrollbar-handle {
|
|
438
|
+
cursor: ew-resize;
|
|
439
|
+
}
|
|
440
|
+
.gpv-scrollbar-y rect.gpv-scrollbar-handle {
|
|
436
441
|
cursor: ns-resize;
|
|
437
442
|
}
|
|
438
443
|
.gpv-scrollbar rect.gpv-scrollbar-bg {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microbiome-informatics/genome-properties-viewer",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
4
|
"description": "A heatmap styled viewer for the genome properties",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@babel/cli": "^7.2.0",
|
|
60
60
|
"@babel/core": "^7.2.0",
|
|
61
61
|
"@babel/preset-env": "^7.2.0",
|
|
62
|
-
"browser-sync": "2.
|
|
62
|
+
"browser-sync": "^2.29.3",
|
|
63
63
|
"eslint": "7.21.0",
|
|
64
64
|
"eslint-config-airbnb-base": "14.2.1",
|
|
65
65
|
"eslint-config-prettier": "8.1.0",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"mysql": "2.18.1",
|
|
70
70
|
"prettier": "2.2.1",
|
|
71
71
|
"regenerator": "0.14.7",
|
|
72
|
-
"rollup": "2.
|
|
72
|
+
"rollup": "^2.80.0",
|
|
73
73
|
"rollup-plugin-babel": "^4.1.0",
|
|
74
74
|
"rollup-plugin-node-resolve": "5.2.0"
|
|
75
75
|
}
|
package/src/gp-controller.js
CHANGED
|
@@ -32,12 +32,15 @@ export default class GenomePropertiesController {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
if (legends_element_selector) {
|
|
35
|
-
|
|
35
|
+
const host = d3.select(legends_element_selector);
|
|
36
|
+
host.selectAll("ul").remove();
|
|
37
|
+
this.legends_component = host.append("ul");
|
|
36
38
|
this.draw_legends();
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
if (tooltip_selector) {
|
|
40
42
|
this.tooltip_selector = tooltip_selector;
|
|
43
|
+
d3.select(tooltip_selector).selectAll("ul").remove();
|
|
41
44
|
this.draw_tooltip(null, null, true);
|
|
42
45
|
}
|
|
43
46
|
|
|
@@ -270,4 +273,10 @@ export default class GenomePropertiesController {
|
|
|
270
273
|
this.dipatcher.on(typename, callback);
|
|
271
274
|
return this;
|
|
272
275
|
}
|
|
276
|
+
|
|
277
|
+
destroy() {
|
|
278
|
+
if (this.legends_component) this.legends_component.remove();
|
|
279
|
+
if (this.tooltip_component) this.tooltip_component.remove();
|
|
280
|
+
if (this.gp_component) this.gp_component.html("");
|
|
281
|
+
}
|
|
273
282
|
}
|
package/src/gp-scroller.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as d3 from "./d3";
|
|
2
2
|
/**
|
|
3
|
-
* Updates this and
|
|
3
|
+
* Updates this and other components as if a scroll event happened.
|
|
4
4
|
* It became the de-facto refresh of the whole viewer, as it groups the minimum necesary changes to trigger a full update.
|
|
5
5
|
* @param {GernomeProperiesViewer} viewer - The instance of the genome properites viewer
|
|
6
6
|
*/
|
|
@@ -13,8 +13,13 @@ export const transformByScroll = (viewer) => {
|
|
|
13
13
|
"transform",
|
|
14
14
|
`translate(${viewer.current_scroll.x}, ${viewer.current_scroll.y})`
|
|
15
15
|
);
|
|
16
|
+
if (viewer.labelGroup) {
|
|
17
|
+
viewer.labelGroup.attr(
|
|
18
|
+
"transform",
|
|
19
|
+
`translate(0, ${viewer.current_scroll.y})`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
16
22
|
viewer.options.dimensions.total.short_side = viewer.options.cell_side;
|
|
17
|
-
viewer.gp_taxonomy.y = viewer.options.dimensions.total.short_side;
|
|
18
23
|
viewer.update_viewer();
|
|
19
24
|
};
|
|
20
25
|
|
|
@@ -24,30 +29,21 @@ export const transformByScroll = (viewer) => {
|
|
|
24
29
|
* @param {GernomeProperiesViewer} viewer - The instance of the genome properites viewer
|
|
25
30
|
*/
|
|
26
31
|
export const drawScrollXBar = (viewer) => {
|
|
27
|
-
const localY = (1 + viewer.organisms.length) * viewer.options.cell_side;
|
|
28
32
|
const scrollerShortSide = viewer.options.dimensions.scroller.short_side;
|
|
29
33
|
viewer.scrollbar_x_g = viewer.mainGroup
|
|
30
34
|
.append("g")
|
|
31
|
-
.attr("class", "gpv-scrollbar")
|
|
32
|
-
.attr("opacity", 0)
|
|
33
|
-
.attr(
|
|
34
|
-
"transform",
|
|
35
|
-
`translate(${
|
|
36
|
-
viewer.options.dimensions.tree.width // at the right of the tree
|
|
37
|
-
}, ${localY})`
|
|
38
|
-
);
|
|
35
|
+
.attr("class", "gpv-scrollbar gpv-scrollbar-x")
|
|
36
|
+
.attr("opacity", 0);
|
|
39
37
|
|
|
40
38
|
viewer.scrollbar_x_bg = viewer.scrollbar_x_g
|
|
41
39
|
.append("rect")
|
|
42
40
|
.attr("class", "gpv-scrollbar-bg")
|
|
43
|
-
.attr("width", viewer.options.width - viewer.options.dimensions.tree.width)
|
|
44
41
|
.attr("height", scrollerShortSide);
|
|
45
42
|
|
|
46
43
|
let selectedXBar = null;
|
|
47
44
|
viewer.scrollbar_x = viewer.scrollbar_x_g
|
|
48
45
|
.append("rect")
|
|
49
46
|
.attr("class", "gpv-scrollbar-handle")
|
|
50
|
-
.attr("width", viewer.options.width - viewer.options.dimensions.tree.width)
|
|
51
47
|
.attr("height", scrollerShortSide - 2)
|
|
52
48
|
.attr("y", 1)
|
|
53
49
|
.attr("rx", scrollerShortSide / 2)
|
|
@@ -64,11 +60,11 @@ export const drawScrollXBar = (viewer) => {
|
|
|
64
60
|
.on("drag", (event) => {
|
|
65
61
|
viewer.skip_scroll_refreshing = true;
|
|
66
62
|
event.sourceEvent.stopPropagation();
|
|
67
|
-
const
|
|
63
|
+
const speciesWidth =
|
|
64
|
+
(viewer.organisms?.length || 0) * viewer.options.cell_side;
|
|
68
65
|
const prevX = Number(selectedXBar.getAttribute("x"));
|
|
69
66
|
let nextX = prevX + event.dx;
|
|
70
|
-
const available_x =
|
|
71
|
-
viewer.options.width - viewer.options.dimensions.tree.width;
|
|
67
|
+
const available_x = viewer.heatmapWidth();
|
|
72
68
|
|
|
73
69
|
nextX = Math.max(
|
|
74
70
|
0,
|
|
@@ -76,52 +72,126 @@ export const drawScrollXBar = (viewer) => {
|
|
|
76
72
|
);
|
|
77
73
|
|
|
78
74
|
viewer.scrollbar_x.attr("x", nextX);
|
|
79
|
-
const dx = (-nextX *
|
|
75
|
+
const dx = (-nextX * speciesWidth) / available_x;
|
|
80
76
|
viewer.current_scroll.x = Math.min(0, dx);
|
|
81
77
|
transformByScroll(viewer);
|
|
82
78
|
})
|
|
83
79
|
);
|
|
80
|
+
|
|
81
|
+
viewer.scrollbar_y_g = viewer.mainGroup
|
|
82
|
+
.append("g")
|
|
83
|
+
.attr("class", "gpv-scrollbar gpv-scrollbar-y")
|
|
84
|
+
.attr("opacity", 0);
|
|
85
|
+
|
|
86
|
+
viewer.scrollbar_y_bg = viewer.scrollbar_y_g
|
|
87
|
+
.append("rect")
|
|
88
|
+
.attr("class", "gpv-scrollbar-bg")
|
|
89
|
+
.attr("width", scrollerShortSide);
|
|
90
|
+
|
|
91
|
+
let selectedYBar = null;
|
|
92
|
+
viewer.scrollbar_y = viewer.scrollbar_y_g
|
|
93
|
+
.append("rect")
|
|
94
|
+
.attr("class", "gpv-scrollbar-handle")
|
|
95
|
+
.attr("width", scrollerShortSide - 2)
|
|
96
|
+
.attr("x", 1)
|
|
97
|
+
.attr("rx", scrollerShortSide / 2)
|
|
98
|
+
.attr("ry", scrollerShortSide / 2)
|
|
99
|
+
.style("cursor", "ns-resize")
|
|
100
|
+
.call(
|
|
101
|
+
d3
|
|
102
|
+
.drag()
|
|
103
|
+
.on("start", (event) => (selectedYBar = event.sourceEvent.target))
|
|
104
|
+
.on("end", () => {
|
|
105
|
+
viewer.skip_scroll_refreshing = false;
|
|
106
|
+
selectedYBar = null;
|
|
107
|
+
})
|
|
108
|
+
.on("drag", (event) => {
|
|
109
|
+
viewer.skip_scroll_refreshing = true;
|
|
110
|
+
event.sourceEvent.stopPropagation();
|
|
111
|
+
const propsHeight = viewer.y(viewer.props?.length || 0) || 0;
|
|
112
|
+
const prevY = Number(selectedYBar.getAttribute("y"));
|
|
113
|
+
let nextY = prevY + event.dy;
|
|
114
|
+
const available_y = viewer.heatmapHeight();
|
|
115
|
+
|
|
116
|
+
nextY = Math.max(
|
|
117
|
+
0,
|
|
118
|
+
Math.min(nextY, available_y - selectedYBar.getAttribute("height"))
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
viewer.scrollbar_y.attr("y", nextY);
|
|
122
|
+
const dy = (-nextY * propsHeight) / available_y;
|
|
123
|
+
viewer.current_scroll.y = Math.min(0, dy);
|
|
124
|
+
transformByScroll(viewer);
|
|
125
|
+
})
|
|
126
|
+
);
|
|
84
127
|
};
|
|
85
128
|
|
|
86
|
-
/**
|
|
87
|
-
* Updates the size and position of the scrollbar.
|
|
88
|
-
* The size of the draggable is proportional to the number of visible columns in the graphic
|
|
89
|
-
* @param {GernomeProperiesViewer} viewer - The instance of the genome properites viewer
|
|
90
|
-
* @param {Number} visible_cols - Indicates how many columns are visible in the area assgined to the heatmap.
|
|
91
|
-
* @param {Number} current_col - Indicates the index of the first visible column out of the total number of GP.
|
|
92
|
-
*/
|
|
93
129
|
const updateScrollBarX = (viewer, visible_cols, current_col) => {
|
|
94
|
-
const
|
|
95
|
-
const
|
|
130
|
+
const total_cols = viewer.organisms.length;
|
|
131
|
+
const available_x = viewer.heatmapWidth();
|
|
96
132
|
viewer.scrollbar_x_g
|
|
97
133
|
.attr(
|
|
98
134
|
"transform",
|
|
99
|
-
`translate(${viewer.
|
|
135
|
+
`translate(${viewer.heatmapLeft}, ${
|
|
136
|
+
viewer.options.height - viewer.options.dimensions.scroller.short_side
|
|
137
|
+
})`
|
|
100
138
|
)
|
|
101
139
|
.attr("opacity", total_cols > 0 ? 1 : 0);
|
|
102
140
|
|
|
103
|
-
const available_x =
|
|
104
|
-
viewer.options.width -
|
|
105
|
-
viewer.options.dimensions.tree.width -
|
|
106
|
-
viewer.options.dimensions.total.short_side;
|
|
107
141
|
viewer.scrollbar_x
|
|
108
142
|
.transition()
|
|
109
143
|
.attr(
|
|
110
144
|
"width",
|
|
111
145
|
available_x *
|
|
112
|
-
Math.min(
|
|
146
|
+
Math.min(
|
|
147
|
+
1,
|
|
148
|
+
total_cols !== 0 ? visible_cols / Math.max(total_cols, 1) : 1
|
|
149
|
+
)
|
|
113
150
|
)
|
|
114
151
|
.attr("x", total_cols ? (current_col * available_x) / total_cols : 0);
|
|
115
152
|
viewer.scrollbar_x_bg.attr("width", available_x);
|
|
116
153
|
};
|
|
117
154
|
|
|
155
|
+
const updateScrollBarY = (viewer, visible_rows, current_row) => {
|
|
156
|
+
const total_rows = viewer.props.length;
|
|
157
|
+
const available_y = viewer.heatmapHeight();
|
|
158
|
+
viewer.scrollbar_y_g
|
|
159
|
+
.attr(
|
|
160
|
+
"transform",
|
|
161
|
+
`translate(${
|
|
162
|
+
viewer.options.width - viewer.options.dimensions.scroller.short_side
|
|
163
|
+
}, ${viewer.heatmapTop})`
|
|
164
|
+
)
|
|
165
|
+
.attr("opacity", total_rows > 0 ? 1 : 0);
|
|
166
|
+
|
|
167
|
+
viewer.scrollbar_y
|
|
168
|
+
.transition()
|
|
169
|
+
.attr(
|
|
170
|
+
"height",
|
|
171
|
+
available_y *
|
|
172
|
+
Math.min(
|
|
173
|
+
1,
|
|
174
|
+
total_rows !== 0 ? visible_rows / Math.max(total_rows, 1) : 1
|
|
175
|
+
)
|
|
176
|
+
)
|
|
177
|
+
.attr("y", total_rows ? (current_row * available_y) / total_rows : 0);
|
|
178
|
+
viewer.scrollbar_y_bg.attr("height", available_y);
|
|
179
|
+
};
|
|
180
|
+
|
|
118
181
|
/**
|
|
119
|
-
* A single method to trigger the update of all the scroll bars of the viewer.
|
|
182
|
+
* A single method to trigger the update of all the scroll bars of the viewer.
|
|
120
183
|
* @param {GernomeProperiesViewer} viewer - The instance of the genome properites viewer
|
|
121
|
-
* @param {Number}
|
|
122
|
-
* @param {Number}
|
|
184
|
+
* @param {Number} visible_rows - Visible property rows in the heatmap.
|
|
185
|
+
* @param {Number} current_row - Index of the first visible property.
|
|
123
186
|
*/
|
|
124
|
-
export const updateScrollBars = (viewer,
|
|
187
|
+
export const updateScrollBars = (viewer, visible_rows, current_row) => {
|
|
188
|
+
const visible_cols = Math.min(
|
|
189
|
+
viewer.organisms.length,
|
|
190
|
+
Math.ceil(viewer.heatmapWidth() / viewer.options.cell_side)
|
|
191
|
+
);
|
|
192
|
+
const current_col = Math.round(
|
|
193
|
+
Math.abs(viewer.current_scroll.x) / viewer.options.cell_side
|
|
194
|
+
);
|
|
125
195
|
updateScrollBarX(viewer, visible_cols, current_col);
|
|
126
|
-
|
|
196
|
+
updateScrollBarY(viewer, visible_rows, current_row);
|
|
127
197
|
};
|
package/src/gp-steps.js
CHANGED
|
@@ -46,9 +46,6 @@ const displayStepsModal = (viewer, gp) => {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
const updateStepDetailsButton = (viewer, gp, element, cellSide) => {
|
|
49
|
-
const localY =
|
|
50
|
-
viewer.organisms.length * cellSide +
|
|
51
|
-
viewer.options.dimensions.scroller.short_side;
|
|
52
49
|
const x0 = cellSide * 0.1;
|
|
53
50
|
const side = cellSide * 0.8;
|
|
54
51
|
const top = cellSide * 0.1;
|
|
@@ -73,7 +70,7 @@ const updateStepDetailsButton = (viewer, gp, element, cellSide) => {
|
|
|
73
70
|
|
|
74
71
|
buttonG
|
|
75
72
|
.merge(button)
|
|
76
|
-
.attr("transform", `translate(${cellSide}, ${
|
|
73
|
+
.attr("transform", `translate(${-cellSide}, ${cellSide})`)
|
|
77
74
|
.selectAll("circle")
|
|
78
75
|
.transition()
|
|
79
76
|
.attr("cx", x0 + half)
|
|
@@ -107,7 +104,7 @@ export const updateSteps = (viewer, gp, element, cellSide, yScale) => {
|
|
|
107
104
|
.append("g")
|
|
108
105
|
.attr("class", "step")
|
|
109
106
|
.merge(steps)
|
|
110
|
-
.attr("transform", (d, i) => `translate(${i * cellSide + p}
|
|
107
|
+
.attr("transform", (d, i) => `translate(0, ${(i + 1) * cellSide + p})`);
|
|
111
108
|
|
|
112
109
|
const onMouseOver = (event, d) => {
|
|
113
110
|
viewer.controller.draw_tooltip(event, {
|
|
@@ -144,7 +141,8 @@ export const updateSteps = (viewer, gp, element, cellSide, yScale) => {
|
|
|
144
141
|
.on("mouseover", onMouseOver)
|
|
145
142
|
.on("mouseout", onMouseOut)
|
|
146
143
|
.merge(stepPerSpecie)
|
|
147
|
-
.attr("
|
|
144
|
+
.attr("x", (d, i) => yScale(i) + p)
|
|
145
|
+
.attr("y", 0)
|
|
148
146
|
.transition()
|
|
149
147
|
.attr("width", side)
|
|
150
148
|
.attr("height", side)
|
|
@@ -158,10 +156,6 @@ export const updateStepToggler = (viewer, gp, element, cellSide) => {
|
|
|
158
156
|
viewer.data[id].isShowingSteps = !viewer.data[id].isShowingSteps;
|
|
159
157
|
viewer.update_viewer();
|
|
160
158
|
};
|
|
161
|
-
const localY =
|
|
162
|
-
viewer.organisms.length * cellSide +
|
|
163
|
-
viewer.options.dimensions.scroller.short_side;
|
|
164
|
-
|
|
165
159
|
const toggler = d3
|
|
166
160
|
.select(element)
|
|
167
161
|
.selectAll(".step-toggler")
|
|
@@ -203,10 +197,7 @@ export const updateStepToggler = (viewer, gp, element, cellSide) => {
|
|
|
203
197
|
|
|
204
198
|
newG
|
|
205
199
|
.merge(toggler)
|
|
206
|
-
.attr(
|
|
207
|
-
"transform",
|
|
208
|
-
`translate(0, ${localY})rotate(90,${cellSide / 2},${cellSide / 2})`
|
|
209
|
-
)
|
|
200
|
+
.attr("transform", `translate(${-cellSide}, 0)`)
|
|
210
201
|
.attr(
|
|
211
202
|
"class",
|
|
212
203
|
(id) => `step-toggler ${viewer.data[id].isShowingSteps ? "expanded" : ""}`
|
package/src/gp-tax-node.js
CHANGED
|
@@ -128,16 +128,16 @@ export default class TaxonomyNodeManager {
|
|
|
128
128
|
event.sourceEvent.stopPropagation();
|
|
129
129
|
const g = d3.select(event.sourceEvent.target.closest("g.node"));
|
|
130
130
|
if (d.has_loaded_leaves) {
|
|
131
|
-
g.attr("transform", (p) => `translate(${
|
|
131
|
+
g.attr("transform", (p) => `translate(${event.x},${p.y})`);
|
|
132
132
|
}
|
|
133
133
|
})
|
|
134
134
|
.on("end", (event, d) => {
|
|
135
135
|
if (d.has_loaded_leaves) {
|
|
136
136
|
const g = d3.select(event.sourceEvent.target.closest("g.node"));
|
|
137
137
|
const w = this.main.cell_side;
|
|
138
|
-
const
|
|
139
|
-
const
|
|
140
|
-
move_tree(d,
|
|
138
|
+
const dx = event.x - d.x;
|
|
139
|
+
const d_col = Math.round(dx / w);
|
|
140
|
+
move_tree(d, d_col);
|
|
141
141
|
const time = d3.transition().duration(500);
|
|
142
142
|
g.transition(time).attr(
|
|
143
143
|
"transform",
|
|
@@ -169,10 +169,14 @@ export default class TaxonomyNodeManager {
|
|
|
169
169
|
|
|
170
170
|
g.append("text")
|
|
171
171
|
.attr("class", "label-species")
|
|
172
|
-
.attr("x",
|
|
173
|
-
.attr("y", this.r
|
|
174
|
-
.style("text-anchor", "
|
|
175
|
-
|
|
172
|
+
.attr("x", this.r)
|
|
173
|
+
.attr("y", this.r)
|
|
174
|
+
.style("text-anchor", "start")
|
|
175
|
+
.attr("transform", (d) =>
|
|
176
|
+
d.children || d._children
|
|
177
|
+
? `translate(0,${-this.r - 2})`
|
|
178
|
+
: "rotate(-70)"
|
|
179
|
+
)
|
|
176
180
|
.style("fill", (d) => (d.data.isFromFile ? "darkred" : null))
|
|
177
181
|
.text((d) => {
|
|
178
182
|
let label = "";
|
package/src/gp-taxonomy.js
CHANGED
|
@@ -23,6 +23,7 @@ export default class GenomePropertiesTaxonomy {
|
|
|
23
23
|
this.svg = null;
|
|
24
24
|
this.collapse_tree = true;
|
|
25
25
|
this.show_tree = show_tree;
|
|
26
|
+
this.dataOffsetX = 0;
|
|
26
27
|
this.dipatcher = d3.dispatch(
|
|
27
28
|
"changeOrder",
|
|
28
29
|
"spaciesRequested",
|
|
@@ -72,44 +73,46 @@ export default class GenomePropertiesTaxonomy {
|
|
|
72
73
|
return this.nodes;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
draw_tree_panel(svg) {
|
|
76
|
+
draw_tree_panel(svg, treeClipId = null) {
|
|
76
77
|
this.svg = svg;
|
|
77
|
-
this.
|
|
78
|
+
this.tree_layer = svg.append("g").attr("class", "taxon_tree_layer");
|
|
79
|
+
if (treeClipId) {
|
|
80
|
+
this.tree_layer.attr("clip-path", `url(#${treeClipId})`);
|
|
81
|
+
}
|
|
82
|
+
this.tree_g = this.tree_layer
|
|
78
83
|
.append("g")
|
|
79
84
|
.attr("class", "taxon_tree")
|
|
80
85
|
.attr("transform", `translate(${this.x}, ${this.y})`);
|
|
81
86
|
this.node_manager.tree_g = this.tree_g;
|
|
82
87
|
}
|
|
83
88
|
|
|
84
|
-
// Walks the tree and calculates x,y values for each node
|
|
89
|
+
// Walks the tree and calculates x,y values for each node.
|
|
90
|
+
// Leaves run along X so they line up with species columns; depth runs down Y.
|
|
85
91
|
tree(node, deepness = 0) {
|
|
86
92
|
let avg = 0;
|
|
87
93
|
|
|
88
94
|
if (node.has_loaded_leaves) {
|
|
89
95
|
if (node.children) {
|
|
90
|
-
// Intermediate nodes with leaves get located in the midle of the leaves
|
|
91
96
|
for (const child of node.children) {
|
|
92
97
|
this.tree(child, deepness + 1);
|
|
93
|
-
avg += child.
|
|
98
|
+
avg += child.x;
|
|
94
99
|
node.deepness =
|
|
95
100
|
!node.deepness || child.deepness > node.deepness
|
|
96
101
|
? child.deepness
|
|
97
102
|
: node.deepness;
|
|
98
103
|
}
|
|
99
|
-
node.
|
|
104
|
+
node.x = avg / node.children.length;
|
|
105
|
+
const leafY = Math.max(0, this.height - this.y - this.cell_side);
|
|
106
|
+
node.y = (deepness / (node.deepness || 1)) * leafY;
|
|
100
107
|
} else {
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
node.x =
|
|
109
|
+
(this.dataOffsetX || 0) +
|
|
103
110
|
this.cell_side / 3 +
|
|
104
111
|
this.cell_side *
|
|
105
112
|
this.current_order.indexOf(this.organisms.indexOf(node.data.taxid));
|
|
106
|
-
node.
|
|
113
|
+
node.y = Math.max(0, this.height - this.y - this.cell_side);
|
|
107
114
|
node.deepness = deepness;
|
|
108
115
|
}
|
|
109
|
-
} else {
|
|
110
|
-
const number_of_selected_org = this.organisms.length;
|
|
111
|
-
const space_for_leaves = this.cell_side * number_of_selected_org;
|
|
112
|
-
node.y = space_for_leaves / 2 + node.y;
|
|
113
116
|
}
|
|
114
117
|
}
|
|
115
118
|
|
|
@@ -231,7 +234,7 @@ export default class GenomePropertiesTaxonomy {
|
|
|
231
234
|
}
|
|
232
235
|
|
|
233
236
|
update_tree(time = 0, cell_side = null) {
|
|
234
|
-
if (this.root === null) return;
|
|
237
|
+
if (this.root === null || !this.tree_g) return;
|
|
235
238
|
if (cell_side !== null) this.cell_side = cell_side;
|
|
236
239
|
this.tree_g.attr("transform", `translate(${this.x}, ${this.y})`);
|
|
237
240
|
|
|
@@ -263,6 +266,10 @@ export default class GenomePropertiesTaxonomy {
|
|
|
263
266
|
.sort((a, b) => a.data.taxid - b.data.taxid);
|
|
264
267
|
const ol = leaves.length;
|
|
265
268
|
this.organisms = leaves.map((n) => n.data.taxid);
|
|
269
|
+
this.dataOffsetX = Math.max(
|
|
270
|
+
0,
|
|
271
|
+
this.width - this.organisms.length * this.cell_side
|
|
272
|
+
);
|
|
266
273
|
|
|
267
274
|
// Precompute the orders.
|
|
268
275
|
this.orders = {
|
|
@@ -285,23 +292,22 @@ export default class GenomePropertiesTaxonomy {
|
|
|
285
292
|
};
|
|
286
293
|
if (!this.current_order || this.current_order.length !== leaves.length)
|
|
287
294
|
this.current_order = this.orders.tree1;
|
|
288
|
-
const
|
|
295
|
+
const layoutHeight = Math.max(
|
|
296
|
+
this.cell_side,
|
|
297
|
+
this.height - (this.y || 0) - this.cell_side
|
|
298
|
+
);
|
|
299
|
+
const tree_f = d3
|
|
300
|
+
.tree()
|
|
301
|
+
.size([Math.max(this.cell_side, this.width), layoutHeight]);
|
|
289
302
|
tree_f(root);
|
|
290
|
-
root.each((node) => {
|
|
291
|
-
const { x, y } = node;
|
|
292
|
-
node.y = x;
|
|
293
|
-
node.x = y;
|
|
294
|
-
});
|
|
295
303
|
this.tree(root);
|
|
296
|
-
const t =
|
|
297
|
-
const visible_nodes = root
|
|
298
|
-
.
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
d.data.expanded ||
|
|
302
|
-
d.parent.data.expanded ||
|
|
303
|
-
d.parent.has_loaded_leaves
|
|
304
|
+
const t = this.tree_g.transition().duration(time).delay(100);
|
|
305
|
+
const visible_nodes = root.descendants().filter((d) => {
|
|
306
|
+
if (!d.parent) return true;
|
|
307
|
+
return (
|
|
308
|
+
d.data.expanded || d.parent.data.expanded || d.parent.has_loaded_leaves
|
|
304
309
|
);
|
|
310
|
+
});
|
|
305
311
|
|
|
306
312
|
const link = this.tree_g
|
|
307
313
|
.selectAll(".link")
|
|
@@ -317,8 +323,8 @@ export default class GenomePropertiesTaxonomy {
|
|
|
317
323
|
.attr(
|
|
318
324
|
"d",
|
|
319
325
|
(d) =>
|
|
320
|
-
`M${d.source.x},${d.source.y}
|
|
321
|
-
d.target.
|
|
326
|
+
`M${d.source.x},${d.source.y}V${d.source.y + 10}H${d.target.x}V${
|
|
327
|
+
d.target.y
|
|
322
328
|
}`
|
|
323
329
|
);
|
|
324
330
|
|
|
@@ -330,8 +336,8 @@ export default class GenomePropertiesTaxonomy {
|
|
|
330
336
|
.attr(
|
|
331
337
|
"d",
|
|
332
338
|
(d) =>
|
|
333
|
-
`M${d.source.x},${d.source.y}
|
|
334
|
-
d.target.
|
|
339
|
+
`M${d.source.x},${d.source.y}V${d.source.y + 10}H${d.target.x}V${
|
|
340
|
+
d.target.y
|
|
335
341
|
}`
|
|
336
342
|
)
|
|
337
343
|
.style("stroke", (d) =>
|