ChartCat 1.2

li.netcat.chart.data
Class DefaultScaleModel

java.lang.Object
  extended byli.netcat.chart.data.AbstractChartModelAdapter
      extended byli.netcat.chart.data.DefaultScaleModel
All Implemented Interfaces:
ChartModelAdapter, NumericScaleModel, ScaleModel

public class DefaultScaleModel
extends AbstractChartModelAdapter
implements NumericScaleModel

Default implementation of a NumericScaleModel that uses a linear scale. This class uses a configurable divide map that defines how to divide a range into sub ranges. The structure of the map consists of a series of triple.

All triples must be sorted by its first value and the triple for the range 1.0 must be present.

The value range of the scale is mapped into the range from 1.0 to 10.0 so that the divide map gets independent of the decimal power. The map value is initialized as follows:

 setDivideMap(new double[] {
                           1.0, 0.2, 1,
                           1.2, 0.2, 1,
                           1.4, 0.2, 1,
                           1.5, 0.3, 1,
                           1.6, 0.2, 1,
                           1.8, 0.3, 1,
                           2.0, 0.25, 2,
                           2.5, 0.5, 1,
                           3.0, 0.5, 1,
                           3.5, 0.5, 1,
                           4.0, 0.5, 1,
                           5.0, 1.0, 0,
                           6.0, 1.0, 0,
                           7.0, 1.0, 0,
                           8.0, 1.0, 0,
                         });
which means: Divide a range of 1.0 by using 5 sub ranges of lenght 0.2 and use 1 decimal place. Divide a range of 1.2 by using sub ranges of 0.2 and use 1 decimal place. ...etc... Divide a range of 8.0 by using sub ranges of 1.0 and use no decimal places. It also means, that a range of 10 gets divided into 5 sub ranges of lenght 2 and use 0 decimal places ...etc...

Author:
Arthur Marxer

Constructor Summary
DefaultScaleModel()
          Constructs and initializes a new DefaultScaleModel.
 
Method Summary
 double[] getDivideMap()
          Returns a clone of the divide map of this scale model.
 float getLength()
          Returns the length of the scale
 int getMarkCount()
          Returns the number of marks of this scale.
 java.text.NumberFormat getNumberFormat(double startValue, double stepWidth, int decimalPlaces)
          Returns the number format that is used to format the values of the scale.
 java.text.NumberFormat getPercentFormat(double startValue, double stepWidth, int decimalPlaces)
          Returns the number format that is used to format the relative values of the scale.
 float getPosition(int markIndex)
          Returns the position of the mark at the given index.
 java.lang.String getText(int textIndex)
          Returns the text of the mark at the given index.
 double getValue(int markIndex)
          Returns the value of the mark at the given index.
 void invalidate()
          Invoked when the underlying model changes.
 boolean isCentered()
          Returns false.
 boolean isReverted()
          Returns true, if this scale model is reverted, which means that the smallest number is at the top of a horizontal scale.
 void setDivideMap(double[] map)
          Sets a new instance of the divide map.
 void setLength(float length)
          Sets the length of the scale.
 void setRange(double min, double max, boolean relative)
          Sets the range for this scale.
 void setReverted(boolean flag)
          Sets the reverted flag.
 float toPosition(double value)
          Calculates the position of an arbitrary value.
 
Methods inherited from class li.netcat.chart.data.AbstractChartModelAdapter
getChartModel, setChartModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface li.netcat.chart.data.ChartModelAdapter
getChartModel, setChartModel
 

Constructor Detail

DefaultScaleModel

public DefaultScaleModel()
Constructs and initializes a new DefaultScaleModel.

Method Detail

setDivideMap

public void setDivideMap(double[] map)
Sets a new instance of the divide map.

Parameters:
map - The new divide map, valid and not null. This parameter gets cloned.

getDivideMap

public double[] getDivideMap()
Returns a clone of the divide map of this scale model. See the method setDivideMap(double[]) for a description of the structure.

Returns:
A clone of the divide map.

getNumberFormat

public java.text.NumberFormat getNumberFormat(double startValue,
                                              double stepWidth,
                                              int decimalPlaces)
Returns the number format that is used to format the values of the scale. This method is intended to be overridden in subclasses to provide another format than the default.

Parameters:
startValue - The start value of the scale.
stepWidth - The value of the step width.
decimalPlaces - The number of preferred decimal places.

getPercentFormat

public java.text.NumberFormat getPercentFormat(double startValue,
                                               double stepWidth,
                                               int decimalPlaces)
Returns the number format that is used to format the relative values of the scale. This method is intended to be overridden in subclasses to provide another format than the default.

Parameters:
startValue - The start value of the scale.
stepWidth - The value of the step width.
decimalPlaces - The number of preferred decimal places.

isReverted

public boolean isReverted()
Returns true, if this scale model is reverted, which means that the smallest number is at the top of a horizontal scale.

Returns:
true if this scale model is reverted.

setReverted

public void setReverted(boolean flag)
Sets the reverted flag. If set to true, the smallest number is at the top of a horizontal scale.

Parameters:
flag - The reverted flag.

setRange

public void setRange(double min,
                     double max,
                     boolean relative)
Description copied from interface: NumericScaleModel
Sets the range for this scale.

Specified by:
setRange in interface NumericScaleModel
Parameters:
min - The minimum value, it is <= max.
max - The maximum value, it is >= min.
relative - Flag that indicates that the values are in percent. The value 1.0 refers to 100%.

getLength

public float getLength()
Description copied from interface: ScaleModel
Returns the length of the scale

Specified by:
getLength in interface ScaleModel
Returns:
The length of the scale. This value is always > 0.0f.

setLength

public void setLength(float length)
Description copied from interface: ScaleModel
Sets the length of the scale.

Specified by:
setLength in interface ScaleModel
Parameters:
length - The length of the scale, must be > 0.0f.

getMarkCount

public int getMarkCount()
Description copied from interface: ScaleModel
Returns the number of marks of this scale.

Specified by:
getMarkCount in interface ScaleModel
Returns:
The number of marks.

getPosition

public float getPosition(int markIndex)
Description copied from interface: ScaleModel
Returns the position of the mark at the given index.

Specified by:
getPosition in interface ScaleModel
Parameters:
markIndex - The index of the mark. It must be >= 0 and < getMarkCount().

getValue

public double getValue(int markIndex)
Description copied from interface: ScaleModel
Returns the value of the mark at the given index.

Specified by:
getValue in interface ScaleModel
Parameters:
markIndex - The index of the mark. It must be >= 0 and < getMarkCount().

getText

public java.lang.String getText(int textIndex)
Description copied from interface: ScaleModel
Returns the text of the mark at the given index.

Specified by:
getText in interface ScaleModel
Parameters:
textIndex - The index of the mark. It must be >= 0 and < getMarkCount().

toPosition

public float toPosition(double value)
Description copied from interface: ScaleModel
Calculates the position of an arbitrary value.

Specified by:
toPosition in interface ScaleModel
Parameters:
value - An arbitrary value.
Returns:
The position of the value in this scale.

isCentered

public boolean isCentered()
Returns false.

Specified by:
isCentered in interface ScaleModel
Returns:
The centered flag.

invalidate

public void invalidate()
Description copied from class: AbstractChartModelAdapter
Invoked when the underlying model changes. Subclasses may override this method and discard all buffered data.

Overrides:
invalidate in class AbstractChartModelAdapter

ChartCat 1.2

Copyright 2003 - 2005 NetCat Inc.. All rights reserved. Feedback

Chart,Charting,Charts,Java,Java Chart,Java Charting,Java Charts,Chart Java,Charts Java,3D,3D Chart,3Dchart,Graph,Graphs,Chart Graph,Java Graph,Diagram,Diagrams,Java Diagram,Java Diagrams,Curve,Curves,Bar Chart,Pie Chart,Line Chart,Area Chart,Bar Graph,Pie Graph,Line Graph,Java Diagram,Chart Diagram,Package,Library,Chart Library,Chart Engine,Chart Package,Graph Package,Paint,Support,Graphic,Graphics,Print, Chart,Charting,Charts,Java,Java Chart,Java Charting,Java Charts,Chart Java,Charts Java,3D,3D Chart,3Dchart,Graph,Graphs,Chart Graph,Java Graph,Diagram,Diagrams,Java Diagram,Java Diagrams,Curve,Curves,Bar Chart,Pie Chart,Line Chart,Area Chart,Bar Graph,Pie Graph,Line Graph,Java Diagram,Chart Diagram,Package,Library,Chart Library,Chart Engine,Chart Package,Graph Package,Paint,Support,Graphic,Graphics,Print, Chart,Charting,Charts,Java,Java Chart,Java Charting,Java Charts,Chart Java,Charts Java,3D,3D Chart,3Dchart,Graph,Graphs,Chart Graph,Java Graph,Diagram,Diagrams,Java Diagram,Java Diagrams,Curve,Curves,Bar Chart,Pie Chart,Line Chart,Area Chart,Bar Graph,Pie Graph,Line Graph,Java Diagram,Chart Diagram,Package,Library,Chart Library,Chart Engine,Chart Package,Graph Package,Paint,Support,Graphic,Graphics,Print