-
-
Notifications
You must be signed in to change notification settings - Fork 363
feat(ImageViewer): support change zoomSpeed #6145
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
Conversation
Introduced a new `ZoomSpeed` property in `ImagePreviewer.razor.cs` to allow configuration of the preview zoom speed, marked with the `[Parameter]` attribute for parent component usage.
…apBlazor into lee/imageview
|
Thanks for your PR, @h2ls. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Reviewer's GuideThis PR adds a new ZoomSpeed parameter to the ImageViewer and ImagePreviewer components, propagates it into the underlying viewer.js module (with a fallback BASE_SPEED), replaces hardcoded wheel zoom increments with the configurable speed (including a slower Shift-key variant), and adjusts event handler registration and disposal accordingly. Sequence Diagram for ZoomSpeed Initialization ProcesssequenceDiagram
participant IV_Component as "ImageViewer (C#)"
participant IP_Component as "ImagePreviewer (C#)"
participant IP_JS as "ImagePreviewer.razor.js"
participant Viewer_JS as "viewer.js"
IV_Component->>IP_Component: Set ZoomSpeed property (e.g., 0.5)
activate IP_Component
IP_Component->>IP_Component: OnAfterRenderAsync / InvokeInitAsync() logic executes
IP_Component->>IP_JS: init(id, prevList, { ZoomSpeed: 0.5 })
deactivate IP_Component
activate IP_JS
IP_JS->>Viewer_JS: Viewer.init(el, prevList, { ZoomSpeed: 0.5 })
deactivate IP_JS
activate Viewer_JS
Viewer_JS->>Viewer_JS: viewer.zoomSpeed = config.zoomSpeed (0.5)
Viewer_JS->>Viewer_JS: Validate viewer.zoomSpeed (if invalid or <=0, use BASE_SPEED)
deactivate Viewer_JS
Sequence Diagram for Mouse Wheel Zoom OperationsequenceDiagram
actor User
participant PrevImgElement as "Image Element (in DOM)"
participant Viewer_JS as "viewer.js (handlerWheel)"
User->>PrevImgElement: Scrolls mouse wheel
activate PrevImgElement
PrevImgElement->>Viewer_JS: mousewheel/DOMMouseScroll event (e)
deactivate PrevImgElement
activate Viewer_JS
Viewer_JS->>Viewer_JS: Read viewer.zoomSpeed (configured value)
Viewer_JS->>Viewer_JS: Read e.shiftKey
Viewer_JS->>Viewer_JS: Calculate zoomStep based on viewer.zoomSpeed and e.shiftKey
alt e.wheelDelta > 0 (or equivalent for zoom in)
Viewer_JS->>Viewer_JS: newScale = currentScale + zoomStep
else (zoom out)
Viewer_JS->>Viewer_JS: newScale = Math.max(minScale, currentScale - zoomStep)
end
Viewer_JS->>Viewer_JS: Call processImage(newScale) to apply zoom
deactivate Viewer_JS
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @h2ls - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6145 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 703 703
Lines 31088 31090 +2
Branches 4395 4395
=========================================
+ Hits 31088 31090 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Enhance the `ImagePreviewer` in `ImageViewer.razor` by introducing a new `ZoomSpeed` parameter, allowing users to adjust the zoom speed when displaying images. This update also includes the addition of the `ZoomSpeed` property in `ImageViewer.razor.cs`, making it publicly accessible and documented for better usability.
Updated the definition of the `BASE_SPEED` constant to use the nullish coalescing operator (`??`) instead of a ternary operator. This change simplifies the code by ensuring `BASE_SPEED` is set to `viewer.zoomSpeed` if defined, or defaults to `0.015` if not. Retained the existing comment for context.
|
@dotnet-policy-service agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @h2ls - I've reviewed your changes - here's some feedback:
- Verify that the ZoomSpeed value from the config object is actually attached to the viewer instance inside the init function; without assigning it (e.g.
viewer.zoomSpeed = config.ZoomSpeed), the JS fallback will always be used. - Consider validating or clamping the ZoomSpeed parameter (ensure it’s positive and within a reasonable range) in the C# component or JS to prevent zero or excessively high zoom rates.
- You may want to give the C# ZoomSpeed parameter a default value (e.g. 0.015) so the default behavior is explicit in the API surface rather than relying solely on the JS fallback.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
@sourcery-ai review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @h2ls - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Link issues
fixes #6144
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Enable configurable zoom speed in the image viewer components by introducing a ZoomSpeed parameter, validating its value, and integrating it into mouse and keyboard zoom logic with proper event handler disposal.
New Features:
Enhancements:
Documentation: