refactor: introduce AbstractPathShape base class for shape hierarchy by tbouffard · Pull Request #953 · maxGraph/maxGraph · GitHub
Skip to content

refactor: introduce AbstractPathShape base class for shape hierarchy#953

Merged
tbouffard merged 7 commits into
mainfrom
refactor/ActorShape
Nov 24, 2025
Merged

refactor: introduce AbstractPathShape base class for shape hierarchy#953
tbouffard merged 7 commits into
mainfrom
refactor/ActorShape

Conversation

@tbouffard

@tbouffard tbouffard commented Nov 19, 2025

Copy link
Copy Markdown
Member

refactor: introduce AbstractPathShape base class for shape hierarchy

Replace ActorShape as the base class for CloudShape, HexagonShape, and
TriangleShape. These classes had no functional relation with ActorShape -
the inheritance was only for technical convenience.

Introduce AbstractPathShape as a dedicated abstract base class to make
the hierarchy more explicit and semantically clear. ActorShape now extends
AbstractPathShape alongside the other shapes.

Changes:

  • Add new AbstractPathShape abstract class
  • Refactor ActorShape to extend AbstractPathShape
  • Update CloudShape, HexagonShape, and TriangleShape to extend AbstractPathShape

Summary by CodeRabbit

  • Refactor

    • Reorganized shape rendering system architecture for improved code structure and maintainability.
  • Documentation

    • Updated shape documentation with enhanced reference annotations.

✏️ Tip: You can customize this high-level summary in your review settings.

Replace ActorShape as the base class for CloudShape, HexagonShape, and
TriangleShape. These classes had no functional relation with ActorShape -
the inheritance was only for technical convenience.

Introduce AbstractPathShape as a dedicated abstract base class to make
the hierarchy more explicit and semantically clear. ActorShape now extends
AbstractPathShape alongside the other shapes.

Changes:
- Add new AbstractPathShape abstract class
- Refactor ActorShape to extend AbstractPathShape
- Update CloudShape, HexagonShape, and TriangleShape to extend AbstractPathShape
@tbouffard tbouffard added the refactor Code refactoring label Nov 19, 2025
@coderabbitai

coderabbitai Bot commented Nov 19, 2025

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/core/src/view/shape/node/CloudShape.ts (1)

19-38: Update CloudShape JSDoc to match new base class

The move to AbstractPathShape and the optional constructor are fine, but the JSDoc still claims this “Extends {@link ActorShape} to implement a cloud shape.”

To avoid confusion for readers, consider updating that line, for example:

-/**
- * Extends {@link ActorShape} to implement a cloud shape.
+/**
+ * Path-based cloud vertex shape built on {@link AbstractPathShape}.

The rest of the implementation can stay as-is.

🧹 Nitpick comments (1)
packages/core/src/view/shape/node/ActorShape.ts (1)

20-39: ActorShape refactor is sound; JSDoc can mention AbstractPathShape

The change to derive ActorShape from AbstractPathShape with an optional constructor that forwards all four arguments to super looks correct and consistent with the other path-based shapes. redrawPath continues to operate in the normalized 0..w/0..h space, which matches AbstractPathShape.paintVertexShape’s translate(x, y) behavior.

The class-level JSDoc still reads:

Extends {@link Shape} to implement an actor shape.

Given the new hierarchy, you might want to reference the path-specific base to make the design clearer, for example:

-/**
- * Extends {@link Shape} to implement an actor shape.
+/**
+ * Path-based actor vertex shape built on {@link AbstractPathShape}.

Functionality-wise, no changes are needed.

Also applies to: 44-52

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb16ce4 and 97cc2c2.

📒 Files selected for processing (6)
  • packages/core/src/view/shape/Shape.ts (1 hunks)
  • packages/core/src/view/shape/node/AbstractPathShape.ts (1 hunks)
  • packages/core/src/view/shape/node/ActorShape.ts (1 hunks)
  • packages/core/src/view/shape/node/CloudShape.ts (2 hunks)
  • packages/core/src/view/shape/node/HexagonShape.ts (2 hunks)
  • packages/core/src/view/shape/node/TriangleShape.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: tbouffard
Repo: maxGraph/maxGraph PR: 776
File: packages/core/src/view/AbstractGraph.ts:492-495
Timestamp: 2025-04-24T12:34:56.726Z
Learning: PR #776 focuses on refactoring to introduce AbstractGraph as a base class and moving code from Graph to AbstractGraph. Type improvements and other refinements should be addressed in future PRs to keep this one focused on the core architectural change.
Learnt from: tbouffard
Repo: maxGraph/maxGraph PR: 849
File: packages/html/stories/DragSource.stories.js:98-101
Timestamp: 2025-06-13T07:48:10.300Z
Learning: User tbouffard prefers answers in English; avoid switching to other languages in future replies.
📚 Learning: 2025-04-24T12:34:56.726Z
Learnt from: tbouffard
Repo: maxGraph/maxGraph PR: 776
File: packages/core/src/view/AbstractGraph.ts:492-495
Timestamp: 2025-04-24T12:34:56.726Z
Learning: PR #776 focuses on refactoring to introduce AbstractGraph as a base class and moving code from Graph to AbstractGraph. Type improvements and other refinements should be addressed in future PRs to keep this one focused on the core architectural change.

Applied to files:

  • packages/core/src/view/shape/node/AbstractPathShape.ts
🧬 Code graph analysis (5)
packages/core/src/view/shape/node/TriangleShape.ts (1)
packages/core/src/types.ts (1)
  • ColorValue (909-909)
packages/core/src/view/shape/node/HexagonShape.ts (1)
packages/core/src/types.ts (1)
  • ColorValue (909-909)
packages/core/src/view/shape/node/CloudShape.ts (1)
packages/core/src/types.ts (1)
  • ColorValue (909-909)
packages/core/src/view/shape/node/AbstractPathShape.ts (2)
packages/core/src/types.ts (1)
  • ColorValue (909-909)
packages/core/src/util/Constants.ts (1)
  • NONE (378-378)
packages/core/src/view/shape/node/ActorShape.ts (3)
packages/core/src/view/canvas/XmlCanvas2D.ts (2)
  • fill (942-944)
  • stroke (935-937)
packages/core/src/view/canvas/SvgCanvas2D.ts (2)
  • fill (1807-1809)
  • stroke (1800-1802)
packages/core/src/types.ts (1)
  • ColorValue (909-909)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: build
  • GitHub Check: build (windows-2022)
  • GitHub Check: build (ubuntu-24.04)
  • GitHub Check: build (macos-14)
🔇 Additional comments (3)
packages/core/src/view/shape/Shape.ts (1)

1019-1020: JSDoc link style change looks good

Using {@link ...} for boundingBox, createBoundingBox, and augmentBoundingBox is consistent with the rest of the file and doesn’t affect behavior.

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

19-40: HexagonShape migration to AbstractPathShape is correct

Imports, inheritance, and the optional constructor forwarding to super(bounds, fill, stroke, strokeWidth) align with the new path-based base while preserving the expected instantiation contract.

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

20-40: TriangleShape refactor to AbstractPathShape is consistent

The new inheritance and constructor delegation to AbstractPathShape are consistent with Hexagon/Cloud/Actor and keep the public instantiation pattern intact.

Comment thread packages/core/src/view/shape/node/AbstractPathShape.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (1)
packages/core/src/view/shape/node/ActorShape.ts (1)

32-39: Constructor is redundant and can be safely omitted

The constructor just forwards parameters to super() without additional logic. Since TypeScript automatically inherits the base class constructor signature when a derived class doesn't declare its own, you can remove this constructor entirely and rely on the inherited constructor from AbstractPathShape. This reduces duplication while maintaining identical behavior and type safety.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b6fc482 and fb497a6.

📒 Files selected for processing (1)
  • packages/core/src/view/shape/node/ActorShape.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: tbouffard
Repo: maxGraph/maxGraph PR: 776
File: packages/core/src/view/AbstractGraph.ts:492-495
Timestamp: 2025-04-24T12:34:56.726Z
Learning: PR #776 focuses on refactoring to introduce AbstractGraph as a base class and moving code from Graph to AbstractGraph. Type improvements and other refinements should be addressed in future PRs to keep this one focused on the core architectural change.
Learnt from: tbouffard
Repo: maxGraph/maxGraph PR: 849
File: packages/html/stories/DragSource.stories.js:98-101
Timestamp: 2025-06-13T07:48:10.300Z
Learning: User tbouffard prefers answers in English; avoid switching to other languages in future replies.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: build
  • GitHub Check: build (ubuntu-24.04)
  • GitHub Check: build (windows-2022)
  • GitHub Check: build (macos-14)
🔇 Additional comments (3)
packages/core/src/view/shape/node/ActorShape.ts (3)

19-23: Imports now align with the new AbstractPathShape base

Switching to AbstractPathShape and using a type-only import for ColorValue is consistent with the new hierarchy and keeps types explicit without impacting runtime.


25-31: Doc and base class correctly reflect the refactored shape hierarchy

The updated description and extends AbstractPathShape cleanly express that ActorShape is a path-based vertex shape and decouple it from unrelated shapes, matching the PR’s architectural goal.


41-52: redrawPath override remains correct and benefits from the override keyword

Marking redrawPath with override keeps the existing path logic while adding compile-time checks against the abstract base, which is exactly what we want for this refactor.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (1)
packages/core/src/view/shape/node/CloudShape.ts (1)

19-42: CloudShape correctly migrated to AbstractPathShape, but JSDoc still mentions ActorShape.

The switch to AbstractPathShape and the type-only AbstractCanvas2D import look consistent with the new path-based hierarchy; CloudShape only customizes redrawPath, so behavior should remain unchanged.

The JSDoc still says “Extends {@link ActorShape}”, which is now inaccurate and could confuse readers. Consider updating it to reference AbstractPathShape or rephrasing without naming the base class.

Based on learnings, treating this as a non-blocking doc tweak aligned with the refactor’s scope.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb497a6 and 8590896.

📒 Files selected for processing (4)
  • packages/core/src/view/shape/node/ActorShape.ts (1 hunks)
  • packages/core/src/view/shape/node/CloudShape.ts (2 hunks)
  • packages/core/src/view/shape/node/HexagonShape.ts (2 hunks)
  • packages/core/src/view/shape/node/TriangleShape.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/view/shape/node/ActorShape.ts
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: tbouffard
Repo: maxGraph/maxGraph PR: 776
File: packages/core/src/view/AbstractGraph.ts:492-495
Timestamp: 2025-04-24T12:34:56.726Z
Learning: PR #776 focuses on refactoring to introduce AbstractGraph as a base class and moving code from Graph to AbstractGraph. Type improvements and other refinements should be addressed in future PRs to keep this one focused on the core architectural change.
Learnt from: tbouffard
Repo: maxGraph/maxGraph PR: 857
File: packages/core/src/view/plugins/SelectionHandler.ts:1081-1092
Timestamp: 2025-06-26T13:27:19.012Z
Learning: User tbouffard prefers to keep PRs focused on their main objective and defer implementation improvements or logic fixes to future dedicated PRs. For maxGraph, refactoring PRs like Dictionary→Map migration should not include unrelated logic improvements even when valid issues are identified in the migrated code.
Learnt from: tbouffard
Repo: maxGraph/maxGraph PR: 849
File: packages/html/stories/DragSource.stories.js:98-101
Timestamp: 2025-06-13T07:48:10.300Z
Learning: User tbouffard prefers answers in English; avoid switching to other languages in future replies.
🔇 Additional comments (2)
packages/core/src/view/shape/node/TriangleShape.ts (1)

20-52: TriangleShape migration to AbstractPathShape looks consistent and behavior-preserving.

Imports, the new extends AbstractPathShape, and the redrawPath override align with a path-based base class, and the use of getBaseArcSize/addPoints suggests shared rounding logic now lives in the base. No functional regressions are apparent in this class.

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

19-51: HexagonShape is cleanly aligned with AbstractPathShape without changing behavior.

The new base class, imports, and redrawPath implementation are consistent with the other refactored shapes. Relying on the inherited constructor and using getBaseArcSize/addPoints centralizes path logic as intended, with no visible functional changes.

@sonarqubecloud

Copy link
Copy Markdown

@tbouffard tbouffard merged commit aaea98a into main Nov 24, 2025
4 checks passed
@tbouffard tbouffard deleted the refactor/ActorShape branch November 24, 2025 10:55
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