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

Pull other static functions #201

Merged
merged 12 commits into from
Nov 8, 2024
Merged

Pull other static functions #201

merged 12 commits into from
Nov 8, 2024

Conversation

joshua-dean
Copy link
Collaborator

@joshua-dean joshua-dean commented Oct 7, 2024

Pull other static functions

Description

This and #200 should be enough to allow #190 to build correctly.

  • Add error_logging.ts
    • elvl_ are now a LogLevel enum - closes elvl_ should be enum #179
    • log_message that properly uses existing console log levels
    • Old functionality of alert and throw for certain levels is still present
  • Add canvas_utils.ts
    • Refactor dynamically_set_n_annos_per_canvas to not need the whole ULabel object
    • initialize_annotation_canvases
    • There is a lot of other canvas functions that could be moved here, but we can burn that bridge once we teach the fisherman how to swim
  • Change after_init to be instance function instead of static
  • Remove load_image_promise and use .decode instead
    • Also simplified the image loading logic

PR Checklist

  • Merged latest main
  • Version number in package.json has been bumped since last release
  • Version numbers match between package package.json and src/version.js
  • Ran npm install and npm run build AFTER bumping the version number
  • Updated documentation if necessary (currently just in api_spec.md)
  • Added changes to changelog.md

Breaking API Changes

no

Comment on lines -705 to +660
var images = [document.getElementById(`${this.config["image_id_pfx"]}__0`)];
let mappable_images = [];
for (let i = 0; i < images.length; i++) {
mappable_images.push(images[i]);
break;
}
let image_promises = mappable_images.map(ULabel.load_image_promise);
Promise.all(image_promises).then((loaded_imgs) => {
let first_bg_img = document.getElementById(`${this.config["image_id_pfx"]}__0`);
first_bg_img.decode().then(() => {
// Store image dimensions
that.config["image_height"] = loaded_imgs[0].naturalHeight;
that.config["image_width"] = loaded_imgs[0].naturalWidth;
that.config["image_height"] = first_bg_img.naturalHeight;
that.config["image_width"] = first_bg_img.naturalWidth;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This looked like a really complicated way to get the first background image. Wrapping it in an array, looping over the array, immediately breaking the loop, mapping a questionable function that directly attaches .onload to the element...

I have made it significantly easier to follow

This was referenced Oct 7, 2024
@joshua-dean
Copy link
Collaborator Author

org/listeners is approved so I merged the latest and am marking this one "ready for review".

@joshua-dean joshua-dean marked this pull request as ready for review October 9, 2024 20:49
src/index.js Outdated Show resolved Hide resolved
Co-authored-by: Trevor Burgoyne <82477095+TrevorBurgoyne@users.noreply.github.com>
Copy link
Member

@TrevorBurgoyne TrevorBurgoyne left a comment

Choose a reason for hiding this comment

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

sweet

@joshua-dean joshua-dean mentioned this pull request Oct 11, 2024
6 tasks
Base automatically changed from org/listeners to rc/v0.16.0 November 8, 2024 18:23
@joshua-dean joshua-dean merged commit d1e8bb0 into rc/v0.16.0 Nov 8, 2024
1 check failed
@joshua-dean joshua-dean deleted the org/other-static-fns branch November 8, 2024 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants