Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to adjust Scalebar width #504

Merged
merged 17 commits into from
May 3, 2023
Merged

Conversation

JulianHn
Copy link
Contributor

Hey all,

This is a first draft to Fix #503

I have added an additional input field to the scalebar_form panel and reordered the inputs to make space.
Adjusting the scalebar in the panel_view is done.

image

image

Known Issue: Site load show Empty string passed to getElementbyId(). This will also be returned multiple times when the scalebar is shown / hidden. Unclear where this is coming from

RFC: Is that approach in principle okay? If yes, I will try to track done that getElementbyId() thing and take a look on what needs to be modified in the export routines.

// Julian

Added additional input for height.
Added necessary properties to the views.
Reordered the panel_form to make space for input.

Known Issue: Site load show Empty string passed to getElementbyId().
This will also be returned multiple times when the scalebar is shown / hidden.
Unclear where this is coming from
Add correct margin specification for top positioned scalebar.
@imagesc-bot
Copy link

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/scalebar-width-adjustement/78827/4

Achieved by querying the new scalebar property and passing the width to draw_scalebar_line().
For correct positioning, offset parameters for the scalebar and the label are introduced.

Seems to work for PDF in all scalebar positions and a variety of width/length combinations.

Known Issue: TIFF export not working yet.
@JulianHn
Copy link
Contributor Author

PDF export seems to be working as well with modifactions to Figure_to_Pdf.py:
Figure_2023-3-23_13-52-0.pdf
Figure_2023-3-23_13-51-44.pdf

I haven't fully understand why the TIFF export breaks with the same parameters ... more investigation to do

adjusting the draw_scalebar_line routine to loop from (-height/2:height/2)
which together with the offset introduced in @adc018c0e8b61b761cde8f039c7d6be4bdd5f965
makes sure that the scalebar will always fit
@JulianHn
Copy link
Contributor Author

And with 1cd3f56 exporting tiffs now also works on a first glance:

image

image

@JulianHn
Copy link
Contributor Author

After some further research:
The Empty string passed to getElementById() warning is also present in current stable omero-figure and occurs exclusively on Firefox. This seems to be a known issue with Firefox and Bootstrap Forms and Dropdown menus and the general consensus seems to be that it is not an actual problem.

E.g:
https://community.wix.com/velo/forum/coding-with-velo/text-input-for-forms-generates-empty-string-passed-to-getelementbyid-error-on-load
https://bugzilla.mozilla.org/show_bug.cgi?id=1333427

The second link and some other StackOverflow threads often involve data-targets pointing to # as the culprit. I am wondering if the parts of the dropdown menus for units and font size are responsible?

Copy link
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.

@JulianHn, thanks for the PR - you've done well to figure all that out!

Just a couple of small points...

The buttons and form elements are slightly bigger than before. You need to add the btn-sm and input-sm classes to them.

Before/after comparison:

Screenshot 2023-03-24 at 10 10 56

Minor point: I wonder if you could get the form to fit on 2 rows instead of 3? If it's too painful don't worry. But if you could get the show/hide button to float right (so as to align with the other forms) that would be great (pull-right class).

It seems that adding an extra text input to the form has disabled the "submit on Enter" behaviour for the length input (and the height input). So that when you enter a length or hight and hit Enter, nothing happens. Previously I was getting the "submit" event for free! Just looked this up at https://www.tjvantoll.com/2013/01/01/enter-should-submit-forms-stop-messing-with-that/

So we need to add that behaviour explicitly. This will do it...

--- a/src/js/views/scalebar_form_view.js
+++ b/src/js/views/scalebar_form_view.js
@@ -27,6 +27,14 @@ var ScalebarFormView = Backbone.View.extend({
         "click .pixel_size_display": "edit_pixel_size",
         "keypress .pixel_size_input"  : "enter_pixel_size",
         "blur .pixel_size_input"  : "save_pixel_size",
+        "keyup input[type='text']"  : "handle_keyup",
+    },
+
+    handle_keyup: function (event) {
+        // If Enter key - submit form...
+        if (event.which == 13) {
+            this.update_scalebar();
+        }
     },

The PDF and TIFF export look great. However I noticed an existing issue that could do with improving (while we're here): In the PDF (right) the label is probably a bit too close to the scalebar: it looks OK on the TIFF. Could you give it a bit more space?

Screenshot 2023-03-24 at 10 35 05

Cheers!

@will-moore
Copy link
Member

Oh, and maybe remove the ? from Label?. I think a checkbox is implicitly boolean.

Add Unit to the font size.
Add correct button/input classes to make sizing consistent.
Float submit button to the right
to reenable Enter based submission of the form.

Remove form from css selector used in update_scalebar to reflect changes of template.
Without this change updating the scalebar does not work when the submit button is in "Show" state.
5 Seems to work as an offset in general for both.
@JulianHn JulianHn marked this pull request as ready for review March 24, 2023 12:45
@JulianHn
Copy link
Contributor Author

Hey @will-moore
thanks for the review.
Fitting the everything in two rows was no problem, my original thought was separating "label-logic" from "bar-logic".

image

All other requested changes are implemented and Enter submission is now working again by applying your patch and fixing a css selector.

The label offset in PDF is now consistent with the one in TIFF, I just used the 5 offset that was already implemented there for both now.

PDF:
image
image

TIFF:
image
image

I have undrafted the PR, as I think it should now have all features and I have done a bit more UI testing without encountering more issues.

// Julian

will-moore and others added 2 commits March 24, 2023 14:42
Merging some changes to improve the scalebar-form layout some more
@will-moore
Copy link
Member

I'm trying to get this included in our daily build, but something's preventing that e.g. snoopycrimecop@ac6d076
lists PR 504 JulianHn 'Add option to adjust Scalebar width' (status: action_required)
But I'm not sure what that action is? cc @sbesson
since I've added "include" label to this PR and the build is green...

@sbesson
Copy link
Member

sbesson commented Mar 28, 2023

The PR inclusion will be conditional to its status. I suspect the issue came from the default requirement to approve GitHub workflows for first-time contributors. Looking at the actions logs, the initial run four days ago was marked as required action and it looks like you approved it and the GitHub workflow ran successfully 2 days ago.
Screenshot 2023-03-28 at 11 02 49

Regarding the commit, note that https://merge-ci.openmicroscopy.org/jenkins/job/OMERO-plugins-push/ did not run at all on March 27th so this PR did not have a change to be included yesterday. The nightly CI run seems to have successfully included it into the merge build as expected - see snoopycrimecop@0948e32

@will-moore
Copy link
Member

@sbesson Ah - thanks, sorry I'd missed that the CI didn't run yesterday.

Keyup event handling was mistakenly commented out at some point. Add back in.
After form template rewrite, CSS selector in scalebar_from_view.update_scalebar()
was not working anymore, because it selects the wrapping div instead of the form.
This caused spurious buggy behaviour (scalebar only changeable when hidden).
Change selector to select by class, which is unique to the scalebar_form.
@will-moore
Copy link
Member

@sbesson the last snoopy merge commit (last night) snoopycrimecop@1cd7091 again failed to merge this PR because action_required again, and I see above that I have to Approve and run again, because 1 commit got added?!

I would have expected to only need to approve once?

@will-moore
Copy link
Member

Hmmm - now "Approve and run" gives me a 500 error at #504 so will try again later...

@will-moore
Copy link
Member

@sbesson I'm still getting this PR excluded - just now: snoopycrimecop@c6c6834 this time with (status: startup_failure).
I don't see anything in the logs at https://merge-ci.openmicroscopy.org/jenkins/job/OMERO-plugins-push/1475/console

@sbesson
Copy link
Member

sbesson commented Mar 30, 2023

Screenshot 2023-03-30 at 09 22 51

Looks like the latest workflow run hit some upstream service unavailability issue

@will-moore
Copy link
Member

@sbesson I can't actually work out how to get to that view of the jobs.
If I follow the "details" link from the job I get to https://github.com/ome/omero-figure/actions/runs/4542452995/jobs/8034996020?pr=504
but I can't figure out how to get to https://github.com/ome/omero-figure/actions/runs/4542452995/ to see the error (except by editing the URL)!?

That shows:

Node.js 12 actions are deprecated. Please update the following actions to use Node.js 16: actions/checkout@v2.
For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/.

cc @jburel

@sbesson
Copy link
Member

sbesson commented Mar 30, 2023

From https://github.com/ome/omero-figure/actions/runs/4542452995/jobs/8034996020?pr=504, can you click on the Latest #3 drop-down then select Latest attempt #3?

@will-moore
Copy link
Member

Thank's to @jburel and #505 it looks like the build is passing now...

@will-moore
Copy link
Member

@JulianHn - Apologies: one more thing... Could you update the JSON model scalebar section at https://github.com/ome/omero-figure/blob/master/docs/figure_file_format.rst
This isn't a new version of the model since it's not a breaking change.

NB: I see that 'Format' page is linked from https://omero-guides.readthedocs.io/en/latest/figure/docs/omero_figure_scripting.html but it would be good to have a link from README here too - since I found it hard to trace just now (but that doesn't have to happen in this PR).

Cheers!

@JulianHn
Copy link
Contributor Author

Just to be sure:
Do I just add the single line to the JSON optional settings specification or is there some documentation of all the options I am missing?

Regarding your NB: I actually do not really see much "how to use" in the current README in general. It's more focused on "how to sysadmin / develop" and the "how to use" is not really linked at all. Should the README be extended in general or do you think a prominent link to the readthedocs would be sufficient.

// Julian

@will-moore
Copy link
Member

Yes, just add a single line to the JSON sample.

For user guide etc there is a link from the README to https://github.com/ome/omero-figure/blob/master/SUPPORT.md, which then lists other links (which are both re-directs now), so maybe we just need to move the content of that SUPPORT.md onto the front page README and update the links to make it more prominent.
But please don't worry about it in this PR - it was just a note-to-self that the doc was kinda hard to find.

The new parameter to adjust scalebar thickness was missing 
a reference in the JSON format documentation. Add it
@will-moore
Copy link
Member

@JulianHn - apologies this has taken a while to get it deployed on our testing server (I was just testing locally before) but it's there now...

I just noticed that when I opened a previously-saved figure, the scalebars don't show up on the figure because the scalebar JSON has no height.
And when I try to generate a PDF it fails:

  File "./script", line 1963, in add_panels_to_page
    self.draw_scalebar(panel, pil_img.size[0], page)
  File "./script", line 1437, in draw_scalebar
    half_height = sb['height'] // 2

This should simply use half_height = sb.get('height', 3) // 2 here and anywhere else it reads the height in the script.

Probably the best way to handle this in the app is to increment the VERSION at https://github.com/ome/omero-figure/blob/master/src/js/models/figure_model.js#L4 to 7.

Then add a block below this section, similar to the handling of addition of scalebar units to version 5:
https://github.com/ome/omero-figure/blob/master/src/js/models/figure_model.js#L189
to add a default scalebar.height (of 3 I think it was).

Cheers

@pwalczysko
Copy link
Member

@JulianHn Sorry, deleted my comment about font and label discrepancy, as it was not introduced by this PR, and created an issue #507 instead.

@JulianHn
Copy link
Contributor Author

Hey @will-moore,

sorry for the delay - I was on vacation / conference the last 1.5 weeks.
For some reason it did not cross my mind to save and reload a figure while testing.
I'll take a look and add the necessary changes to this PR.

@pwalczysko: While it might not have been introduced here, I can add the necessary changes in this PR, if you prefer the layout in the Labels case. I'll track #507

// Julian

@pwalczysko
Copy link
Member

@pwalczysko: While it might not have been introduced here, I can add the necessary changes in this PR, if you prefer the layout in the Labels case. I'll track #507

Thank you very much for this generous suggestion. Yes, we discussed with @will-moore :
Let us go for Labels case, this means the tooltip says Font size everywhere (scalebar and labels) and is the same size and style as in the present state in Labels. Definitely not a blocker of course.

Bump version to 7 to allow automatic insertion of this property in
Figures saved from older versions to allow them to correctly load.
To ensure compatibility, adjust the figure export routine to
use .get with a default value for the height property, so it does not
fail, even if no height is present for any reason
@will-moore
Copy link
Member

@sbesson it seems I need to "Approve and run" this PR after every commit to avoid it being excluded by merge-ci?
Any way to make this a bit easier?

@sbesson
Copy link
Member

sbesson commented Apr 22, 2023

This is definitely the expected behavior and I don't think there is a built-in feature to automatically approve every new commit - see https://github.blog/2021-04-22-github-actions-update-helping-maintainers-combat-bad-actors/ for background. Once the PR of a new contributor is accepted, the approval should no longer be mandatory for future contributions so this is a one-off requirement but it will apply to every new commit of the first PR.

@will-moore
Copy link
Member

The loading of pre-existing Figure files is working now. 👍
Just one more comment above for the python script.
On second thoughts, I don't think #507 has to be fixed in this PR (can follow-up later).

…tency with the labels menu.

Add JQuery call to setup Bootstrap tooltips everytime the scalebar form is generated. This also makes
the rendering of the tooltips consistent with the other tooltips in the menu.
Fixes ome#507.
@JulianHn
Copy link
Contributor Author

I also missed it :)
Your suggested patch in #507 is applied to this tree and tested on Chrome and Firefox on Linux Mint 21.
Now all the menus have Bootstrap tooltips setup, the only inconsistency is that the tooltip for the Font Size in the scalebar form has a linebreak for me. But I am guessing this depends on the screen size etc. and I don't think it makes the whole form look inconsistent.

@will-moore
Copy link
Member

Thanks @JulianHn - looks good 👍

@will-moore
Copy link
Member

  • Opened old figure (scalebars height is 3 by default)
  • Updated height and position on various scalebars
  • Tooltips are fixed - Fixes Label size, font size for labels #507
  • Exported as PDF and TIFF - all good:

Screenshot 2023-05-02 at 13 47 52

@jburel
Copy link
Member

jburel commented May 3, 2023

@will-moore please go ahead with release. This PR introduces a new version of the format.

@pwalczysko
Copy link
Member

Screenshot 2023-05-03 at 09 48 59

Is the Font Size widget completely missing now from the Labels ^^^ ? Looks like it...

@pwalczysko
Copy link
Member

Sorry, #504 (comment) is not precise - the Font Size box appears when the Label checkbox is checked. All good here.

Screenshot 2023-05-03 at 09 55 44

@will-moore will-moore merged commit 45118df into ome:master May 3, 2023
@will-moore
Copy link
Member

released in omero-figure 6.0.0. Thanks @JulianHn

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.

Scalebar line thickness
6 participants