Skip to content

fix: correctly convert "arc" attributes to boolean in StencilShape#788

Merged
tbouffard merged 2 commits intomainfrom
fix/StencilShape_arc_attribute_conversion_error
Apr 29, 2025
Merged

fix: correctly convert "arc" attributes to boolean in StencilShape#788
tbouffard merged 2 commits intomainfrom
fix/StencilShape_arc_attribute_conversion_error

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Apr 28, 2025

When set, the large-arc-flag and sweep-flag attributes were always considered as true, so the rendering was incorrect.
This is a regression introduced during the migration from mxGraph.

A new story has been added to confirm that the problem is now fixed.

Notes

Closes #786

Screenshots

Using the new story,

before now
StencilsViewer story - before the fix StencilsViewer story - with the fix

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added a new Storybook story for visualizing and interacting with custom stencil shapes, including zoom and fit controls.
    • Introduced a utility function for improved node type checking in stories.
  • Bug Fixes

    • Improved the interpretation of arc-related flags in stencil shapes, ensuring correct handling of string values for boolean attributes.
  • Chores

    • Refactored code to use shared utilities and removed unnecessary dependencies in story files.
    • Enhanced documentation comments for shape properties and stencil registry usage for better clarity.

When set, the `large-arc-flag` and `sweep-flag` attributes were always considered as true, so the rendering was incorrect.
This is a regression introduced during the migration from `mxGraph`.

A new story has been added to confirm that the problem is now fixed.
@tbouffard tbouffard added the bug Something isn't working label Apr 28, 2025
@coderabbitai
Copy link

coderabbitai bot commented Apr 28, 2025

Walkthrough

The changes introduce a new utility for converting string attributes to boolean values in the stencil geometry logic, ensuring consistent interpretation of arc flags. In the Storybook stories for stencils, the local element type guard is replaced with a shared utility function, and the dependency on core constants is removed. Additionally, a new Storybook story is added to visualize and interact with a custom stencil shape, including interactive controls for zooming and fitting the graph view. A new shared utility file provides the isElement type guard for use across stories. Minor documentation improvements and JSDoc formatting fixes were also made.

Changes

File(s) Change Summary
packages/core/src/view/geometry/stencil/StencilShape.ts Introduced toBoolean helper for attribute parsing; updated arc flag handling in drawNode method.
packages/html/stories/shared/utils.ts Added new utility file exporting isElement function for type guarding XML nodes.
packages/html/stories/Stencils.stories.ts Replaced local isElement type guard with import from shared utility; removed dependency on core constants.
packages/html/stories/StencilsViewer.stories.ts Added new Storybook story to display and interact with a custom stencil shape, including interactive controls.
packages/core/src/types.ts Expanded JSDoc comment for shape property in CellStateStyle type to clarify shape resolution semantics.
packages/core/src/view/geometry/stencil/StencilShapeRegistry.ts Improved JSDoc comment clarity and example correctness; updated example code and added note about XSD file.
packages/core/src/view/mixins/PanningMixin.type.ts Fixed JSDoc comment formatting for setPanning method in AbstractGraph interface.

Sequence Diagram(s)

sequenceDiagram
    participant StorybookUser as User
    participant Story as StencilsViewer.stories.ts
    participant Graph as maxGraph Graph
    participant StencilRegistry as Stencil Registry

    StorybookUser->>Story: Open StencilsViewer story
    Story->>Story: Parse stencil XML
    Story->>StencilRegistry: Register custom stencil shape
    Story->>Graph: Initialize graph with plugins and options
    Story->>Graph: Insert vertex with custom stencil
    StorybookUser->>Story: Click zoom/fit buttons
    Story->>Graph: Adjust view (zoom/fit)
Loading
sequenceDiagram
    participant StencilShape as StencilShape
    participant XMLNode as XML Node

    XMLNode->>StencilShape: Provide arc flag attributes (as string)
    StencilShape->>StencilShape: Call toBoolean on attributes
    StencilShape->>StencilShape: Use boolean flags in arcTo drawing logic
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 46535df and 6b806f7.

📒 Files selected for processing (6)
  • packages/core/src/types.ts (1 hunks)
  • packages/core/src/view/geometry/stencil/StencilShape.ts (2 hunks)
  • packages/core/src/view/geometry/stencil/StencilShapeRegistry.ts (1 hunks)
  • packages/core/src/view/mixins/PanningMixin.type.ts (1 hunks)
  • packages/html/stories/Stencils.stories.ts (2 hunks)
  • packages/html/stories/StencilsViewer.stories.ts (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • packages/core/src/view/geometry/stencil/StencilShapeRegistry.ts
  • packages/core/src/view/mixins/PanningMixin.type.ts
  • packages/core/src/types.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/html/stories/Stencils.stories.ts
  • packages/core/src/view/geometry/stencil/StencilShape.ts
  • packages/html/stories/StencilsViewer.stories.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build
  • GitHub Check: build (ubuntu-22.04)
  • GitHub Check: build (windows-2022)
  • GitHub Check: build (macos-14)
✨ 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.

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.

implementation: only check number in string in the boolean conversion (conform to xsd)
improve documentation and comments
story: enable panning
@sonarqubecloud
Copy link

@tbouffard tbouffard merged commit 447862e into main Apr 29, 2025
7 checks passed
@tbouffard tbouffard deleted the fix/StencilShape_arc_attribute_conversion_error branch April 29, 2025 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] StencilShape - "arc" element is not working as expected

1 participant