Example usage for org.jfree.chart.axis CategoryAxis getCategoryStart

List of usage examples for org.jfree.chart.axis CategoryAxis getCategoryStart

Introduction

In this page you can find the example usage for org.jfree.chart.axis CategoryAxis getCategoryStart.

Prototype

public double getCategoryStart(int category, int categoryCount, Rectangle2D area, RectangleEdge edge) 

Source Link

Document

Returns the starting coordinate for the specified category.

Usage

From source file:com.choicemaker.cm.modelmaker.gui.utils.HistoChartPanel.java

protected void setContextMenu() {
    CategoryPlot categoryPlot = (CategoryPlot) getChart().getPlot();
    HistoCategoryDataset data = (HistoCategoryDataset) categoryPlot.getDataset();
    if (data.hasData()) {
        CategoryAxis axis = categoryPlot.getDomainAxis();

        //axis.set
        Rectangle2D plotArea = getScreenDataArea();
        final RectangleEdge edge = null;
        int cat = 0;
        int len = data.getColumnCount();
        for (int i = 0; i < len; ++i) {
            if (popupX >= axis.getCategoryStart(i, len, plotArea, edge)
                    && popupX <= axis.getCategoryEnd(i, len, plotArea, edge)) {
                cat = i;/*  w w w.j  av  a2  s .  c om*/
                break;
            }
        }
        float step = 1f / len;
        rangeFrom = cat * step;
        rangeTo = rangeFrom + step;
        select.setText("Select range " + data.getColumnKey(cat));
    }
    select.setEnabled(data.hasData());
}

From source file:org.jfree.chart.demo.GanttRenderer2.java

protected double calculateBarW0(CategoryPlot categoryplot, PlotOrientation plotorientation,
        Rectangle2D rectangle2d, CategoryAxis categoryaxis, CategoryItemRendererState categoryitemrendererstate,
        int i, int j) {
    double d = 0.0D;
    if (plotorientation == PlotOrientation.HORIZONTAL)
        d = rectangle2d.getHeight();/*from  w w  w.ja v  a 2  s  .c  om*/
    else
        d = rectangle2d.getWidth();
    double d1 = categoryaxis.getCategoryStart(j, getColumnCount(), rectangle2d,
            categoryplot.getDomainAxisEdge());
    int k = getRowCount();
    int l = getColumnCount();
    if (k > 1) {
        double d2 = (d * getItemMargin()) / (double) (l * (k - 1));
        double d3 = calculateSeriesWidth(d, categoryaxis, l, k);
        d1 = (d1 + (double) i * (d3 + d2) + d3 / 2D) - categoryitemrendererstate.getBarWidth() / 2D;
    } else {
        d1 = categoryaxis.getCategoryMiddle(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge())
                - categoryitemrendererstate.getBarWidth() / 2D;
    }
    return d1;
}

From source file:soap.ui.stats.LineAndShapeRendererMapToBar.java

public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) {

    // nothing is drawn for null...
    Number v = dataset.getValue(row, column);
    if (v == null)
        return;/*from   w w  w  . j  a  va2  s  .  co m*/

    PlotOrientation orientation = plot.getOrientation();

    // current data point which is associated to a serie...
    double x1 = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    int seriesCount = mBarRenderer.getPlot().getDataset().getRowCount();
    int categoryCount = mBarRenderer.getPlot().getDataset().getColumnCount();
    if (seriesCount > 1 && mNumSerie < seriesCount) {
        double seriesGap = dataArea.getWidth() * 0.2 / (categoryCount * (seriesCount - 1));
        double seriesW = calculateSeriesWidth(dataArea.getWidth(), domainAxis, categoryCount, seriesCount);
        x1 = x1 + mNumSerie * (seriesW + seriesGap) + (seriesW / 2.0) - (state.getBarWidth() / 2.0);

    } else {
        x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    }

    double value = v.doubleValue();
    double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());

    Shape shape = getItemShape(row, column);
    if (orientation == PlotOrientation.HORIZONTAL) {
        shape = createTransformedShape(shape, y1, x1);
    } else if (orientation == PlotOrientation.VERTICAL) {
        shape = createTransformedShape(shape, x1, y1);
    }
    if (isDrawShapes()) {
        if (getItemShapeFilled(row, column)) {
            g2.setPaint(getItemPaint(row, column));
            g2.fill(shape);
        } else {
            g2.setPaint(getItemOutlinePaint(row, column));
            g2.setStroke(getItemOutlineStroke(row, column));
            g2.draw(shape);
        }
    }

    if (isDrawLines()) {
        if (column != 0) {
            Number previousValue = dataset.getValue(row, column - 1);
            if (previousValue != null) {
                // previous data point...
                double previous = previousValue.doubleValue();
                double x0 = domainAxis.getCategoryStart(column - 1, getColumnCount(), dataArea,
                        plot.getDomainAxisEdge());
                //  seriesCount = getRowCount();
                //  categoryCount = getColumnCount();
                if (seriesCount > 1 && mNumSerie < seriesCount) {
                    double seriesGap = dataArea.getWidth() * 0.2 / (categoryCount * (seriesCount - 1));
                    double seriesW = calculateSeriesWidth(dataArea.getWidth(), domainAxis, categoryCount,
                            seriesCount);
                    x0 = x0 + mNumSerie * (seriesW + seriesGap) + (seriesW / 2.0) - (state.getBarWidth() / 2.0);
                } else {
                    x0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea,
                            plot.getDomainAxisEdge());
                }

                double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge());

                Line2D line = null;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    line = new Line2D.Double(y0, x0, y1, x1);
                } else if (orientation == PlotOrientation.VERTICAL) {
                    line = new Line2D.Double(x0, y0, x1, y1);
                }
                g2.setPaint(getItemPaint(row, column));
                g2.setStroke(getItemStroke(row, column));
                g2.draw(line);
            }
        }
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(row, column)) {
        if (orientation == PlotOrientation.HORIZONTAL) {
            drawItemLabel(g2, orientation, dataset, row, column, y1, x1, (value < 0.0));
        } else if (orientation == PlotOrientation.VERTICAL) {
            drawItemLabel(g2, orientation, dataset, row, column, x1, y1, (value < 0.0));
        }
    }

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getInfo().getOwner().getEntityCollection();
        if (entities != null && shape != null) {
            String tip = null;
            CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
            if (tipster != null) {
                tip = tipster.generateToolTip(dataset, row, column);
            }
            String url = null;
            if (getItemURLGenerator(row, column) != null) {
                url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
            }
            CategoryItemEntity entity = new CategoryItemEntity(shape, tip, url, dataset, row,
                    dataset.getColumnKey(column), column);
            entities.addEntity(entity);
        }
    }
}

From source file:gov.nih.nci.caintegrator.application.geneexpression.BoxAndWhiskerCoinPlotRenderer.java

/**
 * {@inheritDoc}//from  w w  w.j a  v  a2 s  .com
 */
@Override
public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea,
        CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row,
        int column) {
    BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset;
    double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea,
            plot.getDomainAxisEdge());
    double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea,
            plot.getDomainAxisEdge());
    double categoryWidth = categoryEnd - categoryStart;
    double xx = categoryStart;
    int seriesCount = getRowCount();
    int categoryCount = getColumnCount();
    xx = retrieveXx(state, dataArea, row, categoryWidth, xx, seriesCount, categoryCount);
    Paint p = null;
    if (this.getPlotColor() != null) {
        p = PaintUtilities.stringToColor(getPlotColor()); // coin plot should all be one color
    } else {
        p = getItemPaint(row, column);
    }
    if (p != null) {
        g2.setPaint(p);
    }
    Stroke s = getItemStroke(row, column);
    g2.setStroke(s);
    double aRadius = 0; // average radius
    RectangleEdge location = drawRectangles(g2, state, dataArea, plot, rangeAxis, row, column, bawDataset, xx);
    g2.setPaint(getArtifactPaint());
    if (this.isDisplayMean()) {
        aRadius = drawMean(g2, state, dataArea, rangeAxis, row, column, bawDataset, xx, aRadius, location);
    }
    if (this.isDisplayMedian()) {
        // draw median...
        Number yMedian = bawDataset.getMedianValue(row, column);
        if (yMedian != null) {
            double yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location);
            g2.draw(new Line2D.Double(xx, yyMedian, xx + state.getBarWidth(), yyMedian));
        }
    }
    double maxAxisValue = rangeAxis.valueToJava2D(rangeAxis.getUpperBound(), dataArea, location) + aRadius;
    double minAxisValue = rangeAxis.valueToJava2D(rangeAxis.getLowerBound(), dataArea, location) - aRadius;
    g2.setPaint(p);
    drawOutliers(g2, state, dataArea, rangeAxis, row, column, bawDataset, xx, aRadius, location, maxAxisValue,
            minAxisValue);
}

From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraphAction.java

/**
 * Add the action listener to the graph.
 *///from www.  j a  v a2s . c o m
private void setAction() {
    gui.pnlGraph.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(final ChartMouseEvent e) {
            if (e.getEntity() instanceof PlotEntity) {
                Point2D p = gui.pnlGraph.translateScreenToJava2D(e.getTrigger().getPoint());
                CategoryPlot plot = (CategoryPlot) gui.pnlGraph.getChart().getPlot();
                Rectangle2D plotArea = gui.pnlGraph.getScreenDataArea();

                DateAxis rangeAxis = (DateAxis) plot.getRangeAxis();
                RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();

                CategoryAxis catAxis = plot.getDomainAxis();
                RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();

                double chartY = rangeAxis.java2DToValue(p.getX(), plotArea, rangeAxisEdge);

                CategoryDataset categories = (CategoryDataset) plot.getDataset(0);

                int categoryCount = categories.getColumnCount();

                for (int i = 0; i < categoryCount; i++) {
                    double catStart = catAxis.getCategoryStart(i, categoryCount, plotArea, domainAxisEdge);
                    double catEnd = catAxis.getCategoryEnd(i, categoryCount, plotArea, domainAxisEdge);

                    if (e.getTrigger().getY() >= catStart && e.getTrigger().getY() < catEnd) {
                        new EditAvailabilityController(gui.function, gui.function.getWorkers().get(i),
                                new Day(new Date((long) chartY)), parent);
                    }

                }
            } else {

                CategoryItemEntity item = (CategoryItemEntity) e.getEntity();
                CategoryPlot plot = (CategoryPlot) gui.pnlGraph.getChart().getPlot();
                Rectangle2D plotArea = gui.pnlGraph.getScreenDataArea();
                RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();

                DateAxis dateAxis = (DateAxis) plot.getRangeAxis();

                double d = dateAxis.java2DToValue(e.getEntity().getArea().getBounds2D().getX(), plotArea,
                        rangeAxisEdge);
                double d2 = dateAxis.java2DToValue(e.getEntity().getArea().getBounds2D().getX()
                        + e.getEntity().getArea().getBounds2D().getWidth(), plotArea, rangeAxisEdge);

                Date startDate = new Date((long) d);
                Date endDate = new Date((long) d2);

                CategoryDataset categories = (CategoryDataset) plot.getDataset(0);
                int workerIndex = categories.getColumnIndex(item.getColumnKey());
                Worker worker = gui.function.getWorkers().get(workerIndex);

                Set<Availability> found = CalendarService.getAllWorkerAvailability(worker.getId(), startDate,
                        endDate);
                Availability foundAv = found.toArray(new Availability[1])[0];

                if (foundAv != null) {
                    new EditAvailabilityController(gui.function, foundAv, parent);
                } else {
                    found = CalendarService.getProjectAvailability(startDate, endDate);
                    foundAv = found.toArray(new Availability[1])[0];
                    if (foundAv != null) {
                        new EditAvailabilityController(gui.function, foundAv, parent);
                    } else {
                        JOptionPane.showMessageDialog(
                                new JFrame(LocalizedStrings.getGeneralStrings().warning()),
                                LocalizedStrings.getErrorMessages().availabilityCanNotBeChanged());
                    }
                }
            }

        }

        @Override
        public void chartMouseMoved(final ChartMouseEvent arg0) {

        }

    });
    /**
     * ActionListener
     */
    gui.btnNext.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            gui.function.increment();
        }

    });
    /**
     * ActionListener
     */
    gui.btnPrev.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            gui.function.decrement();
        }

    });

    for (int i = 0; i < gui.buttons.length; i++) {
        addButtonListener(i);
    }
    /**
     * ActionListener
     */
    gui.btnManualAv.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                gui.function.setManualAv(true);
            } else {
                gui.function.setManualAv(false);
            }
        }

    });

}

From source file:org.talend.dataprofiler.chart.preview.HideSeriesGanttRenderer.java

/**
 * Calculates the coordinate of the first "side" of a bar. This will be the minimum x-coordinate for a vertical bar,
 * and the minimum y-coordinate for a horizontal bar.
 * /*ww  w.  jav a  2 s .co  m*/
 * @param plot the plot.
 * @param orientation the plot orientation.
 * @param dataArea the data area.
 * @param domainAxis the domain axis.
 * @param state the renderer state (has the bar width precalculated).
 * @param row the row index.
 * @param column the column index.
 * 
 * @return The coordinate.
 */
@Override
protected double calculateBarW0(CategoryPlot plot, PlotOrientation orientation, Rectangle2D dataArea,
        CategoryAxis domainAxis, CategoryItemRendererState state, int row, int column) {
    // calculate bar width...
    double space = 0.0;
    if (orientation == PlotOrientation.HORIZONTAL) {
        space = dataArea.getHeight();
    } else {
        space = dataArea.getWidth();
    }
    double barW0 = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    int seriesCount = getRowCount();
    int categoryCount = getColumnCount();
    if (seriesCount > 1) {
        double seriesGap = space * getItemMargin() / (categoryCount * (seriesCount - 1));
        double seriesW = calculateSeriesWidth(space, domainAxis, categoryCount, seriesCount);
        barW0 = barW0 + row * (seriesW + seriesGap) + (seriesW / 2.0) - (state.getBarWidth() / 2.0);
    } else {
        barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge())
                - state.getBarWidth() / 2.0;
    }
    return barW0;
}

From source file:extern.AsymmetricStatisticalBarRenderer.java

/**
 * Draws an item for a plot with a horizontal orientation.
 *
 * @param g2  the graphics device.//from   w  w w .j  a  va  2s .co m
 * @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 visibleRow  the visible row index.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 */
protected void drawHorizontalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea,
        CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis,
        AsymmetricStatisticalCategoryDataset dataset, int visibleRow, int row, int column) {

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();

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

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

    // BAR X
    Number meanValue = dataset.getMeanValue(row, column);
    if (meanValue == null) {
        return;
    }
    double value = meanValue.doubleValue();
    double base = 0.0;
    double lclip = getLowerClip();
    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;
        }
    }

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

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

    Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
    Paint itemPaint = getItemPaint(row, column);
    GradientPaintTransformer t = getGradientPaintTransformer();
    if (t != null && itemPaint instanceof GradientPaint) {
        itemPaint = t.transform((GradientPaint) itemPaint, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    // draw the outline...
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        Stroke stroke = getItemOutlineStroke(row, column);
        Paint paint = getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }

    // CI lines
    Number n = dataset.getUpperValue(row, column);
    Number m = dataset.getLowerValue(row, column);

    if (n != null && m != null) {
        double valueUpperDelta = n.doubleValue();
        double valueLowerDelta = m.doubleValue();

        double highVal = rangeAxis.valueToJava2D(valueUpperDelta, dataArea, yAxisLocation);
        double lowVal = rangeAxis.valueToJava2D(valueLowerDelta, dataArea, yAxisLocation);

        if (this.errorIndicatorPaint != null) {
            g2.setPaint(this.errorIndicatorPaint);
        } else {
            g2.setPaint(getItemOutlinePaint(row, column));
        }
        if (this.errorIndicatorStroke != null) {
            g2.setStroke(this.errorIndicatorStroke);
        } else {
            g2.setStroke(getItemOutlineStroke(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);
    }

    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
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, bar);
    }

}

From source file:extern.AsymmetricStatisticalBarRenderer.java

/**
 * Draws an item for a plot with a vertical orientation.
 *
 * @param g2  the graphics device./*  www .ja  va  2 s.c  o  m*/
 * @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 visibleRow  the visible row index.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 */
protected void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea,
        CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis,
        AsymmetricStatisticalCategoryDataset dataset, int visibleRow, int row, int column) {

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();

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

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

    // BAR Y
    Number meanValue = dataset.getMeanValue(row, column);
    if (meanValue == null) {
        return;
    }

    double value = meanValue.doubleValue();
    double base = 0.0;
    double lclip = getLowerClip();
    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;
        }
    }

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

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

    Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
    Paint itemPaint = getItemPaint(row, column);
    GradientPaintTransformer t = getGradientPaintTransformer();
    if (t != null && itemPaint instanceof GradientPaint) {
        itemPaint = t.transform((GradientPaint) itemPaint, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);
    // draw the outline...
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        Stroke stroke = getItemOutlineStroke(row, column);
        Paint paint = getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }

    // CI lines      
    Number n = dataset.getUpperValue(row, column);
    Number m = dataset.getLowerValue(row, column);

    if (n != null && m != null) {
        double valueUpperDelta = n.doubleValue();
        double valueLowerDelta = m.doubleValue();

        if (valueLowerDelta > meanValue.doubleValue()) {
            double temp = valueLowerDelta - meanValue.doubleValue();
            valueLowerDelta = meanValue.doubleValue() - temp;
        }

        if (valueUpperDelta < meanValue.doubleValue()) {
            double temp = meanValue.doubleValue() - valueUpperDelta;
            valueUpperDelta = temp;
        }

        double highVal = rangeAxis.valueToJava2D(valueUpperDelta, dataArea, yAxisLocation);
        double lowVal = rangeAxis.valueToJava2D(valueLowerDelta, dataArea, yAxisLocation);

        if (this.errorIndicatorPaint != null) {
            g2.setPaint(this.errorIndicatorPaint);
        } else {
            g2.setPaint(getItemOutlinePaint(row, column));
        }
        if (this.errorIndicatorStroke != null) {
            g2.setStroke(this.errorIndicatorStroke);
        } else {
            g2.setStroke(getItemOutlineStroke(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);
    }

    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
    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 vertical orientation.
 * /*from   ww w.  j  av  a2 s.c o 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 ww  w .j av  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 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);
    }

}