org.knime.base.node.viz.histogram.util
Class BinningUtil

java.lang.Object
  extended by org.knime.base.node.viz.histogram.util.BinningUtil

public final class BinningUtil
extends Object

This class provides methods to create the bins of numerical bars.

Author:
Tobias Koetter, University of Konstanz

Method Summary
static int addDataRow2Bin(boolean binNominal, List<? extends BinDataModel> bins, BinDataModel missingValueBin, int startBin, DataCell xCell, Color rowColor, RowKey id, Collection<ColorColumn> aggrColumns, DataCell... aggrCells)
          Adds the given row either to the missing value bin if the x value is missing or to the corresponding bin.
static boolean binNominal(DataColumnSpec colSpec, int noOfBins)
           
static int calculateIntegerMaxNoOfBins(int noOfBins, DataColumnSpec xColSpec)
          Calculates the maximum number of bins for the given column spec if it is an integer column or returns the given number of bins.
static boolean checkDomainRange(DataCell cell, DataColumnSpec spec)
          Checks if the given cell is in the domain range of the given DataColumnSpec.
static String createBarName(boolean firstBar, double leftBoundary, double rightBoundary)
          Creates the name of the bin depending on the given boundaries.
static double createBinInterval(double maxVal, double minVal, int noOfBins, boolean isInteger)
           
static double createBinStart(double minVal, double binInterval, boolean isInteger)
          Called to calculate the left start value of the binning.
static List<InteractiveBinDataModel> createInteractiveIntervalBins(DataColumnSpec colSpec, int numberOfBins)
          Creates the given number of interval bins for the given column specification.
static List<InteractiveBinDataModel> createInteractiveNominalBins(DataColumnSpec colSpec)
          Creates interactive nominal bins for the given column specification.
static List<BinDataModel> createIntervalBins(DataColumnSpec colSpec, int numberOfBins)
          Creates the given number of interval bins for the given column specification.
static List<BinDataModel> createNominalBins(DataColumnSpec colSpec)
          Creates interactive nominal bins for the given column specification.
static double getNumericValue(DataCell cell)
          Checks if the given DataCell is a numeric cell and returns the numeric value.
static double myRoundedBorders(double doubleVal, double increment, int noOfDigits)
          Returns the rounded value which contains the given number of decimal places after the last 0 in the given increment.
static double smallValueRounder(double doubleVal, int noOfDigits, boolean isInteger, boolean roundUp)
          Returns the rounded value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createBinInterval

public static double createBinInterval(double maxVal,
                                       double minVal,
                                       int noOfBins,
                                       boolean isInteger)
Parameters:
maxVal - the maximum possible value
minVal - the minimum possible value
noOfBins - the number of bars
isInteger - true if the value should be an integer
Returns:
the interval for the given min, max value and no of bars

createBinStart

public static double createBinStart(double minVal,
                                    double binInterval,
                                    boolean isInteger)
Called to calculate the left start value of the binning. If the minVal is greater then 0 it returns 0 if the x column is an integer and minVal - interval <= 0 otherwise it rounds the given minVal.

Parameters:
minVal - the minimum value to round
binInterval - the bin interval to check if we can start with 0
isInteger - true if the x column is an integer
Returns:
the left start value of the binning interval

getNumericValue

public static double getNumericValue(DataCell cell)
Checks if the given DataCell is a numeric cell and returns the numeric value. If it's not a numeric cell it throws an IllegalArgumentException.

Parameters:
cell - the cell to convert
Returns:
the numeric value of the given cell

createBarName

public static String createBarName(boolean firstBar,
                                   double leftBoundary,
                                   double rightBoundary)
Creates the name of the bin depending on the given boundaries.

Parameters:
firstBar - indicates if this is the first bar
leftBoundary - the left boundary of the bin
rightBoundary - the right boundary of the bin
Returns:
the bin name

myRoundedBorders

public static double myRoundedBorders(double doubleVal,
                                      double increment,
                                      int noOfDigits)
Returns the rounded value which contains the given number of decimal places after the last 0 in the given increment.

Parameters:
doubleVal - the value to round
increment - the increment which defines the start index of the digit counter
noOfDigits - the number of decimal places to display
Returns:
the rounded value

smallValueRounder

public static double smallValueRounder(double doubleVal,
                                       int noOfDigits,
                                       boolean isInteger,
                                       boolean roundUp)
Returns the rounded value. If the value is bigger or equal 10 it returns the result of the bigValueRounder(double, boolean) method otherwise it returns the rounded value which contains the given number of decimal places after the last 0.

Parameters:
doubleVal - the value to round
noOfDigits - the number of decimal places we want for less then 1 values
isInteger - true if the given number is an integer
roundUp - if the value should be rounded up
Returns:
the rounded value of the given value

createInteractiveNominalBins

public static List<InteractiveBinDataModel> createInteractiveNominalBins(DataColumnSpec colSpec)
Creates interactive nominal bins for the given column specification.

Parameters:
colSpec - the column specification
Returns:
the interactive bins

createNominalBins

public static List<BinDataModel> createNominalBins(DataColumnSpec colSpec)
Creates interactive nominal bins for the given column specification.

Parameters:
colSpec - the column specification
Returns:
the interactive bins

createInteractiveIntervalBins

public static List<InteractiveBinDataModel> createInteractiveIntervalBins(DataColumnSpec colSpec,
                                                                          int numberOfBins)
Creates the given number of interval bins for the given column specification.

Parameters:
colSpec - the column specification
numberOfBins - the number of bins to create
Returns:
the created bins

createIntervalBins

public static List<BinDataModel> createIntervalBins(DataColumnSpec colSpec,
                                                    int numberOfBins)
Creates the given number of interval bins for the given column specification.

Parameters:
colSpec - the column specification
numberOfBins - the number of bins to create
Returns:
the created bins

addDataRow2Bin

public static int addDataRow2Bin(boolean binNominal,
                                 List<? extends BinDataModel> bins,
                                 BinDataModel missingValueBin,
                                 int startBin,
                                 DataCell xCell,
                                 Color rowColor,
                                 RowKey id,
                                 Collection<ColorColumn> aggrColumns,
                                 DataCell... aggrCells)
                          throws IllegalArgumentException
Adds the given row either to the missing value bin if the x value is missing or to the corresponding bin.

Parameters:
binNominal - if true the bins should be nominal bins where the x value has to match exactly. If false the bins should be interval bins and the x value has fit into the lower and upper bound of the bin.
bins - the BinDataModel list
missingValueBin - the bin for the missing x value rows
startBin - the index of the bin to start with to speed up the process if the data rows are sorted by the x value
xCell - the x cell
rowColor - the color of the row
id - the row id
aggrColumns - the aggregation columns as ColorColumn objects in the same order like the aggregation cells
aggrCells - the aggregation DataCell objects which contain the value
Returns:
the index of the bin where the row was added
Throws:
IllegalArgumentException - if the given row doesn't fit in any bin

binNominal

public static boolean binNominal(DataColumnSpec colSpec,
                                 int noOfBins)
Parameters:
colSpec - the DataColumnSpec of the column to bin
noOfBins - the number of bins
Returns:
true if the bins should be nominal

checkDomainRange

public static boolean checkDomainRange(DataCell cell,
                                       DataColumnSpec spec)
Checks if the given cell is in the domain range of the given DataColumnSpec. If the cell is missing the method returns true.

Parameters:
cell - the cell to check
spec - the DataColumnSpec with the domain
Returns:
true if the cell is missing or the value is between the upper and lower bound specified by the domain of the given column specification

calculateIntegerMaxNoOfBins

public static int calculateIntegerMaxNoOfBins(int noOfBins,
                                              DataColumnSpec xColSpec)
Calculates the maximum number of bins for the given column spec if it is an integer column or returns the given number of bins.

Parameters:
noOfBins - the current number of bins
xColSpec - to calculate the range for
Returns:
the maximum number of bins


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.