Example usage for org.jfree.chart.entity EntityCollection add

List of usage examples for org.jfree.chart.entity EntityCollection add

Introduction

In this page you can find the example usage for org.jfree.chart.entity EntityCollection add.

Prototype

public void add(ChartEntity entity);

Source Link

Document

Adds an entity to the collection.

Usage

From source file:hudson.util.NoOverlapCategoryAxis.java

@Override
protected AxisState drawCategoryLabels(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea,
        RectangleEdge edge, AxisState state, PlotRenderingInfo plotState) {

    if (state == null) {
        throw new IllegalArgumentException("Null 'state' argument.");
    }/*from  w  w  w.  j  a v  a 2  s.c o  m*/

    if (isTickLabelsVisible()) {
        java.util.List ticks = refreshTicks(g2, state, plotArea, edge);
        state.setTicks(ticks);

        // remember the last drawn label so that we can avoid drawing overlapping labels.
        Rectangle2D r = null;

        int categoryIndex = 0;
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {

            CategoryTick tick = (CategoryTick) iterator.next();
            g2.setFont(getTickLabelFont(tick.getCategory()));
            g2.setPaint(getTickLabelPaint(tick.getCategory()));

            CategoryLabelPosition position = this.getCategoryLabelPositions().getLabelPosition(edge);
            double x0 = 0.0;
            double x1 = 0.0;
            double y0 = 0.0;
            double y1 = 0.0;
            if (edge == RectangleEdge.TOP) {
                x0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
                x1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
                y1 = state.getCursor() - this.getCategoryLabelPositionOffset();
                y0 = y1 - state.getMax();
            } else if (edge == RectangleEdge.BOTTOM) {
                x0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
                x1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
                y0 = state.getCursor() + this.getCategoryLabelPositionOffset();
                y1 = y0 + state.getMax();
            } else if (edge == RectangleEdge.LEFT) {
                y0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
                y1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
                x1 = state.getCursor() - this.getCategoryLabelPositionOffset();
                x0 = x1 - state.getMax();
            } else if (edge == RectangleEdge.RIGHT) {
                y0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
                y1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
                x0 = state.getCursor() + this.getCategoryLabelPositionOffset();
                x1 = x0 - state.getMax();
            }
            Rectangle2D area = new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0));
            if (r == null || !r.intersects(area)) {
                Point2D anchorPoint = RectangleAnchor.coordinates(area, position.getCategoryAnchor());
                TextBlock block = tick.getLabel();
                block.draw(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                        position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                        position.getAngle());
                Shape bounds = block.calculateBounds(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                        position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                        position.getAngle());
                if (plotState != null && plotState.getOwner() != null) {
                    EntityCollection entities = plotState.getOwner().getEntityCollection();
                    if (entities != null) {
                        String tooltip = getCategoryLabelToolTip(tick.getCategory());
                        entities.add(new CategoryLabelEntity(tick.getCategory(), bounds, tooltip, null));
                    }
                }
                r = bounds.getBounds2D();
            }

            categoryIndex++;
        }

        if (edge.equals(RectangleEdge.TOP)) {
            double h = state.getMax();
            state.cursorUp(h);
        } else if (edge.equals(RectangleEdge.BOTTOM)) {
            double h = state.getMax();
            state.cursorDown(h);
        } else if (edge == RectangleEdge.LEFT) {
            double w = state.getMax();
            state.cursorLeft(w);
        } else if (edge == RectangleEdge.RIGHT) {
            double w = state.getMax();
            state.cursorRight(w);
        }
    }
    return state;
}

From source file:net.sourceforge.processdash.ui.web.CGIChartBase.java

private void writeImageHtml(int width, int height, int imgID, ChartRenderingInfo info) throws IOException {
    String tooltip = getParameter("tooltip");
    if (!StringUtils.hasValue(tooltip))
        tooltip = resources.getHTML("More_Detail_Here_Instruction");

    String href = getParameter("href");
    if (StringUtils.hasValue(href)) {
        // create a copy of the entity collection, and place an entity for
        // the entire chart at the beginning of the list.  This will
        // make it appear last in the image map (which is important,
        // because browsers process the image map areas in the order that
        // they appear; having the entire chart area listed first would
        // obscure all of the other image map areas).
        EntityCollection entities = new StandardEntityCollection();
        entities.add(new ChartEntity(info.getChartArea(), tooltip, href));
        if (info.getEntityCollection() != null)
            entities.addAll(info.getEntityCollection());

        // Next: most of our chart entities will not have URLs. URL values
        // don't inherit in the imagemap, so if we want the entire image
        // to have a single URL, we need to assign that URL to every
        // area in the chart.
        for (Iterator i = entities.iterator(); i.hasNext();) {
            ChartEntity ce = (ChartEntity) i.next();
            // check for no-op chart entity - these won't appear in the
            // image map anyway, so they don't need to be adjusted
            if (ce.getToolTipText() == null && ce.getURLText() == null)
                continue;
            // for other entities, add a tooltip and a URL as needed.
            if (!StringUtils.hasValue(ce.getToolTipText()))
                ce.setToolTipText(tooltip);
            if (!StringUtils.hasValue(ce.getURLText()))
                ce.setURLText(href);/*from   w  ww. java2 s  .  c om*/
        }

        // install our modified version of the entity collection into
        // the chart info object, so it will be used when generating
        // the image map later.
        info.setEntityCollection(entities);
    }

    // write the image tag
    out.write("<img width=\"" + width + "\" height=\"" + height + "\" src=\"/reports/pngCache?id=" + imgID
            + "\" usemap=\"#IMG" + imgID + '"');

    // imagemaps have hyperlink borders by default, even if we don't
    // have a URL we're pointing to.  Turn that border off.
    if (!StringUtils.hasValue(href) || parameters.containsKey("noBorder"))
        out.write(" border=\"0\"");

    // Our client might want to add attributes to the image tag. Look
    // through the query parameters we received for arbitrary attributes
    // starting with the prefix "img", and copy them into the tag.
    for (Iterator i = parameters.entrySet().iterator(); i.hasNext();) {
        Map.Entry e = (Map.Entry) i.next();
        String attrName = (String) e.getKey();
        if (attrName.startsWith("img") && !attrName.endsWith("_ALL")) {
            out.write(" " + attrName.substring(3) + "=\"");
            out.write(HTMLUtils.escapeEntities(e.getValue().toString()));
            out.write('"');
        }
    }

    out.write(">");

    // finally, write the image map.  Note that we have to strip line
    // break characters from the resulting HTML, otherwise firefox seems
    // to decide that the <map> tag actually takes up space on the page
    String imageMapHtml = ImageMapUtilities.getImageMap("IMG" + imgID, info, getToolTipGenerator(tooltip),
            new StandardURLTagFragmentGenerator());
    for (int i = 0; i < imageMapHtml.length(); i++) {
        char c = imageMapHtml.charAt(i);
        if (c != '\r' && c != '\n')
            out.write(c);
    }
    out.flush();
}

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

/**
 * Draws the visual representation of a single data item.
 * //from  w  w  w. jav a  2s  .  c  o  m
 * @param g2
 *            the graphics device.
 * @param state
 *            the renderer state.
 * @param dataArea
 *            the area within which the plot 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.
 * @see org.jfree.chart.renderer.xy.XYItemRenderer#drawItem(Graphics2D,
 *      XYItemRendererState, Rectangle2D, PlotRenderingInfo, XYPlot,
 *      ValueAxis, ValueAxis, XYDataset, int, int, CrosshairState, int)
 */
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;
    }

    VolumeDataset volumeDataset = (VolumeDataset) dataset;
    VolumeItem volumeItem = (VolumeItem) volumeDataset.getSeries(series).getDataItem(item);

    if (volumeItem.isSide()) {
        this.color = Color.GREEN;
    } else {
        this.color = Color.RED;
    }

    double value0;
    double value1;
    if (this.getUseYInterval()) {
        value0 = volumeDataset.getStartYValue(series, item);
        value1 = volumeDataset.getEndYValue(series, item);
    } else {
        value0 = this.getBase();
        value1 = volumeDataset.getYValue(series, item);
    }
    if (Double.isNaN(value0) || Double.isNaN(value1)) {
        return;
    }
    if (value0 <= value1) {
        if (!rangeAxis.getRange().intersects(value0, value1)) {
            return;
        }
    } else {
        if (!rangeAxis.getRange().intersects(value1, value0)) {
            return;
        }
    }

    double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge());
    double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge());
    double bottom = Math.min(translatedValue0, translatedValue1);
    double top = Math.max(translatedValue0, translatedValue1);

    double startX = volumeItem.getPeriod().getFirstMillisecond();
    if (Double.isNaN(startX)) {
        return;
    }
    double endX = volumeItem.getPeriod().getLastMillisecond();
    if (Double.isNaN(endX)) {
        return;
    }

    if (startX <= endX) {
        if (!domainAxis.getRange().intersects(startX, endX)) {
            return;
        }
    } else {
        if (!domainAxis.getRange().intersects(endX, startX)) {
            return;
        }
    }

    // is there an alignment adjustment to be made?
    if (this.getBarAlignmentFactor() >= 0.0 && this.getBarAlignmentFactor() <= 1.0) {
        double x = volumeDataset.getXValue(series, item);
        double interval = endX - startX;
        startX = x - interval * this.getBarAlignmentFactor();
        endX = startX + interval;
    }

    RectangleEdge location = plot.getDomainAxisEdge();
    double translatedStartX = domainAxis.valueToJava2D(startX, dataArea, location);
    double translatedEndX = domainAxis.valueToJava2D(endX, dataArea, location);

    double translatedWidth = Math.max(1, Math.abs(translatedEndX - translatedStartX));

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

    if (getMargin() > 0.0) {
        double cut = translatedWidth * getMargin();
        translatedWidth = translatedWidth - cut;
    }

    Rectangle2D bar = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        // clip left and right bounds to data area
        bottom = Math.max(bottom, dataArea.getMinX());
        top = Math.min(top, dataArea.getMaxX());
        bar = new Rectangle2D.Double(bottom, xx, top - bottom, translatedWidth);
    } else if (orientation == PlotOrientation.VERTICAL) {
        // clip top and bottom bounds to data area
        bottom = Math.max(bottom, dataArea.getMinY());
        top = Math.min(top, dataArea.getMaxY());
        bar = new Rectangle2D.Double(xx - (translatedWidth / 2), bottom, translatedWidth, top - bottom);
    }

    boolean positive = (value1 > 0.0);
    boolean inverted = rangeAxis.isInverted();
    RectangleEdge barBase;
    if (orientation == PlotOrientation.HORIZONTAL) {
        if (positive && inverted || !positive && !inverted) {
            barBase = RectangleEdge.RIGHT;
        } else {
            barBase = RectangleEdge.LEFT;
        }
    } else {
        if (positive && !inverted || !positive && inverted) {
            barBase = RectangleEdge.BOTTOM;
        } else {
            barBase = RectangleEdge.TOP;
        }
    }
    if (getShadowsVisible()) {
        this.getBarPainter().paintBarShadow(g2, this, series, item, bar, barBase, !this.getUseYInterval());
    }
    this.getBarPainter().paintBar(g2, this, series, item, bar, barBase);

    if (isItemLabelVisible(series, item)) {
        XYItemLabelGenerator generator = getItemLabelGenerator(series, item);
        drawItemLabel(g2, dataset, series, item, plot, generator, bar, value1 < 0.0);
    }

    // update the cross hair point
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, location);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge());
    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1,
            plot.getOrientation());

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

        entities.add(entity);
    }
}

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

public void drawItem(Graphics2D graphics2d, CategoryItemRendererState categoryitemrendererstate,
        Rectangle2D rectangle2d, CategoryPlot categoryplot, CategoryAxis categoryaxis, ValueAxis valueaxis,
        CategoryDataset categorydataset, int i, int j, int k) {
    Number number = categorydataset.getValue(i, j);
    if (number == null)
        return;/*from  w w w  .  j av a2  s  .c  o  m*/
    double d = number.doubleValue();
    java.awt.geom.Rectangle2D.Double double1 = new java.awt.geom.Rectangle2D.Double(rectangle2d.getX(),
            rectangle2d.getY() + getYOffset(), rectangle2d.getWidth() - getXOffset(),
            rectangle2d.getHeight() - getYOffset());
    PlotOrientation plotorientation = categoryplot.getOrientation();
    double d1 = calculateBarW0(categoryplot, plotorientation, double1, categoryaxis, categoryitemrendererstate,
            i, j);
    double ad[] = calculateBarL0L1(d);
    if (ad == null)
        return;
    RectangleEdge rectangleedge = categoryplot.getRangeAxisEdge();
    float f = (float) valueaxis.valueToJava2D(ad[0], double1, rectangleedge);
    float f1 = (float) valueaxis.valueToJava2D(ad[1], double1, rectangleedge);
    float f2 = Math.min(f, f1);
    float f3 = Math.abs(f1 - f);
    GeneralPath generalpath = new GeneralPath();
    java.awt.geom.Ellipse2D.Double double2 = null;
    if (plotorientation == PlotOrientation.HORIZONTAL) {
        generalpath.moveTo((float) ((double) f2 + getXOffset() / 2D), (float) d1);
        generalpath.lineTo((float) ((double) (f2 + f3) + getXOffset() / 2D), (float) d1);
        java.awt.geom.Arc2D.Double double3 = new java.awt.geom.Arc2D.Double(f2 + f3, d1, getXOffset(),
                categoryitemrendererstate.getBarWidth(), 90D, 180D, 0);
        generalpath.append(double3, true);
        generalpath.lineTo((float) ((double) f2 + getXOffset() / 2D),
                (float) (d1 + categoryitemrendererstate.getBarWidth()));
        double3 = new java.awt.geom.Arc2D.Double(f2, d1, getXOffset(), categoryitemrendererstate.getBarWidth(),
                270D, -180D, 0);
        generalpath.append(double3, true);
        generalpath.closePath();
        double2 = new java.awt.geom.Ellipse2D.Double(f2 + f3, d1, getXOffset(),
                categoryitemrendererstate.getBarWidth());
    } else {
        generalpath.moveTo((float) d1, (float) ((double) f2 - getYOffset() / 2D));
        generalpath.lineTo((float) d1, (float) ((double) (f2 + f3) - getYOffset() / 2D));
        java.awt.geom.Arc2D.Double double4 = new java.awt.geom.Arc2D.Double(d1,
                (double) (f2 + f3) - getYOffset(), categoryitemrendererstate.getBarWidth(), getYOffset(), 180D,
                180D, 0);
        generalpath.append(double4, true);
        generalpath.lineTo((float) (d1 + categoryitemrendererstate.getBarWidth()),
                (float) ((double) f2 - getYOffset() / 2D));
        double4 = new java.awt.geom.Arc2D.Double(d1, (double) f2 - getYOffset(),
                categoryitemrendererstate.getBarWidth(), getYOffset(), 0.0D, -180D, 0);
        generalpath.append(double4, true);
        generalpath.closePath();
        double2 = new java.awt.geom.Ellipse2D.Double(d1, (double) f2 - getYOffset(),
                categoryitemrendererstate.getBarWidth(), getYOffset());
    }
    Object obj = getItemPaint(i, j);
    if (getGradientPaintTransformer() != null && (obj instanceof GradientPaint)) {
        GradientPaint gradientpaint = (GradientPaint) obj;
        obj = getGradientPaintTransformer().transform(gradientpaint, generalpath);
    }
    graphics2d.setPaint(((java.awt.Paint) (obj)));
    graphics2d.fill(generalpath);
    if (obj instanceof GradientPaint) {
        graphics2d.setPaint(((GradientPaint) obj).getColor2());
    }
    if (double2 != null) {
        graphics2d.fill(double2);
    }
    if (isDrawBarOutline() && categoryitemrendererstate.getBarWidth() > 3D) {
        graphics2d.setStroke(getItemOutlineStroke(i, j));
        graphics2d.setPaint(getItemOutlinePaint(i, j));
        graphics2d.draw(generalpath);
        if (double2 != null)
            graphics2d.draw(double2);
    }
    CategoryItemLabelGenerator categoryitemlabelgenerator = getItemLabelGenerator(i, j);
    if (categoryitemlabelgenerator != null && isItemLabelVisible(i, j))
        drawItemLabel(graphics2d, categorydataset, i, j, categoryplot, categoryitemlabelgenerator,
                generalpath.getBounds2D(), d < 0.0D);
    if (categoryitemrendererstate.getInfo() != null) {
        EntityCollection entitycollection = categoryitemrendererstate.getEntityCollection();
        if (entitycollection != null) {
            String s = null;
            CategoryToolTipGenerator categorytooltipgenerator = getToolTipGenerator(i, j);
            if (categorytooltipgenerator != null)
                s = categorytooltipgenerator.generateToolTip(categorydataset, i, j);
            String s1 = null;
            if (getItemURLGenerator(i, j) != null)
                s1 = getItemURLGenerator(i, j).generateURL(categorydataset, i, j);
            CategoryItemEntity categoryitementity = new CategoryItemEntity(generalpath.getBounds2D(), s, s1,
                    categorydataset, categorydataset.getRowKey(i), categorydataset.getColumnKey(j));
            entitycollection.add(categoryitementity);
        }
    }
}

From source file:ro.nextreports.engine.util.chart.CylinderRenderer.java

/**
 * Draws a cylinder to represent one data item.
 * /*w  w w  .ja v a 2 s. c  o m*/
 * @param g2 the graphics device.
 * @param state the renderer state.
 * @param dataArea the area for plotting the data.
 * @param plot the plot.
 * @param domainAxis the domain axis.
 * @param rangeAxis the range axis.
 * @param dataset the dataset.
 * @param row the row index (zero-based).
 * @param column the column index (zero-based).
 * @param pass the pass index.
 */
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // check the value we are plotting...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    double value = dataValue.doubleValue();

    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(),
            dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());

    PlotOrientation orientation = plot.getOrientation();

    double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column);
    double[] barL0L1 = calculateBarL0L1(value);
    if (barL0L1 == null) {
        return; // the bar is not visible
    }

    RectangleEdge edge = plot.getRangeAxisEdge();
    float transL0 = (float) rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
    float transL1 = (float) rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    float barL0 = Math.min(transL0, transL1);
    float barLength = Math.abs(transL1 - transL0);

    // draw the bar...
    GeneralPath bar = new GeneralPath();
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar.moveTo(barL0, (float) barW0);
        bar.lineTo(barL0, (float) (barW0 + state.getBarWidth()));
        bar.lineTo(barL0 + barLength, (float) (barW0 + state.getBarWidth()));
        bar.lineTo(barL0 + barLength, (float) barW0);
        bar.closePath();
    } else {
        bar.moveTo((float) barW0, (float) (barL0 - getYOffset() / 2));
        bar.lineTo((float) barW0, (float) (barL0 + barLength - getYOffset() / 2));
        Arc2D arc = new Arc2D.Double(barW0, (barL0 + barLength - getYOffset()), state.getBarWidth(),
                getYOffset(), 180, 180, Arc2D.OPEN);
        bar.append(arc, true);
        bar.lineTo((float) (barW0 + state.getBarWidth()), (float) (barL0 - getYOffset() / 2));
        arc = new Arc2D.Double(barW0, (barL0 - getYOffset()), state.getBarWidth(), getYOffset(), 0, -180,
                Arc2D.OPEN);
        bar.append(arc, true);
        bar.closePath();
    }
    Paint itemPaint = getItemPaint(row, column);
    if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) itemPaint;
        itemPaint = getGradientPaintTransformer().transform(gp, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    Shape bar3dTop = new Ellipse2D.Double(barW0, barL0 - getYOffset(), state.getBarWidth(), getYOffset());
    if (itemPaint instanceof GradientPaint) {
        g2.setPaint(((GradientPaint) itemPaint).getColor2());
    }
    g2.fill(bar3dTop);

    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemOutlineStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
        if (bar3dTop != null) {
            g2.draw(bar3dTop);
        }
    }

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

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {

            String tip = null;
            CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
            if (tipster != null) {
                tip = tipster.generateToolTip(dataset, row, column);
            }
            String url = null;
            if (getItemURLGenerator(row, column) != null) {
                url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
            }
            CategoryItemEntity entity = new CategoryItemEntity(bar.getBounds2D(), tip, url, dataset,
                    dataset.getRowKey(row), dataset.getColumnKey(column));
            entities.add(entity);
        }
    }

}

From source file:org.pentaho.plugin.jfreereport.reportcharts.BubbleRenderer.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 (horizontal) axis.
 * @param rangeAxis      the range (vertical) axis.
 * @param dataset        the dataset (an {@link XYZDataset} is expected).
 * @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.
 *//*w w  w.j  a  v a2s .c o m*/
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) {

    final PlotOrientation orientation = plot.getOrientation();

    // get the data point...
    final double x = dataset.getXValue(series, item);
    final double y = dataset.getYValue(series, item);
    double z = Double.NaN;
    if (dataset instanceof XYZDataset) {
        final XYZDataset xyzData = (XYZDataset) dataset;
        z = xyzData.getZValue(series, item);
    }
    if (!Double.isNaN(z)) {
        final RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
        final RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
        final double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation);
        final double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation);

        double circleSize;

        circleSize = maxSize * (z / maxZ);

        circleSize = Math.abs(circleSize);

        Ellipse2D circle = null;
        if (orientation == PlotOrientation.VERTICAL) {
            circle = new Ellipse2D.Double(transX - circleSize / 2.0, transY - circleSize / 2.0, circleSize,
                    circleSize);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            circle = new Ellipse2D.Double(transY - circleSize / 2.0, transX - circleSize / 2.0, circleSize,
                    circleSize);
        }
        g2.setPaint(getItemPaint(series, item));
        g2.fill(circle);
        g2.setStroke(getItemOutlineStroke(series, item));
        g2.setPaint(getItemOutlinePaint(series, item));
        g2.draw(circle);

        if (isItemLabelVisible(series, item)) {
            if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false);
            } else if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false);
            }
        }

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

        // add an entity for the item...
        if (entities != null) {
            String tip = null;
            final 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);
            }
            final XYItemEntity entity = new XYItemEntity(circle, dataset, series, item, tip, url);
            entities.add(entity);
        }

        final int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        final int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                orientation);
    }

}

From source file:org.pentaho.platform.uifoundation.chart.BubbleRenderer.java

/**
 * Draws the visual representation of a single data item.
 * //from   ww  w .  j  ava 2  s .c o  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 (horizontal) axis.
 * @param rangeAxis
 *          the range (vertical) axis.
 * @param dataset
 *          the dataset (an {@link XYZDataset} is expected).
 * @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) {

    PlotOrientation orientation = plot.getOrientation();

    // get the data point...
    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double z = Double.NaN;
    if (dataset instanceof XYZDataset) {
        XYZDataset xyzData = (XYZDataset) dataset;
        z = xyzData.getZValue(series, item);
    }
    if (!Double.isNaN(z)) {
        RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
        RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
        double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation);
        double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation);

        double circleSize;

        circleSize = maxSize * (z / maxZ);

        circleSize = Math.abs(circleSize);

        Ellipse2D circle = null;
        if (orientation == PlotOrientation.VERTICAL) {
            circle = new Ellipse2D.Double(transX - circleSize / 2.0, transY - circleSize / 2.0, circleSize,
                    circleSize);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            circle = new Ellipse2D.Double(transY - circleSize / 2.0, transX - circleSize / 2.0, circleSize,
                    circleSize);
        }
        g2.setPaint(getItemPaint(series, item));
        g2.fill(circle);
        g2.setStroke(getItemOutlineStroke(series, item));
        g2.setPaint(getItemOutlinePaint(series, item));
        g2.draw(circle);

        if (isItemLabelVisible(series, item)) {
            if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false);
            } else if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false);
            }
        }

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

        // add an entity for the item...
        if (entities != 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(circle, dataset, series, item, tip, url);
            entities.add(entity);
        }

        int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                orientation);
    }

}

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;/*from   w  w w  .  ja va 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.bdaum.zoom.report.internal.jfree.custom.CylinderRenderer.java

/**
 * Draws a cylinder to represent one data item.
 *
 * @param g2  the graphics device.//from  w  ww .  ja v a 2  s  .  c om
 * @param state  the renderer state.
 * @param dataArea  the area for plotting the data.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // check the value we are plotting...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    double value = dataValue.doubleValue();

    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(),
            dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());

    PlotOrientation orientation = plot.getOrientation();

    double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column);
    double[] barL0L1 = calculateBarL0L1(value);
    if (barL0L1 == null) {
        return; // the bar is not visible
    }

    RectangleEdge edge = plot.getRangeAxisEdge();
    float transL0 = (float) rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
    float transL1 = (float) rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    float barL0 = Math.min(transL0, transL1);
    float barLength = Math.abs(transL1 - transL0);

    // draw the bar...
    GeneralPath bar = new GeneralPath();
    Shape top = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar.moveTo((float) (barL0 + getXOffset() / 2), (float) barW0);
        bar.lineTo((float) (barL0 + barLength + getXOffset() / 2), (float) barW0);
        Arc2D arc = new Arc2D.Double(barL0 + barLength, barW0, getXOffset(), state.getBarWidth(), 90, 180,
                Arc2D.OPEN);
        bar.append(arc, true);
        bar.lineTo((float) (barL0 + getXOffset() / 2), (float) (barW0 + state.getBarWidth()));
        arc = new Arc2D.Double(barL0, barW0, getXOffset(), state.getBarWidth(), 270, -180, Arc2D.OPEN);
        bar.append(arc, true);
        bar.closePath();
        top = new Ellipse2D.Double(barL0 + barLength, barW0, getXOffset(), state.getBarWidth());

    } else {
        bar.moveTo((float) barW0, (float) (barL0 - getYOffset() / 2));
        bar.lineTo((float) barW0, (float) (barL0 + barLength - getYOffset() / 2));
        Arc2D arc = new Arc2D.Double(barW0, (barL0 + barLength - getYOffset()), state.getBarWidth(),
                getYOffset(), 180, 180, Arc2D.OPEN);
        bar.append(arc, true);
        bar.lineTo((float) (barW0 + state.getBarWidth()), (float) (barL0 - getYOffset() / 2));
        arc = new Arc2D.Double(barW0, (barL0 - getYOffset()), state.getBarWidth(), getYOffset(), 0, -180,
                Arc2D.OPEN);
        bar.append(arc, true);
        bar.closePath();

        top = new Ellipse2D.Double(barW0, barL0 - getYOffset(), state.getBarWidth(), getYOffset());
    }
    Paint itemPaint = getItemPaint(row, column);
    if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) itemPaint;
        itemPaint = getGradientPaintTransformer().transform(gp, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    if (itemPaint instanceof GradientPaint) {
        g2.setPaint(((GradientPaint) itemPaint).getColor2());
    } else {
        g2.setPaint(PaintAlpha.darker(itemPaint)); // bd
    }
    if (top != null) {
        g2.fill(top);
    }

    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemOutlineStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
        if (top != null) {
            g2.draw(top);
        }
    }

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

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

}

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

protected void drawTasks(Graphics2D graphics2d, CategoryItemRendererState categoryitemrendererstate,
        Rectangle2D rectangle2d, CategoryPlot categoryplot, CategoryAxis categoryaxis, ValueAxis valueaxis,
        GanttCategoryDataset ganttcategorydataset, int i, int j) {
    int k = ganttcategorydataset.getSubIntervalCount(i, j);
    if (k == 0)/*from  w ww .ja va2 s  .com*/
        drawTask(graphics2d, categoryitemrendererstate, rectangle2d, categoryplot, categoryaxis, valueaxis,
                ganttcategorydataset, i, j);
    for (int l = 0; l < k; l++) {
        org.jfree.ui.RectangleEdge rectangleedge = categoryplot.getRangeAxisEdge();
        Number number = ganttcategorydataset.getStartValue(i, j, l);
        if (number == null)
            return;
        double d = valueaxis.valueToJava2D(number.doubleValue(), rectangle2d, rectangleedge);
        Number number1 = ganttcategorydataset.getEndValue(i, j, l);
        if (number1 == null)
            return;
        double d1 = valueaxis.valueToJava2D(number1.doubleValue(), rectangle2d, rectangleedge);
        if (d1 < d) {
            double d2 = d1;
            d1 = d;
            d = d2;
        }
        double d3 = calculateBarW0(categoryplot, categoryplot.getOrientation(), rectangle2d, categoryaxis,
                categoryitemrendererstate, i, j);
        double d4 = Math.abs(d1 - d);
        double d5 = categoryitemrendererstate.getBarWidth();
        java.awt.geom.Rectangle2D.Double double1 = null;
        if (categoryplot.getOrientation() == PlotOrientation.HORIZONTAL)
            double1 = new java.awt.geom.Rectangle2D.Double(d, d3, d4, d5);
        else if (categoryplot.getOrientation() == PlotOrientation.VERTICAL)
            double1 = new java.awt.geom.Rectangle2D.Double(d3, d, d5, d4);
        java.awt.geom.Rectangle2D.Double double2 = null;
        java.awt.geom.Rectangle2D.Double double3 = null;
        Number number2 = ganttcategorydataset.getPercentComplete(i, j, l);
        double d6 = getStartPercent();
        double d7 = getEndPercent();
        if (number2 != null) {
            double d8 = number2.doubleValue();
            if (categoryplot.getOrientation() == PlotOrientation.HORIZONTAL) {
                double2 = new java.awt.geom.Rectangle2D.Double(d, d3 + d6 * d5, d4 * d8, d5 * (d7 - d6));
                double3 = new java.awt.geom.Rectangle2D.Double(d + d4 * d8, d3 + d6 * d5, d4 * (1.0D - d8),
                        d5 * (d7 - d6));
            } else if (categoryplot.getOrientation() == PlotOrientation.VERTICAL) {
                double2 = new java.awt.geom.Rectangle2D.Double(d3 + d6 * d5, d + d4 * (1.0D - d8),
                        d5 * (d7 - d6), d4 * d8);
                double3 = new java.awt.geom.Rectangle2D.Double(d3 + d6 * d5, d, d5 * (d7 - d6),
                        d4 * (1.0D - d8));
            }
        }
        Paint paint = getItemPaint(i, j);
        graphics2d.setPaint(paint);
        graphics2d.fill(double1);
        if (double2 != null) {
            graphics2d.setPaint(getCompletePaint());
            graphics2d.fill(double2);
        }
        if (double3 != null) {
            graphics2d.setPaint(getIncompletePaint());
            graphics2d.fill(double3);
        }
        if (isDrawBarOutline() && categoryitemrendererstate.getBarWidth() > 3D) {
            graphics2d.setStroke(getItemStroke(i, j));
            graphics2d.setPaint(getItemOutlinePaint(i, j));
            graphics2d.draw(double1);
        }
        if (categoryitemrendererstate.getInfo() == null)
            continue;
        EntityCollection entitycollection = categoryitemrendererstate.getEntityCollection();
        if (entitycollection == null)
            continue;
        String s = null;
        if (getToolTipGenerator(i, j) != null)
            s = getToolTipGenerator(i, j).generateToolTip(ganttcategorydataset, i, j);
        String s1 = null;
        if (getItemURLGenerator(i, j) != null)
            s1 = getItemURLGenerator(i, j).generateURL(ganttcategorydataset, i, j);
        CategoryItemEntity categoryitementity = new CategoryItemEntity(double1, s, s1, ganttcategorydataset,
                ganttcategorydataset.getRowKey(i), ganttcategorydataset.getColumnKey(j));
        entitycollection.add(categoryitementity);
    }

}