Java Code Examples for org.jfree.data.category.CategoryDataset#getColumnCount()

The following examples show how to use org.jfree.data.category.CategoryDataset#getColumnCount() . 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: jMutRepair_0021_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns a list of the categories that should be displayed for the
 * specified axis.
 * 
 * @param axis  the axis (<code>null</code> not permitted)
 * 
 * @return The categories.
 * 
 * @since 1.0.3
 */
public List getCategoriesForAxis(CategoryAxis axis) {
    List result = new ArrayList();
    int axisIndex = this.domainAxes.indexOf(axis);
    List datasets = datasetsMappedToDomainAxis(axisIndex);
    Iterator iterator = datasets.iterator();
    while (iterator.hasNext()) {
        CategoryDataset dataset = (CategoryDataset) iterator.next();
        // add the unique categories from this dataset
        for (int i = 0; i < dataset.getColumnCount(); i++) {
            Comparable category = dataset.getColumnKey(i);
            if (!result.contains(category)) {
                result.add(category);
            }
        }
    }
    return result;
}
 
Example 2
Source File: JGenProg2017_005_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns a list of the categories that should be displayed for the
 * specified axis.
 * 
 * @param axis  the axis (<code>null</code> not permitted)
 * 
 * @return The categories.
 * 
 * @since 1.0.3
 */
public List getCategoriesForAxis(CategoryAxis axis) {
    List result = new ArrayList();
    int axisIndex = this.domainAxes.indexOf(axis);
    List datasets = datasetsMappedToDomainAxis(axisIndex);
    Iterator iterator = datasets.iterator();
    while (iterator.hasNext()) {
        CategoryDataset dataset = (CategoryDataset) iterator.next();
        // add the unique categories from this dataset
        for (int i = 0; i < dataset.getColumnCount(); i++) {
            Comparable category = dataset.getColumnKey(i);
            if (!result.contains(category)) {
                result.add(category);
            }
        }
    }
    return result;
}
 
Example 3
Source File: BarRenderer.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates the bar width and stores it in the renderer state.
 *
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param rendererIndex  the renderer index.
 * @param state  the renderer state.
 */
protected void calculateBarWidth(CategoryPlot plot,
                                 Rectangle2D dataArea,
                                 int rendererIndex,
                                 CategoryItemRendererState state) {

    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset dataset = plot.getDataset(rendererIndex);
    if (dataset != null) {
        int columns = dataset.getColumnCount();
        int rows = state.getVisibleSeriesCount() >= 0
                ? state.getVisibleSeriesCount() : dataset.getRowCount();
        double space = 0.0;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaximumBarWidth();
        double categoryMargin = 0.0;
        double currentItemMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }
        if (rows > 1) {
            currentItemMargin = getItemMargin();
        }
        double used = space * (1 - domainAxis.getLowerMargin()
                                 - domainAxis.getUpperMargin()
                                 - categoryMargin - currentItemMargin);
        if ((rows * columns) > 0) {
            state.setBarWidth(Math.min(used / (rows * columns), maxWidth));
        }
        else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }
}
 
Example 4
Source File: LayeredBarRenderer.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculates the bar width and stores it in the renderer state.
 *
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param rendererIndex  the renderer index.
 * @param state  the renderer state.
 */
@Override
protected void calculateBarWidth(CategoryPlot plot, Rectangle2D dataArea,
        int rendererIndex, CategoryItemRendererState state) {

    // calculate the bar width - this calculation differs from the
    // BarRenderer calculation because the bars are layered on top of one
    // another, so there is effectively only one bar per category for
    // the purpose of the bar width calculation
    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset dataset = plot.getDataset(rendererIndex);
    if (dataset != null) {
        int columns = dataset.getColumnCount();
        int rows = dataset.getRowCount();
        double space = 0.0;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaximumBarWidth();
        double categoryMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }
        double used = space * (1 - domainAxis.getLowerMargin()
            - domainAxis.getUpperMargin() - categoryMargin);
        if ((rows * columns) > 0) {
            state.setBarWidth(Math.min(used / (dataset.getColumnCount()),
                    maxWidth));
        }
        else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }
}
 
Example 5
Source File: DatasetUtilities.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the maximum value in the dataset range, assuming that values in
 * each category are "stacked".
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The maximum value (possibly <code>null</code>).
 *
 * @see #findMinimumStackedRangeValue(CategoryDataset)
 */
public static Number findMaximumStackedRangeValue(CategoryDataset dataset) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    Number result = null;
    boolean hasValidData = false;
    double maximum = 0.0;
    int categoryCount = dataset.getColumnCount();
    for (int item = 0; item < categoryCount; item++) {
        double total = 0.0;
        int seriesCount = dataset.getRowCount();
        for (int series = 0; series < seriesCount; series++) {
            Number number = dataset.getValue(series, item);
            if (number != null) {
                hasValidData = true;
                double value = number.doubleValue();
                if (value > 0.0) {
                    total = total + value;
                }
            }
        }
        maximum = Math.max(maximum, total);
    }
    if (hasValidData) {
        result = new Double(maximum);
    }
    return result;
}
 
Example 6
Source File: patch1-Chart-26-jMutRepair_patch1-Chart-26-jMutRepair_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Draws the gridlines for the plot.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 * 
 * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List)
 */
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea) {

    // draw the domain grid lines, if any...
    if (isDomainGridlinesVisible()) {
        CategoryAnchor anchor = getDomainGridlinePosition();
        RectangleEdge domainAxisEdge = getDomainAxisEdge();
        Stroke gridStroke = getDomainGridlineStroke();
        Paint gridPaint = getDomainGridlinePaint();
        if ((gridStroke != null) && (gridPaint != null)) {
            // iterate over the categories
            CategoryDataset data = getDataset();
            if (data != null) {
                CategoryAxis axis = getDomainAxis();
                if (axis != null) {
                    int columnCount = data.getColumnCount();
                    for (int c = 0; c < columnCount; c++) {
                        double xx = axis.getCategoryJava2DCoordinate(
                                anchor, c, columnCount, dataArea, 
                                domainAxisEdge);
                        CategoryItemRenderer renderer1 = getRenderer();
                        if (renderer1 != null) {
                            renderer1.drawDomainGridline(g2, this, 
                                    dataArea, xx);
                        }
                    }
                }
            }
        }
    }
}
 
Example 7
Source File: Cardumen_00194_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Creates a pie dataset from a table dataset by taking all the values
 * for a single row.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param row  the row (zero-based index).
 *
 * @return A pie dataset.
 */
public static PieDataset createPieDatasetForRow(CategoryDataset dataset, 
                                                int row) {
    DefaultPieDataset result = new DefaultPieDataset();
    int columnCount = dataset.getColumnCount();
    for (int current = 0; current < columnCount; current++) {
        Comparable columnKey = dataset.getColumnKey(current);
        result.setValue(columnKey, dataset.getValue(row, current));
    }
    return result;
}
 
Example 8
Source File: CategoryTextAnnotation.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  the plot info (<code>null</code> permitted).
 */
public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea,
        CategoryAxis domainAxis, ValueAxis rangeAxis, 
        int rendererIndex, PlotRenderingInfo info) {

    CategoryDataset dataset = plot.getDataset();
    int catIndex = dataset.getColumnIndex(this.category);
    int catCount = dataset.getColumnCount();

    float anchorX = 0.0f;
    float anchorY = 0.0f;
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);
    
    if (orientation == PlotOrientation.HORIZONTAL) {
        anchorY = (float) domainAxis.getCategoryJava2DCoordinate(
                this.categoryAnchor, catIndex, catCount, dataArea, 
                domainEdge);
        anchorX = (float) rangeAxis.valueToJava2D(this.value, dataArea, 
                rangeEdge);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        anchorX = (float) domainAxis.getCategoryJava2DCoordinate(
                this.categoryAnchor, catIndex, catCount, dataArea, 
                domainEdge);
        anchorY = (float) rangeAxis.valueToJava2D(this.value, dataArea, 
                rangeEdge);
    }
    g2.setFont(getFont());
    g2.setPaint(getPaint());
    TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY,
            getTextAnchor(), getRotationAngle(), getRotationAnchor());

}
 
Example 9
Source File: DatasetUtilities.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the minimum value in the dataset range, assuming that values in
 * each category are "stacked".
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The minimum value.
 *
 * @see #findMaximumStackedRangeValue(CategoryDataset)
 */
public static Number findMinimumStackedRangeValue(CategoryDataset dataset) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    Number result = null;
    boolean hasValidData = false;
    double minimum = 0.0;
    int categoryCount = dataset.getColumnCount();
    for (int item = 0; item < categoryCount; item++) {
        double total = 0.0;
        int seriesCount = dataset.getRowCount();
        for (int series = 0; series < seriesCount; series++) {
            Number number = dataset.getValue(series, item);
            if (number != null) {
                hasValidData = true;
                double value = number.doubleValue();
                if (value < 0.0) {
                    total = total + value;
                    // '+', remember value is negative
                }
            }
        }
        minimum = Math.min(minimum, total);
    }
    if (hasValidData) {
        result = new Double(minimum);
    }
    return result;
}
 
Example 10
Source File: BarRenderer.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculates the bar width and stores it in the renderer state.
 *
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param rendererIndex  the renderer index.
 * @param state  the renderer state.
 */
protected void calculateBarWidth(CategoryPlot plot,
                                 Rectangle2D dataArea,
                                 int rendererIndex,
                                 CategoryItemRendererState state) {

    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset dataset = plot.getDataset(rendererIndex);
    if (dataset != null) {
        int columns = dataset.getColumnCount();
        int rows = state.getVisibleSeriesCount() >= 0
                ? state.getVisibleSeriesCount() : dataset.getRowCount();
        double space = 0.0;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaximumBarWidth();
        double categoryMargin = 0.0;
        double currentItemMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }
        if (rows > 1) {
            currentItemMargin = getItemMargin();
        }
        double used = space * (1 - domainAxis.getLowerMargin()
                                 - domainAxis.getUpperMargin()
                                 - categoryMargin - currentItemMargin);
        if ((rows * columns) > 0) {
            state.setBarWidth(Math.min(used / (rows * columns), maxWidth));
        }
        else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }
}
 
Example 11
Source File: jMutRepair_001_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Draws the gridlines for the plot.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 * 
 * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List)
 */
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea) {

    // draw the domain grid lines, if any...
    if (isDomainGridlinesVisible()) {
        CategoryAnchor anchor = getDomainGridlinePosition();
        RectangleEdge domainAxisEdge = getDomainAxisEdge();
        Stroke gridStroke = getDomainGridlineStroke();
        Paint gridPaint = getDomainGridlinePaint();
        if ((gridStroke != null) && (gridPaint != null)) {
            // iterate over the categories
            CategoryDataset data = getDataset();
            if (data != null) {
                CategoryAxis axis = getDomainAxis();
                if (axis != null) {
                    int columnCount = data.getColumnCount();
                    for (int c = 0; c < columnCount; c++) {
                        double xx = axis.getCategoryJava2DCoordinate(
                                anchor, c, columnCount, dataArea, 
                                domainAxisEdge);
                        CategoryItemRenderer renderer1 = getRenderer();
                        if (renderer1 != null) {
                            renderer1.drawDomainGridline(g2, this, 
                                    dataArea, xx);
                        }
                    }
                }
            }
        }
    }
}
 
Example 12
Source File: Cardumen_0079_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Iterates over the data item of the category dataset to find
 * the range bounds.
 * 
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  a flag that determines whether or not the
 *                         y-interval is taken into account.
 * 
 * @return The range (possibly <code>null</code>).
 */
public static Range iterateCategoryRangeBounds(CategoryDataset dataset, 
        boolean includeInterval) {
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    boolean interval = includeInterval 
                       && dataset instanceof IntervalCategoryDataset;
    int rowCount = dataset.getRowCount();
    int columnCount = dataset.getColumnCount();
    for (int row = 0; row < rowCount; row++) {
        for (int column = 0; column < columnCount; column++) {
            Number lvalue;
            Number uvalue;
            if (interval) {
                IntervalCategoryDataset icd 
                    = (IntervalCategoryDataset) dataset;
                lvalue = icd.getStartValue(row, column);
                uvalue = icd.getEndValue(row, column);
            }
            else {
                lvalue = dataset.getValue(row, column);
                uvalue = lvalue;
            }
            if (lvalue != null) {
                minimum = Math.min(minimum, lvalue.doubleValue());
            }
            if (uvalue != null) {
                maximum = Math.max(maximum, uvalue.doubleValue());
            }
        }
    }
    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    }
    else {
        return new Range(minimum, maximum);
    }
}
 
Example 13
Source File: DatasetUtilities.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates the range of values for a dataset where each item is the
 * running total of the items for the current series.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The range.
 *
 * @see #findRangeBounds(CategoryDataset)
 */
public static Range findCumulativeRangeBounds(CategoryDataset dataset) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    boolean allItemsNull = true; // we'll set this to false if there is at
                                 // least one non-null data item...
    double minimum = 0.0;
    double maximum = 0.0;
    for (int row = 0; row < dataset.getRowCount(); row++) {
        double runningTotal = 0.0;
        for (int column = 0; column <= dataset.getColumnCount() - 1;
             column++) {
            Number n = dataset.getValue(row, column);
            if (n != null) {
                allItemsNull = false;
                double value = n.doubleValue();
                if (!Double.isNaN(value)) {
                    runningTotal = runningTotal + value;
                    minimum = Math.min(minimum, runningTotal);
                    maximum = Math.max(maximum, runningTotal);
                }
            }
        }
    }
    if (!allItemsNull) {
        return new Range(minimum, maximum);
    }
    else {
        return null;
    }
}
 
Example 14
Source File: BoxAndWhiskerRenderer.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Initialises the renderer.  This method gets called once at the start of
 * the process of drawing a chart.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area in which the data is to be plotted.
 * @param plot  the plot.
 * @param rendererIndex  the renderer index.
 * @param info  collects chart rendering information for return to caller.
 *
 * @return The renderer state.
 */
@Override
public CategoryItemRendererState initialise(Graphics2D g2, 
        Rectangle2D dataArea, CategoryPlot plot, int rendererIndex,
        PlotRenderingInfo info) {

    CategoryItemRendererState state = super.initialise(g2, dataArea, plot,
            rendererIndex, info);
    // calculate the box width
    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset dataset = plot.getDataset(rendererIndex);
    if (dataset != null) {
        int columns = dataset.getColumnCount();
        int rows = dataset.getRowCount();
        double space = 0.0;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaximumBarWidth();
        double categoryMargin = 0.0;
        double currentItemMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }
        if (rows > 1) {
            currentItemMargin = getItemMargin();
        }
        double used = space * (1 - domainAxis.getLowerMargin()
                                 - domainAxis.getUpperMargin()
                                 - categoryMargin - currentItemMargin);
        if ((rows * columns) > 0) {
            state.setBarWidth(Math.min(used / (dataset.getColumnCount()
                    * dataset.getRowCount()), maxWidth));
        }
        else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }
    return state;

}
 
Example 15
Source File: jMutRepair_0021_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a representation of a dataset within the dataArea region using the
 * appropriate renderer.
 *
 * @param g2  the graphics device.
 * @param dataArea  the region in which the data is to be drawn.
 * @param index  the dataset and renderer index.
 * @param info  an optional object for collection dimension information.
 * 
 * @return A boolean that indicates whether or not real data was found.
 */
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, 
                      PlotRenderingInfo info) {

    boolean foundData = false;
    CategoryDataset currentDataset = getDataset(index);
    CategoryItemRenderer renderer = getRenderer(index);
    CategoryAxis domainAxis = getDomainAxisForDataset(index);
    ValueAxis rangeAxis = getRangeAxisForDataset(index);
    boolean hasData = !DatasetUtilities.isEmptyOrNull(currentDataset);
    if (hasData && renderer != null) {
        
        foundData = true;
        CategoryItemRendererState state = renderer.initialise(g2, dataArea,
                this, index, info);
        int columnCount = currentDataset.getColumnCount();
        int rowCount = currentDataset.getRowCount();
        int passCount = renderer.getPassCount();
        for (int pass = 0; pass < passCount; pass++) {            
            if (this.columnRenderingOrder == SortOrder.ASCENDING) {
                for (int column = 0; column < columnCount; column++) {
                    if (this.rowRenderingOrder == SortOrder.ASCENDING) {
                        for (int row = 0; row < rowCount; row++) {
                            renderer.drawItem(g2, state, dataArea, this, 
                                    domainAxis, rangeAxis, currentDataset, 
                                    row, column, pass);
                        }
                    }
                    else {
                        for (int row = rowCount - 1; row >= 0; row--) {
                            renderer.drawItem(g2, state, dataArea, this, 
                                    domainAxis, rangeAxis, currentDataset, 
                                    row, column, pass);
                        }                        
                    }
                }
            }
            else {
                for (int column = columnCount - 1; column >= 0; column--) {
                    if (this.rowRenderingOrder == SortOrder.ASCENDING) {
                        for (int row = 0; row < rowCount; row++) {
                            renderer.drawItem(g2, state, dataArea, this, 
                                    domainAxis, rangeAxis, currentDataset, 
                                    row, column, pass);
                        }
                    }
                    else {
                        for (int row = rowCount - 1; row >= 0; row--) {
                            renderer.drawItem(g2, state, dataArea, this, 
                                    domainAxis, rangeAxis, currentDataset, 
                                    row, column, pass);
                        }                        
                    }
                }
            }
        }
    }
    return foundData;
    
}
 
Example 16
Source File: Cardumen_0079_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns the maximum range value for the specified dataset.  This is easy
 * if the dataset implements the {@link RangeInfo} interface (a good idea 
 * if there is an efficient way to determine the maximum value).  
 * Otherwise, it involves iterating over the entire data-set.  Returns 
 * <code>null</code> if all the data values are <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The maximum value (possibly <code>null</code>).
 */
public static Number findMaximumRangeValue(CategoryDataset dataset) {

    if (dataset == null) {
        throw new IllegalArgumentException("Null 'dataset' argument.");
    }

    // work out the minimum value...
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeUpperBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else {

        double maximum = Double.NEGATIVE_INFINITY;
        int seriesCount = dataset.getRowCount();
        int itemCount = dataset.getColumnCount();
        for (int series = 0; series < seriesCount; series++) {
            for (int item = 0; item < itemCount; item++) {
                Number value;
                if (dataset instanceof IntervalCategoryDataset) {
                    IntervalCategoryDataset icd 
                        = (IntervalCategoryDataset) dataset;
                    value = icd.getEndValue(series, item);
                }
                else {
                    value = dataset.getValue(series, item);
                }
                if (value != null) {
                    maximum = Math.max(maximum, value.doubleValue());
                }
            }
        }
        if (maximum == Double.NEGATIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(maximum);
        }

    }

}
 
Example 17
Source File: CategoryLineAnnotation.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 */
@Override
public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea,
                 CategoryAxis domainAxis, ValueAxis rangeAxis) {

    CategoryDataset dataset = plot.getDataset();
    int catIndex1 = dataset.getColumnIndex(this.category1);
    int catIndex2 = dataset.getColumnIndex(this.category2);
    int catCount = dataset.getColumnCount();

    double lineX1 = 0.0f;
    double lineY1 = 0.0f;
    double lineX2 = 0.0f;
    double lineY2 = 0.0f;
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
        plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
        plot.getRangeAxisLocation(), orientation);

    if (orientation == PlotOrientation.HORIZONTAL) {
        lineY1 = domainAxis.getCategoryJava2DCoordinate(
            CategoryAnchor.MIDDLE, catIndex1, catCount, dataArea,
            domainEdge);
        lineX1 = rangeAxis.valueToJava2D(this.value1, dataArea, rangeEdge);
        lineY2 = domainAxis.getCategoryJava2DCoordinate(
            CategoryAnchor.MIDDLE, catIndex2, catCount, dataArea,
            domainEdge);
        lineX2 = rangeAxis.valueToJava2D(this.value2, dataArea, rangeEdge);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        lineX1 = domainAxis.getCategoryJava2DCoordinate(
            CategoryAnchor.MIDDLE, catIndex1, catCount, dataArea,
            domainEdge);
        lineY1 = rangeAxis.valueToJava2D(this.value1, dataArea, rangeEdge);
        lineX2 = domainAxis.getCategoryJava2DCoordinate(
            CategoryAnchor.MIDDLE, catIndex2, catCount, dataArea,
            domainEdge);
        lineY2 = rangeAxis.valueToJava2D(this.value2, dataArea, rangeEdge);
    }
    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    g2.drawLine((int) lineX1, (int) lineY1, (int) lineX2, (int) lineY2);
}
 
Example 18
Source File: Cardumen_00194_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns the minimum and maximum values for the dataset's range 
 * (y-values), assuming that the series in one category are stacked.
 *
 * @param dataset  the dataset.
 * @param map  a structure that maps series to groups.
 *
 * @return The value range (<code>null</code> if the dataset contains no 
 *         values).
 */
public static Range findStackedRangeBounds(CategoryDataset dataset,
                                           KeyToGroupMap map) {

    Range result = null;
    if (dataset != null) {
        
        // create an array holding the group indices...
        int[] groupIndex = new int[dataset.getRowCount()];
        for (int i = 0; i < dataset.getRowCount(); i++) {
            groupIndex[i] = map.getGroupIndex(
                map.getGroup(dataset.getRowKey(i))
            );   
        }
        
        // minimum and maximum for each group...
        int groupCount = map.getGroupCount();
        double[] minimum = new double[groupCount];
        double[] maximum = new double[groupCount];
        
        int categoryCount = dataset.getColumnCount();
        for (int item = 0; item < categoryCount; item++) {
            double[] positive = new double[groupCount];
            double[] negative = new double[groupCount];
            int seriesCount = dataset.getRowCount();
            for (int series = 0; series < seriesCount; series++) {
                Number number = dataset.getValue(series, item);
                if (number != null) {
                    double value = number.doubleValue();
                    if (value > 0.0) {
                        positive[groupIndex[series]] 
                             = positive[groupIndex[series]] + value;
                    }
                    if (value < 0.0) {
                        negative[groupIndex[series]] 
                             = negative[groupIndex[series]] + value;
                             // '+', remember value is negative
                    }
                }
            }
            for (int g = 0; g < groupCount; g++) {
                minimum[g] = Math.min(minimum[g], negative[g]);
                maximum[g] = Math.max(maximum[g], positive[g]);
            }
        }
        for (int j = 0; j < groupCount; j++) {
            result = Range.combine(
                result, new Range(minimum[j], maximum[j])
            );
        }
    }
    return result;

}
 
Example 19
Source File: jMutRepair_0021_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a representation of a dataset within the dataArea region using the
 * appropriate renderer.
 *
 * @param g2  the graphics device.
 * @param dataArea  the region in which the data is to be drawn.
 * @param index  the dataset and renderer index.
 * @param info  an optional object for collection dimension information.
 * 
 * @return A boolean that indicates whether or not real data was found.
 */
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, 
                      PlotRenderingInfo info) {

    boolean foundData = false;
    CategoryDataset currentDataset = getDataset(index);
    CategoryItemRenderer renderer = getRenderer(index);
    CategoryAxis domainAxis = getDomainAxisForDataset(index);
    ValueAxis rangeAxis = getRangeAxisForDataset(index);
    boolean hasData = !DatasetUtilities.isEmptyOrNull(currentDataset);
    if (hasData && renderer != null) {
        
        foundData = true;
        CategoryItemRendererState state = renderer.initialise(g2, dataArea,
                this, index, info);
        int columnCount = currentDataset.getColumnCount();
        int rowCount = currentDataset.getRowCount();
        int passCount = renderer.getPassCount();
        for (int pass = 0; pass < passCount; pass++) {            
            if (this.columnRenderingOrder == SortOrder.ASCENDING) {
                for (int column = 0; column < columnCount; column++) {
                    if (this.rowRenderingOrder == SortOrder.ASCENDING) {
                        for (int row = 0; row < rowCount; row++) {
                            renderer.drawItem(g2, state, dataArea, this, 
                                    domainAxis, rangeAxis, currentDataset, 
                                    row, column, pass);
                        }
                    }
                    else {
                        for (int row = rowCount - 1; row >= 0; row--) {
                            renderer.drawItem(g2, state, dataArea, this, 
                                    domainAxis, rangeAxis, currentDataset, 
                                    row, column, pass);
                        }                        
                    }
                }
            }
            else {
                for (int column = columnCount - 1; column >= 0; column--) {
                    if (this.rowRenderingOrder == SortOrder.ASCENDING) {
                        for (int row = 0; row < rowCount; row++) {
                            renderer.drawItem(g2, state, dataArea, this, 
                                    domainAxis, rangeAxis, currentDataset, 
                                    row, column, pass);
                        }
                    }
                    else {
                        for (int row = rowCount - 1; row >= 0; row--) {
                            renderer.drawItem(g2, state, dataArea, this, 
                                    domainAxis, rangeAxis, currentDataset, 
                                    row, column, pass);
                        }                        
                    }
                }
            }
        }
    }
    return foundData;
    
}
 
Example 20
Source File: JGenProg2017_0081_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a representation of a dataset within the dataArea region using the
 * appropriate renderer.
 *
 * @param g2  the graphics device.
 * @param dataArea  the region in which the data is to be drawn.
 * @param index  the dataset and renderer index.
 * @param info  an optional object for collection dimension information.
 * 
 * @return A boolean that indicates whether or not real data was found.
 */
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, 
                      PlotRenderingInfo info) {

    boolean foundData = false;
    CategoryDataset currentDataset = getDataset(index);
    CategoryItemRenderer renderer = getRenderer(index);
    CategoryAxis domainAxis = getDomainAxisForDataset(index);
    ValueAxis rangeAxis = getRangeAxisForDataset(index);
    boolean hasData = !DatasetUtilities.isEmptyOrNull(currentDataset);
    if (hasData && renderer != null) {
        
        foundData = true;
        CategoryItemRendererState state = renderer.initialise(g2, dataArea,
                this, index, info);
        int columnCount = currentDataset.getColumnCount();
        int rowCount = currentDataset.getRowCount();
        int passCount = renderer.getPassCount();
        for (int pass = 0; pass < passCount; pass++) {            
            if (this.columnRenderingOrder == SortOrder.ASCENDING) {
                for (int column = 0; column < columnCount; column++) {
                    if (this.rowRenderingOrder == SortOrder.ASCENDING) {
                        for (int row = 0; row < rowCount; row++) {
                            renderer.drawItem(g2, state, dataArea, this, 
                                    domainAxis, rangeAxis, currentDataset, 
                                    row, column, pass);
                        }
                    }
                    else {
                        for (int row = rowCount - 1; row >= 0; row--) {
                            renderer.drawItem(g2, state, dataArea, this, 
                                    domainAxis, rangeAxis, currentDataset, 
                                    row, column, pass);
                        }                        
                    }
                }
            }
            else {
                for (int column = columnCount - 1; column >= 0; column--) {
                    if (this.rowRenderingOrder == SortOrder.ASCENDING) {
                        for (int row = 0; row < rowCount; row++) {
                            renderer.drawItem(g2, state, dataArea, this, 
                                    domainAxis, rangeAxis, currentDataset, 
                                    row, column, pass);
                        }
                    }
                    else {
                        for (int row = rowCount - 1; row >= 0; row--) {
                            renderer.drawItem(g2, state, dataArea, this, 
                                    domainAxis, rangeAxis, currentDataset, 
                                    row, column, pass);
                        }                        
                    }
                }
            }
        }
    }
    return foundData;
    
}