Package elki.visualization.svg
Class SVGPath
- java.lang.Object
-
- elki.visualization.svg.SVGPath
-
public class SVGPath extends java.lang.ObjectElement used for building an SVG path using a string buffer.- Since:
- 0.3
- Author:
- Erich Schubert
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringBuilderbufString buffer for building the path.private charlastactionThe last action we did, to not add unnecessary commandsstatic charPATH_ARCAbsolute path arc command.static charPATH_ARC_RELATIVERelative path arc command.static charPATH_CLOSEClose path command.static charPATH_CUBIC_TOAbsolute cubic line to command.static charPATH_CUBIC_TO_RELATIVERelative cubic line to command.static charPATH_HORIZONTAL_LINE_TOAbsolute horizontal line to command.static charPATH_HORIZONTAL_LINE_TO_RELATIVERelative horizontal line to command.static charPATH_LINE_TOAbsolute line to command.static charPATH_LINE_TO_RELATIVERelative line to command.static charPATH_MOVEAbsolute move command.static charPATH_MOVE_RELATIVERelative move command.static charPATH_QUAD_TOAbsolute quadratic interpolation to command.static charPATH_QUAD_TO_RELATIVERelative quadratic interpolation to command.static charPATH_SMOOTH_CUBIC_TOAbsolute "smooth cubic to" SVG path command.static charPATH_SMOOTH_CUBIC_TO_RELATIVERelative smooth cubic to command.static charPATH_SMOOTH_QUAD_TOAbsolute smooth quadratic interpolation to command.static charPATH_SMOOTH_QUAD_TO_RELATIVERelative smooth quadratic interpolation to command.static charPATH_VERTICAL_LINE_TOAbsolute vertical line to command.static charPATH_VERTICAL_LINE_TO_RELATIVERelative vertical line to command.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private SVGPathappend(char action)Append an action to the current path.private SVGPathappend(double x)Append a value to the current path.SVGPathclose()Close the path.SVGPathcubicTo(double[] c1xy, double[] c2xy, double[] xy)Cubic Bezier line to the given coordinates.SVGPathcubicTo(double c1x, double c1y, double c2x, double c2y, double x, double y)Cubic Bezier line to the given coordinates.SVGPathdrawTo(double[] xy)Draw a line given a series of coordinates.SVGPathdrawTo(double x, double y)Draw a line given a series of coordinates.SVGPathellipticalArc(double[] rxy, double ar, double la, double sp, double[] xy)Elliptical arc curve to the given coordinates.SVGPathellipticalArc(double rx, double ry, double ar, double la, double sp, double[] xy)Elliptical arc curve to the given coordinates.SVGPathellipticalArc(double rx, double ry, double ar, double la, double sp, double x, double y)Elliptical arc curve to the given coordinates.SVGPathhorizontalLineTo(double x)Draw a horizontal line to the given x coordinate.booleanisStarted()Test whether the path drawing has already started.SVGPathlineTo(double[] xy)Draw a line to the given coordinates.SVGPathlineTo(double x, double y)Draw a line to the given coordinates.org.w3c.dom.ElementmakeElement(SVGPlot plot)Turn the path buffer into an SVG element.org.w3c.dom.ElementmakeElement(SVGPlot plot, java.lang.String cssclass)Turn the path buffer into an SVG element.SVGPathmoveTo(double[] xy)Move to the given coordinates.SVGPathmoveTo(double x, double y)Move to the given coordinates.SVGPathquadTo(double[] c1xy, double[] xy)Quadratic Bezier line to the given coordinates.SVGPathquadTo(double c1x, double c1y, double x, double y)Quadratic Bezier line to the given coordinates.SVGPathrelativeCubicTo(double[] c1xy, double[] c2xy, double[] xy)Cubic Bezier line to the given relative coordinates.SVGPathrelativeCubicTo(double c1x, double c1y, double c2x, double c2y, double x, double y)Cubic Bezier line to the given relative coordinates.SVGPathrelativeEllipticalArc(double[] rxy, double ar, double la, double sp, double[] xy)Elliptical arc curve to the given relative coordinates.SVGPathrelativeEllipticalArc(double rx, double ry, double ar, double la, double sp, double[] xy)Elliptical arc curve to the given relative coordinates.SVGPathrelativeEllipticalArc(double rx, double ry, double ar, double la, double sp, double x, double y)Elliptical arc curve to the given relative coordinates.SVGPathrelativeHorizontalLineTo(double x)Draw a horizontal line to the given relative x coordinate.SVGPathrelativeLineTo(double[] xy)Draw a line to the given relative coordinates.SVGPathrelativeLineTo(double x, double y)Draw a line to the given relative coordinates.SVGPathrelativeMoveTo(double[] xy)Move to the given relative coordinates.SVGPathrelativeMoveTo(double x, double y)Move to the given relative coordinates.SVGPathrelativeQuadTo(double[] c1xy, double[] xy)Quadratic Bezier line to the given relative coordinates.SVGPathrelativeQuadTo(double c1x, double c1y, double x, double y)Quadratic Bezier line to the given relative coordinates.SVGPathrelativeSmoothCubicTo(double[] c2xy, double[] xy)Smooth Cubic Bezier line to the given relative coordinates.SVGPathrelativeSmoothCubicTo(double c2x, double c2y, double x, double y)Smooth Cubic Bezier line to the given relative coordinates.SVGPathrelativeSmoothQuadTo(double[] xy)Smooth quadratic Bezier line to the given relative coordinates.SVGPathrelativeSmoothQuadTo(double x, double y)Smooth quadratic Bezier line to the given relative coordinates.SVGPathrelativeVerticalLineTo(double y)Draw a vertical line to the given relative y coordinate.SVGPathsmoothCubicTo(double[] c2xy, double[] xy)Smooth Cubic Bezier line to the given coordinates.SVGPathsmoothCubicTo(double c2x, double c2y, double x, double y)Smooth Cubic Bezier line to the given coordinates.SVGPathsmoothQuadTo(double[] xy)Smooth quadratic Bezier line to the given coordinates.SVGPathsmoothQuadTo(double x, double y)Smooth quadratic Bezier line to the given coordinates.java.lang.StringtoString()Return the SVG serialization of the path.SVGPathverticalLineTo(double y)Draw a vertical line to the given y coordinate.
-
-
-
Field Detail
-
buf
private java.lang.StringBuilder buf
String buffer for building the path.
-
lastaction
private char lastaction
The last action we did, to not add unnecessary commands
-
PATH_CLOSE
public static final char PATH_CLOSE
Close path command.- See Also:
- Constant Field Values
-
PATH_LINE_TO
public static final char PATH_LINE_TO
Absolute line to command.- See Also:
- Constant Field Values
-
PATH_LINE_TO_RELATIVE
public static final char PATH_LINE_TO_RELATIVE
Relative line to command.- See Also:
- Constant Field Values
-
PATH_MOVE
public static final char PATH_MOVE
Absolute move command.- See Also:
- Constant Field Values
-
PATH_MOVE_RELATIVE
public static final char PATH_MOVE_RELATIVE
Relative move command.- See Also:
- Constant Field Values
-
PATH_HORIZONTAL_LINE_TO
public static final char PATH_HORIZONTAL_LINE_TO
Absolute horizontal line to command.- See Also:
- Constant Field Values
-
PATH_HORIZONTAL_LINE_TO_RELATIVE
public static final char PATH_HORIZONTAL_LINE_TO_RELATIVE
Relative horizontal line to command.- See Also:
- Constant Field Values
-
PATH_VERTICAL_LINE_TO
public static final char PATH_VERTICAL_LINE_TO
Absolute vertical line to command.- See Also:
- Constant Field Values
-
PATH_VERTICAL_LINE_TO_RELATIVE
public static final char PATH_VERTICAL_LINE_TO_RELATIVE
Relative vertical line to command.- See Also:
- Constant Field Values
-
PATH_CUBIC_TO
public static final char PATH_CUBIC_TO
Absolute cubic line to command.- See Also:
- Constant Field Values
-
PATH_CUBIC_TO_RELATIVE
public static final char PATH_CUBIC_TO_RELATIVE
Relative cubic line to command.- See Also:
- Constant Field Values
-
PATH_SMOOTH_CUBIC_TO
public static final char PATH_SMOOTH_CUBIC_TO
Absolute "smooth cubic to" SVG path command.- See Also:
- Constant Field Values
-
PATH_SMOOTH_CUBIC_TO_RELATIVE
public static final char PATH_SMOOTH_CUBIC_TO_RELATIVE
Relative smooth cubic to command.- See Also:
- Constant Field Values
-
PATH_QUAD_TO
public static final char PATH_QUAD_TO
Absolute quadratic interpolation to command.- See Also:
- Constant Field Values
-
PATH_QUAD_TO_RELATIVE
public static final char PATH_QUAD_TO_RELATIVE
Relative quadratic interpolation to command.- See Also:
- Constant Field Values
-
PATH_SMOOTH_QUAD_TO
public static final char PATH_SMOOTH_QUAD_TO
Absolute smooth quadratic interpolation to command.- See Also:
- Constant Field Values
-
PATH_SMOOTH_QUAD_TO_RELATIVE
public static final char PATH_SMOOTH_QUAD_TO_RELATIVE
Relative smooth quadratic interpolation to command.- See Also:
- Constant Field Values
-
PATH_ARC
public static final char PATH_ARC
Absolute path arc command.- See Also:
- Constant Field Values
-
PATH_ARC_RELATIVE
public static final char PATH_ARC_RELATIVE
Relative path arc command.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SVGPath
public SVGPath()
Empty path constructor.
-
SVGPath
public SVGPath(double x, double y)Constructor with initial point.- Parameters:
x- initial coordinatesy- initial coordinates
-
SVGPath
public SVGPath(double[] xy)
Constructor with initial point.- Parameters:
xy- initial coordinates
-
SVGPath
public SVGPath(Polygon vectors)
Constructor from a double[] collection (e.g., a polygon)- Parameters:
vectors- vectors
-
-
Method Detail
-
drawTo
public SVGPath drawTo(double x, double y)
Draw a line given a series of coordinates.Helper function that will use "move" for the first point, "lineto" for the remaining.
- Parameters:
x- new coordinatesy- new coordinates- Returns:
- path object, for compact syntax.
-
drawTo
public SVGPath drawTo(double[] xy)
Draw a line given a series of coordinates.Helper function that will use "move" for the first point, "lineto" for the remaining.
- Parameters:
xy- new coordinates- Returns:
- path object, for compact syntax.
-
isStarted
public boolean isStarted()
Test whether the path drawing has already started.- Returns:
- Path freshness
-
lineTo
public SVGPath lineTo(double x, double y)
Draw a line to the given coordinates.- Parameters:
x- new coordinatesy- new coordinates- Returns:
- path object, for compact syntax.
-
lineTo
public SVGPath lineTo(double[] xy)
Draw a line to the given coordinates.- Parameters:
xy- new coordinates- Returns:
- path object, for compact syntax.
-
relativeLineTo
public SVGPath relativeLineTo(double x, double y)
Draw a line to the given relative coordinates.- Parameters:
x- relative coordinatesy- relative coordinates- Returns:
- path object, for compact syntax.
-
relativeLineTo
public SVGPath relativeLineTo(double[] xy)
Draw a line to the given relative coordinates.- Parameters:
xy- new coordinates- Returns:
- path object, for compact syntax.
-
horizontalLineTo
public SVGPath horizontalLineTo(double x)
Draw a horizontal line to the given x coordinate.- Parameters:
x- new coordinates- Returns:
- path object, for compact syntax.
-
relativeHorizontalLineTo
public SVGPath relativeHorizontalLineTo(double x)
Draw a horizontal line to the given relative x coordinate.- Parameters:
x- new coordinates- Returns:
- path object, for compact syntax.
-
verticalLineTo
public SVGPath verticalLineTo(double y)
Draw a vertical line to the given y coordinate.- Parameters:
y- new coordinate- Returns:
- path object, for compact syntax.
-
relativeVerticalLineTo
public SVGPath relativeVerticalLineTo(double y)
Draw a vertical line to the given relative y coordinate.- Parameters:
y- new coordinate- Returns:
- path object, for compact syntax.
-
moveTo
public SVGPath moveTo(double x, double y)
Move to the given coordinates.- Parameters:
x- new coordinatesy- new coordinates- Returns:
- path object, for compact syntax.
-
moveTo
public SVGPath moveTo(double[] xy)
Move to the given coordinates.- Parameters:
xy- new coordinates- Returns:
- path object, for compact syntax.
-
relativeMoveTo
public SVGPath relativeMoveTo(double x, double y)
Move to the given relative coordinates.- Parameters:
x- new coordinatesy- new coordinates- Returns:
- path object, for compact syntax.
-
relativeMoveTo
public SVGPath relativeMoveTo(double[] xy)
Move to the given relative coordinates.- Parameters:
xy- new coordinates- Returns:
- path object, for compact syntax.
-
cubicTo
public SVGPath cubicTo(double c1x, double c1y, double c2x, double c2y, double x, double y)
Cubic Bezier line to the given coordinates.- Parameters:
c1x- first control point xc1y- first control point yc2x- second control point xc2y- second control point yx- new coordinatesy- new coordinates- Returns:
- path object, for compact syntax.
-
cubicTo
public SVGPath cubicTo(double[] c1xy, double[] c2xy, double[] xy)
Cubic Bezier line to the given coordinates.- Parameters:
c1xy- first control pointc2xy- second control pointxy- new coordinates- Returns:
- path object, for compact syntax.
-
relativeCubicTo
public SVGPath relativeCubicTo(double c1x, double c1y, double c2x, double c2y, double x, double y)
Cubic Bezier line to the given relative coordinates.- Parameters:
c1x- first control point xc1y- first control point yc2x- second control point xc2y- second control point yx- new coordinatesy- new coordinates- Returns:
- path object, for compact syntax.
-
relativeCubicTo
public SVGPath relativeCubicTo(double[] c1xy, double[] c2xy, double[] xy)
Cubic Bezier line to the given relative coordinates.- Parameters:
c1xy- first control pointc2xy- second control pointxy- new coordinates- Returns:
- path object, for compact syntax.
-
smoothCubicTo
public SVGPath smoothCubicTo(double c2x, double c2y, double x, double y)
Smooth Cubic Bezier line to the given coordinates.- Parameters:
c2x- second control point xc2y- second control point yx- new coordinatesy- new coordinates- Returns:
- path object, for compact syntax.
-
smoothCubicTo
public SVGPath smoothCubicTo(double[] c2xy, double[] xy)
Smooth Cubic Bezier line to the given coordinates.- Parameters:
c2xy- second control pointxy- new coordinates- Returns:
- path object, for compact syntax.
-
relativeSmoothCubicTo
public SVGPath relativeSmoothCubicTo(double c2x, double c2y, double x, double y)
Smooth Cubic Bezier line to the given relative coordinates.- Parameters:
c2x- second control point xc2y- second control point yx- new coordinatesy- new coordinates- Returns:
- path object, for compact syntax.
-
relativeSmoothCubicTo
public SVGPath relativeSmoothCubicTo(double[] c2xy, double[] xy)
Smooth Cubic Bezier line to the given relative coordinates.- Parameters:
c2xy- second control pointxy- new coordinates- Returns:
- path object, for compact syntax.
-
quadTo
public SVGPath quadTo(double c1x, double c1y, double x, double y)
Quadratic Bezier line to the given coordinates.- Parameters:
c1x- first control point xc1y- first control point yx- new coordinatesy- new coordinates- Returns:
- path object, for compact syntax.
-
quadTo
public SVGPath quadTo(double[] c1xy, double[] xy)
Quadratic Bezier line to the given coordinates.- Parameters:
c1xy- first control pointxy- new coordinates- Returns:
- path object, for compact syntax.
-
relativeQuadTo
public SVGPath relativeQuadTo(double c1x, double c1y, double x, double y)
Quadratic Bezier line to the given relative coordinates.- Parameters:
c1x- first control point xc1y- first control point yx- new coordinatesy- new coordinates- Returns:
- path object, for compact syntax.
-
relativeQuadTo
public SVGPath relativeQuadTo(double[] c1xy, double[] xy)
Quadratic Bezier line to the given relative coordinates.- Parameters:
c1xy- first control pointxy- new coordinates- Returns:
- path object, for compact syntax.
-
smoothQuadTo
public SVGPath smoothQuadTo(double x, double y)
Smooth quadratic Bezier line to the given coordinates.- Parameters:
x- new coordinatesy- new coordinates- Returns:
- path object, for compact syntax.
-
smoothQuadTo
public SVGPath smoothQuadTo(double[] xy)
Smooth quadratic Bezier line to the given coordinates.- Parameters:
xy- new coordinates- Returns:
- path object, for compact syntax.
-
relativeSmoothQuadTo
public SVGPath relativeSmoothQuadTo(double x, double y)
Smooth quadratic Bezier line to the given relative coordinates.- Parameters:
x- new coordinatesy- new coordinates- Returns:
- path object, for compact syntax.
-
relativeSmoothQuadTo
public SVGPath relativeSmoothQuadTo(double[] xy)
Smooth quadratic Bezier line to the given relative coordinates.- Parameters:
xy- new coordinates- Returns:
- path object, for compact syntax.
-
ellipticalArc
public SVGPath ellipticalArc(double rx, double ry, double ar, double la, double sp, double x, double y)
Elliptical arc curve to the given coordinates.- Parameters:
rx- x radiusry- y radiusar- x-axis-rotationla- large arc flag, if angle >= 180 degsp- sweep flag, if arc will be drawn in positive-angle directionx- new coordinatesy- new coordinates
-
ellipticalArc
public SVGPath ellipticalArc(double rx, double ry, double ar, double la, double sp, double[] xy)
Elliptical arc curve to the given coordinates.- Parameters:
rx- x radiusry- y radiusar- x-axis-rotationla- large arc flag, if angle >= 180 degsp- sweep flag, if arc will be drawn in positive-angle directionxy- new coordinates
-
ellipticalArc
public SVGPath ellipticalArc(double[] rxy, double ar, double la, double sp, double[] xy)
Elliptical arc curve to the given coordinates.- Parameters:
rxy- radiusar- x-axis-rotationla- large arc flag, if angle >= 180 degsp- sweep flag, if arc will be drawn in positive-angle directionxy- new coordinates
-
relativeEllipticalArc
public SVGPath relativeEllipticalArc(double rx, double ry, double ar, double la, double sp, double x, double y)
Elliptical arc curve to the given relative coordinates.- Parameters:
rx- x radiusry- y radiusar- x-axis-rotationla- large arc flag, if angle >= 180 degsp- sweep flag, if arc will be drawn in positive-angle directionx- new coordinatesy- new coordinates
-
relativeEllipticalArc
public SVGPath relativeEllipticalArc(double rx, double ry, double ar, double la, double sp, double[] xy)
Elliptical arc curve to the given relative coordinates.- Parameters:
rx- x radiusry- y radiusar- x-axis-rotationla- large arc flag, if angle >= 180 degsp- sweep flag, if arc will be drawn in positive-angle directionxy- new coordinates
-
relativeEllipticalArc
public SVGPath relativeEllipticalArc(double[] rxy, double ar, double la, double sp, double[] xy)
Elliptical arc curve to the given relative coordinates.- Parameters:
rxy- radiusar- x-axis-rotationla- large arc flag, if angle >= 180 degsp- sweep flag, if arc will be drawn in positive-angle directionxy- new coordinates
-
append
private SVGPath append(char action)
Append an action to the current path.- Parameters:
action- Current action
-
append
private SVGPath append(double x)
Append a value to the current path.- Parameters:
x- coordinate.
-
close
public SVGPath close()
Close the path.- Returns:
- path object, for compact syntax.
-
makeElement
public org.w3c.dom.Element makeElement(SVGPlot plot)
Turn the path buffer into an SVG element.- Parameters:
plot- Plot context (= element factory)- Returns:
- SVG Element
-
makeElement
public org.w3c.dom.Element makeElement(SVGPlot plot, java.lang.String cssclass)
Turn the path buffer into an SVG element.- Parameters:
plot- Plot context (= element factory)cssclass- CSS class- Returns:
- SVG Element
-
toString
public java.lang.String toString()
Return the SVG serialization of the path.- Overrides:
toStringin classjava.lang.Object
-
-