Skip to content

Commit ca01cf4

Browse files
author
Xing
committed
fixed links
1 parent b9f5abe commit ca01cf4

File tree

2 files changed

+62
-9
lines changed

2 files changed

+62
-9
lines changed

js/annotate.js

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ class Link {
2222

2323
this.rootMinWord = null;
2424
this.rootMaxWord = null;
25+
this.nearestConnectedMinWord = null;
26+
this.nearestConnectedMaxWord = null;
2527

26-
2728
this.arrows = [];
2829
this.arrowStyles = [];
2930
this.arrowXPercents = [];
@@ -416,6 +417,46 @@ function checkAndUpdateWordToWordSlots(link, startSlot) { //, minWord, minSide,
416417
return useSlot;
417418
}
418419

420+
//current link, the word we're tracing, and the side that it's on
421+
function traceBackToNearestWordObj(link, type, word, attach) {
422+
423+
var retVal = {w: -1, s: -1};
424+
425+
if (type == types.WORD) {
426+
console.log("in traceback, node is a word, wordObj.val = " + word.val + ", attachSide = " + attach);
427+
428+
retVal.w = word;
429+
retVal.s = attach;
430+
431+
return retVal;
432+
433+
} else {
434+
//// console.log("in traceback, node is a link, wordObj.val, attachSide = " + attach);
435+
436+
var nextLink = word;
437+
var nextType, nextWord, nextAttach;
438+
439+
if (attach == sides.LEFT) { //left
440+
441+
//nextType = nextLink.ts;
442+
nextType = nextLink.leftType;
443+
nextWord = nextLink.leftWord;
444+
nextAttach = nextLink.leftAttach;
445+
446+
} else { // right
447+
448+
//nextType = nextLink.te;
449+
nextType = nextLink.rightType;
450+
nextWord = nextLink.rightWord;
451+
nextAttach = nextLink.rightAttach;
452+
453+
}
454+
455+
console.log("now going to traceback... link: " + nextLink + ", nextType: " + nextType + " nextWord " + nextWord.val + ", nextAttach: " + nextAttach);
456+
457+
return traceBackToWordObj(nextLink, nextType, nextWord, nextAttach);
458+
}
459+
}
419460
//current link, the word we're tracing, and the side that it's on
420461
function traceBackToWordObj(link, type, word, attach) {
421462

@@ -680,17 +721,21 @@ function createLink(link) {
680721
//console.log("left link type: " + link.leftType);
681722
//console.log("left link word: " + link.leftWord);
682723
var rootWordAndSide = traceBackToWordObj(link, link.leftType, link.leftWord, link.leftAttach);
724+
var rootnearestWordAndSide = traceBackToNearestWordObj(link, link.leftType, link.leftWord, link.leftAttach);
683725
link.rootMinWord = rootWordAndSide.w;
684726
link.rootMinSide = rootWordAndSide.s;
685727
//console.log("rootWordAndSideMin: " + rootWordAndSide.w);
686-
728+
link.nearestConnectedMinWord = rootnearestWordAndSide.w;
729+
687730
checkSlotAt = Math.max(checkSlotAt, link.leftWord.h + 1);
688731
//console.log("right link type: " + link.rightType);
689732
//console.log("right link word: " + link.rightWord);
690-
var rootWordAndSide = traceBackToWordObj(link, link.rightType, link.rightWord, link.rightAttach);
733+
rootWordAndSide = traceBackToWordObj(link, link.rightType, link.rightWord, link.rightAttach);
734+
rootWordAndSide = traceBackToNearestWordObj(link, link.rightType, link.rightWord, link.rightAttach);
691735
link.rootMaxWord = rootWordAndSide.w;
692736
link.rootMaxSide = rootWordAndSide.s;
693737
//console.log("rootWordAndSideMax: " + rootWordAndSide.w);
738+
link.nearestConnectedMaxWord = rootnearestWordAndSide.w;
694739
checkSlotAt = Math.max(checkSlotAt, link.rightWord.h + 1); //minimum height to start checking
695740
//set checkSlotAt to 1 if you want to be able to connect from underneath
696741

js/render.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,15 +1462,23 @@ function filterXPositionsForOnlyThisRow(attachmentXPositions, row, link, type) {
14621462
console.log("rootMinWord = " + link.words[aaa].rootMinWord.toString());
14631463
console.log("rootMaxWord = " + link.words[aaa].rootMaxWord.toString());
14641464
//console.log("link idx: " + link.words[aaa].rootMinWord.row.idx + " row: " + row);
1465-
if (link.words[aaa].rootMinWord.row.idx == row ) {
1465+
if (type == rowtypes.END|| type == rowtypes.START) {
1466+
if (link.words[aaa].nearestConnectedMinWord.row.idx == row) {
1467+
console.log("linkaaa: " + link.words[aaa].rootMinWord );
1468+
rowAttachXPos.push( {wordIdx:aaa, xpos:attachmentXPositions[aaa]} );
1469+
}
1470+
else if (link.words[aaa].rootMinWord.row.idx == row ) {
1471+
rowAttachXPos.push( {wordIdx:aaa, xpos:attachmentXPositions[aaa]} );
1472+
console.log("linkaaa: " + link.words[aaa].rootMinWord);
1473+
}
1474+
}
1475+
else if (link.words[aaa].rootMinWord.row.idx == row ) {
14661476
rowAttachXPos.push( {wordIdx:aaa, xpos:attachmentXPositions[aaa]} );
14671477
console.log("linkaaa: " + link.words[aaa].rootMinWord);
14681478
}
1469-
else if (type == rowtypes.END) {
1470-
if (link.words[aaa].rootMinWord.row.idx != link.words[aaa].rootMaxWord.row.idx) {
1471-
console.log("linkaaa: " + link.words[aaa].rootMinWord );
1472-
rowAttachXPos.push( {wordIdx:aaa, xpos:attachmentXPositions[aaa+1]} );
1473-
}
1479+
else if (type == rowtypes.START) {
1480+
1481+
14741482
}
14751483

14761484
} else if (link.words[aaa] instanceof Word) {

0 commit comments

Comments
 (0)