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

Canvas width takes padding on scrollContainer into account #3929

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

Conversation

JanMisker
Copy link
Contributor

@JanMisker JanMisker commented Nov 6, 2024

Set the width of the render canvas to the width of the scrollContainer minus the left&right padding on it.

Short description

Resolves #3892

Implementation details

On two spots in render.ts the paddingLeft and paddingRight of the scrollContainer is subtracted from its clientWidth. Once when setting the canvas size, so it takes up the right amount of space. Second in the getWidth() function.

How to test it

::part(scroll) {
  padding: 12px;
}

Screenshots

See #3892
Screenshot too wide canvas
You can see it is a little bit wider than the wrappers above it (when completely zoomed out), in this case 2*12px = 24px .
Width of the wrapper

Checklist

  • This PR is covered by e2e tests
  • It introduces no breaking API changes

Summary by CodeRabbit

  • New Features
    • Enhanced width calculations for the waveform and scroll container, ensuring accurate display.
    • Improved error handling in the image export functionality to prevent silent failures.

These updates contribute to a more reliable and visually accurate user experience.

… scrollContainer minus the left&right padding on it.
Copy link

coderabbitai bot commented Nov 6, 2024

Walkthrough

The pull request introduces modifications to the Renderer class in src/renderer.ts. Key updates include enhancements to the getWidth() method to accurately calculate the width of the waveform and scroll container by considering padding. The render() method is also adjusted to reflect these changes. Additionally, error handling is added to the exportImage method to prevent failures when no canvases are present. These changes aim to improve the accuracy of width calculations and the robustness of image exporting.

Changes

File Change Summary
src/renderer.ts - Updated getWidth() to account for padding in width calculations.
- Adjusted render() method to incorporate padding in parentWidth calculation.
- Added error handling in exportImage to throw an error if no canvases are present.

Possibly related PRs

  • Fix Timeline Rendering on Zoom #3918: The changes in the TimelinePlugin class involve adjustments to rendering based on scroll position, which is conceptually related to the Renderer class's updates for accurate width calculations based on padding and scroll container dimensions.

Suggested reviewers

  • katspaugh

🐰 In the meadow where waves do sway,
The Renderer hops to save the day.
With widths now true, and errors caught,
A canvas brightens, as it ought!
So let us cheer, for changes grand,
A smoother flow, by rabbit's hand! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
src/renderer.ts (2)

275-276: LGTM! Consider caching computed styles.

The padding calculation is correct and aligns with the PR objective. However, since this calculation is duplicated in the render method, consider caching the computed styles or extracting the calculation to a private method.

+  private getPaddingWidth(): number {
+    const { paddingLeft, paddingRight } = getComputedStyle(this.scrollContainer)
+    return parseFloat(paddingLeft) + parseFloat(paddingRight)
+  }
+
   getWidth(): number {
-    const { paddingLeft, paddingRight } = getComputedStyle(this.scrollContainer)
-    return this.scrollContainer.clientWidth - parseFloat(paddingLeft) - parseFloat(paddingRight)
+    return this.scrollContainer.clientWidth - this.getPaddingWidth()
   }

640-641: Use the extracted method for consistency.

The padding calculation here is identical to the one in getWidth(). Let's use the extracted method to maintain consistency and improve performance.

-    const { paddingLeft, paddingRight } = getComputedStyle(this.scrollContainer)
-    const parentWidth = this.scrollContainer.clientWidth - parseFloat(paddingLeft) - parseFloat(paddingRight)
+    const parentWidth = this.scrollContainer.clientWidth - this.getPaddingWidth()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5f480f3 and a7cd024.

📒 Files selected for processing (1)
  • src/renderer.ts (2 hunks)

Comment on lines +275 to +276
const { paddingLeft, paddingRight } = getComputedStyle(this.scrollContainer)
return this.scrollContainer.clientWidth - parseFloat(paddingLeft) - parseFloat(paddingRight)
Copy link
Owner

Choose a reason for hiding this comment

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

Hey, sorry for the delay!
I'll need more time to evaluate how the performance will be affected by this as the width is read a few times.

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