Search in sources :

Example 51 with RectangleEdge

use of org.jfree.ui.RectangleEdge in project mafscaling by vimsh.

the class XYDomainMutilineAnnotation method draw.

public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
    if (labels.size() == 0)
        return;
    if (info == null)
        return;
    EntityCollection entities = info.getOwner().getEntityCollection();
    if (entities == null)
        return;
    int index = plot.getDomainAxisIndex(domainAxis);
    if (index < 0)
        return;
    RectangleEdge axisEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(index), plot.getOrientation());
    double value = domainAxis.valueToJava2D(this.value, dataArea, axisEdge);
    Line2D line = null;
    if (axisEdge.equals(RectangleEdge.LEFT))
        line = new Line2D.Double(dataArea.getMinX(), value, dataArea.getMaxX(), value);
    else if (axisEdge.equals(RectangleEdge.RIGHT))
        line = new Line2D.Double(dataArea.getMaxX(), value, dataArea.getMinX(), value);
    else if (axisEdge.equals(RectangleEdge.TOP))
        line = new Line2D.Double(value, dataArea.getMinY(), value, dataArea.getMaxY());
    else if (axisEdge.equals(RectangleEdge.BOTTOM))
        line = new Line2D.Double(value, dataArea.getMaxY(), value, dataArea.getMinY());
    if (line == null)
        return;
    g2.setPaint(paint);
    g2.setStroke(stroke);
    g2.draw(line);
    drawLabels(g2, dataArea, line.getBounds2D(), axisEdge);
    AxisAnnotationEntity entity = new AxisAnnotationEntity(ShapeUtilities.createLineRegion(line, 6), rendererIndex, this);
    entities.add(entity);
}
Also used : EntityCollection(org.jfree.chart.entity.EntityCollection) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 52 with RectangleEdge

use of org.jfree.ui.RectangleEdge in project ma-core-public by infiniteautomation.

the class XYSmoothLineAndShapeRenderer method drawPrimaryLine.

protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) {
    if (item == 0) {
        return;
    }
    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }
    double x0 = dataset.getXValue(series, item - 1);
    double y0 = dataset.getYValue(series, item - 1);
    if (Double.isNaN(y0) || Double.isNaN(x0)) {
        return;
    }
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
    // only draw if we have good values
    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) {
        return;
    }
    Point2D.Double point0 = new Point2D.Double();
    Point2D.Double point1 = new Point2D.Double();
    Point2D.Double point2 = new Point2D.Double();
    Point2D.Double point3 = new Point2D.Double();
    if (item == 1) {
        point0 = null;
    } else {
        point0.x = domainAxis.valueToJava2D(dataset.getXValue(series, item - 2), dataArea, xAxisLocation);
        point0.y = rangeAxis.valueToJava2D(dataset.getYValue(series, item - 2), dataArea, yAxisLocation);
    }
    point1.x = transX0;
    point1.y = transY0;
    point2.x = transX1;
    point2.y = transY1;
    if ((item + 1) == dataset.getItemCount(series)) {
        point3 = null;
    } else {
        point3.x = domainAxis.valueToJava2D(dataset.getXValue(series, item + 1), dataArea, xAxisLocation);
        point3.y = rangeAxis.valueToJava2D(dataset.getYValue(series, item + 1), dataArea, yAxisLocation);
    }
    int steps = ((int) ((point2.x - point1.x) / 0.2) < 30) ? (int) ((point2.x - point1.x) / 0.2) : 30;
    Point2D.Double[] points = getBezierCurve(point0, point1, point2, point3, 1, steps);
    for (int i = 1; i < points.length; i++) {
        transX0 = points[i - 1].x;
        transY0 = points[i - 1].y;
        transX1 = points[i].x;
        transY1 = points[i].y;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            state.workingLine.setLine(transY0, transX0, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            state.workingLine.setLine(transX0, transY0, transX1, transY1);
        }
        if (state.workingLine.intersects(dataArea)) {
            drawFirstPassShape(g2, pass, series, item, state.workingLine);
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Point2D(java.awt.geom.Point2D) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 53 with RectangleEdge

use of org.jfree.ui.RectangleEdge in project hudson-2.x by hudson.

the class StackedAreaRenderer2 method drawItem.

// Mostly copied from the base class.
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {
    // plot non-null values...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }
    double value = dataValue.doubleValue();
    // leave the y values (y1, y0) untranslated as it is going to be be
    // stacked up later by previous series values, after this it will be
    // translated.
    double xx1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    double previousHeightx1 = getPreviousHeight(dataset, row, column);
    double y1 = value + previousHeightx1;
    RectangleEdge location = plot.getRangeAxisEdge();
    double yy1 = rangeAxis.valueToJava2D(y1, dataArea, location);
    g2.setPaint(getItemPaint(row, column));
    g2.setStroke(getItemStroke(row, column));
    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    // and this is done in the second pass...
    if (column == 0) {
        if (pass == 1) {
            // draw item labels, if visible
            if (isItemLabelVisible(row, column)) {
                drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, yy1, (y1 < 0.0));
            }
        }
    } else {
        Number previousValue = dataset.getValue(row, column - 1);
        if (previousValue != null) {
            double xx0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea, plot.getDomainAxisEdge());
            double y0 = previousValue.doubleValue();
            // Get the previous height, but this will be different for both
            // y0 and y1 as the previous series values could differ.
            double previousHeightx0 = getPreviousHeight(dataset, row, column - 1);
            // Now stack the current y values on top of the previous values.
            y0 += previousHeightx0;
            // Now translate the previous heights
            double previousHeightxx0 = rangeAxis.valueToJava2D(previousHeightx0, dataArea, location);
            double previousHeightxx1 = rangeAxis.valueToJava2D(previousHeightx1, dataArea, location);
            // Now translate the current y values.
            double yy0 = rangeAxis.valueToJava2D(y0, dataArea, location);
            if (pass == 0) {
                // left half
                Polygon p = new Polygon();
                p.addPoint((int) xx0, (int) yy0);
                p.addPoint((int) (xx0 + xx1) / 2, (int) (yy0 + yy1) / 2);
                p.addPoint((int) (xx0 + xx1) / 2, (int) (previousHeightxx0 + previousHeightxx1) / 2);
                p.addPoint((int) xx0, (int) previousHeightxx0);
                g2.setPaint(getItemPaint(row, column - 1));
                g2.setStroke(getItemStroke(row, column - 1));
                g2.fill(p);
                if (entities != null)
                    addItemEntity(entities, dataset, row, column - 1, p);
                // right half
                p = new Polygon();
                p.addPoint((int) xx1, (int) yy1);
                p.addPoint((int) (xx0 + xx1) / 2, (int) (yy0 + yy1) / 2);
                p.addPoint((int) (xx0 + xx1) / 2, (int) (previousHeightxx0 + previousHeightxx1) / 2);
                p.addPoint((int) xx1, (int) previousHeightxx1);
                g2.setPaint(getItemPaint(row, column));
                g2.setStroke(getItemStroke(row, column));
                g2.fill(p);
                if (entities != null)
                    addItemEntity(entities, dataset, row, column, p);
            } else {
                if (isItemLabelVisible(row, column)) {
                    drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, yy1, (y1 < 0.0));
                }
            }
        }
    }
}
Also used : EntityCollection(org.jfree.chart.entity.EntityCollection) Polygon(java.awt.Polygon) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 54 with RectangleEdge

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

the class XYPlot method calculateDomainAxisSpace.

/**
 * Calculates the space required for the domain axis/axes.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param space  a carrier for the result (<code>null</code> permitted).
 *
 * @return The required space.
 */
protected AxisSpace calculateDomainAxisSpace(Graphics2D g2, Rectangle2D plotArea, AxisSpace space) {
    if (space == null) {
        space = new AxisSpace();
    }
    // reserve some space for the domain axis...
    if (this.fixedDomainAxisSpace != null) {
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            space.ensureAtLeast(this.fixedDomainAxisSpace.getLeft(), RectangleEdge.LEFT);
            space.ensureAtLeast(this.fixedDomainAxisSpace.getRight(), RectangleEdge.RIGHT);
        } else if (this.orientation == PlotOrientation.VERTICAL) {
            space.ensureAtLeast(this.fixedDomainAxisSpace.getTop(), RectangleEdge.TOP);
            space.ensureAtLeast(this.fixedDomainAxisSpace.getBottom(), RectangleEdge.BOTTOM);
        }
    } else {
        // reserve space for the domain axes...
        for (ValueAxis axis : this.domainAxes.values()) {
            if (axis != null) {
                RectangleEdge edge = getDomainAxisEdge(findDomainAxisIndex(axis));
                space = axis.reserveSpace(g2, this, plotArea, edge, space);
            }
        }
    }
    return space;
}
Also used : ValueAxis(org.jfree.chart.axis.ValueAxis) AxisSpace(org.jfree.chart.axis.AxisSpace) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 55 with RectangleEdge

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

the class XYPlot method draw.

/**
 * Draws the plot within the specified area on a graphics device.
 *
 * @param g2  the graphics device.
 * @param area  the plot area (in Java2D space).
 * @param anchor  an anchor point in Java2D space (<code>null</code>
 *                permitted).
 * @param parentState  the state from the parent plot, if there is one
 *                     (<code>null</code> permitted).
 * @param info  collects chart drawing information (<code>null</code>
 *              permitted).
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
    // if the plot area is too small, just return...
    boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
    boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
    if (b1 || b2) {
        return;
    }
    // record the plot area...
    if (info != null) {
        info.setPlotArea(area);
    }
    // adjust the drawing area for the plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);
    AxisSpace space = calculateAxisSpace(g2, area);
    Rectangle2D dataArea = space.shrink(area, null);
    this.axisOffset.trim(dataArea);
    dataArea = integerise(dataArea);
    if (dataArea.isEmpty()) {
        return;
    }
    createAndAddEntity((Rectangle2D) dataArea.clone(), info, null, null);
    if (info != null) {
        info.setDataArea(dataArea);
    }
    // draw the plot background and axes...
    drawBackground(g2, dataArea);
    Map axisStateMap = drawAxes(g2, area, dataArea, info);
    PlotOrientation orient = getOrientation();
    // clicked - the crosshairs will be driven off this point...
    if (anchor != null && !dataArea.contains(anchor)) {
        anchor = null;
    }
    CrosshairState crosshairState = new CrosshairState();
    crosshairState.setCrosshairDistance(Double.POSITIVE_INFINITY);
    crosshairState.setAnchor(anchor);
    crosshairState.setAnchorX(Double.NaN);
    crosshairState.setAnchorY(Double.NaN);
    if (anchor != null) {
        ValueAxis domainAxis = getDomainAxis();
        if (domainAxis != null) {
            double x;
            if (orient == PlotOrientation.VERTICAL) {
                x = domainAxis.java2DToValue(anchor.getX(), dataArea, getDomainAxisEdge());
            } else {
                x = domainAxis.java2DToValue(anchor.getY(), dataArea, getDomainAxisEdge());
            }
            crosshairState.setAnchorX(x);
        }
        ValueAxis rangeAxis = getRangeAxis();
        if (rangeAxis != null) {
            double y;
            if (orient == PlotOrientation.VERTICAL) {
                y = rangeAxis.java2DToValue(anchor.getY(), dataArea, getRangeAxisEdge());
            } else {
                y = rangeAxis.java2DToValue(anchor.getX(), dataArea, getRangeAxisEdge());
            }
            crosshairState.setAnchorY(y);
        }
    }
    crosshairState.setCrosshairX(getDomainCrosshairValue());
    crosshairState.setCrosshairY(getRangeCrosshairValue());
    Shape originalClip = g2.getClip();
    Composite originalComposite = g2.getComposite();
    g2.clip(dataArea);
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
    AxisState domainAxisState = (AxisState) axisStateMap.get(getDomainAxis());
    if (domainAxisState == null) {
        if (parentState != null) {
            domainAxisState = (AxisState) parentState.getSharedAxisStates().get(getDomainAxis());
        }
    }
    AxisState rangeAxisState = (AxisState) axisStateMap.get(getRangeAxis());
    if (rangeAxisState == null) {
        if (parentState != null) {
            rangeAxisState = (AxisState) parentState.getSharedAxisStates().get(getRangeAxis());
        }
    }
    if (domainAxisState != null) {
        drawDomainTickBands(g2, dataArea, domainAxisState.getTicks());
    }
    if (rangeAxisState != null) {
        drawRangeTickBands(g2, dataArea, rangeAxisState.getTicks());
    }
    if (domainAxisState != null) {
        drawDomainGridlines(g2, dataArea, domainAxisState.getTicks());
        drawZeroDomainBaseline(g2, dataArea);
    }
    if (rangeAxisState != null) {
        drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());
        drawZeroRangeBaseline(g2, dataArea);
    }
    Graphics2D savedG2 = g2;
    BufferedImage dataImage = null;
    boolean suppressShadow = Boolean.TRUE.equals(g2.getRenderingHint(JFreeChart.KEY_SUPPRESS_SHADOW_GENERATION));
    if (this.shadowGenerator != null && !suppressShadow) {
        dataImage = new BufferedImage((int) dataArea.getWidth(), (int) dataArea.getHeight(), BufferedImage.TYPE_INT_ARGB);
        g2 = dataImage.createGraphics();
        g2.translate(-dataArea.getX(), -dataArea.getY());
        g2.setRenderingHints(savedG2.getRenderingHints());
    }
    // draw the markers that are associated with a specific dataset...
    for (XYDataset dataset : this.datasets.values()) {
        int datasetIndex = indexOf(dataset);
        drawDomainMarkers(g2, dataArea, datasetIndex, Layer.BACKGROUND);
    }
    for (XYDataset dataset : this.datasets.values()) {
        int datasetIndex = indexOf(dataset);
        drawRangeMarkers(g2, dataArea, datasetIndex, Layer.BACKGROUND);
    }
    // now draw annotations and render data items...
    boolean foundData = false;
    DatasetRenderingOrder order = getDatasetRenderingOrder();
    List<Integer> rendererIndices = getRendererIndices(order);
    List<Integer> datasetIndices = getDatasetIndices(order);
    // draw background annotations
    for (int i : rendererIndices) {
        XYItemRenderer renderer = getRenderer(i);
        if (renderer != null) {
            ValueAxis domainAxis = getDomainAxisForDataset(i);
            ValueAxis rangeAxis = getRangeAxisForDataset(i);
            renderer.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.BACKGROUND, info);
        }
    }
    // render data items...
    for (int datasetIndex : datasetIndices) {
        XYDataset dataset = this.getDataset(datasetIndex);
        foundData = render(g2, dataArea, datasetIndex, info, crosshairState) || foundData;
    }
    // draw foreground annotations
    for (int i : rendererIndices) {
        XYItemRenderer renderer = getRenderer(i);
        if (renderer != null) {
            ValueAxis domainAxis = getDomainAxisForDataset(i);
            ValueAxis rangeAxis = getRangeAxisForDataset(i);
            renderer.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.FOREGROUND, info);
        }
    }
    // draw domain crosshair if required...
    int datasetIndex = crosshairState.getDatasetIndex();
    ValueAxis xAxis = this.getDomainAxisForDataset(datasetIndex);
    RectangleEdge xAxisEdge = getDomainAxisEdge(getDomainAxisIndex(xAxis));
    if (!this.domainCrosshairLockedOnData && anchor != null) {
        double xx;
        if (orient == PlotOrientation.VERTICAL) {
            xx = xAxis.java2DToValue(anchor.getX(), dataArea, xAxisEdge);
        } else {
            xx = xAxis.java2DToValue(anchor.getY(), dataArea, xAxisEdge);
        }
        crosshairState.setCrosshairX(xx);
    }
    setDomainCrosshairValue(crosshairState.getCrosshairX(), false);
    if (isDomainCrosshairVisible()) {
        double x = getDomainCrosshairValue();
        Paint paint = getDomainCrosshairPaint();
        Stroke stroke = getDomainCrosshairStroke();
        drawDomainCrosshair(g2, dataArea, orient, x, xAxis, stroke, paint);
    }
    // draw range crosshair if required...
    ValueAxis yAxis = getRangeAxisForDataset(datasetIndex);
    RectangleEdge yAxisEdge = getRangeAxisEdge(getRangeAxisIndex(yAxis));
    if (!this.rangeCrosshairLockedOnData && anchor != null) {
        double yy;
        if (orient == PlotOrientation.VERTICAL) {
            yy = yAxis.java2DToValue(anchor.getY(), dataArea, yAxisEdge);
        } else {
            yy = yAxis.java2DToValue(anchor.getX(), dataArea, yAxisEdge);
        }
        crosshairState.setCrosshairY(yy);
    }
    setRangeCrosshairValue(crosshairState.getCrosshairY(), false);
    if (isRangeCrosshairVisible()) {
        double y = getRangeCrosshairValue();
        Paint paint = getRangeCrosshairPaint();
        Stroke stroke = getRangeCrosshairStroke();
        drawRangeCrosshair(g2, dataArea, orient, y, yAxis, stroke, paint);
    }
    if (!foundData) {
        drawNoDataMessage(g2, dataArea);
    }
    for (int i : rendererIndices) {
        drawDomainMarkers(g2, dataArea, i, Layer.FOREGROUND);
    }
    for (int i : rendererIndices) {
        drawRangeMarkers(g2, dataArea, i, Layer.FOREGROUND);
    }
    drawAnnotations(g2, dataArea, info);
    if (this.shadowGenerator != null && !suppressShadow) {
        BufferedImage shadowImage = this.shadowGenerator.createDropShadow(dataImage);
        g2 = savedG2;
        g2.drawImage(shadowImage, (int) dataArea.getX() + this.shadowGenerator.calculateOffsetX(), (int) dataArea.getY() + this.shadowGenerator.calculateOffsetY(), null);
        g2.drawImage(dataImage, (int) dataArea.getX(), (int) dataArea.getY(), null);
    }
    g2.setClip(originalClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, dataArea);
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) Shape(java.awt.Shape) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) BufferedImage(java.awt.image.BufferedImage) Paint(java.awt.Paint) Graphics2D(java.awt.Graphics2D) AxisState(org.jfree.chart.axis.AxisState) ValueAxis(org.jfree.chart.axis.ValueAxis) RectangleInsets(org.jfree.ui.RectangleInsets) XYDataset(org.jfree.data.xy.XYDataset) AxisSpace(org.jfree.chart.axis.AxisSpace) AbstractXYItemRenderer(org.jfree.chart.renderer.xy.AbstractXYItemRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) RectangleEdge(org.jfree.ui.RectangleEdge)

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