Search


Ploticus > Scripts >
SVG support


ploticus can produce graphics in SVG format. SVG is a vector graphic format originated by Adobe Systems and defined in a W3C spec . SVGs look good because nice fonts are standard, and graphics scale with no degradation in appearance. SVG can be viewed using Firefox 1.5+ and MSIE browsers, and can be imported into tools such as Word, Powerpoint, etc. There's also the rsvg utility for converting SVG files to PNG or other raster formats.

SVG files have names ending in .svg. SVG files can also be compressed for smaller size; these files have names ending in .svgz. Compression requires zlib and hence may not be available in all ploticus builds.




Generating SVG

To generate SVG, use the -svg or -svgz command line option (-svgz gives you compressed svg results).
    pl -svgz -tag bars2.pl

Output files will have an .svg or .svgz ending by default. The -zlevel n option may be used to set the compression level to n (0 - 9 where 9 is highest level of compression).

There are several settings / command line options particularly for use with SVG. See below.




Embedding SVG graphics within HTML

To display an SVG graphic within an HTML document, use an <object> tag like this:

<object data="myresult.svg" type="image/svg+xml" width=300 height=200 title="ploticus example">
</object>

An older method involving the <embed> tag is no longer recommended. The embed tag was used like this:

<embed src="bars2.svg" name="SVGEmbed" width="500" height="616"
type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/">





Fonts

Default font is Helvetica. Postscript font names such as Times-Roman and Courier may be used. Font names containing embedded whitespace may be problematic with ploticus' SVG driver. More info




Clickable maps

Clickmaps are supported in browser environments. Use -csmap command line option. Here's an example script and svg result. You can specify a target window (similarly to HTML <a target=...>) using this syntax in your ploticus script: clickmapurl: [target=new]http://abc.com/... (changed in 2.33)




Mouseover text bubbles / tooltips

Mouseover text bubbles (tooltips), are supported for SVG when viewing in a browser. There are two javascript-based methods (both suggested by Jamie Echlin) that can be used:

Method #1: (the default) uses javascript files (available from the ploticus download page). Produces SVGs that support mouseover independently without involving the containing HTML file. There are some proc settings attributes that may be useful. Here's an example pl script that uses this method.

Procedure:

    Specify text bubble content using clickmaplabel or clickmaplabeltext in the plotting proc you're using. Specify only the text; no javascript code should be given.
    Run pl -svg -map ...
    View the SVG with MS Internet Explorer (or other browsers that support SVG)

There are some unresolved issues with this method... The size of the blue box is fixed without regard to text length (you can adjust this in the GraphPopups.js code.. see BOX SIZE). The location of the blue box is also fixed. There is code in GraphPopups.js (see BOX LOCATION) that attempts to place the box near the pointer (a nicer effect), but it doesn't work correctly for smaller-sized graphic results... the blue box is often "off the page" and not visible.

Method #2: uses a javascript package called overlibmws which extends overlib allowing the popups to appear over the SVG object. With this method it's easy to format the popup-- you can have HTML elements in the popup, including links and images and so on, through only changing your plot file and not javascript or svg files.

To implement this: Download and unzip overlibmws from http://www.macridesweb.com/oltest/overlibmws.zip

In the containing HTML page include this section in the <head> block, making sure that the URLs are valid in your environment:

<script type="text/javascript" src="mws/overlibmws.js"></script>
<script type="text/javascript" src="mws/overlibmws_iframe.js"></script>
<script type="text/javascript" src="mws/overlibmws_hide.js"></script>
<script type="text/javascript" src="mws/overlibmws_shadow.js"></script>
In the ploticus file use the clickmaplabel or clickmaplabeltext attribute appropriately, eg. in my example I have:
  clickmaplabeltext: onmouseover='overlib( "Date: <b>@1</b> <BR>Value: <b>@2</b>
      <BR>@3", CAPTION, "Spot Details")' onmouseout='nd();'
Also, you'll need to tell ploticus to not generate the method1 SVG tooltip code by specifying this at the top of your script file:
  #proc settings
  svg_mouseover_js: generic

For general information on generating clickmaps and mouseover with ploticus please see the clickmaps and mouseover page.




Displaying PNG/GIF/JPG images in your SVG result

As of ploticus 2.40+ this can now be done, see proc image




Importing SVG into applications

Microsoft Office applications can import SVG graphics. On the version I have, import via dragging and dropping works. Import via the "Insert graphic" menu does not.




pl(1) command line options for use with SVG

-svg .... produce svg output

-svgz .... same as -svg but output is gzip compressed

-svg_tagparms     string

    This allows arbitrary text to be inserted into the opening <svg> tag.
    Example: -svg_tagparms 'height="10cm" width="15cm"'

-omit_xml_declaration

    By default the first line of the SVG result will be the XML declaration <?xml .. > . Use this option to suppress the XML declaration line if the SVG result is to be embedded into a larger XML document.

-xml_encoding     method

    Set the XML character encoding method. This encoding will be indicated in the XML declaration line. The default is iso-8859-1 which provides Latin and Western European character sets. For Unicode fonts this should be set to utf-8 (for more discussion see the Unicode section in fonts ).

-tag

    Causes a suitable HTML <EMBED> tag to be written to standard output.

-zlevel n

    This may be used to set the compression level to n for SVGZ output (0 - 9 where 9 is highest level of compression and the default).




Troubleshooting

As of this writing (fall 2007) Firefox 1.5+ seems to be the best medium for viewing SVG results.

Some web servers still send incorrect mime type in the HTTP header when serving SVG files. For normal SVG files, servers should send the HTTP header:

  Content-Type: image/svg+xml
For gzipped SVG files, servers should send the HTTP headers:
  Content-Type: image/svg+xml
  Content-Encoding: gzip
A symptom of web server sending incorrect mime type is Firefox 1.5+ saying "What should Firefox do with this file?"




Acknowledgement

Many thanks to Bill Traill ( bill@traill.demon.co.uk ) for initiating ploticus SVG support and writing the original ploticus SVG driver.




 


Ploticus 2.42 ... May 2013 Terms of use /