This is a step-by-step description of how to add a yFiles graph component to a basic Vue application.
TL;DR Add yfiles as a dependency in the package.json,
include your license,
and start importing yFiles classes in your project.
At first, create a basic create-vue app by running > npm init vue@latest, e.g., with
the following options:
Project name:yfiles-vue-integration-basicAdd TypeScript?YesAdd JSX Support?NoAdd Vue Router for Single Page Application development?NoAdd Pinia for state management?NoAdd Vitest for Unit testing?NoAdd an End-to-End Testing Solution?NoAdd ESLint for code quality?YesAdd Prettier for code formatting?No
Adding yFiles as a dependency is almost as easy as installing an external library from the npm registry:
-
Add yFiles for HTML as npm dependency to the created project, for example, like this:
"dependencies": { ... "@yfiles/yfiles": "../yFiles-for-HTML-Complete-3.0.0.5-Evaluation/lib-dev/yfiles-30.0.5+eval-dev.tgz" }, -
Install the newly added dependency with
npm install. -
Include your yFiles license by copying the
license.jsonfile into your project. For more options, see the developer's guide
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.
With the yFiles dependency, you can easily create a new Vue component with a yFiles graph component.
-
Create a new
GraphComponent.vuefile in/src/components/which instantiates a new yFiles graph component and optionally add an input mode for basic editing and a sample graph.See the contents of
/src/components/GraphComponent.vuein this repository for the implementation.Make sure to configure your license data as described above. This project assumes that there is a yFiles evaluation package with a license file next to the project's root. Otherwise, you need to change the setting of the license data in
GraphComponent.vue. -
Add the new Vue component to the
App.vuethat was created by the Vue CLI.
And that's it. Run npm run dev to serve the application with a basic yFiles component.
This project uses the yFiles development library from the yFiles package. The development library adds additional type runtime checks to yFiles related method calls and yields readable exception messages to identify problems in JavaScript code more easily. For more details, see the Development Mode section.
Please note that these additional checks slightly affect the performance of the application, therefore it should only be used during development. See also Preparing the Development Mode Library for Production in Webpack to learn how to switch between development and production mode.