docs: migrate the mxGraph tutorial by tbouffard · Pull Request #618 · maxGraph/maxGraph · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
68f86b0
START introducing mxgraph tutorial
tbouffard Jan 3, 2025
abc2fa4
EXTRA package-lock.json --> to check
tbouffard Jan 3, 2025
c4e49aa
more content
tbouffard Jan 3, 2025
875a45b
rename folder
tbouffard Jan 3, 2025
c2b767d
graphs page
tbouffard Jan 3, 2025
3f0c38f
hello world: fix title
tbouffard Jan 3, 2025
45c00a2
graphs: fix title + highlight js example
tbouffard Jan 3, 2025
042c2d0
input-output
tbouffard Jan 3, 2025
5de5e78
remove the tutorial page
tbouffard Jan 3, 2025
83d9f91
add mxGraph source
tbouffard Jan 3, 2025
9243375
graphs: improve js example
tbouffard Jan 3, 2025
7715e45
Revert "EXTRA package-lock.json --> to check"
tbouffard Jan 3, 2025
dd3e92f
split editor out of the graph page
tbouffard Jan 5, 2025
7e9db3f
add warning about the usage of the mxGraph code
tbouffard Jan 5, 2025
0dfa11b
hello world: add screenshot
tbouffard Jan 5, 2025
73e30ad
WIP the-hello-world-example.md migrate to markdown
tbouffard Jan 5, 2025
5b0c50b
WIP the-hello-world-example.md migrate to markdown
tbouffard Jan 5, 2025
b2506f2
WIP input-output.md migrate to markdown
tbouffard Jan 5, 2025
27c90bf
WIP input-output.md migrate to markdown
tbouffard Jan 5, 2025
0fdc346
WIP input-output.md migrate to markdown
tbouffard Jan 5, 2025
0def7ef
rename editor-input-output.md
tbouffard Jan 5, 2025
e67c917
fix link
tbouffard Jan 5, 2025
9acc2c6
editor-input-output.md add description
tbouffard Jan 5, 2025
fbe9243
WIP graph.md migrate to markdown
tbouffard Jan 5, 2025
c9dc255
WIP graph.md migrate to markdown
tbouffard Jan 5, 2025
986419e
WIP graph.md migrate to markdown
tbouffard Jan 5, 2025
cba1210
WIP graph.md migrate to markdown
tbouffard Jan 5, 2025
e2d9e8f
WIP graph.md migrate to markdown
tbouffard Jan 5, 2025
7efa324
WIP editor.md migrate to markdown
tbouffard Jan 5, 2025
2ba4e52
WIP editor.md migrate to markdown
tbouffard Jan 5, 2025
778bb11
WIP editor.md migrate to markdown
tbouffard Jan 5, 2025
048ce24
WIP editor.md migrate to markdown
tbouffard Jan 5, 2025
d7e9e73
editor-input-output.md: update description
tbouffard Jan 5, 2025
286ffd3
remove the warning about the mxGraph doc migration in the announcemen…
tbouffard Jan 5, 2025
bae4b35
remove warning in the doc intro page
tbouffard Jan 5, 2025
ce755ce
README: remove warning about mxGraph documentation migration
tbouffard Jan 5, 2025
f8abd9f
graph.md: use maxGraph api instead of mxGraph api
tbouffard Jan 6, 2025
6eb032f
graph.md: fix typo
tbouffard Jan 6, 2025
c49718e
editor.md: add image alt directive
tbouffard Jan 6, 2025
59212bf
editor-input-output.md: improve the php code example (validation + mo…
tbouffard Jan 6, 2025
35020ba
graph.md: add image alt directive
tbouffard Jan 6, 2025
2ec206b
editor.md: fix call to the "load" function and update related documen…
tbouffard Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions README.md
46 changes: 20 additions & 26 deletions packages/core/src/util/MaxXmlRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class MaxXmlRequest {
const params = <string>this.params;
const pars = params.indexOf('&') > 0 ? params.split('&') : params.split(' ');

// Adds the parameters as textareas to the form
// Adds the parameters as text areas to the form
for (let i = 0; i < pars.length; i += 1) {
const pos = pars[i].indexOf('=');

Expand Down Expand Up @@ -378,57 +378,51 @@ class MaxXmlRequest {
}

/**
* Loads the specified URL *synchronously* and returns the <MaxXmlRequest>.
* Throws an exception if the file cannot be loaded. See {@link Utils#get} for
* an asynchronous implementation.
* Loads the specified URL *synchronously* and returns the {@link MaxXmlRequest}.
* Throws an exception if the file cannot be loaded.
* See {@link get} for an asynchronous implementation.
*
* Example:
*
* ```javascript
* try
* {
* let req = mxUtils.load(filename);
* let root = req.getDocumentElement();
* try {
* const req = load(filename);
* cont root = req.getDocumentElement();
* // Process XML DOM...
* }
* catch (ex)
* {
* mxUtils.alert('Cannot load '+filename+': '+ex);
* } catch (e) {
* console.error(`Cannot load $filename`, e);
* }
* ```
*
* @param url URL to get the data from.
*/
export const load = (url: string) => {
export const load = (url: string): MaxXmlRequest => {
const req = new MaxXmlRequest(url, null, 'GET', false);
req.send();
return req;
};

/**
* Loads the specified URL *asynchronously* and invokes the given functions
* depending on the request status. Returns the <MaxXmlRequest> in use. Both
* functions take the <MaxXmlRequest> as the only parameter. See
* {@link Utils#load} for a synchronous implementation.
* Loads the specified URL *asynchronously* and invokes the given functions depending on the request status.
* Returns the {@link MaxXmlRequest} in use.
* Both functions take the {@link MaxXmlRequest} as the only parameter.
* See {@link load} for a synchronous implementation.
*
* Example:
*
* ```javascript
* mxUtils.get(url, (req)=>
* {
* let node = req.getDocumentElement();
* get(url, (req) => {
* const node = req.getDocumentElement();
* // Process XML DOM...
* });
* ```
*
* So for example, to load a diagram into an existing graph model, the
* following code is used.
* So for example, to load a diagram into an existing graph model, the following code is used.
*
* ```javascript
* mxUtils.get(url, (req)=>
* {
* let node = req.getDocumentElement();
* let dec = new Codec(node.ownerDocument);
* get(url, (req) => {
* const node = req.getDocumentElement();
* const dec = new Codec(node.ownerDocument);
* dec.decode(node, graph.getDataModel());
* });
* ```
Expand Down
2 changes: 1 addition & 1 deletion packages/website/docs/development/_category_.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"label": "Development",
"position": 13,
"position": 21,
"link": {
"type": "generated-index",
"description": "Everything you need to know when you are developing maxGraph."
Expand Down
8 changes: 0 additions & 8 deletions packages/website/docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ which requires finer-grained customization of functionality than off-the-shelf p

## About this documentation

:::warning

This documentation is a **work in progress**.

Please be patient, as content will be gradually updated, especially the content of the original `mxGraph` documentation.

:::

:::tip

The documentation hosted at https://maxgraph.github.io/maxGraph includes the latest development changes.
Expand Down
2 changes: 1 addition & 1 deletion packages/website/docs/known-issues.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 20
sidebar_position: 100
---

# Known Issues
Expand Down
8 changes: 8 additions & 0 deletions packages/website/docs/tutorials/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Tutorials",
"position": 12,
"link": {
"type": "generated-index",
"description": "Everything you need to know to use specific features of maxGraph."
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions packages/website/docs/tutorials/editor-input-output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
sidebar_position: 4
description: Learn how to save and open Editor data stored in a XML file.
---

# Editor Input/Output

:::note

This tutorial is licensed under [Creative Commons Attribution 4.0 International (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/). \
It is adapted from the original [mxGraph tutorial](https://github.com/jgraph/mxgraph/blob/v4.2.2/docs/tutorial.html).

> Copyright 2021-present The maxGraph project Contributors \
Copyright (c) JGraph Ltd 2006-2017

:::


## Codecs

See the dedicated [codecs page](../usage/codecs.md) for more information on how to use codecs.

For encoding other objects, or if no editor instance is available, the [Codec](https://maxgraph.github.io/maxGraph/api-docs/classes/Codec.html) can be used to create and read XML data.


<a id="Files"></a>
## Files

The `save`, `open`, `readGraphModel` and `writeGraphModel` functions implement a standard mechanism for handling files in [Editor](https://maxgraph.github.io/maxGraph/api-docs/classes/Editor.html).

The default implementation of `Editor.save` is called with an argument to indicate if the save was triggered by the user or by the system.
It then uses the `urlPost` variable of the editor object to check if a post request should be issued.
If the variable is defined, the editor issues a post request to the specified URL passing the XML along as a POST variable called xml.


<a id="Post"></a>
## Post

As an example, consider the following PHP file which is located in the same directory as the HTML page.
If the filename is `server.php` then the `urlPost` variable must be set to `server.php` on the editor in order to post the diagram to the server.
The PHP file will get the XML from the POST request and write it to a file called `diagram.xml`.

```php
<?php
// Validate request method
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
exit('Method not allowed');
}

$xml = $_POST['xml'] ?? null;
if ($xml != null) {
// Validate XML content
if (!simplexml_load_string($xml)) {
http_response_code(400);
exit('Invalid XML');
}
$fh=fopen("diagram.xml","w");
fputs($fh, stripslashes($xml));
fclose($fh);
Comment thread
tbouffard marked this conversation as resolved.
}
?>
```

To set the URL to post to, change the respective entry in the `Editor` node of the config file as follows:

```xml
<Editor urlPost="http://www.example.com/server.php" ... >
```

Keep in mind that the JavaScript can only post to the server where it originated from, so we recommend to use relative URLs, e.g. `server.php`.

<a id="FormFields"></a>
## Form Fields

If you need to read/write the graph from/to a string (e.g. to fill a form-field), you can use the following methods:

```javascript
const data = editor.writeGraphModel();
editor.readGraphModel(xmlUtils.parseXml(data));
```
115 changes: 115 additions & 0 deletions packages/website/docs/tutorials/editor.md
Loading