docs: add a Codecs page by tbouffard · Pull Request #524 · maxGraph/maxGraph
Briefly explain what they do and how to configure them.
Also improve the Codecs paragraph in the "migrate from mxGraph" guide
Tasks
- explain what codecs are and what to do with them
- give code examples
- check how this new page fits with the "Manual" pages
- integrate coderabbitai feedback (typo, wording improvements, ....):
Summary by CodeRabbit
Release Notes
-
New Features
- Introduced a new documentation file detailing the
Codecfeature for XML serialization and deserialization. - Enhanced migration documentation from
mxGraphtomaxGraph, providing clearer guidelines and updated class names.
- Introduced a new documentation file detailing the
-
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.htmlfile related to encoding schemes.
- Removed outdated content from the
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
Possibly related PRs
- docs: add a page to highlight demo and examples #602: Related to the
Codecclass and XML serialization documentation updates, emphasizing encoding and decoding processes inmaxGraph.
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?
🪧 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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR. (Beta)@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.
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 errorChange "lets maxGraph knows" to "lets maxGraph know" or "allows maxGraph to know".
21-21: Improve sentence clarityRephrase 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 structureThe sentence is unclear and missing words. Suggested revision:
"maxGraph provides special support to importmxGraphmodels, which have a different XML structure"🧰 Tools
🪛 LanguageTool
[uncategorized] ~88-~88: Possible missing comma found.
Context: ...s a special support to importmxGraphmodels 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 importmxGraphmodels which you a different XML structure (mainly because...(PRP_THE)
129-146: Enhance troubleshooting guidanceConsider adding specific steps to diagnose which class is missing a codec registration. For example:
- How to identify the problematic class from the stack trace
- How to check if a codec is registered for a specific class
224-224: Remove or clarify incomplete questionThe 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
📒 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.
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 informativeConsider 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 structureThe current construction "requires - to register" is grammatically awkward. Consider revising to:
"As explained above, typical usage of theCodecclass requires you to:
- register the codecs for the classes you want to encode/decode, here with
registerModelCodecs- call the
encodeordecodemethod"🧰 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 theCodecclass requires - to register the codecs for the classes you want to ...(ALLOW_TO)
126-126: Fix markdown code fenceThe 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
📒 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:
- Line 54: Uses
resultinstead ofnode - Line 60: Uses undefined
objectvariable
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)
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 descriptionConsider 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 clarityThe 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 theCodecclass requires - to register the codecs for the classes you want to ...(ALLOW_TO)
102-123: Add explanation of mxGraph model structureConsider 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 guidanceConsider adding more specific debugging steps to help users identify which codec is missing:
- How to identify the unregistered class from the stack trace
- Common classes that require registration
- How to verify if a codec is registered
215-236: Organize examples by use caseConsider 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
📒 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.
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 introductionThe 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 onCodecclasses that maps the maxGraph objects to XML nodes and a...(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)
48-62: Enhance code example clarityWhile the code example is functionally correct, consider these improvements for better clarity:
- Add comments explaining what each step does
- 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 descriptionThe 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
📒 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.
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 introductionConsider 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 registrationConsider 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 annotationsConsider 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 exampleThe example XML could be more realistic by:
- Adding comments explaining the structure
- Including more common mxGraph attributes like style
- 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 sectionConsider adding more common troubleshooting scenarios:
- Circular references in objects
- Missing required attributes
- Invalid XML structure
- Type mismatches during decode
175-182: Add more complex custom object examplesConsider adding examples that demonstrate:
- Nested custom objects
- Custom array handling
- Date serialization
- Custom attribute mapping
215-236: Organize examples by use caseConsider organizing the examples into categories:
- Basic Usage
- Advanced Features
- Migration from mxGraph
- Custom Implementation
This would help users find relevant examples more easily.
This was referenced
Jan 3, 2025This was referenced
Jan 14, 2025This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters