Example usage for org.jfree.chart.axis DateAxis getLowerBound

List of usage examples for org.jfree.chart.axis DateAxis getLowerBound

Introduction

In this page you can find the example usage for org.jfree.chart.axis DateAxis getLowerBound.

Prototype

public double getLowerBound() 

Source Link

Document

Returns the lower bound of the axis range.

Usage

From source file:MWC.GUI.JFreeChart.StepperXYPlot.java

/**
 * Draws the XY plot on a Java 2D graphics device (such as the screen or a
 * printer), together with a current time marker
 * <P>/* w  w  w.  j ava 2s. co  m*/
 * XYPlot relies on an XYItemRenderer to draw each item in the plot. This
 * allows the visual representation of the data to be changed easily.
 * <P>
 * The optional info argument collects information about the rendering of the
 * plot (dimensions, tooltip information etc). Just pass in null if you do not
 * need this information.
 * 
 * @param g2
 *          The graphics device.
 * @param plotArea
 *          The area within which the plot (including axis labels) should be
 *          drawn.
 * @param info
 *          Collects chart drawing information (null permitted).
 */
public final void draw(final Graphics2D g2, final Rectangle2D plotArea, final Point2D anchor,
        final PlotState state, final PlotRenderingInfo info) {
    super.draw(g2, plotArea, anchor, state, info);

    // do we want to view the line?
    if (!_showLine)
        return;

    // do we have a time?
    if (_currentTime != null) {
        // find the screen area for the dataset
        final Rectangle2D dataArea = info.getDataArea();

        // determine the time we are plotting the line at
        long theTime = _currentTime.getMicros();

        // hmmm, how do we format the date
        final CanBeRelativeToTimeStepper axis = (CanBeRelativeToTimeStepper) this.getDomainAxis();

        // are we working in relative time mode?
        if (axis.isRelativeTimes()) {
            if (_myStepper != null) {
                // yes, we now need to offset the time
                theTime = theTime - _myStepper.getTimeZero().getMicros();
            }
        }

        // hmm, see if we are wroking with a date or number axis
        double linePosition = 0;
        if (axis instanceof DateAxis) {
            // ok, now scale the time to graph units
            final DateAxis dateAxis = (DateAxis) axis;

            // find the new x value
            linePosition = dateAxis.dateToJava2D(new Date(theTime / 1000), dataArea, this.getDomainAxisEdge());

            if (_resetAxes) {
                dateAxis.setAutoRange(true);
                _resetAxes = false;
            }

            if (isGrowWithTime()) {
                final long endMillis = theTime / 1000;
                long startMillis;

                if (_fixedDuration != null) {
                    startMillis = endMillis - _fixedDuration.getMillis();
                } else {
                    startMillis = (long) dateAxis.getLowerBound();
                }

                final Date startDate = new Date(startMillis);
                final Date endDate = new Date(endMillis);

                dateAxis.setRange(startDate, endDate);
            } else {
            }

        } else {
            if (axis instanceof NumberAxis) {
                final NumberAxis numberAxis = (NumberAxis) axis;
                linePosition = numberAxis.valueToJava2D(theTime, dataArea, this.getDomainAxisEdge());

                if (isGrowWithTime())
                    numberAxis.setRange(numberAxis.getRange().getLowerBound(), theTime);
                else {
                    if (_resetAxes) {
                        numberAxis.setAutoRange(true);
                        _resetAxes = false;
                    }
                }

            }
        }

        // ok, finally draw the line - if we're not showing the growing plot
        if (!isGrowWithTime())
            plotStepperLine(g2, linePosition, dataArea);

    }
}