documentationfor yFiles for HTML 2.5

Migrating from UMD to ES Modules

The /tools/umd-to-es-modules/ folder in the yFiles for HTML package contains a tool that does most of the migration for you. See the corresponding section for more information.

If you would like to do the migration manually, here is the outline of what you need to do:

Remove the Old Loading Mechanism

How to do that depends on the old mechanism:

UMD
Remove all require(['yfiles/…​'], …​) and define('yfiles/…​', …​) calls.
CommonJS
Remove all require('yfiles/…​') calls.
Script Loading (i.e. globals)
Remove all <script> tags that load yFiles modules.

Replace the Fully Qualified Names of yFiles Classes With Their ES Module Name

Usually, this means simply removing the namespace part like this:

// before
const gc = new yfiles.view.GraphComponent()
// after
const gc = new GraphComponent()

There are a couple of exceptions to that rule though: Classes that had identical names but were in different namespaces were renamed to avoid name clashes. These classes are:

UMD Name ES Module Name
yfiles.algorithms.BfsBfsAlgorithm
yfiles.algorithms.BipartitionsBipartitionAlgorithm
yfiles.algorithms.CentralityCentralityAlgorithm
yfiles.algorithms.CyclesCycleAlgorithm
yfiles.algorithms.DataProviderAdapterDataProviderBase
yfiles.algorithms.DfsDfsAlgorithm
yfiles.algorithms.GroupsGroupAlgorithm
yfiles.algorithms.IndependentSetsIndependentSetAlgorithm
yfiles.algorithms.InsetsYInsets
yfiles.algorithms.NetworkFlowsNetworkFlowAlgorithm
yfiles.algorithms.NodeYNode
yfiles.algorithms.NodeListYNodeList
yfiles.algorithms.NodeOrdersNodeOrderAlgorithm
yfiles.algorithms.PathsPathAlgorithm
yfiles.algorithms.RankAssignmentsRankAssignmentAlgorithm
yfiles.algorithms.ShortestPathsShortestPathAlgorithm
yfiles.algorithms.SortingSortingAlgorithm
yfiles.algorithms.SpanningTreesSpanningTreeAlgorithm
yfiles.algorithms.TransitivityTransitivityAlgorithm
yfiles.algorithms.TreesTreeAlgorithm
yfiles.algorithms.TriangulatorTriangulationAlgorithm
yfiles.circular.LayoutStyleCircularLayoutStyle
yfiles.collections.MapHashMap
yfiles.hierarchic.BusDescriptorHierarchicLayoutBusDescriptor
yfiles.hierarchic.EdgeLayoutDescriptorHierarchicLayoutEdgeLayoutDescriptor
yfiles.hierarchic.EdgeRoutingStyleHierarchicLayoutEdgeRoutingStyle
yfiles.hierarchic.INodePlacerIHierarchicLayoutNodePlacer
yfiles.hierarchic.LayeringStrategyHierarchicLayoutLayeringStrategy
yfiles.hierarchic.NodeLayoutDescriptorHierarchicLayoutNodeLayoutDescriptor
yfiles.hierarchic.PortAssignmentModeHierarchicLayoutPortAssignmentMode
yfiles.hierarchic.RoutingStyleHierarchicLayoutRoutingStyle
yfiles.lang.BooleanYBoolean
yfiles.lang.NumberYNumber
yfiles.lang.ObjectYObject
yfiles.lang.StringYString
yfiles.layout.DataProviderAdapterMapperDataProviderAdapter
yfiles.layout.GroupingSupportLayoutGroupingSupport
yfiles.layout.IGroupBoundsCalculatorILayoutGroupBoundsCalculator
yfiles.layout.TabularNodeLayoutDescriptorTabularLayoutNodeLayoutDescriptor
yfiles.organic.ScopeOrganicLayoutScope
yfiles.orthogonal.EdgeLayoutDescriptorOrthogonalLayoutEdgeLayoutDescriptor
yfiles.orthogonal.LayoutStyleOrthogonalLayoutStyle
yfiles.partial.EdgeRoutingStrategyPartialLayoutEdgeRoutingStrategy
yfiles.partial.LayoutOrientationPartialLayoutOrientation
yfiles.radial.EdgeRoutingStrategyRadialLayoutEdgeRoutingStrategy
yfiles.radial.LayeringStrategyRadialLayoutLayeringStrategy
yfiles.router.BusDescriptorBusRouterBusDescriptor
yfiles.router.EdgeLayoutDescriptorEdgeRouterEdgeLayoutDescriptor
yfiles.router.PathEdgeRouterPath
yfiles.router.ScopeEdgeRouterScope
yfiles.seriesparallel.DefaultPortAssignmentDefaultSeriesParallelLayoutPortAssignment
yfiles.seriesparallel.EdgeLayoutDescriptorSeriesParallelLayoutEdgeLayoutDescriptor
yfiles.seriesparallel.IPortAssignmentISeriesParallelLayoutPortAssignment
yfiles.seriesparallel.PortAssignmentModeSeriesParallelLayoutPortAssignmentMode
yfiles.seriesparallel.RoutingStyleSeriesParallelLayoutRoutingStyle
yfiles.tree.DefaultPortAssignmentDefaultTreeLayoutPortAssignment
yfiles.tree.EdgeRoutingStyleClassicTreeLayoutEdgeRoutingStyle
yfiles.tree.INodePlacerITreeLayoutNodePlacer
yfiles.tree.IPortAssignmentITreeLayoutPortAssignment
yfiles.tree.PortAssignmentModeTreeLayoutPortAssignmentMode
yfiles.tree.RoutingStyleTreeLayoutEdgeRoutingStyle

Add Import Statements

The yFiles types that are used in your code have to be imported now. This is done using import statements:

import { GraphComponent, GraphEditorInputMode, ... } from 'yfiles'

Some IDE may offer you an option to add all missing imports, which makes things much easier.

If you are not using webpack or a similar build tool that can resolve symbolic import paths, you will have to specify the actual path to the yFiles library, as this is the only syntax that browsers support natively:

import { GraphComponent, GraphEditorInputMode, ... } from '../lib/yfiles.js'

Add type="module" to Script Tags

Since we are using import statements now, the script has to be loaded in module mode:

<script src="./app.js" type="module"></script>