Skip to content

Commit a5776d4

Browse files
committed
implement link removal
1 parent d25dc51 commit a5776d4

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

js/components/link.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,20 @@ class Link {
88
this.top = top;
99
this.visible = true;
1010

11-
this.slot = 0;
11+
this.resetSlotRecalculation();
1212

1313
if (this.top) {
1414
// top links
1515
if (this.trigger) {
1616
this.trigger.links.push(this);
17-
this.slot = this.trigger.slot;
1817
}
1918
this.arguments.forEach(arg => {
2019
arg.anchor.links.push(this);
21-
if (arg.anchor.slot > this.slot) {
22-
this.slot = arg.anchor.slot;
23-
}
2420
});
25-
26-
this.slot += 1;
2721
}
2822
else {
2923
// bottom links
3024
this.trigger.links.push(this);
31-
this.slot = -1;
3225
this.arguments.forEach(arg => arg.anchor.links.push(this));
3326
}
3427

@@ -391,6 +384,25 @@ class Link {
391384

392385
resetSlotRecalculation() {
393386
this.isRecalculated = false;
387+
this.slot = 0;
388+
389+
if (this.top) {
390+
// top links
391+
if (this.trigger) {
392+
this.slot = this.trigger.slot;
393+
}
394+
this.arguments.forEach(arg => {
395+
if (arg.anchor.slot > this.slot) {
396+
this.slot = arg.anchor.slot;
397+
}
398+
});
399+
400+
this.slot += 1;
401+
}
402+
else {
403+
// bottom links
404+
this.slot = -1;
405+
}
394406
}
395407

396408
recalculateSlots(words) {

js/main.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ const Main = (function() {
4545
rm.moveWordOnRow(e.detail.object, e.detail.x);
4646
});
4747

48+
svg.on('row-recalculate-slots', function(e) {
49+
links.forEach(link => {
50+
link.resetSlotRecalculation();
51+
});
52+
links.forEach(link => {
53+
link.recalculateSlots(words);
54+
link.draw();
55+
});
56+
});
57+
4858
// window event listeners
4959
// resize function
5060
window.onresize = function() {

js/managers/tooltip.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const Tooltip = (function() {
3939
}
4040
else if (activeObject instanceof Link) {
4141
if (e.detail.type === 'text') {
42-
html += '<p id="menu--edit-link-label">Edit label</p>';
42+
html += '<p id="menu--edit-link-label">Edit label</p><p id="menu--remove-link">Remove link</p>';
4343
}
4444
else {
4545
html += '<p id="menu--remove-link">Remove link</p>';
@@ -94,6 +94,7 @@ const Tooltip = (function() {
9494
break;
9595
case 'menu--remove-link':
9696
activeObject.remove();
97+
_svg.fire('row-recalculate-slots', { object: activeObject, r1: activeObject.endpoints[0].row, r2: activeObject.endpoints[1].row });
9798
break;
9899
default: ;
99100
}

0 commit comments

Comments
 (0)