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

Draft: Fix fragment rendering on scaled canvases in bookview #3356

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jbaiter
Copy link
Collaborator

@jbaiter jbaiter commented Nov 27, 2020

Previously, when one of the two canvases was scaled in book-view, the search annotations on this canvas would not match the page image.
This PR fixes this by passing a scaling factor from CanvasWorld to CanvasAnnotationDisplay, multiplication with which fixes the offset fragment so it matches the rendered canvas image.

Before

image

After

image

Unfortunately the test manifest with the content search service is not public (yet), so I can't add it to the integration test suite :-/

To be honest, I'm not completely confident that this change is the best way to fix this behavior, since I have not yet completely understood how the scaling in bookview relates to the annotation overlay, but this seems to fix it in the cases I tested. If there's a better way to do this, let me know and I'll implement it :-)

-- Edit: Don't merge yet, I just found a case where this fix doesn't work, investigating...

@codecov-io
Copy link

Codecov Report

Merging #3356 (93e7df2) into master (8218a6b) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3356      +/-   ##
==========================================
+ Coverage   89.20%   89.23%   +0.03%     
==========================================
  Files         196      196              
  Lines        3380     3391      +11     
==========================================
+ Hits         3015     3026      +11     
  Misses        365      365              
Impacted Files Coverage Δ
src/components/AnnotationsOverlay.js 83.45% <100.00%> (+0.11%) ⬆️
src/lib/CanvasAnnotationDisplay.js 92.18% <100.00%> (+0.38%) ⬆️
src/lib/CanvasWorld.js 96.47% <100.00%> (+0.31%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8218a6b...93e7df2. Read the comment docs.

@jbaiter jbaiter changed the title Fix fragment rendering on scaled canvases in bookview Draft: Fix fragment rendering on scaled canvases in bookview Nov 27, 2020
@@ -104,9 +105,12 @@ export default class CanvasAnnotationDisplay {

/** */
fragmentContext() {
const fragment = this.resource.fragmentSelector;
let fragment = this.resource.fragmentSelector;
fragment[0] += this.offset.x;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering now if perhaps we are calculating the offset incorrectly? Scaling the offsets before applying seem to be a useful transformation.

Copy link
Collaborator

@mejackreed mejackreed Dec 3, 2020

Choose a reason for hiding this comment

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

So I'm thinking we might need to do the following:

  1. Better calculate an offset based off of the scaling
  2. Resize the fragment/svg based off of scaling relationship to the canvas size

@jbaiter
Copy link
Collaborator Author

jbaiter commented Dec 9, 2020

I'm afraid I have to give up on this issue for now :-/
I created a small fixture based on another one by @mejackreed that demonstrates the issue with a canvas that is downscaled from the image, and another one that is upscaled. For neither canvas the annotations render correctly:
https://gist.github.com/jbaiter/8d4889654d87ef400bd6dcef353cdd8f

Hopefully someone smarter than me can pick this up :-)

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.

None yet

3 participants