Skip to content

Commit f216aa8

Browse files
author
angusforbes
committed
Speeds up drawing of word svgs by only updating words at a) the end of a
drag event, or b) when a word moves to a new row.
1 parent 5155007 commit f216aa8

File tree

5 files changed

+802
-577
lines changed

5 files changed

+802
-577
lines changed

index.html

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

137137

138138
// 1. create Words and Links objects (in utils.js) */
139-
var wordObjs = createTestWords(10, 1, 11);
139+
var wordObjs = createTestWords(20, 5, 11);
140140
//var wordObjs = [];
141141
//wordObjs.push(new Word("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0));
142142
//wordObjs.push(new Word("bbbbbbbbbbbbbbbbbbbbbbbbbb", 1));
143143

144144

145+
//var linkObjs = createTestLinks(0, 0, 0);
145146
var linkObjs = createTestLinks(3, 3, 3);
146-
//var linkObjs = createTestLinks(3, 3, 3);
147147

148148
// 2. draw words and boxes around words
149149
drawWords(wordObjs);

js/annotate.js

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ class Link {
3636

3737
//this.rootMinWord
3838
//this.rootMaxWord
39-
39+
40+
4041
}
4142

43+
44+
4245
toString() {
4346
return this.id;
4447
}
@@ -117,24 +120,57 @@ class Word {
117120
this.rightHandle = null; //the right draggable handle to resize word
118121

119122

123+
//used for calculating positions during drag
124+
this.tempX = 0.0;
125+
this.tempW = 0.0;
126+
this.tempY = 0.0;
120127
}
121128

129+
130+
//take temp values and update actual svg values
131+
update() {
132+
133+
//console.log("\n***\nin update : " + this.tempW);
134+
this.rectSVG.x(this.tempX);
135+
this.rectSVG.width(this.tempW);
136+
137+
this.underneathRect.x(this.tempX);
138+
this.underneathRect.width(this.tempW);
139+
140+
141+
this.rect = this.rectSVG.bbox();
142+
143+
144+
145+
this.text.x(this.tempX + (this.tempW/2) - (this.text.bbox().w / 2) );
146+
this.leftX = this.tempX;
147+
this.rightX = this.tempX + this.tempW;
148+
149+
this.percPos = (this.leftX-edgepadding) / (svgWidth-edgepadding*2);
150+
151+
this.leftHandle.x(this.tempX);
152+
this.rightHandle.x(this.rightX - handleW);
153+
154+
155+
}
156+
157+
122158
draw() {
123-
console.log(" in Word " + this.val + " about to call drawWord");
159+
//console.log(" in Word " + this.val + " about to call drawWord");
124160
drawWord(this);
125161
}
126162

127163
getMinWidth() {
128164
return Math.max(minWordWidth, this.tw);
129165
}
130-
166+
131167
/* must return a value less than row width - edgepaddings, else will try to reposition long words forever! */
132168
getMaxWidth() {
133169
return (this.row.rect.width() - (edgepadding*2)) / 3.1;
134170
}
135171

136172
toString() {
137-
return this.id;
173+
return this.id;
138174
}
139175

140176
static testMe(val) {
@@ -177,7 +213,7 @@ function checkAndUpdateWordToWordSlots(link, startSlot) { //, minWord, minSide,
177213

178214
var slotIsAvailable = true;
179215

180-
216+
181217
for (var i = wo1.idx; i <= wo2.idx; i++) {
182218

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

0 commit comments

Comments
 (0)