Java Code Examples for com.github.mikephil.charting.utils.ViewPortHandler#isInBoundsY()

The following examples show how to use com.github.mikephil.charting.utils.ViewPortHandler#isInBoundsY() . 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: XShapeRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void renderShape(
        Canvas c, IScatterDataSet dataSet,
        ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {

    final float shapeHalf = shapeSize / 2f;

    mRenderPaint.setStyle(Paint.Style.STROKE);
    mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    for (int i = 0; i < buffer.size(); i += 2) {

        if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
            break;

        if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
                || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
            continue;

        mRenderPaint.setColor(dataSet.getColor(i / 2));

        c.drawLine(
                buffer.buffer[i] - shapeHalf,
                buffer.buffer[i + 1] - shapeHalf,
                buffer.buffer[i] + shapeHalf,
                buffer.buffer[i + 1] + shapeHalf,
                mRenderPaint);
        c.drawLine(
                buffer.buffer[i] + shapeHalf,
                buffer.buffer[i + 1] - shapeHalf,
                buffer.buffer[i] - shapeHalf,
                buffer.buffer[i + 1] + shapeHalf,
                mRenderPaint);
    }

}
 
Example 2
Source File: CrossShapeRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void renderShape(
        Canvas c, IScatterDataSet dataSet,
        ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {

    final float shapeHalf = shapeSize / 2f;


    mRenderPaint.setStyle(Paint.Style.STROKE);
    mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    for (int i = 0; i < buffer.size(); i += 2) {

        if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
            break;

        if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
                || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
            continue;

        mRenderPaint.setColor(dataSet.getColor(i / 2));

        c.drawLine(
                buffer.buffer[i] - shapeHalf,
                buffer.buffer[i + 1],
                buffer.buffer[i] + shapeHalf,
                buffer.buffer[i + 1],
                mRenderPaint);
        c.drawLine(
                buffer.buffer[i],
                buffer.buffer[i + 1] - shapeHalf,
                buffer.buffer[i],
                buffer.buffer[i + 1] + shapeHalf,
                mRenderPaint);
    }

}
 
Example 3
Source File: ChevronUpShapeRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet,
        ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {

    final float shapeHalf = shapeSize / 2f;

    mRenderPaint.setStyle(Paint.Style.STROKE);
    mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    for (int i = 0; i < buffer.size(); i += 2) {

        if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
            break;

        if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
                || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
            continue;

        mRenderPaint.setColor(dataSet.getColor(i / 2));

        c.drawLine(
                buffer.buffer[i],
                buffer.buffer[i + 1] - (2 * shapeHalf),
                buffer.buffer[i] + (2 * shapeHalf),
                buffer.buffer[i + 1],
                mRenderPaint);

        c.drawLine(
                buffer.buffer[i],
                buffer.buffer[i + 1] - (2 * shapeHalf),
                buffer.buffer[i] - (2 * shapeHalf),
                buffer.buffer[i + 1],
                mRenderPaint);
    }

}
 
Example 4
Source File: ChevronDownShapeRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void renderShape(
        Canvas c, IScatterDataSet dataSet,
        ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {

    final float shapeHalf = shapeSize / 2f;

    mRenderPaint.setStyle(Paint.Style.STROKE);
    mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    for (int i = 0; i < buffer.size(); i += 2) {

        if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
            break;

        if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
                || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
            continue;

        mRenderPaint.setColor(dataSet.getColor(i / 2));

        c.drawLine(
                buffer.buffer[i],
                buffer.buffer[i + 1] + (2 * shapeHalf),
                buffer.buffer[i] + (2 * shapeHalf),
                buffer.buffer[i + 1],
                mRenderPaint);

        c.drawLine(
                buffer.buffer[i],
                buffer.buffer[i + 1] + (2 * shapeHalf),
                buffer.buffer[i] - (2 * shapeHalf),
                buffer.buffer[i + 1],
                mRenderPaint);
    }

}
 
Example 5
Source File: ScatterChartRenderer.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
protected void drawDataSet(Canvas c, IScatterDataSet dataSet) {

        if (dataSet.getEntryCount() < 1)
            return;

        ViewPortHandler viewPortHandler = mViewPortHandler;

        Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());

        float phaseY = mAnimator.getPhaseY();

        IShapeRenderer renderer = dataSet.getShapeRenderer();
        if (renderer == null) {
            Log.i("MISSING", "There's no IShapeRenderer specified for ScatterDataSet");
            return;
        }

        int max = (int)(Math.min(
                Math.ceil((float)dataSet.getEntryCount() * mAnimator.getPhaseX()),
                (float)dataSet.getEntryCount()));

        for (int i = 0; i < max; i++) {

            Entry e = dataSet.getEntryForIndex(i);

            mPixelBuffer[0] = e.getX();
            mPixelBuffer[1] = e.getY() * phaseY;

            trans.pointValuesToPixel(mPixelBuffer);

            if (!viewPortHandler.isInBoundsRight(mPixelBuffer[0]))
                break;

            if (!viewPortHandler.isInBoundsLeft(mPixelBuffer[0])
                    || !viewPortHandler.isInBoundsY(mPixelBuffer[1]))
                continue;

            mRenderPaint.setColor(dataSet.getColor(i / 2));
            renderer.renderShape(
                    c, dataSet, mViewPortHandler,
                    mPixelBuffer[0], mPixelBuffer[1],
                    mRenderPaint);
        }
    }
 
Example 6
Source File: ScatterChartRenderer.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
protected void drawDataSet(Canvas c, IScatterDataSet dataSet) {

        ViewPortHandler viewPortHandler = mViewPortHandler;

        Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());

        float phaseY = mAnimator.getPhaseY();

        IShapeRenderer renderer = dataSet.getShapeRenderer();
        if (renderer == null) {
            Log.i("MISSING", "There's no IShapeRenderer specified for ScatterDataSet");
            return;
        }

        int max = (int)(Math.min(
                Math.ceil((float)dataSet.getEntryCount() * mAnimator.getPhaseX()),
                (float)dataSet.getEntryCount()));

        for (int i = 0; i < max; i++) {

            Entry e = dataSet.getEntryForIndex(i);

            mPixelBuffer[0] = e.getX();
            mPixelBuffer[1] = e.getY() * phaseY;

            trans.pointValuesToPixel(mPixelBuffer);

            if (!viewPortHandler.isInBoundsRight(mPixelBuffer[0]))
                break;

            if (!viewPortHandler.isInBoundsLeft(mPixelBuffer[0])
                    || !viewPortHandler.isInBoundsY(mPixelBuffer[1]))
                continue;

            mRenderPaint.setColor(dataSet.getColor(i / 2));
            renderer.renderShape(
                    c, dataSet, mViewPortHandler,
                    mPixelBuffer[0], mPixelBuffer[1],
                    mRenderPaint);
        }
    }
 
Example 7
Source File: ScatterChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
protected void drawDataSet(Canvas c, IScatterDataSet dataSet) {

        ViewPortHandler viewPortHandler = mViewPortHandler;

        Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());

        float phaseY = mAnimator.getPhaseY();

        IShapeRenderer renderer = dataSet.getShapeRenderer();
        if (renderer == null) {
            Log.i("MISSING", "There's no IShapeRenderer specified for ScatterDataSet");
            return;
        }

        int max = (int)(Math.min(
                Math.ceil((float)dataSet.getEntryCount() * mAnimator.getPhaseX()),
                (float)dataSet.getEntryCount()));

        for (int i = 0; i < max; i++) {

            Entry e = dataSet.getEntryForIndex(i);

            mPixelBuffer[0] = e.getX();
            mPixelBuffer[1] = e.getY() * phaseY;

            trans.pointValuesToPixel(mPixelBuffer);

            if (!viewPortHandler.isInBoundsRight(mPixelBuffer[0]))
                break;

            if (!viewPortHandler.isInBoundsLeft(mPixelBuffer[0])
                    || !viewPortHandler.isInBoundsY(mPixelBuffer[1]))
                continue;

            mRenderPaint.setColor(dataSet.getColor(i / 2));
            renderer.renderShape(
                    c, dataSet, mViewPortHandler,
                    mPixelBuffer[0], mPixelBuffer[1],
                    mRenderPaint);
        }
    }
 
Example 8
Source File: ScatterChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
protected void drawDataSet(Canvas c, IScatterDataSet dataSet) {

        ViewPortHandler viewPortHandler = mViewPortHandler;

        Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());

        float phaseY = mAnimator.getPhaseY();

        IShapeRenderer renderer = dataSet.getShapeRenderer();
        if (renderer == null) {
            Log.i("MISSING", "There's no IShapeRenderer specified for ScatterDataSet");
            return;
        }

        int max = (int)(Math.min(
                Math.ceil((float)dataSet.getEntryCount() * mAnimator.getPhaseX()),
                (float)dataSet.getEntryCount()));

        for (int i = 0; i < max; i++) {

            Entry e = dataSet.getEntryForIndex(i);

            mPixelBuffer[0] = e.getX();
            mPixelBuffer[1] = e.getY() * phaseY;

            trans.pointValuesToPixel(mPixelBuffer);

            if (!viewPortHandler.isInBoundsRight(mPixelBuffer[0]))
                break;

            if (!viewPortHandler.isInBoundsLeft(mPixelBuffer[0])
                    || !viewPortHandler.isInBoundsY(mPixelBuffer[1]))
                continue;

            mRenderPaint.setColor(dataSet.getColor(i / 2));
            renderer.renderShape(
                    c, dataSet, mViewPortHandler,
                    mPixelBuffer[0], mPixelBuffer[1],
                    mRenderPaint);
        }
    }
 
Example 9
Source File: CircleShapeRenderer.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
@Override
public void renderShape(
        Canvas c, IScatterDataSet dataSet,
        ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {

    final float shapeHalf = shapeSize / 2f;
    final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
    final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
    final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;
    final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f;

    final int shapeHoleColor = dataSet.getScatterShapeHoleColor();

    for (int i = 0; i < buffer.size(); i += 2) {

        if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
            break;

        if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
                || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
            continue;

        mRenderPaint.setColor(dataSet.getColor(i / 2));

        if (shapeSize > 0.0) {
            mRenderPaint.setStyle(Paint.Style.STROKE);
            mRenderPaint.setStrokeWidth(shapeStrokeSize);

            c.drawCircle(
                    buffer.buffer[i],
                    buffer.buffer[i + 1],
                    shapeHoleSizeHalf + shapeStrokeSizeHalf,
                    mRenderPaint);

            if (shapeHoleColor != ColorTemplate.COLOR_NONE) {
                mRenderPaint.setStyle(Paint.Style.FILL);

                mRenderPaint.setColor(shapeHoleColor);
                c.drawCircle(
                        buffer.buffer[i],
                        buffer.buffer[i + 1],
                        shapeHoleSizeHalf,
                        mRenderPaint);
            }
        } else {
            mRenderPaint.setStyle(Paint.Style.FILL);

            c.drawCircle(
                    buffer.buffer[i],
                    buffer.buffer[i + 1],
                    shapeHalf,
                    mRenderPaint);
        }
    }

}
 
Example 10
Source File: TriangleShapeRenderer.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
@Override
public void renderShape(
        Canvas c, IScatterDataSet dataSet,
        ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {


    final float shapeHalf = shapeSize / 2f;
    final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
    final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
    final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;

    final int shapeHoleColor = dataSet.getScatterShapeHoleColor();

    mRenderPaint.setStyle(Paint.Style.FILL);

    // create a triangle path
    Path tri = new Path();

    for (int i = 0; i < buffer.size(); i += 2) {

        if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
            break;

        if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
                || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
            continue;

        mRenderPaint.setColor(dataSet.getColor(i / 2));

        tri.moveTo(buffer.buffer[i], buffer.buffer[i + 1] - shapeHalf);
        tri.lineTo(buffer.buffer[i] + shapeHalf, buffer.buffer[i + 1] + shapeHalf);
        tri.lineTo(buffer.buffer[i] - shapeHalf, buffer.buffer[i + 1] + shapeHalf);

        if (shapeSize > 0.0) {
            tri.lineTo(buffer.buffer[i], buffer.buffer[i + 1] - shapeHalf);

            tri.moveTo(buffer.buffer[i] - shapeHalf + shapeStrokeSize,
                    buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
            tri.lineTo(buffer.buffer[i] + shapeHalf - shapeStrokeSize,
                    buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
            tri.lineTo(buffer.buffer[i],
                    buffer.buffer[i + 1] - shapeHalf + shapeStrokeSize);
            tri.lineTo(buffer.buffer[i] - shapeHalf + shapeStrokeSize,
                    buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
        }

        tri.close();

        c.drawPath(tri, mRenderPaint);
        tri.reset();

        if (shapeSize > 0.0 &&
                shapeHoleColor != ColorTemplate.COLOR_NONE) {

            mRenderPaint.setColor(shapeHoleColor);

            tri.moveTo(buffer.buffer[i],
                    buffer.buffer[i + 1] - shapeHalf + shapeStrokeSize);
            tri.lineTo(buffer.buffer[i] + shapeHalf - shapeStrokeSize,
                    buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
            tri.lineTo(buffer.buffer[i] - shapeHalf + shapeStrokeSize,
                    buffer.buffer[i + 1] + shapeHalf - shapeStrokeSize);
            tri.close();

            c.drawPath(tri, mRenderPaint);
            tri.reset();
        }
    }

}
 
Example 11
Source File: SquareShapeRenderer.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
@Override
public void renderShape(
        Canvas c, IScatterDataSet dataSet,
        ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {

    final float shapeHalf = shapeSize / 2f;
    final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
    final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
    final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;
    final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f;

    final int shapeHoleColor = dataSet.getScatterShapeHoleColor();

    for (int i = 0; i < buffer.size(); i += 2) {

        if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
            break;

        if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
                || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
            continue;

        mRenderPaint.setColor(dataSet.getColor(i / 2));

        if (shapeSize > 0.0) {
            mRenderPaint.setStyle(Paint.Style.STROKE);
            mRenderPaint.setStrokeWidth(shapeStrokeSize);

            c.drawRect(buffer.buffer[i] - shapeHoleSizeHalf - shapeStrokeSizeHalf,
                    buffer.buffer[i + 1] - shapeHoleSizeHalf - shapeStrokeSizeHalf,
                    buffer.buffer[i] + shapeHoleSizeHalf + shapeStrokeSizeHalf,
                    buffer.buffer[i + 1] + shapeHoleSizeHalf + shapeStrokeSizeHalf,
                    mRenderPaint);

            if (shapeHoleColor != ColorTemplate.COLOR_NONE) {
                mRenderPaint.setStyle(Paint.Style.FILL);

                mRenderPaint.setColor(shapeHoleColor);
                c.drawRect(buffer.buffer[i] - shapeHoleSizeHalf,
                        buffer.buffer[i + 1] - shapeHoleSizeHalf,
                        buffer.buffer[i] + shapeHoleSizeHalf,
                        buffer.buffer[i + 1] + shapeHoleSizeHalf,
                        mRenderPaint);
            }

        } else {
            mRenderPaint.setStyle(Paint.Style.FILL);

            c.drawRect(buffer.buffer[i] - shapeHalf,
                    buffer.buffer[i + 1] - shapeHalf,
                    buffer.buffer[i] + shapeHalf,
                    buffer.buffer[i + 1] + shapeHalf,
                    mRenderPaint);
        }
    }
}