Search in sources :

Example 11 with TextAnchor

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

the class PolarPlot method refreshAngleTicks.

/**
 * Generates a list of tick values for the angular tick marks.
 *
 * @return A list of {@link NumberTick} instances.
 */
protected List<ValueTick> refreshAngleTicks() {
    List<ValueTick> ticks = new ArrayList<>();
    for (double currentTickVal = 0.0; currentTickVal < 360.0; currentTickVal += this.angleTickUnit.getSize()) {
        TextAnchor ta = calculateTextAnchor(currentTickVal);
        NumberTick tick = new NumberTick(currentTickVal, this.angleTickUnit.valueToString(currentTickVal), ta, TextAnchor.CENTER, 0.0);
        ticks.add(tick);
    }
    return ticks;
}
Also used : ValueTick(org.jfree.chart.axis.ValueTick) TextAnchor(org.jfree.chart.text.TextAnchor) NumberTick(org.jfree.chart.axis.NumberTick) ArrayList(java.util.ArrayList)

Example 12 with TextAnchor

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

the class CategoryTickTest method testHashCode.

/**
 * Two objects that are equal are required to return the same hashCode.
 */
@Test
public void testHashCode() {
    Comparable<String> c1 = "C1";
    TextBlock tb1 = new TextBlock();
    tb1.addLine(new TextLine("Block 1"));
    tb1.addLine(new TextLine("Block 2"));
    TextBlockAnchor tba1 = TextBlockAnchor.CENTER;
    TextAnchor ta1 = TextAnchor.CENTER;
    CategoryTick t1 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
    CategoryTick t2 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
    assertEquals(t1, t2);
    int h1 = t1.hashCode();
    int h2 = t2.hashCode();
    assertEquals(h1, h2);
}
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 13 with TextAnchor

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

the class LogAxis method refreshTicksHorizontal.

/**
 * Returns a list of ticks for an axis at the top or bottom of the chart.
 *
 * @param g2  the graphics device ({@code null} not permitted).
 * @param dataArea  the data area ({@code null} not permitted).
 * @param edge  the edge ({@code null} not permitted).
 *
 * @return A list of ticks.
 */
protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    Range range = getRange();
    List ticks = new ArrayList();
    Font tickLabelFont = getTickLabelFont();
    g2.setFont(tickLabelFont);
    TextAnchor textAnchor;
    if (edge == RectangleEdge.TOP) {
        textAnchor = TextAnchor.BOTTOM_CENTER;
    } else {
        textAnchor = TextAnchor.TOP_CENTER;
    }
    if (isAutoTickUnitSelection()) {
        selectAutoTickUnit(g2, dataArea, edge);
    }
    int minorTickCount = this.tickUnit.getMinorTickCount();
    double unit = getTickUnit().getSize();
    double index = Math.ceil(calculateLog(getRange().getLowerBound()) / unit);
    double start = index * unit;
    double end = calculateLog(getUpperBound());
    double current = start;
    boolean hasTicks = (this.tickUnit.getSize() > 0.0) && !Double.isInfinite(start);
    while (hasTicks && current <= end) {
        double v = calculateValueNoINF(current);
        if (range.contains(v)) {
            ticks.add(new LogTick(TickType.MAJOR, v, createTickLabel(v), textAnchor));
        }
        // add minor ticks (for gridlines)
        double next = Math.pow(this.base, current + this.tickUnit.getSize());
        for (int i = 1; i < minorTickCount; i++) {
            double minorV = v + i * ((next - v) / minorTickCount);
            if (range.contains(minorV)) {
                ticks.add(new LogTick(TickType.MINOR, minorV, null, textAnchor));
            }
        }
        current = current + this.tickUnit.getSize();
    }
    return ticks;
}
Also used : TextAnchor(org.jfree.chart.text.TextAnchor) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Range(org.jfree.data.Range) Font(java.awt.Font)

Example 14 with TextAnchor

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

the class LogarithmicAxis method refreshTicksHorizontal.

/**
 * Calculates the positions of the tick labels for the axis, storing the
 * results in the tick label list (ready for drawing).
 *
 * @param g2  the graphics device.
 * @param dataArea  the area in which the plot should be drawn.
 * @param edge  the location of the axis.
 *
 * @return A list of ticks.
 */
@Override
protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    List ticks = new java.util.ArrayList();
    Range range = getRange();
    // get lower bound value:
    double lowerBoundVal = range.getLowerBound();
    // then set to a small value (don't allow <= 0):
    if (this.smallLogFlag && lowerBoundVal < SMALL_LOG_VALUE) {
        lowerBoundVal = SMALL_LOG_VALUE;
    }
    // get upper bound value
    double upperBoundVal = range.getUpperBound();
    // get log10 version of lower bound and round to integer:
    int iBegCount = (int) Math.rint(switchedLog10(lowerBoundVal));
    // get log10 version of upper bound and round to integer:
    int iEndCount = (int) Math.rint(switchedLog10(upperBoundVal));
    if (iBegCount == iEndCount && iBegCount > 0 && Math.pow(10, iBegCount) > lowerBoundVal) {
        // only 1 power of 10 value, it's > 0 and its resulting
        // tick value will be larger than lower bound of data
        // decrement to generate more ticks
        --iBegCount;
    }
    double currentTickValue;
    String tickLabel;
    boolean zeroTickFlag = false;
    for (int i = iBegCount; i <= iEndCount; i++) {
        // for each power of 10 value; create ten ticks
        for (int j = 0; j < 10; ++j) {
            // for each tick to be displayed
            if (this.smallLogFlag) {
                // small log values in use; create numeric value for tick
                currentTickValue = Math.pow(10, i) + (Math.pow(10, i) * j);
                if (this.expTickLabelsFlag || (i < 0 && currentTickValue > 0.0 && currentTickValue < 1.0)) {
                    // generating tick value between 0 & 1; show fewer
                    if (j == 0 || (i > -4 && j < 2) || currentTickValue >= upperBoundVal) {
                        // first tick of series, or not too small a value and
                        // one of first 3 ticks, or last tick to be displayed
                        // set exact number of fractional digits to be shown
                        // (no effect if showing "1e#"-style ticks):
                        this.numberFormatterObj.setMaximumFractionDigits(-i);
                        // create tick label (force use of fmt obj):
                        tickLabel = makeTickLabel(currentTickValue, true);
                    } else {
                        // no tick label to be shown
                        tickLabel = "";
                    }
                } else {
                    // tick value not between 0 & 1
                    // show tick label if it's the first or last in
                    // the set, or if it's 1-5; beyond that show
                    // fewer as the values get larger:
                    tickLabel = (j < 1 || (i < 1 && j < 5) || (j < 4 - i) || currentTickValue >= upperBoundVal) ? makeTickLabel(currentTickValue) : "";
                }
            } else {
                // not small log values in use; allow for values <= 0
                if (zeroTickFlag) {
                    // if did zero tick last iter then
                    // decrement to do 1.0 tick now
                    --j;
                }
                // calculate power-of-ten value for tick:
                currentTickValue = (i >= 0) ? Math.pow(10, i) + (Math.pow(10, i) * j) : -(Math.pow(10, -i) - (Math.pow(10, -i - 1) * j));
                if (!zeroTickFlag) {
                    // did not do zero tick last iteration
                    if (Math.abs(currentTickValue - 1.0) < 0.0001 && lowerBoundVal <= 0.0 && upperBoundVal >= 0.0) {
                        // tick value is 1.0 and 0.0 is within data range
                        // set tick value to zero
                        currentTickValue = 0.0;
                        // indicate zero tick
                        zeroTickFlag = true;
                    }
                } else {
                    // did zero tick last iteration
                    // clear flag
                    zeroTickFlag = false;
                }
                // create tick label string:
                // show tick label if "1e#"-style and it's one
                // of the first two, if it's the first or last
                // in the set, or if it's 1-5; beyond that
                // show fewer as the values get larger:
                tickLabel = ((this.expTickLabelsFlag && j < 2) || j < 1 || (i < 1 && j < 5) || (j < 4 - i) || currentTickValue >= upperBoundVal) ? makeTickLabel(currentTickValue) : "";
            }
            if (currentTickValue > upperBoundVal) {
                // if past highest data value then exit
                return ticks;
            // method
            }
            if (currentTickValue >= lowerBoundVal - SMALL_LOG_VALUE) {
                // tick value not below lowest data value
                TextAnchor anchor;
                TextAnchor rotationAnchor;
                double angle = 0.0;
                if (isVerticalTickLabels()) {
                    anchor = TextAnchor.CENTER_RIGHT;
                    rotationAnchor = TextAnchor.CENTER_RIGHT;
                    if (edge == RectangleEdge.TOP) {
                        angle = Math.PI / 2.0;
                    } else {
                        angle = -Math.PI / 2.0;
                    }
                } else {
                    if (edge == RectangleEdge.TOP) {
                        anchor = TextAnchor.BOTTOM_CENTER;
                        rotationAnchor = TextAnchor.BOTTOM_CENTER;
                    } else {
                        anchor = TextAnchor.TOP_CENTER;
                        rotationAnchor = TextAnchor.TOP_CENTER;
                    }
                }
                Tick tick = new NumberTick(currentTickValue, tickLabel, anchor, rotationAnchor, angle);
                ticks.add(tick);
            }
        }
    }
    return ticks;
}
Also used : TextAnchor(org.jfree.chart.text.TextAnchor) List(java.util.List) Range(org.jfree.data.Range)

Example 15 with TextAnchor

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

the class NumberAxis method refreshTicksHorizontal.

/**
 * Calculates the positions of the tick labels for the axis, storing the
 * results in the tick label list (ready for drawing).
 *
 * @param g2  the graphics device.
 * @param dataArea  the area in which the data should be drawn.
 * @param edge  the location of the axis.
 *
 * @return A list of ticks.
 */
protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    List result = new java.util.ArrayList();
    Font tickLabelFont = getTickLabelFont();
    g2.setFont(tickLabelFont);
    if (isAutoTickUnitSelection()) {
        selectAutoTickUnit(g2, dataArea, edge);
    }
    TickUnit tu = getTickUnit();
    double size = tu.getSize();
    int count = calculateVisibleTickCount();
    double lowestTickValue = calculateLowestVisibleTickValue();
    if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {
        int minorTickSpaces = getMinorTickCount();
        if (minorTickSpaces <= 0) {
            minorTickSpaces = tu.getMinorTickCount();
        }
        for (int minorTick = 1; minorTick < minorTickSpaces; minorTick++) {
            double minorTickValue = lowestTickValue - size * minorTick / minorTickSpaces;
            if (getRange().contains(minorTickValue)) {
                result.add(new NumberTick(TickType.MINOR, minorTickValue, "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0));
            }
        }
        for (int i = 0; i < count; i++) {
            double currentTickValue = lowestTickValue + (i * size);
            String tickLabel;
            NumberFormat formatter = getNumberFormatOverride();
            if (formatter != null) {
                tickLabel = formatter.format(currentTickValue);
            } else {
                tickLabel = getTickUnit().valueToString(currentTickValue);
            }
            TextAnchor anchor, rotationAnchor;
            double angle = 0.0;
            if (isVerticalTickLabels()) {
                anchor = TextAnchor.CENTER_RIGHT;
                rotationAnchor = TextAnchor.CENTER_RIGHT;
                if (edge == RectangleEdge.TOP) {
                    angle = Math.PI / 2.0;
                } else {
                    angle = -Math.PI / 2.0;
                }
            } else {
                if (edge == RectangleEdge.TOP) {
                    anchor = TextAnchor.BOTTOM_CENTER;
                    rotationAnchor = TextAnchor.BOTTOM_CENTER;
                } else {
                    anchor = TextAnchor.TOP_CENTER;
                    rotationAnchor = TextAnchor.TOP_CENTER;
                }
            }
            Tick tick = new NumberTick(currentTickValue, tickLabel, anchor, rotationAnchor, angle);
            result.add(tick);
            double nextTickValue = lowestTickValue + ((i + 1) * size);
            for (int minorTick = 1; minorTick < minorTickSpaces; minorTick++) {
                double minorTickValue = currentTickValue + (nextTickValue - currentTickValue) * minorTick / minorTickSpaces;
                if (getRange().contains(minorTickValue)) {
                    result.add(new NumberTick(TickType.MINOR, minorTickValue, "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0));
                }
            }
        }
    }
    return result;
}
Also used : TextAnchor(org.jfree.chart.text.TextAnchor) List(java.util.List) Font(java.awt.Font) NumberFormat(java.text.NumberFormat)

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