Example usage for org.jfree.chart.plot XYPlot getOrientation

List of usage examples for org.jfree.chart.plot XYPlot getOrientation

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot getOrientation.

Prototype

@Override
public PlotOrientation getOrientation() 

Source Link

Document

Returns the orientation of the plot.

Usage

From source file:org.trade.ui.chart.renderer.PivotRenderer.java

/**
 * Draws the annotation.//from ww w. ja  v  a2 s  .c o  m
 * 
 * @param g2
 *            the graphics device.
 * @param plot
 *            the plot.
 * @param dataArea
 *            the data area.
 * @param domainAxis
 *            the domain axis.
 * @param rangeAxis
 *            the range axis.
 * @param rendererIndex
 *            the renderer index.
 * @param info
 *            the plot rendering info.
 * @param angle
 *            double
 * @param x
 *            double
 * @param y
 *            double
 * @param ledgend
 *            String
 */
public void drawPivotArrow(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis,
        ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info, double angle, double x, double y,
        String ledgend) {

    double tipRadius = DEFAULT_TIP_RADIUS;
    double baseRadius = DEFAULT_BASE_RADIUS;
    double arrowLength = DEFAULT_ARROW_LENGTH;
    double arrowWidth = DEFAULT_ARROW_WIDTH;
    double labelOffset = DEFAULT_LABEL_OFFSET;
    Font font = DEFAULT_FONT;
    Paint paint = DEFAULT_PAINT;
    boolean outlineVisible = false;
    Paint outlinePaint = Color.black;
    Stroke outlineStroke = new BasicStroke(0.5f);

    TextAnchor textAnchor = DEFAULT_TEXT_ANCHOR;
    TextAnchor rotationAnchor = DEFAULT_ROTATION_ANCHOR;
    double rotationAngle = DEFAULT_ROTATION_ANGLE;

    Stroke arrowStroke = new BasicStroke(1.0f);
    Paint arrowPaint = Color.black;

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
    double j2DX = domainAxis.valueToJava2D(x, dataArea, domainEdge);
    double j2DY = rangeAxis.valueToJava2D(y, dataArea, rangeEdge);
    if (orientation == PlotOrientation.HORIZONTAL) {
        double temp = j2DX;
        j2DX = j2DY;
        j2DY = temp;
    }
    double startX = j2DX + (Math.cos(angle) * baseRadius);
    double startY = j2DY + (Math.sin(angle) * baseRadius);

    double endX = j2DX + (Math.cos(angle) * tipRadius);
    double endY = j2DY + (Math.sin(angle) * tipRadius);

    double arrowBaseX = endX + (Math.cos(angle) * arrowLength);
    double arrowBaseY = endY + (Math.sin(angle) * arrowLength);

    double arrowLeftX = arrowBaseX + (Math.cos(angle + (Math.PI / 2.0)) * arrowWidth);
    double arrowLeftY = arrowBaseY + (Math.sin(angle + (Math.PI / 2.0)) * arrowWidth);

    double arrowRightX = arrowBaseX - (Math.cos(angle + (Math.PI / 2.0)) * arrowWidth);
    double arrowRightY = arrowBaseY - (Math.sin(angle + (Math.PI / 2.0)) * arrowWidth);

    GeneralPath arrow = new GeneralPath();
    arrow.moveTo((float) endX, (float) endY);
    arrow.lineTo((float) arrowLeftX, (float) arrowLeftY);
    arrow.lineTo((float) arrowRightX, (float) arrowRightY);
    arrow.closePath();

    g2.setStroke(arrowStroke);
    g2.setPaint(arrowPaint);
    Line2D line = new Line2D.Double(startX, startY, endX, endY);
    g2.draw(line);
    g2.fill(arrow);

    // draw the label
    double labelX = j2DX + (Math.cos(angle) * (baseRadius + labelOffset));
    double labelY = j2DY + (Math.sin(angle) * (baseRadius + labelOffset));
    g2.setFont(font);
    Shape hotspot = TextUtilities.calculateRotatedStringBounds(ledgend, g2, (float) labelX, (float) labelY,
            textAnchor, rotationAngle, rotationAnchor);
    g2.setPaint(paint);
    TextUtilities.drawRotatedString(ledgend, g2, (float) labelX, (float) labelY, textAnchor, rotationAngle,
            rotationAnchor);
    if (outlineVisible) {
        g2.setStroke(outlineStroke);
        g2.setPaint(outlinePaint);
        g2.draw(hotspot);
    }

    // String toolTip = getToolTipText();
    // String url = getURL();
    // if (toolTip != null || url != null) {
    // addEntity(info, hotspot, rendererIndex, toolTip, url);
    // }

}

From source file:com.att.aro.ui.view.diagnostictab.CreateBarPlot.java

public XYPlot drawYIntervalPlot() {
    // Create the plot renderer
    YIntervalRenderer renderer = new YIntervalRenderer() {
        private static final long serialVersionUID = 1L;

        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();
            }/*from w  ww . j  a  v  a2 s  . c  om*/

            IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;

            double x = intervalDataset.getXValue(series, item);
            double yLow = intervalDataset.getStartYValue(series, item);
            double yHigh = intervalDataset.getEndYValue(series, item);

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

            double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
            double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
            double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);

            Paint p = getItemPaint(series, item);
            Stroke s = getItemStroke(series, item);

            Line2D line = null;
            PlotOrientation orientation = plot.getOrientation();
            if (orientation == PlotOrientation.HORIZONTAL) {
                line = new Line2D.Double(yyLow, xx, yyHigh, xx);
            } else if (orientation == PlotOrientation.VERTICAL) {
                line = new Line2D.Double(xx, yyLow, xx, yyHigh);
            }
            g2.setPaint(p);
            g2.setStroke(s);
            g2.draw(line);

            // add an entity for the item...
            if (entities != null && line != null) {
                if (entityArea == null) {
                    entityArea = line.getBounds();
                }
                String tip = null;
                XYToolTipGenerator generator = getToolTipGenerator(series, item);
                if (generator != null) {
                    tip = generator.generateToolTip(dataset, series, item);
                }
                XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, null);
                entities.add(entity);
            }

        }

    };
    renderer.setAdditionalItemLabelGenerator(null);
    renderer.setBaseShape(new Rectangle());
    renderer.setAutoPopulateSeriesShape(false);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setBasePaint(Color.GRAY);

    // Create the plot
    XYPlot plot = new XYPlot(null, null, new NumberAxis(), renderer);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    plot.getRangeAxis().setVisible(false);

    return plot;
}

From source file:msi.gama.outputs.layers.charts.StandardXYItemRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2/*w w  w. j  a va 2s.  c  o m*/
 *            the graphics device.
 * @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
 *            crosshair information for the plot (<code>null</code> permitted).
 * @param pass
 *            the pass index.
 */
@Override
public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea,
        final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis,
        final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState,
        final int pass) {

    boolean itemVisible = getItemVisible(series, item);

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

    final PlotOrientation orientation = plot.getOrientation();
    final Paint paint = getItemPaint(series, item);
    final Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(seriesStroke);

    // get the data point...
    final double x1 = dataset.getXValue(series, item);
    final double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(x1) || Double.isNaN(y1)) {
        itemVisible = false;
    }

    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    final double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    final double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getPlotLines()) {
        if (this.drawSeriesLineAsPath) {
            final State s = (State) state;
            if (s.getSeriesIndex() != series) {
                // we are starting a new series path
                s.seriesPath.reset();
                s.lastPointGood = false;
                s.setSeriesIndex(series);
            }

            // update path to reflect latest point
            if (itemVisible && !Double.isNaN(transX1) && !Double.isNaN(transY1)) {
                float x = (float) transX1;
                float y = (float) transY1;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    x = (float) transY1;
                    y = (float) transX1;
                }
                if (s.isLastPointGood()) {
                    // TODO: check threshold
                    s.seriesPath.lineTo(x, y);
                } else {
                    s.seriesPath.moveTo(x, y);
                }
                s.setLastPointGood(true);
            } else {
                s.setLastPointGood(false);
            }
            if (item == dataset.getItemCount(series) - 1) {
                if (s.seriesIndex == series) {
                    // draw path
                    g2.setStroke(lookupSeriesStroke(series));
                    g2.setPaint(lookupSeriesPaint(series));
                    g2.draw(s.seriesPath);
                }
            }
        }

        else if (item != 0 && itemVisible) {
            // get the previous data point...
            final double x0 = dataset.getXValue(series, item - 1);
            final double y0 = dataset.getYValue(series, item - 1);
            if (!Double.isNaN(x0) && !Double.isNaN(y0)) {
                boolean drawLine = true;
                if (getPlotDiscontinuous()) {
                    // only draw a line if the gap between the current and
                    // previous data point is within the threshold
                    final int numX = dataset.getItemCount(series);
                    final double minX = dataset.getXValue(series, 0);
                    final double maxX = dataset.getXValue(series, numX - 1);
                    if (this.gapThresholdType == UnitType.ABSOLUTE) {
                        drawLine = Math.abs(x1 - x0) <= this.gapThreshold;
                    } else {
                        drawLine = Math.abs(x1 - x0) <= (maxX - minX) / numX * getGapThreshold();
                    }
                }
                if (drawLine) {
                    final double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
                    final double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

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

                    if (orientation == PlotOrientation.HORIZONTAL) {
                        state.workingLine.setLine(transY0, transX0, transY1, transX1);
                    } else if (orientation == PlotOrientation.VERTICAL) {
                        state.workingLine.setLine(transX0, transY0, transX1, transY1);
                    }

                    if (state.workingLine.intersects(dataArea)) {
                        g2.draw(state.workingLine);
                    }
                }
            }
        }
    }

    // we needed to get this far even for invisible items, to ensure that
    // seriesPath updates happened, but now there is nothing more we need
    // to do for non-visible items...
    if (!itemVisible) {
        return;
    }

    if (getBaseShapesVisible()) {

        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        }
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
        }
        entityArea = shape;

    }

    if (getPlotImages()) {
        final Image image = getImage(plot, series, item, transX1, transY1);
        if (image != null) {
            final Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
            g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null);
            entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(),
                    image.getWidth(null), image.getHeight(null));
        }

    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, y1 < 0.0);
    }

    final int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    final int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1,
            orientation);

    // add an entity for the item...
    if (entities != null && isPointInRect(dataArea, xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }

}

From source file:anl.verdi.plot.jfree.XYBlockRenderer.java

/**
 * Draws the block representing the specified item.
 *
 * @param g2             the graphics device.
 * @param state          the state.//from   ww  w  .jav a2  s .c  o  m
 * @param dataArea       the data area.
 * @param info           the plot rendering info.
 * @param plot           the plot.
 * @param domainAxis     the x-axis.
 * @param rangeAxis      the y-axis.
 * @param dataset        the dataset.
 * @param series         the series index.
 * @param item           the item index.
 * @param crosshairState the crosshair state.
 * @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) {

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double z = 0.0;
    double max = paintScale.getUpperBound();
    double min = paintScale.getLowerBound();

    if (dataset instanceof XYZDataset)
        z = ((XYZDataset) dataset).getZValue(series, item);

    //NOTE: so to get the max/min color instead of unknown (Qun He, UNC, 03/19/2009)
    if (z > max)
        z = max;

    if (z < min)
        z = min;

    Color p = (Color) this.paintScale.getPaint(z);

    double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea, plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea, plot.getRangeAxisEdge());
    double xx1 = domainAxis.valueToJava2D(x + this.blockWidth + this.xOffset, dataArea,
            plot.getDomainAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight + this.yOffset, dataArea,
            plot.getRangeAxisEdge());
    Rectangle2D block;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation.equals(PlotOrientation.HORIZONTAL)) {
        block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0),
                Math.abs(xx0 - xx1));
    } else {
        block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0),
                Math.abs(yy1 - yy0));
    }
    g2.setColor(p);
    g2.fill(block);

    if (gridLinesEnabled) {
        boolean aaOn = false;
        if (g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING) == RenderingHints.VALUE_ANTIALIAS_ON) {
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
            aaOn = true;
        }
        g2.setPaint(gridLineColor);
        g2.setStroke(gridLineStroke);
        g2.draw(block);
        if (aaOn)
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    } else {
        g2.setStroke(basicStroke);
        g2.draw(block);
    }
}

From source file:com.att.aro.main.PacketPlots.java

/**
 * The utility method that creates the packet plots from a packet series map
 *//*  ww w .j a  v  a  2s.  com*/
private XYPlot createPlot() {

    // Create the plot renderer
    YIntervalRenderer renderer = new YIntervalRenderer() {
        private static final long serialVersionUID = 1L;

        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();
            }

            IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;

            double x = intervalDataset.getXValue(series, item);
            double yLow = intervalDataset.getStartYValue(series, item);
            double yHigh = intervalDataset.getEndYValue(series, item);

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

            double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
            double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
            double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);

            Paint p = getItemPaint(series, item);
            Stroke s = getItemStroke(series, item);

            Line2D line = null;
            PlotOrientation orientation = plot.getOrientation();
            if (orientation == PlotOrientation.HORIZONTAL) {
                line = new Line2D.Double(yyLow, xx, yyHigh, xx);
            } else if (orientation == PlotOrientation.VERTICAL) {
                line = new Line2D.Double(xx, yyLow, xx, yyHigh);
            }
            g2.setPaint(p);
            g2.setStroke(s);
            g2.draw(line);

            // add an entity for the item...
            if (entities != null) {
                if (entityArea == null) {
                    entityArea = line.getBounds();
                }
                String tip = null;
                XYToolTipGenerator generator = getToolTipGenerator(series, item);
                if (generator != null) {
                    tip = generator.generateToolTip(dataset, series, item);
                }
                XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, null);
                entities.add(entity);
            }

        }

    };
    renderer.setAdditionalItemLabelGenerator(null);
    renderer.setBaseShape(new Rectangle());
    renderer.setAutoPopulateSeriesShape(false);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setBasePaint(Color.GRAY);

    // Create the plot
    XYPlot plot = new XYPlot(null, null, new NumberAxis(), renderer);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    plot.getRangeAxis().setVisible(false);

    return plot;
}

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

/**    
 * Draws the item shapes and adds chart entities (second pass). This method    
 * draws the shapes which mark the item positions. If <code>entities</code>    
 * is not <code>null</code> it will be populated with entity information    
 * for points that fall within the data area.    
 *    /*w ww  . jav  a2s .  c  om*/
 * @param g2  the graphics device.    
 * @param plot  the plot (can be used to obtain standard color    
 *              information etc).    
 * @param domainAxis  the domain axis.    
 * @param dataArea  the area within which the data is being drawn.    
 * @param rangeAxis  the range axis.    
 * @param dataset  the dataset.    
 * @param pass  the pass.    
 * @param series  the series index (zero-based).    
 * @param item  the item index (zero-based).    
 * @param crosshairState  the crosshair state.    
 * @param entities the entity collection.    
 */
protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item,
        ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis, CrosshairState crosshairState,
        EntityCollection entities) {

    Shape entityArea = null;

    // get the data point...    
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getItemShapeVisible(series, item)) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        }
        entityArea = shape;
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                if (this.useFillPaint) {
                    g2.setPaint(getItemFillPaint(series, item));
                } else {
                    g2.setPaint(getItemPaint(series, item));
                }
                //g2.fill(shape);    
            }
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item));
                } else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.setStroke(getItemOutlineStroke(series, item));
                // g2.draw(shape);    
            }
        }
    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...    
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0));
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1,
            orientation);

    // add an entity for the item, but only if it falls within the data    
    // area...    
    if (entities != null && isPointInRect(dataArea, xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }
}

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

/**
 * Draws an item label.  This method is provided as an alternative to
 * {@link #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int, 
 * double, double, boolean)} so that the bar can be used to calculate the 
 * label anchor point. /*from   w w  w.ja va 2s .  c om*/
 * 
 * @param g2  the graphics device.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param plot  the plot.
 * @param generator  the label generator (<code>null</code> permitted, in 
 *         which case the method does nothing, just returns).
 * @param bar  the bar.
 * @param negative  a flag indicating a negative value.
 */
protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot,
        XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) {

    if (generator == null) {
        return; // nothing to do
    }
    String label = generator.generateLabel(dataset, series, item);
    if (label == null) {
        return; // nothing to do   
    }

    Font labelFont = getItemLabelFont(series, item);
    g2.setFont(labelFont);
    Paint paint = getItemLabelPaint(series, item);
    g2.setPaint(paint);

    // find out where to place the label...
    ItemLabelPosition position = null;
    if (!negative) {
        position = getPositiveItemLabelPosition(series, item);
    } else {
        position = getNegativeItemLabelPosition(series, item);
    }

    // work out the label anchor point...
    Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation());

    if (isInternalAnchor(position.getItemLabelAnchor())) {
        Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(),
                (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());

        if (bounds != null) {
            if (!bar.contains(bounds.getBounds2D())) {
                if (!negative) {
                    position = getPositiveItemLabelPositionFallback();
                } else {
                    position = getNegativeItemLabelPositionFallback();
                }
                if (position != null) {
                    anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar,
                            plot.getOrientation());
                }
            }
        }

    }

    if (position != null) {
        TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(), position.getRotationAnchor());
    }
}

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

/**    
* Draws an item label.  This method is provided as an alternative to    
* {@link #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int,     
* double, double, boolean)} so that the bar can be used to calculate the     
* label anchor point.     //from w ww . ja  v a2  s  . c  o m
*     
* @param g2  the graphics device.    
* @param dataset  the dataset.    
* @param series  the series index.    
* @param item  the item index.    
* @param plot  the plot.    
* @param generator  the label generator (<code>null</code> permitted, in     
*         which case the method does nothing, just returns).    
* @param bar  the bar.    
* @param negative  a flag indicating a negative value.    
*/
protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot,
        XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) {

    if (generator == null) {
        return; // nothing to do    
    }
    String label = generator.generateLabel(dataset, series, item);
    if (label == null) {
        return; // nothing to do       
    }

    Font labelFont = getItemLabelFont(series, item);
    g2.setFont(labelFont);
    Paint paint = getItemLabelPaint(series, item);
    g2.setPaint(paint);

    // find out where to place the label...    
    ItemLabelPosition position = null;
    if (!negative) {
        position = getPositiveItemLabelPosition(series, item);
    } else {
        position = getNegativeItemLabelPosition(series, item);
    }

    // work out the label anchor point...    
    Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation());

    if (isInternalAnchor(position.getItemLabelAnchor())) {
        Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(),
                (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());

        if (bounds != null) {
            if (!bar.contains(bounds.getBounds2D())) {
                if (!negative) {
                    position = getPositiveItemLabelPositionFallback();
                } else {
                    position = getNegativeItemLabelPositionFallback();
                }
                if (position != null) {
                    anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar,
                            plot.getOrientation());
                }
            }
        }

    }

    if (position != null) {
        TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(), position.getRotationAnchor());
    }
}

From source file:org.schreibubi.JCombinations.jfreechart.XYLineAndShapeRendererExtended.java

/**
 * Draws a horizontal line across the chart to represent a 'range marker'.
 * //from www  . j  a va  2s .  c om
 * @param g2
 *            the graphics device.
 * @param plot
 *            the plot.
 * @param rangeAxis
 *            the range axis.
 * @param marker
 *            the marker line.
 * @param dataArea
 *            the axis data area.
 */
@Override
public void drawRangeMarker(Graphics2D g2, XYPlot plot, ValueAxis rangeAxis, Marker marker,
        Rectangle2D dataArea) {

    if (marker instanceof ValueMarker)
        super.drawRangeMarker(g2, plot, rangeAxis, marker, dataArea);
    else if (marker instanceof IntervalMarker)
        super.drawRangeMarker(g2, plot, rangeAxis, marker, dataArea);
    else if (marker instanceof ArbitraryMarker) {

        ArbitraryMarker im = (ArbitraryMarker) marker;
        ArrayList<Double> xvals = im.getDomainVal();
        ArrayList<Double> lows = im.getRangeLowValues();
        ArrayList<Double> highs = im.getRangeHighValues();
        sort(xvals, lows, highs);

        Range range = rangeAxis.getRange();
        ValueAxis domainAxis = plot.getDomainAxis();
        Range domain = domainAxis.getRange();

        int length = xvals.size();
        int[] xpoly = new int[length * 2];
        int[] ypoly = new int[length * 2];

        for (int i = 0; i < xvals.size(); i++) {
            double x = domain.constrain(xvals.get(i));
            double low = range.constrain(lows.get(i));
            double high = range.constrain(highs.get(i));
            int low2d = (int) Math.round(rangeAxis.valueToJava2D(low, dataArea, plot.getRangeAxisEdge()));
            int high2d = (int) Math.round(rangeAxis.valueToJava2D(high, dataArea, plot.getRangeAxisEdge()));
            int x2d = (int) Math.round(domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()));
            xpoly[i] = x2d;
            xpoly[2 * length - 1 - i] = x2d;
            ypoly[i] = low2d;
            ypoly[2 * length - 1 - i] = high2d;
        }

        PlotOrientation orientation = plot.getOrientation();
        Polygon poly = null;
        if (orientation == PlotOrientation.HORIZONTAL)
            poly = new Polygon(ypoly, xpoly, length * 2);
        else if (orientation == PlotOrientation.VERTICAL)
            poly = new Polygon(xpoly, ypoly, length * 2);

        Paint p = im.getPaint();
        if (p instanceof GradientPaint) {
            GradientPaint gp = (GradientPaint) p;
            GradientPaintTransformer t = im.getGradientPaintTransformer();
            if (t != null)
                gp = t.transform(gp, poly);
            g2.setPaint(gp);
        } else
            g2.setPaint(p);
        g2.fill(poly);
        /*
         * String label = marker.getLabel(); RectangleAnchor anchor = marker.getLabelAnchor(); if ( label != null ) {
         * Font labelFont = marker.getLabelFont(); g2.setFont( labelFont ); g2.setPaint( marker.getLabelPaint() );
         * Point2D coordinates = calculateRangeMarkerTextAnchorPoint( g2, orientation, dataArea, poly,
         * marker.getLabelOffset(), marker.getLabelOffsetType(), anchor ); TextUtilities.drawAlignedString( label,
         * g2, ( float ) coordinates.getX(), ( float ) coordinates.getY(), marker.getLabelTextAnchor() ); }
         */
    }
}

From source file:net.sf.maltcms.chromaui.charts.renderer.XYNoBlockRenderer.java

/**
 * Draws the block representing the specified item.
 *
 * @param g2 the graphics device./*from w  ww. j  a va2s .  c  o m*/
 * @param state the state.
 * @param dataArea the data area.
 * @param info the plot rendering info.
 * @param plot the plot.
 * @param domainAxis the x-axis.
 * @param rangeAxis the y-axis.
 * @param dataset the dataset.
 * @param series the series index.
 * @param item the item index.
 * @param crosshairState the crosshair state.
 * @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) {
    //        return;
    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double z = 0.0;
    if (dataset instanceof XYZDataset) {
        z = ((XYZDataset) dataset).getZValue(series, item);
        if (entityThreshold != Double.NaN && z < entityThreshold) {
            return;
        }
    }

    //}
    Paint p = getPaintScale().getPaint(z);
    //        if(p.equals(getPaintScale().getPaint(getPaintScale().getLowerBound()))) {
    //            return;
    //        }
    //        double xx0 = domainAxis.valueToJava2D(x + xOffset, dataArea,
    //                plot.getDomainAxisEdge());
    //        double yy0 = rangeAxis.valueToJava2D(y + yOffset, dataArea,
    //                plot.getRangeAxisEdge());
    //        double xx1 = domainAxis.valueToJava2D(x + blockWidth
    //                + xOffset, dataArea, plot.getDomainAxisEdge());
    //        double yy1 = rangeAxis.valueToJava2D(y + blockHeight
    //                + yOffset, dataArea, plot.getRangeAxisEdge());
    double xx0 = domainAxis.valueToJava2D(x - getBlockWidth() / 2, dataArea, plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y - getBlockHeight() / 2, dataArea, plot.getRangeAxisEdge());
    double xx1 = domainAxis.valueToJava2D(x + getBlockWidth() / 2, dataArea, plot.getDomainAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y + getBlockHeight() / 2, dataArea, plot.getRangeAxisEdge());

    Rectangle2D block;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation.equals(PlotOrientation.HORIZONTAL)) {
        if (dataArea.contains(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0),
                Math.abs(xx0 - xx1))) {
            block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0),
                    Math.abs(xx0 - xx1));
        } else {
            return;
        }
    } else {
        if (dataArea.contains(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0),
                Math.abs(yy0 - yy1))) {
            block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0),
                    Math.abs(yy0 - yy1));
        } else {
            return;
        }
    }

    g2.setPaint(p);
    g2.fill(block);
    g2.setStroke(new BasicStroke(1.0f));
    g2.draw(block);
    EntityCollection entities = state.getEntityCollection();
    //        System.out.println("Entity collection is of type: "+entities.getClass());
    if (entities != null) {
        //System.out.println("Adding entity");
        addEntity(entities, block, dataset, series, item, block.getCenterX(), block.getCenterY());
    }

}