Search in sources :

Example 6 with PieModel

use of org.eazegraph.lib.models.PieModel in project EazeGraph by blackfizz.

the class PieChart method centerOnCurrentItem.

/**
     * Kicks off an animation that will result in the pointer being centered in the
     * pie slice of the currently selected item.
     */
private void centerOnCurrentItem() {
    if (!mPieData.isEmpty()) {
        PieModel current = mPieData.get(getCurrentItem());
        int targetAngle;
        if (mOpenClockwise) {
            targetAngle = (mIndicatorAngle - current.getStartAngle()) - ((current.getEndAngle() - current.getStartAngle()) / 2);
            if (targetAngle < 0 && mPieRotation > 0)
                targetAngle += 360;
        } else {
            targetAngle = current.getStartAngle() + (current.getEndAngle() - current.getStartAngle()) / 2;
            targetAngle += mIndicatorAngle;
            if (targetAngle > 270 && mPieRotation < 90)
                targetAngle -= 360;
        }
        mAutoCenterAnimator.setIntValues(targetAngle);
        mAutoCenterAnimator.setDuration(AUTOCENTER_ANIM_DURATION).start();
    }
}
Also used : PieModel(org.eazegraph.lib.models.PieModel) Paint(android.graphics.Paint)

Example 7 with PieModel

use of org.eazegraph.lib.models.PieModel in project EazeGraph by blackfizz.

the class PieChart method update.

/**
     * Resets and clears the data object.
     */
@Override
public void update() {
    mTotalValue = 0;
    for (PieModel slice : mPieData) {
        mTotalValue += slice.getValue();
    }
    onDataChanged();
}
Also used : PieModel(org.eazegraph.lib.models.PieModel)

Example 8 with PieModel

use of org.eazegraph.lib.models.PieModel in project EazeGraph by blackfizz.

the class PieChart method onGraphDraw.

// ---------------------------------------------------------------------------------------------
//                          Override methods from view layers
// ---------------------------------------------------------------------------------------------
@Override
protected void onGraphDraw(Canvas _Canvas) {
    super.onGraphDraw(_Canvas);
    if (!mPieData.isEmpty()) {
        float innerStartAngle = 0;
        float innerSweepAngle = 0;
        int amountOfPieSlices = mPieData.size();
        for (int pieIndex = 0; pieIndex < amountOfPieSlices; pieIndex++) {
            PieModel model = mPieData.get(pieIndex);
            mGraphPaint.setColor(model.getColor());
            // TODO: put calculation in the animation onUpdate method and provide an animated value
            float startAngle;
            float sweepAngle = (model.getEndAngle() - model.getStartAngle()) * mRevealValue;
            if (mOpenClockwise) {
                startAngle = model.getStartAngle() * mRevealValue;
            } else {
                startAngle = 360 - model.getEndAngle() * mRevealValue;
            }
            if (pieIndex == 0) {
                innerStartAngle = startAngle + (mOpenClockwise ? 0 : (float) Math.ceil(sweepAngle));
            }
            if (mOpenClockwise)
                innerSweepAngle += sweepAngle;
            else
                innerSweepAngle -= (float) Math.ceil(sweepAngle);
            _Canvas.drawArc(mGraphBounds, startAngle, sweepAngle, true, mGraphPaint);
            // Draw the highlighted inner edges if an InnerPadding is selected
            if (mUseInnerPadding) {
                mGraphPaint.setColor(model.getHighlightedColor());
                _Canvas.drawArc(mInnerBounds, startAngle, sweepAngle, true, mGraphPaint);
            }
        }
        // Draw inner white circle
        if (mUseInnerPadding) {
            mGraphPaint.setColor(mInnerPaddingColor);
            _Canvas.drawArc(mInnerOutlineBounds, innerStartAngle, innerSweepAngle, true, mGraphPaint);
        }
    } else {
        // No Data available
        mGraphPaint.setColor(0xFFB6B6B6);
        _Canvas.drawArc(mGraphBounds, 0, 360, true, mGraphPaint);
        // Draw inner white circle
        if (mUseInnerPadding) {
            mGraphPaint.setColor(0xFFC6C6C6);
            _Canvas.drawArc(mInnerBounds, 0, 360, true, mGraphPaint);
            mGraphPaint.setColor(mInnerPaddingColor);
            _Canvas.drawArc(mInnerOutlineBounds, 0, 360, true, mGraphPaint);
        }
    }
}
Also used : PieModel(org.eazegraph.lib.models.PieModel) Paint(android.graphics.Paint)

Example 9 with PieModel

use of org.eazegraph.lib.models.PieModel in project EazeGraph by blackfizz.

the class PieChart method onGraphOverlayDraw.

@Override
protected void onGraphOverlayDraw(Canvas _Canvas) {
    super.onGraphOverlayDraw(_Canvas);
    if (!mPieData.isEmpty() && mDrawValueInPie) {
        PieModel model = mPieData.get(mCurrentItem);
        if (!mUseCustomInnerValue) {
            mInnerValueString = Utils.getFloatString(model.getValue(), mShowDecimal);
            if (mInnerValueUnit != null && mInnerValueUnit.length() > 0) {
                mInnerValueString += " " + mInnerValueUnit;
            }
        }
        mValuePaint.getTextBounds(mInnerValueString, 0, mInnerValueString.length(), mValueTextBounds);
        _Canvas.drawText(mInnerValueString, mInnerBounds.centerX() - (mValueTextBounds.width() / 2), mInnerBounds.centerY() + (mValueTextBounds.height() / 2), mValuePaint);
    }
}
Also used : PieModel(org.eazegraph.lib.models.PieModel)

Aggregations

PieModel (org.eazegraph.lib.models.PieModel)9 Paint (android.graphics.Paint)4 GestureDetector (android.view.GestureDetector)1 Scroller (android.widget.Scroller)1 Animator (com.nineoldandroids.animation.Animator)1 ObjectAnimator (com.nineoldandroids.animation.ObjectAnimator)1 ValueAnimator (com.nineoldandroids.animation.ValueAnimator)1 IOnItemFocusChangedListener (org.eazegraph.lib.communication.IOnItemFocusChangedListener)1