Example usage for org.jfree.chart.axis Timeline toTimelineValue

List of usage examples for org.jfree.chart.axis Timeline toTimelineValue

Introduction

In this page you can find the example usage for org.jfree.chart.axis Timeline toTimelineValue.

Prototype

long toTimelineValue(Date date);

Source Link

Document

Translates a date into a value on this timeline.

Usage

From source file:figs.treeVisualization.gui.PhyloDateAxis.java

/**
 * Translates the data value to the display coordinates (Java 2D User Space)
 * of the chart.// w ww . ja va 2 s  .  c o m
 *
 * @param value  the date to be plotted.
 * @param area  the rectangle (in Java2D space) where the data is to be 
 *              plotted.
 * @param edge  the axis location.
 *
 * @return The coordinate corresponding to the supplied data value.
 * 
 * Original method is in <code>org.jfree.chart.axis.DateAxis</code>
 */
@Override
public double valueToJava2D(double value, Rectangle2D area, RectangleEdge edge) {

    Timeline timeline = this.getTimeline();
    value = timeline.toTimelineValue((long) value);

    DateRange range = (DateRange) getRange();
    double axisMin = timeline.toTimelineValue(range.getLowerDate());
    double axisMax = timeline.toTimelineValue(range.getUpperDate());
    double result = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        double minX = area.getX();
        double maxX = area.getMaxX();
        if (isInverted()) {
            result = maxX + ((value - axisMin) / (axisMax - axisMin)) * (minX - maxX);
        } else {
            result = minX + ((value - axisMin) / (axisMax - axisMin)) * (maxX - minX);
        }
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        //double minY = area.getMinY();
        //double maxY = area.getMaxY();
        double minY = area.getY();
        double maxY = area.getHeight();
        if (isInverted()) {
            result = minY + (((value - axisMin) / (axisMax - axisMin)) * (maxY - minY));
        } else {
            result = maxY - (((value - axisMin) / (axisMax - axisMin)) * (maxY - minY));
        }
    }
    return result;

}