Search in sources :

Example 6 with Size2D

use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class TextTitle method arrangeRN.

/**
 * Arranges the content for this title assuming a range constraint for the
 * width and no bounds on the height, and returns the required size.  This
 * will reflect the fact that a text title positioned on the left or right
 * of a chart will be rotated by 90 degrees.
 *
 * @param g2  the graphics target.
 * @param widthRange  the range for the width.
 *
 * @return The content size.
 */
protected Size2D arrangeRN(Graphics2D g2, Range widthRange) {
    Size2D s = arrangeNN(g2);
    if (widthRange.contains(s.getWidth())) {
        return s;
    }
    double ww = widthRange.constrain(s.getWidth());
    return arrangeFN(g2, ww);
}
Also used : Size2D(org.jfree.chart.block.Size2D)

Example 7 with Size2D

use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class TextLine method calculateDimensions.

/**
 * Calculates the width and height of the text line.
 *
 * @param g2  the graphics device.
 *
 * @return The width and height.
 */
public Size2D calculateDimensions(Graphics2D g2) {
    double width = 0.0;
    double height = 0.0;
    for (TextFragment fragment : this.fragments) {
        final Size2D dimension = fragment.calculateDimensions(g2);
        width = width + dimension.getWidth();
        height = Math.max(height, dimension.getHeight());
    }
    return new Size2D(width, height);
}
Also used : Size2D(org.jfree.chart.block.Size2D)

Example 8 with Size2D

use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class CategoryAxis method calculateCategoryLabelWidth.

/**
 * Calculates the width of a category label when rendered.
 *
 * @param label  the text block ({@code null} not permitted).
 * @param position  the position.
 * @param insets  the label insets.
 * @param g2  the graphics device.
 *
 * @return The width.
 */
protected double calculateCategoryLabelWidth(TextBlock label, CategoryLabelPosition position, RectangleInsets insets, Graphics2D g2) {
    Size2D size = label.calculateDimensions(g2);
    Rectangle2D box = new Rectangle2D.Double(0.0, 0.0, size.getWidth(), size.getHeight());
    Shape rotatedBox = ShapeUtils.rotateShape(box, position.getAngle(), 0.0f, 0.0f);
    double w = rotatedBox.getBounds2D().getWidth() + insets.getLeft() + insets.getRight();
    return w;
}
Also used : Size2D(org.jfree.chart.block.Size2D) Shape(java.awt.Shape) Rectangle2D(java.awt.geom.Rectangle2D)

Example 9 with Size2D

use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class CategoryAxis method calculateCategoryLabelHeight.

/**
 * Calculates the height of a category label when rendered.
 *
 * @param block  the text block ({@code null} not permitted).
 * @param position  the label position ({@code null} not permitted).
 * @param insets  the label insets ({@code null} not permitted).
 * @param g2  the graphics device ({@code null} not permitted).
 *
 * @return The height.
 */
protected double calculateCategoryLabelHeight(TextBlock block, CategoryLabelPosition position, RectangleInsets insets, Graphics2D g2) {
    Size2D size = block.calculateDimensions(g2);
    Rectangle2D box = new Rectangle2D.Double(0.0, 0.0, size.getWidth(), size.getHeight());
    Shape rotatedBox = ShapeUtils.rotateShape(box, position.getAngle(), 0.0f, 0.0f);
    double h = rotatedBox.getBounds2D().getHeight() + insets.getTop() + insets.getBottom();
    return h;
}
Also used : Size2D(org.jfree.chart.block.Size2D) Shape(java.awt.Shape) Rectangle2D(java.awt.geom.Rectangle2D)

Example 10 with Size2D

use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

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());
    float yCursor = 0.0f;
    for (TextLine line : this.lines) {
        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.block.Size2D)

Aggregations

Size2D (org.jfree.chart.block.Size2D)27 Rectangle2D (java.awt.geom.Rectangle2D)11 RectangleConstraint (org.jfree.chart.block.RectangleConstraint)8 RectangleEdge (org.jfree.chart.api.RectangleEdge)5 FontMetrics (java.awt.FontMetrics)4 Shape (java.awt.Shape)4 LengthConstraintType (org.jfree.chart.block.LengthConstraintType)4 Point2D (java.awt.geom.Point2D)2 RectangleInsets (org.jfree.chart.api.RectangleInsets)2 BlockParams (org.jfree.chart.block.BlockParams)2 EntityBlockResult (org.jfree.chart.block.EntityBlockResult)2 G2TextMeasurer (org.jfree.chart.text.G2TextMeasurer)2 Range (org.jfree.data.Range)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 EntityCollection (org.jfree.chart.entity.EntityCollection)1 PlotOrientation (org.jfree.chart.plot.PlotOrientation)1