Skip to content

Commit 5155007

Browse files
author
angusforbes
committed
First pass at speeding up main link rendering loop.
1 parent 7149dca commit 5155007

File tree

6 files changed

+225
-293
lines changed

6 files changed

+225
-293
lines changed

index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171

7272
var rowGroup = draw.group();
7373
var groupAllElements;
74+
var linkG, textG, arrowG;
75+
7476
//var gradientDefGroup = draw.defs().group();
7577

7678
var styles = setupStyles(draw); //creates an associative array of whatever styles you want to make use of later

js/annotate.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11

22
class Link {
3-
constructor(s, e, direction, style) {
3+
constructor(s, e, direction, style, textStr, textStyle) {
44
this.s = s;
55
this.e = e;
66

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

11+
this.textStr = textStr;
12+
this.textStyle = textStyle;
13+
this.textWH = getTextWidthAndHeight(this.textStr, this.textStyle.style)
14+
1115
this.parentsL = [];
1216
this.parentsR = [];
1317
this.h = 0; //which slot is it in

js/interact.js

Lines changed: 18 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,13 @@ function setupLineInteractions(link) {
123123
l.mouseover( function() { link_mover(link) } );
124124
l.mouseout( function() { link_mout(link) } );
125125
}
126+
127+
126128
if (link.labelRect) {
127129
link.labelRect.forEach(addInteraction);
128130
}
129131
link.lines.forEach(addInteraction);
130-
132+
131133
//link.r1.mouseover( function() { link_mover(link) } );
132134
//link.r2.mouseover( function() { link_mover(link) } );
133135

@@ -517,7 +519,6 @@ function checkIfCanMoveLeft(x, y, word, adjustWidth) {
517519
}
518520

519521

520-
521522
function setWordToXW(word, xval, wval) {
522523

523524
word.rectSVG.x(xval);
@@ -650,7 +651,6 @@ function moveWordDownARow(w) {
650651
rows[nextRowIdx].words.unshift(w);
651652
w.row = rows[nextRowIdx];
652653
var nx = edgepadding;
653-
//var ny = w.row.ry + w.row.rh - w.wh;
654654
var ny = w.row.rect.bbox().y + w.row.rect.bbox().h - w.wh;
655655

656656
moveWordToNewPosition(w, nx, ny);
@@ -670,7 +670,6 @@ function moveWordUpARow(w) {
670670
rows[nextRowIdx].words.push(w);
671671
w.row = rows[nextRowIdx];
672672
var nx = svgWidth - edgepadding - w.rectSVG.width();
673-
//var ny = w.row.ry + w.row.rh - w.wh;
674673
var ny = w.row.rect.bbox().y + w.row.rect.bbox().h - w.wh;
675674

676675
moveWordToNewPosition(w, nx, ny);
@@ -683,10 +682,9 @@ function moveWordUpARow(w) {
683682
for (var i = 0; i < rows.length; i++) {
684683
calculateMaxSlotForRow(rows[i]);
685684
}
686-
687-
688685
}
689686

687+
690688
function setUpWordDraggable(word) {
691689

692690
addDragStartingAndEndingListeners(word.rectSVG);
@@ -703,77 +701,16 @@ function setUpWordDraggable(word) {
703701
});
704702
}
705703

706-
/*
707-
function checkMinMaxY(row, y, h) {
708-
709-
var rowArr = row.words;
710-
711-
var miny, maxy;
712-
var dir = directions.NONE;
713-
714-
if (row.idx == 0) {
715-
miny = 0; //edgepadding;
716-
} else {
717-
miny = rows[row.idx-1].rect.bbox().y; //+h?
718-
}
719-
720-
//console.log("x + w = " + (x + word.rect.w));
721-
if (row.idx == (rows.length - 1) ) {
722-
723-
//console.log("svgWidth = " + svgWidth);
724-
//maxx = draw.bbox().w - edgepadding;
725-
//maxx = svgWidth - edgepadding;
726-
} else {
727-
maxy = rows[row.idx+1].rect.bbox().y + rows[row.idx+1].rect.bbox().h; //i think
728-
}
729-
730-
if (y < miny) {
731-
dir = directions.BACKWARD;
732-
} else if (y + h >= maxy) {
733-
//x = maxx - w;
734-
dir = directions.FORWARD;
735-
}
736-
737-
//need to calculate size of other words on this row...
738-
var rowMinY = edgepadding;
739-
for (var i = 0; i < wordInRow; i++) {
740-
rowMinX += rowArr[i].rect.w; //wordInRow
741-
}
742-
743-
var rowMaxX = svgWidth - edgepadding;
744-
745-
for (var i = wordInRow; i < rowArr.length; i++) {
746-
rowMaxX -= rowArr[i].rect.w;
747-
}
748-
749-
if (x < rowMinX) {
750-
x = rowMinX;
751-
} else if (x > rowMaxX) {
752-
x = rowMaxX;
753-
}
754-
755-
return {x:x, dir:dir};
756-
}
757-
*/
758-
759-
760704
function dragRow(x, y, row) {
761705

762-
//console.log("in dragRow("+x+", "+y+", "+row+"), wordHeight = " + wordHeight );
763-
764-
var rowDragRect = row.dragRect;
765706
var prevY = row.rect.bbox().y;
766-
767707
var inc = y - prevY;
768708

769709
var nextRowTooSmall = false;
770710
var nextY = 0;
771711

772712
if (row.idx < rows.length - 1) {
773-
/*
774-
nextY = top of next row + height of next row ... so the bottom of the next row (prob can just use the lineBottom for that...), minus the height of the word's rectangle, then need to subtract the dragRectangle, + the margin between rows.
775-
*/
776-
713+
777714
nextY = (rows[row.idx + 1].lineBottom.bbox().y - wordHeight ) - (dragRectSide + dragRectMargin) - 5 ;
778715

779716
if (y > nextY) {
@@ -797,15 +734,7 @@ function dragRow(x, y, row) {
797734
}
798735

799736
for (var i = 0; i < row.words.length; i++) {
800-
var word = row.words[i];
801-
var wordY = row.lineBottom.bbox().y - word.rectSVG.height();
802-
word.rectSVG.y(wordY);
803-
word.rect = word.rectSVG.bbox();
804-
word.underneathRect.y(wordY);
805-
word.leftHandle.y(wordY);
806-
word.rightHandle.y(wordY);
807-
808-
word.text.y(word.rect.y + textpaddingY);
737+
setWordToY(row.words[i], row.lineBottom.bbox().y - row.words[i].rectSVG.height() );
809738
}
810739

811740
row.baseHeight = row.lineBottom.y() - (textpaddingY*2) - texts.wordText.maxHeight;
@@ -820,22 +749,27 @@ function dragRow(x, y, row) {
820749
nextrow.lineTop.y(row.rect.bbox().y + row.rect.bbox().h + 5);
821750
}
822751

823-
var returnVal = {x:rowDragRect.bbox().x, y:y};
752+
var returnVal = {x:row.dragRect.bbox().x, y:y};
824753

825754
return returnVal;
826755
}
827756

828-
function setUpRowDraggable(row) {
829-
830757

831-
var rowDragRect = row.dragRect;
758+
function setWordToY(word, wy) {
759+
word.rectSVG.y(wy);
760+
word.rect = word.rectSVG.bbox();
761+
word.underneathRect.y(wy);
762+
word.leftHandle.y(wy);
763+
word.rightHandle.y(wy);
764+
word.text.y(word.rect.y + textpaddingY);
765+
}
832766

833-
addDragStartingAndEndingListeners(rowDragRect);
767+
function setUpRowDraggable(row) {
834768

835-
rowDragRect.draggable(function(x, y) {
769+
addDragStartingAndEndingListeners(row.dragRect);
836770

771+
row.dragRect.draggable(function(x, y) {
837772
var returnVal = dragRow(x, y, row);
838-
839773
redrawLinks(); //actually - only redraw links that moving this word would affect + this row?
840774

841775
return returnVal;

0 commit comments

Comments
 (0)