Package elki.visualization.svg
Class SVGUtil
- java.lang.Object
-
- elki.visualization.svg.SVGUtil
-
public final class SVGUtil extends java.lang.ObjectUtility class for SVG processing. Much of the classes are to allow easier attribute setting (conversion to string) and Namespace handling- Since:
- 0.2
- Author:
- Erich Schubert
-
-
Field Summary
Fields Modifier and Type Field Description private static javax.swing.text.html.StyleSheetcolorLookupStylesheetCSS Stylesheet from Javax, to parse color values.static java.text.NumberFormatFMTFormatter to output numbers in a valid SVG number format.static java.lang.StringHOURGLASS_PATHHourglass object.static java.lang.StringHOURGLASS_STYLEHourglass style.private static intNO_VALUEKey not found value.private static it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap<java.lang.String>SVG_COLOR_NAMESSVG color names conversion.static java.lang.StringTHROBBER_PATHThrobber path.static java.lang.StringTHROBBER_STYLEThrobber style.
-
Constructor Summary
Constructors Modifier Constructor Description privateSVGUtil()Private constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddCSSClass(org.w3c.dom.Element e, java.lang.String cssclass)Add a CSS class to an Element.static java.lang.StringcolorToString(int col)Convert a color name from an integer RGB color to CSS syntaxstatic java.lang.StringcolorToString(java.awt.Color col)Convert a color name from an AWT color object to CSS syntaxstatic org.w3c.dom.svg.SVGPointelementCoordinatesFromEvent(org.w3c.dom.Document doc, org.w3c.dom.Element tag, org.w3c.dom.events.Event evt)Convert the coordinates of an DOM Event from screen into element coordinates.static java.lang.Stringfmt(double x)Format a double according to the SVG specs.static java.lang.StringmakeMarginTransform(double owidth, double oheight, double iwidth, double iheight, double margin)Make a transform string to add marginsstatic java.lang.StringmakeMarginTransform(double owidth, double oheight, double iwidth, double iheight, double xmargin, double ymargin)Make a transform string to add marginsstatic java.lang.StringmakeMarginTransform(double owidth, double oheight, double iwidth, double iheight, double lmargin, double tmargin, double rmargin, double bmargin)Make a transform string to add marginsstatic org.w3c.dom.ElementmakeStyleElement(org.w3c.dom.Document document)Make a new CSS style element for the given Document.static voidremoveCSSClass(org.w3c.dom.Element e, java.lang.String cssclass)Remove a CSS class from an Element.static voidremoveFromParent(org.w3c.dom.Element elem)Remove an element from its parent, if defined.static voidremoveLastChild(org.w3c.dom.Element tag)Remove last child of an element, when presentstatic voidsetAtt(org.w3c.dom.Element el, java.lang.String name, double d)Set a SVG attributestatic voidsetAtt(org.w3c.dom.Element el, java.lang.String name, int d)Set a SVG attributestatic voidsetAtt(org.w3c.dom.Element el, java.lang.String name, java.lang.String d)Set a SVG attributestatic voidsetCSSClass(org.w3c.dom.Element e, java.lang.String cssclass)Set the CSS class of an Element.static voidsetStyle(org.w3c.dom.Element el, java.lang.String d)Set a SVG style attributestatic java.awt.ColorstringToColor(java.lang.String str)Convert a color name from SVG syntax to an AWT color object.static org.w3c.dom.ElementsvgCircle(org.w3c.dom.Document document, double cx, double cy, double r)Create a SVG circle element.static org.w3c.dom.ElementsvgCircleSegment(SVGPlot svgp, double centerx, double centery, double angleStart, double angleDelta, double innerRadius, double outerRadius)Create a circle segment.static org.w3c.dom.ElementsvgElement(org.w3c.dom.Document document, java.lang.String name)Create a SVG element in appropriate namespacestatic org.w3c.dom.ElementsvgLine(org.w3c.dom.Document document, double x1, double y1, double x2, double y2)Create a SVG line element.static org.w3c.dom.ElementsvgRect(org.w3c.dom.Document document, double x, double y, double w, double h)Create a SVG rectangle element.static org.w3c.dom.ElementsvgText(org.w3c.dom.Document document, double x, double y, java.lang.String text)Create a SVG text element.static org.w3c.dom.ElementsvgWaitIcon(org.w3c.dom.Document document, double x, double y, double w, double h)Draw a simple "please wait" icon (in-progress) as placeholder for running renderings.
-
-
-
Field Detail
-
FMT
public static final java.text.NumberFormat FMT
Formatter to output numbers in a valid SVG number format.
-
HOURGLASS_PATH
public static final java.lang.String HOURGLASS_PATH
Hourglass object.- See Also:
- Constant Field Values
-
HOURGLASS_STYLE
public static final java.lang.String HOURGLASS_STYLE
Hourglass style.- See Also:
- Constant Field Values
-
THROBBER_PATH
public static final java.lang.String THROBBER_PATH
Throbber path.- See Also:
- Constant Field Values
-
THROBBER_STYLE
public static final java.lang.String THROBBER_STYLE
Throbber style.- See Also:
- Constant Field Values
-
SVG_COLOR_NAMES
private static final it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap<java.lang.String> SVG_COLOR_NAMES
SVG color names conversion.
-
NO_VALUE
private static final int NO_VALUE
Key not found value. Not a reasonable color, fully transparent!- See Also:
- Constant Field Values
-
colorLookupStylesheet
private static final javax.swing.text.html.StyleSheet colorLookupStylesheet
CSS Stylesheet from Javax, to parse color values.
-
-
Method Detail
-
fmt
public static java.lang.String fmt(double x)
Format a double according to the SVG specs.- Parameters:
x- number to format- Returns:
- String representation
-
svgElement
public static org.w3c.dom.Element svgElement(org.w3c.dom.Document document, java.lang.String name)Create a SVG element in appropriate namespace- Parameters:
document- containing documentname- node name- Returns:
- new SVG element.
-
setAtt
public static void setAtt(org.w3c.dom.Element el, java.lang.String name, double d)Set a SVG attribute- Parameters:
el- elementname- attribute named- double value
-
setAtt
public static void setAtt(org.w3c.dom.Element el, java.lang.String name, int d)Set a SVG attribute- Parameters:
el- elementname- attribute named- integer value
-
setAtt
public static void setAtt(org.w3c.dom.Element el, java.lang.String name, java.lang.String d)Set a SVG attribute- Parameters:
el- elementname- attribute named- string value
-
setStyle
public static void setStyle(org.w3c.dom.Element el, java.lang.String d)Set a SVG style attribute- Parameters:
el- elementd- style value
-
setCSSClass
public static void setCSSClass(org.w3c.dom.Element e, java.lang.String cssclass)Set the CSS class of an Element. See alsoaddCSSClass(org.w3c.dom.Element, java.lang.String)andremoveCSSClass(org.w3c.dom.Element, java.lang.String).- Parameters:
e- Elementcssclass- class to set.
-
addCSSClass
public static void addCSSClass(org.w3c.dom.Element e, java.lang.String cssclass)Add a CSS class to an Element.- Parameters:
e- Elementcssclass- class to add.
-
removeCSSClass
public static void removeCSSClass(org.w3c.dom.Element e, java.lang.String cssclass)Remove a CSS class from an Element.- Parameters:
e- Elementcssclass- class to remove.
-
makeStyleElement
public static org.w3c.dom.Element makeStyleElement(org.w3c.dom.Document document)
Make a new CSS style element for the given Document.- Parameters:
document- document (factory)- Returns:
- new CSS style element.
-
svgRect
public static org.w3c.dom.Element svgRect(org.w3c.dom.Document document, double x, double y, double w, double h)Create a SVG rectangle element.- Parameters:
document- document to create in (factory)x- X coordinatey- Y coordinatew- Widthh- Height- Returns:
- new element
-
svgCircle
public static org.w3c.dom.Element svgCircle(org.w3c.dom.Document document, double cx, double cy, double r)Create a SVG circle element.- Parameters:
document- document to create in (factory)cx- center Xcy- center Yr- radius- Returns:
- new element
-
svgLine
public static org.w3c.dom.Element svgLine(org.w3c.dom.Document document, double x1, double y1, double x2, double y2)Create a SVG line element. Do not confuse this with path elements.- Parameters:
document- document to create in (factory)x1- first point xy1- first point yx2- second point xy2- second point y- Returns:
- new element
-
svgText
public static org.w3c.dom.Element svgText(org.w3c.dom.Document document, double x, double y, java.lang.String text)Create a SVG text element.- Parameters:
document- document to create in (factory)x- first point xy- first point ytext- Content of text element.- Returns:
- New text element.
-
svgWaitIcon
public static org.w3c.dom.Element svgWaitIcon(org.w3c.dom.Document document, double x, double y, double w, double h)Draw a simple "please wait" icon (in-progress) as placeholder for running renderings.- Parameters:
document- Document.x- Lefty- Topw- Widthh- Height- Returns:
- New element (currently a
SVGConstants.SVG_PATH_TAG)
-
stringToColor
public static java.awt.Color stringToColor(java.lang.String str)
Convert a color name from SVG syntax to an AWT color object.- Parameters:
str- Color name- Returns:
- Color value
-
colorToString
public static java.lang.String colorToString(java.awt.Color col)
Convert a color name from an AWT color object to CSS syntaxNote: currently only RGB (from ARGB order) are supported.
- Parameters:
col- Color value- Returns:
- Color string
-
colorToString
public static java.lang.String colorToString(int col)
Convert a color name from an integer RGB color to CSS syntaxNote: currently only RGB (from ARGB order) are supported. The alpha channel will be ignored.
- Parameters:
col- Color value- Returns:
- Color string
-
makeMarginTransform
public static java.lang.String makeMarginTransform(double owidth, double oheight, double iwidth, double iheight, double lmargin, double tmargin, double rmargin, double bmargin)Make a transform string to add margins- Parameters:
owidth- Width of outer (embedding) canvasoheight- Height of outer (embedding) canvasiwidth- Width of inner (embedded) canvasiheight- Height of inner (embedded) canvaslmargin- Left margin (in inner canvas' units)tmargin- Top margin (in inner canvas' units)rmargin- Right margin (in inner canvas' units)bmargin- Bottom margin (in inner canvas' units)- Returns:
- Transform string
-
makeMarginTransform
public static java.lang.String makeMarginTransform(double owidth, double oheight, double iwidth, double iheight, double xmargin, double ymargin)Make a transform string to add margins- Parameters:
owidth- Width of outer (embedding) canvasoheight- Height of outer (embedding) canvasiwidth- Width of inner (embedded) canvasiheight- Height of inner (embedded) canvasxmargin- Left and right margin (in inner canvas' units)ymargin- Top and bottom margin (in inner canvas' units)- Returns:
- Transform string
-
makeMarginTransform
public static java.lang.String makeMarginTransform(double owidth, double oheight, double iwidth, double iheight, double margin)Make a transform string to add margins- Parameters:
owidth- Width of outer (embedding) canvasoheight- Height of outer (embedding) canvasiwidth- Width of inner (embedded) canvasiheight- Height of inner (embedded) canvasmargin- Margin (in inner canvas' units)- Returns:
- Transform string
-
elementCoordinatesFromEvent
public static org.w3c.dom.svg.SVGPoint elementCoordinatesFromEvent(org.w3c.dom.Document doc, org.w3c.dom.Element tag, org.w3c.dom.events.Event evt)Convert the coordinates of an DOM Event from screen into element coordinates.- Parameters:
doc- Document contexttag- Element containing the coordinate systemevt- Event to interpret- Returns:
- coordinates
-
removeLastChild
public static void removeLastChild(org.w3c.dom.Element tag)
Remove last child of an element, when present- Parameters:
tag- Parent
-
removeFromParent
public static void removeFromParent(org.w3c.dom.Element elem)
Remove an element from its parent, if defined.- Parameters:
elem- Element to remove
-
svgCircleSegment
public static org.w3c.dom.Element svgCircleSegment(SVGPlot svgp, double centerx, double centery, double angleStart, double angleDelta, double innerRadius, double outerRadius)
Create a circle segment.- Parameters:
svgp- Plot to draw tocenterx- Center X positioncentery- Center Y positionangleStart- Starting angleangleDelta- Angle deltainnerRadius- inner radiusouterRadius- outer radius- Returns:
- SVG element representing this circle segment
-
-