Skip to content

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented May 1, 2025

Prefer the usage of the ShapeValue type.

This slightly decreases the size of applications. In maxGraph examples, the decrease is about 0.5 kB.

BREAKING CHANGES: the SHAPE enum has been removed. Use values of the ShapeValue type instead.

Notes

Covers #378

Summary by CodeRabbit

  • Breaking Changes

    • Removed the SHAPE enum; shape types should now be referenced using string literals as defined in the expanded and documented ShapeValue type.
  • Documentation

    • Updated comments and documentation throughout the codebase to clarify shape registration names and usage.
    • Expanded and clarified the list of default shape names and their mappings.
  • Refactor

    • Replaced usage of the SHAPE enum with string literals for shape names in all relevant areas.

Prefer the usage of the `ShapeValue` type.

This slightly decreases the size of applications. In maxGraph examples, the decrease is about 0.5 kB.

BREAKING CHANGES: the `SHAPE` enum has been removed. Use values of the `ShapeValue` type instead.
@tbouffard tbouffard added the refactor Code refactoring label May 1, 2025
@coderabbitai
Copy link

coderabbitai bot commented May 1, 2025

Walkthrough

This change removes the SHAPE enum, which previously provided constants for shape names, from the codebase. All references to shape constants are updated to use corresponding string literals directly. The ShapeValue type is expanded and documented to enumerate all default shape names and their mappings. Numerous documentation comments are updated to clarify the registration names for shapes, now referencing string literals instead of the removed enum. No functional logic is altered; the changes are limited to type definitions, documentation, imports, and string literal substitutions.

Changes

File(s) Change Summary
packages/core/src/util/Constants.ts Removed the exported SHAPE enum, eliminating all shape name constants and related documentation.
packages/core/src/types.ts Expanded and reordered the ShapeValue type to include all default shape names, with added JSDoc comments specifying their default registered shape classes.
packages/core/src/view/cell/register-shapes.ts Removed import of SHAPE; replaced SHAPE enum usage with string literals for shape registration keys.
packages/core/src/view/mixins/CellsMixin.ts,
packages/core/src/view/mixins/SwimlaneMixin.ts,
packages/core/src/view/style/Stylesheet.ts
Removed import of SHAPE and replaced usages with string literals in style assignments and comparisons.
packages/html/stories/ColorStylePlaceHolders.stories.ts,
packages/html/stories/Folding.stories.ts,
packages/html/stories/SwimLanes.stories.ts
Removed import of constants and replaced all constants.SHAPE.* references with appropriate string literals for shape properties in cell styles.
packages/core/src/view/geometry/edge/ArrowConnectorShape.ts,
ArrowShape.ts,
ConnectorShape.ts,
LineShape.ts,
PolylineShape.ts
Updated documentation comments to clarify shape registration under string literals (e.g., 'arrowConnector', 'arrow', 'connector', 'line') instead of SHAPE enum values; clarified registration status for PolylineShape.
packages/core/src/view/geometry/node/ActorShape.ts,
CloudShape.ts,
CylinderShape.ts,
DoubleEllipseShape.ts,
EllipseShape.ts,
HexagonShape.ts,
ImageShape.ts,
LabelShape.ts,
RectangleShape.ts,
RhombusShape.ts,
SwimlaneShape.ts,
TextShape.ts,
TriangleShape.ts
Updated or added documentation comments to clarify shape registration under string literals (e.g., 'actor', 'cloud', 'cylinder', etc.) and to specify which shapes are not registered by default. No code logic changes.
CHANGELOG.md Updated to document the breaking change: removal of the SHAPE enum and instructions to use ShapeValue type values instead.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Graph
    participant CellRenderer
    participant ShapeClass

    User->>Graph: Create or update cell with style.shape = "rectangle" (string literal)
    Graph->>CellRenderer: Request shape rendering for "rectangle"
    CellRenderer->>ShapeClass: Instantiate RectangleShape
    ShapeClass-->>CellRenderer: Rendered shape
    CellRenderer-->>Graph: Rendered cell
    Graph-->>User: Displayed cell

    Note over Graph,CellRenderer: Shape names are now string literals (e.g., "rectangle"), not SHAPE enum values.
Loading

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 61df8a5 and 131b511.

📒 Files selected for processing (1)
  • packages/core/src/view/style/Stylesheet.ts (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/core/src/view/style/Stylesheet.ts
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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 comments (1)
packages/core/src/view/style/Stylesheet.ts (1)

135-136: 🛠️ Refactor suggestion

Update code example in documentation

The code example in documentation still references SHAPE.RECTANGLE which no longer exists after this refactor.

 /**
  * style.shape = SHAPE.RECTANGLE;
  * style.perimeter = PERIMETER.RECTANGLE;
+ */
+
+/**
+ * style.shape = 'rectangle';
+ * style.perimeter = 'rectanglePerimeter';
  * style.rounded = true;
  * graph.getStylesheet().putCellStyle('rounded', style);
🧹 Nitpick comments (2)
CHANGELOG.md (1)

12-14: Document removal of SHAPE enum in changelog
The new breaking change entry correctly informs users about the removal of the SHAPE enum and directs them to use the ShapeValue type. Consider adding a link to the type definition in packages/core/src/types.ts for easier migration.

packages/html/stories/SwimLanes.stories.ts (1)

123-123: Consider using undefined assignment instead of delete

The static analysis tool has flagged the use of the delete operator which can impact performance.

- delete style.rounded;
+ style.rounded = undefined;
🧰 Tools
🪛 Biome (1.9.4)

[error] 123-123: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7cb8da3 and 61df8a5.

📒 Files selected for processing (28)
  • CHANGELOG.md (1 hunks)
  • packages/core/src/types.ts (1 hunks)
  • packages/core/src/util/Constants.ts (0 hunks)
  • packages/core/src/view/cell/register-shapes.ts (1 hunks)
  • packages/core/src/view/geometry/edge/ArrowConnectorShape.ts (1 hunks)
  • packages/core/src/view/geometry/edge/ArrowShape.ts (1 hunks)
  • packages/core/src/view/geometry/edge/ConnectorShape.ts (1 hunks)
  • packages/core/src/view/geometry/edge/LineShape.ts (1 hunks)
  • packages/core/src/view/geometry/edge/PolylineShape.ts (1 hunks)
  • packages/core/src/view/geometry/node/ActorShape.ts (1 hunks)
  • packages/core/src/view/geometry/node/CloudShape.ts (1 hunks)
  • packages/core/src/view/geometry/node/CylinderShape.ts (1 hunks)
  • packages/core/src/view/geometry/node/DoubleEllipseShape.ts (1 hunks)
  • packages/core/src/view/geometry/node/EllipseShape.ts (1 hunks)
  • packages/core/src/view/geometry/node/HexagonShape.ts (1 hunks)
  • packages/core/src/view/geometry/node/ImageShape.ts (1 hunks)
  • packages/core/src/view/geometry/node/LabelShape.ts (1 hunks)
  • packages/core/src/view/geometry/node/RectangleShape.ts (1 hunks)
  • packages/core/src/view/geometry/node/RhombusShape.ts (1 hunks)
  • packages/core/src/view/geometry/node/SwimlaneShape.ts (1 hunks)
  • packages/core/src/view/geometry/node/TextShape.ts (1 hunks)
  • packages/core/src/view/geometry/node/TriangleShape.ts (1 hunks)
  • packages/core/src/view/mixins/CellsMixin.ts (1 hunks)
  • packages/core/src/view/mixins/SwimlaneMixin.ts (2 hunks)
  • packages/core/src/view/style/Stylesheet.ts (3 hunks)
  • packages/html/stories/ColorStylePlaceHolders.stories.ts (2 hunks)
  • packages/html/stories/Folding.stories.ts (1 hunks)
  • packages/html/stories/SwimLanes.stories.ts (3 hunks)
💤 Files with no reviewable changes (1)
  • packages/core/src/util/Constants.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/html/stories/SwimLanes.stories.ts

[error] 123-123: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🔇 Additional comments (35)
packages/html/stories/Folding.stories.ts (1)

74-74: Replace enum reference with string literal
The import of constants was removed and style.shape now uses the literal 'rectangle', which aligns with the removal of the SHAPE enum. Ensure ShapeValue includes this value across all story files for consistency.

packages/core/src/view/geometry/node/TriangleShape.ts (1)

27-28: Update documentation with string identifier
The JSDoc now clearly indicates that TriangleShape is registered under the key 'triangle', replacing the former enum reference. This matches the updated shape registration approach.

packages/core/src/view/mixins/CellsMixin.ts (1)

960-960: Replace shape enum check with literal
The conditional now compares style.shape === 'label' instead of SHAPE.LABEL, reflecting the removed enum. Verify that downstream code handling shape types aligns with this change.

packages/core/src/view/geometry/node/TextShape.ts (1)

27-27: Clarify TextShape registration behavior
The added note explicitly states that TextShape is not registered by default, matching the registration details for other shapes. This enhances documentation clarity.

packages/html/stories/ColorStylePlaceHolders.stories.ts (2)

17-17: Correctly removed constants import

The import statement has been properly modified to remove the unused constants import from '@maxgraph/core', keeping only the Graph import which is still used in the code.


47-47: Successfully migrated from SHAPE enum to string literal

The shape property now correctly uses the string literal 'swimlane' directly instead of the removed constants.SHAPE.SWIMLANE enum value, aligning with the refactor objective.

packages/core/src/view/style/Stylesheet.ts (3)

19-19: Properly simplified imports

The import statement has been correctly updated to remove the unused SHAPE import, maintaining only the necessary ALIGN and NONE constants.


68-68: Successfully migrated from SHAPE enum to string literal

The default vertex style now correctly uses the string literal 'rectangle' directly instead of the removed SHAPE.RECTANGLE enum value.


84-84: Successfully migrated from SHAPE enum to string literal

The default edge style now correctly uses the string literal 'connector' directly instead of the removed SHAPE.CONNECTOR enum value.

packages/core/src/view/geometry/edge/PolylineShape.ts (1)

30-30: Updated documentation correctly

The class documentation has been appropriately updated to clarify that this shape is not registered in the CellRenderer by using explicit description instead of referencing the removed SHAPE enum.

packages/core/src/view/geometry/edge/ArrowConnectorShape.ts (1)

33-33: Updated documentation correctly

The class documentation has been properly updated to specify that the shape is registered under the string literal 'arrowConnector' instead of using the removed SHAPE.ARROW_CONNECTOR enum reference.

packages/core/src/view/mixins/SwimlaneMixin.ts (2)

20-20: Properly simplified imports

The import statement has been correctly updated to remove the unused SHAPE import, keeping only the necessary constants.


194-194: Successfully migrated from SHAPE enum to string literal

The isSwimlane method now correctly checks against the string literal 'swimlane' directly instead of the removed SHAPE.SWIMLANE enum value.

packages/core/src/view/geometry/node/CloudShape.ts (1)

25-26: Documentation comment correctly updated to use string literal 'cloud'.

The JSDoc now accurately reflects that this shape is registered under the 'cloud' key in CellRenderer, replacing the removed enum. Formatting and punctuation are consistent with other shape classes.

packages/core/src/view/geometry/node/LabelShape.ts (1)

27-28: Documentation comment correctly updated to use string literal 'label'.

The comment now specifies registration under 'label' in CellRenderer, aligning with the removal of the SHAPE enum. The style and punctuation match the other vertex shape docs.

packages/core/src/view/geometry/node/HexagonShape.ts (1)

27-28: Documentation comment correctly updated to use string literal 'hexagon'.

The JSDoc accurately indicates registration under 'hexagon' in CellRenderer, reflecting the enum removal. The change is consistent with the overall refactor.

packages/core/src/view/geometry/edge/ConnectorShape.ts (1)

33-33: Documentation comment correctly updated to use string literal 'connector'.

This doc now states registration under 'connector' in CellRenderer, matching the rest of the enum-removal changes.

packages/core/src/view/geometry/edge/LineShape.ts (1)

29-29: Documentation comment correctly updated to use string literal 'line'.

The JSDoc now specifies registration under 'line' in CellRenderer, in line with the removal of SHAPE.LINE. The style is consistent with other edge shape docs.

packages/core/src/view/geometry/node/ActorShape.ts (1)

27-28: Docs Update: Reflect string-based registration
The JSDoc now correctly replaces the removed SHAPE enum with the literal 'actor' for registration in CellRenderer, aligning with the updated mechanism.

packages/core/src/view/geometry/node/RhombusShape.ts (1)

27-28: Docs Update: Use literal 'rhombus' for registration
The documentation comment now accurately states that the shape is registered under the string key 'rhombus' instead of the old enum constant, ensuring consistency.

packages/core/src/view/geometry/node/EllipseShape.ts (1)

25-26: Docs Update: Use literal 'ellipse' for registration
The JSDoc has been updated to reference the string literal 'ellipse' rather than the removed enum, matching the new registration approach.

packages/core/src/view/geometry/edge/ArrowShape.ts (1)

27-31: Docs Update: Clarify edge shape registration and usage
The JSDoc now clearly separates the note that this shape is for edges and specifies registration under the literal 'arrow', replacing the removed enum constant. This improves readability and consistency across the codebase.

packages/core/src/view/geometry/node/ImageShape.ts (1)

28-29: Docs Update: Reflect string-based registration for image shape
The documentation now correctly states that the image shape is registered under the key 'image' in CellRenderer, in line with the removal of the SHAPE enum.

packages/core/src/view/geometry/node/CylinderShape.ts (1)

26-27: Documentation accurately updated to reflect enum removal

The documentation now correctly references the string literal 'cylinder' instead of the removed SHAPE enum, which aligns with the refactoring objectives.

packages/core/src/view/geometry/node/DoubleEllipseShape.ts (1)

25-26: Documentation properly updated to use string literal

The documentation now correctly references the string literal 'doubleEllipse' instead of the removed SHAPE.DOUBLE_ELLIPSE enum, aligning with the refactoring goal.

packages/core/src/view/cell/register-shapes.ts (1)

48-63: Shape registration successfully converted to string literals

The shape registration array has been correctly updated to use string literals directly instead of the removed SHAPE enum constants. This change maintains the same functionality while reducing the codebase size as mentioned in the PR objectives.

packages/core/src/view/geometry/node/SwimlaneShape.ts (1)

32-33: Documentation updated correctly for string literal usage

The documentation now properly references the string literal 'swimlane' instead of the removed SHAPE.SWIMLANE enum, consistent with the refactoring approach used throughout the codebase.

packages/core/src/view/geometry/node/RectangleShape.ts (1)

27-28: JSDoc updated to reflect shape registration by string key

The JSDoc comment has been properly updated to reflect the new registration mechanism that uses the string key 'rectangle' instead of the removed SHAPE.RECTANGLE enum value. This change aligns with the PR objective of removing the SHAPE enum.

packages/html/stories/SwimLanes.stories.ts (5)

99-99: String literal 'swimlane' replaces SHAPE enum

The code has been updated to use the string literal 'swimlane' directly instead of the removed SHAPE.SWIMLANE enum value. This change aligns with the PR objective of removing the SHAPE enum.


111-111: String literal 'rectangle' replaces SHAPE enum

The code has been updated to use the string literal 'rectangle' directly instead of the removed SHAPE.RECTANGLE enum value. This change aligns with the PR objective of removing the SHAPE enum.


121-121: String literal 'ellipse' replaces SHAPE enum

The code has been updated to use the string literal 'ellipse' directly instead of the removed SHAPE.ELLIPSE enum value. This change aligns with the PR objective of removing the SHAPE enum.


127-127: String literal 'rhombus' replaces SHAPE enum

The code has been updated to use the string literal 'rhombus' directly instead of the removed SHAPE.RHOMBUS enum value. This change aligns with the PR objective of removing the SHAPE enum.


135-135: String literal 'doubleEllipse' replaces SHAPE enum

The code has been updated to use the string literal 'doubleEllipse' directly instead of the removed SHAPE.DOUBLE_ELLIPSE enum value. This change aligns with the PR objective of removing the SHAPE enum.

packages/core/src/types.ts (2)

957-962: Documentation improved for ShapeValue type

The JSDoc comment for the ShapeValue type has been updated to clearly explain that these are names used to register shapes, which can be used as values for the CellStateStyle.shape property. This documentation improvement helps users understand the purpose of the ShapeValue type after the removal of the SHAPE enum.


966-997: Well-documented ShapeValue union type

The ShapeValue type has been expanded and properly documented with JSDoc comments for each shape name, indicating which shape class it corresponds to. This comprehensive documentation is valuable for users who previously relied on the SHAPE enum for discoverability of available shapes.

This change effectively makes ShapeValue the new authoritative source for shape names in the codebase, replacing the removed SHAPE enum.

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 1, 2025

@tbouffard tbouffard merged commit 9de5256 into main May 1, 2025
2 checks passed
@tbouffard tbouffard deleted the refactor/remove_shape_enum branch May 1, 2025 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant