Search in sources :

Example 31 with PointF

use of android.graphics.PointF in project carat by amplab.

the class BarLineChartTouchListener method performDrag.

/**
     * Performs all necessary operations needed for dragging.
     * 
     * @param event
     */
private void performDrag(MotionEvent event) {
    mMatrix.set(mSavedMatrix);
    PointF dragPoint = new PointF(event.getX(), event.getY());
    // check if axis is inverted
    if (!mChart.isInvertYAxisEnabled()) {
        mMatrix.postTranslate(dragPoint.x - mTouchStartPoint.x, dragPoint.y - mTouchStartPoint.y);
    } else {
        mMatrix.postTranslate(dragPoint.x - mTouchStartPoint.x, -(dragPoint.y - mTouchStartPoint.y));
    }
}
Also used : PointF(android.graphics.PointF)

Example 32 with PointF

use of android.graphics.PointF in project carat by amplab.

the class Chart method getMarkerPosition.

/**
     * Returns the actual position in pixels of the MarkerView for the given
     * Entry in the given DataSet.
     *
     * @param xIndex
     * @param dataSetIndex
     * @return
     */
private float[] getMarkerPosition(Entry e, int dataSetIndex) {
    float xPos = e.getXIndex();
    // CandleStickChart
    if (this instanceof CandleStickChart)
        xPos += 0.5f;
    else if (this instanceof BarChart) {
        BarData bd = (BarData) mData;
        float space = bd.getGroupSpace();
        float j = mData.getDataSetByIndex(dataSetIndex).getEntryPosition(e);
        float x = (j * (mData.getDataSetCount() - 1)) + dataSetIndex + space * j + space / 2f + 0.5f;
        xPos += x;
    } else if (this instanceof RadarChart) {
        RadarChart rc = (RadarChart) this;
        float angle = rc.getSliceAngle() * e.getXIndex() + rc.getRotationAngle();
        float val = e.getVal() * rc.getFactor();
        PointF c = getCenterOffsets();
        PointF p = new PointF((float) (c.x + val * Math.cos(Math.toRadians(angle))), (float) (c.y + val * Math.sin(Math.toRadians(angle))));
        return new float[] { p.x, p.y };
    }
    // position of the marker depends on selected value index and value
    float[] pts = new float[] { xPos, e.getVal() * mPhaseY };
    mTrans.pointValuesToPixel(pts);
    return pts;
}
Also used : BarData(com.github.mikephil.charting.data.BarData) PointF(android.graphics.PointF)

Example 33 with PointF

use of android.graphics.PointF in project carat by amplab.

the class RadarChart method drawWeb.

/**
     * Draws the spider web.
     */
private void drawWeb() {
    if (!mDrawWeb)
        return;
    float sliceangle = getSliceAngle();
    // calculate the factor that is needed for transforming the value to
    // pixels
    float factor = getFactor();
    PointF c = getCenterOffsets();
    // draw the web lines that come from the center
    mWebPaint.setStrokeWidth(mWebLineWidth);
    mWebPaint.setColor(mWebColor);
    mWebPaint.setAlpha(mWebAlpha);
    for (int i = 0; i < mData.getXValCount(); i++) {
        PointF p = getPosition(c, mYChartMax * factor, sliceangle * i + mRotationAngle);
        mDrawCanvas.drawLine(c.x, c.y, p.x, p.y, mWebPaint);
    }
    // draw the inner-web
    mWebPaint.setStrokeWidth(mInnerWebLineWidth);
    mWebPaint.setColor(mWebColorInner);
    mWebPaint.setAlpha(mWebAlpha);
    int labelCount = mYLabels.mEntryCount;
    for (int j = 0; j < labelCount; j++) {
        for (int i = 0; i < mData.getXValCount(); i++) {
            float r = ((mYChartMax / labelCount) * (j + 1)) * factor;
            PointF p1 = getPosition(c, r, sliceangle * i + mRotationAngle);
            PointF p2 = getPosition(c, r, sliceangle * (i + 1) + mRotationAngle);
            mDrawCanvas.drawLine(p1.x, p1.y, p2.x, p2.y, mWebPaint);
        }
    }
}
Also used : PointF(android.graphics.PointF) Paint(android.graphics.Paint)

Example 34 with PointF

use of android.graphics.PointF in project carat by amplab.

the class RadarChart method drawYLabels.

/**
     * Draws the y-labels of the RadarChart.
     */
private void drawYLabels() {
    if (!mDrawYLabels)
        return;
    mYLabelPaint.setTypeface(mYLabels.getTypeface());
    mYLabelPaint.setTextSize(mYLabels.getTextSize());
    mYLabelPaint.setColor(mYLabels.getTextColor());
    PointF c = getCenterOffsets();
    float factor = getFactor();
    int labelCount = mYLabels.mEntryCount;
    for (int j = 0; j < labelCount; j++) {
        if (j == labelCount - 1 && mYLabels.isDrawTopYLabelEntryEnabled() == false)
            break;
        float r = ((mYChartMax / labelCount) * j) * factor;
        PointF p = getPosition(c, r, mRotationAngle);
        float val = r / factor;
        String label = Utils.formatNumber(val, mYLabels.mDecimals, mYLabels.isSeparateThousandsEnabled());
        if (mYLabels.isDrawUnitsInYLabelEnabled())
            mDrawCanvas.drawText(label + mUnit, p.x + 10, p.y - 5, mYLabelPaint);
        else {
            mDrawCanvas.drawText(label, p.x + 10, p.y - 5, mYLabelPaint);
        }
    }
}
Also used : PointF(android.graphics.PointF) Paint(android.graphics.Paint)

Example 35 with PointF

use of android.graphics.PointF in project carat by amplab.

the class RadarChart method drawXLabels.

/**
     * Draws the x-labels of the chart.
     */
private void drawXLabels() {
    if (!mDrawXLabels)
        return;
    mXLabelPaint.setTypeface(mXLabels.getTypeface());
    mXLabelPaint.setTextSize(mXLabels.getTextSize());
    mXLabelPaint.setColor(mXLabels.getTextColor());
    float sliceangle = getSliceAngle();
    // calculate the factor that is needed for transforming the value to
    // pixels
    float factor = getFactor();
    PointF c = getCenterOffsets();
    for (int i = 0; i < mData.getXValCount(); i++) {
        String text = mData.getXVals().get(i);
        float angle = (sliceangle * i + mRotationAngle) % 360f;
        PointF p = getPosition(c, mYChartMax * factor + mXLabels.mLabelWidth / 2f, angle);
        mDrawCanvas.drawText(text, p.x, p.y + mXLabels.mLabelHeight / 2f, mXLabelPaint);
    }
}
Also used : PointF(android.graphics.PointF) Paint(android.graphics.Paint)

Aggregations

PointF (android.graphics.PointF)350 Paint (android.graphics.Paint)67 Test (org.junit.Test)31 Matrix (android.graphics.Matrix)28 RectF (android.graphics.RectF)23 Point (android.graphics.Point)19 Path (android.graphics.Path)18 View (android.view.View)12 ValueAnimator (android.animation.ValueAnimator)11 Drawable (android.graphics.drawable.Drawable)11 MotionEvent (android.view.MotionEvent)10 LinearSmoothScroller (android.support.v7.widget.LinearSmoothScroller)9 Animator (android.animation.Animator)8 NonNull (android.support.annotation.NonNull)8 ArrayList (java.util.ArrayList)8 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)7 Rect (android.graphics.Rect)7 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)6 Message (android.os.Message)6 Interpolator (android.view.animation.Interpolator)6