Search in sources :

Example 21 with TextAnchor

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

the class CategoryTickTest method testEquals.

/**
 * Confirm that the equals method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    Comparable<String> c1 = "C1";
    Comparable<String> c2 = "C2";
    TextBlock tb1 = new TextBlock();
    tb1.addLine(new TextLine("Block 1"));
    TextBlock tb2 = new TextBlock();
    tb1.addLine(new TextLine("Block 2"));
    TextBlockAnchor tba1 = TextBlockAnchor.CENTER;
    TextBlockAnchor tba2 = TextBlockAnchor.BOTTOM_CENTER;
    TextAnchor ta1 = TextAnchor.CENTER;
    TextAnchor ta2 = TextAnchor.BASELINE_LEFT;
    CategoryTick t1 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
    CategoryTick t2 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
    assertEquals(t1, t2);
    t1 = new CategoryTick(c2, tb1, tba1, ta1, 1.0f);
    assertNotEquals(t1, t2);
    t2 = new CategoryTick(c2, tb1, tba1, ta1, 1.0f);
    assertEquals(t1, t2);
    t1 = new CategoryTick(c2, tb2, tba1, ta1, 1.0f);
    assertNotEquals(t1, t2);
    t2 = new CategoryTick(c2, tb2, tba1, ta1, 1.0f);
    assertEquals(t1, t2);
    t1 = new CategoryTick(c2, tb2, tba2, ta1, 1.0f);
    assertNotEquals(t1, t2);
    t2 = new CategoryTick(c2, tb2, tba2, ta1, 1.0f);
    assertEquals(t1, t2);
    t1 = new CategoryTick(c2, tb2, tba2, ta2, 1.0f);
    assertNotEquals(t1, t2);
    t2 = new CategoryTick(c2, tb2, tba2, ta2, 1.0f);
    assertEquals(t1, t2);
    t1 = new CategoryTick(c2, tb2, tba2, ta2, 2.0f);
    assertNotEquals(t1, t2);
    t2 = new CategoryTick(c2, tb2, tba2, ta2, 2.0f);
    assertEquals(t1, t2);
}
Also used : TextAnchor(org.jfree.chart.text.TextAnchor) TextLine(org.jfree.chart.text.TextLine) TextBlockAnchor(org.jfree.chart.text.TextBlockAnchor) TextBlock(org.jfree.chart.text.TextBlock) Test(org.junit.jupiter.api.Test)

Example 22 with TextAnchor

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

the class PolarPlot method calculateTextAnchor.

/**
 * Calculate the text position for the given degrees.
 *
 * @param angleDegrees  the angle in degrees.
 *
 * @return The optimal text anchor.
 */
protected TextAnchor calculateTextAnchor(double angleDegrees) {
    TextAnchor ta = TextAnchor.CENTER;
    // normalize angle
    double offset = this.angleOffset;
    while (offset < 0.0) {
        offset += 360.0;
    }
    double normalizedAngle = (((this.counterClockwise ? -1 : 1) * angleDegrees) + offset) % 360;
    while (this.counterClockwise && (normalizedAngle < 0.0)) {
        normalizedAngle += 360.0;
    }
    if (normalizedAngle == 0.0) {
        ta = TextAnchor.CENTER_LEFT;
    } else if (normalizedAngle > 0.0 && normalizedAngle < 90.0) {
        ta = TextAnchor.TOP_LEFT;
    } else if (normalizedAngle == 90.0) {
        ta = TextAnchor.TOP_CENTER;
    } else if (normalizedAngle > 90.0 && normalizedAngle < 180.0) {
        ta = TextAnchor.TOP_RIGHT;
    } else if (normalizedAngle == 180) {
        ta = TextAnchor.CENTER_RIGHT;
    } else if (normalizedAngle > 180.0 && normalizedAngle < 270.0) {
        ta = TextAnchor.BOTTOM_RIGHT;
    } else if (normalizedAngle == 270) {
        ta = TextAnchor.BOTTOM_CENTER;
    } else if (normalizedAngle > 270.0 && normalizedAngle < 360.0) {
        ta = TextAnchor.BOTTOM_LEFT;
    }
    return ta;
}
Also used : TextAnchor(org.jfree.chart.text.TextAnchor)

Example 23 with TextAnchor

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

the class CrosshairOverlay method drawVerticalCrosshair.

/**
 * Draws a crosshair vertically on the plot.
 *
 * @param g2  the graphics target.
 * @param dataArea  the data area.
 * @param x  the x-value in Java2D space.
 * @param crosshair  the crosshair.
 */
protected void drawVerticalCrosshair(Graphics2D g2, Rectangle2D dataArea, double x, Crosshair crosshair) {
    if (x >= dataArea.getMinX() && x <= dataArea.getMaxX()) {
        Line2D line = new Line2D.Double(x, dataArea.getMinY(), x, dataArea.getMaxY());
        Paint savedPaint = g2.getPaint();
        Stroke savedStroke = g2.getStroke();
        g2.setPaint(crosshair.getPaint());
        g2.setStroke(crosshair.getStroke());
        g2.draw(line);
        if (crosshair.isLabelVisible()) {
            String label = crosshair.getLabelGenerator().generateLabel(crosshair);
            if (label != null && !label.isEmpty()) {
                Font savedFont = g2.getFont();
                g2.setFont(crosshair.getLabelFont());
                RectangleAnchor anchor = crosshair.getLabelAnchor();
                Point2D pt = calculateLabelPoint(line, anchor, crosshair.getLabelXOffset(), crosshair.getLabelYOffset());
                float xx = (float) pt.getX();
                float yy = (float) pt.getY();
                TextAnchor alignPt = textAlignPtForLabelAnchorV(anchor);
                Shape hotspot = TextUtils.calculateRotatedStringBounds(label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER);
                if (!dataArea.contains(hotspot.getBounds2D())) {
                    anchor = flipAnchorH(anchor);
                    pt = calculateLabelPoint(line, anchor, crosshair.getLabelXOffset(), crosshair.getLabelYOffset());
                    xx = (float) pt.getX();
                    yy = (float) pt.getY();
                    alignPt = textAlignPtForLabelAnchorV(anchor);
                    hotspot = TextUtils.calculateRotatedStringBounds(label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER);
                }
                g2.setPaint(crosshair.getLabelBackgroundPaint());
                g2.fill(hotspot);
                if (crosshair.isLabelOutlineVisible()) {
                    g2.setPaint(crosshair.getLabelOutlinePaint());
                    g2.setStroke(crosshair.getLabelOutlineStroke());
                    g2.draw(hotspot);
                }
                g2.setPaint(crosshair.getLabelPaint());
                TextUtils.drawAlignedString(label, g2, xx, yy, alignPt);
                g2.setFont(savedFont);
            }
        }
        g2.setPaint(savedPaint);
        g2.setStroke(savedStroke);
    }
}
Also used : Stroke(java.awt.Stroke) TextAnchor(org.jfree.chart.text.TextAnchor) Shape(java.awt.Shape) Point2D(java.awt.geom.Point2D) RectangleAnchor(org.jfree.chart.api.RectangleAnchor) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) Font(java.awt.Font)

Aggregations

TextAnchor (org.jfree.chart.text.TextAnchor)23 Font (java.awt.Font)13 List (java.util.List)10 NumberFormat (java.text.NumberFormat)7 Paint (java.awt.Paint)5 Rectangle2D (java.awt.geom.Rectangle2D)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Shape (java.awt.Shape)4 Test (org.junit.jupiter.api.Test)4 Line2D (java.awt.geom.Line2D)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Range (org.jfree.data.Range)3 FontMetrics (java.awt.FontMetrics)2 Stroke (java.awt.Stroke)2 AffineTransform (java.awt.geom.AffineTransform)2 Point2D (java.awt.geom.Point2D)2 RectangleAnchor (org.jfree.chart.api.RectangleAnchor)2 RectangleInsets (org.jfree.chart.api.RectangleInsets)2