Skip to content

Commit 581e358

Browse files
committed
fix: smart ruler label markers position detection to always prevent overlaps
1 parent 796f29e commit 581e358

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3578,37 +3578,56 @@ function RemoteFunctions(config = {}) {
35783578

35793579
const LABEL_MARGIN = 6;
35803580

3581+
const THRESHOLD_Y = Math.min(150, window.innerHeight * 0.15);
3582+
const THRESHOLD_X = Math.min(150, window.innerWidth * 0.15);
3583+
35813584
const leftLabelWidth = this.labelElements.left.offsetWidth;
35823585
const rightLabelWidth = this.labelElements.right.offsetWidth;
35833586
const topLabelHeight = this.labelElements.top.offsetHeight;
35843587
const bottomLabelHeight = this.labelElements.bottom.offsetHeight;
35853588

3589+
let labelsVerticalPosition = scrollTop + 10;
3590+
3591+
if (rect.top < THRESHOLD_Y && rect.height < window.innerHeight - 2 * THRESHOLD_Y) {
3592+
labelsVerticalPosition = scrollTop + window.innerHeight - 30;
3593+
}
3594+
35863595
let leftLabelLeft = edges.left - leftLabelWidth - LABEL_MARGIN;
35873596
if (rect.left - leftLabelWidth - LABEL_MARGIN < LABEL_MARGIN) {
35883597
leftLabelLeft = edges.left + LABEL_MARGIN;
35893598
}
35903599
this.labelElements.left.style.left = leftLabelLeft + "px";
3591-
this.labelElements.left.style.top = scrollTop + 10 + "px";
3600+
this.labelElements.left.style.top = labelsVerticalPosition + "px";
35923601

35933602
let rightLabelLeft = edges.right + LABEL_MARGIN;
35943603
if (rect.right + rightLabelWidth + LABEL_MARGIN > window.innerWidth - LABEL_MARGIN) {
35953604
rightLabelLeft = edges.right - rightLabelWidth - LABEL_MARGIN;
35963605
}
35973606
this.labelElements.right.style.left = rightLabelLeft + "px";
3598-
this.labelElements.right.style.top = scrollTop + 10 + "px";
3607+
this.labelElements.right.style.top = labelsVerticalPosition + "px";
3608+
3609+
let labelsHorizontalPosition = scrollLeft + 10;
3610+
3611+
if (rect.left < THRESHOLD_X && rect.width < window.innerWidth - 2 * THRESHOLD_X) {
3612+
const maxLabelWidth = Math.max(
3613+
this.labelElements.top.offsetWidth,
3614+
this.labelElements.bottom.offsetWidth
3615+
);
3616+
labelsHorizontalPosition = scrollLeft + window.innerWidth - maxLabelWidth - 20;
3617+
}
35993618

36003619
let topLabelTop = edges.top - topLabelHeight - LABEL_MARGIN;
36013620
if (rect.top - topLabelHeight - LABEL_MARGIN < LABEL_MARGIN) {
36023621
topLabelTop = edges.top + LABEL_MARGIN;
36033622
}
3604-
this.labelElements.top.style.left = scrollLeft + 10 + "px";
3623+
this.labelElements.top.style.left = labelsHorizontalPosition + "px";
36053624
this.labelElements.top.style.top = topLabelTop + "px";
36063625

36073626
let bottomLabelTop = edges.bottom + LABEL_MARGIN;
36083627
if (rect.bottom + bottomLabelHeight + LABEL_MARGIN > window.innerHeight - LABEL_MARGIN) {
36093628
bottomLabelTop = edges.bottom - bottomLabelHeight - LABEL_MARGIN;
36103629
}
3611-
this.labelElements.bottom.style.left = scrollLeft + 10 + "px";
3630+
this.labelElements.bottom.style.left = labelsHorizontalPosition + "px";
36123631
this.labelElements.bottom.style.top = bottomLabelTop + "px";
36133632
},
36143633

0 commit comments

Comments
 (0)