Search in sources :

Example 96 with RectangleEdge

use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.

the class LayeredBarRenderer method drawVerticalItem.

/**
 * 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 drawVerticalItem(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;
    }
    // BAR X
    double rectX = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - state.getBarWidth() / 2.0;
    int seriesCount = getRowCount();
    // BAR Y
    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 = getLowerClip();
        if (value >= uclip) {
            value = uclip;
        }
    }
    RectangleEdge edge = plot.getRangeAxisEdge();
    double transY1 = rangeAxis.valueToJava2D(base, dataArea, edge);
    double transY2 = rangeAxis.valueToJava2D(value, dataArea, edge);
    double rectY = Math.min(transY2, transY1);
    double rectWidth;
    double rectHeight = Math.abs(transY2 - transY1);
    // draw the bar...
    double shift = 0.0;
    double widthFactor = 1.0;
    double seriesBarWidth = getSeriesBarWidth(row);
    if (!Double.isNaN(seriesBarWidth)) {
        widthFactor = seriesBarWidth;
    }
    rectWidth = widthFactor * state.getBarWidth();
    rectX = rectX + (1 - widthFactor) * state.getBarWidth() / 2.0;
    if (seriesCount > 1) {
        // needs to be improved !!!
        shift = rectWidth * 0.20 / (seriesCount - 1);
    }
    Rectangle2D bar = new Rectangle2D.Double((rectX + ((seriesCount - 1 - row) * shift)), rectY, (rectWidth - (seriesCount - 1 - row) * shift * 2), rectHeight);
    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);
        }
    }
    // draw the item labels if there are any...
    double transX1 = rangeAxis.valueToJava2D(base, dataArea, edge);
    double transX2 = rangeAxis.valueToJava2D(value, dataArea, edge);
    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 97 with RectangleEdge

use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.

the class IntervalBarRenderer method drawInterval.

/**
 * Draws a single interval.
 *
 * @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(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, IntervalCategoryDataset dataset, int row, int column) {
    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    PlotOrientation orientation = plot.getOrientation();
    double rectX = 0.0;
    double rectY = 0.0;
    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;
    }
    // BAR WIDTH
    double rectWidth = state.getBarWidth();
    // BAR HEIGHT
    double rectHeight = Math.abs(java2dValue1 - java2dValue0);
    RectangleEdge barBase = RectangleEdge.LEFT;
    if (orientation == PlotOrientation.HORIZONTAL) {
        // BAR Y
        rectX = java2dValue0;
        rectY = calculateBarW0(getPlot(), orientation, dataArea, domainAxis, state, visibleRow, column);
        rectHeight = state.getBarWidth();
        rectWidth = Math.abs(java2dValue1 - java2dValue0);
        barBase = RectangleEdge.LEFT;
    } else if (orientation == PlotOrientation.VERTICAL) {
        // BAR X
        rectX = calculateBarW0(getPlot(), orientation, dataArea, domainAxis, state, visibleRow, column);
        rectY = java2dValue0;
        barBase = RectangleEdge.BOTTOM;
    }
    Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
    BarPainter painter = getBarPainter();
    if (getShadowsVisible()) {
        painter.paintBarShadow(g2, this, row, column, bar, barBase, false);
    }
    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, false);
    }
    // add an item entity, if this information is being collected
    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 98 with RectangleEdge

use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.

the class LogarithmicAxisTest method testJava2DToValue.

/**
 * Test of java2DToValue method.
 */
@Test
public void testJava2DToValue() {
    Rectangle2D plotArea = new Rectangle2D.Double(22, 33, 500, 500);
    RectangleEdge edge = RectangleEdge.BOTTOM;
    // set axis bounds to be both greater than 1
    this.axis.setRange(10, 20);
    checkPointsToValue(edge, plotArea);
    // check for bounds interval that includes 1
    this.axis.setRange(0.5, 10);
    checkPointsToValue(edge, plotArea);
    // check for bounds interval that includes 1
    this.axis.setRange(0.2, 20);
    checkPointsToValue(edge, plotArea);
    // check for both bounds smaller than 1
    this.axis.setRange(0.2, 0.7);
    checkPointsToValue(edge, plotArea);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) RectangleEdge(org.jfree.ui.RectangleEdge) Test(org.junit.Test)

Aggregations

RectangleEdge (org.jfree.ui.RectangleEdge)98 Rectangle2D (java.awt.geom.Rectangle2D)52 PlotOrientation (org.jfree.chart.plot.PlotOrientation)49 Paint (java.awt.Paint)48 EntityCollection (org.jfree.chart.entity.EntityCollection)40 Stroke (java.awt.Stroke)23 Shape (java.awt.Shape)19 Line2D (java.awt.geom.Line2D)18 ValueAxis (org.jfree.chart.axis.ValueAxis)16 AxisSpace (org.jfree.chart.axis.AxisSpace)15 CategoryItemLabelGenerator (org.jfree.chart.labels.CategoryItemLabelGenerator)13 Point2D (java.awt.geom.Point2D)11 GeneralPath (java.awt.geom.GeneralPath)9 GradientPaint (java.awt.GradientPaint)8 Ellipse2D (java.awt.geom.Ellipse2D)7 IntervalXYDataset (org.jfree.data.xy.IntervalXYDataset)7 RectangleInsets (org.jfree.ui.RectangleInsets)7 BasicStroke (java.awt.BasicStroke)6 AxisState (org.jfree.chart.axis.AxisState)6 CrosshairState (org.jfree.chart.plot.CrosshairState)5