Skip to content

Commit 90068e0

Browse files
committed
show/hide links... wip
1 parent 944b20d commit 90068e0

File tree

4 files changed

+164
-5
lines changed

4 files changed

+164
-5
lines changed

css/style2.css

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,63 @@ svg text {
1919
#header {
2020
position:fixed;
2121
z-index:100;
22-
background:black;
22+
background:#555;
2323
width:100%;
2424
height:40px;
2525
top:0;
26+
font: 14px/1.5em helvetica, arial, sans-serif;
27+
}
28+
29+
#options {
30+
float:right;
31+
display:inline-block;
32+
background:inherit;
33+
color:white;
34+
}
35+
#dataset,
36+
#options button {
37+
color:white;
38+
height:40px;
39+
padding: 0 20px;
40+
background: none;
41+
outline:none;
42+
cursor:pointer;
43+
font:inherit;
44+
border:none;
45+
}
46+
#options button {
47+
border: 1px solid #999;
48+
border-width:0 0 0 1px;
49+
border-radius:0;
50+
}
51+
#options.open button {
52+
background: #333;
53+
border-color: #555;
54+
border-width:0 0 1px 0;
55+
}
56+
#options ul {
57+
display:none;
58+
margin:0;
59+
list-style-type: none;
60+
padding: 4px 0;
61+
background: #333;
62+
}
63+
#options > ul {
64+
position:absolute;
65+
min-width:125px;
66+
padding: 10px;
67+
padding-left: 0;
68+
right: 0;
69+
}
70+
#options.open ul {
71+
display:block;
72+
}
73+
#options li {
74+
padding: 3px 10px;
75+
padding-right: 0;
76+
}
77+
#options li input[type="checkbox"] {
78+
margin-right: 5px;
2679
}
2780

2881
#tooltip {

index.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@
1717
<option>passage1</option>
1818
<option>passage2</option>
1919
</select>
20-
<button id="syntax-toggle">Toggle syntax</button>
20+
<div id="options">
21+
<button id="options-toggle">Visible edges ▾</button>
22+
<ul>
23+
<li class="reach">
24+
<input id="reach--all" type="checkbox" checked><label for="reach--all">REACH</label>
25+
</li>
26+
<li class="pos">
27+
<input id="pos--all" type="checkbox" checked><label for="pos--all">Syntax</label>
28+
</li>
29+
</ul>
30+
</div>
2131
</div>
2232

2333
<div id="main">

js2/components/link.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,8 @@ class Link {
373373
get absoluteY() {
374374
return this.rootWord.row.rh + this.rootWord.row.ry - 45 - 15 * this.slot;
375375
}
376+
377+
get val() {
378+
return this.reltype || this.trigger.val;
379+
}
376380
}

js2/main.js

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ const Main = (function() {
5959
changeDataset(this.selectedIndex);
6060
}
6161
}
62-
document.getElementById('syntax-toggle').onclick = function() {
63-
links.forEach(l => l.toggle());
64-
rm.resizeAll();
62+
document.getElementById('options-toggle').onclick = function() {
63+
document.getElementById('options').classList.toggle('open');
6564
}
6665
}
6766

@@ -73,6 +72,7 @@ const Main = (function() {
7372
parser.readJson(`./data/data${index}.json`, function() {
7473
clear();
7574
[words, links, clusters] = buildWordsAndLinks();
75+
populateOptions();
7676
draw();
7777
});
7878
};
@@ -193,6 +193,98 @@ const Main = (function() {
193193
return [ words, links, clusters ];
194194
}
195195

196+
function populateOptions() {
197+
document.querySelector('.reach').onclick = toggleEdgeVisibility;
198+
document.querySelector('.pos').onclick = toggleEdgeVisibility;
199+
200+
let reachTypes = {};
201+
let posTypes = {};
202+
203+
function toggleEdgeVisibility(e) {
204+
if (e.target.nodeName === 'INPUT') {
205+
let id = e.target.id.split('--');
206+
let checked = e.target.checked;
207+
208+
function linkMatchesId(l) {
209+
if (l.top && id[0] === 'reach') {
210+
return l.reltype === id[1] || (l.trigger instanceof Word && l.trigger.tag.val === id[1]);
211+
}
212+
else if (!l.top && id[0] === 'pos') {
213+
return l.arguments.some(arg => arg.type === id[1]);
214+
}
215+
}
216+
217+
if (checked) {
218+
if (id[1] === 'all') {
219+
document.querySelectorAll(`.${id[0]} > ul input`).forEach(i => {
220+
i.disabled = false;
221+
toggleEdgeVisibility({target: i});
222+
});
223+
}
224+
else {
225+
links.forEach(l => linkMatchesId(l) && l.show());
226+
}
227+
}
228+
else {
229+
if (id[1] === 'all') {
230+
document.querySelectorAll(`.${id[0]} > ul input`).forEach(i => {
231+
links.forEach(l => {
232+
if (l.top == (id[0] === 'reach')) {
233+
l.hide();
234+
}
235+
});
236+
i.disabled = true;
237+
});
238+
}
239+
else {
240+
links.forEach(l => linkMatchesId(l) && l.hide());
241+
}
242+
}
243+
}
244+
}
245+
246+
// find link types
247+
links.forEach(link => {
248+
if (link.top) {
249+
let type = link.trigger instanceof Word ? link.trigger.tag : link.reltype;
250+
if (reachTypes[type]) {
251+
reachTypes[type].push(link);
252+
}
253+
else {
254+
reachTypes[type] = [link];
255+
}
256+
}
257+
else {
258+
link.arguments.forEach(arg => {
259+
if (posTypes[arg.type]) {
260+
posTypes[arg.type].push(link);
261+
}
262+
else {
263+
posTypes[arg.type] = [link];
264+
}
265+
});
266+
}
267+
});
268+
269+
// add to options
270+
function createLi(types, name) {
271+
if (Object.keys(types).length > 0) {
272+
let li = Object.keys(types).map(type =>
273+
`<li><input id="${name}--${type}" type="checkbox" checked><label for="${name}--${type}">${type}</label></li>`
274+
);
275+
let ul = document.querySelector(`.${name} > ul`) || document.createElement('ul');
276+
ul.innerHTML = li.join('');
277+
document.querySelector(`.${name}`).appendChild(ul);
278+
}
279+
else {
280+
let ul = document.querySelector(`.${name} > ul`);
281+
if (ul) { ul.parentNode.removeChild(ul); }
282+
}
283+
}
284+
createLi(reachTypes, 'reach');
285+
createLi(posTypes, 'pos');
286+
}
287+
196288
// export public functions
197289
return {
198290
init,

0 commit comments

Comments
 (0)