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

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

Introduction

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

Prototype

@Override
public double valueToJava2D(double value, Rectangle2D area, RectangleEdge edge) 

Source Link

Document

Translates the data value to the display coordinates (Java 2D User Space) of the chart.

Usage

From source file:ucar.unidata.idv.control.chart.TimeSeriesChart.java

/**
 * Draw the sunrise/sunset curves/*from   w  w w.  ja  v a  2s.com*/
 *
 * @param g2  the graphics area
 * @param plot   the plot
 * @param dataArea  the date range
 */
private void drawSunriseSunset(Graphics2D g2, XYPlot plot, Rectangle2D dataArea) {
    if (sunriseLocation == null) {
        return;
    }
    DateAxis domainAxis = (DateAxis) plot.getDomainAxis();
    Date startDate = ((DateAxis) domainAxis).getMinimumDate();
    Date endDate = ((DateAxis) domainAxis).getMaximumDate();
    if ((sunriseDates == null) || !Misc.equals(startDate, lastStartDate)
            || !Misc.equals(endDate, lastEndDate)) {
        lastStartDate = startDate;
        lastEndDate = endDate;
        sunriseDates = IdvTimeline.makeSunriseDates(sunriseLocation, startDate, endDate);
    }
    int top = (int) (dataArea.getY());
    int bottom = (int) (dataArea.getY() + dataArea.getHeight());
    int height = bottom - top;
    g2.setColor(Color.yellow);
    Shape originalClip = g2.getClip();
    g2.clip(dataArea);
    for (int i = 0; i < sunriseDates.size(); i += 2) {
        Date d1 = (Date) sunriseDates.get(i + 1);
        Date d2 = (Date) sunriseDates.get(i);
        int x1 = (int) domainAxis.valueToJava2D(d1.getTime(), dataArea, RectangleEdge.BOTTOM);
        int x2 = (int) domainAxis.valueToJava2D(d2.getTime(), dataArea, RectangleEdge.BOTTOM);
        g2.fillRect(x1, top, (x2 - x1), height);
    }
    g2.setClip(originalClip);
}