Java Code Examples for com.github.mikephil.charting.utils.MPPointF#recycleInstance()

The following examples show how to use com.github.mikephil.charting.utils.MPPointF#recycleInstance() . 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: BarLineChartBase.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
/**
 * Zooms in by 1.4f, into the charts center.
 */
public void zoomIn() {

    MPPointF center = mViewPortHandler.getContentCenter();

    mViewPortHandler.zoomIn(center.x, -center.y, mZoomMatrixBuffer);
    mViewPortHandler.refresh(mZoomMatrixBuffer, this, false);

    MPPointF.recycleInstance(center);

    // Range might have changed, which means that Y-axis labels
    // could have changed in size, affecting Y-axis size.
    // So we need to recalculate offsets.
    calculateOffsets();
    postInvalidate();
}
 
Example 2
Source File: BarChartActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public void onValueSelected(Entry e, Highlight h) {

    if (e == null)
        return;

    RectF bounds = onValueSelectedRectF;
    chart.getBarBounds((BarEntry) e, bounds);
    MPPointF position = chart.getPosition(e, AxisDependency.LEFT);

    Log.i("bounds", bounds.toString());
    Log.i("position", position.toString());

    Log.i("x-index",
            "low: " + chart.getLowestVisibleX() + ", high: "
                    + chart.getHighestVisibleX());

    MPPointF.recycleInstance(position);
}
 
Example 3
Source File: BarLineChartBase.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * Zooms out by 0.7f, from the charts center.
 */
public void zoomOut() {

    MPPointF center = mViewPortHandler.getContentCenter();

    mViewPortHandler.zoomOut(center.x, -center.y, mZoomMatrixBuffer);
    mViewPortHandler.refresh(mZoomMatrixBuffer, this, false);

    MPPointF.recycleInstance(center);

    // Range might have changed, which means that Y-axis labels
    // could have changed in size, affecting Y-axis size.
    // So we need to recalculate offsets.
    calculateOffsets();
    postInvalidate();
}
 
Example 4
Source File: PieRadarChartBase.java    From android-kline with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the distance of a certain point on the chart to the center of the
 * chart.
 *
 * @param x
 * @param y
 * @return
 */
public float distanceToCenter(float x, float y) {

    MPPointF c = getCenterOffsets();

    float dist = 0f;

    float xDist = 0f;
    float yDist = 0f;

    if (x > c.x) {
        xDist = x - c.x;
    } else {
        xDist = c.x - x;
    }

    if (y > c.y) {
        yDist = y - c.y;
    } else {
        yDist = c.y - y;
    }

    // pythagoras
    dist = (float) Math.sqrt(Math.pow(xDist, 2.0) + Math.pow(yDist, 2.0));

    MPPointF.recycleInstance(c);

    return dist;
}
 
Example 5
Source File: RadarChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public void drawValues(Canvas c) {

    float phaseX = mAnimator.getPhaseX();
    float phaseY = mAnimator.getPhaseY();

    float sliceangle = mChart.getSliceAngle();

    // calculate the factor that is needed for transforming the value to
    // pixels
    float factor = mChart.getFactor();

    MPPointF center = mChart.getCenterOffsets();
    MPPointF pOut = MPPointF.getInstance(0,0);
    MPPointF pIcon = MPPointF.getInstance(0,0);

    float yoffset = Utils.convertDpToPixel(5f);

    for (int i = 0; i < mChart.getData().getDataSetCount(); i++) {

        IRadarDataSet dataSet = mChart.getData().getDataSetByIndex(i);

        if (!shouldDrawValues(dataSet))
            continue;

        // apply the text-styling defined by the DataSet
        applyValueTextStyle(dataSet);

        MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
        iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
        iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);

        for (int j = 0; j < dataSet.getEntryCount(); j++) {

            RadarEntry entry = dataSet.getEntryForIndex(j);

             Utils.getPosition(
                     center,
                     (entry.getY() - mChart.getYChartMin()) * factor * phaseY,
                     sliceangle * j * phaseX + mChart.getRotationAngle(),
                     pOut);

            if (dataSet.isDrawValuesEnabled()) {
                drawValue(c,
                        dataSet.getValueFormatter(),
                        entry.getY(),
                        entry,
                        i,
                        pOut.x,
                        pOut.y - yoffset,
                        dataSet.getValueTextColor
                                (j));
            }

            if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {

                Drawable icon = entry.getIcon();

                Utils.getPosition(
                        center,
                        (entry.getY()) * factor * phaseY + iconsOffset.y,
                        sliceangle * j * phaseX + mChart.getRotationAngle(),
                        pIcon);

                //noinspection SuspiciousNameCombination
                pIcon.y += iconsOffset.x;

                Utils.drawImage(
                        c,
                        icon,
                        (int)pIcon.x,
                        (int)pIcon.y,
                        icon.getIntrinsicWidth(),
                        icon.getIntrinsicHeight());
            }
        }

        MPPointF.recycleInstance(iconsOffset);
    }

    MPPointF.recycleInstance(center);
    MPPointF.recycleInstance(pOut);
    MPPointF.recycleInstance(pIcon);
}
 
Example 6
Source File: PieChartRenderer.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
/**
 * This gives all pie-slices a rounded edge.
 *
 * @param c
 */
protected void drawRoundedSlices(Canvas c) {

    if (!mChart.isDrawRoundedSlicesEnabled()) {
        return;
    }

    IPieDataSet dataSet = mChart.getData().getDataSet();

    if (!dataSet.isVisible()) {
        return;
    }

    float phaseX = mAnimator.getPhaseX();
    float phaseY = mAnimator.getPhaseY();

    MPPointF center = mChart.getCenterCircleBox();
    float r = mChart.getRadius();

    // calculate the radius of the "slice-circle"
    float circleRadius = (r - (r * mChart.getHoleRadius() / 100f)) / 2f;

    float[] drawAngles = mChart.getDrawAngles();
    float angle = mChart.getRotationAngle();

    for (int j = 0; j < dataSet.getEntryCount(); j++) {

        float sliceAngle = drawAngles[j];

        Entry e = dataSet.getEntryForIndex(j);

        // draw only if the value is greater than zero
        if ((Math.abs(e.getY()) > Utils.FLOAT_EPSILON)) {

            float x = (float) ((r - circleRadius)
                    * Math.cos(Math.toRadians((angle + sliceAngle)
                    * phaseY)) + center.x);
            float y = (float) ((r - circleRadius)
                    * Math.sin(Math.toRadians((angle + sliceAngle)
                    * phaseY)) + center.y);

            mRenderPaint.setColor(dataSet.getColor(j));
            mBitmapCanvas.drawCircle(x, y, circleRadius, mRenderPaint);
        }

        angle += sliceAngle * phaseX;
    }
    MPPointF.recycleInstance(center);
}
 
Example 7
Source File: RadarChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    float sliceangle = mChart.getSliceAngle();

    // calculate the factor that is needed for transforming the value to
    // pixels
    float factor = mChart.getFactor();

    MPPointF center = mChart.getCenterOffsets();
    MPPointF pOut = MPPointF.getInstance(0,0);

    RadarData radarData = mChart.getData();

    for (Highlight high : indices) {

        IRadarDataSet set = radarData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled())
            continue;

        RadarEntry e = set.getEntryForIndex((int) high.getX());

        if (!isInBoundsX(e, set))
            continue;

        float y = (e.getY() - mChart.getYChartMin());

        Utils.getPosition(center,
                y * factor * mAnimator.getPhaseY(),
                sliceangle * high.getX() * mAnimator.getPhaseX() + mChart.getRotationAngle(),
                pOut);

        high.setDraw(pOut.x, pOut.y);

        // draw the lines
        drawHighlightLines(c, pOut.x, pOut.y, set);

        if (set.isDrawHighlightCircleEnabled()) {

            if (!Float.isNaN(pOut.x) && !Float.isNaN(pOut.y)) {

                int strokeColor = set.getHighlightCircleStrokeColor();
                if (strokeColor == ColorTemplate.COLOR_NONE) {
                    strokeColor = set.getColor(0);
                }

                if (set.getHighlightCircleStrokeAlpha() < 255) {
                    strokeColor = ColorTemplate.colorWithAlpha(strokeColor, set.getHighlightCircleStrokeAlpha());
                }

                drawHighlightCircle(c,
                        pOut,
                        set.getHighlightCircleInnerRadius(),
                        set.getHighlightCircleOuterRadius(),
                        set.getHighlightCircleFillColor(),
                        strokeColor,
                        set.getHighlightCircleStrokeWidth());
            }
        }
    }

    MPPointF.recycleInstance(center);
    MPPointF.recycleInstance(pOut);
}
 
Example 8
Source File: PieRadarChartBase.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
/**
 * returns the angle relative to the chart center for the given point on the
 * chart in degrees. The angle is always between 0 and 360°, 0° is NORTH,
 * 90° is EAST, ...
 *
 * @param x
 * @param y
 * @return
 */
public float getAngleForPoint(float x, float y) {

    MPPointF c = getCenterOffsets();

    double tx = x - c.x, ty = y - c.y;
    double length = Math.sqrt(tx * tx + ty * ty);
    double r = Math.acos(ty / length);

    float angle = (float) Math.toDegrees(r);

    if (x > c.x)
        angle = 360f - angle;

    // add 90° because chart starts EAST
    angle = angle + 90f;

    // neutralize overflow
    if (angle > 360f)
        angle = angle - 360f;

    MPPointF.recycleInstance(c);

    return angle;
}
 
Example 9
Source File: XAxisRendererHorizontalBarChart.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
@Override
public void renderAxisLabels(Canvas c) {

    if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled())
        return;

    float xoffset = mXAxis.getXOffset();

    mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
    mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
    mAxisLabelPaint.setColor(mXAxis.getTextColor());

    MPPointF pointF = MPPointF.getInstance(0,0);

    if (mXAxis.getPosition() == XAxisPosition.TOP) {
        pointF.x = 0.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentRight() + xoffset, pointF);

    } else if (mXAxis.getPosition() == XAxisPosition.TOP_INSIDE) {
        pointF.x = 1.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentRight() - xoffset, pointF);

    } else if (mXAxis.getPosition() == XAxisPosition.BOTTOM) {
        pointF.x = 1.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentLeft() - xoffset, pointF);

    } else if (mXAxis.getPosition() == XAxisPosition.BOTTOM_INSIDE) {
        pointF.x = 1.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentLeft() + xoffset, pointF);

    } else { // BOTH SIDED
        pointF.x = 0.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentRight() + xoffset, pointF);
        pointF.x = 1.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentLeft() - xoffset, pointF);
    }

    MPPointF.recycleInstance(pointF);
}
 
Example 10
Source File: XAxisRendererHorizontalBarChart.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public void renderAxisLabels(Canvas c) {

    if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled())
        return;

    float xoffset = mXAxis.getXOffset();

    mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
    mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
    mAxisLabelPaint.setColor(mXAxis.getTextColor());

    MPPointF pointF = MPPointF.getInstance(0,0);

    if (mXAxis.getPosition() == XAxisPosition.TOP) {
        pointF.x = 0.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentRight() + xoffset, pointF);

    } else if (mXAxis.getPosition() == XAxisPosition.TOP_INSIDE) {
        pointF.x = 1.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentRight() - xoffset, pointF);

    } else if (mXAxis.getPosition() == XAxisPosition.BOTTOM) {
        pointF.x = 1.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentLeft() - xoffset, pointF);

    } else if (mXAxis.getPosition() == XAxisPosition.BOTTOM_INSIDE) {
        pointF.x = 1.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentLeft() + xoffset, pointF);

    } else { // BOTH SIDED
        pointF.x = 0.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentRight() + xoffset, pointF);
        pointF.x = 1.0f;
        pointF.y = 0.5f;
        drawLabels(c, mViewPortHandler.contentLeft() - xoffset, pointF);
    }

    MPPointF.recycleInstance(pointF);
}
 
Example 11
Source File: RadarChartRenderer.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
/**
 * Draws the RadarDataSet
 *
 * @param c
 * @param dataSet
 * @param mostEntries the entry count of the dataset with the most entries
 */
protected void drawDataSet(Canvas c, IRadarDataSet dataSet, int mostEntries) {

    float phaseX = mAnimator.getPhaseX();
    float phaseY = mAnimator.getPhaseY();

    float sliceangle = mChart.getSliceAngle();

    // calculate the factor that is needed for transforming the value to
    // pixels
    float factor = mChart.getFactor();

    MPPointF center = mChart.getCenterOffsets();
    MPPointF pOut = MPPointF.getInstance(0, 0);
    Path surface = mDrawDataSetSurfacePathBuffer;
    surface.reset();

    boolean hasMovedToPoint = false;

    for (int j = 0; j < dataSet.getEntryCount(); j++) {

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

        RadarEntry e = dataSet.getEntryForIndex(j);

        Utils.getPosition(
                center,
                (e.getY() - mChart.getYChartMin()) * factor * phaseY,
                sliceangle * j * phaseX + mChart.getRotationAngle(), pOut);

        if (Float.isNaN(pOut.x)) {
            continue;
        }

        if (!hasMovedToPoint) {
            surface.moveTo(pOut.x, pOut.y);
            hasMovedToPoint = true;
        } else {
            surface.lineTo(pOut.x, pOut.y);
        }
    }

    if (dataSet.getEntryCount() > mostEntries) {
        // if this is not the largest set, draw a line to the center before closing
        surface.lineTo(center.x, center.y);
    }

    surface.close();

    if (dataSet.isDrawFilledEnabled()) {

        final Drawable drawable = dataSet.getFillDrawable();
        if (drawable != null) {

            drawFilledPath(c, surface, drawable);
        } else {

            drawFilledPath(c, surface, dataSet.getFillColor(), dataSet.getFillAlpha());
        }
    }

    mRenderPaint.setStrokeWidth(dataSet.getLineWidth());
    mRenderPaint.setStyle(Paint.Style.STROKE);

    // draw the line (only if filled is disabled or alpha is below 255)
    if (!dataSet.isDrawFilledEnabled() || dataSet.getFillAlpha() < 255) {
        c.drawPath(surface, mRenderPaint);
    }

    MPPointF.recycleInstance(center);
    MPPointF.recycleInstance(pOut);
}
 
Example 12
Source File: YAxisRendererRadarChart.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
public void renderLimitLines(Canvas c) {

    List<LimitLine> limitLines = mYAxis.getLimitLines();

    if (limitLines == null) {
        return;
    }

    float sliceangle = mChart.getSliceAngle();

    // calculate the factor that is needed for transforming the value to
    // pixels
    float factor = mChart.getFactor();

    MPPointF center = mChart.getCenterOffsets();
    MPPointF pOut = MPPointF.getInstance(0, 0);
    for (int i = 0; i < limitLines.size(); i++) {

        LimitLine l = limitLines.get(i);

        if (!l.isEnabled()) {
            continue;
        }

        mLimitLinePaint.setColor(l.getLineColor());
        mLimitLinePaint.setPathEffect(l.getDashPathEffect());
        mLimitLinePaint.setStrokeWidth(l.getLineWidth());

        float r = (l.getLimit() - mChart.getYChartMin()) * factor;

        Path limitPath = mRenderLimitLinesPathBuffer;
        limitPath.reset();


        for (int j = 0; j < mChart.getData().getMaxEntryCountSet().getEntryCount(); j++) {

            Utils.getPosition(center, r, sliceangle * j + mChart.getRotationAngle(), pOut);

            if (j == 0) {
                limitPath.moveTo(pOut.x, pOut.y);
            } else {
                limitPath.lineTo(pOut.x, pOut.y);
            }
        }
        limitPath.close();

        c.drawPath(limitPath, mLimitLinePaint);
    }
    MPPointF.recycleInstance(center);
    MPPointF.recycleInstance(pOut);
}
 
Example 13
Source File: XAxisRenderer.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
@Override
public void renderAxisLabels(Canvas c) {

    if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled())
        return;

    float yoffset = mXAxis.getYOffset();

    mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
    mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
    mAxisLabelPaint.setColor(mXAxis.getTextColor());

    MPPointF pointF = MPPointF.getInstance(0,0);
    if (mXAxis.getPosition() == XAxisPosition.TOP) {
        pointF.x = 0.5f;
        pointF.y = 1.0f;
        drawLabels(c, mViewPortHandler.contentTop() - yoffset, pointF);

    } else if (mXAxis.getPosition() == XAxisPosition.TOP_INSIDE) {
        pointF.x = 0.5f;
        pointF.y = 1.0f;
        drawLabels(c, mViewPortHandler.contentTop() + yoffset + mXAxis.mLabelRotatedHeight, pointF);

    } else if (mXAxis.getPosition() == XAxisPosition.BOTTOM) {
        pointF.x = 0.5f;
        pointF.y = 0.0f;
        drawLabels(c, mViewPortHandler.contentBottom() + yoffset, pointF);

    } else if (mXAxis.getPosition() == XAxisPosition.BOTTOM_INSIDE) {
        pointF.x = 0.5f;
        pointF.y = 0.0f;
        drawLabels(c, mViewPortHandler.contentBottom() - yoffset - mXAxis.mLabelRotatedHeight, pointF);

    } else { // BOTH SIDED
        pointF.x = 0.5f;
        pointF.y = 1.0f;
        drawLabels(c, mViewPortHandler.contentTop() - yoffset, pointF);
        pointF.x = 0.5f;
        pointF.y = 0.0f;
        drawLabels(c, mViewPortHandler.contentBottom() + yoffset, pointF);
    }
    MPPointF.recycleInstance(pointF);
}
 
Example 14
Source File: RadarChartRenderer.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
protected void drawWeb(Canvas c) {

        float sliceangle = mChart.getSliceAngle();

        // calculate the factor that is needed for transforming the value to
        // pixels
        float factor = mChart.getFactor();
        float rotationangle = mChart.getRotationAngle();

        MPPointF center = mChart.getCenterOffsets();

        // draw the web lines that come from the center
        mWebPaint.setStrokeWidth(mChart.getWebLineWidth());
        mWebPaint.setColor(mChart.getWebColor());
        mWebPaint.setAlpha(mChart.getWebAlpha());

        final int xIncrements = 1 + mChart.getSkipWebLineCount();
        int maxEntryCount = mChart.getData().getMaxEntryCountSet().getEntryCount();

        MPPointF p = MPPointF.getInstance(0,0);
        for (int i = 0; i < maxEntryCount; i += xIncrements) {

            Utils.getPosition(
                    center,
                    mChart.getYRange() * factor,
                    sliceangle * i + rotationangle,
                    p);

            c.drawLine(center.x, center.y, p.x, p.y, mWebPaint);
        }
        MPPointF.recycleInstance(p);

        // draw the inner-web
        mWebPaint.setStrokeWidth(mChart.getWebLineWidthInner());
        mWebPaint.setColor(mChart.getWebColorInner());
        mWebPaint.setAlpha(mChart.getWebAlpha());

        int labelCount = mChart.getYAxis().mEntryCount;

        MPPointF p1out = MPPointF.getInstance(0,0);
        MPPointF p2out = MPPointF.getInstance(0,0);
        for (int j = 0; j < labelCount; j++) {

            for (int i = 0; i < mChart.getData().getEntryCount(); i++) {

                float r = (mChart.getYAxis().mEntries[j] - mChart.getYChartMin()) * factor;

                Utils.getPosition(center, r, sliceangle * i + rotationangle, p1out);
                Utils.getPosition(center, r, sliceangle * (i + 1) + rotationangle, p2out);

                c.drawLine(p1out.x, p1out.y, p2out.x, p2out.y, mWebPaint);


            }
        }
        MPPointF.recycleInstance(p1out);
        MPPointF.recycleInstance(p2out);
    }
 
Example 15
Source File: ScatterChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public void drawValues(Canvas c) {

    // if values are drawn
    if (isDrawingValuesAllowed(mChart)) {

        List<IScatterDataSet> dataSets = mChart.getScatterData().getDataSets();

        for (int i = 0; i < mChart.getScatterData().getDataSetCount(); i++) {

            IScatterDataSet dataSet = dataSets.get(i);

            if (!shouldDrawValues(dataSet))
                continue;

            // apply the text-styling defined by the DataSet
            applyValueTextStyle(dataSet);

            mXBounds.set(mChart, dataSet);

            float[] positions = mChart.getTransformer(dataSet.getAxisDependency())
                    .generateTransformedValuesScatter(dataSet,
                            mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max);

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

            MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
            iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
            iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);

            for (int j = 0; j < positions.length; j += 2) {

                if (!mViewPortHandler.isInBoundsRight(positions[j]))
                    break;

                // make sure the lines don't do shitty things outside bounds
                if ((!mViewPortHandler.isInBoundsLeft(positions[j])
                        || !mViewPortHandler.isInBoundsY(positions[j + 1])))
                    continue;

                Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);

                if (dataSet.isDrawValuesEnabled()) {
                    drawValue(c,
                            dataSet.getValueFormatter(),
                            entry.getY(),
                            entry,
                            i,
                            positions[j],
                            positions[j + 1] - shapeSize,
                            dataSet.getValueTextColor(j / 2 + mXBounds.min));
                }

                if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {

                    Drawable icon = entry.getIcon();

                    Utils.drawImage(
                            c,
                            icon,
                            (int)(positions[j] + iconsOffset.x),
                            (int)(positions[j + 1] + iconsOffset.y),
                            icon.getIntrinsicWidth(),
                            icon.getIntrinsicHeight());
                }
            }

            MPPointF.recycleInstance(iconsOffset);
        }
    }
}
 
Example 16
Source File: ScatterChartRenderer.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
public void drawValues(Canvas c) {

    // if values are drawn
    if (isDrawingValuesAllowed(mChart)) {

        List<IScatterDataSet> dataSets = mChart.getScatterData().getDataSets();

        for (int i = 0; i < mChart.getScatterData().getDataSetCount(); i++) {

            IScatterDataSet dataSet = dataSets.get(i);

            if (!shouldDrawValues(dataSet) || dataSet.getEntryCount() < 1)
                continue;

            // apply the text-styling defined by the DataSet
            applyValueTextStyle(dataSet);

            mXBounds.set(mChart, dataSet);

            float[] positions = mChart.getTransformer(dataSet.getAxisDependency())
                    .generateTransformedValuesScatter(dataSet,
                            mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max);

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

            ValueFormatter formatter = dataSet.getValueFormatter();

            MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
            iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
            iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);

            for (int j = 0; j < positions.length; j += 2) {

                if (!mViewPortHandler.isInBoundsRight(positions[j]))
                    break;

                // make sure the lines don't do shitty things outside bounds
                if ((!mViewPortHandler.isInBoundsLeft(positions[j])
                        || !mViewPortHandler.isInBoundsY(positions[j + 1])))
                    continue;

                Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);

                if (dataSet.isDrawValuesEnabled()) {
                    drawValue(c, formatter.getPointLabel(entry), positions[j], positions[j + 1] - shapeSize, dataSet.getValueTextColor(j / 2 + mXBounds.min));
                }

                if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {

                    Drawable icon = entry.getIcon();

                    Utils.drawImage(
                            c,
                            icon,
                            (int) (positions[j] + iconsOffset.x),
                            (int) (positions[j + 1] + iconsOffset.y),
                            icon.getIntrinsicWidth(),
                            icon.getIntrinsicHeight());
                }
            }

            MPPointF.recycleInstance(iconsOffset);
        }
    }
}
 
Example 17
Source File: XAxisRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public void renderAxisLabels(Canvas c) {

    if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled())
        return;

    float yoffset = mXAxis.getYOffset();

    mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
    mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
    mAxisLabelPaint.setColor(mXAxis.getTextColor());

    MPPointF pointF = MPPointF.getInstance(0, 0);
    if (mXAxis.getPosition() == XAxisPosition.TOP) {
        pointF.x = 0.5f;
        pointF.y = 1.0f;
        drawLabels(c, mViewPortHandler.contentTop() - yoffset, pointF);

    } else if (mXAxis.getPosition() == XAxisPosition.TOP_INSIDE) {
        pointF.x = 0.5f;
        pointF.y = 1.0f;
        drawLabels(c, mViewPortHandler.contentTop() + yoffset + mXAxis.mLabelRotatedHeight, pointF);

    } else if (mXAxis.getPosition() == XAxisPosition.BOTTOM) {
        pointF.x = 0.5f;
        pointF.y = 0.0f;
        drawLabels(c, mViewPortHandler.contentBottom() + yoffset, pointF);

    } else if (mXAxis.getPosition() == XAxisPosition.BOTTOM_INSIDE) {
        pointF.x = 0.5f;
        pointF.y = 0.0f;
        drawLabels(c, mViewPortHandler.contentBottom() - yoffset - mXAxis.mLabelRotatedHeight, pointF);

    } else { // BOTH SIDED
        pointF.x = 0.5f;
        pointF.y = 1.0f;
        drawLabels(c, mViewPortHandler.contentTop() - yoffset, pointF);
        pointF.x = 0.5f;
        pointF.y = 0.0f;
        drawLabels(c, mViewPortHandler.contentBottom() + yoffset, pointF);
    }
    MPPointF.recycleInstance(pointF);
}
 
Example 18
Source File: PieChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
/**
 * This gives all pie-slices a rounded edge.
 *
 * @param c
 */
protected void drawRoundedSlices(Canvas c) {

    if (!mChart.isDrawRoundedSlicesEnabled())
        return;

    IPieDataSet dataSet = mChart.getData().getDataSet();

    if (!dataSet.isVisible())
        return;

    float phaseX = mAnimator.getPhaseX();
    float phaseY = mAnimator.getPhaseY();

    MPPointF center = mChart.getCenterCircleBox();
    float r = mChart.getRadius();

    // calculate the radius of the "slice-circle"
    float circleRadius = (r - (r * mChart.getHoleRadius() / 100f)) / 2f;

    float[] drawAngles = mChart.getDrawAngles();
    float angle = mChart.getRotationAngle();

    for (int j = 0; j < dataSet.getEntryCount(); j++) {

        float sliceAngle = drawAngles[j];

        Entry e = dataSet.getEntryForIndex(j);

        // draw only if the value is greater than zero
        if ((Math.abs(e.getY()) > Utils.FLOAT_EPSILON)) {

            float x = (float) ((r - circleRadius)
                    * Math.cos(Math.toRadians((angle + sliceAngle)
                    * phaseY)) + center.x);
            float y = (float) ((r - circleRadius)
                    * Math.sin(Math.toRadians((angle + sliceAngle)
                    * phaseY)) + center.y);

            mRenderPaint.setColor(dataSet.getColor(j));
            mBitmapCanvas.drawCircle(x, y, circleRadius, mRenderPaint);
        }

        angle += sliceAngle * phaseX;
    }
    MPPointF.recycleInstance(center);
}
 
Example 19
Source File: XAxisRendererKline.java    From shinny-futures-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void renderAxisLabels(Canvas c) {

    if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled())
        return;

    float yoffset = mXAxis.getYOffset();

    mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
    mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
    mAxisLabelPaint.setColor(mXAxis.getTextColor());

    MPPointF pointF = MPPointF.getInstance(0, 0);
    if (mXAxis.getPosition() == XAxis.XAxisPosition.TOP) {
        pointF.x = 0.5f;
        pointF.y = 1.0f;
        drawLabels(c, mViewPortHandler.contentTop() - yoffset, pointF);

    } else if (mXAxis.getPosition() == XAxis.XAxisPosition.TOP_INSIDE) {
        pointF.x = 0.5f;
        pointF.y = 1.0f;
        drawLabels(c, mViewPortHandler.contentTop() + yoffset + mXAxis.mLabelRotatedHeight, pointF);

    } else if (mXAxis.getPosition() == XAxis.XAxisPosition.BOTTOM) {
        pointF.x = 0.5f;
        pointF.y = 0.0f;
        drawLabels(c, mViewPortHandler.contentBottom(), pointF);

    } else if (mXAxis.getPosition() == XAxis.XAxisPosition.BOTTOM_INSIDE) {
        pointF.x = 0.5f;
        pointF.y = 0.0f;
        drawLabels(c, mViewPortHandler.contentBottom() - yoffset - mXAxis.mLabelRotatedHeight, pointF);

    } else { // BOTH SIDED
        pointF.x = 0.5f;
        pointF.y = 1.0f;
        drawLabels(c, mViewPortHandler.contentTop() - yoffset, pointF);
        pointF.x = 0.5f;
        pointF.y = 0.0f;
        drawLabels(c, mViewPortHandler.contentBottom() + yoffset, pointF);
    }
    MPPointF.recycleInstance(pointF);
}
 
Example 20
Source File: BarLineChartTouchListener.java    From android-kline with Apache License 2.0 3 votes vote down vote up
@Override
public boolean onDoubleTap(MotionEvent e) {

    mLastGesture = ChartGesture.DOUBLE_TAP;

    OnChartGestureListener l = mChart.getOnChartGestureListener();

    if (l != null) {
        l.onChartDoubleTapped(e);
    }

    // check if double-tap zooming is enabled
    if (mChart.isDoubleTapToZoomEnabled() && mChart.getData().getEntryCount() > 0) {

        MPPointF trans = getTrans(e.getX(), e.getY());

        mChart.zoom(mChart.isScaleXEnabled() ? 1.4f : 1f, mChart.isScaleYEnabled() ? 1.4f : 1f, trans.x, trans.y);

        if (mChart.isLogEnabled())
            Log.i("BarlineChartTouch", "Double-Tap, Zooming In, x: " + trans.x + ", y: "
                    + trans.y);

        MPPointF.recycleInstance(trans);
    }

    return super.onDoubleTap(e);
}