This is a step-by-step description of how to add a yFiles graph component to a basic Angular application.
TL;DR Add yfiles
as a dependency in the package.json
,
include your license,
and start importing yFiles classes in your project.
Run @angular/cli with > ng new yfiles-angular-integration-basic
and select the following options:
? Would you like to add Angular routing?
No? Which stylesheet format whould you like to use?
CSS
This creates a basic Angular project.
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-Evaluation/lib-dev/yfiles-30.0.0+eval-dev.tgz" },
-
Install the newly added dependency with
npm install
. -
Include your yFiles license by copying the
license.json
file 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 Angular component that contains a yFiles GraphComponent.
-
Run
ng generate component graph-component
to scaffold a new Angular component. -
Then add a container
div
in thegraph-component.component.html
that hosts the yFiles GraphComponent and specify a size ingraph-component.component.css
for it. -
In
graph-component.component.ts
, instantiate a new GraphComponent in the containerdiv
with editing capabilities and a basic sample graph. See the contents of/src/app/graph-component/graph-component.component.ts
in this repository for the full implementation.Make sure to configure your license data as described above (see
graph-component.component.ts
, too). -
Add the new component to the
/src/app/app.component.html
that was created by the Angular CLI.
And that's it. Run npm run start
to serve the application at http://localhost:4200/ with a basic yFiles component.