Skip to content

Commit a5d440b

Browse files
committed
Merge branch 'master' of github.com:CreativeCodingLab/TextAnnotationGraphs
2 parents 0678488 + af4bfe0 commit a5d440b

File tree

5 files changed

+138
-25
lines changed

5 files changed

+138
-25
lines changed

index.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484

8585
var levelpadding = 16;
8686
var /*textpadding */ textpaddingX = 8;//12; //this is the x-padding within each word rect, between the text and the rectangle it's inside of
87-
var textpaddingY = 4;//texts.wordText.maxHeight / 2; //padding above and below text, between text and rectangle it's inside of
87+
var textpaddingY = 6;//texts.wordText.maxHeight / 2; //padding above and below text, between text and rectangle it's inside of
8888
var wordpadding = 4; //x padding between the rects containing words
8989
//var topMargin = 0;
9090
var edgepadding = 10; //padding between left side of svg canvas and where first word can be placed, and padding between right side of svg canvas and where last word on a row can fit (before popping over to next row)
@@ -104,7 +104,7 @@
104104
var arrowW = 3; //3
105105

106106
var wordHeight = texts.wordText.maxHeight + (textpaddingY * 2);
107-
var minWordWidth = getTextWidthAndHeight("i", texts.wordText.style).w + (handleW * 2);
107+
var minWordWidth = Math.max( getTextWidthAndHeight("i", texts.wordText.style).w + (handleW * 2), getTextWidthAndHeight("i", texts.tagText.style).w + (handleW * 2) );
108108

109109

110110
var evenRowsColor_selected = '#cdcdff';
@@ -135,8 +135,6 @@
135135

136136
</script>
137137

138-
139-
140138
<script>
141139

142140
/* these should eventually be made non-global too */

js/annotate.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ class Link {
33
constructor(s, e, direction, style, textStr, textStyle) {
44
this.s = s;
55
this.e = e;
6+
this.id = `(${this.s.id}, ${this.e.id})`;
67

7-
//directions and types can be different things
88
this.direction = direction; //see enums.directions
99
this.style = style;
1010

@@ -16,9 +16,11 @@ class Link {
1616
this.parentsR = [];
1717
this.h = 0; //which slot is it in
1818
this.lines = [];
19-
this.id = `(${this.s.id}, ${this.e.id})`;
2019

21-
this.type = "LINK";
20+
this.rootMinWord = null;
21+
this.rootMaxWord = null;
22+
23+
2224
if (this.s instanceof Word) {
2325
this.ts = types.WORD;
2426
} else if (this.s instanceof Link) {
@@ -66,21 +68,10 @@ class Link {
6668
this.labelRectSVGs = [];
6769
this.labelTextSVGs = [];
6870

69-
//this.polyline = null;
70-
//this.polylineSVG = null;
7171
this.label = null;
7272
this.labelRectSVG = null;
7373
this.labelTextSVG = null;
74-
//this.arrow1SVG = null;
75-
//this.arrow2SVG = null;
76-
77-
7874

79-
80-
81-
//this.rootMinWord
82-
//this.rootMaxWord
83-
8475

8576
}
8677

@@ -148,18 +139,20 @@ class Word {
148139
this.id = `(${this.val}, ${this.idx})`;
149140
this.percPos = 0.0; //this is used to indicate where along the row the word is positioned, used when resizing the browser's width, or when popping open a right panel.
150141

151-
this.type = "WORD";
152-
153142
this.isSelected = false;
154143
this.isHovered = false;
155144
this.isDragging = false;
156145

157146
//variables created in first render...
158-
//this.row; //this is a row object, for num do: this.row.idx
147+
//this.row; //this is a row object, for row num do: this.row.idx
159148
this.rectSVG = null; //the actual svg element
160149
this.rect = null; //the bbox of the svg element
161150
this.underneathRect = null; //not clickable, but solid rect on which other word parts are placed (text, handles, clickable rect)
162151
this.text = null; //the svg text
152+
this.tagtext = null; //the svg text for a tag
153+
154+
this.maxtextw = null; //either the word text width, or the tag text with, whichever is wider
155+
163156
this.leftHandle = null; //the left draggable handle to resize word
164157
this.rightHandle = null; //the right draggable handle to resize word
165158

@@ -186,6 +179,7 @@ class Word {
186179
this.rect = this.rectSVG.bbox();
187180

188181
this.text.x(this.tempX + (this.tempW/2) - (this.text.bbox().w / 2) );
182+
this.tagtext.x(this.tempX + (this.tempW/2) - (this.tagtext.bbox().w / 2) );
189183

190184
this.leftX = this.tempX;
191185
this.rightX = this.tempX + this.tempW;

js/interact.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,22 @@ function moveWordToNewPosition(w, nx, ny) {
764764
w.underneathRect.y(ny);
765765

766766
w.text.x(nx + (w.rect.w/2) - (w.text.bbox().w/2) );
767-
w.text.y(ny + textpaddingY);
767+
w.text.y(ny + textpaddingY*2 - texts.wordText.descent);
768+
769+
770+
771+
//TODO - make these match original position - the Y pos for text is off for tags and words - why isn't the text descent needed here?? ny and w.wy should be (and is!) the same - but the text y pos is a few pixels off!
772+
//Looks like the entire row size jumps one pixel when adding a new row... think this may cause the 1 px differentce
773+
w.tagtext.x(nx + (w.rect.w/2) - (w.tagtext.bbox().w/2) );
774+
w.tagtext.y(ny + textpaddingY/2);// - texts.tagText.descent);
775+
776+
console.log("ny = " + ny);
777+
console.log("w.wy = " + w.wy);
778+
console.log("w.text.y = " + w.text.y());
779+
780+
781+
782+
768783

769784
var handley = ny + ( w.wh / 2 ) - ( handleH / 2 );
770785
w.leftHandle.x(nx);

js/render.js

Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ function setUpRowsAndWords(words) {
323323
for (var i = 0; i < words.length; i++) {
324324

325325
var wh = getTextWidthAndHeight(wordObjs[i].val, texts.wordText.style);
326+
var twh = getTextWidthAndHeight(wordObjs[i].tag, texts.tagText.style);
326327

327328
if (i == 0) {
328329

@@ -348,6 +349,12 @@ function setUpRowsAndWords(words) {
348349
row.maxSlots = Math.max(row.maxSlots, getHeightForWord(word));
349350
word.row = row;
350351
word.tw = wh.w;
352+
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
356+
}
357+
351358
word.th = texts.wordText.maxHeight; //guaranteed to be the same for all words
352359

353360
x += wh.w + (textpaddingX*2) + wordpadding;
@@ -379,15 +386,51 @@ function setUpRowsAndWords(words) {
379386
word.h = 0; //the number of link levels is 0 for the word
380387

381388
var textwh = getTextWidthAndHeight(word.val, texts.wordText.style);
389+
var tagtextwh = getTextWidthAndHeight(word.tag, 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)
392+
word.maxtextw = textwh.w;
393+
if (tagtextwh.w > word.maxtextw) {
394+
word.maxtextw = tagtextwh.w;
395+
}
396+
397+
398+
word.ww = word.maxtextw + (textpaddingX * 2);
399+
word.wx = x;
400+
401+
word.wh = texts.wordText.maxHeight + textpaddingY*2;
402+
word.wy = row.ry + row.rh - word.wh;
403+
404+
var tag_textwh = getTextWidthAndHeight("TAG", texts.tagText.style);
405+
word.tww = word.maxtextw + (textpaddingX * 2);
406+
word.twx = word.wx;
407+
408+
word.twh = texts.tagText.maxHeight + textpaddingY*2;
409+
word.twy = word.wy - word.twh;
410+
411+
x += word.maxtextw + (textpaddingX*2) + wordpadding;
412+
413+
414+
/*
382415
word.ww = textwh.w + (textpaddingX * 2);
383416
word.wx = x;
384417
385418
word.wh = texts.wordText.maxHeight + textpaddingY*2;
386419
word.wy = row.ry + row.rh - word.wh;
387420
421+
var tag_textwh = getTextWidthAndHeight("TAG", texts.tagText.style);
422+
word.tww = tag_textwh.w + (textpaddingX * 2);
423+
word.twx = word.wx;
424+
425+
word.twh = texts.tagText.maxHeight + textpaddingY*2;
426+
word.twy = word.wy - word.twh;
427+
388428
x += textwh.w + (textpaddingX*2) + wordpadding;
429+
*/
430+
389431

390-
row.baseHeight = word.wy; //that is, where the top of the word is in the row.
432+
433+
row.baseHeight = word.wy; //that is, where the top of the word is in the row.
391434

392435
}
393436
}
@@ -402,11 +445,28 @@ function drawWord(word) {
402445
var text = draw.text(function(add) {
403446

404447
add.text(word.val)
405-
.y(word.wy + textpaddingY - texts.wordText.descent)
448+
.y(word.wy + textpaddingY*2 - texts.wordText.descent)
406449
.x(word.wx + (word.ww/2) - (textwh.w / 2))
407450
.font(texts.wordText.style);
408451
});
409452

453+
454+
console.log("text.y = " + text.y());
455+
456+
var textwh = getTextWidthAndHeight(word.tag, texts.tagText.style);
457+
var tagXPos = word.twx + (word.ww/2) - (textwh.w / 2);
458+
459+
460+
//add in tag text, IF the word has an associated tag
461+
var tagtext = draw.text(function(add) {
462+
463+
add.text(word.tag)
464+
.y(word.wy + textpaddingY/2 - texts.tagText.descent)
465+
.x(tagXPos)
466+
.font(texts.tagText.style);
467+
});
468+
469+
410470
//this rect is invisible, but used for detecting mouseevents, as its drawn on top of the text+underneathRect (which provided the color+fill+stroke)
411471
var rect = draw.rect(word.ww, word.wh).x( word.wx ).y( word.wy ).fill( {color:'#fff',opacity: 0.0} );
412472

@@ -416,8 +476,10 @@ function drawWord(word) {
416476
var rightHandle = draw.rect(handleW,handleH).x(word.wx + word.ww - (handleW)).y( word.wy + (word.wh / 2 ) - (handleH / 2) ).style(styles.handleFill.style);
417477

418478

419-
420479
word.text = text;
480+
word.tagtext = tagtext;
481+
482+
421483
word.rectSVG = rect;
422484
word.underneathRect = underneathRect;
423485
word.rect = rect.bbox();
@@ -444,9 +506,45 @@ function drawWord(word) {
444506
}
445507
underneathRect.style(styles.wordFill[style]);
446508
});
509+
510+
511+
//if (word.tag) {
512+
// drawTag(word);
513+
//}
514+
447515
}
448516

449517

518+
function drawTag(word) {
519+
520+
var textwh = getTextWidthAndHeight(word.tag, texts.tagText.style);
521+
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);
528+
529+
530+
531+
var tagXPos = word.twx + (word.ww/2) - (textwh.w / 2);
532+
533+
534+
underneathTagRect = draw.rect( textwh.w + textpaddingX*2, word.twh ).x( tagXPos - textpaddingX ).y( word.twy ).style(styles.tagFill.style);
535+
//underneathTagRect = draw.rect( 100,100 ).x( 100 ).y( 100 ); //.style(styles.wordFill.style);
536+
537+
var text = draw.text(function(add) {
538+
539+
add.text(word.tag)
540+
.y(word.twy + textpaddingY*2 - texts.wordText.descent)
541+
.x(tagXPos)
542+
.font(texts.tagText.style);
543+
});
544+
545+
546+
}
547+
450548

451549
var _linkLabels = [];
452550
var _links = [];

js/style.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,13 @@ function setupStyles(svg) {
360360
styleArr.wordFill.selecting('#fcc', 1.0, new LineStyle('#c99', 1));
361361
styleArr.wordFill.hoveringAndSelecting('#fcc', 1.0/*, new LineStyle('#000000', 1)*/);
362362

363+
364+
styleArr.tagFill = new FillStyle('#00ffff', 1.0, new LineStyle('#000', 1) );
365+
styleArr.tagFill.hovering('#ff0000', 1.0/*, new LineStyle('#000000', 1)*/);
366+
styleArr.tagFill.selecting('#fcc', 1.0, new LineStyle('#c99', 1));
367+
styleArr.tagFill.hoveringAndSelecting('#fcc', 1.0/*, new LineStyle('#000000', 1)*/);
368+
369+
363370
styleArr.labelEvenFill = new FillStyle(evenRowsColor, 1.0);
364371
styleArr.labelOddFill = new FillStyle(oddRowsColor, 1.0);
365372

@@ -381,6 +388,7 @@ function setupTexts(svg) {
381388

382389
textArr.wordText = new TextStyle('Brown, BrownPro, futura, helvetica', 12, new FillStyle('#444'));
383390
textArr.linkText = new TextStyle('Brown, BrownPro, futura, helvetica', 10, new FillStyle('#888'));
391+
textArr.tagText = new TextStyle('Brown, BrownPro, futura, helvetica', 12, new FillStyle('#888'));
384392

385393
return textArr;
386394
}

0 commit comments

Comments
 (0)