Java Code Examples for org.jfree.ui.TextAnchor#CENTER_LEFT

The following examples show how to use org.jfree.ui.TextAnchor#CENTER_LEFT . 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: CategoricalChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public TextAnchor asTextAnchor() {
  switch ( this ) {
    case RIGHT:
      return TextAnchor.CENTER_RIGHT;
    case TOP_RIGHT:
      return TextAnchor.TOP_RIGHT;
    case TOP:
      return TextAnchor.TOP_CENTER;
    case TOP_LEFT:
      return TextAnchor.TOP_LEFT;
    case LEFT:
      return TextAnchor.CENTER_LEFT;
    case BOTTOM_LEFT:
      return TextAnchor.BOTTOM_LEFT;
    case BOTTOM:
      return TextAnchor.BOTTOM_CENTER;
    case BOTTOM_RIGHT:
      return TextAnchor.BOTTOM_RIGHT;
    default:
      return null;
  }
}
 
Example 2
Source File: Axis.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
protected TextAnchor labelAnchorH(AxisLabelLocation location) {
    if (location.equals(AxisLabelLocation.HIGH_END)) {
        return TextAnchor.CENTER_RIGHT;
    }
    if (location.equals(AxisLabelLocation.MIDDLE)) {
        return TextAnchor.CENTER;
    }
    if (location.equals(AxisLabelLocation.LOW_END)) {
        return TextAnchor.CENTER_LEFT;
    }
    throw new RuntimeException("Unexpected AxisLabelLocation: " + location);
}
 
Example 3
Source File: Axis.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
protected TextAnchor labelAnchorV(AxisLabelLocation location) {
    if (location.equals(AxisLabelLocation.HIGH_END)) {
        return TextAnchor.CENTER_RIGHT;
    }
    if (location.equals(AxisLabelLocation.MIDDLE)) {
        return TextAnchor.CENTER;
    }
    if (location.equals(AxisLabelLocation.LOW_END)) {
        return TextAnchor.CENTER_LEFT;
    }
    throw new RuntimeException("Unexpected AxisLabelLocation: " + location);
}
 
Example 4
Source File: Axis.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
protected TextAnchor labelAnchorV(AxisLabelLocation location) {
    if (location.equals(AxisLabelLocation.HIGH_END)) {
        return TextAnchor.CENTER_RIGHT;
    }
    if (location.equals(AxisLabelLocation.MIDDLE)) {
        return TextAnchor.CENTER;
    }
    if (location.equals(AxisLabelLocation.LOW_END)) {
        return TextAnchor.CENTER_LEFT;
    }
    throw new RuntimeException("Unexpected AxisLabelLocation: " + location);
}
 
Example 5
Source File: Axis.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
protected TextAnchor labelAnchorH(AxisLabelLocation location) {
    if (location.equals(AxisLabelLocation.HIGH_END)) {
        return TextAnchor.CENTER_RIGHT;
    }
    if (location.equals(AxisLabelLocation.MIDDLE)) {
        return TextAnchor.CENTER;
    }
    if (location.equals(AxisLabelLocation.LOW_END)) {
        return TextAnchor.CENTER_LEFT;
    }
    throw new RuntimeException("Unexpected AxisLabelLocation: " + location);
}
 
Example 6
Source File: Axis.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
protected TextAnchor labelAnchorV(AxisLabelLocation location) {
    if (location.equals(AxisLabelLocation.HIGH_END)) {
        return TextAnchor.CENTER_RIGHT;
    }
    if (location.equals(AxisLabelLocation.MIDDLE)) {
        return TextAnchor.CENTER;
    }
    if (location.equals(AxisLabelLocation.LOW_END)) {
        return TextAnchor.CENTER_LEFT;
    }
    throw new RuntimeException("Unexpected AxisLabelLocation: " + location);
}
 
Example 7
Source File: Axis.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
protected TextAnchor labelAnchorH(AxisLabelLocation location) {
    if (location.equals(AxisLabelLocation.HIGH_END)) {
        return TextAnchor.CENTER_RIGHT;
    }
    if (location.equals(AxisLabelLocation.MIDDLE)) {
        return TextAnchor.CENTER;
    }
    if (location.equals(AxisLabelLocation.LOW_END)) {
        return TextAnchor.CENTER_LEFT;
    }
    throw new RuntimeException("Unexpected AxisLabelLocation: " + location);
}
 
Example 8
Source File: Axis.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
protected TextAnchor labelAnchorV(AxisLabelLocation location) {
    if (location.equals(AxisLabelLocation.HIGH_END)) {
        return TextAnchor.CENTER_RIGHT;
    }
    if (location.equals(AxisLabelLocation.MIDDLE)) {
        return TextAnchor.CENTER;
    }
    if (location.equals(AxisLabelLocation.LOW_END)) {
        return TextAnchor.CENTER_LEFT;
    }
    throw new RuntimeException("Unexpected AxisLabelLocation: " + location);
}
 
Example 9
Source File: Axis.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
protected TextAnchor labelAnchorH(AxisLabelLocation location) {
    if (location.equals(AxisLabelLocation.HIGH_END)) {
        return TextAnchor.CENTER_RIGHT;
    }
    if (location.equals(AxisLabelLocation.MIDDLE)) {
        return TextAnchor.CENTER;
    }
    if (location.equals(AxisLabelLocation.LOW_END)) {
        return TextAnchor.CENTER_LEFT;
    }
    throw new RuntimeException("Unexpected AxisLabelLocation: " + location);
}
 
Example 10
Source File: PolarPlot.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Calculate the text position for the given degrees.
 *
 * @param angleDegrees  the angle in degrees.
 * 
 * @return The optimal text anchor.
 * @since 1.0.14
 */
protected TextAnchor calculateTextAnchor(double angleDegrees) {
    TextAnchor ta = TextAnchor.CENTER;

    // normalize angle
    double offset = this.angleOffset;
    while (offset < 0.0) {
        offset += 360.0;
    }
    double normalizedAngle = (((this.counterClockwise ? -1 : 1)
            * angleDegrees) + offset) % 360;
    while (this.counterClockwise && (normalizedAngle < 0.0)) {
        normalizedAngle += 360.0;
    }

    if (normalizedAngle == 0.0) {
        ta = TextAnchor.CENTER_LEFT;
    }
    else if (normalizedAngle > 0.0 && normalizedAngle < 90.0) {
        ta = TextAnchor.TOP_LEFT;
    }
    else if (normalizedAngle == 90.0) {
        ta = TextAnchor.TOP_CENTER;
    }
    else if (normalizedAngle > 90.0 && normalizedAngle < 180.0) {
        ta = TextAnchor.TOP_RIGHT;
    }
    else if (normalizedAngle == 180) {
        ta = TextAnchor.CENTER_RIGHT;
    }
    else if (normalizedAngle > 180.0 && normalizedAngle < 270.0) {
        ta = TextAnchor.BOTTOM_RIGHT;
    }
    else if (normalizedAngle == 270) {
        ta = TextAnchor.BOTTOM_CENTER;
    }
    else if (normalizedAngle > 270.0 && normalizedAngle < 360.0) {
        ta = TextAnchor.BOTTOM_LEFT;
    }
    return ta;
}
 
Example 11
Source File: SymbolAxis.java    From ccu-historian with GNU General Public License v3.0 4 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 dataArea  the area in which the plot should be drawn.
 * @param edge  the location of the axis.
 *
 * @return The ticks.
 */
@Override
protected List refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea,
        RectangleEdge edge) {

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

    Font tickLabelFont = getTickLabelFont();
    g2.setFont(tickLabelFont);

    double size = getTickUnit().getSize();
    int count = calculateVisibleTickCount();
    double lowestTickValue = calculateLowestVisibleTickValue();

    double previousDrawnTickLabelPos = 0.0;
    double previousDrawnTickLabelLength = 0.0;

    if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {
        for (int i = 0; i < count; i++) {
            double currentTickValue = lowestTickValue + (i * size);
            double yy = valueToJava2D(currentTickValue, dataArea, edge);
            String tickLabel;
            NumberFormat formatter = getNumberFormatOverride();
            if (formatter != null) {
                tickLabel = formatter.format(currentTickValue);
            }
            else {
                tickLabel = valueToString(currentTickValue);
            }

            // avoid to draw overlapping tick labels
            Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2,
                    g2.getFontMetrics());
            double tickLabelLength = isVerticalTickLabels()
                ? bounds.getWidth() : bounds.getHeight();
            boolean tickLabelsOverlapping = false;
            if (i > 0) {
                double avgTickLabelLength = (previousDrawnTickLabelLength
                        + tickLabelLength) / 2.0;
                if (Math.abs(yy - previousDrawnTickLabelPos)
                        < avgTickLabelLength) {
                    tickLabelsOverlapping = true;
                }
            }
            if (tickLabelsOverlapping) {
                tickLabel = ""; // don't draw this tick label
            }
            else {
                // remember these values for next comparison
                previousDrawnTickLabelPos = yy;
                previousDrawnTickLabelLength = tickLabelLength;
            }

            TextAnchor anchor;
            TextAnchor rotationAnchor;
            double angle = 0.0;
            if (isVerticalTickLabels()) {
                anchor = TextAnchor.BOTTOM_CENTER;
                rotationAnchor = TextAnchor.BOTTOM_CENTER;
                if (edge == RectangleEdge.LEFT) {
                    angle = -Math.PI / 2.0;
                }
                else {
                    angle = Math.PI / 2.0;
                }
            }
            else {
                if (edge == RectangleEdge.LEFT) {
                    anchor = TextAnchor.CENTER_RIGHT;
                    rotationAnchor = TextAnchor.CENTER_RIGHT;
                }
                else {
                    anchor = TextAnchor.CENTER_LEFT;
                    rotationAnchor = TextAnchor.CENTER_LEFT;
                }
            }
            Tick tick = new NumberTick(new Double(currentTickValue),
                    tickLabel, anchor, rotationAnchor, angle);
            ticks.add(tick);
        }
    }
    return ticks;

}
 
Example 12
Source File: SymbolAxis.java    From opensim-gui with Apache License 2.0 4 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 dataArea  the area in which the plot should be drawn.
 * @param edge  the location of the axis.
 * 
 * @return The ticks.
 */
protected List refreshTicksVertical(Graphics2D g2,
                                    Rectangle2D dataArea,
                                    RectangleEdge edge) {

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

    Font tickLabelFont = getTickLabelFont();
    g2.setFont(tickLabelFont);

    double size = getTickUnit().getSize();
    int count = calculateVisibleTickCount();
    double lowestTickValue = calculateLowestVisibleTickValue();

    double previousDrawnTickLabelPos = 0.0;         
    double previousDrawnTickLabelLength = 0.0;              

    if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {
        for (int i = 0; i < count; i++) {
            double currentTickValue = lowestTickValue + (i * size);
            double yy = valueToJava2D(currentTickValue, dataArea, edge);
            String tickLabel;
            NumberFormat formatter = getNumberFormatOverride();
            if (formatter != null) {
                tickLabel = formatter.format(currentTickValue);
            }
            else {
                tickLabel = valueToString(currentTickValue);
            }

            // avoid to draw overlapping tick labels
            Rectangle2D bounds = TextUtilities.getTextBounds(
                tickLabel, g2, g2.getFontMetrics()
            );
            double tickLabelLength = isVerticalTickLabels() 
                ? bounds.getWidth() : bounds.getHeight();
            boolean tickLabelsOverlapping = false;
            if (i > 0) {
                double avgTickLabelLength = 
                    (previousDrawnTickLabelLength + tickLabelLength) / 2.0;
                if (Math.abs(yy - previousDrawnTickLabelPos) 
                        < avgTickLabelLength) {
                    tickLabelsOverlapping = true;    
                }
                if (tickLabelsOverlapping) {
                    tickLabel = ""; // don't draw this tick label
                }
                else {
                    // remember these values for next comparison
                    previousDrawnTickLabelPos = yy;
                    previousDrawnTickLabelLength = tickLabelLength;         
                } 
            }
            TextAnchor anchor = null;
            TextAnchor rotationAnchor = null;
            double angle = 0.0;
            if (isVerticalTickLabels()) {
                anchor = TextAnchor.BOTTOM_CENTER;
                rotationAnchor = TextAnchor.BOTTOM_CENTER;
                if (edge == RectangleEdge.LEFT) {
                    angle = -Math.PI / 2.0;
                }
                else {
                    angle = Math.PI / 2.0;
                }                    
            }
            else {
                if (edge == RectangleEdge.LEFT) {
                    anchor = TextAnchor.CENTER_RIGHT;
                    rotationAnchor = TextAnchor.CENTER_RIGHT;
                }
                else {
                    anchor = TextAnchor.CENTER_LEFT;
                    rotationAnchor = TextAnchor.CENTER_LEFT;
                }
            }
            Tick tick = new NumberTick(
                new Double(currentTickValue), tickLabel, anchor, 
                rotationAnchor, angle
            );
            ticks.add(tick);
        }
    }
    return ticks;
    
}
 
Example 13
Source File: SymbolAxis.java    From buffer_bci with GNU General Public License v3.0 4 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 dataArea  the area in which the plot should be drawn.
 * @param edge  the location of the axis.
 *
 * @return The ticks.
 */
@Override
protected List refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea,
        RectangleEdge edge) {

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

    Font tickLabelFont = getTickLabelFont();
    g2.setFont(tickLabelFont);

    double size = getTickUnit().getSize();
    int count = calculateVisibleTickCount();
    double lowestTickValue = calculateLowestVisibleTickValue();

    double previousDrawnTickLabelPos = 0.0;
    double previousDrawnTickLabelLength = 0.0;

    if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {
        for (int i = 0; i < count; i++) {
            double currentTickValue = lowestTickValue + (i * size);
            double yy = valueToJava2D(currentTickValue, dataArea, edge);
            String tickLabel;
            NumberFormat formatter = getNumberFormatOverride();
            if (formatter != null) {
                tickLabel = formatter.format(currentTickValue);
            }
            else {
                tickLabel = valueToString(currentTickValue);
            }

            // avoid to draw overlapping tick labels
            Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2,
                    g2.getFontMetrics());
            double tickLabelLength = isVerticalTickLabels()
                ? bounds.getWidth() : bounds.getHeight();
            boolean tickLabelsOverlapping = false;
            if (i > 0) {
                double avgTickLabelLength = (previousDrawnTickLabelLength
                        + tickLabelLength) / 2.0;
                if (Math.abs(yy - previousDrawnTickLabelPos)
                        < avgTickLabelLength) {
                    tickLabelsOverlapping = true;
                }
            }
            if (tickLabelsOverlapping) {
                tickLabel = ""; // don't draw this tick label
            }
            else {
                // remember these values for next comparison
                previousDrawnTickLabelPos = yy;
                previousDrawnTickLabelLength = tickLabelLength;
            }

            TextAnchor anchor;
            TextAnchor rotationAnchor;
            double angle = 0.0;
            if (isVerticalTickLabels()) {
                anchor = TextAnchor.BOTTOM_CENTER;
                rotationAnchor = TextAnchor.BOTTOM_CENTER;
                if (edge == RectangleEdge.LEFT) {
                    angle = -Math.PI / 2.0;
                }
                else {
                    angle = Math.PI / 2.0;
                }
            }
            else {
                if (edge == RectangleEdge.LEFT) {
                    anchor = TextAnchor.CENTER_RIGHT;
                    rotationAnchor = TextAnchor.CENTER_RIGHT;
                }
                else {
                    anchor = TextAnchor.CENTER_LEFT;
                    rotationAnchor = TextAnchor.CENTER_LEFT;
                }
            }
            Tick tick = new NumberTick(new Double(currentTickValue),
                    tickLabel, anchor, rotationAnchor, angle);
            ticks.add(tick);
        }
    }
    return ticks;

}
 
Example 14
Source File: PolarPlot.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Calculate the text position for the given degrees.
 *
 * @param angleDegrees  the angle in degrees.
 * 
 * @return The optimal text anchor.
 * @since 1.0.14
 */
protected TextAnchor calculateTextAnchor(double angleDegrees) {
    TextAnchor ta = TextAnchor.CENTER;

    // normalize angle
    double offset = this.angleOffset;
    while (offset < 0.0) {
        offset += 360.0;
    }
    double normalizedAngle = (((this.counterClockwise ? -1 : 1)
            * angleDegrees) + offset) % 360;
    while (this.counterClockwise && (normalizedAngle < 0.0)) {
        normalizedAngle += 360.0;
    }

    if (normalizedAngle == 0.0) {
        ta = TextAnchor.CENTER_LEFT;
    }
    else if (normalizedAngle > 0.0 && normalizedAngle < 90.0) {
        ta = TextAnchor.TOP_LEFT;
    }
    else if (normalizedAngle == 90.0) {
        ta = TextAnchor.TOP_CENTER;
    }
    else if (normalizedAngle > 90.0 && normalizedAngle < 180.0) {
        ta = TextAnchor.TOP_RIGHT;
    }
    else if (normalizedAngle == 180) {
        ta = TextAnchor.CENTER_RIGHT;
    }
    else if (normalizedAngle > 180.0 && normalizedAngle < 270.0) {
        ta = TextAnchor.BOTTOM_RIGHT;
    }
    else if (normalizedAngle == 270) {
        ta = TextAnchor.BOTTOM_CENTER;
    }
    else if (normalizedAngle > 270.0 && normalizedAngle < 360.0) {
        ta = TextAnchor.BOTTOM_LEFT;
    }
    return ta;
}
 
Example 15
Source File: PolarPlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Calculate the text position for the given degrees.
 *
 * @param angleDegrees  the angle in degrees.
 * 
 * @return The optimal text anchor.
 * @since 1.0.14
 */
protected TextAnchor calculateTextAnchor(double angleDegrees) {
    TextAnchor ta = TextAnchor.CENTER;

    // normalize angle
    double offset = this.angleOffset;
    while (offset < 0.0) {
        offset += 360.0;
    }
    double normalizedAngle = (((this.counterClockwise ? -1 : 1)
            * angleDegrees) + offset) % 360;
    while (this.counterClockwise && (normalizedAngle < 0.0)) {
        normalizedAngle += 360.0;
    }

    if (normalizedAngle == 0.0) {
        ta = TextAnchor.CENTER_LEFT;
    }
    else if (normalizedAngle > 0.0 && normalizedAngle < 90.0) {
        ta = TextAnchor.TOP_LEFT;
    }
    else if (normalizedAngle == 90.0) {
        ta = TextAnchor.TOP_CENTER;
    }
    else if (normalizedAngle > 90.0 && normalizedAngle < 180.0) {
        ta = TextAnchor.TOP_RIGHT;
    }
    else if (normalizedAngle == 180) {
        ta = TextAnchor.CENTER_RIGHT;
    }
    else if (normalizedAngle > 180.0 && normalizedAngle < 270.0) {
        ta = TextAnchor.BOTTOM_RIGHT;
    }
    else if (normalizedAngle == 270) {
        ta = TextAnchor.BOTTOM_CENTER;
    }
    else if (normalizedAngle > 270.0 && normalizedAngle < 360.0) {
        ta = TextAnchor.BOTTOM_LEFT;
    }
    return ta;
}
 
Example 16
Source File: LogAxis.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a list of ticks for an axis at the left or right of the chart.
 *
 * @param g2  the graphics device ({@code null} not permitted).
 * @param dataArea  the data area ({@code null} not permitted).
 * @param edge  the edge that the axis is aligned to ({@code null} 
 *     not permitted).
 *
 * @return A list of ticks.
 */
protected List refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea,
        RectangleEdge edge) {

    Range range = getRange();
    List ticks = new ArrayList();
    Font tickLabelFont = getTickLabelFont();
    g2.setFont(tickLabelFont);
    TextAnchor textAnchor;
    if (edge == RectangleEdge.RIGHT) {
        textAnchor = TextAnchor.CENTER_LEFT;
    }
    else {
        textAnchor = TextAnchor.CENTER_RIGHT;
    }

    if (isAutoTickUnitSelection()) {
        selectAutoTickUnit(g2, dataArea, edge);
    }
    int minorTickCount = this.tickUnit.getMinorTickCount();
    double unit = getTickUnit().getSize();
    double index = Math.ceil(calculateLog(getRange().getLowerBound()) 
            / unit);
    double start = index * unit;
    double end = calculateLog(getUpperBound());
    double current = start;
    boolean hasTicks = (this.tickUnit.getSize() > 0.0)
                       && !Double.isInfinite(start);
    while (hasTicks && current <= end) {
        double v = calculateValueNoINF(current);
        if (range.contains(v)) {
            ticks.add(new LogTick(TickType.MAJOR, v, createTickLabel(v),
                    textAnchor));
        }
        // add minor ticks (for gridlines)
        double next = Math.pow(this.base, current
                + this.tickUnit.getSize());
        for (int i = 1; i < minorTickCount; i++) {
            double minorV = v + i * ((next - v) / minorTickCount);
            if (range.contains(minorV)) {
                ticks.add(new LogTick(TickType.MINOR, minorV, null,
                        textAnchor));
            }
        }
        current = current + this.tickUnit.getSize();
    }
    return ticks;
}
 
Example 17
Source File: SymbolAxis.java    From openstock with GNU General Public License v3.0 4 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 dataArea  the area in which the plot should be drawn.
 * @param edge  the location of the axis.
 *
 * @return The ticks.
 */
@Override
protected List refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea,
        RectangleEdge edge) {

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

    Font tickLabelFont = getTickLabelFont();
    g2.setFont(tickLabelFont);

    double size = getTickUnit().getSize();
    int count = calculateVisibleTickCount();
    double lowestTickValue = calculateLowestVisibleTickValue();

    double previousDrawnTickLabelPos = 0.0;
    double previousDrawnTickLabelLength = 0.0;

    if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {
        for (int i = 0; i < count; i++) {
            double currentTickValue = lowestTickValue + (i * size);
            double yy = valueToJava2D(currentTickValue, dataArea, edge);
            String tickLabel;
            NumberFormat formatter = getNumberFormatOverride();
            if (formatter != null) {
                tickLabel = formatter.format(currentTickValue);
            }
            else {
                tickLabel = valueToString(currentTickValue);
            }

            // avoid to draw overlapping tick labels
            Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2,
                    g2.getFontMetrics());
            double tickLabelLength = isVerticalTickLabels()
                ? bounds.getWidth() : bounds.getHeight();
            boolean tickLabelsOverlapping = false;
            if (i > 0) {
                double avgTickLabelLength = (previousDrawnTickLabelLength
                        + tickLabelLength) / 2.0;
                if (Math.abs(yy - previousDrawnTickLabelPos)
                        < avgTickLabelLength) {
                    tickLabelsOverlapping = true;
                }
            }
            if (tickLabelsOverlapping) {
                tickLabel = ""; // don't draw this tick label
            }
            else {
                // remember these values for next comparison
                previousDrawnTickLabelPos = yy;
                previousDrawnTickLabelLength = tickLabelLength;
            }

            TextAnchor anchor;
            TextAnchor rotationAnchor;
            double angle = 0.0;
            if (isVerticalTickLabels()) {
                anchor = TextAnchor.BOTTOM_CENTER;
                rotationAnchor = TextAnchor.BOTTOM_CENTER;
                if (edge == RectangleEdge.LEFT) {
                    angle = -Math.PI / 2.0;
                }
                else {
                    angle = Math.PI / 2.0;
                }
            }
            else {
                if (edge == RectangleEdge.LEFT) {
                    anchor = TextAnchor.CENTER_RIGHT;
                    rotationAnchor = TextAnchor.CENTER_RIGHT;
                }
                else {
                    anchor = TextAnchor.CENTER_LEFT;
                    rotationAnchor = TextAnchor.CENTER_LEFT;
                }
            }
            Tick tick = new NumberTick(new Double(currentTickValue),
                    tickLabel, anchor, rotationAnchor, angle);
            ticks.add(tick);
        }
    }
    return ticks;

}
 
Example 18
Source File: LogAxis.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a list of ticks for an axis at the left or right of the chart.
 *
 * @param g2  the graphics device ({@code null} not permitted).
 * @param dataArea  the data area ({@code null} not permitted).
 * @param edge  the edge that the axis is aligned to ({@code null} 
 *     not permitted).
 *
 * @return A list of ticks.
 */
protected List refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea,
        RectangleEdge edge) {

    Range range = getRange();
    List ticks = new ArrayList();
    Font tickLabelFont = getTickLabelFont();
    g2.setFont(tickLabelFont);
    TextAnchor textAnchor;
    if (edge == RectangleEdge.RIGHT) {
        textAnchor = TextAnchor.CENTER_LEFT;
    }
    else {
        textAnchor = TextAnchor.CENTER_RIGHT;
    }

    if (isAutoTickUnitSelection()) {
        selectAutoTickUnit(g2, dataArea, edge);
    }
    int minorTickCount = this.tickUnit.getMinorTickCount();
    double unit = getTickUnit().getSize();
    double index = Math.ceil(calculateLog(getRange().getLowerBound()) 
            / unit);
    double start = index * unit;
    double end = calculateLog(getUpperBound());
    double current = start;
    boolean hasTicks = (this.tickUnit.getSize() > 0.0)
                       && !Double.isInfinite(start);
    while (hasTicks && current <= end) {
        double v = calculateValueNoINF(current);
        if (range.contains(v)) {
            ticks.add(new LogTick(TickType.MAJOR, v, createTickLabel(v),
                    textAnchor));
        }
        // add minor ticks (for gridlines)
        double next = Math.pow(this.base, current
                + this.tickUnit.getSize());
        for (int i = 1; i < minorTickCount; i++) {
            double minorV = v + i * ((next - v) / minorTickCount);
            if (range.contains(minorV)) {
                ticks.add(new LogTick(TickType.MINOR, minorV, null,
                        textAnchor));
            }
        }
        current = current + this.tickUnit.getSize();
    }
    return ticks;
}
 
Example 19
Source File: PolarPlot.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculate the text position for the given degrees.
 *
 * @param angleDegrees  the angle in degrees.
 * 
 * @return The optimal text anchor.
 * @since 1.0.14
 */
protected TextAnchor calculateTextAnchor(double angleDegrees) {
    TextAnchor ta = TextAnchor.CENTER;

    // normalize angle
    double offset = this.angleOffset;
    while (offset < 0.0) {
        offset += 360.0;
    }
    double normalizedAngle = (((this.counterClockwise ? -1 : 1)
            * angleDegrees) + offset) % 360;
    while (this.counterClockwise && (normalizedAngle < 0.0)) {
        normalizedAngle += 360.0;
    }

    if (normalizedAngle == 0.0) {
        ta = TextAnchor.CENTER_LEFT;
    }
    else if (normalizedAngle > 0.0 && normalizedAngle < 90.0) {
        ta = TextAnchor.TOP_LEFT;
    }
    else if (normalizedAngle == 90.0) {
        ta = TextAnchor.TOP_CENTER;
    }
    else if (normalizedAngle > 90.0 && normalizedAngle < 180.0) {
        ta = TextAnchor.TOP_RIGHT;
    }
    else if (normalizedAngle == 180) {
        ta = TextAnchor.CENTER_RIGHT;
    }
    else if (normalizedAngle > 180.0 && normalizedAngle < 270.0) {
        ta = TextAnchor.BOTTOM_RIGHT;
    }
    else if (normalizedAngle == 270) {
        ta = TextAnchor.BOTTOM_CENTER;
    }
    else if (normalizedAngle > 270.0 && normalizedAngle < 360.0) {
        ta = TextAnchor.BOTTOM_LEFT;
    }
    return ta;
}
 
Example 20
Source File: NumberAxis.java    From opensim-gui with Apache License 2.0 4 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 dataArea  the area in which the plot should be drawn.
 * @param edge  the location of the axis.
 * 
 * @return A list of ticks.
 *
 */
protected List refreshTicksVertical(Graphics2D g2,
                                    Rectangle2D dataArea,
                                    RectangleEdge edge) {

    List result = new java.util.ArrayList();
    result.clear();

    Font tickLabelFont = getTickLabelFont();
    g2.setFont(tickLabelFont);
    if (isAutoTickUnitSelection()) {
        selectAutoTickUnit(g2, dataArea, edge);
    }

    double size = getTickUnit().getSize();
    int count = calculateVisibleTickCount();
    double lowestTickValue = calculateLowestVisibleTickValue();

    if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {
        for (int i = 0; i < count; i++) {
            double currentTickValue = lowestTickValue + (i * size);
            String tickLabel;
            NumberFormat formatter = getNumberFormatOverride();
            if (formatter != null) {
                tickLabel = formatter.format(currentTickValue);
            }
            else {
                tickLabel = getTickUnit().valueToString(currentTickValue);
            }

            TextAnchor anchor = null;
            TextAnchor rotationAnchor = null;
            double angle = 0.0;
            if (isVerticalTickLabels()) {
                if (edge == RectangleEdge.LEFT) { 
                    anchor = TextAnchor.BOTTOM_CENTER;
                    rotationAnchor = TextAnchor.BOTTOM_CENTER;
                    angle = -Math.PI / 2.0;
                }
                else {
                    anchor = TextAnchor.BOTTOM_CENTER;
                    rotationAnchor = TextAnchor.BOTTOM_CENTER;
                    angle = Math.PI / 2.0;
                }
            }
            else {
                if (edge == RectangleEdge.LEFT) {
                    anchor = TextAnchor.CENTER_RIGHT;
                    rotationAnchor = TextAnchor.CENTER_RIGHT;
                }
                else {
                    anchor = TextAnchor.CENTER_LEFT;
                    rotationAnchor = TextAnchor.CENTER_LEFT;
                }
            }

            Tick tick = new NumberTick(
                new Double(currentTickValue), tickLabel, anchor, 
                rotationAnchor, angle
            );
            result.add(tick);
        }
    }
    return result;

}