Using Graphics Devices |
Scalable Vector Graphics (SVG) is an XML language for describing two-dimensional vector graphics. SAS creates SVG documents based on the World Wide Web Consortium (W3C) recommendation for SVG documents. SAS SVG files are created using the UNICODE standard encoding.
Note: Animation is not supported in SAS 9.2.
SAS can create SVG documents by using either the SVG Universal Printers or SAS/GRAPH SVG devices. There are four SVG devices: SVG, SVGT, SVGVIEW, and SVGZ. These devices are Universal Printer shortcut devices and are, therefore, intended mainly for use with the LISTING and HTML destinations. With the PRINTER destination, it is recommended that you use the SVG Universal Printers directly (see Differences In Using Shortcut Devices And Universal Printers).
The information provided here is limited to creating SVG documents using SAS/GRAPH devices in the LISTING and HTML destinations. For information about creating SVG documents in the PRINTER destination using the SVG Universal Printers, see Creating Scalable Vector Graphics Using Universal Printing in SAS Language Reference: Concepts.
For detailed information about the SVG standard, see the W3C documentation at http://www.w3.org/TR/SVG.
What Is an SVG Document? |
An SVG document produced by SAS/GRAPH is an XML file that contains an <svg> element.
any number of SVG graphic or container elements enclosed an <svg> element. Typical SVG graphics elements include circle, line, text, image, and many others. These elements draw the graphics that comprise the SVG document.
an SVG document fragment that can stand by itself. The SVG devices produce stand-alone SVG documents. When you send output to the HTML destination, the SVG document is embedded in an HTML document using the <embed> tag.
For example, the following code produces an SVG file named europepop.svg and an HTML file named europe.htm :
goptions reset=all device=svg; ods listing close; ods html file="europe.htm"; title "Population in Europe"; proc gmap map=maps.europe(where=(id ne 405 and id ne 845)) data=sashelp.demographics(where=(cont=93)) all; id id; choro pop / name="europePop"; run; quit; ods html close; ods listing;
You can view the SVG coding by opening the SVG document, europepop.svg , in a text editor. When you view the SVG document in an SVG-enabled browser (see Browsers That Support SVG Documents), the browser renders the image.
Why Create SVG Documents? |
Because SVG graphics are vector graphics, they can be resized without losing quality. A single SVG document can be scaled to any size or transformed to any resolution without compromising the clarity of the document. Bitmap images such as PNG and GIF lose quality any time they are resized.
Also, if you need to display the same graphic at multiple sizes or resolutions, you would need multiple bitmap images, but only one SVG document. SVG documents display clearly at any size in any viewer or browser that supports SVG. The user can zoom in to view details in a complicated SVG graphic.
An SVG document might also be smaller in file size than the same graphic created by a bitmap (image) device such as GIF or PNG.
SVG documents are ideal for producing documents to display on a computer monitor, PDA, or cell phone; or documents to be printed.
The SVG Devices and the Output That They Create |
There are four SVG devices:
produces SVG 1.1 documents. When used in the HTML destination, if your procedure produces multiple graphs, the SVG device produces separate SVG documents for each graph. When used in the LISTING destination, the SVG device produces one SVG file, and the pages are in a continuous layout.
produces SVG 1.1 documents that are transparent (no background). These documents are useful when you want to overlay several graphs on top of each other and you want all of the graphs to be visible. The SVGT device is intended for use when a procedure produces multiple graphs and is best used in conjunction with the ODS PRINTER destination. See Creating Overlaid Transparent SVG Documents in SAS Language Reference: Concepts for more information.
produces compressed SVG 1.1 documents, which are useful when file size is an issue. However, some browsers do not support compressed SVG documents, and you cannot view these files in a text editor. (See also Browsers That Support SVG Documents.)
produces SVG1.1 documents with navigational controls when the SVG file contains multiple pages. This device is primarily for use in the LISTING destination with procedures that produce multiple graphs. The navigational controls enable you to page through the graphs. See Example: Generating A Single SVG Document With Multiple Pages and Page Controls. When used in the HTML destination, the SVGVIEW device produces separate SVG documents for each graph, just like the SVG device.
Example: Placing Images Behind SVG Documents |
You can use the IBACK= graphics option in the GOPTIONS statement to specify the graphics file that you want to be placed behind the SVG graphic. SAS/GRAPH creates a PNG file from the image file that you specify. This PNG file is used as the background image and is referenced in the SVG with an <image> tag. The <image> tag specifies a relative (not absolute) pathname to the PNG file. If the SVG file is moved, the PNG file must also be moved to the same location. If many images are referenced in an SVG file, it is recommended that you create a new directory and store your SVG file and any images it references in the directory. Then, the entire directory can be moved as a package.
/* Reset existing options, specify the SVG device, and */ /* set the size of the SVG document. Specify the */ /* background image with the IBACK= option. Replace */ /* external-image-file with the name of an image that */ /* resides on your system. */ goptions reset=all device=svg hsize=4.8in vsize=3.2in imagestyle=fit iback="external-image-file"; /* Close the LISTING destination to conserve resources. */ /* Open the HTML destination and specify */ /* the name of the HTML output file. */ ods listing close; ods html file="carType.htm"; /* Specify the title for the graphic file and */ /* define response axis characteristics. */ title h=2 "Types of Vehicles Produced Worldwide"; axis1 label=none major=none minor=none; /* Generate the bar chart. The NAME= option */ /* specifies the name of the SVG file. */ proc gchart data=sashelp.cars; vbar type / raxis=axis1 outside=freq noframe name="carType"; run; quit; /* Close the HTML destination and */ /* reopen the LISTING destination. */ ods html close; ods listing;
For additional information, see Displaying an Image in a Graph Background.
Example: Generating A Single SVG Document With Multiple Pages and Page Controls |
The SVGVIEW device is designed to be used when in the LISTING destination. It is useful when a single procedure produces multiple graphs, such as with BY-group processing. When used in the LISTING destination, the SVGVIEW device creates a single SVG document with multiple pages. Each graph produced by the procedure is on a different page. The SVG document, by default, has control buttons that enable you to navigate forward and backward through the graphs as well as display an index page that shows a thumbnail image of each page in the document.
For example, the following display shows the initial graph that is produced by the program in Program Code: Using SVGVIEW Device With BY-Group Processing. The program produces six graphs. You can page through them clicking on using the Prev and Next buttons.
The Index button displays a page of thumbnail images. There is one thumbnail for each page in the SVG document.
The program that generates this SVG document is as follows:
Program Code: Using SVGVIEW Device With BY-Group Processing /* Subset the data set SASHELP.PRDSALE. */ /* Output the subset to WORK.PRODSUB. */ data prodsub; set sashelp.prdsale; where year=1994 and (country = "U.S.A." or country = "CANADA") and region="EAST" and division="CONSUMER" and (product in ("SOFA", "TABLE", "BED")); run; /* Sort WORK.PRODSUB. */ proc sort data=prodsub; by country product; run; /* Define a fileref for the SVG document. */ /* Use the GSFNAME= option to send the */ /* output of the LISTING destination to */ /* that fileref. */ filename mysvg "productView.svg"; goptions reset=all device=svgview gsfmode=replace gsfname=mysvg; /* Join the data points and change the */ /* line style for the predicted sales */ /* to a dashed line. */ symbol1 interpol=join line=1 color=_style_; symbol2 interpol=join line=2 color=_style_; legend1 label=none; /* Generate a graph for each unique */ /* combination of country and product. */ proc gplot data=work.prodsub; by country product; plot actual*month predict*month / overlay legend=legend1; run; quit;
When used in the HTML destination, the SVGVIEW device produces separate SVG documents for each graph, just like the SVG device.
For additional information, see Multi-Page SVG Documents in a Single File and Multi-Page SVG Documents in a Single File in SAS Language Reference: Concepts.
Implementing Drill-Down Functionality With the SVG Devices |
You can implement drill-down links in SVG documents that are generated in the HTML and LISTING destinations. In both cases, you use the HTML= option or the HTML_LEGEND= option (or both options) to specify variables in your input data that define the drill-down URLs. See Adding Links with the HTML= and HTML_LEGEND= Options for information on implementing drill-down links, including defining link variables.
Implementing drill-down links in SVG documents that are generated in the LISTING destination has an additional requirement: you must specify the IMAGEMAP= option in the PROC statement. This option makes the image map generated by the procedure available to the SVG device. For example:
proc gchart data=sashelp.prdsale imagemap=myimgmap;
Web Server Content Type for SVG Documents |
If the mime content type setting for your Web server does not have the correct setting for SVG documents, your Web browser might render SVG documents as text files or SVG documents might be unreadable.
To ensure that SVG documents are rendered correctly, you can configure your Web server to use this mime content type:
image/svg+xml
Browsers That Support SVG Documents |
In order to view SVG documents, you need a viewer or browser that supports Scalable Vector Graphics. Some browsers, such as Mozilla Firefox, have built-in support for SVG documents. Other browsers, such as Microsoft Internet Explorer, require an SVG plug-in to view SVG documents. One such plug-in is available from Adobe Systems, Inc.
The following table lists some browsers and viewers that support SVG documents. See Browser Support for Viewing SVG Documents in SAS Language Reference: Concepts for additional information.
Browser or Viewer | Company |
---|---|
Adobe SVG Viewer 31 | Adobe Systems, Inc. |
Batik SVG Toolkit | Apache Software Foundation |
eSVG Viewer and IDE | eSVG Viewer for PC, PDA, Mobile |
GPAC Project | GPAC |
Mozilla Firefox2 | Mozilla Foundation |
Opera | Opera Software |
TinyLine | TinyLine |
1
Adobe SVG Viewer 3 works in Internet Explorer 7. Check www.adobe.com
for information on support by Adobe
Systems, Inc. for the SVG viewer.
2 Mozilla Firefox does not support compressed SVG documents or font embedding. To avoid font mapping problems, specify the NOFONTEMBEDDING system option. Zooming and panning features are not currently implemented. Also, if you select View Page Style No Style, all graphs appear as a black rectangle. |
Controlling Graph Resolution With The SVG Devices |
The default resolution for the SVG devices is 96 dpi. Because the SVG devices are Universal Printer shortcut devices, you cannot change the resolution using options in the GOPTIONS statement. To change the resolution for these devices, you must use either the Print Setup dialog box or the PRTDEF procedure to change the resolution for the Universal Printer. Universal Printers have a fixed set of supported resolutions.
To use the Print Setup dialog box, select File Print Setup, and select the printer for which you want to change the resolution. Select Properties and click on the Advanced tab. Select the resolution that you want to use from the list.
For information on using the PRTDEF procedure, see The PRTDEF Procedure in Base SAS Procedures Guide.
Controlling Graph Size With the SVG Devices |
The default graph size for the SVG output is 600 x 800 pixels. You can change the size of your graph with the HSIZE= and VSIZE= graphics options. You can change the paper size by specifying the XMAX= and YMAX= or the XPIXELS= and YPIXELS= graphics options. Specifying a value for the XMAX=, YMAX=, XPIXELS=, or YPIXELS= graphics options changes the setting of the PAPERSIZE= system option. See Graphics Options and Device Parameters Dictionary and SAS System Options and SVG Output.
SAS System Options and SVG Output |
Because the SVG devices are Universal Printer shortcut devices, there are several SAS system options that affect the way the SVG devices generate output. These options include SVGHEIGHT=, SVGWIDTH=, SVGVIEWBOX=, SVGCONTROLBUTTONS, and PAPERSIZE=, among others. These options and their interactions are described in several topics in SAS Language Reference: Concepts under Creating Scalable Vector Graphics Using Universal Printing. Before reviewing the topics that deal with the various system options, you should review the topic SVG Terminology.
Topics dealing primarily with SAS system options are as follows:
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.