feat: allow the use of circles for edge handles#586
Conversation
Provide a configuration property that lets you choose another shape for the edge handle. Previously, it was only possible to use square handles (which is still the default).
WalkthroughThe pull request introduces modifications to the Changes
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? 🪧 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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (5)
packages/html/stories/CustomHandlesConfiguration.stories.ts (2)
67-71: Consider adding a comment to document the handleShape feature.The placement of
handleShapeconfiguration alongside other edge-related visual properties is well-organized. To improve maintainability, consider adding a brief comment explaining the available shape options.EdgeHandlerConfig.connectFillColor = 'pink'; + // Configure edge handle shape: 'circle' or 'square' (default) EdgeHandlerConfig.handleShape = 'circle'; EdgeHandlerConfig.selectionColor = selectionColor;
Line range hint
115-127: Consider enhancing the demo with mixed handle shapes.The current demo applies circular handles to all edges. To better showcase the flexibility of the new feature, consider adding an example that uses different handle shapes for different edges, demonstrating that the shape can be configured per edge if needed.
const e3 = graph.insertEdge(parent, null, 'Edge from A3 to X2', v4, v6, { edgeStyle: 'orthogonalEdgeStyle', + handleShape: 'square' // Example of edge-specific handle shape }); e3.geometry!.points = [new Point(490, 60), new Point(130, 130)]; const e4 = graph.insertEdge(parent, null, 'Edge from A4 to X2', v5, v6, { + handleShape: 'circle' // Example of edge-specific handle shape });packages/core/src/view/handler/EdgeHandler.ts (1)
662-664: LGTM! Clean implementation of configurable handle shapes.The implementation elegantly handles the shape selection based on configuration. Consider adding type safety for the shape value.
+type HandleShape = 'circle' | 'square'; + const shapeConstructor = - EdgeHandlerConfig.handleShape === 'circle' ? EllipseShape : RectangleShape; + (EdgeHandlerConfig.handleShape as HandleShape) === 'circle' ? EllipseShape : RectangleShape;packages/core/src/view/handler/config.ts (2)
34-40: Update JSDoc@linkreference to match the type nameThe JSDoc comment refers to
{@link EdgeHandlerConfig}, but the type being described isEdgeHandlerConfigType. For consistency and clarity, update the link to{@link EdgeHandlerConfigType}.Apply this diff to correct the reference:
/** - * Describes {@link EdgeHandlerConfig}. + * Describes {@link EdgeHandlerConfigType}. * * @experimental Subject to change or removal. maxGraph's global configuration may be modified in the future without prior notice. * @since 0.14.0 * @category Configuration */ export type EdgeHandlerConfigType = {
50-50: Consider using an enum forhandleShapefor extensibilityUsing an enum for
handleShapeinstead of a string union type could improve maintainability, scalability, and reduce potential errors, especially if more shapes may be added in the future.Apply this refactor:
// Define an enum for handle shapes export enum HandleShape { Circle = 'circle', Square = 'square', } // Update the type definition export type EdgeHandlerConfigType = { // ... /** * Kind of shape to be used for edge handles. * @default HandleShape.Square */ handleShape: HandleShape; // ... }; // Update the default configuration export const EdgeHandlerConfig: EdgeHandlerConfigType = { // ... handleShape: HandleShape.Square, // ... };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
packages/core/src/view/handler/EdgeHandler.ts(3 hunks)packages/core/src/view/handler/config.ts(1 hunks)packages/html/stories/CustomHandlesConfiguration.stories.ts(1 hunks)
🔇 Additional comments (4)
packages/html/stories/CustomHandlesConfiguration.stories.ts (1)
68-68: LGTM! The handleShape configuration is well-implemented.
The addition of handleShape = 'circle' directly fulfills the PR objective of enabling circular edge handles.
packages/core/src/view/handler/EdgeHandler.ts (2)
40-40: LGTM! Import added for circular handle support.
The import of EllipseShape is correctly placed and necessary for implementing the new circular handle feature.
637-644: LGTM! Method signature improvements.
The changes to createHandleShape improve type safety and documentation:
- Added explicit return type
Shape - Made parameter optional with
? - Updated documentation to clarify parameter usage
packages/core/src/view/handler/config.ts (1)
45-50: New handleShape property enhances customization
The addition of the handleShape property allows users to choose between 'circle' and 'square' edge handles, adding flexibility to the visual representation of edge handles. The type definition and default value are correctly specified.
Provide a configuration property that lets you choose another shape for the edge handle.
Previously, it was only possible to use square handles (which is still the default).
Demo
PR_586_edge_handles_circle.webm
Summary by CodeRabbit
New Features
handleShapeproperty, allowing selection between circle and square shapes.selectionDashedfor configurable selection border style.Bug Fixes
createHandleShapemethod andEdgeHandlerConfig.Documentation
createHandleShapemethod to clarify parameter usage.