org.faceless.graph.formatter
Class DateFormatter

java.lang.Object
  extended by org.faceless.graph.formatter.Formatter
      extended by 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 of Formatter for complete control over the output.


Field Summary
 
Fields inherited from class org.faceless.graph.formatter.Formatter
MINIMAL, NORMAL, SPARSE
 
Constructor Summary
DateFormatter()
          Create a new DataFormatter with a format of "dd MMM yy"
DateFormatter(DateFormat format)
          Create a new DataFormatter with the specified format
DateFormatter(DateFormat format, int density)
          Create a new DateFormatter with the specified format and density
DateFormatter(int density)
          Create a new DataFormatter with a format of "dd MMM yy" and the specified density
 
Method Summary
 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 Date toDate(double in)
          Convert a double to a Date.
static double toDouble(Date in)
          Convert a date to a double, so it can be stored internally.
 
Methods inherited from class org.faceless.graph.formatter.Formatter
isDiscrete, setDensity, setFixedEnds
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 of Formatter.NORMAL, Formatter.SPARSE or Formatter.MINIMAL
Since:
1.0.5

DateFormatter

public DateFormatter(DateFormat format)
Create a new DataFormatter with the specified format

Parameters:
format - The DateFormat to use.

DateFormatter

public DateFormatter(DateFormat format,
                     int density)
Create a new DateFormatter with the specified format and density

Parameters:
format - The DateFormat to use.
density - the density of the formatter - one of Formatter.NORMAL, Formatter.SPARSE or Formatter.MINIMAL
Since:
1.0.5
Method Detail

format

public String format(double in)
Description copied from class: Formatter
Return a String that is the formatted version of the input parameter.

Specified by:
format in class Formatter

toDate

public static 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(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.

Overrides:
steps in class Formatter


Copyright © 2001-2012 Big Faceless Organization