Package com.storedobject.svg
Class Svg
java.lang.Object
com.storedobject.svg.Svg
- Direct Known Subclasses:
Canvas,Chart,Element,TransformedSvg
Base class for all SVG objects.
- Author:
- Syam
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classTransformer for anchoring an SVG to another one.static classTransformer for adding margins.static classTransformer for moving an SVG.static classTransformer for scaling by factors.static classTransformer for scaling to a specific size. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd another SVG at a specific displacement.Add another SVG at a specific point.Add another SVG to this one at a specified side.abstract voidbuild()Build the SVG.static StringEscape XML special characters in a string.Flip this SVG horizontally.Flip this SVG vertically.final StringGet the SVG output that fills its container (100% width and height).final doubleReturns the height of the SVG.final StringgetScaledSvg(double scaleWidthPercentage, double scaleHeightPercentage) Get the SVG output with specified scale percentages for width and height.final StringgetSvg()Get the SVG output using its default dimensions.final doublegetWidth()Returns the width of the SVG.final doublegetX()Returns the X coordinate.final doublegetY()Returns the Y coordinate.abstract booleanisBuilt()Check if the chart is built.margin(double margin) Add a margin to this SVG.Add a margin to this SVG on a specific side.scale(double scale) Scale this SVG by a specified factor.scale(double scaleX, double scaleY) Scale this SVG by specified factors.scaleTo(double newWidth, double newHeight) Scale this SVG to new dimensions.scaleToHeight(double newHeight) Scale this SVG to a new height.scaleToWidth(double newWidth) Scale this SVG to a new width.static StringtoString(double v, int decimals) Convert a double to string with specified decimal places and remove trailing zeros.
-
Field Details
-
svg
SVG content. This is typically set by the build() method. It should not contain the top level svg tag. -
x
protected double xCurrent x and y coordinates. These could be set to any value so that the final SVG output will be translated. -
y
protected double yCurrent x and y coordinates. These could be set to any value so that the final SVG output will be translated. -
width
protected double widthDefault size of the SVG. This could be set to any value so that the final SVG output will compute the view box using these values and the values of x and y. -
height
protected double heightDefault size of the SVG. This could be set to any value so that the final SVG output will compute the view box using these values and the values of x and y.
-
-
Constructor Details
-
Svg
public Svg()Default constructor for theSvgclass. Initializes a new instance of the SVG object with default properties.
-
-
Method Details
-
build
public abstract void build()Build the SVG. This method is called before getting the SVG output. -
isBuilt
public abstract boolean isBuilt()Check if the chart is built.- Returns:
- True if built.
-
getSvg
-
getFilledSvg
Get the SVG output that fills its container (100% width and height).- Returns:
- SVG string.
-
getScaledSvg
Get the SVG output with specified scale percentages for width and height.- Parameters:
scaleWidthPercentage- Scale percentage for width (0 to 100).scaleHeightPercentage- Scale percentage for height (0 to 100).- Returns:
- SVG string.
-
toString
Convert a double to string with specified decimal places and remove trailing zeros.- Parameters:
v- Value.decimals- Number of decimal places.- Returns:
- Formatted string.
-
escapeXml
-
getWidth
public final double getWidth()Returns the width of the SVG. This is the same as the view box width if x and y are 0.- Returns:
- The width of the SVG.
-
getHeight
public final double getHeight()Returns the height of the SVG. This is the same as the view box height if x and y are 0.- Returns:
- The height of the SVG.
-
getX
public final double getX()Returns the X coordinate.- Returns:
- The X coordinate.
-
getY
public final double getY()Returns the Y coordinate.- Returns:
- The Y coordinate.
-
margin
-
margin
-
add
-
add
-
add
-
scaleToWidth
-
scaleToHeight
-
scaleTo
-
scale
-
scale
-
flipHorizontally
-
flipVertically
-