documentationfor yFiles for HTML 2.6

The GraphMLIOHandler

The central class for reading and writing GraphML is the GraphMLIOHandler. Besides its methods for reading and writing graphs it offers a number of customization hooks.

readFromDocument(graph: IGraph, document: Document): Promise<IGraph>
readFromGraphMLText(graph: IGraph, data: string): Promise<IGraph>
readFromURL(graph: IGraph, url: string): Promise<IGraph>
Parses GraphML from different sources and populates the given graph.
write(graph: IGraph): Promise<string>
Returns a promise with the given graph as GraphML string.

By default the GraphMLIOHandler reads and writes GraphML which encodes all structural, visual, and geometric information of a graph. You can easily configure the GraphMLIOHandler to write additional business data which is associated with graph elements or the graph itself. These data can be of simple type like string, e.g. encoding a tooltip or a link. It is also possible, though, to encode complex data like objects which model the entire business data behind a graph item.

Customizing GraphMLIOHandler

To use a customized GraphMLIOHandler with a GraphComponent, you can set its property GraphMLSupport.graphMLIOHandler:

Setting a custom GraphMLIOHandler
const graphMLIOHandler = new GraphMLIOHandler()

// configure the handler to your needs ...

// use the graphml support class to attach some predefined commands that use
// our newly defined graphml handler
const support = new GraphMLSupport({
  graphComponent: graphComponent,
  storageLocation: StorageLocation.FILE_SYSTEM,
  graphMLIOHandler: graphMLIOHandler
})

Events for Reading and Writing

GraphMLIOHandler facilitates events that are fired at different stages of reading or writing. The most common use case is to perform an action after a graph is loaded, for example to apply a layout algorithm to the loaded graph.

Writing
Fired when the writing of a document is about to start.
Written
Fired when the document has been written successfully.
Parsing
Fired when the parsing of the document is about to start.
Parsed
Fired when the document has be parsed successfully.