fix(story): correctly set the perimeter on labels at page load by HalilFocic · Pull Request #589 · maxGraph/maxGraph · GitHub
Skip to content

fix(story): correctly set the perimeter on labels at page load#589

Merged
tbouffard merged 2 commits into
maxGraph:mainfrom
HalilFocic:fix/perimeter-label-bounds-545
Jan 6, 2025
Merged

fix(story): correctly set the perimeter on labels at page load#589
tbouffard merged 2 commits into
maxGraph:mainfrom
HalilFocic:fix/perimeter-label-bounds-545

Conversation

@HalilFocic

@HalilFocic HalilFocic commented Nov 28, 2024

Copy link
Copy Markdown

PR Checklist

  • Addresses an existing open issue: fixes [BUG] PerimeterOnLabelBounds story: perimeter not on the label bounds at story load #545
  • You have discussed this issue with the maintainers of maxGraph, and you are assigned to the issue.
  • The scope of the PR is sufficiently narrow to be examined in a single session. A PR covering several issues must be split into separate PRs. Do not create a large PR, otherwise it cannot be reviewed and you will be asked to split it later or the PR will be closed.
  • I have added tests to prove my fix is effective or my feature works. This can be done in the form of automatic tests in packages/core/_tests_ or a new or altered Storybook story in packages/html/stories (an existing story may also demonstrate the change). Use the existing PerimeterOnLabelBounds.stories
  • I have provided screenshot/videos to demonstrate the change. If no releavant, explain why.
  • I have added or edited necessary documentation,or no docs changes are needed.
  • The PR title follows the "Conventional Commits" guidelines.

Overview

Storybook rendering caused this issue, nothing in core code has been changed, only the setTimeout has been added.
Video of how it works with this change:

The function getPerimeterPoint was being called before anything was painted on canvas and caused getBBox function to return 0 values.

bounds.mov

Notes

Fixes: #545

Summary by CodeRabbit

  • Bug Fixes

    • Introduced a temporary delay in the graph update process to improve compatibility with Storybook.
  • Documentation

    • Added a warning comment regarding the temporary nature of the setTimeout implementation.

This change was added because of the way Storybook loads the story. The function getPerimeterPoint was being called before anything was painted on canvas and caused getBBox function to return 0 values.

Fixes: maxGraph#545
@coderabbitai

coderabbitai Bot commented Nov 28, 2024

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
packages/html/stories/PerimeterOnLabelBounds.stories.ts (1)

Line range hint 44-63: Document the label bounds growth value

The 3px growth value for label bounds appears to be a magic number. Consider documenting why this specific value was chosen or making it configurable.

 if (perimeter && terminal?.text?.boundingBox) {
   // Adds a small border to the label bounds
+  // Note: 3px growth provides sufficient padding to prevent edge-label overlap
+  // while maintaining visual clarity
   const b = terminal.text.boundingBox.clone();
   b.grow(3);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 62d4c8f and f175e6f.

📒 Files selected for processing (1)
  • packages/html/stories/PerimeterOnLabelBounds.stories.ts (1 hunks)
🔇 Additional comments (1)
packages/html/stories/PerimeterOnLabelBounds.stories.ts (1)

112-133: Verify similar patterns in other stories

Let's check if other stories might need similar fixes or already have better solutions implemented.

Comment thread packages/html/stories/PerimeterOnLabelBounds.stories.ts
Comment thread packages/html/stories/PerimeterOnLabelBounds.stories.ts

@tbouffard tbouffard left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, tested locally. Thanks for the contribution.

@tbouffard tbouffard changed the title fix(label-bounds-story): add timeout when calling batchUpdate fix(story): correctly set the perimeter on labels at page load Jan 6, 2025
@tbouffard tbouffard merged commit f4ac267 into maxGraph:main Jan 6, 2025
@tbouffard tbouffard added the bug Something isn't working label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] PerimeterOnLabelBounds story: perimeter not on the label bounds at story load

2 participants