Search in sources :

Example 26 with RectangleEdge

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

the class XYTitleAnnotation method draw.

/**
 * Draws the annotation.  This method is called by the drawing code in the
 * {@link XYPlot} class, you don't normally need to call this method
 * directly.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  if supplied, this info object will be populated with
 *              entity information.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
    PlotOrientation orientation = plot.getOrientation();
    AxisLocation domainAxisLocation = plot.getDomainAxisLocation();
    AxisLocation rangeAxisLocation = plot.getRangeAxisLocation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation);
    Range xRange = domainAxis.getRange();
    Range yRange = rangeAxis.getRange();
    double anchorX, anchorY;
    if (this.coordinateType == XYCoordinateType.RELATIVE) {
        anchorX = xRange.getLowerBound() + (this.x * xRange.getLength());
        anchorY = yRange.getLowerBound() + (this.y * yRange.getLength());
    } else {
        anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge);
        anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge);
    }
    float j2DX = (float) domainAxis.valueToJava2D(anchorX, dataArea, domainEdge);
    float j2DY = (float) rangeAxis.valueToJava2D(anchorY, dataArea, rangeEdge);
    float xx = 0.0f;
    float yy = 0.0f;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = j2DY;
        yy = j2DX;
    } else if (orientation == PlotOrientation.VERTICAL) {
        xx = j2DX;
        yy = j2DY;
    }
    double maxW = dataArea.getWidth();
    double maxH = dataArea.getHeight();
    if (this.coordinateType == XYCoordinateType.RELATIVE) {
        if (this.maxWidth > 0.0) {
            maxW = maxW * this.maxWidth;
        }
        if (this.maxHeight > 0.0) {
            maxH = maxH * this.maxHeight;
        }
    }
    if (this.coordinateType == XYCoordinateType.DATA) {
        maxW = this.maxWidth;
        maxH = this.maxHeight;
    }
    RectangleConstraint rc = new RectangleConstraint(new Range(0, maxW), new Range(0, maxH));
    Size2D size = this.title.arrange(g2, rc);
    Rectangle2D titleRect = new Rectangle2D.Double(0, 0, size.width, size.height);
    Point2D anchorPoint = RectangleAnchor.coordinates(titleRect, this.anchor);
    xx = xx - (float) anchorPoint.getX();
    yy = yy - (float) anchorPoint.getY();
    titleRect.setRect(xx, yy, titleRect.getWidth(), titleRect.getHeight());
    BlockParams p = new BlockParams();
    if (info != null) {
        if (info.getOwner().getEntityCollection() != null) {
            p.setGenerateEntities(true);
        }
    }
    Object result = this.title.draw(g2, titleRect, p);
    if (info != null) {
        if (result instanceof EntityBlockResult) {
            EntityBlockResult ebr = (EntityBlockResult) result;
            info.getOwner().getEntityCollection().addAll(ebr.getEntityCollection());
        }
        String toolTip = getToolTipText();
        String url = getURL();
        if (toolTip != null || url != null) {
            addEntity(info, new Rectangle2D.Float(xx, yy, (float) size.width, (float) size.height), rendererIndex, toolTip, url);
        }
    }
}
Also used : AxisLocation(org.jfree.chart.axis.AxisLocation) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Rectangle2D(java.awt.geom.Rectangle2D) EntityBlockResult(org.jfree.chart.block.EntityBlockResult) Range(org.jfree.data.Range) BlockParams(org.jfree.chart.block.BlockParams) Size2D(org.jfree.ui.Size2D) Point2D(java.awt.geom.Point2D) RectangleConstraint(org.jfree.chart.block.RectangleConstraint) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 27 with RectangleEdge

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

the class CategoryPointerAnnotation method draw.

/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 */
@Override
public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, CategoryAxis domainAxis, ValueAxis rangeAxis) {
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
    CategoryDataset dataset = plot.getDataset();
    int catIndex = dataset.getColumnIndex(getCategory());
    int catCount = dataset.getColumnCount();
    double j2DX = domainAxis.getCategoryMiddle(catIndex, catCount, dataArea, domainEdge);
    double j2DY = rangeAxis.valueToJava2D(getValue(), dataArea, rangeEdge);
    if (orientation == PlotOrientation.HORIZONTAL) {
        double temp = j2DX;
        j2DX = j2DY;
        j2DY = temp;
    }
    double startX = j2DX + Math.cos(this.angle) * this.baseRadius;
    double startY = j2DY + Math.sin(this.angle) * this.baseRadius;
    double endX = j2DX + Math.cos(this.angle) * this.tipRadius;
    double endY = j2DY + Math.sin(this.angle) * this.tipRadius;
    double arrowBaseX = endX + Math.cos(this.angle) * this.arrowLength;
    double arrowBaseY = endY + Math.sin(this.angle) * this.arrowLength;
    double arrowLeftX = arrowBaseX + Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth;
    double arrowLeftY = arrowBaseY + Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth;
    double arrowRightX = arrowBaseX - Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth;
    double arrowRightY = arrowBaseY - Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth;
    GeneralPath arrow = new GeneralPath();
    arrow.moveTo((float) endX, (float) endY);
    arrow.lineTo((float) arrowLeftX, (float) arrowLeftY);
    arrow.lineTo((float) arrowRightX, (float) arrowRightY);
    arrow.closePath();
    g2.setStroke(this.arrowStroke);
    g2.setPaint(this.arrowPaint);
    Line2D line = new Line2D.Double(startX, startY, arrowBaseX, arrowBaseY);
    g2.draw(line);
    g2.fill(arrow);
    // draw the label
    g2.setFont(getFont());
    g2.setPaint(getPaint());
    double labelX = j2DX + Math.cos(this.angle) * (this.baseRadius + this.labelOffset);
    double labelY = j2DY + Math.sin(this.angle) * (this.baseRadius + this.labelOffset);
    /* Rectangle2D hotspot = */
    TextUtilities.drawAlignedString(getText(), g2, (float) labelX, (float) labelY, getTextAnchor());
// TODO: implement the entity for the annotation
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) GeneralPath(java.awt.geom.GeneralPath) CategoryDataset(org.jfree.data.category.CategoryDataset) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 28 with RectangleEdge

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

the class XYBoxAnnotation method draw.

/**
 * Draws the annotation.  This method is usually called by the
 * {@link XYPlot} class, you shouldn't need to call it directly.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  the plot rendering info.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
    double transX0 = domainAxis.valueToJava2D(this.x0, dataArea, domainEdge);
    double transY0 = rangeAxis.valueToJava2D(this.y0, dataArea, rangeEdge);
    double transX1 = domainAxis.valueToJava2D(this.x1, dataArea, domainEdge);
    double transY1 = rangeAxis.valueToJava2D(this.y1, dataArea, rangeEdge);
    Rectangle2D box = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        box = new Rectangle2D.Double(transY0, transX1, transY1 - transY0, transX0 - transX1);
    } else if (orientation == PlotOrientation.VERTICAL) {
        box = new Rectangle2D.Double(transX0, transY1, transX1 - transX0, transY0 - transY1);
    }
    if (this.fillPaint != null) {
        g2.setPaint(this.fillPaint);
        g2.fill(box);
    }
    if (this.stroke != null && this.outlinePaint != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.stroke);
        g2.draw(box);
    }
    addEntity(info, box, rendererIndex, getToolTipText(), getURL());
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Rectangle2D(java.awt.geom.Rectangle2D) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 29 with RectangleEdge

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

the class CategoryLineAnnotation method draw.

/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 */
@Override
public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, CategoryAxis domainAxis, ValueAxis rangeAxis) {
    CategoryDataset dataset = plot.getDataset();
    int catIndex1 = dataset.getColumnIndex(this.category1);
    int catIndex2 = dataset.getColumnIndex(this.category2);
    int catCount = dataset.getColumnCount();
    double lineX1 = 0.0f;
    double lineY1 = 0.0f;
    double lineX2 = 0.0f;
    double lineY2 = 0.0f;
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
    if (orientation == PlotOrientation.HORIZONTAL) {
        lineY1 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex1, catCount, dataArea, domainEdge);
        lineX1 = rangeAxis.valueToJava2D(this.value1, dataArea, rangeEdge);
        lineY2 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex2, catCount, dataArea, domainEdge);
        lineX2 = rangeAxis.valueToJava2D(this.value2, dataArea, rangeEdge);
    } else if (orientation == PlotOrientation.VERTICAL) {
        lineX1 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex1, catCount, dataArea, domainEdge);
        lineY1 = rangeAxis.valueToJava2D(this.value1, dataArea, rangeEdge);
        lineX2 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex2, catCount, dataArea, domainEdge);
        lineY2 = rangeAxis.valueToJava2D(this.value2, dataArea, rangeEdge);
    }
    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    g2.drawLine((int) lineX1, (int) lineY1, (int) lineX2, (int) lineY2);
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 30 with RectangleEdge

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

the class CategoryPlot method drawDomainGridlines.

/**
 * Draws the domain gridlines for the plot, if they are visible.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 *
 * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List)
 */
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea) {
    if (!isDomainGridlinesVisible()) {
        return;
    }
    CategoryAnchor anchor = getDomainGridlinePosition();
    RectangleEdge domainAxisEdge = getDomainAxisEdge();
    CategoryDataset dataset = getDataset();
    if (dataset == null) {
        return;
    }
    CategoryAxis axis = getDomainAxis();
    if (axis != null) {
        int columnCount = dataset.getColumnCount();
        for (int c = 0; c < columnCount; c++) {
            double xx = axis.getCategoryJava2DCoordinate(anchor, c, columnCount, dataArea, domainAxisEdge);
            CategoryItemRenderer renderer1 = getRenderer();
            if (renderer1 != null) {
                renderer1.drawDomainGridline(g2, this, dataArea, xx);
            }
        }
    }
}
Also used : CategoryAnchor(org.jfree.chart.axis.CategoryAnchor) AbstractCategoryItemRenderer(org.jfree.chart.renderer.category.AbstractCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint) 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