com.approximatrix.charting
Class ChartUtilities

java.lang.Object
  extended by com.approximatrix.charting.ChartUtilities

public class ChartUtilities
extends java.lang.Object

This class offers multiple static methods to perform mathematical operations concerning the Chart, e.g. methods for rounding the minimal and maximal x-values gracefully.

Version:
1.0
Author:
mueller

Constructor Summary
ChartUtilities()
           
 
Method Summary
static void addDataToSet(java.util.TreeSet set, java.lang.Number[][] data)
          Adds a two-dimensional array to a TreeSet.
static double calculateTickSpacing(double min, double max)
          Calculates the best tick spacing for the rounded minimal and maximal values.
static double ceil(double d, int exp)
          This method returns the smallest double value that is smaller than d = x * 10exp where x is rounded up to the closest integer.
static int exp(double d)
          A double value can be represented like d = x * 10exp and this method returns the value of exp for a double d.
static double floor(double d, int exp)
          This method returns the largest double value that is smaller than d = x * 10exp where x is rounded down to the closest integer.
static double interpolate(double[] xa, double[] ya, double x)
          This function performs a polynomial interpolation using a set of given x and y values.
static void main(java.lang.String[] args)
          A test routine.
static double[] performAutoScale(double min, double max)
          This method calculates the optimal rounding for the minimal and maximal ChartModel values.
static java.lang.Number[] transformArray(double[] data)
          Transforms an array of primitives to an array of Numbers.
static java.lang.Number[][] transformArray(double[][] data)
          Transforms a two-dimensional array of primitives to an array of Numbers.
static java.lang.Number[] transformArray(int[] data)
          Transforms an array of primitives to an array of Numbers.
static java.lang.Number[][] transformArray(int[][] data)
          Transforms a two-dimensional array of primitives to an array of Numbers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChartUtilities

public ChartUtilities()
Method Detail

performAutoScale

public static double[] performAutoScale(double min,
                                        double max)
This method calculates the optimal rounding for the minimal and maximal ChartModel values. It computes the difference of the minimal and maximal value and rounds the values min and max according to the exponent of the difference.

Parameters:
min - the minimal column value of the ChartDataModel
max - the maximal column value of the ChartDataModel
Returns:
a double[] with the rounded minimal value at index 0 and the maximal value at index 1.

calculateTickSpacing

public static double calculateTickSpacing(double min,
                                          double max)
Calculates the best tick spacing for the rounded minimal and maximal values.

Parameters:
min - the rounded minimal value
max - the rounded maximal value
Returns:
the spacing of ticks on the x-axis.

interpolate

public static double interpolate(double[] xa,
                                 double[] ya,
                                 double x)
This function performs a polynomial interpolation using a set of given x and y values. It uses Neville's interpolation algorithm.

Parameters:
xa - the array of known x-values
ya - the array of known y-values
x - the x value for which the y value will be computed
Returns:
the corresponding y value

floor

public static double floor(double d,
                           int exp)
This method returns the largest double value that is smaller than d = x * 10exp where x is rounded down to the closest integer.

Parameters:
d - the double value to be rounded
exp - the exponent of 10 to which d should be rounded
Returns:
Math.floor(x) * 10exp

ceil

public static double ceil(double d,
                          int exp)
This method returns the smallest double value that is smaller than d = x * 10exp where x is rounded up to the closest integer.

Parameters:
d - the double value to be rounded
exp - the exponent of 10 to which d should be rounded
Returns:
Math.ceil(x) * 10exp

exp

public static int exp(double d)
A double value can be represented like d = x * 10exp and this method returns the value of exp for a double d.

Parameters:
d - the double value
Returns:
the exponent of 10

transformArray

public static java.lang.Number[][] transformArray(int[][] data)
Transforms a two-dimensional array of primitives to an array of Numbers.


transformArray

public static java.lang.Number[][] transformArray(double[][] data)
Transforms a two-dimensional array of primitives to an array of Numbers.


transformArray

public static java.lang.Number[] transformArray(double[] data)
Transforms an array of primitives to an array of Numbers.


transformArray

public static java.lang.Number[] transformArray(int[] data)
Transforms an array of primitives to an array of Numbers.


addDataToSet

public static void addDataToSet(java.util.TreeSet set,
                                java.lang.Number[][] data)
Adds a two-dimensional array to a TreeSet.


main

public static void main(java.lang.String[] args)
A test routine.