docs: migrate the mxGraph tutorial#618
Conversation
This reverts commit abc2fa4.
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (10)
packages/website/docs/tutorials/editor-input-output.md (2)
67-70: Modernize JavaScript exampleThe JavaScript example could be improved with modern practices:
-const data = editor.writeGraphModel(); -editor.readGraphModel(xmlUtils.parseXml(data)); +try { + const data = editor.writeGraphModel(); + editor.readGraphModel(xmlUtils.parseXml(data)); +} catch (error) { + console.error('Failed to process graph model:', error); + // Handle error appropriately +}
33-33: Add missing comma for better readability-The editor issues a post request to the specified URL passing the XML along as a POST variable called xml. +The editor issues a post request to the specified URL, passing the XML along as a POST variable called xml.🧰 Tools
🪛 LanguageTool
[uncategorized] ~33-~33: Possible missing comma found.
Context: ... issues a post request to the specified URL passing the XML along as a POST variabl...(AI_HYDRA_LEO_MISSING_COMMA)
packages/website/docs/tutorials/the-hello-world-example.md (2)
34-34: Enhance CSS styling guidanceConsider providing a complete CSS example for container styling:
.graph-container { width: 100%; height: 600px; border: 1px solid #ccc; overflow: auto; /* Optional: Prevent text selection during graph interaction */ user-select: none; }
63-79: Add error handling to the graph manipulation exampleThe code example should demonstrate proper error handling:
// Gets the default parent for inserting new cells. // This is normally the first child of the root (ie. layer 0). const parent = graph.getDefaultParent(); // Adds cells to the model in a single step model.beginUpdate(); try { + if (!parent) { + throw new Error('Failed to get default parent'); + } const v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30); const v2 = graph.insertVertex(parent, null, 'World!', 200, 150, 80, 30); graph.insertEdge(parent, null, '', v1, v2); +} catch (error) { + console.error('Failed to create graph:', error); + // Handle error appropriately } finally { // Updates the display model.endUpdate(); }packages/website/docs/tutorials/editor.md (2)
36-39: Update code example to use modern practicesThe code example uses the older
mxUtils. Consider updating to modern practices:-const config = mxUtils.load('editors/config/keyhandler-commons.xml').getDocumentElement(); -const editor = new Editor(config); +async function createEditor() { + try { + const response = await fetch('editors/config/keyhandler-commons.xml'); + const text = await response.text(); + const parser = new DOMParser(); + const config = parser.parseFromString(text, 'text/xml').documentElement; + return new Editor(config); + } catch (error) { + console.error('Failed to initialize editor:', error); + throw error; + } +}
70-84: Add explanation for XML template attributesThe XML template example would benefit from detailed comments explaining each attribute's purpose:
<add as="symbol"> <Symbol label="Symbol" customAttribute="whatever"> <Cell vertex="1" connectable="true"> + <!-- Geometry defines the size of the cell --> <Geometry as="geometry" width="32" height="32"/> + <!-- Style configuration for the cell --> <Object fillColor="green" image="images/event.png" as="style"> <Array as="baseStyleNames"> + <!-- Base style that this cell inherits from --> <add value="symbol" /> </Array> </Object> </Cell> + <!-- Custom child elements can be added for additional metadata --> <CustomChild customAttribute="whatever"/> </Symbol> </add>packages/website/docs/tutorials/graph.md (4)
29-29: Add alt text to the Graph class hierarchy diagramThe image is missing alt text which impacts accessibility.
- +
43-43: Add alt text to the model diagramThe image is missing alt text which impacts accessibility.
- +🧰 Tools
🪛 Markdownlint (0.37.0)
43-43: null
Images should have alternate text (alt text)(MD045, no-alt-text)
100-100: Update TODO comment to be more specificThe TODO comment about migrating to a new method signature should include more details about the expected changes.
-[//]: # (TODO migrate to the new insertVertex method using a single object parameter) +[//]: # (TODO migrate to use graph.insertVertex({ parent, value, position: [x, y], size: [width, height], style }) instead of the legacy parameter list)
26-27: Improve wording in introductionConsider a more concise wording to avoid wordiness.
-Instantiate [Graph](https://maxgraph.github.io/maxGraph/api-docs/classes/Graph.html) in order to create a graph. This is the central class in the API. +Create a graph by instantiating the [Graph](https://maxgraph.github.io/maxGraph/api-docs/classes/Graph.html) class, which is central to the API.🧰 Tools
🪛 LanguageTool
[style] ~26-~26: Consider a shorter alternative to avoid wordiness.
Context: ...o/maxGraph/api-docs/classes/Graph.html) in order to create a graph. This is the central cla...(IN_ORDER_TO_PREMIUM)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (4)
packages/website/docs/tutorials/assets/graphs/editor.pngis excluded by!**/*.pngpackages/website/docs/tutorials/assets/graphs/graph.pngis excluded by!**/*.pngpackages/website/docs/tutorials/assets/graphs/model.pngis excluded by!**/*.pngpackages/website/docs/tutorials/assets/hello-world-example.pngis excluded by!**/*.png
📒 Files selected for processing (12)
README.md(1 hunks)packages/website/docs/development/_category_.json(1 hunks)packages/website/docs/intro.md(0 hunks)packages/website/docs/known-issues.md(1 hunks)packages/website/docs/tutorials/_category_.json(1 hunks)packages/website/docs/tutorials/editor-input-output.md(1 hunks)packages/website/docs/tutorials/editor.md(1 hunks)packages/website/docs/tutorials/graph.md(1 hunks)packages/website/docs/tutorials/the-hello-world-example.md(1 hunks)packages/website/docs/usage/_category_.json(1 hunks)packages/website/docusaurus.config.ts(1 hunks)packages/website/old-mxgraph/tutorial.html(0 hunks)
💤 Files with no reviewable changes (2)
- packages/website/docs/intro.md
- packages/website/old-mxgraph/tutorial.html
✅ Files skipped from review due to trivial changes (5)
- packages/website/docs/usage/category.json
- packages/website/docs/development/category.json
- packages/website/docs/known-issues.md
- packages/website/docusaurus.config.ts
- packages/website/docs/tutorials/category.json
🧰 Additional context used
🪛 LanguageTool
packages/website/docs/tutorials/graph.md
[style] ~26-~26: Consider a shorter alternative to avoid wordiness.
Context: ...o/maxGraph/api-docs/classes/Graph.html) in order to create a graph. This is the central cla...
(IN_ORDER_TO_PREMIUM)
packages/website/docs/tutorials/editor-input-output.md
[uncategorized] ~33-~33: Possible missing comma found.
Context: ... issues a post request to the specified URL passing the XML along as a POST variabl...
(AI_HYDRA_LEO_MISSING_COMMA)
[uncategorized] ~39-~39: Possible missing comma found.
Context: ... an example, consider the following PHP file which is located in the same directory ...
(AI_HYDRA_LEO_MISSING_COMMA)
[style] ~40-~40: Consider a shorter alternative to avoid wordiness.
Context: ...st be set to server.php on the editor in order to post the diagram to the server. The PHP...
(IN_ORDER_TO_PREMIUM)
packages/website/docs/tutorials/the-hello-world-example.md
[uncategorized] ~55-~55: Although a hyphen is possible, it is not necessary in a compound modifier in which the first word is an adverb that ends in ‘ly’.
Context: ...The endUpdate should always go into a finally-block to make sure it is always executed if t...
(HYPHENATED_LY_ADVERB_ADJECTIVE)
packages/website/docs/tutorials/editor.md
[uncategorized] ~11-~11: Possible missing comma found.
Context: ...Graphtutorial was used to create this page which still containsmxGraph` class di...
(AI_HYDRA_LEO_MISSING_COMMA)
[style] ~26-~26: Consider a shorter alternative to avoid wordiness.
Context: .../maxGraph/api-docs/classes/Editor.html) in order to create an editor. This is the central c...
(IN_ORDER_TO_PREMIUM)
🪛 Markdownlint (0.37.0)
packages/website/docs/tutorials/graph.md
68-68: null
Spaces inside link text
(MD039, no-space-in-links)
85-85: null
Spaces inside link text
(MD039, no-space-in-links)
43-43: null
Images should have alternate text (alt text)
(MD045, no-alt-text)
packages/website/docs/tutorials/editor.md
32-32: null
Images should have alternate text (alt text)
(MD045, no-alt-text)
🔇 Additional comments (1)
README.md (1)
132-132: LGTM! Documentation update is clear and conciseThe simplified warning message better reflects the current state of the documentation while maintaining transparency about ongoing improvements.
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (3)
packages/website/docs/tutorials/editor.md (1)
71-84: Add XML example contextThe XML template example could benefit from a brief explanation of:
- The purpose of the
Symbolelement- The significance of the
customAttribute- The role of
baseStyleNamespackages/website/docs/tutorials/graph.md (2)
100-100: Address TODO comment about migrationThere's a TODO comment about migrating to the new
insertVertexmethod.Would you like me to help implement the migration to the new method signature or create an issue to track this task?
68-68: Fix markdown formattingRemove spaces inside link text for better markdown formatting:
-A style is a [CellStateStyle object ](https://maxgraph.github.io/maxGraph/api-docs/types/CellStateStyle.html) +A style is a [CellStateStyle object](https://maxgraph.github.io/maxGraph/api-docs/types/CellStateStyle.html)Also applies to: 85-85
🧰 Tools
🪛 Markdownlint (0.37.0)
68-68: null
Spaces inside link text(MD039, no-space-in-links)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/website/docs/tutorials/editor-input-output.md(1 hunks)packages/website/docs/tutorials/editor.md(1 hunks)packages/website/docs/tutorials/graph.md(1 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/website/docs/tutorials/graph.md (1)
Learnt from: tbouffard
PR: maxGraph/maxGraph#618
File: packages/website/docs/tutorials/graph.md:56-59
Timestamp: 2025-01-06T09:09:47.410Z
Learning: In the maxGraph library, the classes "Cell" and "GraphDataModel" are valid, while "GraphCell" and "GraphModel" do not exist.
🪛 LanguageTool
packages/website/docs/tutorials/graph.md
[uncategorized] ~11-~11: Possible missing comma found.
Context: ...Graphtutorial was used to create this page which still containsmxGraph` class di...
(AI_HYDRA_LEO_MISSING_COMMA)
[style] ~26-~26: Consider a shorter alternative to avoid wordiness.
Context: ...o/maxGraph/api-docs/classes/Graph.html) in order to create a graph. This is the central cla...
(IN_ORDER_TO_PREMIUM)
[uncategorized] ~115-~115: A comma might be missing here.
Context: ...earance"> ## Appearance In certain cases you may want to override specific attri...
(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)
packages/website/docs/tutorials/editor.md
[style] ~26-~26: Consider a shorter alternative to avoid wordiness.
Context: .../maxGraph/api-docs/classes/Editor.html) in order to create an editor. This is the central c...
(IN_ORDER_TO_PREMIUM)
packages/website/docs/tutorials/editor-input-output.md
[style] ~40-~40: Consider a shorter alternative to avoid wordiness.
Context: ...st be set to server.php on the editor in order to post the diagram to the server. The PHP...
(IN_ORDER_TO_PREMIUM)
🪛 Markdownlint (0.37.0)
packages/website/docs/tutorials/graph.md
68-68: null
Spaces inside link text
(MD039, no-space-in-links)
85-85: null
Spaces inside link text
(MD039, no-space-in-links)
43-43: null
Images should have alternate text (alt text)
(MD045, no-alt-text)
…tation of the "load" function
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (8)
packages/website/docs/tutorials/editor.md (1)
72-84: Add comments to explain XML attributesConsider adding inline comments to explain the purpose of key attributes in the template XML.
<add as="symbol"> + <!-- 'as' attribute defines the template name --> <Symbol label="Symbol" customAttribute="whatever"> + <!-- Cell element defines the graphical properties --> <Cell vertex="1" connectable="true"> <Geometry as="geometry" width="32" height="32"/> + <!-- Object element defines the visual style --> <Object fillColor="green" image="images/event.png" as="style"> <Array as="baseStylenames"> <add value="symbol" /> </Array> </Object> </Cell> <CustomChild customAttribute="whatever"/> </Symbol> </add>packages/website/docs/tutorials/graph.md (3)
11-11: Fix grammar in warning messageAdd a comma after "this page" for better readability.
-The original `mxGraph` tutorial was used to create this page which still contains `mxGraph` class diagrams to migrate to the maxGraph API. +The original `mxGraph` tutorial was used to create this page, which still contains `mxGraph` class diagrams to migrate to the maxGraph API.🧰 Tools
🪛 LanguageTool
[uncategorized] ~11-~11: Possible missing comma found.
Context: ...Graphtutorial was used to create this page which still containsmxGraph` class di...(AI_HYDRA_LEO_MISSING_COMMA)
68-68: Fix markdown link formattingRemove extra spaces in link text for better markdown compliance.
-A style is a [CellStateStyle object ](https://maxgraph.github.io/maxGraph/api-docs/types/CellStateStyle.html), to be used with the cells. +A style is a [CellStateStyle object](https://maxgraph.github.io/maxGraph/api-docs/types/CellStateStyle.html), to be used with the cells. -The cell style is a [CellStateStyle object ](https://maxgraph.github.io/maxGraph/api-docs/types/CellStateStyle.html) which tells the graph to use the given named styles and override the specified keys. +The cell style is a [CellStateStyle object](https://maxgraph.github.io/maxGraph/api-docs/types/CellStateStyle.html) which tells the graph to use the given named styles and override the specified keys.Also applies to: 85-85
🧰 Tools
🪛 Markdownlint (0.37.0)
68-68: null
Spaces inside link text(MD039, no-space-in-links)
100-100: Address TODO comment about insertVertex method migrationThe TODO comment indicates that the
insertVertexmethod needs to be migrated to use a single object parameter.Would you like me to help implement this migration or create a GitHub issue to track this task?
packages/core/src/util/MaxXmlRequest.ts (1)
414-415: Show complete usage example.
The snippet properly demonstrates retrieving the document element. Consider adding minimal error handling for completeness.packages/website/docs/usage/migrate-from-mxgraph.md (3)
176-176: Minor punctuation suggestion.
In the bullet list, consider removing the trailing colon after “getXml()”. The sentence reads more cleanly without it.- - `getXml()`: Update your code to use `xmlUtils.getXml()` ... + - `getXml()` Update your code to use `xmlUtils.getXml()` ...🧰 Tools
🪛 LanguageTool
[uncategorized] ~176-~176: Loose punctuation mark.
Context: ...tPoint(). ####xmlUtils-getXml(): Update your code to usexmlUtils.getXm...(UNLIKELY_OPENING_PUNCTUATION)
179-179: Check section headings for clarity.
Ensure “In the default namespace” matches actual usage. If it’s describing only “get” and “load,” consider renaming for clarity.
180-181: Grammar and formatting consistency.
The bullet points forget()andload()sections read well, but each line could be rephrased to keep the instructions parallel (e.g., “Useget()instead ofmxUtils.get()” to match the line forload()).🧰 Tools
🪛 LanguageTool
[uncategorized] ~181-~181: Loose punctuation mark.
Context: ...instead ofmxUtils.get(). -load(): Update your code to useload()` instea...(UNLIKELY_OPENING_PUNCTUATION)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
packages/core/src/util/MaxXmlRequest.ts(2 hunks)packages/website/docs/tutorials/editor.md(1 hunks)packages/website/docs/tutorials/graph.md(1 hunks)packages/website/docs/usage/migrate-from-mxgraph.md(1 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/website/docs/tutorials/graph.md (1)
Learnt from: tbouffard
PR: maxGraph/maxGraph#618
File: packages/website/docs/tutorials/graph.md:56-59
Timestamp: 2025-01-06T09:09:47.410Z
Learning: In the maxGraph library, the classes "Cell" and "GraphDataModel" are valid, while "GraphCell" and "GraphModel" do not exist.
🪛 LanguageTool
packages/website/docs/tutorials/graph.md
[uncategorized] ~11-~11: Possible missing comma found.
Context: ...Graphtutorial was used to create this page which still containsmxGraph` class di...
(AI_HYDRA_LEO_MISSING_COMMA)
[style] ~26-~26: Consider a shorter alternative to avoid wordiness.
Context: ...o/maxGraph/api-docs/classes/Graph.html) in order to create a graph. This is the central cla...
(IN_ORDER_TO_PREMIUM)
packages/website/docs/usage/migrate-from-mxgraph.md
[uncategorized] ~176-~176: Loose punctuation mark.
Context: ...tPoint(). #### xmlUtils-getXml(): Update your code to use xmlUtils.getXm...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~177-~177: Loose punctuation mark.
Context: ...Utils.getXml(). - createXmlDocument(): Update your code to use xmlUtils.creat...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~181-~181: Loose punctuation mark.
Context: ...instead ofmxUtils.get(). - load(): Update your code to use load()` instea...
(UNLIKELY_OPENING_PUNCTUATION)
packages/website/docs/tutorials/editor.md
[style] ~26-~26: Consider a shorter alternative to avoid wordiness.
Context: .../maxGraph/api-docs/classes/Editor.html) in order to create an editor. This is the central c...
(IN_ORDER_TO_PREMIUM)
🪛 Markdownlint (0.37.0)
packages/website/docs/tutorials/graph.md
68-68: null
Spaces inside link text
(MD039, no-space-in-links)
85-85: null
Spaces inside link text
(MD039, no-space-in-links)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: build
- GitHub Check: build (windows-2022)
- GitHub Check: build (macos-14)
- GitHub Check: build (ubuntu-22.04)
🔇 Additional comments (7)
packages/website/docs/tutorials/editor.md (1)
37-39: 🛠️ Refactor suggestionUpdate code example to use xmlUtils
The example should use the
xmlUtilsutility class instead of the deprecatedloadfunction.-import { load } from '@maxgraph/core'; -const config = load('editors/config/keyhandler-commons.xml').getDocumentElement(); +import { xmlUtils } from '@maxgraph/core'; +const config = xmlUtils.parseXml('editors/config/keyhandler-commons.xml').documentElement; const editor = new Editor(config);Likely invalid or redundant comment.
packages/core/src/util/MaxXmlRequest.ts (6)
347-347: Use plain definitions for clarity.
This change clarifies “textareas” → “text areas” in the comment, improving the documentation’s readability.
381-383: Ensure doc references match.
The doc block referencesgetfor asynchronous loading, which aligns well with the newly documented function. This is consistent, no issues noted.
388-390: Validate error reporting.
Switching from an alert-based error toconsole.erroris more user-friendly in modern JS environments. Confirm thatconsole.errormeets the project’s logging guidelines.Also applies to: 392-393
399-399: Return type clarity.
ReturningMaxXmlRequestfromloadclarifies its usage for the caller. This is a good way to indicate the synced request outcome.
406-409: Improved documentation on async loading.
These lines adequately describe how the async call works. The mention of both success and error callbacks is helpful.
420-420: Consistency in examples.
All examples follow a similar pattern across the file, which is good for new users. Keep them consistent in style with the rest of the docs.Also applies to: 423-425

Adapt the mxGraph tutorial, which mainly includes information about the Editor class.
Notes
Closes #613
Summary by CodeRabbit
Documentation
Chores