Skip to content

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Aug 29, 2024

Briefly explain what they do and how to configure them.
Also improve the Codecs paragraph in the "migrate from mxGraph" guide

Tasks

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new documentation file detailing the Codec feature for XML serialization and deserialization.
    • Enhanced migration documentation from mxGraph to maxGraph, providing clearer guidelines and updated class names.
  • Documentation

    • Updated global configuration documentation to clarify codec registration.
    • Added detailed instructions for using CSS and images with maxGraph.
    • Modified sidebar positions for several documentation files to improve navigation.
  • Bug Fixes

    • Removed outdated content from the tutorial.html file related to encoding schemes.

@tbouffard tbouffard added the documentation Improvements or additions to documentation label Aug 29, 2024
@tbouffard tbouffard force-pushed the docs/add_codecs_page branch from 8de3ec6 to a7d55f8 Compare December 6, 2024 09:04
@coderabbitai
Copy link

coderabbitai bot commented Dec 6, 2024

Walkthrough

This pull request introduces significant updates to the documentation and implementation of the maxGraph library, particularly focusing on codec functionality and XML serialization. Key changes include the modification of the Codec class for XML handling, the addition of comprehensive documentation about codec registration and usage, and detailed migration instructions from mxGraph. The updates span multiple documentation files, adjusting sidebar positions and enhancing clarity regarding the serialization processes and configuration settings for developers transitioning between library versions.

Changes

File Change Summary
packages/core/src/serialization/Codec.ts Updated XML serialization method, replacing mxUtils.getXml() with xmlUtils.getXml() and modifying XML structure with <GraphDataModel> root element.
packages/website/docs/usage/codecs.md New documentation file introducing Codec feature, serialization processes, and usage guidelines.
packages/website/docs/usage/css-and-images.md Updated sidebar position from 4 to 10.
packages/website/docs/usage/global-configuration.md Updated "Serialization" section to "Codecs and Serialization", added content about CodecRegistry.
packages/website/docs/usage/migrate-from-mxgraph.md Comprehensive update to migration documentation, including class and method renamings, API changes.
packages/website/docs/usage/perimeters.md Updated sidebar position from 2 to 10.
packages/website/docs/usage/plugins.md Updated sidebar position from 3 to 10.
packages/website/old-mxgraph/tutorial.html Added TODO for codecs page link, commented out default encoding scheme explanation.

Sequence Diagram

sequenceDiagram
    participant Developer
    participant CodecRegistry
    participant Codec
    participant GraphDataModel
    
    Developer->>CodecRegistry: Register codecs
    CodecRegistry-->>Developer: Codec registration confirmed
    Developer->>Codec: Encode object
    Codec->>GraphDataModel: Convert to XML
    GraphDataModel-->>Codec: XML representation
    Codec-->>Developer: Serialized XML
Loading

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?

❤️ 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. (Beta)
  • @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 force-pushed the docs/add_codecs_page branch from a7d55f8 to 847f29c Compare December 19, 2024 16:05
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: 1

🧹 Nitpick comments (5)
packages/website/docs/usage/codecs.md (5)

16-16: Fix grammatical error

Change "lets maxGraph knows" to "lets maxGraph know" or "allows maxGraph to know".


21-21: Improve sentence clarity

Rephrase to: "To use codecs, you must register them for the classes you want to encode/decode before using a Codec."

🧰 Tools
🪛 LanguageTool

[grammar] ~21-~21: Did you mean “registering”? Or maybe you should add a pronoun? In active voice, ‘require’ + ‘to’ takes an object, usually a pronoun.
Context: ...egistration The use of codecs requires to register the codecs for the classes you want to ...

(ALLOW_TO)


88-88: Fix unclear sentence structure

The sentence is unclear and missing words. Suggested revision:
"maxGraph provides special support to import mxGraph models, which have a different XML structure"

🧰 Tools
🪛 LanguageTool

[uncategorized] ~88-~88: Possible missing comma found.
Context: ...s a special support to import mxGraph models which you a different XML structure (ma...

(AI_HYDRA_LEO_MISSING_COMMA)


[grammar] ~88-~88: A verb may be missing between “you” and “a”, or a word may be misspelled.
Context: ...upport to import mxGraph models which you a different XML structure (mainly because...

(PRP_THE)


129-146: Enhance troubleshooting guidance

Consider adding specific steps to diagnose which class is missing a codec registration. For example:

  1. How to identify the problematic class from the stack trace
  2. How to check if a codec is registered for a specific class

224-224: Remove or clarify incomplete question

The line ends with a question mark and seems incomplete. Consider removing the question mark or completing the thought.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9b2401b and 8ff6a69.

📒 Files selected for processing (1)
  • packages/website/docs/usage/codecs.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
packages/website/docs/usage/codecs.md

[grammar] ~21-~21: Did you mean “registering”? Or maybe you should add a pronoun? In active voice, ‘require’ + ‘to’ takes an object, usually a pronoun.
Context: ...egistration The use of codecs requires to register the codecs for the classes you want to ...

(ALLOW_TO)


[grammar] ~63-~63: Did you mean “registering”? Or maybe you should add a pronoun? In active voice, ‘require’ + ‘to’ takes an object, usually a pronoun.
Context: ...l usage of the Codec class requires - to register the codecs for the classes you want to ...

(ALLOW_TO)


[uncategorized] ~88-~88: Possible missing comma found.
Context: ...s a special support to import mxGraph models which you a different XML structure (ma...

(AI_HYDRA_LEO_MISSING_COMMA)


[grammar] ~88-~88: A verb may be missing between “you” and “a”, or a word may be misspelled.
Context: ...upport to import mxGraph models which you a different XML structure (mainly because...

(PRP_THE)

🔇 Additional comments (1)
packages/website/docs/usage/codecs.md (1)

151-201: Well-documented custom objects section

The section provides clear examples and properly attributes the original content.

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

🧹 Nitpick comments (3)
packages/website/docs/usage/codecs.md (3)

3-3: Enhance the description to be more informative

Consider expanding the description to better reflect the content, for example: "Learn how to use codecs for serializing and deserializing maxGraph objects in XML format."


68-70: Improve sentence structure

The current construction "requires - to register" is grammatically awkward. Consider revising to:
"As explained above, typical usage of the Codec class requires you to:

  • register the codecs for the classes you want to encode/decode, here with registerModelCodecs
  • call the encode or decode method"
🧰 Tools
🪛 LanguageTool

[grammar] ~69-~69: Did you mean “registering”? Or maybe you should add a pronoun? In active voice, ‘require’ + ‘to’ takes an object, usually a pronoun.
Context: ...l usage of the Codec class requires - to register the codecs for the classes you want to ...

(ALLOW_TO)


126-126: Fix markdown code fence

The code block is closed with four backticks (``````) while it was opened with three (```). This inconsistency might cause rendering issues in some markdown processors. Please use three backticks consistently.

-````
+```
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8ff6a69 and 8eac495.

📒 Files selected for processing (2)
  • packages/website/docs/usage/codecs.md (1 hunks)
  • packages/website/docs/usage/migrate-from-mxgraph.md (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/website/docs/usage/migrate-from-mxgraph.md
🧰 Additional context used
🪛 LanguageTool
packages/website/docs/usage/codecs.md

[grammar] ~69-~69: Did you mean “registering”? Or maybe you should add a pronoun? In active voice, ‘require’ + ‘to’ takes an object, usually a pronoun.
Context: ...l usage of the Codec class requires - to register the codecs for the classes you want to ...

(ALLOW_TO)

🔇 Additional comments (2)
packages/website/docs/usage/codecs.md (2)

47-61: Fix inconsistencies in code example

The code example contains several issues that need to be addressed:

  1. Line 54: Uses result instead of node
  2. Line 60: Uses undefined object variable

1-235: Well-structured and comprehensive documentation!

The documentation provides a thorough explanation of the Codec feature, including:

  • Clear introduction and concepts
  • Detailed registration process
  • Practical code examples
  • Troubleshooting guidance
  • Links to examples and demos

The content is well-organized and will be valuable for users implementing the Codec feature.

🧰 Tools
🪛 LanguageTool

[grammar] ~69-~69: Did you mean “registering”? Or maybe you should add a pronoun? In active voice, ‘require’ + ‘to’ takes an object, usually a pronoun.
Context: ...l usage of the Codec class requires - to register the codecs for the classes you want to ...

(ALLOW_TO)

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

🧹 Nitpick comments (5)
packages/website/docs/usage/codecs.md (5)

3-3: Enhance the documentation description

Consider expanding the description to better reflect the content and purpose of this page. For example:
"Guide to using codecs for serializing and deserializing maxGraph objects in XML format."

-description: How-to use codecs.
+description: Guide to using codecs for serializing and deserializing maxGraph objects in XML format.

69-71: Improve sentence structure for clarity

The current wording is a bit awkward. Consider restructuring the sentence for better readability.

-As explained above, the typical usage of the `Codec` class requires
-- to register the codecs for the classes you want to encode/decode, here with `registerModelCodecs`
-- to call the `encode` or `decode` method
+As explained above, the typical usage of the `Codec` class requires you to:
+- Register the codecs for the classes you want to encode/decode (using `registerModelCodecs`)
+- Call the `encode` or `decode` method
🧰 Tools
🪛 LanguageTool

[grammar] ~70-~70: Did you mean “registering”? Or maybe you should add a pronoun? In active voice, ‘require’ + ‘to’ takes an object, usually a pronoun.
Context: ...l usage of the Codec class requires - to register the codecs for the classes you want to ...

(ALLOW_TO)


102-123: Add explanation of mxGraph model structure

Consider adding a brief explanation of the key elements in the mxGraph model structure (e.g., what mxCell, mxGeometry, etc. represent) to help users understand the XML format they need to provide.


136-153: Enhance troubleshooting guidance

Consider adding more specific debugging steps to help users identify which codec is missing:

  1. How to identify the unregistered class from the stack trace
  2. Common classes that require registration
  3. How to verify if a codec is registered

215-236: Organize examples by use case

Consider grouping the examples into categories for easier navigation:

  • Basic Usage Examples
  • Custom Data Examples
  • Migration Examples
  • Integration Examples

This would help users find relevant examples more quickly.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8eac495 and 11bdc92.

📒 Files selected for processing (1)
  • packages/website/docs/usage/codecs.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
packages/website/docs/usage/codecs.md

[grammar] ~70-~70: Did you mean “registering”? Or maybe you should add a pronoun? In active voice, ‘require’ + ‘to’ takes an object, usually a pronoun.
Context: ...l usage of the Codec class requires - to register the codecs for the classes you want to ...

(ALLOW_TO)

🔇 Additional comments (1)
packages/website/docs/usage/codecs.md (1)

48-62: LGTM! Code example is now correct

The code example properly demonstrates the encode/decode process with clear variable naming and correct usage of the API.

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

🧹 Nitpick comments (3)
packages/website/docs/usage/codecs.md (3)

15-15: Fix grammar in introduction

The verb "maps" should agree with the plural subject "classes".

-The serialization/deserialization process is based on `Codec` classes that maps the maxGraph objects to XML nodes and attributes.
+The serialization/deserialization process is based on `Codec` classes that map the maxGraph objects to XML nodes and attributes.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~15-~15: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...rocess is based on Codec classes that maps the maxGraph objects to XML nodes and a...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)


48-62: Enhance code example clarity

While the code example is functionally correct, consider these improvements for better clarity:

  1. Add comments explaining what each step does
  2. Add type annotations for better understanding
 import { Codec, popup, xmlUtils } from '@mxgraph/core';

 // encode/export
 const sourceObject = {}; // your object
 const encoder = new Codec();
+// Convert object to XML node
 const node = encoder.encode(sourceObject);
+// Convert XML node to pretty-printed string
 const encodedXml = xmlUtils.getPrettyXml(node);

 // decode/import
-const xml = '...'; // your XML string
+const xml: string = '...'; // your XML string
+// Object to populate with decoded data
 const targetObject = {}; // object to decode into
 const decoder = new Codec();
+// Parse XML string into DOM document
 const doc = xmlUtils.parseXml(input);
+// Decode XML into target object
 new Codec(doc).decode(doc.documentElement, targetObject);

74-74: Fix grammar in ModelXmlSerializer description

The verb "provide" should agree with the singular subject "It".

-It registers codecs under the hood and provide a simpler syntax.
+It registers codecs under the hood and provides a simpler syntax.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~74-~74: This verb does not appear to agree with the subject. Consider using a different form.
Context: ... It registers codecs under the hood and provide a simpler syntax. The code becomes: `...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 11bdc92 and 4a935d9.

📒 Files selected for processing (1)
  • packages/website/docs/usage/codecs.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
packages/website/docs/usage/codecs.md

[uncategorized] ~15-~15: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...rocess is based on Codec classes that maps the maxGraph objects to XML nodes and a...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)


[uncategorized] ~74-~74: This verb does not appear to agree with the subject. Consider using a different form.
Context: ... It registers codecs under the hood and provide a simpler syntax. The code becomes: `...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)


[uncategorized] ~97-~97: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...ability with draw.io/diagrams.net and ease the migration from mxGraph. Here is ...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)

🔇 Additional comments (5)
packages/website/docs/usage/codecs.md (5)

21-40: Well-structured explanation of codec registration!

The section effectively communicates the registration requirements, version changes, and performance considerations.


73-90: Excellent explanation of ModelXmlSerializer!

The section effectively demonstrates the simplified approach compared to direct Codec usage.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~74-~74: This verb does not appear to agree with the subject. Consider using a different form.
Context: ... It registers codecs under the hood and provide a simpler syntax. The code becomes: `...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)


134-154: Well-documented troubleshooting guide!

The section effectively explains the common "maximum call stack" error and provides clear steps to resolve it.


169-213: Comprehensive explanation of custom object encoding!

The section effectively demonstrates the default encoding scheme with clear examples.


215-236: Excellent collection of practical examples!

The section provides a comprehensive set of examples with both live demos and source code references.

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

🧹 Nitpick comments (7)
packages/website/docs/usage/codecs.md (7)

1-17: Add version compatibility information to the introduction

Consider adding a note about which versions of maxGraph this documentation applies to, helping users understand version compatibility upfront.


19-40: Add a code example for codec registration

Consider adding a basic code example showing how to register codecs, particularly for users who might need to register custom codecs. This would complement the existing explanation of the registration functions.

// Example to add:
import { CodecRegistry, registerCoreCodecs } from '@mxgraph/core';

// Register all core codecs
registerCoreCodecs();

// Or register a custom codec
CodecRegistry.register('MyCustomClass', new MyCustomCodec());

48-62: Enhance code example with type annotations

Consider adding TypeScript type annotations to make the example more clear and type-safe.

-const sourceObject = {}; // your object
-const targetObject = {}; // object to decode into
+interface YourObject {
+  // Define your object structure
+}
+const sourceObject: YourObject = {}; // your object
+const targetObject: YourObject = {}; // object to decode into

102-123: Enhance mxGraph import example

The example XML could be more realistic by:

  1. Adding comments explaining the structure
  2. Including more common mxGraph attributes like style
  3. Showing error handling
 const mxGraphModelAsXml = `<mxGraphModel>
   <root>
+    <!-- Root element required by mxGraph -->
     <mxCell id="0"/>
+    <!-- Default parent element -->
     <mxCell id="1" parent="0"/>
+    <!-- Example vertex with style -->
-    <mxCell id="2" vertex="1" parent="1" value="Vertex #2">
+    <mxCell id="2" vertex="1" parent="1" value="Vertex #2" style="rounded=1;whiteSpace=wrap;html=1;">
       <mxGeometry x="380" y="20" width="140" height="30" as="geometry"/>
     </mxCell>

134-154: Expand troubleshooting section

Consider adding more common troubleshooting scenarios:

  1. Circular references in objects
  2. Missing required attributes
  3. Invalid XML structure
  4. Type mismatches during decode

175-182: Add more complex custom object examples

Consider adding examples that demonstrate:

  1. Nested custom objects
  2. Custom array handling
  3. Date serialization
  4. Custom attribute mapping

215-236: Organize examples by use case

Consider organizing the examples into categories:

  • Basic Usage
  • Advanced Features
  • Migration from mxGraph
  • Custom Implementation
    This would help users find relevant examples more easily.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4a935d9 and ed9ea43.

📒 Files selected for processing (1)
  • packages/website/docs/usage/codecs.md (1 hunks)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant