Search in sources :

Example 16 with Size2D

use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.

the class ImageTitle method drawVertical.

/**
 * Draws the title on a Java 2D graphics device (such as the screen or a
 * printer).
 *
 * @param g2  the graphics device.
 * @param chartArea  the area within which the title (and plot) should be
 *                   drawn.
 *
 * @return The size of the area used by the title.
 */
protected Size2D drawVertical(Graphics2D g2, Rectangle2D chartArea) {
    double startX = 0.0;
    double topSpace = 0.0;
    double bottomSpace = 0.0;
    double leftSpace = 0.0;
    double rightSpace = 0.0;
    double w = getWidth();
    double h = getHeight();
    RectangleInsets padding = getPadding();
    if (padding != null) {
        topSpace = padding.calculateTopOutset(h);
        bottomSpace = padding.calculateBottomOutset(h);
        leftSpace = padding.calculateLeftOutset(w);
        rightSpace = padding.calculateRightOutset(w);
    }
    if (getPosition() == RectangleEdge.LEFT) {
        startX = chartArea.getX() + leftSpace;
    } else {
        startX = chartArea.getMaxX() - rightSpace - w;
    }
    // what is our alignment?
    VerticalAlignment alignment = getVerticalAlignment();
    double startY = 0.0;
    if (alignment == VerticalAlignment.CENTER) {
        startY = chartArea.getMinY() + topSpace + chartArea.getHeight() / 2.0 - h / 2.0;
    } else if (alignment == VerticalAlignment.TOP) {
        startY = chartArea.getMinY() + topSpace;
    } else if (alignment == VerticalAlignment.BOTTOM) {
        startY = chartArea.getMaxY() - bottomSpace - h;
    }
    g2.drawImage(this.image, (int) startX, (int) startY, (int) w, (int) h, null);
    return new Size2D(chartArea.getWidth() + leftSpace + rightSpace, h + topSpace + bottomSpace);
}
Also used : Size2D(org.jfree.chart.util.Size2D) RectangleInsets(org.jfree.chart.util.RectangleInsets) VerticalAlignment(org.jfree.chart.util.VerticalAlignment)

Example 17 with Size2D

use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.

the class ImageTitle method drawHorizontal.

/**
 * Draws the title on a Java 2D graphics device (such as the screen or a
 * printer).
 *
 * @param g2  the graphics device.
 * @param chartArea  the area within which the title (and plot) should be
 *                   drawn.
 *
 * @return The size of the area used by the title.
 */
protected Size2D drawHorizontal(Graphics2D g2, Rectangle2D chartArea) {
    double startY = 0.0;
    double topSpace = 0.0;
    double bottomSpace = 0.0;
    double leftSpace = 0.0;
    double rightSpace = 0.0;
    double w = getWidth();
    double h = getHeight();
    RectangleInsets padding = getPadding();
    topSpace = padding.calculateTopOutset(h);
    bottomSpace = padding.calculateBottomOutset(h);
    leftSpace = padding.calculateLeftOutset(w);
    rightSpace = padding.calculateRightOutset(w);
    if (getPosition() == RectangleEdge.TOP) {
        startY = chartArea.getY() + topSpace;
    } else {
        startY = chartArea.getY() + chartArea.getHeight() - bottomSpace - h;
    }
    // what is our alignment?
    HorizontalAlignment horizontalAlignment = getHorizontalAlignment();
    double startX = 0.0;
    if (horizontalAlignment == HorizontalAlignment.CENTER) {
        startX = chartArea.getX() + leftSpace + chartArea.getWidth() / 2.0 - w / 2.0;
    } else if (horizontalAlignment == HorizontalAlignment.LEFT) {
        startX = chartArea.getX() + leftSpace;
    } else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
        startX = chartArea.getX() + chartArea.getWidth() - rightSpace - w;
    }
    g2.drawImage(this.image, (int) startX, (int) startY, (int) w, (int) h, null);
    return new Size2D(chartArea.getWidth() + leftSpace + rightSpace, h + topSpace + bottomSpace);
}
Also used : Size2D(org.jfree.chart.util.Size2D) RectangleInsets(org.jfree.chart.util.RectangleInsets) HorizontalAlignment(org.jfree.chart.util.HorizontalAlignment)

Example 18 with Size2D

use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.

the class LegendGraphic method arrange.

/**
 * Arranges the contents of the block, within the given constraints, and
 * returns the block size.
 *
 * @param g2  the graphics device.
 * @param constraint  the constraint (<code>null</code> not permitted).
 *
 * @return The block size (in Java2D units, never <code>null</code>).
 */
public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) {
    RectangleConstraint contentConstraint = toContentConstraint(constraint);
    LengthConstraintType w = contentConstraint.getWidthConstraintType();
    LengthConstraintType h = contentConstraint.getHeightConstraintType();
    Size2D contentSize = null;
    if (w == LengthConstraintType.NONE) {
        if (h == LengthConstraintType.NONE) {
            contentSize = arrangeNN(g2);
        } else if (h == LengthConstraintType.RANGE) {
            throw new RuntimeException("Not yet implemented.");
        } else if (h == LengthConstraintType.FIXED) {
            throw new RuntimeException("Not yet implemented.");
        }
    } else if (w == LengthConstraintType.RANGE) {
        if (h == LengthConstraintType.NONE) {
            throw new RuntimeException("Not yet implemented.");
        } else if (h == LengthConstraintType.RANGE) {
            throw new RuntimeException("Not yet implemented.");
        } else if (h == LengthConstraintType.FIXED) {
            throw new RuntimeException("Not yet implemented.");
        }
    } else if (w == LengthConstraintType.FIXED) {
        if (h == LengthConstraintType.NONE) {
            throw new RuntimeException("Not yet implemented.");
        } else if (h == LengthConstraintType.RANGE) {
            throw new RuntimeException("Not yet implemented.");
        } else if (h == LengthConstraintType.FIXED) {
            contentSize = new Size2D(contentConstraint.getWidth(), contentConstraint.getHeight());
        }
    }
    return new Size2D(calculateTotalWidth(contentSize.getWidth()), calculateTotalHeight(contentSize.getHeight()));
}
Also used : Size2D(org.jfree.chart.util.Size2D) LengthConstraintType(org.jfree.chart.block.LengthConstraintType) RectangleConstraint(org.jfree.chart.block.RectangleConstraint)

Example 19 with Size2D

use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.

the class TextBlock method draw.

/**
 * Draws the text block, aligning it with the specified anchor point and
 * rotating it about the specified rotation point.
 *
 * @param g2  the graphics device.
 * @param anchorX  the x-coordinate for the anchor point.
 * @param anchorY  the y-coordinate for the anchor point.
 * @param anchor  the point on the text block that is aligned to the
 *                anchor point.
 * @param rotateX  the x-coordinate for the rotation point.
 * @param rotateY  the x-coordinate for the rotation point.
 * @param angle  the rotation (in radians).
 */
public void draw(Graphics2D g2, float anchorX, float anchorY, TextBlockAnchor anchor, float rotateX, float rotateY, double angle) {
    Size2D d = calculateDimensions(g2);
    float[] offsets = calculateOffsets(anchor, d.getWidth(), d.getHeight());
    Iterator iterator = this.lines.iterator();
    float yCursor = 0.0f;
    while (iterator.hasNext()) {
        TextLine line = (TextLine) iterator.next();
        Size2D dimension = line.calculateDimensions(g2);
        float lineOffset = 0.0f;
        if (this.lineAlignment == HorizontalAlignment.CENTER) {
            lineOffset = (float) (d.getWidth() - dimension.getWidth()) / 2.0f;
        } else if (this.lineAlignment == HorizontalAlignment.RIGHT) {
            lineOffset = (float) (d.getWidth() - dimension.getWidth());
        }
        line.draw(g2, anchorX + offsets[0] + lineOffset, anchorY + offsets[1] + yCursor, TextAnchor.TOP_LEFT, rotateX, rotateY, angle);
        yCursor = yCursor + (float) dimension.getHeight();
    }
}
Also used : Size2D(org.jfree.chart.util.Size2D) Iterator(java.util.Iterator)

Example 20 with Size2D

use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.

the class TextBlock method calculateDimensions.

/**
 * Returns the width and height of the text block.
 *
 * @param g2  the graphics device.
 *
 * @return The width and height.
 */
public Size2D calculateDimensions(Graphics2D g2) {
    double width = 0.0;
    double height = 0.0;
    Iterator iterator = this.lines.iterator();
    while (iterator.hasNext()) {
        TextLine line = (TextLine) iterator.next();
        Size2D dimension = line.calculateDimensions(g2);
        width = Math.max(width, dimension.getWidth());
        height = height + dimension.getHeight();
    }
    return new Size2D(width, height);
}
Also used : Size2D(org.jfree.chart.util.Size2D) Iterator(java.util.Iterator)

Aggregations

Size2D (org.jfree.chart.util.Size2D)49 Rectangle2D (java.awt.geom.Rectangle2D)21 List (java.util.List)10 RectangleConstraint (org.jfree.chart.block.RectangleConstraint)8 Iterator (java.util.Iterator)5 RectangleEdge (org.jfree.chart.util.RectangleEdge)5 Range (org.jfree.data.Range)5 FontMetrics (java.awt.FontMetrics)4 Shape (java.awt.Shape)4 ArrayList (java.util.ArrayList)4 LengthConstraintType (org.jfree.chart.block.LengthConstraintType)4 RectangleInsets (org.jfree.chart.util.RectangleInsets)4 Point2D (java.awt.geom.Point2D)2 BlockParams (org.jfree.chart.block.BlockParams)2 EntityBlockResult (org.jfree.chart.block.EntityBlockResult)2 G2TextMeasurer (org.jfree.chart.text.G2TextMeasurer)2 Arc2D (java.awt.geom.Arc2D)1 AxisLocation (org.jfree.chart.axis.AxisLocation)1 AxisSpace (org.jfree.chart.axis.AxisSpace)1 BlockContainer (org.jfree.chart.block.BlockContainer)1