lt.monarch.chart.mapper
Class LogMathRange

java.lang.Object
  extended by lt.monarch.chart.mapper.LogMathRange
All Implemented Interfaces:
java.io.Serializable, Range<java.lang.Double>

public class LogMathRange
extends java.lang.Object
implements Range<java.lang.Double>, java.io.Serializable

Manages a range of double values. Any value passed to this class is converted to logarithm of a given value. So this class can work with large ranges.

See Also:
LogAxisRange, Serialized Form

Field Summary
Modifier and Type Field and Description
protected  double base
          Logarithm base
protected  double firstMark
           
protected  double max
           
protected  double min
           
protected  double precision
           
protected  int precisionPlaces
           
protected  double requestedMax
           
protected  double requestedMin
           
protected  double step
          Used for steps determination
protected  int steps
           
 
Constructor Summary
Constructor and Description
LogMathRange(double min, double max)
          Creates the logarithmic mathematical range with specified smallest and biggest values.
LogMathRange(double min, double max, double base)
          Creates the logarithmical mathematical range with specified smallest and biggest range values and logarithm base.
 
Method Summary
Modifier and Type Method and Description
 void adjustRange()
          Updates and adjusts range.
 void adjustStep()
          Adjusts the step to the specified range
protected  void determineStepCount()
          Determines count of steps in the range
protected  double findFirstMark()
          Finds the first mark in the range
 java.lang.String format(double val)
          Returns a string representation of the specified double value.
 double getBase()
          Returns base of logarithm used in the range.
 double getFirstMark()
          Returns the value of the first mark in the range.
 java.text.DecimalFormat getLastNumberFormat()
          Gets the lastNumberFormat value
 java.lang.Double getMaximum()
          Gets the end (biggest value) of the range.
 java.lang.Double getMinimum()
          Gets the beginning of the range.
 int getPrecisionPlaces()
          Gets the precision places
 double getRange()
          Returns the width of the range.
 double getStep()
          Returns step.
 int getStepCount()
          Returns the step count in the range.
 boolean inRange(double v)
          Checks if v is in the range.
protected  double lg(double x)
          Returns the logarithm of a double value.
 double map(double value)
          Finds the position for the value in the range.
 double mapBack(double pos)
          Converts the position in the range axis to the double value.
 void setBase(double base)
          Set base of logarithm used in the range.
 void setPrecisionPlaces(int places)
          Sets precision places for this range.
 void setRange(double min, double max)
          Sets the range for this LogMathRange object.
 void setRange(Range<java.lang.Double> r)
          Sets the range for this LogMathRange object.
 void setRangeMinimum(double m)
          Sets the beginning of the range.
 void setStep(double step)
          Sets a step size for this range.
 void updateRange(double d)
          Updates the range so that d will be in the range.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

min

protected double min

max

protected double max

firstMark

protected double firstMark

requestedMin

protected double requestedMin

requestedMax

protected double requestedMax

step

protected double step
Used for steps determination


steps

protected int steps

precisionPlaces

protected int precisionPlaces

precision

protected double precision

base

protected double base
Logarithm base

Constructor Detail

LogMathRange

public LogMathRange(double min,
                    double max)
Creates the logarithmic mathematical range with specified smallest and biggest values.

Parameters:
min - The smallest range value
max - The biggest range value
Throws:
java.lang.IllegalArgumentException - if min >= max or min <= 0

LogMathRange

public LogMathRange(double min,
                    double max,
                    double base)
Creates the logarithmical mathematical range with specified smallest and biggest range values and logarithm base.

Parameters:
min - The smallest range value
max - The biggest range value
base -
Throws:
java.lang.IllegalArgumentException - if min >= max, min <= 0 or base <= 0
Method Detail

lg

protected double lg(double x)
Returns the logarithm of a double value. A base of the logarithm is specified with the setBase method.

Parameters:
x - a number greater than 0.0
Returns:
if x <= 0 returns Double.NaN, otherwise - the logarithm of x

setRange

public void setRange(double min,
                     double max)
Sets the range for this LogMathRange object.

Parameters:
min - The new smallest range value
max - The new biggest range value
Throws:
java.lang.IllegalArgumentException - if min >= max or min <= 0

setRange

public void setRange(Range<java.lang.Double> r)
Sets the range for this LogMathRange object. The range is specified as other Range object.

Parameters:
r - The new range
See Also:
Range

setRangeMinimum

public void setRangeMinimum(double m)
Sets the beginning of the range.

Parameters:
m - The new beginning of the range

getMinimum

public java.lang.Double getMinimum()
Gets the beginning of the range.

Specified by:
getMinimum in interface Range<java.lang.Double>
Returns:
The beginning of the range

getMaximum

public java.lang.Double getMaximum()
Gets the end (biggest value) of the range.

Specified by:
getMaximum in interface Range<java.lang.Double>
Returns:
The end of the range

getStepCount

public final int getStepCount()
Returns the step count in the range. All steps in this range are different. For example if range would be [10, 10000] and base is set to 10 then range would be subdivided so: {10, 100, 1000, 10000} and this method will return value 4.

Returns:
The number of steps

getStep

public final double getStep()
Returns step.

Returns:
The step

getRange

public final double getRange()
Returns the width of the range.

Returns:
The width of the range

getFirstMark

public final double getFirstMark()
Returns the value of the first mark in the range.

Returns:
The value of the first mark

updateRange

public void updateRange(double d)
Updates the range so that d will be in the range. Parameter d must be greater than 0.

Parameters:
d - double value
Throws:
java.lang.IllegalArgumentException - if d <= 0.

map

public double map(double value)
Finds the position for the value in the range. Parameter d must be greater than 0.

Parameters:
value - double value
Returns:
The position of the value in the range
Throws:
java.lang.IllegalArgumentException - if value <= 0.

mapBack

public double mapBack(double pos)
Converts the position in the range axis to the double value.

Parameters:
pos - Position in the range. Must be in range [0,1]
Returns:
double value that corresponds to the position in the range

adjustRange

public void adjustRange()
Updates and adjusts range.


inRange

public final boolean inRange(double v)
Checks if v is in the range.

Parameters:
v - double value
Returns:
true - if v is in the range, false - otherwise
Throws:
java.lang.IllegalArgumentException - if v <= 0

findFirstMark

protected double findFirstMark()
Finds the first mark in the range

Returns:
first mark in the range

determineStepCount

protected void determineStepCount()
Determines count of steps in the range


getBase

public double getBase()
Returns base of logarithm used in the range.

Returns:
base of logarithm.

setBase

public void setBase(double base)
Set base of logarithm used in the range.

Parameters:
base - base of logarithm.
Throws:
java.lang.IllegalArgumentException - if base <= 0

format

public java.lang.String format(double val)
Returns a string representation of the specified double value. The double value is rounded using precision of the range.

Parameters:
val - the double value to format.
Returns:
string representation of the double value.
See Also:
setPrecisionPlaces(int)

setPrecisionPlaces

public void setPrecisionPlaces(int places)
Sets precision places for this range. Minimum, maximum and step of this range are rounded. The precision is used for rounding operations. Positive precision number means that after comma the number is rounded. The negative precision places means that number is rounded to integer values e.g. we supply -2 for number 218, the result 2

Parameters:
places - the number of precision places

setStep

public void setStep(double step)
Sets a step size for this range. First mark, number of steps and number of precision places are updated.

Parameters:
step - the step size; a number greater than 0.0.

adjustStep

public void adjustStep()
Adjusts the step to the specified range


getPrecisionPlaces

public int getPrecisionPlaces()
Gets the precision places

Returns:
Returns the precision places.

getLastNumberFormat

public java.text.DecimalFormat getLastNumberFormat()
Gets the lastNumberFormat value

Returns:
the lastNumberFormat value