Package elki.visualization.svg
Class SVGPlot
- java.lang.Object
-
- elki.visualization.svg.SVGPlot
-
- Direct Known Subclasses:
VisualizationPlot
public class SVGPlot extends java.lang.ObjectBase class for SVG plots. Provides some basic functionality such as element creation, axis plotting, markers and number formatting for SVG.- Since:
- 0.2
- Author:
- Erich Schubert
-
-
Field Summary
Fields Modifier and Type Field Description private static org.w3c.dom.DOMImplementationBATIK_DOMBatik DOM implementation.private static java.lang.String[]BATIK_DOMSDOM implementations to try.private CSSClassManagercssmanCSS class managerstatic floatDEFAULT_QUALITYDefault JPEG quality settingprivate org.w3c.dom.ElementdefsDefinitions element of the document.private booleandisableInteractionsFlag whether Batik interactions should be disabled.private org.w3c.dom.svg.SVGDocumentdocumentSVG document we plot to.static java.lang.StringNO_EXPORT_ATTRIBUTEAttribute to block export of element.private java.util.HashMap<java.lang.String,java.lang.ref.WeakReference<org.w3c.dom.Element>>objWithIdManage objects with an id.private org.w3c.dom.ElementrootRoot element of the document.private UpdateRunnerrunnerRegisters changes of this SVGPlot.private org.w3c.dom.ElementstylePrimary style information
-
Constructor Summary
Constructors Constructor Description SVGPlot()Create a new plotting document.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCSSClassOrLogError(CSSClass cls)Convenience method to add a CSS class or log an error.protected org.w3c.dom.svg.SVGDocumentcloneDocument()Clone the SVGPlot document for transcoding.voiddispose()Clean up the plot.voiddumpDebugFile()Dump the SVG plot to a debug file.org.w3c.dom.svg.SVGPointelementCoordinatesFromEvent(org.w3c.dom.Element tag, org.w3c.dom.events.Event evt)Convert screen coordinates to element coordinates.protected java.util.Collection<java.lang.String>getAllIds()Get all used DOM Ids in this plot.CSSClassManagergetCSSClassManager()Get the plots CSS class manager.org.w3c.dom.ElementgetDefs()Getter for definitions sectionbooleangetDisableInteractions()Get Batik disable default interactions flag.org.w3c.dom.svg.SVGDocumentgetDocument()Retrieve the SVG document.static org.w3c.dom.DOMImplementationgetDomImpl()Get a suitable SVG DOM implementation from Batik 1.7 or 1.8.org.w3c.dom.ElementgetIdElement(java.lang.String id)Get an element by its id.org.w3c.dom.ElementgetRoot()Getter for root element.java.awt.image.BufferedImagemakeAWTImage(int width, int height)Convert the SVG to a thumbnail image.voidputIdElement(java.lang.String id, org.w3c.dom.Element obj)Add an object id.voidsaveAsANY(java.nio.file.Path file, int width, int height, float quality)Save a file trying to auto-guess the file type.voidsaveAsEPS(java.nio.file.Path file)Transcode file to EPS.voidsaveAsJPEG(java.nio.file.Path file, int width, int height)Transcode file to JPEG.voidsaveAsJPEG(java.nio.file.Path file, int width, int height, float quality)Transcode file to JPEG.voidsaveAsPDF(java.nio.file.Path file)Transcode file to PDF.voidsaveAsPNG(java.nio.file.Path file, int width, int height)Transcode file to PNG.voidsaveAsPS(java.nio.file.Path file)Transcode file to PS.voidsaveAsSVG(java.nio.file.Path file)Save document into a SVG file.voidscheduleUpdate(java.lang.Runnable runnable)Schedule an update.voidsetDisableInteractions(boolean disable)Disable Batik predefined interactions.org.w3c.dom.ElementsvgCircle(double cx, double cy, double r)Create a SVG circleorg.w3c.dom.ElementsvgElement(java.lang.String name)Create a SVG element in the SVG namespace.org.w3c.dom.ElementsvgElement(java.lang.String name, java.lang.String cssclass)Create a SVG element in the SVG namespace.org.w3c.dom.ElementsvgLine(double x1, double y1, double x2, double y2)Create a SVG line elementorg.w3c.dom.ElementsvgRect(double x, double y, double w, double h)Create a SVG rectangleorg.w3c.dom.ElementsvgText(double x, double y, java.lang.String text)Create a SVG text element.voidsynchronizeWith(UpdateSynchronizer sync)Assign an update synchronizer.protected voidtranscode(java.nio.file.Path file, org.apache.batik.transcoder.Transcoder transcoder)Transcode a document into a file using the given transcoder.voidunsynchronizeWith(UpdateSynchronizer sync)Detach from synchronization.voidupdateStyleElement()Update style element - invoke this appropriately after any change to the CSS styles.
-
-
-
Field Detail
-
DEFAULT_QUALITY
public static final float DEFAULT_QUALITY
Default JPEG quality setting- See Also:
- Constant Field Values
-
NO_EXPORT_ATTRIBUTE
public static final java.lang.String NO_EXPORT_ATTRIBUTE
Attribute to block export of element.- See Also:
- Constant Field Values
-
BATIK_DOM
private static final org.w3c.dom.DOMImplementation BATIK_DOM
Batik DOM implementation.
-
BATIK_DOMS
private static final java.lang.String[] BATIK_DOMS
DOM implementations to try.
-
document
private org.w3c.dom.svg.SVGDocument document
SVG document we plot to.
-
root
private org.w3c.dom.Element root
Root element of the document.
-
defs
private org.w3c.dom.Element defs
Definitions element of the document.
-
style
private org.w3c.dom.Element style
Primary style information
-
cssman
private CSSClassManager cssman
CSS class manager
-
objWithId
private java.util.HashMap<java.lang.String,java.lang.ref.WeakReference<org.w3c.dom.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.
-
-
Method Detail
-
getDomImpl
public static org.w3c.dom.DOMImplementation getDomImpl()
Get a suitable SVG DOM implementation from Batik 1.7 or 1.8.- Returns:
- DOM implementation
-
dispose
public void dispose()
Clean up the plot.
-
svgElement
public org.w3c.dom.Element svgElement(java.lang.String name)
Create a SVG element in the SVG namespace. Non-static version.- Parameters:
name- node name- Returns:
- new SVG element.
-
svgElement
public org.w3c.dom.Element svgElement(java.lang.String name, java.lang.String cssclass)Create a SVG element in the SVG namespace. Non-static version.- Parameters:
name- node namecssclass- CSS class- Returns:
- new SVG element.
-
svgRect
public org.w3c.dom.Element svgRect(double x, double y, double w, double h)Create a SVG rectangle- Parameters:
x- X coordinatey- Y coordinatew- Widthh- Height- Returns:
- new element
-
svgCircle
public org.w3c.dom.Element svgCircle(double cx, double cy, double r)Create a SVG circle- Parameters:
cx- center Xcy- center Yr- radius- Returns:
- new element
-
svgLine
public org.w3c.dom.Element svgLine(double x1, double y1, double x2, double y2)Create a SVG line element- Parameters:
x1- first point xy1- first point yx2- second point xy2- second point y- Returns:
- new element
-
svgText
public org.w3c.dom.Element svgText(double x, double y, java.lang.String text)Create a SVG text element.- Parameters:
x- first point xy- first point ytext- Content of text element.- Returns:
- New text element.
-
elementCoordinatesFromEvent
public org.w3c.dom.svg.SVGPoint elementCoordinatesFromEvent(org.w3c.dom.Element tag, org.w3c.dom.events.Event evt)Convert screen coordinates to element coordinates.- Parameters:
tag- Element to convert the coordinates forevt- Event object- Returns:
- Coordinates
-
getDocument
public org.w3c.dom.svg.SVGDocument getDocument()
Retrieve the SVG document.- Returns:
- resulting document.
-
getRoot
public org.w3c.dom.Element getRoot()
Getter for root element.- Returns:
- DOM element
-
getDefs
public org.w3c.dom.Element getDefs()
Getter for definitions section- Returns:
- 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(java.nio.file.Path file) throws java.io.IOException, javax.xml.transform.TransformerFactoryConfigurationError, javax.xml.transform.TransformerExceptionSave document into a SVG file.References PNG images from the temporary files will be inlined automatically.
- Parameters:
file- Output filename- Throws:
java.io.IOException- On write errorsjavax.xml.transform.TransformerFactoryConfigurationError- Transformation errorjavax.xml.transform.TransformerException- Transformation error
-
transcode
protected void transcode(java.nio.file.Path file, org.apache.batik.transcoder.Transcoder transcoder) throws java.io.IOException, org.apache.batik.transcoder.TranscoderExceptionTranscode a document into a file using the given transcoder.- Parameters:
file- Output filetranscoder- Transcoder to use- Throws:
java.io.IOException- On write errorsorg.apache.batik.transcoder.TranscoderException- On input/parsing errors
-
cloneDocument
protected org.w3c.dom.svg.SVGDocument cloneDocument()
Clone the SVGPlot document for transcoding.This will usually be necessary for exporting the SVG document if it is currently being displayed: otherwise, we break the Batik rendering trees. (Discovered by Simon).
- Returns:
- cloned document
-
saveAsPDF
public void saveAsPDF(java.nio.file.Path file) throws java.io.IOException, org.apache.batik.transcoder.TranscoderException, java.lang.ClassNotFoundExceptionTranscode file to PDF.- Parameters:
file- Output filename- Throws:
java.io.IOException- On write errorsorg.apache.batik.transcoder.TranscoderException- On input/parsing errors.java.lang.ClassNotFoundException- PDF transcoder not installed
-
saveAsPS
public void saveAsPS(java.nio.file.Path file) throws java.io.IOException, org.apache.batik.transcoder.TranscoderException, java.lang.ClassNotFoundExceptionTranscode file to PS.- Parameters:
file- Output filename- Throws:
java.io.IOException- On write errorsorg.apache.batik.transcoder.TranscoderException- On input/parsing errors.java.lang.ClassNotFoundException- PS transcoder not installed
-
saveAsEPS
public void saveAsEPS(java.nio.file.Path file) throws java.io.IOException, org.apache.batik.transcoder.TranscoderException, java.lang.ClassNotFoundExceptionTranscode file to EPS.- Parameters:
file- Output filename- Throws:
java.io.IOException- On write errorsorg.apache.batik.transcoder.TranscoderException- On input/parsing errors.java.lang.ClassNotFoundException- EPS transcoder not installed
-
saveAsPNG
public void saveAsPNG(java.nio.file.Path file, int width, int height) throws java.io.IOException, org.apache.batik.transcoder.TranscoderExceptionTranscode file to PNG.- Parameters:
file- Output filenamewidth- Widthheight- Height- Throws:
java.io.IOException- On write errorsorg.apache.batik.transcoder.TranscoderException- On input/parsing errors.
-
saveAsJPEG
public void saveAsJPEG(java.nio.file.Path file, int width, int height, float quality) throws java.io.IOException, org.apache.batik.transcoder.TranscoderExceptionTranscode file to JPEG.- Parameters:
file- Output filenamewidth- Widthheight- Heightquality- JPEG quality setting, between 0.0 and 1.0- Throws:
java.io.IOException- On write errorsorg.apache.batik.transcoder.TranscoderException- On input/parsing errors.
-
saveAsJPEG
public void saveAsJPEG(java.nio.file.Path file, int width, int height) throws java.io.IOException, org.apache.batik.transcoder.TranscoderExceptionTranscode file to JPEG.- Parameters:
file- Output filenamewidth- Widthheight- Height- Throws:
java.io.IOException- On write errorsorg.apache.batik.transcoder.TranscoderException- On input/parsing errors.
-
saveAsANY
public void saveAsANY(java.nio.file.Path file, int width, int height, float quality) throws java.io.IOException, org.apache.batik.transcoder.TranscoderException, javax.xml.transform.TransformerFactoryConfigurationError, javax.xml.transform.TransformerException, java.lang.ClassNotFoundExceptionSave a file trying to auto-guess the file type.- Parameters:
file- File namewidth- Width (for pixel formats)height- Height (for pixel formats)quality- Quality (for lossy compression)- Throws:
java.io.IOException- on file write errors or unrecognized file extensionsorg.apache.batik.transcoder.TranscoderException- on transcoding errorsjavax.xml.transform.TransformerFactoryConfigurationError- on transcoding errorsjavax.xml.transform.TransformerException- on transcoding errorsjava.lang.ClassNotFoundException- when the transcoder was not installed
-
makeAWTImage
public java.awt.image.BufferedImage makeAWTImage(int width, int height) throws org.apache.batik.transcoder.TranscoderExceptionConvert the SVG to a thumbnail image.- Parameters:
width- Width of thumbnailheight- Height of thumbnail- Returns:
- Buffered image
- Throws:
org.apache.batik.transcoder.TranscoderException
-
dumpDebugFile
public void dumpDebugFile()
Dump the SVG plot to a debug file.
-
putIdElement
public void putIdElement(java.lang.String id, org.w3c.dom.Element obj)Add an object id.- Parameters:
id- IDobj- Element
-
getIdElement
public org.w3c.dom.Element getIdElement(java.lang.String id)
Get an element by its id.- Parameters:
id- ID- Returns:
- Element
-
getAllIds
protected java.util.Collection<java.lang.String> getAllIds()
Get all used DOM Ids in this plot.- Returns:
- Collection of DOM element IDs.
-
scheduleUpdate
public void scheduleUpdate(java.lang.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
-
-