Example usage for org.jfree.util ShapeUtilities createTranslatedShape

List of usage examples for org.jfree.util ShapeUtilities createTranslatedShape

Introduction

In this page you can find the example usage for org.jfree.util ShapeUtilities createTranslatedShape.

Prototype

public static Shape createTranslatedShape(final Shape shape, final double transX, final double transY) 

Source Link

Document

Creates and returns a translated shape.

Usage

From source file:com.bdb.weather.display.day.ItemRenderer.java

/**
 * Plots the data for a given series.//w ww .  j  a  v  a 2s .  c om
 * 
 * @param g2  the drawing surface.
 * @param dataArea  the data area.
 * @param info  collects plot rendering info.
 * @param plot  the plot.
 * @param dataset  the dataset.
 * @param seriesIndex  the series index.
 */
@Override
public void drawSeries(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, PolarPlot plot,
        XYDataset dataset, int seriesIndex) {
    Shape point = new Rectangle2D.Double(-2, -2, 4, 4);

    int numPoints = dataset.getItemCount(seriesIndex);

    g2.setPaint(lookupSeriesPaint(seriesIndex));
    g2.setStroke(lookupSeriesStroke(seriesIndex));

    for (int i = 0; i < numPoints; i++) {
        double theta = dataset.getXValue(seriesIndex, i);
        double radius = dataset.getYValue(seriesIndex, i);

        Point p = plot.translateToJava2D(theta, radius, plot.getAxis(), dataArea);

        Shape shape = ShapeUtilities.createTranslatedShape(point, p.getX(), p.getY());

        g2.fill(shape);
    }
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

public static Shape translateChartShape(Shape shape, Rectangle2D imageArea, JFreeChart chart) {
    if (shape instanceof Line2D) {
        Line2D line = (Line2D) shape;
        double length = line.getP1().distance(line.getP2());
        if (length == 0) {
            Point2D point = line.getP1();
            Point2D newPoint = ChartMaskingUtilities.translateChartPoint(point, imageArea, chart);
            Shape oShape = ShapeUtilities.createDiagonalCross(5f, 0.2f);
            //             Shape oShape = ShapeUtilities.createRegularCross(3f, 0.5f);
            Shape newShape = ShapeUtilities.createTranslatedShape(oShape, newPoint.getX(), newPoint.getY());
            return newShape;
        } else if (length < 1e-6) {
            if (line.getP1().getX() == line.getP2().getX()) {
                double newX = ChartMaskingUtilities.translateChartPoint(line.getP1(), imageArea, chart).getX();
                Line2D newLine = new Line2D.Double(newX, imageArea.getMinY(), newX, imageArea.getMaxY());
                return newLine;
            } else {
                double newY = ChartMaskingUtilities.translateChartPoint(line.getP1(), imageArea, chart).getY();
                Line2D newLine = new Line2D.Double(imageArea.getMinX(), newY, imageArea.getMaxX(), newY);
                return newLine;
            }//from  w  w  w. ja v a 2 s  .c o m
        }
        Line2D newShape = (Line2D) line.clone();
        Point2D newP1 = translateChartPoint(line.getP1(), imageArea, chart);
        Point2D newP2 = translateChartPoint(line.getP2(), imageArea, chart);
        newShape.setLine(newP1, newP2);
        return newShape;
    } else if (shape instanceof RectangularShape) {
        RectangularShape rect = (RectangularShape) shape;
        RectangularShape newShape = (RectangularShape) rect.clone();
        Rectangle2D bound = rect.getBounds2D();
        Point2D start = new Point2D.Double(bound.getMinX(), bound.getMinY());
        Point2D end = new Point2D.Double(bound.getMaxX(), bound.getMaxY());
        Point2D screenStart = translateChartPoint(start, imageArea, chart);
        Point2D screenEnd = translateChartPoint(end, imageArea, chart);
        newShape.setFrame(new Rectangle2D.Double(Math.min(screenStart.getX(), screenEnd.getX()),
                Math.min(screenStart.getY(), screenEnd.getY()), Math.abs(screenStart.getX() - screenEnd.getX()),
                Math.abs(screenStart.getY() - screenEnd.getY())));
        return newShape;
    } else {
        return shape;
    }
}

From source file:edu.cuny.jfree.chart.renderer.category.ValueListShapeRenderer.java

@Override
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) {

    final ListCategoryDataset setData = (ListCategoryDataset) dataset;

    final List list = setData.getList(row, column);
    if (list == null) {
        return;/*w w w.j  av a  2 s.c o m*/
    }

    final PlotOrientation orientation = plot.getOrientation();
    final double x = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());

    final Iterator iterator = list.iterator();
    while (iterator.hasNext()) {
        final Number value = (Number) iterator.next();
        final double y = rangeAxis.valueToJava2D(value.doubleValue(), dataArea, plot.getRangeAxisEdge());

        Shape shape = getItemShape(row, column);

        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y, x);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x, y);
        }
        if (getItemShapeVisible(row, column)) {
            if (getItemShapeFilled(row, column)) {
                g2.setPaint(getItemPaint(row, column));
                g2.fill(shape);
            } else {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(row, column));
                } else {
                    g2.setPaint(getItemPaint(row, column));
                }
                g2.setStroke(getItemOutlineStroke(row, column));
                g2.draw(shape);
            }
        }
        g2.setPaint(getItemPaint(row, column));

        if (isItemLabelVisible(row, column)) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, row, column, y, x, value.doubleValue() < 0.0D);
            } else if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, row, column, x, y, value.doubleValue() < 0.0D);
            }
        }

        if (state.getInfo() != null) {
            final EntityCollection entities = state.getEntityCollection();
            if ((entities != null) && (shape != null)) {
                String tip = null;
                final CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
                if (tipster != null) {
                    tip = tipster.generateToolTip(dataset, row, column);
                }
                String url = null;
                if (getItemURLGenerator(row, column) != null) {
                    url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
                }
                final CategoryItemEntity entity = new CategoryItemEntity(shape, tip, url, dataset,
                        dataset.getRowKey(row), dataset.getColumnKey(column));
                entities.add(entity);
            }
        }
    }
}

From source file:com.rapidminer.gui.plotter.charts.ColorizedShapeItemRenderer.java

/**
 * Draws the block representing the specified item.
 * /*from   ww w.j  a  va2s  .  c  om*/
 * @param g2
 *            the graphics device.
 * @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) {

    Shape hotspot = null;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double colorValue = ((XYZDataset) dataset).getZValue(series, item);
    double normalized = (colorValue - minColor) / (maxColor - minColor);

    if (Double.isNaN(x) || Double.isNaN(y)) {
        // can't draw anything
        return;
    }

    double transX = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
    double transY = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());

    PlotOrientation orientation = plot.getOrientation();

    Shape shape = getItemShape(series, item);
    if (orientation == PlotOrientation.HORIZONTAL) {
        shape = ShapeUtilities.createTranslatedShape(shape, transY, transX);
    } else if (orientation == PlotOrientation.VERTICAL) {
        shape = ShapeUtilities.createTranslatedShape(shape, transX, transY);
    }
    hotspot = shape;
    if (shape.intersects(dataArea)) {
        g2.setPaint(colorProvider.getPointColor(normalized));
        g2.fill(shape);
        if (getDrawOutlines()) {
            if (getUseOutlinePaint()) {
                g2.setPaint(getItemOutlinePaint(series, item));
            } else {
                g2.setPaint(getItemPaint(series, item));
            }
            g2.setStroke(getItemOutlineStroke(series, item));
            g2.draw(shape);
        }
    }

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

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.renderer.FormattedScatterRenderer.java

/**
 * This function is taken directly from JFreeChart with adjustments to draw differently colored
 * items./*from  ww  w.  ja  v a2  s. c o m*/
 * 
 * When updating JFreeChart this function must probably be adapted.
 * 
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
        return;
    }
    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    int visibleRowCount = state.getVisibleSeriesCount();

    PlotOrientation orientation = plot.getOrientation();

    ValueSourceToMultiValueCategoryDatasetAdapter dataSet = (ValueSourceToMultiValueCategoryDatasetAdapter) dataset;
    List values = dataSet.getValues(row, column);
    if (values == null) {
        return;
    }
    int valueCount = values.size();
    for (int i = 0; i < valueCount; i++) {
        // current data point...
        double x1;
        if (getUseSeriesOffset()) {
            x1 = domainAxis.getCategorySeriesMiddle(column, dataset.getColumnCount(), visibleRow,
                    visibleRowCount, getItemMargin(), dataArea, plot.getDomainAxisEdge());
        } else {
            x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
        }
        Number n = (Number) values.get(i);
        int idx = dataSet.getValueIndex(row, column, i);
        double value = n.doubleValue();
        double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());

        Shape shape = getItemShape(row, idx);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
        }
        if (getItemShapeFilled(row, column)) {
            if (getUseFillPaint()) {
                g2.setPaint(getItemFillPaint(row, column));
            } else {
                g2.setPaint(getItemPaint(row, idx));
            }
            g2.fill(shape);
        }
        if (getDrawOutlines()) {
            if (getUseOutlinePaint()) {
                g2.setPaint(getItemOutlinePaint(row, column));
            } else {
                g2.setPaint(getItemPaint(row, idx));
            }
            g2.setStroke(getItemOutlineStroke(row, column));
            g2.draw(shape);
        }
    }
}

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

/**
 * Draw a single data item./*from   ww  w. j a  v  a2  s  .co m*/
 * 
 * @param g2 the graphics device.
 * @param state the renderer state.
 * @param dataArea the area in which the data is drawn.
 * @param plot the plot.
 * @param domainAxis the domain axis.
 * @param rangeAxis the range axis.
 * @param dataset the dataset (a {@link StatisticalCategoryDataset} is required).
 * @param row the row index (zero-based).
 * @param column the column index (zero-based).
 * @param pass the pass.
 */
@Override
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) {

    // nothing is drawn for null...
    final Number v = dataset.getValue(row, column);
    if (v == null) {
        return;
    }
    // *************** This line was changed relative to StatisticalLineAndShapeRenderer*****
    final AsymmetricStatisticalCategoryDataset statData = (AsymmetricStatisticalCategoryDataset) dataset;
    // *************** end of changed line **********************************************

    final Number meanValue = statData.getMeanValue(row, column);

    final PlotOrientation orientation = plot.getOrientation();

    // current data point...
    final double x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea,
            plot.getDomainAxisEdge());

    final double y1 = rangeAxis.valueToJava2D(meanValue.doubleValue(), dataArea, plot.getRangeAxisEdge());

    Shape shape = getItemShape(row, column);
    if (orientation == PlotOrientation.HORIZONTAL) {
        shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
    } else if (orientation == PlotOrientation.VERTICAL) {
        shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
    }
    if (getItemShapeVisible(row, column)) {

        if (getItemShapeFilled(row, column)) {
            g2.setPaint(getItemPaint(row, column));
            g2.fill(shape);
        } else {
            if (getUseOutlinePaint()) {
                g2.setPaint(getItemOutlinePaint(row, column));
            } else {
                g2.setPaint(getItemPaint(row, column));
            }
            g2.setStroke(getItemOutlineStroke(row, column));
            g2.draw(shape);
        }
    }

    if (getItemLineVisible(row, column)) {
        if (column != 0) {

            final Number previousValue = statData.getValue(row, column - 1);
            if (previousValue != null) {

                // previous data point...
                final double previous = previousValue.doubleValue();
                final double x0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea,
                        plot.getDomainAxisEdge());
                final double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge());

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

    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    double rectX = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, xAxisLocation);

    rectX = rectX + row * state.getBarWidth();

    g2.setPaint(getItemPaint(row, column));
    // ************* This is the block with changes relative to StatisticalLineAndShapeRenderer *********
    // standard deviation lines
    final Number highValObj = statData.getUpperValue(row, column);
    final Number lowValObj = statData.getLowerValue(row, column);

    if (highValObj != null && lowValObj != null) { // rinke added this test
        double highVal = highValObj.doubleValue();
        double lowVal = lowValObj.doubleValue();
        if (highVal > rangeAxis.getRange().getUpperBound()) {
            highVal = rangeAxis.valueToJava2D(rangeAxis.getRange().getUpperBound(), dataArea, yAxisLocation);
        } else {
            highVal = rangeAxis.valueToJava2D(highVal, dataArea, yAxisLocation);
        }

        if (lowVal < rangeAxis.getRange().getLowerBound()) {
            lowVal = rangeAxis.valueToJava2D(rangeAxis.getRange().getLowerBound(), dataArea, yAxisLocation);
        } else {
            lowVal = rangeAxis.valueToJava2D(lowVal, dataArea, yAxisLocation);
        }
        // ****************** end of changed block **********************************

        if (errorIndicatorPaint != null) {
            g2.setPaint(errorIndicatorPaint);
        } else {
            g2.setPaint(getItemPaint(row, column));
        }
        final Line2D line = new Line2D.Double();
        if (orientation == PlotOrientation.HORIZONTAL) {
            line.setLine(lowVal, x1, highVal, x1);
            g2.draw(line);
            line.setLine(lowVal, x1 - 5.0d, lowVal, x1 + 5.0d);
            g2.draw(line);
            line.setLine(highVal, x1 - 5.0d, highVal, x1 + 5.0d);
            g2.draw(line);
        } else { // PlotOrientation.VERTICAL
            line.setLine(x1, lowVal, x1, highVal);
            g2.draw(line);
            line.setLine(x1 - 5.0d, highVal, x1 + 5.0d, highVal);
            g2.draw(line);
            line.setLine(x1 - 5.0d, lowVal, x1 + 5.0d, lowVal);
            g2.draw(line);
        }

    }

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

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

        }

    }

}

From source file:umontreal.iro.lecuyer.charts.EmpiricalRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2           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./*from  w  w  w .j av a2 s  . com*/
 * @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) {

    if (!getItemVisible(series, item))
        return;
    PlotOrientation orientation = plot.getOrientation();
    java.awt.Paint seriesPaint = getItemPaint(series, item);
    java.awt.Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(seriesPaint);
    g2.setStroke(seriesStroke);
    double x0 = dataset.getXValue(series, item);
    double y0 = dataset.getYValue(series, item);
    if (java.lang.Double.isNaN(y0))
        return;
    org.jfree.ui.RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    org.jfree.ui.RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

    double x1 = 0, y1 = 0;
    if (item < dataset.getItemCount(series) - 1) {
        x1 = dataset.getXValue(series, item + 1);
        y1 = dataset.getYValue(series, item + 1);
    } else {
        x1 = dataArea.getMaxX();
        y1 = dataArea.getMaxY();
    }

    boolean useFillPaint = getUseFillPaint();
    ;
    boolean drawOutlines = getDrawOutlines();
    if (!java.lang.Double.isNaN(y0)) {
        double transX1;
        double transY1;
        if (item < dataset.getItemCount(series) - 1) {
            transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
            transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
        } else {
            transX1 = x1;
            transY1 = y1;
        }
        Line2D line = state.workingLine;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line.setLine(transY0, transX0, transY0, transX1);
            g2.draw(line);
        } else if (orientation == PlotOrientation.VERTICAL) {
            line.setLine(transX0, transY0, transX1, transY0);
            g2.draw(line);
        }
    }
    if (getItemShapeVisible(series, item)) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL)
            shape = ShapeUtilities.createTranslatedShape(shape, transY0, transX0);
        else if (orientation == PlotOrientation.VERTICAL)
            shape = ShapeUtilities.createTranslatedShape(shape, transX0, transY0);
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                if (useFillPaint)
                    g2.setPaint(getItemFillPaint(series, item));
                else
                    g2.setPaint(getItemPaint(series, item));
                g2.fill(shape);
            }
            if (drawOutlines) {
                if (getUseOutlinePaint())
                    g2.setPaint(getItemOutlinePaint(series, item));
                else
                    g2.setPaint(getItemPaint(series, item));
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }
    }
    if (isItemLabelVisible(series, item)) {
        double xx = transX0;
        double yy = transY0;
        if (orientation == PlotOrientation.HORIZONTAL) {
            xx = transY0;
            yy = transX0;
        }
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, y0 < 0.0D);
    }
    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x0, y0, domainAxisIndex, rangeAxisIndex, transX0, transY0,
            orientation);
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            int r = getDefaultEntityRadius();
            java.awt.Shape shape = orientation != PlotOrientation.VERTICAL
                    ? ((java.awt.Shape) (new java.awt.geom.Rectangle2D.Double(transY0 - (double) r,
                            transX0 - (double) r, 2 * r, 2 * r)))
                    : ((java.awt.Shape) (new java.awt.geom.Rectangle2D.Double(transX0 - (double) r,
                            transY0 - (double) r, 2 * r, 2 * r)));
            if (shape != null) {
                String tip = null;
                XYToolTipGenerator generator = getToolTipGenerator(series, item);
                if (generator != null)
                    tip = generator.generateToolTip(dataset, series, item);
                String url = null;
                if (getURLGenerator() != null)
                    url = getURLGenerator().generateURL(dataset, series, item);
                XYItemEntity entity = new XYItemEntity(shape, dataset, series, item, tip, url);
                entities.add(entity);
            }
        }
    }
}

From source file:org.mwc.cmap.grideditor.chart.RendererWithDynamicFeedback.java

/**
 * @see drawSecondaryPass/* ww  w .j a  v  a 2s. c o m*/
 */
private void drawFeedBackNode(final Graphics2D g2, final XYPlot plot, final XYDataset dataset, final int pass, //
        final int series, final int item, final ValueAxis domainAxis, final Rectangle2D dataArea,
        final ValueAxis rangeAxis, //
        final CrosshairState crosshairState, final EntityCollection entities) {

    // get the data point...
    final double x1 = myFeedBackValue != null ? myFeedBackValue.x : dataset.getXValue(series, item);
    final double y1 = myFeedBackValue != null ? myFeedBackValue.y : dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }

    final PlotOrientation orientation = plot.getOrientation();
    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 (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);
        }
        if (shape.intersects(dataArea)) {
            g2.setPaint(getFeedbackNodePaint());
            g2.fill(shape);
        }
    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }
    drawFeedbackItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0));
}

From source file:org.geotools.renderer.chart.GeometryRenderer.java

void drawCoordinate(Coordinate c, Graphics2D g2, int series, int item, Rectangle2D dataArea, XYPlot plot,
        ValueAxis domainAxis, ValueAxis rangeAxis) {

    double tx = domainAxis.valueToJava2D(c.x, dataArea, plot.getDomainAxisEdge());
    double ty = rangeAxis.valueToJava2D(c.y, dataArea, plot.getRangeAxisEdge());

    Shape shape = getItemShape(series, item);
    shape = ShapeUtilities.createTranslatedShape(shape, tx, ty);

    if (fillCoordinates) {
        g2.fill(shape);//from  ww  w.  ja  v  a 2 s . c  om
    } else {
        g2.draw(shape);
    }
}

From source file:gda.plots.SimpleXYItemRenderer.java

/**
 * Draws the visual representation of a single data item. This mostly reproduces the code of StandardXYItemRenderer
 * but using the line by line information stored in the SimpleXYSeries instead of the series indexed information
 * stored in the Renderer itself./*  w  w w.j av  a2 s . co  m*/
 * 
 * @param g2
 *            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(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {
    SimpleXYSeries sxys = (SimpleXYSeries) ((SimpleXYSeriesCollection) dataset).getSeries(series);

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

    PlotOrientation orientation = plot.getOrientation();
    g2.setPaint(sxys.getPaint());
    g2.setStroke(sxys.getStroke());

    // get the data point
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);

    // Test
    x1 = xValueTransformer.transformValue(x1);

    if (Double.isNaN(x1) || Double.isNaN(y1)) {
        return;
    }

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

    if (sxys.isDrawLines()) {
        if (item > 0) {
            // get the previous data point...
            double x0 = dataset.getXValue(series, item - 1);
            double y0 = dataset.getYValue(series, item - 1);

            // Test
            // System.out.print("tranformed " + x0);
            x0 = xValueTransformer.transformValue(x0);
            // Message.debug(" to " + x0);
            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
                    int numX = dataset.getItemCount(series);
                    double minX = dataset.getXValue(series, 0);
                    double maxX = dataset.getXValue(series, numX - 1);
                    drawLine = (x1 - x0) <= ((maxX - minX) / numX * getGapThreshold());
                }
                if (drawLine) {
                    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
                    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);
                    }
                }
            }
        }
    }

    if (sxys.isDrawMarkers()) {

        Shape shape = sxys.getSymbol();
        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)) {
            g2.setPaint(sxys.getSymbolPaint());
            // Always use full stroke for drawing marker
            g2.setStroke(new BasicStroke());
            if (sxys.getFilled()) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
            g2.setPaint(sxys.getPaint());
            g2.setStroke(sxys.getStroke());
        }
        entityArea = shape;

    }

    if (getPlotImages()) {
        // use shape scale with transform??
        // double scale = getShapeScale(plot, series, item, transX1,
        // transY1);
        Image image = getImage(plot, series, item, transX1, transY1);
        if (image != null) {
            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));
        }

    }

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

    updateCrosshairValues(crosshairState, x1, y1, transX1, transY1, orientation);

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

}