Search in sources :

Example 11 with DateRange

use of org.jfree.data.time.DateRange in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class DateAxis method java2DToValue.

/**
 * Translates a Java2D coordinate into the corresponding data value.  To
 * perform this translation, you need to know the area used for plotting
 * data, and which edge the axis is located on.
 *
 * @param java2DValue  the coordinate in Java2D space.
 * @param area  the rectangle (in Java2D space) where the data is to be
 *              plotted.
 * @param edge  the axis location.
 *
 * @return A data value.
 */
@Override
public double java2DToValue(double java2DValue, Rectangle2D area, RectangleEdge edge) {
    DateRange range = (DateRange) getRange();
    double axisMin = this.timeline.toTimelineValue(range.getLowerMillis());
    double axisMax = this.timeline.toTimelineValue(range.getUpperMillis());
    double min = 0.0;
    double max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = area.getX();
        max = area.getMaxX();
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        min = area.getMaxY();
        max = area.getY();
    }
    double result;
    if (isInverted()) {
        result = axisMax - ((java2DValue - min) / (max - min) * (axisMax - axisMin));
    } else {
        result = axisMin + ((java2DValue - min) / (max - min) * (axisMax - axisMin));
    }
    return this.timeline.toMillisecond((long) result);
}
Also used : DateRange(org.jfree.data.time.DateRange)

Example 12 with DateRange

use of org.jfree.data.time.DateRange 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)

Example 13 with DateRange

use of org.jfree.data.time.DateRange in project seng438-a3-R41Ryan by seng438-winter-2022.

the class DateAxis method setMinimumDate.

/**
 * Sets the minimum date visible on the axis and sends an
 * {@link AxisChangeEvent} to all registered listeners.  If
 * <code>date</code> is on or after the current maximum date for
 * the axis, the maximum date will be shifted to preserve the current
 * length of the axis.
 *
 * @param date  the date (<code>null</code> not permitted).
 *
 * @see #getMinimumDate()
 * @see #setMaximumDate(Date)
 */
public void setMinimumDate(Date date) {
    ParamChecks.nullNotPermitted(date, "date");
    // check the new minimum date relative to the current maximum date
    Date maxDate = getMaximumDate();
    long maxMillis = maxDate.getTime();
    long newMinMillis = date.getTime();
    if (maxMillis <= newMinMillis) {
        Date oldMin = getMinimumDate();
        long length = maxMillis - oldMin.getTime();
        maxDate = new Date(newMinMillis + length);
    }
    setRange(new DateRange(date, maxDate), true, false);
    fireChangeEvent();
}
Also used : DateRange(org.jfree.data.time.DateRange) Date(java.util.Date)

Example 14 with DateRange

use of org.jfree.data.time.DateRange in project seng438-a3-R41Ryan by seng438-winter-2022.

the class DateAxis method setRange.

/**
 * Sets the range for the axis, if requested, sends an
 * {@link AxisChangeEvent} to all registered listeners.  As a side-effect,
 * the auto-range flag is set to <code>false</code> (optional).
 *
 * @param range  the range (<code>null</code> not permitted).
 * @param turnOffAutoRange  a flag that controls whether or not the auto
 *                          range is turned off.
 * @param notify  a flag that controls whether or not listeners are
 *                notified.
 */
@Override
public void setRange(Range range, boolean turnOffAutoRange, boolean notify) {
    ParamChecks.nullNotPermitted(range, "range");
    // conversion...
    if (!(range instanceof DateRange)) {
        range = new DateRange(range);
    }
    super.setRange(range, turnOffAutoRange, notify);
}
Also used : DateRange(org.jfree.data.time.DateRange)

Example 15 with DateRange

use of org.jfree.data.time.DateRange in project seng438-a3-R41Ryan by seng438-winter-2022.

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.ui.RectangleInsets) FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics) Font(java.awt.Font) Date(java.util.Date)

Aggregations

DateRange (org.jfree.data.time.DateRange)39 Date (java.util.Date)24 Range (org.jfree.data.Range)13 Font (java.awt.Font)7 FontMetrics (java.awt.FontMetrics)6 FontRenderContext (java.awt.font.FontRenderContext)6 LineMetrics (java.awt.font.LineMetrics)6 DateFormat (java.text.DateFormat)6 SimpleDateFormat (java.text.SimpleDateFormat)6 RectangleInsets (org.jfree.ui.RectangleInsets)4 Plot (org.jfree.chart.plot.Plot)3 ValueAxisPlot (org.jfree.chart.plot.ValueAxisPlot)3 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 RectangleInsets (org.jfree.chart.api.RectangleInsets)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 TransferStatus (com.tesshu.jpsonic.domain.TransferStatus)1 BoundedDateAxis (fr.jmmc.oiexplorer.core.gui.chart.BoundedDateAxis)1 BasicStroke (java.awt.BasicStroke)1