|
63 | 63 |
|
64 | 64 | <div id="header"> |
65 | 65 | <input type="file"> |
66 | | - <button class="active" id="POS">POS</button> |
67 | | - <button id="BIO">BIO</button> |
| 66 | + <button id="POS">POS</button> |
| 67 | + <button class="active" id="REACH">REACH</button> |
68 | 68 | </div> |
69 | 69 |
|
70 | 70 | <div id="drawing"> |
|
181 | 181 | // init objects/listeners... |
182 | 182 | window.onload = function() { |
183 | 183 |
|
| 184 | + function generateLinksPOS(){}; |
| 185 | + function generateLinksREACH(){}; |
| 186 | + |
184 | 187 | // init buttons |
185 | 188 | const State = { |
186 | 189 | annotationStyle: document.querySelector('button.active').id, |
187 | 190 | setAnnotationStyle: function(type) { |
188 | 191 | this.annotationStyle = type; |
189 | 192 | if (type === "POS") { |
190 | 193 | wordObjs.forEach(w => w.tag = w.data.syntaxData.tag); |
| 194 | + generateLinksPOS(); |
191 | 195 | } |
192 | 196 | else { |
193 | 197 | wordObjs.forEach(w => w.tag = w.data.bioData.tag); |
| 198 | + generateLinksREACH(); |
194 | 199 | } |
195 | 200 | redrawWords(wordObjs); |
| 201 | + redrawLinks(true); |
196 | 202 | } |
197 | 203 | }; |
198 | 204 | const buttons = document.querySelectorAll('#header button'); |
|
385 | 391 | wordObjs.push(w); |
386 | 392 | }) |
387 | 393 |
|
388 | | - linkObjs = []; |
389 | | - if (State.annotationStyle == 'POS') { |
390 | | - // syntaxDataArray.forEach |
391 | | - // } |
392 | | - // else { |
| 394 | + function clearLinkObjs() { |
| 395 | + linkObjs.forEach(link => link.removeSVGs()); |
| 396 | + linkObjs = []; |
| 397 | + |
| 398 | + wordObjs.forEach(word => { |
| 399 | + word.slotsL = []; |
| 400 | + word.slotsR = []; |
| 401 | + word.parentsL = []; |
| 402 | + word.parentsR = []; |
| 403 | + }) |
| 404 | + } |
| 405 | + |
| 406 | + generateLinksPOS = function() { |
| 407 | + clearLinkObjs(); |
| 408 | + syntaxDataArray.forEach(link => { |
| 409 | + let ltr = link.source.locationInSentence < link.destination.locationInSentence; |
| 410 | + let style; |
| 411 | + switch (link.label) { |
| 412 | + case "nsubj": |
| 413 | + style = ltr ? styles.gradientLine2 : styles.gradientLine2r; |
| 414 | + break; |
| 415 | + case "dobj": |
| 416 | + style = ltr ? styles.gradientLine1 : styles.gradientLine1r; |
| 417 | + break; |
| 418 | + case "det": |
| 419 | + style = styles.simpleLine; |
| 420 | + break; |
| 421 | + default: |
| 422 | + style = styles.noneLine; |
| 423 | + break; |
| 424 | + } |
| 425 | + |
| 426 | + |
| 427 | + let linkObject = new Link( |
| 428 | + link.source.object, |
| 429 | + link.destination.object, |
| 430 | + ltr ? 1 : -1, |
| 431 | + style, |
| 432 | + link.label, |
| 433 | + texts.linkText |
| 434 | + ); |
| 435 | + |
| 436 | + // create circular reference to link and data |
| 437 | + linkObject.data = link; |
| 438 | + link.object = linkObject; |
| 439 | + linkObjs.push( linkObject ); |
| 440 | + createLink(linkObject); |
| 441 | + }) |
| 442 | + } |
| 443 | + |
| 444 | + generateLinksREACH = function() { |
| 445 | + clearLinkObjs(); |
393 | 446 | mentionDataArray.forEach(function(link) { |
394 | 447 | if (link.words) { |
395 | 448 |
|
|
458 | 511 | }); |
459 | 512 | } |
460 | 513 |
|
461 | | - // draw |
462 | | - // linkObjs.sort(function(a, b) { |
463 | | - // var d1 = Math.abs(a.s.idx - a.e.idx); |
464 | | - // var d2 = Math.abs(b.s.idx - b.e.idx); |
465 | | - |
466 | | - // return d1 - d2; |
467 | | - // }); |
468 | | - // linkObjs.forEach(createLink); |
469 | 514 |
|
| 515 | + // draw |
| 516 | + generateLinksREACH(); |
470 | 517 | drawWords(wordObjs); |
471 | 518 | drawLinks(linkObjs); |
472 | 519 |
|
|
0 commit comments