Class Formatter
- java.lang.Object
-
- org.faceless.graph.formatter.Formatter
-
- Direct Known Subclasses:
CurrencyFormatter
,DateFormatter
,DiscreteFormatter
,FloatingPointFormatter
,IntegerFormatter
,NullFormatter
,PercentageFormatter
,SimpleFormatter
public abstract class Formatter extends java.lang.Object
A
Formatter
controls how the values displayed on the axis of a graph are displayed - as integers, floating point, percentages, dates etc.Several concrete subclasses are provided which allow for easy graphing of integers, floats, percentages, dates and discrete values (like the names of the bars in a bar graph). The class can easily be overridden however to allow just about anything to be used as an axis value.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
density
static int
MINIMAL
Passed to thesetDensity(int)
method to set the number of ticks returned by this formatter to a "minimal" level - depending on the data and formatter between 3 and 4 points.static int
NORMAL
Passed to thesetDensity(int)
method to set the number of ticks returned by this formatter to a "normal" level - depending on the data and formatter, between about 8 and 14 points.static int
SPARSE
Passed to thesetDensity(int)
method to set the number of ticks returned by this formatter to a "sparse" level - depending on the data and formatter, between about 4 and 7 points.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Formatter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected double[]
fixMinMax(double[] out, double min, double max, double ss)
abstract java.lang.String
format(double in)
Return a String that is the formatted version of the input parameter.boolean
isDiscrete()
If this formatter is for formatting discrete values.void
setDensity(int density)
Set the "density" of the formatter - the number of ticks it asks to be printed on the axis.void
setFixedEnds(boolean fixed)
Cause the ends of the axes to be fixed to the min and max values of the data.double[]
steps(double min, double max)
Which steps between min and max should be marked on the axis.
-
-
-
Field Detail
-
density
protected int density
-
NORMAL
public static final int NORMAL
Passed to thesetDensity(int)
method to set the number of ticks returned by this formatter to a "normal" level - depending on the data and formatter, between about 8 and 14 points.- See Also:
- Constant Field Values
-
SPARSE
public static final int SPARSE
Passed to thesetDensity(int)
method to set the number of ticks returned by this formatter to a "sparse" level - depending on the data and formatter, between about 4 and 7 points.- See Also:
- Constant Field Values
-
MINIMAL
public static final int MINIMAL
Passed to thesetDensity(int)
method to set the number of ticks returned by this formatter to a "minimal" level - depending on the data and formatter between 3 and 4 points.- See Also:
- Constant Field Values
-
-
Method Detail
-
setDensity
public void setDensity(int density)
Set the "density" of the formatter - the number of ticks it asks to be printed on the axis. Valid values are either
NORMAL
(the default),SPARSE
orMINIMAL
Whether the subclass of formatter uses or ignores this value is down to it's implementation.
- Parameters:
the
- density of the formatter- Since:
- 1.0.5
-
setFixedEnds
public void setFixedEnds(boolean fixed)
Cause the ends of the axes to be fixed to the min and max values of the data. When this value is set to false, plotting data from (say) 31 to 78 would probably result in an axis that ran from 30 to 80. When this value is set to true, the axes will always start and end at the end of the data - 31 to 78 in this case. The default is false, except for the X-axis on area graphs, which default to true
- Since:
- 1.1.5
-
format
public abstract java.lang.String format(double in)
Return a String that is the formatted version of the input parameter.
-
isDiscrete
public boolean isDiscrete()
If this formatter is for formatting discrete values. This returns false, which is true for every one of it's subclasses except theDiscreteFormatter
, which overrides this method
-
steps
public double[] steps(double min, double max)
Which steps between min and max should be marked on the axis. This is an array because although the steps will usually be evenly spaced, they may not always be (see the
DateFormatter
for an example).This method returns the default settings, which is to calculate a number of "useful" values between min and max, possibly rounding those two values up or down to fit the scale. The number of values returned depends on the density setting.
-
fixMinMax
protected final double[] fixMinMax(double[] out, double min, double max, double ss)
-
-