documentationfor yFiles for HTML 2.6

yFiles Library Formats

The yFiles for HTML API is divided into a number of ES modules for seamless integration into modern JavaScript projects. We recommend using this variant for almost all yFiles for HTML projects.

For those few use cases where using ES modules is not an option, the package also contains a UMD version of the library. This variant is only recommended for Node.js applications and for projects where yFiles for HTML will be loaded using an AMD loader or browser globals.

Both library variants come as npm modules that can be easily included in your project. We recommend using yFiles for HTML as a npm module for an optimal development experience.

The yfiles.css file, which is provided with the library, is optional. If it is loaded explicitly, no <style> element is added to the DOM during instantiation of a GraphComponent.For more information see also Default Look and Feel.

ES Modules

The ES module library is suitable for most new yFiles for HTML projects, as it integrates seamlessly with modern JavaScript build tools and IDEs. These modules can be loaded in browsers that support the import statement and used with tools that expect JS Modules as input.

ES Module dependencies gives an overview of the dependencies between these modules. Note that the yfiles/lang and yfiles/core modules are omitted from the diagram since all modules depend on these modules. For brevity and clarity, the diagram also does not show transitive dependencies and omits the 'yfiles/' prefix in modules names.

ES Module dependencies
module dependencies es6

Here is a brief overview of the various JS Modules and their contents:

Modules
Module name Description
yfiles/view-componentContains the basic visualization infrastructure, styles and support classes for collections, iterations etc.
yfiles/view-editorProvides GraphEditorInputMode and related types.
yfiles/view-foldingProvides folding support for IGraph, most notably the FoldingManager implementation and helpers.
yfiles/styles-otherContains styles for the visualization of graph elements.
yfiles/styles-templateContains styles for the visualization of graph elements through template binding.
yfiles/styles-groupContains styles for the visualization of group nodes.
yfiles/view-graphmlProvides GraphML input and output via GraphMLIOHandler and the GraphComponent.
yfiles/view-tableProvides infrastructure for table node support in IGraph, alongside its styles and input mode.
yfiles/view-webglSupports WebGL2 to provide hardware-accelerated graph rendering and interaction.
yfiles/view-layout-bridgeBrings LayoutExecutor and integrated layout execution to GraphComponent, as well as layout morphing.
yfiles/layout-coreProvides core support for layout and a couple of more general layout algorithms.
yfiles/algorithmsProvides the basic graph structure for layout and a couple of core analytic algorithms.
yfiles/layout-treeProvides the tree layouts algorithms.
yfiles/layout-organicProvides the organic and interactive organic algorithms. Also provides the circular and helper types.
yfiles/layout-hierarchicProvides the set of hierarchic layout algorithms, most notably the HierarchicLayout.
yfiles/layout-orthogonalProvides the orthogonal layout algorithm.
yfiles/layout-orthogonal-compactProvides the compact orthogonal algorithm.
yfiles/layout-areaProvides the layout algorithms that clear or fill a specified area.
yfiles/layout-cactusProvides the cactus group layout algorithm.
yfiles/layout-familytreeProvides the family tree layout algorithm.
yfiles/layout-multipageProvides the multi-page layout algorithm and its infrastructure.
yfiles/layout-radialProvides the radial layout algorithm.
yfiles/layout-seriesparallelProvides the series-parallel layout algorithm.
yfiles/router-polylineProvides the polyline edge routing algorithm.
yfiles/router-otherProvides orthogonal and organic edge routing algorithms.
yfiles/router-busProvides an algorithm which routes edges of a graph in an orthogonal bus-style.

Importing the ES Modules of yFiles for HTML

You can load yFiles for HTML by using the JS Module variant of the library and import statements:

Importing ES modules
import { GraphComponent } from '../../node_modules/yfiles/yfiles.js'
const graphComponent = new GraphComponent()

This syntax is supported natively by most modern browsers.

For the best developer experience, you can use symbolic names for the imports instead of the full path:

Importing ES modules with symbolic names
import { GraphComponent } from 'yfiles'
const graphComponent = new GraphComponent()

For this to work, some tool has to resolve these symbolic names to real paths. One such tool is webpack. Additionally, the web server that is included in the yFiles for HTML package is able to resolve references to the yFiles library, which is why most of the demos use the symbolic names in their imports.

Using the symbolic name also provides the advantage that most IDEs offer superior code completion and documentation lookup for this kind of imports.

InvalidOperationError: Missing module

During development, you might encounter an error message like this:

Missing module: This feature requires the 'view-layout-bridge' module of yfiles. To make sure it’s loaded, add the line 'Class.ensure(LayoutExecutor)'.

The solution is to follow the instructions in the message and add the suggested line to your application. In the above example, this would be

Class.ensure(LayoutExecutor)

The cause is that, internally, the yFiles modules don’t use strict imports to get types from the modules they depend on. Instead, they are only loosely coupled. This makes it possible for build tools to remove unused modules with optimizations like tree shaking.

However, it can happen that a build optimization removes a module that is actually needed. In this case, the missing module error is thrown.

The solution recommended in the error message makes sure that an explicit import of a type of the missing module is added to your project, thus requiring the optimization to include that module. In the above example, this would be the LayoutExecutor class from the view-layout-bridge module:

Alternatively, make sure that the named module is included in your build tool’s configuration.

UMD Modules

The yFiles for HTML package contains a version of the library in UMD format. It provides the same "flat" API as the ES module variant. Additionally, the legacy namespaced API is also still available for backwards compatibility:

// new "flat" API
const { GraphComponent } = yfiles
const graphComponent = new GraphComponent()

// legacy namespaced API
const graphComponent = new yfiles.view.GraphComponent()

Modules that make use of the UMD API can be loaded in various environments:

Module dependencies gives an overview of the dependencies between these modules. Note that module yfiles/lang is omitted from the diagram since all modules depend on that module. For brevity and clarity, the diagram also does not show transitive dependencies.

Module dependencies
module dependencies

Here is a brief overview of the various UMD modules and their contents:

Modules
Module name Description
yfiles/completeDepends on all available modules and can thus be used during development to make sure that the complete API is available. It basically bundles the viewer modules together with the layout modules and the bridge module that is used to mediate between the viewer and the layout functionality.
yfiles/viewDepends on all modules that are used for the visualization and interaction, as well as data import and data export.
yfiles/layoutDepends on all available layout and algorithm modules.
yfiles/view-componentContains the basic visualization infrastructure, styles and support classes for collections, iterations etc.
yfiles/view-editorProvides GraphEditorInputMode and related types.
yfiles/view-foldingProvides folding support for IGraph, most notably the FoldingManager implementation and helpers.
yfiles/view-tableProvides infrastructure for table node support in IGraph, alongside its styles and input mode.
yfiles/view-webglSupports WebGL2 to provide hardware-accelerated graph rendering and interaction.
yfiles/view-graphmlProvides GraphML input and output via GraphMLIOHandler and the GraphComponent.
yfiles/view-layout-bridgeBrings LayoutExecutor and integrated layout execution to GraphComponent, as well as layout morphing.
yfiles/algorithmsProvides the basic graph structure for layout and a couple of core analytic and layout algorithms.
yfiles/layout-tree, yfiles/layout-organic, yfiles/layout-hierarchic, yfiles/layout-orthogonal, yfiles/layout-orthogonal-compact, yfiles/layout-area, yfiles/layout-cactus, yfiles/layout-familytree, yfiles/layout-multipage, yfiles/layout-radial, yfiles/layout-seriesparallel, yfiles/router-polyline, yfiles/router-other, yfiles/router-busProvides the corresponding layout algorithm.

Loading the UMD Modules Using an AMD Loader

AMD loading enables asynchronous module loading, and automatic module resolution.

Once your AMD loader is available, you can call the require function which loads the desired yFiles for HTML modules and their dependencies and then executes a provided callback function.

Using an AMD loader
require.config({
  paths: {
    yfiles: './node_modules/yfiles-umd'
  }
})
require(['yfiles/complete'], ({ GraphComponent, License }) => {
  License.value = {
    /* <add your license information here> */
  }

  // this is where the application code can be placed in
  const graphComponent = new GraphComponent()
})

AMD loading enables asynchronous module loading, and automatic module resolution. For example, load RequireJS from a CDN and include it in your document.

Loading the UMD Modules Using CommonJS

CommonJS is the module loading mechanism of Node.js. As yFiles for HTML comes as a npm module, it can be required like any other node module.

Using CommonJS loading
const { GraphComponent } = require('yfiles')

const graphComponent = new GraphComponent()

See the Node.js demo for an example.

Loading the UMD Modules Using Browser Globals

In some environments, the only option to use third-party libraries is to load them as a global variable.

Loading yFiles for HTML as a global variable (index.html)
<body>
  <script src="./node_modules/yfiles-umd/impl/lang.js"></script>
  <script src="./node_modules/yfiles-umd/impl/core-lib.js"></script>
  <script src="./node_modules/yfiles-umd/impl/graph-core.js"></script>
  <script src="app.js"></script>
</body>
Loading yFiles for HTML as a global variable (app.js)
const { GraphComponent } = yfiles

const graphComponent = new GraphComponent()