Skip to content

Commit b142aeb

Browse files
author
angusforbes
committed
Fixes a bug with recalculateRows, which is fired when the window size
changes. Now it repositions words correctly again, when necessary (like when there's no room for words on a row to compress anymore anymore)
1 parent 9f2e9a6 commit b142aeb

File tree

5 files changed

+174
-289
lines changed

5 files changed

+174
-289
lines changed

index.html

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,14 @@
8383
var isDragging = false;
8484

8585
var levelpadding = 16;
86-
var /*textpadding */ textpaddingX = 12; //this is the x-padding within each word rect, between the text and the rectangle it's inside of
86+
var /*textpadding */ textpaddingX = 8;//12; //this is the x-padding within each word rect, between the text and the rectangle it's inside of
8787
var textpaddingY = 4;//texts.wordText.maxHeight / 2; //padding above and below text, between text and rectangle it's inside of
88-
var wordpadding = 5; //x padding between the rects containing words
89-
var topMargin = 0;
88+
var wordpadding = 4; //x padding between the rects containing words
89+
//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)
91+
var hideLinkLinesPercentage = 3.0; //percentage at which links and arrows are hidden
92+
var hideLinkTextPercentage = 7.0; //percentage at which words are link words are hidden
93+
9194

9295

9396
var handleW = 10;
@@ -102,7 +105,6 @@
102105

103106
var wordHeight = texts.wordText.maxHeight + (textpaddingY * 2);
104107
var minWordWidth = getTextWidthAndHeight("i", texts.wordText.style).w + (handleW * 2);
105-
//var minWordWidth = 10; //used when dragging handles to shrink or grow word size
106108

107109

108110
var evenRowsColor_selected = '#cdcdff';
@@ -125,34 +127,23 @@
125127

126128
var attachmentMargin = 0.1; //percentage value
127129

128-
var arrowColor = '#000000';
129-
var arrowOpacity = 1.0;
130-
131130
var word2word_strategy = strategies.FARTHEST;
132-
var word2link_strategy = strategies.FARTHEST;
133-
var link2link_strategy = strategies.FARTHEST; //CLOSEST sometimes causes overlaps - need to be a bit more rigorous when assigning slots - don't assign any slots that have the potential to overlap (when dragged manually)? - or let the buyer beware that this could happen - they can always move out of the way - right now it won't automatically overlap, but won't prevent a user from doing it.
131+
var word2link_strategy = strategies.CLOSEST;
132+
var link2link_strategy = strategies.CLOSEST; //CLOSEST sometimes causes overlaps - need to be a bit more rigorous when assigning slots - don't assign any slots that have the potential to overlap (when dragged manually)? - or let the buyer beware that this could happen - they can always move out of the way - right now it won't automatically overlap, but won't prevent a user from doing it.
134133

135134
var rows = []; //list of Row object, each of those has a list of Word objects
136135

137136

138137
// 1. create Words and Links objects (in utils.js) */
139-
var wordObjs = createTestWords(13, 5, 11);
140-
//var wordObjs = [];
141-
//wordObjs.push(new Word("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0));
142-
//wordObjs.push(new Word("bbbbbbbbbbbbbbbbbbbbbbbbbb", 1));
143-
138+
var wordObjs = createTestWords(15, 1, 15);
144139

145140
//var linkObjs = createTestLinks(1,1,0);
146141
var linkObjs = createTestLinks(4,4,4);
147142

148-
149143
// 2. draw words and boxes around words
150144
drawWords(wordObjs);
151145

152146
// 3. draw each of the links
153-
var hidePercentage = 3;
154-
var hidePercentage2 = 7;
155-
156147
drawLinks(linkObjs);
157148

158149
var prevWidth = svgWidth;

js/annotate.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,36 +178,22 @@ class Word {
178178

179179
// console.log("\n***\nin update X = " + this.tempX + ", Y = " + this.tempY + ", W = " + this.tempW );
180180
this.rectSVG.x(this.tempX);
181-
//this.rectSVG.y(this.tempY);
182181
this.rectSVG.width(this.tempW);
183182

184183
this.underneathRect.x(this.tempX);
185-
//this.underneathRect.y(this.tempY);
186184
this.underneathRect.width(this.tempW);
187185

188186
this.rect = this.rectSVG.bbox();
189-
190-
191187

192188
this.text.x(this.tempX + (this.tempW/2) - (this.text.bbox().w / 2) );
193-
//this.text.y(this.tempY + textpaddingY);
194-
195189

196190
this.leftX = this.tempX;
197191
this.rightX = this.tempX + this.tempW;
198192

199193
this.percPos = (this.leftX-edgepadding) / (svgWidth-edgepadding*2);
200194

201-
202-
//var handley = this.tempY + ( this.wh / 2 ) - ( handleH / 2 );
203-
204195
this.leftHandle.x(this.tempX);
205-
//this.leftHandle.y(handley);
206-
207-
208196
this.rightHandle.x(this.rightX - handleW);
209-
//this.rightHandle.y(handley);
210-
211197
}
212198

213199

js/interact.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ function updateLinksOfWord(word) {
7979
}
8080

8181

82+
function updateAllLinks() {
83+
for (let item of linkObjs) {
84+
item.needsUpdate = true;
85+
}
86+
}
8287

8388
function updateLinks(link) {
8489

@@ -470,7 +475,7 @@ function dragLeftHandle(x, y, word) {
470475
function checkIfCanDragLeftHandleLeft(x, y, word) {
471476
var rw = Math.max( Math.min(word.getMaxWidth(), (word.rightX - x)), word.getMinWidth() );
472477

473-
setWordToXWY(word, x, rw, y);
478+
setWordToXW(word, x, rw);
474479

475480
var rv = checkIfCanMoveLeft(x, rw, y, word, true);
476481
rv.y = word.y;
@@ -481,7 +486,7 @@ function checkIfCanDragLeftHandleRight(x, y, word) {
481486

482487
var rw = Math.max( Math.min(word.getMaxWidth(), (word.rightX - x) ), word.getMinWidth() );
483488

484-
setWordToXWY(word, x, rw, y);
489+
setWordToXW(word, x, rw);
485490

486491
var rv = checkIfCanMoveRight(x, rw, y, word, true);
487492
rv.y = word.y;
@@ -510,7 +515,7 @@ function dragRightHandle(x, y, word) {
510515
function checkIfCanDragRightHandleLeft(x, y, word) {
511516
var rw = Math.max( Math.min(word.getMaxWidth(), (x - word.leftX + handleW)), word.getMinWidth() );
512517

513-
setWordToXWY(word, word.leftX, rw, y);
518+
setWordToXW(word, word.leftX, rw);
514519

515520
var rv = checkIfCanMoveLeft(x - (rw - handleW), rw, y, word, false);
516521
//rv.x = word.leftX + rw - handleW;
@@ -526,7 +531,7 @@ function checkIfCanDragRightHandleRight(x, y, word) {
526531

527532
var rw = Math.max( Math.min(word.getMaxWidth(), (x - word.leftX + handleW) ), word.getMinWidth() );
528533

529-
setWordToXWY(word, word.leftX, rw, y);
534+
setWordToXW(word, word.leftX, rw);
530535

531536
var rv = checkIfCanMoveRight(x - (rw - handleW), rw, y, word, false);
532537
//rv.x = word.leftX + rw - handleW;
@@ -582,6 +587,9 @@ function checkIfCanMoveRight(x, w, y, word, adjustWidth) {
582587
}
583588

584589

590+
w = Math.max( Math.min(w, word.getMaxWidth()), word.getMinWidth()) ;
591+
592+
585593
/* Check to see if the word needs to jump to the next row */
586594

587595
//am i the last word (or only word) in this row?
@@ -609,7 +617,7 @@ function checkIfCanMoveRight(x, w, y, word, adjustWidth) {
609617
}
610618

611619
/* Set new position of this word */
612-
setWordToXWY(word, rx, w, ry);
620+
setWordToXW(word, rx, w);
613621

614622
/* Does it push into the next word? */
615623
posInRow = word.row.words.indexOf(word);
@@ -728,7 +736,9 @@ function checkIfCanMoveLeft(x, w, y, word, adjustWidth) {
728736
rw = w;
729737
}
730738

731-
setWordToXWY(word, rx, rw, ry);
739+
//rw = Math.max( Math.min(rw, word.getMaxWidth()), word.getMinWidth()) ;
740+
741+
setWordToXW(word, rx, rw);
732742

733743

734744
return {x:rx, y:ry};
@@ -740,8 +750,7 @@ function moveWordToNewPosition(w, nx, ny) {
740750

741751
w.tempX = nx;
742752
w.tempW = w.rect.w;
743-
//w.needsUpdate = true;
744-
753+
745754
w.rectSVG.x(nx);
746755
w.rectSVG.y(ny);
747756

@@ -764,10 +773,12 @@ function moveWordToNewPosition(w, nx, ny) {
764773
w.rightHandle.x( w.rightX - handleW );
765774
w.rightHandle.y(handley);
766775

776+
w.needsUpdate = true;
777+
767778
}
768779

769780

770-
function setWordToXWY(word, xval, wval, yval) {
781+
function setWordToXW(word, xval, wval) {
771782

772783
word.tempX = xval;
773784
word.tempW = wval;
@@ -967,7 +978,7 @@ function dragRow(x, y, row) {
967978

968979
for (var i = 0; i < row.words.length; i++) {
969980
setWordToY(row.words[i], row.lineBottom.bbox().y - row.words[i].rectSVG.height() );
970-
updateLinksOfWord(row.words[i]);
981+
//updateLinksOfWord(row.words[i]);
971982
}
972983

973984
row.baseHeight = row.lineBottom.y() - (textpaddingY*2) - texts.wordText.maxHeight;
@@ -986,13 +997,12 @@ function dragRow(x, y, row) {
986997
nextrow.lineTop.y(row.rect.bbox().y + row.rect.bbox().h + 5);
987998

988999
for (var i = 0; i < nextrow.words.length; i++) {
989-
updateLinksOfWord(nextrow.words[i]);
1000+
//updateLinksOfWord(nextrow.words[i]);
9901001
}
9911002
}
9921003

993-
//redrawLinks();
994-
//updateWords();
995-
1004+
//hmm... what about links that pass through the row, but aren't attached to any word on this row?
1005+
updateAllLinks(); //this works for now
9961006

9971007
var returnVal = {x:row.dragRect.bbox().x, y:y};
9981008

0 commit comments

Comments
 (0)