Class Axis
- java.lang.Object
-
- org.faceless.graph2.Axis
-
public abstract class Axis extends Object
An Axis is what a
Series
is plotted against on anAxesGraph
. There are up to five Axes on anAxesGraph
, one on the bottom, left, top and right (and the Z-axis, which is a bit different), and each Series is plotted against two adjacent axes - bottom and left, top and right and so on.The Axis itself consists of a "spine", which has several "teeth" coming off it showing it's scale. These teeth usually have some text next to them, the format of which is controlled by the
format(double)
method, which (along with thesteps(double, double)
method) is commonly overridden by those wanting to create their own subclasses of Axis. The source code to theNumericAxis
andDateAxis
classes is supplied in the "docs" directory of the download package, which is where to start if you do plan on creating your own subclass.
-
-
Field Summary
Fields Modifier and Type Field Description static int
BOTTOM
A constant which can be passed intoAxesGraph.setAxis
to set the bottom axisstatic int
DENSITY_MINIMAL
A constant used by many subclasses of Axis to control how many teeth are placed on the graph.static int
DENSITY_NORMAL
A constant used by many subclasses of Axis to control how many teeth are placed on the graph.static int
DENSITY_SPARSE
A constant used by many subclasses of Axis to control how many teeth are placed on the graph.static int
LEFT
A constant which can be passed intoAxesGraph.setAxis
to set the left axisstatic int
RIGHT
A constant which can be passed intoAxesGraph.setAxis
to set the right axisstatic int
TOP
A constant which can be passed intoAxesGraph.setAxis
to set the top axisstatic int
ZAXIS
A constant which can be passed intoAxesGraph.setAxis
to set the Z-Axis.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract String
format(double in)
Given the specified number, return the text that should be placed against the tooth at that position.void
setLabel(String text, TextStyle style)
Set a label to be displayed next to the axis.void
setMaxValue(double max)
Set the maximum value to be plotted on the Axis.void
setMinValue(double min)
Set the minimum value to be plotted on the Axis.void
setSpineStyle(Style style)
Set the style used to draw the spine of the axis.void
setToothLength(double toothlength)
Set the length of the teeth that come off the spine of the axis.void
setToothTextStyle(TextStyle style)
Set the style used to draw the labels on the teeth.void
setWallPaint(Paint paint)
Set the paint to be used on the wall next to this axis.void
setWallPaint(Paint[] paints, Color color, double[] dash)
Set the paint to be used on the wall next to this axis to a series of stripes.void
setWallPaint(StripedPaint paint)
Set the paint to be used on the wall to aStripedPaint
void
setZeroIntersection(boolean zero)
Whether this axis should cross it's adjacent axis where that axis is zero.abstract double[]
steps(double min, double max)
Thesteps
method controls where the teeth are placed on the spine.String
toString()
-
-
-
Field Detail
-
DENSITY_NORMAL
public static final int DENSITY_NORMAL
A constant used by many subclasses of Axis to control how many teeth are placed on the graph. NORMAL results in about 8-10 teeth- See Also:
- Constant Field Values
-
DENSITY_SPARSE
public static final int DENSITY_SPARSE
A constant used by many subclasses of Axis to control how many teeth are placed on the graph. SPARSE results in about 4-5 teeth- See Also:
- Constant Field Values
-
DENSITY_MINIMAL
public static final int DENSITY_MINIMAL
A constant used by many subclasses of Axis to control how many teeth are placed on the graph. MINIMAL results in 2 or 3 teeth.- See Also:
- Constant Field Values
-
LEFT
public static final int LEFT
A constant which can be passed intoAxesGraph.setAxis
to set the left axis- See Also:
- Constant Field Values
-
RIGHT
public static final int RIGHT
A constant which can be passed intoAxesGraph.setAxis
to set the right axis- See Also:
- Constant Field Values
-
BOTTOM
public static final int BOTTOM
A constant which can be passed intoAxesGraph.setAxis
to set the bottom axis- See Also:
- Constant Field Values
-
TOP
public static final int TOP
A constant which can be passed intoAxesGraph.setAxis
to set the top axis- See Also:
- Constant Field Values
-
ZAXIS
public static final int ZAXIS
A constant which can be passed intoAxesGraph.setAxis
to set the Z-Axis.- See Also:
- Constant Field Values
-
-
Method Detail
-
setZeroIntersection
public void setZeroIntersection(boolean zero)
Whether this axis should cross it's adjacent axis where that axis is zero. Unless you're plotting negative values on the graph, this setting won't have any effect.- Parameters:
zero
- whether to cross the adjacent axis at zero. The default is false
-
setSpineStyle
public void setSpineStyle(Style style)
Set the style used to draw the spine of the axis.- Parameters:
style
- the style to draw the spine and teeth in - the default is a solid black line.
-
setToothLength
public void setToothLength(double toothlength)
Set the length of the teeth that come off the spine of the axis. The toothlength is a fraction of the width of the whole graph (as a guide, the default is 0.01) so a value between 0 (for no teeth) and 0.02 would be typical.- Parameters:
toothlength
- the length of the teeth as a proportion of the width of the graph. The default is 0.01
-
setToothTextStyle
public void setToothTextStyle(TextStyle style)
Set the style used to draw the labels on the teeth. The default is Black 10pt text in the Default font. Remember thesetPadding...
methods can be used to increase the space between the teeth and their text, and theTextStyle.setAlign(int)
method used to control the position of the text relative to the teeth.- Parameters:
style
- the style to display the teeth labels in.
-
setWallPaint
public void setWallPaint(Paint paint)
Set the paint to be used on the wall next to this axis. These walls run "into" the graph, so for graphs displayed only in 2D (ie. with noX-Rotation
orY-Rotation
these walls would be invisible.- Parameters:
paint
- the Paint to use on the wall running into the graph from this axis, ornull
to not paint the wall- See Also:
AxesGraph.setBackWallPaint(Paint)
-
setWallPaint
public void setWallPaint(Paint[] paints, Color color, double[] dash)
Set the paint to be used on the wall next to this axis to a series of stripes. The same as thesetWallPaint(Paint)
method, but can be used to draw stripes on the wall.- Parameters:
paints
- an Array ofPaint
objects which will be used to paint the wallcolor
- the color of the line to seperate the stripes, ornull
for no linedash
- an array of doubles specifying the dashing pattern for the line, ornull
if no line is drawn (or if it's not to be dashed)- Since:
- 2.4.6
- See Also:
AxesGraph.setBackWallPaint(Paint[]...)
-
setWallPaint
public void setWallPaint(StripedPaint paint)
Set the paint to be used on the wall to aStripedPaint
- Since:
- 2.4.6
-
steps
public abstract double[] steps(double min, double max)
The
steps
method controls where the teeth are placed on the spine. Each subclass of Axis has a different strategy - for instance, theDateAxis
will try and place ticks on the 1st of the month, theNumericAxis
will try and place them evenly across the range and so on.The returned array should consist of a range of numbers, ordered from low to high, which mark the locations of the teeth on the spine.
min
andmax
are the minimum and maximum values of the data to plot, and these values will usually be the first and last values in the returned array.Those wanting to create their own custom axis will typically override this method and
format(double)
.- Parameters:
min
- the minimum value of the data to plotmax
- the maximum value of the data to plot- Returns:
- an array of doubles representing the positions to place teeth on this axis
-
format
public abstract String format(double in)
Given the specified number, return the text that should be placed against the tooth at that position. For example, an Axis that simply plotted integer values might return
Integer.toString((int)in)
Those wanting to create their own custom axis will typically override this method and
steps(double, double)
.- Parameters:
in
- the value to format- Returns:
- the value formatted as a String
-
setLabel
public void setLabel(String text, TextStyle style)
Set a label to be displayed next to the axis. Users may want to play with theTextStyle.setPaddingBottom(double)
andTextStyle.setPaddingTop(double)
settings of the style to control the distance between the label and the axis.- Parameters:
text
- the text to displaystyle
- the style to draw the text in
-
setMinValue
public void setMinValue(double min)
Set the minimum value to be plotted on the Axis. If not set, this will default to the minimum value of all the Series plotted against this axis. LikesetMaxValue(double)
this value will be expanded if required to fit the values from the various series.- Parameters:
min
- the minimum value to plot on this axis
-
setMaxValue
public void setMaxValue(double max)
Set the maximum value to be plotted on the Axis. If not set, this will default to the maximum value of all the Series plotted against this axis. If this value is too small to fit the values from the series, it will be expanded - for example, if your series plots values from 0 to 10 and this is set to 5, it will be silently increased to 10 to accomodate the required range of values.- Parameters:
max
- the maximum value to plot on this axis
-
-