afreechart/src/main/java/org/afree/chart/axis/DateAxis.java
/**
     * Estimates the maximum width of the tick labels, assuming the specified
     * tick unit is used.
     * <P>
     * Rather than computing the string bounds of every tick on the axis, we
     * just look at two values: the lower bound and the upper bound for the
     * axis.  These two values will usually be representative.
     *
     * @param canvas  the graphics device.
     * @param unit  the tick unit to use for calculation.
     *
     * @return The estimated maximum width of the tick labels.
     */
Estimates the maximum width of the tick labels, assuming the specified
tick unit is used.

Rather than computing the string bounds of every tick on the axis, we
just look at two values: the lower bound and the upper bound for the
axis.  These two values will usually be representative.

@param canvas  the graphics device.
@param unit  the tick unit to use for calculation.

@return The estimated maximum width of the tick labels.
Estimates the maximum width of the tick labels assuming the specified tick unit is used . Rather than computing the string bounds of every tick on the axis we just look at two values : the lower bound and the upper bound for the axis . These two values will usually be representative . @param canvas the graphics device . @param unit the tick unit to use for calculation . @return The estimated maximum width of the tick labels .
private double estimateMaximumTickLabelHeight(Canvas g2_temp,
                                                  DateTickUnit unit) {
        RectangleInsets tickLabelInsets = getTickLabelInsets();
        double result = tickLabelInsets.getTop() + tickLabelInsets.getBottom();
        if (!isVerticalTickLabels()) {
            Paint p = PaintUtility.createPaint(Paint.ANTI_ALIAS_FLAG, getTickLabelPaintType(), getTickLabelFont());
            RectShape rec = TextUtilities.getTextBounds("0", p);
            result += rec.getHeight();
        }
        else {
            Paint p = PaintUtility.createPaint(Paint.ANTI_ALIAS_FLAG, getTickLabelPaintType(), getTickLabelFont());
            DateRange range = (DateRange) getRange();
            Date lower = range.getLowerDate();
            Date upper = range.getUpperDate();
            String lowerStr = "";
            String upperStr = "";
            DateFormat formatter = getDateFormatOverride();
            if (formatter != null) {
                lowerStr = formatter.format(lower);
                upperStr = formatter.format(upper);
            } else {
                lowerStr = unit.dateToString(lower);
                upperStr = unit.dateToString(upper);
            }
            double w1 = TextUtilities.getTextBounds(lowerStr, p).getWidth();
            double w2 = TextUtilities.getTextBounds(upperStr, p).getWidth();
            result += Math.max(w1, w2);
        }
        return result;
    }
private double estimateMaximumTickLabelHeight ( Canvas g2_temp , DateTickUnit unit ) { RectangleInsets tickLabelInsets = getTickLabelInsets ( ) ; double result = tickLabelInsets . getTop ( ) + tickLabelInsets . getBottom ( ) ; if ( ! isVerticalTickLabels ( ) ) { Paint p = PaintUtility . createPaint ( Paint . ANTI_ALIAS_FLAG , getTickLabelPaintType ( ) , getTickLabelFont ( ) ) ; RectShape rec = TextUtilities . getTextBounds ( "0" , p ) ; result += rec . getHeight ( ) ; } else { Paint p = PaintUtility . createPaint ( Paint . ANTI_ALIAS_FLAG , getTickLabelPaintType ( ) , getTickLabelFont ( ) ) ; DateRange range = ( DateRange ) getRange ( ) ; Date lower = range . getLowerDate ( ) ; Date upper = range . getUpperDate ( ) ; String lowerStr = "" ; String upperStr = "" ; DateFormat formatter = getDateFormatOverride ( ) ; if ( formatter != null ) { lowerStr = formatter . format ( lower ) ; upperStr = formatter . format ( upper ) ; } else { lowerStr = unit . dateToString ( lower ) ; upperStr = unit . dateToString ( upper ) ; } double w1 = TextUtilities . getTextBounds ( lowerStr , p ) . getWidth ( ) ; double w2 = TextUtilities . getTextBounds ( upperStr , p ) . getWidth ( ) ; result += Math . max ( w1 , w2 ) ; } return result ; }
Estimates the maximum width of the tick labels, assuming the specified
 tick unit is used.
Estimates the maximum width of the tick labels assuming the specified tick unit is used .
//        FontRenderContext frc = canvas.getFontRenderContext(); //        LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc); // all tick labels have the same width (equal to the height of // the font)... //result += lm.getHeight(); // look at lower and upper bounds... //          FontMetrics fm = canvas.getFontMetrics(tickLabelFont); //          double w1 = fm.stringWidth(lowerStr); //          double w2 = fm.stringWidth(upperStr);