Skip to content
Navigation Menu
{{ message }}
forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 201
docs: migrate the mxGraph tutorial #618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 abc2fa4
EXTRA package-lock.json --> to check
tbouffard c4e49aa
more content
tbouffard 875a45b
rename folder
tbouffard c2b767d
graphs page
tbouffard 3f0c38f
hello world: fix title
tbouffard 45c00a2
graphs: fix title + highlight js example
tbouffard 042c2d0
input-output
tbouffard 5de5e78
remove the tutorial page
tbouffard 83d9f91
add mxGraph source
tbouffard 9243375
graphs: improve js example
tbouffard 7715e45
Revert "EXTRA package-lock.json --> to check"
tbouffard dd3e92f
split editor out of the graph page
tbouffard 7e9db3f
add warning about the usage of the mxGraph code
tbouffard 0dfa11b
hello world: add screenshot
tbouffard 73e30ad
WIP the-hello-world-example.md migrate to markdown
tbouffard 5b0c50b
WIP the-hello-world-example.md migrate to markdown
tbouffard b2506f2
WIP input-output.md migrate to markdown
tbouffard 27c90bf
WIP input-output.md migrate to markdown
tbouffard 0fdc346
WIP input-output.md migrate to markdown
tbouffard 0def7ef
rename editor-input-output.md
tbouffard e67c917
fix link
tbouffard 9acc2c6
editor-input-output.md add description
tbouffard fbe9243
WIP graph.md migrate to markdown
tbouffard c9dc255
WIP graph.md migrate to markdown
tbouffard 986419e
WIP graph.md migrate to markdown
tbouffard cba1210
WIP graph.md migrate to markdown
tbouffard e2d9e8f
WIP graph.md migrate to markdown
tbouffard 7efa324
WIP editor.md migrate to markdown
tbouffard 2ba4e52
WIP editor.md migrate to markdown
tbouffard 778bb11
WIP editor.md migrate to markdown
tbouffard 048ce24
WIP editor.md migrate to markdown
tbouffard d7e9e73
editor-input-output.md: update description
tbouffard 286ffd3
remove the warning about the mxGraph doc migration in the announcemen…
tbouffard bae4b35
remove warning in the doc intro page
tbouffard ce755ce
README: remove warning about mxGraph documentation migration
tbouffard f8abd9f
graph.md: use maxGraph api instead of mxGraph api
tbouffard 6eb032f
graph.md: fix typo
tbouffard c49718e
editor.md: add image alt directive
tbouffard 59212bf
editor-input-output.md: improve the php code example (validation + mo…
tbouffard 35020ba
graph.md: add image alt directive
tbouffard 2ec206b
editor.md: fix call to the "load" function and update related documen…
tbouffard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This 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
This 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
This 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
This 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
This 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| --- | ||
| sidebar_position: 20 | ||
| sidebar_position: 100 | ||
| --- | ||
|
|
||
| # Known Issues | ||
|
|
||
This 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
| 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." | ||
| } | ||
| } |
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This 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
| 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); | ||
| } | ||
| ?> | ||
| ``` | ||
|
|
||
| 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)); | ||
| ``` | ||
This 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| --- | ||
| sidebar_position: 3 | ||
| description: Learn how to use the maxGraph Editor. | ||
| --- | ||
|
|
||
| # Editor | ||
|
|
||
| :::warning | ||
|
|
||
| The content of this page is a **work in progress**. | ||
| The original `mxGraph` tutorial was used to create this page which still contains `mxGraph` class diagrams to migrate to the maxGraph API. | ||
|
|
||
| ::: | ||
|
|
||
| :::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 | ||
|
|
||
| ::: | ||
|
|
||
|
|
||
| Instantiate [Editor](https://maxgraph.github.io/maxGraph/api-docs/classes/Editor.html) in order to create an editor. | ||
| This is the central class in the editor package. Everything else in this package is auxiliary. | ||
|
|
||
| To create a new editor instance and configure it using a config file, you can pass the name of the config file to the | ||
| [Editor constructor](https://maxgraph.github.io/maxGraph/api-docs/classes/Editor.html). | ||
|
|
||
|  | ||
|
|
||
| To create a new editor instance and configure it, the following code is used: | ||
|
|
||
| ```javascript | ||
| import { load } from '@maxgraph/core'; | ||
| const config = load('editors/config/keyhandler-commons.xml').getDocumentElement(); | ||
| const editor = new Editor(config); | ||
| ``` | ||
|
|
||
| The configuration file is an XML file that is passed to [Codec](https://maxgraph.github.io/maxGraph/api-docs/classes/Codec.html), | ||
| which in turn uses [EditorCodec](https://maxgraph.github.io/maxGraph/api-docs/classes/EditorCodec.html) and others to read the XML into the editor object hierarchy. | ||
|
|
||
| This is normally done at startup time to configure the editor, graph, model, toolbar, popupmenus, etc. using the [I/O subsystem](./editor-input-output.md). | ||
|
|
||
|
|
||
| <a id="CSS"></a> | ||
| ## CSS | ||
|
|
||
| The CSS stylesheet contains the style definitions for various elements of the user interface, such as the rubberband selection, | ||
| the in-place editor or the popup menu. | ||
|
|
||
| Additional stylesheets may either be added via a stylesheet tag of the UI section in the editor configuration, e.g.: | ||
|
|
||
|
|
||
| ```xml | ||
| <Editor> | ||
| <ui> | ||
| <stylesheet name="examples/editors/css/process.css"/> | ||
| </ui> | ||
| </Editor> | ||
| ``` | ||
|
|
||
|
|
||
| <a id="Templates"></a> | ||
| ## Templates | ||
|
|
||
| To add new cell types, create a template in the templates array section of the model in the config file (Editor/Graph/GraphDataModel/Array[as=templates]) as follows: | ||
|
|
||
| ```xml | ||
| <add as="symbol"> | ||
| <Symbol label="Symbol" customAttribute="whatever"> | ||
| <Cell vertex="1" connectable="true"> | ||
| <Geometry as="geometry" width="32" height="32"/> | ||
| <Object fillColor="green" image="images/event.png" as="style"> | ||
| <Array as="baseStyleNames"> | ||
| <add value="symbol" /> | ||
| </Array> | ||
| </Object> | ||
| </Cell> | ||
| <CustomChild customAttribute="whatever"/> | ||
| </Symbol> | ||
| </add> | ||
| ``` | ||
|
|
||
| The `as`-attribute of the `add`-element contains the name under which the template will be accessible for later use. | ||
| The `Symbol`-child element is a custom (ie workflow) element, and can have any name and any number of child elements and custom attributes. | ||
|
|
||
| The label attribute is a special one that is used for the textual representation of the cell in the graph. | ||
| The `Cell` element is another special child node which contains the graphical information for the cell, namely, the cell-type, -style, -size and -position. | ||
|
|
||
| See `Graph.convertValueToString` if you would like to use another attribute or a combination of attributes for the textual representation, | ||
| and `Cell.valueChanged` to handle in-place editing by storing the new text value in the respective attribute(s). | ||
|
|
||
|
|
||
| <a id="Toolbar"></a> | ||
| ## Toolbar | ||
|
|
||
|
|
||
| To use the template in the graph, a toolbar item must be added which refers to the template in the `DefaultToolbar` section | ||
| of the config file (Editor/DefaultToolbar[as=toolbar]) as follows: | ||
|
|
||
| ```xml | ||
| <add as="symbolTool" template="symbol" | ||
| style="symbol;image=wf/images/bpmn/special_event.png" | ||
| icon="wf/images/bpmn/small_event.gif"/> | ||
| ``` | ||
|
|
||
| The `as` attribute specifies the tooltip to be displayed for the icon in the toolbar, the `template`-attribute refers to the name under which the template was previously added. | ||
| The `style`- attribute is optional, and may be used to override the style defined in the template definition. | ||
| Finally, the icon specifies the icon to be used for the toolbar item. | ||
|
|
||
| Note that the `as` attribute is assumed to be the key for a language resource, in this case `symbolTool`. | ||
| If the resource is not defined in [Translations resources](https://maxgraph.github.io/maxGraph/api-docs/classes/Translations.html#resources), then the attribute value is used as the label. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
You can’t perform that action at this time.

Uh oh!
There was an error while loading. Please reload this page.