de.lmu.ifi.dbs.elki.visualization.svg
Class SVGPlot

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.visualization.svg.SVGPlot
Direct Known Subclasses:
DetailView, OverviewPlot

public class SVGPlot
extends Object

Base class for SVG plots. Provides some basic functionality such as element creation, axis plotting, markers and number formatting for SVG.


Field Summary
private  CSSClassManager cssman
          CSS class manager
static double DEFAULT_QUALITY
          Default JPEG quality setting
private  Element defs
          Definitions element of the document.
private  boolean disableInteractions
          Flag whether Batik interactions should be disabled.
private  org.w3c.dom.svg.SVGDocument document
          SVG document we plot to.
private  HashMap<String,WeakReference<Element>> objWithId
          Manage objects with an id.
private  Element root
          Root element of the document.
private  UpdateRunner runner
          Registers changes of this SVGPlot.
private  Element style
          Primary style information
 
Constructor Summary
SVGPlot()
          Create a new plotting document.
 
Method Summary
 void addCSSClassOrLogError(CSSClass cls)
          Convenience method to add a CSS class or log an error.
 void dispose()
          Clean up the plot.
 void dumpDebugFile()
          Dump the SVG plot to a debug file.
 org.w3c.dom.svg.SVGPoint elementCoordinatesFromEvent(Element tag, Event evt)
          Convert screen coordinates to element coordinates.
protected  Collection<String> getAllIds()
          Get all used DOM Ids in this plot.
 CSSClassManager getCSSClassManager()
          Get the plots CSS class manager.
 Element getDefs()
          Getter for definitions section
 boolean getDisableInteractions()
          Get Batik disable default interactions flag.
 org.w3c.dom.svg.SVGDocument getDocument()
          Retrieve the SVG document.
 Element getIdElement(String id)
          Get an element by its id.
 Element getRoot()
          Getter for root element.
 Element getStyle()
          Deprecated. Contents will be overwritten by CSS class manager!
private  UpdateRunner getUpdateRunner()
          Get the plots update runner.
 void putIdElement(String id, Element obj)
          Add an object id.
 void saveAsANY(File file, int width, int height, double quality)
          Save a file trying to auto-guess the file type.
 void saveAsEPS(File file)
          Transcode file to EPS.
 void saveAsJPEG(File file, int width, int height)
          Transcode file to JPEG.
 void saveAsJPEG(File file, int width, int height, double quality)
          Transcode file to JPEG.
 void saveAsPDF(File file)
          Transcode file to PDF.
 void saveAsPNG(File file, int width, int height)
          Transcode file to PNG.
 void saveAsPS(File file)
          Transcode file to PS.
 void saveAsSVG(File file)
          Save document into a SVG file.
 void scheduleUpdate(Runnable runnable)
          Schedule an update.
 void setDisableInteractions(boolean disable)
          Disable Batik predefined interactions.
 Element svgCircle(double cx, double cy, double r)
          Create a SVG circle
 Element svgElement(String name)
          Create a SVG element in the SVG namespace.
 Element svgLine(double x1, double y1, double x2, double y2)
          Create a SVG line element
 Element svgRect(double x, double y, double w, double h)
          Create a SVG rectangle
 Element svgText(double x, double y, String text)
          Create a SVG text element.
 void synchronizeWith(UpdateSynchronizer sync)
          Assign an update synchronizer.
protected  void transcode(File file, org.apache.batik.transcoder.Transcoder transcoder)
          Transcode a document into a file using the given transcoder.
 void unsynchronizeWith(UpdateSynchronizer sync)
          Detach from synchronization.
 void updateStyleElement()
          Update style element - invoke this appropriately after any change to the CSS styles.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_QUALITY

public static final double DEFAULT_QUALITY
Default JPEG quality setting

See Also:
Constant Field Values

document

private org.w3c.dom.svg.SVGDocument document
SVG document we plot to.


root

private Element root
Root element of the document.


defs

private Element defs
Definitions element of the document.


style

private Element style
Primary style information


cssman

private CSSClassManager cssman
CSS class manager


objWithId

private HashMap<String,WeakReference<Element>> objWithId
Manage objects with an id.


runner

private UpdateRunner runner
Registers changes of this SVGPlot.


disableInteractions

private boolean disableInteractions
Flag whether Batik interactions should be disabled.

Constructor Detail

SVGPlot

public SVGPlot()
Create a new plotting document.

Method Detail

dispose

public void dispose()
Clean up the plot.


svgElement

public Element svgElement(String name)
Create a SVG element in the SVG namespace. Non-static version.

Parameters:
name - node name
Returns:
new SVG element.

svgRect

public Element svgRect(double x,
                       double y,
                       double w,
                       double h)
Create a SVG rectangle

Parameters:
x - X coordinate
y - Y coordinate
w - Width
h - Height
Returns:
new element

svgCircle

public Element svgCircle(double cx,
                         double cy,
                         double r)
Create a SVG circle

Parameters:
cx - center X
cy - center Y
r - radius
Returns:
new element

svgLine

public Element svgLine(double x1,
                       double y1,
                       double x2,
                       double y2)
Create a SVG line element

Parameters:
x1 - first point x
y1 - first point y
x2 - second point x
y2 - second point y
Returns:
new element

svgText

public Element svgText(double x,
                       double y,
                       String text)
Create a SVG text element.

Parameters:
x - first point x
y - first point y
text - Content of text element.
Returns:
New text element.

elementCoordinatesFromEvent

public org.w3c.dom.svg.SVGPoint elementCoordinatesFromEvent(Element tag,
                                                            Event evt)
Convert screen coordinates to element coordinates.

Parameters:
tag - Element to convert the coordinates for
evt - Event object
Returns:
Coordinates

getDocument

public org.w3c.dom.svg.SVGDocument getDocument()
Retrieve the SVG document.

Returns:
resulting document.

getRoot

public Element getRoot()
Getter for root element.

Returns:
DOM element

getDefs

public Element getDefs()
Getter for definitions section

Returns:
DOM element

getStyle

@Deprecated
public Element getStyle()
Deprecated. Contents will be overwritten by CSS class manager!

Getter for style element.

Returns:
stylesheet DOM element

getCSSClassManager

public CSSClassManager getCSSClassManager()
Get the plots CSS class manager. Note that you need to invoke updateStyleElement() to make changes take effect.

Returns:
CSS class manager.

addCSSClassOrLogError

public void addCSSClassOrLogError(CSSClass cls)
Convenience method to add a CSS class or log an error.

Parameters:
cls - CSS class to add.

updateStyleElement

public void updateStyleElement()
Update style element - invoke this appropriately after any change to the CSS styles.


saveAsSVG

public void saveAsSVG(File file)
               throws IOException,
                      TransformerFactoryConfigurationError,
                      TransformerException
Save document into a SVG file. References PNG images from the temporary files will be inlined automatically.

Parameters:
file - Output filename
Throws:
IOException - On write errors
TransformerFactoryConfigurationError - Transformation error
TransformerException - Transformation error

transcode

protected void transcode(File file,
                         org.apache.batik.transcoder.Transcoder transcoder)
                  throws IOException,
                         org.apache.batik.transcoder.TranscoderException
Transcode a document into a file using the given transcoder.

Parameters:
file - Output file
transcoder - Transcoder to use
Throws:
IOException - On write errors
org.apache.batik.transcoder.TranscoderException - On input/parsing errors

saveAsPDF

public void saveAsPDF(File file)
               throws IOException,
                      org.apache.batik.transcoder.TranscoderException
Transcode file to PDF.

Parameters:
file - Output filename
Throws:
IOException - On write errors
org.apache.batik.transcoder.TranscoderException - On input/parsing errors.

saveAsPS

public void saveAsPS(File file)
              throws IOException,
                     org.apache.batik.transcoder.TranscoderException
Transcode file to PS.

Parameters:
file - Output filename
Throws:
IOException - On write errors
org.apache.batik.transcoder.TranscoderException - On input/parsing errors.

saveAsEPS

public void saveAsEPS(File file)
               throws IOException,
                      org.apache.batik.transcoder.TranscoderException
Transcode file to EPS.

Parameters:
file - Output filename
Throws:
IOException - On write errors
org.apache.batik.transcoder.TranscoderException - On input/parsing errors.

saveAsPNG

public void saveAsPNG(File file,
                      int width,
                      int height)
               throws IOException,
                      org.apache.batik.transcoder.TranscoderException
Transcode file to PNG.

Parameters:
file - Output filename
width - Width
height - Height
Throws:
IOException - On write errors
org.apache.batik.transcoder.TranscoderException - On input/parsing errors.

saveAsJPEG

public void saveAsJPEG(File file,
                       int width,
                       int height,
                       double quality)
                throws IOException,
                       org.apache.batik.transcoder.TranscoderException
Transcode file to JPEG.

Parameters:
file - Output filename
width - Width
height - Height
quality - JPEG quality setting, between 0.0 and 1.0
Throws:
IOException - On write errors
org.apache.batik.transcoder.TranscoderException - On input/parsing errors.

saveAsJPEG

public void saveAsJPEG(File file,
                       int width,
                       int height)
                throws IOException,
                       org.apache.batik.transcoder.TranscoderException
Transcode file to JPEG.

Parameters:
file - Output filename
width - Width
height - Height
Throws:
IOException - On write errors
org.apache.batik.transcoder.TranscoderException - On input/parsing errors.

saveAsANY

public void saveAsANY(File file,
                      int width,
                      int height,
                      double quality)
               throws IOException,
                      org.apache.batik.transcoder.TranscoderException,
                      TransformerFactoryConfigurationError,
                      TransformerException
Save a file trying to auto-guess the file type.

Parameters:
file - File name
width - Width (for pixel formats)
height - Height (for pixel formats)
quality - Quality (for lossy compression)
Throws:
IOException - on file write errors or unrecognized file extensions
org.apache.batik.transcoder.TranscoderException - on transcoding errors
TransformerFactoryConfigurationError - on transcoding errors
TransformerException - on transcoding errors

dumpDebugFile

public void dumpDebugFile()
Dump the SVG plot to a debug file.


putIdElement

public void putIdElement(String id,
                         Element obj)
Add an object id.

Parameters:
id - ID
obj - Element

getIdElement

public Element getIdElement(String id)
Get an element by its id.

Parameters:
id - ID
Returns:
Element

getAllIds

protected Collection<String> getAllIds()
Get all used DOM Ids in this plot.

Returns:
Collection of DOM element IDs.

getUpdateRunner

private UpdateRunner getUpdateRunner()
Get the plots update runner.

Returns:
update runner

scheduleUpdate

public void scheduleUpdate(Runnable runnable)
Schedule an update.

Parameters:
runnable - Runnable to schedule

synchronizeWith

public void synchronizeWith(UpdateSynchronizer sync)
Assign an update synchronizer.

Parameters:
sync - Update synchronizer

unsynchronizeWith

public void unsynchronizeWith(UpdateSynchronizer sync)
Detach from synchronization.

Parameters:
sync - Update synchronizer to detach from.

getDisableInteractions

public boolean getDisableInteractions()
Get Batik disable default interactions flag.

Returns:
true when Batik default interactions are disabled

setDisableInteractions

public void setDisableInteractions(boolean disable)
Disable Batik predefined interactions.

Parameters:
disable - Flag

Release 0.4.0 (2011-09-20_1324)