com.github.mikephil.charting.buffer.ScatterBuffer Java Examples

The following examples show how to use com.github.mikephil.charting.buffer.ScatterBuffer. 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: ScatterChartRenderer.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
protected void drawDataSet(Canvas c, IScatterDataSet dataSet) {

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

        float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
        float phaseY = mAnimator.getPhaseY();

        final float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize());

        ScatterBuffer buffer = mScatterBuffers[mChart.getScatterData().getIndexOfDataSet(
                dataSet)];
        buffer.setPhases(phaseX, phaseY);
        buffer.feed(dataSet);

        trans.pointValuesToPixel(buffer.buffer);

        String shape = dataSet.getScatterShape();
        ShapeRenderer renderer = mChart.getShapeRenderer(shape);

        if (renderer != null) {
            renderer.renderShape(c, dataSet, mViewPortHandler, buffer, mRenderPaint, shapeSize);
        } else {
            throw new RuntimeException("No ShapeRenderer found for provided identifier. Please make sure to add a ShapeRenderer" +
                    " capable of rendering the provided shape.");
        }
    }
 
Example #2
Source File: ScatterChartRenderer.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@Override
public void initBuffers() {

    ScatterData scatterData = mChart.getScatterData();

    mScatterBuffers = new ScatterBuffer[scatterData.getDataSetCount()];

    for (int i = 0; i < mScatterBuffers.length; i++) {
        ScatterDataSet set = scatterData.getDataSetByIndex(i);
        mScatterBuffers[i] = new ScatterBuffer(set.getEntryCount() * 2);
    }
}
 
Example #3
Source File: ScatterChartRenderer.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void initBuffers() {

    ScatterData scatterData = mChart.getScatterData();

    mScatterBuffers = new ScatterBuffer[scatterData.getDataSetCount()];

    for (int i = 0; i < mScatterBuffers.length; i++) {
        IScatterDataSet set = scatterData.getDataSetByIndex(i);
        mScatterBuffers[i] = new ScatterBuffer(set.getEntryCount() * 2);
    }
}
 
Example #4
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 #5
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 #6
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 #7
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 #8
Source File: ScatterChartRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void initBuffers() {

    ScatterData scatterData = mChart.getScatterData();

    mScatterBuffers = new ScatterBuffer[scatterData.getDataSetCount()];

    for (int i = 0; i < mScatterBuffers.length; i++) {
        IScatterDataSet set = scatterData.getDataSetByIndex(i);
        mScatterBuffers[i] = new ScatterBuffer(set.getEntryCount() * 2);
    }
}
 
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);
        }
    }
}
 
Example #12
Source File: ShapeRenderer.java    From NetKnight with Apache License 2.0 2 votes vote down vote up
/**
 * Renders the provided ScatterDataSet with a shape.
 *
 * @param c
 * @param dataSet
 * @param viewPortHandler
 * @param buffer
 * @param renderPaint
 * @param shapeSize
 */
void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, ScatterBuffer buffer, Paint
        renderPaint, final float shapeSize);