Example usage for org.jfree.ui RectangleEdge isLeftOrRight

List of usage examples for org.jfree.ui RectangleEdge isLeftOrRight

Introduction

In this page you can find the example usage for org.jfree.ui RectangleEdge isLeftOrRight.

Prototype

public static boolean isLeftOrRight(final RectangleEdge edge) 

Source Link

Document

Returns true if the edge is LEFT or RIGHT, and false otherwise.

Usage

From source file:peakml.util.jfreechart.LognAxis.java

@Override
public double valueToJava2D(double value, Rectangle2D plotArea, RectangleEdge edge) {
    Range range = getRange();//from   w ww .j  a va2  s.com
    double axisMin = log(range.getLowerBound());
    double axisMax = log(range.getUpperBound());

    double min = 0.0, max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = plotArea.getMinX();
        max = plotArea.getMaxX();
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        min = plotArea.getMaxY();
        max = plotArea.getMinY();
    }

    value = log(value);
    if (isInverted())
        return max - (((value - axisMin) / (axisMax - axisMin)) * (max - min));
    else
        return min + (((value - axisMin) / (axisMax - axisMin)) * (max - min));
}

From source file:peakml.util.jfreechart.LognAxis.java

@Override
public double java2DToValue(double java2DValue, Rectangle2D plotArea, RectangleEdge edge) {
    Range range = getRange();//from w  w  w .  ja v  a 2  s.c  o m
    double axisMin = log(range.getLowerBound());
    double axisMax = log(range.getUpperBound());

    double min = 0.0, max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = plotArea.getX();
        max = plotArea.getMaxX();
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        min = plotArea.getMaxY();
        max = plotArea.getMinY();
    }

    if (isInverted())
        return pow(axisMax - ((java2DValue - min) / (max - min)) * (axisMax - axisMin));
    else
        return pow(axisMin + ((java2DValue - min) / (max - min)) * (axisMax - axisMin));
}

From source file:org.fhaes.fhrecorder.util.NumericCategoryAxis.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override//  www  . ja  va2 s  . co m
public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {

    List ticks = new java.util.ArrayList();

    // sanity check for data area...
    if (dataArea.getHeight() <= 0.0 || dataArea.getWidth() < 0.0) {
        return ticks;
    }

    CategoryPlot plot = (CategoryPlot) getPlot();
    List categories = plot.getCategoriesForAxis(this);
    double max = 0.0;

    if (categories != null) {
        CategoryLabelPosition position = this.getCategoryLabelPositions().getLabelPosition(edge);
        float r = this.getMaximumCategoryLabelWidthRatio();
        if (r <= 0.0) {
            r = position.getWidthRatio();
        }

        float l = 0.0f;
        if (position.getWidthType() == CategoryLabelWidthType.CATEGORY) {
            l = (float) calculateCategorySize(categories.size(), dataArea, edge);
        } else {
            if (RectangleEdge.isLeftOrRight(edge)) {
                l = (float) dataArea.getWidth();
            } else {
                l = (float) dataArea.getHeight();
            }
        }
        int categoryIndex = 0;
        Iterator iterator = categories.iterator();
        while (iterator.hasNext()) {
            Comparable category = (Comparable) iterator.next();

            try {
                Integer intcategory = Integer.valueOf(category.toString());

                int modulus = intcategory % labelEveryXCategories;

                if (modulus != 0)
                    category = " ";

            } catch (NumberFormatException e) {

            }

            TextBlock label = createLabel(category, l * r, edge, g2);
            if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) {
                max = Math.max(max, calculateTextBlockHeight(label, position, g2));
            } else if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
                max = Math.max(max, calculateTextBlockWidth(label, position, g2));
            }
            Tick tick = new CategoryTick(category, label, position.getLabelAnchor(),
                    position.getRotationAnchor(), position.getAngle());
            ticks.add(tick);
            categoryIndex = categoryIndex + 1;
        }
    }
    state.setMax(max);
    return ticks;
}

From source file:org.jfree.eastwood.GCategoryAxis.java

/**
 * Creates a temporary list of ticks that can be used when drawing the axis.
 *
 * @param g2  the graphics device (used to get font measurements).
 * @param state  the axis state./*from   w  ww. j  a  v  a 2  s  .c om*/
 * @param dataArea  the area inside the axes.
 * @param edge  the location of the axis.
 *
 * @return A list of ticks.
 */
public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {

    List ticks = new java.util.ArrayList();

    // sanity check for data area...
    if (dataArea.getHeight() <= 0.0 || dataArea.getWidth() < 0.0) {
        return ticks;
    }

    CategoryPlot plot = (CategoryPlot) getPlot();
    List categories = null;
    if (this.labels == null) {
        categories = plot.getCategories();
    } else {
        categories = new java.util.ArrayList(this.labels);
        // handle a little quirk in the Google Chart API - for a horizontal
        // bar chart, the labels on the axis get applied in reverse order
        // relative to the data values
        if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
            Collections.reverse(categories);
        }
    }
    double max = 0.0;

    if (categories != null) {
        CategoryLabelPosition position = getCategoryLabelPositions().getLabelPosition(edge);
        float r = getMaximumCategoryLabelWidthRatio();
        if (r <= 0.0) {
            r = position.getWidthRatio();
        }

        float l = 0.0f;
        if (position.getWidthType() == CategoryLabelWidthType.CATEGORY) {
            l = (float) calculateCategorySize(categories.size(), dataArea, edge);
        } else {
            if (RectangleEdge.isLeftOrRight(edge)) {
                l = (float) dataArea.getWidth();
            } else {
                l = (float) dataArea.getHeight();
            }
        }
        int categoryIndex = 0;
        Iterator iterator = categories.iterator();
        while (iterator.hasNext()) {
            Comparable category = (Comparable) iterator.next();
            TextBlock label = createLabel(category, l * r, edge, g2);
            if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) {
                max = Math.max(max, calculateTextBlockHeight(label, position, g2));
            } else if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
                max = Math.max(max, calculateTextBlockWidth(label, position, g2));
            }
            Tick tick = new CategoryTick(category, label, position.getLabelAnchor(),
                    position.getRotationAnchor(), position.getAngle());
            ticks.add(tick);
            categoryIndex = categoryIndex + 1;
        }
    }
    state.setMax(max);
    return ticks;

}

From source file:com.newatlanta.bluedragon.CategoryAxis.java

public AxisSpace reserveSpace(Graphics2D g2, Plot plot, Rectangle2D plotArea, RectangleEdge edge,
        AxisSpace space) {/*from ww w .j a  v  a 2  s  .c  o m*/

    // create a new space object if one wasn't supplied...
    if (space == null) {
        space = new AxisSpace();
    }

    // if the axis is not visible, no additional space is required...
    if (!isVisible()) {
        return space;
    }

    // calculate the max size of the tick labels (if visible)...
    double tickLabelHeight = 0.0;
    double tickLabelWidth = 0.0;
    if (isTickLabelsVisible()) {
        g2.setFont(getTickLabelFont());
        AxisState state = new AxisState();
        // we call refresh ticks just to get the maximum width or height
        if (RectangleEdge.isTopOrBottom(edge)) {
            // BEGIN fix for category labels that wrap
            // If space has been reserved to the left and right then we need to
            // reduce the plot area
            // by this amount so that the space needed by category labels that wrap
            // on to multiple lines
            // will be calculated properly.
            Rectangle2D newPlotArea = new Rectangle2D.Double(plotArea.getX(), plotArea.getY(),
                    plotArea.getWidth() - space.getLeft() - space.getRight(), plotArea.getHeight());
            refreshTicks(g2, state, newPlotArea, edge);
            // END fix for category labels that wrap
        } else {
            refreshTicks(g2, state, plotArea, edge);
        }
        if (edge == RectangleEdge.TOP) {
            tickLabelHeight = state.getMax();
        } else if (edge == RectangleEdge.BOTTOM) {
            tickLabelHeight = state.getMax();
        } else if (edge == RectangleEdge.LEFT) {
            tickLabelWidth = state.getMax();
        } else if (edge == RectangleEdge.RIGHT) {
            tickLabelWidth = state.getMax();
        }
    }

    // get the axis label size and update the space object...
    Rectangle2D labelEnclosure = getLabelEnclosure(g2, edge);
    double labelHeight = 0.0;
    double labelWidth = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        labelHeight = labelEnclosure.getHeight();
        space.add(labelHeight + tickLabelHeight + this.getCategoryLabelPositionOffset(), edge);
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        labelWidth = labelEnclosure.getWidth();
        space.add(labelWidth + tickLabelWidth + this.getCategoryLabelPositionOffset(), edge);
    }
    return space;

}

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

/**
 * Translates the data value to the display coordinates (Java 2D User Space)
 * of the chart.//from  ww w . j ava 2 s. co  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;

}

From source file:org.jfree.experimental.chart.axis.LogAxis.java

/**
 * Converts a Java2D coordinate to an axis value, assuming that the
 * axis covers the specified <code>edge</code> of the <code>area</code>.
 * /*from   w  w  w .  j  av a2s  .  c  o m*/
 * @param java2DValue  the Java2D coordinate.
 * @param area  the area.
 * @param edge  the edge that the axis belongs to.
 * 
 * @return A value along the axis scale.
 */
public double java2DToValue(double java2DValue, Rectangle2D area, RectangleEdge edge) {

    Range range = getRange();
    double axisMin = calculateLog(range.getLowerBound());
    double axisMax = calculateLog(range.getUpperBound());

    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 log = 0.0;
    if (isInverted()) {
        log = axisMax - (java2DValue - min) / (max - min) * (axisMax - axisMin);
    } else {
        log = axisMin + (java2DValue - min) / (max - min) * (axisMax - axisMin);
    }
    return calculateValue(log);
}

From source file:org.jfree.experimental.chart.axis.LogAxis.java

/**
 * Converts a value on the axis scale to a Java2D coordinate relative to 
 * the given <code>area</code>, based on the axis running along the 
 * specified <code>edge</code>.
 * /*  ww  w  .  j a  v  a  2 s. c  o  m*/
 * @param value  the data value.
 * @param area  the area.
 * @param edge  the edge.
 * 
 * @return The Java2D coordinate corresponding to <code>value</code>.
 */
public double valueToJava2D(double value, Rectangle2D area, RectangleEdge edge) {

    Range range = getRange();
    double axisMin = calculateLog(range.getLowerBound());
    double axisMax = calculateLog(range.getUpperBound());
    value = calculateLog(value);

    double min = 0.0;
    double max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = area.getX();
        max = area.getMaxX();
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        max = area.getMinY();
        min = area.getMaxY();
    }
    if (isInverted()) {
        return max - ((value - axisMin) / (axisMax - axisMin)) * (max - min);
    } else {
        return min + ((value - axisMin) / (axisMax - axisMin)) * (max - min);
    }
}

From source file:org.jfree.experimental.chart.axis.LogAxis.java

/**
 * 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.// w  w w. ja  v a2s  .c  om
 * @param state  the axis state.
 * @param dataArea  the area in which the plot should be drawn.
 * @param edge  the location of the axis.
 * 
 * @return A list of ticks.
 *
 */
public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {

    List result = new java.util.ArrayList();
    if (RectangleEdge.isTopOrBottom(edge)) {
        result = refreshTicksHorizontal(g2, dataArea, edge);
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        result = refreshTicksVertical(g2, dataArea, edge);
    }
    return result;

}

From source file:org.gumtree.vis.plot1d.LogarithmizableAxis.java

/**
 * Converts a data value to a coordinate in Java2D space, assuming that
 * the axis runs along one edge of the specified plotArea.
 * Note that it is possible for the coordinate to fall outside the
 * plotArea./* w  w w.  j  av  a 2 s.c o m*/
 *
 * @param value  the data value.
 * @param plotArea  the area for plotting the data.
 * @param edge  the axis location.
 *
 * @return The Java2D coordinate.
 */
public double logValueToJava2D(double value, Rectangle2D plotArea, RectangleEdge edge) {

    Range range = getRange();
    double axisMin = switchedLog10(range.getLowerBound());
    double axisMax = switchedLog10(range.getUpperBound());

    double min = 0.0;
    double max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = plotArea.getMinX();
        max = plotArea.getMaxX();
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        min = plotArea.getMaxY();
        max = plotArea.getMinY();
    }

    value = switchedLog10(value);

    if (isInverted()) {
        return max - (((value - axisMin) / (axisMax - axisMin)) * (max - min));
    } else {
        return min + (((value - axisMin) / (axisMax - axisMin)) * (max - min));
    }

}