Java Code Examples for org.jfree.data.DataUtilities#calculateColumnTotal()

The following examples show how to use org.jfree.data.DataUtilities#calculateColumnTotal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractCategoryItemLabelGenerator.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * {@link MessageFormat} class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 *
 * @return The items (never <code>null</code>).
 */
protected Object[] createItemArray(CategoryDataset dataset,
                                   int row, int column) {
    Object[] result = new Object[4];
    result[0] = dataset.getRowKey(row).toString();
    result[1] = dataset.getColumnKey(column).toString();
    Number value = dataset.getValue(row, column);
    if (value != null) {
        if (this.numberFormat != null) {
            result[2] = this.numberFormat.format(value);
        }
        else if (this.dateFormat != null) {
            result[2] = this.dateFormat.format(value);
        }
    }
    else {
        result[2] = this.nullValueString;
    }
    if (value != null) {
        double total = DataUtilities.calculateColumnTotal(dataset, column);
        double percent = value.doubleValue() / total;
        result[3] = this.percentFormat.format(percent);
    }

    return result;
}
 
Example 2
Source File: AbstractCategoryItemLabelGenerator.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * {@link MessageFormat} class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 *
 * @return The items (never <code>null</code>).
 */
protected Object[] createItemArray(CategoryDataset dataset,
                                   int row, int column) {
    Object[] result = new Object[4];
    result[0] = dataset.getRowKey(row).toString();
    result[1] = dataset.getColumnKey(column).toString();
    Number value = dataset.getValue(row, column);
    if (value != null) {
        if (this.numberFormat != null) {
            result[2] = this.numberFormat.format(value);
        }
        else if (this.dateFormat != null) {
            result[2] = this.dateFormat.format(value);
        }
    }
    else {
        result[2] = this.nullValueString;
    }
    if (value != null) {
        double total = DataUtilities.calculateColumnTotal(dataset, column);
        double percent = value.doubleValue() / total;
        result[3] = this.percentFormat.format(percent);
    }

    return result;
}
 
Example 3
Source File: StackedAreaRenderer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Calculates the stacked value of the all series up to, but not including 
 * <code>series</code> for the specified category, <code>category</code>.  
 * It returns 0.0 if <code>series</code> is the first series, i.e. 0.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series.
 * @param category  the category.
 *
 * @return double returns a cumulative value for all series' values up to 
 *         but excluding <code>series</code> for Object 
 *         <code>category</code>.
 */
protected double getPreviousHeight(CategoryDataset dataset, 
                                   int series, int category) {

    double result = 0.0;
    Number n;
    double total = 0.0;
    if (this.renderAsPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset, category);
    }
    for (int i = 0; i < series; i++) {
        n = dataset.getValue(i, category);
        if (n != null) {
            double v = n.doubleValue();
            if (this.renderAsPercentages) {
                v = v / total;
            }
            result += v;
        }
    }
    return result;

}
 
Example 4
Source File: StackedAreaRenderer.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Calculates the stacked value of the all series up to, but not including
 * <code>series</code> for the specified category, <code>category</code>.
 * It returns 0.0 if <code>series</code> is the first series, i.e. 0.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series.
 * @param category  the category.
 *
 * @return double returns a cumulative value for all series' values up to
 *         but excluding <code>series</code> for Object
 *         <code>category</code>.
 *
 * @deprecated As of 1.0.13, as the method is never used internally.
 */
protected double getPreviousHeight(CategoryDataset dataset,
        int series, int category) {

    double result = 0.0;
    Number n;
    double total = 0.0;
    if (this.renderAsPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset, category);
    }
    for (int i = 0; i < series; i++) {
        n = dataset.getValue(i, category);
        if (n != null) {
            double v = n.doubleValue();
            if (this.renderAsPercentages) {
                v = v / total;
            }
            result += v;
        }
    }
    return result;

}
 
Example 5
Source File: StackedAreaRenderer.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the stacked value of the all series up to, but not including
 * <code>series</code> for the specified category, <code>category</code>.
 * It returns 0.0 if <code>series</code> is the first series, i.e. 0.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series.
 * @param category  the category.
 *
 * @return double returns a cumulative value for all series' values up to
 *         but excluding <code>series</code> for Object
 *         <code>category</code>.
 *
 * @deprecated As of 1.0.13, as the method is never used internally.
 */
protected double getPreviousHeight(CategoryDataset dataset,
        int series, int category) {

    double result = 0.0;
    Number n;
    double total = 0.0;
    if (this.renderAsPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset, category);
    }
    for (int i = 0; i < series; i++) {
        n = dataset.getValue(i, category);
        if (n != null) {
            double v = n.doubleValue();
            if (this.renderAsPercentages) {
                v = v / total;
            }
            result += v;
        }
    }
    return result;

}
 
Example 6
Source File: StackedAreaRenderer.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Calculates the stacked value of the all series up to, but not including
 * <code>series</code> for the specified category, <code>category</code>.
 * It returns 0.0 if <code>series</code> is the first series, i.e. 0.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series.
 * @param category  the category.
 *
 * @return double returns a cumulative value for all series' values up to
 *         but excluding <code>series</code> for Object
 *         <code>category</code>.
 *
 * @deprecated As of 1.0.13, as the method is never used internally.
 */
protected double getPreviousHeight(CategoryDataset dataset,
        int series, int category) {

    double result = 0.0;
    Number n;
    double total = 0.0;
    if (this.renderAsPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset, category);
    }
    for (int i = 0; i < series; i++) {
        n = dataset.getValue(i, category);
        if (n != null) {
            double v = n.doubleValue();
            if (this.renderAsPercentages) {
                v = v / total;
            }
            result += v;
        }
    }
    return result;

}
 
Example 7
Source File: StackedAreaRenderer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Calculates the stacked value of the all series up to, but not including
 * <code>series</code> for the specified category, <code>category</code>.
 * It returns 0.0 if <code>series</code> is the first series, i.e. 0.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series.
 * @param category  the category.
 *
 * @return double returns a cumulative value for all series' values up to
 *         but excluding <code>series</code> for Object
 *         <code>category</code>.
 */
protected double getPreviousHeight(CategoryDataset dataset,
                                   int series, int category) {

    double result = 0.0;
    Number n;
    double total = 0.0;
    if (this.renderAsPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset, category);
    }
    for (int i = 0; i < series; i++) {
        n = dataset.getValue(i, category);
        if (n != null) {
            double v = n.doubleValue();
            if (this.renderAsPercentages) {
                v = v / total;
            }
            result += v;
        }
    }
    return result;

}
 
Example 8
Source File: AbstractCategoryItemLabelGenerator.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * {@link MessageFormat} class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 *
 * @return The items (never <code>null</code>).
 */
protected Object[] createItemArray(CategoryDataset dataset,
                                   int row, int column) {
    Object[] result = new Object[4];
    result[0] = dataset.getRowKey(row).toString();
    result[1] = dataset.getColumnKey(column).toString();
    Number value = dataset.getValue(row, column);
    if (value != null) {
        if (this.numberFormat != null) {
            result[2] = this.numberFormat.format(value);
        }
        else if (this.dateFormat != null) {
            result[2] = this.dateFormat.format(value);
        }
    }
    else {
        result[2] = this.nullValueString;
    }
    if (value != null) {
        double total = DataUtilities.calculateColumnTotal(dataset, column);
        double percent = value.doubleValue() / total;
        result[3] = this.percentFormat.format(percent);
    }

    return result;
}
 
Example 9
Source File: StackedAreaRenderer.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Calculates the stacked value of the all series up to, but not including
 * <code>series</code> for the specified category, <code>category</code>.
 * It returns 0.0 if <code>series</code> is the first series, i.e. 0.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series.
 * @param category  the category.
 *
 * @return double returns a cumulative value for all series' values up to
 *         but excluding <code>series</code> for Object
 *         <code>category</code>.
 *
 * @deprecated As of 1.0.13, as the method is never used internally.
 */
protected double getPreviousHeight(CategoryDataset dataset,
        int series, int category) {

    double result = 0.0;
    Number n;
    double total = 0.0;
    if (this.renderAsPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset, category);
    }
    for (int i = 0; i < series; i++) {
        n = dataset.getValue(i, category);
        if (n != null) {
            double v = n.doubleValue();
            if (this.renderAsPercentages) {
                v = v / total;
            }
            result += v;
        }
    }
    return result;

}
 
Example 10
Source File: StackedAreaRenderer.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculates the stacked values (one positive and one negative) of all
 * series up to, but not including, <code>series</code> for the specified
 * item. It returns [0.0, 0.0] if <code>series</code> is the first series.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series index.
 * @param index  the item index.
 * @param validRows  the valid rows.
 *
 * @return An array containing the cumulative negative and positive values
 *     for all series values up to but excluding <code>series</code>
 *     for <code>index</code>.
 */
protected double[] getStackValues(CategoryDataset dataset,
        int series, int index, int[] validRows) {
    double[] result = new double[2];
    double total = 0.0;
    if (this.renderAsPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset, index, 
                validRows);
    }
    for (int i = 0; i < series; i++) {
        if (isSeriesVisible(i)) {
            double v = 0.0;
            Number n = dataset.getValue(i, index);
            if (n != null) {
                v = n.doubleValue();
                if (this.renderAsPercentages) {
                    v = v / total;
                }
            }
            if (!Double.isNaN(v)) {
                if (v >= 0.0) {
                    result[1] += v;
                }
                else {
                    result[0] += v;
                }
            }
        }
    }
    return result;
}
 
Example 11
Source File: StackedAreaRenderer.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculates the stacked values (one positive and one negative) of all
 * series up to, but not including, <code>series</code> for the specified
 * item. It returns [0.0, 0.0] if <code>series</code> is the first series.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series index.
 * @param index  the item index.
 * @param validRows  the valid rows.
 *
 * @return An array containing the cumulative negative and positive values
 *     for all series values up to but excluding <code>series</code>
 *     for <code>index</code>.
 */
protected double[] getStackValues(CategoryDataset dataset,
        int series, int index, int[] validRows) {
    double[] result = new double[2];
    double total = 0.0;
    if (this.renderAsPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset, index, 
                validRows);
    }
    for (int i = 0; i < series; i++) {
        if (isSeriesVisible(i)) {
            double v = 0.0;
            Number n = dataset.getValue(i, index);
            if (n != null) {
                v = n.doubleValue();
                if (this.renderAsPercentages) {
                    v = v / total;
                }
            }
            if (!Double.isNaN(v)) {
                if (v >= 0.0) {
                    result[1] += v;
                }
                else {
                    result[0] += v;
                }
            }
        }
    }
    return result;
}
 
Example 12
Source File: StackedAreaRenderer.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculates the stacked values (one positive and one negative) of all
 * series up to, but not including, <code>series</code> for the specified
 * item. It returns [0.0, 0.0] if <code>series</code> is the first series.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series index.
 * @param index  the item index.
 * @param validRows  the valid rows.
 *
 * @return An array containing the cumulative negative and positive values
 *     for all series values up to but excluding <code>series</code>
 *     for <code>index</code>.
 */
protected double[] getStackValues(CategoryDataset dataset,
        int series, int index, int[] validRows) {
    double[] result = new double[2];
    double total = 0.0;
    if (this.renderAsPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset, index, 
                validRows);
    }
    for (int i = 0; i < series; i++) {
        if (isSeriesVisible(i)) {
            double v = 0.0;
            Number n = dataset.getValue(i, index);
            if (n != null) {
                v = n.doubleValue();
                if (this.renderAsPercentages) {
                    v = v / total;
                }
            }
            if (!Double.isNaN(v)) {
                if (v >= 0.0) {
                    result[1] += v;
                }
                else {
                    result[0] += v;
                }
            }
        }
    }
    return result;
}
 
Example 13
Source File: AggregationExecutionChartBuilder.java    From livingdoc-confluence with GNU General Public License v3.0 5 votes vote down vote up
private double getColumnTotal(CategoryDataset dataset, int column) {
    Double total = totals.get(column);

    if (total == null) {
        total = DataUtilities.calculateColumnTotal(dataset, column);
        totals.put(column, total);
    }

    return total;
}
 
Example 14
Source File: StackedAreaRenderer.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates the stacked values (one positive and one negative) of all
 * series up to, but not including, <code>series</code> for the specified
 * item. It returns [0.0, 0.0] if <code>series</code> is the first series.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series index.
 * @param index  the item index.
 * @param validRows  the valid rows.
 *
 * @return An array containing the cumulative negative and positive values
 *     for all series values up to but excluding <code>series</code>
 *     for <code>index</code>.
 */
protected double[] getStackValues(CategoryDataset dataset,
        int series, int index, int[] validRows) {
    double[] result = new double[2];
    double total = 0.0;
    if (this.renderAsPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset, index, 
                validRows);
    }
    for (int i = 0; i < series; i++) {
        if (isSeriesVisible(i)) {
            double v = 0.0;
            Number n = dataset.getValue(i, index);
            if (n != null) {
                v = n.doubleValue();
                if (this.renderAsPercentages) {
                    v = v / total;
                }
            }
            if (!Double.isNaN(v)) {
                if (v >= 0.0) {
                    result[1] += v;
                }
                else {
                    result[0] += v;
                }
            }
        }
    }
    return result;
}
 
Example 15
Source File: Test.java    From IntelliJDeodorant with MIT License 4 votes vote down vote up
protected List createStackedValueList(CategoryDataset dataset,
                                      Comparable category, int[] includedRows, double base,
                                      boolean asPercentages) {

    List result = new ArrayList();
    double posBase = base;
    double negBase = base;
    double total = 0.0;
    if (asPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset,
                dataset.getColumnIndex(category), includedRows);
    }

    int baseIndex = -1;
    int rowCount = includedRows.length;
    for (int i = 0; i < rowCount; i++) {
        int r = includedRows[i];
        Number n = dataset.getValue(dataset.getRowKey(r), category);
        if (n == null) {
            continue;
        }
        double v = n.doubleValue();
        if (asPercentages) {
            v = v / total;
        }
        if ((v > 0.0) || (!this.ignoreZeroValues && v >= 0.0)) {
            if (baseIndex < 0) {
                result.add(new Object[]{null, new Double(base)});
                baseIndex = 0;
            }
            posBase = posBase + v;
            result.add(new Object[]{new Integer(r), new Double(posBase)});
        } else if (v < 0.0) {
            if (baseIndex < 0) {
                result.add(new Object[]{null, new Double(base)});
                baseIndex = 0;
            }
            negBase = negBase + v;
            result.add(0, new Object[]{new Integer(-r - 1),
                    new Double(negBase)});
            baseIndex++;
        }
    }
    return result;

}
 
Example 16
Source File: StackedBarRenderer3D.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a list containing the stacked values for the specified series
 * in the given dataset, plus the supplied base value.
 *  
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param category  the category key (<code>null</code> not permitted).
 * @param base  the base value.
 * @param asPercentages  a flag that controls whether the values in the
 *     list are converted to percentages of the total.
 *     
 * @return The value list.
 *
 * @since 1.2.0
 */
protected List createStackedValueList(CategoryDataset dataset, 
        Comparable category, double base, boolean asPercentages) {
    
    List result = new ArrayList();
    double posBase = base;
    double negBase = base;
    double total = 0.0;
    if (asPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset, 
                dataset.getColumnIndex(category));
    }

    int baseIndex = -1;
    int seriesCount = dataset.getRowCount();
    for (int s = 0; s < seriesCount; s++) {
        Number n = dataset.getValue(dataset.getRowKey(s), category);
        if (n == null) {
            continue;
        }
        double v = n.doubleValue();
        if (asPercentages) {
            v = v / total;
        }
        if ((v > 0.0) || (!this.ignoreZeroValues && v >= 0.0)) {
            if (baseIndex < 0) {
                result.add(new Object[] {null, new Double(base)});
                baseIndex = 0;
            }
            posBase = posBase + v;
            result.add(new Object[] {new Integer(s), new Double(posBase)});
        }
        else if (v < 0.0) {
            if (baseIndex < 0) {
                result.add(new Object[] {null, new Double(base)});
                baseIndex = 0;
            }
            negBase = negBase + v; // '+' because v is negative
            result.add(0, new Object[] {new Integer(-s), 
                    new Double(negBase)});
            baseIndex++;
        }
    }
    return result;
    
}
 
Example 17
Source File: StackedBarRenderer3D.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a list containing the stacked values for the specified series
 * in the given dataset, plus the supplied base value.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param category  the category key (<code>null</code> not permitted).
 * @param includedRows  the included rows.
 * @param base  the base value.
 * @param asPercentages  a flag that controls whether the values in the
 *     list are converted to percentages of the total.
 *
 * @return The value list.
 *
 * @since 1.0.13
 */
protected List createStackedValueList(CategoryDataset dataset,
        Comparable category, int[] includedRows, double base,
        boolean asPercentages) {

    List result = new ArrayList();
    double posBase = base;
    double negBase = base;
    double total = 0.0;
    if (asPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset,
                dataset.getColumnIndex(category), includedRows);
    }

    int baseIndex = -1;
    int rowCount = includedRows.length;
    for (int i = 0; i < rowCount; i++) {
        int r = includedRows[i];
        Number n = dataset.getValue(dataset.getRowKey(r), category);
        if (n == null) {
            continue;
        }
        double v = n.doubleValue();
        if (asPercentages) {
            v = v / total;
        }
        if ((v > 0.0) || (!this.ignoreZeroValues && v >= 0.0)) {
            if (baseIndex < 0) {
                result.add(new Object[] {null, new Double(base)});
                baseIndex = 0;
            }
            posBase = posBase + v;
            result.add(new Object[] {new Integer(r), new Double(posBase)});
        }
        else if (v < 0.0) {
            if (baseIndex < 0) {
                result.add(new Object[] {null, new Double(base)});
                baseIndex = 0;
            }
            negBase = negBase + v; // '+' because v is negative
            result.add(0, new Object[] {new Integer(-r - 1),
                    new Double(negBase)});
            baseIndex++;
        }
    }
    return result;

}
 
Example 18
Source File: TestProduct.java    From IntelliJDeodorant with MIT License 4 votes vote down vote up
public List createStackedValueList(CategoryDataset dataset,
                                   Comparable category, int[] includedRows, double base,
                                   boolean asPercentages) {

    List result = new ArrayList();
    double posBase = base;
    double negBase = base;
    double total = 0.0;
    if (asPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset,
                dataset.getColumnIndex(category), includedRows);
    }

    int baseIndex = -1;
    int rowCount = includedRows.length;
    for (int i = 0; i < rowCount; i++) {
        int r = includedRows[i];
        Number n = dataset.getValue(dataset.getRowKey(r), category);
        if (n == null) {
            continue;
        }
        double v = n.doubleValue();
        if (asPercentages) {
            v = v / total;
        }
        if ((v > 0.0) || (!this.ignoreZeroValues && v >= 0.0)) {
            if (baseIndex < 0) {
                result.add(new Object[]{null, new Double(base)});
                baseIndex = 0;
            }
            posBase = posBase + v;
            result.add(new Object[]{new Integer(r), new Double(posBase)});
        } else if (v < 0.0) {
            if (baseIndex < 0) {
                result.add(new Object[]{null, new Double(base)});
                baseIndex = 0;
            }
            negBase = negBase + v;
            result.add(0, new Object[]{new Integer(-r - 1),
                    new Double(negBase)});
            baseIndex++;
        }
    }
    return result;

}
 
Example 19
Source File: StackedBarRenderer3D.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a list containing the stacked values for the specified series
 * in the given dataset, plus the supplied base value.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param category  the category key (<code>null</code> not permitted).
 * @param includedRows  the included rows.
 * @param base  the base value.
 * @param asPercentages  a flag that controls whether the values in the
 *     list are converted to percentages of the total.
 *
 * @return The value list.
 *
 * @since 1.0.13
 */
protected List createStackedValueList(CategoryDataset dataset,
        Comparable category, int[] includedRows, double base,
        boolean asPercentages) {

    List result = new ArrayList();
    double posBase = base;
    double negBase = base;
    double total = 0.0;
    if (asPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset,
                dataset.getColumnIndex(category), includedRows);
    }

    int baseIndex = -1;
    int rowCount = includedRows.length;
    for (int i = 0; i < rowCount; i++) {
        int r = includedRows[i];
        Number n = dataset.getValue(dataset.getRowKey(r), category);
        if (n == null) {
            continue;
        }
        double v = n.doubleValue();
        if (asPercentages) {
            v = v / total;
        }
        if ((v > 0.0) || (!this.ignoreZeroValues && v >= 0.0)) {
            if (baseIndex < 0) {
                result.add(new Object[] {null, new Double(base)});
                baseIndex = 0;
            }
            posBase = posBase + v;
            result.add(new Object[] {new Integer(r), new Double(posBase)});
        }
        else if (v < 0.0) {
            if (baseIndex < 0) {
                result.add(new Object[] {null, new Double(base)});
                baseIndex = 0;
            }
            negBase = negBase + v; // '+' because v is negative
            result.add(0, new Object[] {new Integer(-r - 1),
                    new Double(negBase)});
            baseIndex++;
        }
    }
    return result;

}
 
Example 20
Source File: StackedBarRenderer3D.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a list containing the stacked values for the specified series
 * in the given dataset, plus the supplied base value.
 *  
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param category  the category key (<code>null</code> not permitted).
 * @param base  the base value.
 * @param asPercentages  a flag that controls whether the values in the
 *     list are converted to percentages of the total.
 *     
 * @return The value list.
 *
 * @since 1.0.4
 */
protected static List createStackedValueList(CategoryDataset dataset, 
        Comparable category, double base, boolean asPercentages) {
    
    List result = new ArrayList();
    double posBase = base;
    double negBase = base;
    double total = 0.0;
    if (asPercentages) {
        total = DataUtilities.calculateColumnTotal(dataset, 
                dataset.getColumnIndex(category));
    }

    int baseIndex = -1;
    int seriesCount = dataset.getRowCount();
    for (int s = 0; s < seriesCount; s++) {
        Number n = dataset.getValue(dataset.getRowKey(s), category);
        if (n == null) {
            continue;
        }
        double v = n.doubleValue();
        if (asPercentages) {
            v = v / total;
        }
        if (v >= 0.0) {
            if (baseIndex < 0) {
                result.add(new Object[] {null, new Double(base)});
                baseIndex = 0;
            }
            posBase = posBase + v;
            result.add(new Object[] {new Integer(s), new Double(posBase)});
        }
        else if (v < 0.0) {
            if (baseIndex < 0) {
                result.add(new Object[] {null, new Double(base)});
                baseIndex = 0;
            }
            negBase = negBase + v; // '+' because v is negative
            result.add(0, new Object[] {new Integer(-s), 
                    new Double(negBase)});
            baseIndex++;
        }
    }
    return result;
    
}