-
Notifications
You must be signed in to change notification settings - Fork 199
feat!: make edge bend points easier to manage #633
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
feat!: make edge bend points easier to manage #633
Conversation
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
WalkthroughThis 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
Possibly related PRs
Suggested labels
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
packages/html/stories/CustomHandlesConfiguration.stories.ts (2)
61-65: Avoid unintended whitespace in template literalsThe indentation within the template literal for
divMessage.innerHTMLmay 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 storyModifying
EdgeHandlerConfigdirectly within theTemplatefunction 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:
- Grammar: Add missing article in line 448: "configured with a global configuration object"
- 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 inmaxGraph: -mxEdgeHandlertoEdgeHandler-mxEdgeSegmentHandlertoEdgeSegmentHandler-mxElbowEdgeHandlertoElbowEdgeHandler-mxVertexHandlertoVertexHandlerInmxGraph, 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
📒 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 behaviorThe updated comment at line 154 correctly describes that
preferHtmlis 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 appropriateThe parameters
_senderand_evtin theescapeHandlerfunction 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 implementedThe condition now checks
EdgeHandlerConfig.virtualBendsEnabled, allowing the enabling or disabling of virtual bends through configuration, enhancing flexibility.
669-669: Documentation for optional parameter enhances clarityThe addition of the
@param dblClickdescription in the JSDoc comment provides clarity on the purpose of the optionaldblClickfunction parameter, improving maintainability.
795-799: Conditional addition of bends based on configuration is correctly implementedThe introduction of the
EdgeHandlerConfig.addBendOnShiftClickEnabledcondition 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 handlesThe condition for removing bends checks
EdgeHandlerConfig.removeBendOnShiftClickEnabledandthis.isRemovePointEvent(me.getEvent()), but does not verify ifhandlecorresponds 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 configurationReplacing the hardcoded opacity with
EdgeHandlerConfig.virtualBendOpacityallows centralized control over the virtual bend opacity, enhancing customization options.packages/core/src/view/handler/config.ts (8)
41-48: New configuration propertyaddBendOnShiftClickEnabledis well-definedThe addition of the
addBendOnShiftClickEnabledproperty, along with clear documentation and default value, enhances configurability for adding bends via shift-click.
59-66: New configuration propertyremoveBendOnShiftClickEnabledis properly introducedThe
removeBendOnShiftClickEnabledproperty allows configurable control over bend removal through shift-click, providing users with flexibility. The accompanying documentation is clear and informative.
83-87: Configuration propertyvirtualBendOpacityadds customizationIntroducing
virtualBendOpacityenables control over the opacity of virtual bends, enhancing the visual customization options for edge rendering.
105-106: Default value foraddBendOnShiftClickEnabledis correctly setThe default value of
falseforaddBendOnShiftClickEnabledensures that the experimental feature is opt-in, maintaining existing behavior by default.
111-112: Default value forremoveBendOnShiftClickEnabledis appropriately setSetting
removeBendOnShiftClickEnabledtofalseby default maintains current functionality and prevents unintended bend removal unless explicitly enabled.
119-120: Default opacity for virtual bends is appropriately definedThe default value of
20forvirtualBendOpacityprovides a reasonable level of visibility for virtual bends without being intrusive.
121-121:virtualBendsEnableddefault value ensures existing behavior is preservedSetting
virtualBendsEnabledtofalseby default maintains existing behavior, allowing users to enable virtual bends as needed.
124-124: Initialization of default configuration is appropriateThe
defaultEdgeHandlerConfigvariable captures the default configuration values ofEdgeHandlerConfig, 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.
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.
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 inmaxGraph: -mxEdgeHandlertoEdgeHandler-mxEdgeSegmentHandlertoEdgeSegmentHandler-mxElbowEdgeHandlertoElbowEdgeHandler-mxVertexHandlertoVertexHandlerInmxGraph, 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
📒 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)
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.
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.
- The arrow format (
-->) is inconsistent with other breaking changes in the changelog.virtualBendOpacityandvirtualBendsEnabledare 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
📒 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)
Previously in
mxGraph, this was done by updating the properties on the prototype of theEdgeHandlerclass. This didn't work anymore inmaxGraph.It is now possible to configure them back by using new properties available in
EdgeHandlerConfigBREAKING CHANGES: the following properties have been removed from
EdgeHandlerand are replaced by global configurationin
EdgeHandlerConfig:Demo in Storybook
PR_633_new_properties_in_story.mp4
Summary by CodeRabbit
New Features
Configuration Changes
Documentation
Refactoring