Class DateFormatter
- java.lang.Object
-
- org.faceless.graph.formatter.Formatter
-
- org.faceless.graph.formatter.DateFormatter
-
public class DateFormatter extends Formatter
A subclasss of
Formatter
that deals with dates and times.The Date formatter will select "useful" dates to plot on the axis that fall into the given timespan. The smallest unit this class can handle is the second, and it can be used to plot date ranges from between 2 seconds and a hundred years. The returned dates are those that we consider "sensible" depending on the range - for example, every 15 seconds, every day or the first of every quarter (the number of values returned can be set with the
Formatter.setDensity(int)
method). The start and end dates specified are always returned.In addition, because of the non-uniform spacing of days in the year (e.g. February 1st is 31 days after January 1st, but March 1st is only another 28 days) the spacing between entries may not be uniform. We felt this was less of a compromise than returning dates like
01-Jan
,01-Feb
,04-Mar
, but if you think otherwise then we would recommend writing a custom subclass ofFormatter
for complete control over the output.
-
-
Constructor Summary
Constructors Constructor Description DateFormatter()
Create a new DataFormatter with a format of "dd MMM yy"DateFormatter(int density)
Create a new DataFormatter with a format of "dd MMM yy" and the specified densityDateFormatter(java.text.DateFormat format)
Create a new DataFormatter with the specified formatDateFormatter(java.text.DateFormat format, int density)
Create a new DateFormatter with the specified format and density
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
format(double in)
Return a String that is the formatted version of the input parameter.double[]
steps(double min, double max)
Which steps between min and max should be marked on the axis.static java.util.Date
toDate(double in)
Convert a double to a Date.static double
toDouble(java.util.Date in)
Convert a date to a double, so it can be stored internally.-
Methods inherited from class org.faceless.graph.formatter.Formatter
fixMinMax, isDiscrete, setDensity, setFixedEnds
-
-
-
-
Constructor Detail
-
DateFormatter
public DateFormatter()
Create a new DataFormatter with a format of "dd MMM yy"
-
DateFormatter
public DateFormatter(int density)
Create a new DataFormatter with a format of "dd MMM yy" and the specified density- Parameters:
density
- the density of the formatter - one ofFormatter.NORMAL
,Formatter.SPARSE
orFormatter.MINIMAL
- Since:
- 1.0.5
-
DateFormatter
public DateFormatter(java.text.DateFormat format)
Create a new DataFormatter with the specified format- Parameters:
format
- TheDateFormat
to use.
-
DateFormatter
public DateFormatter(java.text.DateFormat format, int density)
Create a new DateFormatter with the specified format and density- Parameters:
format
- TheDateFormat
to use.density
- the density of the formatter - one ofFormatter.NORMAL
,Formatter.SPARSE
orFormatter.MINIMAL
- Since:
- 1.0.5
-
-
Method Detail
-
format
public java.lang.String format(double in)
Description copied from class:Formatter
Return a String that is the formatted version of the input parameter.
-
toDate
public static java.util.Date toDate(double in)
Convert a double to a Date. The opposite of toDouble(). Use this to convert a double passed in to the "format()" method back to a Date.
-
toDouble
public static double toDouble(java.util.Date in)
Convert a date to a double, so it can be stored internally. For example, to plot todays date on a Line Graph, you would do something like this:DataCurve data = new DataCurve(); Date today = new Date(); data.set(DateFormatter.toDouble(today), 123.45);
-
steps
public double[] steps(double min, double max)
Description copied from class:Formatter
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.
-
-