Skip to content

Commit 42f032f

Browse files
committed
commit latest so i can work on something else
1 parent 518635a commit 42f032f

File tree

1 file changed

+64
-22
lines changed

1 file changed

+64
-22
lines changed

js/GraphLayout.js

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ const GraphLayout = (function() {
6161
.nodeSize([30,80])
6262
.separation((a,b) => {
6363
let separation = a.parent == b.parent ? 1 : 2;
64-
separation += Math.max(b.data.incoming.length, a.data.incoming.length) / 2;
64+
function reduce(acc, val) {
65+
if (val.expanded) { return acc + val.size; }
66+
return acc + 1;
67+
}
68+
separation += Math.max(b.data.incoming.reduce(reduce, 0), a.data.incoming.reduce(reduce, 0)) / 2;
6569
return separation;
6670
});
6771

@@ -113,19 +117,27 @@ const GraphLayout = (function() {
113117
adjustMargins() {
114118
let bounds = this.div.getBoundingClientRect();
115119

116-
d3.selectAll('.group')
120+
/* d3.selectAll('.group')
117121
.attr('transform', (d, i, el) => {
118122
119123
let bbox = el[i].getBBox();
120124
let y = -bbox.height / 2 - bbox.y;
121125
126+
if (i !== d.index && d.anchor) {
127+
console.log(d3.select(el[d.index]).attr('transform'));
128+
// console.log(bbox.y);
129+
// y = bounds.height / 2 + bbox.y + (d.anchor.x - d.dx);
130+
}
131+
122132
return 'translate(' + [0, y] + ')';
123133
});
124-
134+
*/
125135
let bbox2 = this.g.node().getBBox();
126136
let x = 20 - bbox2.x + this.dx;
127137

128-
this.g.attr('transform', 'translate(' + [x, bounds.height / 2] + ')');
138+
let y = bounds.height / 2 - bbox2.height / 2 - bbox2.y;
139+
140+
this.g.attr('transform', 'translate(' + [x, y/*bounds.height / 2*/] + ')');
129141
}
130142
clear() {
131143
this.words = [];
@@ -168,40 +180,70 @@ const GraphLayout = (function() {
168180
const anchorInNewTree = root.descendants().find(node => node.data.node === data.anchor.data.node);
169181

170182
let tree2 = tree(root);
171-
let dy = data.anchor.y - anchorInNewTree.y;
172183

173-
console.log('root.x', root.x, anchorInNewTree.x);
174-
console.log('old root.x', this.data[index].root.x, data.anchor.x);
184+
// remove extraneous hooks / shared nodes
185+
let range = d3.extent(root.leaves().concat(data.anchor), d => d.x);
175186

176-
let graftLeftOfRoot = data.anchor.x < this.data[index].root.x;
177-
let range = d3.extent(this.data[index].root.leaves(), d => d.x);
178-
179-
let dx;
180-
if (graftLeftOfRoot) {
181-
dx = range[1] - anchorInNewTree.x;
182-
}
183-
else {
184-
dx = range[0] - anchorInNewTree.x;
185-
}
187+
data.anchor.data.incoming.splice(data.anchor.data.incoming.indexOf(data.node), 1);
188+
anchorInNewTree.parent.children.splice(anchorInNewTree.parent.children.indexOf(anchorInNewTree), 1);
186189

190+
// translate grafted tree onto old tree
191+
let dy = data.anchor.y - anchorInNewTree.y;
192+
let dx = data.anchor.x - anchorInNewTree.x;
187193
root.descendants().forEach(node => {
188194
node.x += dx;
189195
node.y += dy;
190196
});
191197

198+
console.log('----- range',d3.extent(this.data[index].root.descendants(), d => d.x));
199+
console.log('graft range',d3.extent(root.descendants(), d => d.x));
200+
console.log(data.anchor.x, dx);
201+
202+
// -------- in progress
203+
// test case : Pos_reg --> graft "outside"
204+
// test case : Promotes --> graft "inside"
205+
// test case : Phosphorylation --> two
206+
/* let graftLeftOfRoot = data.anchor.x < this.data[index].root.x;
207+
208+
console.log(root.descendants());
209+
210+
// rearrange old tree to not interfere with graft
211+
let range = d3.extent(root.leaves().concat(data.anchor), d => d.x);
212+
console.log(range);
213+
console.log(this.data[index].root.descendants().map(d => d.x));
214+
215+
let children = data.anchor.descendants();
216+
let offset = Number.MIN_SAFE_INTEGER;
217+
this.data[index].root.descendants().forEach(node => {
218+
// not a shared branch
219+
if (children.indexOf(node) < 0) {
220+
if (node.x <= range[1] && node.x >= range[0]) {
221+
offset = Math.max(offset, node.x);
222+
}
223+
}
224+
});
225+
offset = data.anchor.x - offset;
226+
console.log(offset);
227+
this.data[index].root.descendants().forEach(node => {
228+
if (children.indexOf(node) < 0) {
229+
if (node.x <= range[1] && node.x >= range[0]) {
230+
node.x -= offset;
231+
}
232+
}
233+
})
234+
235+
*/
236+
// ------ end testing
237+
192238
this.data.push({
193239
index,
194240
root,
241+
dx,
195242
tree: tree2,
196243
anchor: data.anchor,
197244
offset: this.data[index].offset
198245
});
199246

200-
// remove extraneous hooks
201-
data.anchor.data.incoming.splice(data.anchor.data.incoming.indexOf(data.node), 1);
202-
203-
anchorInNewTree.parent.children.splice(anchorInNewTree.parent.children.indexOf(anchorInNewTree), 1);
204-
205247
this.updateGraph();
206248
}
207249

0 commit comments

Comments
 (0)