Skip to content

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Jan 12, 2025

Previously in mxGraph, this was done by updating the properties on the prototype of the EdgeHandler class. This didn't work anymore in maxGraph.
It is now possible to configure them back by using new properties available in EdgeHandlerConfig

BREAKING CHANGES: the following properties have been removed from EdgeHandler and are replaced by global configuration
in EdgeHandlerConfig:

  • addEnabled --> addBendOnShiftClickEnabled
  • removeEnabled --> removeBendOnShiftClickEnabled
  • virtualBendOpacity
  • virtualBendsEnabled

Demo in Storybook

PR_633_new_properties_in_story.mp4

Summary by CodeRabbit

  • New Features

    • Enhanced interactivity with new instructions for adding and removing edge bends.
    • Enabled addition and removal of edge bends via shift-click actions.
    • Modified visual representation settings for bends, including opacity and visibility.
  • Configuration Changes

    • Introduced new configuration options for edge handling.
    • Added ability to enable/disable adding and removing bends via shift-click.
    • Implemented virtual bend opacity and visibility settings.
  • Documentation

    • Updated migration guide for transitioning from mxGraph to maxGraph.
    • Provided detailed instructions on class and configuration changes.
    • Added a section on breaking changes related to property removals.
  • Refactoring

    • Removed direct property management for edge handlers.
    • Centralized configuration management for edge-related functionality.

Previously in `mxGraph`, this was done by updating the properties on the prototype of the `EdgeHandler` class. This
didn't work anymore in `maxGraph`.
It is now possible to configure them back by using new properties available in `EdgeHandlerConfig`

BREAKING CHANGES: the following properties have been removed from `EdgeHandler` and are replaced by global configuration
in `EdgeHandlerConfig`:
  - addEnabled --> addBendOnShiftClickEnabled
  - removeEnabled --> removeBendOnShiftClickEnabled
 - virtualBendOpacity
 - virtualBendsEnabled
@tbouffard tbouffard added the enhancement New feature or request label Jan 12, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jan 12, 2025

Walkthrough

This pull request introduces significant changes to the edge handling configuration in the maxGraph library. The modifications focus on transitioning from direct property management to a more flexible, configuration-driven approach for edge handlers. Key changes include removing explicit boolean properties for bend management and introducing a new configuration object that centralizes settings for adding, removing, and visualizing edge bends.

Changes

File Change Summary
packages/core/src/view/handler/EdgeHandler.ts Removed properties: addEnabled, removeEnabled, virtualBendsEnabled, virtualBendOpacity; Updated escapeHandler method signature
packages/core/src/view/handler/EdgeSegmentHandler.ts Added import for EdgeHandlerConfig; Updated bend opacity configuration
packages/core/src/view/handler/config.ts Added new configuration properties: addBendOnShiftClickEnabled, removeBendOnShiftClickEnabled, virtualBendOpacity, virtualBendsEnabled; Removed selectionDashed property
packages/html/stories/CustomHandlesConfiguration.stories.ts Updated edge handler configuration with new properties
packages/website/docs/usage/migrate-from-mxgraph.md Expanded migration documentation with details on class and configuration changes
CHANGELOG.md Added "Breaking Changes" section detailing the removal of properties from EdgeHandler and introduction of EdgeHandlerConfig

Possibly related PRs

  • docs: add a Codecs page #524: The changes in the main PR regarding the removal of properties in EdgeHandler and the introduction of EdgeHandlerConfig are related to the updates in the EdgeSegmentHandler where EdgeHandlerConfig is utilized for managing opacity, indicating a direct connection in functionality.
  • fix(VertexHandler): do not create label handle for swimlane #607: Although this PR focuses on the VertexHandler, it is part of the same broader context of handling graph elements, which may relate to the overall architecture changes in the main PR.
  • docs: migrate the mxGraph tutorial #618: This PR discusses the migration from mxGraph to maxGraph, which includes changes to the EdgeHandler class, aligning with the modifications in the main PR that also involve significant changes to the EdgeHandler.

Suggested labels

refactor


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@tbouffard tbouffard marked this pull request as ready for review January 12, 2025 17:52
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

🧹 Nitpick comments (3)
packages/html/stories/CustomHandlesConfiguration.stories.ts (2)

61-65: Avoid unintended whitespace in template literals

The indentation within the template literal for divMessage.innerHTML may introduce unwanted whitespaces or line breaks in the rendered HTML. Consider adjusting the template literal to prevent this issue.

Apply this diff to fix the issue:

-      divMessage.innerHTML = `To add a new edge bend, shift-click on the edge where you wish to add it.
-      <br>
-        To remove an existing edge bend, shift-click on it.
-      `;
+      divMessage.innerHTML = `To add a new edge bend, shift-click on the edge where you wish to add it.<br>To remove an existing edge bend, shift-click on it.`;

77-85: Consider resetting global configurations after the story

Modifying EdgeHandlerConfig directly within the Template function affects global settings and may impact other stories or components. To prevent unintended side effects, consider resetting the configurations after the story renders.

Apply this diff to reset the configurations:

+  import { resetEdgeHandlerConfig } from '@maxgraph/core';

  // Toggle custom handle defaults with storybook args
  if (args.customHandleDefaults) {
    // Existing configuration changes
  }

  // General configuration
  VertexHandlerConfig.rotationEnabled = true;

  // ... rest of the code ...

  return div;
+  
+  // Reset configurations after use
+  resetEdgeHandlerConfig();
packages/website/docs/usage/migrate-from-mxgraph.md (1)

439-452: Fix grammar and improve formatting.

The Cell handlers section needs minor improvements:

  1. Grammar: Add missing article in line 448: "configured with a global configuration object"
  2. Formatting: Consider adding code examples to demonstrate the before/after configuration changes

Apply this diff to fix the grammar:

-In `maxGraph`, the handlers are configured with global configuration object.
+In `maxGraph`, the handlers are configured with a global configuration object.

Would you like me to generate code examples showing the before/after configuration changes for better clarity?

🧰 Tools
🪛 LanguageTool

[grammar] ~442-~442: This phrase is duplicated. You should probably use “to to” only once.
Context: ...enamed in maxGraph: - mxEdgeHandler to EdgeHandler - mxEdgeSegmentHandler to EdgeSegmentHandler - mxElbowEdgeHandler to ElbowEdgeHandler - mxVertexHandler to VertexHandler In mxGraph, the hand...

(PHRASE_REPETITION)


[uncategorized] ~448-~448: Possible missing article found.
Context: ...raph`, the handlers are configured with global configuration object. For more details,...

(AI_HYDRA_LEO_MISSING_A)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 49a4df1 and 61a6823.

📒 Files selected for processing (5)
  • packages/core/src/view/handler/EdgeHandler.ts (6 hunks)
  • packages/core/src/view/handler/EdgeSegmentHandler.ts (2 hunks)
  • packages/core/src/view/handler/config.ts (3 hunks)
  • packages/html/stories/CustomHandlesConfiguration.stories.ts (1 hunks)
  • packages/website/docs/usage/migrate-from-mxgraph.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
packages/website/docs/usage/migrate-from-mxgraph.md

[grammar] ~442-~442: This phrase is duplicated. You should probably use “to to” only once.
Context: ...enamed in maxGraph: - mxEdgeHandler to EdgeHandler - mxEdgeSegmentHandler to EdgeSegmentHandler - mxElbowEdgeHandler to ElbowEdgeHandler - mxVertexHandler to VertexHandler In mxGraph, the hand...

(PHRASE_REPETITION)


[uncategorized] ~448-~448: Possible missing article found.
Context: ...raph`, the handlers are configured with global configuration object. For more details,...

(AI_HYDRA_LEO_MISSING_A)

🔇 Additional comments (17)
packages/core/src/view/handler/EdgeHandler.ts (7)

154-154: Comment update accurately reflects behavior

The updated comment at line 154 correctly describes that preferHtml is updated in the constructor based on whether the edge or its terminals have HTML labels.


307-307: Use of underscore prefixes for unused parameters is appropriate

The parameters _sender and _evt in the escapeHandler function are prefixed with underscores to indicate that they are unused, adhering to common TypeScript conventions and improving code readability.


393-393: Configuration check for virtual bends is properly implemented

The condition now checks EdgeHandlerConfig.virtualBendsEnabled, allowing the enabling or disabling of virtual bends through configuration, enhancing flexibility.


669-669: Documentation for optional parameter enhances clarity

The addition of the @param dblClick description in the JSDoc comment provides clarity on the purpose of the optional dblClick function parameter, improving maintainability.


795-799: Conditional addition of bends based on configuration is correctly implemented

The introduction of the EdgeHandlerConfig.addBendOnShiftClickEnabled condition ensures that adding bends via shift-click is only enabled when configured, providing better control over edge manipulation features.


805-808: Verify that bend removal only occurs on bend handles

The condition for removing bends checks EdgeHandlerConfig.removeBendOnShiftClickEnabled and this.isRemovePointEvent(me.getEvent()), but does not verify if handle corresponds to an existing bend handle. Ensure that bend removal only occurs when shift-clicking on an existing bend handle to prevent unintended behavior.


1982-1982: Opacity of virtual bends now utilizes configuration

Replacing the hardcoded opacity with EdgeHandlerConfig.virtualBendOpacity allows centralized control over the virtual bend opacity, enhancing customization options.

packages/core/src/view/handler/config.ts (8)

41-48: New configuration property addBendOnShiftClickEnabled is well-defined

The addition of the addBendOnShiftClickEnabled property, along with clear documentation and default value, enhances configurability for adding bends via shift-click.


59-66: New configuration property removeBendOnShiftClickEnabled is properly introduced

The removeBendOnShiftClickEnabled property allows configurable control over bend removal through shift-click, providing users with flexibility. The accompanying documentation is clear and informative.


83-87: Configuration property virtualBendOpacity adds customization

Introducing virtualBendOpacity enables control over the opacity of virtual bends, enhancing the visual customization options for edge rendering.


105-106: Default value for addBendOnShiftClickEnabled is correctly set

The default value of false for addBendOnShiftClickEnabled ensures that the experimental feature is opt-in, maintaining existing behavior by default.


111-112: Default value for removeBendOnShiftClickEnabled is appropriately set

Setting removeBendOnShiftClickEnabled to false by default maintains current functionality and prevents unintended bend removal unless explicitly enabled.


119-120: Default opacity for virtual bends is appropriately defined

The default value of 20 for virtualBendOpacity provides a reasonable level of visibility for virtual bends without being intrusive.


121-121: virtualBendsEnabled default value ensures existing behavior is preserved

Setting virtualBendsEnabled to false by default maintains existing behavior, allowing users to enable virtual bends as needed.


124-124: Initialization of default configuration is appropriate

The defaultEdgeHandlerConfig variable captures the default configuration values of EdgeHandlerConfig, facilitating the reset functionality correctly.

packages/core/src/view/handler/EdgeSegmentHandler.ts (2)

28-28: LGTM! Import statement added correctly.

The import of EdgeHandlerConfig from './config' aligns with the architectural changes moving from prototype-based to configuration-based management.


408-409: LGTM! Correct usage of EdgeHandlerConfig.

The change from using instance property to global configuration via EdgeHandlerConfig.virtualBendOpacity is implemented correctly.

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

🧹 Nitpick comments (4)
packages/website/docs/usage/migrate-from-mxgraph.md (4)

447-449: Add a code example to illustrate the configuration changes.

While the explanation is clear, adding a before/after code example would make it easier for users to understand how to migrate their handler configurations from prototype-based to the new global configuration approach.

Consider adding an example like this:

- // Before in mxGraph
- mxEdgeHandler.prototype.addEnabled = true;
- mxEdgeHandler.prototype.removeEnabled = true;
+ // Now in maxGraph
+ EdgeHandlerConfig.addBendOnShiftClickEnabled = true;
+ EdgeHandlerConfig.removeBendOnShiftClickEnabled = true;

439-440: Add cross-references to related sections.

Consider adding references to related sections that might be relevant for handler configuration, such as the "Global Configuration" section mentioned later and any sections about event handling that might affect handlers.


442-445: Fix formatting in the class renaming list.

The list of renamed classes has a minor formatting issue. Each item should end with a period for consistency with other similar lists in the document.

Apply this change:

- - `mxEdgeHandler` to `EdgeHandler`
- - `mxEdgeSegmentHandler` to `EdgeSegmentHandler`
- - `mxElbowEdgeHandler` to `ElbowEdgeHandler`
- - `mxVertexHandler` to `VertexHandler`
+ - `mxEdgeHandler` to `EdgeHandler`.
+ - `mxEdgeSegmentHandler` to `EdgeSegmentHandler`.
+ - `mxElbowEdgeHandler` to `ElbowEdgeHandler`.
+ - `mxVertexHandler` to `VertexHandler`.
🧰 Tools
🪛 LanguageTool

[grammar] ~442-~442: This phrase is duplicated. You should probably use “to to” only once.
Context: ...enamed in maxGraph: - mxEdgeHandler to EdgeHandler - mxEdgeSegmentHandler to EdgeSegmentHandler - mxElbowEdgeHandler to ElbowEdgeHandler - mxVertexHandler to VertexHandler In mxGraph, the hand...

(PHRASE_REPETITION)


450-452: Add more context about the impact of property removals.

When mentioning the removal of properties like rotationEnabled, it would be helpful to explain the benefits of moving to the new configuration approach and any potential gotchas during migration.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 61a6823 and 2cbcf0f.

📒 Files selected for processing (1)
  • packages/website/docs/usage/migrate-from-mxgraph.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
packages/website/docs/usage/migrate-from-mxgraph.md

[grammar] ~442-~442: This phrase is duplicated. You should probably use “to to” only once.
Context: ...enamed in maxGraph: - mxEdgeHandler to EdgeHandler - mxEdgeSegmentHandler to EdgeSegmentHandler - mxElbowEdgeHandler to ElbowEdgeHandler - mxVertexHandler to VertexHandler In mxGraph, the hand...

(PHRASE_REPETITION)

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

🧹 Nitpick comments (3)
CHANGELOG.md (3)

13-14: Enhance the explanation of the breaking change.

The current explanation "not possible to correctly change their value" is vague. Consider providing more context about why these properties couldn't be changed correctly and the benefits of moving to global configuration.

-Some properties have been removed from `EdgeHandler` as it was not possible to correctly change their value.
+Some properties have been removed from `EdgeHandler` and moved to global configuration in `EdgeHandlerConfig` to ensure consistent edge handling behavior across the application. This change addresses issues where modifying these properties at runtime did not properly update the edge handling behavior.

15-18: Standardize the property mapping format and provide missing replacements.

  1. The arrow format (-->) is inconsistent with other breaking changes in the changelog.
  2. virtualBendOpacity and virtualBendsEnabled are missing their replacement property names.
-  - addEnabled --> addBendOnShiftClickEnabled
-  - removeEnabled --> removeBendOnShiftClickEnabled
-  - virtualBendOpacity
-  - virtualBendsEnabled
+  - `addEnabled` is replaced by `EdgeHandlerConfig.addBendOnShiftClickEnabled`
+  - `removeEnabled` is replaced by `EdgeHandlerConfig.removeBendOnShiftClickEnabled`
+  - `virtualBendOpacity` is replaced by `EdgeHandlerConfig.bendOpacity`
+  - `virtualBendsEnabled` is replaced by `EdgeHandlerConfig.bendsEnabled`

19-20: Add a code example for migration.

Following the pattern of other breaking changes in the changelog, consider adding a code example to help users migrate from the old properties to the new configuration.

   - virtualBendsEnabled

+Example of migrating from the old properties to the new configuration:
+```js
+// Old usage
+edgeHandler.addEnabled = true;
+edgeHandler.removeEnabled = true;
+edgeHandler.virtualBendOpacity = 0.5;
+edgeHandler.virtualBendsEnabled = true;
+
+// New usage
+EdgeHandlerConfig.addBendOnShiftClickEnabled = true;
+EdgeHandlerConfig.removeBendOnShiftClickEnabled = true;
+EdgeHandlerConfig.bendOpacity = 0.5;
+EdgeHandlerConfig.bendsEnabled = true;
+```
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2cbcf0f and a7fc1ea.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build
  • GitHub Check: build (windows-2022)
  • GitHub Check: build (macos-14)
  • GitHub Check: build (ubuntu-22.04)

@tbouffard tbouffard merged commit 04a3235 into main Jan 14, 2025
6 checks passed
@tbouffard tbouffard deleted the feat/EdgeHandler_config_virtual_bends_and_dblClickRemovedBends branch January 14, 2025 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant