Skip to content

Commit 67bd759

Browse files
committed
Links/Clusters: Fixed WordCluster Links
- Links that have WordClusters as arguments now display properly. - Updated Reach format test file (`test-reach.json`)
1 parent 125f694 commit 67bd759

File tree

6 files changed

+66
-18
lines changed

6 files changed

+66
-18
lines changed

demo/data/test-reach.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@
99
"for the tokenisation of the text string."
1010
],
1111
"entities": [
12-
["T1", "Tag 1", [["0", "4"]]],
13-
["T2", "Cluster 1", [["10", "22"]]]
12+
["T1", "Tag", [["0", "4"]]],
13+
["T2", "Cluster 1", [["10", "22"]]],
14+
["T3", "Tag", [["29", "33"]]],
15+
["T4", "Cluster 1", [["39", "51"]]]
1416
],
1517
"attributes": [],
1618
"text": "This is a word cluster test. This is a word cluster test.",
17-
"relations": [],
18-
"triggers": [],
19-
"events": []
19+
"relations": [
20+
["R1", "Relation Test", [["Arg1", "T1"], ["Arg2", "T2"]]]
21+
],
22+
"triggers": [
23+
["T3", "Tag", [["29", "33"]]]
24+
],
25+
"events": [
26+
["E1", "T3", [["Word Anchor", "T1"], ["Cluster Anchor", "T4"]]]
27+
]
2028
},
2129
"syntaxData": {
2230
"comments": [],

demo/demo.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/components/link.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,13 +776,24 @@ class Link {
776776
// Let this Word know we're watching it
777777
word.passingLinks.push(this);
778778

779+
// Word Links
779780
for (const link of word.links) {
780781
// Only consider Links on the same side of the Row as this one
781782
if (link !== this &&
782783
link.top === this.top && intervening.indexOf(link) < 0) {
783784
intervening.push(link);
784785
}
785786
}
787+
788+
// WordCluster Links
789+
for (const cluster of word.clusters) {
790+
for (const link of cluster.links) {
791+
if (link !== this &&
792+
link.top === this.top && intervening.indexOf(link) < 0) {
793+
intervening.push(link);
794+
}
795+
}
796+
}
786797
}
787798
intervening = Util.sortForSlotting(intervening);
788799

src/js/components/word-cluster.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,15 @@ class WordCluster {
299299
return this.endpoints[0].row;
300300
}
301301

302+
/**
303+
* Returns the absolute y-position of the top of the WordCluster's label
304+
* (for positioning Links that point at it)
305+
* @return {Number}
306+
*/
302307
get absoluteY() {
303-
return this.endpoints[0].absoluteY;
308+
// The text label lives with the left arm of the curly brace
309+
const thisHeight = this.svgs[0].bbox().height;
310+
return this.endpoints[0].absoluteY - thisHeight;
304311
}
305312

306313
get idx() {
@@ -323,8 +330,30 @@ class WordCluster {
323330
return this.svgText.bbox().width;
324331
}
325332

326-
get tagOffset() {
327-
return -28;
333+
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
334+
// Debug functions
335+
/**
336+
* Draws the outline of this component's bounding box
337+
*/
338+
drawBbox() {
339+
const bbox = this.svgs[0].bbox();
340+
this.svgs[0].polyline([
341+
[bbox.x, bbox.y], [bbox.x2, bbox.y], [bbox.x2, bbox.y2], [bbox.x, bbox.y2],
342+
[bbox.x, bbox.y]])
343+
.fill("none")
344+
.stroke({width: 1});
345+
}
346+
347+
/**
348+
* Draws the outline of the text element's bounding box
349+
*/
350+
drawTextBbox() {
351+
const bbox = this.svgText.bbox();
352+
this.svgs[0].polyline([
353+
[bbox.x, bbox.y], [bbox.x2, bbox.y], [bbox.x2, bbox.y2], [bbox.x, bbox.y2],
354+
[bbox.x, bbox.y]])
355+
.fill("none")
356+
.stroke({width: 1});
328357
}
329358
}
330359

src/js/components/word.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ class Word {
298298
*/
299299
get absoluteY() {
300300
return this.row
301-
? this.row.ry + this.row.rh - this.boxHeight
301+
? this.row.baseline - this.boxHeight
302302
: this.boxHeight;
303303
}
304304

src/js/main.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ class Main {
132132
*/
133133
draw() {
134134
let t0 = performance.now();
135-
console.log("----------");
136-
console.log("Starting draw");
135+
// console.log("----------");
136+
// console.log("Starting draw");
137137

138138
// Save a reference to the currently loaded tokens and links
139139
const data = this.parser.getParsedData();
@@ -160,7 +160,7 @@ class Main {
160160
this.rowManager.addWordToRow(word, this.rowManager.lastRow);
161161
});
162162

163-
console.log(`Words done (${performance.now() - t0}ms)`);
163+
// console.log(`Words done (${performance.now() - t0}ms)`);
164164
t0 = performance.now();
165165

166166
// We have to initialise all the Links before we draw any of them, to
@@ -172,7 +172,7 @@ class Main {
172172
word.links.forEach(link => link.draw());
173173
});
174174

175-
console.log(`Links done (${performance.now() - t0}ms)`);
175+
// console.log(`Links done (${performance.now() - t0}ms)`);
176176
t0 = performance.now();
177177

178178
// Change token colours based on the current taxonomy, if loaded
@@ -182,7 +182,7 @@ class Main {
182182
this.options.showSyntax ? this.showSyntax() : this.hideSyntax();
183183

184184
this.rowManager.resizeAll();
185-
console.log(`Resize done (${performance.now() - t0}ms)`);
185+
// console.log(`Resize done (${performance.now() - t0}ms)`);
186186
}
187187

188188
/**

0 commit comments

Comments
 (0)