Skip to content

Commit a05d717

Browse files
committed
Update for yFiles for HTML 2.5
1 parent 0bab7a3 commit a05d717

File tree

9 files changed

+142
-69
lines changed

9 files changed

+142
-69
lines changed

.env

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ This sample application serves as a basic scaffold of how to integrate [yFiles f
88

99
## Version Information
1010

11-
- create-react-app v4.0.3
12-
- yFiles for HTML 2.4
11+
- create-react-app v5.0.1
12+
- yFiles for HTML 2.5
1313

1414
## Getting Started
1515

@@ -43,7 +43,7 @@ This basic yFiles integration can be used as a starting point to test the capabi
4343

4444
You can browse through the demos and look for features that you find interesting for your use case and integrate it in this basic component to build a more sophisticated application.
4545

46-
There is also a slightly bigger [React integration demo](https://live.yworks.com/demos/toolkit/react/index.html) available in the package and on [GitHub](https://github.com/yWorks/yfiles-for-html-demos/tree/master/demos/toolkit/react). This is also available with [TypeScript](https://live.yworks.com/demos/toolkit/react-typescript/index.html) (see [GitHub](https://github.com/yWorks/yfiles-for-html-demos/tree/master/demos/toolkit/react-typescript)).
46+
The yFiles package also contains a more extensive [React integration demo](https://live.yworks.com/demos/toolkit/react/index.html) ([GitHub](https://github.com/yWorks/yfiles-for-html-demos/tree/master/demos/toolkit/react)). This is also available with [TypeScript](https://live.yworks.com/demos/toolkit/react-typescript/index.html) (see [GitHub](https://github.com/yWorks/yfiles-for-html-demos/tree/master/demos/toolkit/react-typescript)).
4747

4848
Furthermore, there is an extensive [Developer's Guide](https://docs.yworks.com/yfileshtml/#/dguide/introduction#top) that covers anything from graph creation and styling to automatic layouts and advanced customizations.
4949

integration-howto.md

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,63 @@
22

33
This is a step-by-step description of how to add a yFiles graph component to a basic React application.
44

5-
TL;DR Add yFiles as a dependency in the `package.json` and start importing yFiles classes in your project.
5+
TL;DR Add `yfiles` as a dependency in the `package.json`,
6+
[include your license](https://docs.yworks.com/yfileshtml/#/dguide/licensing#_general_concept),
7+
and start importing yFiles classes in your project.
68

79
## Running the CLI
810

9-
Run the create-react-app CLI with `> npx create-react-app yfiles-react-integration-basic` which scaffolds a basic React application.
11+
Run the create-react-app CLI with `> npx create-react-app yfiles-react-integration-basic` which
12+
scaffolds a basic React application.
1013

1114
## Add yFiles as a dependency
1215

13-
Adding yFiles as a dependency is as easy as installing an external library from the npm registry:
16+
Adding yFiles as a dependency is almost as easy as installing an external library from the npm registry:
1417

15-
1. Add yFiles for HTML as npm dependency to the created project:
18+
1. Add yFiles for HTML as npm dependency to the created project, for example like this:
1619

17-
- If you have a fresh yFiles for HTML package, you need to prepare the library package first by running `npm install` in the
18-
package folder. This creates the development library and a tarball that can be installed as npm dependency in
19-
other projects. See also [Working with the yFiles npm Module](https://docs.yworks.com/yfileshtml/#/dguide/yfiles_npm_module#yfiles_npm_module).
20+
```
21+
"dependencies": {
22+
...
23+
"yfiles": "../yFiles-for-HTML-Complete-2.5-Evaluation/lib-dev/yfiles-25.0.0+eval-dev.tgz"
24+
},
25+
```
2026

21-
Note: This sample project runs `npm install` as `preinstall` script in the `package.json`.
27+
2. Install the newly added dependency with `npm install`.
2228

23-
- Reference the packed library in the `package.json` of the project:
24-
```
25-
"dependencies": {
26-
...
27-
"yfiles": "../yFiles-for-HTML-Complete-2.4.0.6-Evaluation/lib-dev/es-modules/yfiles-24.0.6-eval-dev.tgz"
28-
},
29-
```
29+
3. Include your yFiles license by copying the `license.json` file into your project. For more options,
30+
see the [developer's guide](https://docs.yworks.com/yfileshtml/#/dguide/licensing#_general_concept)
3031

31-
2. Now install the newly added dependency with `npm install`.
32-
33-
After installing the dependency, you can import classes from `yfiles` in your project. Since yFiles is installed as proper npm dependency, IDEs provide full code-completion and automatic imports out of the box to easily work with the library.
32+
After installing the dependency, you can import classes from `yfiles` in your project. Since yFiles
33+
is installed as proper npm dependency, IDEs provide full code-completion and automatic imports out
34+
of the box to easily work with the library.
3435

3536
## Integrate a basic yFiles graph component
3637

3738
With the yFiles dependency, you can easily create a new React component that contains a yFiles GraphComponent.
3839

39-
1. Create a new `ReactGraphComponent.js` file in `/src/` which instantiates a new yFiles GraphComponent with editing capabilities and a basic sample graph.
40+
1. Create a new `ReactGraphComponent.js` file in `/src/` which instantiates a new yFiles GraphComponent
41+
with editing capabilities and a basic sample graph.
4042

41-
Note how the yFiles GraphComponent is added to the DOM by providing a reference to an empty `div` element in which it is supposed to be created.
43+
Note how the yFiles GraphComponent is added to the DOM by providing a reference to an empty `div`
44+
element in which it is supposed to be created.
4245

4346
See the contents of `/src/ReactGraphComponent.js` in this repository for the full implementation.
4447

45-
There are two things to look out for:
46-
47-
- Make sure to configure your `license.json` for the library.
48+
Make sure to configure your license data as described above.
4849

4950
2. Afterwards, just add the new React component to the `App.js`.
5051

5152
And that's it. Run `npm run start` to serve the application at [http://localhost:3000/](http://localhost:3000/) with a basic yFiles component.
5253

5354
## Development Mode
5455

55-
This project uses the yFiles development library from the yFiles package. The development library adds additional
56-
type runtime checks to yFiles related method calls and
57-
yields readable exception messages to identify problems in JavaScript code more easily.
58-
For more details see [Development Mode](http://docs.yworks.com/yfileshtml/#/dguide/yfiles_development_mode).
56+
This project uses the yFiles development library from the yFiles package. The development library
57+
adds additional type runtime checks to yFiles related method calls and yields readable exception
58+
messages to identify problems in JavaScript code more easily.
59+
For more details, see the [Development Mode section](http://docs.yworks.com/yfileshtml/#/dguide/yfiles_development_mode).
5960

60-
Please note that these additional checks degrade the performance of the application slightly, therefore it should only be used during development. See also [Preparing the Development Mode Library for Production](https://docs.yworks.com/yfileshtml/#/dguide/deployment#dev-deployment) in Webpack to learn how to switch between development and production mode.
61+
Please note that these additional checks slightly affect the performance of the application,
62+
therefore it should only be used during development.
63+
See also [Preparing the Development Mode Library for Production](https://docs.yworks.com/yfileshtml/#/dguide/deployment#dev-deployment)
64+
in Webpack to learn how to switch between development and production mode.

package.json

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,28 @@
44
"author": "yWorks GmbH <[email protected]>",
55
"private": true,
66
"dependencies": {
7-
"@testing-library/jest-dom": "^5.14.1",
8-
"@testing-library/react": "^12.0.0",
9-
"@testing-library/user-event": "^13.1.9",
10-
"react": "^17.0.2",
11-
"react-dom": "^17.0.2",
12-
"react-scripts": "4.0.3",
13-
"web-vitals": "^2.0.1",
14-
"yfiles": "../yFiles-for-HTML-Complete-2.4.0.6-Evaluation/lib-dev/es-modules/yfiles-24.0.6-eval-dev.tgz"
7+
"@testing-library/jest-dom": "^5.16.4",
8+
"@testing-library/react": "^13.3.0",
9+
"@testing-library/user-event": "^14.3.0",
10+
"react": "^18.2.0",
11+
"react-dom": "^18.2.0",
12+
"react-scripts": "5.0.1",
13+
"web-vitals": "^2.1.4",
14+
"yfiles": "../yFiles-for-HTML-Complete-2.5-Evaluation/lib-dev/yfiles-25.0.0+eval-dev.tgz"
1515
},
1616
"scripts": {
17-
"preinstall": "cd ../yFiles-for-HTML-Complete-2.4.0.6-Evaluation && npm run prepare-package",
18-
"postinstall": " node -e \"require('fs').copyFileSync('../yFiles-for-HTML-Complete-2.4.0.6-Evaluation/lib/license.json','./src/license.json')\"",
19-
"start": "react-scripts --expose-gc --max-old-space-size=8192 start",
20-
"build": "react-scripts --expose-gc --max-old-space-size=8192 build",
21-
"eject": "react-scripts eject"
17+
"start": "react-scripts start",
18+
"build": "react-scripts build",
19+
"test": "react-scripts test",
20+
"eject": "react-scripts eject",
21+
"postinstall": "npm run copy-eval-license",
22+
"copy-eval-license": "node -e \"require('fs').copyFileSync('../yFiles-for-HTML-Complete-2.5-Evaluation/lib/license.json','./src/license.json')\""
2223
},
2324
"eslintConfig": {
24-
"extends": "react-app"
25+
"extends": [
26+
"react-app",
27+
"react-app/jest"
28+
]
2529
},
2630
"browserslist": {
2731
"production": [

public/index.html

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1" />
66
<meta name="theme-color" content="#000000" />
7-
<meta
8-
name="description"
9-
content="Web site created using create-react-app"
10-
/>
7+
<meta name="description" content="Web site created using create-react-app" />
8+
<!--
9+
manifest.json provides metadata used when your web app is installed on a
10+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
11+
-->
12+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
13+
<!--
14+
Notice the use of %PUBLIC_URL% in the tags above.
15+
It will be replaced with the URL of the `public` folder during the build.
16+
Only files inside the `public` folder can be referenced from the HTML.
17+
18+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
19+
work correctly both with client-side routing and a non-root public URL.
20+
Learn how to configure a non-root public URL by running `npm run build`.
21+
-->
1122
<title>React App</title>
1223
</head>
1324
<body>

public/manifest.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
},
10+
{
11+
"src": "logo192.png",
12+
"type": "image/png",
13+
"sizes": "192x192"
14+
},
15+
{
16+
"src": "logo512.png",
17+
"type": "image/png",
18+
"sizes": "512x512"
19+
}
20+
],
21+
"start_url": ".",
22+
"display": "standalone",
23+
"theme_color": "#000000",
24+
"background_color": "#ffffff"
25+
}

src/ReactGraphComponent.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,31 @@ import licenseData from './license'
55
License.value = licenseData
66

77
export default class ReactGraphComponent extends Component {
8-
constructor(props) {
9-
super(props)
10-
11-
// instantiate a new GraphComponent
12-
this.graphComponent = new GraphComponent()
13-
14-
// configure an input mode for out of the box editing
15-
this.graphComponent.inputMode = new GraphEditorInputMode()
16-
}
17-
188
componentDidMount() {
9+
if (!this.graphComponent) {
10+
// instantiate a new GraphComponent once
11+
this.graphComponent = this.initializeGraphComponent()
12+
}
1913
// append the GraphComponent to the DOM
2014
this.div.appendChild(this.graphComponent.div)
15+
// center the content of the GraphComponent after it was added to the DOM
16+
this.graphComponent.fitGraphBounds()
17+
}
2118

22-
// create some graph elements
23-
this.createSampleGraph(this.graphComponent.graph)
19+
componentWillUnmount() {
20+
// Remove the GraphComponent on unmount.
21+
// Depending on the use case, you may also clear the GraphComponent entirely and create a
22+
// new one on each unmount / mount cycle.
23+
this.div.removeChild(this.graphComponent.div)
24+
}
2425

25-
// center the newly created graph
26-
this.graphComponent.fitGraphBounds()
26+
initializeGraphComponent() {
27+
const graphComponent = new GraphComponent()
28+
// configure an input mode for out of the box editing
29+
graphComponent.inputMode = new GraphEditorInputMode()
30+
// create some graph elements
31+
this.createSampleGraph(graphComponent.graph)
32+
return graphComponent
2733
}
2834

2935
createSampleGraph(graph) {

src/index.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
import React from 'react'
2-
import ReactDOM from 'react-dom'
3-
import './index.css'
4-
import App from './App'
1+
import React from 'react';
2+
import ReactDOM from 'react-dom/client';
3+
import './index.css';
4+
import App from './App';
5+
import reportWebVitals from './reportWebVitals';
56

6-
ReactDOM.render(<App />, document.getElementById('root'))
7+
const root = ReactDOM.createRoot(document.getElementById('root'));
8+
root.render(
9+
<React.StrictMode>
10+
<App />
11+
</React.StrictMode>
12+
);
13+
14+
// If you want to start measuring performance in your app, pass a function
15+
// to log results (for example: reportWebVitals(console.log))
16+
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
17+
reportWebVitals();

src/reportWebVitals.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const reportWebVitals = onPerfEntry => {
2+
if (onPerfEntry && onPerfEntry instanceof Function) {
3+
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4+
getCLS(onPerfEntry);
5+
getFID(onPerfEntry);
6+
getFCP(onPerfEntry);
7+
getLCP(onPerfEntry);
8+
getTTFB(onPerfEntry);
9+
});
10+
}
11+
};
12+
13+
export default reportWebVitals;

0 commit comments

Comments
 (0)