Skip to content

Commit 7149dca

Browse files
author
angusforbes
committed
Cleans up code in interact.js, simplifies the drag handle and drag word
code.
1 parent 000efa5 commit 7149dca

File tree

5 files changed

+169
-438
lines changed

5 files changed

+169
-438
lines changed

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@
134134

135135

136136
// 1. create Words and Links objects (in utils.js) */
137-
var wordObjs = createTestWords(12, 1, 15);
137+
var wordObjs = createTestWords(10, 1, 11);
138138
//var wordObjs = [];
139139
//wordObjs.push(new Word("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0));
140140
//wordObjs.push(new Word("bbbbbbbbbbbbbbbbbbbbbbbbbb", 1));
141141

142142

143-
//var linkObjs = createTestLinks(0, 0, 0);
144143
var linkObjs = createTestLinks(3, 3, 3);
144+
//var linkObjs = createTestLinks(3, 3, 3);
145145

146146
// 2. draw words and boxes around words
147147
drawWords(wordObjs);

js/annotate.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class Word {
124124
return Math.max(minWordWidth, this.tw);
125125
}
126126

127+
/* must return a value less than row width - edgepaddings, else will try to reposition long words forever! */
127128
getMaxWidth() {
128129
return (this.row.rect.width() - (edgepadding*2)) / 3.1;
129130
}
@@ -177,7 +178,8 @@ function checkAndUpdateWordToWordSlots(link, startSlot) { //, minWord, minSide,
177178

178179
if (i == wo1.idx) { //check right side...
179180

180-
if (side1 == 0) { //then have to check left side too...
181+
//side1 == 0
182+
if (side1 == sides.LEFT) { //then have to check left side too...
181183

182184
if (checkSlotAvailabity(x, wordObjs[i].slotsL)) {
183185

@@ -210,7 +212,8 @@ function checkAndUpdateWordToWordSlots(link, startSlot) { //, minWord, minSide,
210212
break;
211213
}
212214

213-
if (side2 == 1) { //then have to check right side too...
215+
//side2 == 1
216+
if (side2 == sides.RIGHT) { //then have to check right side too...
214217

215218
if (checkSlotAvailabity(x, wordObjs[i].slotsR)) {
216219
slotIsAvailable = false;
@@ -233,7 +236,8 @@ function checkAndUpdateWordToWordSlots(link, startSlot) { //, minWord, minSide,
233236

234237
if (i == wo1.idx) { //update right side...
235238

236-
if (side1 == 0) {
239+
//side1 == 0
240+
if (side1 == sides.LEFT) {
237241
wordObjs[i].slotsL.push(useSlot);
238242
}
239243

@@ -248,7 +252,8 @@ function checkAndUpdateWordToWordSlots(link, startSlot) { //, minWord, minSide,
248252

249253
wordObjs[i].slotsL.push(useSlot);
250254

251-
if (side2 == 1) {
255+
//side2 == 1
256+
if (side2 == sides.RIGHT) {
252257
wordObjs[i].slotsR.push(useSlot);
253258
}
254259
}
@@ -475,21 +480,23 @@ function createLink(link) {
475480
//console.log("rightWord = " + link.rightWord.id);
476481

477482
//explicitly link parents of link (i.e., links that attach to this link)
478-
if (link.leftAttach == 0) {
483+
//if (link.leftAttach == 0) {
484+
if (link.leftAttach == sides.LEFT) {
479485
//console.log(link.leftWord);
480486
//console.log(link.leftWord.parentsL);
481487
link.leftWord.parentsL.push(link);
482-
} else {
488+
} else if (link.leftAttach == sides.RIGHT) {
483489
//console.log(link.leftWord);
484490
//console.log(link.leftWord.parentsR);
485491
link.leftWord.parentsR.push(link);
486492
}
487493

488-
if (link.rightAttach == 0) {
494+
//if (link.rightAttach == 0) {
495+
if (link.rightAttach == sides.LEFT) {
489496
//console.log(link.rightWord);
490497
//console.log(link.rightWord.parentsL);
491498
link.rightWord.parentsL.push(link);
492-
} else {
499+
} else if (link.rightAttach == sides.RIGHT) {
493500
//console.log(link.rightWord);
494501
//console.log(link.rightWord.parentsR);
495502
link.rightWord.parentsR.push(link);

js/enums.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ var types = {
55
};
66

77
var sides = {
8-
LEFT: 0,
8+
LEFT: -1,
9+
CENTER: 0,
910
RIGHT: 1,
1011
};
1112

0 commit comments

Comments
 (0)