Skip to content

Commit 0a371ee

Browse files
committed
modify syntax tree visibility toggle and row resize
1 parent 50160bc commit 0a371ee

File tree

5 files changed

+54
-17
lines changed

5 files changed

+54
-17
lines changed

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
</div>
4040
<div class="page" id="graph"></div>
4141
<div class="page" id="options">
42-
<p><input type="checkbox" checked> Syntax tree visible</p>
43-
<p><input type="checkbox"> Hide links when moving words</p>
42+
<p><input type="checkbox" data-option="syntax"> Show syntax tree</p>
43+
<p><input type="checkbox" data-option="links"> Show links when moving words</p>
4444
</div>
4545
</div>
4646
</div>

js/components/link.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Link {
3737
init(svg) {
3838
this.mainSVG = svg;
3939
this.svg = svg.group().addClass(this.top ? 'link' : 'link syntax-link');
40+
if (!this.visible) { this.svg.hide(); }
4041

4142
// init handles
4243
// get location of trigger

js/components/word.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class Word {
9797
.on('dragstart', function(e) {
9898
mousemove = false;
9999
x = e.detail.p.x;
100+
svg.fire('word-move-start');
100101
})
101102
.on('dragmove', (e) => {
102103
e.preventDefault();
@@ -106,9 +107,7 @@ class Word {
106107
if (dx !== 0) { mousemove = true; }
107108
})
108109
.on('dragend', (e) => {
109-
if (mousemove === false) {
110-
svg.fire('word-clicked', { object: this });
111-
}
110+
svg.fire('word-move-end', { object: this, clicked: mousemove === false });
112111
});
113112

114113
// attach right click listener

js/main.js

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const Main = (function() {
1313
// other html elements
1414
let tooltip = {};
1515
let tree = {};
16+
let options = {
17+
showSyntax: false,
18+
showLinksOnMove: false
19+
};
1620

1721
//--------------------------------
1822
// public functions
@@ -42,12 +46,24 @@ const Main = (function() {
4246
rm.resizeRow(e.detail.object.idx, e.detail.y);
4347
});
4448

49+
svg.on('word-move-start', function() {
50+
if (!options.showLinksOnMove && options.showSyntax) {
51+
setSyntaxVisibility(false);
52+
}
53+
});
54+
4555
svg.on('word-move', function(e) {
4656
tooltip.clear()
4757
lm.stopEditing();
4858
rm.moveWordOnRow(e.detail.object, e.detail.x);
4959
});
5060

61+
svg.on('word-move-end', function(e) {
62+
if (!options.showLinksOnMove && options.showSyntax) {
63+
setSyntaxVisibility(true);
64+
}
65+
});
66+
5167
svg.on('row-recalculate-slots', function(e) {
5268
links.forEach(link => {
5369
link.resetSlotRecalculation();
@@ -78,16 +94,21 @@ const Main = (function() {
7894
}
7995
}
8096

81-
// let showSyntax = true;
82-
// document.getElementById('syntax-toggle').onclick = function() {
83-
// showSyntax = !showSyntax;
84-
// this.innerHTML = showSyntax ? 'Hide syntax' : 'Show syntax';
85-
// links.forEach(l => {
86-
// if (!l.top) {
87-
// showSyntax ? l.show() : l.hide();
88-
// }
89-
// });
90-
// }
97+
document.querySelectorAll('#options input').forEach(input => {
98+
input.onclick = function() {
99+
let option = this.getAttribute('data-option');
100+
switch(option) {
101+
case 'syntax':
102+
options.showSyntax = this.checked;
103+
setSyntaxVisibility();
104+
break;
105+
case 'links':
106+
options.showLinksOnMove = this.checked;
107+
break;
108+
default: ;
109+
}
110+
};
111+
});
91112

92113
function setActiveTab(pageId, modalId="modal") {
93114
let m = document.getElementById(modalId);
@@ -163,6 +184,7 @@ const Main = (function() {
163184
clear();
164185
ymlToJson.convert('taxonomy.yml.txt', function(taxonomy) {
165186
[words, links, clusters] = buildWordsAndLinks();
187+
setSyntaxVisibility();
166188
draw();
167189

168190
tm.buildTree(taxonomy);
@@ -206,6 +228,21 @@ const Main = (function() {
206228
//--------------------------------
207229
// private functions
208230
//--------------------------------
231+
232+
/** options to set visibility of syntax tree
233+
*/
234+
function setSyntaxVisibility(bool) {
235+
bool = (bool === undefined) ? options.showSyntax : bool;
236+
links.forEach(l => {
237+
if (!l.top) {
238+
bool ? l.show() : l.hide();
239+
}
240+
});
241+
if (rm.rows.length > 0) {
242+
rm.resizeAll();
243+
}
244+
}
245+
209246
function buildWordsAndLinks() {
210247
// construct word objects and tags from tokens, entities, and triggers
211248
const words = parser.tokens.map((token, i) => {

js/managers/rowmanager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const RowManager = (function() {
1010
resizeAll() {
1111
_rows.forEach(row => {
1212
this.recalculateRowSlots(row);
13-
this.resizeRow(row.idx);
1413
});
14+
this.resizeRow(0);
1515
}
1616

1717
resizeRow(i, dy = 0) {
@@ -211,7 +211,7 @@ const RowManager = (function() {
211211
}
212212

213213
getSlotRange(acc, anchor) {
214-
// if (anchor instanceof Link && !anchor.visible) { return [acc, acc]; }
214+
if (anchor instanceof Link && !anchor.visible) { return [acc[0], acc[1]]; }
215215
if (anchor.links.length === 0) {
216216
return [Math.min(acc[0], anchor.slot), Math.max(acc[1], anchor.slot)];
217217
}

0 commit comments

Comments
 (0)