@@ -350,11 +350,12 @@ function setUpRowsAndWords(words) {
350350 word . row = row ;
351351 word . tw = wh . w ;
352352
353- //TODO - check if word has an associated tag
354- if ( twh . w > word . tw ) {
355- word . tw = twh . w ; //think tw is ONLY used for checking minWidth, so this should be ok
353+ if ( word . tag != null ) {
354+ if ( twh . w > word . tw ) {
355+ word . tw = twh . w ; //think tw is ONLY used for checking minWidth, so this should be ok
356+ }
356357 }
357-
358+
358359 word . th = texts . wordText . maxHeight ; //guaranteed to be the same for all words
359360
360361 x += wh . w + ( textpaddingX * 2 ) + wordpadding ;
@@ -386,29 +387,36 @@ function setUpRowsAndWords(words) {
386387 word . h = 0 ; //the number of link levels is 0 for the word
387388
388389 var textwh = getTextWidthAndHeight ( word . val , texts . wordText . style ) ;
389- var tagtextwh = getTextWidthAndHeight ( "TAGABCDEF" , texts . tagText . style ) ;
390-
391- //make sure that we are using the longest word to set the width (if a tag is present in this word)
392390 word . maxtextw = textwh . w ;
393- if ( tagtextwh . w > word . maxtextw ) {
394- word . maxtextw = tagtextwh . w ;
391+
392+ if ( word . tag != null ) {
393+
394+ var tagtextwh = getTextWidthAndHeight ( word . tag , texts . tagText . style ) ;
395+
396+ //make sure that we are using the longest word to set the width (if a tag is present in this word)
397+ if ( tagtextwh . w > word . maxtextw ) {
398+ word . maxtextw = tagtextwh . w ;
399+ }
400+
395401 }
396402
397-
398403 word . ww = word . maxtextw + ( textpaddingX * 2 ) ;
399404 word . wx = x ;
400405
401406 word . wh = texts . wordText . maxHeight + textpaddingY * 2 ;
402407 word . wy = row . ry + row . rh - word . wh ;
403408
404- var tag_textwh = getTextWidthAndHeight ( "TAG" , texts . tagText . style ) ;
405- word . tww = word . maxtextw + ( textpaddingX * 2 ) ;
406- word . twx = word . wx ;
409+ if ( word . tag != null ) {
410+ var tag_textwh = getTextWidthAndHeight ( word . tag , texts . tagText . style ) ;
411+ word . tww = word . maxtextw + ( textpaddingX * 2 ) ;
412+ word . twx = word . wx ;
407413
408- word . twh = texts . tagText . maxHeight + textpaddingY * 2 ;
409- word . twy = word . wy - word . twh ;
414+ word . twh = texts . tagText . maxHeight + textpaddingY * 2 ;
415+ word . twy = word . wy - word . twh ;
410416
411- x += word . maxtextw + ( textpaddingX * 2 ) + wordpadding ;
417+ }
418+
419+ x += word . maxtextw + ( textpaddingX * 2 ) + wordpadding ;
412420
413421
414422 /*
@@ -453,88 +461,90 @@ function drawWord(word) {
453461
454462 console . log ( "text.y = " + text . y ( ) ) ;
455463
456- var textwh = getTextWidthAndHeight ( "TAGABCDEF" , texts . tagText . style ) ;
457- var tagXPos = word . twx + ( word . ww / 2 ) - ( textwh . w / 2 ) ;
464+ if ( word . tag != null ) {
465+ var textwh = getTextWidthAndHeight ( word . tag , texts . tagText . style ) ;
466+ var tagXPos = word . twx + ( word . ww / 2 ) - ( textwh . w / 2 ) ;
458467
459468
460- //add in tag text, IF the word has an associated tag
461- var tagtext = draw . text ( function ( add ) {
469+ //add in tag text, IF the word has an associated tag
470+ var tagtext = draw . text ( function ( add ) {
462471
463- add . text ( "TAGABCDEF" )
464- . y ( word . wy + textpaddingY / 2 - texts . tagText . descent )
465- . x ( tagXPos )
466- . font ( texts . tagText . style ) ;
467- } ) ;
472+ add . text ( word . tag )
473+ . y ( word . wy + textpaddingY / 2 - texts . tagText . descent )
474+ . x ( tagXPos )
475+ . font ( texts . tagText . style ) ;
476+ } ) ;
468477
478+ }
469479
470- //this rect is invisible, but used for detecting mouseevents, as its drawn on top of the text+underneathRect (which provided the color+fill+stroke)
471- var rect = draw . rect ( word . ww , word . wh ) . x ( word . wx ) . y ( word . wy ) . fill ( { color :'#fff' , opacity : 0.0 } ) ;
480+ //this rect is invisible, but used for detecting mouseevents, as its drawn on top of the text+underneathRect (which provided the color+fill+stroke)
481+ var rect = draw . rect ( word . ww , word . wh ) . x ( word . wx ) . y ( word . wy ) . fill ( { color :'#fff' , opacity : 0.0 } ) ;
472482
473- var leftHandle = draw . rect ( handleW , handleH ) . x ( word . wx ) . y ( word . wy + ( word . wh / 2 ) - ( handleH / 2 ) ) . style ( styles . handleFill . style ) ;
483+ var leftHandle = draw . rect ( handleW , handleH ) . x ( word . wx ) . y ( word . wy + ( word . wh / 2 ) - ( handleH / 2 ) ) . style ( styles . handleFill . style ) ;
474484
475485
476- var rightHandle = draw . rect ( handleW , handleH ) . x ( word . wx + word . ww - ( handleW ) ) . y ( word . wy + ( word . wh / 2 ) - ( handleH / 2 ) ) . style ( styles . handleFill . style ) ;
486+ var rightHandle = draw . rect ( handleW , handleH ) . x ( word . wx + word . ww - ( handleW ) ) . y ( word . wy + ( word . wh / 2 ) - ( handleH / 2 ) ) . style ( styles . handleFill . style ) ;
477487
478488
479- word . text = text ;
480- word . tagtext = tagtext ;
489+ word . text = text ;
490+ word . tagtext = tagtext ;
481491
482492
483- word . rectSVG = rect ;
484- word . underneathRect = underneathRect ;
485- word . rect = rect . bbox ( ) ;
486- word . leftX = rect . bbox ( ) . x ;
487- word . rightX = rect . bbox ( ) . x + rect . bbox ( ) . w ;
488- word . leftHandle = leftHandle ;
489- word . rightHandle = rightHandle ;
490- word . percPos = ( word . leftX - edgepadding ) / ( svgWidth - edgepadding * 2 ) ;
493+ word . rectSVG = rect ;
494+ word . underneathRect = underneathRect ;
495+ word . rect = rect . bbox ( ) ;
496+ word . leftX = rect . bbox ( ) . x ;
497+ word . rightX = rect . bbox ( ) . x + rect . bbox ( ) . w ;
498+ word . leftHandle = leftHandle ;
499+ word . rightHandle = rightHandle ;
500+ word . percPos = ( word . leftX - edgepadding ) / ( svgWidth - edgepadding * 2 ) ;
491501
492- setUpLeftHandleDraggable ( leftHandle , rect , text , word , word . idx ) ;
493- setUpRightHandleDraggable ( rightHandle , rect , text , word , word . idx ) ;
502+ setUpLeftHandleDraggable ( leftHandle , rect , text , word , word . idx ) ;
503+ setUpRightHandleDraggable ( rightHandle , rect , text , word , word . idx ) ;
494504
495- setUpWordDraggable ( word ) ;
496- setupMouseOverInteractions ( word ) ;
505+ setUpWordDraggable ( word ) ;
506+ setupMouseOverInteractions ( word ) ;
497507
498- rect . dblclick ( function ( ) {
499- word . isSelected = ! word . isSelected ;
508+ rect . dblclick ( function ( ) {
509+ word . isSelected = ! word . isSelected ;
500510
501- if ( word . isSelected ) {
502- style = word . isHovered ? "hoverAndSelect" : "select" ;
503- }
504- else {
505- style = word . isHovered ? "hover" : "style" ;
506- }
507- underneathRect . style ( styles . wordFill [ style ] ) ;
508- } ) ;
511+ if ( word . isSelected ) {
512+ style = word . isHovered ? "hoverAndSelect" : "select" ;
513+ }
514+ else {
515+ style = word . isHovered ? "hover" : "style" ;
516+ }
517+ underneathRect . style ( styles . wordFill [ style ] ) ;
518+ } ) ;
509519
510520
511- //if (word.tag) {
512- // drawTag(word);
513- //}
521+ //if (word.tag) {
522+ // drawTag(word);
523+ //}
514524
515525}
516526
517527
518528function drawTag ( word ) {
519529
520- var textwh = getTextWidthAndHeight ( "TAGABCDEF" , texts . tagText . style ) ;
530+ var textwh = getTextWidthAndHeight ( "TAGABCDEF" , texts . tagText . style ) ;
521531
522- console . log ( "\n***\n" ) ;
523- console . log ( "textwh.w = " + textwh . w ) ;
524- console . log ( "textwh.h = " + textwh . h ) ;
525- console . log ( "word.twx = " + word . twx ) ;
526- console . log ( "word.twy = " + word . twy ) ;
527- console . log ( "word.twh = " + word . twh ) ;
532+ console . log ( "\n***\n" ) ;
533+ console . log ( "textwh.w = " + textwh . w ) ;
534+ console . log ( "textwh.h = " + textwh . h ) ;
535+ console . log ( "word.twx = " + word . twx ) ;
536+ console . log ( "word.twy = " + word . twy ) ;
537+ console . log ( "word.twh = " + word . twh ) ;
528538
529539
530540
531- var tagXPos = word . twx + ( word . ww / 2 ) - ( textwh . w / 2 ) ;
541+ var tagXPos = word . twx + ( word . ww / 2 ) - ( textwh . w / 2 ) ;
532542
533543
534544 underneathTagRect = draw . rect ( textwh . w + textpaddingX * 2 , word . twh ) . x ( tagXPos - textpaddingX ) . y ( word . twy ) . style ( styles . tagFill . style ) ;
535545 //underneathTagRect = draw.rect( 100,100 ).x( 100 ).y( 100 ); //.style(styles.wordFill.style);
536546
537- var text = draw . text ( function ( add ) {
547+ var text = draw . text ( function ( add ) {
538548
539549 add . text ( "TAGABCDEF" )
540550 . y ( word . twy + textpaddingY * 2 - texts . wordText . descent )
0 commit comments