Class SVGIOHandler from the extension package provides the yFiles library with export support for the SVG file format. It is a direct subclass of abstract class IOHandler from package y.io of the yFiles library, see also Figure 11.1, “SVG output handler class hierarchy”.
The code fragment in Example 11.1, “Instantiating a SVGIOHandler” shows how to instantiate and use a SVGIOHandler to export the content of a given Graph2DView to a SVG-encoded file. Class SVGZIOHandler can be used in a similar manner to write Zip-compressed SVG files which are up to 50 times smaller than their uncompressed counterparts.
Example 11.1. Instantiating a SVGIOHandler
public void exportSVG(Graph2DView view) { // Instantiate a SVG output handler and export the view's content. try { IOHandler ioh = new SVGIOHandler(); double tmpPDT = view.getPaintDetailThreshold(); view.setPaintDetailThreshold(0.0); ioh.write(view.getGraph2D(), "MySVG.svg"); view.setPaintDetailThreshold(tmpPDT); } catch (IOException ioEx) { // Something went wrong. Complain. } }
Besides exporting the content of a Graph2DView to SVG, the ySVG extension package also enables to directly use SVG content for the representation of a graph's nodes. Either of the classes SVGNodeRealizer or SVGPainter can be used to this end. Both use an SVGModel that holds the actual SVG content:
Copyright ©2004-2012, yWorks GmbH. All rights reserved. |