Package org.faceless.graph2
Class SVGOutput
- java.lang.Object
-
- org.faceless.graph2.Output
-
- org.faceless.graph2.SVGOutput
-
public class SVGOutput extends Output
A subclass ofOutput
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);
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getTrace(String name)
Return the path taken by the specified line series.void
setPrefix(String prefix)
Set the prefix to use for any "id" attributes that need to be createdvoid
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 org.faceless.graph2.Output
getAreas, storeAreas
-
-
-
-
Constructor Detail
-
SVGOutput
public SVGOutput(int width, int height)
Create a new SVGOutput- Parameters:
width
- the width of the image in user unitsheight
- 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 imageheight
- the height of the imagebackground
- the background color of the SVG, ornull
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 theextraxml
parameter, and is added immediately after the<svg>
tag. Additional attributes for the<svg>
tag are specified with thesvgatts
parameter. Both parameters may be null. As an example, callingsetXMLExtras("<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
orFileWriter
, 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 theOutputStreamWriter
object, eg.new OutputStreamWriter(stream, "UTF-8")
instead ofnew OutputStreamWriter(stream)
- Parameters:
writer
- theWriter
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 theOutput.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
-
setPrefix
public void setPrefix(String prefix)
Set the prefix to use for any "id" attributes that need to be created- Parameters:
prefix
- the prefix, or null for none- Since:
- 2.4.9
-
-