This documentation provides instructions for migrating from mxGraph to maxGraph.
It includes information about application setup changes, code changes, styles, event handling and other relevant information.
Here's a breakdown of the proposed changes:
Note:
⚠️ ⚠️ ⚠️ This page is under construction.⚠️ ⚠️ ⚠️
Comments are welcome by creating an issue or starting a discussion!.
The maxGraph APIs are not fully compatible with the mxGraph APIs, but the maxGraph APIs are close to the former mxGraph APIs.
The concepts are the same, so experienced mxGraph users should be able to switch from mxGraph to maxGraph without problems.
The main changes are the removal of support for Internet Explorer (including VML support) and Legacy Edge.
To migrate your application setup from mxGraph to maxGraph, follow these steps:
- Remove the
mxgraphdependency from your project:
npm uninstall mxgraph- Install the
maxgraph@coredependency:
npm install maxgraph@coreℹ️ The maxgraph@core package contains the core functionality of maxGraph.
In your application setup code, replace the mxGraph initialization code that uses the factory function with direct access to maxGraph objects.
For example, if you had code like this in mxGraph:
import factory from 'mxgraph';
const mxgraph = factory({});
const graph = mxgraph.mxGraph(container);
const point = new mxgraph.mxPoint(10, 50);
// ... more initialization codeReplace it with the corresponding code in maxGraph:
import { Graph } from 'maxgraph';
const graph = new Graph(container);
const point = new Point(10, 50);
// ... more initialization codeIf you used the @typed-mxgraph/typed-mxgraph dependency in your project, remove it from your package.json file:
npm uninstall @typed-mxgraph/typed-mxgraphRemove any typeroots settings related to typed-mxgraph from your tsconfig.json file.
For example, if you have a configuration like this:
"typeroots": ["./node_modules/@types", "./node_modules/@typed-mxgraph/typed-mxgraph", ...]Remove "./node_modules/@typed-mxgraph/typed-mxgraph".
If you only configured typeroots to add the typed-mxgraph types, remove the line to restore the TypeScript defaults.
Here are some general guidelines to keep in mind when migrating from mxGraph to maxGraph:
- The names of
mxGraphobjects were all prefixed withmx. This prefix has been dropped inmaxGraph. - Most names remain the same, but some utility functions whose implementation is natively available in modern versions of ECMAScript have been removed.
This section outlines specific code changes required when migrating from mxGraph to maxGraph.
Please update your code accordingly.
Note: Much information is available at maxGraph#70.
The strokewidth property has been renamed to strokeWidth in maxGraph.
The shape names in maxGraph have been updated to have a consistent postfix. Please update the shape names in your code as follows:
mxRectangleShapeshould be updated toRectangleShape.mxImageShapeshould be updated toImageShape.mxEllipseshould be updated toEllipseShape.mxRhombusshould be updated toRhombusShape.mxMarkershould be updated toMarkerShape.mxConnectorshould be updated toConnectorShape.mxTextshould be updated toTextShape.
Additionally, some shape properties have been renamed:
- The
strokewidthproperty should now be replaced bystrokeWidth.
Several functions in mxUtils have been moved to their own namespaces in maxGraph. Some remain in utils.
extractTextWithWhitespace(): : Update your code to usedomUtils.extractTextWithWhitespace()instead ofmxUtils.extractTextWithWhitespace().
trim(): Update your code to usestringUtils.trim()instead ofmxUtils.trim().
convertPoint(): Update your code to usestyleUtils.convertPoint()instead ofmxUtils.convertPoint().
getXml(): Update your code to usexmlUtils.getXml()instead ofmxUtils.getXml().createXmlDocument(): Update your code to usexmlUtils.createXmlDocument()instead ofmxUtils.createXmlDocument().
The mxAbstractCanvas2D class has been renamed to AbstractCanvas2D in maxGraph, and there is a parameter type change in one of its methods.
The arcTo() method in AbstractCanvas2D has updated parameter types. The largeArcFlag and sweepFlag parameters, which were previously of type number, are now of type boolean.
Here is the updated signature:
Before
arcTo:(rx: number, ry: number, angle: number, largeArcFlag: number, sweepFlag: number, x: number, y: number) => voidNow
Some number parameters that took the 0 or 1 values have been transformed into boolean parameters.
arcTo:(rx: number, ry: number, angle: number, largeArcFlag: boolean, sweepFlag: boolean, x: number, y: number) => voidThe mxSvgCanvas2D class has been renamed to SvgCanvas2D in maxGraph.
The constructor parameter has been updated. Instead of accepting an Element, it now expects a SvgElement and a boolean value.
Before
// Old constructor
const canvas = new mxgraph.mxSvgCanvas2D(element);Now
// Updated constructor
const canvas = new SvgCanvas2D(svgElement, oneBoolean);change types ???????
The value parameter, which was previously of type string, is now of type number.
Before
format:(value: string) => numberNow
format:(value: number) => numberThe mxGraph class has been renamed to Graph in maxGraph.
There have also been some changes related to properties and methods.
The panningHandler property has been removed and replaced by a plugin. Instead of accessing panningHandler directly, you can use the getPlugin() method to get the PanningHandler plugin instance. Here's an example:
Before
// Old way to access panningHandler
const panningHandler = graph.panningHandler;Now
// Updated way using getPlugin()
const panningHandler = this.graph.getPlugin('PanningHandler') as PanningHandler;Instead of calling getModel() that returned an instance of mxGraphModel, call getDataModel which returns an instance of GraphDataModel.
Here's an example:
Before
// Old way of accessing the model
const model = graph.getModel();Now
// Updated way to access the model
const model = graph.getDataModel();The insertVertex() and insertEdge() methods in maxGraph now also accept one object as parameter instead of multiple parameters. Instead of passing individual parameters, you can pass an object containing all the required properties.
The former methods having several parameters still exist but the new signature should be used instead.
Here's an example:
Before
// Old way of using insertVertex()
graph.insertVertex(parent, id, value, x, y, width, height, style);
// Old way of using insertEdge()
graph.insertEdge(parent, id, value, source, target, style);Now
// New way to use an object parameter for insertVertex()
graph.insertVertex({ parent, id, value, x, y, width, height, style });
// New way to use an object parameter for insertEdge()
graph.insertEdge({ parent, id, value, source, target, style });renamed properties: TODO which
Functions that existed in mxGraph and mxGraphModel have been removed. They provided a way to extend/override the default behavior of mxGraphModel or mxCell. Only the functions for mxCell/Cell remain. See maxGraph#24
Some functions previously available in mxGraph and mxGraphModel have been removed. These functions allowed for customizing the behavior of mxGraphModel and mxCell. However, now only the functions specific to mxCell/Cell remain.
ℹ️ You can find more information about these changes in the following GitHub pull request: maxGraph#24.
The mxCell class has been renamed to Cell for simplicity.
The style property of Cell has undergone a type change from string to CellStyle.
Several functions from the mxGraphDataModel class have been moved to the Cell class. These functions no longer need the cell parameter:
filterDescendants()getGeometry()isEdge()getParent()
Codec renaming and output: maxGraph#70
mxDictionary -> Dictionary<K, V>
The event handling mechanism in maxGraph has been updated. Use the following guidelines to update your event handling code:
mxEventhas been replaced byeventUtilsandInternalEventfor most event-related operations.mxMouseEventhas been replaced byInternalMouseEvent.
- Use the
eventUtils.isMultiTouchEvent()method, to detect touch events, instead ofmxEvent.isMultiTouchEvent(). - Use the
eventUtils.isLeftMouseButton()method, to detect mouse events, instead ofmxEvent.isLeftMouseButton().
- Use the
eventUtils.PAN_STARTproperty instead ofmxEvent.PAN_START. - Use the
eventUtils.PAN_ENDproperty instead ofmxEvent.PAN_END. - Use the
eventUtils.addMouseWheelListener()method instead ofmxEvent.addMouseWheelListener(). - Use the
eventUtils.consume()method instead ofmxEvent.consume().
mxGraph
- Default styles defined with
mxStyleSheet. - Style of a Cell: a string containing all properties and values, using a specific syntax and delimiter.
- Style of a State Cell: a
StyleMapinstance (See StyleMap as atyped-mxgraphtype).
maxGraph
- Default styles defined via
StyleSheet. - Style of a Cell: a dedicated
CellStyleobject that reuses the same properties as the string form used by mxGraph (see below for changes). - Style of a State Cell: a
CellStateStyleinstance.
In mxGraph, the properties are defined as string. The property keys are defined in mxConstants and are prefixed by STYLE_ like mxConstants.STYLE_FILLCOLOR.
In maxGraph, they are object properties. mxConstants.STYLE_* have been replaced by the object properties (see PR #31).
Property names and values are generally the same as in mxGraph. The ones that change are listed below.
autosizetoautoSize(from maxgraph@0.2.0)
Property type changed from number (0 or 1) to boolean (if not specified, from maxgraph@0.1.0):
anchorPointDirectionabsoluteArcSize(as of maxgraph@0.2.0)autosizebackgroundOutline(as of maxgraph@0.2.0)bendablecloneablecurveddasheddeletableeditableendFillentryPerimeterexitPerimeterfixDashflipHflipVfoldableglasshorizontalimageAspectmovablenoEdgeStylenoLabelorthogonalorthogonalLooppointerEventsresizableresizeHeightresizeWidthrotatableroundedshadowstartFillswimlaneLine
TODO: what is a StyleSheet? link to JSDoc/code
The migration consists of converting StyleMap objects to CellStyle objects.
If you have been using string or named properties, you can keep that syntax. You just need to rename the property or update its value as described in (TODO anchor to properties change paragraph)
style['propertyName1'] = value1
style.propertyName2 = value2If you used mxConstants, remove it and use named properties instead.
// mxGraphStyle is a StyleMap
mxGraphStyle[mxConstants.STYLE_STARTSIZE] = 8
// maxGraph style is a CellStyle
style['startSize'] = 8;
// or
style.startSize = 8;- TODO: what is a style? link to JSDoc/code
For a named style, the the stylename must be the first element of the cell style: (code) stylename;image=http://www.example.com/image.gif (end) A cell style can have any number of key=value pairs added, divided by a semicolon as follows: (code) [stylename;|key=value;] (end)
Styles are a collection of key, value pairs and a stylesheet is a collection of named styles. The names are referenced by the cellstyle, which is stored in <mxCell.style> with the following format: [stylename;|key=value;]. The string is resolved to a collection of key, value pairs, where the keys are overridden with the values in the string.
See also
- https://jgraph.github.io/mxgraph/docs/tutorial.html#3.3
- https://jgraph.github.io/mxgraph/docs/manual.html#3.1.3.1
In maxGraph, the style is no more defined as a string but as a CellStyle object.
Most of the time, the name of CellStyle properties is the same as the style keys in the mxGraph style.
Migration example
// Before
graph.insertVertex(..., 'style1;style2;shape=cylinder;strokeWidth=2;fillColor:#ffffff');// Now using the insertVertex method taking a single parameter
graph.insertVertex({
...
style: {
baseStyleNames: ['style1', 'style2']
shape: 'cylinder',
strokeWidth: 2,
fillColor: '#ffffff'
}
});Special migration case
In mxGraph, to not merge properties of the default style, the style string must start with a ; (semicolon) as in ;style1;style2;prop1=value1;......
This is documented in the mxStylesheet documentation.
To override the default style for a cell, add a leading semicolon to the style definition, e.g. ;shadow=1
This is currently not supported in maxGraph: maxGraph#154 "Add a way to not use default style properties when calculating cell styles".
By following these guidelines and updating your codebase accordingly, you should be able to migrate your application from mxGraph to maxGraph.
Remember to test your application thoroughly after the migration to ensure that its functionality is preserved.
If you encounter any problems during the migration process, please refer to the maxGraph documentation or ask the maxGraph community for help.