FileDocCategorySizeDatePackage
TickScaler.javaAPI DocAndroid 1.5 API4486Wed May 06 22:41:10 BST 2009com.android.traceview

TickScaler

public class TickScaler extends Object

Fields Summary
private double
mMinVal
private double
mMaxVal
private double
mRangeVal
private int
mNumPixels
private int
mPixelsPerTick
private double
mPixelsPerRange
private double
mTickIncrement
private double
mMinMajorTick
Constructors Summary
TickScaler(double minVal, double maxVal, int numPixels, int pixelsPerTick)

        mMinVal = minVal;
        mMaxVal = maxVal;
        mNumPixels = numPixels;
        mPixelsPerTick = pixelsPerTick;
    
Methods Summary
public voidcomputeTicks(boolean useGivenEndPoints)

        int numTicks = mNumPixels / mPixelsPerTick;
        mRangeVal = mMaxVal - mMinVal;
        mTickIncrement = mRangeVal / numTicks;
        double dlogTickIncrement = Math.log10(mTickIncrement);
        int logTickIncrement = (int) Math.floor(dlogTickIncrement);
        double scale = Math.pow(10, logTickIncrement);
        double scaledTickIncr = mTickIncrement / scale;
        if (scaledTickIncr > 5.0)
            scaledTickIncr = 10;
        else if (scaledTickIncr > 2)
            scaledTickIncr = 5;
        else if (scaledTickIncr > 1)
            scaledTickIncr = 2;
        else
            scaledTickIncr = 1;
        mTickIncrement = scaledTickIncr * scale;

        if (!useGivenEndPoints) {
            // Round up the max val to the next minor tick
            double minorTickIncrement = mTickIncrement / 5;
            double dval = mMaxVal / minorTickIncrement;
            int ival = (int) dval;
            if (ival != dval)
                mMaxVal = (ival + 1) * minorTickIncrement;

            // Round down the min val to a multiple of tickIncrement
            ival = (int) (mMinVal / mTickIncrement);
            mMinVal = ival * mTickIncrement;
            mMinMajorTick = mMinVal;
        } else {
            int ival = (int) (mMinVal / mTickIncrement);
            mMinMajorTick = ival * mTickIncrement;
            if (mMinMajorTick < mMinVal)
                mMinMajorTick = mMinMajorTick + mTickIncrement;
        }

        mRangeVal = mMaxVal - mMinVal;
        mPixelsPerRange = (double) mNumPixels / mRangeVal;
    
public doublegetMaxVal()

        return mMaxVal;
    
public doublegetMinMajorTick()

        return mMinMajorTick;
    
public doublegetMinVal()

        return mMinVal;
    
public intgetNumPixels()

        return mNumPixels;
    
public doublegetPixelsPerRange()

        return mPixelsPerRange;
    
public intgetPixelsPerTick()

        return mPixelsPerTick;
    
public doublegetTickIncrement()

        return mTickIncrement;
    
public doublepixelToValue(int pixel)

        return mMinVal + (pixel / mPixelsPerRange);
    
public voidsetMaxVal(double maxVal)

        mMaxVal = maxVal;
    
public voidsetMinMajorTick(double minMajorTick)

        mMinMajorTick = minMajorTick;
    
public voidsetMinVal(double minVal)

        mMinVal = minVal;
    
public voidsetNumPixels(int numPixels)

        mNumPixels = numPixels;
    
public voidsetPixelsPerRange(double pixelsPerRange)

        mPixelsPerRange = pixelsPerRange;
    
public voidsetPixelsPerTick(int pixelsPerTick)

        mPixelsPerTick = pixelsPerTick;
    
public voidsetTickIncrement(double tickIncrement)

        mTickIncrement = tickIncrement;
    
public intvalueToPixel(double value)

        return (int) Math.ceil(mPixelsPerRange * (value - mMinVal) - 0.5);
    
public doublevalueToPixelFraction(double value)

        return mPixelsPerRange * (value - mMinVal);