Skip to content

Conversation

@HalilFocic
Copy link

@HalilFocic HalilFocic commented Nov 22, 2024

The rotation handle was incorrectly positioned while rotating, it was always on the right side after any rotation. This fix:

  • Aligns the rotation handle properly based on current rotation value

PR Checklist

  • Addresses an existing open issue: Fixes [BUG] In Handles and Stencils stories, the rotation handle is always located on the right of the vertex #482
  • 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).
  • 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

Code for sizers was properly getting the current rotation angle and positioning sizers correctly while rotation handle was using different logic which always though rotation was some specific angle.

Both stencils and handles stories now properly work while rotating:

handles.mov
stencils.mov

Notes

Summary by CodeRabbit

  • New Features

    • Improved accuracy of the rotation handle's position in the vertex editing interface.
    • Enhanced visibility control of the rotation handle during text editing.
  • Bug Fixes

    • Updated rotation angle calculation to reflect the current style state, ensuring more reliable behavior.

…x rotation

The rotation handle was incorrectly positioned while rotating, it was always on the right side after any rotation.
This fix:
- Aligns the rotation handle properly based on current rotation value

Fixes maxGraph#482

if (this.rotationShape) {
const alpha = toRadians(this.currentAlpha);
const alpha = toRadians(this.state.style.rotation ?? 0);
Copy link
Member

@tbouffard tbouffard Nov 22, 2024

Choose a reason for hiding this comment

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

suggestion: Good catch! The problem was introduced during the migration from mxGraph.
Could you match the original mxGraph behavior? AFAIK, this.currentAlpha was used if not nullish. See https://github.com/jgraph/mxgraph/blob/v4.2.2/javascript/src/js/handler/mxVertexHandler.js#L2019

ℹ️ there is no need have a single commit with the initial implementation and the suggested change that would be forced pushed in the PR.
I will squash all commits when merging the PR

Copy link
Author

Choose a reason for hiding this comment

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

I can try to pull it off tomorrow but if I recall correctly from code in the mxGraph currentAlpha was null by deafult, in our case its 100 for some reason. I tried setting initial alpha to 0 but the rotation was still not working. I am sure the calculation in rotation function is badly calculated when setting new alpha.

Copy link
Member

Choose a reason for hiding this comment

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

OK I will also check on my side (I am not sure that I will be able to do it during the week-end)

Copy link
Author

Choose a reason for hiding this comment

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

I looked all around this file and when declaring alpha the variable was derived from this.state.style.rotation. I logged the value of currentAlpha and this.style.rotation and they do have same values at the at but after I release there were 2 redrawHandle function calls where both style.rotation and currentAlpha was 0 (it should be 90 since i rotated for 90 deg). Confusing thing is the values are always the same but for some reason results differ. My assumption is that alpha is not set until we finish rotating while style.rotation properly updates while we rotate. This could cause this behaviour but im not sure.

@tbouffard tbouffard added the bug Something isn't working label Nov 28, 2024
@coderabbitai
Copy link

coderabbitai bot commented Nov 28, 2024

Walkthrough

The changes in this pull request modify the VertexHandler class, specifically the redrawHandles method. The rotation angle calculation for the rotationShape has been updated to use the rotation property from state.style instead of the currentAlpha property. Additionally, the method now includes a visibility check for the rotation handle during text editing, enhancing control over its display based on the editing state of the graph.

Changes

File Change Summary
packages/core/src/view/handler/VertexHandler.ts Updated redrawHandles method to calculate rotation angle using state.style.rotation and added visibility management for the rotation handle during text editing.

Assessment against linked issues

Objective Addressed Explanation
Ensure rotation handle reflects actual rotation (#482)
Manage visibility of rotation handle during editing (#482)

Possibly related PRs


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)
packages/core/src/view/handler/VertexHandler.ts (2)

1890-1893: The rotation handle positioning fix looks good!

The change to use state.style.rotation instead of currentAlpha correctly fixes the rotation handle positioning issue. This aligns with the original mxGraph behavior and ensures the handle position accurately reflects the vertex's current rotation.

Consider adding a comment explaining why style.rotation is preferred over currentAlpha to help future maintainers understand this important implementation detail.

-      const alpha = toRadians(this.state.style.rotation ?? 0);
+      // Use style.rotation instead of currentAlpha to ensure handle position
+      // matches the vertex's actual rotation state
+      const alpha = toRadians(this.state.style.rotation ?? 0);

Line range hint 1898-1902: Improve rotation handle visibility management

The visibility logic for the rotation handle mixes multiple concerns. Consider extracting this into a dedicated method for better maintainability.

-        this.rotationShape.node.style.visibility =
-          this.state.view.graph.isEditing() || !this.handlesVisible ? 'hidden' : '';
+        this.rotationShape.node.style.visibility = this.isRotationHandleVisible() ? '' : 'hidden';

+  private isRotationHandleVisible(): boolean {
+    return !this.state.view.graph.isEditing() && this.handlesVisible;
+  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bf1f874 and 27679fc.

📒 Files selected for processing (1)
  • packages/core/src/view/handler/VertexHandler.ts (1 hunks)
🔇 Additional comments (1)
packages/core/src/view/handler/VertexHandler.ts (1)

1890-1893: Verify rotation preservation during operations

While the rotation handle positioning is fixed, we should verify that the rotation value is properly preserved during all vertex operations (e.g., resizing, moving, etc.).

Also applies to: 1052-1054

@tbouffard tbouffard changed the title fix(vertex-handler): correct rotation handle positioning during vertex rotation fix: correct rotation handle positioning during vertex rotation Nov 28, 2024
@tbouffard
Copy link
Member

@HalilFocic here are my 2 cents about the currentAlpha value.

My guess is that the value 100 was probably chosen because the property name including the “alpha” term was mistakenly considered to carry information about opacity. This property name is used for this purpose in several places in the code, such as AbstractCanvas2D.

To go ahead with the fix, I suggest we keep the implementation you're currently proposing, which doesn't use the currentAlpha property, since it solves the problem.
In parallel, I suggest that we:

  • create a GitHub issue about the currentAlpha calculation problem
  • place a link to the new issue as a comment in the code, and indicate the code we'd like to use when currentAlpha is correctly calculated

Does this solution suit you? I can create the issue and let you make the changes in the PR code.
I'll wait for your answer before going any further.

@HalilFocic
Copy link
Author

@HalilFocic here are my 2 cents about the currentAlpha value.

My guess is that the value 100 was probably chosen because the property name including the “alpha” term was mistakenly considered to carry information about opacity. This property name is used for this purpose in several places in the code, such as AbstractCanvas2D.

To go ahead with the fix, I suggest we keep the implementation you're currently proposing, which doesn't use the currentAlpha property, since it solves the problem.

In parallel, I suggest that we:

  • create a GitHub issue about the currentAlpha calculation problem

  • place a link to the new issue as a comment in the code, and indicate the code we'd like to use when currentAlpha is correctly calculated

Does this solution suit you? I can create the issue and let you make the changes in the PR code.

I'll wait for your answer before going any further.

Yeah, seems right. I think the handles are also not using the alpha. I investigated a bit and for some reason the currentAlpha has same value as rotation when we are holding mousedown but after release there is redraw where rotation is correct but alpha is incorrect.

@tbouffard
Copy link
Member

@HalilFocic I have just created #590

@HalilFocic
Copy link
Author

@tbouffard I will close this PR since #592 is updated example that resembles mxGraph functionality better and fixes both this issue and #590

@HalilFocic HalilFocic closed this Nov 30, 2024
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] In Handles and Stencils stories, the rotation handle is always located on the right of the vertex

2 participants