Search in sources :

Example 1 with CategoryItemLabelGenerator

use of org.jfree.chart.labels.CategoryItemLabelGenerator in project tdq-studio-se by Talend.

the class HideSeriesGanttRenderer method drawTask.

/**
 * Draws a single task.
 *
 * @param g2 the graphics device.
 * @param state the renderer state.
 * @param dataArea the data plot area.
 * @param plot the plot.
 * @param domainAxis the domain axis.
 * @param rangeAxis the range axis.
 * @param dataset the data.
 * @param row the row index (zero-based).
 * @param column the column index (zero-based).
 */
protected void drawTask(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, GanttCategoryDataset dataset, int row, int column) {
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
    // Y0
    Number value0 = dataset.getEndValue(row, column);
    if (value0 == null) {
        return;
    }
    double java2dValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation);
    // Y1
    Number value1 = dataset.getStartValue(row, column);
    if (value1 == null) {
        return;
    }
    double java2dValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation);
    if (java2dValue1 < java2dValue0) {
        double temp = java2dValue1;
        java2dValue1 = java2dValue0;
        java2dValue0 = temp;
        Number tempNum = value1;
        value1 = value0;
        value0 = tempNum;
    }
    // count the number of non-null values
    int totalBars = countNonNullValues(dataset, column);
    if (totalBars == 0) {
        return;
    }
    // count non-null values up to but not including the current value
    int priorBars = countPriorNonNullValues(dataset, column, row);
    // double rectStart = calculateBarW0(plot, orientation, dataArea,
    // domainAxis, state, row, column);
    // double rectBreadth = state.getBarWidth();
    double rectBreadth = (domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge())) / totalBars;
    double rectStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) + rectBreadth * priorBars;
    double rectLength = Math.abs(java2dValue1 - java2dValue0);
    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(java2dValue0, rectStart, rectLength, rectBreadth);
    } else if (orientation == PlotOrientation.VERTICAL) {
        bar = new Rectangle2D.Double(rectStart, java2dValue1, rectBreadth, rectLength);
    }
    Rectangle2D completeBar = null;
    Rectangle2D incompleteBar = null;
    Number percent = dataset.getPercentComplete(row, column);
    double start = getStartPercent();
    double end = getEndPercent();
    if (percent != null) {
        double p = percent.doubleValue();
        if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
            completeBar = new Rectangle2D.Double(java2dValue0, rectStart + start * rectBreadth, rectLength * p, rectBreadth * (end - start));
            incompleteBar = new Rectangle2D.Double(java2dValue0 + rectLength * p, rectStart + start * rectBreadth, rectLength * (1 - p), rectBreadth * (end - start));
        } else if (plot.getOrientation() == PlotOrientation.VERTICAL) {
            completeBar = new Rectangle2D.Double(rectStart + start * rectBreadth, java2dValue1 + rectLength * (1 - p), rectBreadth * (end - start), rectLength * p);
            incompleteBar = new Rectangle2D.Double(rectStart + start * rectBreadth, java2dValue1, rectBreadth * (end - start), rectLength * (1 - p));
        }
    }
    Paint seriesPaint = getItemPaint(row, column);
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (completeBar != null) {
        g2.setPaint(getCompletePaint());
        g2.fill(completeBar);
    }
    if (incompleteBar != null) {
        g2.setPaint(getIncompletePaint());
        g2.fill(incompleteBar);
    }
    // draw the outline...
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        Stroke stroke = getItemOutlineStroke(row, column);
        Paint paint = getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }
    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) {
        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);
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Stroke(java.awt.Stroke) Rectangle2D(java.awt.geom.Rectangle2D) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) Paint(java.awt.Paint) Paint(java.awt.Paint) EntityCollection(org.jfree.chart.entity.EntityCollection) CategoryToolTipGenerator(org.jfree.chart.labels.CategoryToolTipGenerator) CategoryItemEntity(org.jfree.chart.entity.CategoryItemEntity) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 2 with CategoryItemLabelGenerator

use of org.jfree.chart.labels.CategoryItemLabelGenerator in project SIMVA-SoS by SESoS.

the class GroupedStackedBarRenderer method drawItem.

/**
 * Draws a stacked bar for a specific item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the plot area.
 * @param plot  the plot.
 * @param domainAxis  the domain (category) axis.
 * @param rangeAxis  the range (value) axis.
 * @param dataset  the data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset 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();
    Comparable group = this.seriesToGroupMap.getGroup(dataset.getRowKey(row));
    PlotOrientation orientation = plot.getOrientation();
    double barW0 = calculateBarW0(plot, orientation, dataArea, domainAxis, state, row, column);
    double positiveBase = 0.0;
    double negativeBase = 0.0;
    for (int i = 0; i < row; i++) {
        if (group.equals(this.seriesToGroupMap.getGroup(dataset.getRowKey(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;
    boolean positive = (value > 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;
        }
    }
    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;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);
    }
    getBarPainter().paintBar(g2, this, row, column, bar, barBase);
    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }
    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            addItemEntity(entities, dataset, row, column, bar);
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) EntityCollection(org.jfree.chart.entity.EntityCollection) Rectangle2D(java.awt.geom.Rectangle2D) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 3 with CategoryItemLabelGenerator

use of org.jfree.chart.labels.CategoryItemLabelGenerator in project SIMVA-SoS by SESoS.

the class LayeredBarRenderer method drawHorizontalItem.

/**
 * Draws the bar for a single (series, category) data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data area.
 * @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).
 */
protected void drawHorizontalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) {
    // nothing is drawn for null values...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }
    // X
    double value = dataValue.doubleValue();
    double base = 0.0;
    double lclip = getLowerClip();
    double uclip = getUpperClip();
    if (uclip <= 0.0) {
        // cases 1, 2, 3 and 4
        if (value >= uclip) {
            // bar is not visible
            return;
        }
        base = uclip;
        if (value <= lclip) {
            value = lclip;
        }
    } else if (lclip <= 0.0) {
        // cases 5, 6, 7 and 8
        if (value >= uclip) {
            value = uclip;
        } else {
            if (value <= lclip) {
                value = lclip;
            }
        }
    } else {
        // cases 9, 10, 11 and 12
        if (value <= lclip) {
            // bar is not visible
            return;
        }
        base = lclip;
        if (value >= uclip) {
            value = uclip;
        }
    }
    RectangleEdge edge = plot.getRangeAxisEdge();
    double transX1 = rangeAxis.valueToJava2D(base, dataArea, edge);
    double transX2 = rangeAxis.valueToJava2D(value, dataArea, edge);
    double rectX = Math.min(transX1, transX2);
    double rectWidth = Math.abs(transX2 - transX1);
    // Y
    double rectY = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - state.getBarWidth() / 2.0;
    int seriesCount = getRowCount();
    // draw the bar...
    double shift = 0.0;
    double rectHeight;
    double widthFactor = 1.0;
    double seriesBarWidth = getSeriesBarWidth(row);
    if (!Double.isNaN(seriesBarWidth)) {
        widthFactor = seriesBarWidth;
    }
    rectHeight = widthFactor * state.getBarWidth();
    rectY = rectY + (1 - widthFactor) * state.getBarWidth() / 2.0;
    if (seriesCount > 1) {
        shift = rectHeight * 0.20 / (seriesCount - 1);
    }
    Rectangle2D bar = new Rectangle2D.Double(rectX, (rectY + ((seriesCount - 1 - row) * shift)), rectWidth, (rectHeight - (seriesCount - 1 - row) * shift * 2));
    Paint itemPaint = getItemPaint(row, column);
    GradientPaintTransformer t = getGradientPaintTransformer();
    if (t != null && itemPaint instanceof GradientPaint) {
        itemPaint = t.transform((GradientPaint) itemPaint, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);
    // draw the outline...
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        Stroke stroke = getItemOutlineStroke(row, column);
        Paint paint = getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }
    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (transX1 > transX2));
    }
    // collect entity and tool tip information...
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, bar);
    }
}
Also used : Stroke(java.awt.Stroke) GradientPaintTransformer(org.jfree.ui.GradientPaintTransformer) EntityCollection(org.jfree.chart.entity.EntityCollection) Rectangle2D(java.awt.geom.Rectangle2D) GradientPaint(java.awt.GradientPaint) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 4 with CategoryItemLabelGenerator

use of org.jfree.chart.labels.CategoryItemLabelGenerator in project SIMVA-SoS by SESoS.

the class LevelRenderer method drawItem.

/**
 * Draws the bar for a single (series, category) data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data area.
 * @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.
 */
@Override
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 if the row index is not included in the list with
    // the indices of the visible rows...
    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    // 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 = calculateBarW0(plot, orientation, dataArea, domainAxis, state, visibleRow, column);
    RectangleEdge edge = plot.getRangeAxisEdge();
    double barL = rangeAxis.valueToJava2D(value, dataArea, edge);
    // draw the bar...
    Line2D line;
    double x, y;
    if (orientation == PlotOrientation.HORIZONTAL) {
        x = barL;
        y = barW0 + state.getBarWidth() / 2.0;
        line = new Line2D.Double(barL, barW0, barL, barW0 + state.getBarWidth());
    } else {
        x = barW0 + state.getBarWidth() / 2.0;
        y = barL;
        line = new Line2D.Double(barW0, barL, barW0 + state.getBarWidth(), barL);
    }
    Stroke itemStroke = getItemStroke(row, column);
    Paint itemPaint = getItemPaint(row, column);
    g2.setStroke(itemStroke);
    g2.setPaint(itemPaint);
    g2.draw(line);
    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, orientation, dataset, row, column, x, y, (value < 0.0));
    }
    // submit the current data point as a crosshair candidate
    int datasetIndex = plot.indexOf(dataset);
    updateCrosshairValues(state.getCrosshairState(), dataset.getRowKey(row), dataset.getColumnKey(column), value, datasetIndex, barW0, barL, orientation);
    // collect entity and tool tip information...
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, line.getBounds());
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Stroke(java.awt.Stroke) EntityCollection(org.jfree.chart.entity.EntityCollection) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 5 with CategoryItemLabelGenerator

use of org.jfree.chart.labels.CategoryItemLabelGenerator in project SIMVA-SoS by SESoS.

the class StackedBarRenderer3D method drawStackHorizontal.

/**
 * Draws a stack of bars for one category, with a horizontal orientation.
 *
 * @param values  the value list.
 * @param category  the category.
 * @param g2  the graphics device.
 * @param state  the state.
 * @param dataArea  the data area (adjusted for the 3D effect).
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 *
 * @since 1.0.4
 */
protected void drawStackHorizontal(List values, Comparable category, Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset) {
    int column = dataset.getColumnIndex(category);
    double barX0 = domainAxis.getCategoryMiddle(column, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()) - state.getBarWidth() / 2.0;
    double barW = state.getBarWidth();
    // a list to store the series index and bar region, so we can draw
    // all the labels at the end...
    List itemLabelList = new ArrayList();
    // draw the blocks
    boolean inverted = rangeAxis.isInverted();
    int blockCount = values.size() - 1;
    for (int k = 0; k < blockCount; k++) {
        int index = (inverted ? blockCount - k - 1 : k);
        Object[] prev = (Object[]) values.get(index);
        Object[] curr = (Object[]) values.get(index + 1);
        int series;
        if (curr[0] == null) {
            series = -((Integer) prev[0]).intValue() - 1;
        } else {
            series = ((Integer) curr[0]).intValue();
            if (series < 0) {
                series = -((Integer) prev[0]).intValue() - 1;
            }
        }
        double v0 = ((Double) prev[1]).doubleValue();
        double vv0 = rangeAxis.valueToJava2D(v0, dataArea, plot.getRangeAxisEdge());
        double v1 = ((Double) curr[1]).doubleValue();
        double vv1 = rangeAxis.valueToJava2D(v1, dataArea, plot.getRangeAxisEdge());
        Shape[] faces = createHorizontalBlock(barX0, barW, vv0, vv1, inverted);
        Paint fillPaint = getItemPaint(series, column);
        Paint fillPaintDark = PaintAlpha.darker(fillPaint);
        boolean drawOutlines = isDrawBarOutline();
        Paint outlinePaint = fillPaint;
        if (drawOutlines) {
            outlinePaint = getItemOutlinePaint(series, column);
            g2.setStroke(getItemOutlineStroke(series, column));
        }
        for (int f = 0; f < 6; f++) {
            if (f == 5) {
                g2.setPaint(fillPaint);
            } else {
                g2.setPaint(fillPaintDark);
            }
            g2.fill(faces[f]);
            if (drawOutlines) {
                g2.setPaint(outlinePaint);
                g2.draw(faces[f]);
            }
        }
        itemLabelList.add(new Object[] { new Integer(series), faces[5].getBounds2D(), BooleanUtilities.valueOf(v0 < getBase()) });
        // add an item entity, if this information is being collected
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            addItemEntity(entities, dataset, series, column, faces[5]);
        }
    }
    for (int i = 0; i < itemLabelList.size(); i++) {
        Object[] record = (Object[]) itemLabelList.get(i);
        int series = ((Integer) record[0]).intValue();
        Rectangle2D bar = (Rectangle2D) record[1];
        boolean neg = ((Boolean) record[2]).booleanValue();
        CategoryItemLabelGenerator generator = getItemLabelGenerator(series, column);
        if (generator != null && isItemLabelVisible(series, column)) {
            drawItemLabel(g2, dataset, series, column, plot, generator, bar, neg);
        }
    }
}
Also used : Shape(java.awt.Shape) ArrayList(java.util.ArrayList) Rectangle2D(java.awt.geom.Rectangle2D) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) Paint(java.awt.Paint) Paint(java.awt.Paint) EntityCollection(org.jfree.chart.entity.EntityCollection) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

CategoryItemLabelGenerator (org.jfree.chart.labels.CategoryItemLabelGenerator)17 EntityCollection (org.jfree.chart.entity.EntityCollection)15 Paint (java.awt.Paint)14 Rectangle2D (java.awt.geom.Rectangle2D)14 RectangleEdge (org.jfree.ui.RectangleEdge)13 PlotOrientation (org.jfree.chart.plot.PlotOrientation)9 Stroke (java.awt.Stroke)8 GradientPaint (java.awt.GradientPaint)6 GradientPaintTransformer (org.jfree.ui.GradientPaintTransformer)4 Line2D (java.awt.geom.Line2D)3 BasicStroke (java.awt.BasicStroke)2 Shape (java.awt.Shape)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Color (java.awt.Color)1 Font (java.awt.Font)1 GeneralPath (java.awt.geom.GeneralPath)1 Point2D (java.awt.geom.Point2D)1 DecimalFormat (java.text.DecimalFormat)1 CategoryItemEntity (org.jfree.chart.entity.CategoryItemEntity)1