@@ -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 = [ ] ;
@@ -120,6 +121,9 @@ class Link {
120121 this . rightWord = this . words [ this . words . length - 1 ] ;
121122 this . id = `(${ this . leftWord . id } , ${ this . rightWord . id } )` ;
122123
124+ console . log ( "\n\n *** \n\n in setStartAndEnd" ) ;
125+ console . log ( "leftWord: " + this . leftWord ) ;
126+ console . log ( "rightWord: " + this . rightWord ) ;
123127
124128 if ( this . leftWord instanceof Word ) {
125129 this . leftType = types . WORD ;
@@ -414,15 +418,16 @@ function checkAndUpdateWordToWordSlots(link, startSlot) { //, minWord, minSide,
414418}
415419
416420//current link, the word we're tracing, and the side that it's on
417- function traceBackToWordObj ( link , type , word , attach ) {
421+ function traceBackToNearestWordObj ( link , type , word , attach ) {
418422
419423 var retVal = { w : - 1 , s : - 1 } ;
420424
421425 if ( type == types . WORD ) {
422- //// console.log("in traceback, node is a word, wordObj.val = " + word.val + ", attachSide = " + attach);
426+ console . log ( "in traceback, node is a word, wordObj.val = " + word . val + ", attachSide = " + attach ) ;
423427
424428 retVal . w = word ;
425429 retVal . s = attach ;
430+
426431 return retVal ;
427432
428433 } else {
@@ -439,44 +444,113 @@ function traceBackToWordObj(link, type, word, attach) {
439444 nextAttach = nextLink . leftAttach ;
440445
441446 } else { // right
442-
447+
443448 //nextType = nextLink.te;
444449 nextType = nextLink . rightType ;
445450 nextWord = nextLink . rightWord ;
446451 nextAttach = nextLink . rightAttach ;
447452
448453 }
449454
450- //// console.log("now going to traceback... link: " + nextLink + ", nextType: " + nextType + " nextWord " + nextWord.val + ", nextAttach: " + nextAttach);
455+ console . log ( "now going to traceback... link: " + nextLink + ", nextType: " + nextType + " nextWord " + nextWord . val + ", nextAttach: " + nextAttach ) ;
451456
452457 return traceBackToWordObj ( nextLink , nextType , nextWord , nextAttach ) ;
453458 }
454459}
460+ //current link, the word we're tracing, and the side that it's on
461+ function traceBackToWordObj ( link , type , word , attach ) {
455462
463+ var retVal = { w : - 1 , s : - 1 } ;
456464
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 ) {
465+ if ( type == types . WORD ) {
466+ console . log ( "in traceback, node is a word, wordObj.val = " + word . val + ", attachSide = " + attach ) ;
459467
460- var rootS , rootE ;
468+ retVal . w = word ;
469+ retVal . s = attach ;
461470
462- if ( link . leftType == types . WORD ) {
463- rootS = link . leftWord . idx ;
464- //console.log("rootS = " + link.leftWord.id);
471+ return retVal ;
465472
466473 } else {
467- rootS = link . leftWord . rootMinWord . idx ;
468- //console.log("rootS = " + link.leftWord.rootMinWord.id);
474+ //// console.log("in traceback, node is a link, wordObj.val, attachSide = " + attach);
469475
470- }
476+ var nextLink = word ;
477+ var nextType , nextWord , nextAttach ;
471478
472- if ( link . rightType == types . WORD ) {
473- rootE = link . rightWord . idx ;
474- //console.log("rootE = " + link.rightWord.id);
479+ console . log ( "nextLinkleft: " + nextLink . leftWord ) ;
480+ console . log ( "nextLinkleft: " + nextLink . rightWord ) ;
481+ if ( determineSide ( link ) == swapside . YES ) {
482+ if ( attach == sides . RIGHT ) { //left
475483
476- } else {
477- rootE = link . rightWord . rootMaxWord . idx ;
478- //console.log("rootE = " + link.rightWord.rootMaxWord.id);
484+ //nextType = nextLink.ts;
485+ nextType = nextLink . leftType ;
486+ nextWord = nextLink . leftWord ;
487+ nextAttach = nextLink . leftAttach ;
488+
489+ } else { // right
490+
491+ //nextType = nextLink.te;
492+ nextType = nextLink . rightType ;
493+ nextWord = nextLink . rightWord ;
494+ nextAttach = nextLink . rightAttach ;
495+
496+ }
497+ }
498+ else {
499+ if ( attach == sides . LEFT ) { //left
500+
501+ //nextType = nextLink.ts;
502+ nextType = nextLink . leftType ;
503+ nextWord = nextLink . leftWord ;
504+ nextAttach = nextLink . leftAttach ;
505+
506+ } else { // right
507+
508+ //nextType = nextLink.te;
509+ nextType = nextLink . rightType ;
510+ nextWord = nextLink . rightWord ;
511+ nextAttach = nextLink . rightAttach ;
512+
513+ }
514+ }
515+
516+ console . log ( "now going to traceback... link: " + nextLink + ", nextType: " + nextType + " nextWord " + nextWord . val + ", nextAttach: " + nextAttach ) ;
517+
518+ return traceBackToWordObj ( nextLink , nextType , nextWord , nextAttach ) ;
479519 }
520+ }
521+
522+ function determineSide ( link ) {
523+ var rootS , rootE ;
524+
525+ if ( link . leftType == types . WORD ) {
526+ rootS = link . leftWord . idx ;
527+ //console.log("rootS = " + link.leftWord.id);
528+
529+ } else {
530+ rootS = link . leftWord . rootMinWord . idx ;
531+ //console.log("rootS = " + link.leftWord.rootMinWord.id);
532+
533+ }
534+
535+ if ( link . rightType == types . WORD ) {
536+ rootE = link . rightWord . idx ;
537+ //console.log("rootE = " + link.rightWord.id);
538+
539+ } else {
540+ rootE = link . rightWord . rootMaxWord . idx ;
541+ //console.log("rootE = " + link.rightWord.rootMaxWord.id);
542+ }
543+
544+ if ( rootS < rootE ) {
545+ return swapside . YES ;
546+ }
547+ else {
548+ return swapside . NO ;
549+ }
550+ }
551+
552+ //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??
553+ function calcAttachPoints ( link , strategy ) {
480554
481555 //link.leftWord.nr += 1;
482556 //link.rightWord.nl += 1;
@@ -497,7 +571,7 @@ function calcAttachPoints(link, strategy) {
497571
498572 //console.log("" + link.id + " strategy = CLOSEST");
499573
500- if ( rootS < rootE ) {
574+ if ( determineSide ( link ) == swapside . YES ) {
501575 //console.log("rootS < rootE (" +rootS +" < " + rootE +")");
502576 link . leftWord . nr += 1 ;
503577 link . rightWord . nl += 1 ;
@@ -631,7 +705,6 @@ function createLink(link) {
631705
632706 //calculate attachment points to child links
633707
634-
635708 if ( link . leftType == types . WORD && link . rightType == types . WORD ) {
636709 calcAttachPoints ( link , Config . word2word_strategy ) ;
637710 } else if ( link . leftType == types . LINK && link . rightType == types . LINK ) {
@@ -644,17 +717,25 @@ function createLink(link) {
644717 //calculate attachment points to root
645718 var checkSlotAt = 1 ;
646719 var minWord , minSide , maxWord , maxSide ;
647-
720+ //console.log("\n\n*** \n\n in createLink" + link.words);
721+ //console.log("left link type: " + link.leftType);
722+ //console.log("left link word: " + link.leftWord);
648723 var rootWordAndSide = traceBackToWordObj ( link , link . leftType , link . leftWord , link . leftAttach ) ;
724+ var rootnearestWordAndSide = traceBackToNearestWordObj ( link , link . leftType , link . leftWord , link . leftAttach ) ;
649725 link . rootMinWord = rootWordAndSide . w ;
650726 link . rootMinSide = rootWordAndSide . s ;
727+ //console.log("rootWordAndSideMin: " + rootWordAndSide.w);
728+ link . nearestConnectedMinWord = rootnearestWordAndSide . w ;
651729
652730 checkSlotAt = Math . max ( checkSlotAt , link . leftWord . h + 1 ) ;
653-
654- var rootWordAndSide = traceBackToWordObj ( link , link . rightType , link . rightWord , link . rightAttach ) ;
731+ //console.log("right link type: " + link.rightType);
732+ //console.log("right link word: " + link.rightWord);
733+ rootWordAndSide = traceBackToWordObj ( link , link . rightType , link . rightWord , link . rightAttach ) ;
734+ rootWordAndSide = traceBackToNearestWordObj ( link , link . rightType , link . rightWord , link . rightAttach ) ;
655735 link . rootMaxWord = rootWordAndSide . w ;
656736 link . rootMaxSide = rootWordAndSide . s ;
657-
737+ //console.log("rootWordAndSideMax: " + rootWordAndSide.w);
738+ link . nearestConnectedMaxWord = rootnearestWordAndSide . w ;
658739 checkSlotAt = Math . max ( checkSlotAt , link . rightWord . h + 1 ) ; //minimum height to start checking
659740 //set checkSlotAt to 1 if you want to be able to connect from underneath
660741
0 commit comments