|
2 | 2 |
|
3 | 3 | This is a step-by-step description of how to add a yFiles graph component to a basic React application.
|
4 | 4 |
|
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. |
6 | 8 |
|
7 | 9 | ## Running the CLI
|
8 | 10 |
|
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. |
10 | 13 |
|
11 | 14 | ## Add yFiles as a dependency
|
12 | 15 |
|
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: |
14 | 17 |
|
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: |
16 | 19 |
|
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 | + ``` |
20 | 26 |
|
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`. |
22 | 28 |
|
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) |
30 | 31 |
|
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. |
34 | 35 |
|
35 | 36 | ## Integrate a basic yFiles graph component
|
36 | 37 |
|
37 | 38 | With the yFiles dependency, you can easily create a new React component that contains a yFiles GraphComponent.
|
38 | 39 |
|
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. |
40 | 42 |
|
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. |
42 | 45 |
|
43 | 46 | See the contents of `/src/ReactGraphComponent.js` in this repository for the full implementation.
|
44 | 47 |
|
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. |
48 | 49 |
|
49 | 50 | 2. Afterwards, just add the new React component to the `App.js`.
|
50 | 51 |
|
51 | 52 | And that's it. Run `npm run start` to serve the application at [http://localhost:3000/](http://localhost:3000/) with a basic yFiles component.
|
52 | 53 |
|
53 | 54 | ## Development Mode
|
54 | 55 |
|
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). |
59 | 60 |
|
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. |
0 commit comments