Merge pull request #4981 from node-red/4978-zoom-annotation-fix

Apply zoom scale when calculating annotation positions
pull/4949/head^2
Nick O'Leary 2024-12-05 16:23:36 +00:00 committed by GitHub
commit 69753a9940
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 5 deletions

View File

@ -11,7 +11,7 @@ RED.view.annotations = (function() {
}
let badgeRDX = 0;
let badgeLDX = 0;
const scale = RED.view.scale()
for (let i=0,l=evt.el.__annotations__.length;i<l;i++) {
const annotation = evt.el.__annotations__[i];
if (annotations.hasOwnProperty(annotation.id)) {
@ -42,15 +42,17 @@ RED.view.annotations = (function() {
}
if (isBadge) {
if (showAnnotation) {
const rect = annotation.element.getBoundingClientRect();
// getBoundingClientRect is in real-world scale so needs to be adjusted according to
// the current scale factor
const rectWidth = annotation.element.getBoundingClientRect().width / scale;
let annotationX
if (!opts.align || opts.align === 'right') {
annotationX = evt.node.w - 3 - badgeRDX - rect.width
badgeRDX += rect.width + 4;
annotationX = evt.node.w - 3 - badgeRDX - rectWidth
badgeRDX += rectWidth + 4;
} else if (opts.align === 'left') {
annotationX = 3 + badgeLDX
badgeLDX += rect.width + 4;
badgeLDX += rectWidth + 4;
}
annotation.element.setAttribute("transform", "translate("+annotationX+", -8)");
}