Skip to content

Commit aa6e622

Browse files
committed
Link: Relations drawn correctly
- Demo: Added option to hide/show main link labels - Link: Optimised and corrected Relation link drawing algorithm - Link: Labels are now drawn with a rounded rectangular background that tries not to be too obtrusive
1 parent a0241bf commit aa6e622

File tree

14 files changed

+226
-113
lines changed

14 files changed

+226
-113
lines changed

demo/demo.min.css

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

demo/demo.min.css.map

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

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.

demo/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ <h5 class="modal-title" id="options-title">Options</h5>
195195
</div>
196196

197197
<div class="custom-control custom-checkbox mt-3">
198+
<input type="checkbox" class="custom-control-input" id="tag-option-main-label">
199+
<label class="custom-control-label" for="tag-option-main-label">
200+
Show main label on links
201+
</label>
202+
</div>
203+
<div class="custom-control custom-checkbox">
198204
<input type="checkbox" class="custom-control-input" id="tag-option-arg-labels">
199205
<label class="custom-control-label" for="tag-option-arg-labels">
200206
Show argument labels on links

demo/src/demo.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ $(async () => {
198198
);
199199
});
200200

201+
const $optionMainLabel = $("#tag-option-main-label");
202+
$optionMainLabel
203+
.prop("checked", uiTag.getOption("showMainLabel"))
204+
.on("change", () => {
205+
uiTag.setMainLabelVisibility($optionMainLabel[0].checked);
206+
});
207+
201208
const $optionArgLabels = $("#tag-option-arg-labels");
202209
$optionArgLabels
203210
.prop("checked", uiTag.getOption("showArgLabels"))

dist/tag/css/tag.css

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

dist/tag/css/tag.css.map

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/css/tag.min.css

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/css/tag.min.css.map

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: 104 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -38987,6 +38987,25 @@ function () {
3898738987

3898838988
this.visible = false;
3898938989
}
38990+
/**
38991+
* Shows the main label for this Link
38992+
*/
38993+
38994+
}, {
38995+
key: "showMainLabel",
38996+
value: function showMainLabel() {
38997+
this.linkLabel.show();
38998+
this.draw();
38999+
}
39000+
/**
39001+
* Hides the main label for this Link
39002+
*/
39003+
39004+
}, {
39005+
key: "hideMainLabel",
39006+
value: function hideMainLabel() {
39007+
this.linkLabel.hide();
39008+
}
3899039009
/**
3899139010
* Shows the argument labels for this Link
3899239011
*/
@@ -39529,7 +39548,6 @@ function () {
3952939548
// one less than the index for this handle in `this.handles`
3953039549

3953139550
var label = this.argLabels[this.handles.indexOf(_handle) - 1];
39532-
label.show();
3953339551
var textLength = label.length();
3953439552
var textY = this.getLineY(_handle.row);
3953539553
var textLeft = pHandle.x + this.config.linkCurveWidth;
@@ -39646,8 +39664,6 @@ function () {
3964639664

3964739665
var _label = this.argLabels[this.handles.indexOf(_handle2) - 1];
3964839666

39649-
_label.show();
39650-
3965139667
var _textLength = _label.length();
3965239668

3965339669
var _textY = this.getLineY(_handle2.row);
@@ -39789,71 +39805,73 @@ function () {
3978939805
var sameRow = leftHandle.row.idx === rightHandle.row.idx; // Width/position of the Link's label
3979039806
// (Always on the first row for multi-line Links)
3979139807

39792-
this.linkLabel.show();
3979339808
var textLength = this.linkLabel.length();
39794-
var textY = this.getLineY(leftHandle.row); // Centre on the segment of the Link line on the first row
39809+
var textY = this.getLineY(leftHandle.row); // Centre on the segment of the Link line on the first row, making sure
39810+
// it doesn't overshoot the right row boundary
3979539811

3979639812
var textCentre = sameRow ? (pStart.x + pEnd.x) / 2 : (pStart.x + leftHandle.row.rw) / 2;
39797-
var textLeft = textCentre - textLength / 2; // Make sure it doesn't overshoot the right row boundary
3979839813

39799-
if (textLeft + textLength > leftHandle.row.rw) {
39800-
textLeft = leftHandle.row.rw - textLength;
39801-
textCentre = textLeft + textLength / 2;
39814+
if (textCentre + textLength / 2 > leftHandle.row.rw) {
39815+
textCentre = leftHandle.row.rw - textLength / 2;
3980239816
} // Start preparing path string
3980339817

3980439818

39805-
d += "M" + [pStart.x, pStart.y]; // Left handle
39819+
d += "M" + [pStart.x, pStart.y]; // Left handle/label
39820+
// Draw up to the level of the Link line, then position the left arg label
3980639821

3980739822
var firstY = this.getLineY(leftHandle.row);
39823+
var curveLeftX = pStart.x + this.config.linkCurveWidth;
39824+
curveLeftX = Math.min(curveLeftX, leftHandle.row.rw);
39825+
var curveLeftY = firstY + this.config.linkCurveWidth;
39826+
d += "L" + [pStart.x, curveLeftY] + "Q" + [pStart.x, firstY, curveLeftX, firstY];
39827+
var leftLabel = this.argLabels[this.handles.indexOf(leftHandle)];
39828+
var leftLabelCentre = pStart.x;
3980839829

39809-
if (textLeft < pStart.x) {
39810-
// Just draw a vertical line up to the label
39811-
d += "L" + [pStart.x, firstY];
39812-
} else {
39813-
// Draw curve up to the main Link line, then, go up to the label
39814-
var curveLeftX = pStart.x + this.config.linkCurveWidth;
39815-
curveLeftX = Math.min(curveLeftX, textLeft);
39816-
d += "C" + [pStart.x, firstY, pStart.x, firstY, curveLeftX, firstY] + "L" + [textLeft, firstY];
39817-
} // Left handle label
39818-
39830+
if (leftLabelCentre + leftLabel.length() / 2 > leftHandle.row.rw) {
39831+
leftLabelCentre = leftHandle.row.rw - leftLabel.length() / 2;
39832+
}
3981939833

39820-
var leftLabel = this.argLabels[this.handles.indexOf(leftHandle)];
39821-
leftLabel.move(pStart.x, (pStart.y + firstY) / 2); // Right handle/label
39834+
if (leftLabelCentre - leftLabel.length() / 2 < 0) {
39835+
leftLabelCentre = leftLabel.length() / 2;
39836+
}
3982239837

39823-
var rightLabel = this.argLabels[this.handles.indexOf(rightHandle)];
39838+
leftLabel.move(leftLabelCentre, (pStart.y + firstY) / 2); // Right handle/label
39839+
// Handling depends on whether or not the right handle is on the same
39840+
// row as the left handle
3982439841

39825-
if (sameRow) {
39826-
if (textLeft + textLength > pEnd.x) {
39827-
// Just draw a vertical line down to the handle
39828-
d += "M" + [pEnd.x, firstY] + "L" + [pEnd.x, pEnd.y];
39829-
} else {
39830-
// Draw curve down from the main Link line
39831-
var curveRightX = pEnd.x - this.config.linkCurveWidth;
39832-
curveRightX = Math.max(curveRightX, textLeft + textLength);
39833-
d += "M" + [textLeft + textLength, firstY] + "L" + [curveRightX, firstY] + "C" + [pEnd.x, firstY, pEnd.x, firstY, pEnd.x, pEnd.y];
39834-
}
39842+
var finalY = firstY;
3983539843

39836-
rightLabel.move(pEnd.x, (pEnd.y + firstY) / 2);
39837-
} else {
39844+
if (!sameRow) {
3983839845
// Draw in Link line across the end of the first row, and all
3983939846
// intervening rows
39840-
d += "M" + [textLeft + textLength, firstY] + "L" + [leftHandle.row.rw, firstY];
39847+
d += "L" + [leftHandle.row.rw, firstY];
3984139848

3984239849
for (var i = leftHandle.row.idx + 1; i < rightHandle.row.idx; i++) {
3984339850
var thisRow = this.main.rowManager.rows[i];
3984439851
var lineY = this.getLineY(thisRow);
3984539852
d += "M" + [0, lineY] + "L" + [thisRow.rw, lineY];
39846-
} // Draw in the last row
39853+
}
39854+
39855+
finalY = this.getLineY(rightHandle.row);
39856+
d += "M" + [0, finalY];
39857+
} // Draw down from the main Link line on last row
3984739858

3984839859

39849-
var _curveRightX3 = pEnd.x - this.config.linkCurveWidth;
39860+
var curveRightX = pEnd.x - this.config.linkCurveWidth;
39861+
var curveRightY = finalY + this.config.linkCurveWidth;
39862+
d += "L" + [curveRightX, finalY] + "Q" + [pEnd.x, finalY, pEnd.x, curveRightY] + "L" + [pEnd.x, pEnd.y];
39863+
var rightLabel = this.argLabels[this.handles.indexOf(rightHandle)];
39864+
var rightLabelCentre = pEnd.x;
39865+
39866+
if (rightLabelCentre + rightLabel.length() / 2 > rightHandle.row.rw) {
39867+
rightLabelCentre = rightHandle.row.rw - rightLabel.length() / 2;
39868+
}
3985039869

39851-
_curveRightX3 = Math.max(_curveRightX3, 0);
39852-
var finalY = this.getLineY(rightHandle.row);
39853-
d += "M" + [0, finalY] + "L" + [_curveRightX3, finalY] + "C" + [pEnd.x, finalY, pEnd.x, finalY, pEnd.x, pEnd.y];
39854-
rightLabel.move(pEnd.x, (pEnd.y + finalY) / 2);
39855-
} // Arrowheads
39870+
if (rightLabelCentre - rightLabel.length() / 2 < 0) {
39871+
rightLabelCentre = rightLabel.length() / 2;
39872+
}
3985639873

39874+
rightLabel.move(rightLabelCentre, (pEnd.y + finalY) / 2); // Arrowheads
3985739875

3985839876
d += this._arrowhead(pStart) + this._arrowhead(pEnd); // Main label
3985939877

@@ -40165,16 +40183,26 @@ function () {
4016540183

4016640184
this.fontSize = parseInt($(this.svgText.node).css("font-size"));
4016740185
this.svgText.transform({
40168-
y: -this.fontSize + 1
40186+
y: -this.fontSize
4016940187
});
40170-
this.svgTextBbox = this.svgText.bbox(); // Background rectangle
40188+
this.svgTextBbox = this.svgText.bbox(); // Background (rectangle)
4017140189

40172-
this.svgBackground = this.svg.rect(this.svgTextBbox.width, this.svgTextBbox.height).addClass("tag-element").addClass("link-text-bg").addClass(addClass).back(); // Transform the rectangle to sit nicely behind the label
40190+
this.svgBackground = this.svg.rect(this.svgTextBbox.width, this.svgTextBbox.height - 4).addClass("tag-element").addClass("link-text-bg").addClass(addClass).radius(2).back(); // Transform the rectangle to sit nicely behind the label
4017340191

4017440192
this.svgBackground.transform({
4017540193
x: -this.svgTextBbox.width / 2,
40176-
y: -this.fontSize + 1
40177-
}); // Click events
40194+
y: -this.fontSize + 2
40195+
}); // // Background (text)
40196+
// this.svgBackground = this.svg.text(text)
40197+
// .addClass("tag-element")
40198+
// .addClass("link-text-bg")
40199+
// .addClass(addClass)
40200+
// .back();
40201+
// // Transform the background to sit nicely behind the label
40202+
// this.svgBackground.transform({
40203+
// y: -this.fontSize
40204+
// });
40205+
// Click events
4017840206

4017940207
this.svgText.node.oncontextmenu = function (e) {
4018040208
_this5.selectedLabel = text;
@@ -42308,7 +42336,8 @@ function () {
4230842336
// Continue to display top/bottom Links when moving Words?
4230942337
showTopLinksOnMove: true,
4231042338
showBottomLinksOnMove: false,
42311-
// Show argument labels on Links?
42339+
// Show main/argument labels on Links?
42340+
showMainLabel: true,
4231242341
showArgLabels: true
4231342342
}; // Initialisation
4231442343

@@ -42474,6 +42503,12 @@ function () {
4247442503
link.show();
4247542504
}
4247642505

42506+
if (_this.options.showMainLabel) {
42507+
link.showMainLabel();
42508+
} else {
42509+
link.hideMainLabel();
42510+
}
42511+
4247742512
if (_this.options.showArgLabels) {
4247842513
link.showArgLabels();
4247942514
} else {
@@ -42717,6 +42752,26 @@ function () {
4271742752
}
4271842753
});
4271942754
}
42755+
/**
42756+
* Shows/hides the main label on Links
42757+
* @param {Boolean} visible - Show if true, hide if false
42758+
*/
42759+
42760+
}, {
42761+
key: "setMainLabelVisibility",
42762+
value: function setMainLabelVisibility(visible) {
42763+
this.setOption("showMainLabel", visible);
42764+
42765+
if (visible) {
42766+
this.links.forEach(function (link) {
42767+
return link.showMainLabel();
42768+
});
42769+
} else {
42770+
this.links.forEach(function (link) {
42771+
return link.hideMainLabel();
42772+
});
42773+
}
42774+
}
4272042775
/**
4272142776
* Shows/hides the argument labels on Links
4272242777
* @param {Boolean} visible - Show if true, hide if false

0 commit comments

Comments
 (0)