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:net.sourceforge.processdash.ui.lib.chart.StandardDiscItemRenderer.java

public void drawItem(Graphics2D g2, DiscItemRendererState state, Rectangle2D dataArea, Ellipse2D discLocation,
        PlotRenderingInfo info, DiscPlot plot, PieDataset dataset, int item) {

    Ellipse2D shape = plot.getDiscDistributor().getDiscLocation(item);
    if (shape == null)
        return;/*from w  w w. j a v  a 2 s .com*/

    Comparable key = dataset.getKey(item);
    Paint discPaint = lookupDiscPaint(key, true);

    drawDisc(g2, shape, discPaint, item);
    drawLabel(g2, plot, dataset, shape, key, discPaint);
    drawOutline(g2, shape, key);

    if (info != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            String tip = null;
            if (plot.getToolTipGenerator() != null) {
                tip = plot.getToolTipGenerator().generateToolTip(dataset, key);
            }
            String url = null;
            if (plot.getUrlGenerator() != null) {
                url = plot.getUrlGenerator().generateURL(dataset, key, item);
            }
            DiscItemEntity entity = new DiscItemEntity(shape, dataset, item, key, tip, url);
            entities.add(entity);
        }
    }

}

From source file:org.ietr.preesm.mapper.ui.MyGanttRenderer.java

/**
 * Draws the tasks/subtasks for one item.
 * //  w ww .j  av  a2 s  .  c o  m
 * @param g2
 *            the graphics device.
 * @param state
 *            the renderer state.
 * @param dataArea
 *            the data plot area.
 * @param plot
 *            the plot.
 * @param domainAxis
 *            the domain axis.
 * @param rangeAxis
 *            the range axis.
 * @param dataset
 *            the data.
 * @param row
 *            the row index (zero-based).
 * @param column
 *            the column index (zero-based).
 */
@Override
protected void drawTasks(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea,
        CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, GanttCategoryDataset dataset, int row,
        int column) {

    int count = dataset.getSubIntervalCount(row, column);
    if (count == 0) {
        drawTask(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column);
    }

    for (int subinterval = 0; subinterval < count; subinterval++) {

        RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();

        // value 0
        Number value0 = dataset.getStartValue(row, column, subinterval);
        if (value0 == null) {
            return;
        }
        double translatedValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation);

        // value 1
        Number value1 = dataset.getEndValue(row, column, subinterval);
        if (value1 == null) {
            return;
        }
        double translatedValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation);

        if (translatedValue1 < translatedValue0) {
            double temp = translatedValue1;
            translatedValue1 = translatedValue0;
            translatedValue0 = temp;
        }

        double rectStart = calculateBarW0(plot, plot.getOrientation(), dataArea, domainAxis, state, row,
                column);
        double rectLength = Math.abs(translatedValue1 - translatedValue0);
        double rectBreadth = state.getBarWidth();

        // DRAW THE BARS...
        RoundRectangle2D bar = null;

        bar = new RoundRectangle2D.Double(translatedValue0, rectStart, rectLength, rectBreadth, 10.0, 10.0);

        /* Paint seriesPaint = */getItemPaint(row, column);

        if (((TaskSeriesCollection) dataset).getSeriesCount() > 0)
            if (((TaskSeriesCollection) dataset).getSeries(0).getItemCount() > column)
                if (((TaskSeriesCollection) dataset).getSeries(0).get(column).getSubtaskCount() > subinterval) {
                    g2.setPaint(getRandomBrightColor(((TaskSeriesCollection) dataset).getSeries(0).get(column)
                            .getSubtask(subinterval).getDescription()));

                }
        g2.fill(bar);

        if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
            g2.setStroke(getItemStroke(row, column));
            g2.setPaint(getItemOutlinePaint(row, column));
            g2.draw(bar);
        }

        // Displaying the tooltip inside the bar if enough space is
        // available
        if (getToolTipGenerator(row, column) != null) {
            // Getting the string to display
            String tip = getToolTipGenerator(row, column).generateToolTip(dataset, subinterval, column);

            // Truncting the string if it is too long
            String subtip = "";
            if (rectLength > 0) {
                double percent = (g2.getFontMetrics().getStringBounds(tip, g2).getWidth() + 10) / rectLength;

                if (percent > 1.0) {
                    subtip = tip.substring(0, (int) (tip.length() / percent));
                } else if (percent > 0) {
                    subtip = tip;
                }

                // Setting font and color
                Font font = new Font("Garamond", Font.BOLD, 12);
                g2.setFont(font);
                g2.setColor(Color.WHITE);

                // Testing width and displaying
                if (!subtip.isEmpty()) {
                    g2.drawString(subtip, (int) translatedValue0 + 5,
                            (int) rectStart + g2.getFontMetrics().getHeight());
                }
            }
        }

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

}

From source file:de.hdm.uls.loadtests.ui.XYLineAndAreaRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.//from  w  w w. java  2s. c o m
 * @param state  the renderer state.
 * @param dataArea  the area within which the data is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color information
 *              etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  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;
    }
    XYAreaRendererState areaState = (XYAreaRendererState) state;

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1)) {
        y1 = 0.0;
    }
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, plot.getDomainAxisEdge());
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge());

    // get the previous point and the next point so we can calculate a
    // "hot spot" for the area (used by the chart entity)...
    int itemCount = dataset.getItemCount(series);
    double x0 = dataset.getXValue(series, Math.max(item - 1, 0));
    double y0 = dataset.getYValue(series, Math.max(item - 1, 0));
    if (Double.isNaN(y0)) {
        y0 = 0.0;
    }
    double transX0 = domainAxis.valueToJava2D(x0, dataArea, plot.getDomainAxisEdge());
    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, plot.getRangeAxisEdge());

    double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1));
    double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1));
    if (Double.isNaN(y2)) {
        y2 = 0.0;
    }
    double transX2 = domainAxis.valueToJava2D(x2, dataArea, plot.getDomainAxisEdge());
    double transY2 = rangeAxis.valueToJava2D(y2, dataArea, plot.getRangeAxisEdge());

    double transZero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge());
    Polygon hotspot = null;
    if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
        hotspot = new Polygon();
        hotspot.addPoint((int) transZero, (int) ((transX0 + transX1) / 2.0));
        hotspot.addPoint((int) ((transY0 + transY1) / 2.0), (int) ((transX0 + transX1) / 2.0));
        hotspot.addPoint((int) transY1, (int) transX1);
        hotspot.addPoint((int) ((transY1 + transY2) / 2.0), (int) ((transX1 + transX2) / 2.0));
        hotspot.addPoint((int) transZero, (int) ((transX1 + transX2) / 2.0));
    } else { // vertical orientation
        hotspot = new Polygon();
        hotspot.addPoint((int) ((transX0 + transX1) / 2.0), (int) transZero);
        hotspot.addPoint((int) ((transX0 + transX1) / 2.0), (int) ((transY0 + transY1) / 2.0));
        hotspot.addPoint((int) transX1, (int) transY1);
        hotspot.addPoint((int) ((transX1 + transX2) / 2.0), (int) ((transY1 + transY2) / 2.0));
        hotspot.addPoint((int) ((transX1 + transX2) / 2.0), (int) transZero);
    }

    if (item == 0) { // create a new area polygon for the series
        areaState.area = new Polygon();
        // the first point is (x, 0)
        double zero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge());
        if (plot.getOrientation() == PlotOrientation.VERTICAL) {
            areaState.area.addPoint((int) transX1, (int) zero);
        } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
            areaState.area.addPoint((int) zero, (int) transX1);
        }
    }

    // Add each point to Area (x, y)
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        areaState.area.addPoint((int) transX1, (int) transY1);
    } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
        areaState.area.addPoint((int) transY1, (int) transX1);
    }

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

    Shape shape = null;
    if (getPlotShapes()) {
        shape = getItemShape(series, item);
        if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        }
        g2.draw(shape);
    }

    if (getPlotLines()) {
        if (item > 0) {
            if (plot.getOrientation() == PlotOrientation.VERTICAL) {
                areaState.line.setLine(transX0, transY0, transX1, transY1);
            } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
                areaState.line.setLine(transY0, transX0, transY1, transX1);
            }
            g2.draw(areaState.line);
        }
    }

    // Check if the item is the last item for the series.
    // and number of items > 0.  We can't draw an area for a single point.
    if (getPlotArea() && item > 0 && item == (itemCount - 1)) {

        if (orientation == PlotOrientation.VERTICAL) {
            // Add the last point (x,0)
            areaState.area.addPoint((int) transX1, (int) transZero);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            // Add the last point (x,0)
            areaState.area.addPoint((int) transZero, (int) transX1);
        }

        Paint fillPaint = getItemFillPaint(series, item);
        if (fillPaint instanceof GradientPaint) {
            GradientPaint gp = (GradientPaint) fillPaint;
            GradientPaintTransformer t = new StandardGradientPaintTransformer();
            fillPaint = t.transform(gp, areaState.area.getBounds());
        }
        g2.setPaint(fillPaint);
        g2.fill(areaState.area);

        // draw an outline around the Area.
        if (isOutline()) {
            g2.setStroke(getItemOutlineStroke(series, item));
            g2.setPaint(getItemOutlinePaint(series, item));
            g2.draw(areaState.area);
        }
    }

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

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null && hotspot != 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(hotspot, dataset, series, item, tip, url);
            entities.add(entity);
        }
    }

}

From source file:com.newatlanta.bluedragon.CustomClusteredXYBarRenderer.java

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

    IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;

    Paint seriesPaint = getItemPaint(series, item);

    double value0;
    double value1;
    if (getUseYInterval()) {
        value0 = intervalDataset.getStartYValue(series, item);
        value1 = intervalDataset.getEndYValue(series, item);
    } else {/*from   w ww  .j a  v a  2 s  .  c o  m*/
        value0 = getBase();
        value1 = intervalDataset.getYValue(series, item);
    }
    if (Double.isNaN(value0) || Double.isNaN(value1)) {
        return;
    }

    double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge());
    double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge());

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    double x1 = intervalDataset.getStartXValue(series, item);
    double translatedX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);

    double x2 = intervalDataset.getEndXValue(series, item);
    double translatedX2 = domainAxis.valueToJava2D(x2, dataArea, xAxisLocation);

    double translatedWidth = Math.max(1, Math.abs(translatedX2 - translatedX1));
    double translatedHeight = Math.abs(translatedValue0 - translatedValue1);

    /*
     * With BlueDragon, this value is always false so it's safe to comment this
     * code out. if (this.centerBarAtStartValue) { translatedX1 -=
     * translatedWidth / 2; }
     */

    PlotOrientation orientation = plot.getOrientation();
    if (getMargin() > 0.0) {
        if (orientation == PlotOrientation.HORIZONTAL) {
            // BEGIN fix for horizontal bar charts that have a margin
            double cut = translatedWidth * getMargin();
            translatedWidth = translatedWidth - cut;
            translatedX1 = translatedX1 - cut / 2;
            // END fix for horizontal bar charts that have a margin
        } else if (orientation == PlotOrientation.VERTICAL) {
            double cut = translatedWidth * getMargin();
            translatedWidth = translatedWidth - cut;
            translatedX1 = translatedX1 + cut / 2;
        }
    }

    int numSeries = dataset.getSeriesCount();
    double seriesBarWidth = translatedWidth / numSeries;

    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(Math.min(translatedValue0, translatedValue1),
                translatedX1 - seriesBarWidth * (numSeries - series), translatedHeight, seriesBarWidth);
    } else if (orientation == PlotOrientation.VERTICAL) {

        bar = new Rectangle2D.Double(translatedX1 + seriesBarWidth * series,
                Math.min(translatedValue0, translatedValue1), seriesBarWidth, translatedHeight);

    }
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (isDrawBarOutline() && Math.abs(translatedX2 - translatedX1) > 3) {
        g2.setStroke(getItemOutlineStroke(series, item));
        g2.setPaint(getItemOutlinePaint(series, item));
        g2.draw(bar);
    }

    // TODO: we need something better for the item labels
    if (isItemLabelVisible(series, item)) {
        // Change parameters passed to this method to call our local version
        drawItemLabel(g2, orientation, dataset, series, item, bar, value1 < 0.0);
    }

    // add an entity for the item...
    if (info != null) {
        EntityCollection entities = info.getOwner().getEntityCollection();
        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(bar, dataset, series, item, tip, url);
            entities.add(entity);
        }
    }

}

From source file:org.pentaho.plugin.jfreereport.reportcharts.backport.XYDotRenderer.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./*w ww. ja v  a  2s. c  om*/
 * @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(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) {

    // get the data point...
    final double x = dataset.getXValue(series, item);
    final double y = dataset.getYValue(series, item);
    final double adjx = (this.dotWidth - 1) / 2.0;
    final double adjy = (this.dotHeight - 1) / 2.0;
    if (!Double.isNaN(y)) {
        final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
        final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
        final double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx;
        final double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy;

        g2.setPaint(getItemPaint(series, item));
        final PlotOrientation orientation = plot.getOrientation();
        final Shape s;
        if (orientation == PlotOrientation.HORIZONTAL) {
            //noinspection SuspiciousNameCombination
            s = new Rectangle2D.Double(transY, transX, this.dotHeight, this.dotWidth);
        } else if (orientation == PlotOrientation.VERTICAL) {
            s = new Rectangle2D.Double(transX, transY, this.dotWidth, this.dotHeight);
        } else {
            throw new IllegalStateException("PlotOrientation is neither Horizontal nor Vertical");
        }
        g2.fill(s);

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

        // collect entity and tool tip information...
        if (state.getInfo() != null) {
            final EntityCollection entities = state.getEntityCollection();
            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(s, dataset, series, item, tip, url);
                entities.add(entity);
            }
        }
    }

}

From source file:diet.gridr.g5k.util.ExtendedStackedBarRenderer.java

/**
 * Draws a stacked bar for a specific item.
 *
 * @param g2  the graphics device./*from   w w w.  j ava  2 s  .co  m*/
 * @param state  the renderer state.
 * @param dataArea  the plot area.
 * @param plot  the plot.
 * @param domainAxis  the domain (category) axis.
 * @param rangeAxis  the range (value) axis.
 * @param dataset  the data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // nothing is drawn for null values...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    double value = dataValue.doubleValue();

    PlotOrientation orientation = plot.getOrientation();
    double barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge())
            - state.getBarWidth() / 2.0;

    double positiveBase = 0.0;
    double negativeBase = 0.0;

    for (int i = 0; i < row; i++) {
        Number v = dataset.getValue(i, column);
        if (v != null) {
            double d = v.doubleValue();
            if (d > 0) {
                positiveBase = positiveBase + d;
            } else {
                negativeBase = negativeBase + d;
            }
        }
    }

    double translatedBase;
    double translatedValue;
    RectangleEdge location = plot.getRangeAxisEdge();
    if (value > 0.0) {
        translatedBase = rangeAxis.valueToJava2D(positiveBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(positiveBase + value, dataArea, location);
    } else {
        translatedBase = rangeAxis.valueToJava2D(negativeBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(negativeBase + value, dataArea, location);
    }
    double barL0 = Math.min(translatedBase, translatedValue);
    double barLength = Math.max(Math.abs(translatedValue - translatedBase), getMinimumBarLength());

    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);
    }
    Paint seriesPaint = getItemPaint(row, column);
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
    }

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

    if (value > 0.0) {
        if (this.showPositiveTotal) {
            if (isLastPositiveItem(dataset, row, column)) {
                g2.setPaint(Color.black);
                g2.setFont(this.totalLabelFont);
                double total = calculateSumOfPositiveValuesForCategory(dataset, column);
                TextUtilities.drawRotatedString(this.totalFormatter.format(total), g2, (float) bar.getCenterX(),
                        (float) (bar.getMinY() - 4.0), TextAnchor.BOTTOM_CENTER, 0.0, TextAnchor.BOTTOM_CENTER);
            }
        }
    } else {
        if (this.showNegativeTotal) {
            if (isLastNegativeItem(dataset, row, column)) {
                g2.setPaint(Color.black);
                g2.setFont(this.totalLabelFont);
                double total = calculateSumOfNegativeValuesForCategory(dataset, column);
                TextUtilities.drawRotatedString(String.valueOf(total), g2, (float) bar.getCenterX(),
                        (float) (bar.getMaxY() + 4.0), TextAnchor.TOP_CENTER, 0.0, TextAnchor.TOP_CENTER);
            }
        }
    }

    // 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, tip, url, dataset, row,
                    dataset.getColumnKey(column), column);
            entities.add(entity);
        }
    }

}

From source file:edu.ucla.stat.SOCR.chart.gui.ExtendedStackedBarRenderer.java

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

    // nothing is drawn for null values...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    double value = dataValue.doubleValue();

    PlotOrientation orientation = plot.getOrientation();
    double barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge())
            - state.getBarWidth() / 2.0;

    double positiveBase = 0.0;
    double negativeBase = 0.0;

    for (int i = 0; i < row; i++) {
        Number v = dataset.getValue(i, column);
        if (v != null) {
            double d = v.doubleValue();
            if (d > 0) {
                positiveBase = positiveBase + d;
            } else {
                negativeBase = negativeBase + d;
            }
        }
    }

    double translatedBase;
    double translatedValue;
    RectangleEdge location = plot.getRangeAxisEdge();
    if (value > 0.0) {
        translatedBase = rangeAxis.valueToJava2D(positiveBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(positiveBase + value, dataArea, location);
    } else {
        translatedBase = rangeAxis.valueToJava2D(negativeBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(negativeBase + value, dataArea, location);
    }
    double barL0 = Math.min(translatedBase, translatedValue);
    double barLength = Math.max(Math.abs(translatedValue - translatedBase), getMinimumBarLength());

    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);
    }
    Paint seriesPaint = getItemPaint(row, column);
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
    }

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

    if (value > 0.0) {
        if (this.showPositiveTotal) {
            if (isLastPositiveItem(dataset, row, column)) {
                g2.setPaint(Color.black);
                g2.setFont(this.totalLabelFont);
                double total = calculateSumOfPositiveValuesForCategory(dataset, column);
                if (orientation == PlotOrientation.HORIZONTAL)
                    TextUtilities.drawRotatedString(this.totalFormatter.format(total), g2,
                            (float) (bar.getMaxX() + 5.0), (float) bar.getCenterY(), TextAnchor.CENTER_LEFT,
                            0.0, TextAnchor.CENTER_LEFT);

                else
                    TextUtilities.drawRotatedString(this.totalFormatter.format(total), g2,
                            (float) bar.getCenterX(), (float) (bar.getMinY() - 4.0), TextAnchor.BOTTOM_CENTER,
                            0.0, TextAnchor.BOTTOM_CENTER);
            }
        }
    } else {
        if (this.showNegativeTotal) {
            if (isLastNegativeItem(dataset, row, column)) {
                g2.setPaint(Color.black);
                g2.setFont(this.totalLabelFont);
                double total = calculateSumOfNegativeValuesForCategory(dataset, column);
                if (orientation == PlotOrientation.HORIZONTAL)
                    TextUtilities.drawRotatedString(String.valueOf(total), g2, (float) (bar.getMinX() - 5.0),
                            (float) bar.getCenterY(), TextAnchor.CENTER_RIGHT, 0.0, TextAnchor.CENTER_RIGHT);
                else
                    TextUtilities.drawRotatedString(String.valueOf(total), g2, (float) bar.getCenterX(),
                            (float) (bar.getMaxY() + 4.0), TextAnchor.TOP_CENTER, 0.0, TextAnchor.TOP_CENTER);
            }
        }
    }

    // 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, tip, url, dataset, dataset.getRowKey(row),
                    dataset.getColumnKey(column));
            entities.add(entity);
        }
    }

}

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

/**
 * Draws a single interval.//from w w w  .  ja v a  2  s.c om
 * 
 * @param g2
 *          the graphics device.
 * @param state
 *          the renderer state.
 * @param dataArea
 *          the data plot area.
 * @param plot
 *          the plot.
 * @param domainAxis
 *          the domain axis.
 * @param rangeAxis
 *          the range axis.
 * @param dataset
 *          the data.
 * @param row
 *          the row index (zero-based).
 * @param column
 *          the column index (zero-based).
 */
protected void drawInterval(final Graphics2D g2, final CategoryItemRendererState state,
        final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis,
        final ValueAxis rangeAxis, final DefaultIntervalListCategoryDataset dataset, final int row,
        final int column) {

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

    final PlotOrientation orientation = plot.getOrientation();

    double rectX = 0.0;
    double rectY = 0.0;

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

    final List list = dataset.getList(row, column);

    if (list == null) {
        return;
    }

    Interval interval = null;
    for (int i = 0; i < list.size(); i++) {

        interval = (Interval) list.get(i);

        if (!interval.isMeaningful()) {
            continue;
        }

        // Y0
        double java2dValue0 = rangeAxis.valueToJava2D(interval.low, dataArea, rangeAxisLocation);

        // Y1
        double java2dValue1 = rangeAxis.valueToJava2D(interval.high, dataArea, rangeAxisLocation);

        if (java2dValue1 < java2dValue0) {
            final double temp = java2dValue1;
            java2dValue1 = java2dValue0;
            java2dValue0 = temp;
        }

        // BAR WIDTH
        double rectWidth = state.getBarWidth();

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

        if (orientation == PlotOrientation.HORIZONTAL) {
            // BAR Y
            rectY = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation);
            if (seriesCount > 1) {
                final double seriesGap = dataArea.getHeight() * getItemMargin()
                        / (categoryCount * (seriesCount - 1));
                rectY = rectY + row * (state.getBarWidth() + seriesGap);
            } else {
                rectY = rectY + row * state.getBarWidth();
            }

            rectX = java2dValue0;

            rectHeight = state.getBarWidth();
            rectWidth = Math.abs(java2dValue1 - java2dValue0);

        } else if (orientation == PlotOrientation.VERTICAL) {
            // BAR X
            rectX = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation);

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

            rectY = java2dValue0;

        }
        final Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
        final Paint seriesPaint = getItemPaint(row, column);
        g2.setPaint(seriesPaint);
        g2.fill(bar);

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

        final CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
        if ((generator != null) && isItemLabelVisible(row, column)) {
            drawItemLabel(g2, dataset, row, column, plot, generator, bar, false);
        }

        // collect entity and tool tip information...
        if (state.getInfo() != null) {
            final EntityCollection entities = state.getInfo().getOwner().getEntityCollection();
            if (entities != 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(bar, tip, url, dataset,
                        dataset.getRowKey(row), dataset.getColumnKey(column));
                entities.add(entity);
            }
        }
    }
}

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

protected void drawTask(Graphics2D graphics2d, CategoryItemRendererState categoryitemrendererstate,
        Rectangle2D rectangle2d, CategoryPlot categoryplot, CategoryAxis categoryaxis, ValueAxis valueaxis,
        GanttCategoryDataset ganttcategorydataset, int i, int j) {
    PlotOrientation plotorientation = categoryplot.getOrientation();
    org.jfree.ui.RectangleEdge rectangleedge = categoryplot.getRangeAxisEdge();
    Number number = ganttcategorydataset.getEndValue(i, j);
    if (number == null)
        return;//from  w w w  .jav  a2s.  c om
    double d = valueaxis.valueToJava2D(number.doubleValue(), rectangle2d, rectangleedge);
    Number number1 = ganttcategorydataset.getStartValue(i, j);
    if (number1 == null)
        return;
    double d1 = valueaxis.valueToJava2D(number1.doubleValue(), rectangle2d, rectangleedge);
    if (d1 < d) {
        double d2 = d1;
        d1 = d;
        d = d2;
        Number number2 = number1;
        number1 = number;
        number = number2;
    }
    int k = countNonNullValues(ganttcategorydataset, j);
    if (k == 0)
        return;
    int l = countPriorNonNullValues(ganttcategorydataset, j, i);
    double d3 = (categoryaxis.getCategoryEnd(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge())
            - categoryaxis.getCategoryStart(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge()))
            / (double) k;
    double d4 = categoryaxis.getCategoryStart(j, getColumnCount(), rectangle2d,
            categoryplot.getDomainAxisEdge()) + d3 * (double) l;
    double d5 = Math.abs(d1 - d);
    java.awt.geom.Rectangle2D.Double double1 = null;
    if (plotorientation == PlotOrientation.HORIZONTAL)
        double1 = new java.awt.geom.Rectangle2D.Double(d, d4, d5, d3);
    else if (plotorientation == PlotOrientation.VERTICAL)
        double1 = new java.awt.geom.Rectangle2D.Double(d4, d1, d3, d5);
    java.awt.geom.Rectangle2D.Double double2 = null;
    java.awt.geom.Rectangle2D.Double double3 = null;
    Number number3 = ganttcategorydataset.getPercentComplete(i, j);
    double d6 = getStartPercent();
    double d7 = getEndPercent();
    if (number3 != null) {
        double d8 = number3.doubleValue();
        if (categoryplot.getOrientation() == PlotOrientation.HORIZONTAL) {
            double2 = new java.awt.geom.Rectangle2D.Double(d, d4 + d6 * d3, d5 * d8, d3 * (d7 - d6));
            double3 = new java.awt.geom.Rectangle2D.Double(d + d5 * d8, d4 + d6 * d3, d5 * (1.0D - d8),
                    d3 * (d7 - d6));
        } else if (categoryplot.getOrientation() == PlotOrientation.VERTICAL) {
            double2 = new java.awt.geom.Rectangle2D.Double(d4 + d6 * d3, d1 + d5 * (1.0D - d8), d3 * (d7 - d6),
                    d5 * d8);
            double3 = new java.awt.geom.Rectangle2D.Double(d4 + d6 * d3, d1, d3 * (d7 - d6), d5 * (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) {
        java.awt.Stroke stroke = getItemOutlineStroke(i, j);
        Paint paint1 = getItemOutlinePaint(i, j);
        if (stroke != null && paint1 != null) {
            graphics2d.setStroke(stroke);
            graphics2d.setPaint(paint1);
            graphics2d.draw(double1);
        }
    }
    org.jfree.chart.labels.CategoryItemLabelGenerator categoryitemlabelgenerator = getItemLabelGenerator(i, j);
    if (categoryitemlabelgenerator != null && isItemLabelVisible(i, j))
        drawItemLabel(graphics2d, ganttcategorydataset, i, j, categoryplot, categoryitemlabelgenerator, double1,
                false);
    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(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);
        }
    }
}

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

/**
 * Draw a single data item./* w w w.  ja va  2 s . c  o 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);

        }

    }

}