Example usage for org.jfree.chart.axis NumberTick getText

List of usage examples for org.jfree.chart.axis NumberTick getText

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberTick getText.

Prototype

public String getText() 

Source Link

Document

Returns the text version of the tick value.

Usage

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

/**
 * Creates and returns a list of ticks to display for the
 * axis./*from  w w w.ja v  a2s. c om*/
 *
 * @param g2  the graphics target.
 * @param state
 * @param dataArea
 * @param edge
 *
 * @return The list.
 */
public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {

    if (this.tickLabels.isEmpty()) {

        // here we auto-generate the axis labels using a non-visible axis
        // first we must align the axis range
        boolean inverted = (this.labelAxisStart > this.labelAxisEnd);
        double range = this.labelAxisEnd - this.labelAxisStart;
        double v0 = this.labelAxisStart + getLowerBound() * range;
        double v1 = this.labelAxisStart + getUpperBound() * range;
        this.axisForAutoLabels.setRange(Math.min(v0, v1), Math.max(v0, v1));
        this.axisForAutoLabels.setInverted(inverted);

        List ticks = this.axisForAutoLabels.refreshTicks(g2, state, dataArea, edge);
        // now we must 'normalise' the tick positions into the range
        // 0.0 to 1.0
        List normalisedTicks = new java.util.ArrayList();
        double min = Math.min(this.labelAxisStart, this.labelAxisEnd);
        double max = Math.max(this.labelAxisStart, this.labelAxisEnd);
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            NumberTick tick = (NumberTick) iterator.next();
            double v = tick.getValue();
            double vv = (v - min) / (max - min);
            if (this.axisForAutoLabels.isInverted()) {
                vv = 1.0 - vv;
            }
            normalisedTicks.add(new NumberTick(new Double(vv), tick.getText(), tick.getTextAnchor(),
                    tick.getRotationAnchor(), tick.getAngle()));
        }
        return normalisedTicks;
    }

    List result = new java.util.ArrayList();
    int labelCount = this.tickLabels.size();
    int positionCount = this.tickLabelPositions.size();
    int tickCount = Math.max(labelCount, positionCount);

    // work out the label anchor points according to which side of the
    // chart the axis lies on...
    TextAnchor anchor = null;
    TextAnchor rotationAnchor = TextAnchor.CENTER;
    if (edge == RectangleEdge.LEFT) {
        anchor = TextAnchor.CENTER_RIGHT;
    } else if (edge == RectangleEdge.BOTTOM) {
        anchor = TextAnchor.TOP_CENTER;
    } else if (edge == RectangleEdge.TOP) {
        anchor = TextAnchor.BOTTOM_CENTER;
    } else if (edge == RectangleEdge.RIGHT) {
        anchor = TextAnchor.CENTER_LEFT;
    }

    for (int i = 0; i < tickCount; i++) {
        String tickLabel = null;
        if (i < labelCount) {
            tickLabel = this.tickLabels.get(i).toString();
        } else {
            tickLabel = String.valueOf(this.tickLabelPositions.get(i));
        }

        // is there a value specified
        double tickValue = Double.NaN;
        if (i < positionCount) {
            Number tv = (Number) this.tickLabelPositions.get(i);
            if (tv != null) {
                tickValue = (tv.doubleValue() - this.labelAxisStart)
                        / (this.labelAxisEnd - this.labelAxisStart);
            }
        }
        if (Double.isNaN(tickValue)) {
            tickValue = (i * (1.0 / (Math.max(labelCount - 1, 1))));
        }
        Tick tick = new NumberTick(new Double(tickValue), tickLabel, anchor, rotationAnchor, 0.0);

        result.add(tick);
    }
    return result;
}

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

private List getAllTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    // TODO Auto-generated method stub
    List ticks = new java.util.ArrayList();
    Range range = getRange();//from   w  ww  . j  ava  2  s  . c o  m

    //get lower bound value:
    double lowerBoundVal = range.getLowerBound();
    //if small log values and lower bound value too small
    // then set to a small value (don't allow <= 0):
    if (this.smallLogFlag && lowerBoundVal < SMALL_LOG_VALUE) {
        lowerBoundVal = SMALL_LOG_VALUE;
    }

    //get upper bound value
    double upperBoundVal = range.getUpperBound();

    //get log10 version of lower bound and round to integer:
    int iBegCount = (int) Math.rint(switchedLog10(lowerBoundVal));
    //get log10 version of upper bound and round to integer:
    int iEndCount = (int) Math.rint(switchedLog10(upperBoundVal));

    //        if (iBegCount == iEndCount && iBegCount >= 0
    if (iBegCount == iEndCount && Math.pow(10, iBegCount) > lowerBoundVal) {
        //only 1 power of 10 value, it's > 0 and its resulting
        // tick value will be larger than lower bound of data
        --iBegCount; //decrement to generate more ticks
    }

    int numberOfGrids = 0;
    int numberOfTicks = 0;
    NumberTick lastTick = null;

    double currentTickValue;
    String tickLabel;
    boolean zeroTickFlag = false;
    for (int i = iBegCount; i <= iEndCount; i++) {
        //for each power of 10 value; create ten ticks
        for (int j = 0; j < 10; ++j) {
            //for each tick to be displayed
            if (this.smallLogFlag) {
                //small log values in use; create numeric value for tick
                currentTickValue = Math.pow(10, i) + (Math.pow(10, i) * j);
                if (this.expTickLabelsFlag || (i < 0 && currentTickValue > 0.0 && currentTickValue < 1.0)) {
                    //showing "1e#"-style ticks or negative exponent
                    // generating tick value between 0 & 1; show fewer
                    //first tick of series, or not too small a value and
                    // one of first 3 ticks, or last tick to be displayed
                    // set exact number of fractional digits to be shown
                    // (no effect if showing "1e#"-style ticks):
                    this.numberFormatterObj.setMaximumFractionDigits(-i);
                    //create tick label (force use of fmt obj):
                    tickLabel = makeTickLabel(currentTickValue, true);
                } else { //tick value not between 0 & 1
                         //show tick label if it's the first or last in
                         // the set, or if it's 1-5; beyond that show
                         // fewer as the values get larger:
                    tickLabel = makeTickLabel(currentTickValue);
                }
            } else { //not small log values in use; allow for values <= 0
                if (zeroTickFlag) { //if did zero tick last iter then
                    --j; //decrement to do 1.0 tick now
                } //calculate power-of-ten value for tick:
                currentTickValue = (i >= 0) ? Math.pow(10, i) + (Math.pow(10, i) * j)
                        : -(Math.pow(10, -i) - (Math.pow(10, -i - 1) * j));
                if (!zeroTickFlag) { // did not do zero tick last iteration
                    if (Math.abs(currentTickValue - 1.0) < 0.0001 && lowerBoundVal <= 0.0
                            && upperBoundVal >= 0.0) {
                        //tick value is 1.0 and 0.0 is within data range
                        currentTickValue = 0.0; //set tick value to zero
                        zeroTickFlag = true; //indicate zero tick
                    }
                } else { //did zero tick last iteration
                    zeroTickFlag = false; //clear flag
                } //create tick label string:
                //show tick label if "1e#"-style and it's one
                // of the first two, if it's the first or last
                // in the set, or if it's 1-5; beyond that
                // show fewer as the values get larger:
                tickLabel = makeTickLabel(currentTickValue);
            }

            if (currentTickValue > upperBoundVal) {
                if (lastTick != null) {
                    String lastTickText = lastTick.getText();
                    if (lastTickText == null || lastTickText.trim().length() == 0) {
                        ticks.remove(lastTick);
                        ticks.add(new NumberTick(lastTick.getValue(),
                                createTickLabel(lastTick.getValue(), i - 1), lastTick.getTextAnchor(),
                                lastTick.getRotationAnchor(), lastTick.getAngle()));
                    }
                }
                if (ticks.size() < 2) {
                    double definition = Math.abs(lowerBoundVal - upperBoundVal);
                    int numberOfDigits = 0;
                    if (definition >= 1)
                        numberOfDigits = 0;
                    else {
                        numberOfDigits = (int) Math.ceil((-Math.log10(definition)));
                    }
                    if (definition < 2 * Math.pow(10, -numberOfDigits)) {
                        numberOfDigits++;
                    }
                    double tickVal;
                    tickVal = lowerBoundVal;
                    if (definition > 1)
                        tickLabel = Long.toString((long) Math.rint(tickVal));
                    else
                        tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
                    ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.TOP_CENTER,
                            TextAnchor.TOP_CENTER, 0.0));
                    tickVal = upperBoundVal;
                    if (definition > 1)
                        tickLabel = Long.toString((long) Math.rint(tickVal));
                    else
                        tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
                    ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.TOP_CENTER,
                            TextAnchor.TOP_CENTER, 0.0));
                }
                return ticks; // if past highest data value then exit
                              // method
            }

            if (currentTickValue >= lowerBoundVal - SMALL_LOG_VALUE) {
                //tick value not below lowest data value
                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;
                    }
                }

                lastTick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor,
                        angle);
                ticks.add(lastTick);
                if (tickLabel != null && tickLabel.trim().length() > 0)
                    numberOfTicks++;
                numberOfGrids++;
            }
        }
    }
    if (ticks.size() < 2) {
        double definition = Math.abs(lowerBoundVal - upperBoundVal);
        int numberOfDigits = 0;
        if (definition >= 1)
            numberOfDigits = 0;
        else {
            numberOfDigits = (int) Math.ceil((-Math.log10(definition)));
        }
        double tickVal;
        tickVal = lowerBoundVal;
        if (definition > 1)
            tickLabel = Long.toString((long) Math.rint(tickVal));
        else
            tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
        ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.TOP_CENTER, TextAnchor.TOP_CENTER,
                0.0));
        tickVal = upperBoundVal;
        if (definition > 1)
            tickLabel = Long.toString((long) Math.rint(tickVal));
        else
            tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
        ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.TOP_CENTER, TextAnchor.TOP_CENTER,
                0.0));
    }
    return ticks;
}

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

protected List getAllTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    List ticks = new java.util.ArrayList();

    //get lower bound value:
    double lowerBoundVal = getRange().getLowerBound();
    //if small log values and lower bound value too small
    // then set to a small value (don't allow <= 0):
    if (this.smallLogFlag && lowerBoundVal < SMALL_LOG_VALUE) {
        lowerBoundVal = SMALL_LOG_VALUE;
    }//from w  ww .  j ava2  s  .  c  om
    //get upper bound value
    double upperBoundVal = getRange().getUpperBound();

    //get log10 version of lower bound and round to integer:
    int iBegCount = (int) Math.rint(switchedLog10(lowerBoundVal));
    //get log10 version of upper bound and round to integer:
    int iEndCount = (int) Math.rint(switchedLog10(upperBoundVal));

    if (iBegCount == iEndCount && iBegCount > 0 && Math.pow(10, iBegCount) > lowerBoundVal) {
        //only 1 power of 10 value, it's > 0 and its resulting
        // tick value will be larger than lower bound of data
        --iBegCount; //decrement to generate more ticks
    }

    int numberOfGrids = 0;
    int numberOfTicks = 0;
    NumberTick lastTick = null;
    double tickVal;
    String tickLabel;
    //        tickVal = lowerBoundVal;
    //        
    //        tickLabel = Long.toString((long) Math.rint(tickVal));
    //        ticks.add(new NumberTick(new Double(tickVal), tickLabel,
    //              TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0));
    boolean zeroTickFlag = false;
    for (int i = iBegCount; i <= iEndCount; i++) {
        //for each tick with a label to be displayed
        int jEndCount = 10;
        if (i == iEndCount) {
            //                jEndCount = 1;
        }

        for (int j = 0; j < jEndCount; j++) {
            //for each tick to be displayed
            if (this.smallLogFlag) {
                //small log values in use
                tickVal = Math.pow(10, i) + (Math.pow(10, i) * j);
                //first tick of group; create label text
                if (this.log10TickLabelsFlag) {
                    //if flag then
                    tickLabel = "10^" + i; //create "log10"-type label
                } else { //not "log10"-type label
                    if (this.expTickLabelsFlag) {
                        //if flag then
                        tickLabel = "1e" + i; //create "1e#"-type label
                    } else { //not "1e#"-type label
                        if (i >= 0) { // if positive exponent then
                                      // make integer
                            NumberFormat format = getNumberFormatOverride();
                            if (format != null) {
                                tickLabel = format.format(tickVal);
                            } else {
                                tickLabel = Long.toString((long) Math.rint(tickVal));
                            }
                        } else {
                            //negative exponent; create fractional value
                            //set exact number of fractional digits to
                            // be shown:
                            this.numberFormatterObj.setMaximumFractionDigits(-i);
                            //create tick label:
                            tickLabel = this.numberFormatterObj.format(tickVal);
                        }
                    }
                }
            } else { //not small log values in use; allow for values <= 0
                if (zeroTickFlag) { //if did zero tick last iter then
                    --j;
                } //decrement to do 1.0 tick now
                tickVal = (i >= 0) ? Math.pow(10, i) + (Math.pow(10, i) * j)
                        : -(Math.pow(10, -i) - (Math.pow(10, -i - 1) * j));
                if (!zeroTickFlag) { // did not do zero tick last
                                     // iteration
                    if (i > iBegCount && i < iEndCount && Math.abs(tickVal - 1.0) < 0.0001) {
                        // not first or last tick on graph and value
                        // is 1.0
                        tickVal = 0.0; //change value to 0.0
                        zeroTickFlag = true; //indicate zero tick
                        tickLabel = "0"; //create label for tick
                    } else {
                        //first or last tick on graph or value is 1.0
                        //create label for tick:
                        tickLabel = createTickLabel(tickVal, i);
                    }
                } else { // not first tick of group
                    tickLabel = createTickLabel(tickVal, i);
                }
            }

            if (tickVal > upperBoundVal) {
                if (lastTick != null) {
                    String lastTickText = lastTick.getText();
                    if (lastTickText == null || lastTickText.trim().length() == 0) {
                        ticks.remove(lastTick);
                        ticks.add(new NumberTick(lastTick.getValue(),
                                createTickLabel(lastTick.getValue(), i - 1), lastTick.getTextAnchor(),
                                lastTick.getRotationAnchor(), lastTick.getAngle()));
                    }
                }
                if (ticks.size() < 2) {
                    double definition = Math.abs(lowerBoundVal - upperBoundVal);
                    int numberOfDigits = 0;
                    if (definition >= 1)
                        numberOfDigits = 0;
                    else {
                        numberOfDigits = (int) Math.ceil((-Math.log10(definition)));
                    }
                    tickVal = lowerBoundVal;
                    if (definition > 1)
                        tickLabel = Long.toString((long) Math.rint(tickVal));
                    else
                        tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
                    ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.CENTER_RIGHT,
                            TextAnchor.CENTER_RIGHT, 0.0));
                    tickVal = upperBoundVal;
                    if (definition > 1)
                        tickLabel = Long.toString((long) Math.rint(tickVal));
                    else
                        tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
                    ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.CENTER_RIGHT,
                            TextAnchor.CENTER_RIGHT, 0.0));
                }
                return ticks; //if past highest data value then exit method
            }

            if (tickVal >= lowerBoundVal - SMALL_LOG_VALUE) {
                //tick value not below lowest data value
                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;
                    }
                }
                //create tick object and add to list:
                lastTick = new NumberTick(new Double(tickVal), tickLabel, anchor, rotationAnchor, angle);
                ticks.add(lastTick);
                if (tickLabel != null && tickLabel.trim().length() > 0)
                    numberOfTicks++;
                numberOfGrids++;
            }
        }
    }
    if (ticks.size() < 2) {
        double definition = Math.abs(lowerBoundVal - upperBoundVal);
        int numberOfDigits = 0;
        if (definition >= 1)
            numberOfDigits = 0;
        else {
            numberOfDigits = (int) Math.ceil((-Math.log10(definition)));
        }
        tickVal = lowerBoundVal;
        if (definition > 1)
            tickLabel = Long.toString((long) Math.rint(tickVal));
        else
            tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
        ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.CENTER_RIGHT,
                TextAnchor.CENTER_RIGHT, 0.0));
        tickVal = upperBoundVal;
        if (definition > 1)
            tickLabel = Long.toString((long) Math.rint(tickVal));
        else
            tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
        ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.CENTER_RIGHT,
                TextAnchor.CENTER_RIGHT, 0.0));
    }
    return ticks;
}

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

@Override
protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    // TODO Auto-generated method stub
    List ticks = new java.util.ArrayList();
    Range range = getRange();/*from ww w  .  j av a  2 s . co  m*/

    //get lower bound value:
    double lowerBoundVal = range.getLowerBound();
    //if small log values and lower bound value too small
    // then set to a small value (don't allow <= 0):
    if (this.smallLogFlag && lowerBoundVal < SMALL_LOG_VALUE) {
        lowerBoundVal = SMALL_LOG_VALUE;
    }

    //get upper bound value
    double upperBoundVal = range.getUpperBound();

    //get log10 version of lower bound and round to integer:
    int iBegCount = (int) Math.rint(switchedLog10(lowerBoundVal));
    //get log10 version of upper bound and round to integer:
    int iEndCount = (int) Math.rint(switchedLog10(upperBoundVal));

    //        if (iBegCount == iEndCount && iBegCount >= 0
    if (iBegCount == iEndCount && Math.pow(10, iBegCount) > lowerBoundVal) {
        //only 1 power of 10 value, it's > 0 and its resulting
        // tick value will be larger than lower bound of data
        --iBegCount; //decrement to generate more ticks
    }

    int numberOfGrids = 0;
    int numberOfTicks = 0;
    NumberTick lastTick = null;

    double currentTickValue;
    String tickLabel;
    boolean zeroTickFlag = false;
    for (int i = iBegCount; i <= iEndCount; i++) {
        //for each power of 10 value; create ten ticks
        for (int j = 0; j < 10; ++j) {
            //for each tick to be displayed
            if (this.smallLogFlag) {
                //small log values in use; create numeric value for tick
                currentTickValue = Math.pow(10, i) + (Math.pow(10, i) * j);
                if (this.expTickLabelsFlag || (i < 0 && currentTickValue > 0.0 && currentTickValue < 1.0)) {
                    //showing "1e#"-style ticks or negative exponent
                    // generating tick value between 0 & 1; show fewer
                    if (j == 0 || (i > -4 && (j < 2 || j == 4)) || currentTickValue >= upperBoundVal) {
                        //first tick of series, or not too small a value and
                        // one of first 3 ticks, or last tick to be displayed
                        // set exact number of fractional digits to be shown
                        // (no effect if showing "1e#"-style ticks):
                        this.numberFormatterObj.setMaximumFractionDigits(-i);
                        //create tick label (force use of fmt obj):
                        tickLabel = makeTickLabel(currentTickValue, true);
                    } else { //no tick label to be shown
                        //                            tickLabel = "";
                        if (numberOfTicks == 0) {
                            tickLabel = makeTickLabel(currentTickValue, true);
                        } else
                            tickLabel = "";
                    }
                } else { //tick value not between 0 & 1
                         //show tick label if it's the first or last in
                         // the set, or if it's 1-5; beyond that show
                         // fewer as the values get larger:
                    tickLabel = (j < 1 || (i < 1 && j < 5) || (j < 4 - i) || currentTickValue >= upperBoundVal
                            || numberOfTicks == 0) ? makeTickLabel(currentTickValue) : "";
                }
            } else { //not small log values in use; allow for values <= 0
                if (zeroTickFlag) { //if did zero tick last iter then
                    --j; //decrement to do 1.0 tick now
                } //calculate power-of-ten value for tick:
                currentTickValue = (i >= 0) ? Math.pow(10, i) + (Math.pow(10, i) * j)
                        : -(Math.pow(10, -i) - (Math.pow(10, -i - 1) * j));
                if (!zeroTickFlag) { // did not do zero tick last iteration
                    if (Math.abs(currentTickValue - 1.0) < 0.0001 && lowerBoundVal <= 0.0
                            && upperBoundVal >= 0.0) {
                        //tick value is 1.0 and 0.0 is within data range
                        currentTickValue = 0.0; //set tick value to zero
                        zeroTickFlag = true; //indicate zero tick
                    }
                } else { //did zero tick last iteration
                    zeroTickFlag = false; //clear flag
                } //create tick label string:
                //show tick label if "1e#"-style and it's one
                // of the first two, if it's the first or last
                // in the set, or if it's 1-5; beyond that
                // show fewer as the values get larger:
                tickLabel = ((this.expTickLabelsFlag && j < 2) || j < 1 || (i < 1 && j < 5) || (j < 4 - i)
                        || currentTickValue >= upperBoundVal || numberOfTicks == 0)
                                ? makeTickLabel(currentTickValue)
                                : "";
            }

            if (currentTickValue > upperBoundVal) {
                if (lastTick != null) {
                    String lastTickText = lastTick.getText();
                    if (lastTickText == null || lastTickText.trim().length() == 0) {
                        ticks.remove(lastTick);
                        ticks.add(new NumberTick(lastTick.getValue(),
                                createTickLabel(lastTick.getValue(), i - 1), lastTick.getTextAnchor(),
                                lastTick.getRotationAnchor(), lastTick.getAngle()));
                    }
                }
                if (numberOfTicks < 4) {
                    return getAllTicksHorizontal(g2, dataArea, edge);
                }
                return ticks; // if past highest data value then exit
                              // method
            }

            if (currentTickValue >= lowerBoundVal - SMALL_LOG_VALUE) {
                //tick value not below lowest data value
                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;
                    }
                }

                lastTick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor,
                        angle);
                ticks.add(lastTick);
                if (tickLabel != null && tickLabel.trim().length() > 0)
                    numberOfTicks++;
                numberOfGrids++;
            }
        }
    }
    if (numberOfTicks < 4) {
        return getAllTicksHorizontal(g2, dataArea, edge);
    }
    return ticks;
}

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

private List getAllTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    // TODO Auto-generated method stub
    List ticks = new java.util.ArrayList();
    Range range = getRange();//  w  w w  .jav a 2s . c o  m

    //get lower bound value:
    double lowerBoundVal = range.getLowerBound();
    //if small log values and lower bound value too small
    // then set to a small value (don't allow <= 0):
    if (this.smallLogFlag && lowerBoundVal < SMALL_LOG_VALUE) {
        lowerBoundVal = SMALL_LOG_VALUE;
    }

    //get upper bound value
    double upperBoundVal = range.getUpperBound();

    //get log10 version of lower bound and round to integer:
    int iBegCount = (int) Math.rint(switchedLog10(lowerBoundVal));
    //get log10 version of upper bound and round to integer:
    int iEndCount = (int) Math.rint(switchedLog10(upperBoundVal));

    //        if (iBegCount == iEndCount && iBegCount >= 0
    if (iBegCount == iEndCount && Math.pow(10, iBegCount) > lowerBoundVal) {
        //only 1 power of 10 value, it's > 0 and its resulting
        // tick value will be larger than lower bound of data
        --iBegCount; //decrement to generate more ticks
    }

    int numberOfGrids = 0;
    int numberOfTicks = 0;
    NumberTick lastTick = null;

    double currentTickValue;
    String tickLabel;
    boolean zeroTickFlag = false;
    for (int i = iBegCount; i <= iEndCount; i++) {
        //for each power of 10 value; create ten ticks
        for (int j = 0; j < 10; ++j) {
            //for each tick to be displayed
            if (this.smallLogFlag) {
                //small log values in use; create numeric value for tick
                currentTickValue = Math.pow(10, i) + (Math.pow(10, i) * j);
                if (this.expTickLabelsFlag || (i < 0 && currentTickValue > 0.0 && currentTickValue < 1.0)) {
                    //showing "1e#"-style ticks or negative exponent
                    // generating tick value between 0 & 1; show fewer
                    //first tick of series, or not too small a value and
                    // one of first 3 ticks, or last tick to be displayed
                    // set exact number of fractional digits to be shown
                    // (no effect if showing "1e#"-style ticks):
                    this.numberFormatterObj.setMaximumFractionDigits(-i);
                    //create tick label (force use of fmt obj):
                    tickLabel = makeTickLabel(currentTickValue, true);
                } else { //tick value not between 0 & 1
                         //show tick label if it's the first or last in
                         // the set, or if it's 1-5; beyond that show
                         // fewer as the values get larger:
                    tickLabel = makeTickLabel(currentTickValue);
                }
            } else { //not small log values in use; allow for values <= 0
                if (zeroTickFlag) { //if did zero tick last iter then
                    --j; //decrement to do 1.0 tick now
                } //calculate power-of-ten value for tick:
                currentTickValue = (i >= 0) ? Math.pow(10, i) + (Math.pow(10, i) * j)
                        : -(Math.pow(10, -i) - (Math.pow(10, -i - 1) * j));
                if (!zeroTickFlag) { // did not do zero tick last iteration
                    if (Math.abs(currentTickValue - 1.0) < 0.0001 && lowerBoundVal <= 0.0
                            && upperBoundVal >= 0.0) {
                        //tick value is 1.0 and 0.0 is within data range
                        currentTickValue = 0.0; //set tick value to zero
                        zeroTickFlag = true; //indicate zero tick
                    }
                } else { //did zero tick last iteration
                    zeroTickFlag = false; //clear flag
                } //create tick label string:
                //show tick label if "1e#"-style and it's one
                // of the first two, if it's the first or last
                // in the set, or if it's 1-5; beyond that
                // show fewer as the values get larger:
                tickLabel = makeTickLabel(currentTickValue);
            }

            if (currentTickValue > upperBoundVal) {
                if (lastTick != null) {
                    String lastTickText = lastTick.getText();
                    if (lastTickText == null || lastTickText.trim().length() == 0) {
                        ticks.remove(lastTick);
                        ticks.add(new NumberTick(lastTick.getValue(),
                                createTickLabel(lastTick.getValue(), i - 1), lastTick.getTextAnchor(),
                                lastTick.getRotationAnchor(), lastTick.getAngle()));
                    }
                }
                if (ticks.size() < 2) {
                    double definition = Math.abs(lowerBoundVal - upperBoundVal);
                    int numberOfDigits = 0;
                    if (definition >= 1)
                        numberOfDigits = 0;
                    else {
                        numberOfDigits = (int) Math.ceil((-Math.log10(definition)));
                    }
                    if (definition < 2 * Math.pow(10, -numberOfDigits)) {
                        numberOfDigits++;
                    }
                    double tickVal;
                    tickVal = lowerBoundVal;
                    if (definition > 1)
                        tickLabel = Long.toString((long) Math.rint(tickVal));
                    else
                        tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
                    ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.TOP_CENTER,
                            TextAnchor.TOP_CENTER, 0.0));
                    tickVal = upperBoundVal;
                    if (definition > 1) {
                        tickLabel = Long.toString((long) Math.rint(tickVal));
                    } else {
                        tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
                    }
                    ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.TOP_CENTER,
                            TextAnchor.TOP_CENTER, 0.0));
                }
                return ticks; // if past highest data value then exit
                              // method
            }

            if (currentTickValue >= lowerBoundVal - SMALL_LOG_VALUE) {
                //tick value not below lowest data value
                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;
                    }
                }

                lastTick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor,
                        angle);
                ticks.add(lastTick);
                if (tickLabel != null && tickLabel.trim().length() > 0)
                    numberOfTicks++;
                numberOfGrids++;
            }
        }
    }
    if (ticks.size() < 2) {
        double definition = Math.abs(lowerBoundVal - upperBoundVal);
        int numberOfDigits = 0;
        if (definition >= 1)
            numberOfDigits = 0;
        else {
            numberOfDigits = (int) Math.ceil((-Math.log10(definition)));
        }
        double tickVal;
        tickVal = lowerBoundVal;
        if (definition > 1)
            tickLabel = Long.toString((long) Math.rint(tickVal));
        else
            tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
        ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.TOP_CENTER, TextAnchor.TOP_CENTER,
                0.0));
        tickVal = upperBoundVal;
        if (definition > 1)
            tickLabel = Long.toString((long) Math.rint(tickVal));
        else
            tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
        ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.TOP_CENTER, TextAnchor.TOP_CENTER,
                0.0));
    }
    return ticks;
}

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

private List getAllTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    List ticks = new java.util.ArrayList();

    //get lower bound value:
    double lowerBoundVal = getRange().getLowerBound();
    //if small log values and lower bound value too small
    // then set to a small value (don't allow <= 0):
    if (this.smallLogFlag && lowerBoundVal < SMALL_LOG_VALUE) {
        lowerBoundVal = SMALL_LOG_VALUE;
    }/*from  w w  w. j  ava 2  s . c om*/
    //get upper bound value
    double upperBoundVal = getRange().getUpperBound();

    //get log10 version of lower bound and round to integer:
    int iBegCount = (int) Math.rint(switchedLog10(lowerBoundVal));
    //get log10 version of upper bound and round to integer:
    int iEndCount = (int) Math.rint(switchedLog10(upperBoundVal));

    if (iBegCount == iEndCount && iBegCount > 0 && Math.pow(10, iBegCount) > lowerBoundVal) {
        //only 1 power of 10 value, it's > 0 and its resulting
        // tick value will be larger than lower bound of data
        --iBegCount; //decrement to generate more ticks
    }

    int numberOfGrids = 0;
    int numberOfTicks = 0;
    NumberTick lastTick = null;
    double tickVal;
    String tickLabel;
    //        tickVal = lowerBoundVal;
    //        
    //        tickLabel = Long.toString((long) Math.rint(tickVal));
    //        ticks.add(new NumberTick(new Double(tickVal), tickLabel,
    //              TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0));
    boolean zeroTickFlag = false;
    for (int i = iBegCount; i <= iEndCount; i++) {
        //for each tick with a label to be displayed
        int jEndCount = 10;
        if (i == iEndCount) {
            //                jEndCount = 1;
        }

        for (int j = 0; j < jEndCount; j++) {
            //for each tick to be displayed
            if (this.smallLogFlag) {
                //small log values in use
                tickVal = Math.pow(10, i) + (Math.pow(10, i) * j);
                //first tick of group; create label text
                if (this.log10TickLabelsFlag) {
                    //if flag then
                    tickLabel = "10^" + i; //create "log10"-type label
                } else { //not "log10"-type label
                    if (this.expTickLabelsFlag) {
                        //if flag then
                        tickLabel = "1e" + i; //create "1e#"-type label
                    } else { //not "1e#"-type label
                        if (i >= 0) { // if positive exponent then
                                      // make integer
                            NumberFormat format = getNumberFormatOverride();
                            if (format != null) {
                                tickLabel = format.format(tickVal);
                            } else {
                                tickLabel = Long.toString((long) Math.rint(tickVal));
                            }
                        } else {
                            //negative exponent; create fractional value
                            //set exact number of fractional digits to
                            // be shown:
                            this.numberFormatterObj.setMaximumFractionDigits(-i);
                            //create tick label:
                            tickLabel = this.numberFormatterObj.format(tickVal);
                        }
                    }
                }
            } else { //not small log values in use; allow for values <= 0
                if (zeroTickFlag) { //if did zero tick last iter then
                    --j;
                } //decrement to do 1.0 tick now
                tickVal = (i >= 0) ? Math.pow(10, i) + (Math.pow(10, i) * j)
                        : -(Math.pow(10, -i) - (Math.pow(10, -i - 1) * j));
                if (!zeroTickFlag) { // did not do zero tick last
                                     // iteration
                    if (i > iBegCount && i < iEndCount && Math.abs(tickVal - 1.0) < 0.0001) {
                        // not first or last tick on graph and value
                        // is 1.0
                        tickVal = 0.0; //change value to 0.0
                        zeroTickFlag = true; //indicate zero tick
                        tickLabel = "0"; //create label for tick
                    } else {
                        //first or last tick on graph or value is 1.0
                        //create label for tick:
                        tickLabel = createTickLabel(tickVal, i);
                    }
                } else { // not first tick of group
                    tickLabel = createTickLabel(tickVal, i);
                }
            }

            if (tickVal > upperBoundVal) {
                if (lastTick != null) {
                    String lastTickText = lastTick.getText();
                    if (lastTickText == null || lastTickText.trim().length() == 0) {
                        ticks.remove(lastTick);
                        ticks.add(new NumberTick(lastTick.getValue(),
                                createTickLabel(lastTick.getValue(), i - 1), lastTick.getTextAnchor(),
                                lastTick.getRotationAnchor(), lastTick.getAngle()));
                    }
                }
                if (ticks.size() < 2) {
                    double definition = Math.abs(lowerBoundVal - upperBoundVal);
                    int numberOfDigits = 0;
                    if (definition >= 1)
                        numberOfDigits = 0;
                    else {
                        numberOfDigits = (int) Math.ceil((-Math.log10(definition)));
                    }
                    tickVal = lowerBoundVal;
                    if (definition > 1)
                        tickLabel = Long.toString((long) Math.rint(tickVal));
                    else
                        tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
                    ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.CENTER_RIGHT,
                            TextAnchor.CENTER_RIGHT, 0.0));
                    tickVal = upperBoundVal;
                    if (definition > 1)
                        tickLabel = Long.toString((long) Math.rint(tickVal));
                    else
                        tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
                    ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.CENTER_RIGHT,
                            TextAnchor.CENTER_RIGHT, 0.0));
                }
                return ticks; //if past highest data value then exit method
            }

            if (tickVal >= lowerBoundVal - SMALL_LOG_VALUE) {
                //tick value not below lowest data value
                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;
                    }
                }
                //create tick object and add to list:
                lastTick = new NumberTick(new Double(tickVal), tickLabel, anchor, rotationAnchor, angle);
                ticks.add(lastTick);
                if (tickLabel != null && tickLabel.trim().length() > 0)
                    numberOfTicks++;
                numberOfGrids++;
            }
        }
    }
    if (ticks.size() < 2) {
        double definition = Math.abs(lowerBoundVal - upperBoundVal);
        int numberOfDigits = 0;
        if (definition >= 1)
            numberOfDigits = 0;
        else {
            numberOfDigits = (int) Math.ceil((-Math.log10(definition)));
        }
        tickVal = lowerBoundVal;
        if (definition > 1)
            tickLabel = Long.toString((long) Math.rint(tickVal));
        else
            tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
        ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.CENTER_RIGHT,
                TextAnchor.CENTER_RIGHT, 0.0));
        tickVal = upperBoundVal;
        if (definition > 1)
            tickLabel = Long.toString((long) Math.rint(tickVal));
        else
            tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
        ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.CENTER_RIGHT,
                TextAnchor.CENTER_RIGHT, 0.0));
    }
    return ticks;
}

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

protected List newRefreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    // TODO Auto-generated method stub
    List ticks = new java.util.ArrayList();
    Range range = getRange();//w w w .j  a v  a2s .c o m

    //get lower bound value:
    double lowerBoundVal = range.getLowerBound();
    //if small log values and lower bound value too small
    // then set to a small value (don't allow <= 0):
    if (this.smallLogFlag && lowerBoundVal < SMALL_LOG_VALUE) {
        lowerBoundVal = SMALL_LOG_VALUE;
    }

    //get upper bound value
    double upperBoundVal = range.getUpperBound();

    //get log10 version of lower bound and round to integer:
    int iBegCount = (int) Math.rint(switchedLog10(lowerBoundVal));
    //get log10 version of upper bound and round to integer:
    int iEndCount = (int) Math.rint(switchedLog10(upperBoundVal));

    //        if (iBegCount == iEndCount && iBegCount >= 0
    if (iBegCount == iEndCount && Math.pow(10, iBegCount) > lowerBoundVal) {
        //only 1 power of 10 value, it's > 0 and its resulting
        // tick value will be larger than lower bound of data
        --iBegCount; //decrement to generate more ticks
    }

    int numberOfGrids = 0;
    int numberOfTicks = 0;
    NumberTick lastTick = null;

    double currentTickValue;
    String tickLabel;
    boolean zeroTickFlag = false;
    for (int i = iBegCount; i <= iEndCount; i++) {
        //for each power of 10 value; create ten ticks
        for (int j = 0; j < 10; ++j) {
            //for each tick to be displayed
            if (this.smallLogFlag) {
                //small log values in use; create numeric value for tick
                currentTickValue = Math.pow(10, i) + (Math.pow(10, i) * j);
                if (this.expTickLabelsFlag || (i < 0 && currentTickValue > 0.0 && currentTickValue < 1.0)) {
                    //showing "1e#"-style ticks or negative exponent
                    // generating tick value between 0 & 1; show fewer
                    if (j == 0 || (i > -4 && (j < 2 || j == 4)) || currentTickValue >= upperBoundVal) {
                        //first tick of series, or not too small a value and
                        // one of first 3 ticks, or last tick to be displayed
                        // set exact number of fractional digits to be shown
                        // (no effect if showing "1e#"-style ticks):
                        this.numberFormatterObj.setMaximumFractionDigits(-i);
                        //create tick label (force use of fmt obj):
                        tickLabel = makeTickLabel(currentTickValue, true);
                    } else { //no tick label to be shown
                        //                            tickLabel = "";
                        if (numberOfTicks == 0) {
                            tickLabel = makeTickLabel(currentTickValue, true);
                        } else
                            tickLabel = "";
                    }
                } else { //tick value not between 0 & 1
                         //show tick label if it's the first or last in
                         // the set, or if it's 1-5; beyond that show
                         // fewer as the values get larger:
                    tickLabel = (j < 1 || (i < 1 && j < 5) || (j < 4 - i) || currentTickValue >= upperBoundVal
                            || numberOfTicks == 0) ? makeTickLabel(currentTickValue) : "";
                }
            } else { //not small log values in use; allow for values <= 0
                if (zeroTickFlag) { //if did zero tick last iter then
                    --j; //decrement to do 1.0 tick now
                } //calculate power-of-ten value for tick:
                currentTickValue = (i >= 0) ? Math.pow(10, i) + (Math.pow(10, i) * j)
                        : -(Math.pow(10, -i) - (Math.pow(10, -i - 1) * j));
                if (!zeroTickFlag) { // did not do zero tick last iteration
                    if (Math.abs(currentTickValue - 1.0) < 0.0001 && lowerBoundVal <= 0.0
                            && upperBoundVal >= 0.0) {
                        //tick value is 1.0 and 0.0 is within data range
                        currentTickValue = 0.0; //set tick value to zero
                        zeroTickFlag = true; //indicate zero tick
                    }
                } else { //did zero tick last iteration
                    zeroTickFlag = false; //clear flag
                } //create tick label string:
                //show tick label if "1e#"-style and it's one
                // of the first two, if it's the first or last
                // in the set, or if it's 1-5; beyond that
                // show fewer as the values get larger:
                tickLabel = ((this.expTickLabelsFlag && j < 2) || j < 1 || (i < 1 && j < 5) || (j < 4 - i)
                        || currentTickValue >= upperBoundVal || numberOfTicks == 0)
                                ? makeTickLabel(currentTickValue)
                                : "";
            }

            if (currentTickValue > upperBoundVal) {
                if (lastTick != null) {
                    String lastTickText = lastTick.getText();
                    if (lastTickText == null || lastTickText.trim().length() == 0) {
                        ticks.remove(lastTick);
                        ticks.add(new NumberTick(lastTick.getValue(),
                                createTickLabel(lastTick.getValue(), i - 1), lastTick.getTextAnchor(),
                                lastTick.getRotationAnchor(), lastTick.getAngle()));
                    }
                }
                if (numberOfTicks < 4) {
                    return getAllTicksHorizontal(g2, dataArea, edge);
                }
                return ticks; // if past highest data value then exit
                              // method
            }

            if (currentTickValue >= lowerBoundVal - SMALL_LOG_VALUE) {
                //tick value not below lowest data value
                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;
                    }
                }

                lastTick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor,
                        angle);
                ticks.add(lastTick);
                if (tickLabel != null && tickLabel.trim().length() > 0)
                    numberOfTicks++;
                numberOfGrids++;
            }
        }
    }
    if (numberOfTicks < 4) {
        return getAllTicksHorizontal(g2, dataArea, edge);
    }
    return ticks;
}

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

@Override
protected List refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    List ticks = new java.util.ArrayList();

    //get lower bound value:
    double lowerBoundVal = getRange().getLowerBound();
    //if small log values and lower bound value too small
    // then set to a small value (don't allow <= 0):
    if (this.smallLogFlag && lowerBoundVal < SMALL_LOG_VALUE) {
        lowerBoundVal = SMALL_LOG_VALUE;
    }/*from  ww w .j a v  a  2 s.c o m*/
    //get upper bound value
    double upperBoundVal = getRange().getUpperBound();

    //get log10 version of lower bound and round to integer:
    int iBegCount = (int) Math.rint(switchedLog10(lowerBoundVal));
    //get log10 version of upper bound and round to integer:
    int iEndCount = (int) Math.rint(switchedLog10(upperBoundVal));

    if (iBegCount == iEndCount && iBegCount > 0 && Math.pow(10, iBegCount) > lowerBoundVal) {
        //only 1 power of 10 value, it's > 0 and its resulting
        // tick value will be larger than lower bound of data
        --iBegCount; //decrement to generate more ticks
    }

    int numberOfGrids = 0;
    int numberOfTicks = 0;
    NumberTick lastTick = null;
    double tickVal;
    String tickLabel;
    //        tickVal = lowerBoundVal;
    //        
    //        tickLabel = Long.toString((long) Math.rint(tickVal));
    //        ticks.add(new NumberTick(new Double(tickVal), tickLabel,
    //              TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0));
    boolean zeroTickFlag = false;
    for (int i = iBegCount; i <= iEndCount; i++) {
        //for each tick with a label to be displayed
        int jEndCount = 10;
        if (i == iEndCount) {
            //                jEndCount = 1;
        }

        for (int j = 0; j < jEndCount; j++) {
            //for each tick to be displayed
            if (this.smallLogFlag) {
                //small log values in use
                tickVal = Math.pow(10, i) + (Math.pow(10, i) * j);
                if (j == 0 || j == 1 || j == 4) {
                    //first tick of group; create label text
                    if (this.log10TickLabelsFlag) {
                        //if flag then
                        tickLabel = "10^" + i; //create "log10"-type label
                    } else { //not "log10"-type label
                        if (this.expTickLabelsFlag) {
                            //if flag then
                            tickLabel = "1e" + i; //create "1e#"-type label
                        } else { //not "1e#"-type label
                            if (i >= 0) { // if positive exponent then
                                          // make integer
                                NumberFormat format = getNumberFormatOverride();
                                if (format != null) {
                                    tickLabel = format.format(tickVal);
                                } else {
                                    tickLabel = Long.toString((long) Math.rint(tickVal));
                                }
                            } else {
                                //negative exponent; create fractional value
                                //set exact number of fractional digits to
                                // be shown:
                                this.numberFormatterObj.setMaximumFractionDigits(-i);
                                //create tick label:
                                tickLabel = this.numberFormatterObj.format(tickVal);
                            }
                        }
                    }
                } else { //not first tick to be displayed
                    if (numberOfTicks == 0)
                        tickLabel = createTickLabel(tickVal, i);
                    else
                        tickLabel = ""; //no label
                    //                        tickLabel = "";     //no tick label
                }
            } else { //not small log values in use; allow for values <= 0
                if (zeroTickFlag) { //if did zero tick last iter then
                    --j;
                } //decrement to do 1.0 tick now
                tickVal = (i >= 0) ? Math.pow(10, i) + (Math.pow(10, i) * j)
                        : -(Math.pow(10, -i) - (Math.pow(10, -i - 1) * j));
                if (j == 0 || j == 1 || j == 4) { //first tick of group
                    if (!zeroTickFlag) { // did not do zero tick last
                                         // iteration
                        if (i > iBegCount && i < iEndCount && Math.abs(tickVal - 1.0) < 0.0001) {
                            // not first or last tick on graph and value
                            // is 1.0
                            tickVal = 0.0; //change value to 0.0
                            zeroTickFlag = true; //indicate zero tick
                            tickLabel = "0"; //create label for tick
                        } else {
                            //first or last tick on graph or value is 1.0
                            //create label for tick:
                            tickLabel = createTickLabel(tickVal, i);
                        }
                    } else { // did zero tick last iteration
                        if (numberOfTicks == 0)
                            tickLabel = createTickLabel(tickVal, i);
                        else
                            tickLabel = ""; //no label
                        zeroTickFlag = false; //clear flag
                    }
                } else { // not first tick of group
                    if (numberOfTicks == 0)
                        tickLabel = createTickLabel(tickVal, i);
                    else
                        tickLabel = ""; //no label
                    zeroTickFlag = false; //make sure flag cleared
                }
            }

            if (tickVal > upperBoundVal) {
                if (lastTick != null) {
                    String lastTickText = lastTick.getText();
                    double value = lastTick.getValue();
                    if (numberOfTicks < 8 || getFirstDigit(value) != 6)
                        if (lastTickText == null || lastTickText.trim().length() == 0) {
                            ticks.remove(lastTick);
                            ticks.add(new NumberTick(lastTick.getValue(),
                                    createTickLabel(lastTick.getValue(), i - 1), lastTick.getTextAnchor(),
                                    lastTick.getRotationAnchor(), lastTick.getAngle()));
                        }
                }
                if (numberOfTicks < 4) {
                    return getAllTicksVertical(g2, dataArea, edge);
                }
                return ticks; //if past highest data value then exit method
            }

            if (tickVal >= lowerBoundVal - SMALL_LOG_VALUE) {
                //tick value not below lowest data value
                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;
                    }
                }
                //create tick object and add to list:
                lastTick = new NumberTick(new Double(tickVal), tickLabel, anchor, rotationAnchor, angle);
                ticks.add(lastTick);
                if (tickLabel != null && tickLabel.trim().length() > 0)
                    numberOfTicks++;
                numberOfGrids++;
            }
        }
    }
    if (numberOfTicks < 4) {
        return getAllTicksVertical(g2, dataArea, edge);
    }
    return ticks;
}

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

protected List newRefreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    List ticks = new java.util.ArrayList();

    //get lower bound value:
    double lowerBoundVal = getRange().getLowerBound();
    //if small log values and lower bound value too small
    // then set to a small value (don't allow <= 0):
    if (this.smallLogFlag && lowerBoundVal < SMALL_LOG_VALUE) {
        lowerBoundVal = SMALL_LOG_VALUE;
    }// w  w  w.ja  v a2s.co m
    //get upper bound value
    double upperBoundVal = getRange().getUpperBound();

    //get log10 version of lower bound and round to integer:
    int iBegCount = (int) Math.rint(switchedLog10(lowerBoundVal));
    //get log10 version of upper bound and round to integer:
    int iEndCount = (int) Math.rint(switchedLog10(upperBoundVal));

    if (iBegCount == iEndCount && iBegCount > 0 && Math.pow(10, iBegCount) > lowerBoundVal) {
        //only 1 power of 10 value, it's > 0 and its resulting
        // tick value will be larger than lower bound of data
        --iBegCount; //decrement to generate more ticks
    }

    //      nxi@ansto: check how many ticks get produced. Put more if less than 4
    int numberOfGrids = 0;
    int numberOfTicks = 0;
    NumberTick lastTick = null;

    double tickVal;
    String tickLabel;
    //        tickVal = lowerBoundVal;
    //        
    //        tickLabel = Long.toString((long) Math.rint(tickVal));
    //        ticks.add(new NumberTick(new Double(tickVal), tickLabel,
    //              TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0));
    boolean zeroTickFlag = false;
    for (int i = iBegCount; i <= iEndCount; i++) {
        //for each tick with a label to be displayed
        int jEndCount = 10;
        if (i == iEndCount) {
            //                jEndCount = 1;
        }

        for (int j = 0; j < jEndCount; j++) {
            //for each tick to be displayed
            if (this.smallLogFlag) {
                //small log values in use
                tickVal = Math.pow(10, i) + (Math.pow(10, i) * j);
                if (j == 0 || j == 1 || j == 4) {
                    //first tick of group; create label text
                    if (this.log10TickLabelsFlag) {
                        //if flag then
                        tickLabel = "10^" + i; //create "log10"-type label
                    } else { //not "log10"-type label
                        if (this.expTickLabelsFlag) {
                            //if flag then
                            tickLabel = "1e" + i; //create "1e#"-type label
                        } else { //not "1e#"-type label
                            if (i >= 0) { // if positive exponent then
                                          // make integer
                                NumberFormat format = getNumberFormatOverride();
                                if (format != null) {
                                    tickLabel = format.format(tickVal);
                                } else {
                                    tickLabel = Long.toString((long) Math.rint(tickVal));
                                }
                            } else {
                                //negative exponent; create fractional value
                                //set exact number of fractional digits to
                                // be shown:
                                this.numberFormatterObj.setMaximumFractionDigits(-i);
                                //create tick label:
                                tickLabel = this.numberFormatterObj.format(tickVal);
                            }
                        }
                    }
                } else { //not first tick to be displayed
                    if (numberOfTicks == 0)
                        tickLabel = createTickLabel(tickVal, i);
                    else
                        tickLabel = ""; //no label
                    //                        tickLabel = "";     //no tick label
                }
            } else { //not small log values in use; allow for values <= 0
                if (zeroTickFlag) { //if did zero tick last iter then
                    --j;
                } //decrement to do 1.0 tick now
                tickVal = (i >= 0) ? Math.pow(10, i) + (Math.pow(10, i) * j)
                        : -(Math.pow(10, -i) - (Math.pow(10, -i - 1) * j));
                if (j == 0 || j == 1 || j == 4) { //first tick of group
                    if (!zeroTickFlag) { // did not do zero tick last
                                         // iteration
                        if (i > iBegCount && i < iEndCount && Math.abs(tickVal - 1.0) < 0.0001) {
                            // not first or last tick on graph and value
                            // is 1.0
                            tickVal = 0.0; //change value to 0.0
                            zeroTickFlag = true; //indicate zero tick
                            tickLabel = "0"; //create label for tick
                        } else {
                            //first or last tick on graph or value is 1.0
                            //create label for tick:
                            tickLabel = createTickLabel(tickVal, i);
                        }
                    } else { // did zero tick last iteration
                        if (numberOfTicks == 0)
                            tickLabel = createTickLabel(tickVal, i);
                        else
                            tickLabel = ""; //no label
                        zeroTickFlag = false; //clear flag
                    }
                } else { // not first tick of group
                    if (numberOfTicks == 0)
                        tickLabel = createTickLabel(tickVal, i);
                    else
                        tickLabel = ""; //no label
                    zeroTickFlag = false; //make sure flag cleared
                }
            }

            if (tickVal > upperBoundVal) {
                if (lastTick != null) {
                    String lastTickText = lastTick.getText();
                    double value = lastTick.getValue();
                    if (numberOfTicks < 8 || getFirstDigit(value) != 6)
                        if (lastTickText == null || lastTickText.trim().length() == 0) {
                            ticks.remove(lastTick);
                            ticks.add(new NumberTick(lastTick.getValue(),
                                    createTickLabel(lastTick.getValue(), i - 1), lastTick.getTextAnchor(),
                                    lastTick.getRotationAnchor(), lastTick.getAngle()));
                        }
                }
                if (numberOfTicks < 4) {
                    return getAllTicksVertical(g2, dataArea, edge);
                }
                return ticks; //if past highest data value then exit method
            }

            if (tickVal >= lowerBoundVal - SMALL_LOG_VALUE) {
                //tick value not below lowest data value
                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;
                    }
                }
                // nxi@ansto: create tick object and add to list:
                lastTick = new NumberTick(new Double(tickVal), tickLabel, anchor, rotationAnchor, angle);
                ticks.add(lastTick);
                if (tickLabel != null && tickLabel.trim().length() > 0)
                    numberOfTicks++;
                numberOfGrids++;
            }
        }
    }
    if (numberOfTicks < 4) {
        return getAllTicksVertical(g2, dataArea, edge);
    }
    return ticks;
}