Search in sources :

Example 1 with RectangleInsets

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

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;
    double topSpace;
    double bottomSpace;
    double leftSpace;
    double rightSpace;
    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?
    double startX = 0.0;
    switch(getHorizontalAlignment()) {
        case CENTER:
            startX = chartArea.getX() + leftSpace + chartArea.getWidth() / 2.0 - w / 2.0;
            break;
        case LEFT:
            startX = chartArea.getX() + leftSpace;
            break;
        case RIGHT:
            startX = chartArea.getX() + chartArea.getWidth() - rightSpace - w;
            break;
        default:
            throw new IllegalStateException("Unexpected horizontal alignment.");
    }
    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.block.Size2D) RectangleInsets(org.jfree.chart.api.RectangleInsets)

Example 2 with RectangleInsets

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

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;
    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?
    double startY = 0.0;
    switch(getVerticalAlignment()) {
        case CENTER:
            startY = chartArea.getMinY() + topSpace + chartArea.getHeight() / 2.0 - h / 2.0;
            break;
        case TOP:
            startY = chartArea.getMinY() + topSpace;
            break;
        case BOTTOM:
            startY = chartArea.getMaxY() - bottomSpace - h;
            break;
        default:
            throw new IllegalStateException("Unexpected vertical alignment.");
    }
    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.block.Size2D) RectangleInsets(org.jfree.chart.api.RectangleInsets)

Example 3 with RectangleInsets

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

the class LogAxis method estimateMaximumTickLabelWidth.

/**
 * Estimates the maximum width of the tick labels, assuming the specified
 * tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we
 * just look at two values: the lower bound and the upper bound for the
 * axis.  These two values will usually be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return The estimated maximum width of the tick labels.
 */
protected double estimateMaximumTickLabelWidth(Graphics2D g2, TickUnit unit) {
    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight();
    if (isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of the
        // font)...
        FontRenderContext frc = g2.getFontRenderContext();
        LineMetrics lm = getTickLabelFont().getLineMetrics("0", frc);
        result += lm.getHeight();
    } else {
        // look at lower and upper bounds...
        Range range = getRange();
        double lower = range.getLowerBound();
        double upper = range.getUpperBound();
        AttributedString lowerStr = createTickLabel(lower);
        AttributedString upperStr = createTickLabel(upper);
        double w1 = AttrStringUtils.getTextBounds(lowerStr, g2).getWidth();
        double w2 = AttrStringUtils.getTextBounds(upperStr, g2).getWidth();
        result += Math.max(w1, w2);
    }
    return result;
}
Also used : AttributedString(java.text.AttributedString) RectangleInsets(org.jfree.chart.api.RectangleInsets) FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics) Range(org.jfree.data.Range)

Example 4 with RectangleInsets

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

the class LogAxis method estimateMaximumTickLabelHeight.

/**
 * Estimates the maximum tick label height.
 *
 * @param g2  the graphics device.
 *
 * @return The maximum height.
 */
protected double estimateMaximumTickLabelHeight(Graphics2D g2) {
    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getTop() + tickLabelInsets.getBottom();
    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    result += tickLabelFont.getLineMetrics("123", frc).getHeight();
    return result;
}
Also used : RectangleInsets(org.jfree.chart.api.RectangleInsets) FontRenderContext(java.awt.font.FontRenderContext) Font(java.awt.Font)

Example 5 with RectangleInsets

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

the class DateAxis method estimateMaximumTickLabelWidth.

/**
 * Estimates the maximum width of the tick labels, assuming the specified
 * tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we
 * just look at two values: the lower bound and the upper bound for the
 * axis.  These two values will usually be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return The estimated maximum width of the tick labels.
 */
private double estimateMaximumTickLabelWidth(Graphics2D g2, DateTickUnit unit) {
    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight();
    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
    if (isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of
        // the font)...
        result += lm.getHeight();
    } else {
        // look at lower and upper bounds...
        DateRange range = (DateRange) getRange();
        Date lower = range.getLowerDate();
        Date upper = range.getUpperDate();
        String lowerStr, upperStr;
        DateFormat formatter = getDateFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        } else {
            lowerStr = unit.dateToString(lower);
            upperStr = unit.dateToString(upper);
        }
        FontMetrics fm = g2.getFontMetrics(tickLabelFont);
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }
    return result;
}
Also used : DateRange(org.jfree.data.time.DateRange) FontMetrics(java.awt.FontMetrics) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) RectangleInsets(org.jfree.chart.api.RectangleInsets) FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics) Font(java.awt.Font) Date(java.util.Date)

Aggregations

RectangleInsets (org.jfree.chart.api.RectangleInsets)58 Rectangle2D (java.awt.geom.Rectangle2D)19 Test (org.junit.jupiter.api.Test)17 Font (java.awt.Font)16 BasicStroke (java.awt.BasicStroke)14 GradientPaint (java.awt.GradientPaint)13 Paint (java.awt.Paint)9 Shape (java.awt.Shape)9 AxisState (org.jfree.chart.axis.AxisState)7 FontMetrics (java.awt.FontMetrics)6 Stroke (java.awt.Stroke)6 FontRenderContext (java.awt.font.FontRenderContext)6 LineMetrics (java.awt.font.LineMetrics)6 RectangleEdge (org.jfree.chart.api.RectangleEdge)6 AxisSpace (org.jfree.chart.axis.AxisSpace)6 ValueAxis (org.jfree.chart.axis.ValueAxis)6 StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)6 StandardPieToolTipGenerator (org.jfree.chart.labels.StandardPieToolTipGenerator)6 AlphaComposite (java.awt.AlphaComposite)5 Composite (java.awt.Composite)5