Example usage for java.awt Graphics2D setPaint

List of usage examples for java.awt Graphics2D setPaint

Introduction

In this page you can find the example usage for java.awt Graphics2D setPaint.

Prototype

public abstract void setPaint(Paint paint);

Source Link

Document

Sets the Paint attribute for the Graphics2D context.

Usage

From source file:edu.dlnu.liuwenpeng.render.CandlestickRenderer.java

/**    
* Draws the visual representation of a single data item.    
*    //from   w  ww .j a v  a  2 s. com
* @param g2  the graphics device.    
* @param state  the renderer state.    
* @param dataArea  the area within which the plot is being drawn.    
* @param info  collects info about the drawing.    
* @param plot  the plot (can be used to obtain standard color    
*              information etc).    
* @param domainAxis  the domain axis.    
* @param rangeAxis  the range axis.    
* @param dataset  the dataset.    
* @param series  the series index (zero-based).    
* @param item  the item index (zero-based).    
* @param crosshairState  crosshair information for the plot    
*                        (<code>null</code> permitted).    
* @param pass  the pass index.    
*/
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    boolean horiz;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        horiz = true;
    } else if (orientation == PlotOrientation.VERTICAL) {
        horiz = false;
    } else {
        return;
    }

    // setup for collecting optional entity info...    
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    OHLCDataset highLowData = (OHLCDataset) dataset;

    double x = highLowData.getXValue(series, item);
    double yHigh = highLowData.getHighValue(series, item);
    double yLow = highLowData.getLowValue(series, item);
    double yOpen = highLowData.getOpenValue(series, item);
    double yClose = highLowData.getCloseValue(series, item);

    RectangleEdge domainEdge = plot.getDomainAxisEdge();
    double xx = domainAxis.valueToJava2D(x, dataArea, domainEdge);

    RectangleEdge edge = plot.getRangeAxisEdge();
    double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, edge);
    double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, edge);
    double yyOpen = rangeAxis.valueToJava2D(yOpen, dataArea, edge);
    double yyClose = rangeAxis.valueToJava2D(yClose, dataArea, edge);

    double volumeWidth;
    double stickWidth;
    if (this.candleWidth > 0) {
        // These are deliberately not bounded to minimums/maxCandleWidth to    
        //  retain old behaviour.    
        volumeWidth = this.candleWidth;
        stickWidth = this.candleWidth;
    } else {
        double xxWidth = 0;
        int itemCount;
        switch (this.autoWidthMethod) {

        case WIDTHMETHOD_AVERAGE:
            itemCount = highLowData.getItemCount(series);
            if (horiz) {
                xxWidth = dataArea.getHeight() / itemCount;
            } else {
                xxWidth = dataArea.getWidth() / itemCount;
            }
            break;

        case WIDTHMETHOD_SMALLEST:
            // Note: It would be nice to pre-calculate this per series    
            itemCount = highLowData.getItemCount(series);
            double lastPos = -1;
            xxWidth = dataArea.getWidth();
            for (int i = 0; i < itemCount; i++) {
                double pos = domainAxis.valueToJava2D(highLowData.getXValue(series, i), dataArea, domainEdge);
                if (lastPos != -1) {
                    xxWidth = Math.min(xxWidth, Math.abs(pos - lastPos));
                }
                lastPos = pos;
            }
            break;

        case WIDTHMETHOD_INTERVALDATA:
            IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset;
            double startPos = domainAxis.valueToJava2D(intervalXYData.getStartXValue(series, item), dataArea,
                    plot.getDomainAxisEdge());
            double endPos = domainAxis.valueToJava2D(intervalXYData.getEndXValue(series, item), dataArea,
                    plot.getDomainAxisEdge());
            xxWidth = Math.abs(endPos - startPos);
            break;

        }
        xxWidth -= 2 * this.autoWidthGap;
        xxWidth *= this.autoWidthFactor;
        xxWidth = Math.min(xxWidth, this.maxCandleWidth);
        volumeWidth = Math.max(Math.min(1, this.maxCandleWidth), xxWidth);
        stickWidth = Math.max(Math.min(3, this.maxCandleWidth), xxWidth);
    }

    Paint p = getItemPaint(series, item);
    Paint outlinePaint = null;
    if (this.useOutlinePaint) {
        outlinePaint = getItemOutlinePaint(series, item);
    }
    Stroke s = getItemStroke(series, item);

    g2.setStroke(s);

    if (this.drawVolume) {
        int volume = (int) highLowData.getVolumeValue(series, item);
        double volumeHeight = volume / this.maxVolume;

        double min, max;
        if (horiz) {
            min = dataArea.getMinX();
            max = dataArea.getMaxX();
        } else {
            min = dataArea.getMinY();
            max = dataArea.getMaxY();
        }

        double zzVolume = volumeHeight * (max - min);

        g2.setPaint(getVolumePaint());
        Composite originalComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f));

        if (horiz) {
            g2.fill(new Rectangle2D.Double(min, xx - volumeWidth / 2, zzVolume, volumeWidth));
        } else {
            g2.fill(new Rectangle2D.Double(xx - volumeWidth / 2, max - zzVolume, volumeWidth, zzVolume));
        }

        g2.setComposite(originalComposite);
    }

    if (this.useOutlinePaint) {
        g2.setPaint(outlinePaint);
    } else {
        g2.setPaint(p);
    }

    double yyMaxOpenClose = Math.max(yyOpen, yyClose);
    double yyMinOpenClose = Math.min(yyOpen, yyClose);
    double maxOpenClose = Math.max(yOpen, yClose);
    double minOpenClose = Math.min(yOpen, yClose);

    // draw the upper shadow    
    if (yHigh > maxOpenClose) {
        if (yClose > yOpen) {
            g2.setPaint(Color.green);
        } else {
            g2.setPaint(Color.red);

        }
        if (horiz) {
            g2.draw(new Line2D.Double(yyHigh, xx, yyMaxOpenClose, xx));
        } else {
            g2.draw(new Line2D.Double(xx, yyHigh, xx, yyMaxOpenClose));
        }
    }

    // draw the lower shadow    
    if (yLow < minOpenClose) {
        if (yClose > yOpen) {
            g2.setPaint(Color.green);
        } else {
            g2.setPaint(Color.red);

        }
        if (horiz) {
            g2.draw(new Line2D.Double(yyLow, xx, yyMinOpenClose, xx));
        } else {
            g2.draw(new Line2D.Double(xx, yyLow, xx, yyMinOpenClose));
        }
    }

    // draw the body    
    Rectangle2D body = null;
    Rectangle2D hotspot = null;
    double length = Math.abs(yyHigh - yyLow);
    double base = Math.min(yyHigh, yyLow);
    if (horiz) {
        body = new Rectangle2D.Double(yyMinOpenClose, xx - stickWidth / 2, yyMaxOpenClose - yyMinOpenClose,
                stickWidth);

        hotspot = new Rectangle2D.Double(base, xx - stickWidth / 2, length, stickWidth);
    } else {
        body = new Rectangle2D.Double(xx - stickWidth / 2, yyMinOpenClose, stickWidth,
                yyMaxOpenClose - yyMinOpenClose);
        hotspot = new Rectangle2D.Double(xx - stickWidth / 2, base, stickWidth, length);

    }
    if (yClose > yOpen) {
        if (this.upPaint != null) {
            g2.setPaint(this.upPaint);
        } else {
            g2.setPaint(p);
        }
        g2.fill(body);
    } else {
        if (this.downPaint != null) {
            g2.setPaint(this.downPaint);
        } else {
            g2.setPaint(p);
        }
        g2.fill(body);
    }
    if (this.useOutlinePaint) {
        g2.setPaint(outlinePaint);

    } else {
        if (yClose > yOpen) {
            g2.setPaint(Color.green);

        } else {
            g2.setPaint(p);
        }
    }
    g2.draw(body);

    // add an entity for the item...    
    if (entities != null) {
        addEntity(entities, hotspot, dataset, series, item, 0.0, 0.0);
    }

}

From source file:org.forester.archaeopteryx.TreePanel.java

final void paintPhylogeny(final Graphics2D g, final boolean to_pdf, final boolean to_graphics_file,
        final int graphics_file_width, final int graphics_file_height, final int graphics_file_x,
        final int graphics_file_y) {
    /* GUILHEM_BEG */
    _query_sequence = _control_panel.getSelectedQuerySequence();
    /* GUILHEM_END */
    // Color the background
    if (!to_pdf) {
        final Rectangle r = getVisibleRect();
        if (!getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite()) {
            g.setColor(getTreeColorSet().getBackgroundColor());
            if (!to_graphics_file) {
                g.fill(r);/*from   w w  w  .j av  a  2 s.c o m*/
            } else {
                if (getOptions().isPrintBlackAndWhite()) {
                    g.setColor(Color.WHITE);
                }
                g.fillRect(graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height);
            }
        } else {
            if (!to_graphics_file) {
                g.setPaint(new GradientPaint(r.x, r.y, getTreeColorSet().getBackgroundColor(), r.x,
                        r.y + r.height, getTreeColorSet().getBackgroundColorGradientBottom()));
                g.fill(r);
            } else {
                g.setPaint(new GradientPaint(graphics_file_x, graphics_file_y,
                        getTreeColorSet().getBackgroundColor(), graphics_file_x,
                        graphics_file_y + graphics_file_height,
                        getTreeColorSet().getBackgroundColorGradientBottom()));
                g.fillRect(graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height);
            }
        }
        g.setStroke(new BasicStroke(1));
    } else {
        g.setStroke(new BasicStroke(getOptions().getPrintLineWidth()));
    }
    if ((getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED)
            && (getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR)) {
        _external_node_index = 0;
        // Position starting X of tree
        if (!_phylogeny.isRooted()) {
            _phylogeny.getRoot().setXcoord(TreePanel.MOVE);
        } else if ((_phylogeny.getRoot().getDistanceToParent() > 0.0) && getControlPanel().isDrawPhylogram()) {
            _phylogeny.getRoot().setXcoord((float) (TreePanel.MOVE
                    + (_phylogeny.getRoot().getDistanceToParent() * getXcorrectionFactor())));
        } else {
            _phylogeny.getRoot().setXcoord(TreePanel.MOVE + getXdistance());
        }
        // Position starting Y of tree
        _phylogeny.getRoot().setYcoord(
                (getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes()) + (TreePanel.MOVE / 2.0f));
        final int dynamic_hiding_factor = (int) (getTreeFontSet()._fm_large.getHeight()
                / (1.5 * getYdistance()));
        if (getControlPanel().isDynamicallyHideData()) {
            if (dynamic_hiding_factor > 1) {
                getControlPanel().setDynamicHidingIsOn(true);
            } else {
                getControlPanel().setDynamicHidingIsOn(false);
            }
        }
        final PhylogenyNodeIterator it;
        for (it = _phylogeny.iteratorPreorder(); it.hasNext();) {
            paintNodeRectangular(g, it.next(), to_pdf,
                    getControlPanel().isDynamicallyHideData() && (dynamic_hiding_factor > 1),
                    dynamic_hiding_factor, to_graphics_file);
        }
        if (getOptions().isShowScale()) {
            if (!(to_graphics_file || to_pdf)) {
                paintScale(g, getVisibleRect().x, getVisibleRect().y + getVisibleRect().height, to_pdf,
                        to_graphics_file);
            } else {
                paintScale(g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf,
                        to_graphics_file);
            }
        }
        if (getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf) {
            paintPhylogenyLite(g);
        }
    } else if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED) {
        if (getControlPanel().getDynamicallyHideData() != null) {
            getControlPanel().setDynamicHidingIsOn(false);
        }
        final double angle = getStartingAngle();
        final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
        _dynamic_hiding_factor = 0;
        if (getControlPanel().isDynamicallyHideData()) {
            _dynamic_hiding_factor = (int) ((getTreeFontSet()._fm_large.getHeight() * 1.5
                    * getPhylogeny().getNumberOfExternalNodes()) / (TWO_PI * 10));
        }
        if (getControlPanel().getDynamicallyHideData() != null) {
            if (_dynamic_hiding_factor > 1) {
                getControlPanel().setDynamicHidingIsOn(true);
            } else {
                getControlPanel().setDynamicHidingIsOn(false);
            }
        }
        paintUnrooted(_phylogeny.getRoot(), angle, (float) (angle + 2 * Math.PI), radial_labels, g, to_pdf,
                to_graphics_file);
        if (getOptions().isShowScale()) {
            if (!(to_graphics_file || to_pdf)) {
                paintScale(g, getVisibleRect().x, getVisibleRect().y + getVisibleRect().height, to_pdf,
                        to_graphics_file);
            } else {
                paintScale(g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf,
                        to_graphics_file);
            }
        }
        if (getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf) {
            g.setColor(getTreeColorSet().getOvColor());
            paintUnrootedLite(_phylogeny.getRoot(), angle, angle + 2 * Math.PI, g,
                    (getUrtFactorOv() / (getVisibleRect().width / getOvMaxWidth())));
            paintOvRectangle(g);
        }
    } else if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR) {
        final int radius = (int) ((Math.min(getPreferredSize().getWidth(), getPreferredSize().getHeight()) / 2)
                - (MOVE + getLongestExtNodeInfo()));
        final int d = radius + MOVE + getLongestExtNodeInfo();
        _dynamic_hiding_factor = 0;
        if (getControlPanel().isDynamicallyHideData() && (radius > 0)) {
            _dynamic_hiding_factor = (int) ((getTreeFontSet()._fm_large.getHeight() * 1.5
                    * getPhylogeny().getNumberOfExternalNodes()) / (TWO_PI * radius));
        }
        if (getControlPanel().getDynamicallyHideData() != null) {
            if (_dynamic_hiding_factor > 1) {
                getControlPanel().setDynamicHidingIsOn(true);
            } else {
                getControlPanel().setDynamicHidingIsOn(false);
            }
        }
        paintCircular(_phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf,
                to_graphics_file);
        if (getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf) {
            final int radius_ov = (int) (getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2
                    : getOvMaxWidth() / 2);
            double x_scale = 1.0;
            double y_scale = 1.0;
            int x_pos = getVisibleRect().x + getOvXPosition();
            int y_pos = getVisibleRect().y + getOvYPosition();
            if (getWidth() > getHeight()) {
                x_scale = (double) getHeight() / getWidth();
                x_pos = ForesterUtil.roundToInt(x_pos / x_scale);
            } else {
                y_scale = (double) getWidth() / getHeight();
                y_pos = ForesterUtil.roundToInt(y_pos / y_scale);
            }
            _at = g.getTransform();
            g.scale(x_scale, y_scale);
            paintCircularLite(_phylogeny, getStartingAngle(), x_pos + radius_ov, y_pos + radius_ov,
                    (int) (radius_ov - (getLongestExtNodeInfo()
                            / (getVisibleRect().width / getOvRectangle().getWidth()))),
                    g);
            g.setTransform(_at);
            paintOvRectangle(g);
        }
    }
}

From source file:de.saring.util.gui.jfreechart.StackedRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2 the graphics device./*from w  w  w  .  ja  v  a2  s.  c  o m*/
 * @param state the renderer state.
 * @param dataArea the area within which the data is being drawn.
 * @param info collects information about the drawing.
 * @param plot the plot (can be used to obtain standard color information
 * etc).
 * @param domainAxis the domain axis.
 * @param rangeAxis the range axis.
 * @param dataset the dataset.
 * @param series the series index (zero-based).
 * @param item the item index (zero-based).
 * @param crosshairState information about crosshairs on a plot.
 * @param pass the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    // setup for collecting optional entity info...
    Shape entityArea = null;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    TableXYDataset tdataset = (TableXYDataset) dataset;

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1)) {
        y1 = 0.0;
    }
    double[] stack1 = getStackValues(tdataset, series, item);

    // get the previous point and the next point so we can calculate a 
    // "hot spot" for the area (used by the chart entity)...
    double x0 = dataset.getXValue(series, Math.max(item - 1, 0));
    double y0 = dataset.getYValue(series, Math.max(item - 1, 0));
    if (Double.isNaN(y0)) {
        y0 = 0.0;
    }
    double[] stack0 = getStackValues(tdataset, series, Math.max(item - 1, 0));

    int itemCount = dataset.getItemCount(series);
    double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1));
    double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1));
    if (Double.isNaN(y2)) {
        y2 = 0.0;
    }
    double[] stack2 = getStackValues(tdataset, series, Math.min(item + 1, itemCount - 1));

    double xleft = (x0 + x1) / 2.0;
    double xright = (x1 + x2) / 2.0;
    double[] stackLeft = averageStackValues(stack0, stack1);
    double[] stackRight = averageStackValues(stack1, stack2);
    double[] adjStackLeft = adjustedStackValues(stack0, stack1);
    double[] adjStackRight = adjustedStackValues(stack1, stack2);

    RectangleEdge edge0 = plot.getDomainAxisEdge();

    float transX1 = (float) domainAxis.valueToJava2D(x1, dataArea, edge0);
    float transXLeft = (float) domainAxis.valueToJava2D(xleft, dataArea, edge0);
    float transXRight = (float) domainAxis.valueToJava2D(xright, dataArea, edge0);

    if (this.roundXCoordinates) {
        transX1 = Math.round(transX1);
        transXLeft = Math.round(transXLeft);
        transXRight = Math.round(transXRight);
    }
    float transY1;

    RectangleEdge edge1 = plot.getRangeAxisEdge();

    GeneralPath left = new GeneralPath();
    GeneralPath right = new GeneralPath();
    if (y1 >= 0.0) { // handle positive value
        transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[1], dataArea, edge1);
        float transStack1 = (float) rangeAxis.valueToJava2D(stack1[1], dataArea, edge1);
        float transStackLeft = (float) rangeAxis.valueToJava2D(stackLeft[1], dataArea, edge1); // other than StackedXYAreaRenderer2!

        // LEFT POLYGON
        if (y0 >= 0.0) {
            double yleft = (y0 + y1) / 2.0 + stackLeft[1];
            float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1);
            left.moveTo(transX1, transY1);
            left.lineTo(transX1, transStack1);
            left.lineTo(transXLeft, transStackLeft);
            left.lineTo(transXLeft, transYLeft);
            left.closePath();
        } else {
            left.moveTo(transX1, transStack1);
            left.lineTo(transX1, transY1);
            left.lineTo(transXLeft, transStackLeft);
            left.closePath();
        }

        float transStackRight = (float) rangeAxis.valueToJava2D(stackRight[1], dataArea, edge1); // other than StackedXYAreaRenderer2!
        // RIGHT POLYGON
        if (y2 >= 0.0) {
            double yright = (y1 + y2) / 2.0 + stackRight[1];
            float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1);
            right.moveTo(transX1, transStack1);
            right.lineTo(transX1, transY1);
            right.lineTo(transXRight, transYRight);
            right.lineTo(transXRight, transStackRight);
            right.closePath();
        } else {
            right.moveTo(transX1, transStack1);
            right.lineTo(transX1, transY1);
            right.lineTo(transXRight, transStackRight);
            right.closePath();
        }
    } else { // handle negative value
        transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[0], dataArea, edge1);
        float transStack1 = (float) rangeAxis.valueToJava2D(stack1[0], dataArea, edge1);
        float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[0], dataArea, edge1);

        // LEFT POLYGON
        if (y0 >= 0.0) {
            left.moveTo(transX1, transStack1);
            left.lineTo(transX1, transY1);
            left.lineTo(transXLeft, transStackLeft);
            left.clone();
        } else {
            double yleft = (y0 + y1) / 2.0 + stackLeft[0];
            float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1);
            left.moveTo(transX1, transY1);
            left.lineTo(transX1, transStack1);
            left.lineTo(transXLeft, transStackLeft);
            left.lineTo(transXLeft, transYLeft);
            left.closePath();
        }
        float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[0], dataArea, edge1);

        // RIGHT POLYGON
        if (y2 >= 0.0) {
            right.moveTo(transX1, transStack1);
            right.lineTo(transX1, transY1);
            right.lineTo(transXRight, transStackRight);
            right.closePath();
        } else {
            double yright = (y1 + y2) / 2.0 + stackRight[0];
            float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1);
            right.moveTo(transX1, transStack1);
            right.lineTo(transX1, transY1);
            right.lineTo(transXRight, transYRight);
            right.lineTo(transXRight, transStackRight);
            right.closePath();
        }
    }

    //  Get series Paint and Stroke
    Paint itemPaint = getItemPaint(series, item);
    if (pass == 0) {
        g2.setPaint(itemPaint);
        g2.fill(left);
        g2.fill(right);
    } else if (pass == 1) {
        if (item == 0 || (y1 == 0.0 && y0 == 0.0)) {
            return;
        }

        // get the data point...
        if (Double.isNaN(y1) || Double.isNaN(x1)) {
            return;
        }

        if (Double.isNaN(y0) || Double.isNaN(x0)) {
            return;
        }

        RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
        RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

        double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
        double transY0 = rangeAxis.valueToJava2D(y0 + stack0[1], dataArea, yAxisLocation);

        // only draw if we have good values
        if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) {
            return;
        }

        state.workingLine.setLine(transX0, transY0, transX1, transY1);

        if (state.workingLine.intersects(dataArea)) {
            g2.setStroke(getItemStroke(series, item));
            g2.setPaint(super.lookupSeriesPaint(series));
            g2.draw(state.workingLine);
        }

        return;
    }

    // add an entity for the item...
    if (entities != null) {
        GeneralPath gp = new GeneralPath(left);
        gp.append(right, false);
        entityArea = gp;
        addEntity(entities, entityArea, dataset, series, item, transX1, transY1);
    }

}

From source file:ucar.unidata.idv.control.chart.MyXYPlot.java

/**
 * Draws the quadrants./*  w  w  w  .  j a  va  2  s  .  c  o  m*/
 *
 * @param g2  the graphics device.
 * @param area  the area.
 */
protected void drawQuadrants(Graphics2D g2, Rectangle2D area) {

    //  0 | 1
    //  --+--
    //  2 | 3
    boolean somethingToDraw = false;

    ValueAxis xAxis = getDomainAxis();
    double x = this.quadrantOrigin.getX();
    double xx = xAxis.valueToJava2D(x, area, getDomainAxisEdge());

    ValueAxis yAxis = getRangeAxis();
    double y = this.quadrantOrigin.getY();
    double yy = yAxis.valueToJava2D(y, area, getRangeAxisEdge());

    double xmin = xAxis.getLowerBound();
    double xxmin = xAxis.valueToJava2D(xmin, area, getDomainAxisEdge());

    double xmax = xAxis.getUpperBound();
    double xxmax = xAxis.valueToJava2D(xmax, area, getDomainAxisEdge());

    double ymin = yAxis.getLowerBound();
    double yymin = yAxis.valueToJava2D(ymin, area, getRangeAxisEdge());

    double ymax = yAxis.getUpperBound();
    double yymax = yAxis.valueToJava2D(ymax, area, getRangeAxisEdge());

    Rectangle2D[] r = new Rectangle2D[] { null, null, null, null };
    if (this.quadrantPaint[0] != null) {
        if ((x > xmin) && (y < ymax)) {
            if (this.orientation == PlotOrientation.HORIZONTAL) {
                r[0] = new Rectangle2D.Double(Math.min(yymax, yy), Math.min(xxmin, xx), Math.abs(yy - yymax),
                        Math.abs(xx - xxmin));
            } else { // PlotOrientation.VERTICAL
                r[0] = new Rectangle2D.Double(Math.min(xxmin, xx), Math.min(yymax, yy), Math.abs(xx - xxmin),
                        Math.abs(yy - yymax));
            }
            somethingToDraw = true;
        }
    }
    if (this.quadrantPaint[1] != null) {
        if ((x < xmax) && (y < ymax)) {
            if (this.orientation == PlotOrientation.HORIZONTAL) {
                r[1] = new Rectangle2D.Double(Math.min(yymax, yy), Math.min(xxmax, xx), Math.abs(yy - yymax),
                        Math.abs(xx - xxmax));
            } else { // PlotOrientation.VERTICAL
                r[1] = new Rectangle2D.Double(Math.min(xx, xxmax), Math.min(yymax, yy), Math.abs(xx - xxmax),
                        Math.abs(yy - yymax));
            }
            somethingToDraw = true;
        }
    }
    if (this.quadrantPaint[2] != null) {
        if ((x > xmin) && (y > ymin)) {
            if (this.orientation == PlotOrientation.HORIZONTAL) {
                r[2] = new Rectangle2D.Double(Math.min(yymin, yy), Math.min(xxmin, xx), Math.abs(yy - yymin),
                        Math.abs(xx - xxmin));
            } else { // PlotOrientation.VERTICAL
                r[2] = new Rectangle2D.Double(Math.min(xxmin, xx), Math.min(yymin, yy), Math.abs(xx - xxmin),
                        Math.abs(yy - yymin));
            }
            somethingToDraw = true;
        }
    }
    if (this.quadrantPaint[3] != null) {
        if ((x < xmax) && (y > ymin)) {
            if (this.orientation == PlotOrientation.HORIZONTAL) {
                r[3] = new Rectangle2D.Double(Math.min(yymin, yy), Math.min(xxmax, xx), Math.abs(yy - yymin),
                        Math.abs(xx - xxmax));
            } else { // PlotOrientation.VERTICAL
                r[3] = new Rectangle2D.Double(Math.min(xx, xxmax), Math.min(yymin, yy), Math.abs(xx - xxmax),
                        Math.abs(yy - yymin));
            }
            somethingToDraw = true;
        }
    }
    if (somethingToDraw) {
        Composite originalComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getBackgroundAlpha()));
        for (int i = 0; i < 4; i++) {
            if ((this.quadrantPaint[i] != null) && (r[i] != null)) {
                g2.setPaint(this.quadrantPaint[i]);
                g2.fill(r[i]);
            }
        }
        g2.setComposite(originalComposite);
    }
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.backport.StackedAreaRenderer.java

/**
 * Draw a single data item./*w  w  w.jav a 2s . co m*/
 *
 * @param g2         the graphics device.
 * @param state      the renderer state.
 * @param dataArea   the data plot 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).
 * @param pass       the pass index.
 */
public void drawItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea,
        final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis,
        final CategoryDataset dataset, final int row, final int column, final int pass) {

    if (!isSeriesVisible(row)) {
        return;
    }

    if ((pass == 1) && !isItemLabelVisible(row, column)) {
        return;
    }

    // setup for collecting optional entity info...
    Shape entityArea = null;
    final EntityCollection entities = state.getEntityCollection();

    double y1 = 0.0;
    Number n = dataset.getValue(row, column);
    if (n != null) {
        y1 = n.doubleValue();
        if (this.renderAsPercentages) {
            final double total = DataUtilities.calculateColumnTotal(dataset, column);
            y1 = y1 / total;
        }
    }
    final double[] stack1 = getStackValues(dataset, row, column);

    // leave the y values (y1, y0) untranslated as it is going to be be
    // stacked up later by previous series values, after this it will be
    // translated.
    double xx1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());

    // get the previous point and the next point so we can calculate a
    // "hot spot" for the area (used by the chart entity)...
    double y0 = 0.0;
    n = dataset.getValue(row, Math.max(column - 1, 0));
    if (n != null) {
        y0 = n.doubleValue();
        if (this.renderAsPercentages) {
            final double total = DataUtilities.calculateColumnTotal(dataset, Math.max(column - 1, 0));
            y0 = y0 / total;
        }
    }
    final double[] stack0 = getStackValues(dataset, row, Math.max(column - 1, 0));

    // FIXME: calculate xx0
    double xx0 = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());

    final int itemCount = dataset.getColumnCount();
    double y2 = 0.0;
    n = dataset.getValue(row, Math.min(column + 1, itemCount - 1));
    if (n != null) {
        y2 = n.doubleValue();
        if (this.renderAsPercentages) {
            final double total = DataUtilities.calculateColumnTotal(dataset,
                    Math.min(column + 1, itemCount - 1));
            y2 = y2 / total;
        }
    }
    final double[] stack2 = getStackValues(dataset, row, Math.min(column + 1, itemCount - 1));

    double xx2 = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());

    // This gets rid of the white lines between most category values
    // Doug Moran - Hitachi Vantara
    xx0 = Math.round(xx0);
    xx1 = Math.round(xx1);
    xx2 = Math.round(xx2);

    // FIXME: calculate xxLeft and xxRight
    final double xxLeft = xx0;
    final double xxRight = xx2;

    final double[] stackLeft = averageStackValues(stack0, stack1);
    final double[] stackRight = averageStackValues(stack1, stack2);
    final double[] adjStackLeft = adjustedStackValues(stack0, stack1);
    final double[] adjStackRight = adjustedStackValues(stack1, stack2);

    final float transY1;

    final RectangleEdge edge1 = plot.getRangeAxisEdge();

    final GeneralPath left = new GeneralPath();
    final GeneralPath right = new GeneralPath();
    if (y1 >= 0.0) { // handle positive value
        transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[1], dataArea, edge1);
        final float transStack1 = (float) rangeAxis.valueToJava2D(stack1[1], dataArea, edge1);
        final float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[1], dataArea, edge1);

        // LEFT POLYGON
        if (y0 >= 0.0) {
            final double yleft = (y0 + y1) / 2.0 + stackLeft[1];
            final float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1);
            left.moveTo((float) xx1, transY1);
            left.lineTo((float) xx1, transStack1);
            left.lineTo((float) xxLeft, transStackLeft);
            left.lineTo((float) xxLeft, transYLeft);
            left.closePath();
        } else {
            left.moveTo((float) xx1, transStack1);
            left.lineTo((float) xx1, transY1);
            left.lineTo((float) xxLeft, transStackLeft);
            left.closePath();
        }

        final float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[1], dataArea, edge1);
        // RIGHT POLYGON
        if (y2 >= 0.0) {
            final double yright = (y1 + y2) / 2.0 + stackRight[1];
            final float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1);
            right.moveTo((float) xx1, transStack1);
            right.lineTo((float) xx1, transY1);
            right.lineTo((float) xxRight, transYRight);
            right.lineTo((float) xxRight, transStackRight);
            right.closePath();
        } else {
            right.moveTo((float) xx1, transStack1);
            right.lineTo((float) xx1, transY1);
            right.lineTo((float) xxRight, transStackRight);
            right.closePath();
        }
    } else { // handle negative value
        transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[0], dataArea, edge1);
        final float transStack1 = (float) rangeAxis.valueToJava2D(stack1[0], dataArea, edge1);
        final float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[0], dataArea, edge1);

        // LEFT POLYGON
        if (y0 >= 0.0) {
            left.moveTo((float) xx1, transStack1);
            left.lineTo((float) xx1, transY1);
            left.lineTo((float) xxLeft, transStackLeft);
            left.clone();
        } else {
            final double yleft = (y0 + y1) / 2.0 + stackLeft[0];
            final float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1);
            left.moveTo((float) xx1, transY1);
            left.lineTo((float) xx1, transStack1);
            left.lineTo((float) xxLeft, transStackLeft);
            left.lineTo((float) xxLeft, transYLeft);
            left.closePath();
        }
        final float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[0], dataArea, edge1);

        // RIGHT POLYGON
        if (y2 >= 0.0) {
            right.moveTo((float) xx1, transStack1);
            right.lineTo((float) xx1, transY1);
            right.lineTo((float) xxRight, transStackRight);
            right.closePath();
        } else {
            final double yright = (y1 + y2) / 2.0 + stackRight[0];
            final float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1);
            right.moveTo((float) xx1, transStack1);
            right.lineTo((float) xx1, transY1);
            right.lineTo((float) xxRight, transYRight);
            right.lineTo((float) xxRight, transStackRight);
            right.closePath();
        }
    }

    if (pass == 0) {
        final Paint itemPaint = getItemPaint(row, column);
        g2.setPaint(itemPaint);
        g2.fill(left);
        g2.fill(right);

        // add an entity for the item...
        if (entities != null) {
            final GeneralPath gp = new GeneralPath(left);
            gp.append(right, false);
            entityArea = gp;
            addItemEntity(entities, dataset, row, column, entityArea);
        }
    } else if (pass == 1) {
        drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, transY1, y1 < 0.0);
    }

}

From source file:com.aurel.track.report.gantt.data.TrackGanttRenderer.java

/**
 * Draws a single task./*  www. java  2s .co m*/
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data plot 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 drawTask(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, TrackTaskSeriesCollection dataset, int row, int column,
        int pass) {

    log.debug("Working on item at position - column: " + column + " row: " + row);

    int seriesCount = getRowCount();
    int categoryCount = getColumnCount();

    RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();

    // Y0
    Number value0 = dataset.getEndValue(row, column);
    if (value0 == null) {
        return;
    }
    double java2dValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation);

    // Y1
    Number value1 = dataset.getStartValue(row, column);
    if (value1 == null) {
        return;
    }
    double java2dValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation);

    if (java2dValue1 < java2dValue0) {
        double temp = java2dValue1;
        java2dValue1 = java2dValue0;
        java2dValue0 = temp;
        Number tempNum = value1;
        value1 = value0;
        value0 = tempNum;
    }

    double rectStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation);

    // BREADTH
    double rectBreadth = state.getBarWidth();

    // BAR HEIGHT
    double rectLength = Math.abs(java2dValue1 - java2dValue0);

    Rectangle2D bar = null;

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

    // correct the start/stop Bars point
    if (startBars > (int) (java2dValue1 - rectLength)) {
        this.startBars = (int) (java2dValue1 - rectLength);
    }

    if (stopBars < (int) java2dValue1) {
        stopBars = (int) java2dValue1;
    }

    // The coordinates for the bar labels
    int startLabelX = 0;
    int startLabelY = 0;

    int endLabelX = 0;
    int endLabelY = 0;

    int barLabelX = 0;
    int barLabelY = 0;

    Polygon outer = null;
    Polygon inner = null;

    boolean isMilestone = dataset.isMilestone(column, row);
    boolean isSupertask = dataset.isSupertask(column, row);

    if (isMilestone) {

        // The start point for the end date label
        endLabelX = (int) (java2dValue1 + rectBreadth / 2);
        endLabelY = (int) (rectStart + (3 * rectBreadth / 4));

        barLabelX = (int) (java2dValue1 - rectBreadth / 2);
        barLabelY = (int) (rectStart + (3 * rectBreadth / 4));

        int breadth = (int) rectBreadth;

        int centerX = (int) java2dValue1;

        int centerY = (int) (rectStart + rectBreadth / 2);

        int[] xPoints = { centerX, centerX - breadth / 2, centerX, centerX + breadth / 2 };
        int[] yPoints = { centerY - breadth / 2, centerY, centerY + breadth / 2, centerY };

        outer = new Polygon(xPoints, yPoints, 4);

        //calculate the difference from the ratio
        int diff = (int) (rectBreadth / (2 * msInfo.getRatio()));

        int[] xPointsI = { centerX, centerX - breadth / 2 + diff, centerX, centerX + breadth / 2 - diff };
        int[] yPointsI = { centerY - breadth / 2 + diff, centerY, centerY + breadth / 2 - diff, centerY };

        inner = new Polygon(xPointsI, yPointsI, 4);

    }

    else if (isSupertask) {

        // The start point for the end date label
        startLabelX = (int) (java2dValue1 - rectLength - rectBreadth / 2);
        startLabelY = (int) (rectStart + rectBreadth * 3 / 4);

        endLabelX = (int) (java2dValue1 + rectBreadth / 2);
        endLabelY = (int) (rectStart + rectBreadth * 3 / 4);

        barLabelX = (int) (java2dValue1 - rectLength + rectBreadth / 3);
        barLabelY = (int) (rectStart + rectBreadth);

        int breadth = (int) rectBreadth;
        int length = (int) rectLength;

        int startX = (int) (java2dValue1 - rectLength);
        int startY = (int) rectStart;

        int[] xPoints = { startX - breadth / 2, startX + length + breadth / 2, startX + length + breadth / 2,
                startX + length, startX + length - breadth / 2, startX + breadth / 2, startX,
                startX - breadth / 2 };
        int[] yPoints = { startY, startY, startY + breadth / 2, startY + breadth, startY + breadth / 2,
                startY + breadth / 2, startY + breadth, startY + breadth / 2 };

        outer = new Polygon(xPoints, yPoints, 8);

        //calculate the difference from the ratio
        int diff = (int) (rectBreadth / (2 * stInfo.getRatio()));

        int[] xPointsI = { startX - breadth / 2 + diff, startX + length + breadth / 2 - diff,
                startX + length + breadth / 2 - diff, startX + length, startX + length - breadth / 2 + diff,
                startX + length - breadth / 2 + diff, startX + breadth / 2 - diff, startX + breadth / 2 - diff,
                startX, startX - breadth / 2 + diff };
        int[] yPointsI = { startY + diff, startY + diff, startY + breadth / 2, startY + breadth / 2 + diff,
                startY + breadth / 2, startY + breadth / 2 - diff, startY + breadth / 2 - diff,
                startY + breadth / 2, startY + breadth / 2 + diff, startY + breadth / 2 };

        inner = new Polygon(xPointsI, yPointsI, 10);
    } else {

        rectBreadth = rectBreadth / 2.0;
        // The start point for the end date label
        startLabelX = (int) (java2dValue1 - rectLength);
        startLabelY = (int) (rectStart + rectBreadth * 3 / 4);

        endLabelX = (int) java2dValue1;
        endLabelY = (int) (rectStart + rectBreadth * 3 / 4);

        barLabelX = (int) (java2dValue1 - rectLength);
        barLabelY = (int) (rectStart); //+ rectBreadth * 4 / 3 );

        bar = new Rectangle2D.Double(java2dValue0, rectStart, rectLength, rectBreadth);
        // percent complete could be obtained in the 
        // ReportBeans, set in the ReportBean and set in the Item by the GanttGenerator
        // currently this is not relevant.
        Rectangle2D completeBar = null;
        Rectangle2D incompleteBar = null;
        Number percent = dataset.getPercentComplete(row, column);
        double start = getStartPercent();
        double end = getEndPercent();
        if (percent != null) {
            double p = percent.doubleValue();
            completeBar = new Rectangle2D.Double(java2dValue0, rectStart + start * rectBreadth, rectLength * p,
                    rectBreadth * (end - start));
            incompleteBar = new Rectangle2D.Double(java2dValue0 + rectLength * p,
                    rectStart + start * rectBreadth, rectLength * (1 - p), rectBreadth * (end - start));
        }

        /** This is for displaying e.g. (german Soll und Ist Termine). This implementation is designed to display only one Series.
         * If you need Soll und Ist, you can generate two gantt charts.
         * --->> Paint seriesPaint = getItemPaint (row, column);
         */

        Paint seriesPaint = tsInfo.getInnerColor();

        g2.setPaint(seriesPaint);
        g2.fill(bar);

        if (tsInfo.isDisplayIDLabel() && (!tsInfo.isDisplaySynopsis())) {
            // draw the tasks ID
            drawLabel(new Integer(dataset.getItem(column, row).getId()).toString(), g2, barLabelX, barLabelY,
                    tsInfo.getLabelFontID(), false, (int) rectLength);
        }

        else if (tsInfo.isDisplaySynopsis()) {
            if (tsInfo.isDisplayDateLabel()) {

                // format start date to the requested format using the current locale
                String label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale))
                        .format(dataset.getItem(column, row).getStart());

                label = dataset.getItem(column, row).getDescription() + " - " + label;
                drawLabel(label, g2, barLabelX, barLabelY, tsInfo.getLabelFont(), true);

                // format end date to the requested format using the current locale
                label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale))
                        .format(dataset.getItem(column, row).getStop());

                // draw the supertasks end date
                drawLabel(label, g2, endLabelX, endLabelY, tsInfo.getLabelFont(), false);

            } else {
                drawLabel(dataset.getItem(column, row).getDescription(), g2, startLabelX, startLabelY,
                        tsInfo.getLabelFont(), true);
            }
        }

        if (tsInfo.isDisplayDateLabel() && (!tsInfo.isDisplaySynopsis())) {

            // format start date to the requested format using the current locale
            String label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale))
                    .format(dataset.getItem(column, row).getStart());

            // draw the tasks start date
            drawLabel(label, g2, startLabelX, startLabelY, tsInfo.getLabelFont(), true);

            // format end date to the requested format using the current locale
            label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale))
                    .format(dataset.getItem(column, row).getStop());
            // draw the tasks end date
            drawLabel(label, g2, endLabelX, endLabelY, tsInfo.getLabelFont(), false);
        }

        if (completeBar != null) {
            g2.setPaint(getCompletePaint());
            g2.fill(completeBar);
        }
        if (incompleteBar != null) {
            g2.setPaint(getIncompletePaint());
            g2.fill(incompleteBar);
        }

        // draw the outline...
        if (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);
            }
        }
    }

    // Draw milestone or Supertask
    if (isMilestone) {

        g2.setPaint(msInfo.getOuterColor());
        g2.fill(outer);
        g2.draw(outer);

        g2.setPaint(msInfo.getInnerColor());
        g2.fill(inner);
        g2.draw(inner);

        Stroke stroke = getItemOutlineStroke(row, column);
        Paint paint = getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(outer);
        }

        // draw the milestones due date
        if (msInfo.isDisplayDateLabel()) {

            // format milestone date to the requested format using the current locale
            String label = (new SimpleDateFormat(msInfo.getDateLabelFormat(), locale))
                    .format(dataset.getItem(column, row).getStart());

            drawLabel(label, g2, endLabelX, endLabelY, msInfo.getLabelFont(), false);
        }

        if (msInfo.isDisplayIDLabel() && (!msInfo.isDisplaySynopsis())) {
            // for milestones the ID is aligned at the left side.
            drawLabel(new Integer(dataset.getItem(column, row).getId()).toString(), g2, barLabelX, barLabelY,
                    msInfo.getLabelFontID(), true, (int) rectLength);
        } else if (msInfo.isDisplaySynopsis()) {
            drawLabel(dataset.getItem(column, row).getDescription(), g2, barLabelX, barLabelY,
                    msInfo.getLabelFont(), true, (int) rectLength);
        }

    } else if (isSupertask) {

        g2.setPaint(stInfo.getOuterColor());
        g2.fill(outer);
        g2.draw(outer);

        g2.setPaint(stInfo.getInnerColor());
        g2.fill(inner);
        g2.draw(inner);

        Stroke stroke = getItemOutlineStroke(row, column);
        Paint paint = getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(outer);
        }

        // draw the supertasks ID
        if (stInfo.isDisplayIDLabel() && (!stInfo.isDisplaySynopsis())) {
            drawLabel(new Integer(dataset.getItem(column, row).getId()).toString(), g2, barLabelX, barLabelY,
                    stInfo.getLabelFontID(), false, (int) rectLength);
        } else if (stInfo.isDisplaySynopsis()) {
            if (stInfo.isDisplayDateLabel()) {

                // format start date to the requested format using the current locale
                String label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale))
                        .format(dataset.getItem(column, row).getStart());

                label = dataset.getItem(column, row).getDescription() + " - " + label;
                drawLabel(label, g2, startLabelX, startLabelY, stInfo.getLabelFont(), true);

                // format end date to the requested format using the current locale
                label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale))
                        .format(dataset.getItem(column, row).getStop());

                // draw the supertasks end date
                drawLabel(label, g2, endLabelX, endLabelY, stInfo.getLabelFont(), false);

            } else {
                drawLabel(dataset.getItem(column, row).getDescription(), g2, startLabelX, startLabelY,
                        stInfo.getLabelFont(), true);
            }
        }
        if (stInfo.isDisplayDateLabel() && (!tsInfo.isDisplaySynopsis())) {

            // format start date to the requested format using the current locale
            String label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale))
                    .format(dataset.getItem(column, row).getStart());

            // draw the supertasks start date
            drawLabel(label, g2, startLabelX, startLabelY, stInfo.getLabelFont(), true);

            // format end date to the requested format using the current locale
            label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale))
                    .format(dataset.getItem(column, row).getStop());

            // draw the supertasks end date
            drawLabel(label, g2, endLabelX, endLabelY, stInfo.getLabelFont(), false);
        }
    }
}

From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java

/**
 * Draws the visual representation of a series as lines.
 *
 * @param g2  the graphics device./*from ww w. java 2s . com*/
 * @param state  the renderer state.
 * @param dataArea  the area within which the data is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param crosshairState  crosshair information for the plot
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 */
protected void drawVerticalSeriesLine(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea,
        PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
        int series, CrosshairState crosshairState, int pass) {

    State s = (State) state;
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double lowestVisibleX = domainAxis.getLowerBound();
    double highestVisibleX = domainAxis.getUpperBound();
    double width = dataArea.getWidth();
    double dX = (highestVisibleX - lowestVisibleX) / width * lineWidth;
    double lowestVisibleY = rangeAxis.getLowerBound();
    double highestVisibleY = rangeAxis.getUpperBound();

    double lastX = Double.NEGATIVE_INFINITY;
    double lastY = 0.0;
    double highY = 0.0;
    double lowY = 0.0;
    double openY = 0.0;
    double closeY = 0.0;
    boolean lastIntervalDone = false;
    boolean currentPointVisible = false;
    boolean lastPointVisible = false;
    boolean lastPointGood = false;
    boolean lastPointInInterval = false;
    boolean pathStarted = false;
    for (int itemIndex = state.getFirstItemIndex(); itemIndex <= state.getLastItemIndex(); itemIndex++) {
        double x = dataset.getXValue(series, itemIndex);
        double y = dataset.getYValue(series, itemIndex);
        if (!Double.isNaN(x) && !Double.isNaN(y)) {
            //System.out.println ("Breakpoint 736: pathStarted " + pathStarted);
            if (!pathStarted) {
                float startX = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
                float startY = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
                s.seriesPath.moveTo(startX, startY);
                pathStarted = true;
            }
            if ((Math.abs(x - lastX) > dX)) {
                //System.out.println ("Breakpoint 744: leaving interval ");
                //in any case, add the interval that we are about to leave to the intervalPath
                float intervalPathX = 0.0f;
                float intervalPathStartY = 0.0f;
                float intervalPathEndY = 0.0f;
                float seriesPathCurrentX = 0.0f;
                float seriesPathCurrentY = 0.0f;
                float seriesPathLastX = 0.0f;
                float seriesPathLastY = 0.0f;

                //first set some variables
                intervalPathX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                intervalPathStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
                intervalPathEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
                seriesPathCurrentX = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
                seriesPathLastX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                seriesPathCurrentY = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
                seriesPathLastY = (float) rangeAxis.valueToJava2D(closeY, dataArea, yAxisLocation);
                /*if((lowY - highY) < 1){
                lastPointInInterval = false;
                }*/
                //Double[] values = new Double[]{new Double(openY), new Double(closeY), new Double(highY), new Double(lowY), new Double(lastX)};
                /*MessageFormat mf = new MessageFormat("openY {0,number, integer},"
                    + " closeY {1,number, integer}"
                    + " highY {2,number, integer}"
                    + " lowY {3,number, integer}"
                    + "lastX {4,number, integer}");*/
                //String text = mf.format(values);
                //System.out.println("Breakpoint 772"  + text);
                boolean drawInterval = false;
                if (openY >= closeY) {
                    if (highY > openY || lowY < closeY) {
                        drawInterval = true;
                    }
                }
                if (openY < closeY) {
                    if (lowY < openY || highY > closeY) {
                        drawInterval = true;
                    }
                }
                //System.out.println("Breakpoint 784, drawInterval "  + drawInterval);
                if (drawInterval) {
                    s.intervalPath.moveTo(intervalPathX, intervalPathStartY);
                    s.intervalPath.lineTo(intervalPathX, intervalPathEndY);
                }
                lastIntervalDone = true;

                //now the series path
                currentPointVisible = ((x >= lowestVisibleX) && (x <= highestVisibleX) && (y >= lowestVisibleY)
                        && (y <= highestVisibleY));
                if (!lastPointGood && !lastPointInInterval) {//last point not valid --
                    if (currentPointVisible) {//--> if the current position is visible move seriesPath cursor to the current position
                        s.seriesPath.moveTo(seriesPathCurrentX, seriesPathCurrentY);
                    }
                } else {//last point valid
                    //if the last point was visible and not part of an interval,
                    //we have already moved the seriesPath cursor to the last point, either with or without drawingh a line
                    //thus we only need to draw a line to the current position
                    if (lastPointInInterval && lastPointGood) {
                        s.seriesPath.lineTo(seriesPathLastX, seriesPathLastY);
                        s.seriesPath.lineTo(seriesPathCurrentX, seriesPathCurrentY);
                    } //if the last point was not visible or part of an interval, we have just stored the y values of the last point
                      //and not yet moved the seriesPath cursor. Thus, we need to move the cursor to the last point without drawing
                      //and draw a line to the current position.
                    else {
                        s.seriesPath.lineTo(seriesPathCurrentX, seriesPathCurrentY);
                    }
                }
                lastPointVisible = currentPointVisible;
                lastX = x;
                lastY = y;
                highY = y;
                lowY = y;
                openY = y;
                closeY = y;
                lastPointInInterval = false;
            } else {
                lastIntervalDone = false;
                lastPointInInterval = true;
                highY = Math.max(highY, y);
                lowY = Math.min(lowY, y);
                closeY = y;
            }
            lastPointGood = true;
        } else {
            lastPointGood = false;
        }
    }
    // if this is the last item, draw the path ...
    // draw path, but first check whether we need to complete an interval
    if (!lastIntervalDone) {
        if (lowY < highY) {
            float intervalX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
            float intervalStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
            float intervalEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
            s.intervalPath.moveTo(intervalX, intervalStartY);
            s.intervalPath.lineTo(intervalX, intervalEndY);
        }
    }
    PathIterator pi = s.seriesPath.getPathIterator(null);
    g2.setStroke(getItemStroke(series, 0));
    g2.setPaint(getItemPaint(series, 0));
    g2.draw(s.seriesPath);
    g2.draw(s.intervalPath);
}

From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.renderer.HierarchicalBarRenderer.java

/**
 * Draws the bar for one item in the dataset.
 *
 * @param g2/*from  w  ww. j  a  v  a  2  s  .c om*/
 *            the graphics device.
 * @param state
 *            the renderer state.
 * @param dataArea
 *            the plot area.
 * @param plot
 *            the plot.
 * @param domainAxis
 *            the domain (category) axis.
 * @param rangeAxis
 *            the range (value) axis.
 * @param data
 *            the data.
 * @param row
 *            the row index (zero-based).
 * @param column
 *            the column index (zero-based).
 * @param pass
 *            the pass index.
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset data, int row, int column, int pass) {
    // nothing is drawn for null values...
    Number dataValue = data.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    // BAR X
    double rectX = domainAxis.getCategoryMiddle(column, this.getColumnCount(), dataArea,
            plot.getDomainAxisEdge()) - (state.getBarWidth() / 2.0);

    int seriesCount = this.getRowCount();

    // BAR Y
    double value = dataValue.doubleValue();
    double base = 0.0;
    double lclip = this.getLowerClip();
    double uclip = this.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 = this.getLowerClip();
        if (value >= uclip) {
            value = uclip;
        }
    }

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

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

    // draw the bar...
    double shift = 0.0;
    rectWidth = 0.0;
    double widthFactor = 1.0;
    double seriesBarWidth = this.getSeriesBarWidth(row);
    if (!Double.isNaN(seriesBarWidth)) {
        widthFactor = seriesBarWidth;
    }
    rectWidth = widthFactor * state.getBarWidth();
    rectX = rectX + (((1 - widthFactor) * state.getBarWidth()) / 2.0);
    if (seriesCount > 1) {
        // needs to be improved !!!
        shift = (rectWidth * 0.20) / (seriesCount - 1);
    }

    Rectangle2D bar = new Rectangle2D.Double((rectX + ((seriesCount - 1 - row) * shift)), rectY,
            (rectWidth - ((seriesCount - 1 - row) * shift * 2)), rectHeight);

    double rrX;
    double rrY;
    double rrW;
    double rrH;
    if (row == 0) {
        @SuppressWarnings("unchecked")
        Iterator it = this.datasetTree[column].getDescendants();
        int numElement = -1;
        while (it.hasNext()) {
            try {
                Element elt = (Element) it.next();
                numElement++;
                String name = elt.getAttributeValue("name");
                dataValue = Double.valueOf(elt.getAttributeValue("avg"));
                // System.out.println("["+column+"] "+name+" \t-->
                // "+dataValue);
                // BAR X
                rectX = domainAxis.getCategoryMiddle(column, this.getColumnCount(), dataArea,
                        plot.getDomainAxisEdge()) - (state.getBarWidth() / 2.0);

                seriesCount = this.getRowCount();

                // BAR Y
                value = dataValue.doubleValue();
                base = 0.0;
                lclip = this.getLowerClip();
                uclip = this.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 = this.getLowerClip();
                    if (value >= uclip) {
                        value = uclip;
                    }
                }

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

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

                // draw the bar...
                shift = 0.0;
                rectWidth = 0.0;
                widthFactor = 1.0;
                seriesBarWidth = this.getSeriesBarWidth(row);
                if (!Double.isNaN(seriesBarWidth)) {
                    widthFactor = seriesBarWidth;
                }
                rectWidth = widthFactor * state.getBarWidth();
                rectX = rectX + (((1 - widthFactor) * state.getBarWidth()) / 2.0);
                if (seriesCount > 1) {
                    // needs to be improved !!!
                    shift = (rectWidth * 0.20) / (seriesCount - 1);
                }
                rrX = (rectX + ((seriesCount - 1 - row) * shift));
                rrY = rectY;
                rrW = (rectWidth - ((seriesCount - 1 - row) * shift * 2));
                rrH = rectHeight;

                // IMPORTANT NOTE :
                // dev attribute is used to save width of the element
                // min attribute is used to save X position of the element
                // max attribute is used to save the number of child already
                // managed
                if (numElement == 0) {
                    elt.setAttribute("dev", "" + rrW);
                    elt.setAttribute("min", "" + rrX);
                    elt.setAttribute("max", "0");
                } else {
                    Element parent = elt.getParentElement();

                    // System.out.println(" Parent
                    // "+parent.getAttributeValue("name")
                    // + " rrX/rrW/child -> "
                    // + parent.getAttributeValue("min")+"/"
                    // + parent.getAttributeValue("dev")+"/"
                    // + parent.getAttributeValue("max") );
                    double pW = Double.valueOf(parent.getAttributeValue("dev"));
                    double pX = Double.valueOf(parent.getAttributeValue("min"));
                    int numChild = Integer.valueOf(parent.getAttributeValue("max"));

                    rrW = pW / parent.getChildren().size();
                    rrX = pX + (rrW * numChild);
                    rrX += HierarchicalBarRenderer.INCLUSION_MARGIN;
                    rrW -= (HierarchicalBarRenderer.INCLUSION_MARGIN * 2);
                    elt.setAttribute("dev", "" + rrW);
                    elt.setAttribute("min", "" + rrX);
                    parent.setAttribute("max", "" + (numChild + 1));
                }

                RoundRectangle2D rbar = new RoundRectangle2D.Double(rrX, rrY, rrW, rrH,
                        HierarchicalBarRenderer.CORNER, HierarchicalBarRenderer.CORNER);

                Rectangle2D childSumLine = null;
                double childSum = Double.valueOf(elt.getAttributeValue("sum"));
                transY1 = rangeAxis.valueToJava2D(base, dataArea, edge);
                transY2 = rangeAxis.valueToJava2D(childSum, dataArea, edge);
                rectY = Math.min(transY2, transY1);

                childSum = (childSum / dataValue.doubleValue()) * rrH;
                if ((childSum < rrH) && (childSum > 0) && ((childSum / rrH) < 0.95)) {
                    childSumLine = new Rectangle2D.Double(rrX, rectY, rrW, 1);
                }
                Paint itemPaint = this.getItemPaintFromName(name, this.series, column);
                GradientPaintTransformer t = this.getGradientPaintTransformer();
                if ((t != null) && itemPaint instanceof GradientPaint) {
                    itemPaint = t.transform((GradientPaint) itemPaint, bar);
                }
                g2.setPaint(itemPaint);

                Color c = g2.getColor();
                g2.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), this.alpha));
                g2.fill(rbar);
                g2.setColor(Color.DARK_GRAY);
                if (childSumLine != null) {
                    g2.fill(childSumLine);
                }

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

    // ////////////////////////////

    // draw the item labels if there are any...
    double transX1 = rangeAxis.valueToJava2D(base, dataArea, edge);
    double transX2 = rangeAxis.valueToJava2D(value, dataArea, edge);

    CategoryItemLabelGenerator generator = this.getItemLabelGenerator(row, column);
    if ((generator != null) && this.isItemLabelVisible(row, column)) {
        this.drawItemLabel(g2, data, row, column, plot, generator, bar, (transX1 > transX2));
    }

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

From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java

protected void drawSeriesLine(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea,
        PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
        int series, CrosshairState crosshairState, int pass) {

    State s = (State) state;
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double lowestVisibleX = domainAxis.getLowerBound();
    double highestVisibleX = domainAxis.getUpperBound();
    double width = (orientation == PlotOrientation.HORIZONTAL) ? dataArea.getHeight() : dataArea.getWidth();
    double dX = (highestVisibleX - lowestVisibleX) / width * lineWidth;
    double lowestVisibleY = rangeAxis.getLowerBound();
    double highestVisibleY = rangeAxis.getUpperBound();

    double lastX = Double.NEGATIVE_INFINITY;
    double lastY = 0.0;
    double highY = 0.0;
    double lowY = 0.0;
    double closeY = 0.0;
    boolean lastIntervalDone = false;
    boolean currentPointVisible = false;
    boolean lastPointVisible = false;
    boolean lastPointGood = false;
    boolean lastPointInInterval = false;
    int intervalCount = 0;
    int badPoints = 0;
    for (int itemIndex = state.getFirstItemIndex(); itemIndex <= state.getLastItemIndex(); itemIndex++) {
        double x = dataset.getXValue(series, itemIndex);
        double y = dataset.getYValue(series, itemIndex);
        if (!Double.isNaN(x) && !Double.isNaN(y)) {
            if ((Math.abs(x - lastX) > dX)) {
                //System.out.println("Breakpoint 1: leaving interval");
                //in any case, add the interval that we are about to leave to the intervalPath
                float intervalStartX = 0.0f;
                float intervalEndX = 0.0f;
                float intervalStartY = 0.0f;
                float intervalEndY = 0.0f;
                float currentX = 0.0f;
                float currentY = 0.0f;
                float lastFX = 0.0f;
                float lastFY = 0.0f;

                //first set some variables
                if (orientation == PlotOrientation.VERTICAL) {
                    intervalStartX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                    intervalEndX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                    intervalStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
                    intervalEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
                    currentX = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
                    lastFX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                    currentY = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
                    lastFY = (float) rangeAxis.valueToJava2D(closeY, dataArea, yAxisLocation);
                } else {
                    intervalStartX = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
                    intervalEndX = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
                    intervalStartY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                    intervalEndY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                    currentX = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
                    lastFX = (float) rangeAxis.valueToJava2D(closeY, dataArea, yAxisLocation);
                    currentY = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
                    lastFY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                }/*  w  w  w .j  a v  a 2s  .  c om*/
                if ((lowY - highY) < 1) {
                    //System.out.println("Breakpoint 2: setting lastPointInInterval");
                    lastPointInInterval = false;
                }
                //System.out.println("Breakpoint 3: lastPointInInterval: " +lastPointInInterval);
                if ((lowY < highY)) {
                    intervalCount++;
                    //System.out.println("Breakpoint 4: adding segment to interval path:" );
                    //System.out.println("xStart" + intervalStartX + ", yStart " + intervalStartY + ", xEnd " + intervalEndX + ", yEnd " + intervalEndY);
                    s.intervalPath.moveTo(intervalStartX, intervalStartY);
                    s.intervalPath.lineTo(intervalEndX, intervalEndY);
                    lastIntervalDone = true;
                }

                //now the series path
                currentPointVisible = ((x >= lowestVisibleX) && (x <= highestVisibleX) && (y >= lowestVisibleY)
                        && (y <= highestVisibleY));
                if (!lastPointGood) {//last point not valid --
                    badPoints++;
                    if (currentPointVisible) {//--> if the current position is visible move seriesPath cursor to the current position
                        s.seriesPath.moveTo(currentX, currentY);
                    }
                } else {//last point valid
                    //if the last point was visible and not part of an interval,
                    //we have already moved the seriesPath cursor to the last point, either with or without drawingh a line
                    //thus we only need to draw a line to the current position
                    if (lastPointVisible && !lastPointInInterval) {
                        s.seriesPath.lineTo(currentX, currentY);
                    } //if the last point was not visible or part of an interval, we have just stored the y values of the last point
                      //and not yet moved the seriesPath cursor. Thus, we need to move the cursor to the last point without drawing
                      //and draw a line to the current position.
                    else {
                        s.seriesPath.moveTo(lastFX, lastFY);
                        s.seriesPath.lineTo(currentX, currentY);
                    }
                }
                lastPointVisible = currentPointVisible;
                lastX = x;
                lastY = y;
                highY = y;
                lowY = y;
                closeY = y;
                lastPointInInterval = false;
            } else {
                lastIntervalDone = false;
                lastPointInInterval = true;
                highY = Math.max(highY, y);
                lowY = Math.min(lowY, y);
                closeY = y;
            }
            lastPointGood = true;
        } else {
            lastPointGood = false;
        }
    }
    // if this is the last item, draw the path ...
    // draw path, but first check whether we need to complete an interval
    if (!lastIntervalDone) {
        if (lowY < highY) {
            float intervalStartX = 0.0f;
            float intervalEndX = 0.0f;
            float intervalStartY = 0.0f;
            float intervalEndY = 0.0f;
            if (orientation == PlotOrientation.VERTICAL) {
                intervalStartX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                intervalEndX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                intervalStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
                intervalEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
            } else {
                intervalStartX = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
                intervalEndX = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
                intervalStartY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                intervalEndY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
            }
            intervalCount++;
            s.intervalPath.moveTo(intervalStartX, intervalStartY);
            s.intervalPath.lineTo(intervalEndX, intervalEndY);
        }
    }
    PathIterator pi = s.seriesPath.getPathIterator(null);
    g2.setStroke(getItemStroke(series, 0));
    g2.setPaint(getItemPaint(series, 0));
    g2.draw(s.seriesPath);
    g2.draw(s.intervalPath);
    //System.out.println("Interval count " + intervalCount);
    //System.out.println("Bad points " + badPoints);
}