Java Code Examples for com.github.mikephil.charting.utils.ColorTemplate#COLOR_NONE

The following examples show how to use com.github.mikephil.charting.utils.ColorTemplate#COLOR_NONE . 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: Legend.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Deprecated
public Legend(int[] colors, String[] labels) {
    this();

    if (colors == null || labels == null) {
        throw new IllegalArgumentException("colors array or labels array is NULL");
    }

    if (colors.length != labels.length) {
        throw new IllegalArgumentException(
                "colors array and labels array need to be of same size");
    }

    List<LegendEntry> entries = new ArrayList<>();

    for (int i = 0; i < Math.min(colors.length, labels.length); i++) {
        final LegendEntry entry = new LegendEntry();
        entry.formColor = colors[i];
        entry.label = labels[i];

        if (entry.formColor == ColorTemplate.COLOR_SKIP)
            entry.form = LegendForm.NONE;
        else if (entry.formColor == ColorTemplate.COLOR_NONE ||
                entry.formColor == 0)
            entry.form = LegendForm.EMPTY;

        entries.add(entry);
    }

    mEntries = entries.toArray(new LegendEntry[entries.size()]);
}
 
Example 2
Source File: RadarChartRenderer.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
public void drawHighlightCircle(Canvas c,
                                MPPointF point,
                                float innerRadius,
                                float outerRadius,
                                int fillColor,
                                int strokeColor,
                                float strokeWidth) {
    c.save();

    outerRadius = Utils.convertDpToPixel(outerRadius);
    innerRadius = Utils.convertDpToPixel(innerRadius);

    if (fillColor != ColorTemplate.COLOR_NONE) {
        Path p = mDrawHighlightCirclePathBuffer;
        p.reset();
        p.addCircle(point.x, point.y, outerRadius, Path.Direction.CW);
        if (innerRadius > 0.f) {
            p.addCircle(point.x, point.y, innerRadius, Path.Direction.CCW);
        }
        mHighlightCirclePaint.setColor(fillColor);
        mHighlightCirclePaint.setStyle(Paint.Style.FILL);
        c.drawPath(p, mHighlightCirclePaint);
    }

    if (strokeColor != ColorTemplate.COLOR_NONE) {
        mHighlightCirclePaint.setColor(strokeColor);
        mHighlightCirclePaint.setStyle(Paint.Style.STROKE);
        mHighlightCirclePaint.setStrokeWidth(Utils.convertDpToPixel(strokeWidth));
        c.drawCircle(point.x, point.y, outerRadius, mHighlightCirclePaint);
    }

    c.restore();
}
 
Example 3
Source File: Legend.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Deprecated
public int[] getExtraColors() {

    int[] old = new int[mExtraEntries.length];
    for (int i = 0; i < mExtraEntries.length; i++) {
        old[i] = mExtraEntries[i].form == LegendForm.NONE ? ColorTemplate.COLOR_SKIP :
                (mExtraEntries[i].form == LegendForm.EMPTY ? ColorTemplate.COLOR_NONE :
                        mExtraEntries[i].formColor);
    }
    return old;
}
 
Example 4
Source File: Legend.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Deprecated
public int[] getColors() {

    int[] old = new int[mEntries.length];
    for (int i = 0; i < mEntries.length; i++) {
        old[i] = mEntries[i].form == LegendForm.NONE ? ColorTemplate.COLOR_SKIP :
                (mEntries[i].form == LegendForm.EMPTY ? ColorTemplate.COLOR_NONE :
                        mEntries[i].formColor);
    }
    return old;
}
 
Example 5
Source File: Legend.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Deprecated
public Legend(int[] colors, String[] labels) {
    this();

    if (colors == null || labels == null) {
        throw new IllegalArgumentException("colors array or labels array is NULL");
    }

    if (colors.length != labels.length) {
        throw new IllegalArgumentException(
                "colors array and labels array need to be of same size");
    }

    List<LegendEntry> entries = new ArrayList<>();

    for (int i = 0; i < Math.min(colors.length, labels.length); i++) {
        final LegendEntry entry = new LegendEntry();
        entry.formColor = colors[i];
        entry.label = labels[i];

        if (entry.formColor == ColorTemplate.COLOR_SKIP)
            entry.form = LegendForm.NONE;
        else if (entry.formColor == ColorTemplate.COLOR_NONE ||
                entry.formColor == 0)
            entry.form = LegendForm.EMPTY;

        entries.add(entry);
    }

    mEntries = entries.toArray(new LegendEntry[entries.size()]);
}
 
Example 6
Source File: RadarChartRenderer.java    From android-kline with Apache License 2.0 5 votes vote down vote up
public void drawHighlightCircle(Canvas c,
                                MPPointF point,
                                float innerRadius,
                                float outerRadius,
                                int fillColor,
                                int strokeColor,
                                float strokeWidth) {
    c.save();

    outerRadius = Utils.convertDpToPixel(outerRadius);
    innerRadius = Utils.convertDpToPixel(innerRadius);

    if (fillColor != ColorTemplate.COLOR_NONE) {
        Path p = mDrawHighlightCirclePathBuffer;
        p.reset();
        p.addCircle(point.x, point.y, outerRadius, Path.Direction.CW);
        if (innerRadius > 0.f) {
            p.addCircle(point.x, point.y, innerRadius, Path.Direction.CCW);
        }
        mHighlightCirclePaint.setColor(fillColor);
        mHighlightCirclePaint.setStyle(Paint.Style.FILL);
        c.drawPath(p, mHighlightCirclePaint);
    }

    if (strokeColor != ColorTemplate.COLOR_NONE) {
        mHighlightCirclePaint.setColor(strokeColor);
        mHighlightCirclePaint.setStyle(Paint.Style.STROKE);
        mHighlightCirclePaint.setStrokeWidth(Utils.convertDpToPixel(strokeWidth));
        c.drawCircle(point.x, point.y, outerRadius, mHighlightCirclePaint);
    }

    c.restore();
}
 
Example 7
Source File: RadarChartRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
public void drawHighlightCircle(Canvas c,
                            PointF point,
                            float innerRadius,
                            float outerRadius,
                            int fillColor,
                            int strokeColor,
                            float strokeWidth) {
    c.save();

    outerRadius = Utils.convertDpToPixel(outerRadius);
    innerRadius = Utils.convertDpToPixel(innerRadius);

    if (fillColor != ColorTemplate.COLOR_NONE) {
        Path p = new Path();
        p.addCircle(point.x, point.y, outerRadius, Path.Direction.CW);
        if (innerRadius > 0.f) {
            p.addCircle(point.x, point.y, innerRadius, Path.Direction.CCW);
        }
        mHighlightCirclePaint.setColor(fillColor);
        mHighlightCirclePaint.setStyle(Paint.Style.FILL);
        c.drawPath(p, mHighlightCirclePaint);
    }

    if (strokeColor != ColorTemplate.COLOR_NONE) {
        mHighlightCirclePaint.setColor(strokeColor);
        mHighlightCirclePaint.setStyle(Paint.Style.STROKE);
        mHighlightCirclePaint.setStrokeWidth(Utils.convertDpToPixel(strokeWidth));
        c.drawCircle(point.x, point.y, outerRadius, mHighlightCirclePaint);
    }

    c.restore();
}
 
Example 8
Source File: SquareShapeRenderer.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeSize = dataSet.getScatterShapeSize();
    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();

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

        c.drawRect(posX - shapeHoleSizeHalf - shapeStrokeSizeHalf,
                posY - shapeHoleSizeHalf - shapeStrokeSizeHalf,
                posX + shapeHoleSizeHalf + shapeStrokeSizeHalf,
                posY + shapeHoleSizeHalf + shapeStrokeSizeHalf,
                renderPaint);

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

            renderPaint.setColor(shapeHoleColor);
            c.drawRect(posX - shapeHoleSizeHalf,
                    posY - shapeHoleSizeHalf,
                    posX + shapeHoleSizeHalf,
                    posY + shapeHoleSizeHalf,
                    renderPaint);
        }

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

        c.drawRect(posX - shapeHalf,
                posY - shapeHalf,
                posX + shapeHalf,
                posY + shapeHalf,
                renderPaint);
    }
}
 
Example 9
Source File: CircleShapeRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeSize = dataSet.getScatterShapeSize();
    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();

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

        c.drawCircle(
                posX,
                posY,
                shapeHoleSizeHalf + shapeStrokeSizeHalf,
                renderPaint);

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

            renderPaint.setColor(shapeHoleColor);
            c.drawCircle(
                    posX,
                    posY,
                    shapeHoleSizeHalf,
                    renderPaint);
        }
    } else {
        renderPaint.setStyle(Paint.Style.FILL);

        c.drawCircle(
                posX,
                posY,
                shapeHalf,
                renderPaint);
    }

}
 
Example 10
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 11
Source File: LineChartRenderer.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
protected void drawCircles(Canvas c) {

        mRenderPaint.setStyle(Paint.Style.FILL);

        float phaseY = mAnimator.getPhaseY();

        mCirclesBuffer[0] = 0;
        mCirclesBuffer[1] = 0;

        List<ILineDataSet> dataSets = mChart.getLineData().getDataSets();

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

            ILineDataSet dataSet = dataSets.get(i);

            if (!dataSet.isVisible() || !dataSet.isDrawCirclesEnabled() ||
                    dataSet.getEntryCount() == 0)
                continue;

            mCirclePaintInner.setColor(dataSet.getCircleHoleColor());

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

            mXBounds.set(mChart, dataSet);

            float circleRadius = dataSet.getCircleRadius();
            float circleHoleRadius = dataSet.getCircleHoleRadius();
            boolean drawCircleHole = dataSet.isDrawCircleHoleEnabled() &&
                    circleHoleRadius < circleRadius &&
                    circleHoleRadius > 0.f;
            boolean drawTransparentCircleHole = drawCircleHole &&
                    dataSet.getCircleHoleColor() == ColorTemplate.COLOR_NONE;

            DataSetImageCache imageCache;

            if (mImageCaches.containsKey(dataSet)) {
                imageCache = mImageCaches.get(dataSet);
            } else {
                imageCache = new DataSetImageCache();
                mImageCaches.put(dataSet, imageCache);
            }

            boolean changeRequired = imageCache.init(dataSet);

            // only fill the cache with new bitmaps if a change is required
            if (changeRequired) {
                imageCache.fill(dataSet, drawCircleHole, drawTransparentCircleHole);
            }

            int boundsRangeCount = mXBounds.range + mXBounds.min;

            for (int j = mXBounds.min; j <= boundsRangeCount; j++) {

                Entry e = dataSet.getEntryForIndex(j);

                if (e == null) break;

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

                trans.pointValuesToPixel(mCirclesBuffer);

                if (!mViewPortHandler.isInBoundsRight(mCirclesBuffer[0]))
                    break;

                if (!mViewPortHandler.isInBoundsLeft(mCirclesBuffer[0]) ||
                        !mViewPortHandler.isInBoundsY(mCirclesBuffer[1]))
                    continue;

                Bitmap circleBitmap = imageCache.getBitmap(j);

                if (circleBitmap != null) {
                    c.drawBitmap(circleBitmap, mCirclesBuffer[0] - circleRadius, mCirclesBuffer[1] - circleRadius, null);
                }
            }
        }
    }
 
Example 12
Source File: LegendRenderer.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
/**
 * Draws the Legend-form at the given position with the color at the given
 * index.
 *
 * @param c      canvas to draw with
 * @param x      position
 * @param y      position
 * @param entry  the entry to render
 * @param legend the legend context
 */
protected void drawForm(
        Canvas c,
        float x, float y,
        LegendEntry entry,
        Legend legend) {

    if (entry.formColor == ColorTemplate.COLOR_SKIP ||
            entry.formColor == ColorTemplate.COLOR_NONE ||
            entry.formColor == 0)
        return;

    int restoreCount = c.save();

    Legend.LegendForm form = entry.form;
    if (form == Legend.LegendForm.DEFAULT)
        form = legend.getForm();

    mLegendFormPaint.setColor(entry.formColor);

    final float formSize = Utils.convertDpToPixel(
            Float.isNaN(entry.formSize)
                    ? legend.getFormSize()
                    : entry.formSize);
    final float half = formSize / 2f;

    switch (form) {
        case NONE:
            // Do nothing
            break;

        case EMPTY:
            // Do not draw, but keep space for the form
            break;

        case DEFAULT:
        case CIRCLE:
            mLegendFormPaint.setStyle(Paint.Style.FILL);
            c.drawCircle(x + half, y, half, mLegendFormPaint);
            break;

        case SQUARE:
            mLegendFormPaint.setStyle(Paint.Style.FILL);
            c.drawRect(x, y - half, x + formSize, y + half, mLegendFormPaint);
            break;

        case LINE:
        {
            final float formLineWidth = Utils.convertDpToPixel(
                    Float.isNaN(entry.formLineWidth)
                            ? legend.getFormLineWidth()
                            : entry.formLineWidth);
            final DashPathEffect formLineDashEffect = entry.formLineDashEffect == null
                    ? legend.getFormLineDashEffect()
                    : entry.formLineDashEffect;
            mLegendFormPaint.setStyle(Paint.Style.STROKE);
            mLegendFormPaint.setStrokeWidth(formLineWidth);
            mLegendFormPaint.setPathEffect(formLineDashEffect);

            mLineFormPath.reset();
            mLineFormPath.moveTo(x, y);
            mLineFormPath.lineTo(x + formSize, y);
            c.drawPath(mLineFormPath, mLegendFormPaint);
        }
            break;
    }

    c.restoreToCount(restoreCount);
}
 
Example 13
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 14
Source File: LineChartRenderer.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
protected void drawCircles(Canvas c) {

        mRenderPaint.setStyle(Paint.Style.FILL);

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

        float[] circlesBuffer = new float[2];

        List<ILineDataSet> dataSets = mChart.getLineData().getDataSets();

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

            ILineDataSet dataSet = dataSets.get(i);

            if (!dataSet.isVisible() || !dataSet.isDrawCirclesEnabled() ||
                    dataSet.getEntryCount() == 0)
                continue;

            mCirclePaintInner.setColor(dataSet.getCircleHoleColor());

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

            int entryCount = dataSet.getEntryCount();

            Entry entryFrom = dataSet.getEntryForXIndex((mMinX < 0) ? 0 : mMinX,
                    DataSet.Rounding.DOWN);
            Entry entryTo = dataSet.getEntryForXIndex(mMaxX, DataSet.Rounding.UP);

            int diff = (entryFrom == entryTo) ? 1 : 0;
            if (dataSet.getMode() == LineDataSet.Mode.CUBIC_BEZIER)
                diff += 1;

            int minx = Math.max(dataSet.getEntryIndex(entryFrom) - diff, 0);
            int maxx = Math.min(Math.max(minx + 2, dataSet.getEntryIndex(entryTo) + 1), entryCount);

            float circleRadius = dataSet.getCircleRadius();
            float circleHoleRadius = dataSet.getCircleHoleRadius();
            boolean drawCircleHole = dataSet.isDrawCircleHoleEnabled() &&
                    circleHoleRadius < circleRadius &&
                    circleHoleRadius > 0.f;
            boolean drawTransparentCircleHole = drawCircleHole &&
                    dataSet.getCircleHoleColor() == ColorTemplate.COLOR_NONE;

            for (int j = minx,
                 count = (int) Math.ceil((maxx - minx) * phaseX + minx);
                 j < count;
                 j ++) {

                Entry e = dataSet.getEntryForIndex(j);

                if (e == null) break;

                circlesBuffer[0] = e.getXIndex();
                circlesBuffer[1] = e.getVal() * phaseY;

                trans.pointValuesToPixel(circlesBuffer);

                if (!mViewPortHandler.isInBoundsRight(circlesBuffer[0]))
                    break;

                // make sure the circles don't do shitty things outside
                // bounds
                if (!mViewPortHandler.isInBoundsLeft(circlesBuffer[0]) ||
                        !mViewPortHandler.isInBoundsY(circlesBuffer[1]))
                    continue;

                mRenderPaint.setColor(dataSet.getCircleColor(j));

                if (drawTransparentCircleHole) {

                    // Begin path for circle with hole
                    mCirclePathBuffer.reset();

                    mCirclePathBuffer.addCircle(circlesBuffer[0], circlesBuffer[1],
                            circleRadius,
                            Path.Direction.CW);

                    // Cut hole in path
                    mCirclePathBuffer.addCircle(circlesBuffer[0], circlesBuffer[1],
                            circleHoleRadius,
                            Path.Direction.CCW);

                    // Fill in-between
                    c.drawPath(mCirclePathBuffer, mRenderPaint);

                } else {

                    c.drawCircle(circlesBuffer[0], circlesBuffer[1],
                            circleRadius,
                            mRenderPaint);

                    if (drawCircleHole) {
                        c.drawCircle(circlesBuffer[0], circlesBuffer[1],
                                circleHoleRadius,
                                mCirclePaintInner);
                    }
                }
            }
        }
    }
 
Example 15
Source File: CircleShapeRenderer.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeSize = dataSet.getScatterShapeSize();
    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();

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

        c.drawCircle(
                posX,
                posY,
                shapeHoleSizeHalf + shapeStrokeSizeHalf,
                renderPaint);

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

            renderPaint.setColor(shapeHoleColor);
            c.drawCircle(
                    posX,
                    posY,
                    shapeHoleSizeHalf,
                    renderPaint);
        }
    } else {
        renderPaint.setStyle(Paint.Style.FILL);

        c.drawCircle(
                posX,
                posY,
                shapeHalf,
                renderPaint);
    }

}
 
Example 16
Source File: SquareShapeRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeSize = dataSet.getScatterShapeSize();
    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();

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

        c.drawRect(posX - shapeHoleSizeHalf - shapeStrokeSizeHalf,
                posY - shapeHoleSizeHalf - shapeStrokeSizeHalf,
                posX + shapeHoleSizeHalf + shapeStrokeSizeHalf,
                posY + shapeHoleSizeHalf + shapeStrokeSizeHalf,
                renderPaint);

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

            renderPaint.setColor(shapeHoleColor);
            c.drawRect(posX - shapeHoleSizeHalf,
                    posY - shapeHoleSizeHalf,
                    posX + shapeHoleSizeHalf,
                    posY + shapeHoleSizeHalf,
                    renderPaint);
        }

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

        c.drawRect(posX - shapeHalf,
                posY - shapeHalf,
                posX + shapeHalf,
                posY + shapeHalf,
                renderPaint);
    }
}
 
Example 17
Source File: LineChartRenderer.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
protected void drawCircles(Canvas c) {

        mRenderPaint.setStyle(Paint.Style.FILL);

        float phaseY = mAnimator.getPhaseY();

        mCirclesBuffer[0] = 0;
        mCirclesBuffer[1] = 0;

        List<ILineDataSet> dataSets = mChart.getLineData().getDataSets();

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

            ILineDataSet dataSet = dataSets.get(i);

            if (!dataSet.isVisible() || !dataSet.isDrawCirclesEnabled() ||
                    dataSet.getEntryCount() == 0) {
                continue;
            }

            mCirclePaintInner.setColor(dataSet.getCircleHoleColor());

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

            mXBounds.set(mChart, dataSet);

            float circleRadius = dataSet.getCircleRadius();
            float circleHoleRadius = dataSet.getCircleHoleRadius();
            boolean drawCircleHole = dataSet.isDrawCircleHoleEnabled() &&
                    circleHoleRadius < circleRadius &&
                    circleHoleRadius > 0.f;
            boolean drawTransparentCircleHole = drawCircleHole &&
                    dataSet.getCircleHoleColor() == ColorTemplate.COLOR_NONE;

            DataSetImageCache imageCache;

            if (mImageCaches.containsKey(dataSet)) {
                imageCache = mImageCaches.get(dataSet);
            } else {
                imageCache = new DataSetImageCache();
                mImageCaches.put(dataSet, imageCache);
            }

            boolean changeRequired = imageCache.init(dataSet);

            // only fill the cache with new bitmaps if a change is required
            if (changeRequired) {
                imageCache.fill(dataSet, drawCircleHole, drawTransparentCircleHole);
            }

            int boundsRangeCount = mXBounds.range + mXBounds.min;

            for (int j = mXBounds.min; j <= boundsRangeCount; j++) {

                Entry e = dataSet.getEntryForIndex(j);

                if (e == null) {
                    break;
                }

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

                trans.pointValuesToPixel(mCirclesBuffer);

                if (!mViewPortHandler.isInBoundsRight(mCirclesBuffer[0])) {
                    break;
                }

                if (!mViewPortHandler.isInBoundsLeft(mCirclesBuffer[0]) ||
                        !mViewPortHandler.isInBoundsY(mCirclesBuffer[1])) {
                    continue;
                }

                Bitmap circleBitmap = imageCache.getBitmap(j);

                if (circleBitmap != null) {
                    c.drawBitmap(circleBitmap, mCirclesBuffer[0] - circleRadius, mCirclesBuffer[1] - circleRadius, null);
                }
            }
        }
    }
 
Example 18
Source File: LegendRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the Legend-form at the given position with the color at the given
 * index.
 *
 * @param c      canvas to draw with
 * @param x      position
 * @param y      position
 * @param entry  the entry to render
 * @param legend the legend context
 */
protected void drawForm(
        Canvas c,
        float x, float y,
        LegendEntry entry,
        Legend legend) {

    if (entry.formColor == ColorTemplate.COLOR_SKIP ||
            entry.formColor == ColorTemplate.COLOR_NONE ||
            entry.formColor == 0)
        return;

    int restoreCount = c.save();

    Legend.LegendForm form = entry.form;
    if (form == Legend.LegendForm.DEFAULT)
        form = legend.getForm();

    mLegendFormPaint.setColor(entry.formColor);

    final float formSize = Utils.convertDpToPixel(
            Float.isNaN(entry.formSize)
                    ? legend.getFormSize()
                    : entry.formSize);
    final float half = formSize / 2f;

    switch (form) {
        case NONE:
            // Do nothing
            break;

        case EMPTY:
            // Do not draw, but keep space for the form
            break;

        case DEFAULT:
        case CIRCLE:
            mLegendFormPaint.setStyle(Paint.Style.FILL);
            c.drawCircle(x + half, y, half, mLegendFormPaint);
            break;

        case SQUARE:
            mLegendFormPaint.setStyle(Paint.Style.FILL);
            c.drawRect(x, y - half, x + formSize, y + half, mLegendFormPaint);
            break;

        case LINE:
        {
            final float formLineWidth = Utils.convertDpToPixel(
                    Float.isNaN(entry.formLineWidth)
                            ? legend.getFormLineWidth()
                            : entry.formLineWidth);
            final DashPathEffect formLineDashEffect = entry.formLineDashEffect == null
                    ? legend.getFormLineDashEffect()
                    : entry.formLineDashEffect;
            mLegendFormPaint.setStyle(Paint.Style.STROKE);
            mLegendFormPaint.setStrokeWidth(formLineWidth);
            mLegendFormPaint.setPathEffect(formLineDashEffect);

            mLineFormPath.reset();
            mLineFormPath.moveTo(x, y);
            mLineFormPath.lineTo(x + formSize, y);
            c.drawPath(mLineFormPath, mLegendFormPaint);
        }
            break;
    }

    c.restoreToCount(restoreCount);
}
 
Example 19
Source File: LineChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
protected void drawCircles(Canvas c) {

        mRenderPaint.setStyle(Paint.Style.FILL);

        float phaseY = mAnimator.getPhaseY();

        mCirclesBuffer[0] = 0;
        mCirclesBuffer[1] = 0;

        List<ILineDataSet> dataSets = mChart.getLineData().getDataSets();

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

            ILineDataSet dataSet = dataSets.get(i);

            if (!dataSet.isVisible() || !dataSet.isDrawCirclesEnabled() ||
                    dataSet.getEntryCount() == 0)
                continue;

            mCirclePaintInner.setColor(dataSet.getCircleHoleColor());

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

            mXBounds.set(mChart, dataSet);

            float circleRadius = dataSet.getCircleRadius();
            float circleHoleRadius = dataSet.getCircleHoleRadius();
            boolean drawCircleHole = dataSet.isDrawCircleHoleEnabled() &&
                    circleHoleRadius < circleRadius &&
                    circleHoleRadius > 0.f;
            boolean drawTransparentCircleHole = drawCircleHole &&
                    dataSet.getCircleHoleColor() == ColorTemplate.COLOR_NONE;

            DataSetImageCache imageCache;

            if (mImageCaches.containsKey(dataSet)) {
                imageCache = mImageCaches.get(dataSet);
            } else {
                imageCache = new DataSetImageCache();
                mImageCaches.put(dataSet, imageCache);
            }

            boolean changeRequired = imageCache.init(dataSet);

            // only fill the cache with new bitmaps if a change is required
            if (changeRequired) {
                imageCache.fill(dataSet, drawCircleHole, drawTransparentCircleHole);
            }

            int boundsRangeCount = mXBounds.range + mXBounds.min;

            for (int j = mXBounds.min; j <= boundsRangeCount; j++) {

                Entry e = dataSet.getEntryForIndex(j);

                if (e == null) break;

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

                trans.pointValuesToPixel(mCirclesBuffer);

                if (!mViewPortHandler.isInBoundsRight(mCirclesBuffer[0]))
                    break;

                if (!mViewPortHandler.isInBoundsLeft(mCirclesBuffer[0]) ||
                        !mViewPortHandler.isInBoundsY(mCirclesBuffer[1]))
                    continue;

                Bitmap circleBitmap = imageCache.getBitmap(j);

                if (circleBitmap != null) {
                    c.drawBitmap(circleBitmap, mCirclesBuffer[0] - circleRadius, mCirclesBuffer[1] - circleRadius, null);
                }
            }
        }
    }
 
Example 20
Source File: TriangleShapeRenderer.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeSize = dataSet.getScatterShapeSize();
    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();

    renderPaint.setStyle(Paint.Style.FILL);

    // create a triangle path
    Path tri = mTrianglePathBuffer;
    tri.reset();

    tri.moveTo(posX, posY - shapeHalf);
    tri.lineTo(posX + shapeHalf, posY + shapeHalf);
    tri.lineTo(posX - shapeHalf, posY + shapeHalf);

    if (shapeSize > 0.0) {
        tri.lineTo(posX, posY - shapeHalf);

        tri.moveTo(posX - shapeHalf + shapeStrokeSize,
                posY + shapeHalf - shapeStrokeSize);
        tri.lineTo(posX + shapeHalf - shapeStrokeSize,
                posY + shapeHalf - shapeStrokeSize);
        tri.lineTo(posX,
                posY - shapeHalf + shapeStrokeSize);
        tri.lineTo(posX - shapeHalf + shapeStrokeSize,
                posY + shapeHalf - shapeStrokeSize);
    }

    tri.close();

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

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

        renderPaint.setColor(shapeHoleColor);

        tri.moveTo(posX,
                posY - shapeHalf + shapeStrokeSize);
        tri.lineTo(posX + shapeHalf - shapeStrokeSize,
                posY + shapeHalf - shapeStrokeSize);
        tri.lineTo(posX - shapeHalf + shapeStrokeSize,
                posY + shapeHalf - shapeStrokeSize);
        tri.close();

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

}