Skip to content

Commit b75d1b6

Browse files
author
Xing
committed
fixed minRow and maxRow
1 parent e9df4c3 commit b75d1b6

File tree

3 files changed

+89
-40
lines changed

3 files changed

+89
-40
lines changed

js/annotate.js

Lines changed: 75 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ class Link {
120120
this.rightWord = this.words[this.words.length - 1];
121121
this.id = `(${this.leftWord.id}, ${this.rightWord.id})`;
122122

123+
console.log("\n\n *** \n\n in setStartAndEnd");
124+
console.log("leftWord: " + this.leftWord);
125+
console.log("rightWord: " + this.rightWord);
123126

124127
if (this.leftWord instanceof Word) {
125128
this.leftType = types.WORD;
@@ -419,10 +422,11 @@ function traceBackToWordObj(link, type, word, attach) {
419422
var retVal = {w: -1, s: -1};
420423

421424
if (type == types.WORD) {
422-
//// console.log("in traceback, node is a word, wordObj.val = " + word.val + ", attachSide = " + attach);
425+
console.log("in traceback, node is a word, wordObj.val = " + word.val + ", attachSide = " + attach);
423426

424427
retVal.w = word;
425428
retVal.s = attach;
429+
426430
return retVal;
427431

428432
} else {
@@ -431,52 +435,81 @@ function traceBackToWordObj(link, type, word, attach) {
431435
var nextLink = word;
432436
var nextType, nextWord, nextAttach;
433437

434-
if (attach == sides.LEFT) { //left
438+
console.log("nextLinkleft: " + nextLink.leftWord);
439+
console.log("nextLinkleft: " + nextLink.rightWord);
440+
if (determineSide(link) == swapside.YES) {
441+
if (attach == sides.RIGHT) { //left
435442

436-
//nextType = nextLink.ts;
437-
nextType = nextLink.leftType;
438-
nextWord = nextLink.leftWord;
439-
nextAttach = nextLink.leftAttach;
440-
441-
} else { // right
442-
443-
//nextType = nextLink.te;
444-
nextType = nextLink.rightType;
445-
nextWord = nextLink.rightWord;
446-
nextAttach = nextLink.rightAttach;
447-
443+
//nextType = nextLink.ts;
444+
nextType = nextLink.leftType;
445+
nextWord = nextLink.leftWord;
446+
nextAttach = nextLink.leftAttach;
447+
448+
} else { // right
449+
450+
//nextType = nextLink.te;
451+
nextType = nextLink.rightType;
452+
nextWord = nextLink.rightWord;
453+
nextAttach = nextLink.rightAttach;
454+
455+
}
456+
}
457+
else {
458+
if (attach == sides.LEFT) { //left
459+
460+
//nextType = nextLink.ts;
461+
nextType = nextLink.leftType;
462+
nextWord = nextLink.leftWord;
463+
nextAttach = nextLink.leftAttach;
464+
465+
} else { // right
466+
467+
//nextType = nextLink.te;
468+
nextType = nextLink.rightType;
469+
nextWord = nextLink.rightWord;
470+
nextAttach = nextLink.rightAttach;
471+
472+
}
448473
}
449474

450-
//// console.log("now going to traceback... link: " + nextLink + ", nextType: " + nextType + " nextWord " + nextWord.val + ", nextAttach: " + nextAttach);
475+
console.log("now going to traceback... link: " + nextLink + ", nextType: " + nextType + " nextWord " + nextWord.val + ", nextAttach: " + nextAttach);
451476

452477
return traceBackToWordObj(nextLink, nextType, nextWord, nextAttach);
453478
}
454479
}
455480

456-
457-
//TODO - should there be a global strategy for each class of link types? for the different styles of links? for each parent word/link? or for every single individual link??? E.g., could a word support links with different strategies, or would that become cluttered??
458-
function calcAttachPoints(link, strategy) {
459-
481+
function determineSide(link) {
460482
var rootS, rootE;
461483

462-
if (link.leftType == types.WORD) {
463-
rootS = link.leftWord.idx;
464-
//console.log("rootS = " + link.leftWord.id);
484+
if (link.leftType == types.WORD) {
485+
rootS = link.leftWord.idx;
486+
//console.log("rootS = " + link.leftWord.id);
465487

466-
} else {
467-
rootS = link.leftWord.rootMinWord.idx;
468-
//console.log("rootS = " + link.leftWord.rootMinWord.id);
488+
} else {
489+
rootS = link.leftWord.rootMinWord.idx;
490+
//console.log("rootS = " + link.leftWord.rootMinWord.id);
469491

470-
}
492+
}
471493

472-
if (link.rightType == types.WORD) {
473-
rootE = link.rightWord.idx;
474-
//console.log("rootE = " + link.rightWord.id);
494+
if (link.rightType == types.WORD) {
495+
rootE = link.rightWord.idx;
496+
//console.log("rootE = " + link.rightWord.id);
475497

476-
} else {
477-
rootE = link.rightWord.rootMaxWord.idx;
478-
//console.log("rootE = " + link.rightWord.rootMaxWord.id);
479-
}
498+
} else {
499+
rootE = link.rightWord.rootMaxWord.idx;
500+
//console.log("rootE = " + link.rightWord.rootMaxWord.id);
501+
}
502+
503+
if(rootS < rootE) {
504+
return swapside.YES;
505+
}
506+
else {
507+
return swapside.NO;
508+
}
509+
}
510+
511+
//TODO - should there be a global strategy for each class of link types? for the different styles of links? for each parent word/link? or for every single individual link??? E.g., could a word support links with different strategies, or would that become cluttered??
512+
function calcAttachPoints(link, strategy) {
480513

481514
//link.leftWord.nr += 1;
482515
//link.rightWord.nl += 1;
@@ -497,7 +530,7 @@ function calcAttachPoints(link, strategy) {
497530

498531
//console.log("" + link.id + " strategy = CLOSEST");
499532

500-
if (rootS < rootE) {
533+
if (determineSide(link) == swapside.YES) {
501534
//console.log("rootS < rootE (" +rootS +" < " + rootE +")");
502535
link.leftWord.nr += 1;
503536
link.rightWord.nl += 1;
@@ -631,7 +664,6 @@ function createLink(link) {
631664

632665
//calculate attachment points to child links
633666

634-
635667
if (link.leftType == types.WORD && link.rightType == types.WORD) {
636668
calcAttachPoints(link, Config.word2word_strategy);
637669
} else if (link.leftType == types.LINK && link.rightType == types.LINK) {
@@ -644,17 +676,21 @@ function createLink(link) {
644676
//calculate attachment points to root
645677
var checkSlotAt = 1;
646678
var minWord, minSide, maxWord, maxSide;
647-
679+
//console.log("\n\n*** \n\n in createLink" + link.words);
680+
//console.log("left link type: " + link.leftType);
681+
//console.log("left link word: " + link.leftWord);
648682
var rootWordAndSide = traceBackToWordObj(link, link.leftType, link.leftWord, link.leftAttach);
649683
link.rootMinWord = rootWordAndSide.w;
650684
link.rootMinSide = rootWordAndSide.s;
651-
685+
//console.log("rootWordAndSideMin: " + rootWordAndSide.w);
686+
652687
checkSlotAt = Math.max(checkSlotAt, link.leftWord.h + 1);
653-
688+
//console.log("right link type: " + link.rightType);
689+
//console.log("right link word: " + link.rightWord);
654690
var rootWordAndSide = traceBackToWordObj(link, link.rightType, link.rightWord, link.rightAttach);
655691
link.rootMaxWord = rootWordAndSide.w;
656692
link.rootMaxSide = rootWordAndSide.s;
657-
693+
//console.log("rootWordAndSideMax: " + rootWordAndSide.w);
658694
checkSlotAt = Math.max(checkSlotAt, link.rightWord.h + 1); //minimum height to start checking
659695
//set checkSlotAt to 1 if you want to be able to connect from underneath
660696

js/enums.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ var strategies = {
2222
FARTHEST: 1,
2323
};
2424

25+
var swapside = {
26+
YES: 1,
27+
NO: 0
28+
};
2529

js/render.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ function drawAllLinkLabels() {
767767
/** redraws all links that have been marked as needsUpdate = true, OR by passing in a boolean of true to indicate that the window has resized **/
768768
function redrawLinks(forceRedrawingAll) { //force redraw of all when resizing window
769769

770-
console.log("inredraw links:" + forceRedrawingAll);
770+
console.log("\n\n***\n\n in redraw links:" + forceRedrawingAll);
771771
Object.keys(linkObjs).forEach(function(key) {
772772
if (linkObjs[key].needsUpdate || forceRedrawingAll == true) {
773773
console.log(" link #" + key + " needsUpdate");
@@ -789,6 +789,7 @@ function getLeftXForWord(word, link) {
789789
if (word instanceof Word) { //is a word
790790
return word.leftX;
791791
} else { //is a link
792+
792793
if (link.leftAttach == sides.LEFT) {
793794
return word.linesLeftX[0];
794795
} else if (link.leftAttach == sides.RIGHT){
@@ -1372,6 +1373,14 @@ function drawLink(link) {
13721373
var minRow = link.rootMinWord.row.idx;
13731374
var maxRow = link.rootMaxWord.row.idx;
13741375

1376+
console.log("minWord: " + link.rootMinWord);
1377+
console.log("minRow: " + link.rootMinWord.row.idx);
1378+
1379+
/* Object.keys(linkObjs).forEach(function(key) {
1380+
console.log("link minWord: " + linkObjs[key].rootMinWord);
1381+
console.log("link minRow: " + linkObjs[key].rootMinWord.row);
1382+
});
1383+
*/
13751384
link.numLineSegments = (maxRow - minRow)+1;
13761385

13771386
var linkStyles;

0 commit comments

Comments
 (0)