Search in sources :

Example 1 with LegendModel

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

the class ValueLineChart method onLegendDraw.

@Override
protected void onLegendDraw(Canvas _Canvas) {
    super.onLegendDraw(_Canvas);
    mLegendPaint.setColor(mLegendColor);
    mLegendPaint.setStrokeWidth(DEF_LEGEND_STROKE);
    if (!mSeries.isEmpty()) {
        _Canvas.translate(Utils.getTranslationX(mDrawMatrixValues), 0);
        if (mUseCustomLegend) {
            for (LegendModel model : mLegendList) {
                RectF bounds = model.getLegendBounds();
                _Canvas.drawText(model.getLegendLabel(), model.getLegendLabelPosition(), bounds.bottom - mMaxFontHeight, mLegendPaint);
                _Canvas.drawLine(bounds.centerX(), bounds.bottom - mMaxFontHeight * 2 - mLegendTopPadding, bounds.centerX(), mLegendTopPadding, mLegendPaint);
            }
        } else {
            List<? extends BaseModel> list = mSeries.get(0).getSeries();
            for (BaseModel model : list) {
                if (model.canShowLabel()) {
                    RectF bounds = model.getLegendBounds();
                    _Canvas.drawText(model.getLegendLabel(), model.getLegendLabelPosition(), bounds.bottom - mMaxFontHeight, mLegendPaint);
                    _Canvas.drawLine(bounds.centerX(), bounds.bottom - mMaxFontHeight * 2 - mLegendTopPadding, bounds.centerX(), mLegendTopPadding, mLegendPaint);
                }
            }
        }
    }
}
Also used : RectF(android.graphics.RectF) BaseModel(org.eazegraph.lib.models.BaseModel) LegendModel(org.eazegraph.lib.models.LegendModel)

Example 2 with LegendModel

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

the class ValueLineChart method onLegendDataChanged.

/**
     * Calculates the legend bounds for a custom list of legends.
     */
protected void onLegendDataChanged() {
    int legendCount = mLegendList.size();
    float margin = (mGraphWidth / legendCount);
    float currentOffset = 0;
    for (LegendModel model : mLegendList) {
        model.setLegendBounds(new RectF(currentOffset, 0, currentOffset + margin, mLegendHeight));
        currentOffset += margin;
    }
    Utils.calculateLegendInformation(mLegendList, 0, mGraphWidth, mLegendPaint);
    invalidateGlobal();
}
Also used : RectF(android.graphics.RectF) LegendModel(org.eazegraph.lib.models.LegendModel) ValueLinePoint(org.eazegraph.lib.models.ValueLinePoint) Paint(android.graphics.Paint)

Example 3 with LegendModel

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

the class ValueLineChart method initializeGraph.

/**
     * This is the main entry point after the graph has been inflated. Used to initialize the graph
     * and its corresponding members.
     */
@Override
protected void initializeGraph() {
    super.initializeGraph();
    mDrawMatrix.setValues(mDrawMatrixValues);
    mGraphOverlay.decelerate();
    mSeries = new ArrayList<ValueLineSeries>();
    mLegendList = new ArrayList<LegendModel>();
    mLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mLinePaint.setStrokeWidth(mLineStroke);
    mLegendPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mLegendPaint.setColor(mLegendColor);
    mLegendPaint.setTextSize(mLegendTextSize);
    mLegendPaint.setStrokeWidth(2);
    mLegendPaint.setStyle(Paint.Style.FILL);
    mMaxFontHeight = Utils.calculateMaxTextHeight(mLegendPaint, null);
    mIndicatorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mIndicatorPaint.setColor(mIndicatorLineColor);
    mIndicatorPaint.setTextSize(mIndicatorTextSize);
    mIndicatorPaint.setStrokeWidth(mIndicatorWidth);
    mIndicatorPaint.setStyle(Paint.Style.FILL);
    mScaleGestureDetector = new ScaleGestureDetector(getContext(), mScaleGestureListener);
    mGestureDetector = new GestureDetector(getContext(), mGestureListener);
    mScroller = new Scroller(getContext());
    mRevealAnimator = ValueAnimator.ofFloat(0, 1);
    mRevealAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mRevealValue = animation.getAnimatedFraction();
            mDrawMatrix.reset();
            mDrawMatrix.setScale(1, 1.f * mRevealValue, 0, mGraphHeight - mNegativeOffset);
            mGraph.invalidate();
        }
    });
    mRevealAnimator.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mStartedAnimation = false;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    // The scroller doesn't have any built-in animation functions--it just supplies
    // values when we ask it to. So we have to have a way to call it every frame
    // until the fling ends. This code (ab)uses a ValueAnimator object to generate
    // a callback on every animation frame. We don't use the animated value at all.
    mScrollAnimator = ValueAnimator.ofFloat(0, 1);
    mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            tickScrollAnimation();
            invalidateGlobal();
        }
    });
    if (this.isInEditMode()) {
        ValueLineSeries series1 = new ValueLineSeries();
        series1.setColor(0xFF63CBB0);
        series1.addPoint(new ValueLinePoint(1.4f));
        series1.addPoint(new ValueLinePoint(4.4f));
        series1.addPoint(new ValueLinePoint(2.4f));
        series1.addPoint(new ValueLinePoint(3.2f));
        series1.addPoint(new ValueLinePoint(2.6f));
        series1.addPoint(new ValueLinePoint(5.0f));
        series1.addPoint(new ValueLinePoint(3.5f));
        series1.addPoint(new ValueLinePoint(2.4f));
        series1.addPoint(new ValueLinePoint(0.4f));
        series1.addPoint(new ValueLinePoint(3.4f));
        series1.addPoint(new ValueLinePoint(2.5f));
        series1.addPoint(new ValueLinePoint(1.0f));
        series1.addPoint(new ValueLinePoint(4.2f));
        series1.addPoint(new ValueLinePoint(2.4f));
        series1.addPoint(new ValueLinePoint(3.6f));
        series1.addPoint(new ValueLinePoint(1.0f));
        series1.addPoint(new ValueLinePoint(2.5f));
        series1.addPoint(new ValueLinePoint(1.4f));
        addSeries(series1);
    }
}
Also used : GestureDetector(android.view.GestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector) Paint(android.graphics.Paint) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) ValueLinePoint(org.eazegraph.lib.models.ValueLinePoint) ValueLineSeries(org.eazegraph.lib.models.ValueLineSeries) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) ScaleGestureDetector(android.view.ScaleGestureDetector) Scroller(android.widget.Scroller) LegendModel(org.eazegraph.lib.models.LegendModel)

Aggregations

LegendModel (org.eazegraph.lib.models.LegendModel)3 Paint (android.graphics.Paint)2 RectF (android.graphics.RectF)2 ValueLinePoint (org.eazegraph.lib.models.ValueLinePoint)2 GestureDetector (android.view.GestureDetector)1 ScaleGestureDetector (android.view.ScaleGestureDetector)1 Scroller (android.widget.Scroller)1 Animator (com.nineoldandroids.animation.Animator)1 ValueAnimator (com.nineoldandroids.animation.ValueAnimator)1 BaseModel (org.eazegraph.lib.models.BaseModel)1 ValueLineSeries (org.eazegraph.lib.models.ValueLineSeries)1