Skip to content

feat: allow the use of circles for edge handles#586

Merged
tbouffard merged 2 commits intomainfrom
feat/EdgeHandler_additional_handle_shape
Nov 27, 2024
Merged

feat: allow the use of circles for edge handles#586
tbouffard merged 2 commits intomainfrom
feat/EdgeHandler_additional_handle_shape

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Nov 26, 2024

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

    • Enhanced edge handle customization with the addition of handleShape property, allowing selection between circle and square shapes.
    • Introduced a new property selectionDashed for configurable selection border style.
  • Bug Fixes

    • Improved type safety and clarity in the createHandleShape method and EdgeHandlerConfig.
  • Documentation

    • Refined documentation comments for the createHandleShape method to clarify parameter usage.

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).
@tbouffard tbouffard added the enhancement New feature or request label Nov 26, 2024
@coderabbitai
Copy link

coderabbitai bot commented Nov 26, 2024

Walkthrough

The pull request introduces modifications to the EdgeHandler class and its configuration in the EdgeHandlerConfig. Key changes include the addition of the EllipseShape import and updates to the createHandleShape method, which now supports conditional shape creation based on configuration. The method signature has been altered to accept an optional _index parameter. Additionally, the EdgeHandlerConfig has been redefined to enhance type safety, introducing new properties such as handleShape and selectionDashed. A related update in the story file adds a default handleShape configuration.

Changes

File Path Change Summary
packages/core/src/view/handler/EdgeHandler.ts - Added import for EllipseShape.
- Updated createHandleShape method to support conditional shape creation and changed parameter from index to _index.
- Refined documentation comments and specified return type as Shape.
packages/core/src/view/handler/config.ts - Replaced EdgeHandlerConfig with EdgeHandlerConfigType for explicit type definitions.
- Introduced new properties: handleShape and selectionDashed, with updated types for existing properties.
- Updated EdgeHandlerConfig constant to use the new type.
packages/html/stories/CustomHandlesConfiguration.stories.ts - Added handleShape property with value 'circle' to EdgeHandlerConfig based on args.customHandleDefaults.

Possibly related PRs

  • refactor: simplify the reset config functions #582: The changes in the main PR regarding the EdgeHandlerConfig and its properties are related to the modifications in the resetEdgeHandlerConfig function in the retrieved PR, which also deals with the configuration management for the EdgeHandler.

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.

@tbouffard tbouffard marked this pull request as ready for review November 26, 2024 06:12
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 (5)
packages/html/stories/CustomHandlesConfiguration.stories.ts (2)

67-71: Consider adding a comment to document the handleShape feature.

The placement of handleShape configuration 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 @link reference to match the type name

The JSDoc comment refers to {@link EdgeHandlerConfig}, but the type being described is EdgeHandlerConfigType. 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 for handleShape for extensibility

Using an enum for handleShape instead 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

📥 Commits

Reviewing files that changed from the base of the PR and between ee67d35 and f5094fd.

📒 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:

  1. Added explicit return type Shape
  2. Made parameter optional with ?
  3. 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.

@tbouffard tbouffard merged commit 0d6b8c3 into main Nov 27, 2024
@tbouffard tbouffard deleted the feat/EdgeHandler_additional_handle_shape branch November 27, 2024 05:40
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