Skip to content

Commit 789d6ac

Browse files
committed
constrain arrows to tag width, fix some resizing issues
1 parent 949b152 commit 789d6ac

File tree

4 files changed

+81
-5
lines changed

4 files changed

+81
-5
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<option>passage1</option>
1818
<option>passage2</option>
1919
</select>
20+
<button id="syntax-toggle">Hide syntax</button>
2021
<button id="taxonomy-toggle">Taxonomy ▾</button>
2122
</header>
2223

js/components/link.js

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,35 @@ class Link {
107107
let dx = e.detail.p.x - x;
108108
x = e.detail.p.x;
109109
draggedHandle.offset += dx;
110+
let anchor = draggedHandle.anchor;
111+
if (anchor instanceof Link) {
112+
if (anchor.trigger) {
113+
if (anchor.trigger.idx > anchor.endpoints[0].idx) {
114+
console.log('hey');
115+
}
116+
}
117+
118+
// let l = draggedHandle.anchor;
119+
// let boundaries = l.handles
120+
// // .filter(h => !l.trigger || h.anchor.row === l.trigger.row)
121+
// .map(h => h.x);
122+
// if (l.trigger) { console.log(l.trigger.row); }
123+
// console.log(boundaries);
124+
// // console.log(draggedHandle.anchor.cx, draggedHandle.anchor.endpoints);
125+
}
126+
else {
127+
let halfWidth = anchor.boxWidth / 2;
128+
if (this.top && anchor.tag instanceof WordTag) {
129+
halfWidth = anchor.tag.ww / 2;
130+
}
131+
else if (!this.top && anchor.syntaxTag instanceof WordTag) {
132+
halfWidth = anchor.syntaxTag.ww / 2;
133+
}
134+
draggedHandle.offset = draggedHandle.offset < 0
135+
? Math.max(-halfWidth + 3, draggedHandle.offset)
136+
: Math.min(halfWidth - 3, draggedHandle.offset);
137+
}
110138
this.draw(draggedHandle.anchor);
111-
// console.log(dx, x, draggedHandle );
112139
}
113140
})
114141
.on('dragend', () => { draggedHandle = null });
@@ -230,11 +257,18 @@ class Link {
230257

231258
if (handlePrecedesTrigger) {
232259
// draw trigger to the right of the arrow segment
233-
d += 'L' + [this.handles[0].x - dx, y]
234-
+ 'c' + [dx, 0, dx, 0, dx, this.handles[0].y - y];
235260
if (i + 1 < il) {
261+
d += 'L' + [this.handles[0].x - dx, y]
262+
+ 'c' + [dx, 0, dx, 0, dx, this.handles[0].y - y]
263+
+ 'm' + [dx, 0]
264+
+ 'l' + [-2 * dx, 0]
265+
+ 'm' + [dx, 0]
266+
+ 'C' + [this.handles[0].x, y, this.handles[0].x, y, this.handles[0].x + dx, y];
236267
rowCrossed = this.handles[i + 2].anchor.row.idx != this.handles[0].anchor.row.idx;
237-
d += 'C' + [this.handles[0].x, y, this.handles[0].x, y, this.handles[0].x + dx, y];
268+
}
269+
else {
270+
d += 'L' + [this.handles[0].x - dx, y]
271+
+ 'c' + [dx, 0, dx, 0, dx, this.handles[0].y - y];
238272
}
239273
}
240274
}
@@ -409,6 +443,14 @@ class Link {
409443
}
410444

411445
get cx() {
446+
if (this.line) {
447+
if (this.trigger) {
448+
return this.trigger.cx + this.handles[0].offset;
449+
}
450+
else {
451+
// FIXME: does not occur currently
452+
}
453+
}
412454
return this.rootWord.cx;
413455
}
414456

js/main.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,27 @@ const Main = (function() {
4949
// resize function
5050
window.onresize = function() {
5151
body = document.body.getBoundingClientRect();
52+
links.forEach(l => l.hide());
5253
svg.width(body.width);
5354
rm.width(body.width);
55+
links.forEach(l => l.show());
5456
}
5557
document.getElementById('dataset').onchange = function(e) {
5658
if (this.selectedIndex > 0) {
5759
changeDataset(this.selectedIndex);
5860
}
5961
}
62+
63+
// let showSyntax = true;
64+
// document.getElementById('syntax-toggle').onclick = function() {
65+
// showSyntax = !showSyntax;
66+
// this.innerHTML = showSyntax ? 'Hide syntax' : 'Show syntax';
67+
// links.forEach(l => {
68+
// if (!l.top) {
69+
// showSyntax ? l.show() : l.hide();
70+
// }
71+
// });
72+
// }
6073
document.getElementById('taxonomy-toggle').onclick = function() {
6174
document.getElementById('taxonomy').classList.add('open');
6275
}

js/managers/rowmanager.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ const RowManager = (function() {
1616

1717
resizeRow(i, dy = 0) {
1818
let row = _rows[i];
19+
if (i > 0) {
20+
let adjust = _rows[i - 1].ry2 + ROW_PADDING - row.ry;
21+
row.move(row.ry + adjust);
22+
row.height(row.rh - adjust);
23+
}
1924
dy = Math.max(-row.rh + row.minHeight, dy);
2025
row.height(row.rh + dy);
2126
row.words.forEach(word => word.redrawLinks());
@@ -32,8 +37,23 @@ const RowManager = (function() {
3237
}
3338

3439
width(rw) {
35-
_rows.forEach(function(row) {
40+
_rows.forEach(row => {
3641
row.width(rw);
42+
43+
let i = row.words.findIndex(w => w.x > rw);
44+
if (i > 0) {
45+
this.moveWordOnRow(row.words[i - 1], 0);
46+
}
47+
else {
48+
row.words.forEach(word => {
49+
word.links.forEach(function(l) {
50+
if (l.endpoints[1].row !== l.endpoints[0].row) {
51+
l.draw(this);
52+
}
53+
});
54+
word.redrawClusters();
55+
});
56+
}
3757
});
3858
}
3959

0 commit comments

Comments
 (0)