org.faceless.graph2
Class SVGOutput

java.lang.Object
  extended by org.faceless.graph2.Output
      extended by org.faceless.graph2.SVGOutput

public class SVGOutput
extends Output

A subclass of Output which allows the finished Graph to be rendered to SVG. At it's simplest, something like this would generally do:

 Graph graph = makeMyGraph();
 SVGOutput out = new SVGOutput(100,100);
 graph.draw(out);
 out.writeSVG(new OutputStreamWriter(new FileOutputStream("Graph.svg"), "UTF-8"), true);
 

See Also:
Graph.draw(org.faceless.graph2.Output), Graph.setMetaData(java.lang.String, java.lang.String)

Constructor Summary
SVGOutput(int width, int height)
          Create a new SVGOutput
SVGOutput(int width, int height, Paint background)
          Create a new SVGOutput
 
Method Summary
 String getTrace(String name)
          Return the path taken by the specified line series.
 void setXMLExtras(String extraxml, String svgatts)
          Add additional XML to the XVG object and/or additional attributes to the <svg> tag.
 void writeSVG(Writer writer, boolean header)
           Write the SVG data to the specified writer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SVGOutput

public SVGOutput(int width,
                 int height)
Create a new SVGOutput

Parameters:
width - the width of the image in user units
height - the height of the image in user units

SVGOutput

public SVGOutput(int width,
                 int height,
                 Paint background)
Create a new SVGOutput

Parameters:
width - the width of the image
height - the height of the image
background - the background color of the SVG, or null for no background
Method Detail

setXMLExtras

public void setXMLExtras(String extraxml,
                         String svgatts)
Add additional XML to the XVG object and/or additional attributes to the <svg> tag. Additional XML is specified with the extraxml parameter, and is added immediately after the <svg> tag. Additional attributes for the <svg> tag are specified with the svgatts parameter. Both parameters may be null. As an example, calling setXMLExtras("<script xlink:href=\"myscript.js\" />", "xmlns:xlink=\"http://www.w3.org/1999/xlink\""); would result in SVG that looks something like this (features set by this call in bold):
 <svg width="300" height="300" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink"<
 <script xlink:href="myscript.js" />
 <g><polygon ...
 

Parameters:
extraxml - the XML which should be inserted immediately after the <svg> tag. May be null.
svgatts - any additional attributes for the <svg> tag. May be null.
Since:
2.1

writeSVG

public void writeSVG(Writer writer,
                     boolean header)
              throws IOException

Write the SVG data to the specified writer. For standalone SVG documents, the header flag should be set to true to generate the <?xml version="1.0"... header, and the DOCTYPE line defining the output as an SVG document.

Note that when writing to an OutputStreamWriter or FileWriter, the encoding of the XML header will be set to match the encoding of that Writer. This implies that if you want to control the encoding of the XML, make sure you set the encoding explicitly when creating the OutputStreamWriter object, eg. new OutputStreamWriter(stream, "UTF-8") instead of new OutputStreamWriter(stream)

Parameters:
writer - the Writer to write the finished SVG to.
header - whether to include the "<?xml"... header and the DOCTYPE.
Throws:
IOException

getTrace

public String getTrace(String name)
Return the path taken by the specified line series. This method functions a similar way to the ImageOutput.getAreas() method - given a line series called "Prices", passing in the string "trace.graph.series.Prices" will return a String containing a list of comma-separated points which define the path taken by that series. There is no reason for end users to call this method.

Since:
2.1


Copyright © 2001-2011 Big Faceless Organization