Skip to content

Commit 7029e59

Browse files
committed
Scaffolding for adding new labels to Links
- Under the full Odin spec, all Links (both Events and Relations) have one main label and individual type labels for each argument. Both types of labels should be drawn for all Links. (Previously, Event Links only had their argument labels drawn, and Relation Links only had their main label drawn). - Parse: Odin parses now include both label types for all Links - Link: Both label types are initialised for all Links, but the ones not in use are hidden for now. - Config: Increased the Link slot interval in preparation for showing argument labels along the vertical lines
1 parent d863da2 commit 7029e59

File tree

7 files changed

+109
-243
lines changed

7 files changed

+109
-243
lines changed

demo/data/test-reach.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
["T4", "Cluster 1", [["39", "51"]]]
1616
],
1717
"attributes": [],
18-
"text": "This is a word cluster test. This is a word cluster test.",
18+
"text": "This is a word cluster test. This is a word cluster test. This is a word cluster test.",
1919
"relations": [
2020
["R1", "Relation Test", [["Arg1", "T1"], ["Arg2", "T2"]]]
2121
],
2222
"triggers": [
23-
["T3", "Tag", [["29", "33"]]]
23+
["T3", "Tag", [["29", "33"]]],
24+
["T15", "Tag", [["58", "62"]]]
2425
],
2526
"events": [
2627
["E1", "T3", [["Word Anchor", "T1"], ["Cluster Anchor", "T4"]]]
@@ -42,10 +43,17 @@
4243
["T11", "NN", [["39", "43"]]],
4344
["T12", "NN", [["44", "51"]]],
4445
["T13", "NN", [["52", "56"]]],
45-
["T14", ".", [["56", "57"]]]
46+
["T14", ".", [["56", "57"]]],
47+
["T15", "DT", [["58", "62"]]],
48+
["T16", "VBZ", [["63", "65"]]],
49+
["T17", "DT", [["66", "67"]]],
50+
["T18", "NN", [["68", "72"]]],
51+
["T19", "NN", [["73", "80"]]],
52+
["T20", "NN", [["81", "85"]]],
53+
["T21", ".", [["85", "86"]]]
4654
],
4755
"attributes": [],
48-
"text": "This is a word cluster test. This is a word cluster test.",
56+
"text": "This is a word cluster test. This is a word cluster test. This is a word cluster test.",
4957
"relations": [],
5058
"triggers": [],
5159
"events": []

demo/demo.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/tag/js/tag.js

Lines changed: 50 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -38775,9 +38775,13 @@ function () {
3877538775
this.handles = []; // SVG Path and last-drawn path string
3877638776

3877738777
this.path = null;
38778-
this.lastPathString = "";
38779-
this.svgTexts = [];
38780-
this.lastDrawnWidth = null;
38778+
this.lastPathString = ""; // (Horizontal-only) width of the last drawn line for this Link; used
38779+
// for calculating Handle positions for parent Links
38780+
38781+
this.lastDrawnWidth = null; // SVG Texts for main Link label / argument labels
38782+
38783+
this.argTexts = [];
38784+
this.linkText = null;
3878138785
}
3878238786
/**
3878338787
* Initialises this Link against the main API instance
@@ -38796,41 +38800,38 @@ function () {
3879638800
this.svg = main.svg.group().addClass("tag-element").addClass(this.top ? "link" : "link syntax-link"); // Links are hidden by default; the main function should call `.show()`
3879738801
// for any Links to be shown
3879838802

38799-
this.svg.hide(); // Init handles
38803+
this.svg.hide(); // Init handles and SVG texts.
38804+
// If there is a trigger, it will be the first handle
3880038805

3880138806
if (this.trigger) {
3880238807
this.handles.push(new Handle(this.trigger, this));
38803-
}
38804-
38805-
this.arguments.forEach(function (arg) {
38806-
_this2.handles.push(new Handle(arg.anchor, _this2)); // Also prepare svgTexts for each trigger-argument relation
38808+
} // Arguments
3880738809

3880838810

38809-
if (_this2.trigger) {
38810-
var text = _this2.svg.text(arg.type).leading(1).addClass("tag-element").addClass("link-text"); // Transform the text based on its font-size so that we can position it
38811-
// relative to its baseline
38812-
38813-
38814-
text.transform({
38815-
y: -parseInt($(text.node).css("font-size")) + 1
38816-
});
38817-
38818-
_this2.svgTexts.push(text);
38819-
}
38820-
}); // draw svgText for a non-trigger relation
38811+
this.arguments.forEach(function (arg) {
38812+
_this2.handles.push(new Handle(arg.anchor, _this2));
3882138813

38822-
if (this.reltype) {
38823-
var text = this.svg.text(this.reltype).leading(1).addClass("tag-element").addClass("link-text"); // Transform the text based on its font-size so that we can position it
38814+
var text = _this2.svg.text(arg.type).leading(1).addClass("tag-element").addClass("link-text"); // Transform the text based on its font-size so that we can position it
3882438815
// relative to its baseline
3882538816

38817+
3882638818
text.transform({
3882738819
y: -parseInt($(text.node).css("font-size")) + 1
3882838820
});
38829-
this.svgTexts.push(text);
38830-
} // apply click events to text
38821+
text.hide();
38822+
38823+
_this2.argTexts.push(text);
38824+
}); // Main Link label
3883138825

38826+
this.linkText = this.svg.text(this.reltype).leading(1).addClass("tag-element").addClass("link-text"); // Transform the text based on its font-size so that we can position it
38827+
// relative to its baseline
3883238828

38833-
this.svgTexts.forEach(function (text) {
38829+
this.linkText.transform({
38830+
y: -parseInt($(this.linkText.node).css("font-size")) + 1
38831+
});
38832+
this.linkText.hide(); // apply click events to argument labels
38833+
38834+
this.argTexts.forEach(function (text) {
3883438835
text.node.oncontextmenu = function (e) {
3883538836
_this2.selectedLabel = text;
3883638837
e.preventDefault();
@@ -39221,8 +39222,8 @@ function () {
3922139222
}, {
3922239223
key: "getLineY",
3922339224
value: function getLineY(row) {
39224-
return this.top ? row.ry + row.rh - row.wordHeight - 15 * this.slot // Bottom Links have negative slot numbers
39225-
: row.ry + row.rh + row.wordDescent - 15 * this.slot;
39225+
return this.top ? row.ry + row.rh - row.wordHeight - this.config.linkSlotInterval * this.slot // Bottom Links have negative slot numbers
39226+
: row.ry + row.rh + row.wordDescent - this.config.linkSlotInterval * this.slot;
3922639227
}
3922739228
/**
3922839229
* Given the full array of Words in the document, calculates this Link's
@@ -39541,7 +39542,8 @@ function () {
3954139542
// The trigger always takes up index 0, so the index for the label is
3954239543
// one less than the index for this handle in `this.handles`
3954339544

39544-
var label = this.svgTexts[this.handles.indexOf(_handle) - 1];
39545+
var label = this.argTexts[this.handles.indexOf(_handle) - 1];
39546+
label.show();
3954539547
var textLength = label.length();
3954639548
var textY = this.getLineY(_handle.row);
3954739549
var textLeft = pHandle.x + this.config.linkCurveWidth;
@@ -39656,7 +39658,9 @@ function () {
3965639658
// The trigger always takes up index 0, so the index for the label is
3965739659
// one less than the index for this handle in `this.handles`
3965839660

39659-
var _label = this.svgTexts[this.handles.indexOf(_handle2) - 1];
39661+
var _label = this.argTexts[this.handles.indexOf(_handle2) - 1];
39662+
39663+
_label.show();
3966039664

3966139665
var _textLength = _label.length();
3966239666

@@ -39799,7 +39803,8 @@ function () {
3979939803
var sameRow = leftHandle.row.idx === rightHandle.row.idx; // Width/position of the Link's label
3980039804
// (Always on the first row for multi-line Links)
3980139805

39802-
var textLength = this.svgTexts[0].length();
39806+
this.linkText.show();
39807+
var textLength = this.linkText.length();
3980339808
var textY = this.getLineY(leftHandle.row); // Centre on the segment of the Link line on the first row
3980439809

3980539810
var textCentre = sameRow ? (pStart.x + pEnd.x) / 2 : (pStart.x + leftHandle.row.rw) / 2;
@@ -39858,7 +39863,7 @@ function () {
3985839863

3985939864
d += this._arrowhead(pStart) + this._arrowhead(pEnd); // Move label
3986039865

39861-
this.svgTexts[0].move(textCentre, textY); // Perform draw
39866+
this.linkText.move(textCentre, textY); // Perform draw
3986239867

3986339868
if (this.lastPathString !== d) {
3986439869
this.path.plot(d);
@@ -42096,7 +42101,7 @@ var Config = function Config() {
4209642101
// Drawing options for Links in the visualisation
4209742102
// Vertical distance between each Link slot (for crossing/overlapping Links)
4209842103

42099-
this.linkSlotInterval = 15; // Vertical padding between Link arrowheads and their anchors
42104+
this.linkSlotInterval = 30; // Vertical padding between Link arrowheads and their anchors
4210042105

4210142106
this.linkHandlePadding = 2; // Corner curve width for Links
4210242107

@@ -43807,7 +43812,7 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
4380743812

4380843813
var _word = _interopRequireDefault(require("../components/word.js"));
4380943814

43810-
var _link2 = _interopRequireDefault(require("../components/link.js"));
43815+
var _link = _interopRequireDefault(require("../components/link.js"));
4381143816

4381243817
var _wordCluster = _interopRequireDefault(require("../components/word-cluster.js"));
4381343818

@@ -43996,14 +44001,14 @@ function () {
4399644001
edgeId = _step4$value[0],
4399744002
edge = _step4$value[1];
4399844003

43999-
this.data.links.push(new _link2.default( // eventId
44004+
this.data.links.push(new _link.default( // eventId
4400044005
"".concat(docId, "-").concat(sentenceId, "-").concat(graphType, "-").concat(edgeId), // Trigger
4400144006
thisSentence[edge.source], // Arguments
4400244007
[{
4400344008
anchor: thisSentence[edge.destination],
4400444009
type: edge.relation
4400544010
}], // Relation type
44006-
null, // Draw Link above Words?
44011+
edge.relation, // Draw Link above Words?
4400744012
false, // Category
4400844013
graphType));
4400944014
}
@@ -44092,22 +44097,26 @@ function () {
4409244097
this.parsedMentions[mention.id] = cluster;
4409344098
return cluster;
4409444099
}
44095-
} // EventMention
44100+
} // EventMention/RelationMention
4409644101
// Will become a Link
4409744102

4409844103

44099-
if (mention.type === "EventMention") {
44104+
if (mention.type === "EventMention" || mention.type === "RelationMention") {
4410044105
// If there is a trigger, it will be a nested Mention. Ensure it is
4410144106
// parsed.
4410244107
var trigger = null;
4410344108

4410444109
if (mention.trigger) {
4410544110
trigger = this._parseMention(mention.trigger);
44106-
}
44111+
} // Read the relation label
44112+
4410744113

44108-
var linkArgs = []; // `mentions.arguments` is an Object keyed by argument type.
44114+
var relType = mention.labels[0]; // Generate the arguments array
44115+
// `mentions.arguments` is an Object keyed by argument type.
4410944116
// The value of each key is an array of nested Mentions as arguments
4411044117

44118+
var linkArgs = [];
44119+
4411144120
var _arr = Object.entries(mention["arguments"]);
4411244121

4411344122
for (var _i2 = 0; _i2 < _arr.length; _i2++) {
@@ -44148,102 +44157,15 @@ function () {
4414844157
} // Done; prepare the new Link
4414944158

4415044159

44151-
var link = new _link2.default( // eventId
44160+
var link = new _link.default( // eventId
4415244161
mention.id, // Trigger
4415344162
trigger, // Arguments
4415444163
linkArgs, // Relation type
44155-
null, // Draw Link above Words?
44164+
relType, // Draw Link above Words?
4415644165
true);
4415744166
this.data.links.push(link);
4415844167
this.parsedMentions[mention.id] = link;
4415944168
return link;
44160-
} // RelationMention
44161-
// Will become a Link
44162-
44163-
44164-
if (mention.type === "RelationMention") {
44165-
// `mentions.arguments` is an Object keyed by argument type.
44166-
// The value of each key is an array of nested Mentions as arguments
44167-
// Sort the keys properly so that we can generate an accurate label;
44168-
// the arguments with lower starting tokens should be on the left.
44169-
var argTypes = Object.keys(mention["arguments"]);
44170-
argTypes.sort(function (a, b) {
44171-
// Go through the array of mentions and pick out the lowest starting
44172-
// token
44173-
var mentionsA = mention["arguments"][a];
44174-
var mentionsB = mention["arguments"][b];
44175-
var firstTokenA = mentionsA.reduce(function (prev, next) {
44176-
if (next.tokenInterval.start < prev) {
44177-
return next.tokenInterval.start;
44178-
} else {
44179-
return prev;
44180-
}
44181-
}, mentionsA[0].tokenInterval.start);
44182-
var firstTokenB = mentionsB.reduce(function (prev, next) {
44183-
if (next.tokenInterval.start < prev) {
44184-
return next.tokenInterval.start;
44185-
} else {
44186-
return prev;
44187-
}
44188-
}, mentionsB[0].tokenInterval.start);
44189-
44190-
if (firstTokenA <= firstTokenB) {
44191-
return -1;
44192-
} else {
44193-
return 1;
44194-
}
44195-
}); // Generate the relation label
44196-
44197-
var reltype = argTypes.join("-"); // Generate the arguments array
44198-
44199-
var _linkArgs = [];
44200-
44201-
for (var _i3 = 0; _i3 < argTypes.length; _i3++) {
44202-
var type = argTypes[_i3];
44203-
var args = mention["arguments"][type];
44204-
var _iteratorNormalCompletion6 = true;
44205-
var _didIteratorError6 = false;
44206-
var _iteratorError6 = undefined;
44207-
44208-
try {
44209-
for (var _iterator6 = args[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
44210-
var _arg = _step6.value;
44211-
44212-
// Ensure that the argument mention has been parsed before
44213-
var _anchor = this._parseMention(_arg);
44214-
44215-
_linkArgs.push({
44216-
anchor: _anchor,
44217-
type: type
44218-
});
44219-
}
44220-
} catch (err) {
44221-
_didIteratorError6 = true;
44222-
_iteratorError6 = err;
44223-
} finally {
44224-
try {
44225-
if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
44226-
_iterator6.return();
44227-
}
44228-
} finally {
44229-
if (_didIteratorError6) {
44230-
throw _iteratorError6;
44231-
}
44232-
}
44233-
}
44234-
} // Done; prepare the new Link
44235-
44236-
44237-
var _link = new _link2.default( // eventId
44238-
mention.id, // Trigger
44239-
null, // Arguments
44240-
_linkArgs, // Relation type
44241-
reltype, // Draw Link above Words?
44242-
true);
44243-
44244-
this.data.links.push(_link);
44245-
this.parsedMentions[mention.id] = _link;
44246-
return _link;
4424744169
}
4424844170
}
4424944171
}]);

dist/tag/js/tag.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)