@@ -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
420461function 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
0 commit comments