lt.monarch.chart.mapper
Class MathAxisMapper

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

public class MathAxisMapper
extends AnalogAxisMapper<Range<java.lang.Double>>

Numeric axis mapper.

See Also:
Serialized Form

Field Summary
Modifier and Type Field and Description
protected  AxisMapperRange mapperRange
          the axis mapper range
protected  NormalizedMathRange totalRange
          the total range
protected  NormalizedMathRange visibleRange
          the visible range
 
Constructor Summary
Constructor and Description
MathAxisMapper()
          Constructs a new MathAxisMapper with the normalized range [0; 1].
MathAxisMapper(double min, double max)
          Constructs a new MathAxisMapper with the specified range.
MathAxisMapper(double min, double max, AxisMapperRange mapperRange)
          Constructs a new MathAxisMapper with the specified mapping range and the specified visible range.
 
Method Summary
Modifier and Type Method and Description
protected  void adjustRange(NormalizedMathRange range)
          Adjusts the specified normalized mathematical range.
protected  AnalogAxisScale createScale()
          Creates and returns a new AxisScale for this axis.
 java.lang.String formatKey(java.lang.Object key)
          Formats the specified key.
protected  java.text.Format[] getFormats()
          Gets axis mapper formats.
 java.text.NumberFormat getNumberFormat()
          Gets mapper's NumberFormat.
 Range<java.lang.Double> getRange()
          Gets mapping range of the mapper.
 AxisScale getScale()
          Returns a scale object for this axis.
 AxisMapperRange getViewRange()
          Gets an AxisMapperRange object representing visible axis range.
 Range<java.lang.Double> getVisibleRange()
          Gets visible range of the mapper.
 boolean isAdjusting()
          Returns the flag indicating whether the axis range will be adjusted (normalized).
 double map(double key)
          Finds a position of the specified double value in the mapping range.
 double map(java.lang.Object key)
          Finds position of the specified key in the visible range.
 java.lang.Object mapBack(double pos)
          Finds a number corresponding to the specified position in the visible range.
 void setDrawSubScale(boolean drawSubScale)
          Sets if the sub-scale on the axis should be drawn.
 void setIsAdjusting(boolean adjust)
          Sets the flag indicating whether the axis range will be adjusted (normalized).
 void setMinimumSteps(int minSteps)
          Sets a minimum number of steps for this axis mapper.
 void setNumberFormat(java.text.NumberFormat nf)
          Assigns number format to mapper.
 void setRange(double min, double max)
          Sets mapping range for this mapper.
 void setVisibleRange(double min, double max)
          Sets the visible range for this mapper.
 void updateRange(double value)
          Updates the mapping range so that the specified value will be in the range.
 
Methods inherited from class lt.monarch.chart.mapper.AnalogAxisMapper
getPreferredHeight, getPreferredWidth
 
Methods inherited from class lt.monarch.chart.mapper.AbstractAxisMapper
addListener, fireMappingChanged, getProjectionRange, removeListener, setProjectionRange
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

totalRange

protected final NormalizedMathRange totalRange
the total range


mapperRange

protected final AxisMapperRange mapperRange
the axis mapper range


visibleRange

protected final NormalizedMathRange visibleRange
the visible range

Constructor Detail

MathAxisMapper

public MathAxisMapper()
Constructs a new MathAxisMapper with the normalized range [0; 1].


MathAxisMapper

public MathAxisMapper(double min,
                      double max)
Constructs a new MathAxisMapper with the specified range. Entire range is visible.

Parameters:
min - the range minimum
max - the range maximum

MathAxisMapper

public MathAxisMapper(double min,
                      double max,
                      AxisMapperRange mapperRange)
Constructs a new MathAxisMapper with the specified mapping range and the specified visible range.

Parameters:
min - the mapping range start
max - the mapping range end
mapperRange - the axis mapper range object representing visible range part
Method Detail

setMinimumSteps

public void setMinimumSteps(int minSteps)
Sets a minimum number of steps for this axis mapper. The visible mapping range will be divided into at least minSteps steps.

Parameters:
minSteps - minimum number of steps
See Also:
NormalizedMathRange.setMinimumSteps(int)

createScale

protected AnalogAxisScale createScale()
Creates and returns a new AxisScale for this axis.

Returns:
an instance of MathAxisScale representing scale for this axis

setDrawSubScale

public void setDrawSubScale(boolean drawSubScale)
Sets if the sub-scale on the axis should be drawn.

Parameters:
drawSubScale - True if to draw sub-scale

setNumberFormat

public void setNumberFormat(java.text.NumberFormat nf)
Assigns number format to mapper.

Parameters:
nf - the number format

setRange

public void setRange(double min,
                     double max)
Sets mapping range for this mapper. All mapper listeners are notified that mapping changed.

Parameters:
min - start of the mapping range
max - end of the mapping range

getRange

public Range<java.lang.Double> getRange()
Gets mapping range of the mapper. Real values (not normalized are returned)

Specified by:
getRange in class AnalogAxisMapper<Range<java.lang.Double>>
Returns:
MathRange object representing current mapping range

setVisibleRange

public void setVisibleRange(double min,
                            double max)
Sets the visible range for this mapper. The visible range bounds should be inside mapping range.

Parameters:
min - start of the visible range
max - end of the visible range

getVisibleRange

public Range<java.lang.Double> getVisibleRange()
Gets visible range of the mapper. It is the real values of the visible range (not normalized)

Specified by:
getVisibleRange in class AnalogAxisMapper<Range<java.lang.Double>>
Returns:
MathRange object representing current visible range

getViewRange

public AxisMapperRange getViewRange()
Description copied from interface: AxisMapper
Gets an AxisMapperRange object representing visible axis range. The object can be used to set visible axis range. Returns normalized value from [0..1]

Returns:
AxisMapperRange object representing visible axis range

getScale

public AxisScale getScale()
Returns a scale object for this axis. An instance of MathAxisScale is returned.

Returns:
scale object for this axis

adjustRange

protected void adjustRange(NormalizedMathRange range)
Adjusts the specified normalized mathematical range. Calls adjustSteps method of the range. If the mapper is adjusting calls adjustRange method of the range also.

Parameters:
range - the range to adjust
See Also:
setIsAdjusting(boolean)

map

public double map(double key)
Finds a position of the specified double value in the mapping range.

Parameters:
key - double value to map
Returns:
position of the specified value in the mapping range
See Also:
NormalizedMathRange.map(double)

map

public double map(java.lang.Object key)
Finds position of the specified key in the visible range. The key is casted to Number and it's double value is forwarded to visible range's map (double value) method.

Parameters:
key - the Number to map
Returns:
position of the specified key in the mapping range
See Also:
NormalizedMathRange.map(double)

mapBack

public java.lang.Object mapBack(double pos)
Finds a number corresponding to the specified position in the visible range. If extent of the visible range is equal to 0, then Double.NaN is returned.

Specified by:
mapBack in interface AxisMapper
Overrides:
mapBack in class AbstractAxisMapper
Parameters:
pos - position in the visible range; should be a value in range [0,1]
Returns:
Number corresponding to the specified position
See Also:
NormalizedMathRange.mapBack(double)

formatKey

public java.lang.String formatKey(java.lang.Object key)
Formats the specified key. The key is casted to Number and it's double value is forwarded to visible range's formatPrecise method.

Parameters:
key - the Number to format
Returns:
string representation of the key
See Also:
NormalizedMathRange.formatPrecise(double)

getNumberFormat

public java.text.NumberFormat getNumberFormat()
Gets mapper's NumberFormat.

Returns:
mapper's NumberFormat

updateRange

public void updateRange(double value)
Updates the mapping range so that the specified value will be in the range. If the specified value is in range at the moment then the mapping range remains the same. Otherwise mapping range bounds is changed.

Parameters:
value - the double value
See Also:
NormalizedMathRange.updateRange(double)

isAdjusting

public boolean isAdjusting()
Returns the flag indicating whether the axis range will be adjusted (normalized). For example if you set the range to [-150, 150] and isAdjusting flag is set to true, then the range will be adjusted to [-200,200]. Initial value is 'true'.

Returns:
true if the range will be adjusted (normalized), false otherwise.

setIsAdjusting

public void setIsAdjusting(boolean adjust)
Sets the flag indicating whether the axis range will be adjusted (normalized). I.e. if you set the range to [-150, 150] and isAdjusting flag is set to true, then the range will be adjusted to [-200,200].

Parameters:
adjust - - true if the range must be adjusted, false otherwise.

getFormats

protected java.text.Format[] getFormats()
Description copied from class: AnalogAxisMapper
Gets axis mapper formats.

Specified by:
getFormats in class AnalogAxisMapper<Range<java.lang.Double>>
Returns:
axis mapper formats