afreechart/src/main/java/org/afree/chart/axis/SymbolAxis.java
/**
     * Calculates the positions of the tick labels for the axis, storing the
     * results in the tick label list (ready for drawing).
     *
     * @param canvas  the graphics device.
     * @param dataArea  the area in which the data should be drawn.
     * @param edge  the location of the axis.
     *
     * @return The ticks.
     */
Calculates the positions of the tick labels for the axis, storing the
results in the tick label list (ready for drawing).

@param canvas  the graphics device.
@param dataArea  the area in which the data should be drawn.
@param edge  the location of the axis.

@return The ticks.
Calculates the positions of the tick labels for the axis storing the results in the tick label list ( ready for drawing ) . @param canvas the graphics device . @param dataArea the area in which the data should be drawn . @param edge the location of the axis . @return The ticks .
protected List refreshTicksHorizontal(Canvas canvas,
                                          RectShape dataArea,
                                          RectangleEdge edge) {
        List ticks = new java.util.ArrayList();
        Paint labelPaint = PaintUtility.createPaint(Paint.ANTI_ALIAS_FLAG, getTickLabelPaintType(), getTickLabelFont());
        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 xx = valueToJava2D(currentTickValue, dataArea, edge);
                String tickLabel;
                NumberFormat formatter = getNumberFormatOverride();
                if (formatter != null) {
                    tickLabel = formatter.format(currentTickValue);
                }
                else {
                    tickLabel = valueToString(currentTickValue);
                }
                RectShape bounds = TextUtilities.getTextBounds(tickLabel, labelPaint);
                double tickLabelLength = isVerticalTickLabels()
                        ? bounds.getHeight() : bounds.getWidth();
                boolean tickLabelsOverlapping = false;
                if (i > 0) {
                    double avgTickLabelLength = (previousDrawnTickLabelLength
                            + tickLabelLength) / 2.0;
                    if (Math.abs(xx - previousDrawnTickLabelPos)
                            < avgTickLabelLength) {
                        tickLabelsOverlapping = true;
                    }
                }
                if (tickLabelsOverlapping) {
                    tickLabel = ""; 
                }
                else {
                    previousDrawnTickLabelPos = xx;
                    previousDrawnTickLabelLength = tickLabelLength;
                }
                TextAnchor anchor = null;
                TextAnchor rotationAnchor = null;
                double angle = 0.0;
                if (isVerticalTickLabels()) {
                    anchor = TextAnchor.CENTER_RIGHT;
                    rotationAnchor = TextAnchor.CENTER_RIGHT;
                    if (edge == RectangleEdge.TOP) {
                        angle = Math.PI / 2.0;
                    }
                    else {
                        angle = -Math.PI / 2.0;
                    }
                }
                else {
                    if (edge == RectangleEdge.TOP) {
                        anchor = TextAnchor.BOTTOM_CENTER;
                        rotationAnchor = TextAnchor.BOTTOM_CENTER;
                    }
                    else {
                        anchor = TextAnchor.TOP_CENTER;
                        rotationAnchor = TextAnchor.TOP_CENTER;
                    }
                }
                Tick tick = new NumberTick(new Double(currentTickValue),
                        tickLabel, anchor, rotationAnchor, angle);
                ticks.add(tick);
            }
        }
        return ticks;
    }
protected List refreshTicksHorizontal ( Canvas canvas , RectShape dataArea , RectangleEdge edge ) { List ticks = new java . util . ArrayList ( ) ; Paint labelPaint = PaintUtility . createPaint ( Paint . ANTI_ALIAS_FLAG , getTickLabelPaintType ( ) , getTickLabelFont ( ) ) ; 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 xx = valueToJava2D ( currentTickValue , dataArea , edge ) ; String tickLabel ; NumberFormat formatter = getNumberFormatOverride ( ) ; if ( formatter != null ) { tickLabel = formatter . format ( currentTickValue ) ; } else { tickLabel = valueToString ( currentTickValue ) ; } RectShape bounds = TextUtilities . getTextBounds ( tickLabel , labelPaint ) ; double tickLabelLength = isVerticalTickLabels ( ) ? bounds . getHeight ( ) : bounds . getWidth ( ) ; boolean tickLabelsOverlapping = false ; if ( i > 0 ) { double avgTickLabelLength = ( previousDrawnTickLabelLength + tickLabelLength ) / 2.0 ; if ( Math . abs ( xx - previousDrawnTickLabelPos ) < avgTickLabelLength ) { tickLabelsOverlapping = true ; } } if ( tickLabelsOverlapping ) { tickLabel = "" ; } else { previousDrawnTickLabelPos = xx ; previousDrawnTickLabelLength = tickLabelLength ; } TextAnchor anchor = null ; TextAnchor rotationAnchor = null ; double angle = 0.0 ; if ( isVerticalTickLabels ( ) ) { anchor = TextAnchor . CENTER_RIGHT ; rotationAnchor = TextAnchor . CENTER_RIGHT ; if ( edge == RectangleEdge . TOP ) { angle = Math . PI / 2.0 ; } else { angle = - Math . PI / 2.0 ; } } else { if ( edge == RectangleEdge . TOP ) { anchor = TextAnchor . BOTTOM_CENTER ; rotationAnchor = TextAnchor . BOTTOM_CENTER ; } else { anchor = TextAnchor . TOP_CENTER ; rotationAnchor = TextAnchor . TOP_CENTER ; } } Tick tick = new NumberTick ( new Double ( currentTickValue ) , tickLabel , anchor , rotationAnchor , angle ) ; ticks . add ( tick ) ; } } return ticks ; }
Calculates the positions of the tick labels for the axis, storing the
 results in the tick label list (ready for drawing).
Calculates the positions of the tick labels for the axis storing the results in the tick label list ( ready for drawing ) .
// avoid to draw overlapping tick labels // don't draw this tick label // remember these values for next comparison