maxGraph/README.md

229 lines
8.4 KiB
Markdown
Raw Normal View History

# maxGraph
2021-04-15 04:09:30 +00:00
[![npm version](https://img.shields.io/npm/v/@maxgraph/core?color=blue&style=flat)](https://www.npmjs.com/package/@maxgraph/core)
[![build status](https://github.com/maxGraph/maxGraph/workflows/Build/badge.svg)](https://github.com/maxGraph/maxGraph/actions/workflows/build.yml)
2021-04-15 04:09:30 +00:00
<!-- copied into packages/core/README.md and packages/website/docs/intro.md -->
`maxGraph` is a TypeScript library which can display and allow interaction with vector diagrams. At a high level, it provides:
- **Nodes**, also known as **vertices** which are typically represented by shapes like rectangles.
- **Edges** which can be lines and arrows which normally point between one node and another.
2021-04-15 04:09:30 +00:00
It provides many of the diagramming features which would be expected by a piece of presentation software like Microsoft® PowerPoint™
or LibreOffice® Impress such as being able to resize, move or rotate nodes, but has a stronger focus on automatic layout
algorithms and applications of [Graph Theory](https://en.wikipedia.org/wiki/Graph_theory). It is suited towards software
which requires finer-grained customization of functionality than off-the-shelf packages.
<!-- END OF 'copied into packages/core/README.md and packages/website/docs/intro.md' -->
2021-04-15 04:09:30 +00:00
The `maxGraph` library uses no third-party software, it requires no plugins and can be integrated in virtually any framework (it's vanilla JS).
2021-04-15 04:09:30 +00:00
`maxGraph` is the successor of [mxGraph](https://github.com/jgraph/mxgraph) which is now end of life.
At first, it provides the same features as `mxGraph` and adds
- TypeScript support
- maintained npm package
- modern modular, tree shakable, version of `mxGraph` to reduce the whole package size
2021-04-15 04:09:30 +00:00
New features will follow.
2021-04-15 04:09:30 +00:00
## Browser support
2021-04-15 04:09:30 +00:00
Chrome, Edge, Firefox, Safari, Chromium based browsers (Brave, Opera, ....) for mobile and desktop.
2021-04-15 04:09:30 +00:00
## Project status
2021-04-15 04:09:30 +00:00
`maxGraph` is under active development and is in **alpha**. Please try it in your application and [submit an issue](https://github.com/maxGraph/maxGraph/issues)
if you think that something is not working.
2020-11-12 13:45:04 +00:00
You can also test `maxGraph` by running the [Storybook examples](#development) or [build the npm package locally](#build-local-npm-package) to get the latest changes.
2021-04-15 04:09:30 +00:00
## Install
Install the latest version of `maxGraph` from the [npm registry](https://www.npmjs.com/package/@maxgraph/core).
npm
```
npm install @maxgraph/core
```
yarn
```
yarn add @maxgraph/core
```
pnpm
```
pnpm add @maxgraph/core
```
2020-11-12 13:45:04 +00:00
## Getting Started
2020-11-12 13:51:32 +00:00
Assuming your page defines an element with the id `graph-container`, the following will display a rectangle connected to an orange circle.
```typescript
import {type CellStyle, Graph, InternalEvent} from '@maxgraph/core';
2021-04-11 09:04:33 +00:00
const container = <HTMLElement>document.getElementById('graph-container');
// Disables the built-in context menu
InternalEvent.disableContextMenu(container);
chore: improve the configuration to build the npm package (#87) Root and all package.json files - Fix license, version and authors - Remove the non-relevant .npmignore file at the project. It was designed for mxgraph, the whole directory structure changed, and we don't plan to publish the root package `core` package - Generate type definition and javascript files for ESM output - dedicated folder for `esm` and `types` in the `dist` folder to clearly separate concerns - exported in the package.json - Add npm script for `npm pack` configuration - Drop the `postinstall` npm script that built the `core` bundle. It would have been run when the package is installed in dependent projects at dependencies install. And it would have failed as it tries to build the project from TypeScript sources that are not available in the npm package. fix: ConstraintHandler now loads image as everywhere else in the code using `Client.imageBasePath` Using import doesn't work as the image is not available in the npm package. It generated error like this in ViteJS project: Failed to resolve import "../../../images/point.gif" from "../core/dist/esm/view/handler/ConstraintHandler.js". Does the file exist? This gif import had been introduced to make `Anchors.stories.js` retrieve the gif file. Configuring `imageBasePath` as already done in other stories fixes the issue. Don't export EditorCodec and StylesheetCodec as they generate errors. This is a temporary solution to avoid error in dependent project (at least, with ViteJS projects).
2022-07-05 06:08:25 +00:00
const graph = new Graph(container);
graph.setPanning(true); // Use mouse right button for panning
// 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
graph.batchUpdate(() => {
const vertex01 = graph.insertVertex({
parent,
position: [10, 10],
size: [100, 100],
value: 'rectangle',
});
const vertex02 = graph.insertVertex({
parent,
position: [350, 90],
size: [50, 50],
style: {
fillColor: 'orange',
shape: 'ellipse',
verticalAlign: 'top',
verticalLabelPosition: 'bottom',
},
value: 'ellipse',
});
graph.insertEdge({
parent,
source: vertex01,
target: vertex02,
value: 'edge',
style: {
edgeStyle: 'orthogonalEdgeStyle',
rounded: true,
},
});
});
2021-04-11 09:04:33 +00:00
```
2020-11-12 13:45:04 +00:00
chore: improve the configuration to build the npm package (#87) Root and all package.json files - Fix license, version and authors - Remove the non-relevant .npmignore file at the project. It was designed for mxgraph, the whole directory structure changed, and we don't plan to publish the root package `core` package - Generate type definition and javascript files for ESM output - dedicated folder for `esm` and `types` in the `dist` folder to clearly separate concerns - exported in the package.json - Add npm script for `npm pack` configuration - Drop the `postinstall` npm script that built the `core` bundle. It would have been run when the package is installed in dependent projects at dependencies install. And it would have failed as it tries to build the project from TypeScript sources that are not available in the npm package. fix: ConstraintHandler now loads image as everywhere else in the code using `Client.imageBasePath` Using import doesn't work as the image is not available in the npm package. It generated error like this in ViteJS project: Failed to resolve import "../../../images/point.gif" from "../core/dist/esm/view/handler/ConstraintHandler.js". Does the file exist? This gif import had been introduced to make `Anchors.stories.js` retrieve the gif file. Configuring `imageBasePath` as already done in other stories fixes the issue. Don't export EditorCodec and StylesheetCodec as they generate errors. This is a temporary solution to avoid error in dependent project (at least, with ViteJS projects).
2022-07-05 06:08:25 +00:00
You will see something like in the following _maxGraph panning_ demo:
![maxGraph panning demo](docs/images/maxgraph_demo.gif "maxGraph panning demo")
For more details, have a look at the [storybook stories](packages/html/stories).
Notice that some elements produced by `maxGraph` require to use [CSS and images](packages/website/docs/usage/css-and-images.md) provided in the npm package.
## TypeScript support
`maxGraph` is written in TypeScript and provides type definitions so `maxGraph` can be easily integrated into TypeScript applications.
`maxGraph` requires **TypeScript 3.8** or greater.
## Support
For usage question, please open a new [discussion](https://github.com/maxGraph/maxGraph/discussions/categories/q-a) on GitHub. You can also use
[GitHub discussions](https://github.com/maxGraph/maxGraph/discussions) for other topics like `maxGraph` development or to get the latest news.
Until we provide a complete documentation, you can check the mxGraph resources
- mxGraph documentation: [Github pages branch](https://jgraph.github.io/mxgraph/). The key resources are the JavaScript user manual, the JavaScript examples and the JavaScript API specification.
- [mxgraph tag on Stack Overflow](http://stackoverflow.com/questions/tagged/mxgraph). Please ensure your questions adhere to the [SO guidelines](http://stackoverflow.com/help/on-topic), otherwise it is likely to be closed.
2020-11-12 13:45:04 +00:00
## Migrating from mxGraph
2020-11-09 10:24:48 +00:00
`maxGraph` APIs are not fully compatible with `mxGraph` APIs. The concepts are the same, so experienced `mxGraph` users should be able to switch from `mxGraph` to `maxGraph` without issues.
2020-11-13 09:04:55 +00:00
For a complete guide, see the [dedicated migration page](packages/website/docs/usage/migrate-from-mxgraph.md).
refactor(style)!: rename/remove properties and types (#165) Remove the `StyleMap` class. It is not used anymore since the introduction of the `CellStateStyle` interface. Changes in `CellStateStyle` - remove `defaultEdge` and `defaultVertex` that have been introduced by mistake. They have never been used. - rename `autosize` into `autoSize` for naming consistency. All properties use camelCase. - change types from "number" to "boolean" + fix default management in the Shape classes - `backgroundOutline` - `absoluteArcSize` Other `CellStateStyle` changes: remove a property in favor of another property The following properties were introduced by mistake while removing mxConstants.STYLE_* references in 707605cedd1144a98292947b7618c219abe934e2 (2021-05-02). Their counterpart was used in `mxGraph` and is used in all `maxGraph` examples - `backgroundColor` in favor of `labelBackgroundColor`. The `STYLE_LABEL_BACKGROUNDCOLOR` constant was replaced by 'backgroundColor' instead of 'labelBackgroundColor' - `loop` in favor of `loopStyle`. The `STYLE_LOOP` constant was replaced by 'loop' instead of 'loopStyle' Other types that changed - `CellStateStyle`: better type guidance for the `indicatorShape` property - `CanvasState`: order properties alphabetically + add JSDoc on some properties - Rename `ArrowType` into `ArrowValue` for consistency with other types (they all end with the 'Value' post-fix) Documentation update - CHANGELOG.md: mention the breaking changes - Initiate a specific document to help migration from mxGraph: start by adding the changes on style -------------------------------------------------------------------------------- **BREAKING CHANGES**: some `CellStateStyle` properties and types have been removed/renamed.
2023-01-30 10:44:06 +00:00
2013-01-11 13:30:18 +00:00
## History
2013-01-11 12:34:48 +00:00
On 2020-11-09, the development on `mxGraph` stopped and `mxGraph` became effectively end of life.
2013-01-11 12:34:48 +00:00
On 2020-11-12, a fork of the `mxGraph` was created with a call to Contributors.
2013-01-11 12:34:48 +00:00
> 12 Nov 2020.
>
> If you are interested in becoming a maintainer of mxGraph please comment on issue [#1](https://github.com/maxGraph/maxGraph/issues/1)
>
> Initial objectives:
>
> - The first priority is to maintain a working version of mxGraph and its **npm package**
> - The ambitious stretch goal is to refactor the codebase to create a modern modular, tree shakable, version of mxGraph to reduce the whole package size.
>
> -- Colin Claverie
2017-10-18 22:31:13 +00:00
The project was then [renamed on 2021-06-02](https://github.com/maxGraph/maxGraph/discussions/47) into `maxGraph` due to [licensing issue](https://github.com/maxGraph/maxGraph/discussions/23).
Starting from the `mxGraph` 4.2.2 release, we
- moved code to ES9
- removed Internet Explorer specific code
- migrated to TypeScript, based on the work initiated in [typed-mxgraph](https://github.com/typed-mxgraph/typed-mxgraph)
- migrated the examples to [Storybook](https://storybook.js.org/)
## Development
### Clean former mxGraph tags
Ensure you don't have the former `mxGraph` tags locally (see [#92](https://github.com/maxGraph/maxGraph/issues/92) fore more details):
```
git fetch --all --tags --prune
```
### Setting up local development environment
NodeJS requirements:
- use the version declared in [.nvmrc](./.nvmrc). Other versions may work but are not supported.
- this is the version used by GitHub Actions
- nvm users can run `nvm use`. If the Node version is not installed, nvm will state how to install the required version.
In the project root directory, execute
```sh
$ npm install
```
In the `packages/core` folder, execute
```sh
npm pack
```
To watch the core package, execute (in the project root directory)
```sh
$ npm run dev
```
and select `@maxgraph/core`.
To run the html(vanilla-js) version of [Storybook](https://storybook.js.org/), execute (in the project root directory)
```sh
$ npm run dev
```
and select `@maxgraph/html`.
Since both commands are in watch mode, so it's recommended to open two terminals and run them separately. When a file is saved from the core package, the html storybook will be automatically updated.
2017-02-27 16:13:53 +00:00
### <a id="build-local-npm-package"></a> Building the npm package locally
**Reminder**: the released version are available at [npmjs](https://www.npmjs.com/package/@maxgraph/core).
chore: improve the configuration to build the npm package (#87) Root and all package.json files - Fix license, version and authors - Remove the non-relevant .npmignore file at the project. It was designed for mxgraph, the whole directory structure changed, and we don't plan to publish the root package `core` package - Generate type definition and javascript files for ESM output - dedicated folder for `esm` and `types` in the `dist` folder to clearly separate concerns - exported in the package.json - Add npm script for `npm pack` configuration - Drop the `postinstall` npm script that built the `core` bundle. It would have been run when the package is installed in dependent projects at dependencies install. And it would have failed as it tries to build the project from TypeScript sources that are not available in the npm package. fix: ConstraintHandler now loads image as everywhere else in the code using `Client.imageBasePath` Using import doesn't work as the image is not available in the npm package. It generated error like this in ViteJS project: Failed to resolve import "../../../images/point.gif" from "../core/dist/esm/view/handler/ConstraintHandler.js". Does the file exist? This gif import had been introduced to make `Anchors.stories.js` retrieve the gif file. Configuring `imageBasePath` as already done in other stories fixes the issue. Don't export EditorCodec and StylesheetCodec as they generate errors. This is a temporary solution to avoid error in dependent project (at least, with ViteJS projects).
2022-07-05 06:08:25 +00:00
Run
- from the project root: `npm install`
- then, from the `packages/core` folder: `npm pack`
The `packages/core` folder or the generated `packages/core/maxgraph-core-***.tgz` file are now ready for use in your application, using [npm link](https://docs.npmjs.com/cli/v8/commands/npm-link) or `npm install`.
2020-11-13 09:04:46 +00:00
Examples of use can be found in the [maxgraph-integration-examples](https://github.com/maxGraph/maxgraph-integration-examples) repository.
### Release
See the dedicated [release](packages/website/docs/development/release.md) page.