Java Code Examples for org.jfree.ui.RectangleEdge#isLeftOrRight()

The following examples show how to use org.jfree.ui.RectangleEdge#isLeftOrRight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SubCategoryAxis.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the maximum of the relevant dimension (height or width) of the
 * subcategory labels.
 *
 * @param g2  the graphics device.
 * @param edge  the edge.
 *
 * @return The maximum dimension.
 */
private double getMaxDim(Graphics2D g2, RectangleEdge edge) {
    double result = 0.0;
    g2.setFont(this.subLabelFont);
    FontMetrics fm = g2.getFontMetrics();
    Iterator iterator = this.subCategories.iterator();
    while (iterator.hasNext()) {
        Comparable subcategory = (Comparable) iterator.next();
        String label = subcategory.toString();
        Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm);
        double dim;
        if (RectangleEdge.isLeftOrRight(edge)) {
            dim = bounds.getWidth();
        }
        else {  // must be top or bottom
            dim = bounds.getHeight();
        }
        result = Math.max(result, dim);
    }
    return result;
}
 
Example 2
Source File: ModuloAxis.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a length in data coordinates into the corresponding length in 
 * Java2D coordinates.
 * 
 * @param length  the length.
 * @param area  the plot area.
 * @param edge  the edge along which the axis lies.
 * 
 * @return The length in Java2D coordinates.
 */
public double lengthToJava2D(double length, Rectangle2D area, 
                             RectangleEdge edge) {
    double axisLength = 0.0;
    if (this.displayEnd > this.displayStart) {
        axisLength = this.displayEnd - this.displayStart;
    }
    else {
        axisLength = (this.fixedRange.getUpperBound() - this.displayStart) 
            + (this.displayEnd - this.fixedRange.getLowerBound());
    }
    double areaLength = 0.0;
    if (RectangleEdge.isLeftOrRight(edge)) {
        areaLength = area.getHeight();
    }
    else {
        areaLength = area.getWidth();
    }
    return (length / axisLength) * areaLength;
}
 
Example 3
Source File: DateAxis.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * 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.
 * @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 = null;
    if (RectangleEdge.isTopOrBottom(edge)) {
        result = refreshTicksHorizontal(g2, dataArea, edge);
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        result = refreshTicksVertical(g2, dataArea, edge);
    }
    return result;

}
 
Example 4
Source File: ModuloAxis.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a length in data coordinates into the corresponding length in
 * Java2D coordinates.
 *
 * @param length  the length.
 * @param area  the plot area.
 * @param edge  the edge along which the axis lies.
 *
 * @return The length in Java2D coordinates.
 */
@Override
public double lengthToJava2D(double length, Rectangle2D area,
                             RectangleEdge edge) {
    double axisLength = 0.0;
    if (this.displayEnd > this.displayStart) {
        axisLength = this.displayEnd - this.displayStart;
    }
    else {
        axisLength = (this.fixedRange.getUpperBound() - this.displayStart)
            + (this.displayEnd - this.fixedRange.getLowerBound());
    }
    double areaLength;
    if (RectangleEdge.isLeftOrRight(edge)) {
        areaLength = area.getHeight();
    }
    else {
        areaLength = area.getWidth();
    }
    return (length / axisLength) * areaLength;
}
 
Example 5
Source File: DateAxis.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * 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.
 */
public double java2DToValue(double java2DValue, Rectangle2D area, 
                            RectangleEdge edge) {
    
    DateRange range = (DateRange) getRange();
    double axisMin = this.timeline.toTimelineValue(range.getLowerDate());
    double axisMax = this.timeline.toTimelineValue(range.getUpperDate());

    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); 
}
 
Example 6
Source File: LogAxis.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts a value on the axis scale to a Java2D coordinate relative to
 * the given {@code area}, based on the axis running along the
 * specified {@code edge}.
 *
 * @param value  the data value.
 * @param area  the area ({@code null} not permitted).
 * @param edge  the edge ({@code null} not permitted).
 *
 * @return The Java2D coordinate corresponding to {@code value}.
 */
@Override
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);
    }
}
 
Example 7
Source File: DateAxis.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Translates the data value to the display coordinates (Java 2D User Space)
 * of the chart.
 *
 * @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.
 */
@Override
public double valueToJava2D(double value, Rectangle2D area,
        RectangleEdge edge) {

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

    DateRange range = (DateRange) getRange();
    double axisMin = this.timeline.toTimelineValue(range.getLowerMillis());
    double axisMax = this.timeline.toTimelineValue(range.getUpperMillis());
    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();
        if (isInverted()) {
            result = minY + (((value - axisMin) / (axisMax - axisMin))
                     * (maxY - minY));
        }
        else {
            result = maxY - (((value - axisMin) / (axisMax - axisMin))
                     * (maxY - minY));
        }
    }
    return result;
}
 
Example 8
Source File: NumberAxis.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts a coordinate in Java2D space to the corresponding data value,
 * assuming that the axis runs along one edge of the specified dataArea.
 *
 * @param java2DValue  the coordinate in Java2D space.
 * @param area  the area in which the data is plotted.
 * @param edge  the location.
 *
 * @return The data value.
 *
 * @see #valueToJava2D(double, Rectangle2D, RectangleEdge)
 */
@Override
public double java2DToValue(double java2DValue, Rectangle2D area,
        RectangleEdge edge) {

    Range range = getRange();
    double axisMin = range.getLowerBound();
    double axisMax = 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();
    }
    if (isInverted()) {
        return axisMax
               - (java2DValue - min) / (max - min) * (axisMax - axisMin);
    }
    else {
        return axisMin
               + (java2DValue - min) / (max - min) * (axisMax - axisMin);
    }

}
 
Example 9
Source File: PeriodAxis.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a coordinate in Java2D space to the corresponding data value,
 * assuming that the axis runs along one edge of the specified dataArea.
 *
 * @param java2DValue  the coordinate in Java2D space.
 * @param area  the area in which the data is plotted.
 * @param edge  the edge along which the axis lies.
 *
 * @return The data value.
 */
public double java2DToValue(double java2DValue,
                            Rectangle2D area,
                            RectangleEdge edge) {

    double result = Double.NaN;
    double min = 0.0;
    double max = 0.0;
    double axisMin = this.first.getFirstMillisecond(this.calendar);
    double axisMax = this.last.getLastMillisecond(this.calendar);
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = area.getX();
        max = area.getMaxX();
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        min = area.getMaxY();
        max = area.getY();
    }
    if (isInverted()) {
         result = axisMax - ((java2DValue - min) / (max - min) 
                  * (axisMax - axisMin));
    }
    else {
         result = axisMin + ((java2DValue - min) / (max - min) 
                  * (axisMax - axisMin));
    }
    return result;
}
 
Example 10
Source File: ModuloAxis.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Translates a data value to a Java2D value for the first section of the 
 * axis.
 * 
 * @param value  the value.
 * @param area  the data area.
 * @param edge  the edge along which the axis lies.
 * @param length1  the length of the first section.
 * @param length2  the length of the second section.
 * 
 * @return The Java2D coordinate.
 */
private double transStart(double value, Rectangle2D area, 
                          RectangleEdge edge,
                          double length1, double length2) {
    double min = 0.0;
    double max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = area.getX();
        max = area.getX() + area.getWidth() * length1 / (length1 + length2);
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        min = area.getMaxY();
        max = area.getMaxY() - area.getHeight() * length1 
              / (length1 + length2);
    }
    if (isInverted()) {
        return max - ((value - this.displayStart) 
            / (this.fixedRange.getUpperBound() - this.displayStart)) 
            * (max - min);
    }
    else {
        return min + ((value - this.displayStart) 
            / (this.fixedRange.getUpperBound() - this.displayStart)) 
            * (max - min);
    }

}
 
Example 11
Source File: NumberAxis.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 * @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.
 */
@Override
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;

}
 
Example 12
Source File: DateAxis.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 * @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.
 */
@Override
public List refreshTicks(Graphics2D g2, AxisState state, 
        Rectangle2D dataArea, RectangleEdge edge) {

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

}
 
Example 13
Source File: LogarithmicAxis.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a coordinate in Java2D space to the corresponding data
 * value, assuming that the axis runs along one edge of the specified
 * plotArea.
 *
 * @param java2DValue  the coordinate in Java2D space.
 * @param plotArea  the area in which the data is plotted.
 * @param edge  the axis location.
 *
 * @return The data value.
 */
@Override
public double java2DToValue(double java2DValue, Rectangle2D plotArea,
                            RectangleEdge edge) {

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

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

    if (isInverted()) {
        return switchedPow10(axisMax - ((java2DValue - plotMin)
                / (plotMax - plotMin)) * (axisMax - axisMin));
    }
    else {
        return switchedPow10(axisMin + ((java2DValue - plotMin)
                / (plotMax - plotMin)) * (axisMax - axisMin));
    }
}
 
Example 14
Source File: ColorBar.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculates the bar thickness.
 *
 * @param plotArea  the plot area.
 * @param edge  the location.
 *
 * @return The thickness.
 */
private double calculateBarThickness(Rectangle2D plotArea,
        RectangleEdge edge) {
    double result;
    if (RectangleEdge.isLeftOrRight(edge)) {
        result = plotArea.getWidth() * this.colorBarThicknessPercent;
    }
    else {
        result = plotArea.getHeight() * this.colorBarThicknessPercent;
    }
    return result;
}
 
Example 15
Source File: LogarithmicAxis.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts a coordinate in Java2D space to the corresponding data
 * value, assuming that the axis runs along one edge of the specified
 * plotArea.
 *
 * @param java2DValue  the coordinate in Java2D space.
 * @param plotArea  the area in which the data is plotted.
 * @param edge  the axis location.
 *
 * @return The data value.
 */
@Override
public double java2DToValue(double java2DValue, Rectangle2D plotArea,
                            RectangleEdge edge) {

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

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

    if (isInverted()) {
        return switchedPow10(axisMax - ((java2DValue - plotMin)
                / (plotMax - plotMin)) * (axisMax - axisMin));
    }
    else {
        return switchedPow10(axisMin + ((java2DValue - plotMin)
                / (plotMax - plotMin)) * (axisMax - axisMin));
    }
}
 
Example 16
Source File: CategoryAxis.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Estimates the space required for the axis, given a specific drawing area.
 *
 * @param g2  the graphics device (used to obtain font information).
 * @param plot  the plot that the axis belongs to.
 * @param plotArea  the area within which the axis should be drawn.
 * @param edge  the axis location (top or bottom).
 * @param space  the space already reserved.
 *
 * @return The space required to draw the axis.
 */
@Override
public AxisSpace reserveSpace(Graphics2D g2, Plot plot, 
        Rectangle2D plotArea, RectangleEdge edge, AxisSpace space) {

    // 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
        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, labelWidth;
    if (RectangleEdge.isTopOrBottom(edge)) {
        labelHeight = labelEnclosure.getHeight();
        space.add(labelHeight + tickLabelHeight
                + this.categoryLabelPositionOffset, edge);
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        labelWidth = labelEnclosure.getWidth();
        space.add(labelWidth + tickLabelWidth
                + this.categoryLabelPositionOffset, edge);
    }
    return space;
}
 
Example 17
Source File: ColorBar.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a 
 * printer).
 *
 * @param g2  the graphics device.
 * @param cursor  the cursor.
 * @param plotArea  the area within which the chart should be drawn.
 * @param dataArea  the area within which the plot should be drawn (a
 *                  subset of the drawArea).
 * @param reservedArea  the reserved area.
 * @param edge  the color bar location.
 * 
 * @return The new cursor location.
 */
public double draw(Graphics2D g2, double cursor,
                   Rectangle2D plotArea, Rectangle2D dataArea, 
                   Rectangle2D reservedArea, RectangleEdge edge) {


    Rectangle2D colorBarArea = null;
    
    double thickness = calculateBarThickness(dataArea, edge);
    if (this.colorBarThickness > 0) {
        thickness = this.colorBarThickness;  // allow fixed thickness
    }

    double length = 0.0;
    if (RectangleEdge.isLeftOrRight(edge)) {
        length = dataArea.getHeight();
    }
    else {
        length = dataArea.getWidth();
    }
    
    if (this.colorBarLength > 0) {
        length = this.colorBarLength;
    }

    if (edge == RectangleEdge.BOTTOM) {
        colorBarArea = new Rectangle2D.Double(
            dataArea.getX(), plotArea.getMaxY() + this.outerGap,
            length, thickness
        );
    }
    else if (edge == RectangleEdge.TOP) {
        colorBarArea = new Rectangle2D.Double(
            dataArea.getX(), reservedArea.getMinY() + this.outerGap,
            length, thickness
        );
    }
    else if (edge == RectangleEdge.LEFT) {
        colorBarArea = new Rectangle2D.Double(
            plotArea.getX() - thickness - this.outerGap ,
            dataArea.getMinY(), thickness, length
        );            
    }
    else if (edge == RectangleEdge.RIGHT) {
        colorBarArea = new Rectangle2D.Double(
            plotArea.getMaxX() + this.outerGap, dataArea.getMinY(),
            thickness, length
        );            
    }
    
    // update, but dont draw tick marks (needed for stepped colors)
    this.axis.refreshTicks(
        g2, new AxisState(), colorBarArea, edge
    );

    drawColorBar(g2, colorBarArea, edge);

    AxisState state = null;
    if (edge == RectangleEdge.TOP) {
        cursor = colorBarArea.getMinY();
        state = this.axis.draw(
            g2, cursor, reservedArea, colorBarArea, RectangleEdge.TOP, null
        );
    } 
    else if (edge == RectangleEdge.BOTTOM) {
        cursor = colorBarArea.getMaxY();
        state = this.axis.draw(
            g2, cursor, reservedArea, colorBarArea, RectangleEdge.BOTTOM, 
            null
        );
    } 
    else if (edge == RectangleEdge.LEFT) {
        cursor = colorBarArea.getMinX();
        state = this.axis.draw(
            g2, cursor, reservedArea, colorBarArea, RectangleEdge.LEFT, null
        );
    } 
    else if (edge == RectangleEdge.RIGHT) {
        cursor = colorBarArea.getMaxX();
        state = this.axis.draw(
            g2, cursor, reservedArea, colorBarArea, RectangleEdge.RIGHT, 
            null
        );
    }
    return state.getCursor();
    
}
 
Example 18
Source File: PeriodAxis.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Estimates the space (height or width) required to draw the axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot that the axis belongs to.
 * @param plotArea  the area within which the plot (including axes) should 
 *                  be drawn.
 * @param edge  the axis location.
 * @param space  space already reserved.
 *
 * @return The space required to draw the axis (including pre-reserved 
 *         space).
 */
public AxisSpace reserveSpace(Graphics2D g2, Plot plot, 
                              Rectangle2D plotArea, RectangleEdge edge, 
                              AxisSpace space) {
    // 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;
    }

    // if the axis has a fixed dimension, return it...
    double dimension = getFixedDimension();
    if (dimension > 0.0) {
        space.ensureAtLeast(dimension, edge);
    }
    
    // get the axis label size and update the space object...
    Rectangle2D labelEnclosure = getLabelEnclosure(g2, edge);
    double labelHeight = 0.0;
    double labelWidth = 0.0;
    double tickLabelBandsDimension = 0.0;
    
    for (int i = 0; i < this.labelInfo.length; i++) {
        PeriodAxisLabelInfo info = this.labelInfo[i];
        FontMetrics fm = g2.getFontMetrics(info.getLabelFont());
        tickLabelBandsDimension 
            += info.getPadding().extendHeight(fm.getHeight());
    }
    
    if (RectangleEdge.isTopOrBottom(edge)) {
        labelHeight = labelEnclosure.getHeight();
        space.add(labelHeight + tickLabelBandsDimension, edge);
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        labelWidth = labelEnclosure.getWidth();
        space.add(labelWidth + tickLabelBandsDimension, edge);
    }

    // add space for the outer tick labels, if any...
    double tickMarkSpace = 0.0;
    if (isTickMarksVisible()) {
        tickMarkSpace = getTickMarkOutsideLength();
    }
    if (this.minorTickMarksVisible) {
        tickMarkSpace = Math.max(tickMarkSpace, 
                this.minorTickMarkOutsideLength);
    }
    space.add(tickMarkSpace, edge);
    return space;
}
 
Example 19
Source File: CategoryAxis.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * 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.
 * @param dataArea  the area inside the axes.
 * @param edge  the location of the axis.
 *
 * @return A list of ticks.
 */
@Override
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.categoryLabelPositions.getLabelPosition(edge);
        float r = this.maximumCategoryLabelWidthRatio;
        if (r <= 0.0) {
            r = position.getWidthRatio();
        }

        float l;
        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();
            g2.setFont(getTickLabelFont(category));
            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;

}
 
Example 20
Source File: LogAxis.java    From buffer_bci with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Selects an appropriate tick value for the axis.  The strategy is to
 * display as many ticks as possible (selected from an array of 'standard'
 * tick units) without the labels overlapping.
 *
 * @param g2  the graphics device ({@code null} not permitted).
 * @param dataArea  the area defined by the axes ({@code null} not 
 *     permitted).
 * @param edge  the axis location ({@code null} not permitted).
 *
 * @since 1.0.7
 */
protected void selectAutoTickUnit(Graphics2D g2, Rectangle2D dataArea,
        RectangleEdge edge) {
    if (RectangleEdge.isTopOrBottom(edge)) {
        selectHorizontalAutoTickUnit(g2, dataArea, edge);
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        selectVerticalAutoTickUnit(g2, dataArea, edge);
    }
}