no.hig.okolloen.graphics.chart
Class ValueScaler
java.lang.Object
|
+--no.hig.okolloen.graphics.chart.ValueScaler
- public class ValueScaler
- extends java.lang.Object
The ValueScaler class is used to scale values so that graphs and charts look nice.
Initialize it with the max and min value and it will be ready for use.
Then ask it for labels and it will return an array of five strings with the max, min
and three middle values to use for tags on your graphs and charts.
Use the getNormalizedValue to get a value between 0 and 1 that represents the
scaled value given in respect to the labels.
If your data changes call the rescale with new max and min values and everything will be
recalculated.
This is the number 1 class I've always wanted when doing graphs and charts.
- Since:
- rev 0.1
Constructor Summary |
ValueScaler(double max,
double min)
Constructor for the ValueScaler class. |
Method Summary |
double |
getMax()
Returns the current maximum limit of this ValueScaler. |
double |
getMin()
Returns the current minumum limit of this ValueScaler. |
double |
getNormalizedValue(double value)
Returns a double scaled according to the current max and min values. |
java.lang.String[] |
getScaleLabels()
Returns an array of labels to use as markers on a graph/chart. |
int |
getScaleType()
Returns an integer that corresponds to the scale range used internally. |
boolean |
isValidValue(double value)
Checks to see if the given value is a valid value for this ValueScaler. |
void |
rescale(double max,
double min)
Recalibrates the internal data of the ValueScaler when your dataset changes its min and max values. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
SCALE_ONE_TO_MINUS_ONE
public static final int SCALE_ONE_TO_MINUS_ONE
SCALE_FIVE_TO_MINUS_FIVE
public static final int SCALE_FIVE_TO_MINUS_FIVE
SCALE_TWO_TO_MINUS_TWO
public static final int SCALE_TWO_TO_MINUS_TWO
SCALE_TEN_TO_ZERO
public static final int SCALE_TEN_TO_ZERO
SCALE_FOUR_TO_ZERO
public static final int SCALE_FOUR_TO_ZERO
SCALE_TWO_TO_ZERO
public static final int SCALE_TWO_TO_ZERO
SCALE_ZERO_TO_MINUS_TEN
public static final int SCALE_ZERO_TO_MINUS_TEN
SCALE_ZERO_TO_MINUS_FOUR
public static final int SCALE_ZERO_TO_MINUS_FOUR
SCALE_ZERO_TO_MINUS_TWO
public static final int SCALE_ZERO_TO_MINUS_TWO
ValueScaler
public ValueScaler(double max,
double min)
- Constructor for the ValueScaler class.
- Parameters:
max
- the maximum value in a given dataset.min
- the minumum value in a given dataset.
rescale
public void rescale(double max,
double min)
- Recalibrates the internal data of the ValueScaler when your dataset changes its min and max values.
- Parameters:
max
- the maximum value in a given dataset.min
- the minumum value in a given dataset.
getScaleLabels
public java.lang.String[] getScaleLabels()
- Returns an array of labels to use as markers on a graph/chart.
- Returns:
- String[] with new labels.
getScaleType
public int getScaleType()
- Returns an integer that corresponds to the scale range used internally.
- Returns:
- integer value corresponding to one of the public static final variables declared in the class.
getNormalizedValue
public double getNormalizedValue(double value)
throws java.lang.RuntimeException
- Returns a double scaled according to the current max and min values.
- Returns:
- double value between 0 and 1.
getMax
public double getMax()
- Returns the current maximum limit of this ValueScaler.
- Returns:
- double value representing the maximum value that can be scaled with this object.
getMin
public double getMin()
- Returns the current minumum limit of this ValueScaler.
- Returns:
- double value representing the minimum value that can be scaled with this object.
isValidValue
public boolean isValidValue(double value)
- Checks to see if the given value is a valid value for this ValueScaler.
- Parameters:
value
- is the value to be checked- Returns:
- boolean true if the given value is larger than min and less than max.