Skip to content

Fix labels around border#616

Merged
will-moore merged 11 commits into
ome:masterfrom
Rdornier:fix-labels-on-border
Sep 23, 2025
Merged

Fix labels around border#616
will-moore merged 11 commits into
ome:masterfrom
Rdornier:fix-labels-on-border

Conversation

@Rdornier
Copy link
Copy Markdown
Contributor

@Rdornier Rdornier commented Feb 3, 2025

Resolves #614, resolves #615

y = panel['y']
width = panel['width']
height = panel['height']
border = panel['border']
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to use border = panel.get('border') which won't cause an error if border is missing

@will-moore
Copy link
Copy Markdown
Member

will-moore commented Feb 17, 2025

The app JS fix looks good.

The PDF labels are shifted OK for single labels in some positions, but where we have multiple labels (e.g top right panel) or labels on the inside corners then it's not looking right.
Also left-vertical labels (bottom-left panel) is too far left.

Screenshot shows app (top-left), PDF with this PR (top-right) and PDF without this PR (bottom). All borders are 15 px:

Screenshot 2025-02-17 at 15 31 23

@Rdornier
Copy link
Copy Markdown
Contributor Author

Hello Will,

Thanks for you careful review. I've made a fix to correct that.

There is only one remaining thing. When you re-open the figure, with vertical labels on panel with borders, the vertical labels are very far away from the panel. If you move the panel, then the position of the labels are correctly updated.

I found out that this behavior is coming from those two lines

            // need to force update of vertical labels layout
            $('.left_vlabels', self.$el).css('width', 3 * self.$el.height() + 'px');
            $('.right_vlabels', self.$el).css('width', 3 * self.$el.height() + 'px');

If I remove them, this behavior disappear. But I don't know if I'm allowed to remove them, as they should be needed for something, right ?

Rémy.

@will-moore
Copy link
Copy Markdown
Member

OK, so this took me quite a bit of digging...

You do need those force update lines... I saw the commit that added them mentioned "fix labels on non-square panesl" or something like that, and if you have a rectangular panel you'll see that they are really needed!

I also noticed that if you simply toggle the border (hide then show) then it fixes the issue, which turns out that simply calling render_labels() again is all that's needed.

Then I tried adding an extra call to render_labels() into the setTimeout() block (in the diff below), and that ALSO fixed the problem!
It took a while to work out that self.$el.height() (in the "problematic" lines that you tried removing) returns 2 different values: When render_labels() is first called on the initial render(), and again after the timeout. The difference in the heights is equivalent to 2 x border width.

It turns out that the first time that render() and render_labels() is called is BEFORE the panel has been added to the DOM. At that point it's just a jQuery object. After the timeout it is then attached to the DOM, and is then subject to different page layout css etc. So, calling render_labels() again gives a different self.$el.height().

If I update the code to avoid calling render() until AFTER the panel is added to the DOM, then it all behaves much better.
I also found that render_labels() is being called lots of times, so I've tried to clean that up too.

With that change, it also turns out that we don't need render_shapes() to be called after a timeout either! It needed that before because Raphael code was unhappy if the elements weren't on the page DOM.

Give this a try!

diff --git a/src/js/views/figure_view.js b/src/js/views/figure_view.js
index 361c3535..4eeff4df 100644
--- a/src/js/views/figure_view.js
+++ b/src/js/views/figure_view.js
@@ -796,7 +796,9 @@
         addOne: function(panel) {
             var page_color = this.model.get('page_color');
             var view = new PanelView({model:panel, page_color:page_color});
-            this.$figure.append(view.render().el);
+            this.$figure.append(view.el);
+            // render works better AFTER attaching element to the DOM
+            view.render();
         },
 
         renderLoadingSpinner: function() {
diff --git a/src/js/views/panel_view.js b/src/js/views/panel_view.js
index 4efa11a6..a5ce5b6a 100644
--- a/src/js/views/panel_view.js
+++ b/src/js/views/panel_view.js
@@ -48,7 +48,6 @@
             if (opts.page_color) {
                 this.page_color = opts.page_color;
             }
-            this.render();
         },
 
         events: {
@@ -373,15 +372,8 @@
 
             // update src, layout etc.
             this.render_image();
-            this.render_labels();
-            this.render_scalebar();     // also calls render_layout()
-
-            // At this point, element is not ready for Raphael svg
-            // If we wait a short time, works fine
-            var self = this;
-            setTimeout(function(){
-                self.render_shapes();
-            }, 10);
+            this.render_scalebar();     // also calls render_layout() -> render_labels()
+            this.render_shapes();
 
             return this;

@Rdornier
Copy link
Copy Markdown
Contributor Author

Hi @will-moore

Indeed, it's a deep review you did here, thanks for your time !
I've tested it and the bug indeed disappear. I don't see any other bug that could be induced by those changes, at least on what I've tested. So, I think it's good.

Thanks again for finding the solution,
Rémy.

@snoopycrimecop
Copy link
Copy Markdown
Member

Conflicting PR. Removed from build OMERO-plugins-push#345. See the console output for more details.
Possible conflicts:

--conflicts

Comment thread src/js/views/panel_view.js Outdated
self.render_shapes();
}, 10);
this.render_scalebar(); // also calls render_layout() -> render_labels()
this.render_shapes();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snoopycrimecop
Copy link
Copy Markdown
Member

Conflicting PR. Removed from build OMERO-plugins-push#346. See the console output for more details.
Possible conflicts:

--conflicts

@snoopycrimecop
Copy link
Copy Markdown
Member

Conflicting PR. Removed from build OMERO-plugins-push#347. See the console output for more details.
Possible conflicts:

--conflicts

Copy link
Copy Markdown
Contributor

@Tom-TBT Tom-TBT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this PR fixes what it says it fixes. I also tested together with the colorbar PR #605 and there's no interference. Looks good on that front.

But I would like to also fix the "crop page around panel" to account for the border. But this would bring more conflicts as I'm also modifying those parts extensively in the colorbar PR.

I suggest to proceed in this order:

  • merge colorbar PR
  • solve current conflicts
  • add following changes to handle the "crop page"
diff --git a/src/js/models/panel_model.js b/src/js/models/panel_model.js
index fbef52a5..722e6465 100644
--- a/src/js/models/panel_model.js
+++ b/src/js/models/panel_model.js
@@ -1104,6 +1104,10 @@
             shift = top_labels.reduce(function(prev, l){
                 return prev + (LINE_HEIGHT * l.size);
             }, shift);
+            var border = this.get("border");
+            if (border && border["showBorder"]) {
+                shift = shift + border["strokeWidth"];
+            }

             var shift_cbar = 0;
             var cb = this.get("colorbar");
@@ -1138,6 +1142,10 @@
                 const width = this.measureTextSize(l.text, l.size + "px");
                 shift = Math.max(shift, width);
             }
+            var border = this.get("border");
+            if (border && border["showBorder"]) {
+                shift = shift + border["strokeWidth"];
+            }

             var start = "";
             var end = "";
@@ -1185,6 +1193,10 @@
                 const width = this.measureTextSize(l.text, l.size + "px");
                 shift = Math.max(shift, width);
             }
+            var border = this.get("border");
+            if (border && border["showBorder"]) {
+                shift = shift + border["strokeWidth"];
+            }

             var start = "";
             var end = "";
@@ -1226,6 +1238,10 @@
             shift = bottom_labels.reduce(function(prev, l){
                 return prev + (LINE_HEIGHT * l.size);
             }, shift);
+            var border = this.get("border");
+            if (border && border["showBorder"]) {
+                shift = shift + border["strokeWidth"];
+            }

             var shift_cbar = 0;
             var cb = this.get("colorbar");

@snoopycrimecop
Copy link
Copy Markdown
Member

Conflicting PR. Removed from build OMERO-plugins-push#419. See the console output for more details.
Possible conflicts:

--conflicts

@snoopycrimecop
Copy link
Copy Markdown
Member

Conflicting PR. Removed from build OMERO-plugins-push#420. See the console output for more details.
Possible conflicts:

--conflicts

@snoopycrimecop
Copy link
Copy Markdown
Member

Conflicting PR. Removed from build OMERO-plugins-push#421. See the console output for more details.
Possible conflicts:

--conflicts

@snoopycrimecop
Copy link
Copy Markdown
Member

Conflicting PR. Removed from build OMERO-plugins-push#422. See the console output for more details.
Possible conflicts:

--conflicts

@snoopycrimecop
Copy link
Copy Markdown
Member

Conflicting PR. Removed from build OMERO-plugins-push#423. See the console output for more details.
Possible conflicts:

--conflicts

@snoopycrimecop
Copy link
Copy Markdown
Member

Conflicting PR. Removed from build OMERO-plugins-push#424. See the console output for more details.
Possible conflicts:

--conflicts

@snoopycrimecop
Copy link
Copy Markdown
Member

Conflicting PR. Removed from build OMERO-plugins-push#451. See the console output for more details.
Possible conflicts:

--conflicts

@snoopycrimecop
Copy link
Copy Markdown
Member

snoopycrimecop commented Aug 1, 2025

Conflicting PR. Removed from build OMERO-plugins-push#491. See the console output for more details.
Possible conflicts:

--conflicts Conflict resolved in build OMERO-plugins-push#531. See the console output for more details.

@Rdornier
Copy link
Copy Markdown
Contributor Author

Hi @Tom-TBT , "crop page around panel" should be fixed thanks to your above code snippet

Copy link
Copy Markdown
Member

@will-moore will-moore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all working fine now. Cropping is good etc.

@will-moore will-moore merged commit b9486b4 into ome:master Sep 23, 2025
@will-moore will-moore added this to the 7.3.0 milestone Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Label spacing not updated when hiding border No border spacing added on labels when exporting as PDF

4 participants