Example usage for org.jfree.data.statistics HistogramType RELATIVE_FREQUENCY

List of usage examples for org.jfree.data.statistics HistogramType RELATIVE_FREQUENCY

Introduction

In this page you can find the example usage for org.jfree.data.statistics HistogramType RELATIVE_FREQUENCY.

Prototype

HistogramType RELATIVE_FREQUENCY

To view the source code for org.jfree.data.statistics HistogramType RELATIVE_FREQUENCY.

Click Source Link

Document

Relative frequency.

Usage

From source file:pipeline.GUI_utils.JXTablePerColumnFiltering.java

public void updateRangeOfColumn(int columnIndex, boolean reinitializeSelection, int boundsToUpdate,
        boolean suppressModelInit) {
    if (!suppressModelInit) {
        needToInitializeFilterModel = true;
        initializeFilterModel();//ww  w .ja v  a  2 s  .com
    }
    boolean isFloat = model.getValueAt(0, columnIndex) instanceof Float;
    boolean isDouble = model.getValueAt(0, columnIndex) instanceof Double;
    boolean isInteger = model.getValueAt(0, columnIndex) instanceof Integer;
    boolean isSpreadsheetCell = model.getValueAt(0, columnIndex) instanceof SpreadsheetCell;
    if (!(isFloat || isInteger || isSpreadsheetCell || isDouble))
        return;
    double min = Double.MAX_VALUE;
    double max = Double.MIN_VALUE;

    double[] valuesForHistogram = new double[model.getRowCount()];

    for (int i = 0; i < model.getRowCount(); i++) {
        double value;
        if (isFloat)
            value = (Float) model.getValueAt(i, columnIndex);
        else if (isDouble)
            value = (Double) model.getValueAt(i, columnIndex);
        else if (isInteger)
            value = (Integer) model.getValueAt(i, columnIndex);
        else {
            value = ((SpreadsheetCell) model.getValueAt(i, columnIndex)).getFloatValue();
        }
        if (Double.isNaN(value))
            value = 0.0d;
        if (value < min)
            min = value;
        if (value > max)
            max = value;
        valuesForHistogram[i] = value;
    }

    // Now compute a histogram; this could be optimized

    HistogramDataset dataset = new HistogramDataset();
    dataset.setType(HistogramType.RELATIVE_FREQUENCY);
    dataset.addSeries("Histogram", valuesForHistogram, 15);

    if (isFloat || isDouble || isSpreadsheetCell) {
        FloatRangeParameter param = (FloatRangeParameter) filteringModel.getValueAt(0, columnIndex);
        param.histogram = dataset;
        float[] currentValue = (float[]) param.getValue();
        if ((boundsToUpdate == BOTH_BOUNDS) || boundsToUpdate == LOWER_BOUND)
            currentValue[2] = (float) min;
        if ((boundsToUpdate == BOTH_BOUNDS) || boundsToUpdate == UPPER_BOUND)
            currentValue[3] = (float) max;
        if (reinitializeSelection) {
            currentValue[0] = currentValue[2];
            currentValue[1] = currentValue[3];
        }
        param.setValueFireIfAppropriate(currentValue, false, true, true);
    } else {
        IntRangeParameter param = (IntRangeParameter) filteringModel.getValueAt(0, columnIndex);
        int[] currentValue = (int[]) param.getValue();
        if ((boundsToUpdate == BOTH_BOUNDS) || boundsToUpdate == LOWER_BOUND)
            currentValue[2] = (int) min;
        if ((boundsToUpdate == BOTH_BOUNDS) || boundsToUpdate == UPPER_BOUND)
            currentValue[3] = (int) max;
        if (reinitializeSelection) {
            currentValue[0] = currentValue[2];
            currentValue[1] = currentValue[3];
        }
        param.setValueFireIfAppropriate(currentValue, false, true, true);
    }
}