Example usage for org.jfree.data.statistics StatisticalCategoryDataset getValue

List of usage examples for org.jfree.data.statistics StatisticalCategoryDataset getValue

Introduction

In this page you can find the example usage for org.jfree.data.statistics StatisticalCategoryDataset getValue.

Prototype

public Number getValue(Comparable rowKey, Comparable columnKey);

Source Link

Document

Returns the value associated with the specified keys.

Usage

From source file:nl.strohalm.cyclos.utils.jfreeAsymmetric.AsymmetricStatisticalBarRenderer.java

/**
 * Draws an item for a plot with a vertical orientation.
 * //w ww.j a  v  a 2s .co m
 * @param g2 the graphics device.
 * @param state the renderer state.
 * @param dataArea the data area.
 * @param plot the plot.
 * @param domainAxis the domain axis.
 * @param rangeAxis the range axis.
 * @param dataset the data.
 * @param row the row index (zero-based).
 * @param column the column index (zero-based).
 */
protected void drawVerticalItem(final Graphics2D g2, final CategoryItemRendererState state,
        final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis,
        final ValueAxis rangeAxis, final StatisticalCategoryDataset dataset, final int row, final int column) {
    // nothing is drawn for null... //ADDED THIS BLOCK, RINKE
    final Number v = dataset.getValue(row, column);
    if (v == null) {
        return;
    }

    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();

    // BAR X
    double rectX = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, xAxisLocation);

    final int seriesCount = getRowCount();
    final int categoryCount = getColumnCount();
    if (seriesCount > 1) {
        final double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1));
        rectX = rectX + row * (state.getBarWidth() + seriesGap);
    } else {
        rectX = rectX + row * state.getBarWidth();
    }

    // BAR Y
    final Number meanValue = dataset.getMeanValue(row, column);

    double value = meanValue.doubleValue();
    double base = 0.0;
    final double lclip = getLowerClip();
    final double uclip = getUpperClip();

    if (uclip <= 0.0) { // cases 1, 2, 3 and 4
        if (value >= uclip) {
            return; // bar is not visible
        }
        base = uclip;
        if (value <= lclip) {
            value = lclip;
        }
    } else if (lclip <= 0.0) { // cases 5, 6, 7 and 8
        if (value >= uclip) {
            value = uclip;
        } else {
            if (value <= lclip) {
                value = lclip;
            }
        }
    } else { // cases 9, 10, 11 and 12
        if (value <= lclip) {
            return; // bar is not visible
        }
        base = getLowerClip();
        if (value >= uclip) {
            value = uclip;
        }
    }

    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    final double transY1 = rangeAxis.valueToJava2D(base, dataArea, yAxisLocation);
    final double transY2 = rangeAxis.valueToJava2D(value, dataArea, yAxisLocation);
    final double rectY = Math.min(transY2, transY1);

    final double rectWidth = state.getBarWidth();
    final double rectHeight = Math.abs(transY2 - transY1);

    final Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
    final Paint seriesPaint = getItemPaint(row, column);
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (state.getBarWidth() > 3) {
        g2.setStroke(getItemStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
    }

    // standard deviation lines
    final AsymmetricStatisticalCategoryDataset asymmDataset = (AsymmetricStatisticalCategoryDataset) dataset;
    final Number highValRaw = asymmDataset.getUpperValue(row, column);
    final Number lowValRaw = asymmDataset.getLowerValue(row, column);
    // only draw if both error bars items are not null
    if (highValRaw != null && lowValRaw != null) { // ADDED THIS IF, RINKE
        final double highVal = rangeAxis.valueToJava2D(highValRaw.doubleValue(), dataArea, yAxisLocation);
        final double lowVal = rangeAxis.valueToJava2D(lowValRaw.doubleValue(), dataArea, yAxisLocation);

        if (getErrorIndicatorPaint() != null) {
            g2.setPaint(getErrorIndicatorPaint());
        } else {
            g2.setPaint(getItemOutlinePaint(row, column));
        }
        Line2D line = null;
        line = new Line2D.Double(rectX + rectWidth / 2.0d, lowVal, rectX + rectWidth / 2.0d, highVal);
        g2.draw(line);
        line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, highVal, rectX + rectWidth / 2.0d + 5.0d,
                highVal);
        g2.draw(line);
        line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, lowVal, rectX + rectWidth / 2.0d + 5.0d,
                lowVal);
        g2.draw(line);
    }

    final CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    // add an item entity, if this information is being collected
    final EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, bar);
    }
}

From source file:nl.strohalm.cyclos.utils.jfreeAsymmetric.AsymmetricStatisticalBarRenderer.java

/**
 * Draws an item for a plot with a horizontal orientation.
 * //from  w w  w.ja va  2 s  . co  m
 * @param g2 the graphics device.
 * @param state the renderer state.
 * @param dataArea the data area.
 * @param plot the plot.
 * @param domainAxis the domain axis.
 * @param rangeAxis the range axis.
 * @param dataset the data.
 * @param row the row index (zero-based).
 * @param column the column index (zero-based).
 */
protected void drawHorizontalItem(final Graphics2D g2, final CategoryItemRendererState state,
        final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis,
        final ValueAxis rangeAxis, final StatisticalCategoryDataset dataset, final int row, final int column) {
    // nothing is drawn for null... //added this test block, Rinke
    final Number v = dataset.getValue(row, column);
    if (v == null) {
        return;
    }

    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();

    // BAR Y
    double rectY = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, xAxisLocation);

    final int seriesCount = getRowCount();
    final int categoryCount = getColumnCount();
    if (seriesCount > 1) {
        final double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1));
        rectY = rectY + row * (state.getBarWidth() + seriesGap);
    } else {
        rectY = rectY + row * state.getBarWidth();
    }

    // BAR X
    final Number meanValue = dataset.getMeanValue(row, column);

    double value = meanValue.doubleValue();
    double base = 0.0;
    final double lclip = getLowerClip();
    final double uclip = getUpperClip();

    if (uclip <= 0.0) { // cases 1, 2, 3 and 4
        if (value >= uclip) {
            return; // bar is not visible
        }
        base = uclip;
        if (value <= lclip) {
            value = lclip;
        }
    } else if (lclip <= 0.0) { // cases 5, 6, 7 and 8
        if (value >= uclip) {
            value = uclip;
        } else {
            if (value <= lclip) {
                value = lclip;
            }
        }
    } else { // cases 9, 10, 11 and 12
        if (value <= lclip) {
            return; // bar is not visible
        }
        base = getLowerClip();
        if (value >= uclip) {
            value = uclip;
        }
    }

    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    final double transY1 = rangeAxis.valueToJava2D(base, dataArea, yAxisLocation);
    final double transY2 = rangeAxis.valueToJava2D(value, dataArea, yAxisLocation);
    final double rectX = Math.min(transY2, transY1);

    final double rectHeight = state.getBarWidth();
    final double rectWidth = Math.abs(transY2 - transY1);

    final Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
    final Paint seriesPaint = getItemPaint(row, column);
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (state.getBarWidth() > 3) {
        g2.setStroke(getItemStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
    }
    // ********** BLOCK WITH CHANGES RELATIVE TO StatisticalBarRenderere *********************
    // standard deviation lines
    final AsymmetricStatisticalCategoryDataset asymmDataset = (AsymmetricStatisticalCategoryDataset) dataset;
    final Number highValRaw = asymmDataset.getUpperValue(row, column);
    final Number lowValRaw = asymmDataset.getLowerValue(row, column);
    if (highValRaw != null && lowValRaw != null) { // ADDED THIS IF, RINKE
        final double highVal = rangeAxis.valueToJava2D(highValRaw.doubleValue(), dataArea, yAxisLocation);
        final double lowVal = rangeAxis.valueToJava2D(lowValRaw.doubleValue(), dataArea, yAxisLocation);
        // *************************** end of block with changes ******************************

        if (getErrorIndicatorPaint() != null) {
            g2.setPaint(getErrorIndicatorPaint());
        } else {
            g2.setPaint(getItemOutlinePaint(row, column));
        }
        Line2D line = null;
        line = new Line2D.Double(lowVal, rectY + rectHeight / 2.0d, highVal, rectY + rectHeight / 2.0d);
        g2.draw(line);
        line = new Line2D.Double(highVal, rectY + rectHeight * 0.25, highVal, rectY + rectHeight * 0.75);
        g2.draw(line);
        line = new Line2D.Double(lowVal, rectY + rectHeight * 0.25, lowVal, rectY + rectHeight * 0.75);
        g2.draw(line);
    }

    final CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    // add an item entity, if this information is being collected
    final EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, bar);
    }

}